]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Introduce a more convenient virCgroupNewDetectMachine
authorDaniel P. Berrange <berrange@redhat.com>
Wed, 24 Jul 2013 16:36:42 +0000 (17:36 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Thu, 25 Jul 2013 18:47:30 +0000 (19:47 +0100)
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@redhat.com>
src/libvirt_private.syms
src/lxc/lxc_process.c
src/qemu/qemu_cgroup.c
src/util/vircgroup.c
src/util/vircgroup.h

index d5ec1466469cd4f0a3dd9fd663802c521bda4946..b076e60c65887f32ac8bb054cdd9ec12a0abd610 100644 (file)
@@ -1192,6 +1192,7 @@ virCgroupKillPainfully;
 virCgroupKillRecursive;
 virCgroupMoveTask;
 virCgroupNewDetect;
+virCgroupNewDetectMachine;
 virCgroupNewDomainPartition;
 virCgroupNewEmulator;
 virCgroupNewIgnoreError;
index 06ead9fafd9dd776f32a2e0407f449f7a7f5565b..e632e1390d7c36d6046b624299e0591cd63c3bd7 100644 (file)
@@ -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;
         }
 
index bca86303233edb326ec29ed43f61b32f763e065f..07e901c34c8e8c56c117ad23c72393caf4195ffb 100644 (file)
@@ -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;
index 87325c03943eafd6e5d9ad810c47050f0baf80fc..6872ac4d12dbd83376abd949bbed8e67b9575c76 100644 (file)
@@ -1575,6 +1575,28 @@ int virCgroupNewDetect(pid_t pid ATTRIBUTE_UNUSED,
 }
 #endif
 
+/*
+ * Returns 0 on success (but @group may be NULL), -1 on fatal error
+ */
+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,
index e47367ce5d73e348508dc940b1850f920aac49e7..4f72aa8ced21743e4308bed59e3f37bbe1f90115 100644 (file)
@@ -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,