From d04bb05fb7e9bf057b88032ffcd6709d1b70daef Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Tue, 6 Dec 2016 06:17:20 -0500 Subject: [PATCH] storage: Fix virStorageBackendUpdateVolTargetInfo type check 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 | 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 453f20acf0..742dc07db6 100644 --- a/src/storage/storage_backend.c +++ b/src/storage/storage_backend.c @@ -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, diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h index 3f04039074..b00b0f8978 100644 --- a/src/storage/storage_backend.h +++ b/src/storage/storage_backend.h @@ -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); diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c index c3f7959380..ecf74de491 100644 --- a/src/storage/storage_backend_fs.c +++ b/src/storage/storage_backend_fs.c @@ -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, -- GitLab