Fix detection of 'emulator' cgroup

When a VM has an 'emulator' child cgroup present, we must
strip off that suffix when detecting the cgroup for a
machine

Rename the virCgroupIsValidMachineGroup method to
virCgroupValidateMachineGroup to make a bit clearer
that this isn't simply a boolean check, it will make
changes to the object.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2013-07-24 17:41:44 +01:00
parent 525c9d5a49
commit c101b851c1

View File

@ -96,9 +96,10 @@ bool virCgroupAvailable(void)
} }
static bool static bool
virCgroupIsValidMachineGroup(virCgroupPtr group, virCgroupValidateMachineGroup(virCgroupPtr group,
const char *name, const char *name,
const char *drivername) const char *drivername,
bool stripEmulatorSuffix)
{ {
size_t i; size_t i;
bool valid = false; bool valid = false;
@ -120,12 +121,26 @@ virCgroupIsValidMachineGroup(virCgroupPtr group,
tmp = strrchr(group->controllers[i].placement, '/'); tmp = strrchr(group->controllers[i].placement, '/');
if (!tmp) if (!tmp)
goto cleanup; goto cleanup;
if (stripEmulatorSuffix &&
(i == VIR_CGROUP_CONTROLLER_CPU ||
i == VIR_CGROUP_CONTROLLER_CPUACCT ||
i == VIR_CGROUP_CONTROLLER_CPUSET)) {
if (STREQ(tmp, "/emulator"))
*tmp = '\0';
tmp = strrchr(group->controllers[i].placement, '/');
if (!tmp)
goto cleanup;
}
tmp++; tmp++;
if (STRNEQ(tmp, name) && if (STRNEQ(tmp, name) &&
STRNEQ(tmp, partname)) STRNEQ(tmp, partname)) {
VIR_DEBUG("Name '%s' does not match '%s' or '%s'",
tmp, name, partname);
goto cleanup; goto cleanup;
}
} }
valid = true; valid = true;
@ -1590,7 +1605,9 @@ int virCgroupNewDetectMachine(const char *name,
return -1; return -1;
} }
if (!virCgroupIsValidMachineGroup(*group, name, drivername)) { if (!virCgroupValidateMachineGroup(*group, name, drivername, true)) {
VIR_DEBUG("Failed to validate machine name for '%s' driver '%s'",
name, drivername);
virCgroupFree(group); virCgroupFree(group);
return 0; return 0;
} }