]> xenbits.xensource.com Git - libvirt.git/commitdiff
Restore skipping of setting capacity
authorJohn Ferlan <jferlan@redhat.com>
Tue, 15 Apr 2014 20:32:04 +0000 (16:32 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Fri, 2 May 2014 11:11:05 +0000 (07:11 -0400)
Commit id 'ac9a0963' refactored out the 'withCapacity' for the
virStorageBackendUpdateVolInfo() API.  See:

http://www.redhat.com/archives/libvir-list/2014-April/msg00043.html

This resulted in a difference in how 'virsh vol-info --pool <poolName>
<volume>' or 'virsh vol-list vol-list --pool <poolName> --details' outputs
the capacity information for a directory pool with a qcow2 sparse file.

For example, using the following XML

mkdir /home/TestPool
cat testpool.xml
<pool type='dir'>
  <name>TestPool</name>
  <uuid>6bf80895-10b6-75a6-6059-89fdea2aefb7</uuid>
  <source>
  </source>
  <target>
    <path>/home/TestPool</path>
    <permissions>
      <mode>0755</mode>
      <owner>0</owner>
      <group>0</group>
    </permissions>
  </target>
</pool>

virsh pool-create testpool.xml
virsh vol-create-as --pool TestPool temp_vol_1 \
      --capacity 1048576 --allocation 1048576 --format qcow2
virsh vol-info --pool TestPool temp_vol_1

Results in listing a Capacity value.  Prior to the commit, the value would
be '1.0 MiB' (1048576 bytes). However, after the commit the output would be
(for example) '192.50 KiB', which for my system was the size of the volume
in my file system (eg 'ls -l TestPool/temp_vol_1' results in '197120' bytes
or 192.50 KiB). While perhaps technically correct, it's not necessarily
what the user expected (certainly virt-test didn't expect it).

This patch restores the code to not update the target capacity for this path

src/storage/storage_backend.c
src/storage/storage_backend.h
src/storage/storage_backend_disk.c
src/storage/storage_backend_fs.c
src/storage/storage_backend_gluster.c
src/storage/storage_backend_logical.c
src/storage/storage_backend_mpath.c
src/storage/storage_backend_scsi.c

index 58468b3735bee73eb1169463b5f289026822392f..e5d1b0c906ebfae0efc4be67f640844d50b692db 100644 (file)
@@ -1403,6 +1403,7 @@ virStorageBackendVolOpen(const char *path, struct stat *sb,
 
 int
 virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
+                                     bool updateCapacity,
                                      bool withBlockVolFormat,
                                      unsigned int openflags)
 {
@@ -1413,7 +1414,8 @@ virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
         goto cleanup;
     fd = ret;
 
-    if ((ret = virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb)) < 0)
+    if ((ret = virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb,
+                                                      updateCapacity)) < 0)
         goto cleanup;
 
     if (withBlockVolFormat) {
@@ -1429,18 +1431,21 @@ virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
 
 int
 virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
+                               bool updateCapacity,
                                bool withBlockVolFormat,
                                unsigned int openflags)
 {
     int ret;
 
     if ((ret = virStorageBackendUpdateVolTargetInfo(&vol->target,
+                                    updateCapacity,
                                     withBlockVolFormat,
                                     openflags)) < 0)
         return ret;
 
     if (vol->backingStore.path &&
         (ret = virStorageBackendUpdateVolTargetInfo(&vol->backingStore,
+                                            updateCapacity,
                                             withBlockVolFormat,
                                             VIR_STORAGE_VOL_OPEN_DEFAULT)) < 0)
         return ret;
@@ -1453,15 +1458,15 @@ virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
  * @target: target definition ptr of volume to update
  * @fd: fd of storage volume to update, via virStorageBackendOpenVol*, or -1
  * @sb: details about file (must match @fd, if that is provided)
- * @allocation: If not NULL, updated allocation information will be stored
- * @capacity: If not NULL, updated capacity info will be stored
+ * @updateCapacity: If true, updated capacity info will be stored
  *
  * Returns 0 for success, -1 on a legitimate error condition.
  */
 int
 virStorageBackendUpdateVolTargetInfoFD(virStorageSourcePtr target,
                                        int fd,
-                                       struct stat *sb)
+                                       struct stat *sb,
+                                       bool updateCapacity)
 {
 #if WITH_SELINUX
     security_context_t filecon = NULL;
@@ -1477,10 +1482,12 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageSourcePtr target,
         /* Regular files may be sparse, so logical size (capacity) is not same
          * as actual allocation above
          */
-        target->capacity = sb->st_size;
+        if (updateCapacity)
+            target->capacity = sb->st_size;
     } else if (S_ISDIR(sb->st_mode)) {
         target->allocation = 0;
-        target->capacity = 0;
+        if (updateCapacity)
+            target->capacity = 0;
     } else if (fd >= 0) {
         off_t end;
         /* XXX this is POSIX compliant, but doesn't work for CHAR files,
@@ -1496,7 +1503,8 @@ virStorageBackendUpdateVolTargetInfoFD(virStorageSourcePtr target,
             return -1;
         }
         target->allocation = end;
-        target->capacity = end;
+        if (updateCapacity)
+            target->capacity = end;
     }
 
     if (!target->perms && VIR_ALLOC(target->perms) < 0)
index 5997077072c5aab84d8c2028a137257555d9d37e..456b9d764e12f9cbb99e37b44bcbbb132fd6d8b0 100644 (file)
@@ -137,14 +137,17 @@ int virStorageBackendVolOpen(const char *path, struct stat *sb,
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
 int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
+                                   bool updateCapacity,
                                    bool withBlockVolFormat,
                                    unsigned int openflags);
 int virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
+                                         bool updateCapacity,
                                          bool withBlockVolFormat,
                                          unsigned int openflags);
 int virStorageBackendUpdateVolTargetInfoFD(virStorageSourcePtr target,
                                            int fd,
-                                           struct stat *sb);
+                                           struct stat *sb,
+                                           bool updateCapacity);
 
 char *virStorageBackendStablePath(virStoragePoolObjPtr pool,
                                   const char *devpath,
index 71634c6a1dfc717605378beafb51566614689aaa..b8e69bb6e6d1c583b58925218f6786d4ac6f6a99 100644 (file)
@@ -111,7 +111,7 @@ virStorageBackendDiskMakeDataVol(virStoragePoolObjPtr pool,
     }
 
     /* Refresh allocation/capacity/perms */
-    if (virStorageBackendUpdateVolInfo(vol, false,
+    if (virStorageBackendUpdateVolInfo(vol, true, false,
                                        VIR_STORAGE_VOL_OPEN_DEFAULT) < 0)
         return -1;
 
index 0f98853a26e80aafb74a26747aa1549e34eafc9e..03b5a05cc2d7860471914a9f765299c9991a2bd6 100644 (file)
@@ -84,7 +84,8 @@ virStorageBackendProbeTarget(virStorageSourcePtr target,
         goto error; /* Take care to propagate ret, it is not always -1 */
     fd = ret;
 
-    if ((ret = virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb)) < 0) {
+    if ((ret = virStorageBackendUpdateVolTargetInfoFD(target, fd,
+                                                      &sb, true)) < 0) {
         goto error;
     }
 
@@ -914,7 +915,7 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
             vol->backingStore.format = backingStoreFormat;
 
             ignore_value(virStorageBackendUpdateVolTargetInfo(
-                                               &vol->backingStore, false,
+                                               &vol->backingStore, true, false,
                                                VIR_STORAGE_VOL_OPEN_DEFAULT));
             /* If this failed, the backing file is currently unavailable,
              * the capacity, allocation, owner, group and mode are unknown.
@@ -1192,8 +1193,10 @@ virStorageBackendFileSystemVolRefresh(virConnectPtr conn,
 {
     int ret;
 
-    /* Refresh allocation / permissions info in case its changed */
-    ret = virStorageBackendUpdateVolInfo(vol, false,
+    /* Refresh allocation / permissions info in case its changed
+     * don't update the capacity value for this pass
+     */
+    ret = virStorageBackendUpdateVolInfo(vol, false, false,
                                          VIR_STORAGE_VOL_FS_OPEN_FLAGS);
     if (ret < 0)
         return ret;
index 5ab1e7ef91fc50bced525327008aff128928979c..656e97354385492024ae5389bb556f956b5aa4ed 100644 (file)
@@ -267,7 +267,7 @@ virStorageBackendGlusterRefreshVol(virStorageBackendGlusterStatePtr state,
     if (VIR_ALLOC(vol) < 0)
         goto cleanup;
 
-    if (virStorageBackendUpdateVolTargetInfoFD(&vol->target, -1, st) < 0)
+    if (virStorageBackendUpdateVolTargetInfoFD(&vol->target, -1, st, true) < 0)
         goto cleanup;
 
     if (virStorageBackendGlusterSetMetadata(state, vol, name) < 0)
index ed3a012cfb22c72d0f2e3eb3545adcf4221864d7..a597e6745c71334d97829cc880abc1c7e02c7099 100644 (file)
@@ -149,7 +149,7 @@ virStorageBackendLogicalMakeVol(char **const groups,
     if (!vol->key && VIR_STRDUP(vol->key, groups[2]) < 0)
         goto cleanup;
 
-    if (virStorageBackendUpdateVolInfo(vol, false,
+    if (virStorageBackendUpdateVolInfo(vol, true, false,
                                        VIR_STORAGE_VOL_OPEN_DEFAULT) < 0)
         goto cleanup;
 
index f0ed189e614e40b58448d74ed2118719be3756cc..8c3b0dfae5698e573aac48107315d824645998b7 100644 (file)
@@ -60,7 +60,7 @@ virStorageBackendMpathNewVol(virStoragePoolObjPtr pool,
     if (virAsprintf(&vol->target.path, "/dev/%s", dev) < 0)
         goto cleanup;
 
-    if (virStorageBackendUpdateVolInfo(vol, true,
+    if (virStorageBackendUpdateVolInfo(vol, true, true,
                                        VIR_STORAGE_VOL_OPEN_DEFAULT) < 0) {
         goto cleanup;
     }
index d037f4688375183975030d44d87b80bbb8b00493..f6f3ca28b6b69acd076cb3518461479c1d3efbfc 100644 (file)
@@ -199,7 +199,7 @@ virStorageBackendSCSINewLun(virStoragePoolObjPtr pool,
         goto free_vol;
     }
 
-    if (virStorageBackendUpdateVolInfo(vol, true,
+    if (virStorageBackendUpdateVolInfo(vol, true, true,
                                        VIR_STORAGE_VOL_OPEN_DEFAULT) < 0) {
         retval = -1;
         goto free_vol;