Skip to contentSkip to conversation

master - select: add support for selection to match string list subset, recognize { } operator

PATCH Peter Rajnoha 1 participant 1 message Aug 13, 2014

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=fa793bed64a728185a9f8aa6196f0d411f89daf5
Commit:        fa793bed64a728185a9f8aa6196f0d411f89daf5
Parent:        6dd98c1fa89abb8ee9b91504a73d3a1c3f10e6d4
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Wed Aug 13 15:39:03 2014 +0200
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Wed Aug 13 16:10:12 2014 +0200

select: add support for selection to match string list subset, recognize { } operator

Using "[ ]" operator together with "&&" (or ",") inside causes the string list to be matched if and only if all the items given match the value reported and the number of items also match. This is strict list matching and the original behaviour we already have.

In contrast to that, the new "{ }" operator together with "&&" inside causes the string list to be matched if and only if all the items given match the value reported but the number of items don't need to match. So we can provide a subset in selection criteria and if the subset is found, it matches.

For example:

$ lvs -o name,tags
  LV    LV Tags
  lvol0 a
  lvol1 a,b
  lvol2 b,c,x
  lvol3 a,b,y
$ lvs -o name,tags -S 'tags=[a,b]'
  LV    LV Tags
  lvol1 a,b
$ lvs -o name,tags -S 'tags={a,b}'
  LV    LV Tags
  lvol1 a,b
  lvol3 a,b,y

So in the example above the a,b is subset of a,b,y and therefore it also matches.

Clearly, when using "||" (or "#") inside, the { } and [ ] is the same:

$ lvs -o name,tags -S 'tags=[a#b]'
  LV    LV Tags
  lvol0 a
  lvol1 a,b
  lvol2 b,c,x
  lvol3 a,b,y
$ lvs -o name,tags -S 'tags={a#b}'
  LV    LV Tags
  lvol0 a
  lvol1 a,b
  lvol2 b,c,x
  lvol3 a,b,y

Also in addition to the above feature, fix list with single value matching when using [ ]:

Before this patch:

$ lvs -o name,tags -S 'tags=[a]'
  LV    LV Tags
  lvol0 a
  lvol1 a,b
  lvol3 a,b,y

With this patch applied:

$ lvs -o name,tags -S 'tags=[a]'
  LV    LV Tags
  lvol0 a

In case neither [] or {} is used, assume {} (the behaviour is not changed here):

$ lvs -o name,tags -S 'tags=a'
  LV    LV Tags
  lvol0 a
  lvol1 a,b
  lvol3 a,b,y

So in new terms 'tags=a' is equal to 'tags={a}'.

---
 WHATS_NEW_DM         |    2 +
 libdm/libdm-report.c |  109 +++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 92 insertions(+), 19 deletions(-)
WHATS_NEW_DM +2 -0
index 7bb3f4c..cf74aca 100644
@@ -1,5 +1,7 @@
 Version 1.02.89 -
 =================================
+  Add support for selection to match string list subset, recognize { } operator.
+  Fix string list selection with '[value]' to not match list that's superset.
   Fix string list selection to match whole words only, not prefixes.
 
 Version 1.02.88 - 5th August 2014
libdm/libdm-report.c +90 -19

199 lines not on this page · raw message