]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vircgroup: extract virCgroupV1(Set|Get)BlkioDeviceWeight
authorPavel Hrdina <phrdina@redhat.com>
Mon, 24 Sep 2018 10:20:19 +0000 (12:20 +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/vircgrouppriv.h
src/util/vircgroupv1.c

index a4816d699b43985bf0202b076a1be291aae5e0a2..206b5f330a7894d51de53dea5bda87319b05b7e1 100644 (file)
@@ -494,7 +494,7 @@ virCgroupGetValueStr(virCgroupPtr group,
 }
 
 
-static int
+int
 virCgroupGetValueForBlkDev(virCgroupPtr group,
                            int controller,
                            const char *key,
@@ -1497,19 +1497,7 @@ virCgroupSetBlkioDeviceWeight(virCgroupPtr group,
                               const char *path,
                               unsigned int weight)
 {
-    VIR_AUTOFREE(char *) str = NULL;
-    VIR_AUTOFREE(char *) blkstr = NULL;
-
-    if (!(blkstr = virCgroupGetBlockDevString(path)))
-        return -1;
-
-    if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
-        return -1;
-
-    return virCgroupSetValueStr(group,
-                                VIR_CGROUP_CONTROLLER_BLKIO,
-                                "blkio.weight_device",
-                                str);
+    VIR_CGROUP_BACKEND_CALL(group, setBlkioDeviceWeight, -1, path, weight);
 }
 
 /**
@@ -1661,25 +1649,7 @@ virCgroupGetBlkioDeviceWeight(virCgroupPtr group,
                               const char *path,
                               unsigned int *weight)
 {
-    VIR_AUTOFREE(char *) str = NULL;
-
-    if (virCgroupGetValueForBlkDev(group,
-                                   VIR_CGROUP_CONTROLLER_BLKIO,
-                                   "blkio.weight_device",
-                                   path,
-                                   &str) < 0)
-        return -1;
-
-    if (!str) {
-        *weight = 0;
-    } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Unable to parse '%s' as an integer"),
-                       str);
-        return -1;
-    }
-
-    return 0;
+    VIR_CGROUP_BACKEND_CALL(group, getBlkioDeviceWeight, -1, path, weight);
 }
 
 
index e16d631a0f7175f82465aca3bff44f68f32afd78..aef2a87c6106e9ac6da280fff2343ffcef6f2c57 100644 (file)
@@ -160,6 +160,16 @@ typedef int
                                        long long *requests_read,
                                        long long *requests_write);
 
+typedef int
+(*virCgroupSetBlkioDeviceWeightCB)(virCgroupPtr group,
+                                   const char *path,
+                                   unsigned int weight);
+
+typedef int
+(*virCgroupGetBlkioDeviceWeightCB)(virCgroupPtr group,
+                                   const char *path,
+                                   unsigned int *weight);
+
 struct _virCgroupBackend {
     virCgroupBackendType type;
 
@@ -188,6 +198,8 @@ struct _virCgroupBackend {
     virCgroupGetBlkioWeightCB getBlkioWeight;
     virCgroupGetBlkioIoServicedCB getBlkioIoServiced;
     virCgroupGetBlkioIoDeviceServicedCB getBlkioIoDeviceServiced;
+    virCgroupSetBlkioDeviceWeightCB setBlkioDeviceWeight;
+    virCgroupGetBlkioDeviceWeightCB getBlkioDeviceWeight;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
index 525c288a9a7087cf245e8154937c9360df25a091..3a968c1ce21699adc7a9850ba1bba9a46b6b9d1e 100644 (file)
@@ -82,6 +82,12 @@ int virCgroupPartitionEscape(char **path);
 
 char *virCgroupGetBlockDevString(const char *path);
 
+int virCgroupGetValueForBlkDev(virCgroupPtr group,
+                               int controller,
+                               const char *key,
+                               const char *path,
+                               char **value);
+
 int virCgroupNewPartition(const char *path,
                           bool create,
                           int controllers,
index 0d876c8f76c381e562c3a69016e31b117bf07965..691270bec39a831317dd58a0824d9eb87b6a0e6b 100644 (file)
@@ -1137,6 +1137,54 @@ virCgroupV1GetBlkioIoDeviceServiced(virCgroupPtr group,
 }
 
 
+static int
+virCgroupV1SetBlkioDeviceWeight(virCgroupPtr group,
+                                const char *path,
+                                unsigned int weight)
+{
+    VIR_AUTOFREE(char *) str = NULL;
+    VIR_AUTOFREE(char *) blkstr = NULL;
+
+    if (!(blkstr = virCgroupGetBlockDevString(path)))
+        return -1;
+
+    if (virAsprintf(&str, "%s%d", blkstr, weight) < 0)
+        return -1;
+
+    return virCgroupSetValueStr(group,
+                                VIR_CGROUP_CONTROLLER_BLKIO,
+                                "blkio.weight_device",
+                                str);
+}
+
+
+static int
+virCgroupV1GetBlkioDeviceWeight(virCgroupPtr group,
+                                const char *path,
+                                unsigned int *weight)
+{
+    VIR_AUTOFREE(char *) str = NULL;
+
+    if (virCgroupGetValueForBlkDev(group,
+                                   VIR_CGROUP_CONTROLLER_BLKIO,
+                                   "blkio.weight_device",
+                                   path,
+                                   &str) < 0)
+        return -1;
+
+    if (!str) {
+        *weight = 0;
+    } else if (virStrToLong_ui(str, NULL, 10, weight) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Unable to parse '%s' as an integer"),
+                       str);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 virCgroupBackend virCgroupV1Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
 
@@ -1163,6 +1211,8 @@ virCgroupBackend virCgroupV1Backend = {
     .getBlkioWeight = virCgroupV1GetBlkioWeight,
     .getBlkioIoServiced = virCgroupV1GetBlkioIoServiced,
     .getBlkioIoDeviceServiced = virCgroupV1GetBlkioIoDeviceServiced,
+    .setBlkioDeviceWeight = virCgroupV1SetBlkioDeviceWeight,
+    .getBlkioDeviceWeight = virCgroupV1GetBlkioDeviceWeight,
 };