This commit should be squashed to previous one. Keeping it separate for code-review purposes only as it's mostly noise due to changes of the struct definitions in previous patch:
* vboxPrivate (aka old vboxGlobalData *data argument) no longer needs to be passed around as g_pVBoxGlobalData is the only one that has pFuncs reference. * for vbox 3.x, the even handling code was updated to use VirtuaBoxCallback struct (that is modeled after IVirtualBoxCallback) but includes additional members to carry contextual info so that g_pVBoxGlobalData does not have to be used in the callbacks. The additional members keep virConnectPtr reference and callback reference counter (taken out from old vboxGlobalData) P.S. VBox 3.x callback handling code updates were only compile-tested as VBOX 3 is no longer supported by upstream and does not work on any reasonably modern linux distro. --- src/vbox/vbox_common.c | 101 +++++++---------- src/vbox/vbox_common.h | 32 +++--- src/vbox/vbox_network.c | 31 +++-- src/vbox/vbox_tmpl.c | 258 ++++++++++++++++++------------------------ src/vbox/vbox_uniformed_api.h | 49 ++++---- 5 files changed, 206 insertions(+), 265 deletions(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 1728275..3c98a34 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -520,24 +520,12 @@ vboxDomainSave(virDomainPtr dom, const char *path ATTRIBUTE_UNUSED) return ret; } -static void vboxDriverLock(vboxPrivate *data) -{ - virMutexLock(&data->lock); -} - -static void vboxDriverUnlock(vboxPrivate *data) -{ - virMutexUnlock(&data->lock); -} - static int vboxConnectGetVersion(virConnectPtr conn, unsigned long *version) { vboxPrivate *data = conn->privateData; VIR_DEBUG("%s: in vboxGetVersion", conn->driver->name); - vboxDriverLock(data); *version = data->version; - vboxDriverUnlock(data); return 0; } @@ -600,9 +588,7 @@ static char *vboxConnectGetCapabilities(virConnectPtr conn) if (!data->vboxObj) return ret; - vboxDriverLock(data); ret = virCapabilitiesFormatXML(data->caps); - vboxDriverUnlock(data); return ret; } @@ -1712,7 +1698,7 @@ vboxAttachDisplay(virDomainDefPtr def, vboxPrivate *data, IMachine *machine) } static void -vboxAttachUSB(virDomainDefPtr def, vboxPrivate *data, IMachine *machine) +vboxAttachUSB(virDomainDefPtr def, IMachine *machine) { IUSBCommon *USBCommon = NULL; size_t i = 0; @@ -1816,7 +1802,7 @@ vboxAttachUSB(virDomainDefPtr def, vboxPrivate *data, IMachine *machine) } static void -vboxAttachSharedFolder(virDomainDefPtr def, vboxPrivate *data, IMachine *machine) +vboxAttachSharedFolder(virDomainDefPtr def, IMachine *machine) { size_t i; PRUnichar *nameUtf16; @@ -1957,8 +1943,8 @@ vboxDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int flags vboxAttachParallel(def, data, machine); vboxAttachVideo(def, machine); vboxAttachDisplay(def, data, machine); - vboxAttachUSB(def, data, machine); - vboxAttachSharedFolder(def, data, machine); + vboxAttachUSB(def, machine); + vboxAttachSharedFolder(def, machine); /* Save the machine settings made till now and close the * session. also free up the mchiid variable used. @@ -2020,7 +2006,7 @@ detachDevices_common(vboxPrivate *data, vboxIIDUnion *iidu) if (NS_SUCCEEDED(rc)) { rc = gVBoxAPI.UISession.GetMachine(data->vboxSession, &machine); if (NS_SUCCEEDED(rc) && machine) { - gVBoxAPI.detachDevices(data, machine, hddcnameUtf16); + gVBoxAPI.detachDevices(machine, hddcnameUtf16); gVBoxAPI.UIMachine.SaveSettings(machine); } gVBoxAPI.UISession.Close(data->vboxSession); @@ -2983,7 +2969,7 @@ static int vboxDomainGetMaxVcpus(virDomainPtr dom) } static void -vboxHostDeviceGetXMLDesc(vboxPrivate *data, virDomainDefPtr def, IMachine *machine) +vboxHostDeviceGetXMLDesc(virDomainDefPtr def, IMachine *machine) { IUSBCommon *USBCommon = NULL; PRBool enabled = PR_FALSE; @@ -3408,7 +3394,7 @@ vboxDumpDisplay(virDomainDefPtr def, vboxPrivate *data, IMachine *machine) } static void -vboxDumpSharedFolders(virDomainDefPtr def, vboxPrivate *data, IMachine *machine) +vboxDumpSharedFolders(virDomainDefPtr def, IMachine *machine) { /* shared folders */ vboxArray sharedFolders = VBOX_ARRAY_INITIALIZER; @@ -3469,7 +3455,7 @@ vboxDumpSharedFolders(virDomainDefPtr def, vboxPrivate *data, IMachine *machine) } static void -vboxDumpNetwork(virDomainDefPtr def, vboxPrivate *data, IMachine *machine, PRUint32 networkAdapterCount) +vboxDumpNetwork(virDomainDefPtr def, IMachine *machine, PRUint32 networkAdapterCount) { PRUint32 netAdpIncCnt = 0; size_t i = 0; @@ -3648,7 +3634,7 @@ vboxDumpAudio(virDomainDefPtr def, vboxPrivate *data ATTRIBUTE_UNUSED, } static void -vboxDumpSerial(virDomainDefPtr def, vboxPrivate *data, IMachine *machine, PRUint32 serialPortCount) +vboxDumpSerial(virDomainDefPtr def, IMachine *machine, PRUint32 serialPortCount) { PRUint32 serialPortIncCount = 0; size_t i = 0; @@ -3736,7 +3722,7 @@ vboxDumpSerial(virDomainDefPtr def, vboxPrivate *data, IMachine *machine, PRUint } static void -vboxDumpParallel(virDomainDefPtr def, vboxPrivate *data, IMachine *machine, PRUint32 parallelPortCount) +vboxDumpParallel(virDomainDefPtr def, IMachine *machine, PRUint32 parallelPortCount) { PRUint32 parallelPortIncCount = 0; size_t i = 0; @@ -3947,24 +3933,24 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags) * into the common code. */ if (gVBoxAPI.oldMediumInterface) - gVBoxAPI.dumpIDEHDDsOld(def, data, machine); + gVBoxAPI.dumpIDEHDDsOld(def, machine); else vboxDumpIDEHDDsNew(def, data, machine); - vboxDumpSharedFolders(def, data, machine); - vboxDumpNetwork(def, data, machine, networkAdapterCount); + vboxDumpSharedFolders(def, machine); + vboxDumpNetwork(def, machine, networkAdapterCount); vboxDumpAudio(def, data, machine); if (gVBoxAPI.oldMediumInterface) { - gVBoxAPI.dumpDVD(def, data, machine); - gVBoxAPI.dumpFloppy(def, data, machine); + gVBoxAPI.dumpDVD(def, machine); + gVBoxAPI.dumpFloppy(def, machine); } - vboxDumpSerial(def, data, machine, serialPortCount); - vboxDumpParallel(def, data, machine, parallelPortCount); + vboxDumpSerial(def, machine, serialPortCount); + vboxDumpParallel(def, machine, parallelPortCount); /* dump USB devices/filters if active */ - vboxHostDeviceGetXMLDesc(data, def, machine); + vboxHostDeviceGetXMLDesc(def, machine); ret = virDomainDefFormat(def, data->caps, virDomainDefFormatConvertXMLFlags(flags)); @@ -4565,7 +4551,7 @@ vboxSnapshotRedefine(virDomainPtr dom, _("Unable to get the read write medium id")); goto cleanup; } - gVBoxAPI.UIID.vboxIIDToUtf8(data, &iid, &uuid); + gVBoxAPI.UIID.vboxIIDToUtf8(&iid, &uuid); vboxIIDUnalloc(&iid); rc = gVBoxAPI.UIMedium.GetFormat(readWriteMedium, &formatUtf); @@ -4673,7 +4659,7 @@ vboxSnapshotRedefine(virDomainPtr dom, _("Unable to get hard disk id")); goto cleanup; } - gVBoxAPI.UIID.vboxIIDToUtf8(data, &iid, &uuid); + gVBoxAPI.UIID.vboxIIDToUtf8(&iid, &uuid); vboxIIDUnalloc(&iid); rc = gVBoxAPI.UIMedium.GetFormat(readOnlyMedium, &formatUtf); @@ -4704,7 +4690,7 @@ vboxSnapshotRedefine(virDomainPtr dom, VIR_FREE(uuid); goto cleanup; } - gVBoxAPI.UIID.vboxIIDToUtf8(data, &parentiid, &parentUuid); + gVBoxAPI.UIID.vboxIIDToUtf8(&parentiid, &parentUuid); vboxIIDUnalloc(&parentiid); rc = gVBoxAPI.UIMedium.Close(readOnlyMedium); @@ -4988,7 +4974,7 @@ vboxSnapshotRedefine(virDomainPtr dom, VIR_FREE(disk); goto cleanup; } - gVBoxAPI.UIID.vboxIIDToUtf8(data, &iid, &uuid); + gVBoxAPI.UIID.vboxIIDToUtf8(&iid, &uuid); disk->uuid = uuid; vboxIIDUnalloc(&iid); @@ -5001,7 +4987,7 @@ vboxSnapshotRedefine(virDomainPtr dom, } gVBoxAPI.UIMedium.GetId(parentDisk, &parentiid); - gVBoxAPI.UIID.vboxIIDToUtf8(data, &parentiid, &parentUuid); + gVBoxAPI.UIID.vboxIIDToUtf8(&parentiid, &parentUuid); vboxIIDUnalloc(&parentiid); if (virVBoxSnapshotConfAddHardDiskToMediaRegistry(disk, snapshotMachineDesc->mediaRegistry, @@ -5086,7 +5072,7 @@ vboxSnapshotRedefine(virDomainPtr dom, (unsigned)rc); goto cleanup; } - gVBoxAPI.UIID.vboxIIDToUtf8(data, &parentiid, &parentUuid); + gVBoxAPI.UIID.vboxIIDToUtf8(&parentiid, &parentUuid); vboxIIDUnalloc(&parentiid); VBOX_UTF8_TO_UTF16("VDI", &formatUtf16); @@ -5135,7 +5121,7 @@ vboxSnapshotRedefine(virDomainPtr dom, (unsigned)rc); goto cleanup; } - gVBoxAPI.UIID.vboxIIDToUtf8(data, &iid, &uuid); + gVBoxAPI.UIID.vboxIIDToUtf8(&iid, &uuid); disk->uuid = uuid; vboxIIDUnalloc(&iid); @@ -5491,10 +5477,7 @@ vboxDomainSnapshotGetAll(virDomainPtr dom, } static ISnapshot * -vboxDomainSnapshotGet(vboxPrivate *data, - virDomainPtr dom, - IMachine *machine, - const char *name) +vboxDomainSnapshotGet(virDomainPtr dom, IMachine *machine, const char *name) { ISnapshot **snapshots = NULL; ISnapshot *snapshot = NULL; @@ -5569,7 +5552,7 @@ static int vboxSnapshotGetReadWriteDisks(virDomainSnapshotDefPtr def, if (openSessionForMachine(data, dom->uuid, &domiid, &machine, false) < 0) goto cleanup; - if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name))) + if (!(snap = vboxDomainSnapshotGet(dom, machine, snapshot->name))) goto cleanup; rc = gVBoxAPI.UISnapshot.GetId(snap, &snapIid); @@ -5579,7 +5562,7 @@ static int vboxSnapshotGetReadWriteDisks(virDomainSnapshotDefPtr def, goto cleanup; } - gVBoxAPI.UIID.vboxIIDToUtf8(data, &snapIid, &snapshotUuidStr); + gVBoxAPI.UIID.vboxIIDToUtf8(&snapIid, &snapshotUuidStr); vboxIIDUnalloc(&snapIid); rc = gVBoxAPI.UISnapshot.GetMachine(snap, &snapMachine); if (NS_FAILED(rc)) { @@ -5789,7 +5772,7 @@ int vboxSnapshotGetReadOnlyDisks(virDomainSnapshotPtr snapshot, if (openSessionForMachine(data, dom->uuid, &domiid, &machine, false) < 0) goto cleanup; - if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name))) + if (!(snap = vboxDomainSnapshotGet(dom, machine, snapshot->name))) goto cleanup; rc = gVBoxAPI.UISnapshot.GetMachine(snap, &snapMachine); @@ -6006,7 +5989,7 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot, if (openSessionForMachine(data, dom->uuid, &domiid, &machine, false) < 0) goto cleanup; - if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name))) + if (!(snap = vboxDomainSnapshotGet(dom, machine, snapshot->name))) goto cleanup; if (VIR_ALLOC(def) < 0 || !(def->dom = virDomainDefNew())) @@ -6269,7 +6252,7 @@ vboxDomainSnapshotLookupByName(virDomainPtr dom, const char *name, if (openSessionForMachine(data, dom->uuid, &iid, &machine, false) < 0) goto cleanup; - if (!(snapshot = vboxDomainSnapshotGet(data, dom, machine, name))) + if (!(snapshot = vboxDomainSnapshotGet(dom, machine, name))) goto cleanup; ret = virGetDomainSnapshot(dom, name); @@ -6340,7 +6323,7 @@ vboxDomainSnapshotGetParent(virDomainSnapshotPtr snapshot, if (openSessionForMachine(data, dom->uuid, &iid, &machine, false) < 0) goto cleanup; - if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name))) + if (!(snap = vboxDomainSnapshotGet(dom, machine, snapshot->name))) goto cleanup; rc = gVBoxAPI.UISnapshot.GetParent(snap, &parent); @@ -6461,7 +6444,7 @@ static int vboxDomainSnapshotIsCurrent(virDomainSnapshotPtr snapshot, if (openSessionForMachine(data, dom->uuid, &iid, &machine, false) < 0) goto cleanup; - if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name))) + if (!(snap = vboxDomainSnapshotGet(dom, machine, snapshot->name))) goto cleanup; rc = gVBoxAPI.UIMachine.GetCurrentSnapshot(machine, ¤t); @@ -6519,7 +6502,7 @@ static int vboxDomainSnapshotHasMetadata(virDomainSnapshotPtr snapshot, goto cleanup; /* Check that snapshot exists. If so, there is no metadata. */ - if (!(snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name))) + if (!(snap = vboxDomainSnapshotGet(dom, machine, snapshot->name))) goto cleanup; ret = 0; @@ -6553,7 +6536,7 @@ static int vboxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, if (openSessionForMachine(data, dom->uuid, &domiid, &machine, false) < 0) goto cleanup; - newSnapshot = vboxDomainSnapshotGet(data, dom, machine, snapshot->name); + newSnapshot = vboxDomainSnapshotGet(dom, machine, snapshot->name); if (!newSnapshot) goto cleanup; @@ -6605,9 +6588,7 @@ static int vboxDomainRevertToSnapshot(virDomainSnapshotPtr snapshot, } static int -vboxDomainSnapshotDeleteSingle(vboxPrivate *data, - IConsole *console, - ISnapshot *snapshot) +vboxDomainSnapshotDeleteSingle(IConsole *console, ISnapshot *snapshot) { IProgress *progress = NULL; vboxIIDUnion iid; @@ -6674,7 +6655,7 @@ vboxDomainSnapshotDeleteTree(vboxPrivate *data, goto cleanup; } - ret = vboxDomainSnapshotDeleteSingle(data, console, snapshot); + ret = vboxDomainSnapshotDeleteSingle(console, snapshot); cleanup: gVBoxAPI.UArray.vboxArrayRelease(&children); @@ -6842,7 +6823,7 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot) (unsigned)rc); goto cleanup; } - gVBoxAPI.UIID.vboxIIDToUtf8(data, &parentiid, &parentUuid); + gVBoxAPI.UIID.vboxIIDToUtf8(&parentiid, &parentUuid); vboxIIDUnalloc(&parentiid); VBOX_UTF16_FREE(locationUtf16); VBOX_UTF8_TO_UTF16("VDI", &formatUtf16); @@ -6893,7 +6874,7 @@ vboxDomainSnapshotDeleteMetadataOnly(virDomainSnapshotPtr snapshot) VIR_FREE(disk); goto cleanup; } - gVBoxAPI.UIID.vboxIIDToUtf8(data, &iid, &uuid); + gVBoxAPI.UIID.vboxIIDToUtf8(&iid, &uuid); disk->uuid = uuid; vboxIIDUnalloc(&iid); @@ -7155,7 +7136,7 @@ static int vboxDomainSnapshotDelete(virDomainSnapshotPtr snapshot, if (openSessionForMachine(data, dom->uuid, &domiid, &machine, false) < 0) goto cleanup; - snap = vboxDomainSnapshotGet(data, dom, machine, snapshot->name); + snap = vboxDomainSnapshotGet(dom, machine, snapshot->name); if (!snap) goto cleanup; @@ -7206,7 +7187,7 @@ static int vboxDomainSnapshotDelete(virDomainSnapshotPtr snapshot, if (flags & VIR_DOMAIN_SNAPSHOT_DELETE_CHILDREN) ret = vboxDomainSnapshotDeleteTree(data, console, snap); else - ret = vboxDomainSnapshotDeleteSingle(data, console, snap); + ret = vboxDomainSnapshotDeleteSingle(console, snap); cleanup: VBOX_RELEASE(console); diff --git a/src/vbox/vbox_common.h b/src/vbox/vbox_common.h index b178878..074cb4e 100644 --- a/src/vbox/vbox_common.h +++ b/src/vbox/vbox_common.h @@ -348,44 +348,44 @@ typedef nsISupports IKeyboard; # define RC_SUCCEEDED(rc) NS_SUCCEEDED(rc.resultCode) # define RC_FAILED(rc) NS_FAILED(rc.resultCode) -# define VBOX_UTF16_FREE(arg) \ +# define VBOX_UTF16_FREE(arg) \ do { \ if (arg) { \ - gVBoxAPI.UPFN.Utf16Free(data->pFuncs, arg); \ + gVBoxAPI.UPFN.Utf16Free(arg); \ (arg) = NULL; \ } \ } while (0) -# define VBOX_UTF8_FREE(arg) \ +# define VBOX_UTF8_FREE(arg) \ do { \ if (arg) { \ - gVBoxAPI.UPFN.Utf8Free(data->pFuncs, arg); \ + gVBoxAPI.UPFN.Utf8Free(arg); \ (arg) = NULL; \ } \ } while (0) -# define VBOX_COM_UNALLOC_MEM(arg) \ +# define VBOX_COM_UNALLOC_MEM(arg) \ do { \ if (arg) { \ - gVBoxAPI.UPFN.ComUnallocMem(data->pFuncs, arg); \ + gVBoxAPI.UPFN.ComUnallocMem(arg); \ (arg) = NULL; \ } \ } while (0) -# define VBOX_UTF16_TO_UTF8(arg1, arg2) gVBoxAPI.UPFN.Utf16ToUtf8(data->pFuncs, arg1, arg2) -# define VBOX_UTF8_TO_UTF16(arg1, arg2) gVBoxAPI.UPFN.Utf8ToUtf16(data->pFuncs, arg1, arg2) +# define VBOX_UTF16_TO_UTF8(arg1, arg2) gVBoxAPI.UPFN.Utf16ToUtf8(arg1, arg2) +# define VBOX_UTF8_TO_UTF16(arg1, arg2) gVBoxAPI.UPFN.Utf8ToUtf16(arg1, arg2) # define VBOX_ADDREF(arg) gVBoxAPI.nsUISupports.AddRef((void *)(arg)) -# define VBOX_RELEASE(arg) \ +# define VBOX_RELEASE(arg) \ do { \ if (arg) { \ - gVBoxAPI.nsUISupports.Release((void *)arg); \ + gVBoxAPI.nsUISupports.Release((void *)arg); \ (arg) = NULL; \ } \ } while (0) -# define VBOX_MEDIUM_RELEASE(arg) \ +# define VBOX_MEDIUM_RELEASE(arg) \ do { \ if (arg) { \ gVBoxAPI.UIMedium.Release(arg); \ @@ -393,13 +393,13 @@ typedef nsISupports IKeyboard; } \ } while (0) -# define vboxIIDUnalloc(iid) gVBoxAPI.UIID.vboxIIDUnalloc(data, iid) -# define vboxIIDToUUID(iid, uuid) gVBoxAPI.UIID.vboxIIDToUUID(data, iid, uuid) -# define vboxIIDFromUUID(iid, uuid) gVBoxAPI.UIID.vboxIIDFromUUID(data, iid, uuid) -# define vboxIIDIsEqual(iid1, iid2) gVBoxAPI.UIID.vboxIIDIsEqual(data, iid1, iid2) +# define vboxIIDUnalloc(iid) gVBoxAPI.UIID.vboxIIDUnalloc(iid) +# define vboxIIDToUUID(iid, uuid) gVBoxAPI.UIID.vboxIIDToUUID(iid, uuid) +# define vboxIIDFromUUID(iid, uuid) gVBoxAPI.UIID.vboxIIDFromUUID(iid, uuid) +# define vboxIIDIsEqual(iid1, iid2) gVBoxAPI.UIID.vboxIIDIsEqual(iid1, iid2) # define DEBUGIID(msg, iid) gVBoxAPI.UIID.DEBUGIID(msg, iid) # define vboxIIDFromArrayItem(iid, array, idx) \ - gVBoxAPI.UIID.vboxIIDFromArrayItem(data, iid, array, idx) + gVBoxAPI.UIID.vboxIIDFromArrayItem(iid, array, idx) # define VBOX_IID_INITIALIZE(iid) gVBoxAPI.UIID.vboxIIDInitialize(iid) diff --git a/src/vbox/vbox_network.c b/src/vbox/vbox_network.c index ec66fab..d6b4fd0 100644 --- a/src/vbox/vbox_network.c +++ b/src/vbox/vbox_network.c @@ -350,7 +350,7 @@ static virNetworkPtr vboxNetworkLookupByName(virConnectPtr conn, const char *nam } static PRUnichar * -vboxSocketFormatAddrUtf16(vboxPrivate *data, virSocketAddrPtr addr) +vboxSocketFormatAddrUtf16(virSocketAddrPtr addr) { char *utf8 = NULL; PRUnichar *utf16 = NULL; @@ -462,10 +462,10 @@ vboxNetworkDefineCreateXML(virConnectPtr conn, const char *xml, bool start) PRUnichar *toIPAddressUtf16 = NULL; PRUnichar *trunkTypeUtf16 = NULL; - ipAddressUtf16 = vboxSocketFormatAddrUtf16(data, &ipdef->address); - networkMaskUtf16 = vboxSocketFormatAddrUtf16(data, &netmask); - fromIPAddressUtf16 = vboxSocketFormatAddrUtf16(data, &ipdef->ranges[0].start); - toIPAddressUtf16 = vboxSocketFormatAddrUtf16(data, &ipdef->ranges[0].end); + ipAddressUtf16 = vboxSocketFormatAddrUtf16(&ipdef->address); + networkMaskUtf16 = vboxSocketFormatAddrUtf16(&netmask); + fromIPAddressUtf16 = vboxSocketFormatAddrUtf16(&ipdef->ranges[0].start); + toIPAddressUtf16 = vboxSocketFormatAddrUtf16(&ipdef->ranges[0].end); if (ipAddressUtf16 == NULL || networkMaskUtf16 == NULL || fromIPAddressUtf16 == NULL || toIPAddressUtf16 == NULL) { @@ -507,8 +507,8 @@ vboxNetworkDefineCreateXML(virConnectPtr conn, const char *xml, bool start) PRUnichar *ipAddressUtf16 = NULL; PRUnichar *networkMaskUtf16 = NULL; - ipAddressUtf16 = vboxSocketFormatAddrUtf16(data, &ipdef->hosts[0].ip); - networkMaskUtf16 = vboxSocketFormatAddrUtf16(data, &netmask); + ipAddressUtf16 = vboxSocketFormatAddrUtf16(&ipdef->hosts[0].ip); + networkMaskUtf16 = vboxSocketFormatAddrUtf16(&netmask); if (ipAddressUtf16 == NULL || networkMaskUtf16 == NULL) { VBOX_UTF16_FREE(ipAddressUtf16); @@ -739,8 +739,7 @@ static int vboxNetworkCreate(virNetworkPtr network) } static int -vboxSocketParseAddrUtf16(vboxPrivate *data, const PRUnichar *utf16, - virSocketAddrPtr addr) +vboxSocketParseAddrUtf16(const PRUnichar *utf16, virSocketAddrPtr addr) { int result = -1; char *utf8 = NULL; @@ -837,13 +836,13 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags) /* Currently virtualbox supports only one dhcp server per network * with contigious address space from start to end */ - if (vboxSocketParseAddrUtf16(data, ipAddressUtf16, + if (vboxSocketParseAddrUtf16(ipAddressUtf16, &ipdef->address) < 0 || - vboxSocketParseAddrUtf16(data, networkMaskUtf16, + vboxSocketParseAddrUtf16(networkMaskUtf16, &ipdef->netmask) < 0 || - vboxSocketParseAddrUtf16(data, fromIPAddressUtf16, + vboxSocketParseAddrUtf16(fromIPAddressUtf16, &ipdef->ranges[0].start) < 0 || - vboxSocketParseAddrUtf16(data, toIPAddressUtf16, + vboxSocketParseAddrUtf16(toIPAddressUtf16, &ipdef->ranges[0].end) < 0) { errorOccurred = true; } @@ -874,7 +873,7 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags) VBOX_UTF16_TO_UTF8(macAddressUtf16, &ipdef->hosts[0].mac); - if (vboxSocketParseAddrUtf16(data, ipAddressUtf16, + if (vboxSocketParseAddrUtf16(ipAddressUtf16, &ipdef->hosts[0].ip) < 0) { errorOccurred = true; } @@ -896,9 +895,9 @@ static char *vboxNetworkGetXMLDesc(virNetworkPtr network, unsigned int flags) gVBoxAPI.UIHNInterface.GetNetworkMask(networkInterface, &networkMaskUtf16); gVBoxAPI.UIHNInterface.GetIPAddress(networkInterface, &ipAddressUtf16); - if (vboxSocketParseAddrUtf16(data, networkMaskUtf16, + if (vboxSocketParseAddrUtf16(networkMaskUtf16, &ipdef->netmask) < 0 || - vboxSocketParseAddrUtf16(data, ipAddressUtf16, + vboxSocketParseAddrUtf16(ipAddressUtf16, &ipdef->address) < 0) { errorOccurred = true; } diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c index 37dcd3e..df19fdc 100644 --- a/src/vbox/vbox_tmpl.c +++ b/src/vbox/vbox_tmpl.c @@ -110,7 +110,7 @@ static vboxGlobalData *g_pVBoxGlobalData; #define VBOX_UTF16_FREE(arg) \ do { \ if (arg) { \ - data->pFuncs->pfnUtf16Free(arg); \ + g_pVBoxGlobalData->pFuncs->pfnUtf16Free(arg); \ (arg) = NULL; \ } \ } while (0) @@ -118,13 +118,13 @@ static vboxGlobalData *g_pVBoxGlobalData; #define VBOX_UTF8_FREE(arg) \ do { \ if (arg) { \ - data->pFuncs->pfnUtf8Free(arg); \ + g_pVBoxGlobalData->pFuncs->pfnUtf8Free(arg); \ (arg) = NULL; \ } \ } while (0) -#define VBOX_UTF16_TO_UTF8(arg1, arg2) data->pFuncs->pfnUtf16ToUtf8(arg1, arg2) -#define VBOX_UTF8_TO_UTF16(arg1, arg2) data->pFuncs->pfnUtf8ToUtf16(arg1, arg2) +#define VBOX_UTF16_TO_UTF8(arg1, arg2) g_pVBoxGlobalData->pFuncs->pfnUtf16ToUtf8(arg1, arg2) +#define VBOX_UTF8_TO_UTF16(arg1, arg2) g_pVBoxGlobalData->pFuncs->pfnUtf8ToUtf16(arg1, arg2) #define VBOX_RELEASE(arg) \ do { \ @@ -302,8 +302,7 @@ vboxIIDUnalloc_v2_x_WIN32(vboxPrivate *data ATTRIBUTE_UNUSED, } static void -_vboxIIDUnalloc(vboxPrivate *data ATTRIBUTE_UNUSED, - vboxIIDUnion *iid ATTRIBUTE_UNUSED) +_vboxIIDUnalloc(vboxIIDUnion *iid ATTRIBUTE_UNUSED) { /* Nothing to free */ } @@ -315,25 +314,23 @@ vboxIIDToUUID_v2_x_WIN32(vboxIID_v2_x_WIN32 *iid, unsigned char *uuid) } static void -_vboxIIDToUUID(vboxPrivate *data ATTRIBUTE_UNUSED, vboxIIDUnion *iidu, unsigned char *uuid) +_vboxIIDToUUID(vboxIIDUnion *iidu, unsigned char *uuid) { vboxIIDToUUID_v2_x_WIN32(&iidu->vboxIID_v2_x_WIN32, uuid); } static void -vboxIIDFromUUID_v2_x_WIN32(vboxPrivate *data, vboxIID_v2_x_WIN32 *iid, - const unsigned char *uuid) +vboxIIDFromUUID_v2_x_WIN32(vboxIID_v2_x_WIN32 *iid, const unsigned char *uuid) { - vboxIIDUnalloc_v2_x_WIN32(data, iid); + vboxIIDUnalloc_v2_x_WIN32(iid); nsIDFromChar((nsID *)&iid->value, uuid); } static void -_vboxIIDFromUUID(vboxPrivate *data, vboxIIDUnion *iidu, - const unsigned char *uuid) +_vboxIIDFromUUID(vboxIIDUnion *iidu, const unsigned char *uuid) { - vboxIIDFromUUID_v2_x_WIN32(data, &iidu->vboxIID_v2_x_WIN32, uuid); + vboxIIDFromUUID_v2_x_WIN32(&iidu->vboxIID_v2_x_WIN32, uuid); } static bool @@ -343,27 +340,26 @@ vboxIIDIsEqual_v2_x_WIN32(vboxIID_v2_x_WIN32 *iid1, vboxIID_v2_x_WIN32 *iid2) } static bool -_vboxIIDIsEqual(vboxPrivate *data ATTRIBUTE_UNUSED, vboxIIDUnion *iidu1, vboxIIDUnion *iidu2) +_vboxIIDIsEqual(vboxIIDUnion *iidu1, vboxIIDUnion *iidu2) { return vboxIIDIsEqual_v2_x_WIN32(&iidu1->vboxIID_v2_x_WIN32, &iidu2->vboxIID_v2_x_WIN32); } static void -vboxIIDFromArrayItem_v2_x_WIN32(vboxPrivate *data, vboxIID_v2_x_WIN32 *iid, +vboxIIDFromArrayItem_v2_x_WIN32(vboxIID_v2_x_WIN32 *iid, vboxArray *array, int idx) { GUID *items = (GUID *)array->items; - vboxIIDUnalloc_v2_x_WIN32(data, iid); + vboxIIDUnalloc_v2_x_WIN32(iid); memcpy(&iid->value, &items[idx], sizeof(GUID)); } static void -_vboxIIDFromArrayItem(vboxPrivate *data, vboxIIDUnion *iidu, - vboxArray *array, int idx) +_vboxIIDFromArrayItem(vboxIIDUnion *iidu, vboxArray *array, int idx) { - vboxIIDFromArrayItem_v2_x_WIN32(data, &iidu->vboxIID_v2_x_WIN32, array, idx); + vboxIIDFromArrayItem_v2_x_WIN32(&iidu->vboxIID_v2_x_WIN32, array, idx); } # define vboxIIDUnalloc(iid) vboxIIDUnalloc_v2_x_WIN32(data, iid) @@ -383,21 +379,21 @@ typedef struct _vboxIID_v2_x vboxIID_v2_x; # define IID_MEMBER(name) (iidu->vboxIID_v2_x.name) static void -vboxIIDUnalloc_v2_x(vboxPrivate *data, vboxIID_v2_x *iid) +vboxIIDUnalloc_v2_x(vboxIID_v2_x *iid) { if (iid->value == NULL) return; if (iid->value != &iid->backing) - data->pFuncs->pfnComUnallocMem(iid->value); + g_pVBoxGlobalData->pFuncs->pfnComUnallocMem(iid->value); iid->value = NULL; } static void -_vboxIIDUnalloc(vboxPrivate *data, vboxIIDUnion *iidu) +_vboxIIDUnalloc(vboxIIDUnion *iidu) { - vboxIIDUnalloc_v2_x(data, &iidu->vboxIID_v2_x); + vboxIIDUnalloc_v2_x(&iidu->vboxIID_v2_x); } static void @@ -407,17 +403,15 @@ vboxIIDToUUID_v2_x(vboxIID_v2_x *iid, unsigned char *uuid) } static void -_vboxIIDToUUID(vboxPrivate *data ATTRIBUTE_UNUSED, - vboxIIDUnion *iidu, unsigned char *uuid) +_vboxIIDToUUID(vboxIIDUnion *iidu, unsigned char *uuid) { vboxIIDToUUID_v2_x(&iidu->vboxIID_v2_x, uuid); } static void -vboxIIDFromUUID_v2_x(vboxPrivate *data, vboxIID_v2_x *iid, - const unsigned char *uuid) +vboxIIDFromUUID_v2_x(vboxIID_v2_x *iid, const unsigned char *uuid) { - vboxIIDUnalloc_v2_x(data, iid); + vboxIIDUnalloc_v2_x(iid); iid->value = &iid->backing; @@ -426,10 +420,9 @@ vboxIIDFromUUID_v2_x(vboxPrivate *data, vboxIID_v2_x *iid, } static void -_vboxIIDFromUUID(vboxPrivate *data, vboxIIDUnion *iidu, - const unsigned char *uuid) +_vboxIIDFromUUID(vboxIIDUnion *iidu, const unsigned char *uuid) { - vboxIIDFromUUID_v2_x(data, &iidu->vboxIID_v2_x, uuid); + vboxIIDFromUUID_v2_x(&iidu->vboxIID_v2_x, uuid); } static bool @@ -439,17 +432,15 @@ vboxIIDIsEqual_v2_x(vboxIID_v2_x *iid1, vboxIID_v2_x *iid2) } static bool -_vboxIIDIsEqual(vboxPrivate *data ATTRIBUTE_UNUSED, - vboxIIDUnion *iidu1, vboxIIDUnion *iidu2) +_vboxIIDIsEqual(vboxIIDUnion *iidu1, vboxIIDUnion *iidu2) { return vboxIIDIsEqual_v2_x(&iidu1->vboxIID_v2_x, &iidu2->vboxIID_v2_x); } static void -vboxIIDFromArrayItem_v2_x(vboxPrivate *data, vboxIID_v2_x *iid, - vboxArray *array, int idx) +vboxIIDFromArrayItem_v2_x(vboxIID_v2_x *iid, vboxArray *array, int idx) { - vboxIIDUnalloc_v2_x(data, iid); + vboxIIDUnalloc_v2_x(iid); iid->value = &iid->backing; @@ -457,18 +448,17 @@ vboxIIDFromArrayItem_v2_x(vboxPrivate *data, vboxIID_v2_x *iid, } static void -_vboxIIDFromArrayItem(vboxPrivate *data, vboxIIDUnion *iidu, - vboxArray *array, int idx) +_vboxIIDFromArrayItem(vboxIIDUnion *iidu, vboxArray *array, int idx) { - vboxIIDFromArrayItem_v2_x(data, &iidu->vboxIID_v2_x, array, idx); + vboxIIDFromArrayItem_v2_x(&iidu->vboxIID_v2_x, array, idx); } -# define vboxIIDUnalloc(iid) vboxIIDUnalloc_v2_x(data, iid) +# define vboxIIDUnalloc(iid) vboxIIDUnalloc_v2_x(iid) # define vboxIIDToUUID(iid, uuid) vboxIIDToUUID_v2_x(iid, uuid) -# define vboxIIDFromUUID(iid, uuid) vboxIIDFromUUID_v2_x(data, iid, uuid) +# define vboxIIDFromUUID(iid, uuid) vboxIIDFromUUID_v2_x(iid, uuid) # define vboxIIDIsEqual(iid1, iid2) vboxIIDIsEqual_v2_x(iid1, iid2) # define vboxIIDFromArrayItem(iid, array, idx) \ - vboxIIDFromArrayItem_v2_x(data, iid, array, idx) + vboxIIDFromArrayItem_v2_x(iid, array, idx) # define DEBUGIID(msg, iid) DEBUGUUID(msg, iid) # endif /* !WIN32 */ @@ -482,64 +472,59 @@ typedef struct _vboxIID_v3_x vboxIID_v3_x; # define IID_MEMBER(name) (iidu->vboxIID_v3_x.name) static void -vboxIIDUnalloc_v3_x(vboxPrivate *data, vboxIID_v3_x *iid) +vboxIIDUnalloc_v3_x(vboxIID_v3_x *iid) { if (iid->value != NULL && iid->owner) - data->pFuncs->pfnUtf16Free(iid->value); + g_pVBoxGlobalData->pFuncs->pfnUtf16Free(iid->value); iid->value = NULL; iid->owner = true; } static void -_vboxIIDUnalloc(vboxPrivate *data, vboxIIDUnion *iidu) +_vboxIIDUnalloc(vboxIIDUnion *iidu) { - vboxIIDUnalloc_v3_x(data, &iidu->vboxIID_v3_x); + vboxIIDUnalloc_v3_x(&iidu->vboxIID_v3_x); } static void -vboxIIDToUUID_v3_x(vboxPrivate *data, vboxIID_v3_x *iid, - unsigned char *uuid) +vboxIIDToUUID_v3_x(vboxIID_v3_x *iid, unsigned char *uuid) { char *utf8 = NULL; - data->pFuncs->pfnUtf16ToUtf8(iid->value, &utf8); + g_pVBoxGlobalData->pFuncs->pfnUtf16ToUtf8(iid->value, &utf8); ignore_value(virUUIDParse(utf8, uuid)); - data->pFuncs->pfnUtf8Free(utf8); + g_pVBoxGlobalData->pFuncs->pfnUtf8Free(utf8); } static void -_vboxIIDToUUID(vboxPrivate *data, vboxIIDUnion *iidu, - unsigned char *uuid) +_vboxIIDToUUID(vboxIIDUnion *iidu, unsigned char *uuid) { - vboxIIDToUUID_v3_x(data, &iidu->vboxIID_v3_x, uuid); + vboxIIDToUUID_v3_x(&iidu->vboxIID_v3_x, uuid); } static void -vboxIIDFromUUID_v3_x(vboxPrivate *data, vboxIID_v3_x *iid, - const unsigned char *uuid) +vboxIIDFromUUID_v3_x(vboxIID_v3_x *iid, const unsigned char *uuid) { char utf8[VIR_UUID_STRING_BUFLEN]; - vboxIIDUnalloc_v3_x(data, iid); + vboxIIDUnalloc_v3_x(iid); virUUIDFormat(uuid, utf8); - data->pFuncs->pfnUtf8ToUtf16(utf8, &iid->value); + g_pVBoxGlobalData->pFuncs->pfnUtf8ToUtf16(utf8, &iid->value); } static void -_vboxIIDFromUUID(vboxPrivate *data, vboxIIDUnion *iidu, - const unsigned char *uuid) +_vboxIIDFromUUID(vboxIIDUnion *iidu, const unsigned char *uuid) { - vboxIIDFromUUID_v3_x(data, &iidu->vboxIID_v3_x, uuid); + vboxIIDFromUUID_v3_x(&iidu->vboxIID_v3_x, uuid); } static bool -vboxIIDIsEqual_v3_x(vboxPrivate *data, vboxIID_v3_x *iid1, - vboxIID_v3_x *iid2) +vboxIIDIsEqual_v3_x(vboxIID_v3_x *iid1, vboxIID_v3_x *iid2) { unsigned char uuid1[VIR_UUID_BUFLEN]; unsigned char uuid2[VIR_UUID_BUFLEN]; @@ -549,42 +534,39 @@ vboxIIDIsEqual_v3_x(vboxPrivate *data, vboxIID_v3_x *iid1, * or mixture of both and we don't want to fail here by * using direct string comparison. Here virUUIDParse() takes * care of these cases. */ - vboxIIDToUUID_v3_x(data, iid1, uuid1); - vboxIIDToUUID_v3_x(data, iid2, uuid2); + vboxIIDToUUID_v3_x(iid1, uuid1); + vboxIIDToUUID_v3_x(iid2, uuid2); return memcmp(uuid1, uuid2, VIR_UUID_BUFLEN) == 0; } static bool -_vboxIIDIsEqual(vboxPrivate *data, vboxIIDUnion *iidu1, - vboxIIDUnion *iidu2) +_vboxIIDIsEqual(vboxIIDUnion *iidu1, vboxIIDUnion *iidu2) { - return vboxIIDIsEqual_v3_x(data, &iidu1->vboxIID_v3_x, &iidu2->vboxIID_v3_x); + return vboxIIDIsEqual_v3_x(&iidu1->vboxIID_v3_x, &iidu2->vboxIID_v3_x); } static void -vboxIIDFromArrayItem_v3_x(vboxPrivate *data, vboxIID_v3_x *iid, - vboxArray *array, int idx) +vboxIIDFromArrayItem_v3_x(vboxIID_v3_x *iid, vboxArray *array, int idx) { - vboxIIDUnalloc_v3_x(data, iid); + vboxIIDUnalloc_v3_x(iid); iid->value = array->items[idx]; iid->owner = false; } static void -_vboxIIDFromArrayItem(vboxPrivate *data, vboxIIDUnion *iidu, - vboxArray *array, int idx) +_vboxIIDFromArrayItem(vboxIIDUnion *iidu, vboxArray *array, int idx) { - vboxIIDFromArrayItem_v3_x(data, &iidu->vboxIID_v3_x, array, idx); + vboxIIDFromArrayItem_v3_x(&iidu->vboxIID_v3_x, array, idx); } -# define vboxIIDUnalloc(iid) vboxIIDUnalloc_v3_x(data, iid) -# define vboxIIDToUUID(iid, uuid) vboxIIDToUUID_v3_x(data, iid, uuid) -# define vboxIIDFromUUID(iid, uuid) vboxIIDFromUUID_v3_x(data, iid, uuid) -# define vboxIIDIsEqual(iid1, iid2) vboxIIDIsEqual_v3_x(data, iid1, iid2) +# define vboxIIDUnalloc(iid) vboxIIDUnalloc_v3_x(iid) +# define vboxIIDToUUID(iid, uuid) vboxIIDToUUID_v3_x(iid, uuid) +# define vboxIIDFromUUID(iid, uuid) vboxIIDFromUUID_v3_x(iid, uuid) +# define vboxIIDIsEqual(iid1, iid2) vboxIIDIsEqual_v3_x(iid1, iid2) # define vboxIIDFromArrayItem(iid, array, idx) \ - vboxIIDFromArrayItem_v3_x(data, iid, array, idx) + vboxIIDFromArrayItem_v3_x(iid, array, idx) # define DEBUGIID(msg, strUtf16) DEBUGPRUnichar(msg, strUtf16) #endif /* !(VBOX_API_VERSION == 2002000) */ @@ -1404,12 +1386,11 @@ static nsresult PR_COM_METHOD vboxCallbackOnMachineStateChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED, PRUnichar *machineId, PRUint32 state) { + VirtualBoxCallback *callback = (VirtualBoxCallback *) pThis; virDomainPtr dom = NULL; int event = 0; int detail = 0; - vboxDriverLock((vboxPrivate *) g_pVBoxGlobalData); - VIR_DEBUG("IVirtualBoxCallback: %p, State: %d", pThis, state); DEBUGPRUnichar("machineId", machineId); @@ -1420,9 +1401,10 @@ vboxCallbackOnMachineStateChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED, g_pVBoxGlobalData->pFuncs->pfnUtf16ToUtf8(machineId, &machineIdUtf8); ignore_value(virUUIDParse(machineIdUtf8, uuid)); - dom = vboxDomainLookupByUUID(g_pVBoxGlobalData->conn, uuid); + dom = vboxDomainLookupByUUID(callback->conn, uuid); if (dom) { virObjectEventPtr ev; + vboxPrivate *data = (vboxPrivate *) callback->conn->privateData; if (state == MachineState_Starting) { event = VIR_DOMAIN_EVENT_STARTED; @@ -1456,12 +1438,10 @@ vboxCallbackOnMachineStateChange(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED, ev = virDomainEventLifecycleNewFromDom(dom, event, detail); if (ev) - virObjectEventStateQueue(g_pVBoxGlobalData->domainEvents, ev); + virObjectEventStateQueue(data->domainEvents, ev); } } - vboxDriverUnlock((vboxPrivate *) g_pVBoxGlobalData); - return NS_OK; } @@ -1523,12 +1503,11 @@ static nsresult PR_COM_METHOD vboxCallbackOnMachineRegistered(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED, PRUnichar *machineId, PRBool registered) { + VirtualBoxCallback *callback = (VirtualBoxCallback *) pThis; virDomainPtr dom = NULL; int event = 0; int detail = 0; - vboxDriverLock((vboxPrivate *) g_pVBoxGlobalData); - VIR_DEBUG("IVirtualBoxCallback: %p, registered: %s", pThis, registered ? "true" : "false"); DEBUGPRUnichar("machineId", machineId); @@ -1539,9 +1518,10 @@ vboxCallbackOnMachineRegistered(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED, g_pVBoxGlobalData->pFuncs->pfnUtf16ToUtf8(machineId, &machineIdUtf8); ignore_value(virUUIDParse(machineIdUtf8, uuid)); - dom = vboxDomainLookupByUUID(g_pVBoxGlobalData->conn, uuid); + dom = vboxDomainLookupByUUID(callback->conn, uuid); if (dom) { virObjectEventPtr ev; + vboxPrivate *data = (vboxPrivate *) callback->conn->privateData; /* CURRENT LIMITATION: we never get the VIR_DOMAIN_EVENT_UNDEFINED * event because the when the machine is de-registered the call @@ -1560,12 +1540,10 @@ vboxCallbackOnMachineRegistered(IVirtualBoxCallback *pThis ATTRIBUTE_UNUSED, ev = virDomainEventLifecycleNewFromDom(dom, event, detail); if (ev) - virObjectEventStateQueue(g_pVBoxGlobalData->domainEvents, ev); + virObjectEventStateQueue(data->domainEvents, ev); } } - vboxDriverUnlock((vboxPrivate *) g_pVBoxGlobalData); - return NS_OK; } @@ -1634,8 +1612,9 @@ static nsresult PR_COM_METHOD vboxCallbackAddRef(nsISupports *pThis ATTRIBUTE_UNUSED) { nsresult c; + VirtualBoxCallback *callback = (VirtualBoxCallback *) pThis; - c = ++g_pVBoxGlobalData->vboxCallBackRefCount; + c = ++callback->vboxCallBackRefCount; VIR_DEBUG("pThis: %p, vboxCallback AddRef: %d", pThis, c); @@ -1646,8 +1625,9 @@ static nsresult PR_COM_METHOD vboxCallbackRelease(nsISupports *pThis) { nsresult c; + VirtualBoxCallback *callback = (VirtualBoxCallback *) pThis; - c = --g_pVBoxGlobalData->vboxCallBackRefCount; + c = --callback->vboxCallBackRefCount; if (c == 0) { /* delete object */ VIR_FREE(pThis->vtbl); @@ -1662,17 +1642,17 @@ vboxCallbackRelease(nsISupports *pThis) static nsresult PR_COM_METHOD vboxCallbackQueryInterface(nsISupports *pThis, const nsID *iid, void **resultp) { - IVirtualBoxCallback *that = (IVirtualBoxCallback *)pThis; + VirtualBoxCallback *callback = (VirtualBoxCallback *) pThis; static const nsID ivirtualboxCallbackUUID = IVIRTUALBOXCALLBACK_IID; static const nsID isupportIID = NS_ISUPPORTS_IID; /* Match UUID for IVirtualBoxCallback class */ if (memcmp(iid, &ivirtualboxCallbackUUID, sizeof(nsID)) == 0 || memcmp(iid, &isupportIID, sizeof(nsID)) == 0) { - g_pVBoxGlobalData->vboxCallBackRefCount++; - *resultp = that; + callback->vboxCallBackRefCount++; + *resultp = callback; - VIR_DEBUG("pThis: %p, vboxCallback QueryInterface: %d", pThis, g_pVBoxGlobalData->vboxCallBackRefCount); + VIR_DEBUG("pThis: %p, vboxCallback QueryInterface: %d", callback, callback->vboxCallBackRefCount); return NS_OK; } @@ -1685,8 +1665,8 @@ vboxCallbackQueryInterface(nsISupports *pThis, const nsID *iid, void **resultp) } -static IVirtualBoxCallback *vboxAllocCallbackObj(void) { - IVirtualBoxCallback *vboxCallback = NULL; +static IVirtualBoxCallback *vboxAllocCallbackObj(virConnectPtr conn) { + VirtualBoxCallback *vboxCallback = NULL; /* Allocate, Initialize and return a valid * IVirtualBoxCallback object here @@ -1718,27 +1698,30 @@ static IVirtualBoxCallback *vboxAllocCallbackObj(void) { # endif /* VBOX_API_VERSION >= 3002000 */ vboxCallback->vtbl->OnSnapshotChange = &vboxCallbackOnSnapshotChange; vboxCallback->vtbl->OnGuestPropertyChange = &vboxCallbackOnGuestPropertyChange; - g_pVBoxGlobalData->vboxCallBackRefCount = 1; - + vboxCallback->vboxCallBackRefCount = 1; } - return vboxCallback; + vboxCallback->conn = conn; + + return (IVirtualBoxCallback *) vboxCallback; } static void vboxReadCallback(int watch ATTRIBUTE_UNUSED, int fd, int events ATTRIBUTE_UNUSED, - void *opaque ATTRIBUTE_UNUSED) + void *opaque) { + vboxPrivate *data = (vboxPrivate *) opaque; + if (fd >= 0) { - g_pVBoxGlobalData->vboxQueue->vtbl->ProcessPendingEvents(g_pVBoxGlobalData->vboxQueue); + data->vboxQueue->vtbl->ProcessPendingEvents(data->vboxQueue); } else { nsresult rc; PLEvent *pEvent = NULL; - rc = g_pVBoxGlobalData->vboxQueue->vtbl->WaitForEvent(g_pVBoxGlobalData->vboxQueue, &pEvent); + rc = data->vboxQueue->vtbl->WaitForEvent(data->vboxQueue, &pEvent); if (NS_SUCCEEDED(rc)) - g_pVBoxGlobalData->vboxQueue->vtbl->HandleEvent(g_pVBoxGlobalData->vboxQueue, pEvent); + data->vboxQueue->vtbl->HandleEvent(data->vboxQueue, pEvent); } } @@ -1762,7 +1745,7 @@ vboxConnectDomainEventRegister(virConnectPtr conn, vboxDriverLock(data); if (data->vboxCallback == NULL) { - data->vboxCallback = vboxAllocCallbackObj(); + data->vboxCallback = vboxAllocCallbackObj(conn); if (data->vboxCallback != NULL) { rc = data->vboxObj->vtbl->RegisterCallback(data->vboxObj, data->vboxCallback); if (NS_SUCCEEDED(rc)) @@ -1780,7 +1763,7 @@ vboxConnectDomainEventRegister(virConnectPtr conn, PRInt32 vboxFileHandle; vboxFileHandle = data->vboxQueue->vtbl->GetEventQueueSelectFD(data->vboxQueue); - data->fdWatch = virEventAddHandle(vboxFileHandle, VIR_EVENT_HANDLE_READABLE, vboxReadCallback, NULL, NULL); + data->fdWatch = virEventAddHandle(vboxFileHandle, VIR_EVENT_HANDLE_READABLE, vboxReadCallback, data, NULL); } if (data->fdWatch >= 0) { @@ -1866,7 +1849,7 @@ static int vboxConnectDomainEventRegisterAny(virConnectPtr conn, vboxDriverLock(data); if (data->vboxCallback == NULL) { - data->vboxCallback = vboxAllocCallbackObj(); + data->vboxCallback = vboxAllocCallbackObj(conn); if (data->vboxCallback != NULL) { rc = data->vboxObj->vtbl->RegisterCallback(data->vboxObj, data->vboxCallback); if (NS_SUCCEEDED(rc)) @@ -1884,7 +1867,7 @@ static int vboxConnectDomainEventRegisterAny(virConnectPtr conn, PRInt32 vboxFileHandle; vboxFileHandle = data->vboxQueue->vtbl->GetEventQueueSelectFD(data->vboxQueue); - data->fdWatch = virEventAddHandle(vboxFileHandle, VIR_EVENT_HANDLE_READABLE, vboxReadCallback, NULL, NULL); + data->fdWatch = virEventAddHandle(vboxFileHandle, VIR_EVENT_HANDLE_READABLE, vboxReadCallback, data, NULL); } if (data->fdWatch >= 0) { @@ -1971,7 +1954,7 @@ _initializeDomainEvent(vboxPrivate *data ATTRIBUTE_UNUSED) #else /* VBOX_API_VERSION > 2002000 || VBOX_API_VERSION < 4000000 */ /* Initialize the fWatch needed for Event Callbacks */ data->fdWatch = -1; - data->pFuncs->pfnGetEventQueue(&data->vboxQueue); + g_pVBoxGlobalData->pFuncs->pfnGetEventQueue(&data->vboxQueue); if (data->vboxQueue == NULL) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("nsIEventQueue object is null")); @@ -2020,8 +2003,7 @@ vboxGlobalData* _registerGlobalData(void) # if VBOX_API_VERSION < 3001000 static void -_detachDevices(vboxPrivate *data ATTRIBUTE_UNUSED, - IMachine *machine, PRUnichar *hddcnameUtf16) +_detachDevices(IMachine *machine, PRUnichar *hddcnameUtf16) { /* Disconnect all the drives if present */ machine->vtbl->DetachHardDisk(machine, hddcnameUtf16, 0, 0); @@ -2030,8 +2012,7 @@ _detachDevices(vboxPrivate *data ATTRIBUTE_UNUSED, } # else /* VBOX_API_VERSION >= 3001000 */ static void -_detachDevices(vboxPrivate *data, IMachine *machine, - PRUnichar *hddcnameUtf16 ATTRIBUTE_UNUSED) +_detachDevices(IMachine *machine, PRUnichar *hddcnameUtf16 ATTRIBUTE_UNUSED) { /* get all the controller first, then the attachments and * remove them all so that the machine can be undefined @@ -2096,8 +2077,7 @@ _deleteConfig(IMachine *machine) #else /* VBOX_API_VERSION >= 4000000 */ static void -_detachDevices(vboxPrivate *data ATTRIBUTE_UNUSED, - IMachine *machine ATTRIBUTE_UNUSED, +_detachDevices(IMachine *machine ATTRIBUTE_UNUSED, PRUnichar *hddcnameUtf16 ATTRIBUTE_UNUSED) { vboxUnsupported(); @@ -2167,9 +2147,7 @@ _deleteConfig(IMachine *machine) #if VBOX_API_VERSION < 3001000 static void -_dumpIDEHDDsOld(virDomainDefPtr def, - vboxPrivate *data, - IMachine *machine) +_dumpIDEHDDsOld(virDomainDefPtr def, IMachine *machine) { PRInt32 hddNum = 0; IHardDisk *hardDiskPM = NULL; @@ -2276,9 +2254,7 @@ _dumpIDEHDDsOld(virDomainDefPtr def, } static void -_dumpDVD(virDomainDefPtr def, - vboxPrivate *data, - IMachine *machine) +_dumpDVD(virDomainDefPtr def, IMachine *machine) { IDVDDrive *dvdDrive = NULL; IDVDImage *dvdImage = NULL; @@ -2415,9 +2391,7 @@ _detachDVD(IMachine *machine) } static void -_dumpFloppy(virDomainDefPtr def, - vboxPrivate *data, - IMachine *machine) +_dumpFloppy(virDomainDefPtr def, IMachine *machine) { IFloppyDrive *floppyDrive = NULL; IFloppyImage *floppyImage = NULL; @@ -2571,7 +2545,6 @@ _detachFloppy(IMachine *machine) static void _dumpIDEHDDsOld(virDomainDefPtr def ATTRIBUTE_UNUSED, - vboxPrivate *data ATTRIBUTE_UNUSED, IMachine *machine ATTRIBUTE_UNUSED) { vboxUnsupported(); @@ -2579,7 +2552,6 @@ _dumpIDEHDDsOld(virDomainDefPtr def ATTRIBUTE_UNUSED, static void _dumpDVD(virDomainDefPtr def ATTRIBUTE_UNUSED, - vboxPrivate *data ATTRIBUTE_UNUSED, IMachine *machine ATTRIBUTE_UNUSED) { vboxUnsupported(); @@ -2603,7 +2575,6 @@ _detachDVD(IMachine *machine ATTRIBUTE_UNUSED) static void _dumpFloppy(virDomainDefPtr def ATTRIBUTE_UNUSED, - vboxPrivate *data ATTRIBUTE_UNUSED, IMachine *machine ATTRIBUTE_UNUSED) { vboxUnsupported(); @@ -2674,29 +2645,29 @@ static void _pfnUninitialize(vboxPrivate *data) } } -static void _pfnComUnallocMem(PCVBOXXPCOM pFuncs, void *pv) +static void _pfnComUnallocMem(void *pv) { - pFuncs->pfnComUnallocMem(pv); + g_pVBoxGlobalData->pFuncs->pfnComUnallocMem(pv); } -static void _pfnUtf16Free(PCVBOXXPCOM pFuncs, PRUnichar *pwszString) +static void _pfnUtf16Free(PRUnichar *pwszString) { - pFuncs->pfnUtf16Free(pwszString); + g_pVBoxGlobalData->pFuncs->pfnUtf16Free(pwszString); } -static void _pfnUtf8Free(PCVBOXXPCOM pFuncs, char *pszString) +static void _pfnUtf8Free(char *pszString) { - pFuncs->pfnUtf8Free(pszString); + g_pVBoxGlobalData->pFuncs->pfnUtf8Free(pszString); } -static int _pfnUtf16ToUtf8(PCVBOXXPCOM pFuncs, const PRUnichar *pwszString, char **ppszString) +static int _pfnUtf16ToUtf8(const PRUnichar *pwszString, char **ppszString) { - return pFuncs->pfnUtf16ToUtf8(pwszString, ppszString); + return g_pVBoxGlobalData->pFuncs->pfnUtf16ToUtf8(pwszString, ppszString); } -static int _pfnUtf8ToUtf16(PCVBOXXPCOM pFuncs, const char *pszString, PRUnichar **ppwszString) +static int _pfnUtf8ToUtf16(const char *pszString, PRUnichar **ppwszString) { - return pFuncs->pfnUtf8ToUtf16(pszString, ppwszString); + return g_pVBoxGlobalData->pFuncs->pfnUtf8ToUtf16(pszString, ppwszString); } #if VBOX_API_VERSION == 2002000 @@ -2731,14 +2702,13 @@ static void _DEBUGIID(const char *msg, vboxIIDUnion *iidu) #endif /* VBOX_API_VERSION != 2002000 */ static void -_vboxIIDToUtf8(vboxPrivate *data ATTRIBUTE_UNUSED, - vboxIIDUnion *iidu ATTRIBUTE_UNUSED, +_vboxIIDToUtf8(vboxIIDUnion *iidu ATTRIBUTE_UNUSED, char **utf8 ATTRIBUTE_UNUSED) { #if VBOX_API_VERSION == 2002000 vboxUnsupported(); #else /* !(VBOX_API_VERSION == 2002000) */ - data->pFuncs->pfnUtf16ToUtf8(IID_MEMBER(value), utf8); + g_pVBoxGlobalData->pFuncs->pfnUtf16ToUtf8(IID_MEMBER(value), utf8); #endif /* !(VBOX_API_VERSION == 2002000) */ } @@ -5151,12 +5121,6 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI) pVBoxAPI->domainEventCallbacks = 1; #endif /* VBOX_API_VERSION > 2002000 || VBOX_API_VERSION < 4000000 */ -#if VBOX_API_VERSION == 2002000 - pVBoxAPI->hasStaticGlobalData = 0; -#else /* VBOX_API_VERSION > 2002000 */ - pVBoxAPI->hasStaticGlobalData = 1; -#endif /* VBOX_API_VERSION > 2002000 */ - #if VBOX_API_VERSION >= 4000000 /* Get machine for the call to VBOX_SESSION_OPEN_EXISTING */ pVBoxAPI->getMachineForSession = 1; diff --git a/src/vbox/vbox_uniformed_api.h b/src/vbox/vbox_uniformed_api.h index dac44e6..1fc5fff 100644 --- a/src/vbox/vbox_uniformed_api.h +++ b/src/vbox/vbox_uniformed_api.h @@ -21,7 +21,7 @@ # include "internal.h" -/* This file may be used in three place. That is vbox_tmpl.c, +/* This file may be used in three places. That is vbox_tmpl.c, * vbox_common.c and vbox_driver.c. The vboxUniformedAPI and some * types used for vboxUniformedAPI is defined here. * @@ -29,23 +29,21 @@ * architecture of those vbox structs(vboxObj, vboxSession, * pFuncs, vboxCallback and vboxQueue). The file should be included * after the currect vbox_CAPI_v*.h, then we can use the vbox structs - * in vboxGlobalData. The vbox_tmpl.c should implement functions + * in vboxPrivate. The vbox_tmpl.c should implement functions * defined in vboxUniformedAPI. * * In vbox_driver.c, it is used to define the struct vboxUniformedAPI. * The vbox_driver.c collects vboxUniformedAPI for all versions. * Then vboxRegister calls the vboxRegisterUniformedAPI to register. - * Note: In vbox_driver.c, the vbox structs in vboxGlobalData is - * defined by vbox_CAPI_v2.2.h. * * The vbox_common.c, it is used to generate common codes for all vbox - * versions. Bacause the same member varible's offset in a vbox struct + * versions. Bacause the same member variable's offset in a vbox struct * may change between different vbox versions. The vbox_common.c - * shouldn't directly use struct's member varibles defined in - * vbox_CAPI_v*.h. To make things safety, we include the + * shouldn't directly use struct's member variables defined in + * vbox_CAPI_v*.h. To make things safe, we include the * vbox_common.h in vbox_common.c. In this case, we treat structs - * defined by vbox as a void*. The common codes don't concern about - * the inside of this structs(actually, we can't, in the common level). + * defined by vbox as a void*. The common code is not concerned about + * the inside of those structs (actually, we can't, in the common level). * With the help of vboxUniformed API, we call VirtualBox's API and * implement the vbox driver in a high level. * @@ -155,22 +153,22 @@ typedef struct { typedef struct { int (*Initialize)(vboxPrivate *data); void (*Uninitialize)(vboxPrivate *data); - void (*ComUnallocMem)(PCVBOXXPCOM pFuncs, void *pv); - void (*Utf16Free)(PCVBOXXPCOM pFuncs, PRUnichar *pwszString); - void (*Utf8Free)(PCVBOXXPCOM pFuncs, char *pszString); - int (*Utf16ToUtf8)(PCVBOXXPCOM pFuncs, const PRUnichar *pwszString, char **ppszString); - int (*Utf8ToUtf16)(PCVBOXXPCOM pFuncs, const char *pszString, PRUnichar **ppwszString); + void (*ComUnallocMem)(void *pv); + void (*Utf16Free)(PRUnichar *pwszString); + void (*Utf8Free)(char *pszString); + int (*Utf16ToUtf8)(const PRUnichar *pwszString, char **ppszString); + int (*Utf8ToUtf16)(const char *pszString, PRUnichar **ppwszString); } vboxUniformedPFN; /* Functions for vboxIID */ typedef struct { void (*vboxIIDInitialize)(vboxIIDUnion *iidu); - void (*vboxIIDUnalloc)(vboxPrivate *data, vboxIIDUnion *iidu); - void (*vboxIIDToUUID)(vboxPrivate *data, vboxIIDUnion *iidu, unsigned char *uuid); - void (*vboxIIDFromUUID)(vboxPrivate *data, vboxIIDUnion *iidu, const unsigned char *uuid); - bool (*vboxIIDIsEqual)(vboxPrivate *data, vboxIIDUnion *iidu1, vboxIIDUnion *iidu2); - void (*vboxIIDFromArrayItem)(vboxPrivate *data, vboxIIDUnion *iidu, vboxArray *array, int idx); - void (*vboxIIDToUtf8)(vboxPrivate *data, vboxIIDUnion *iidu, char **utf8); + void (*vboxIIDUnalloc)(vboxIIDUnion *iidu); + void (*vboxIIDToUUID)(vboxIIDUnion *iidu, unsigned char *uuid); + void (*vboxIIDFromUUID)(vboxIIDUnion *iidu, const unsigned char *uuid); + bool (*vboxIIDIsEqual)(vboxIIDUnion *iidu1, vboxIIDUnion *iidu2); + void (*vboxIIDFromArrayItem)(vboxIIDUnion *iidu, vboxArray *array, int idx); + void (*vboxIIDToUtf8)(vboxIIDUnion *iidu, char **utf8); void (*DEBUGIID)(const char *msg, vboxIIDUnion *iidu); } vboxUniformedIID; @@ -566,17 +564,17 @@ typedef struct { uint32_t XPCOMCVersion; /* vbox APIs */ int (*initializeDomainEvent)(vboxPrivate *data); - void (*registerGlobalData)(vboxPrivate *data); - void (*detachDevices)(vboxPrivate *data, IMachine *machine, PRUnichar *hddcnameUtf16); + vboxGlobalData* (*registerGlobalData)(void); + void (*detachDevices)(IMachine *machine, PRUnichar *hddcnameUtf16); nsresult (*unregisterMachine)(vboxPrivate *data, vboxIIDUnion *iidu, IMachine **machine); void (*deleteConfig)(IMachine *machine); void (*vboxAttachDrivesOld)(virDomainDefPtr def, vboxPrivate *data, IMachine *machine); virDomainState (*vboxConvertState)(PRUint32 state); - void (*dumpIDEHDDsOld)(virDomainDefPtr def, vboxPrivate *data, IMachine *machine); - void (*dumpDVD)(virDomainDefPtr def, vboxPrivate *data, IMachine *machine); + void (*dumpIDEHDDsOld)(virDomainDefPtr def, IMachine *machine); + void (*dumpDVD)(virDomainDefPtr def, IMachine *machine); int (*attachDVD)(vboxPrivate *data, IMachine *machine, const char *src); int (*detachDVD)(IMachine *machine); - void (*dumpFloppy)(virDomainDefPtr def, vboxPrivate *data, IMachine *machine); + void (*dumpFloppy)(virDomainDefPtr def, IMachine *machine); int (*attachFloppy)(vboxPrivate *data, IMachine *machine, const char *src); int (*detachFloppy)(IMachine *machine); int (*snapshotRestore)(virDomainPtr dom, IMachine *machine, ISnapshot *snapshot); @@ -613,7 +611,6 @@ typedef struct { uniformedMachineStateChecker machineStateChecker; /* vbox API features */ bool domainEventCallbacks; - bool hasStaticGlobalData; bool getMachineForSession; bool detachDevicesExplicitly; bool chipsetType; -- 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list