[libvirt] [PATCHv3 10/11] storage: Add overwrite flag checking for logical pool

John Ferlan jferlan at redhat.com
Thu Dec 15 21:42:15 UTC 2016


Add support and documentation for the [NO_]OVERWRITE flags for the
logical backend.

Update virsh.pod with a description of the process for usage of
the flags and building of the pool's volume group.

Signed-off-by: John Ferlan <jferlan at redhat.com>

  v2: http://www.redhat.com/archives/libvir-list/2016-November/msg00810.html

  Changes are too numerous to mention, but suffice to say this patch will
  add the overwrite checking much the same as the fs and disk backing storage
  makes the checks. The only really "odd" part is that I found using the
  'blkid -p /dev/XXX' that the target devices for a logical pool are formatted
  and blkid knows them as "LVM2_member" - so I went with it.

 src/libvirt_private.syms              |  1 +
 src/storage/storage_backend_logical.c | 18 +++++++++++++++---
 tools/virsh.pod                       | 12 +++++++++++-
 3 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 7beebbf..02f4c38 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -876,6 +876,7 @@ virStoragePoolFormatDiskTypeFromString;
diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index 2d8e288..f128941 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -759,17 +759,29 @@ virStorageBackendLogicalBuildPool(virConnectPtr conn ATTRIBUTE_UNUSED,
                                   virStoragePoolObjPtr pool,
                                   unsigned int flags)
-    virCommandPtr vgcmd;
+    virCommandPtr vgcmd = NULL;
     int ret = -1;
-    size_t i;
+    size_t i = 0;
-    virCheckFlags(0, -1);
+                  VIR_STORAGE_POOL_BUILD_NO_OVERWRITE, ret);
+                             VIR_STORAGE_POOL_BUILD_NO_OVERWRITE,
+                             cleanup);
     vgcmd = virCommandNewArgList(VGCREATE, pool->def->source.name, NULL);
     for (i = 0; i < pool->def->source.ndevice; i++) {
         const char *path = pool->def->source.devices[i].path;
+        /* The blkid FS and Part probing code doesn't know "lvm2" (this
+         * pool's only format type), but it does know "LVM2_member", so
+         * we'll pass that here */
+        if (!(flags & VIR_STORAGE_POOL_BUILD_OVERWRITE) &&
+            !virStorageBackendDeviceProbeEmpty(path, "LVM2_member", true))
+            goto cleanup;
         if (virStorageBackendLogicalInitializeDevice(path) < 0)
             goto cleanup;
diff --git a/tools/virsh.pod b/tools/virsh.pod
index fd0f7fa..2813fe2 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -3452,7 +3452,7 @@ Configure whether I<pool> should automatically start at boot.
 Build a given pool.
 Options I<--overwrite> and I<--no-overwrite> can only be used for
-B<pool-build> a filesystem or disk pool.
+B<pool-build> a filesystem, disk, or logical pool.
 For a file system pool if neither flag is specified, then B<pool-build>
 just makes the target path directory and no attempt to run mkfs on the
@@ -3471,6 +3471,16 @@ then no check will be made on the target volume device prior to writing
 a new label. Writing of the label uses the pool source format type
 or "dos" if not specified.
+For a logical pool, if neither of them is specified or I<--no-overwrite>
+is specified, B<pool-build> will check the target volume devices for
+existing filesystems or partitions before attempting to initialize
+and format each device for usage by the logical pool. If any target
+volume device already has a label, the command will fail. If
+I<--overwrite> is specified, then no check will be made on the target
+volume devices prior to initializing and formatting each device. Once
+all the target volume devices are properly formatted via pvcreate,
+the volume group will be created using all the devices.
 =item B<pool-create> I<file>
 [I<--build>] [[I<--overwrite>] | [I<--no-overwrite>]]

More information about the libvir-list mailing list