[PATCH 1/5] Introduce a more convenient virCgroupNewDetectMachine

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

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

Instead of requiring drivers to use a combination of calls
to virCgroupNewDetect and virCgroupIsValidMachine, combine
the two into virCgroupNewDetectMachine

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 src/libvirt_private.syms |  1 +
 src/lxc/lxc_process.c    | 20 ++++++++------------
 src/qemu/qemu_cgroup.c   | 16 ++++------------
 src/util/vircgroup.c     | 22 ++++++++++++++++++++++
 src/util/vircgroup.h     |  5 +++++
 5 files changed, 40 insertions(+), 24 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index d5ec146..b076e60 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1192,6 +1192,7 @@ virCgroupKillPainfully;
 virCgroupKillRecursive;
 virCgroupMoveTask;
 virCgroupNewDetect;
+virCgroupNewDetectMachine;
 virCgroupNewDomainPartition;
 virCgroupNewEmulator;
 virCgroupNewIgnoreError;
diff --git a/src/lxc/lxc_process.c b/src/lxc/lxc_process.c
index 06ead9f..e632e13 100644
--- a/src/lxc/lxc_process.c
+++ b/src/lxc/lxc_process.c
@@ -1189,16 +1189,14 @@ int virLXCProcessStart(virConnectPtr conn,
         goto cleanup;
     }
 
-    if (virCgroupNewDetect(vm->pid, &priv->cgroup) < 0)
+    if (virCgroupNewDetectMachine(vm->def->name, "lxc",
+                                  vm->pid, &priv->cgroup) < 0)
         goto error;
 
-    if (!virCgroupIsValidMachineGroup(priv->cgroup,
-                                      vm->def->name,
-                                      "lxc")) {
+    if (!priv->cgroup) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Cgroup name is not valid for machine %s"),
+                       _("No valid cgroup for machine %s"),
                        vm->def->name);
-        virCgroupFree(&priv->cgroup);
         goto error;
     }
 
@@ -1399,16 +1397,14 @@ virLXCProcessReconnectDomain(virDomainObjPtr vm,
         if (!(priv->monitor = virLXCProcessConnectMonitor(driver, vm)))
             goto error;
 
-        if (virCgroupNewDetect(vm->pid, &priv->cgroup) < 0)
+        if (virCgroupNewDetectMachine(vm->def->name, "lxc",
+                                      vm->pid, &priv->cgroup) < 0)
             goto error;
 
-        if (!virCgroupIsValidMachineGroup(priv->cgroup,
-                                          vm->def->name,
-                                          "lxc")) {
+        if (!priv->cgroup) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
-                           _("Cgroup name is not valid for machine %s"),
+                           _("No valid cgroup for machine %s"),
                            vm->def->name);
-            virCgroupFree(&priv->cgroup);
             goto error;
         }
 
diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c
index bca8630..07e901c 100644
--- a/src/qemu/qemu_cgroup.c
+++ b/src/qemu/qemu_cgroup.c
@@ -704,19 +704,11 @@ qemuConnectCgroup(virQEMUDriverPtr driver,
 
     virCgroupFree(&priv->cgroup);
 
-    if (virCgroupNewDetect(vm->pid, &priv->cgroup) < 0) {
-        if (virCgroupNewIgnoreError())
-            goto done;
+    if (virCgroupNewDetectMachine(vm->def->name,
+                                  "qemu",
+                                  vm->pid,
+                                  &priv->cgroup) < 0)
         goto cleanup;
-    }
-
-    if (!virCgroupIsValidMachineGroup(priv->cgroup,
-                                      vm->def->name,
-                                      "qemu")) {
-        VIR_DEBUG("Cgroup name is not valid for machine");
-        virCgroupFree(&priv->cgroup);
-        goto done;
-    }
 
 done:
     ret = 0;
diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index 87325c0..fe6c314 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -1575,6 +1575,28 @@ int virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED,
 }
 #endif
 
+/*
+ * Returns 0 on success, -1 on fatal error, -2 on no valid cgroup
+ */
+int virCgroupNewDetectMachine(const char *name,
+                              const char *drivername,
+                              pid_t pid,
+                              virCgroupPtr *group)
+{
+    if (virCgroupNewDetect(pid, group) < 0) {
+        if (virCgroupNewIgnoreError())
+            return 0;
+        return -1;
+    }
+
+    if (!virCgroupIsValidMachineGroup(*group, name, drivername)) {
+        virCgroupFree(group);
+        return 0;
+    }
+
+    return 0;
+}
+
 int virCgroupNewMachine(const char *name,
                         const char *drivername,
                         bool privileged ATTRIBUTE_UNUSED,
diff --git a/src/util/vircgroup.h b/src/util/vircgroup.h
index e47367c..4f72aa8 100644
--- a/src/util/vircgroup.h
+++ b/src/util/vircgroup.h
@@ -83,6 +83,11 @@ int virCgroupNewEmulator(virCgroupPtr domain,
 int virCgroupNewDetect(pid_t pid,
                        virCgroupPtr *group);
 
+int virCgroupNewDetectMachine(const char *name,
+                              const char *drivername,
+                              pid_t pid,
+                              virCgroupPtr *group);
+
 int virCgroupNewMachine(const char *name,
                         const char *drivername,
                         bool privileged,
-- 
1.8.1.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]