[libvirt] [PATCH v3 4/4] logical: Display thin lv's found in a libvirt managed volume group

John Ferlan jferlan at redhat.com
Mon Feb 1 20:29:53 UTC 2016


Modify the regex for the 'devices' (a/k/a 'extents') from "(\\S+)"
(e.g., 1 or more) to "(\\S*)" (e.g., zero or more).

Then for any "thin" lv's found, mark the volume as a sparse volume so
that the volume wipe algorithm doesn't work.

Since a "thin" segtype has no devices, this will result in any "thin"
lv part of some thin-pool within a volume group used as a libvirt pool
to be displayed as a possible volume to use.

NB:
Based on a proposal authored by Joe Harvell <joe.harvell at tekcomms.com>,
but with much intervening rework, the resulting patch is changed from
the original concept. About all that remains is changing the regex and
checking for NULL/empty field during parse.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/storage/storage_backend_logical.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/storage/storage_backend_logical.c b/src/storage/storage_backend_logical.c
index eb22fd0..601a896 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -88,9 +88,13 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDefPtr vol,
     unsigned long long offset, size, length;
     virStorageVolSourceExtent extent;
 
+    /* If the devices field is NULL or empty, then there's nothing to do */
+    if (!groups[3] || !*groups[3])
+        return 0;
+
     memset(&extent, 0, sizeof(extent));
 
-    /* Assume 1 extent (the regex for 'devices' is "(\\S+)") and only
+    /* Assume 1 extent (since we checked for NULL or empty above) and only
      * check the 'stripes' field if we have a striped, mirror, or one of
      * the raid (raid1, raid4, raid5*, raid6*, or raid10) segtypes in which
      * case the stripes field will denote the number of lv's within the
@@ -257,13 +261,15 @@ virStorageBackendLogicalMakeVol(char **const groups,
             goto cleanup;
     }
 
-    /* Mark the (s) sparse/snapshot lv, e.g. the lv created using
-     * the --virtualsize/-V option. We've already ignored the (t)hin
-     * pool definition. In the manner libvirt defines these, the
-     * thin pool is hidden to the lvs output, except as the name
-     * in brackets [] described for the groups[1] (backingStore).
+    /* Mark the (s) sparse/snapshot or the (V) thin/thin-pool member lv,
+     * e.g. the lv created using the --virtualsize/-V option to ensure
+     * the volume wipe algorithm doesn't overwrite sparse/thin volumes.
+     * We've already ignored the (t)hin pool definition. In the manner
+     * libvirt defines these, the thin pool is hidden to the lvs output,
+     * except as the name in brackets [] described for the groups[1]
+     * (backingStore).
      */
-    if (attrs[0] == 's')
+    if (attrs[0] == 's' || attrs[0] == 'V')
         vol->target.sparse = true;
 
     /* Skips the backingStore of lv created with "--virtualsize",
@@ -342,7 +348,7 @@ virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
      *    striped, so "," is not a suitable separator either (rhbz 727474).
      */
     const char *regexes[] = {
-       "^\\s*(\\S+)#(\\S*)#(\\S+)#(\\S+)#(\\S+)#([0-9]+)#(\\S+)#([0-9]+)#([0-9]+)#(\\S+)#?\\s*$"
+       "^\\s*(\\S+)#(\\S*)#(\\S+)#(\\S*)#(\\S+)#([0-9]+)#(\\S+)#([0-9]+)#([0-9]+)#(\\S+)#?\\s*$"
     };
     int vars[] = {
         10
-- 
2.5.0




More information about the libvir-list mailing list