diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c index 18846f5f262e84731df4de05b04fc6d48d18cd62..205ec1c8dd6c6d4497a6d35775d20981ba9d0c05 100644 --- a/src/parallels/parallels_driver.c +++ b/src/parallels/parallels_driver.c @@ -1097,6 +1097,75 @@ static int parallelsDomainAttachDevice(virDomainPtr dom, const char *xml) VIR_DOMAIN_AFFECT_CONFIG | VIR_DOMAIN_AFFECT_LIVE); } +static int parallelsDomainDetachDeviceFlags(virDomainPtr dom, const char *xml, + unsigned int flags) +{ + int ret = -1; + parallelsConnPtr privconn = dom->conn->privateData; + virDomainDeviceDefPtr dev = NULL; + virDomainObjPtr privdom = NULL; + bool domactive = false; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + privdom = parallelsDomObjFromDomain(dom); + if (privdom == NULL) + return -1; + + if (!(flags & VIR_DOMAIN_AFFECT_CONFIG)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("device detach needs VIR_DOMAIN_AFFECT_CONFIG " + "flag to be set")); + goto cleanup; + } + + domactive = virDomainObjIsActive(privdom); + if (!domactive && (flags & VIR_DOMAIN_AFFECT_LIVE)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("cannot do live update a device on " + "inactive domain")); + goto cleanup; + } + if (domactive && !(flags & VIR_DOMAIN_AFFECT_LIVE)) { + virReportError(VIR_ERR_OPERATION_INVALID, "%s", + _("Updates on a running domain need " + "VIR_DOMAIN_AFFECT_LIVE flag")); + } + + dev = virDomainDeviceDefParse(xml, privdom->def, privconn->caps, + privconn->xmlopt, VIR_DOMAIN_XML_INACTIVE); + if (dev == NULL) + goto cleanup; + + switch (dev->type) { + case VIR_DOMAIN_DEVICE_DISK: + ret = prlsdkDetachVolume(dom->conn, privdom, dev->data.disk); + if (ret) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", + _("disk detach failed")); + goto cleanup; + } + break; + default: + virReportError(VIR_ERR_OPERATION_UNSUPPORTED, + _("device type '%s' cannot be detached"), + virDomainDeviceTypeToString(dev->type)); + break; + } + + ret = 0; + cleanup: + virObjectUnlock(privdom); + return ret; +} + +static int parallelsDomainDetachDevice(virDomainPtr dom, const char *xml) +{ + return parallelsDomainDetachDeviceFlags(dom, xml, + VIR_DOMAIN_AFFECT_CONFIG | VIR_DOMAIN_AFFECT_LIVE); +} + static unsigned long long parallelsDomainGetMaxMemory(virDomainPtr domain) { @@ -1147,6 +1216,8 @@ static virHypervisorDriver parallelsDriver = { .domainUndefineFlags = parallelsDomainUndefineFlags, /* 1.2.10 */ .domainAttachDevice = parallelsDomainAttachDevice, /* 1.2.15 */ .domainAttachDeviceFlags = parallelsDomainAttachDeviceFlags, /* 1.2.15 */ + .domainDetachDevice = parallelsDomainDetachDevice, /* 1.2.15 */ + .domainDetachDeviceFlags = parallelsDomainDetachDeviceFlags, /* 1.2.15 */ .domainIsActive = parallelsDomainIsActive, /* 1.2.10 */ .connectDomainEventRegisterAny = parallelsConnectDomainEventRegisterAny, /* 1.2.10 */ .connectDomainEventDeregisterAny = parallelsConnectDomainEventDeregisterAny, /* 1.2.10 */ diff --git a/src/parallels/parallels_sdk.c b/src/parallels/parallels_sdk.c index 7242c0c16952f7e5307566a7cdcf0037961692f8..ad744c92116b71f0b9c09167e4d9133a6be2c988 100644 --- a/src/parallels/parallels_sdk.c +++ b/src/parallels/parallels_sdk.c @@ -3113,6 +3113,36 @@ prlsdkGetDiskIndex(PRL_HANDLE sdkdom, virDomainDiskDefPtr disk) return idx; } +int prlsdkDetachVolume(virConnectPtr conn, + virDomainObjPtr dom, + virDomainDiskDefPtr disk) +{ + int ret = -1, idx; + parallelsConnPtr privconn = conn->privateData; + parallelsDomObjPtr privdom = dom->privateData; + PRL_HANDLE job = PRL_INVALID_HANDLE; + + idx = prlsdkGetDiskIndex(privdom->sdkdom, disk); + if (idx < 0) + goto cleanup; + + job = PrlVm_BeginEdit(privdom->sdkdom); + if (PRL_FAILED(waitJob(job, privconn->jobTimeout))) + goto cleanup; + + ret = prlsdkDelDisk(privdom->sdkdom, idx); + if (ret == 0) { + job = PrlVm_CommitEx(privdom->sdkdom, PVCF_DETACH_HDD_BUNDLE); + if (PRL_FAILED(waitJob(job, privconn->jobTimeout))) { + ret = -1; + goto cleanup; + } + } + + cleanup: + return ret; +} + static int prlsdkAddFS(PRL_HANDLE sdkdom, virDomainFSDefPtr fs) { diff --git a/src/parallels/parallels_sdk.h b/src/parallels/parallels_sdk.h index 00fa44d3d9cd4443d832b73b0fb42e5530dfadaf..3ad46c37a86388e813d360d0c93dd669efc5767a 100644 --- a/src/parallels/parallels_sdk.h +++ b/src/parallels/parallels_sdk.h @@ -64,3 +64,6 @@ int prlsdkAttachVolume(virConnectPtr conn, virDomainObjPtr dom, virDomainDiskDefPtr disk); +int prlsdkDetachVolume(virConnectPtr conn, + virDomainObjPtr dom, + virDomainDiskDefPtr disk);