]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
storage: Introduce virStorageBackendDiskStartPool
authorJohn Ferlan <jferlan@redhat.com>
Thu, 1 Oct 2015 12:38:58 +0000 (08:38 -0400)
committerJohn Ferlan <jferlan@redhat.com>
Mon, 5 Oct 2015 12:14:44 +0000 (08:14 -0400)
https://bugzilla.redhat.com/show_bug.cgi?id=1251461

When 'starting' up a disk pool, we need to make sure the label on the
device is valid; otherwise, the followup refreshPool will assume the
disk has been properly formatted for use. If we don't find the valid
label, then refuse the start and give a proper reason.

src/storage/storage_backend_disk.c

index b66a4a1a8114fc45a27834290957e41bfdc2c416..c6317a24194f11715d61f859ace3a3e4034792ed 100644 (file)
@@ -461,7 +461,8 @@ 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
+ * for the purpose of rewriting the label during build or being able to
+ * start a pool on a device.
  *
  * When 'writelabel' is true, if we find a valid disk label on the device,
  * then we shouldn't be attempting to write as the volume may contain
@@ -469,6 +470,10 @@ virStorageBackendDiskFindLabel(const char* device)
  * order to be certain. When the disk label is unrecognized, then it
  * should be safe to write.
  *
+ * When 'writelabel' is false, only if we find a valid disk label on the
+ * device should we allow the start since for this path we won't be
+ * rewriting the label.
+ *
  * Return: True if it's OK
  *         False if something's wrong
  */
@@ -509,6 +514,27 @@ virStorageBackendDiskValidLabel(const char *device,
 }
 
 
+static int
+virStorageBackendDiskStartPool(virConnectPtr conn ATTRIBUTE_UNUSED,
+                               virStoragePoolObjPtr pool)
+{
+    virFileWaitForDevices();
+
+    if (!virFileExists(pool->def->source.devices[0].path)) {
+        virReportError(VIR_ERR_INVALID_ARG,
+                       _("device path '%s' doesn't exist"),
+                       pool->def->source.devices[0].path);
+        return -1;
+    }
+
+    if (!virStorageBackendDiskValidLabel(pool->def->source.devices[0].path,
+                                         false))
+        return -1;
+
+    return 0;
+}
+
+
 /**
  * Write a new partition table header
  */
@@ -940,6 +966,7 @@ virStorageBackendDiskVolWipe(virConnectPtr conn,
 virStorageBackend virStorageBackendDisk = {
     .type = VIR_STORAGE_POOL_DISK,
 
+    .startPool = virStorageBackendDiskStartPool,
     .buildPool = virStorageBackendDiskBuildPool,
     .refreshPool = virStorageBackendDiskRefreshPool,