[libvirt] [PATCH] build: Don't use code with dbus_message_unref when built without dbus

Martin Kletzander mkletzan at redhat.com
Mon Apr 14 14:43:09 UTC 2014


In order to do that, virNodeSuspendSupportsTargetPMUtils() and
virSystemdPMSupportTarget() are created even when pm-utils and dbus
are compiled out, respectively, but in that case returning -2 meaning
"unavailable" (this return code was already used for unavailability
before).  Error is reported in virNodeSuspendSupportsTarget() only if
both functions returned -2, otherwise the error (or success) is properly
propagated up the stack.

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---

Notes:
    v1: https://www.redhat.com/archives/libvir-list/2014-April/msg00550.html
    
    This is a build-breaker if building --without-dbus due to
    dbus_message_unref being called unconditionally.  However, I'm not
    pushing it as such.
    
    I haven't followed the suggestion of return codes -1, 0 and 1 because
    there is already a -2 used for unavailability and these return codes
    are used in other parts of the code for similar reasons as well
    (e.g. storage driver).

 src/util/virnodesuspend.c | 22 ++++++++++++++++++----
 src/util/virsystemd.c     | 11 ++++++++++-
 2 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/src/util/virnodesuspend.c b/src/util/virnodesuspend.c
index 59b84ef..60b86ee 100644
--- a/src/util/virnodesuspend.c
+++ b/src/util/virnodesuspend.c
@@ -1,6 +1,7 @@
 /*
  * virnodesuspend.c: Support for suspending a node (host machine)
  *
+ * Copyright (C) 2014 Red Hat, Inc.
  * Copyright (C) 2011 Srivatsa S. Bhat <srivatsa.bhat at linux.vnet.ibm.com>
  *
  * This library is free software; you can redistribute it and/or
@@ -267,7 +268,14 @@ virNodeSuspendSupportsTargetPMUtils(unsigned int target, bool *supported)
     virCommandFree(cmd);
     return ret;
 }
-#endif
+#else /* ! WITH_PM_UTILS */
+static int
+virNodeSuspendSupportsTargetPMUtils(unsigned int target ATTRIBUTE_UNUSED,
+                                    bool *supported ATTRIBUTE_UNUSED)
+{
+    return -2;
+}
+#endif /* ! WITH_PM_UTILS */

 static int
 virNodeSuspendSupportsTargetSystemd(unsigned int target, bool *supported)
@@ -313,10 +321,16 @@ virNodeSuspendSupportsTarget(unsigned int target, bool *supported)
     int ret;

     ret = virNodeSuspendSupportsTargetSystemd(target, supported);
-#ifdef WITH_PM_UTILS
-    if (ret < 0)
+
+    /* If just unavailable, try other options */
+    if (ret == -2)
         ret = virNodeSuspendSupportsTargetPMUtils(target, supported);
-#endif
+
+    /* If still unavailable, then report error */
+    if (ret == -2) {
+        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                       _("Cannot probe for supported suspend types"));
+    }

     return ret;
 }
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index e9ca564..e67956f 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -1,7 +1,7 @@
 /*
  * virsystemd.c: helpers for using systemd APIs
  *
- * Copyright (C) 2013 Red Hat, Inc.
+ * Copyright (C) 2013, 2014 Red Hat, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -326,6 +326,7 @@ virSystemdNotifyStartup(void)
 #endif
 }

+#ifdef WITH_SYSTEMD_DAEMON
 static int
 virSystemdPMSupportTarget(const char *methodName, bool *result)
 {
@@ -369,6 +370,14 @@ virSystemdPMSupportTarget(const char *methodName, bool *result)

     return ret;
 }
+#else /* ! WITH_SYSTEMD_DAEMON */
+static int
+virSystemdPMSupportTarget(const char *methodName ATTRIBUTE_UNUSED,
+                          bool *result ATTRIBUTE_UNUSED)
+{
+    return -2;
+}
+#endif /* ! WITH_SYSTEMD_DAEMON */

 int virSystemdCanSuspend(bool *result)
 {
-- 
1.9.2




More information about the libvir-list mailing list