提交 6be94596 编写于 作者: T Taowei 提交者: Michal Privoznik

vbox: Rewrite vboxDomainUpdateDeviceFlags

Since vboxDomainAttachDeviceImple not used in vbox_tmpl.c, it has
been deleted.
上级 58776877
......@@ -4163,3 +4163,19 @@ int vboxDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
return vboxDomainAttachDeviceImpl(dom, xml, 0);
}
int vboxDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
unsigned int flags)
{
virCheckFlags(VIR_DOMAIN_AFFECT_CURRENT |
VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("cannot modify the persistent configuration of a domain"));
return -1;
}
return vboxDomainAttachDeviceImpl(dom, xml, 1);
}
......@@ -1451,221 +1451,6 @@ _vboxAttachDrivesOld(virDomainDefPtr def ATTRIBUTE_UNUSED,
#endif /* VBOX_API_VERSION >= 4000000 */
static int vboxDomainAttachDeviceImpl(virDomainPtr dom,
const char *xml,
int mediaChangeOnly ATTRIBUTE_UNUSED)
{
VBOX_OBJECT_CHECK(dom->conn, int, -1);
IMachine *machine = NULL;
vboxIID iid = VBOX_IID_INITIALIZER;
PRUint32 state = MachineState_Null;
virDomainDefPtr def = NULL;
virDomainDeviceDefPtr dev = NULL;
nsresult rc;
if (VIR_ALLOC(def) < 0)
return ret;
if (VIR_STRDUP(def->os.type, "hvm") < 0)
goto cleanup;
dev = virDomainDeviceDefParse(xml, def, data->caps, data->xmlopt,
VIR_DOMAIN_XML_INACTIVE);
if (dev == NULL)
goto cleanup;
vboxIIDFromUUID(&iid, dom->uuid);
rc = VBOX_OBJECT_GET_MACHINE(iid.value, &machine);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_NO_DOMAIN, "%s",
_("no domain with matching uuid"));
goto cleanup;
}
if (machine) {
machine->vtbl->GetState(machine, &state);
if ((state == MachineState_Running) ||
(state == MachineState_Paused)) {
rc = VBOX_SESSION_OPEN_EXISTING(iid.value, machine);
} else {
rc = VBOX_SESSION_OPEN(iid.value, machine);
}
if (NS_SUCCEEDED(rc)) {
rc = data->vboxSession->vtbl->GetMachine(data->vboxSession, &machine);
if (NS_SUCCEEDED(rc) && machine) {
if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
#if VBOX_API_VERSION < 3001000
const char *src = virDomainDiskGetSource(dev->data.disk);
int type = virDomainDiskGetType(dev->data.disk);
if (dev->data.disk->device == VIR_DOMAIN_DISK_DEVICE_CDROM) {
if (type == VIR_STORAGE_TYPE_FILE && src) {
IDVDDrive *dvdDrive = NULL;
/* Currently CDROM/DVD Drive is always IDE
* Secondary Master so neglecting the following
* parameter dev->data.disk->bus
*/
machine->vtbl->GetDVDDrive(machine, &dvdDrive);
if (dvdDrive) {
IDVDImage *dvdImage = NULL;
PRUnichar *dvdfileUtf16 = NULL;
vboxIID dvduuid = VBOX_IID_INITIALIZER;
vboxIID dvdemptyuuid = VBOX_IID_INITIALIZER;
VBOX_UTF8_TO_UTF16(src, &dvdfileUtf16);
data->vboxObj->vtbl->FindDVDImage(data->vboxObj, dvdfileUtf16, &dvdImage);
if (!dvdImage) {
data->vboxObj->vtbl->OpenDVDImage(data->vboxObj, dvdfileUtf16, dvdemptyuuid.value, &dvdImage);
}
if (dvdImage) {
rc = dvdImage->vtbl->imedium.GetId((IMedium *)dvdImage, &dvduuid.value);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("can't get the uuid of the file to "
"be attached to cdrom: %s, rc=%08x"),
src, (unsigned)rc);
} else {
/* unmount the previous mounted image */
dvdDrive->vtbl->Unmount(dvdDrive);
rc = dvdDrive->vtbl->MountImage(dvdDrive, dvduuid.value);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("could not attach the file to cdrom: %s, rc=%08x"),
src, (unsigned)rc);
} else {
ret = 0;
DEBUGIID("CD/DVD Image UUID:", dvduuid.value);
}
}
VBOX_MEDIUM_RELEASE(dvdImage);
}
vboxIIDUnalloc(&dvduuid);
VBOX_UTF16_FREE(dvdfileUtf16);
VBOX_RELEASE(dvdDrive);
}
} else if (type == VIR_STORAGE_TYPE_BLOCK) {
}
} else if (dev->data.disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY) {
if (type == VIR_STORAGE_TYPE_FILE && src) {
IFloppyDrive *floppyDrive;
machine->vtbl->GetFloppyDrive(machine, &floppyDrive);
if (floppyDrive) {
rc = floppyDrive->vtbl->SetEnabled(floppyDrive, 1);
if (NS_SUCCEEDED(rc)) {
IFloppyImage *floppyImage = NULL;
PRUnichar *fdfileUtf16 = NULL;
vboxIID fduuid = VBOX_IID_INITIALIZER;
vboxIID fdemptyuuid = VBOX_IID_INITIALIZER;
VBOX_UTF8_TO_UTF16(src, &fdfileUtf16);
rc = data->vboxObj->vtbl->FindFloppyImage(data->vboxObj,
fdfileUtf16,
&floppyImage);
if (!floppyImage) {
data->vboxObj->vtbl->OpenFloppyImage(data->vboxObj,
fdfileUtf16,
fdemptyuuid.value,
&floppyImage);
}
if (floppyImage) {
rc = floppyImage->vtbl->imedium.GetId((IMedium *)floppyImage, &fduuid.value);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("can't get the uuid of the file to be "
"attached to floppy drive: %s, rc=%08x"),
src, (unsigned)rc);
} else {
rc = floppyDrive->vtbl->MountImage(floppyDrive, fduuid.value);
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("could not attach the file to floppy drive: %s, rc=%08x"),
src, (unsigned)rc);
} else {
ret = 0;
DEBUGIID("attached floppy, UUID:", fduuid.value);
}
}
VBOX_MEDIUM_RELEASE(floppyImage);
}
vboxIIDUnalloc(&fduuid);
VBOX_UTF16_FREE(fdfileUtf16);
}
VBOX_RELEASE(floppyDrive);
}
} else if (type == VIR_STORAGE_TYPE_BLOCK) {
}
}
#else /* VBOX_API_VERSION >= 3001000 */
#endif /* VBOX_API_VERSION >= 3001000 */
} else if (dev->type == VIR_DOMAIN_DEVICE_NET) {
} else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
if (dev->data.hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS) {
if (dev->data.hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
}
}
} else if (dev->type == VIR_DOMAIN_DEVICE_FS &&
dev->data.fs->type == VIR_DOMAIN_FS_TYPE_MOUNT) {
PRUnichar *nameUtf16;
PRUnichar *hostPathUtf16;
PRBool writable;
VBOX_UTF8_TO_UTF16(dev->data.fs->dst, &nameUtf16);
VBOX_UTF8_TO_UTF16(dev->data.fs->src, &hostPathUtf16);
writable = !dev->data.fs->readonly;
#if VBOX_API_VERSION < 4000000
rc = machine->vtbl->CreateSharedFolder(machine, nameUtf16, hostPathUtf16,
writable);
#else /* VBOX_API_VERSION >= 4000000 */
rc = machine->vtbl->CreateSharedFolder(machine, nameUtf16, hostPathUtf16,
writable, PR_FALSE);
#endif /* VBOX_API_VERSION >= 4000000 */
if (NS_FAILED(rc)) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("could not attach shared folder '%s', rc=%08x"),
dev->data.fs->dst, (unsigned)rc);
} else {
ret = 0;
}
VBOX_UTF16_FREE(nameUtf16);
VBOX_UTF16_FREE(hostPathUtf16);
}
machine->vtbl->SaveSettings(machine);
VBOX_RELEASE(machine);
}
VBOX_SESSION_CLOSE();
}
}
cleanup:
vboxIIDUnalloc(&iid);
virDomainDefFree(def);
virDomainDeviceDefFree(dev);
return ret;
}
static int vboxDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
unsigned int flags)
{
virCheckFlags(VIR_DOMAIN_AFFECT_CURRENT |
VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG, -1);
if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("cannot modify the persistent configuration of a domain"));
return -1;
}
return vboxDomainAttachDeviceImpl(dom, xml, 1);
}
static int vboxDomainDetachDevice(virDomainPtr dom, const char *xml)
{
VBOX_OBJECT_CHECK(dom->conn, int, -1);
......
......@@ -527,6 +527,8 @@ int vboxConnectNumOfDefinedDomains(virConnectPtr conn);
int vboxDomainAttachDevice(virDomainPtr dom, const char *xml);
int vboxDomainAttachDeviceFlags(virDomainPtr dom, const char *xml,
unsigned int flags);
int vboxDomainUpdateDeviceFlags(virDomainPtr dom, const char *xml,
unsigned int flags);
/* Version specified functions for installing uniformed API */
void vbox22InstallUniformedAPI(vboxUniformedAPI *pVBoxAPI);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册