[PATCH v2 2/3] Parallels: implement domainAttachDeviceFlags

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx>
---
 src/parallels/parallels_driver.c |   51 ++++++++++++++++++++++++++++++++++++++
 src/parallels/parallels_sdk.c    |   28 ++++++++++++++++++++
 src/parallels/parallels_sdk.h    |    4 +++
 3 files changed, 83 insertions(+), 0 deletions(-)

diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index f5e58a8..dd8ed7d 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -1004,6 +1004,56 @@ 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;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG, -1);
+
+    privdom = virDomainObjListFindByUUID(privconn->domains, dom->uuid);
+    if (privdom == NULL) {
+        parallelsDomNotFoundError(dom);
+        goto cleanup;
+    }
+
+    if (!virDomainObjIsActive(privdom) && (flags & VIR_DOMAIN_AFFECT_LIVE)) {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("cannot do live update a device on "
+                         "inactive domain"));
+        goto cleanup;
+    }
+
+    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 +1088,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..0b324d9 100644
--- a/src/parallels/parallels_sdk.c
+++ b/src/parallels/parallels_sdk.c
@@ -2890,6 +2890,34 @@ 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 sdkdom = PRL_INVALID_HANDLE;
+    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(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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]