This patch rewrites the following functions
*vboxStorageOpen
*vboxStorageClose
*vboxConnectNumOfStoragePools
*vboxConnectListStoragePools
*vboxStoragePoolLookupByName
These functions do not call any vbox API, so I directly move it
from vbox_tmpl.c to vbox_storage.c
A small improvement is made on vboxConnectListStoragePools.
The if condition nnames == 1 is modified to nnames > 0. So if the
caller put more than one slot to get active storage pools, the new
function will return exactly one, while the old one would only
return 0.
---
src/Makefile.am | 1 +
src/vbox/vbox_storage.c | 106 +++++++++++++++++++++++++++++++++++++++++
src/vbox/vbox_tmpl.c | 69 ---------------------------
src/vbox/vbox_uniformed_api.h | 6 +++
4 files changed, 113 insertions(+), 69 deletions(-)
create mode 100644 src/vbox/vbox_storage.c
diff --git a/src/Makefile.am b/src/Makefile.am
index 7521bde..b245dd1 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -679,6 +679,7 @@ VBOX_DRIVER_SOURCES = \
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_storage.c \
vbox/vbox_uniformed_api.h \
vbox/vbox_get_driver.h
diff --git a/src/vbox/vbox_storage.c b/src/vbox/vbox_storage.c
new file mode 100644
index 0000000..8fa7782
--- /dev/null
+++ b/src/vbox/vbox_storage.c
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2014 Taowei Luo (uaedante(a)gmail.com)
+ * Copyright (C) 2010-2014 Red Hat, Inc.
+ * Copyright (C) 2008-2009 Sun Microsystems, Inc.
+ *
+ * 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/>.
+ */
+
+#include <config.h>
+
+#include "internal.h"
+#include "datatypes.h"
+#include "domain_conf.h"
+#include "domain_event.h"
+#include "virlog.h"
+#include "virstring.h"
+
+#include "vbox_common.h"
+#include "vbox_uniformed_api.h"
+
+#define VIR_FROM_THIS VIR_FROM_VBOX
+
+VIR_LOG_INIT("vbox.vbox_storage");
+
+/**
+ * The Storage Functions here on
+ */
+
+virDrvOpenStatus vboxStorageOpen(virConnectPtr conn,
+ virConnectAuthPtr auth ATTRIBUTE_UNUSED,
+ unsigned int flags)
+{
+ vboxGlobalData *data = conn->privateData;
+
+ virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
+ if (STRNEQ(conn->driver->name, "VBOX"))
+ return VIR_DRV_OPEN_DECLINED;
+
+ if ((!data->pFuncs) || (!data->vboxObj) || (!data->vboxSession))
+ return VIR_DRV_OPEN_ERROR;
+
+ VIR_DEBUG("vbox storage initialized");
+ /* conn->storagePrivateData = some storage specific data */
+ return VIR_DRV_OPEN_SUCCESS;
+}
+
+int vboxStorageClose(virConnectPtr conn)
+{
+ VIR_DEBUG("vbox storage uninitialized");
+ conn->storagePrivateData = NULL;
+ return 0;
+}
+
+int vboxConnectNumOfStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED)
+{
+
+ /** Currently only one pool supported, the default one
+ * given by ISystemProperties::defaultHardDiskFolder()
+ */
+
+ return 1;
+}
+
+int vboxConnectListStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED,
+ char **const names, int nnames)
+{
+ int numActive = 0;
+
+ if (nnames > 0 &&
+ VIR_STRDUP(names[numActive], "default-pool") > 0)
+ numActive++;
+ return numActive;
+}
+
+virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn, const char *name)
+{
+ virStoragePoolPtr ret = NULL;
+
+ /** Current limitation of the function: since
+ * the default pool doesn't have UUID just assign
+ * one till vbox can handle pools
+ */
+ if (STREQ("default-pool", name)) {
+ unsigned char uuid[VIR_UUID_BUFLEN];
+ const char *uuidstr = "1deff1ff-1481-464f-967f-a50fe8936cc4";
+
+ ignore_value(virUUIDParse(uuidstr, uuid));
+
+ ret = virGetStoragePool(conn, name, uuid, NULL, NULL);
+ }
+
+ return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 8fa03ba..c952331 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -2033,75 +2033,6 @@ _registerDomainEvent(virHypervisorDriverPtr driver)
* The Storage Functions here on
*/
-static virDrvOpenStatus vboxStorageOpen(virConnectPtr conn,
- virConnectAuthPtr auth ATTRIBUTE_UNUSED,
- unsigned int flags)
-{
- vboxGlobalData *data = conn->privateData;
-
- virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
-
- if (STRNEQ(conn->driver->name, "VBOX"))
- return VIR_DRV_OPEN_DECLINED;
-
- if ((data->pFuncs == NULL) ||
- (data->vboxObj == NULL) ||
- (data->vboxSession == NULL))
- return VIR_DRV_OPEN_ERROR;
-
- VIR_DEBUG("vbox storage initialized");
- /* conn->storagePrivateData = some storage specific data */
- return VIR_DRV_OPEN_SUCCESS;
-}
-
-static int vboxStorageClose(virConnectPtr conn)
-{
- VIR_DEBUG("vbox storage uninitialized");
- conn->storagePrivateData = NULL;
- return 0;
-}
-
-static int vboxConnectNumOfStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED)
-{
-
- /** Currently only one pool supported, the default one
- * given by ISystemProperties::defaultHardDiskFolder()
- */
-
- return 1;
-}
-
-static int vboxConnectListStoragePools(virConnectPtr conn ATTRIBUTE_UNUSED,
- char **const names, int nnames) {
- int numActive = 0;
-
- if (nnames == 1 &&
- VIR_STRDUP(names[numActive], "default-pool") > 0)
- numActive++;
- return numActive;
-}
-
-static virStoragePoolPtr
-vboxStoragePoolLookupByName(virConnectPtr conn, const char *name)
-{
- virStoragePoolPtr ret = NULL;
-
- /** Current limitation of the function: since
- * the default pool doesn't have UUID just assign
- * one till vbox can handle pools
- */
- if (STREQ("default-pool", name)) {
- unsigned char uuid[VIR_UUID_BUFLEN];
- const char *uuidstr = "1deff1ff-1481-464f-967f-a50fe8936cc4";
-
- ignore_value(virUUIDParse(uuidstr, uuid));
-
- ret = virGetStoragePool(conn, name, uuid, NULL, NULL);
- }
-
- return ret;
-}
-
static int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool)
{
VBOX_OBJECT_CHECK(pool->conn, int, -1);
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index e1790cd..352d170 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -586,6 +586,12 @@ typedef struct {
virDomainPtr vboxDomainLookupByUUID(virConnectPtr conn,
const unsigned char *uuid);
+virDrvOpenStatus vboxStorageOpen(virConnectPtr conn, virConnectAuthPtr auth,
+ unsigned int flags);
+int vboxStorageClose(virConnectPtr conn);
+int vboxConnectNumOfStoragePools(virConnectPtr conn);
+int vboxConnectListStoragePools(virConnectPtr conn, char **const names, int nnames);
+virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn, const char *name);
/* Version specified functions for installing uniformed API */
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
--
1.7.9.5