[libvirt] [PATCH 1/2] storage: Fix virStorageBackendUpdateVolTargetInfo type check

John Ferlan jferlan at redhat.com
Tue Dec 6 23:43:38 UTC 2016


For volume processing in virStorageBackendUpdateVolTargetInfo to get
the capacity commit id 'a760ba3a7' added the ability to probe a volume
that didn't list a target format. Unfortunately, the code used the
virStorageSource  (e.g. target->type - virStorageType) rather than
virStorageVolDef (e.g. vol->type - virStorageVolType) in order to
make the comparison. As it turns out target->type for a volume is
not filled in at all for a voldef as the code relies on vol->type.
Ironically the result is that only VIR_STORAGE_VOL_BLOCK's would get
their capacity updated.

This patch will adjust the code to check the "vol->type" field instead
as an argument. This way for a voldef, the correct comparison is made.

Additionally for a backingStore, the 'type' field is never filled in;
however, since we know that the provided path is a location at which
the backing store can be accessed on the local filesystem thus just
pass VIR_STORAGE_VOL_FILE in order to satisfy the adjusted voltype
check. Whether it's a FILE or a BLOCK only matters if we're trying to
get more data based on the target->format.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/storage/storage_backend.c    | 12 ++++++++----
 src/storage/storage_backend.h    |  3 ++-
 src/storage/storage_backend_fs.c |  3 ++-
 3 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index d4334dc..cadc29a 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -1865,6 +1865,7 @@ virStorageBackendRedoPloopUpdate(virStorageSourcePtr target, struct stat *sb,
 
 /*
  * virStorageBackendUpdateVolTargetInfo
+ * @voltype: Volume type
  * @target: target definition ptr of volume to update
  * @withBlockVolFormat: true if caller determined a block file
  * @openflags: various VolOpenCheckMode flags to handle errors on open
@@ -1877,7 +1878,8 @@ virStorageBackendRedoPloopUpdate(virStorageSourcePtr target, struct stat *sb,
  * be returned if the caller passed a readflagsflag.
  */
 int
-virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
+virStorageBackendUpdateVolTargetInfo(virStorageVolType voltype,
+                                     virStorageSourcePtr target,
                                      bool withBlockVolFormat,
                                      unsigned int openflags,
                                      unsigned int readflags)
@@ -1895,7 +1897,7 @@ virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
     if ((ret = virStorageBackendUpdateVolTargetInfoFD(target, fd, &sb)) < 0)
         goto cleanup;
 
-    if (target->type == VIR_STORAGE_VOL_FILE &&
+    if (voltype == VIR_STORAGE_VOL_FILE &&
         target->format != VIR_STORAGE_FILE_NONE) {
         if (S_ISDIR(sb.st_mode)) {
             if (virStorageBackendIsPloopDir(target->path)) {
@@ -1971,13 +1973,15 @@ virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
 {
     int ret;
 
-    if ((ret = virStorageBackendUpdateVolTargetInfo(&vol->target,
+    if ((ret = virStorageBackendUpdateVolTargetInfo(vol->type,
+                                                    &vol->target,
                                                     withBlockVolFormat,
                                                     openflags, readflags)) < 0)
         return ret;
 
     if (vol->target.backingStore &&
-        (ret = virStorageBackendUpdateVolTargetInfo(vol->target.backingStore,
+        (ret = virStorageBackendUpdateVolTargetInfo(VIR_STORAGE_VOL_FILE,
+                                                    vol->target.backingStore,
                                                     withBlockVolFormat,
                                                     VIR_STORAGE_VOL_OPEN_DEFAULT |
                                                     VIR_STORAGE_VOL_OPEN_NOERROR,
diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h
index 28e1a65..50d5339 100644
--- a/src/storage/storage_backend.h
+++ b/src/storage/storage_backend.h
@@ -221,7 +221,8 @@ int virStorageBackendUpdateVolInfo(virStorageVolDefPtr vol,
                                    bool withBlockVolFormat,
                                    unsigned int openflags,
                                    unsigned int readflags);
-int virStorageBackendUpdateVolTargetInfo(virStorageSourcePtr target,
+int virStorageBackendUpdateVolTargetInfo(virStorageVolType voltype,
+                                         virStorageSourcePtr target,
                                          bool withBlockVolFormat,
                                          unsigned int openflags,
                                          unsigned int readflags);
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index de0e8d5..af80eee 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -954,7 +954,8 @@ virStorageBackendFileSystemRefresh(virConnectPtr conn ATTRIBUTE_UNUSED,
             vol->type = VIR_STORAGE_VOL_PLOOP;
 
         if (vol->target.backingStore) {
-            ignore_value(virStorageBackendUpdateVolTargetInfo(vol->target.backingStore,
+            ignore_value(virStorageBackendUpdateVolTargetInfo(VIR_STORAGE_VOL_FILE,
+                                                              vol->target.backingStore,
                                                               false,
                                                               VIR_STORAGE_VOL_OPEN_DEFAULT, 0));
             /* If this failed, the backing file is currently unavailable,
-- 
2.7.4




More information about the libvir-list mailing list