Re: [PATCH 04/18] vz: add device updates

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

 



20.04.2016 17:05, Nikolay Shirokovskiy пишет:

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx>
---
  src/vz/vz_driver.c | 37 ++++++++++++++++++++++
  src/vz/vz_sdk.c    | 92 +++++++++++++++++++++++++++++++++++++++++++++---------
  src/vz/vz_sdk.h    |  2 ++
  3 files changed, 116 insertions(+), 15 deletions(-)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index ab4aa74..2778a9a 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -1185,6 +1185,42 @@ static int vzDomainDetachDevice(virDomainPtr dom, const char *xml)
                                       VIR_DOMAIN_AFFECT_CONFIG | VIR_DOMAIN_AFFECT_LIVE);
  }
+static int vzDomainUpdateDeviceFlags(virDomainPtr dom,
+                                     const char *xml,
+                                     unsigned int flags)
+{
+    int ret = -1;
+    vzConnPtr privconn = dom->conn->privateData;
+    virDomainObjPtr privdom = NULL;
+    virDomainDeviceDefPtr dev = NULL;
+    vzDriverPtr driver = privconn->driver;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG, -1);
+
+    if (!(privdom = vzDomObjFromDomain(dom)))
+        return -1;
+
+    if (vzCheckConfigUpdateFlags(privdom, &flags) < 0)
+        goto cleanup;
+
+    if (!(dev = virDomainDeviceDefParse(xml, privdom->def, driver->caps,
+                                        driver->xmlopt,
+                                        VIR_DOMAIN_XML_INACTIVE)))
+        goto cleanup;
+
+    if (prlsdkUpdateDevice(driver, privdom, dev) < 0)
+        goto cleanup;
+
+    ret = 0;
+ cleanup:
+
+    virDomainDeviceDefFree(dev);
+    virObjectUnlock(privdom);
+    return ret;
+}
+
+
  static unsigned long long
  vzDomainGetMaxMemory(virDomainPtr domain)
  {
@@ -1584,6 +1620,7 @@ static virHypervisorDriver vzHypervisorDriver = {
      .connectUnregisterCloseCallback = vzConnectUnregisterCloseCallback, /* 1.3.2 */
      .domainSetMemoryFlags = vzDomainSetMemoryFlags, /* 1.3.4 */
      .domainSetMemory = vzDomainSetMemory, /* 1.3.4 */
+    .domainUpdateDeviceFlags = vzDomainUpdateDeviceFlags, /* 1.3.4 */

s/1.3.4/2.0.0

  };
static virConnectDriver vzConnectDriver = {
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index cb624dc..7e36cb0 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -39,6 +39,11 @@
VIR_LOG_INIT("parallels.sdk"); +static PRL_HANDLE
+prlsdkFindNetByMAC(PRL_HANDLE sdkdom, virMacAddrPtr mac);
+static PRL_HANDLE
+prlsdkGetDisk(PRL_HANDLE sdkdom, virDomainDiskDefPtr disk, bool isCt);
+
  /*
   * Log error description
   */
@@ -2809,10 +2814,10 @@ static const char * prlsdkFormatMac(virMacAddrPtr mac, char *macstr)
      return macstr;
  }
-static int prlsdkAddNet(vzDriverPtr driver,
-                        PRL_HANDLE sdkdom,
-                        virDomainNetDefPtr net,
-                        bool isCt)
+static int prlsdkConfigureNet(vzDriverPtr driver,
+                              PRL_HANDLE sdkdom,
+                              virDomainNetDefPtr net,
+                              bool isCt, bool create)
  {
      PRL_RESULT pret;
      PRL_HANDLE sdknet = PRL_INVALID_HANDLE;
@@ -2829,8 +2834,14 @@ static int prlsdkAddNet(vzDriverPtr driver,
      if (prlsdkCheckNetUnsupportedParams(net) < 0)
          return -1;
- pret = PrlVmCfg_CreateVmDev(sdkdom, PDE_GENERIC_NETWORK_ADAPTER, &sdknet);
-    prlsdkCheckRetGoto(pret, cleanup);
+    if (create) {
+        pret = PrlVmCfg_CreateVmDev(sdkdom, PDE_GENERIC_NETWORK_ADAPTER, &sdknet);
+        prlsdkCheckRetGoto(pret, cleanup);
+    } else {
+        sdknet = prlsdkFindNetByMAC(sdkdom, &net->mac);
+        if (sdknet == PRL_INVALID_HANDLE)
+            return -1;
+    }
pret = PrlVmDev_SetEnabled(sdknet, 1);
      prlsdkCheckRetGoto(pret, cleanup);
@@ -3101,9 +3112,11 @@ prlsdkFindNetByMAC(PRL_HANDLE sdkdom, virMacAddrPtr mac)
      return adapter;
  }
-static int prlsdkAddDisk(vzDriverPtr driver,
-                         PRL_HANDLE sdkdom,
-                         virDomainDiskDefPtr disk)
+static int prlsdkConfigureDisk(vzDriverPtr driver,
+                               PRL_HANDLE sdkdom,
+                               virDomainDiskDefPtr disk,
+                               bool isCt,
+                               bool create)
  {
      PRL_RESULT pret;
      PRL_HANDLE sdkdisk = PRL_INVALID_HANDLE;
@@ -3122,8 +3135,14 @@ static int prlsdkAddDisk(vzDriverPtr driver,
      else
          devType = PDE_OPTICAL_DISK;
- pret = PrlVmCfg_CreateVmDev(sdkdom, devType, &sdkdisk);
-    prlsdkCheckRetGoto(pret, cleanup);
+    if (create) {
+        pret = PrlVmCfg_CreateVmDev(sdkdom, devType, &sdkdisk);
+        prlsdkCheckRetGoto(pret, cleanup);
+    } else {
+        sdkdisk = prlsdkGetDisk(sdkdom, disk, isCt);
+        if (sdkdisk == PRL_INVALID_HANDLE)
+            return -1;
+    }
pret = PrlVmDev_SetEnabled(sdkdisk, 1);
      prlsdkCheckRetGoto(pret, cleanup);
@@ -3294,7 +3313,8 @@ prlsdkAttachDevice(vzDriverPtr driver,
switch (dev->type) {
      case VIR_DOMAIN_DEVICE_DISK:
-        if (prlsdkAddDisk(driver, privdom->sdkdom, dev->data.disk) < 0)
+        if (prlsdkConfigureDisk(driver, privdom->sdkdom,
+                                dev->data.disk, IS_CT(dom->def), true) < 0)
              return -1;
break;
@@ -3305,7 +3325,8 @@ prlsdkAttachDevice(vzDriverPtr driver,
              return -1;
          }
- if (prlsdkAddNet(driver, privdom->sdkdom, dev->data.net, IS_CT(dom->def)) < 0)
+        if (prlsdkConfigureNet(driver, privdom->sdkdom, dev->data.net,
+                               IS_CT(dom->def), true) < 0)
              return -1;
break;
@@ -3384,6 +3405,45 @@ prlsdkDetachDevice(vzDriverPtr driver,
      return ret;
  }
+int
+prlsdkUpdateDevice(vzDriverPtr driver,
+                   virDomainObjPtr dom,
+                   virDomainDeviceDefPtr dev)
+{
+    vzDomObjPtr privdom = dom->privateData;
+    PRL_HANDLE job = PRL_INVALID_HANDLE;
+
+    job = PrlVm_BeginEdit(privdom->sdkdom);
+    if (PRL_FAILED(waitJob(job)))
+        return -1;
+
+    switch (dev->type) {
+    case VIR_DOMAIN_DEVICE_DISK:
+        if (prlsdkConfigureDisk(driver, privdom->sdkdom, dev->data.disk,
+                                IS_CT(dom->def), false) < 0)
+            return -1;
+
+        break;
+    case VIR_DOMAIN_DEVICE_NET:
+        if (prlsdkConfigureNet(driver, privdom->sdkdom, dev->data.net,
+                               IS_CT(dom->def), false) < 0)
+            return -1;
+
+        break;
+    default:
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("updating device type '%s' is unsupported"),
+                       virDomainDeviceTypeToString(dev->type));
+        return -1;
+    }
+
+    job = PrlVm_CommitEx(privdom->sdkdom, PVCF_DETACH_HDD_BUNDLE);
+    if (PRL_FAILED(waitJob(job)))
+        return -1;
+
+    return 0;
+}
+
  static int
  prlsdkAddFS(PRL_HANDLE sdkdom, virDomainFSDefPtr fs)
  {
@@ -3568,7 +3628,8 @@ prlsdkDoApplyConfig(vzDriverPtr driver,
      }
for (i = 0; i < def->nnets; i++) {
-        if (prlsdkAddNet(driver, sdkdom, def->nets[i], IS_CT(def)) < 0)
+        if (prlsdkConfigureNet(driver, sdkdom, def->nets[i],
+                               IS_CT(def), true) < 0)
              goto error;
      }
@@ -3589,7 +3650,8 @@ prlsdkDoApplyConfig(vzDriverPtr driver,
      }
for (i = 0; i < def->ndisks; i++) {
-        if (prlsdkAddDisk(driver, sdkdom, def->disks[i]) < 0)
+        if (prlsdkConfigureDisk(driver, sdkdom, def->disks[i],
+                                IS_CT(def), true) < 0)
              goto error;
      }
diff --git a/src/vz/vz_sdk.h b/src/vz/vz_sdk.h
index e68a710..f129d68 100644
--- a/src/vz/vz_sdk.h
+++ b/src/vz/vz_sdk.h
@@ -67,6 +67,8 @@ prlsdkAttachDevice(vzDriverPtr driver, virDomainObjPtr dom, virDomainDeviceDefPt
  int
  prlsdkDetachDevice(vzDriverPtr driver, virDomainObjPtr dom, virDomainDeviceDefPtr disk);
  int
+prlsdkUpdateDevice(vzDriverPtr driver, virDomainObjPtr dom, virDomainDeviceDefPtr disk);
+int

s/disk/dev

  prlsdkGetBlockStats(virDomainObjPtr dom, virDomainDiskDefPtr disk, virDomainBlockStatsPtr stats);
  int
  prlsdkGetNetStats(virDomainObjPtr dom, const char *path, virDomainInterfaceStatsPtr stats);

ACK with minor nits fixed.

Maxim

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