[PATCH 04/11] storage: Add writelabel bool for virStorageBackendDeviceProbe

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



It's possible that the API could be called from a startup path in
order to check whether the label on the device matches what our
format is. In order to handle that condition, add a 'writelabel'
boolean to the API in order to indicate whether a write or just
read is about to happen.

This alters two "error" conditions that would care about knowing.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/storage/storage_backend.c    | 26 +++++++++++++++++++-------
 src/storage/storage_backend.h    |  3 ++-
 src/storage/storage_backend_fs.c |  2 +-
 3 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index 065f2ef..834973d 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -2730,6 +2730,7 @@ virStorageBackendBLKIDProbePart(blkid_probe probe,
 /*
  * @device: Path to device
  * @format: Desired format
+ * @writelabel: True if desire to write the label
  *
  * Use the blkid_ APIs in order to get details regarding whether a file
  * system or partition exists on the disk already.
@@ -2740,7 +2741,8 @@ virStorageBackendBLKIDProbePart(blkid_probe probe,
  */
 static int
 virStorageBackendBLKIDProbe(const char *device,
-                            const char *format)
+                            const char *format,
+                            bool writelabel)
 {
 
     int ret = -1;
@@ -2768,7 +2770,12 @@ virStorageBackendBLKIDProbe(const char *device,
 
     switch (rc) {
     case VIR_STORAGE_BLKID_PROBE_UNDEFINED:
-        ret = 0;
+        if (writelabel)
+            ret = 0;
+        else
+            virReportError(VIR_ERR_STORAGE_PROBE_FAILED,
+                           _("Device '%s' is unrecognized, requires build"),
+                           device);
         break;
 
     case VIR_STORAGE_BLKID_PROBE_ERROR:
@@ -2784,9 +2791,12 @@ virStorageBackendBLKIDProbe(const char *device,
         break;
 
     case VIR_STORAGE_BLKID_PROBE_MATCH:
-        virReportError(VIR_ERR_STORAGE_POOL_BUILT,
-                       _("Device '%s' already formatted using '%s'"),
-                       device, format);
+        if (writelabel)
+            virReportError(VIR_ERR_STORAGE_POOL_BUILT,
+                           _("Device '%s' already formatted using '%s'"),
+                           device, format);
+        else
+            ret = 0;
         break;
 
     case VIR_STORAGE_BLKID_PROBE_DIFFERENT:
@@ -2827,6 +2837,7 @@ virStorageBackendBLKIDProbe(const char *device ATTRIBUTE_UNUSED,
 /* virStorageBackendDeviceProbeEmpty:
  * @devpath: Path to the device to check
  * @format: Desired format string
+ * @writelabel: True if the caller expects to write the label
  *
  * Check if the @devpath has some sort of known file system using the
  * BLKID API if available.
@@ -2836,9 +2847,10 @@ virStorageBackendBLKIDProbe(const char *device ATTRIBUTE_UNUSED,
  */
 bool
 virStorageBackendDeviceProbeEmpty(const char *devpath,
-                                  const char *format)
+                                  const char *format,
+                                  bool writelabel)
 {
-    if (virStorageBackendBLKIDProbe(devpath, format) == 0)
+    if (virStorageBackendBLKIDProbe(devpath, format, writelabel) == 0)
         true;
 
     return false;
diff --git a/src/storage/storage_backend.h b/src/storage/storage_backend.h
index 75f2ed6..4adc075 100644
--- a/src/storage/storage_backend.h
+++ b/src/storage/storage_backend.h
@@ -159,7 +159,8 @@ int virStorageBackendVolWipeLocal(virConnectPtr conn,
                                   unsigned int flags);
 
 bool virStorageBackendDeviceProbeEmpty(const char *devpath,
-                                       const char *format);
+                                       const char *format,
+                                       bool writelabel);
 
 typedef struct _virStorageBackend virStorageBackend;
 typedef virStorageBackend *virStorageBackendPtr;
diff --git a/src/storage/storage_backend_fs.c b/src/storage/storage_backend_fs.c
index c3986af..db5b340 100644
--- a/src/storage/storage_backend_fs.c
+++ b/src/storage/storage_backend_fs.c
@@ -693,7 +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 &&
-               virStorageBackendDeviceProbeEmpty(device, format)) {
+               virStorageBackendDeviceProbeEmpty(device, format, true)) {
         ok_to_mkfs = true;
     }
 
-- 
2.7.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux