Parallels Cloud Server supports block devices and virtual NIC
live attachment. I implemented that function for block devices so
OpenStack volume attachment is now works.
Signed-off-by: Alexander Burluka <aburluka(a)parallels.com>
---
src/parallels/parallels_driver.c | 65 ++++++++++++++++++++++++++++++++++++++
src/parallels/parallels_sdk.c | 27 ++++++++++++++++
src/parallels/parallels_sdk.h | 4 ++
3 files changed, 96 insertions(+), 0 deletions(-)
diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index f5e58a8..8058903 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -1004,6 +1004,70 @@ parallelsDomainHasManagedSaveImage(virDomainPtr domain, unsigned
int flags)
return 0;
}
+static int parallelsDomainAttachDeviceFlags(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 = virDomainObjListFindByUUID(privconn->domains, dom->uuid);
+ if (privdom == NULL) {
+ parallelsDomNotFoundError(dom);
+ goto cleanup;
+ }
+
+ if (!(flags & VIR_DOMAIN_AFFECT_CONFIG)) {
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("device attach 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 = prlsdkAttachVolume(dom->conn, privdom, dev->data.disk);
+ if (ret) {
+ virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+ _("disk attach failed"));
+ goto cleanup;
+ }
+ break;
+ default:
+ virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+ _("device type '%s' cannot be detached"),
+ virDomainDeviceTypeToString(dev->type));
+ break;
+ }
+
+ ret = 0;
+ cleanup:
+ return ret;
+}
+
static virHypervisorDriver parallelsDriver = {
.name = "Parallels",
.connectOpen = parallelsConnectOpen, /* 0.10.0 */
@@ -1038,6 +1102,7 @@ static virHypervisorDriver parallelsDriver = {
.domainDefineXMLFlags = parallelsDomainDefineXMLFlags, /* 1.2.12 */
.domainUndefine = parallelsDomainUndefine, /* 1.2.10 */
.domainUndefineFlags = parallelsDomainUndefineFlags, /* 1.2.10 */
+ .domainAttachDeviceFlags = parallelsDomainAttachDeviceFlags, /* 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 fa5c44d..05b21d4 100644
--- a/src/parallels/parallels_sdk.c
+++ b/src/parallels/parallels_sdk.c
@@ -2890,6 +2890,33 @@ static int prlsdkAddDisk(PRL_HANDLE sdkdom, virDomainDiskDefPtr
disk, bool bootD
return ret;
}
+int
+prlsdkAttachVolume(virConnectPtr conn,
+ virDomainObjPtr dom,
+ virDomainDiskDefPtr disk)
+{
+ int ret = -1;
+ parallelsConnPtr privconn = conn->privateData;
+ parallelsDomObjPtr privdom = dom->privateData;
+ PRL_HANDLE job = PRL_INVALID_HANDLE;
+
+ job = PrlVm_BeginEdit(privdom->sdkdom);
+ if (PRL_FAILED(waitJob(job, privconn->jobTimeout)))
+ goto cleanup;
+
+ ret = prlsdkAddDisk(privdom->sdkdom, disk, false);
+ 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 694c19b..d68cada 100644
--- a/src/parallels/parallels_sdk.h
+++ b/src/parallels/parallels_sdk.h
@@ -53,3 +53,7 @@ int prlsdkCreateVm(virConnectPtr conn, virDomainDefPtr def);
int prlsdkCreateCt(virConnectPtr conn, virDomainDefPtr def);
int
prlsdkUnregisterDomain(parallelsConnPtr privconn, virDomainObjPtr dom);
+int
+prlsdkAttachVolume(virConnectPtr conn,
+ virDomainObjPtr dom,
+ virDomainDiskDefPtr disk);
--
1.7.1