From dbb4cbf532fa02a5e0ef359edace1eb559510e4e Mon Sep 17 00:00:00 2001 From: Michal Privoznik Date: Fri, 22 Aug 2014 11:37:52 +0200 Subject: [PATCH] vbox: Register per partes Since times when vbox moved to the daemon (due to some licensing issue) the subdrivers that vbox implements were registered, but not opened since our generic subdrivers took priority. I've tried to fix this in 65b7d553f39ff9 but it was not correct. Apparently moving vbox driver registration upfront changes the default connection URI which makes some users sad. So, this commit breaks vbox into pieces and register vbox's network and storage drivers first, and vbox driver then at the end. This way, the vbox driver is registered in the order it always was, but its subdrivers are registered prior the generic ones. Signed-off-by: Michal Privoznik Signed-off-by: Martin Kletzander --- daemon/libvirtd.c | 16 ++++++++++-- libvirt.spec.in | 2 ++ src/Makefile.am | 41 ++++++++++++++++++++++++++++--- src/vbox/vbox_driver.c | 56 ++++++++++++++++++++++++++++++++++++------ src/vbox/vbox_driver.h | 10 ++++++++ 5 files changed, 112 insertions(+), 13 deletions(-) diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 87af9038f9..0503cd025d 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -383,7 +383,7 @@ static void daemonInitialize(void) * is not loaded they'll get a suitable error at that point */ # ifdef WITH_VBOX - virDriverLoadModule("vbox"); + virDriverLoadModule("vbox_network"); # endif # ifdef WITH_NETWORK virDriverLoadModule("network"); @@ -391,6 +391,9 @@ static void daemonInitialize(void) # ifdef WITH_INTERFACE virDriverLoadModule("interface"); # endif +# ifdef WITH_VBOX + virDriverLoadModule("vbox_storage"); +# endif # ifdef WITH_STORAGE virDriverLoadModule("storage"); # endif @@ -418,12 +421,15 @@ static void daemonInitialize(void) # ifdef WITH_UML virDriverLoadModule("uml"); # endif +# ifdef WITH_VBOX + virDriverLoadModule("vbox"); +# endif # ifdef WITH_BHYVE virDriverLoadModule("bhyve"); # endif #else # ifdef WITH_VBOX - vboxRegister(); + vboxNetworkRegister(); # endif # ifdef WITH_NETWORK networkRegister(); @@ -431,6 +437,9 @@ static void daemonInitialize(void) # ifdef WITH_INTERFACE interfaceRegister(); # endif +# ifdef WITH_VBOX + vboxStorageRegister(); +# endif # ifdef WITH_STORAGE storageRegister(); # endif @@ -458,6 +467,9 @@ static void daemonInitialize(void) # ifdef WITH_UML umlRegister(); # endif +# ifdef WITH_VBOX + vboxRegister(); +# endif # ifdef WITH_BHYVE bhyveRegister(); # endif diff --git a/libvirt.spec.in b/libvirt.spec.in index 9126277bc6..b7a26a1e74 100644 --- a/libvirt.spec.in +++ b/libvirt.spec.in @@ -2094,6 +2094,8 @@ exit 0 %files daemon-driver-vbox %defattr(-, root, root) %{_libdir}/%{name}/connection-driver/libvirt_driver_vbox.so +%{_libdir}/%{name}/connection-driver/libvirt_driver_vbox_network.so +%{_libdir}/%{name}/connection-driver/libvirt_driver_vbox_storage.so %endif %endif # %{with_driver_modules} diff --git a/src/Makefile.am b/src/Makefile.am index 538530e31a..46e411e1fd 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1135,13 +1135,27 @@ libvirt_driver_vmware_la_SOURCES = $(VMWARE_DRIVER_SOURCES) endif WITH_VMWARE if WITH_VBOX -noinst_LTLIBRARIES += libvirt_driver_vbox_impl.la +noinst_LTLIBRARIES += \ + libvirt_driver_vbox_impl.la \ + libvirt_driver_vbox_network_impl.la \ + libvirt_driver_vbox_storage_impl.la libvirt_driver_vbox_la_SOURCES = libvirt_driver_vbox_la_LIBADD = libvirt_driver_vbox_impl.la +libvirt_driver_vbox_network_la_SOURCES = +libvirt_driver_vbox_network_la_LIBADD = libvirt_driver_vbox_network_impl.la +libvirt_driver_vbox_storage_la_SOURCES = +libvirt_driver_vbox_storage_la_LIBADD = libvirt_driver_vbox_storage_impl.la if WITH_DRIVER_MODULES -mod_LTLIBRARIES += libvirt_driver_vbox.la +mod_LTLIBRARIES += \ + libvirt_driver_vbox.la \ + libvirt_driver_vbox_network.la \ + libvirt_driver_vbox_storage.la libvirt_driver_vbox_la_LIBADD += ../gnulib/lib/libgnu.la libvirt_driver_vbox_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS) +libvirt_driver_vbox_network_la_LIBADD += ../gnulib/lib/libgnu.la +libvirt_driver_vbox_network_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS) +libvirt_driver_vbox_storage_la_LIBADD += ../gnulib/lib/libgnu.la +libvirt_driver_vbox_storage_la_LDFLAGS = -module -avoid-version $(AM_LDFLAGS) else ! WITH_DRIVER_MODULES noinst_LTLIBRARIES += libvirt_driver_vbox.la # GPLv2-only license requries that it be linked into @@ -1151,12 +1165,33 @@ endif ! WITH_DRIVER_MODULES libvirt_driver_vbox_impl_la_CFLAGS = \ -I$(top_srcdir)/src/conf \ - $(AM_CFLAGS) + $(AM_CFLAGS) \ + -DVBOX_DRIVER libvirt_driver_vbox_impl_la_LDFLAGS = $(AM_LDFLAGS) libvirt_driver_vbox_impl_la_LIBADD = $(DLOPEN_LIBS) \ $(MSCOM_LIBS) \ $(LIBXML_LIBS) libvirt_driver_vbox_impl_la_SOURCES = $(VBOX_DRIVER_SOURCES) + +libvirt_driver_vbox_network_impl_la_CFLAGS = \ + -I$(top_srcdir)/src/conf \ + $(AM_CFLAGS) \ + -DVBOX_NETWORK_DRIVER +libvirt_driver_vbox_network_impl_la_LDFLAGS = $(AM_LDFLAGS) +libvirt_driver_vbox_network_impl_la_LIBADD = $(DLOPEN_LIBS) \ + $(MSCOM_LIBS) \ + $(LIBXML_LIBS) +libvirt_driver_vbox_network_impl_la_SOURCES = $(VBOX_DRIVER_SOURCES) + +libvirt_driver_vbox_storage_impl_la_CFLAGS = \ + -I$(top_srcdir)/src/conf \ + $(AM_CFLAGS) \ + -DVBOX_STORAGE_DRIVER +libvirt_driver_vbox_storage_impl_la_LDFLAGS = $(AM_LDFLAGS) +libvirt_driver_vbox_storage_impl_la_LIBADD = $(DLOPEN_LIBS) \ + $(MSCOM_LIBS) \ + $(LIBXML_LIBS) +libvirt_driver_vbox_storage_impl_la_SOURCES = $(VBOX_DRIVER_SOURCES) endif WITH_VBOX if WITH_XENAPI diff --git a/src/vbox/vbox_driver.c b/src/vbox/vbox_driver.c index 498be71530..d33f78f2b8 100644 --- a/src/vbox/vbox_driver.c +++ b/src/vbox/vbox_driver.c @@ -75,12 +75,15 @@ static virDriver vboxDriverDummy; #define VIR_FROM_THIS VIR_FROM_VBOX -int vboxRegister(void) +static void +vboxGetDrivers(virDriverPtr *driver_ret, + virNetworkDriverPtr *networkDriver_ret, + virStorageDriverPtr *storageDriver_ret) { - virDriverPtr driver; + virDriverPtr driver; virNetworkDriverPtr networkDriver; virStorageDriverPtr storageDriver; - uint32_t uVersion; + uint32_t uVersion; /* * If the glue layer does not initialize, we register a driver @@ -157,15 +160,52 @@ int vboxRegister(void) VIR_DEBUG("VBoxCGlueInit failed, using dummy driver"); } - if (virRegisterDriver(driver) < 0) - return -1; + if (driver_ret) + *driver_ret = driver; + if (networkDriver_ret) + *networkDriver_ret = networkDriver; + if (storageDriver_ret) + *storageDriver_ret = storageDriver; +} + + +#if !defined(WITH_DRIVER_MODULES) || defined(VBOX_NETWORK_DRIVER) +int vboxNetworkRegister(void) +{ + virNetworkDriverPtr networkDriver; + + vboxGetDrivers(NULL, &networkDriver, NULL); if (virRegisterNetworkDriver(networkDriver) < 0) return -1; - if (virRegisterStorageDriver(storageDriver) < 0) - return -1; - return 0; } +#endif + +#if !defined(WITH_DRIVER_MODULES) || defined(VBOX_STORAGE_DRIVER) +int vboxStorageRegister(void) +{ + virStorageDriverPtr storageDriver; + + vboxGetDrivers(NULL, NULL, &storageDriver); + + if (virRegisterStorageDriver(storageDriver) < 0) + return -1; + return 0; +} +#endif + +#if !defined(WITH_DRIVER_MODULES) || defined(VBOX_DRIVER) +int vboxRegister(void) +{ + virDriverPtr driver; + + vboxGetDrivers(&driver, NULL, NULL); + + if (virRegisterDriver(driver) < 0) + return -1; + return 0; +} +#endif static virDrvOpenStatus dummyConnectOpen(virConnectPtr conn, virConnectAuthPtr auth ATTRIBUTE_UNUSED, diff --git a/src/vbox/vbox_driver.h b/src/vbox/vbox_driver.h index 399e4c67f4..ccd331a410 100644 --- a/src/vbox/vbox_driver.h +++ b/src/vbox/vbox_driver.h @@ -31,6 +31,16 @@ # include "internal.h" +# if !defined(WITH_DRIVER_MODULES) || defined(VBOX_NETWORK_DRIVER) +int vboxNetworkRegister(void); +# endif + +# if !defined(WITH_DRIVER_MODULES) || defined(VBOX_STORAGE_DRIVER) +int vboxStorageRegister(void); +# endif + +# if !defined(WITH_DRIVER_MODULES) || defined(VBOX_DRIVER) int vboxRegister(void); +# endif #endif