[libvirt] [PATCH v2 1/5] cgroup macros refactoring

Roman Bogorodskiy bogorodskiy at gmail.com
Sun Aug 11 12:04:25 UTC 2013


- Introduce VIR_CGROUP_SUPPORTED conditional
- Convert virCgroupKill* to use it
- Convert virCgroupIsolateMount() to use it
---
 src/util/vircgroup.c | 59 ++++++++++++++++++++++++++++------------------------
 1 file changed, 32 insertions(+), 27 deletions(-)

diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c
index cfb4b3f..5f656b1 100644
--- a/src/util/vircgroup.c
+++ b/src/util/vircgroup.c
@@ -56,6 +56,11 @@
 
 #define VIR_FROM_THIS VIR_FROM_CGROUP
 
+#if defined(__linux__) && defined(HAVE_GETMNTENT_R) \
+ && defined(_DIRENT_HAVE_D_TYPE)
+# define VIR_CGROUP_SUPPORTED
+#endif
+
 VIR_ENUM_IMPL(virCgroupController, VIR_CGROUP_CONTROLLER_LAST,
               "cpu", "cpuacct", "cpuset", "memory", "devices",
               "freezer", "blkio", "net_cls", "perf_event",
@@ -2682,7 +2687,7 @@ int virCgroupGetFreezerState(virCgroupPtr group, char **state)
 }
 
 
-#if defined HAVE_KILL && defined HAVE_MNTENT_H && defined HAVE_GETMNTENT_R
+#ifdef VIR_CGROUP_SUPPORTED
 /*
  * Returns 1 if some PIDs are killed, 0 if none are killed, or -1 on error
  */
@@ -2866,6 +2871,7 @@ cleanup:
     return ret;
 }
 
+
 int virCgroupKillRecursive(virCgroupPtr group, int signum)
 {
     int ret;
@@ -2911,31 +2917,7 @@ int virCgroupKillPainfully(virCgroupPtr group)
     return ret;
 }
 
-#else /* !(HAVE_KILL, HAVE_MNTENT_H, HAVE_GETMNTENT_R) */
-int virCgroupKill(virCgroupPtr group ATTRIBUTE_UNUSED,
-                  int signum ATTRIBUTE_UNUSED)
-{
-    virReportSystemError(ENOSYS, "%s",
-                         _("Control groups not supported on this platform"));
-    return -1;
-}
-int virCgroupKillRecursive(virCgroupPtr group ATTRIBUTE_UNUSED,
-                           int signum ATTRIBUTE_UNUSED)
-{
-    virReportSystemError(ENOSYS, "%s",
-                         _("Control groups not supported on this platform"));
-    return -1;
-}
 
-int virCgroupKillPainfully(virCgroupPtr group ATTRIBUTE_UNUSED)
-{
-    virReportSystemError(ENOSYS, "%s",
-                         _("Control groups not supported on this platform"));
-    return -1;
-}
-#endif /* HAVE_KILL, HAVE_MNTENT_H, HAVE_GETMNTENT_R */
-
-#ifdef __linux__
 static char *virCgroupIdentifyRoot(virCgroupPtr group)
 {
     char *ret = NULL;
@@ -3048,7 +3030,30 @@ cleanup:
     VIR_FREE(opts);
     return ret;
 }
-#else /* __linux__ */
+#else /* VIR_CGROUP_SUPPORTED */
+int virCgroupKill(virCgroupPtr group ATTRIBUTE_UNUSED,
+                  int signum ATTRIBUTE_UNUSED)
+{
+    virReportSystemError(ENOSYS, "%s",
+                         _("Control groups not supported on this platform"));
+    return -1;
+}
+
+int virCgroupKillRecursive(virCgroupPtr group ATTRIBUTE_UNUSED,
+                           int signum ATTRIBUTE_UNUSED)
+{
+    virReportSystemError(ENOSYS, "%s",
+                         _("Control groups not supported on this platform"));
+    return -1;
+}
+
+int virCgroupKillPainfully(virCgroupPtr group ATTRIBUTE_UNUSED)
+{
+    virReportSystemError(ENOSYS, "%s",
+                         _("Control groups not supported on this platform"));
+    return -1;
+}
+
 int virCgroupIsolateMount(virCgroupPtr group ATTRIBUTE_UNUSED,
                           const char *oldroot ATTRIBUTE_UNUSED,
                           const char *mountopts ATTRIBUTE_UNUSED)
@@ -3057,4 +3062,4 @@ int virCgroupIsolateMount(virCgroupPtr group ATTRIBUTE_UNUSED,
                          _("Control groups not supported on this platform"));
     return -1;
 }
-#endif /* __linux__ */
+#endif /* VIR_CGROUP_SUPPORTED */
-- 
1.8.2.3




More information about the libvir-list mailing list