Skip to contentSkip to conversation

master - select: fix matching reserved values while <, <=, >, >= is used in selection criteria

PATCH Peter Rajnoha 1 participant 1 message Apr 24, 2015

lore
Share & tools
lore
#0 lore raw
Gitweb:        http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=82f6dbfaf7b62c044cd765c207bd8eb1db0edc5a
Commit:        82f6dbfaf7b62c044cd765c207bd8eb1db0edc5a
Parent:        de0ce46361d65af7fb58699e4aba0b649551a6a8
Author:        Peter Rajnoha <[email protected]>
AuthorDate:    Fri Apr 24 09:47:25 2015 +0200
Committer:     Peter Rajnoha <[email protected]>
CommitterDate: Fri Apr 24 09:48:57 2015 +0200

select: fix matching reserved values while <,<=,>,>= is used in selection criteria

Scenario:

$ vgs -o+vg_mda_copies
  VG     #PV #LV #SN Attr   VSize VFree #VMdaCps
  fedora   1   2   0 wz--n- 9.51g    0  unmanaged
  vg      16   9   0 wz--n- 1.94g 1.83g         2
$ lvs -o+read_ahead vg/lvol6 vg/lvol7
  LV    VG   Attr       LSize Pool Origin Data%  Rahead
  lvol6 vg   Vwi-a-tz-- 1.00g pool lvol5  0.00      auto
  lvol7 vg   Vwi---tz-k 1.00g pool lvol6         256.00k

Before this patch:

$vgs -o vg_name,vg_mda_copies -S 'vg_mda_copies < unmanaged'
VG #VMdaCps
vg 2

Problem:
Reserved values can be only used with exact match = or !=, not <,<=,>,>=. In the example above, the "unamanaged" is internally represented as 18446744073709551615, but this should be ignored while not comparing field directly with "unmanaged" reserved name with = or !=. Users should not be aware of this internal mapping of the reserved value name to its internal value and hence it doesn't make sense for such reserved value to take place in results of <,<=,> and >=. There's no order defined for reserved values!!! It's a special *reserved* value that is taken out of the usual value range of that type.

This is very similar to what we have already fixed with 2f7f6932dcd450ba75fe590aba8c09838d2618dc, but it's the other way round now - we're using reserved value name in selection criteria now (in the patch 2f7f693, we had concrete value and we compared it with the reserved value). So this patch completes patch 2f7f693.

This patch also fixes this problem:

$ lvs -o+read_ahead vg/lvol6 vg/lvol7 -S 'read_ahead > 32k'
  LV    VG   Attr       LSize Pool Origin Data%  Rahead
  lvol6 vg   Vwi-a-tz-- 1.00g pool lvol5  0.00      auto
  lvol7 vg   Vwi---tz-k 1.00g pool lvol6         256.00k

Problem:
In the example above, the internal reserved value "auto" is in the range of selection "> 32k" - it shouldn't match as well. Here the "auto" is internally represented as MAX_DBL and of course, numerically, MAX_DBL > 256k. But for users, the reserved value should be uncomparable to any number so the mapping of the reserved value name to its interna
value is transparent to users. Again, there's no order defined for
reserved values and hence it should never match if using <,<=,>,>= operators.

This is actually exactly the same problem as already described in 2f7f6932dcd450ba75fe590aba8c09838d2618dc, but that patch failed for size field types because of incorrect internal representation used.

With this patch applied, both problematic scenarios mentioned above are fixed now:

$ vgs -o vg_name,vg_mda_copies -S 'vg_mda_copies < unmanaged'
(blank)
$ lvs -o+read_ahead vg/lvol6 vg/lvol7 -S 'read_ahead > 32k'
  LV    VG   Attr       LSize Pool Origin Rahead
  lvol7 vg   Vwi---tz-k 1.00g pool lvol6  256.00k
---
 WHATS_NEW_DM         |    2 +
 lib/report/report.c  |   18 ++++++---
 lib/report/values.h  |    2 +-
 libdm/libdm-report.c |  103 +++++++++++++++++++++++++++++---------------------
 4 files changed, 75 insertions(+), 50 deletions(-)
WHATS_NEW_DM +2 -0
index cead126..dda91a2 100644
@@ -1,5 +1,7 @@
 Version 1.02.96 - 
 =================================
+  Fix selection to not match if using reserved value in criteria with >,<,>=,<.
+  Fix selection to not match reserved values for size fields if using >,<,>=,<.
   Include uuid or device number in log message after ioctl failure.
   Add DM_INTERNAL_SUSPEND_FLAG to dm-ioctl.h.
   Install blkdeactivate script and its man page with make install_device-mapper.
lib/report/report.c +12 -6
index 86b0a54..c29acdb 100644
@@ -26,6 +26,7 @@
 #include "str_list.h"
 
 #include <stddef.h> /* offsetof() */
+#include <float.h> /* DBL_MAX */
 
 struct lvm_report_object {
 	struct volume_group *vg;
@@ -54,6 +55,7 @@ static const char _str_one[] = "1";
 static const char _str_no[] = "no";
 static const char _str_yes[] = "yes";
 static const char _str_unknown[] = "unknown";
+static const double _siz_max = DBL_MAX;
 
 /*
  * 32 bit signed is casted to 64 bit unsigned in dm_report_field internally!
@@ -94,6 +96,7 @@ static const int32_t _reserved_num_undef_32 = INT32_C(-1);
  * 		- 'reserved_value_id_n' (for 0)
  */
 #define NUM uint64_t
+#define SIZ double
 
 #define TYPE_RESERVED_VALUE(type, id, desc, value, ...) \
 	static const char *_reserved_ ## id ## _names[] = { __VA_ARGS__, NULL}; \
@@ -110,6 +113,7 @@ static const int32_t _reserved_num_undef_32 = INT32_C(-1);
 #include "values.h"
 
 #undef NUM
+#undef SIZ
 #undef TYPE_RESERVED_VALUE
 #undef FIELD_RESERVED_VALUE
 #undef FIELD_RESERVED_BINARY_VALUE
@@ -122,6 +126,7 @@ static const int32_t _reserved_num_undef_32 = INT32_C(-1);
 */
 
 #define NUM DM_REPORT_FIELD_TYPE_NUMBER
+#define SIZ DM_REPORT_FIELD_TYPE_SIZE
 
 #define TYPE_RESERVED_VALUE(type, id, desc, value, ...) {type, &_reserved_ ## id, _reserved_ ## id ## _names, desc},
 
@@ -133,10 +138,11 @@ static const int32_t _reserved_num_undef_32 = INT32_C(-1);
 
 static const struct dm_report_reserved_value _report_reserved_values[] = {
 	#include "values.h"
-	{0, NULL, NULL}
+	{0, NULL, NULL, NULL}
 };
 
 #undef NUM
+#undef SIZ
 #undef TYPE_RESERVED_VALUE
 #undef FIELD_RESERVED_VALUE
 #undef FIELD_RESERVED_BINARY_VALUE
@@ -659,7 +665,7 @@ static int _size32_disp(struct dm_report *rh __attribute__((unused)), struct dm_
 {
 	const uint32_t size = *(const uint32_t *) data;
 	const char *disp, *repstr;
-	uint64_t *sortval;
+	double *sortval;
 
 	if (!*(disp = display_size_units(private, (uint64_t) size)))
 		return_0;
@@ -674,7 +680,7 @@ static int _size32_disp(struct dm_report *rh __attribute__((unused)), struct dm_
 		return 0;
 	}
 
-	*sortval = (uint64_t) size;
+	*sortval = (double) size;
 
 	return _field_set_value(field, repstr, sortval);
 }
@@ -686,7 +692,7 @@ static int _size64_disp(struct dm_report *rh __attribute__((unused)),
 {
 	const uint64_t size = *(const uint64_t *) data;
 	const char *disp, *repstr;
-	uint64_t *sortval;
+	double *sortval;
 
 	if (!*(disp = display_size_units(private, size)))
 		return_0;
@@ -696,12 +702,12 @@ static int _size64_disp(struct dm_report *rh __attribute__((unused)),
 		return 0;
 	}
 
-	if (!(sortval = dm_pool_alloc(mem, sizeof(uint64_t)))) {
+	if (!(sortval = dm_pool_alloc(mem, sizeof(double)))) {
 		log_error("dm_pool_alloc failed");
 		return 0;
 	}
 
-	*sortval = size;
+	*sortval = (double) size;
 
 	return _field_set_value(field, repstr, sortval);
 }
lib/report/values.h +1 -1
index bc42563..dd20caf 100644
@@ -83,7 +83,7 @@ FIELD_RESERVED_BINARY_VALUE(zero, zero, "", "zero")
 FIELD_RESERVED_VALUE(lv_permissions, lv_permissions_rw, "", "writeable", "writeable", "rw", "read-write")
 FIELD_RESERVED_VALUE(lv_permissions, lv_permissions_r, "", "read-only", "read-only", "r", "ro")
 FIELD_RESERVED_VALUE(lv_permissions, lv_permissions_r_override, "", "read-only-override", "read-only-override", "ro-override", "r-override", "R")
-FIELD_RESERVED_VALUE(lv_read_ahead, lv_read_ahead_auto, "", &GET_TYPE_RESERVED_VALUE(num_undef_64), "auto")
+FIELD_RESERVED_VALUE(lv_read_ahead, lv_read_ahead_auto, "", &_siz_max, "auto")
 FIELD_RESERVED_VALUE(lv_when_full, lv_when_full_error, "", "error", "error", "error when full", "error if no space")
 FIELD_RESERVED_VALUE(lv_when_full, lv_when_full_queue, "", "queue", "queue", "queue when full", "queue if no space")
 FIELD_RESERVED_VALUE(lv_when_full, lv_when_full_undef, "", "", "", "undefined")
libdm/libdm-report.c +60 -43

208 lines not on this page · raw message