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.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/storage/storage_backend_disk.c | 29 ++++++++++++++++++++++++++++-
1 file changed, 28 insertions(+), 1 deletion(-)
diff --git a/src/storage/storage_backend_disk.c b/src/storage/storage_backend_disk.c
index b66a4a1..c6317a2 100644
--- a/src/storage/storage_backend_disk.c
+++ b/src/storage/storage_backend_disk.c
@@ -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,
--
2.1.0