render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c480ed
From 272c540c20234508b31dcb9a7c3b548e2e328656 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <272c540c20234508b31dcb9a7c3b548e2e328656@dist-git>
c480ed
From: Pavel Hrdina <phrdina@redhat.com>
c480ed
Date: Mon, 1 Jul 2019 17:06:38 +0200
c480ed
Subject: [PATCH] vircgroup: extract virCgroupV1HasEmptyTasks
c480ed
MIME-Version: 1.0
c480ed
Content-Type: text/plain; charset=UTF-8
c480ed
Content-Transfer-Encoding: 8bit
c480ed
c480ed
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
(cherry picked from commit c4047141a0af36c5d428bfcc1f14d012f8352a11)
c480ed
c480ed
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c480ed
c480ed
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c480ed
Message-Id: <e81675457cc7dd357792080ff07d5e1159b88738.1561993100.git.phrdina@redhat.com>
c480ed
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c480ed
---
c480ed
 src/util/vircgroup.c        | 13 +------------
c480ed
 src/util/vircgroupbackend.h |  5 +++++
c480ed
 src/util/vircgroupv1.c      | 20 ++++++++++++++++++++
c480ed
 3 files changed, 26 insertions(+), 12 deletions(-)
c480ed
c480ed
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c480ed
index a5076cb554..d4d02d8f5b 100644
c480ed
--- a/src/util/vircgroup.c
c480ed
+++ b/src/util/vircgroup.c
c480ed
@@ -3465,18 +3465,7 @@ virCgroupSupportsCpuBW(virCgroupPtr cgroup)
c480ed
 int
c480ed
 virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller)
c480ed
 {
c480ed
-    int ret = -1;
c480ed
-    VIR_AUTOFREE(char *) content = NULL;
c480ed
-
c480ed
-    if (!cgroup)
c480ed
-        return -1;
c480ed
-
c480ed
-    ret = virCgroupGetValueStr(cgroup, controller, "tasks", &content);
c480ed
-
c480ed
-    if (ret == 0 && content[0] == '\0')
c480ed
-        ret = 1;
c480ed
-
c480ed
-    return ret;
c480ed
+    return cgroup->backend->hasEmptyTasks(cgroup, controller);
c480ed
 }
c480ed
 
c480ed
 bool
c480ed
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c480ed
index bff1f8938e..3e0f6d01f4 100644
c480ed
--- a/src/util/vircgroupbackend.h
c480ed
+++ b/src/util/vircgroupbackend.h
c480ed
@@ -122,6 +122,10 @@ typedef int
c480ed
                       pid_t pid,
c480ed
                       unsigned int flags);
c480ed
 
c480ed
+typedef int
c480ed
+(*virCgroupHasEmptyTasksCB)(virCgroupPtr cgroup,
c480ed
+                            int controller);
c480ed
+
c480ed
 struct _virCgroupBackend {
c480ed
     virCgroupBackendType type;
c480ed
 
c480ed
@@ -141,6 +145,7 @@ struct _virCgroupBackend {
c480ed
     virCgroupMakeGroupCB makeGroup;
c480ed
     virCgroupRemoveCB remove;
c480ed
     virCgroupAddTaskCB addTask;
c480ed
+    virCgroupHasEmptyTasksCB hasEmptyTasks;
c480ed
 };
c480ed
 typedef struct _virCgroupBackend virCgroupBackend;
c480ed
 typedef virCgroupBackend *virCgroupBackendPtr;
c480ed
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
c480ed
index fda2c43eef..b057cdfd9e 100644
c480ed
--- a/src/util/vircgroupv1.c
c480ed
+++ b/src/util/vircgroupv1.c
c480ed
@@ -736,6 +736,25 @@ virCgroupV1AddTask(virCgroupPtr group,
c480ed
 }
c480ed
 
c480ed
 
c480ed
+static int
c480ed
+virCgroupV1HasEmptyTasks(virCgroupPtr cgroup,
c480ed
+                         int controller)
c480ed
+{
c480ed
+    int ret = -1;
c480ed
+    VIR_AUTOFREE(char *) content = NULL;
c480ed
+
c480ed
+    if (!cgroup)
c480ed
+        return -1;
c480ed
+
c480ed
+    ret = virCgroupGetValueStr(cgroup, controller, "tasks", &content);
c480ed
+
c480ed
+    if (ret == 0 && content[0] == '\0')
c480ed
+        ret = 1;
c480ed
+
c480ed
+    return ret;
c480ed
+}
c480ed
+
c480ed
+
c480ed
 virCgroupBackend virCgroupV1Backend = {
c480ed
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
c480ed
 
c480ed
@@ -754,6 +773,7 @@ virCgroupBackend virCgroupV1Backend = {
c480ed
     .makeGroup = virCgroupV1MakeGroup,
c480ed
     .remove = virCgroupV1Remove,
c480ed
     .addTask = virCgroupV1AddTask,
c480ed
+    .hasEmptyTasks = virCgroupV1HasEmptyTasks,
c480ed
 };
c480ed
 
c480ed
 
c480ed
-- 
c480ed
2.22.0
c480ed