On Wed, 2016-02-03 at 16:49 -0500, John Ferlan wrote:
Rather than have a unwieldy regex string - split it up into its
components
each having it's own #define and then combine in a different #define
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
src/storage/storage_backend_logical.c | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/src/storage/storage_backend_logical.c
b/src/storage/storage_backend_logical.c
index eb22fd0..ba26223 100644
--- a/src/storage/storage_backend_logical.c
+++ b/src/storage/storage_backend_logical.c
@@ -312,6 +312,34 @@ virStorageBackendLogicalMakeVol(char **const groups,
return ret;
}
+#define VIR_STORAGE_VOL_LOGICAL_PREFIX_REGEX "^\\s*"
+#define VIR_STORAGE_VOL_LOGICAL_LV_NAME_REGEX "(\\S+)#"
+#define VIR_STORAGE_VOL_LOGICAL_ORIGIN_REGEX "(\\S*)#"
+#define VIR_STORAGE_VOL_LOGICAL_UUID_REGEX "(\\S+)#"
+#define VIR_STORAGE_VOL_LOGICAL_DEVICES_REGEX "(\\S+)#"
+#define VIR_STORAGE_VOL_LOGICAL_SEGTYPE_REGEX "(\\S+)#"
+#define VIR_STORAGE_VOL_LOGICAL_STRIPES_REGEX "([0-9]+)#"
+#define VIR_STORAGE_VOL_LOGICAL_SEG_SIZE_REGEX "(\\S+)#"
+#define VIR_STORAGE_VOL_LOGICAL_VG_EXTENT_SIZE_REGEX "([0-9]+)#"
+#define VIR_STORAGE_VOL_LOGICAL_SIZE_REGEX "([0-9]+)#"
+#define VIR_STORAGE_VOL_LOGICAL_LV_ATTR_REGEX "(\\S+)#"
+#define VIR_STORAGE_VOL_LOGICAL_SUFFIX_REGEX "?\\s*$"
+
+#define VIR_STORAGE_VOL_LOGICAL_REGEX_COUNT 10
+#define VIR_STORAGE_VOL_LOGICAL_REGEX \
+ VIR_STORAGE_VOL_LOGICAL_PREFIX_REGEX \
+ VIR_STORAGE_VOL_LOGICAL_LV_NAME_REGEX \
+ VIR_STORAGE_VOL_LOGICAL_ORIGIN_REGEX \
+ VIR_STORAGE_VOL_LOGICAL_UUID_REGEX \
+ VIR_STORAGE_VOL_LOGICAL_DEVICES_REGEX \
+ VIR_STORAGE_VOL_LOGICAL_SEGTYPE_REGEX \
+ VIR_STORAGE_VOL_LOGICAL_STRIPES_REGEX \
+ VIR_STORAGE_VOL_LOGICAL_SEG_SIZE_REGEX \
+ VIR_STORAGE_VOL_LOGICAL_VG_EXTENT_SIZE_REGEX \
+ VIR_STORAGE_VOL_LOGICAL_SIZE_REGEX \
+ VIR_STORAGE_VOL_LOGICAL_LV_ATTR_REGEX \
+ VIR_STORAGE_VOL_LOGICAL_SUFFIX_REGEX
+
static int
virStorageBackendLogicalFindLVs(virStoragePoolObjPtr pool,
virStorageVolDefPtr vol)
@@ -342,10 +370,10 @@ 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*$"
+ VIR_STORAGE_VOL_LOGICAL_REGEX
};
int vars[] = {
- 10
+ VIR_STORAGE_VOL_LOGICAL_REGEX_COUNT
};
int ret = -1;
virCommandPtr cmd;
Clever way to label the various chunks, I love it. Crucially, the original
regex and the one obtained by putting all the bits together match. (See
what I did there?)
ACK.
--
Andrea Bolognani
Software Engineer - Virtualization Team