]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Fix virStorageBackendUpdateVolTargetInfo type check
authorJohn Ferlan <jferlan@redhat.com>
Tue, 6 Dec 2016 11:17:20 +0000 (06:17 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 18 Jan 2017 11:09:38 +0000 (06:09 -0500)
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.

src/storage/storage_backend.c
src/storage/storage_backend.h
src/storage/storage_backend_fs.c

index 453f20acf02f8b62658831156cfa84ab83800fa8..742dc07db6a1560a5b81390c7946a53a29fa60a9 100644 (file)
@@ -1869,6 +1869,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
@@ -1881,7 +1882,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)
@@ -1898,7 +1900,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)) {
@@ -1969,13 +1971,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,
index 3f0403907474ddd4f2023057a6941154c8e8b93a..b00b0f897819709041a999cf448411b794496699 100644 (file)
@@ -226,7 +226,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);
index c3f7959380c66bf3c4bd9e773f3ef5894a7a9e4e..ecf74de491d7bbd030a1b7cbe50f3b897f017e26 100644 (file)
@@ -875,7 +875,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,