[PATCH 4/8] storage: Refactor disk label checking

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

 



Create a new function virStorageBackendDiskValidLabel to handle checking
whether there is a label on the device and whether it's valid or not.
While initially for the purpose of determining whether the label can be
overwritten during DiskBuild, a future use during DiskStart could determine
whether the pool should be started using the label found.

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

diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index ba70a5a..da2a4d4 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -432,6 +432,33 @@ virStorageBackendDiskFindLabel(const char* device)
 
 
 /**
+ * Determine whether the label on the disk is valid or in a known format
+ * for the purpose of rewriting the label during build
+ *
+ * Return: True if it's OK
+ *         False if something's wrong
+ */
+static bool
+virStorageBackendDiskValidLabel(const char *device)
+{
+    bool valid = false;
+    int check;
+
+    check = virStorageBackendDiskFindLabel(device);
+    if (check > 0) {
+        valid = true;
+    } else if (check < 0) {
+        virReportError(VIR_ERR_OPERATION_FAILED, "%s",
+                       _("Error checking for disk label"));
+    } else {
+        virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                       _("Disk label already present"));
+    }
+    return valid;
+}
+
+
+/**
  * Write a new partition table header
  */
 static int
@@ -450,23 +477,11 @@ virStorageBackendDiskBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
                              VIR_STORAGE_POOL_BUILD_NO_OVERWRITE,
                              error);
 
-    if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) {
+    if (flags & VIR_STORAGE_POOL_BUILD_OVERWRITE)
         ok_to_mklabel = true;
-    } else {
-        int check;
-
-        check = virStorageBackendDiskFindLabel(
-                    pool->def->source.devices[0].path);
-        if (check > 0) {
-            ok_to_mklabel = true;
-        } else if (check < 0) {
-            virReportError(VIR_ERR_OPERATION_FAILED, "%s",
-                           _("Error checking for disk label"));
-        } else {
-            virReportError(VIR_ERR_OPERATION_INVALID, "%s",
-                           _("Disk label already present"));
-        }
-    }
+    else
+        ok_to_mklabel = virStorageBackendDiskValidLabel(
+                                            pool->def->source.devices[0].path);
 
     if (ok_to_mklabel) {
         /* eg parted /dev/sda mklabel --script msdos */
-- 
2.1.0

--
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]