Skip to contentSkip to conversation

Minor fixes and updates

PATCH New Zdenek Kabelac 1 participant 7 messages Feb 10, 2010

lore
Share & tools
lore
#0 lore raw

cover Minor fixes and updates

Set of miscelaneous updates and fixes awaiting some review
- especially the last patch

Zdenek Kabelac (6):
Cleanup gcc warning: function declaration isn't a prototype Cleanup gcc const warning
Clean gcc const warning
Cleanup float arithmetic gcc warning
Fix report_uint64
Fix compiler warning about strict-aliasing break

 lib/device/device.c  |   18 +++++++++---------
 lib/report/report.c  |   12 ++++++------
 libdm/libdm-report.c |   12 ++++++------
 tools/lvmcmdline.c   |    2 +-
 4 files changed, 22 insertions(+), 22 deletions(-)
#1 lore raw

PATCH 1/6 Cleanup gcc warning: function declaration isn't a prototype

---
 tools/lvmcmdline.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
tools/lvmcmdline.c +1 -1
index 85d6ce3..4881d54 100644
@@ -912,7 +912,7 @@ static void _apply_settings(struct cmd_context *cmd)
 	cmd->handles_missing_pvs = 0;
 }
 
-static void _set_udev_checking()
+static void _set_udev_checking(void)
 {
 	const char *e;
 
Signature · 1 line
1.6.6.1
#2 lore raw

PATCH 2/6 Cleanup gcc const warning

In reply to Zdenek Kabelac
---
 libdm/libdm-report.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
libdm/libdm-report.c +2 -2
index 9925614..aead864 100644
@@ -819,8 +819,8 @@ static int _report_headings(struct dm_report *rh)
  */
 static int _row_compare(const void *a, const void *b)
 {
-	const struct row *rowa = *(const struct row **) a;
-	const struct row *rowb = *(const struct row **) b;
+	const struct row *rowa = *(const struct row * const *) a;
+	const struct row *rowb = *(const struct row * const *) b;
 	const struct dm_report_field *sfa, *sfb;
 	uint32_t cnt;
 
Signature · 1 line
1.6.6.1
#3 lore raw

PATCH 3/6 Clean gcc const warning

In reply to Zdenek Kabelac
---
 lib/report/report.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
lib/report/report.c +4 -4
index 2cceedd..cf037cb 100644
@@ -66,7 +66,7 @@ static int _dev_name_disp(struct dm_report *rh, struct dm_pool *mem __attribute(
 			  struct dm_report_field *field,
 			  const void *data, void *private __attribute((unused)))
 {
-	const char *name = dev_name(*(const struct device **) data);
+	const char *name = dev_name(*(const struct device * const *) data);
 
 	return dm_report_field_string(rh, field, &name);
 }
@@ -795,7 +795,7 @@ static int _devsize_disp(struct dm_report *rh, struct dm_pool *mem,
 			 struct dm_report_field *field,
 			 const void *data, void *private)
 {
-	const struct device *dev = *(const struct device **) data;
+	const struct device *dev = *(const struct device * const *) data;
 	uint64_t size;
 
 	if (!dev_get_size(dev, &size))
@@ -879,7 +879,7 @@ static int _pvmdafree_disp(struct dm_report *rh, struct dm_pool *mem,
 {
 	struct lvmcache_info *info;
 	uint64_t freespace = UINT64_MAX, mda_free;
-	const char *pvid = (const char *)(&((struct id *) data)->uuid);
+	const char *pvid = (const char *)(&((const struct id *) data)->uuid);
 	struct metadata_area *mda;
 
 	if ((info = info_from_pvid(pvid, 0)))
@@ -922,7 +922,7 @@ static int _pvmdasize_disp(struct dm_report *rh, struct dm_pool *mem,
 {
 	struct lvmcache_info *info;
 	uint64_t min_mda_size = 0;
-	const char *pvid = (const char *)(&((struct id *) data)->uuid);
+	const char *pvid = (const char *)(&((const struct id *) data)->uuid);
 
 	/* PVs could have 2 mdas of different sizes (rounding effect) */
 	if ((info = info_from_pvid(pvid, 0)))
Signature · 1 line
1.6.6.1
#4 lore raw

PATCH 4/6 Cleanup float arithmetic gcc warning

In reply to Zdenek Kabelac
---
 lib/report/report.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
lib/report/report.c +2 -2
index cf037cb..e27f4e1 100644
@@ -1055,7 +1055,7 @@ static int _snpercent_disp(struct dm_report *rh __attribute((unused)), struct dm
 		return 0;
 	}
 
-	*sortval = snap_percent * UINT64_C(1000);
+	*sortval = (uint64_t)(snap_percent * 1000.f);
 	dm_report_field_set_value(field, repstr, sortval);
 
 	return 1;
@@ -1097,7 +1097,7 @@ static int _copypercent_disp(struct dm_report *rh __attribute((unused)),
 		return 0;
 	}
 
-	*sortval = percent * UINT64_C(1000);
+	*sortval = (uint64_t)(percent * 1000.f);
 	dm_report_field_set_value(field, repstr, sortval);
 
 	return 1;
Signature · 1 line
1.6.6.1
#5 lore raw

PATCH 5/6 Fix report_uint64

In reply to Zdenek Kabelac

Fix dm_report_field_uint64 to really use 64bit. Function is currently not used by lvm - so another fix might be, to complete remove this function.

---
 libdm/libdm-report.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
libdm/libdm-report.c +4 -4
index aead864..e13115a 100644
@@ -207,7 +207,7 @@ int dm_report_field_int32(struct dm_report *rh,
 int dm_report_field_uint64(struct dm_report *rh,
 			   struct dm_report_field *field, const uint64_t *data)
 {
-	const int value = *data;
+	const uint64_t value = *data;
 	uint64_t *sortval;
 	char *repstr;
 
@@ -221,12 +221,12 @@ int dm_report_field_uint64(struct dm_report *rh,
 		return 0;
 	}
 
-	if (dm_snprintf(repstr, 21, "%d", value) < 0) {
-		log_error("dm_report_field_uint64: uint64 too big: %d", value);
+	if (dm_snprintf(repstr, 21, "%" PRIu64 , value) < 0) {
+		log_error("dm_report_field_uint64: uint64 too big: %" PRIu64, value);
 		return 0;
 	}
 
-	*sortval = (const uint64_t) value;
+	*sortval = value;
 	field->sort_value = sortval;
 	field->report_string = repstr;
 
Signature · 1 line
1.6.6.1
#6 lore raw

PATCH 6/6 Fix compiler warning about strict-aliasing break

In reply to Zdenek Kabelac

This patch not really tested - and just show a possible solution for strict-alliasing error.

So patch is just a proposal of one of many solution.

---
 lib/device/device.c |   18 +++++++++---------
 1 files changed, 9 insertions(+), 9 deletions(-)
lib/device/device.c +9 -9
index 72f3eab..f6410e4 100644
@@ -58,9 +58,11 @@ static int _has_partition_table(struct device *dev)
 {
 	int ret = 0;
 	unsigned p;
-	uint16_t buf[SECTOR_SIZE/sizeof(uint16_t)];
-	uint16_t *part_magic;
-	struct partition *part;
+	struct {
+	    uint8_t skip[PART_OFFSET];
+	    struct partition part[4];
+	    uint16_t magic;
+	} __attribute__((packed)) buf; /* sizeof() == SECTOR_SIZE */
 
 	if (!dev_open(dev)) {
 		stack;
@@ -73,17 +75,15 @@ static int _has_partition_table(struct device *dev)
 	/* FIXME Check for other types of partition table too */
 
 	/* Check for msdos partition table */
-	part_magic = buf + PART_MAGIC_OFFSET/sizeof(buf[0]);
-	if ((*part_magic == xlate16(PART_MAGIC))) {
-		part = (struct partition *) (buf + PART_OFFSET/sizeof(buf[0]));
-		for (p = 0; p < 4; p++, part++) {
+	if (buf.magic == xlate16(PART_MAGIC)) {
+		for (p = 0; p < 4; p++) {
 			/* Table is invalid if boot indicator not 0 or 0x80 */
-			if ((part->boot_ind & 0x7f)) {
+			if (buf.part[p].boot_ind & 0x7f) {
 				ret = 0;
 				break;
 			}
 			/* Must have at least one non-empty partition */
-			if (part->nr_sects)
+			if (buf.part[p].nr_sects)
 				ret = 1;
 		}
 	}
Signature · 1 line
1.6.6.1