Skip to contentSkip to conversation

dm: fix printk errors about whether %lu/%Lu is right for sector_t - revised

PATCH In review [email protected] 2 participants 4 messages Oct 22, 2004 – Oct 25, 2004 Device mapper

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dm: fix printk errors about whether %lu/%Lu is right for sector_t - revised

The Device Manager code barfs when sector_t is 64bit wide (i.e. an u64) and CONFIG_LBD is off. This happens on printk(), resulting in wrong memory accesses, but also on sscanf(), resulting in overflows (because it uses %lu for a long long in this case). And region_t, chunk_t are typedefs for sector_t, so we have warnings for these, too.

Andrew Morton suggested simply using "%llu" and casting sector_t to unsigned long long; but he missed the sscanf()'s, which cannot be fixed this way.

I've used %llu instead of %Lu for standards conformance, as suggested by

The problem is this code in drivers/md/dm.h:
/*
* FIXME: I think this should be with the definition of sector_t
* in types.h.
*/
#ifdef CONFIG_LBD
#define SECTOR_FORMAT "%Lu"
#else
#define SECTOR_FORMAT "%lu"
#endif

So we must fix the FIXME. However, having sector_t defined by the arch is wrong in all current cases, and we fix these: we can simply decide this in linux/types.h following CONFIG_LBD.

So, I have also removed HAVE_SECTOR_T; you can readd it, but it has no users.

All 64-bit arch use a 64-bit wide long for sector_t; almost all 32-bit archs use a long long only if CONFIG_LBD is on. The only exception is h8300: for that case, we add CONFIG_LBD = y and we are again in the general case. And x86_64 does not need to define sector_t on its own.

Sample warnings (from both 2.6.8.1 and 2.6.9-rc2):
drivers/md/dm-raid1.c: In function `get_mirror':
drivers/md/dm-raid1.c:930: warning: long unsigned int format, sector_t arg (arg 3) drivers/md/dm-raid1.c: In function `mirror_status':
drivers/md/dm-raid1.c:1200: warning: long unsigned int format, region_t arg (arg 4) drivers/md/dm-raid1.c:1200: warning: long unsigned int format, region_t arg (arg 5) drivers/md/dm-raid1.c:1206: warning: long unsigned int format, sector_t arg (arg 5) drivers/md/dm-raid1.c:1212: warning: long unsigned int format, sector_t arg (arg 5)

---

 linux-2.6.9-current-paolo/arch/h8300/Kconfig         |    4 ++++
 linux-2.6.9-current-paolo/drivers/md/dm.h            |   10 ----------
 linux-2.6.9-current-paolo/include/asm-h8300/types.h  |    3 ---
 linux-2.6.9-current-paolo/include/asm-i386/types.h   |    5 -----
 linux-2.6.9-current-paolo/include/asm-mips/types.h   |    5 -----
 linux-2.6.9-current-paolo/include/asm-ppc/types.h    |    5 -----
 linux-2.6.9-current-paolo/include/asm-s390/types.h   |    5 -----
 linux-2.6.9-current-paolo/include/asm-sh/types.h     |    5 -----
 linux-2.6.9-current-paolo/include/asm-x86_64/types.h |    3 ---
 linux-2.6.9-current-paolo/include/linux/types.h      |   17 ++++++++++++++---
 10 files changed, 18 insertions(+), 44 deletions(-)
drivers/md/dm.h renamed from drivers/md/dm.h~fix-dm-warnings +0 -10
diff -puN drivers/md/dm.h~fix-dm-warnings drivers/md/dm.h
@@ -22,16 +22,6 @@
 #define DMEMIT(x...) sz += ((sz >= maxlen) ? \
 			  0 : scnprintf(result + sz, maxlen - sz, x))
 
-/*
- * FIXME: I think this should be with the definition of sector_t
- * in types.h.
- */
-#ifdef CONFIG_LBD
-#define SECTOR_FORMAT "%Lu"
-#else
-#define SECTOR_FORMAT "%lu"
-#endif
-
 #define SECTOR_SHIFT 9
 
 /*
include/asm-h8300/types.h renamed from include/asm-h8300/types.h~fix-dm-warnings +0 -3
diff -puN include/asm-h8300/types.h~fix-dm-warnings include/asm-h8300/types.h
@@ -55,9 +55,6 @@ typedef unsigned long long u64;
 
 typedef u32 dma_addr_t;
 
-#define HAVE_SECTOR_T
-typedef u64 sector_t;
-
 typedef unsigned int kmem_bufctl_t;
 
 #endif /* __KERNEL__ */
include/asm-i386/types.h renamed from include/asm-i386/types.h~fix-dm-warnings +0 -5
diff -puN include/asm-i386/types.h~fix-dm-warnings include/asm-i386/types.h
@@ -58,11 +58,6 @@ typedef u32 dma_addr_t;
 #endif
 typedef u64 dma64_addr_t;
 
-#ifdef CONFIG_LBD
-typedef u64 sector_t;
-#define HAVE_SECTOR_T
-#endif
-
 typedef unsigned short kmem_bufctl_t;
 
 #endif /* __ASSEMBLY__ */
include/asm-mips/types.h renamed from include/asm-mips/types.h~fix-dm-warnings +0 -5
diff -puN include/asm-mips/types.h~fix-dm-warnings include/asm-mips/types.h
@@ -94,11 +94,6 @@ typedef unsigned long long phys_t;
 typedef unsigned long phys_t;
 #endif
 
-#ifdef CONFIG_LBD
-typedef u64 sector_t;
-#define HAVE_SECTOR_T
-#endif
-
 typedef unsigned short kmem_bufctl_t;
 
 #endif /* __ASSEMBLY__ */
include/asm-ppc/types.h renamed from include/asm-ppc/types.h~fix-dm-warnings +0 -5
diff -puN include/asm-ppc/types.h~fix-dm-warnings include/asm-ppc/types.h
@@ -57,11 +57,6 @@ typedef __vector128 vector128;
 typedef u32 dma_addr_t;
 typedef u64 dma64_addr_t;
 
-#ifdef CONFIG_LBD
-typedef u64 sector_t;
-#define HAVE_SECTOR_T
-#endif
-
 typedef unsigned int kmem_bufctl_t;
 
 #endif /* __ASSEMBLY__ */
include/asm-s390/types.h renamed from include/asm-s390/types.h~fix-dm-warnings +0 -5
diff -puN include/asm-s390/types.h~fix-dm-warnings include/asm-s390/types.h
@@ -90,11 +90,6 @@ typedef union {
 	} subreg;
 } register_pair;
 
-#ifdef CONFIG_LBD
-typedef u64 sector_t;
-#define HAVE_SECTOR_T
-#endif
-
 #endif /* ! __s390x__   */
 #endif /* __ASSEMBLY__  */
 #endif /* __KERNEL__    */
include/asm-sh/types.h renamed from include/asm-sh/types.h~fix-dm-warnings +0 -5
diff -puN include/asm-sh/types.h~fix-dm-warnings include/asm-sh/types.h
@@ -53,11 +53,6 @@ typedef unsigned long long u64;
 
 typedef u32 dma_addr_t;
 
-#ifdef CONFIG_LBD
-typedef u64 sector_t;
-#define HAVE_SECTOR_T
-#endif
-
 typedef unsigned int kmem_bufctl_t;
 
 #endif /* __ASSEMBLY__ */
include/asm-x86_64/types.h renamed from include/asm-x86_64/types.h~fix-dm-warnings +0 -3
diff -puN include/asm-x86_64/types.h~fix-dm-warnings include/asm-x86_64/types.h
@@ -48,9 +48,6 @@ typedef unsigned long long u64;
 typedef u64 dma64_addr_t;
 typedef u64 dma_addr_t;
 
-typedef u64 sector_t;
-#define HAVE_SECTOR_T
-
 typedef unsigned short kmem_bufctl_t;
 
 #endif /* __ASSEMBLY__ */
include/linux/types.h renamed from include/linux/types.h~fix-dm-warnings +14 -3
diff -puN include/linux/types.h~fix-dm-warnings include/linux/types.h
@@ -125,12 +125,23 @@ typedef		__s64		int64_t;
 
 /*
  * The type used for indexing onto a disc or disc partition.
- * If required, asm/types.h can override it and define
- * HAVE_SECTOR_T
+ * You cannot override it any more in asm- includes; define CONFIG_LBD
+ * to turn it inside a long long (only on 32-bit archs).
+ * The DM code must also scanf sector_t's, so here we define SECTOR_FORMAT
+ * for them.
  */
-#ifndef HAVE_SECTOR_T
+
+#ifndef CONFIG_LBD
 typedef unsigned long sector_t;
+#define SECTOR_FORMAT "%lu"
+#else /* CONFIG_LBD */
+#if BITS_PER_LONG == 64
+#error Cannot define CONFIG_LBD on 64-bit archs.
+#else
+typedef unsigned long long sector_t;
+#define SECTOR_FORMAT "%llu"
 #endif
+#endif /* CONFIG_LBD */
 
 /*
  * The type of an index into the pagecache.  Use a #define so asm/types.h
arch/h8300/Kconfig renamed from arch/h8300/Kconfig~fix-dm-warnings +4 -0
diff -puN arch/h8300/Kconfig~fix-dm-warnings arch/h8300/Kconfig
@@ -25,6 +25,10 @@ config UID16
 	bool
 	default y
 
+config LBD
+	bool
+	default y
+
 config RWSEM_GENERIC_SPINLOCK
 	bool
 	default y

_

#1 lore raw
Quoted 6 lines · [email protected] wrote:

The Device Manager code barfs when sector_t is 64bit wide (i.e. an u64) and
CONFIG_LBD is off. This happens on printk(), resulting in wrong memory accesses, but also on sscanf(), resulting in overflows (because it uses %lu for a long long in this case). And region_t, chunk_t are typedefs for sector_t, so we have warnings for these, too.

This patch caused the x86_64 build to puke: "Not allowed to define CONFIG_LBD on this architecture" or some such.

I'd much prefer that you simply remove SECTOR_FORMAT completely.

#2 lore raw
Quoted 9 lines · Andrew Morton
Quoted 5 lines · [email protected] wrote:

The Device Manager code barfs when sector_t is 64bit wide (i.e. an u64) and CONFIG_LBD is off. This happens on printk(), resulting in wrong memory accesses, but also on sscanf(), resulting in overflows (because it uses %lu for a long long in this case). And region_t, chunk_t are typedefs for sector_t, so we have warnings for these, too.

This patch caused the x86_64 build to puke: "Not allowed to define CONFIG_LBD on this architecture" or some such.

Yes, there is an #error directive for this.

Who would ever need to use CONFIG_LBD when sector_t is already 64-bit? So this is flagged as an error (feel free to remove that, if you know a good reason).

In fact, this is your fault, given both the 2.6.9 kernel and the 2.6.10-rc1 one:

config LBD
bool "Support for Large Block Devices"
depends on X86 || MIPS32 || PPC32 || ARCH_S390_31 || SUPERH help
Say Y here if you want to attach large (bigger than 2TB) discs to your machine, or if you want to have a raid or loopback device bigger than 2TB. Otherwise say N.

So if you define LBD on a x86_64 kernel, you get to keep the pieces.

A make oldconfig would probably help - don't you think so?

Quoted 1 line

I'd much prefer that you simply remove SECTOR_FORMAT completely.

Impossible - doing a scanf and then copying the value is much uglier. I just add 5 lines of code to avoid the problem, while removing the silly HAVE_SECTOR_T trick and moving the CONFIG_LBD handling to arch-independent code.

Signature · 2 lines
Paolo Giarrusso, aka Blaisorblade
Linux registered user n. 292729
#3 lore raw
Quoted 4 lines · BlaisorBlade
Quoted 2 lines

I'd much prefer that you simply remove SECTOR_FORMAT completely.

Impossible - doing a scanf and then copying the value is much uglier.

Put this in ll_rw_blk.c:

/*
* Parse an ascii decimal number into a sector_t. Return 1 on success */
int str_to_sector_t(const char *str, sector_t *sector)

{
	unsigned long long val;
	int ret;

	ret = sscanf(str, "%llu", &val);
	if (ret == 1)
		*sector = val;
	return ret;
}

EXPORT_SYMBOL(str_to_sector_t);