Re: 64-bit kdev_t - just for playing

From: Roman Zippel (zippel@linux-m68k.org)
Date: Wed Apr 02 2003 - 08:02:04 EST


Hi,

On Tue, 1 Apr 2003, Greg KH wrote:

> On Tue, Apr 01, 2003 at 03:42:14PM +0100, Alan Cox wrote:
>
> > We need to default to 12:20 for char but where the 20 is actually
> > defaulting to 0000xx so we don't get extra minors for any device
> > that hasnt been audited for it

Why do we need to introduce new arbitrary limits?
I played a bit with the patch below, which adds dynamic device numbers and
with a simple script like this the corresponding dev entries can be
created:

mount -tsysfs none /sysfs
cd /sysfs/block
for d in *; do
        n=0x`cat $d/dev`
        ~/mn /dev/$d $n
        p=1
        while [ $p -lt `cat $d/range` ]; do
                ~/mn /dev/$d$p $[$n+$p]
                p=$[$p+1]
        done
done

We are sooo close to dynamic device numbers, so I really don't understand
why people want to go back all the way back to static numbers.
The kernel is mostly ready, what is missing now is the userspace and a
driver audit.

> I thought Andries's patch prevented the need for this, as it restricted
> the number of minors assigned to a device unless they converted to the
> new API.

This 'new API' is _huge_ step backwards, because it puts the burden of
managing static device numbers on the drivers again.

bye, Roman

Index: drivers/block/genhd.c
===================================================================
RCS file: /home/other/cvs/linux/linux-2.5/drivers/block/genhd.c,v
retrieving revision 1.1.1.31
diff -u -p -r1.1.1.31 genhd.c
--- drivers/block/genhd.c 25 Mar 2003 09:21:17 -0000 1.1.1.31
+++ drivers/block/genhd.c 2 Apr 2003 11:07:16 -0000
@@ -253,6 +253,14 @@ static int exact_lock(dev_t dev, void *d
  */
 void add_disk(struct gendisk *disk)
 {
+ if (disk->flags & GENHD_FL_DYNAMIC) {
+ static dev_t next_dev = 0x10000;
+
+ disk->major = MAJOR(next_dev);
+ disk->first_minor = 0;
+ next_dev += 0x100;
+ }
+
         disk->flags |= GENHD_FL_UP;
         blk_register_region(MKDEV(disk->major, disk->first_minor),
                             disk->minors, NULL, exact_match, exact_lock, disk);
Index: drivers/scsi/sd.c
===================================================================
RCS file: /home/other/cvs/linux/linux-2.5/drivers/scsi/sd.c,v
retrieving revision 1.1.1.38
diff -u -p -r1.1.1.38 sd.c
--- drivers/scsi/sd.c 18 Mar 2003 09:37:07 -0000 1.1.1.38
+++ drivers/scsi/sd.c 2 Apr 2003 12:41:34 -0000
@@ -56,7 +56,7 @@
  * Remaining dev_t-handling stuff
  */
 #define SD_MAJORS 16
-#define SD_DISKS (SD_MAJORS << 4)
+#define SD_DISKS 4096
 
 /*
  * Time out in seconds for disks and Magneto-opticals (which are slower).
@@ -125,8 +125,7 @@ static int sd_major(int major_idx)
         case 8 ... 15:
                 return SCSI_DISK8_MAJOR + major_idx;
         default:
- BUG();
- return 0; /* shut up gcc */
+ return 0;
         }
 }
 
@@ -1344,6 +1343,10 @@ static int sd_attach(struct scsi_device
 
         gd->driverfs_dev = &sdp->sdev_driverfs_dev;
         gd->flags = GENHD_FL_DRIVERFS | GENHD_FL_DEVFS;
+#if 0
+ if (!gd->major)
+#endif
+ gd->flags |= GENHD_FL_DYNAMIC;
         if (sdp->removable)
                 gd->flags |= GENHD_FL_REMOVABLE;
         gd->private_data = &sdkp->driver;
Index: include/asm-i386/posix_types.h
===================================================================
RCS file: /home/other/cvs/linux/linux-2.5/include/asm-i386/posix_types.h,v
retrieving revision 1.1.1.2
diff -u -p -r1.1.1.2 posix_types.h
--- include/asm-i386/posix_types.h 25 Feb 2003 11:50:47 -0000 1.1.1.2
+++ include/asm-i386/posix_types.h 2 Apr 2003 11:07:16 -0000
@@ -7,7 +7,7 @@
  * assume GCC is being used.
  */
 
-typedef unsigned short __kernel_dev_t;
+typedef unsigned long __kernel_dev_t;
 typedef unsigned long __kernel_ino_t;
 typedef unsigned short __kernel_mode_t;
 typedef unsigned short __kernel_nlink_t;
Index: include/linux/genhd.h
===================================================================
RCS file: /home/other/cvs/linux/linux-2.5/include/linux/genhd.h,v
retrieving revision 1.1.1.18
diff -u -p -r1.1.1.18 genhd.h
--- include/linux/genhd.h 18 Mar 2003 09:39:54 -0000 1.1.1.18
+++ include/linux/genhd.h 2 Apr 2003 11:07:16 -0000
@@ -71,6 +71,7 @@ struct hd_struct {
 #define GENHD_FL_DEVFS 4
 #define GENHD_FL_CD 8
 #define GENHD_FL_UP 16
+#define GENHD_FL_DYNAMIC 32
 
 struct disk_stats {
         unsigned read_sectors, write_sectors;
Index: include/linux/kdev_t.h
===================================================================
RCS file: /home/other/cvs/linux/linux-2.5/include/linux/kdev_t.h,v
retrieving revision 1.1.1.6
diff -u -p -r1.1.1.6 kdev_t.h
--- include/linux/kdev_t.h 5 Nov 2002 10:48:59 -0000 1.1.1.6
+++ include/linux/kdev_t.h 2 Apr 2003 11:07:16 -0000
@@ -70,7 +70,7 @@ aeb - 950811
  * static arrays, and they are sized for a 8-bit index.
  */
 typedef struct {
- unsigned short value;
+ unsigned long value;
 } kdev_t;
 
 #define KDEV_MINOR_BITS 8
@@ -112,7 +112,7 @@ static inline int kdev_same(kdev_t dev1,
 
 /* Mask off the high bits for now.. */
 #define minor(dev) ((dev).value & 0xff)
-#define major(dev) (((dev).value >> KDEV_MINOR_BITS) & 0xff)
+#define major(dev) ((dev).value >> KDEV_MINOR_BITS)
 
 /* These are for user-level "dev_t" */
 #define MINORBITS 8

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Mon Apr 07 2003 - 22:00:16 EST