[PATCH 1/2] vircgroup: Add virCgroupSetupBlkiotune()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



virCgroupSetupBlkiotune() has been introduced in order to remove the
code duplication present between virLXCCgroupSetupBlkioTune() and
qemuSetupBlkioCgroup().

Signed-off-by: Fabiano Fidêncio <fabiano@xxxxxxxxxxxx>
---
 src/libvirt_private.syms |  1 +
 src/lxc/lxc_cgroup.c     | 49 +------------------------------------------
 src/qemu/qemu_cgroup.c   | 47 +----------------------------------------
 src/util/vircgroup.c     | 54 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/util/vircgroup.h     |  3 +++
 5 files changed, 60 insertions(+), 94 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 6001635916..4bec93c786 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1545,6 +1545,7 @@ virCgroupSetMemoryHardLimit;
 virCgroupSetMemorySoftLimit;
 virCgroupSetMemSwapHardLimit;
 virCgroupSetOwner;
+virCgroupSetupBlkiotune;
 virCgroupSupportsCpuBW;
 virCgroupTerminateMachine;
 
diff --git a/src/lxc/lxc_cgroup.c b/src/lxc/lxc_cgroup.c
index 8e937ec389..2158c1c12b 100644
--- a/src/lxc/lxc_cgroup.c
+++ b/src/lxc/lxc_cgroup.c
@@ -106,54 +106,7 @@ static int virLXCCgroupSetupCpusetTune(virDomainDefPtr def,
 static int virLXCCgroupSetupBlkioTune(virDomainDefPtr def,
                                       virCgroupPtr cgroup)
 {
-    size_t i;
-
-    if (def->blkio.weight &&
-        virCgroupSetBlkioWeight(cgroup, def->blkio.weight) < 0)
-        return -1;
-
-    if (def->blkio.ndevices) {
-        for (i = 0; i < def->blkio.ndevices; i++) {
-            virBlkioDevicePtr dev = &def->blkio.devices[i];
-
-            if (dev->weight &&
-                (virCgroupSetBlkioDeviceWeight(cgroup, dev->path,
-                                               dev->weight) < 0 ||
-                 virCgroupGetBlkioDeviceWeight(cgroup, dev->path,
-                                               &dev->weight) < 0))
-                return -1;
-
-            if (dev->riops &&
-                (virCgroupSetBlkioDeviceReadIops(cgroup, dev->path,
-                                                 dev->riops) < 0 ||
-                 virCgroupGetBlkioDeviceReadIops(cgroup, dev->path,
-                                                 &dev->riops) < 0))
-                return -1;
-
-            if (dev->wiops &&
-                (virCgroupSetBlkioDeviceWriteIops(cgroup, dev->path,
-                                                  dev->wiops) < 0 ||
-                 virCgroupGetBlkioDeviceWriteIops(cgroup, dev->path,
-                                                  &dev->wiops) < 0))
-                return -1;
-
-            if (dev->rbps &&
-                (virCgroupSetBlkioDeviceReadBps(cgroup, dev->path,
-                                                dev->rbps) < 0 ||
-                 virCgroupGetBlkioDeviceReadBps(cgroup, dev->path,
-                                                &dev->rbps) < 0))
-                return -1;
-
-            if (dev->wbps &&
-                (virCgroupSetBlkioDeviceWriteBps(cgroup, dev->path,
-                                                 dev->wbps) < 0 ||
-                 virCgroupGetBlkioDeviceWriteBps(cgroup, dev->path,
-                                                 &dev->wbps) < 0))
-                return -1;
-        }
-    }
-
-    return 0;
+    return virCgroupSetupBlkiotune(cgroup, &def->blkio);
 }
 
 
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 546a4c8e63..47ee23796c 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -510,7 +510,6 @@ static int
 qemuSetupBlkioCgroup(virDomainObjPtr vm)
 {
     qemuDomainObjPrivatePtr priv = vm->privateData;
-    size_t i;
 
     if (!virCgroupHasController(priv->cgroup,
                                 VIR_CGROUP_CONTROLLER_BLKIO)) {
@@ -523,51 +522,7 @@ qemuSetupBlkioCgroup(virDomainObjPtr vm)
         }
     }
 
-    if (vm->def->blkio.weight != 0 &&
-        virCgroupSetBlkioWeight(priv->cgroup, vm->def->blkio.weight) < 0)
-        return -1;
-
-    if (vm->def->blkio.ndevices) {
-        for (i = 0; i < vm->def->blkio.ndevices; i++) {
-            virBlkioDevicePtr dev = &vm->def->blkio.devices[i];
-            if (dev->weight &&
-                (virCgroupSetBlkioDeviceWeight(priv->cgroup, dev->path,
-                                               dev->weight) < 0 ||
-                 virCgroupGetBlkioDeviceWeight(priv->cgroup, dev->path,
-                                               &dev->weight) < 0))
-                return -1;
-
-            if (dev->riops &&
-                (virCgroupSetBlkioDeviceReadIops(priv->cgroup, dev->path,
-                                                 dev->riops) < 0 ||
-                 virCgroupGetBlkioDeviceReadIops(priv->cgroup, dev->path,
-                                                 &dev->riops) < 0))
-                return -1;
-
-            if (dev->wiops &&
-                (virCgroupSetBlkioDeviceWriteIops(priv->cgroup, dev->path,
-                                                  dev->wiops) < 0 ||
-                 virCgroupGetBlkioDeviceWriteIops(priv->cgroup, dev->path,
-                                                  &dev->wiops) < 0))
-                return -1;
-
-            if (dev->rbps &&
-                (virCgroupSetBlkioDeviceReadBps(priv->cgroup, dev->path,
-                                                dev->rbps) < 0 ||
-                 virCgroupGetBlkioDeviceReadBps(priv->cgroup, dev->path,
-                                                &dev->rbps) < 0))
-                return -1;
-
-            if (dev->wbps &&
-                (virCgroupSetBlkioDeviceWriteBps(priv->cgroup, dev->path,
-                                                 dev->wbps) < 0 ||
-                 virCgroupGetBlkioDeviceWriteBps(priv->cgroup, dev->path,
-                                                 &dev->wbps) < 0))
-                return -1;
-        }
-    }
-
-    return 0;
+    return virCgroupSetupBlkiotune(priv->cgroup, &vm->def->blkio);
 }
 
 
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 0a31947b0d..4e57f1322f 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -4920,3 +4920,57 @@ virCgroupDelThread(virCgroupPtr cgroup,
 
     return 0;
 }
+
+
+int
+virCgroupSetupBlkiotune(virCgroupPtr cgroup,
+                        virDomainBlkiotunePtr blkio)
+{
+    size_t i;
+
+    if (blkio->weight != 0 &&
+        virCgroupSetBlkioWeight(cgroup, blkio->weight) < 0)
+        return -1;
+
+    if (blkio->ndevices) {
+        for (i = 0; i < blkio->ndevices; i++) {
+            virBlkioDevicePtr dev = &blkio->devices[i];
+            if (dev->weight &&
+                (virCgroupSetBlkioDeviceWeight(cgroup, dev->path,
+                                               dev->weight) < 0 ||
+                 virCgroupGetBlkioDeviceWeight(cgroup, dev->path,
+                                               &dev->weight) < 0))
+                return -1;
+
+            if (dev->riops &&
+                (virCgroupSetBlkioDeviceReadIops(cgroup, dev->path,
+                                                 dev->riops) < 0 ||
+                 virCgroupGetBlkioDeviceReadIops(cgroup, dev->path,
+                                                 &dev->riops) < 0))
+                return -1;
+
+            if (dev->wiops &&
+                (virCgroupSetBlkioDeviceWriteIops(cgroup, dev->path,
+                                                  dev->wiops) < 0 ||
+                 virCgroupGetBlkioDeviceWriteIops(cgroup, dev->path,
+                                                  &dev->wiops) < 0))
+                return -1;
+
+            if (dev->rbps &&
+                (virCgroupSetBlkioDeviceReadBps(cgroup, dev->path,
+                                                dev->rbps) < 0 ||
+                 virCgroupGetBlkioDeviceReadBps(cgroup, dev->path,
+                                                &dev->rbps) < 0))
+                return -1;
+
+            if (dev->wbps &&
+                (virCgroupSetBlkioDeviceWriteBps(cgroup, dev->path,
+                                                 dev->wbps) < 0 ||
+                 virCgroupGetBlkioDeviceWriteBps(cgroup, dev->path,
+                                                 &dev->wbps) < 0))
+                return -1;
+        }
+    }
+
+    return 0;
+}
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
index d833927678..bd7e7c6d70 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -27,6 +27,7 @@
 
 # include "virutil.h"
 # include "virbitmap.h"
+# include "conf/domain_conf.h"
 
 struct virCgroup;
 typedef struct virCgroup *virCgroupPtr;
@@ -297,4 +298,6 @@ int virCgroupSetOwner(virCgroupPtr cgroup,
 int virCgroupHasEmptyTasks(virCgroupPtr cgroup, int controller);
 
 bool virCgroupControllerAvailable(int controller);
+
+int virCgroupSetupBlkiotune(virCgroupPtr cgroup, virDomainBlkiotunePtr blkio);
 #endif /* __VIR_CGROUP_H__ */
-- 
2.14.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux