[PATCH 18/20] vbox: Rewrite vboxStorageVolGetPath

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

 



---
 src/vbox/vbox_common.c        |   50 +++++++++++++++++++++++++++++++++
 src/vbox/vbox_tmpl.c          |   61 -----------------------------------------
 src/vbox/vbox_uniformed_api.h |    1 +
 3 files changed, 51 insertions(+), 61 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 8f981f3..e32bee5 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -9049,6 +9049,56 @@ char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags)
     return ret;
 }
 
+char *vboxStorageVolGetPath(virStorageVolPtr vol)
+{
+    VBOX_OBJECT_CHECK(vol->conn, char *, NULL);
+    IHardDisk *hardDisk  = NULL;
+    PRUnichar *hddLocationUtf16 = NULL;
+    char      *hddLocationUtf8  = NULL;
+    unsigned char uuid[VIR_UUID_BUFLEN];
+    vboxIIDUnion hddIID;
+    PRUint32 hddstate;
+    nsresult rc;
+
+    if (virUUIDParse(vol->key, uuid) < 0) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("Could not parse UUID from '%s'"), vol->key);
+        return ret;
+    }
+
+    VBOX_IID_INITIALIZE(&hddIID);
+    vboxIIDFromUUID(&hddIID, uuid);
+    rc = gVBoxAPI.UIVirtualBox.GetHardDiskByIID(data->vboxObj, &hddIID, &hardDisk);
+    if (NS_FAILED(rc))
+        goto cleanup;
+
+    gVBoxAPI.UIMedium.GetState(hardDisk, &hddstate);
+    if (hddstate == MediaState_Inaccessible)
+        goto cleanup;
+
+    gVBoxAPI.UIMedium.GetLocation(hardDisk, &hddLocationUtf16);
+    if (!hddLocationUtf16)
+        goto cleanup;
+
+    VBOX_UTF16_TO_UTF8(hddLocationUtf16, &hddLocationUtf8);
+    if (!hddLocationUtf8)
+        goto cleanup;
+
+    ignore_value(VIR_STRDUP(ret, hddLocationUtf8));
+
+    VIR_DEBUG("Storage Volume Name: %s", vol->name);
+    VIR_DEBUG("Storage Volume Path: %s", hddLocationUtf8);
+    VIR_DEBUG("Storage Volume Pool: %s", vol->pool);
+
+    VBOX_UTF8_FREE(hddLocationUtf8);
+
+ cleanup:
+    VBOX_UTF16_FREE(hddLocationUtf16);
+    VBOX_MEDIUM_RELEASE(hardDisk);
+    vboxIIDUnalloc(&hddIID);
+    return ret;
+}
+
 /**
  * Function Tables
  */
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 9ce1ddb..73a72c7 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -2017,67 +2017,6 @@ _registerDomainEvent(virDriverPtr driver)
 
 #endif /* !(VBOX_API_VERSION == 2002000 || VBOX_API_VERSION >= 4000000) */
 
-/**
- * The Storage Functions here on
- */
-
-static char *vboxStorageVolGetPath(virStorageVolPtr vol) {
-    VBOX_OBJECT_CHECK(vol->conn, char *, NULL);
-    IHardDisk *hardDisk  = NULL;
-    unsigned char uuid[VIR_UUID_BUFLEN];
-    vboxIID hddIID = VBOX_IID_INITIALIZER;
-    nsresult rc;
-
-    if (virUUIDParse(vol->key, uuid) < 0) {
-        virReportError(VIR_ERR_INVALID_ARG,
-                       _("Could not parse UUID from '%s'"), vol->key);
-        return ret;
-    }
-
-    vboxIIDFromUUID(&hddIID, uuid);
-#if VBOX_API_VERSION < 4000000
-    rc = data->vboxObj->vtbl->GetHardDisk(data->vboxObj, hddIID.value, &hardDisk);
-#elif VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000
-    rc = data->vboxObj->vtbl->FindMedium(data->vboxObj, hddIID.value,
-                                         DeviceType_HardDisk, &hardDisk);
-#else
-    rc = data->vboxObj->vtbl->OpenMedium(data->vboxObj, hddIID.value,
-                                         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 *hddLocationUtf16 = NULL;
-            char      *hddLocationUtf8  = NULL;
-
-            VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetLocation, &hddLocationUtf16);
-
-            VBOX_UTF16_TO_UTF8(hddLocationUtf16, &hddLocationUtf8);
-            if (hddLocationUtf8) {
-
-                ignore_value(VIR_STRDUP(ret, hddLocationUtf8));
-
-                VIR_DEBUG("Storage Volume Name: %s", vol->name);
-                VIR_DEBUG("Storage Volume Path: %s", hddLocationUtf8);
-                VIR_DEBUG("Storage Volume Pool: %s", vol->pool);
-
-                VBOX_UTF8_FREE(hddLocationUtf8);
-            }
-
-            VBOX_UTF16_FREE(hddLocationUtf16);
-        }
-
-        VBOX_MEDIUM_RELEASE(hardDisk);
-    }
-
-    vboxIIDUnalloc(&hddIID);
-
-    return ret;
-}
-
 static int _pfnInitialize(vboxGlobalData *data)
 {
     data->pFuncs = g_pfnGetFunctions(VBOX_XPCOMC_VERSION);
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 46c64e7..5ec0dee 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -624,6 +624,7 @@ virStorageVolPtr vboxStorageVolCreateXML(virStoragePoolPtr pool,
 int vboxStorageVolDelete(virStorageVolPtr vol, unsigned int flags);
 int vboxStorageVolGetInfo(virStorageVolPtr vol, virStorageVolInfoPtr info);
 char *vboxStorageVolGetXMLDesc(virStorageVolPtr vol, unsigned int flags);
+char *vboxStorageVolGetPath(virStorageVolPtr vol);
 
 /* Version specified functions for installing uniformed API */
 void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
-- 
1.7.9.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]