mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
vz: reuse edit config frame in for attach/detach functions
Attach/detach functions for disk/net are quite trivial and typically call a few functions in begin/end edit frame. Having in mind update function too adding configuring for another device (like graphics) will introduce 3 trivial functions more. Let's replace current approach by attach/detach functions for device. Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@virtuozzo.com> Signed-off-by: Maxim Nestratov <mnestratov@virtuozzo.com>
This commit is contained in:
parent
f6e13453e7
commit
0f38187b68
@ -1150,6 +1150,7 @@ static int vzDomainAttachDeviceFlags(virDomainPtr domain, const char *xml,
|
||||
vzConnPtr privconn = domain->conn->privateData;
|
||||
virDomainDeviceDefPtr dev = NULL;
|
||||
virDomainObjPtr dom = NULL;
|
||||
vzDriverPtr driver = privconn->driver;
|
||||
|
||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
||||
@ -1160,34 +1161,13 @@ static int vzDomainAttachDeviceFlags(virDomainPtr domain, const char *xml,
|
||||
if (vzCheckConfigUpdateFlags(dom, &flags) < 0)
|
||||
goto cleanup;
|
||||
|
||||
dev = virDomainDeviceDefParse(xml, dom->def, privconn->driver->caps,
|
||||
privconn->driver->xmlopt, VIR_DOMAIN_XML_INACTIVE);
|
||||
dev = virDomainDeviceDefParse(xml, dom->def, driver->caps,
|
||||
driver->xmlopt, VIR_DOMAIN_XML_INACTIVE);
|
||||
if (dev == NULL)
|
||||
goto cleanup;
|
||||
|
||||
switch (dev->type) {
|
||||
case VIR_DOMAIN_DEVICE_DISK:
|
||||
ret = prlsdkAttachVolume(privconn->driver, dom, dev->data.disk);
|
||||
if (ret) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("disk attach failed"));
|
||||
goto cleanup;
|
||||
}
|
||||
break;
|
||||
case VIR_DOMAIN_DEVICE_NET:
|
||||
ret = prlsdkAttachNet(privconn->driver, dom, dev->data.net);
|
||||
if (ret) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("network attach failed"));
|
||||
goto cleanup;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
|
||||
_("device type '%s' cannot be attached"),
|
||||
virDomainDeviceTypeToString(dev->type));
|
||||
break;
|
||||
}
|
||||
if (prlsdkAttachDevice(driver, dom, dev) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
@ -1208,6 +1188,7 @@ static int vzDomainDetachDeviceFlags(virDomainPtr domain, const char *xml,
|
||||
vzConnPtr privconn = domain->conn->privateData;
|
||||
virDomainDeviceDefPtr dev = NULL;
|
||||
virDomainObjPtr dom = NULL;
|
||||
vzDriverPtr driver = privconn->driver;
|
||||
|
||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
||||
@ -1219,36 +1200,15 @@ static int vzDomainDetachDeviceFlags(virDomainPtr domain, const char *xml,
|
||||
if (vzCheckConfigUpdateFlags(dom, &flags) < 0)
|
||||
goto cleanup;
|
||||
|
||||
dev = virDomainDeviceDefParse(xml, dom->def, privconn->driver->caps,
|
||||
privconn->driver->xmlopt,
|
||||
dev = virDomainDeviceDefParse(xml, dom->def, driver->caps,
|
||||
driver->xmlopt,
|
||||
VIR_DOMAIN_XML_INACTIVE |
|
||||
VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE);
|
||||
if (dev == NULL)
|
||||
goto cleanup;
|
||||
|
||||
switch (dev->type) {
|
||||
case VIR_DOMAIN_DEVICE_DISK:
|
||||
ret = prlsdkDetachVolume(dom, dev->data.disk);
|
||||
if (ret) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("disk detach failed"));
|
||||
goto cleanup;
|
||||
}
|
||||
break;
|
||||
case VIR_DOMAIN_DEVICE_NET:
|
||||
ret = prlsdkDetachNet(privconn->driver, dom, dev->data.net);
|
||||
if (ret) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("network detach failed"));
|
||||
goto cleanup;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
|
||||
_("device type '%s' cannot be detached"),
|
||||
virDomainDeviceTypeToString(dev->type));
|
||||
break;
|
||||
}
|
||||
if (prlsdkDetachDevice(driver, dom, dev) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
cleanup:
|
||||
|
156
src/vz/vz_sdk.c
156
src/vz/vz_sdk.c
@ -3053,34 +3053,6 @@ prlsdkCleanupBridgedNet(vzDriverPtr driver, virDomainNetDefPtr net)
|
||||
PrlHandle_Free(vnet);
|
||||
}
|
||||
|
||||
int prlsdkAttachNet(vzDriverPtr driver,
|
||||
virDomainObjPtr dom,
|
||||
virDomainNetDefPtr net)
|
||||
{
|
||||
int ret = -1;
|
||||
vzDomObjPtr privdom = dom->privateData;
|
||||
PRL_HANDLE job = PRL_INVALID_HANDLE;
|
||||
|
||||
if (!IS_CT(dom->def)) {
|
||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
||||
_("network device cannot be attached"));
|
||||
return ret;
|
||||
}
|
||||
|
||||
job = PrlVm_BeginEdit(privdom->sdkdom);
|
||||
if (PRL_FAILED(waitJob(job)))
|
||||
return ret;
|
||||
|
||||
ret = prlsdkAddNet(driver, privdom->sdkdom, net, IS_CT(dom->def));
|
||||
if (ret == 0) {
|
||||
job = PrlVm_CommitEx(privdom->sdkdom, PVCF_DETACH_HDD_BUNDLE);
|
||||
if (PRL_FAILED(waitJob(job)))
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static PRL_HANDLE
|
||||
prlsdkFindNetByMAC(PRL_HANDLE sdkdom, virMacAddrPtr mac)
|
||||
{
|
||||
@ -3116,46 +3088,6 @@ prlsdkFindNetByMAC(PRL_HANDLE sdkdom, virMacAddrPtr mac)
|
||||
return adapter;
|
||||
}
|
||||
|
||||
int prlsdkDetachNet(vzDriverPtr driver,
|
||||
virDomainObjPtr dom,
|
||||
virDomainNetDefPtr net)
|
||||
{
|
||||
int ret = -1;
|
||||
vzDomObjPtr privdom = dom->privateData;
|
||||
PRL_HANDLE job = PRL_INVALID_HANDLE;
|
||||
PRL_HANDLE sdknet = PRL_INVALID_HANDLE;
|
||||
PRL_RESULT pret;
|
||||
|
||||
if (!IS_CT(dom->def)) {
|
||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
||||
_("network device cannot be detached"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
job = PrlVm_BeginEdit(privdom->sdkdom);
|
||||
if (PRL_FAILED(waitJob(job)))
|
||||
goto cleanup;
|
||||
|
||||
sdknet = prlsdkFindNetByMAC(privdom->sdkdom, &net->mac);
|
||||
if (sdknet == PRL_INVALID_HANDLE)
|
||||
goto cleanup;
|
||||
|
||||
prlsdkCleanupBridgedNet(driver, net);
|
||||
|
||||
pret = PrlVmDev_Remove(sdknet);
|
||||
prlsdkCheckRetGoto(pret, cleanup);
|
||||
|
||||
job = PrlVm_CommitEx(privdom->sdkdom, PVCF_DETACH_HDD_BUNDLE);
|
||||
if (PRL_FAILED(waitJob(job)))
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
PrlHandle_Free(sdknet);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int prlsdkAddDisk(vzDriverPtr driver,
|
||||
PRL_HANDLE sdkdom,
|
||||
virDomainDiskDefPtr disk)
|
||||
@ -3335,50 +3267,96 @@ prlsdkGetDisk(PRL_HANDLE sdkdom, virDomainDiskDefPtr disk, bool isCt)
|
||||
}
|
||||
|
||||
int
|
||||
prlsdkAttachVolume(vzDriverPtr driver,
|
||||
prlsdkAttachDevice(vzDriverPtr driver,
|
||||
virDomainObjPtr dom,
|
||||
virDomainDiskDefPtr disk)
|
||||
virDomainDeviceDefPtr dev)
|
||||
{
|
||||
int ret = -1;
|
||||
vzDomObjPtr privdom = dom->privateData;
|
||||
PRL_HANDLE job = PRL_INVALID_HANDLE;
|
||||
|
||||
job = PrlVm_BeginEdit(privdom->sdkdom);
|
||||
if (PRL_FAILED(waitJob(job)))
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
ret = prlsdkAddDisk(driver, privdom->sdkdom, disk);
|
||||
if (ret == 0) {
|
||||
job = PrlVm_CommitEx(privdom->sdkdom, PVCF_DETACH_HDD_BUNDLE);
|
||||
if (PRL_FAILED(waitJob(job))) {
|
||||
ret = -1;
|
||||
goto cleanup;
|
||||
switch (dev->type) {
|
||||
case VIR_DOMAIN_DEVICE_DISK:
|
||||
if (prlsdkAddDisk(driver, privdom->sdkdom, dev->data.disk) < 0)
|
||||
return -1;
|
||||
|
||||
break;
|
||||
case VIR_DOMAIN_DEVICE_NET:
|
||||
if (!IS_CT(dom->def)) {
|
||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
||||
_("attaching network device to VM is unsupported"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (prlsdkAddNet(driver, privdom->sdkdom, dev->data.net, IS_CT(dom->def)) < 0)
|
||||
return -1;
|
||||
|
||||
break;
|
||||
default:
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("attaching device type '%s' is unsupported"),
|
||||
virDomainDeviceTypeToString(dev->type));
|
||||
return -1;
|
||||
}
|
||||
|
||||
cleanup:
|
||||
return ret;
|
||||
job = PrlVm_CommitEx(privdom->sdkdom, PVCF_DETACH_HDD_BUNDLE);
|
||||
if (PRL_FAILED(waitJob(job)))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
prlsdkDetachVolume(virDomainObjPtr dom, virDomainDiskDefPtr disk)
|
||||
prlsdkDetachDevice(vzDriverPtr driver,
|
||||
virDomainObjPtr dom,
|
||||
virDomainDeviceDefPtr dev)
|
||||
{
|
||||
int ret = -1;
|
||||
vzDomObjPtr privdom = dom->privateData;
|
||||
PRL_HANDLE job = PRL_INVALID_HANDLE;
|
||||
PRL_HANDLE sdkdisk;
|
||||
PRL_HANDLE sdkdev = PRL_INVALID_HANDLE;
|
||||
PRL_RESULT pret;
|
||||
|
||||
sdkdisk = prlsdkGetDisk(privdom->sdkdom, disk, IS_CT(dom->def));
|
||||
if (sdkdisk == PRL_INVALID_HANDLE)
|
||||
goto cleanup;
|
||||
|
||||
job = PrlVm_BeginEdit(privdom->sdkdom);
|
||||
if (PRL_FAILED(waitJob(job)))
|
||||
goto cleanup;
|
||||
|
||||
pret = PrlVmDev_Remove(sdkdisk);
|
||||
prlsdkCheckRetGoto(pret, cleanup);
|
||||
switch (dev->type) {
|
||||
case VIR_DOMAIN_DEVICE_DISK:
|
||||
sdkdev = prlsdkGetDisk(privdom->sdkdom, dev->data.disk, IS_CT(dom->def));
|
||||
if (sdkdev == PRL_INVALID_HANDLE)
|
||||
goto cleanup;
|
||||
|
||||
pret = PrlVmDev_Remove(sdkdev);
|
||||
prlsdkCheckRetGoto(pret, cleanup);
|
||||
|
||||
break;
|
||||
case VIR_DOMAIN_DEVICE_NET:
|
||||
if (!IS_CT(dom->def)) {
|
||||
virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
|
||||
_("detaching network device from VM is unsupported"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
sdkdev = prlsdkFindNetByMAC(privdom->sdkdom, &dev->data.net->mac);
|
||||
if (sdkdev == PRL_INVALID_HANDLE)
|
||||
goto cleanup;
|
||||
|
||||
prlsdkCleanupBridgedNet(driver, dev->data.net);
|
||||
|
||||
pret = PrlVmDev_Remove(sdkdev);
|
||||
prlsdkCheckRetGoto(pret, cleanup);
|
||||
|
||||
break;
|
||||
default:
|
||||
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||
_("detaching device type '%s' is unsupported"),
|
||||
virDomainDeviceTypeToString(dev->type));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
job = PrlVm_CommitEx(privdom->sdkdom, PVCF_DETACH_HDD_BUNDLE);
|
||||
if (PRL_FAILED(waitJob(job)))
|
||||
@ -3388,7 +3366,7 @@ prlsdkDetachVolume(virDomainObjPtr dom, virDomainDiskDefPtr disk)
|
||||
|
||||
cleanup:
|
||||
|
||||
PrlHandle_Free(sdkdisk);
|
||||
PrlHandle_Free(sdkdev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -63,16 +63,12 @@ prlsdkUnregisterDomain(vzDriverPtr driver, virDomainObjPtr dom, unsigned int fla
|
||||
int
|
||||
prlsdkDomainManagedSaveRemove(virDomainObjPtr dom);
|
||||
int
|
||||
prlsdkAttachVolume(vzDriverPtr driver, virDomainObjPtr dom, virDomainDiskDefPtr disk);
|
||||
prlsdkAttachDevice(vzDriverPtr driver, virDomainObjPtr dom, virDomainDeviceDefPtr dev);
|
||||
int
|
||||
prlsdkDetachVolume(virDomainObjPtr dom, virDomainDiskDefPtr disk);
|
||||
prlsdkDetachDevice(vzDriverPtr driver, virDomainObjPtr dom, virDomainDeviceDefPtr dev);
|
||||
int
|
||||
prlsdkGetBlockStats(PRL_HANDLE sdkstats, virDomainDiskDefPtr disk, virDomainBlockStatsPtr stats);
|
||||
int
|
||||
prlsdkAttachNet(vzDriverPtr driver, virDomainObjPtr dom, virDomainNetDefPtr net);
|
||||
int
|
||||
prlsdkDetachNet(vzDriverPtr driver, virDomainObjPtr dom, virDomainNetDefPtr net);
|
||||
int
|
||||
prlsdkGetNetStats(PRL_HANDLE sdkstas, PRL_HANDLE sdkdom, const char *path, virDomainInterfaceStatsPtr stats);
|
||||
int
|
||||
prlsdkGetVcpuStats(PRL_HANDLE sdkstas, int idx, unsigned long long *time);
|
||||
|
Loading…
Reference in New Issue
Block a user