[PATCH v2 8/9] virStateInitialize: Propagate whether running in monolithic daemon mode to stateful driver init

Peter Krempa pkrempa at redhat.com
Fri Sep 9 11:58:18 UTC 2022


Upcoming patch which is fixing the opening of drivers in monolithic mode
needs to know whether we are inside 'libvirtd' but the code where the
decision needs to happen is not re-compiled per daemon. Thus we need to
pass this information to the stateful driver init function so that it
can be remebered.

Signed-off-by: Peter Krempa <pkrempa at redhat.com>
---
 src/bhyve/bhyve_driver.c                | 1 +
 src/ch/ch_driver.c                      | 1 +
 src/driver-state.h                      | 1 +
 src/interface/interface_backend_netcf.c | 1 +
 src/interface/interface_backend_udev.c  | 1 +
 src/libvirt.c                           | 5 ++++-
 src/libvirt_internal.h                  | 1 +
 src/libxl/libxl_driver.c                | 1 +
 src/lxc/lxc_driver.c                    | 1 +
 src/network/bridge_driver.c             | 1 +
 src/node_device/node_device_udev.c      | 1 +
 src/nwfilter/nwfilter_driver.c          | 1 +
 src/qemu/qemu_driver.c                  | 1 +
 src/remote/remote_daemon.c              | 6 ++++++
 src/remote/remote_driver.c              | 1 +
 src/secret/secret_driver.c              | 1 +
 src/storage/storage_driver.c            | 1 +
 src/vz/vz_driver.c                      | 1 +
 18 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c
index 09ba52483a..e0bf2a19a6 100644
--- a/src/bhyve/bhyve_driver.c
+++ b/src/bhyve/bhyve_driver.c
@@ -1178,6 +1178,7 @@ bhyveStateCleanup(void)
 static int
 bhyveStateInitialize(bool privileged,
                      const char *root,
+                     bool monolithic G_GNUC_UNUSED,
                      virStateInhibitCallback callback G_GNUC_UNUSED,
                      void *opaque G_GNUC_UNUSED)
 {
diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c
index c6e92efb2c..db2a66d131 100644
--- a/src/ch/ch_driver.c
+++ b/src/ch/ch_driver.c
@@ -861,6 +861,7 @@ static int chStateCleanup(void)

 static int chStateInitialize(bool privileged,
                              const char *root,
+                             bool monolithic G_GNUC_UNUSED,
                              virStateInhibitCallback callback G_GNUC_UNUSED,
                              void *opaque G_GNUC_UNUSED)
 {
diff --git a/src/driver-state.h b/src/driver-state.h
index f3a0638e90..7f8b61fa1c 100644
--- a/src/driver-state.h
+++ b/src/driver-state.h
@@ -33,6 +33,7 @@ typedef enum {
 typedef virDrvStateInitResult
 (*virDrvStateInitialize)(bool privileged,
                          const char *root,
+                         bool monolithic,
                          virStateInhibitCallback callback,
                          void *opaque);

diff --git a/src/interface/interface_backend_netcf.c b/src/interface/interface_backend_netcf.c
index 90514692e2..5964720e0f 100644
--- a/src/interface/interface_backend_netcf.c
+++ b/src/interface/interface_backend_netcf.c
@@ -89,6 +89,7 @@ virNetcfDriverStateDispose(void *obj)
 static int
 netcfStateInitialize(bool privileged,
                      const char *root,
+                     bool monolithic G_GNUC_UNUSED,
                      virStateInhibitCallback callback G_GNUC_UNUSED,
                      void *opaque G_GNUC_UNUSED)
 {
diff --git a/src/interface/interface_backend_udev.c b/src/interface/interface_backend_udev.c
index 32318d8d50..979f187d87 100644
--- a/src/interface/interface_backend_udev.c
+++ b/src/interface/interface_backend_udev.c
@@ -1110,6 +1110,7 @@ udevStateCleanup(void);
 static int
 udevStateInitialize(bool privileged,
                     const char *root,
+                    bool monolithic G_GNUC_UNUSED,
                     virStateInhibitCallback callback G_GNUC_UNUSED,
                     void *opaque G_GNUC_UNUSED)
 {
diff --git a/src/libvirt.c b/src/libvirt.c
index d5ae68d16f..1b4c90e110 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -604,6 +604,7 @@ virRegisterStateDriver(virStateDriver *driver)
  * @privileged: set to true if running with root privilege, false otherwise
  * @mandatory: set to true if all drivers must report success, not skipped
  * @root: directory to use for embedded mode
+ * @monolithic: set to true if running in monolithic mode (daemon is libvirtd)
  * @callback: callback to invoke to inhibit shutdown of the daemon
  * @opaque: data to pass to @callback
  *
@@ -633,6 +634,7 @@ int
 virStateInitialize(bool privileged,
                    bool mandatory,
                    const char *root,
+                   bool monolithic,
                    virStateInhibitCallback callback,
                    void *opaque)
 {
@@ -650,6 +652,7 @@ virStateInitialize(bool privileged,
             virStateDriverTab[i]->initialized = true;
             ret = virStateDriverTab[i]->stateInitialize(privileged,
                                                         root,
+                                                        monolithic,
                                                         callback,
                                                         opaque);
             VIR_DEBUG("State init result %d (mandatory=%d)", ret, mandatory);
@@ -1016,7 +1019,7 @@ virConnectOpenInternal(const char *name,
                 virAccessManagerSetDefault(acl);
             }

-            if (virStateInitialize(geteuid() == 0, true, root, NULL, NULL) < 0)
+            if (virStateInitialize(geteuid() == 0, true, root, false, NULL, NULL) < 0)
                 return NULL;

             embed = true;
diff --git a/src/libvirt_internal.h b/src/libvirt_internal.h
index f4e592922d..1ae3e2b2e0 100644
--- a/src/libvirt_internal.h
+++ b/src/libvirt_internal.h
@@ -32,6 +32,7 @@ typedef void (*virStateInhibitCallback)(bool inhibit,
 int virStateInitialize(bool privileged,
                        bool mandatory,
                        const char *root,
+                       bool monolithic,
                        virStateInhibitCallback inhibit,
                        void *opaque);
 int virStateShutdownPrepare(void);
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 79af2f4441..1b8b40e9e0 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -648,6 +648,7 @@ libxlAddDom0(libxlDriverPrivate *driver)
 static int
 libxlStateInitialize(bool privileged,
                      const char *root,
+                     bool monolithic G_GNUC_UNUSED,
                      virStateInhibitCallback callback,
                      void *opaque)
 {
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index f2a358805a..d66c26221c 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -1430,6 +1430,7 @@ lxcSecurityInit(virLXCDriverConfig *cfg)

 static int lxcStateInitialize(bool privileged,
                               const char *root,
+                              bool monolithic G_GNUC_UNUSED,
                               virStateInhibitCallback callback G_GNUC_UNUSED,
                               void *opaque G_GNUC_UNUSED)
 {
diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
index 7c7812e276..7c6430b4e3 100644
--- a/src/network/bridge_driver.c
+++ b/src/network/bridge_driver.c
@@ -575,6 +575,7 @@ firewalld_dbus_signal_callback(GDBusConnection *connection G_GNUC_UNUSED,
 static int
 networkStateInitialize(bool privileged,
                        const char *root,
+                       bool monolithic G_GNUC_UNUSED,
                        virStateInhibitCallback callback G_GNUC_UNUSED,
                        void *opaque G_GNUC_UNUSED)
 {
diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_device_udev.c
index a06eaade5d..07c10f0d88 100644
--- a/src/node_device/node_device_udev.c
+++ b/src/node_device/node_device_udev.c
@@ -2226,6 +2226,7 @@ mdevctlEventHandleCallback(GFileMonitor *monitor G_GNUC_UNUSED,
 static int
 nodeStateInitialize(bool privileged,
                     const char *root,
+                    bool monolithic G_GNUC_UNUSED,
                     virStateInhibitCallback callback G_GNUC_UNUSED,
                     void *opaque G_GNUC_UNUSED)
 {
diff --git a/src/nwfilter/nwfilter_driver.c b/src/nwfilter/nwfilter_driver.c
index d1bdd806fc..9cb306909c 100644
--- a/src/nwfilter/nwfilter_driver.c
+++ b/src/nwfilter/nwfilter_driver.c
@@ -211,6 +211,7 @@ nwfilterStateCleanup(void)
 static int
 nwfilterStateInitialize(bool privileged,
                         const char *root,
+                        bool monolithic G_GNUC_UNUSED,
                         virStateInhibitCallback callback G_GNUC_UNUSED,
                         void *opaque G_GNUC_UNUSED)
 {
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 6931f0670d..94b70872d4 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -549,6 +549,7 @@ qemuDomainFindMaxID(virDomainObj *vm,
 static int
 qemuStateInitialize(bool privileged,
                     const char *root,
+                    bool monolithic G_GNUC_UNUSED,
                     virStateInhibitCallback callback,
                     void *opaque)
 {
diff --git a/src/remote/remote_daemon.c b/src/remote/remote_daemon.c
index 36d95de83d..f369d09d35 100644
--- a/src/remote/remote_daemon.c
+++ b/src/remote/remote_daemon.c
@@ -591,6 +591,11 @@ static void daemonRunStateInit(void *opaque)
 #else /* ! MODULE_NAME */
     bool mandatory = false;
 #endif /* ! MODULE_NAME */
+#ifdef LIBVIRTD
+    bool monolithic = true;
+#else /* ! LIBVIRTD */
+    bool monolithic = false;
+#endif /* ! LIBVIRTD */

     virIdentitySetCurrent(sysident);

@@ -605,6 +610,7 @@ static void daemonRunStateInit(void *opaque)
     if (virStateInitialize(virNetDaemonIsPrivileged(dmn),
                            mandatory,
                            NULL,
+                           monolithic,
                            daemonInhibitCallback,
                            dmn) < 0) {
         VIR_ERROR(_("Driver state initialization failed"));
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 25c80a09c7..33cc6b1fce 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -168,6 +168,7 @@ static void make_nonnull_domain_snapshot(remote_nonnull_domain_snapshot *snapsho
 static int
 remoteStateInitialize(bool privileged G_GNUC_UNUSED,
                       const char *root G_GNUC_UNUSED,
+                      bool monolithic G_GNUC_UNUSED,
                       virStateInhibitCallback callback G_GNUC_UNUSED,
                       void *opaque G_GNUC_UNUSED)
 {
diff --git a/src/secret/secret_driver.c b/src/secret/secret_driver.c
index 080ed962a9..6328589fa4 100644
--- a/src/secret/secret_driver.c
+++ b/src/secret/secret_driver.c
@@ -462,6 +462,7 @@ secretStateCleanup(void)
 static int
 secretStateInitialize(bool privileged,
                       const char *root,
+                      bool monolithic G_GNUC_UNUSED,
                       virStateInhibitCallback callback G_GNUC_UNUSED,
                       void *opaque G_GNUC_UNUSED)
 {
diff --git a/src/storage/storage_driver.c b/src/storage/storage_driver.c
index 8dc2cfa7c9..fccf0fcf52 100644
--- a/src/storage/storage_driver.c
+++ b/src/storage/storage_driver.c
@@ -242,6 +242,7 @@ storageDriverAutostart(void)
 static int
 storageStateInitialize(bool privileged,
                        const char *root,
+                       bool monolithic G_GNUC_UNUSED,
                        virStateInhibitCallback callback G_GNUC_UNUSED,
                        void *opaque G_GNUC_UNUSED)
 {
diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 571d895167..4f5e340d53 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -4077,6 +4077,7 @@ vzStateCleanup(void)
 static int
 vzStateInitialize(bool privileged,
                   const char *root,
+                  bool monolithic G_GNUC_UNUSED,
                   virStateInhibitCallback callback G_GNUC_UNUSED,
                   void *opaque G_GNUC_UNUSED)
 {
-- 
2.37.1



More information about the libvir-list mailing list