Re: [PATCH 2/2] parallels: implement domainDetachDevice and domainDetachDeviceFlags

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

 



On 04/23/2015 09:37 PM, Maxim Nestratov wrote:
New functions utilize previosly added prlsdkDelDisk and prlsdkGetDiskIndex
Signed-off-by: Maxim Nestratov <mnestratov@xxxxxxxxxxxxx>
---
  src/parallels/parallels_driver.c |   71 ++++++++++++++++++++++++++++++++++++++
  src/parallels/parallels_sdk.c    |   30 ++++++++++++++++
  src/parallels/parallels_sdk.h    |    3 ++
  3 files changed, 104 insertions(+), 0 deletions(-)

diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index 07f1311..b667e02 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -1098,6 +1098,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 virHypervisorDriver parallelsDriver = {
      .name = "Parallels",
      .connectOpen = parallelsConnectOpen,            /* 0.10.0 */
@@ -1134,6 +1203,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 */
diff --git a/src/parallels/parallels_sdk.c b/src/parallels/parallels_sdk.c
index 5e6e21c..94274a2 100644
--- a/src/parallels/parallels_sdk.c
+++ b/src/parallels/parallels_sdk.c
@@ -3106,6 +3106,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)
  {
diff --git a/src/parallels/parallels_sdk.h b/src/parallels/parallels_sdk.h
index 00fa44d..3ad46c3 100644
--- a/src/parallels/parallels_sdk.h
+++ b/src/parallels/parallels_sdk.h
@@ -64,3 +64,6 @@ int
  prlsdkAttachVolume(virConnectPtr conn,
                     virDomainObjPtr dom,
                     virDomainDiskDefPtr disk);
+int prlsdkDetachVolume(virConnectPtr conn,
+                   virDomainObjPtr dom,
+                   virDomainDiskDefPtr disk);

Rebased, ACKed and pushed.

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