]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Adjust disk label found to match labels
authorJohn Ferlan <jferlan@redhat.com>
Thu, 15 Dec 2016 20:45:01 +0000 (15:45 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 10 Jan 2017 13:44:50 +0000 (08:44 -0500)
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@redhat.com>
src/storage/storage_backend.c

index 1039664542dd6eb8c05eb6715dc785bea0f689df..060b1c0673f90b263b48c416635c6438d07b974f 100644 (file)
@@ -2853,7 +2853,8 @@ virStorageBackendBLKIDFindEmpty(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*/
@@ -2866,7 +2867,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,
@@ -2914,7 +2916,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);
@@ -2944,12 +2950,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",
@@ -2957,15 +2964,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;
@@ -3010,7 +3023,7 @@ virStorageBackendDeviceIsEmpty(const char *devpath,
 
     if ((ret = virStorageBackendBLKIDFindEmpty(devpath, format,
                                                writelabel)) == -2)
-        ret = virStorageBackendPARTEDValidLabel(devpath, writelabel);
+        ret = virStorageBackendPARTEDValidLabel(devpath, format, writelabel);
 
     return ret == 0;
 }