提交 2af93cd4 编写于 作者: E Eric Blake

vbox: factor a large function

* src/vbox/vbox_tmpl.c (vboxDomainDefineXML): Split...
(vboxSetBootDeviceOrder, vboxAttachDrives, vboxAttachSound)
(vboxAttachNetwork, vboxAttachSerial, vboxAttachParallel)
(vboxAttachVideo, vboxAttachDisplay, vboxAttachUSB): ...into new
helper functions.
上级 f694036f
......@@ -3379,129 +3379,10 @@ static int vboxDomainCreate(virDomainPtr dom) {
return vboxDomainCreateWithFlags(dom, 0);
}
static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
VBOX_OBJECT_CHECK(conn, virDomainPtr, NULL);
IMachine *machine = NULL;
IBIOSSettings *bios = NULL;
vboxIID *iid = NULL;
vboxIID *mchiid = NULL;
virDomainDefPtr def = NULL;
PRUnichar *machineNameUtf16 = NULL;
#if VBOX_API_VERSION >= 3002
PRBool override = PR_FALSE;
#endif
nsresult rc;
if (!(def = virDomainDefParseString(data->caps, xml,
VIR_DOMAIN_XML_INACTIVE))) {
goto cleanup;
}
#if VBOX_API_VERSION == 2002
if (VIR_ALLOC(iid) < 0) {
virReportOOMError();
goto cleanup;
}
#endif
VBOX_UTF8_TO_UTF16(def->name, &machineNameUtf16);
vboxIIDFromUUID(def->uuid, iid);
#if VBOX_API_VERSION < 3002
rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj,
machineNameUtf16,
NULL,
NULL,
iid,
&machine);
#else /* VBOX_API_VERSION >= 3002 */
rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj,
machineNameUtf16,
NULL,
NULL,
iid,
override,
&machine);
#endif /* VBOX_API_VERSION >= 3002 */
VBOX_UTF16_FREE(machineNameUtf16);
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("could not define a domain, rc=%08x"), (unsigned)rc);
goto cleanup;
}
rc = machine->vtbl->SetMemorySize(machine, def->memory / 1024);
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("could not set the memory size of the domain to: %lu Kb, "
"rc=%08x"),
def->memory, (unsigned)rc);
}
rc = machine->vtbl->SetCPUCount(machine, def->vcpus);
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("could not set the number of virtual CPUs to: %lu, rc=%08x"),
def->vcpus, (unsigned)rc);
}
#if VBOX_API_VERSION < 3001
rc = machine->vtbl->SetPAEEnabled(machine, (def->features) &
(1 << VIR_DOMAIN_FEATURE_PAE));
#elif VBOX_API_VERSION == 3001
rc = machine->vtbl->SetCpuProperty(machine, CpuPropertyType_PAE,
(def->features) &
(1 << VIR_DOMAIN_FEATURE_PAE));
#elif VBOX_API_VERSION >= 3002
rc = machine->vtbl->SetCPUProperty(machine, CPUPropertyType_PAE,
(def->features) &
(1 << VIR_DOMAIN_FEATURE_PAE));
#endif
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("could not change PAE status to: %s, rc=%08x"),
((def->features) & (1 << VIR_DOMAIN_FEATURE_PAE))
? _("Enabled") : _("Disabled"), (unsigned)rc);
}
machine->vtbl->GetBIOSSettings(machine, &bios);
if (bios) {
rc = bios->vtbl->SetACPIEnabled(bios, (def->features) &
(1 << VIR_DOMAIN_FEATURE_ACPI));
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("could not change ACPI status to: %s, rc=%08x"),
((def->features) & (1 << VIR_DOMAIN_FEATURE_ACPI))
? _("Enabled") : _("Disabled"), (unsigned)rc);
}
rc = bios->vtbl->SetIOAPICEnabled(bios, (def->features) &
(1 << VIR_DOMAIN_FEATURE_APIC));
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("could not change APIC status to: %s, rc=%08x"),
((def->features) & (1 << VIR_DOMAIN_FEATURE_APIC))
? _("Enabled") : _("Disabled"), (unsigned)rc);
}
VBOX_RELEASE(bios);
}
/* Register the machine before attaching other devices to it */
rc = data->vboxObj->vtbl->RegisterMachine(data->vboxObj, machine);
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("could not define a domain, rc=%08x"), (unsigned)rc);
goto cleanup;
}
/* Get the uuid of the machine, currently it is immutable
* object so open a session to it and get it back, so that
* you can make changes to the machine setting
*/
machine->vtbl->GetId(machine, &mchiid);
data->vboxObj->vtbl->OpenSession(data->vboxObj, data->vboxSession, mchiid);
data->vboxSession->vtbl->GetMachine(data->vboxSession, &machine);
{ /* Started:Block to set the boot device order */
static void
vboxSetBootDeviceOrder(virDomainDefPtr def, vboxGlobalData *data,
IMachine *machine)
{
ISystemProperties *systemProperties = NULL;
PRUint32 maxBootPosition = 0;
int i = 0;
......@@ -3525,7 +3406,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
data->vboxObj->vtbl->GetSystemProperties(data->vboxObj, &systemProperties);
if (systemProperties) {
systemProperties->vtbl->GetMaxBootPosition(systemProperties, &maxBootPosition);
systemProperties->vtbl->GetMaxBootPosition(systemProperties,
&maxBootPosition);
VBOX_RELEASE(systemProperties);
systemProperties = NULL;
}
......@@ -3549,13 +3431,17 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
}
machine->vtbl->SetBootOrder(machine, i+1, device);
}
} /* Finished:Block to set the boot device order */
#if VBOX_API_VERSION < 3001
{ /* Started:Block to attach the CDROM/DVD Drive and HardDisks to the VM */
}
if (def->ndisks > 0) {
static void
vboxAttachDrives(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
{
int i;
nsresult rc;
#if VBOX_API_VERSION < 3001
if (def->ndisks == 0)
return;
for (i = 0; i < def->ndisks; i++) {
DEBUG("disk(%d) type: %d", i, def->disks[i]->type);
......@@ -3566,8 +3452,10 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
DEBUG("disk(%d) driverName: %s", i, def->disks[i]->driverName);
DEBUG("disk(%d) driverType: %s", i, def->disks[i]->driverType);
DEBUG("disk(%d) cachemode: %d", i, def->disks[i]->cachemode);
DEBUG("disk(%d) readonly: %s", i, def->disks[i]->readonly ? "True" : "False");
DEBUG("disk(%d) shared: %s", i, def->disks[i]->shared ? "True" : "False");
DEBUG("disk(%d) readonly: %s", i, (def->disks[i]->readonly
? "True" : "False"));
DEBUG("disk(%d) shared: %s", i, (def->disks[i]->shared
? "True" : "False"));
if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
if (def->disks[i]->type == VIR_DOMAIN_DISK_TYPE_FILE &&
......@@ -3595,16 +3483,24 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
VBOX_UTF8_TO_UTF16(def->disks[i]->src, &dvdfileUtf16);
data->vboxObj->vtbl->FindDVDImage(data->vboxObj, dvdfileUtf16, &dvdImage);
data->vboxObj->vtbl->FindDVDImage(data->vboxObj,
dvdfileUtf16, &dvdImage);
if (!dvdImage) {
# if VBOX_API_VERSION == 2002
data->vboxObj->vtbl->OpenDVDImage(data->vboxObj, dvdfileUtf16, &dvdemptyuuid, &dvdImage);
data->vboxObj->vtbl->OpenDVDImage(data->vboxObj,
dvdfileUtf16,
&dvdemptyuuid,
&dvdImage);
# else
data->vboxObj->vtbl->OpenDVDImage(data->vboxObj, dvdfileUtf16, dvdemptyuuidUtf16, &dvdImage);
data->vboxObj->vtbl->OpenDVDImage(data->vboxObj,
dvdfileUtf16,
dvdemptyuuidUtf16,
&dvdImage);
# endif
}
if (dvdImage) {
rc = dvdImage->vtbl->imedium.GetId((IMedium *)dvdImage, &dvduuid);
rc = dvdImage->vtbl->imedium.GetId((IMedium *)dvdImage,
&dvduuid);
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("can't get the uuid of the file to "
......@@ -3645,7 +3541,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
VBOX_UTF8_TO_UTF16(def->disks[i]->src, &hddfileUtf16);
VBOX_UTF8_TO_UTF16("", &hddEmpty);
data->vboxObj->vtbl->FindHardDisk(data->vboxObj, hddfileUtf16, &hardDisk);
data->vboxObj->vtbl->FindHardDisk(data->vboxObj, hddfileUtf16,
&hardDisk);
if (!hardDisk) {
# if VBOX_API_VERSION == 2002
......@@ -3666,7 +3563,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
}
if (hardDisk) {
rc = hardDisk->vtbl->imedium.GetId((IMedium *)hardDisk, &hdduuid);
rc = hardDisk->vtbl->imedium.GetId((IMedium *)hardDisk,
&hdduuid);
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("can't get the uuid of the file to be "
......@@ -3674,10 +3572,12 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
def->disks[i]->src, (unsigned)rc);
} else {
if (def->disks[i]->readonly) {
hardDisk->vtbl->SetType(hardDisk, HardDiskType_Immutable);
hardDisk->vtbl->SetType(hardDisk,
HardDiskType_Immutable);
DEBUG0("setting harddisk to readonly");
} else if (!def->disks[i]->readonly) {
hardDisk->vtbl->SetType(hardDisk, HardDiskType_Normal);
hardDisk->vtbl->SetType(hardDisk,
HardDiskType_Normal);
DEBUG0("setting harddisk type to normal");
}
if (def->disks[i]->bus == VIR_DOMAIN_DISK_BUS_IDE) {
......@@ -3765,14 +3665,16 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
}
if (floppyImage) {
rc = floppyImage->vtbl->imedium.GetId((IMedium *)floppyImage, &fduuid);
rc = floppyImage->vtbl->imedium.GetId((IMedium *)floppyImage,
&fduuid);
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("can't get the uuid of the file to "
"be attached to floppy drive: %s, rc=%08x"),
def->disks[i]->src, (unsigned)rc);
} else {
rc = floppyDrive->vtbl->MountImage(floppyDrive, fduuid);
rc = floppyDrive->vtbl->MountImage(floppyDrive,
fduuid);
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("could not attach the file to "
......@@ -3793,23 +3695,19 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
}
}
}
}
} /* Finished:Block to attach the CDROM/DVD Drive and HardDisks to the VM */
#else /* VBOX_API_VERSION >= 3001 */
{
PRUint32 maxPortPerInst[StorageBus_Floppy + 1] = {};
PRUint32 maxSlotPerPort[StorageBus_Floppy + 1] = {};
PRUnichar *storageCtlName = NULL;
bool error = false;
int i = 0;
/* get the max port/slots/etc for the given storage bus */
error = !vboxGetMaxPortSlotValues(data->vboxObj, maxPortPerInst, maxSlotPerPort);
error = !vboxGetMaxPortSlotValues(data->vboxObj, maxPortPerInst,
maxSlotPerPort);
/* add a storage controller for the mediums to be attached */
/* this needs to change when multiple controller are supported for ver > 3.1 */
/* this needs to change when multiple controller are supported for
* ver > 3.1 */
{
IStorageController *storageCtl = NULL;
PRUnichar *sName = NULL;
......@@ -3847,7 +3745,6 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
VBOX_RELEASE(storageCtl);
}
/* Started:Block to attach the CDROM/DVD Drive and HardDisks to the VM */
for (i = 0; i < def->ndisks && !error; i++) {
DEBUG("disk(%d) type: %d", i, def->disks[i]->type);
DEBUG("disk(%d) device: %d", i, def->disks[i]->device);
......@@ -3857,8 +3754,10 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
DEBUG("disk(%d) driverName: %s", i, def->disks[i]->driverName);
DEBUG("disk(%d) driverType: %s", i, def->disks[i]->driverType);
DEBUG("disk(%d) cachemode: %d", i, def->disks[i]->cachemode);
DEBUG("disk(%d) readonly: %s", i, def->disks[i]->readonly ? "True" : "False");
DEBUG("disk(%d) shared: %s", i, def->disks[i]->shared ? "True" : "False");
DEBUG("disk(%d) readonly: %s", i, (def->disks[i]->readonly
? "True" : "False"));
DEBUG("disk(%d) shared: %s", i, (def->disks[i]->shared
? "True" : "False"));
if (def->disks[i]->type == VIR_DOMAIN_DISK_TYPE_FILE &&
def->disks[i]->src != NULL) {
......@@ -3875,13 +3774,16 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_DISK) {
deviceType = DeviceType_HardDisk;
data->vboxObj->vtbl->FindHardDisk(data->vboxObj, mediumFileUtf16, &medium);
data->vboxObj->vtbl->FindHardDisk(data->vboxObj,
mediumFileUtf16, &medium);
} else if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
deviceType = DeviceType_DVD;
data->vboxObj->vtbl->FindDVDImage(data->vboxObj, mediumFileUtf16, &medium);
data->vboxObj->vtbl->FindDVDImage(data->vboxObj,
mediumFileUtf16, &medium);
} else if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
deviceType = DeviceType_Floppy;
data->vboxObj->vtbl->FindFloppyImage(data->vboxObj, mediumFileUtf16, &medium);
data->vboxObj->vtbl->FindFloppyImage(data->vboxObj,
mediumFileUtf16, &medium);
} else {
VBOX_UTF16_FREE(mediumFileUtf16);
continue;
......@@ -3901,12 +3803,14 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
false,
mediumEmpty,
&medium);
} else if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
} else if (def->disks[i]->device ==
VIR_DOMAIN_DISK_DEVICE_CDROM) {
data->vboxObj->vtbl->OpenDVDImage(data->vboxObj,
mediumFileUtf16,
mediumEmpty,
&medium);
} else if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
} else if (def->disks[i]->device ==
VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
data->vboxObj->vtbl->OpenFloppyImage(data->vboxObj,
mediumFileUtf16,
mediumEmpty,
......@@ -4001,11 +3905,14 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
VBOX_UTF16_FREE(storageCtlName);
}
}
}
/* Finished:Block to attach the CDROM/DVD Drive and HardDisks to the VM */
#endif /* VBOX_API_VERSION >= 3001 */
}
static void
vboxAttachSound(virDomainDefPtr def, IMachine *machine)
{
nsresult rc;
{ /* Started:Block to attach the Sound Controller to the VM */
/* Check if def->nsounds is one as VirtualBox currently supports
* only one sound card
*/
......@@ -4017,24 +3924,29 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
rc = audioAdapter->vtbl->SetEnabled(audioAdapter, 1);
if (NS_SUCCEEDED(rc)) {
if (def->sounds[0]->model == VIR_DOMAIN_SOUND_MODEL_SB16) {
audioAdapter->vtbl->SetAudioController(audioAdapter, AudioControllerType_SB16);
audioAdapter->vtbl->SetAudioController(audioAdapter,
AudioControllerType_SB16);
} else if (def->sounds[0]->model == VIR_DOMAIN_SOUND_MODEL_AC97) {
audioAdapter->vtbl->SetAudioController(audioAdapter, AudioControllerType_AC97);
audioAdapter->vtbl->SetAudioController(audioAdapter,
AudioControllerType_AC97);
}
}
VBOX_RELEASE(audioAdapter);
}
}
} /* Finished:Block to attach the Sound Controller to the VM */
}
{ /* Started:Block to attach the Network Card to the VM */
static void
vboxAttachNetwork(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
{
ISystemProperties *systemProperties = NULL;
PRUint32 networkAdapterCount = 0;
int i = 0;
data->vboxObj->vtbl->GetSystemProperties(data->vboxObj, &systemProperties);
if (systemProperties) {
systemProperties->vtbl->GetNetworkAdapterCount(systemProperties, &networkAdapterCount);
systemProperties->vtbl->GetNetworkAdapterCount(systemProperties,
&networkAdapterCount);
VBOX_RELEASE(systemProperties);
systemProperties = NULL;
}
......@@ -4110,7 +4022,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
adapter->vtbl->AttachToBridgedInterface(adapter);
if (def->nets[i]->data.bridge.brname) {
VBOX_UTF8_TO_UTF16(def->nets[i]->data.bridge.brname, &hostInterface);
VBOX_UTF8_TO_UTF16(def->nets[i]->data.bridge.brname,
&hostInterface);
adapter->vtbl->SetHostInterface(adapter, hostInterface);
VBOX_UTF16_FREE(hostInterface);
}
......@@ -4121,7 +4034,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
adapter->vtbl->AttachToInternalNetwork(adapter);
if (def->nets[i]->data.internal.name) {
VBOX_UTF8_TO_UTF16(def->nets[i]->data.internal.name, &internalNetwork);
VBOX_UTF8_TO_UTF16(def->nets[i]->data.internal.name,
&internalNetwork);
adapter->vtbl->SetInternalNetwork(adapter, internalNetwork);
VBOX_UTF16_FREE(internalNetwork);
}
......@@ -4134,7 +4048,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
adapter->vtbl->AttachToHostOnlyInterface(adapter);
if (def->nets[i]->data.network.name) {
VBOX_UTF8_TO_UTF16(def->nets[i]->data.network.name, &hostInterface);
VBOX_UTF8_TO_UTF16(def->nets[i]->data.network.name,
&hostInterface);
adapter->vtbl->SetHostInterface(adapter, hostInterface);
VBOX_UTF16_FREE(hostInterface);
}
......@@ -4153,16 +4068,19 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
VBOX_UTF16_FREE(MACAddress);
}
}
} /* Finished:Block to attach the Network Card to the VM */
}
{ /* Started:Block to attach the Serial Port to the VM */
static void
vboxAttachSerial(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
{
ISystemProperties *systemProperties = NULL;
PRUint32 serialPortCount = 0;
int i = 0;
data->vboxObj->vtbl->GetSystemProperties(data->vboxObj, &systemProperties);
if (systemProperties) {
systemProperties->vtbl->GetSerialPortCount(systemProperties, &serialPortCount);
systemProperties->vtbl->GetSerialPortCount(systemProperties,
&serialPortCount);
VBOX_RELEASE(systemProperties);
systemProperties = NULL;
}
......@@ -4173,7 +4091,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
ISerialPort *serialPort = NULL;
DEBUG("SerialPort(%d): Type: %d", i, def->serials[i]->type);
DEBUG("SerialPort(%d): target.port: %d", i, def->serials[i]->target.port);
DEBUG("SerialPort(%d): target.port: %d", i,
def->serials[i]->target.port);
machine->vtbl->GetSerialPort(machine, i, &serialPort);
if (serialPort) {
......@@ -4216,7 +4135,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
serialPort->vtbl->SetHostMode(serialPort, PortMode_RawFile);
#endif /* VBOX_API_VERSION >= 3000 */
} else {
serialPort->vtbl->SetHostMode(serialPort, PortMode_Disconnected);
serialPort->vtbl->SetHostMode(serialPort,
PortMode_Disconnected);
}
VBOX_RELEASE(serialPort);
......@@ -4226,16 +4146,19 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
}
}
}
} /* Finished:Block to attach the Serial Port to the VM */
}
{ /* Started:Block to attach the Parallel Port to the VM */
static void
vboxAttachParallel(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
{
ISystemProperties *systemProperties = NULL;
PRUint32 parallelPortCount = 0;
int i = 0;
data->vboxObj->vtbl->GetSystemProperties(data->vboxObj, &systemProperties);
if (systemProperties) {
systemProperties->vtbl->GetParallelPortCount(systemProperties, &parallelPortCount);
systemProperties->vtbl->GetParallelPortCount(systemProperties,
&parallelPortCount);
VBOX_RELEASE(systemProperties);
systemProperties = NULL;
}
......@@ -4246,7 +4169,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
IParallelPort *parallelPort = NULL;
DEBUG("ParallelPort(%d): Type: %d", i, def->parallels[i]->type);
DEBUG("ParallelPort(%d): target.port: %d", i, def->parallels[i]->target.port);
DEBUG("ParallelPort(%d): target.port: %d", i,
def->parallels[i]->target.port);
machine->vtbl->GetParallelPort(machine, i, &parallelPort);
if (parallelPort) {
......@@ -4289,16 +4213,21 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
}
}
}
} /* Finished:Block to attach the Parallel Port to the VM */
}
{ /* Started:Block to specify video card settings */
if ((def->nvideos == 1) && (def->videos[0]->type == VIR_DOMAIN_VIDEO_TYPE_VBOX)) {
static void
vboxAttachVideo(virDomainDefPtr def, IMachine *machine)
{
if ((def->nvideos == 1) &&
(def->videos[0]->type == VIR_DOMAIN_VIDEO_TYPE_VBOX)) {
machine->vtbl->SetVRAMSize(machine, def->videos[0]->vram);
machine->vtbl->SetMonitorCount(machine, def->videos[0]->heads);
if (def->videos[0]->accel) {
machine->vtbl->SetAccelerate3DEnabled(machine, def->videos[0]->accel->support3d);
machine->vtbl->SetAccelerate3DEnabled(machine,
def->videos[0]->accel->support3d);
#if VBOX_API_VERSION >= 3001
machine->vtbl->SetAccelerate2DVideoEnabled(machine, def->videos[0]->accel->support2d);
machine->vtbl->SetAccelerate2DVideoEnabled(machine,
def->videos[0]->accel->support2d);
#endif /* VBOX_API_VERSION >= 3001 */
} else {
machine->vtbl->SetAccelerate3DEnabled(machine, 0);
......@@ -4307,9 +4236,11 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
#endif /* VBOX_API_VERSION >= 3001 */
}
}
} /* Finished:Block to specify video card settings */
}
{ /* Started:Block to attach the Remote Display to VM */
static void
vboxAttachDisplay(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
{
int vrdpPresent = 0;
int sdlPresent = 0;
int guiPresent = 0;
......@@ -4320,7 +4251,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
for (i = 0; i < def->ngraphics; i++) {
IVRDPServer *VRDPServer = NULL;
if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_RDP) && (vrdpPresent == 0)) {
if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_RDP) &&
(vrdpPresent == 0)) {
vrdpPresent = 1;
machine->vtbl->GetVRDPServer(machine, &VRDPServer);
......@@ -4330,8 +4262,10 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
#if VBOX_API_VERSION < 3001
if (def->graphics[i]->data.rdp.port) {
VRDPServer->vtbl->SetPort(VRDPServer, def->graphics[i]->data.rdp.port);
DEBUG("VRDP Port changed to: %d", def->graphics[i]->data.rdp.port);
VRDPServer->vtbl->SetPort(VRDPServer,
def->graphics[i]->data.rdp.port);
DEBUG("VRDP Port changed to: %d",
def->graphics[i]->data.rdp.port);
} else if (def->graphics[i]->data.rdp.autoport) {
/* Setting the port to 0 will reset its value to
* the default one which is 3389 currently
......@@ -4347,21 +4281,26 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
#endif /* VBOX_API_VERSION >= 3001 */
if (def->graphics[i]->data.rdp.replaceUser) {
VRDPServer->vtbl->SetReuseSingleConnection(VRDPServer, PR_TRUE);
VRDPServer->vtbl->SetReuseSingleConnection(VRDPServer,
PR_TRUE);
DEBUG0("VRDP set to reuse single connection");
}
if (def->graphics[i]->data.rdp.multiUser) {
VRDPServer->vtbl->SetAllowMultiConnection(VRDPServer, PR_TRUE);
VRDPServer->vtbl->SetAllowMultiConnection(VRDPServer,
PR_TRUE);
DEBUG0("VRDP set to allow multiple connection");
}
if (def->graphics[i]->data.rdp.listenAddr) {
PRUnichar *netAddressUtf16 = NULL;
VBOX_UTF8_TO_UTF16(def->graphics[i]->data.rdp.listenAddr, &netAddressUtf16);
VRDPServer->vtbl->SetNetAddress(VRDPServer, netAddressUtf16);
DEBUG("VRDP listen address is set to: %s", def->graphics[i]->data.rdp.listenAddr);
VBOX_UTF8_TO_UTF16(def->graphics[i]->data.rdp.listenAddr,
&netAddressUtf16);
VRDPServer->vtbl->SetNetAddress(VRDPServer,
netAddressUtf16);
DEBUG("VRDP listen address is set to: %s",
def->graphics[i]->data.rdp.listenAddr);
VBOX_UTF16_FREE(netAddressUtf16);
}
......@@ -4370,7 +4309,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
}
}
if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP) && (guiPresent == 0)) {
if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_DESKTOP) &&
(guiPresent == 0)) {
guiPresent = 1;
if (def->graphics[i]->data.desktop.display) {
guiDisplay = strdup(def->graphics[i]->data.desktop.display);
......@@ -4384,7 +4324,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
}
}
if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) && (sdlPresent == 0)) {
if ((def->graphics[i]->type == VIR_DOMAIN_GRAPHICS_TYPE_SDL) &&
(sdlPresent == 0)) {
sdlPresent = 1;
if (def->graphics[i]->data.sdl.display) {
sdlDisplay = strdup(def->graphics[i]->data.sdl.display);
......@@ -4431,7 +4372,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
VBOX_UTF8_TO_UTF16("FRONTEND/Display", &keyDislpayUtf16);
VBOX_UTF8_TO_UTF16(sdlDisplay, &valueDisplayUtf16);
machine->vtbl->SetExtraData(machine, keyDislpayUtf16, valueDisplayUtf16);
machine->vtbl->SetExtraData(machine, keyDislpayUtf16,
valueDisplayUtf16);
VBOX_UTF16_FREE(keyDislpayUtf16);
VBOX_UTF16_FREE(valueDisplayUtf16);
......@@ -4456,7 +4398,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
VBOX_UTF8_TO_UTF16("FRONTEND/Display", &keyDislpayUtf16);
VBOX_UTF8_TO_UTF16(guiDisplay, &valueDisplayUtf16);
machine->vtbl->SetExtraData(machine, keyDislpayUtf16, valueDisplayUtf16);
machine->vtbl->SetExtraData(machine, keyDislpayUtf16,
valueDisplayUtf16);
VBOX_UTF16_FREE(keyDislpayUtf16);
VBOX_UTF16_FREE(valueDisplayUtf16);
......@@ -4465,13 +4408,18 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
VIR_FREE(guiDisplay);
VIR_FREE(sdlDisplay);
}
} /* Finished:Block to attach the Remote Display to VM */
{ /* Started:Block to attach USB Devices to VM */
if (def->nhostdevs > 0) {
static void
vboxAttachUSB(virDomainDefPtr def, vboxGlobalData *data, IMachine *machine)
{
IUSBController *USBController = NULL;
int i = 0, isUSB = 0;
int i = 0;
bool isUSB = false;
if (def->nhostdevs == 0)
return;
/* Loop through the devices first and see if you
* have a USB Device, only if you have one then
* start the USB controller else just proceed as
......@@ -4487,13 +4435,14 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
DEBUG("USB Device detected, VendorId:0x%x, ProductId:0x%x",
def->hostdevs[i]->source.subsys.u.usb.vendor,
def->hostdevs[i]->source.subsys.u.usb.product);
isUSB++;
isUSB = true;
break;
}
}
}
}
if (isUSB > 0) {
if (isUSB) {
/* First Start the USB Controller and then loop
* to attach USB Devices to it
*/
......@@ -4541,7 +4490,8 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
if (def->hostdevs[i]->source.subsys.u.usb.product) {
sprintf(productId, "%x", def->hostdevs[i]->source.subsys.u.usb.product);
VBOX_UTF8_TO_UTF16(productId, &productIdUtf16);
filter->vtbl->SetProductId(filter, productIdUtf16);
filter->vtbl->SetProductId(filter,
productIdUtf16);
VBOX_UTF16_FREE(productIdUtf16);
}
filter->vtbl->SetActive(filter, 1);
......@@ -4557,8 +4507,139 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
VBOX_RELEASE(USBController);
}
}
}
static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
VBOX_OBJECT_CHECK(conn, virDomainPtr, NULL);
IMachine *machine = NULL;
IBIOSSettings *bios = NULL;
vboxIID *iid = NULL;
vboxIID *mchiid = NULL;
virDomainDefPtr def = NULL;
PRUnichar *machineNameUtf16 = NULL;
#if VBOX_API_VERSION >= 3002
PRBool override = PR_FALSE;
#endif
nsresult rc;
if (!(def = virDomainDefParseString(data->caps, xml,
VIR_DOMAIN_XML_INACTIVE))) {
goto cleanup;
}
} /* Finished:Block to attach USB Devices to VM */
#if VBOX_API_VERSION == 2002
if (VIR_ALLOC(iid) < 0) {
virReportOOMError();
goto cleanup;
}
#endif
VBOX_UTF8_TO_UTF16(def->name, &machineNameUtf16);
vboxIIDFromUUID(def->uuid, iid);
#if VBOX_API_VERSION < 3002
rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj,
machineNameUtf16,
NULL,
NULL,
iid,
&machine);
#else /* VBOX_API_VERSION >= 3002 */
rc = data->vboxObj->vtbl->CreateMachine(data->vboxObj,
machineNameUtf16,
NULL,
NULL,
iid,
override,
&machine);
#endif /* VBOX_API_VERSION >= 3002 */
VBOX_UTF16_FREE(machineNameUtf16);
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("could not define a domain, rc=%08x"), (unsigned)rc);
goto cleanup;
}
rc = machine->vtbl->SetMemorySize(machine, def->memory / 1024);
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("could not set the memory size of the domain to: %lu Kb, "
"rc=%08x"),
def->memory, (unsigned)rc);
}
rc = machine->vtbl->SetCPUCount(machine, def->vcpus);
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("could not set the number of virtual CPUs to: %lu, rc=%08x"),
def->vcpus, (unsigned)rc);
}
#if VBOX_API_VERSION < 3001
rc = machine->vtbl->SetPAEEnabled(machine, (def->features) &
(1 << VIR_DOMAIN_FEATURE_PAE));
#elif VBOX_API_VERSION == 3001
rc = machine->vtbl->SetCpuProperty(machine, CpuPropertyType_PAE,
(def->features) &
(1 << VIR_DOMAIN_FEATURE_PAE));
#elif VBOX_API_VERSION >= 3002
rc = machine->vtbl->SetCPUProperty(machine, CPUPropertyType_PAE,
(def->features) &
(1 << VIR_DOMAIN_FEATURE_PAE));
#endif
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("could not change PAE status to: %s, rc=%08x"),
((def->features) & (1 << VIR_DOMAIN_FEATURE_PAE))
? _("Enabled") : _("Disabled"), (unsigned)rc);
}
machine->vtbl->GetBIOSSettings(machine, &bios);
if (bios) {
rc = bios->vtbl->SetACPIEnabled(bios, (def->features) &
(1 << VIR_DOMAIN_FEATURE_ACPI));
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("could not change ACPI status to: %s, rc=%08x"),
((def->features) & (1 << VIR_DOMAIN_FEATURE_ACPI))
? _("Enabled") : _("Disabled"), (unsigned)rc);
}
rc = bios->vtbl->SetIOAPICEnabled(bios, (def->features) &
(1 << VIR_DOMAIN_FEATURE_APIC));
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("could not change APIC status to: %s, rc=%08x"),
((def->features) & (1 << VIR_DOMAIN_FEATURE_APIC))
? _("Enabled") : _("Disabled"), (unsigned)rc);
}
VBOX_RELEASE(bios);
}
/* Register the machine before attaching other devices to it */
rc = data->vboxObj->vtbl->RegisterMachine(data->vboxObj, machine);
if (NS_FAILED(rc)) {
vboxError(VIR_ERR_INTERNAL_ERROR,
_("could not define a domain, rc=%08x"), (unsigned)rc);
goto cleanup;
}
/* Get the uuid of the machine, currently it is immutable
* object so open a session to it and get it back, so that
* you can make changes to the machine setting
*/
machine->vtbl->GetId(machine, &mchiid);
data->vboxObj->vtbl->OpenSession(data->vboxObj, data->vboxSession, mchiid);
data->vboxSession->vtbl->GetMachine(data->vboxSession, &machine);
vboxSetBootDeviceOrder(def, data, machine);
vboxAttachDrives(def, data, machine);
vboxAttachSound(def, machine);
vboxAttachNetwork(def, data, machine);
vboxAttachSerial(def, data, machine);
vboxAttachParallel(def, data, machine);
vboxAttachVideo(def, machine);
vboxAttachDisplay(def, data, machine);
vboxAttachUSB(def, data, machine);
/* Save the machine settings made till now and close the
* session. also free up the mchiid variable used.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册