Rename virStorageBackendFileSystemProbe and to virStorageBackendBLKIDProbe
and move to the more common storage_backend module.
Create a shim virStorageBackendDeviceProbeEmpty which will make the call
to the virStorageBackendBLKIDProbeFS and check the return value.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/storage/storage_backend.c | 120 +++++++++++++++++++++++++++++++++++++++
src/storage/storage_backend.h | 3 +
src/storage/storage_backend_fs.c | 90 +----------------------------
3 files changed, 124 insertions(+), 89 deletions(-)
diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index f2fc038..2432b54 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -42,6 +42,10 @@
# endif
#endif
+#if WITH_BLKID
+# include <blkid/blkid.h>
+#endif
+
#if WITH_SELINUX
# include <selinux/selinux.h>
#endif
@@ -2632,3 +2636,119 @@ virStorageBackendFindGlusterPoolSources(const char *host
ATTRIBUTE_UNUSED,
return 0;
}
#endif /* #ifdef GLUSTER_CLI */
+
+
+#if WITH_BLKID
+/*
+ * @device: Path to device
+ * @format: Desired format
+ *
+ * Use the blkid_ APIs in order to get details regarding whether a file
+ * system exists on the disk already.
+ *
+ * Returns @virStoragePoolProbeResult value, where any error will also
+ * set the error message.
+ */
+static virStoragePoolProbeResult
+virStorageBackendBLKIDProbeFS(const char *device,
+ const char *format)
+{
+
+ virStoragePoolProbeResult ret = FILESYSTEM_PROBE_ERROR;
+ blkid_probe probe = NULL;
+ const char *fstype = NULL;
+ char *names[2], *libblkid_format = NULL;
+
+ VIR_DEBUG("Probing for existing filesystem of type %s on device %s",
+ format, device);
+
+ if (blkid_known_fstype(format) == 0) {
+ virReportError(VIR_ERR_STORAGE_PROBE_FAILED,
+ _("Not capable of probing for "
+ "filesystem of type %s"),
+ format);
+ goto error;
+ }
+
+ probe = blkid_new_probe_from_filename(device);
+ if (probe == NULL) {
+ virReportError(VIR_ERR_STORAGE_PROBE_FAILED,
+ _("Failed to create filesystem probe "
+ "for device %s"),
+ device);
+ goto error;
+ }
+
+ if (VIR_STRDUP(libblkid_format, format) < 0)
+ goto error;
+
+ names[0] = libblkid_format;
+ names[1] = NULL;
+
+ blkid_probe_filter_superblocks_type(probe,
+ BLKID_FLTR_ONLYIN,
+ names);
+
+ if (blkid_do_probe(probe) != 0) {
+ VIR_INFO("No filesystem of type '%s' found on device
'%s'",
+ format, device);
+ ret = FILESYSTEM_PROBE_NOT_FOUND;
+ } 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);
+ ret = FILESYSTEM_PROBE_FOUND;
+ }
+
+ if (blkid_do_probe(probe) != 1) {
+ virReportError(VIR_ERR_STORAGE_PROBE_FAILED, "%s",
+ _("Found additional probes to run, "
+ "filesystem probing may be incorrect"));
+ ret = FILESYSTEM_PROBE_ERROR;
+ }
+
+ error:
+ VIR_FREE(libblkid_format);
+
+ if (probe != NULL)
+ blkid_free_probe(probe);
+
+ return ret;
+}
+
+#else /* #if WITH_BLKID */
+
+static virStoragePoolProbeResult
+virStorageBackendBLKIDProbeFS(const char *device ATTRIBUTE_UNUSED,
+ const char *format ATTRIBUTE_UNUSED)
+{
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("probing for filesystems is unsupported "
+ "by this build"));
+ return FILESYSTEM_PROBE_ERROR;
+}
+
+#endif /* #if WITH_BLKID */
+
+
+/* virStorageBackendDeviceProbeEmpty:
+ * @devpath: Path to the device to check
+ * @format: Desired format string
+ *
+ * Check if the @devpath has some sort of known file system using the
+ * BLKID API if available.
+ *
+ * Returns true if the probe deems the device has nothing valid on it
+ * and returns false if the probe finds something
+ */
+bool
+virStorageBackendDeviceProbeEmpty(const char *devpath,
+ const char *format)
+{
+ if (virStorageBackendBLKIDProbeFS(devpath, format) ==
+ FILESYSTEM_PROBE_NOT_FOUND)
+ true;
+
+ return false;
+}
diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h
index 28e1a65..75f2ed6 100644
--- a/src/storage/storage_backend.h
+++ b/src/storage/storage_backend.h
@@ -158,6 +158,9 @@ int virStorageBackendVolWipeLocal(virConnectPtr conn,
unsigned int algorithm,
unsigned int flags);
+bool virStorageBackendDeviceProbeEmpty(const char *devpath,
+ const char *format);
+
typedef struct _virStorageBackend virStorageBackend;
typedef virStorageBackend *virStorageBackendPtr;
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index de0e8d5..c29791b 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -37,10 +37,6 @@
#include <libxml/tree.h>
#include <libxml/xpath.h>
-#if WITH_BLKID
-# include <blkid/blkid.h>
-#endif
-
#include "virerror.h"
#include "storage_backend_fs.h"
#include "storage_conf.h"
@@ -617,89 +613,6 @@ virStorageBackendFileSystemStart(virConnectPtr conn
ATTRIBUTE_UNUSED,
}
#endif /* WITH_STORAGE_FS */
-#if WITH_BLKID
-static virStoragePoolProbeResult
-virStorageBackendFileSystemProbe(const char *device,
- const char *format)
-{
-
- virStoragePoolProbeResult ret = FILESYSTEM_PROBE_ERROR;
- blkid_probe probe = NULL;
- const char *fstype = NULL;
- char *names[2], *libblkid_format = NULL;
-
- VIR_DEBUG("Probing for existing filesystem of type %s on device %s",
- format, device);
-
- if (blkid_known_fstype(format) == 0) {
- virReportError(VIR_ERR_STORAGE_PROBE_FAILED,
- _("Not capable of probing for "
- "filesystem of type %s"),
- format);
- goto error;
- }
-
- probe = blkid_new_probe_from_filename(device);
- if (probe == NULL) {
- virReportError(VIR_ERR_STORAGE_PROBE_FAILED,
- _("Failed to create filesystem probe "
- "for device %s"),
- device);
- goto error;
- }
-
- if (VIR_STRDUP(libblkid_format, format) < 0)
- goto error;
-
- names[0] = libblkid_format;
- names[1] = NULL;
-
- blkid_probe_filter_superblocks_type(probe,
- BLKID_FLTR_ONLYIN,
- names);
-
- if (blkid_do_probe(probe) != 0) {
- VIR_INFO("No filesystem of type '%s' found on device
'%s'",
- format, device);
- ret = FILESYSTEM_PROBE_NOT_FOUND;
- } 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);
- ret = FILESYSTEM_PROBE_FOUND;
- }
-
- if (blkid_do_probe(probe) != 1) {
- virReportError(VIR_ERR_STORAGE_PROBE_FAILED, "%s",
- _("Found additional probes to run, "
- "filesystem probing may be incorrect"));
- ret = FILESYSTEM_PROBE_ERROR;
- }
-
- error:
- VIR_FREE(libblkid_format);
-
- if (probe != NULL)
- blkid_free_probe(probe);
-
- return ret;
-}
-
-#else /* #if WITH_BLKID */
-
-static virStoragePoolProbeResult
-virStorageBackendFileSystemProbe(const char *device ATTRIBUTE_UNUSED,
- const char *format ATTRIBUTE_UNUSED)
-{
- virReportError(VIR_ERR_OPERATION_INVALID, "%s",
- _("probing for filesystems is unsupported "
- "by this build"));
-
- return FILESYSTEM_PROBE_ERROR;
-}
-
-#endif /* #if WITH_BLKID */
/* some platforms don't support mkfs */
#ifdef MKFS
@@ -780,8 +693,7 @@ virStorageBackendMakeFileSystem(virStoragePoolObjPtr pool,
if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) {
ok_to_mkfs = true;
} else if (flags & VIR_STORAGE_POOL_BUILD_NO_OVERWRITE &&
- virStorageBackendFileSystemProbe(device, format) ==
- FILESYSTEM_PROBE_NOT_FOUND) {
+ virStorageBackendDeviceProbeEmpty(device, format)) {
ok_to_mkfs = true;
}
--
2.7.4