]> xenbits.xensource.com Git - libvirt.git/commitdiff
storage: Add writelabel bool for virStorageBackendDeviceProbe
authorJohn Ferlan <jferlan@redhat.com>
Wed, 14 Dec 2016 23:03:20 +0000 (18:03 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 10 Jan 2017 13:44:50 +0000 (08:44 -0500)
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@redhat.com>
src/storage/storage_backend.c
src/storage/storage_backend.h
src/storage/storage_backend_fs.c

index 6be928e992144651b6710a44b1b045f931c9cfee..fb7b744f60ef9d80f9bf49c7b88ca454c1de62f8 100644 (file)
@@ -2730,6 +2730,7 @@ virStorageBackendBLKIDFindPart(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 @@ virStorageBackendBLKIDFindPart(blkid_probe probe,
  */
 static int
 virStorageBackendBLKIDFindEmpty(const char *device,
-                                const char *format)
+                                const char *format,
+                                bool writelabel)
 {
 
     int ret = -1;
@@ -2768,7 +2770,12 @@ virStorageBackendBLKIDFindEmpty(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 @@ virStorageBackendBLKIDFindEmpty(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:
@@ -2813,7 +2823,8 @@ virStorageBackendBLKIDFindEmpty(const char *device,
 
 static int
 virStorageBackendBLKIDFindEmpty(const char *device ATTRIBUTE_UNUSED,
-                                const char *format ATTRIBUTE_UNUSED)
+                                const char *format ATTRIBUTE_UNUSED,
+                                bool writelabel ATTRIBUTE_UNUSED)
 {
     virReportError(VIR_ERR_OPERATION_INVALID, "%s",
                    _("probing for filesystems is unsupported "
@@ -2827,6 +2838,7 @@ virStorageBackendBLKIDFindEmpty(const char *device ATTRIBUTE_UNUSED,
 /* virStorageBackendDeviceIsEmpty:
  * @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,7 +2848,8 @@ virStorageBackendBLKIDFindEmpty(const char *device ATTRIBUTE_UNUSED,
  */
 bool
 virStorageBackendDeviceIsEmpty(const char *devpath,
-                               const char *format)
+                               const char *format,
+                               bool writelabel)
 {
-    return virStorageBackendBLKIDFindEmpty(devpath, format) == 0;
+    return virStorageBackendBLKIDFindEmpty(devpath, format, writelabel) == 0;
 }
index c7b2e32d184bd83be46e06bfda7bd835b5819762..7ae8d58dbc29775f596655734071378605159ef9 100644 (file)
@@ -159,7 +159,8 @@ int virStorageBackendVolWipeLocal(virConnectPtr conn,
                                   unsigned int flags);
 
 bool virStorageBackendDeviceIsEmpty(const char *devpath,
-                                    const char *format);
+                                    const char *format,
+                                    bool writelabel);
 
 typedef struct _virStorageBackend virStorageBackend;
 typedef virStorageBackend *virStorageBackendPtr;
index ba4f598975960fa0ff7617109a0c64a7306a4734..f0ef07b2fae724e03a9b13eab9ac6de9653de61a 100644 (file)
@@ -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 &&
-               virStorageBackendDeviceIsEmpty(device, format)) {
+               virStorageBackendDeviceIsEmpty(device, format, true)) {
         ok_to_mkfs = true;
     }