[PATCH v2 4/7] dumpxml: let blockinfo reuse virStorageSource

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

 



In a future patch, the implementation of VIR_DOMAIN_XML_BLOCK_INFO
will use information stored in virStorageSource.  In order to
maximize code reuse, it is easiest if BlockInfo code also uses the
same location for information.

* src/util/virstoragefile.h (_virStorageSource): Add physical, to
mirror virDomainBlockInfo.
* src/qemu/qemu_driver.c (qemuDomainGetBlockInfo): Store into
storage source, then copy to block info.

Signed-off-by: Eric Blake <eblake@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c    | 22 ++++++++++++++--------
 src/util/virstoragefile.h |  3 ++-
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index cd70fde..aa24658 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -11046,15 +11046,15 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
     /* Get info for normal formats */
     if (S_ISREG(sb.st_mode) || fd == -1) {
 #ifndef WIN32
-        info->physical = (unsigned long long)sb.st_blocks *
+        disk->src->physical = (unsigned long long)sb.st_blocks *
             (unsigned long long)DEV_BSIZE;
 #else
-        info->physical = sb.st_size;
+        disk->src->physical = sb.st_size;
 #endif
         /* Regular files may be sparse, so logical size (capacity) is not same
          * as actual physical above
          */
-        info->capacity = sb.st_size;
+        disk->src->capacity = sb.st_size;
     } else {
         /* NB. Because we configure with AC_SYS_LARGEFILE, off_t should
          * be 64 bits on all platforms.
@@ -11065,17 +11065,17 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
                                  _("failed to seek to end of %s"), path);
             goto endjob;
         }
-        info->physical = end;
-        info->capacity = end;
+        disk->src->physical = end;
+        disk->src->capacity = end;
     }

     /* If the file we probed has a capacity set, then override
      * what we calculated from file/block extents */
     if (meta->capacity)
-        info->capacity = meta->capacity;
+        disk->src->capacity = meta->capacity;

     /* Set default value .. */
-    info->allocation = info->physical;
+    disk->src->allocation = disk->src->physical;

     /* ..but if guest is not using raw disk format and on a block device,
      * then query highest allocated extent from QEMU
@@ -11097,13 +11097,19 @@ qemuDomainGetBlockInfo(virDomainPtr dom,
         qemuDomainObjEnterMonitor(driver, vm);
         ret = qemuMonitorGetBlockExtent(priv->mon,
                                         disk->info.alias,
-                                        &info->allocation);
+                                        &disk->src->allocation);
         qemuDomainObjExitMonitor(driver, vm);

     } else {
         ret = 0;
     }

+    if (ret == 0) {
+        info->capacity = disk->src->capacity;
+        info->allocation = disk->src->allocation;
+        info->physical = disk->src->physical;
+    }
+
  endjob:
     if (!qemuDomainObjEndJob(driver, vm))
         vm = NULL;
diff --git a/src/util/virstoragefile.h b/src/util/virstoragefile.h
index 2583e10..681e50a 100644
--- a/src/util/virstoragefile.h
+++ b/src/util/virstoragefile.h
@@ -252,8 +252,9 @@ struct _virStorageSource {

     virStoragePermsPtr perms;
     virStorageTimestampsPtr timestamps;
-    unsigned long long allocation; /* in bytes, 0 if unknown */
     unsigned long long capacity; /* in bytes, 0 if unknown */
+    unsigned long long allocation; /* in bytes, 0 if unknown */
+    unsigned long long physical; /* in bytes, 0 if unknown */
     size_t nseclabels;
     virSecurityDeviceLabelDefPtr *seclabels;

-- 
1.9.3

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