From: "Daniel P. Berrange" <berrange(a)redhat.com>
Rename all the virCgroupForXXX methods to use the form
virCgroupNewXXX since they are all constructors. Also
make sure the output parameter is the last one in the
list, and annotate all pointers as non-null. Fix up
all callers, and make sure they use true/false not 0/1
for the boolean parameters
Signed-off-by: Daniel P. Berrange <berrange(a)redhat.com>
---
src/libvirt_private.syms | 10 +++---
src/lxc/lxc_cgroup.c | 6 ++--
src/qemu/qemu_cgroup.c | 14 ++++----
src/qemu/qemu_driver.c | 18 +++++------
src/util/vircgroup.c | 84 ++++++++++++++++++++++--------------------------
src/util/vircgroup.h | 33 +++++++++++--------
6 files changed, 82 insertions(+), 83 deletions(-)
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 4db0734..1fea9a2 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1095,11 +1095,6 @@ virCgroupDenyAllDevices;
virCgroupDenyDevice;
virCgroupDenyDeviceMajor;
virCgroupDenyDevicePath;
-virCgroupForDomain;
-virCgroupForDriver;
-virCgroupForEmulator;
-virCgroupForSelf;
-virCgroupForVcpu;
virCgroupFree;
virCgroupGetBlkioWeight;
virCgroupGetCpuacctPercpuUsage;
@@ -1121,6 +1116,11 @@ virCgroupKill;
virCgroupKillPainfully;
virCgroupKillRecursive;
virCgroupMoveTask;
+virCgroupNewDomain;
+virCgroupNewDriver;
+virCgroupNewEmulator;
+virCgroupNewSelf;
+virCgroupNewVcpu;
virCgroupPathOfController;
virCgroupRemove;
virCgroupRemoveRecursively;
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index 1bad9ec..7d1432b 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -293,7 +293,7 @@ int virLXCCgroupGetMeminfo(virLXCMeminfoPtr meminfo)
int ret;
virCgroupPtr cgroup;
- ret = virCgroupForSelf(&cgroup);
+ ret = virCgroupNewSelf(&cgroup);
if (ret < 0) {
virReportSystemError(-ret, "%s",
_("Unable to get cgroup for container"));
@@ -529,14 +529,14 @@ virCgroupPtr virLXCCgroupCreate(virDomainDefPtr def)
virCgroupPtr cgroup = NULL;
int rc;
- rc = virCgroupForDriver("lxc", &driver, 1, 0, -1);
+ rc = virCgroupNewDriver("lxc", true, false, -1, &driver);
if (rc != 0) {
virReportSystemError(-rc, "%s",
_("Unable to get cgroup for driver"));
goto cleanup;
}
- rc = virCgroupForDomain(driver, def->name, &cgroup, 1);
+ rc = virCgroupNewDomain(driver, def->name, true, &cgroup);
if (rc != 0) {
virReportSystemError(-rc,
_("Unable to create cgroup for domain %s"),
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 019aa2e..cb53acb 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -197,9 +197,11 @@ int qemuInitCgroup(virQEMUDriverPtr driver,
virCgroupFree(&priv->cgroup);
- rc = virCgroupForDriver("qemu", &driverGroup,
- cfg->privileged, true,
- cfg->cgroupControllers);
+ rc = virCgroupNewDriver("qemu",
+ cfg->privileged,
+ true,
+ cfg->cgroupControllers,
+ &driverGroup);
if (rc != 0) {
if (rc == -ENXIO ||
rc == -EPERM ||
@@ -214,7 +216,7 @@ int qemuInitCgroup(virQEMUDriverPtr driver,
goto cleanup;
}
- rc = virCgroupForDomain(driverGroup, vm->def->name, &priv->cgroup, 1);
+ rc = virCgroupNewDomain(driverGroup, vm->def->name, true,
&priv->cgroup);
if (rc != 0) {
virReportSystemError(-rc,
_("Unable to create cgroup for %s"),
@@ -610,7 +612,7 @@ int qemuSetupCgroupForVcpu(virDomainObjPtr vm)
}
for (i = 0; i < priv->nvcpupids; i++) {
- rc = virCgroupForVcpu(priv->cgroup, i, &cgroup_vcpu, 1);
+ rc = virCgroupNewVcpu(priv->cgroup, i, true, &cgroup_vcpu);
if (rc < 0) {
virReportSystemError(-rc,
_("Unable to create vcpu cgroup for %s(vcpu:"
@@ -688,7 +690,7 @@ int qemuSetupCgroupForEmulator(virQEMUDriverPtr driver,
if (priv->cgroup == NULL)
return 0; /* Not supported, so claim success */
- rc = virCgroupForEmulator(priv->cgroup, &cgroup_emulator, 1);
+ rc = virCgroupNewEmulator(priv->cgroup, true, &cgroup_emulator);
if (rc < 0) {
virReportSystemError(-rc,
_("Unable to create emulator cgroup for %s"),
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index ab6b74d..d9124e0 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -3600,7 +3600,7 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver,
if (priv->cgroup) {
int rv = -1;
/* Create cgroup for the onlined vcpu */
- rv = virCgroupForVcpu(priv->cgroup, i, &cgroup_vcpu, 1);
+ rv = virCgroupNewVcpu(priv->cgroup, i, true, &cgroup_vcpu);
if (rv < 0) {
virReportSystemError(-rv,
_("Unable to create vcpu cgroup for
%s(vcpu:"
@@ -3674,7 +3674,7 @@ static int qemuDomainHotplugVcpus(virQEMUDriverPtr driver,
if (priv->cgroup) {
int rv = -1;
- rv = virCgroupForVcpu(priv->cgroup, i, &cgroup_vcpu, 0);
+ rv = virCgroupNewVcpu(priv->cgroup, i, false, &cgroup_vcpu);
if (rv < 0) {
virReportSystemError(-rv,
_("Unable to access vcpu cgroup for
%s(vcpu:"
@@ -3913,7 +3913,7 @@ qemuDomainPinVcpuFlags(virDomainPtr dom,
/* Configure the corresponding cpuset cgroup before set affinity. */
if (virCgroupHasController(priv->cgroup, VIR_CGROUP_CONTROLLER_CPUSET)) {
- if (virCgroupForVcpu(priv->cgroup, vcpu, &cgroup_vcpu, 0) == 0
&&
+ if (virCgroupNewVcpu(priv->cgroup, vcpu, false, &cgroup_vcpu) == 0
&&
qemuSetupCgroupVcpuPin(cgroup_vcpu, newVcpuPin, newVcpuPinNum, vcpu) <
0) {
virReportError(VIR_ERR_OPERATION_INVALID,
_("failed to set cpuset.cpus in cgroup"
@@ -4169,7 +4169,7 @@ qemuDomainPinEmulator(virDomainPtr dom,
* Configure the corresponding cpuset cgroup.
* If no cgroup for domain or hypervisor exists, do nothing.
*/
- if (virCgroupForEmulator(priv->cgroup, &cgroup_emulator, 0) == 0)
{
+ if (virCgroupNewEmulator(priv->cgroup, false, &cgroup_emulator) ==
0) {
if (qemuSetupCgroupEmulatorPin(cgroup_emulator,
newVcpuPin[0]->cpumask) < 0) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
@@ -7742,7 +7742,7 @@ qemuSetVcpusBWLive(virDomainObjPtr vm, virCgroupPtr cgroup,
*/
if (priv->nvcpupids != 0 && priv->vcpupids[0] != vm->pid) {
for (i = 0; i < priv->nvcpupids; i++) {
- rc = virCgroupForVcpu(cgroup, i, &cgroup_vcpu, 0);
+ rc = virCgroupNewVcpu(cgroup, i, false, &cgroup_vcpu);
if (rc < 0) {
virReportSystemError(-rc,
_("Unable to find vcpu cgroup for
%s(vcpu:"
@@ -7780,7 +7780,7 @@ qemuSetEmulatorBandwidthLive(virDomainObjPtr vm, virCgroupPtr
cgroup,
return 0;
}
- rc = virCgroupForEmulator(cgroup, &cgroup_emulator, 0);
+ rc = virCgroupNewEmulator(cgroup, false, &cgroup_emulator);
if (rc < 0) {
virReportSystemError(-rc,
_("Unable to find emulator cgroup for %s"),
@@ -8033,7 +8033,7 @@ qemuGetVcpusBWLive(virDomainObjPtr vm,
}
/* get period and quota for vcpu0 */
- rc = virCgroupForVcpu(priv->cgroup, 0, &cgroup_vcpu, 0);
+ rc = virCgroupNewVcpu(priv->cgroup, 0, false, &cgroup_vcpu);
if (!cgroup_vcpu) {
virReportSystemError(-rc,
_("Unable to find vcpu cgroup for %s(vcpu: 0)"),
@@ -8071,7 +8071,7 @@ qemuGetEmulatorBandwidthLive(virDomainObjPtr vm, virCgroupPtr
cgroup,
}
/* get period and quota for emulator */
- rc = virCgroupForEmulator(cgroup, &cgroup_emulator, 0);
+ rc = virCgroupNewEmulator(cgroup, false, &cgroup_emulator);
if (!cgroup_emulator) {
virReportSystemError(-rc,
_("Unable to find emulator cgroup for %s"),
@@ -14336,7 +14336,7 @@ getSumVcpuPercpuStats(virDomainObjPtr vm,
unsigned long long tmp;
int j;
- if (virCgroupForVcpu(priv->cgroup, i, &group_vcpu, 0) < 0) {
+ if (virCgroupNewVcpu(priv->cgroup, i, false, &group_vcpu) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
_("error accessing cgroup cpuacct for vcpu"));
goto cleanup;
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index dfa3c8a..2f52c92 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -927,7 +927,7 @@ cleanup:
}
/**
- * virCgroupForDriver:
+ * virCgroupNewDriver:
*
* @name: name of this driver (e.g., xen, qemu, lxc)
* @group: Pointer to returned virCgroupPtr
@@ -935,11 +935,11 @@ cleanup:
* Returns 0 on success
*/
#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R
-int virCgroupForDriver(const char *name,
- virCgroupPtr *group,
+int virCgroupNewDriver(const char *name,
bool privileged,
bool create,
- int controllers)
+ int controllers,
+ virCgroupPtr *group)
{
int rc;
char *path = NULL;
@@ -970,10 +970,11 @@ out:
return rc;
}
#else
-int virCgroupForDriver(const char *name ATTRIBUTE_UNUSED,
- virCgroupPtr *group ATTRIBUTE_UNUSED,
+int virCgroupNewDriver(const char *name ATTRIBUTE_UNUSED,
bool privileged ATTRIBUTE_UNUSED,
- bool create ATTRIBUTE_UNUSED)
+ bool create ATTRIBUTE_UNUSED,
+ int controllers ATTRIBUTE_UNUSED,
+ virCgroupPtr *group ATTRIBUTE_UNUSED)
{
/* Claim no support */
return -ENXIO;
@@ -981,7 +982,7 @@ int virCgroupForDriver(const char *name ATTRIBUTE_UNUSED,
#endif
/**
-* virCgroupForSelf:
+* virCgroupNewSelf:
*
* @group: Pointer to returned virCgroupPtr
*
@@ -991,19 +992,19 @@ int virCgroupForDriver(const char *name ATTRIBUTE_UNUSED,
* Returns 0 on success
*/
#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R
-int virCgroupForSelf(virCgroupPtr *group)
+int virCgroupNewSelf(virCgroupPtr *group)
{
return virCgroupNew("/", -1, group);
}
#else
-int virCgroupForSelf(virCgroupPtr *group ATTRIBUTE_UNUSED)
+int virCgroupNewSelf(virCgroupPtr *group ATTRIBUTE_UNUSED)
{
return -ENXIO;
}
#endif
/**
- * virCgroupForDomain:
+ * virCgroupNewDomain:
*
* @driver: group for driver owning the domain
* @name: name of the domain
@@ -1012,17 +1013,14 @@ int virCgroupForSelf(virCgroupPtr *group ATTRIBUTE_UNUSED)
* Returns 0 on success
*/
#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R
-int virCgroupForDomain(virCgroupPtr driver,
+int virCgroupNewDomain(virCgroupPtr driver,
const char *name,
- virCgroupPtr *group,
- bool create)
+ bool create,
+ virCgroupPtr *group)
{
int rc;
char *path;
- if (driver == NULL)
- return -EINVAL;
-
if (virAsprintf(&path, "%s/%s", driver->path, name) < 0)
return -ENOMEM;
@@ -1048,38 +1046,35 @@ int virCgroupForDomain(virCgroupPtr driver,
return rc;
}
#else
-int virCgroupForDomain(virCgroupPtr driver ATTRIBUTE_UNUSED,
+int virCgroupNewDomain(virCgroupPtr driver ATTRIBUTE_UNUSED,
const char *name ATTRIBUTE_UNUSED,
- virCgroupPtr *group ATTRIBUTE_UNUSED,
- bool create ATTRIBUTE_UNUSED)
+ bool create ATTRIBUTE_UNUSED,
+ virCgroupPtr *group ATTRIBUTE_UNUSED)
{
return -ENXIO;
}
#endif
/**
- * virCgroupForVcpu:
+ * virCgroupNewVcpu:
*
- * @driver: group for the domain
+ * @domain: group for the domain
* @vcpuid: id of the vcpu
* @group: Pointer to returned virCgroupPtr
*
* Returns 0 on success
*/
#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R
-int virCgroupForVcpu(virCgroupPtr driver,
+int virCgroupNewVcpu(virCgroupPtr domain,
int vcpuid,
- virCgroupPtr *group,
- bool create)
+ bool create,
+ virCgroupPtr *group)
{
int rc;
char *path;
int controllers;
- if (driver == NULL)
- return -EINVAL;
-
- if (virAsprintf(&path, "%s/vcpu%d", driver->path, vcpuid) < 0)
+ if (virAsprintf(&path, "%s/vcpu%d", domain->path, vcpuid) < 0)
return -ENOMEM;
controllers = ((1 << VIR_CGROUP_CONTROLLER_CPU) |
@@ -1090,7 +1085,7 @@ int virCgroupForVcpu(virCgroupPtr driver,
VIR_FREE(path);
if (rc == 0) {
- rc = virCgroupMakeGroup(driver, *group, create, VIR_CGROUP_NONE);
+ rc = virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_NONE);
if (rc != 0)
virCgroupFree(group);
}
@@ -1098,36 +1093,33 @@ int virCgroupForVcpu(virCgroupPtr driver,
return rc;
}
#else
-int virCgroupForVcpu(virCgroupPtr driver ATTRIBUTE_UNUSED,
+int virCgroupNewVcpu(virCgroupPtr domain ATTRIBUTE_UNUSED,
int vcpuid ATTRIBUTE_UNUSED,
- virCgroupPtr *group ATTRIBUTE_UNUSED,
- bool create ATTRIBUTE_UNUSED)
+ bool create ATTRIBUTE_UNUSED,
+ virCgroupPtr *group ATTRIBUTE_UNUSED)
{
return -ENXIO;
}
#endif
/**
- * virCgroupForEmulator:
+ * virCgroupNewEmulator:
*
- * @driver: group for the domain
+ * @domain: group for the domain
* @group: Pointer to returned virCgroupPtr
*
* Returns: 0 on success or -errno on failure
*/
#if defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R
-int virCgroupForEmulator(virCgroupPtr driver,
- virCgroupPtr *group,
- bool create)
+int virCgroupNewEmulator(virCgroupPtr domain,
+ bool create,
+ virCgroupPtr *group)
{
int rc;
char *path;
int controllers;
- if (driver == NULL)
- return -EINVAL;
-
- if (virAsprintf(&path, "%s/emulator", driver->path) < 0)
+ if (virAsprintf(&path, "%s/emulator", domain->path) < 0)
return -ENOMEM;
controllers = ((1 << VIR_CGROUP_CONTROLLER_CPU) |
@@ -1138,7 +1130,7 @@ int virCgroupForEmulator(virCgroupPtr driver,
VIR_FREE(path);
if (rc == 0) {
- rc = virCgroupMakeGroup(driver, *group, create, VIR_CGROUP_NONE);
+ rc = virCgroupMakeGroup(domain, *group, create, VIR_CGROUP_NONE);
if (rc != 0)
virCgroupFree(group);
}
@@ -1146,9 +1138,9 @@ int virCgroupForEmulator(virCgroupPtr driver,
return rc;
}
#else
-int virCgroupForEmulator(virCgroupPtr driver ATTRIBUTE_UNUSED,
- virCgroupPtr *group ATTRIBUTE_UNUSED,
- bool create ATTRIBUTE_UNUSED)
+int virCgroupNewEmulator(virCgroupPtr domain ATTRIBUTE_UNUSED,
+ bool create ATTRIBUTE_UNUSED,
+ virCgroupPtr *group ATTRIBUTE_UNUSED)
{
return -ENXIO;
}
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
index 4c1134d..91143e2 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -44,27 +44,32 @@ enum {
VIR_ENUM_DECL(virCgroupController);
-int virCgroupForDriver(const char *name,
- virCgroupPtr *group,
+int virCgroupNewDriver(const char *name,
bool privileged,
bool create,
- int controllers);
+ int controllers,
+ virCgroupPtr *group)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(5);
-int virCgroupForSelf(virCgroupPtr *group);
+int virCgroupNewSelf(virCgroupPtr *group)
+ ATTRIBUTE_NONNULL(1);
-int virCgroupForDomain(virCgroupPtr driver,
+int virCgroupNewDomain(virCgroupPtr driver,
const char *name,
- virCgroupPtr *group,
- bool create);
+ bool create,
+ virCgroupPtr *group)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_NONNULL(4);
-int virCgroupForVcpu(virCgroupPtr driver,
+int virCgroupNewVcpu(virCgroupPtr domain,
int vcpuid,
- virCgroupPtr *group,
- bool create);
-
-int virCgroupForEmulator(virCgroupPtr driver,
- virCgroupPtr *group,
- bool create);
+ bool create,
+ virCgroupPtr *group)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
+
+int virCgroupNewEmulator(virCgroupPtr domain,
+ bool create,
+ virCgroupPtr *group)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
int virCgroupPathOfController(virCgroupPtr group,
int controller,
--
1.8.1.4