]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: Alter logic when both BLKID and PARTED unavailable
authorJohn Ferlan <jferlan@redhat.com>
Fri, 13 Jan 2017 00:29:40 +0000 (19:29 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Sat, 14 Jan 2017 15:13:05 +0000 (10:13 -0500)
If neither BLKID or PARTED is available and we're not writing, then
just return 0 which allows the underlying storage pool to generate
a failure. If both are unavailable and we're writing, then generate
a more generic error message.

src/storage/storage_backend.c

index 18433e9c7e791be3369f85d9a6963127fe7e4f58..cf7e68a5cd764555260577191ded80d323828686 100644 (file)
@@ -2842,9 +2842,6 @@ virStorageBackendBLKIDFindEmpty(const char *device ATTRIBUTE_UNUSED,
                                 const char *format ATTRIBUTE_UNUSED,
                                 bool writelabel ATTRIBUTE_UNUSED)
 {
-    virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                   _("probing for filesystems is unsupported "
-                     "by this build"));
     return -2;
 }
 
@@ -2868,11 +2865,10 @@ virStorageBackendPARTEDValidLabel(const char *device ATTRIBUTE_UNUSED,
                                   const char *format ATTRIBUTE_UNUSED,
                                   bool writelabel ATTRIBUTE_UNUSED)
 {
-    virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                   _("PARTED is unsupported by this build"));
-    return -1;
+    return -2;
 }
 
+
 #endif /* #if WITH_STORAGE_DISK */
 
 
@@ -2885,7 +2881,9 @@ virStorageBackendPARTEDValidLabel(const char *device ATTRIBUTE_UNUSED,
  * 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
+ * or when we cannot check and we're not writing the label.
+ *
+ * Returns false if the probe finds something
  */
 bool
 virStorageBackendDeviceIsEmpty(const char *devpath,
@@ -2898,5 +2896,15 @@ virStorageBackendDeviceIsEmpty(const char *devpath,
                                                writelabel)) == -2)
         ret = virStorageBackendPARTEDValidLabel(devpath, format, writelabel);
 
+    if (ret == -2 && !writelabel)
+        ret = 0;
+
+    if (ret == -2) {
+        virReportError(VIR_ERR_OPERATION_INVALID,
+                       _("Unable to probe '%s' for existing data, "
+                         "forced overwrite is necessary"),
+                       devpath);
+    }
+
     return ret == 0;
 }