util: Add function virCgroupHasEmptyTasks

That function helps checking whether there's a task in that cgroup.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Martin Kletzander 2014-12-13 09:56:00 +01:00
parent 97c6271150
commit 1a80b97ddf
3 changed files with 27 additions and 1 deletions

View File

@ -1096,6 +1096,7 @@ virCgroupGetMemSwapHardLimit;
virCgroupGetMemSwapUsage; virCgroupGetMemSwapUsage;
virCgroupGetPercpuStats; virCgroupGetPercpuStats;
virCgroupHasController; virCgroupHasController;
virCgroupHasEmptyTasks;
virCgroupIsolateMount; virCgroupIsolateMount;
virCgroupKill; virCgroupKill;
virCgroupKillPainfully; virCgroupKillPainfully;

View File

@ -3926,6 +3926,20 @@ virCgroupSupportsCpuBW(virCgroupPtr cgroup)
return ret; return ret;
} }
int
virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller)
{
int ret = -1;
char *content = NULL;
ret = virCgroupGetValueStr(cgroup, controller, "tasks", &content);
if (ret == 0 && content[0] == '\0')
ret = 1;
VIR_FREE(content);
return ret;
}
#else /* !VIR_CGROUP_SUPPORTED */ #else /* !VIR_CGROUP_SUPPORTED */
@ -4655,4 +4669,13 @@ virCgroupSetOwner(virCgroupPtr cgroup ATTRIBUTE_UNUSED,
return -1; return -1;
} }
int
virCgroupHasEmptyTasks(virCgroupPtr cgroup ATTRIBUTE_UNUSED,
int controller ATTRIBUTE_UNUSED)
{
virReportSystemError(ENOSYS, "%s",
_("Control groups not supported on this platform"));
return -1;
}
#endif /* !VIR_CGROUP_SUPPORTED */ #endif /* !VIR_CGROUP_SUPPORTED */

View File

@ -1,7 +1,7 @@
/* /*
* vircgroup.h: methods for managing control cgroups * vircgroup.h: methods for managing control cgroups
* *
* Copyright (C) 2011-2013 Red Hat, Inc. * Copyright (C) 2011-2014 Red Hat, Inc.
* Copyright IBM Corp. 2008 * Copyright IBM Corp. 2008
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
@ -270,4 +270,6 @@ int virCgroupSetOwner(virCgroupPtr cgroup,
gid_t gid, gid_t gid,
int controllers); int controllers);
int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller);
#endif /* __VIR_CGROUP_H__ */ #endif /* __VIR_CGROUP_H__ */