[PATCH] vz: support virDomainGetBlockInfo in driver

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

 



Actually physical size is not available in vz sdk right now so let's
set it to allocation as an estimation in non sparse case.
---
 src/vz/vz_driver.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/vz/vz_sdk.c    | 23 +++++++++++++++++++++++
 src/vz/vz_sdk.h    |  1 +
 3 files changed, 74 insertions(+)

diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c
index 9a429f4..7b32558 100644
--- a/src/vz/vz_driver.c
+++ b/src/vz/vz_driver.c
@@ -4005,6 +4005,55 @@ vzDomainBlockResize(virDomainPtr domain,
     return ret;
 }
 
+static int
+vzDomainGetBlockInfo(virDomainPtr domain,
+                     const char *path,
+                     virDomainBlockInfoPtr info,
+                     unsigned int flags)
+{
+    virDomainObjPtr dom;
+    virDomainDiskDefPtr disk;
+    long long allocation;
+    bool job = false;
+    int ret = -1;
+
+    virCheckFlags(0, -1);
+
+    if (!(dom = vzDomObjFromDomainRef(domain)))
+        return -1;
+
+    if (virDomainGetBlockInfoEnsureACL(domain->conn, dom->def) < 0)
+        goto cleanup;
+
+    if (vzDomainObjBeginJob(dom) < 0)
+        goto cleanup;
+    job = true;
+
+    if (vzEnsureDomainExists(dom) < 0)
+        goto cleanup;
+
+    if (!(disk = virDomainDiskByName(dom->def, path, false))) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("invalid path %s not assigned to domain"), path);
+        goto cleanup;
+    }
+
+    if ((allocation = prlsdkGetDiskAllocation(dom, disk)) < 0)
+        goto cleanup;
+
+    info->capacity = disk->src->capacity;
+    info->allocation = allocation;
+    info->physical = allocation;
+
+    ret = 0;
+
+ cleanup:
+    if (job)
+        vzDomainObjEndJob(dom);
+    virDomainObjEndAPI(&dom);
+    return ret;
+}
+
 static virHypervisorDriver vzHypervisorDriver = {
     .name = "vz",
     .connectOpen = vzConnectOpen,            /* 0.10.0 */
@@ -4106,6 +4155,7 @@ static virHypervisorDriver vzHypervisorDriver = {
     .domainAbortJob = vzDomainAbortJob, /* 3.1.0 */
     .domainReset = vzDomainReset, /* 3.1.0 */
     .domainBlockResize = vzDomainBlockResize, /* 3.3.0 */
+    .domainGetBlockInfo = vzDomainGetBlockInfo, /* 3.4.0 */
 };
 
 static virConnectDriver vzConnectDriver = {
diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c
index 4d2c6b0..b8f561c 100644
--- a/src/vz/vz_sdk.c
+++ b/src/vz/vz_sdk.c
@@ -4962,3 +4962,26 @@ int prlsdkResizeImage(virDomainObjPtr dom, virDomainDiskDefPtr disk,
     PrlHandle_Free(prldisk);
     return ret;
 }
+
+long long prlsdkGetDiskAllocation(virDomainObjPtr dom,
+                                  virDomainDiskDefPtr disk)
+{
+    vzDomObjPtr privdom = dom->privateData;
+    PRL_HANDLE job;
+    PRL_HANDLE prldisk;
+    PRL_UINT32 size;
+    PRL_RESULT pret;
+
+    job = PrlVm_RefreshConfig(privdom->sdkdom);
+    if (waitDomainJob(job, dom))
+        return -1;
+
+    prldisk = prlsdkGetDisk(privdom->sdkdom, disk);
+    if (prldisk == PRL_INVALID_HANDLE)
+        return -1;
+
+    pret = PrlVmDevHd_GetSizeOnDisk(prldisk, &size);
+    prlsdkCheckRetExit(pret, -1);
+
+    return ((unsigned long long)size) << 20;
+}
diff --git a/src/vz/vz_sdk.h b/src/vz/vz_sdk.h
index 0a77431..6b73067 100644
--- a/src/vz/vz_sdk.h
+++ b/src/vz/vz_sdk.h
@@ -91,3 +91,4 @@ PRL_HANDLE
 prlsdkSdkDomainLookupByName(vzDriverPtr driver, const char *name);
 int prlsdkCancelJob(virDomainObjPtr dom);
 int prlsdkResizeImage(virDomainObjPtr dom, virDomainDiskDefPtr disk, unsigned long long newsize);
+long long prlsdkGetDiskAllocation(virDomainObjPtr dom, virDomainDiskDefPtr disk);
-- 
1.8.3.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]
  Powered by Linux