[PATCH 05/19] vbox: Rewrite vboxStoragePoolNumOfVolumes

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

 



We use typedef IMedium IHardDisk to make IHardDisk hierachy from
IMedium (Actually it did on vbox 2.2 and 3.0's C++ API).
So when calling
    VBOX_MEDIUM_FUNC_ARG*(IHardDisk, func, args)
we can directly replace it to
    gVBoxAPI.UIMedium.func(IHardDisk, args)

When dealing with this two types, we get some rules from it's
hierachy relationship.

When using IHardDisk and IMedium as input, we can't transfer a
IMedium to IHardDisk. Like:
    gVBoxAPI.UIHardDisk.func(IHardDisk *hardDisk, args)
    Here, we can't put a *IMedium as a argument.

When using IHardDisk and IMedium as output, we can't transfer a
IHardDisk to IMedium. Like:
    gVBoxAPI.UIMachine.GetMedium(IMedium **out)
    Here, we can't put a **IHardDisk as a argument. If this case
    do happen, we either change the API to GetHardDisk or write a
    new one.
---
 po/POTFILES.in                |    1 +
 src/vbox/vbox_common.h        |   12 +++++++++++
 src/vbox/vbox_storage.c       |   43 ++++++++++++++++++++++++++++++++++++++
 src/vbox/vbox_tmpl.c          |   46 +++++++++++------------------------------
 src/vbox/vbox_uniformed_api.h |    3 +++
 5 files changed, 71 insertions(+), 34 deletions(-)

diff --git a/po/POTFILES.in b/po/POTFILES.in
index 59be2e6..a785a5d 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -222,6 +222,7 @@ src/vbox/vbox_XPCOMCGlue.c
 src/vbox/vbox_driver.c
 src/vbox/vbox_common.c
 src/vbox/vbox_network.c
+src/vbox/vbox_storage.c
 src/vbox/vbox_snapshot_conf.c
 src/vbox/vbox_tmpl.c
 src/vmware/vmware_conf.c
diff --git a/src/vbox/vbox_common.h b/src/vbox/vbox_common.h
index 98317b2..9af3129 100644
--- a/src/vbox/vbox_common.h
+++ b/src/vbox/vbox_common.h
@@ -279,6 +279,17 @@ enum HostNetworkInterfaceType
     HostNetworkInterfaceType_HostOnly = 2
 };
 
+enum MediaState
+{
+    MediaState_NotCreated = 0,
+    MediaState_Created = 1,
+    MediaState_LockedRead = 2,
+    MediaState_LockedWrite = 3,
+    MediaState_Inaccessible = 4,
+    MediaState_Creating = 5,
+    MediaState_Deleting = 6
+};
+
 # define VBOX_E_OBJECT_NOT_FOUND 0x80BB0001
 # define VBOX_E_INVALID_VM_STATE 0x80BB0002
 # define VBOX_E_VM_ERROR 0x80BB0003
@@ -319,6 +330,7 @@ typedef nsISupports IDisplay;
 typedef nsISupports IHost;
 typedef nsISupports IHostNetworkInterface;
 typedef nsISupports IDHCPServer;
+typedef IMedium IHardDisk;
 
 /* Macros for all vbox drivers. */
 
diff --git a/src/vbox/vbox_storage.c b/src/vbox/vbox_storage.c
index 8fa7782..804f723 100644
--- a/src/vbox/vbox_storage.c
+++ b/src/vbox/vbox_storage.c
@@ -34,6 +34,8 @@
 
 VIR_LOG_INIT("vbox.vbox_storage");
 
+static vboxUniformedAPI gVBoxAPI;
+
 /**
  * The Storage Functions here on
  */
@@ -104,3 +106,44 @@ virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn, const char *na
 
     return ret;
 }
+
+int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool)
+{
+    vboxGlobalData *data = pool->conn->privateData;
+    vboxArray hardDisks = VBOX_ARRAY_INITIALIZER;
+    PRUint32 hardDiskAccessible = 0;
+    nsresult rc;
+    size_t i;
+    int ret = -1;
+
+    if (!data->vboxObj) {
+        return ret;
+    }
+
+    rc = gVBoxAPI.UArray.vboxArrayGet(&hardDisks, data->vboxObj,
+                                      gVBoxAPI.UArray.handleGetHardDisks(data->vboxObj));
+    if (NS_FAILED(rc)) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("could not get number of volumes in the pool: %s, rc=%08x"),
+                       pool->name, (unsigned)rc);
+        return ret;
+    }
+
+    for (i = 0; i < hardDisks.count; ++i) {
+        IHardDisk *hardDisk = hardDisks.items[i];
+        PRUint32 hddstate;
+
+        if (!hardDisk)
+            continue;
+
+        gVBoxAPI.UIMedium.GetState(hardDisk, &hddstate);
+        if (hddstate != MediaState_Inaccessible)
+            hardDiskAccessible++;
+    }
+
+    gVBoxAPI.UArray.vboxArrayRelease(&hardDisks);
+
+    ret = hardDiskAccessible;
+
+    return ret;
+}
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index c952331..c78cd44 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -2033,40 +2033,6 @@ _registerDomainEvent(virHypervisorDriverPtr driver)
  * The Storage Functions here on
  */
 
-static int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool)
-{
-    VBOX_OBJECT_CHECK(pool->conn, int, -1);
-    vboxArray hardDisks = VBOX_ARRAY_INITIALIZER;
-    PRUint32 hardDiskAccessible = 0;
-    nsresult rc;
-    size_t i;
-
-    rc = vboxArrayGet(&hardDisks, data->vboxObj, data->vboxObj->vtbl->GetHardDisks);
-    if (NS_SUCCEEDED(rc)) {
-        for (i = 0; i < hardDisks.count; ++i) {
-            IHardDisk *hardDisk = hardDisks.items[i];
-            if (hardDisk) {
-                PRUint32 hddstate;
-
-                VBOX_MEDIUM_FUNC_ARG1(hardDisk, GetState, &hddstate);
-                if (hddstate != MediaState_Inaccessible)
-                    hardDiskAccessible++;
-            }
-        }
-
-        vboxArrayRelease(&hardDisks);
-
-        ret = hardDiskAccessible;
-    } else {
-        ret = -1;
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("could not get number of volumes in the pool: %s, rc=%08x"),
-                       pool->name, (unsigned)rc);
-    }
-
-    return ret;
-}
-
 static int vboxStoragePoolListVolumes(virStoragePoolPtr pool, char **const names, int nnames) {
     VBOX_OBJECT_CHECK(pool->conn, int, -1);
     vboxArray hardDisks = VBOX_ARRAY_INITIALIZER;
@@ -3579,6 +3545,11 @@ static void* _handleGetMachines(IVirtualBox *vboxObj)
     return vboxObj->vtbl->GetMachines;
 }
 
+static void* _handleGetHardDisks(IVirtualBox *vboxObj)
+{
+    return vboxObj->vtbl->GetHardDisks;
+}
+
 static void* _handleUSBGetDeviceFilters(IUSBCommon *USBCommon)
 {
     return USBCommon->vtbl->GetDeviceFilters;
@@ -4928,6 +4899,11 @@ static nsresult _mediumGetLocation(IMedium *medium, PRUnichar **location)
     return medium->vtbl->GetLocation(medium, location);
 }
 
+static nsresult _mediumGetState(IMedium *medium, PRUint32 *state)
+{
+    return medium->vtbl->GetState(medium, state);
+}
+
 static nsresult _mediumGetReadOnly(IMedium *medium ATTRIBUTE_UNUSED,
                                    PRBool *readOnly ATTRIBUTE_UNUSED)
 {
@@ -5446,6 +5422,7 @@ static vboxUniformedArray _UArray = {
     .vboxArrayGetWithIIDArg = _vboxArrayGetWithIIDArg,
     .vboxArrayRelease = vboxArrayRelease,
     .handleGetMachines = _handleGetMachines,
+    .handleGetHardDisks = _handleGetHardDisks,
     .handleUSBGetDeviceFilters = _handleUSBGetDeviceFilters,
     .handleMachineGetMediumAttachments = _handleMachineGetMediumAttachments,
     .handleMachineGetSharedFolders = _handleMachineGetSharedFolders,
@@ -5648,6 +5625,7 @@ static vboxUniformedIUSBDeviceFilter _UIUSBDeviceFilter = {
 static vboxUniformedIMedium _UIMedium = {
     .GetId = _mediumGetId,
     .GetLocation = _mediumGetLocation,
+    .GetState = _mediumGetState,
     .GetReadOnly = _mediumGetReadOnly,
     .GetParent = _mediumGetParent,
     .GetChildren = _mediumGetChildren,
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index 352d170..4c17051 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -170,6 +170,7 @@ typedef struct {
     void (*vboxArrayRelease)(vboxArray *array);
     /* Generate function pointers for vboxArrayGet */
     void* (*handleGetMachines)(IVirtualBox *vboxObj);
+    void* (*handleGetHardDisks)(IVirtualBox *vboxObj);
     void* (*handleUSBGetDeviceFilters)(IUSBCommon *USBCommon);
     void* (*handleMachineGetMediumAttachments)(IMachine *machine);
     void* (*handleMachineGetSharedFolders)(IMachine *machine);
@@ -407,6 +408,7 @@ typedef struct {
 typedef struct {
     nsresult (*GetId)(IMedium *medium, vboxIIDUnion *iidu);
     nsresult (*GetLocation)(IMedium *medium, PRUnichar **location);
+    nsresult (*GetState)(IMedium *medium, PRUint32 *state);
     nsresult (*GetReadOnly)(IMedium *medium, PRBool *readOnly);
     nsresult (*GetParent)(IMedium *medium, IMedium **parent);
     nsresult (*GetChildren)(IMedium *medium, PRUint32 *childrenSize, IMedium ***children);
@@ -592,6 +594,7 @@ int vboxStorageClose(virConnectPtr conn);
 int vboxConnectNumOfStoragePools(virConnectPtr conn);
 int vboxConnectListStoragePools(virConnectPtr conn, char **const names, int nnames);
 virStoragePoolPtr vboxStoragePoolLookupByName(virConnectPtr conn, const char *name);
+int vboxStoragePoolNumOfVolumes(virStoragePoolPtr pool);
 
 /* 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]