[dm-devel] [PATCH] dmsetup: Use correct major()/minor() macros.

Kevin Corry kevcorry at us.ibm.com
Thu Jun 17 15:27:18 UTC 2004


While doing some large-number-of-devices testing, I noticed that when device 
minor numbers start to go beyond 255, dmsetup no longer displays the correct 
major:minor in "dmsetup ls". I tracked this down to dmsetup using the MAJOR() 
and MINOR() macros from <linux/kdev_t.h> instead of the major() and minor() 
macros from <sys/sysmacros.h>. I've included a patch below against the latest 
device-mapper CVS tree.

To see the behavior I'm talking about, run this set of simple commands to 
create a bunch of devices. Replace /dev/hdd with an appropriate disk or 
partition.

for ((a=0; $a<3; a++)); do
   for ((b=0; $b<10; b++)); do
      for ((c=0; $c<10; c++)); do
         echo "0 1 linear /dev/hdd 0" | dmsetup create test$a$b$c
      done
   done
done

Then run "dmsetup ls |sort", and you'll get this as part of the output:

...
test253 (253, 253)
test254 (253, 254)
test255 (253, 255)
test256 (4349, 0)
test257 (4349, 1)
test258 (4350, 2)
...

This patch just changes all MAJOR() and MINOR() macros to major() and minor(). 
In order for the fix to work right, you also need a relatively recent set of 
system header files that know how to deal with the new dev_t representation 
in the 2.6 kernel.

-- 
Kevin Corry
kevcorry at us.ibm.com
http://evms.sourceforge.net/



Index: dmsetup.c
===================================================================
RCS file: /cvs/dm/device-mapper/dmsetup/dmsetup.c,v
retrieving revision 1.40
diff -u -r1.40 dmsetup.c
--- dmsetup.c	16 Jun 2004 16:44:12 -0000	1.40
+++ dmsetup.c	17 Jun 2004 20:09:31 -0000
@@ -37,14 +37,6 @@
 #  define OPTIND_INIT 1
 #endif
 
-#ifdef linux
-#  include <linux/kdev_t.h>
-#else
-#  define MAJOR(x) major((x))
-#  define MINOR(x) minor((x))
-#  define MKDEV(x,y) makedev((x),(y))
-#endif
-
 #define LINE_SIZE 1024
 
 #define err(msg, x...) fprintf(stderr, msg "\n", ##x)
@@ -658,8 +650,8 @@
 
 	for (i = 0; i < deps->count; i++)
 		printf(" (%d, %d)",
-		       (int) MAJOR(deps->device[i]),
-		       (int) MINOR(deps->device[i]));
+		       major(deps->device[i]),
+		       minor(deps->device[i]));
 	printf("\n");
 
 	if (data && _switches[VERBOSE_ARG])
@@ -677,7 +669,7 @@
 	struct dm_names *names = (struct dm_names *) data;
 
 	printf("%s\t(%d, %d)\n", names->name,
-	       (int) MAJOR(names->dev), (int) MINOR(names->dev));
+	       major(names->dev), minor(names->dev));
 
 	return 1;
 }



More information about the dm-devel mailing list