[PATCH] qemu: Fix improper logic of qemuCgroupSetup

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

 



It throws errors as long as the cgroup controller is not available,
regardless of whether we really want to use it to do setup or not,
which is not what we want, fixing it with throwing error when need
to use the controller.

And change "VIR_WARN" to "qemuReportError" for memory controller
incidentally.

---
 src/qemu/qemu_cgroup.c |   78 +++++++++++++++++++++++++----------------------
 1 files changed, 41 insertions(+), 37 deletions(-)

diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index 8cf45da..7e88a67 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -294,8 +294,8 @@ int qemuSetupCgroup(struct qemud_driver *driver,
         }
     }

-    if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) {
-        if (vm->def->blkio.weight != 0) {
+    if (vm->def->blkio.weight != 0) {
+        if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_BLKIO)) {
             rc = virCgroupSetBlkioWeight(cgroup, vm->def->blkio.weight);
             if(rc != 0) {
                 virReportSystemError(-rc,
@@ -303,48 +303,52 @@ int qemuSetupCgroup(struct qemud_driver *driver,
                                      vm->def->name);
                 goto cleanup;
             }
+        } else {
+            qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                            _("Block I/O tuning is not available on this host"));
         }
-    } else {
-        qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                        _("Block I/O tuning is not available on this host"));
     }

-    if ((rc = qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_MEMORY))) {
-        if (vm->def->mem.hard_limit != 0) {
-            rc = virCgroupSetMemoryHardLimit(cgroup, vm->def->mem.hard_limit);
-            if (rc != 0) {
-                virReportSystemError(-rc,
-                                     _("Unable to set memory hard limit for domain %s"),
-                                     vm->def->name);
-                goto cleanup;
+    if (vm->def->mem.hard_limit != 0 ||
+        vm->def->mem.soft_limit != 0 ||
+        vm->def->mem.swap_hard_limit != 0) {
+        if ((rc = qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_MEMORY))) {
+            if (vm->def->mem.hard_limit != 0) {
+                rc = virCgroupSetMemoryHardLimit(cgroup, vm->def->mem.hard_limit);
+                if (rc != 0) {
+                    virReportSystemError(-rc,
+                                         _("Unable to set memory hard limit for domain %s"),
+                                         vm->def->name);
+                    goto cleanup;
+                }
             }
-        }
-        if (vm->def->mem.soft_limit != 0) {
-            rc = virCgroupSetMemorySoftLimit(cgroup, vm->def->mem.soft_limit);
-            if (rc != 0) {
-                virReportSystemError(-rc,
-                                     _("Unable to set memory soft limit for domain %s"),
-                                     vm->def->name);
-                goto cleanup;
+            if (vm->def->mem.soft_limit != 0) {
+                rc = virCgroupSetMemorySoftLimit(cgroup, vm->def->mem.soft_limit);
+                if (rc != 0) {
+                    virReportSystemError(-rc,
+                                         _("Unable to set memory soft limit for domain %s"),
+                                         vm->def->name);
+                    goto cleanup;
+                }
             }
-        }

-        if (vm->def->mem.swap_hard_limit != 0) {
-            rc = virCgroupSetMemSwapHardLimit(cgroup, vm->def->mem.swap_hard_limit);
-            if (rc != 0) {
-                virReportSystemError(-rc,
-                                     _("Unable to set swap hard limit for domain %s"),
-                                     vm->def->name);
-                goto cleanup;
+            if (vm->def->mem.swap_hard_limit != 0) {
+                rc = virCgroupSetMemSwapHardLimit(cgroup, vm->def->mem.swap_hard_limit);
+                if (rc != 0) {
+                    virReportSystemError(-rc,
+                                         _("Unable to set swap hard limit for domain %s"),
+                                         vm->def->name);
+                    goto cleanup;
+                }
             }
+        } else {
+            qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                            _("Memory tuning is not available on this host"));
         }
-    } else {
-        VIR_WARN("Memory cgroup is disabled in qemu configuration file: %s",
-                 vm->def->name);
     }

-    if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
-        if (vm->def->cputune.shares != 0) {
+    if (vm->def->cputune.shares != 0) {
+        if (qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
             rc = virCgroupSetCpuShares(cgroup, vm->def->cputune.shares);
             if(rc != 0) {
                 virReportSystemError(-rc,
@@ -352,10 +356,10 @@ int qemuSetupCgroup(struct qemud_driver *driver,
                                      vm->def->name);
                 goto cleanup;
             }
+        } else {
+            qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                            _("CPU tuning is not available on this host"));
         }
-    } else {
-        qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                        _("CPU tuning is not available on this host"));
     }

 done:
--
1.7.4

--
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]