提交 18f24c65 编写于 作者: M Maxim Nestratov 提交者: Dmitry Guryanov

parallels: implement domainDetachDevice and domainDetachDeviceFlags

New functions utilize previosly added prlsdkDelDisk and prlsdkGetDiskIndex
Signed-off-by: NMaxim Nestratov <mnestratov@parallels.com>
上级 0d20195e
......@@ -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 */
......
......@@ -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)
{
......
......@@ -64,3 +64,6 @@ int
prlsdkAttachVolume(virConnectPtr conn,
virDomainObjPtr dom,
virDomainDiskDefPtr disk);
int prlsdkDetachVolume(virConnectPtr conn,
virDomainObjPtr dom,
virDomainDiskDefPtr disk);
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册