[libvirt] [PATCHv2 2/2] cgroup: Don't fail to start a VM when DBus isn't compiled in or running

Peter Krempa pkrempa at redhat.com
Fri Aug 16 14:48:31 UTC 2013


The systemd code to create cgroups has fallback means built in, but
fails to engage them if a host isn't running DBus or libvirtd is
compiled without DBus (yes, you still don't need to run DBus).

This patch changes the return value in case DBus isn't available to so
that the fallback code can be activated and cgroups are created
manually.

Additionally, the functions no longer report errors as they were
reported over and over again and were no hard errors.
---
 daemon/libvirtd.c                 |  2 +-
 daemon/remote.c                   |  2 +-
 src/node_device/node_device_hal.c |  2 +-
 src/nwfilter/nwfilter_driver.c    |  4 ++--
 src/rpc/virnetserver.c            |  2 +-
 src/util/virdbus.c                | 15 ++++++++-------
 src/util/virdbus.h                |  2 +-
 src/util/virsystemd.c             |  4 ++--
 8 files changed, 17 insertions(+), 16 deletions(-)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index c9cd1a1..bea0190 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -921,7 +921,7 @@ static void daemonRunStateInit(void *opaque)
             dbus_connection_add_filter(sessionBus,
                                        handleSessionMessageFunc, srv, NULL);

-        systemBus = virDBusGetSystemBus();
+        systemBus = virDBusGetSystemBus(true);
         if (systemBus != NULL) {
             dbus_connection_add_filter(systemBus,
                                        handleSystemMessageFunc, srv, NULL);
diff --git a/daemon/remote.c b/daemon/remote.c
index 03d5557..d385edf 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -2874,7 +2874,7 @@ remoteDispatchAuthPolkit(virNetServerPtr server ATTRIBUTE_UNUSED,
                     (long long) callerPid, callerUid) < 0)
         goto authfail;

-    if (!(sysbus = virDBusGetSystemBus()))
+    if (!(sysbus = virDBusGetSystemBus(true)))
         goto authfail;

     VIR_INFO("Checking PID %lld running as %d",
diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_device_hal.c
index d94767c..de1b7f9 100644
--- a/src/node_device/node_device_hal.c
+++ b/src/node_device/node_device_hal.c
@@ -652,7 +652,7 @@ nodeStateInitialize(bool privileged ATTRIBUTE_UNUSED,
     }
     nodeDeviceLock(driverState);

-    if (!(sysbus = virDBusGetSystemBus())) {
+    if (!(sysbus = virDBusGetSystemBus(true))) {
         virErrorPtr verr = virGetLastError();
         VIR_ERROR(_("DBus not available, disabling HAL driver: %s"),
                     verr->message);
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index 9bb4b4e..75290a9 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -100,7 +100,7 @@ nwfilterDriverRemoveDBusMatches(void)
 {
     DBusConnection *sysbus;

-    sysbus = virDBusGetSystemBus();
+    sysbus = virDBusGetSystemBus(true);
     if (sysbus) {
         dbus_bus_remove_match(sysbus,
                               DBUS_RULE_FWD_NAMEOWNERCHANGED,
@@ -175,7 +175,7 @@ nwfilterStateInitialize(bool privileged,
     DBusConnection *sysbus = NULL;

 #if WITH_DBUS
-    sysbus = virDBusGetSystemBus();
+    sysbus = virDBusGetSystemBus(true);
 #endif /* WITH_DBUS */

     if (VIR_ALLOC(driverState) < 0)
diff --git a/src/rpc/virnetserver.c b/src/rpc/virnetserver.c
index 2306e10..98c3594 100644
--- a/src/rpc/virnetserver.c
+++ b/src/rpc/virnetserver.c
@@ -755,7 +755,7 @@ static void virNetServerCallInhibit(virNetServerPtr srv,
     VIR_DEBUG("srv=%p what=%s who=%s why=%s mode=%s",
               srv, NULLSTR(what), NULLSTR(who), NULLSTR(why), NULLSTR(mode));

-    if (!(systemBus = virDBusGetSystemBus()))
+    if (!(systemBus = virDBusGetSystemBus(true)))
         return;

     /* Only one outstanding call at a time */
diff --git a/src/util/virdbus.c b/src/util/virdbus.c
index e88dc26..8333788 100644
--- a/src/util/virdbus.c
+++ b/src/util/virdbus.c
@@ -73,7 +73,7 @@ static void virDBusSystemBusInit(void)
     systembus = virDBusBusInit(DBUS_BUS_SYSTEM, &systemdbuserr);
 }

-DBusConnection *virDBusGetSystemBus(void)
+DBusConnection *virDBusGetSystemBus(bool fatal)
 {
     if (virOnce(&systemonce, virDBusSystemBusInit) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -82,9 +82,10 @@ DBusConnection *virDBusGetSystemBus(void)
     }

     if (!systembus) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Unable to get DBus system bus connection: %s"),
-                       systemdbuserr.message ? systemdbuserr.message : "watch setup failed");
+        virReportErrorConditional(fatal, VIR_ERR_INTERNAL_ERROR,
+                                  _("Unable to get DBus system bus "
+                                    "connection: %s"),
+                                  systemdbuserr.message ? systemdbuserr.message : "watch setup failed");
         return NULL;
     }

@@ -1188,10 +1189,10 @@ int virDBusMessageRead(DBusMessage *msg,


 #else /* ! WITH_DBUS */
-DBusConnection *virDBusGetSystemBus(void)
+DBusConnection *virDBusGetSystemBus(bool fatal)
 {
-    virReportError(VIR_ERR_INTERNAL_ERROR,
-                   "%s", _("DBus support not compiled into this binary"));
+    virReportErrorConditional(fatal, VIR_ERR_INTERNAL_ERROR, "%s"
+                              _("DBus support not compiled into this binary"));
     return NULL;
 }

diff --git a/src/util/virdbus.h b/src/util/virdbus.h
index 39de479..a30dbc3 100644
--- a/src/util/virdbus.h
+++ b/src/util/virdbus.h
@@ -31,7 +31,7 @@
 # endif
 # include "internal.h"

-DBusConnection *virDBusGetSystemBus(void);
+DBusConnection *virDBusGetSystemBus(bool fatal);
 DBusConnection *virDBusGetSessionBus(void);

 int virDBusCallMethod(DBusConnection *conn,
diff --git a/src/util/virsystemd.c b/src/util/virsystemd.c
index 251b846..f81c50b 100644
--- a/src/util/virsystemd.c
+++ b/src/util/virsystemd.c
@@ -145,8 +145,8 @@ int virSystemdCreateMachine(const char *name,
     char *username = NULL;
     char *slicename = NULL;

-    if (!(conn = virDBusGetSystemBus()))
-        return -1;
+    if (!(conn = virDBusGetSystemBus(false)))
+        return -2;

     if (privileged) {
         if (virAsprintf(&machinename, "%s-%s", drivername, name) < 0)
-- 
1.8.3.2




More information about the libvir-list mailing list