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

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: NDaniel P. Berrange <berrange@redhat.com>
上级 66a7f857
......@@ -1182,6 +1182,7 @@ virCgroupGetMemSwapHardLimit;
virCgroupGetMemSwapUsage;
virCgroupHasController;
virCgroupIsolateMount;
virCgroupIsValidMachineGroup;
virCgroupKill;
virCgroupKillPainfully;
virCgroupKillRecursive;
......
......@@ -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:
*
......
......@@ -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,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册