[PATCH 2/2] vz: support virDomainBlockResize

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

 



Signed-off-by: Konstantin Neumoin <kneumoin@xxxxxxxxxxxxx>
---
 src/vz/vz_driver.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/vz/vz_sdk.c    | 37 ++++++++++++++++++++++++++++++++++
 src/vz/vz_sdk.h    |  1 +
 3 files changed, 96 insertions(+)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index ed7132f..24156ca 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -3945,6 +3945,63 @@ static int vzDomainSetVcpus(virDomainPtr dom, unsigned int nvcpus)
     return vzDomainSetVcpusFlags(dom, nvcpus,
                                  VIR_DOMAIN_AFFECT_LIVE | VIR_DOMAIN_AFFECT_CONFIG);
 }
+static int
+vzDomainBlockResize(virDomainPtr domain,
+                    const char *path,
+                    unsigned long long size,
+                    unsigned int flags)
+{
+    virDomainObjPtr dom = NULL;
+    virDomainDiskDefPtr disk = NULL;
+    int ret = -1;
+    bool job = false;
+
+    virCheckFlags(VIR_DOMAIN_BLOCK_RESIZE_BYTES, -1);
+
+    if (!(dom = vzDomObjFromDomainRef(domain)))
+        goto cleanup;
+
+    if (virDomainSetVcpusFlagsEnsureACL(domain->conn, dom->def, flags) < 0)
+        goto cleanup;
+
+    if (path[0] == '\0') {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       "%s", _("empty path"));
+        goto cleanup;
+    }
+
+    /* sdk wants Mb */
+    if (flags & VIR_DOMAIN_BLOCK_RESIZE_BYTES)
+        size /= 1024;
+    size /= 1024;
+
+    if (!(disk = virDomainDiskByName(dom->def, path, false))) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("invalid path: %s"), path);
+        goto cleanup;
+    }
+
+    if (vzDomainObjBeginJob(dom) < 0)
+        goto cleanup;
+    job = true;
+
+    if (vzEnsureDomainExists(dom) < 0)
+        goto cleanup;
+
+    if (!virDomainObjIsActive(dom)) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       "%s", _("domain is not running"));
+        goto cleanup;
+    }
+
+    ret = prlsdkResizeImage(dom, disk, size);
+
+ cleanup:
+    if (job)
+        vzDomainObjEndJob(dom);
+    virDomainObjEndAPI(&dom);
+    return ret;
+}
 
 static virHypervisorDriver vzHypervisorDriver = {
     .name = "vz",
@@ -4046,6 +4103,7 @@ static virHypervisorDriver vzHypervisorDriver = {
     .connectGetAllDomainStats = vzConnectGetAllDomainStats, /* 3.1.0 */
     .domainAbortJob = vzDomainAbortJob, /* 3.1.0 */
     .domainReset = vzDomainReset, /* 3.1.0 */
+    .domainBlockResize = vzDomainBlockResize, /* 3.3.0 */
 };
 
 static virConnectDriver vzConnectDriver = {
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 2daa44a..4d2c6b0 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -4925,3 +4925,40 @@ int prlsdkSetCpuCount(virDomainObjPtr dom, unsigned int count)
  error:
     return -1;
 }
+
+int prlsdkResizeImage(virDomainObjPtr dom, virDomainDiskDefPtr disk,
+                      unsigned long long newsize)
+{
+    int ret = -1;
+    PRL_RESULT pret;
+    vzDomObjPtr privdom = dom->privateData;
+    PRL_UINT32 emulatedType;
+    PRL_HANDLE job = PRL_INVALID_HANDLE;
+    PRL_HANDLE prldisk = PRL_INVALID_HANDLE;
+
+    prldisk = prlsdkGetDisk(privdom->sdkdom, disk);
+    if (prldisk == PRL_INVALID_HANDLE)
+        goto cleanup;
+
+    pret = PrlVmDev_GetEmulatedType(prldisk, &emulatedType);
+    prlsdkCheckRetGoto(pret, cleanup);
+
+    if (emulatedType != PDT_USE_IMAGE_FILE &&
+        emulatedType != PDT_USE_FILE_SYSTEM) {
+        virReportError(VIR_ERR_INVALID_ARG, "%s",
+                       _("Only disk image supported for resize"));
+        goto cleanup;
+    }
+
+    job = PrlVmDev_ResizeImage(prldisk, newsize,
+                               PRIF_RESIZE_LAST_PARTITION);
+    if (PRL_FAILED(waitJob(job)))
+        goto cleanup;
+
+    ret = 0;
+
+ cleanup:
+
+    PrlHandle_Free(prldisk);
+    return ret;
+}
diff --git a/src/vz/vz_sdk.h b/src/vz/vz_sdk.h
index 100a5e3..0a77431 100644
--- a/src/vz/vz_sdk.h
+++ b/src/vz/vz_sdk.h
@@ -90,3 +90,4 @@ prlsdkMigrate(virDomainObjPtr dom,
 PRL_HANDLE
 prlsdkSdkDomainLookupByName(vzDriverPtr driver, const char *name);
 int prlsdkCancelJob(virDomainObjPtr dom);
+int prlsdkResizeImage(virDomainObjPtr dom, virDomainDiskDefPtr disk, unsigned long long newsize);
-- 
2.7.4

--
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]
  Powered by Linux