vircgroup: extract virCgroupV1HasEmptyTasks

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Pavel Hrdina 2018-08-17 15:25:48 +02:00
parent 064024e70a
commit c4047141a0
3 changed files with 26 additions and 12 deletions

View File

@ -3461,18 +3461,7 @@ virCgroupSupportsCpuBW(virCgroupPtr cgroup)
int
virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller)
{
int ret = -1;
VIR_AUTOFREE(char *) content = NULL;
if (!cgroup)
return -1;
ret = virCgroupGetValueStr(cgroup, controller, "tasks", &content);
if (ret == 0 && content[0] == '\0')
ret = 1;
return ret;
return cgroup->backend->hasEmptyTasks(cgroup, controller);
}
bool

View File

@ -122,6 +122,10 @@ typedef int
pid_t pid,
unsigned int flags);
typedef int
(*virCgroupHasEmptyTasksCB)(virCgroupPtr cgroup,
int controller);
struct _virCgroupBackend {
virCgroupBackendType type;
@ -141,6 +145,7 @@ struct _virCgroupBackend {
virCgroupMakeGroupCB makeGroup;
virCgroupRemoveCB remove;
virCgroupAddTaskCB addTask;
virCgroupHasEmptyTasksCB hasEmptyTasks;
};
typedef struct _virCgroupBackend virCgroupBackend;
typedef virCgroupBackend *virCgroupBackendPtr;

View File

@ -735,6 +735,25 @@ virCgroupV1AddTask(virCgroupPtr group,
}
static int
virCgroupV1HasEmptyTasks(virCgroupPtr cgroup,
int controller)
{
int ret = -1;
VIR_AUTOFREE(char *) content = NULL;
if (!cgroup)
return -1;
ret = virCgroupGetValueStr(cgroup, controller, "tasks", &content);
if (ret == 0 && content[0] == '\0')
ret = 1;
return ret;
}
virCgroupBackend virCgroupV1Backend = {
.type = VIR_CGROUP_BACKEND_TYPE_V1,
@ -753,6 +772,7 @@ virCgroupBackend virCgroupV1Backend = {
.makeGroup = virCgroupV1MakeGroup,
.remove = virCgroupV1Remove,
.addTask = virCgroupV1AddTask,
.hasEmptyTasks = virCgroupV1HasEmptyTasks,
};