[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 11/20] vbox: Rewrite vboxStorageVolLookupByPath



---
 src/vbox/vbox_common.c        |   72 ++++++++++++++++++++++++++++++++++++++
 src/vbox/vbox_tmpl.c          |   77 -----------------------------------------
 src/vbox/vbox_uniformed_api.h |    1 +
 3 files changed, 73 insertions(+), 77 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index a5dcf83..cfc73d8 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -8578,6 +8578,78 @@ virStorageVolPtr vboxStorageVolLookupByKey(virConnectPtr conn, const char *key)
     return ret;
 }
 
+virStorageVolPtr vboxStorageVolLookupByPath(virConnectPtr conn, const char *path)
+{
+    VBOX_OBJECT_CHECK(conn, virStorageVolPtr, NULL);
+    PRUnichar *hddPathUtf16 = NULL;
+    IHardDisk *hardDisk     = NULL;
+    PRUnichar *hddNameUtf16 = NULL;
+    char      *hddNameUtf8  = NULL;
+    unsigned char uuid[VIR_UUID_BUFLEN];
+    char key[VIR_UUID_STRING_BUFLEN] = "";
+    vboxIIDUnion hddIID;
+    PRUint32 hddstate;
+    nsresult rc;
+
+    VBOX_IID_INITIALIZE(&hddIID);
+
+    if (!path)
+        return ret;
+
+    VBOX_UTF8_TO_UTF16(path, &hddPathUtf16);
+
+    if (!hddPathUtf16)
+        return ret;
+
+    rc = gVBoxAPI.UIVirtualBox.FindHardDisk(data->vboxObj, hddPathUtf16,
+                                            DeviceType_HardDisk, AccessMode_ReadWrite, &hardDisk);
+    if (NS_FAILED(rc))
+        goto cleanup;
+
+    gVBoxAPI.UIMedium.GetState(hardDisk, &hddstate);
+    if (hddstate == MediaState_Inaccessible)
+        goto cleanup;
+
+    gVBoxAPI.UIMedium.GetName(hardDisk, &hddNameUtf16);
+
+    if (!hddNameUtf16)
+        goto cleanup;
+
+    VBOX_UTF16_TO_UTF8(hddNameUtf16, &hddNameUtf8);
+    VBOX_UTF16_FREE(hddNameUtf16);
+
+    if (!hddNameUtf8)
+        goto cleanup;
+
+    rc = gVBoxAPI.UIMedium.GetId(hardDisk, &hddIID);
+    if (NS_FAILED(rc)) {
+        VBOX_UTF8_FREE(hddNameUtf8);
+        goto cleanup;
+    }
+
+    vboxIIDToUUID(&hddIID, uuid);
+    virUUIDFormat(uuid, key);
+
+    /* TODO: currently only one default pool and thus
+     * the check below, change it when pools are supported
+     */
+    if (vboxConnectNumOfStoragePools(conn) == 1)
+        ret = virGetStorageVol(conn, "default-pool", hddNameUtf8, key,
+                               NULL, NULL);
+
+    VIR_DEBUG("Storage Volume Pool: %s", "default-pool");
+    VIR_DEBUG("Storage Volume Name: %s", hddNameUtf8);
+    VIR_DEBUG("Storage Volume key : %s", key);
+
+    vboxIIDUnalloc(&hddIID);
+    VBOX_UTF8_FREE(hddNameUtf8);
+
+ cleanup:
+    VBOX_MEDIUM_RELEASE(hardDisk);
+    VBOX_UTF16_FREE(hddPathUtf16);
+    return ret;
+}
+
 /**
  * Function Tables
  */
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 7c04ba8..03d194b 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -2022,83 +2022,6 @@ _registerDomainEvent(virDriverPtr driver)
  * The Storage Functions here on
  */
 
-static virStorageVolPtr
-vboxStorageVolLookupByPath(virConnectPtr conn, const char *path)
-{
-    VBOX_OBJECT_CHECK(conn, virStorageVolPtr, NULL);
-    PRUnichar *hddPathUtf16 = NULL;
-    IHardDisk *hardDisk     = NULL;
-    nsresult rc;
-
-    if (!path)
-        return ret;
-
-    VBOX_UTF8_TO_UTF16(path, &hddPathUtf16);
-
-    if (!hddPathUtf16)
-        return ret;
-
-#if VBOX_API_VERSION < 4000000
-    rc = data->vboxObj->vtbl->FindHardDisk(data->vboxObj, hddPathUtf16, &hardDisk);
-#elif VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000
-    rc = data->vboxObj->vtbl->FindMedium(data->vboxObj, hddPathUtf16,
-                                         DeviceType_HardDisk, &hardDisk);
-#else
-    rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj, hddPathUtf16,
-                                         DeviceType_HardDisk, AccessMode_ReadWrite,
-                                         PR_FALSE, &hardDisk);
-#endif /* VBOX_API_VERSION >= 4000000 */
-    if (NS_SUCCEEDED(rc)) {
-        PRUint32 hddstate;
-
-        VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetState, &hddstate);
-        if (hddstate != MediaState_Inaccessible) {
-            PRUnichar *hddNameUtf16 = NULL;
-            char      *hddNameUtf8  = NULL;
-
-            VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetName, &hddNameUtf16);
-
-            if (hddNameUtf16) {
-                VBOX_UTF16_TO_UTF8(hddNameUtf16, &hddNameUtf8);
-                VBOX_UTF16_FREE(hddNameUtf16);
-            }
-
-            if (hddNameUtf8) {
-                vboxIID hddIID = VBOX_IID_INITIALIZER;
-                unsigned char uuid[VIR_UUID_BUFLEN];
-                char key[VIR_UUID_STRING_BUFLEN] = "";
-
-                rc = VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetId, &hddIID.value);
-                if (NS_SUCCEEDED(rc)) {
-                    vboxIIDToUUID(&hddIID, uuid);
-                    virUUIDFormat(uuid, key);
-
-                    /* TODO: currently only one default pool and thus
-                     * the check below, change it when pools are supported
-                     */
-                    if (vboxConnectNumOfStoragePools(conn) == 1)
-                        ret = virGetStorageVol(conn, "default-pool", hddNameUtf8, key,
-                                               NULL, NULL);
-
-                    VIR_DEBUG("Storage Volume Pool: %s", "default-pool");
-                    VIR_DEBUG("Storage Volume Name: %s", hddNameUtf8);
-                    VIR_DEBUG("Storage Volume key : %s", key);
-                }
-
-                vboxIIDUnalloc(&hddIID);
-            }
-
-            VBOX_UTF8_FREE(hddNameUtf8);
-        }
-
-        VBOX_MEDIUM_RELEASE(hardDisk);
-    }
-
-    VBOX_UTF16_FREE(hddPathUtf16);
-
-    return ret;
-}
-
 static virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool,
                                                 const char *xml,
                                                 unsigned int flags)
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 2a9c3b2..4843824 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -601,6 +601,7 @@ int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool);
 int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int nnames);
 virStorageVolPtr vboxStorageVolLookupByName(virStoragePoolPtr pool, const char *name);
 virStorageVolPtr vboxStorageVolLookupByKey(virConnectPtr conn, const char *key);
+virStorageVolPtr vboxStorageVolLookupByPath(virConnectPtr conn, const char *path);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]