mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-11-03 11:51:11 +00:00
vbox: Rewrite vboxConnectNumOfNetworks
This commit is contained in:
parent
9e0637997f
commit
a8b1b043bf
@ -265,6 +265,19 @@ enum MediumVariant
|
|||||||
MediumVariant_Diff = 0x20000
|
MediumVariant_Diff = 0x20000
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum HostNetworkInterfaceStatus
|
||||||
|
{
|
||||||
|
HostNetworkInterfaceStatus_Unknown = 0,
|
||||||
|
HostNetworkInterfaceStatus_Up = 1,
|
||||||
|
HostNetworkInterfaceStatus_Down = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
enum HostNetworkInterfaceType
|
||||||
|
{
|
||||||
|
HostNetworkInterfaceType_Bridged = 1,
|
||||||
|
HostNetworkInterfaceType_HostOnly = 2
|
||||||
|
};
|
||||||
|
|
||||||
# define VBOX_E_OBJECT_NOT_FOUND 0x80BB0001
|
# define VBOX_E_OBJECT_NOT_FOUND 0x80BB0001
|
||||||
# define VBOX_E_INVALID_VM_STATE 0x80BB0002
|
# define VBOX_E_INVALID_VM_STATE 0x80BB0002
|
||||||
# define VBOX_E_VM_ERROR 0x80BB0003
|
# define VBOX_E_VM_ERROR 0x80BB0003
|
||||||
@ -302,5 +315,7 @@ typedef nsISupports IStorageController;
|
|||||||
typedef nsISupports ISharedFolder;
|
typedef nsISupports ISharedFolder;
|
||||||
typedef nsISupports ISnapshot;
|
typedef nsISupports ISnapshot;
|
||||||
typedef nsISupports IDisplay;
|
typedef nsISupports IDisplay;
|
||||||
|
typedef nsISupports IHost;
|
||||||
|
typedef nsISupports IHostNetworkInterface;
|
||||||
|
|
||||||
#endif /* VBOX_COMMON_H */
|
#endif /* VBOX_COMMON_H */
|
||||||
|
@ -33,6 +33,16 @@
|
|||||||
|
|
||||||
VIR_LOG_INIT("vbox.vbox_network");
|
VIR_LOG_INIT("vbox.vbox_network");
|
||||||
|
|
||||||
|
#define VBOX_RELEASE(arg) \
|
||||||
|
do { \
|
||||||
|
if (arg) { \
|
||||||
|
gVBoxAPI.nsUISupports.Release((void *)arg); \
|
||||||
|
(arg) = NULL; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
static vboxUniformedAPI gVBoxAPI;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The Network Functions here on
|
* The Network Functions here on
|
||||||
*/
|
*/
|
||||||
@ -65,3 +75,48 @@ int vboxNetworkClose(virConnectPtr conn)
|
|||||||
conn->networkPrivateData = NULL;
|
conn->networkPrivateData = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int vboxConnectNumOfNetworks(virConnectPtr conn)
|
||||||
|
{
|
||||||
|
vboxGlobalData *data = conn->privateData;
|
||||||
|
vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
|
||||||
|
IHost *host = NULL;
|
||||||
|
size_t i = 0;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
if (!data->vboxObj)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
gVBoxAPI.UIVirtualBox.GetHost(data->vboxObj, &host);
|
||||||
|
if (!host)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
gVBoxAPI.UArray.vboxArrayGet(&networkInterfaces, host,
|
||||||
|
gVBoxAPI.UArray.handleHostGetNetworkInterfaces(host));
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
for (i = 0; i < networkInterfaces.count; i++) {
|
||||||
|
IHostNetworkInterface *networkInterface = networkInterfaces.items[i];
|
||||||
|
PRUint32 status = HostNetworkInterfaceStatus_Unknown;
|
||||||
|
PRUint32 interfaceType = 0;
|
||||||
|
|
||||||
|
if (!networkInterface)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
gVBoxAPI.UIHNInterface.GetInterfaceType(networkInterface, &interfaceType);
|
||||||
|
if (interfaceType != HostNetworkInterfaceType_HostOnly)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
gVBoxAPI.UIHNInterface.GetStatus(networkInterface, &status);
|
||||||
|
|
||||||
|
if (status == HostNetworkInterfaceStatus_Up)
|
||||||
|
ret++;
|
||||||
|
}
|
||||||
|
|
||||||
|
gVBoxAPI.UArray.vboxArrayRelease(&networkInterfaces);
|
||||||
|
|
||||||
|
VBOX_RELEASE(host);
|
||||||
|
|
||||||
|
VIR_DEBUG("numActive: %d", ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
@ -2060,40 +2060,6 @@ _registerDomainEvent(virDriverPtr driver)
|
|||||||
* The Network Functions here on
|
* The Network Functions here on
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static int vboxConnectNumOfNetworks(virConnectPtr conn)
|
|
||||||
{
|
|
||||||
VBOX_OBJECT_HOST_CHECK(conn, int, 0);
|
|
||||||
vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
|
|
||||||
size_t i = 0;
|
|
||||||
|
|
||||||
vboxArrayGet(&networkInterfaces, host, host->vtbl->GetNetworkInterfaces);
|
|
||||||
|
|
||||||
for (i = 0; i < networkInterfaces.count; i++) {
|
|
||||||
IHostNetworkInterface *networkInterface = networkInterfaces.items[i];
|
|
||||||
|
|
||||||
if (networkInterface) {
|
|
||||||
PRUint32 interfaceType = 0;
|
|
||||||
|
|
||||||
networkInterface->vtbl->GetInterfaceType(networkInterface, &interfaceType);
|
|
||||||
if (interfaceType == HostNetworkInterfaceType_HostOnly) {
|
|
||||||
PRUint32 status = HostNetworkInterfaceStatus_Unknown;
|
|
||||||
|
|
||||||
networkInterface->vtbl->GetStatus(networkInterface, &status);
|
|
||||||
|
|
||||||
if (status == HostNetworkInterfaceStatus_Up)
|
|
||||||
ret++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vboxArrayRelease(&networkInterfaces);
|
|
||||||
|
|
||||||
VBOX_RELEASE(host);
|
|
||||||
|
|
||||||
VIR_DEBUG("numActive: %d", ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames) {
|
static int vboxConnectListNetworks(virConnectPtr conn, char **const names, int nnames) {
|
||||||
VBOX_OBJECT_HOST_CHECK(conn, int, 0);
|
VBOX_OBJECT_HOST_CHECK(conn, int, 0);
|
||||||
vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
|
vboxArray networkInterfaces = VBOX_ARRAY_INITIALIZER;
|
||||||
@ -4501,6 +4467,11 @@ static void* _handleMediumGetSnapshotIds(IMedium *medium)
|
|||||||
return medium->vtbl->GetSnapshotIds;
|
return medium->vtbl->GetSnapshotIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void* _handleHostGetNetworkInterfaces(IHost *host)
|
||||||
|
{
|
||||||
|
return host->vtbl->GetNetworkInterfaces;
|
||||||
|
}
|
||||||
|
|
||||||
static nsresult _nsisupportsRelease(nsISupports *nsi)
|
static nsresult _nsisupportsRelease(nsISupports *nsi)
|
||||||
{
|
{
|
||||||
return nsi->vtbl->Release(nsi);
|
return nsi->vtbl->Release(nsi);
|
||||||
@ -4547,6 +4518,12 @@ _virtualboxGetSystemProperties(IVirtualBox *vboxObj, ISystemProperties **systemP
|
|||||||
return vboxObj->vtbl->GetSystemProperties(vboxObj, systemProperties);
|
return vboxObj->vtbl->GetSystemProperties(vboxObj, systemProperties);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static nsresult
|
||||||
|
_virtualboxGetHost(IVirtualBox *vboxObj, IHost **host)
|
||||||
|
{
|
||||||
|
return vboxObj->vtbl->GetHost(vboxObj, host);
|
||||||
|
}
|
||||||
|
|
||||||
static nsresult
|
static nsresult
|
||||||
_virtualboxCreateMachine(vboxGlobalData *data, virDomainDefPtr def, IMachine **machine, char *uuidstr ATTRIBUTE_UNUSED)
|
_virtualboxCreateMachine(vboxGlobalData *data, virDomainDefPtr def, IMachine **machine, char *uuidstr ATTRIBUTE_UNUSED)
|
||||||
{
|
{
|
||||||
@ -6043,6 +6020,18 @@ _displayTakeScreenShotPNGToArray(IDisplay *display ATTRIBUTE_UNUSED,
|
|||||||
#endif /* VBOX_API_VERSION >= 4000000 */
|
#endif /* VBOX_API_VERSION >= 4000000 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static nsresult
|
||||||
|
_hnInterfaceGetInterfaceType(IHostNetworkInterface *hni, PRUint32 *interfaceType)
|
||||||
|
{
|
||||||
|
return hni->vtbl->GetInterfaceType(hni, interfaceType);
|
||||||
|
}
|
||||||
|
|
||||||
|
static nsresult
|
||||||
|
_hnInterfaceGetStatus(IHostNetworkInterface *hni, PRUint32 *status)
|
||||||
|
{
|
||||||
|
return hni->vtbl->GetStatus(hni, status);
|
||||||
|
}
|
||||||
|
|
||||||
static bool _machineStateOnline(PRUint32 state)
|
static bool _machineStateOnline(PRUint32 state)
|
||||||
{
|
{
|
||||||
return ((state >= MachineState_FirstOnline) &&
|
return ((state >= MachineState_FirstOnline) &&
|
||||||
@ -6109,6 +6098,7 @@ static vboxUniformedArray _UArray = {
|
|||||||
.handleSnapshotGetChildren = _handleSnapshotGetChildren,
|
.handleSnapshotGetChildren = _handleSnapshotGetChildren,
|
||||||
.handleMediumGetChildren = _handleMediumGetChildren,
|
.handleMediumGetChildren = _handleMediumGetChildren,
|
||||||
.handleMediumGetSnapshotIds = _handleMediumGetSnapshotIds,
|
.handleMediumGetSnapshotIds = _handleMediumGetSnapshotIds,
|
||||||
|
.handleHostGetNetworkInterfaces = _handleHostGetNetworkInterfaces,
|
||||||
};
|
};
|
||||||
|
|
||||||
static vboxUniformednsISupports _nsUISupports = {
|
static vboxUniformednsISupports _nsUISupports = {
|
||||||
@ -6121,6 +6111,7 @@ static vboxUniformedIVirtualBox _UIVirtualBox = {
|
|||||||
.GetMachine = _virtualboxGetMachine,
|
.GetMachine = _virtualboxGetMachine,
|
||||||
.OpenMachine = _virtualboxOpenMachine,
|
.OpenMachine = _virtualboxOpenMachine,
|
||||||
.GetSystemProperties = _virtualboxGetSystemProperties,
|
.GetSystemProperties = _virtualboxGetSystemProperties,
|
||||||
|
.GetHost = _virtualboxGetHost,
|
||||||
.CreateMachine = _virtualboxCreateMachine,
|
.CreateMachine = _virtualboxCreateMachine,
|
||||||
.CreateHardDiskMedium = _virtualboxCreateHardDiskMedium,
|
.CreateHardDiskMedium = _virtualboxCreateHardDiskMedium,
|
||||||
.RegisterMachine = _virtualboxRegisterMachine,
|
.RegisterMachine = _virtualboxRegisterMachine,
|
||||||
@ -6344,6 +6335,11 @@ static vboxUniformedIDisplay _UIDisplay = {
|
|||||||
.TakeScreenShotPNGToArray = _displayTakeScreenShotPNGToArray,
|
.TakeScreenShotPNGToArray = _displayTakeScreenShotPNGToArray,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static vboxUniformedIHNInterface _UIHNInterface = {
|
||||||
|
.GetInterfaceType = _hnInterfaceGetInterfaceType,
|
||||||
|
.GetStatus = _hnInterfaceGetStatus,
|
||||||
|
};
|
||||||
|
|
||||||
static uniformedMachineStateChecker _machineStateChecker = {
|
static uniformedMachineStateChecker _machineStateChecker = {
|
||||||
.Online = _machineStateOnline,
|
.Online = _machineStateOnline,
|
||||||
.Inactive = _machineStateInactive,
|
.Inactive = _machineStateInactive,
|
||||||
@ -6397,6 +6393,7 @@ void NAME(InstallUniformedAPI)(vboxUniformedAPI *pVBoxAPI)
|
|||||||
pVBoxAPI->UISharedFolder = _UISharedFolder;
|
pVBoxAPI->UISharedFolder = _UISharedFolder;
|
||||||
pVBoxAPI->UISnapshot = _UISnapshot;
|
pVBoxAPI->UISnapshot = _UISnapshot;
|
||||||
pVBoxAPI->UIDisplay = _UIDisplay;
|
pVBoxAPI->UIDisplay = _UIDisplay;
|
||||||
|
pVBoxAPI->UIHNInterface = _UIHNInterface;
|
||||||
pVBoxAPI->machineStateChecker = _machineStateChecker;
|
pVBoxAPI->machineStateChecker = _machineStateChecker;
|
||||||
|
|
||||||
#if VBOX_API_VERSION <= 2002000 || VBOX_API_VERSION >= 4000000
|
#if VBOX_API_VERSION <= 2002000 || VBOX_API_VERSION >= 4000000
|
||||||
|
@ -176,6 +176,7 @@ typedef struct {
|
|||||||
void* (*handleSnapshotGetChildren)(ISnapshot *snapshot);
|
void* (*handleSnapshotGetChildren)(ISnapshot *snapshot);
|
||||||
void* (*handleMediumGetChildren)(IMedium *medium);
|
void* (*handleMediumGetChildren)(IMedium *medium);
|
||||||
void* (*handleMediumGetSnapshotIds)(IMedium *medium);
|
void* (*handleMediumGetSnapshotIds)(IMedium *medium);
|
||||||
|
void* (*handleHostGetNetworkInterfaces)(IHost *host);
|
||||||
} vboxUniformedArray;
|
} vboxUniformedArray;
|
||||||
|
|
||||||
/* Functions for nsISupports */
|
/* Functions for nsISupports */
|
||||||
@ -190,6 +191,7 @@ typedef struct {
|
|||||||
nsresult (*GetMachine)(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IMachine **machine);
|
nsresult (*GetMachine)(IVirtualBox *vboxObj, vboxIIDUnion *iidu, IMachine **machine);
|
||||||
nsresult (*OpenMachine)(IVirtualBox *vboxObj, PRUnichar *settingsFile, IMachine **machine);
|
nsresult (*OpenMachine)(IVirtualBox *vboxObj, PRUnichar *settingsFile, IMachine **machine);
|
||||||
nsresult (*GetSystemProperties)(IVirtualBox *vboxObj, ISystemProperties **systemProperties);
|
nsresult (*GetSystemProperties)(IVirtualBox *vboxObj, ISystemProperties **systemProperties);
|
||||||
|
nsresult (*GetHost)(IVirtualBox *vboxObj, IHost **host);
|
||||||
nsresult (*CreateMachine)(vboxGlobalData *data, virDomainDefPtr def, IMachine **machine, char *uuidstr);
|
nsresult (*CreateMachine)(vboxGlobalData *data, virDomainDefPtr def, IMachine **machine, char *uuidstr);
|
||||||
nsresult (*CreateHardDiskMedium)(IVirtualBox *vboxObj, PRUnichar *format, PRUnichar *location, IMedium **medium);
|
nsresult (*CreateHardDiskMedium)(IVirtualBox *vboxObj, PRUnichar *format, PRUnichar *location, IMedium **medium);
|
||||||
nsresult (*RegisterMachine)(IVirtualBox *vboxObj, IMachine *machine);
|
nsresult (*RegisterMachine)(IVirtualBox *vboxObj, IMachine *machine);
|
||||||
@ -464,6 +466,12 @@ typedef struct {
|
|||||||
PRUint8** screenData);
|
PRUint8** screenData);
|
||||||
} vboxUniformedIDisplay;
|
} vboxUniformedIDisplay;
|
||||||
|
|
||||||
|
/* Functions for IHostNetworkInterface */
|
||||||
|
typedef struct {
|
||||||
|
nsresult (*GetInterfaceType)(IHostNetworkInterface *hni, PRUint32 *interfaceType);
|
||||||
|
nsresult (*GetStatus)(IHostNetworkInterface *hni, PRUint32 *status);
|
||||||
|
} vboxUniformedIHNInterface;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
bool (*Online)(PRUint32 state);
|
bool (*Online)(PRUint32 state);
|
||||||
bool (*Inactive)(PRUint32 state);
|
bool (*Inactive)(PRUint32 state);
|
||||||
@ -518,6 +526,7 @@ typedef struct {
|
|||||||
vboxUniformedISharedFolder UISharedFolder;
|
vboxUniformedISharedFolder UISharedFolder;
|
||||||
vboxUniformedISnapshot UISnapshot;
|
vboxUniformedISnapshot UISnapshot;
|
||||||
vboxUniformedIDisplay UIDisplay;
|
vboxUniformedIDisplay UIDisplay;
|
||||||
|
vboxUniformedIHNInterface UIHNInterface;
|
||||||
uniformedMachineStateChecker machineStateChecker;
|
uniformedMachineStateChecker machineStateChecker;
|
||||||
/* vbox API features */
|
/* vbox API features */
|
||||||
bool domainEventCallbacks;
|
bool domainEventCallbacks;
|
||||||
@ -538,6 +547,7 @@ virDrvOpenStatus vboxNetworkOpen(virConnectPtr conn,
|
|||||||
virConnectAuthPtr auth,
|
virConnectAuthPtr auth,
|
||||||
unsigned int flags);
|
unsigned int flags);
|
||||||
int vboxNetworkClose(virConnectPtr conn);
|
int vboxNetworkClose(virConnectPtr conn);
|
||||||
|
int vboxConnectNumOfNetworks(virConnectPtr conn);
|
||||||
|
|
||||||
/* Version specified functions for installing uniformed API */
|
/* Version specified functions for installing uniformed API */
|
||||||
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
|
||||||
|
Loading…
Reference in New Issue
Block a user