Skip to contentSkip to conversation

Sparse minor space in ub

PATCH Pete Zaitcev 3 participants 4 messages Jun 15, 2006 – Jun 17, 2006

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

I wrote a patch which allows to expand the number of partitions in ub without breaking compatibility with the existing non-udev based distributions.

I do not know if I want this in the kernel or not. Looks pretty fishy, and its reason to exist is my lack of foresight. So far I heard from one user only who hit the limit, so obviously it's not something vitally important.

But I thought I'd just throw this out in case anyone wants something similar in the future for any reason.

Here how it looks in shell:

[zaitcev@lembas ~]$ cat /proc/partitions
major minor #blocks name

   3     0   39070080 hda
   3     1    5935986 hda1
   3     2    5936017 hda2
   3     3     554242 hda3
   3     4          1 hda4
   3     5   26643771 hda5
 180     0     253440 uba
 180     1     253424 uba1
 180     8     128000 ubb
 180     9        752 ubb1
 180    10          1 ubb2
 180    13        752 ubb5
 180    14        752 ubb6
 180    15        752 ubb7
 180   264        752 ubb8
 180   265       1008 ubb9
[zaitcev@lembas ~]$ ls -l /dev/ub*
brw-r----- 1 root disk 180,   0 Jun 14 23:18 /dev/uba
brw-r----- 1 root disk 180,   1 Jun 14 23:18 /dev/uba1
brw-r----- 1 root disk 180,   8 Jun 14 23:18 /dev/ubb
brw-r----- 1 root disk 180,   9 Jun 14 23:18 /dev/ubb1
brw-r----- 1 root disk 180,  10 Jun 14 23:18 /dev/ubb2
brw-r----- 1 root disk 180,  13 Jun 14 23:18 /dev/ubb5
brw-r----- 1 root disk 180,  14 Jun 14 23:18 /dev/ubb6
brw-r----- 1 root disk 180,  15 Jun 14 23:18 /dev/ubb7

brw-r----- 1 root disk 180, 264 Jun 14 23:18 /dev/ubb8 brw-r----- 1 root disk 180, 265 Jun 14 23:18 /dev/ubb9 [zaitcev@lembas ~]$

By the way, when I looked at the way things work in kobj_lookup(), a thought occured to me. If floppy ever returns NULL from its match function floppy_find(), the whole thing is going to loop endlessly. This happens because we restart the search, which, I suspect, was done to accomodate md. The md_probe() always returns NULL, and inserts new arrays into the list of regions. Thus, it needs a rescan. Someone needs to think about this mechanism, it seems a little underdeveloped. I have no idea if my patch below implements the lock/match API correctly, especially in regards to locking.

-- Pete

block/genhd.c +8 -7
diff -urp -X dontdiff linux-2.6.17-rc5/block/genhd.c linux-2.6.17-rc5-lem/block/genhd.c
@@ -183,7 +183,8 @@ static int exact_lock(dev_t dev, void *d
 void add_disk(struct gendisk *disk)
 {
 	disk->flags |= GENHD_FL_UP;
-	blk_register_region(MKDEV(disk->major, disk->first_minor),
+	if (!(disk->flags & GENHD_FL_SPARSE_MINORS))
+		blk_register_region(MKDEV(disk->major, disk->first_minor),
 			    disk->minors, NULL, exact_match, exact_lock, disk);
 	register_disk(disk);
 	blk_register_queue(disk);
@@ -195,8 +196,9 @@ EXPORT_SYMBOL(del_gendisk);	/* in partit
 void unlink_gendisk(struct gendisk *disk)
 {
 	blk_unregister_queue(disk);
-	blk_unregister_region(MKDEV(disk->major, disk->first_minor),
-			      disk->minors);
+	if (!(disk->flags & GENHD_FL_SPARSE_MINORS))
+		blk_unregister_region(MKDEV(disk->major, disk->first_minor),
+				      disk->minors);
 }
 
 #define to_disk(obj) container_of(obj,struct gendisk,kobj)
@@ -268,7 +270,7 @@ static int show_partition(struct seq_fil
 		if (sgp->part[n]->nr_sects == 0)
 			continue;
 		seq_printf(part, "%4d  %4d %10llu %s\n",
-			sgp->major, n + 1 + sgp->first_minor,
+			sgp->major, sgp->part[n]->partmin,
 			(unsigned long long)sgp->part[n]->nr_sects >> 1 ,
 			disk_name(sgp, n + 1, buf));
 	}
@@ -466,8 +468,7 @@ static int block_uevent(struct kset *kse
 		disk = container_of(kobj->parent, struct gendisk, kobj);
 		part = container_of(kobj, struct hd_struct, kobj);
 		add_uevent_var(envp, num_envp, &i, buffer, buffer_size,
-			       &length, "MINOR=%u",
-			       disk->first_minor + part->partno);
+			       &length, "MINOR=%u", part->partmin);
 	} else
 		return 0;
 
@@ -586,7 +587,7 @@ static int diskstats_show(struct seq_fil
 
 		if (hd && hd->nr_sects)
 			seq_printf(s, "%4d %4d %s %u %u %u %u\n",
-				gp->major, n + gp->first_minor + 1,
+				gp->major, hd->partmin,
 				disk_name(gp, n + 1, buf),
 				hd->ios[0], hd->sectors[0],
 				hd->ios[1], hd->sectors[1]);
Documentation/devices.txt +4 -4
diff -urp -X dontdiff linux-2.6.17-rc5/Documentation/devices.txt linux-2.6.17-rc5-lem/Documentation/devices.txt
@@ -2552,10 +2552,10 @@ Your cooperation is appreciated.
 		 66 = /dev/usb/cpad0	Synaptics cPad (mouse/LCD)
 
 180 block	USB block devices
-		0 = /dev/uba		First USB block device
-		8 = /dev/ubb		Second USB block device
-		16 = /dev/ubc		Thrid USB block device
-		...
+		  0 = /dev/uba		First USB block device
+		 16 = /dev/ubb		Second USB block device
+		 32 = /dev/ubc		Third USB block device
+		    ...
 
 181 char	Conrad Electronic parallel port radio clocks
 		  0 = /dev/pcfclock0	First Conrad radio clock
drivers/block/ub.c +107 -16

229 lines not on this page · raw message

fs/partitions/check.c +5 -2
diff -urp -X dontdiff linux-2.6.17-rc5/fs/partitions/check.c linux-2.6.17-rc5-lem/fs/partitions/check.c
@@ -236,7 +236,7 @@ static ssize_t part_uevent_store(struct 
 static ssize_t part_dev_read(struct hd_struct * p, char *page)
 {
 	struct gendisk *disk = container_of(p->kobj.parent,struct gendisk,kobj);
-	dev_t dev = MKDEV(disk->major, disk->first_minor + p->partno); 
+	dev_t dev = MKDEV(disk->major, p->partmin); 
 	return print_dev_t(page, dev);
 }
 static ssize_t part_start_read(struct hd_struct * p, char *page)
@@ -347,7 +347,10 @@ void add_partition(struct gendisk *disk,
 	memset(p, 0, sizeof(*p));
 	p->start_sect = start;
 	p->nr_sects = len;
-	p->partno = part;
+	if (disk->fops->partmap)
+		p->partmin = disk->fops->partmap(disk, part);
+	else
+		p->partmin = disk->first_minor + part;
 
 	devfs_mk_bdev(MKDEV(disk->major, disk->first_minor + part),
 			S_IFBLK|S_IRUSR|S_IWUSR,
include/linux/fs.h +1 -0
diff -urp -X dontdiff linux-2.6.17-rc5/include/linux/fs.h linux-2.6.17-rc5-lem/include/linux/fs.h
@@ -977,6 +977,7 @@ struct block_device_operations {
 	int (*media_changed) (struct gendisk *);
 	int (*revalidate_disk) (struct gendisk *);
 	int (*getgeo)(struct block_device *, struct hd_geometry *);
+	unsigned (*partmap)(struct gendisk *, int partno);
 	struct module *owner;
 };
 
include/linux/genhd.h +3 -1
diff -urp -X dontdiff linux-2.6.17-rc5/include/linux/genhd.h linux-2.6.17-rc5-lem/include/linux/genhd.h
@@ -80,7 +80,8 @@ struct hd_struct {
 	struct kobject kobj;
 	struct kobject *holder_dir;
 	unsigned ios[2], sectors[2];	/* READs and WRITEs */
-	int policy, partno;
+	int policy;
+	unsigned int partmin;
 };
 
 #define GENHD_FL_REMOVABLE			1
@@ -88,6 +89,7 @@ struct hd_struct {
 #define GENHD_FL_CD				8
 #define GENHD_FL_UP				16
 #define GENHD_FL_SUPPRESS_PARTITION_INFO	32
+#define GENHD_FL_SPARSE_MINORS			64
 
 struct disk_stats {
 	unsigned long sectors[2];	/* READs and WRITEs */
#1 lore raw
Quoted 4 lines · Pete Zaitcev
Documentation/devices.txt +0 -0
@@ -2552,10 +2552,10 @@ Your cooperation is appreciated.
 		 66 = /dev/usb/cpad0	Synaptics cPad (mouse/LCD)

Documentation/devices.txt Your cooperation is appreciated. · line 2558

Quoted 10 lines
Documentation/devices.txt +4 -4
 
 180 block	USB block devices
-		0 = /dev/uba		First USB block device
-		8 = /dev/ubb		Second USB block device
-		16 = /dev/ubc		Thrid USB block device
-		...
+		  0 = /dev/uba		First USB block device
+		 16 = /dev/ubb		Second USB block device
+		 32 = /dev/ubc		Third USB block device
+		    ...

I don't think that distros that have a static /dev will like this change at all :(

Anyway to put the extra partitions some where else in the minor range?

thanks,

greg k-h

#2 lore raw
Quoted 5 lines · Greg KH

Documentation/devices.txt Your cooperation is appreciated. · line 2556

Quoted 2 lines
Documentation/devices.txt +1 -1
-		8 = /dev/ubb		Second USB block device
+		 16 = /dev/ubb		Second USB block device

I don't think that distros that have a static /dev will like this change at all :(

That was an erroneous change in the documentation, I'm sorry. In reality, everything is fully compatible. This is with the new driver:

[zaitcev@lembas ~]$ ls -l /dev/ub*

brw-r----- 1 root disk 180,   0 Jun 14 23:18 /dev/uba
brw-r----- 1 root disk 180,   1 Jun 14 23:18 /dev/uba1
brw-r----- 1 root disk 180,   8 Jun 14 23:18 /dev/ubb
brw-r----- 1 root disk 180,   9 Jun 14 23:18 /dev/ubb1
brw-r----- 1 root disk 180,  10 Jun 14 23:18 /dev/ubb2
brw-r----- 1 root disk 180,  13 Jun 14 23:18 /dev/ubb5
brw-r----- 1 root disk 180,  14 Jun 14 23:18 /dev/ubb6
brw-r----- 1 root disk 180,  15 Jun 14 23:18 /dev/ubb7

brw-r----- 1 root disk 180, 264 Jun 14 23:18 /dev/ubb8 brw-r----- 1 root disk 180, 265 Jun 14 23:18 /dev/ubb9 [zaitcev@lembas ~]$

/*
- */
+ * The minor layout is:
+ * 19 - 11 0xFF800

+ *   10 -  8    0x700   Upper 3 bits of partition number
+ *    7 -  3     0xF8   Host index, or same as "id". UB_MAX_HOSTS fit here.
+ *    2 -  0      0x7   Lower 3 bits of partition number

+ */

-- Pete

#3 lore raw
In reply to Greg KH
Quoted 19 lines · Pete Zaitcev
Quoted 4 lines
Documentation/devices.txt +0 -0
@@ -2552,10 +2552,10 @@ Your cooperation is appreciated.
 		 66 = /dev/usb/cpad0	Synaptics cPad (mouse/LCD)

Documentation/devices.txt Your cooperation is appreciated. · line 2558

Quoted 10 lines
Documentation/devices.txt +4 -4
 
 180 block	USB block devices
-		0 = /dev/uba		First USB block device
-		8 = /dev/ubb		Second USB block device
-		16 = /dev/ubc		Thrid USB block device
-		...
+		  0 = /dev/uba		First USB block device
+		 16 = /dev/ubb		Second USB block device
+		 32 = /dev/ubc		Third USB block device
+		    ...

I don't think that distros that have a static /dev will like this change at all :(

Quoted 1 line

Anyway to put the extra partitions some where else in the minor range?

(a)
come with something up like glibc's compatibility scheme for high device numbers, ie.

    minor = ((ubdisk & 0x1F)  << 4) | (ubpart & 0x03) |
            ((ubdisk & ~0x1F) << 9) | ((ubpart & 0x08) << 8)

bits 10 09 08 | 07 06 05 04 03 02 01 00

  old              d  d  d  d  d  p  p  p
  new ..d  d  p |  d  d  d  d  d  p  p  p

Would give the usual 16 partitions. But see (b).

(b)
"181 block" seems free.
Suggestion: have block-major-180 be ub disks with 8 parts max (and marked as deprecated)
and block-major-181 be ub disks with 16 parts max

Jan Engelhardt