mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-24 22:55:23 +00:00
vbox: Make FindMedium support old vbox versions
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.
This commit is contained in:
parent
f67ae174eb
commit
1599319c7e
@ -1081,7 +1081,7 @@ vboxAttachDrivesNew(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine
|
||||
continue;
|
||||
}
|
||||
|
||||
gVBoxAPI.UIVirtualBox.FindMedium(data->vboxObj, mediumFileUtf16,
|
||||
gVBoxAPI.UIVirtualBox.FindHardDisk(data->vboxObj, mediumFileUtf16,
|
||||
deviceType, accessMode, &medium);
|
||||
|
||||
if (!medium) {
|
||||
|
@ -3553,22 +3553,23 @@ _virtualboxRegisterMachine(IVirtualBox *vboxObj, IMachine *machine)
|
||||
}
|
||||
|
||||
static nsresult
|
||||
_virtualboxFindMedium(IVirtualBox *vboxObj ATTRIBUTE_UNUSED,
|
||||
PRUnichar *location ATTRIBUTE_UNUSED,
|
||||
_virtualboxFindHardDisk(IVirtualBox *vboxObj, PRUnichar *location,
|
||||
PRUint32 deviceType ATTRIBUTE_UNUSED,
|
||||
PRUint32 accessMode ATTRIBUTE_UNUSED,
|
||||
IMedium **medium 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
|
||||
@ -5287,7 +5288,7 @@ static vboxUniformedIVirtualBox _UIVirtualBox = {
|
||||
.CreateMachine = _virtualboxCreateMachine,
|
||||
.CreateHardDiskMedium = _virtualboxCreateHardDiskMedium,
|
||||
.RegisterMachine = _virtualboxRegisterMachine,
|
||||
.FindMedium = _virtualboxFindMedium,
|
||||
.FindHardDisk = _virtualboxFindHardDisk,
|
||||
.OpenMedium = _virtualboxOpenMedium,
|
||||
.GetHardDiskByIID = _virtualboxGetHardDiskByIID,
|
||||
.FindDHCPServerByNetworkName = _virtualboxFindDHCPServerByNetworkName,
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user