]> xenbits.xensource.com Git - libvirt.git/commitdiff
vircgroup: extract virCgroupV1(Allow|Deny)AllDevices
authorPavel Hrdina <phrdina@redhat.com>
Wed, 5 Sep 2018 18:10:02 +0000 (20:10 +0200)
committerPavel Hrdina <phrdina@redhat.com>
Tue, 25 Sep 2018 11:40:22 +0000 (13:40 +0200)
Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
src/util/vircgroup.c
src/util/vircgroupbackend.h
src/util/vircgroupv1.c

index f9fa3cffe35ccbd62267edd6ade578fbc26e387d..5f161a95c6a3709d1a696b9cb570c501dda7010c 100644 (file)
@@ -1818,10 +1818,7 @@ virCgroupGetCpusetCpus(virCgroupPtr group, char **cpus)
 int
 virCgroupDenyAllDevices(virCgroupPtr group)
 {
-    return virCgroupSetValueStr(group,
-                                VIR_CGROUP_CONTROLLER_DEVICES,
-                                "devices.deny",
-                                "a");
+    VIR_CGROUP_BACKEND_CALL(group, denyAllDevices, -1);
 }
 
 /**
@@ -1841,18 +1838,7 @@ virCgroupDenyAllDevices(virCgroupPtr group)
 int
 virCgroupAllowAllDevices(virCgroupPtr group, int perms)
 {
-    int ret = -1;
-
-    if (virCgroupAllowDevice(group, 'b', -1, -1, perms) < 0)
-        goto cleanup;
-
-    if (virCgroupAllowDevice(group, 'c', -1, -1, perms) < 0)
-        goto cleanup;
-
-    ret = 0;
-
- cleanup:
-    return ret;
+    VIR_CGROUP_BACKEND_CALL(group, allowAllDevices, -1, perms);
 }
 
 
index 04897b5895495b2ed7f0e5aa27e9d2223710ee7d..436c83f6faa63e3b90e3f44ca7008fa08253b84f 100644 (file)
@@ -269,6 +269,13 @@ typedef int
                          int minor,
                          int perms);
 
+typedef int
+(*virCgroupAllowAllDevicesCB)(virCgroupPtr group,
+                              int perms);
+
+typedef int
+(*virCgroupDenyAllDevicesCB)(virCgroupPtr group);
+
 struct _virCgroupBackend {
     virCgroupBackendType type;
 
@@ -321,6 +328,8 @@ struct _virCgroupBackend {
 
     virCgroupAllowDeviceCB allowDevice;
     virCgroupDenyDeviceCB denyDevice;
+    virCgroupAllowAllDevicesCB allowAllDevices;
+    virCgroupDenyAllDevicesCB denyAllDevices;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
index 7bac2542a5d71803315706c69db20555096e2b08..1bded9208ac84fb8c8ca208425e953e0a7a5da95 100644 (file)
@@ -1736,6 +1736,35 @@ virCgroupV1DenyDevice(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV1AllowAllDevices(virCgroupPtr group,
+                           int perms)
+{
+    int ret = -1;
+
+    if (virCgroupV1AllowDevice(group, 'b', -1, -1, perms) < 0)
+        goto cleanup;
+
+    if (virCgroupV1AllowDevice(group, 'c', -1, -1, perms) < 0)
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+    return ret;
+}
+
+
+static int
+virCgroupV1DenyAllDevices(virCgroupPtr group)
+{
+    return virCgroupSetValueStr(group,
+                                VIR_CGROUP_CONTROLLER_DEVICES,
+                                "devices.deny",
+                                "a");
+}
+
+
 virCgroupBackend virCgroupV1Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
 
@@ -1786,6 +1815,8 @@ virCgroupBackend virCgroupV1Backend = {
 
     .allowDevice = virCgroupV1AllowDevice,
     .denyDevice = virCgroupV1DenyDevice,
+    .allowAllDevices = virCgroupV1AllowAllDevices,
+    .denyAllDevices = virCgroupV1DenyAllDevices,
 };