[PATCH 10/20] vbox: Make FindMedium support old vbox versions

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

 



In old version, function FindMedium in UIVirtualBox doesn't work
for vbox2.2 and 3.0. We assume it will not be used when vbox in
these versions.

But when rewriting vboxStorageVolLookupByPath, we found it was
compatibe to use FindMedium to get a IHardDisk object, even in
vbox old versions. To achieve this, first make FindMedium call
FindHardDisk when VBOX_API_VERSION < 4000000.
Then change the argument type **IMedium to **IHardDisk. (As the
rules in heriachy, we can't transfer a IHardDisk to match
IMedium in output)

In vbox 2.2 and 3.0, the caller must be aware that they will get
a IHardDisk object in return.
---
 src/vbox/vbox_common.c        |    4 ++--
 src/vbox/vbox_tmpl.c          |   29 +++++++++++++++--------------
 src/vbox/vbox_uniformed_api.h |    3 ++-
 3 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index befd192..a5dcf83 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -1138,8 +1138,8 @@ vboxAttachDrivesNew(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine
                 continue;
             }
 
-            gVBoxAPI.UIVirtualBox.FindMedium(data->vboxObj, mediumFileUtf16,
-                                             deviceType, accessMode, &medium);
+            gVBoxAPI.UIVirtualBox.FindHardDisk(data->vboxObj, mediumFileUtf16,
+                                               deviceType, accessMode, &medium);
 
             if (!medium) {
                 PRUnichar *mediumEmpty = NULL;
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index e239517..7c04ba8 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -3540,22 +3540,23 @@ _virtualboxRegisterMachine(IVirtualBox *vboxObj, IMachine *machine)
 }
 
 static nsresult
-_virtualboxFindMedium(IVirtualBox *vboxObj ATTRIBUTE_UNUSED,
-                      PRUnichar *location ATTRIBUTE_UNUSED,
-                      PRUint32 deviceType ATTRIBUTE_UNUSED,
-                      PRUint32 accessMode ATTRIBUTE_UNUSED,
-                      IMedium **medium ATTRIBUTE_UNUSED)
+_virtualboxFindHardDisk(IVirtualBox *vboxObj, PRUnichar *location,
+                        PRUint32 deviceType ATTRIBUTE_UNUSED,
+                        PRUint32 accessMode ATTRIBUTE_UNUSED,
+                        IHardDisk **hardDisk)
 {
-#if VBOX_API_VERSION >= 4000000 && VBOX_API_VERSION < 4002000
+    /* In vbox 2.2 and 3.0, this function will create a IHardDisk object.
+     * In vbox 3.1 and later, this function will create a IMedium object.
+     */
+#if VBOX_API_VERSION < 4000000
+    return vboxObj->vtbl->FindHardDisk(vboxObj, location, hardDisk);
+#elif VBOX_API_VERSION < 4002000
     return vboxObj->vtbl->FindMedium(vboxObj, location,
-                                     deviceType, medium);
-#elif VBOX_API_VERSION >= 4002000
+                                     deviceType, hardDisk);
+#else /* VBOX_API_VERSION >= 4002000 */
     return vboxObj->vtbl->OpenMedium(vboxObj, location,
-                                     deviceType, accessMode, PR_FALSE, medium);
-#else
-    vboxUnsupported();
-    return 0;
-#endif
+                                     deviceType, accessMode, PR_FALSE, hardDisk);
+#endif /* VBOX_API_VERSION >= 4002000 */
 }
 
 static nsresult
@@ -5273,7 +5274,7 @@ static vboxUniformedIVirtualBox _UIVirtualBox = {
     .CreateMachine = _virtualboxCreateMachine,
     .CreateHardDiskMedium = _virtualboxCreateHardDiskMedium,
     .RegisterMachine = _virtualboxRegisterMachine,
-    .FindMedium = _virtualboxFindMedium,
+    .FindHardDisk = _virtualboxFindHardDisk,
     .OpenMedium = _virtualboxOpenMedium,
     .GetHardDiskByIID = _virtualboxGetHardDiskByIID,
     .FindDHCPServerByNetworkName = _virtualboxFindDHCPServerByNetworkName,
diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h
index a275d6a..2a9c3b2 100644
--- a/src/vbox/vbox_uniformed_api.h
+++ b/src/vbox/vbox_uniformed_api.h
@@ -196,7 +196,8 @@ typedef struct {
     nsresult (*CreateMachine)(vboxGlobalData *data, virDomainDefPtr def, IMachine **machine, char *uuidstr);
     nsresult (*CreateHardDiskMedium)(IVirtualBox *vboxObj, PRUnichar *format, PRUnichar *location, IMedium **medium);
     nsresult (*RegisterMachine)(IVirtualBox *vboxObj, IMachine *machine);
-    nsresult (*FindMedium)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IMedium **medium);
+    nsresult (*FindHardDisk)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType,
+                             PRUint32 accessMode, IHardDisk **hardDisk);
     nsresult (*OpenMedium)(IVirtualBox *vboxObj, PRUnichar *location, PRUint32 deviceType, PRUint32 accessMode, IMedium **medium);
     nsresult (*GetHardDiskByIID)(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IHardDisk **hardDisk);
     nsresult (*FindDHCPServerByNetworkName)(IVirtualBox *vboxObj, PRUnichar *name, IDHCPServer **server);
-- 
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]