]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
vircgroup: extract virCgroupV1(Set|Get)BlkioWeight
authorPavel Hrdina <phrdina@redhat.com>
Fri, 17 Aug 2018 13:28:50 +0000 (15:28 +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 f6115a67a9c35d34a142a13dec529433413bd8ff..a1fc252d04dab212d52fac1de5b49bbfb88a1318 100644 (file)
@@ -1506,10 +1506,7 @@ virCgroupGetBlkioIoDeviceServiced(virCgroupPtr group,
 int
 virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight)
 {
-    return virCgroupSetValueU64(group,
-                                VIR_CGROUP_CONTROLLER_BLKIO,
-                                "blkio.weight",
-                                weight);
+    VIR_CGROUP_BACKEND_CALL(group, setBlkioWeight, -1, weight);
 }
 
 
@@ -1524,14 +1521,7 @@ virCgroupSetBlkioWeight(virCgroupPtr group, unsigned int weight)
 int
 virCgroupGetBlkioWeight(virCgroupPtr group, unsigned int *weight)
 {
-    unsigned long long tmp;
-    int ret;
-    ret = virCgroupGetValueU64(group,
-                               VIR_CGROUP_CONTROLLER_BLKIO,
-                               "blkio.weight", &tmp);
-    if (ret == 0)
-        *weight = tmp;
-    return ret;
+    VIR_CGROUP_BACKEND_CALL(group, getBlkioWeight, -1, weight);
 }
 
 /**
index 74af796c2fecf2e17772bd57d8634dde8b162fbe..ccce65f1e26a1789457a64504b5e761c13fde502 100644 (file)
@@ -137,6 +137,14 @@ typedef int
                        gid_t gid,
                        int controllers);
 
+typedef int
+(*virCgroupSetBlkioWeightCB)(virCgroupPtr group,
+                             unsigned int weight);
+
+typedef int
+(*virCgroupGetBlkioWeightCB)(virCgroupPtr group,
+                             unsigned int *weight);
+
 struct _virCgroupBackend {
     virCgroupBackendType type;
 
@@ -159,6 +167,10 @@ struct _virCgroupBackend {
     virCgroupHasEmptyTasksCB hasEmptyTasks;
     virCgroupBindMountCB bindMount;
     virCgroupSetOwnerCB setOwner;
+
+    /* Optional cgroup controller specific callbacks. */
+    virCgroupSetBlkioWeightCB setBlkioWeight;
+    virCgroupGetBlkioWeightCB getBlkioWeight;
 };
 typedef struct _virCgroupBackend virCgroupBackend;
 typedef virCgroupBackend *virCgroupBackendPtr;
@@ -169,4 +181,12 @@ virCgroupBackendRegister(virCgroupBackendPtr backend);
 virCgroupBackendPtr *
 virCgroupBackendGetAll(void);
 
+# define VIR_CGROUP_BACKEND_CALL(group, func, ret, ...) \
+    if (!group->backend->func) { \
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, \
+                       _("operation '%s' not supported"), #func); \
+        return ret; \
+    } \
+    return group->backend->func(group, ##__VA_ARGS__);
+
 #endif /* __VIR_CGROUP_BACKEND_H__ */
index 003da71ceed5f66aecbd98ac18acf4c9bb6cbd8f..862c009ccd4c38f2b938ae1b2937f6e95a5ad7ce 100644 (file)
@@ -928,6 +928,32 @@ virCgroupV1SetOwner(virCgroupPtr cgroup,
 }
 
 
+static int
+virCgroupV1SetBlkioWeight(virCgroupPtr group,
+                          unsigned int weight)
+{
+    return virCgroupSetValueU64(group,
+                                VIR_CGROUP_CONTROLLER_BLKIO,
+                                "blkio.weight",
+                                weight);
+}
+
+
+static int
+virCgroupV1GetBlkioWeight(virCgroupPtr group,
+                          unsigned int *weight)
+{
+    unsigned long long tmp;
+    int ret;
+    ret = virCgroupGetValueU64(group,
+                               VIR_CGROUP_CONTROLLER_BLKIO,
+                               "blkio.weight", &tmp);
+    if (ret == 0)
+        *weight = tmp;
+    return ret;
+}
+
+
 virCgroupBackend virCgroupV1Backend = {
     .type = VIR_CGROUP_BACKEND_TYPE_V1,
 
@@ -949,6 +975,9 @@ virCgroupBackend virCgroupV1Backend = {
     .hasEmptyTasks = virCgroupV1HasEmptyTasks,
     .bindMount = virCgroupV1BindMount,
     .setOwner = virCgroupV1SetOwner,
+
+    .setBlkioWeight = virCgroupV1SetBlkioWeight,
+    .getBlkioWeight = virCgroupV1GetBlkioWeight,
 };