]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
vbox: Interfaces for register per parties
authorTaowei <uaedante@gmail.com>
Thu, 2 Oct 2014 03:30:25 +0000 (11:30 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 3 Oct 2014 08:43:03 +0000 (10:43 +0200)
The patch dbb4cbf532fa by Michal has splited the vbox driver into
three parties. This modification brings a more suitable interface
to the previous patch.

The new function vboxGetDriver is introduced to get the
corresponding vbox domain driver directly thought the vbox version.

Functions like vboxGetNetworkDriver and vboxGetStorageDriver
will be introduced after rewriting it's drivers.

This patch, by the way, fixed the align problem for vbox in
Makefile.am

src/Makefile.am
src/vbox/vbox_common.c
src/vbox/vbox_driver.c
src/vbox/vbox_get_driver.h [new file with mode: 0644]
src/vbox/vbox_install_api.h [deleted file]

index e65177f1bde5b01a304b157cc17e8882a34cdc48..dcd2ae237e37caa43ca000304174405e74adacdb 100644 (file)
@@ -666,7 +666,7 @@ VMWARE_DRIVER_SOURCES =                                             \
 VBOX_DRIVER_SOURCES =                                          \
        vbox/vbox_glue.c vbox/vbox_glue.h                       \
        vbox/vbox_driver.c vbox/vbox_driver.h                   \
-       vbox/vbox_snapshot_conf.c vbox/vbox_snapshot_conf.h \
+       vbox/vbox_snapshot_conf.c vbox/vbox_snapshot_conf.h     \
        vbox/vbox_V2_2.c vbox/vbox_CAPI_v2_2.h                  \
        vbox/vbox_V3_0.c vbox/vbox_CAPI_v3_0.h                  \
        vbox/vbox_V3_1.c vbox/vbox_CAPI_v3_1.h                  \
@@ -674,12 +674,12 @@ VBOX_DRIVER_SOURCES =                                             \
        vbox/vbox_V4_0.c vbox/vbox_CAPI_v4_0.h                  \
        vbox/vbox_V4_1.c vbox/vbox_CAPI_v4_1.h                  \
        vbox/vbox_V4_2.c vbox/vbox_CAPI_v4_2.h                  \
-       vbox/vbox_V4_2_20.c vbox/vbox_CAPI_v4_2_20.h                    \
+       vbox/vbox_V4_2_20.c vbox/vbox_CAPI_v4_2_20.h            \
        vbox/vbox_V4_3.c vbox/vbox_CAPI_v4_3.h                  \
        vbox/vbox_V4_3_4.c vbox/vbox_CAPI_v4_3_4.h              \
        vbox/vbox_common.c vbox/vbox_common.h                   \
        vbox/vbox_uniformed_api.h                               \
-       vbox/vbox_install_api.h
+       vbox/vbox_get_driver.h
 
 VBOX_DRIVER_EXTRA_DIST =                                       \
                vbox/vbox_tmpl.c vbox/README                    \
index 7d75478eea80c76357826b5fa1199cd30ff17028..44270ffcf988b0964aec24a8153483720d0ea946 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "vbox_common.h"
 #include "vbox_uniformed_api.h"
-#include "vbox_install_api.h"
+#include "vbox_get_driver.h"
 
 /* Common codes for vbox driver. With the definitions in vbox_common.h,
  * it treats vbox structs as a void*. Though vboxUniformedAPI
@@ -121,41 +121,6 @@ if (!data->vboxObj) {\
 /* global vbox API, used for all common codes. */
 static vboxUniformedAPI gVBoxAPI;
 
-/* update the virDriver according to the vboxUniformedAPI */
-static void updateDriver(void);
-
-int vboxRegisterUniformedAPI(uint32_t uVersion)
-{
-    /* Install gVBoxAPI according to the vbox API version.
-     * Return -1 for unsupported version.
-     */
-    if (uVersion >= 2001052 && uVersion < 2002051) {
-        vbox22InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 2002051 && uVersion < 3000051) {
-        vbox30InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 3000051 && uVersion < 3001051) {
-        vbox31InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 3001051 && uVersion < 3002051) {
-        vbox32InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 3002051 && uVersion < 4000051) {
-        vbox40InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 4000051 && uVersion < 4001051) {
-        vbox41InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 4001051 && uVersion < 4002020) {
-        vbox42InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 4002020 && uVersion < 4002051) {
-        vbox42_20InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 4002051 && uVersion < 4003004) {
-        vbox43InstallUniformedAPI(&gVBoxAPI);
-    } else if (uVersion >= 4003004 && uVersion < 4003051) {
-        vbox43_4InstallUniformedAPI(&gVBoxAPI);
-    } else {
-        return -1;
-    }
-    updateDriver();
-    return 0;
-}
-
 static int openSessionForMachine(vboxGlobalData *data, const unsigned char *dom_uuid, vboxIIDUnion *iid,
                                  IMachine **machine, bool checkflag)
 {
@@ -7565,3 +7530,35 @@ static void updateDriver(void)
     else
         vboxCommonDriver.domainScreenshot = NULL;
 }
+
+virDriverPtr vboxGetDriver(uint32_t uVersion)
+{
+    /* Install gVBoxAPI according to the vbox API version.
+     * Return -1 for unsupported version.
+     */
+    if (uVersion >= 2001052 && uVersion < 2002051) {
+        vbox22InstallUniformedAPI(&gVBoxAPI);
+    } else if (uVersion >= 2002051 && uVersion < 3000051) {
+        vbox30InstallUniformedAPI(&gVBoxAPI);
+    } else if (uVersion >= 3000051 && uVersion < 3001051) {
+        vbox31InstallUniformedAPI(&gVBoxAPI);
+    } else if (uVersion >= 3001051 && uVersion < 3002051) {
+        vbox32InstallUniformedAPI(&gVBoxAPI);
+    } else if (uVersion >= 3002051 && uVersion < 4000051) {
+        vbox40InstallUniformedAPI(&gVBoxAPI);
+    } else if (uVersion >= 4000051 && uVersion < 4001051) {
+        vbox41InstallUniformedAPI(&gVBoxAPI);
+    } else if (uVersion >= 4001051 && uVersion < 4002020) {
+        vbox42InstallUniformedAPI(&gVBoxAPI);
+    } else if (uVersion >= 4002020 && uVersion < 4002051) {
+        vbox42_20InstallUniformedAPI(&gVBoxAPI);
+    } else if (uVersion >= 4002051 && uVersion < 4003004) {
+        vbox43InstallUniformedAPI(&gVBoxAPI);
+    } else if (uVersion >= 4003004 && uVersion < 4003051) {
+        vbox43_4InstallUniformedAPI(&gVBoxAPI);
+    } else {
+        return NULL;
+    }
+    updateDriver();
+    return &vboxCommonDriver;
+}
index d33f78f2b8030226c88301c93736b7268782d201..89d49bedef4f809a29ef98e235d23407f85147b4 100644 (file)
@@ -42,7 +42,7 @@
 #include "domain_event.h"
 #include "domain_conf.h"
 
-#include "vbox_install_api.h"
+#include "vbox_get_driver.h"
 
 #define VIR_FROM_THIS VIR_FROM_VBOX
 
@@ -69,18 +69,14 @@ extern virStorageDriver vbox43StorageDriver;
 extern virNetworkDriver vbox43_4NetworkDriver;
 extern virStorageDriver vbox43_4StorageDriver;
 
-extern virDriver vboxCommonDriver;
-
-static virDriver vboxDriverDummy;
-
 #define VIR_FROM_THIS VIR_FROM_VBOX
 
+#if !defined(WITH_DRIVER_MODULES) || defined(VBOX_NETWORK_DRIVER) || defined(VBOX_STORAGE_DRIVER)
 static void
 vboxGetDrivers(virDriverPtr *driver_ret,
                virNetworkDriverPtr *networkDriver_ret,
                virStorageDriverPtr *storageDriver_ret)
 {
-    virDriverPtr driver;
     virNetworkDriverPtr networkDriver;
     virStorageDriverPtr storageDriver;
     uint32_t uVersion;
@@ -91,7 +87,6 @@ vboxGetDrivers(virDriverPtr *driver_ret,
      * if the user requests a vbox:// URI which we know will
      * never work
      */
-    driver        = &vboxDriverDummy;
     networkDriver = &vbox22NetworkDriver;
     storageDriver = &vbox22StorageDriver;
 
@@ -150,24 +145,18 @@ vboxGetDrivers(virDriverPtr *driver_ret,
         } else {
             VIR_DEBUG("Unsupported VirtualBox API version: %u", uVersion);
         }
-        /* Register vboxUniformedAPI. */
-        if (vboxRegisterUniformedAPI(uVersion) == 0)
-            /* Only if successfully register the uniformed api,
-             * can we use the vboxCommonDriver. Or use the
-             * vboxDriverDummy in case of failure. */
-            driver = &vboxCommonDriver;
     } else {
         VIR_DEBUG("VBoxCGlueInit failed, using dummy driver");
     }
 
     if (driver_ret)
-        *driver_ret = driver;
+        *driver_ret = NULL;
     if (networkDriver_ret)
         *networkDriver_ret = networkDriver;
     if (storageDriver_ret)
         *storageDriver_ret = storageDriver;
 }
-
+#endif
 
 #if !defined(WITH_DRIVER_MODULES) || defined(VBOX_NETWORK_DRIVER)
 int vboxNetworkRegister(void)
@@ -195,18 +184,6 @@ int vboxStorageRegister(void)
 #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,
                                          unsigned int flags)
@@ -252,3 +229,20 @@ static virDriver vboxDriverDummy = {
     "VBOX",
     .connectOpen = dummyConnectOpen, /* 0.6.3 */
 };
+
+int vboxRegister(void)
+{
+    virDriverPtr driver = NULL;
+    uint32_t uVersion;
+
+    if (VBoxCGlueInit(&uVersion) == 0)
+        driver = vboxGetDriver(uVersion);
+
+    if (!driver)
+        driver = &vboxDriverDummy;
+
+    if (virRegisterDriver(driver) < 0)
+        return -1;
+    return 0;
+}
+#endif
diff --git a/src/vbox/vbox_get_driver.h b/src/vbox/vbox_get_driver.h
new file mode 100644 (file)
index 0000000..cfc8b93
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2014, Taowei Luo (uaedante@gmail.com)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library.  If not, see
+ * <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef VBOX_GET_DRIVER_H
+# define VBOX_GET_DRIVER_H
+
+# include "internal.h"
+
+virDriverPtr vboxGetDriver(uint32_t uVersion);
+
+#endif /* VBOX_GET_DRIVER_H */
diff --git a/src/vbox/vbox_install_api.h b/src/vbox/vbox_install_api.h
deleted file mode 100644 (file)
index 45a8d8c..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2014, Taowei Luo (uaedante@gmail.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library.  If not, see
- * <http://www.gnu.org/licenses/>.
- */
-
-#ifndef VBOX_INSTALL_API_H
-# define VBOX_INSTALL_API_H
-
-# include "internal.h"
-
-int vboxRegisterUniformedAPI(uint32_t uVersion);
-
-#endif /* VBOX_INSTALL_API_H */