Skip to contentSkip to conversation

2080 SD's and devfs fixes

PATCH New Richard Gooch 1 participant 1 message Sep 7, 2001

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 2080 SD's and devfs fixes

Hi, all. Appended is a patch I would really appreciate lots of
people trying out. It adds support for up to 2080 SCSI discs, safely (i.e. does not re-use assigned majors), as well as fixing a number of races in the devfs core.

If enough people respond here, and all responses are "it doesn't screw my data", it might convince Linus that this patch is indeed safe :-) So please test and report back here. I've been running this patch for over a month now, and it works fine. Other people have tried it too and it works fine for them.

The patch was generated against 2.4.10-pre3 but applies cleanly against 2.4.10-pre4 as well.

				Regards,

					Richard....
Permanent: [email protected]
Current:   [email protected]
Documentation/Configure.help +11 -0
diff -urN linux-2.4.10-pre3/Documentation/Configure.help linux/Documentation/Configure.help
@@ -5453,6 +5453,17 @@
   located on a SCSI disk. In this case, do not compile the driver for
   your SCSI host adapter (below) as a module either.
 
+Many SCSI Discs support
+CONFIG_SD_MANY
+  This allows you to support a very large number of SCSI discs
+  (approximately 2144). You will also need to set CONFIG_DEVFS_FS=y
+  later. This option may consume all unassigned block majors
+  (i.e. those which do not have an allocation in
+  Documentation/devices.txt). Enabling this will consume a few extra
+  kilobytes of kernel memory.
+
+  Unless you have a large storage array, say N.
+
 Extra SCSI Disks
 CONFIG_SD_EXTRA_DEVS
   This controls the amount of additional space allocated in tables for
Documentation/filesystems/devfs/ChangeLog +76 -0

79 lines not on this page · raw message

Documentation/filesystems/devfs/README +105 -29

210 lines not on this page · raw message

Documentation/filesystems/devfs/boot-options +5 -7
diff -urN linux-2.4.10-pre3/Documentation/filesystems/devfs/boot-options linux/Documentation/filesystems/devfs/boot-options
@@ -4,7 +4,7 @@
 
 		Richard Gooch <[email protected]>
 
-			      30-APR-2000
+			      18-AUG-2001
 
 
 When CONFIG_DEVFS_DEBUG is enabled, you can pass several boot options
@@ -19,6 +19,8 @@
 
 devfs=dmod,dreg
 
+You may prefix "no" to any option. This will invert the option.
+
 
 Debugging Options
 =================
@@ -42,11 +44,11 @@
 
 dilookup	print inode lookup requests
 
-diread		print inode reads
+diget		print VFS inode allocations
 
 diunlink	print inode unlinks
 
-diwrite		print inode writes
+dichange	print inode changes
 
 dimknod		print calls to mknod(2)
 
@@ -58,10 +60,6 @@
 
 These control the default behaviour of devfs. The options are:
 
-show		show unregistered devices by default
-
 mount		mount devfs onto /dev at boot time
-
-nomount		do not mount devfs onto /dev at boot time
 
 only		disable non-devfs device nodes for devfs-capable drivers
drivers/char/pty.c +2 -1
diff -urN linux-2.4.10-pre3/drivers/char/pty.c linux/drivers/char/pty.c
@@ -334,7 +334,8 @@
 	/*  Register a slave for the master  */
 	if (tty->driver.major == PTY_MASTER_MAJOR)
 		tty_register_devfs(&tty->link->driver,
-				   DEVFS_FL_AUTO_OWNER | DEVFS_FL_WAIT,
+				   DEVFS_FL_CURRENT_OWNER |
+				   DEVFS_FL_NO_PERSISTENCE | DEVFS_FL_WAIT,
 				   tty->link->driver.minor_start +
 				   MINOR(tty->device)-tty->driver.minor_start);
 	retval = 0;
drivers/char/rocket.c +8 -0
diff -urN linux-2.4.10-pre3/drivers/char/rocket.c linux/drivers/char/rocket.c
@@ -2185,7 +2185,11 @@
 	 */
 	memset(&rocket_driver, 0, sizeof(struct tty_driver));
 	rocket_driver.magic = TTY_DRIVER_MAGIC;
+#ifdef CONFIG_DEVFS_FS
+	rocket_driver.name = "tts/R%d";
+#else
 	rocket_driver.name = "ttyR";
+#endif
 	rocket_driver.major = TTY_ROCKET_MAJOR;
 	rocket_driver.minor_start = 0;
 	rocket_driver.num = MAX_RP_PORTS;
@@ -2227,7 +2231,11 @@
 	 * the minor number and the subtype code.
 	 */
 	callout_driver = rocket_driver;
+#ifdef CONFIG_DEVFS_FS
+	callout_driver.name = "cua/R%d";
+#else
 	callout_driver.name = "cur";
+#endif
 	callout_driver.major = CUA_ROCKET_MAJOR;
 	callout_driver.minor_start = 0;
 	callout_driver.subtype = SERIAL_TYPE_CALLOUT;
drivers/char/stallion.c +5 -0
diff -urN linux-2.4.10-pre3/drivers/char/stallion.c linux/drivers/char/stallion.c
@@ -139,8 +139,13 @@
 static char	*stl_drvtitle = "Stallion Multiport Serial Driver";
 static char	*stl_drvname = "stallion";
 static char	*stl_drvversion = "5.6.0";
+#ifdef CONFIG_DEVFS_FS
+static char	*stl_serialname = "tts/E%d";
+static char	*stl_calloutname = "cua/E%d";
+#else
 static char	*stl_serialname = "ttyE";
 static char	*stl_calloutname = "cue";
+#endif
 
 static struct tty_driver	stl_serial;
 static struct tty_driver	stl_callout;
drivers/char/tty_io.c +1 -1
diff -urN linux-2.4.10-pre3/drivers/char/tty_io.c linux/drivers/char/tty_io.c
@@ -2021,7 +2021,7 @@
 			break;
 		default:
 			if (driver->major == PTY_MASTER_MAJOR)
-				flags |= DEVFS_FL_AUTO_OWNER;
+				mode |= S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
 			break;
 	}
 	if ( (minor <  driver->minor_start) || 
drivers/scsi/Config.in +2 -1
diff -urN linux-2.4.10-pre3/drivers/scsi/Config.in linux/drivers/scsi/Config.in
@@ -3,7 +3,8 @@
 dep_tristate '  SCSI disk support' CONFIG_BLK_DEV_SD $CONFIG_SCSI
 
 if [ "$CONFIG_BLK_DEV_SD" != "n" ]; then
-   int  'Maximum number of SCSI disks that can be loaded as modules' CONFIG_SD_EXTRA_DEVS 40
+   bool '    Many (~2144) SCSI discs support (requires devfs)' CONFIG_SD_MANY
+   int  '    Maximum number of SCSI disks that can be loaded as modules' CONFIG_SD_EXTRA_DEVS 40
 fi
 
 dep_tristate '  SCSI tape support' CONFIG_CHR_DEV_ST $CONFIG_SCSI
drivers/scsi/hosts.h +2 -3
diff -urN linux-2.4.10-pre3/drivers/scsi/hosts.h linux/drivers/scsi/hosts.h
@@ -506,9 +506,8 @@
     const char * tag;
     struct module * module;	  /* Used for loadable modules */
     unsigned char scsi_type;
-    unsigned int major;
-    unsigned int min_major;      /* Minimum major in range. */ 
-    unsigned int max_major;      /* Maximum major in range. */
+    unsigned int *majors;         /* Array of majors used by driver */
+    unsigned int num_majors;      /* Number of majors used by driver */
     unsigned int nr_dev;	  /* Number currently attached */
     unsigned int dev_noticed;	  /* Number of devices detected. */
     unsigned int dev_max;	  /* Current size of arrays */
drivers/scsi/osst.c +0 -1
diff -urN linux-2.4.10-pre3/drivers/scsi/osst.c linux/drivers/scsi/osst.c
@@ -160,7 +160,6 @@
        name:		"OnStream tape",
        tag:		"osst",
        scsi_type:	TYPE_TAPE,
-       major:		OSST_MAJOR,
        detect:		osst_detect,
        init:		osst_init,
        attach:		osst_attach,
drivers/scsi/scsi_lib.c +4 -19
diff -urN linux-2.4.10-pre3/drivers/scsi/scsi_lib.c linux/drivers/scsi/scsi_lib.c
@@ -788,25 +788,10 @@
 		 * Search for a block device driver that supports this
 		 * major.
 		 */
-		if (spnt->blk && spnt->major == major) {
-			return spnt;
-		}
-		/*
-		 * I am still not entirely satisfied with this solution,
-		 * but it is good enough for now.  Disks have a number of
-		 * major numbers associated with them, the primary
-		 * 8, which we test above, and a secondary range of 7
-		 * different consecutive major numbers.   If this ever
-		 * becomes insufficient, then we could add another function
-		 * to the structure, and generalize this completely.
-		 */
-		if( spnt->min_major != 0 
-		    && spnt->max_major != 0
-		    && major >= spnt->min_major
-		    && major <= spnt->max_major )
-		{
-			return spnt;
-		}
+		int i;
+		if (!spnt->blk || !spnt->majors) continue;
+		for (i = 0; i < spnt->num_majors; ++i)
+			if (spnt->majors[i] == major) return spnt;
 	}
 	return NULL;
 }
drivers/scsi/sd.c +73 -23

182 lines not on this page · raw message

drivers/scsi/sd.h +6 -2
diff -urN linux-2.4.10-pre3/drivers/scsi/sd.h linux/drivers/scsi/sd.h
@@ -42,10 +42,14 @@
  */
 extern kdev_t sd_find_target(void *host, int tgt);
 
-#define N_SD_MAJORS	8
+#define N_SD_PREASSIGNED_MAJORS	8
 
-#define SD_MAJOR_MASK	(N_SD_MAJORS - 1)
+#ifdef CONFIG_SD_MANY
+#define SD_PARTITION(i)		((sd_devnum_to_index((i)) << 4) | ((i)&0x0f))
+#else
+#define SD_MAJOR_MASK	(N_SD_PREASSIGNED_MAJORS - 1)
 #define SD_PARTITION(i)		(((MAJOR(i) & SD_MAJOR_MASK) << 8) | (MINOR(i) & 255))
+#endif
 
 #endif
 
drivers/scsi/sg.c +0 -1
diff -urN linux-2.4.10-pre3/drivers/scsi/sg.c linux/drivers/scsi/sg.c
@@ -123,7 +123,6 @@
 {
       tag:"sg",
       scsi_type:0xff,
-      major:SCSI_GENERIC_MAJOR,
       detect:sg_detect,
       init:sg_init,
       finish:sg_finish,
drivers/scsi/sr.c +4 -1
diff -urN linux-2.4.10-pre3/drivers/scsi/sr.c linux/drivers/scsi/sr.c
@@ -69,12 +69,15 @@
 
 static int sr_init_command(Scsi_Cmnd *);
 
+static unsigned int sr_major = SCSI_CDROM_MAJOR;
+
 static struct Scsi_Device_Template sr_template =
 {
 	name:"cdrom",
 	tag:"sr",
 	scsi_type:TYPE_ROM,
-	major:SCSI_CDROM_MAJOR,
+	majors:&sr_major,
+	num_majors:1,
 	blk:1,
 	detect:sr_detect,
 	init:sr_init,
drivers/scsi/st.c +0 -1
diff -urN linux-2.4.10-pre3/drivers/scsi/st.c linux/drivers/scsi/st.c
@@ -166,7 +166,6 @@
 	name:"tape", 
 	tag:"st", 
 	scsi_type:TYPE_TAPE,
-	major:SCSI_TAPE_MAJOR, 
 	detect:st_detect, 
 	init:st_init,
 	attach:st_attach, 
fs/devfs/base.c +235 -239

755 lines not on this page · raw message

fs/devfs/util.c +24 -13
diff -urN linux-2.4.10-pre3/fs/devfs/util.c linux/fs/devfs/util.c
@@ -39,6 +39,15 @@
                Created <devfs_*alloc_major> and <devfs_*alloc_devnum>.
     20010710   Richard Gooch <[email protected]>
                Created <devfs_*alloc_unique_number>.
+    20010730   Richard Gooch <[email protected]>
+               Documentation typo fix.
+    20010806   Richard Gooch <[email protected]>
+               Made <block_semaphore> and <char_semaphore> private.
+    20010813   Richard Gooch <[email protected]>
+               Fixed bug in <devfs_alloc_unique_number>: limited to 128 numbers
+    20010818   Richard Gooch <[email protected]>
+               Updated major masks up to Linus' "no new majors" proclamation.
+	       Block: were 126 now 122 free, char: were 26 now 19 free.
 */
 #include <linux/module.h>
 #include <linux/init.h>
@@ -181,15 +190,15 @@
 };
 
 /*  Block majors already assigned:
-    0-3, 7-9, 11-12, 13-63, 65-93, 95-99, 101, 103-111, 120-127, 199, 201,
-    240-255
+    0-3, 7-9, 11-63, 65-99, 101-113, 120-127, 199, 201, 240-255
+    Total free: 122
 */
 static struct major_list block_major_list =
 {SPIN_LOCK_UNLOCKED,
     {0xfffffb8f,  /*  Majors 0   to 31   */
      0xffffffff,  /*  Majors 32  to 63   */
-     0xbffffffe,  /*  Majors 64  to 95   */
-     0xff00ffaf,  /*  Majors 96  to 127  */
+     0xfffffffe,  /*  Majors 64  to 95   */
+     0xff03ffef,  /*  Majors 96  to 127  */
      0x00000000,  /*  Majors 128 to 159  */
      0x00000000,  /*  Majors 160 to 191  */
      0x00000280,  /*  Majors 192 to 223  */
@@ -197,7 +206,8 @@
 };
 
 /*  Char majors already assigned:
-    0-7, 9-151, 154-158, 160-195, 198-211, 216-221, 224-225, 240-255
+    0-7, 9-151, 154-158, 160-211, 216-221, 224-230, 240-255
+    Total free: 19
 */
 static struct major_list char_major_list =
 {SPIN_LOCK_UNLOCKED,
@@ -207,14 +217,14 @@
      0xffffffff,  /*  Majors 96  to 127  */
      0x7cffffff,  /*  Majors 128 to 159  */
      0xffffffff,  /*  Majors 160 to 191  */
-     0x3f0fffcf,  /*  Majors 192 to 223  */
-     0xffff0003}  /*  Majors 224 to 255  */
+     0x3f0fffff,  /*  Majors 192 to 223  */
+     0xffff007f}  /*  Majors 224 to 255  */
 };
 
 
 /**
  *	devfs_alloc_major - Allocate a major number.
- *	@type: The type of the major (DEVFS_SPECIAL_CHR or DEVFS_SPECIAL_BLOCK)
+ *	@type: The type of the major (DEVFS_SPECIAL_CHR or DEVFS_SPECIAL_BLK)
 
  *	Returns the allocated major, else -1 if none are available.
  *	This routine is thread safe and does not block.
@@ -238,7 +248,7 @@
 
 /**
  *	devfs_dealloc_major - Deallocate a major number.
- *	@type: The type of the major (DEVFS_SPECIAL_CHR or DEVFS_SPECIAL_BLOCK)
+ *	@type: The type of the major (DEVFS_SPECIAL_CHR or DEVFS_SPECIAL_BLK)
  *	@major: The major number.
  *	This routine is thread safe and does not block.
  */
@@ -273,16 +283,16 @@
     int none_free;
 };
 
-DECLARE_MUTEX (block_semaphore);
+static DECLARE_MUTEX (block_semaphore);
 static struct device_list block_list;
 
-DECLARE_MUTEX (char_semaphore);
+static DECLARE_MUTEX (char_semaphore);
 static struct device_list char_list;
 
 
 /**
  *	devfs_alloc_devnum - Allocate a device number.
- *	@type: The type (DEVFS_SPECIAL_CHR or DEVFS_SPECIAL_BLOCK).
+ *	@type: The type (DEVFS_SPECIAL_CHR or DEVFS_SPECIAL_BLK).
  *
  *	Returns the allocated device number, else NODEV if none are available.
  *	This routine is thread safe and may block.
@@ -347,7 +357,7 @@
 
 /**
  *	devfs_dealloc_devnum - Dellocate a device number.
- *	@type: The type (DEVFS_SPECIAL_CHR or DEVFS_SPECIAL_BLOCK).
+ *	@type: The type (DEVFS_SPECIAL_CHR or DEVFS_SPECIAL_BLK).
  *	@devnum: The device number.
  *
  *	This routine is thread safe and does not block.
@@ -437,6 +447,7 @@
 	space->length = length;
     }
     number = find_first_zero_bit (space->bits, space->length << 3);
+    --space->num_free;
     __set_bit (number, space->bits);
     up (&space->semaphore);
     return number;
include/linux/blk.h +4 -0
diff -urN linux-2.4.10-pre3/include/linux/blk.h linux/include/linux/blk.h
@@ -144,7 +144,11 @@
 
 #define DEVICE_NAME "scsidisk"
 #define TIMEOUT_VALUE (2*HZ)
+#ifdef CONFIG_SD_MANY
+#define DEVICE_NR(device) sd_devnum_to_index((device))
+#else
 #define DEVICE_NR(device) (((MAJOR(device) & SD_MAJOR_MASK) << (8 - 4)) + (MINOR(device) >> 4))
+#endif
 
 /* Kludge to use the same number for both char and block major numbers */
 #elif  (MAJOR_NR == MD_MAJOR) && defined(MD_DRIVER)
include/linux/devfs_fs.h +1 -0
diff -urN linux-2.4.10-pre3/include/linux/devfs_fs.h linux/include/linux/devfs_fs.h
@@ -20,6 +20,7 @@
 #define DEVFSD_NOTIFY_LOOKUP        4
 #define DEVFSD_NOTIFY_CHANGE        5
 #define DEVFSD_NOTIFY_CREATE        6
+#define DEVFSD_NOTIFY_DELETE        7
 
 #define DEVFS_PATHLEN               1024  /*  Never change this otherwise the
 					      binary interface will change   */
include/linux/devfs_fs_kernel.h +7 -9
diff -urN linux-2.4.10-pre3/include/linux/devfs_fs_kernel.h linux/include/linux/devfs_fs_kernel.h
@@ -30,17 +30,15 @@
 					 is closed, ownership reverts back to
 					 <<uid>> and <<gid>> and the protection
 					 is set to read-write for all        */
-#define DEVFS_FL_SHOW_UNREG     0x002 /* Show unregistered entries in
-					 directory listings                  */
-#define DEVFS_FL_HIDE           0x004 /* Do not show entry in directory list */
-#define DEVFS_FL_AUTO_DEVNUM    0x008 /* Automatically generate device number
+#define DEVFS_FL_HIDE           0x002 /* Do not show entry in directory list */
+#define DEVFS_FL_AUTO_DEVNUM    0x004 /* Automatically generate device number
 				       */
-#define DEVFS_FL_AOPEN_NOTIFY   0x010 /* Asynchronously notify devfsd on open
+#define DEVFS_FL_AOPEN_NOTIFY   0x008 /* Asynchronously notify devfsd on open
 				       */
-#define DEVFS_FL_REMOVABLE      0x020 /* This is a removable media device    */
-#define DEVFS_FL_WAIT           0x040 /* Wait for devfsd to finish           */
-#define DEVFS_FL_NO_PERSISTENCE 0x080 /* Forget changes after unregister     */
-#define DEVFS_FL_CURRENT_OWNER  0x100 /* Set initial ownership to current    */
+#define DEVFS_FL_REMOVABLE      0x010 /* This is a removable media device    */
+#define DEVFS_FL_WAIT           0x020 /* Wait for devfsd to finish           */
+#define DEVFS_FL_NO_PERSISTENCE 0x040 /* Forget changes after unregister     */
+#define DEVFS_FL_CURRENT_OWNER  0x080 /* Set initial ownership to current    */
 #define DEVFS_FL_DEFAULT        DEVFS_FL_NONE