Blob Blame History Raw
From 272c540c20234508b31dcb9a7c3b548e2e328656 Mon Sep 17 00:00:00 2001
Message-Id: <272c540c20234508b31dcb9a7c3b548e2e328656@dist-git>
From: Pavel Hrdina <phrdina@redhat.com>
Date: Mon, 1 Jul 2019 17:06:38 +0200
Subject: [PATCH] vircgroup: extract virCgroupV1HasEmptyTasks
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
(cherry picked from commit c4047141a0af36c5d428bfcc1f14d012f8352a11)

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
Message-Id: <e81675457cc7dd357792080ff07d5e1159b88738.1561993100.git.phrdina@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/vircgroup.c        | 13 +------------
 src/util/vircgroupbackend.h |  5 +++++
 src/util/vircgroupv1.c      | 20 ++++++++++++++++++++
 3 files changed, 26 insertions(+), 12 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index a5076cb554..d4d02d8f5b 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -3465,18 +3465,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
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
index bff1f8938e..3e0f6d01f4 100644
--- a/src/util/vircgroupbackend.h
+++ b/src/util/vircgroupbackend.h
@@ -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;
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
index fda2c43eef..b057cdfd9e 100644
--- a/src/util/vircgroupv1.c
+++ b/src/util/vircgroupv1.c
@@ -736,6 +736,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,
 
@@ -754,6 +773,7 @@ virCgroupBackend virCgroupV1Backend = {
     .makeGroup = virCgroupV1MakeGroup,
     .remove = virCgroupV1Remove,
     .addTask = virCgroupV1AddTask,
+    .hasEmptyTasks = virCgroupV1HasEmptyTasks,
 };
 
 
-- 
2.22.0