1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-20 06:50:22 +03:00

Add API for checking if a cgroup is valid for a domain

Add virCgroupIsValidMachine API to check whether an auto
detected cgroup is valid for a machine. This lets us
check if a VM has just been placed into some generic
shared cgroup, or worse, the root cgroup

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrange 2013-07-23 15:26:21 +01:00
parent 66a7f857f3
commit e638778eb3
3 changed files with 48 additions and 0 deletions

View File

@ -1182,6 +1182,7 @@ virCgroupGetMemSwapHardLimit;
virCgroupGetMemSwapUsage;
virCgroupHasController;
virCgroupIsolateMount;
virCgroupIsValidMachineGroup;
virCgroupKill;
virCgroupKillPainfully;
virCgroupKillRecursive;

View File

@ -67,6 +67,8 @@ typedef enum {
*/
} virCgroupFlags;
static int virCgroupPartitionEscape(char **path);
bool virCgroupAvailable(void)
{
FILE *mounts = NULL;
@ -91,6 +93,46 @@ bool virCgroupAvailable(void)
return ret;
}
bool virCgroupIsValidMachineGroup(virCgroupPtr group,
const char *name,
const char *drivername)
{
size_t i;
bool valid = false;
char *partname;
if (virAsprintf(&partname, "%s.libvirt-%s",
name, drivername) < 0)
goto cleanup;
if (virCgroupPartitionEscape(&partname) < 0)
goto cleanup;
for (i = 0; i < VIR_CGROUP_CONTROLLER_LAST; i++) {
char *tmp;
if (!group->controllers[i].placement)
continue;
tmp = strrchr(group->controllers[i].placement, '/');
if (!tmp)
goto cleanup;
tmp++;
if (STRNEQ(tmp, name) &&
STRNEQ(tmp, partname))
goto cleanup;
}
valid = true;
cleanup:
VIR_FREE(partname);
return valid;
}
/**
* virCgroupFree:
*

View File

@ -48,6 +48,11 @@ VIR_ENUM_DECL(virCgroupController);
bool virCgroupAvailable(void);
bool virCgroupIsValidMachineGroup(virCgroupPtr group,
const char *machinename,
const char *drivername);
int virCgroupNewPartition(const char *path,
bool create,
int controllers,