c313de
From 4cf3b3d335b83b5feb49e71775b6a8f1fddbbce9 Mon Sep 17 00:00:00 2001
c313de
Message-Id: <4cf3b3d335b83b5feb49e71775b6a8f1fddbbce9@dist-git>
c313de
From: Pavel Hrdina <phrdina@redhat.com>
c313de
Date: Mon, 1 Jul 2019 17:06:55 +0200
c313de
Subject: [PATCH] vircgroup: extract virCgroupV1(Allow|Deny)AllDevices
c313de
MIME-Version: 1.0
c313de
Content-Type: text/plain; charset=UTF-8
c313de
Content-Transfer-Encoding: 8bit
c313de
c313de
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c313de
(cherry picked from commit fd9a0368b91c425f860115c0451067ee917574d1)
c313de
c313de
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1689297
c313de
c313de
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
c313de
Message-Id: <cec0c47305736e9da14175d4002509b5583e4ab0.1561993100.git.phrdina@redhat.com>
c313de
Reviewed-by: Ján Tomko <jtomko@redhat.com>
c313de
---
c313de
 src/util/vircgroup.c        | 18 ++----------------
c313de
 src/util/vircgroupbackend.h |  9 +++++++++
c313de
 src/util/vircgroupv1.c      | 31 +++++++++++++++++++++++++++++++
c313de
 3 files changed, 42 insertions(+), 16 deletions(-)
c313de
c313de
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
c313de
index a30fc6241d..67c68f3dc6 100644
c313de
--- a/src/util/vircgroup.c
c313de
+++ b/src/util/vircgroup.c
c313de
@@ -1822,10 +1822,7 @@ virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus)
c313de
 int
c313de
 virCgroupDenyAllDevices(virCgroupPtr group)
c313de
 {
c313de
-    return virCgroupSetValueStr(group,
c313de
-                                VIR_CGROUP_CONTROLLER_DEVICES,
c313de
-                                "devices.deny",
c313de
-                                "a");
c313de
+    VIR_CGROUP_BACKEND_CALL(group, denyAllDevices, -1);
c313de
 }
c313de
 
c313de
 /**
c313de
@@ -1845,18 +1842,7 @@ virCgroupDenyAllDevices(virCgroupPtr group)
c313de
 int
c313de
 virCgroupAllowAllDevices(virCgroupPtr group, int perms)
c313de
 {
c313de
-    int ret = -1;
c313de
-
c313de
-    if (virCgroupAllowDevice(group, 'b', -1, -1, perms) < 0)
c313de
-        goto cleanup;
c313de
-
c313de
-    if (virCgroupAllowDevice(group, 'c', -1, -1, perms) < 0)
c313de
-        goto cleanup;
c313de
-
c313de
-    ret = 0;
c313de
-
c313de
- cleanup:
c313de
-    return ret;
c313de
+    VIR_CGROUP_BACKEND_CALL(group, allowAllDevices, -1, perms);
c313de
 }
c313de
 
c313de
 
c313de
diff --git a/src/util/vircgroupbackend.h b/src/util/vircgroupbackend.h
c313de
index 04897b5895..436c83f6fa 100644
c313de
--- a/src/util/vircgroupbackend.h
c313de
+++ b/src/util/vircgroupbackend.h
c313de
@@ -269,6 +269,13 @@ typedef int
c313de
                          int minor,
c313de
                          int perms);
c313de
 
c313de
+typedef int
c313de
+(*virCgroupAllowAllDevicesCB)(virCgroupPtr group,
c313de
+                              int perms);
c313de
+
c313de
+typedef int
c313de
+(*virCgroupDenyAllDevicesCB)(virCgroupPtr group);
c313de
+
c313de
 struct _virCgroupBackend {
c313de
     virCgroupBackendType type;
c313de
 
c313de
@@ -321,6 +328,8 @@ struct _virCgroupBackend {
c313de
 
c313de
     virCgroupAllowDeviceCB allowDevice;
c313de
     virCgroupDenyDeviceCB denyDevice;
c313de
+    virCgroupAllowAllDevicesCB allowAllDevices;
c313de
+    virCgroupDenyAllDevicesCB denyAllDevices;
c313de
 };
c313de
 typedef struct _virCgroupBackend virCgroupBackend;
c313de
 typedef virCgroupBackend *virCgroupBackendPtr;
c313de
diff --git a/src/util/vircgroupv1.c b/src/util/vircgroupv1.c
c313de
index 02cd7ab956..34393812d2 100644
c313de
--- a/src/util/vircgroupv1.c
c313de
+++ b/src/util/vircgroupv1.c
c313de
@@ -1737,6 +1737,35 @@ virCgroupV1DenyDevice(virCgroupPtr group,
c313de
 }
c313de
 
c313de
 
c313de
+static int
c313de
+virCgroupV1AllowAllDevices(virCgroupPtr group,
c313de
+                           int perms)
c313de
+{
c313de
+    int ret = -1;
c313de
+
c313de
+    if (virCgroupV1AllowDevice(group, 'b', -1, -1, perms) < 0)
c313de
+        goto cleanup;
c313de
+
c313de
+    if (virCgroupV1AllowDevice(group, 'c', -1, -1, perms) < 0)
c313de
+        goto cleanup;
c313de
+
c313de
+    ret = 0;
c313de
+
c313de
+ cleanup:
c313de
+    return ret;
c313de
+}
c313de
+
c313de
+
c313de
+static int
c313de
+virCgroupV1DenyAllDevices(virCgroupPtr group)
c313de
+{
c313de
+    return virCgroupSetValueStr(group,
c313de
+                                VIR_CGROUP_CONTROLLER_DEVICES,
c313de
+                                "devices.deny",
c313de
+                                "a");
c313de
+}
c313de
+
c313de
+
c313de
 virCgroupBackend virCgroupV1Backend = {
c313de
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
c313de
 
c313de
@@ -1787,6 +1816,8 @@ virCgroupBackend virCgroupV1Backend = {
c313de
 
c313de
     .allowDevice = virCgroupV1AllowDevice,
c313de
     .denyDevice = virCgroupV1DenyDevice,
c313de
+    .allowAllDevices = virCgroupV1AllowAllDevices,
c313de
+    .denyAllDevices = virCgroupV1DenyAllDevices,
c313de
 };
c313de
 
c313de
 
c313de
-- 
c313de
2.22.0
c313de