Move code for loading information about pools to a separate
function - parallelsLoadPools.
Signed-off-by: Dmitry Guryanov <dguryanov(a)parallels.com>
---
src/parallels/parallels_storage.c | 65 ++++++++++++++++++++++---------------
1 files changed, 39 insertions(+), 26 deletions(-)
diff --git a/src/parallels/parallels_storage.c b/src/parallels/parallels_storage.c
index 112e288..0453de3 100644
--- a/src/parallels/parallels_storage.c
+++ b/src/parallels/parallels_storage.c
@@ -114,30 +114,12 @@ cleanup:
}
-static virDrvOpenStatus
-parallelsStorageOpen(virConnectPtr conn,
- virConnectAuthPtr auth ATTRIBUTE_UNUSED,
- unsigned int flags)
+static int parallelsLoadPools(virConnectPtr conn)
{
- char *base = NULL;
- virStorageDriverStatePtr storageState;
- int privileged = (geteuid() == 0);
parallelsConnPtr privconn = conn->privateData;
- virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
-
- if (STRNEQ(conn->driver->name, "Parallels"))
- return VIR_DRV_OPEN_DECLINED;
-
- if (VIR_ALLOC(storageState) < 0) {
- virReportOOMError();
- return VIR_DRV_OPEN_ERROR;
- }
-
- if (virMutexInit(&storageState->lock) < 0) {
- VIR_FREE(storageState);
- return VIR_DRV_OPEN_ERROR;
- }
- parallelsStorageLock(storageState);
+ virStorageDriverStatePtr storageState = conn->storagePrivateData;
+ int privileged = (geteuid() == 0);
+ char *base = NULL;
if (privileged) {
if ((base = strdup(SYSCONFDIR "/libvirt")) == NULL)
@@ -192,16 +174,47 @@ parallelsStorageOpen(virConnectPtr conn,
virStoragePoolObjUnlock(privconn->pools.objs[i]);
}
- parallelsStorageUnlock(storageState);
+ return 0;
+
+out_of_memory:
+ virReportOOMError();
+error:
+ VIR_FREE(base);
+ return -1;
+}
+
+static virDrvOpenStatus
+parallelsStorageOpen(virConnectPtr conn,
+ virConnectAuthPtr auth ATTRIBUTE_UNUSED,
+ unsigned int flags)
+{
+ virStorageDriverStatePtr storageState;
+ virCheckFlags(VIR_CONNECT_RO, VIR_DRV_OPEN_ERROR);
+
+ if (STRNEQ(conn->driver->name, "Parallels"))
+ return VIR_DRV_OPEN_DECLINED;
+
+ if (VIR_ALLOC(storageState) < 0) {
+ virReportOOMError();
+ return VIR_DRV_OPEN_ERROR;
+ }
+
+ if (virMutexInit(&storageState->lock) < 0) {
+ VIR_FREE(storageState);
+ return VIR_DRV_OPEN_ERROR;
+ }
conn->storagePrivateData = storageState;
+ parallelsStorageLock(storageState);
+
+ if (parallelsLoadPools(conn))
+ goto error;
+
+ parallelsStorageUnlock(storageState);
return VIR_DRV_OPEN_SUCCESS;
-out_of_memory:
- virReportOOMError();
error:
- VIR_FREE(base);
parallelsStorageUnlock(storageState);
parallelsStorageClose(conn);
return -1;
--
1.7.1