Skip to contentSkip to conversation

Fix and cleanups

PATCH New Zdenek Kabelac 2 participants 5 messages Dec 11, 2009 – Dec 14, 2009

lore
Share & tools
lore
#0 lore raw

cover Fix and cleanups

This patchset fixed 'dmsetup info -c -o all'
Update one log error message
And makes lvm compilable with clang by using standard offsetof() macro.

Zdenek Kabelac (3):
Fix reporting dmsetup info -c -o all
Report unrecognised key instead of field
Use standard C macro offsetof()

 lib/report/report.c  |   25 ++++++++++++-------------
 libdm/libdm-report.c |    6 ++++--
 2 files changed, 16 insertions(+), 15 deletions(-)
#1 lore raw

PATCH 1/3 Fix reporting dmsetup info -c -o all

Use whole bitmask of all options.

---
 libdm/libdm-report.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
libdm/libdm-report.c +3 -1
index 6784a11..339213e 100644
@@ -379,7 +379,9 @@ static uint32_t _all_match(struct dm_report *rh, const char *field, size_t flen)
 			       _all_match(rh, prefixed_all,
 					  strlen(prefixed_all));
 		} else
-			return rh->report_types;
+			/* all without type use full bitmask */
+			return (!rh->report_types)
+				? UINT_MAX : rh->report_types;
 	}
 
 	for (t = rh->types; t->data_fn; t++) {
Signature · 1 line
1.6.5.3
#2 lore raw

PATCH 1/3 Fix reporting dmsetup info -c -o all

Quoted 1 line · Zdenek Kabelac

Use whole bitmask of all options.

IOW fixes
dmsetup info -c -o all
to work and print all possible values.

ACK.

libdm/libdm-report.c static uint32_t _all_match(struct dm_report *rh, const char *field, size_t flen) · line 384

Quoted 8 lines
libdm/libdm-report.c +3 -1
@@ -379,7 +379,9 @@ static uint32_t _all_match(struct dm_report *rh, const char *field, size_t flen)
 			       _all_match(rh, prefixed_all,
 					  strlen(prefixed_all));
 		} else
-			return rh->report_types;
+			/* all without type use full bitmask */
+			return (!rh->report_types)
+				? UINT_MAX : rh->report_types;

IMHO better

#define DM_REPORT_TYPE_ALL_FIELDS ~0
(or something like that instead of UINT_MAX)

libdm/libdm-report.c static uint32_t _all_match(struct dm_report *rh, const char *field, size_t flen) · line 387

Quoted 3 lines
libdm/libdm-report.c +0 -0
 	}
 
 	for (t = rh->types; t->data_fn; t++) {

Milan

#3 lore raw

PATCH 2/3 Report unrecognised key instead of field

In reply to Zdenek Kabelac
---
 libdm/libdm-report.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
libdm/libdm-report.c +1 -1
index 339213e..ecd3717 100644
@@ -549,7 +549,7 @@ static int _parse_keys(struct dm_report *rh, const char *keys,
 		while (*we && *we != ',')
 			we++;
 		if (!_key_match(rh, ws, (size_t) (we - ws), report_type_only)) {
-			log_error("dm_report: Unrecognised field: %.*s",
+			log_error("dm_report: Unrecognised key: %.*s",
 				  (int) (we - ws), ws);
 			return 0;
 		}
Signature · 1 line
1.6.5.3
#4 lore raw

PATCH 3/3 Use standard C macro offsetof()

In reply to Zdenek Kabelac

Patch uses <stddef.h> defined offsetof() macro and avoids usage of _dummy union (safe few bytes in bss)

---
 lib/report/report.c |   25 ++++++++++++-------------
 1 files changed, 12 insertions(+), 13 deletions(-)
lib/report/report.c +12 -13
index 54192d5..31e3174 100644
@@ -24,6 +24,8 @@
 #include "str_list.h"
 #include "lvmcache.h"
 
+#include <stddef.h> /* offsetof() */
+
 struct lvm_report_object {
 	struct volume_group *vg;
 	struct logical_volume *lv;
@@ -32,17 +34,6 @@ struct lvm_report_object {
 	struct pv_segment *pvseg;
 };
 
-/*
- * For macro use
- */
-static union {
-	struct physical_volume _pv;
-	struct logical_volume _lv;
-	struct volume_group _vg;
-	struct lv_segment _seg;
-	struct pv_segment _pvseg;
-} _dummy;
-
 static char _alloc_policy_char(alloc_policy_t alloc)
 {
 	switch (alloc) {
@@ -1156,9 +1147,17 @@ static const struct dm_report_object_type _report_types[] = {
 
 #define STR DM_REPORT_FIELD_TYPE_STRING
 #define NUM DM_REPORT_FIELD_TYPE_NUMBER
-#define FIELD(type, strct, sorttype, head, field, width, func, id, desc) {type, sorttype, (off_t)((uintptr_t)&_dummy._ ## strct.field - (uintptr_t)&_dummy._ ## strct), width, id, head, &_ ## func ## _disp, desc},
+#define FIELD(type, strct, sorttype, head, field, width, func, id, desc) \
+	{type, sorttype, offsetof(type_ ## strct, field), width, \
+	 id, head, &_ ## func ## _disp, desc},
+
+typedef struct physical_volume type_pv;
+typedef struct logical_volume type_lv;
+typedef struct volume_group type_vg;
+typedef struct lv_segment type_seg;
+typedef struct pv_segment type_pvseg;
 
-static struct dm_report_field_type _fields[] = {
+static const struct dm_report_field_type _fields[] = {
 #include "columns.h"
 {0, 0, 0, 0, "", "", NULL, NULL},
 };
Signature · 1 line
1.6.5.3