Re: [PATCH 2/3] Parallels: implement domainAttachDeviceFlags

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

 



On 03/26/2015 08:51 PM, Alexander Burluka wrote:
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 |   45 ++++++++++++++++++++++++++++++++++++++
  src/parallels/parallels_sdk.c    |   30 +++++++++++++++++++++++++
  src/parallels/parallels_sdk.h    |    4 +++
  3 files changed, 79 insertions(+), 0 deletions(-)

diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index f5e58a8..87297cf 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -1004,6 +1004,50 @@ 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);

qemu driver forbids updating stopped domain without flag

VIR_DOMAIN_AFFECT_LIVE


+
+    privdom = virDomainObjListFindByUUID(privconn->domains, dom->uuid);
+    if (dom == NULL) {
+        parallelsDomNotFoundError(dom);
+        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 +1082,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..bdfd487 100644
--- a/src/parallels/parallels_sdk.c
+++ b/src/parallels/parallels_sdk.c
@@ -2890,6 +2890,36 @@ 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;
+    PRL_HANDLE sdkdom = PRL_INVALID_HANDLE;
+    PRL_HANDLE job = PRL_INVALID_HANDLE;
+
+    sdkdom = prlsdkSdkDomainLookupByUUID(privconn, dom->def->uuid);
+    if (sdkdom == PRL_INVALID_HANDLE)
+        goto cleanup;
SDK handle is stored in virDomainObj, you can get pointer to parallelsDomObjPtr:

parallelsDomObjPtr privdom = dom->privateData;
and then use privdom->sdkdom


+
+    job = PrlVm_BeginEdit(sdkdom);
+    if (PRL_FAILED(waitJob(job, privconn->jobTimeout)))
+        goto cleanup;
+
+    ret = prlsdkAddDisk(sdkdom, disk, false);
+    if (ret == 0) {
+        job = PrlVm_CommitEx(sdkdom, PVCF_DETACH_HDD_BUNDLE);
+        if (PRL_FAILED(waitJob(job, privconn->jobTimeout)))
+            goto cleanup;
+    }
+
+ cleanup:
+    PrlHandle_Free(sdkdom);
+    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);


--
Dmitry Guryanov

--
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]