[PATCH 07/11] storage: Adjust disk label found to match labels

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

 



Currently as long as the disk is formatted using a known parted format
type, the algorithm is happy to continue. However, that leaves a scenario
whereby a disk formatted using "pc98" could be used by a pool that's defined
using "dvh" (or vice versa). Alter the check to be match and different
and adjust the caller.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/storage/storage_backend.c | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/storage/storage_backend.c b/src/storage/storage_backend.c
index cc04d3a..6dd0fa9 100644
--- a/src/storage/storage_backend.c
+++ b/src/storage/storage_backend.c
@@ -2852,7 +2852,8 @@ virStorageBackendBLKIDProbe(const char *device ATTRIBUTE_UNUSED,
 
 typedef enum {
     VIR_STORAGE_PARTED_ERROR = -1,
-    VIR_STORAGE_PARTED_FOUND,       /* Valid label found */
+    VIR_STORAGE_PARTED_MATCH,       /* Valid label found and matches format */
+    VIR_STORAGE_PARTED_DIFFERENT,   /* Valid label found but not match format */
     VIR_STORAGE_PARTED_UNKNOWN,     /* No or unrecognized label */
     VIR_STORAGE_PARTED_NOPTTYPE,    /* Did not find the Partition Table type */
     VIR_STORAGE_PARTED_PTTYPE_UNK,  /* Partition Table type unknown*/
@@ -2865,7 +2866,8 @@ typedef enum {
  * returns virStorageBackendPARTEDResult
  */
 static virStorageBackendPARTEDResult
-virStorageBackendPARTEDFindLabel(const char *device)
+virStorageBackendPARTEDFindLabel(const char *device,
+                                 const char *format)
 {
     const char *const args[] = {
         device, "print", "--script", NULL,
@@ -2913,7 +2915,11 @@ virStorageBackendPARTEDFindLabel(const char *device)
         goto cleanup;
     }
 
-    ret = VIR_STORAGE_PARTED_FOUND;
+    /*  Does the on disk match what the pool desired? */
+    if (STREQ(start, format))
+        ret = VIR_STORAGE_PARTED_MATCH;
+
+    ret = VIR_STORAGE_PARTED_DIFFERENT;
 
  cleanup:
     virCommandFree(cmd);
@@ -2943,12 +2949,13 @@ virStorageBackendPARTEDFindLabel(const char *device)
  */
 static int
 virStorageBackendPARTEDValidLabel(const char *device,
+                                  const char *format,
                                   bool writelabel)
 {
     int ret = -1;
     virStorageBackendPARTEDResult check;
 
-    check = virStorageBackendPARTEDFindLabel(device);
+    check = virStorageBackendPARTEDFindLabel(device, format);
     switch (check) {
     case VIR_STORAGE_PARTED_ERROR:
         virReportError(VIR_ERR_OPERATION_FAILED, "%s",
@@ -2956,15 +2963,21 @@ virStorageBackendPARTEDValidLabel(const char *device,
                          "disk partition information"));
         break;
 
-    case VIR_STORAGE_PARTED_FOUND:
+    case VIR_STORAGE_PARTED_MATCH:
         if (writelabel)
-            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                           _("Valid disk label already present, "
-                             "requires --overwrite"));
+            virReportError(VIR_ERR_OPERATION_INVALID,
+                           _("Disk label already formatted using '%s'"),
+                           format);
         else
             ret = 0;
         break;
 
+    case VIR_STORAGE_PARTED_DIFFERENT:
+        virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                       _("Known, but different label format present, "
+                         "requires build --overwrite"));
+        break;
+
     case VIR_STORAGE_PARTED_UNKNOWN:
         if (writelabel)
             ret = 0;
@@ -3008,7 +3021,7 @@ virStorageBackendDeviceProbeEmpty(const char *devpath,
     int ret;
 
     if ((ret = virStorageBackendBLKIDProbe(devpath, format, writelabel)) == -2)
-        ret = virStorageBackendPARTEDValidLabel(devpath, writelabel);
+        ret = virStorageBackendPARTEDValidLabel(devpath, format, writelabel);
 
     if (ret == 0)
         return 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