提交 04c18d25 编写于 作者: D Daniel P. Berrange

Rename virCgroupForXXX to virCgroupNewXXX

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: NDaniel P. Berrange <berrange@redhat.com>
上级 f0e5f924
......@@ -1101,11 +1101,6 @@ virCgroupDenyAllDevices;
virCgroupDenyDevice;
virCgroupDenyDeviceMajor;
virCgroupDenyDevicePath;
virCgroupForDomain;
virCgroupForDriver;
virCgroupForEmulator;
virCgroupForSelf;
virCgroupForVcpu;
virCgroupFree;
virCgroupGetBlkioWeight;
virCgroupGetCpuacctPercpuUsage;
......@@ -1127,6 +1122,11 @@ virCgroupKill;
virCgroupKillPainfully;
virCgroupKillRecursive;
virCgroupMoveTask;
virCgroupNewDomain;
virCgroupNewDriver;
virCgroupNewEmulator;
virCgroupNewSelf;
virCgroupNewVcpu;
virCgroupPathOfController;
virCgroupRemove;
virCgroupRemoveRecursively;
......
......@@ -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"),
......
......@@ -224,9 +224,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 ||
......@@ -241,7 +243,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"),
......@@ -643,7 +645,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:"
......@@ -721,7 +723,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"),
......
......@@ -3561,7 +3561,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:"
......@@ -3635,7 +3635,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:"
......@@ -3862,7 +3862,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"
......@@ -4124,7 +4124,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",
......@@ -7640,7 +7640,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:"
......@@ -7678,7 +7678,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"),
......@@ -7926,7 +7926,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)"),
......@@ -7964,7 +7964,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"),
......@@ -14148,7 +14148,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;
......
......@@ -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,11 +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,
int controllers ATTRIBUTE_UNUSED)
int controllers ATTRIBUTE_UNUSED,
virCgroupPtr *group ATTRIBUTE_UNUSED)
{
/* Claim no support */
return -ENXIO;
......@@ -982,7 +982,7 @@ int virCgroupForDriver(const char *name ATTRIBUTE_UNUSED,
#endif
/**
* virCgroupForSelf:
* virCgroupNewSelf:
*
* @group: Pointer to returned virCgroupPtr
*
......@@ -992,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
......@@ -1013,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;
......@@ -1049,38 +1046,36 @@ 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
* @create: true to create if not already existing
* @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) |
......@@ -1091,7 +1086,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);
}
......@@ -1099,36 +1094,34 @@ 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
* @create: true to create if not already existing
* @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) |
......@@ -1139,7 +1132,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);
}
......@@ -1147,9 +1140,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;
}
......
......@@ -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);
bool create,
virCgroupPtr *group)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(4);
int virCgroupForEmulator(virCgroupPtr driver,
virCgroupPtr *group,
bool create);
int virCgroupNewEmulator(virCgroupPtr domain,
bool create,
virCgroupPtr *group)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(3);
int virCgroupPathOfController(virCgroupPtr group,
int controller,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册