https://bugzilla.redhat.com/show_bug.cgi?id=1363586
There's actually a couple of bugs here...
only the "input" format type, so any other "types" of format would
be
filtered during the blkid_do_probe resulting in allowing a new format
type to overwrite a previous format type since when it's determined a
format type cannot be determined that we'd return 0 (or prior to the
previous patch a NOT_FOUND value). So instead of passing just one type
to filter on, pass the entire list of virStoragePoolFormatFileSystem
types. According to recent docs, this call may be unnecessary unless
we care about superblock probing only. Ironically, if the on disk
format type was the same as the requested format, the code would then
fail on the else condition (fixed in #2).
was returning -1 (or prior to previous patch FOUND) with an error
which caused the caller to just fail. So even though it was found
it did nothing. Change that to compare the on disk type with the
passed format type and return 0 or -1 as necessary.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/storage/storage_backend_fs.c | 26 +++++++++++++-------------
1 file changed, 13 insertions(+), 13 deletions(-)
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index 2413e82..74b278d 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -626,7 +626,8 @@ virStorageBackendFileSystemProbe(const char *device,
int ret = -1;
blkid_probe probe = NULL;
const char *fstype = NULL;
- char *names[2], *libblkid_format = NULL;
+ size_t i;
+ const char *names[VIR_STORAGE_POOL_FS_LAST] = {0};
VIR_DEBUG("Probing for existing filesystem of type %s on device %s",
format, device);
@@ -648,25 +649,26 @@ virStorageBackendFileSystemProbe(const char *device,
goto error;
}
- if (VIR_STRDUP(libblkid_format, format) < 0)
- goto error;
-
- names[0] = libblkid_format;
- names[1] = NULL;
+ for (i = 1; i < VIR_STORAGE_POOL_FS_LAST; i++)
+ names[i - 1] = virStoragePoolFormatFileSystemTypeToString(i);
blkid_probe_filter_superblocks_type(probe,
BLKID_FLTR_ONLYIN,
- names);
+ (char **)names);
if (blkid_do_probe(probe) != 0) {
VIR_INFO("No filesystem of type '%s' found on device
'%s'",
format, device);
ret = 0;
} else if (blkid_probe_lookup_value(probe, "TYPE", &fstype, NULL) == 0)
{
- virReportError(VIR_ERR_STORAGE_POOL_BUILT,
- _("Existing filesystem of type '%s' found on "
- "device '%s'"),
- fstype, device);
+ if (STRNEQ(fstype, format)) {
+ virReportError(VIR_ERR_STORAGE_POOL_BUILT,
+ _("Existing filesystem of type '%s' found on
"
+ "device '%s'"),
+ fstype, device);
+ } else {
+ ret = 0;
+ }
}
if (blkid_do_probe(probe) != 1) {
@@ -677,8 +679,6 @@ virStorageBackendFileSystemProbe(const char *device,
}
error:
- VIR_FREE(libblkid_format);
-
if (probe != NULL)
blkid_free_probe(probe);
--
2.7.4