mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrzej Krzysztofowicz <ankry@green.mif.pg.gda.pl>
To: alan@lxorguk.ukuu.org.uk (Alan Cox),
	torvalds@transmeta.com (Linus Torvalds)
Cc: linux-kernel@vger.kernel.org (kernel list)
Subject: [PATCH] SCSI disk minor number cleaning
Date: Tue, 15 May 2001 22:35:57 +0200 (CEST)	[thread overview]
Message-ID: <200105152035.WAA23563@green.mif.pg.gda.pl> (raw)

Hi,
  The following patch cleans up a bit usage of parameters related to
number of minors per disk in the SCSI subsystem. This is a preliminary
patch and it seems to not contain any problematic changes. The full version
of the patch (that allows to succesfully change SCSI_MINOR_SHIFT and use
more/less partitions per disk) is available at

ftp://rudy.mif.pg.gda.pl/pub/People/ankry/patches/scsi-minor/

Both are against 2.4.4-ac9, but the "shorter" one can be applied to
2.4.5-pre series as well.

Any comments are welcome.

    Andrzej

******************************************************************
diff -uNr linux-2.4.4-ac9/drivers/scsi/sd.c linux-scsi/drivers/scsi/sd.c
--- linux-2.4.4-ac9/drivers/scsi/sd.c	Thu May  3 19:29:16 2001
+++ linux-scsi/drivers/scsi/sd.c	Tue May 15 22:21:01 2001
@@ -50,6 +50,7 @@
 #include <asm/io.h>
 
 #define MAJOR_NR SCSI_DISK0_MAJOR
+#include <linux/scsi_minor.h>
 #include <linux/blk.h>
 #include <linux/blkpg.h>
 #include "scsi.h"
@@ -67,11 +68,12 @@
 
 #define SD_MAJOR(i) (!(i) ? SCSI_DISK0_MAJOR : SCSI_DISK1_MAJOR-1+(i))
 
-#define SCSI_DISKS_PER_MAJOR	16
+#define SCSI_MINOR_SHIFT	4
+#define SCSI_DISKS_PER_MAJOR	(1 << (8 - SCSI_MINOR_SHIFT))
 #define SD_MAJOR_NUMBER(i)	SD_MAJOR((i) >> 8)
 #define SD_MINOR_NUMBER(i)	((i) & 255)
 #define MKDEV_SD_PARTITION(i)	MKDEV(SD_MAJOR_NUMBER(i), (i) & 255)
-#define MKDEV_SD(index)		MKDEV_SD_PARTITION((index) << 4)
+#define MKDEV_SD(index)		MKDEV_SD_PARTITION((index) << SCSI_MINOR_SHIFT)
 #define N_USED_SCSI_DISKS  (sd_template.dev_max + SCSI_DISKS_PER_MAJOR - 1)
 #define N_USED_SD_MAJORS   (N_USED_SCSI_DISKS / SCSI_DISKS_PER_MAJOR)
 
@@ -298,7 +300,7 @@
 	SCSI_LOG_HLQUEUE(1, printk("Doing sd request, dev = %d, block = %d\n", devm, block));
 
 	dpnt = &rscsi_disks[dev];
-	if (devm >= (sd_template.dev_max << 4) ||
+	if (devm >= (sd_template.dev_max << SCSI_MINOR_SHIFT) ||
 	    !dpnt ||
 	    !dpnt->device->online ||
  	    block + SCpnt->request.nr_sectors > sd[devm].nr_sects) {
@@ -563,8 +565,8 @@
 {
 	SCSI_DISK0_MAJOR,	/* Major number */
 	"sd",			/* Major name */
-	4,			/* Bits to shift to get real from partition */
-	1 << 4,			/* Number of partitions per real */
+	SCSI_MINOR_SHIFT,	/* Bits to shift to get real from partition */
+	1 << SCSI_MINOR_SHIFT,	/* Number of partitions per real */
 	NULL,			/* hd struct */
 	NULL,			/* block sizes */
 	0,			/* number */
@@ -951,7 +953,7 @@
 			 * The disk reading code does not allow for reading
 			 * of partial sectors.
 			 */
-			for (m = i << 4; m < ((i + 1) << 4); m++) {
+			for (m = i << SCSI_MINOR_SHIFT; m < ((i + 1) << SCSI_MINOR_SHIFT); m++) {
 				sd_blocksizes[m] = sector_size;
 			}
 		} {
@@ -964,8 +966,11 @@
 			int hard_sector = sector_size;
 			int sz = rscsi_disks[i].capacity * (hard_sector/256);
 
-			/* There are 16 minors allocated for each major device */
-			for (m = i << 4; m < ((i + 1) << 4); m++) {
+			/* 
+			 * There are 1<<SCSI_MINOR_SHIFT minors allocated 
+			 * for each major device
+			 */
+			for (m = i << SCSI_MINOR_SHIFT; m < ((i + 1) << SCSI_MINOR_SHIFT); m++) {
 				sd_hardsizes[m] = hard_sector;
 			}
 
@@ -1083,34 +1088,34 @@
 	memset(rscsi_disks, 0, sd_template.dev_max * sizeof(Scsi_Disk));
 
 	/* for every (necessary) major: */
-	sd_sizes = kmalloc((sd_template.dev_max << 4) * sizeof(int), GFP_ATOMIC);
+	sd_sizes = kmalloc((sd_template.dev_max << SCSI_MINOR_SHIFT) * sizeof(int), GFP_ATOMIC);
 	if (!sd_sizes)
 		goto cleanup_disks;
-	memset(sd_sizes, 0, (sd_template.dev_max << 4) * sizeof(int));
+	memset(sd_sizes, 0, (sd_template.dev_max << SCSI_MINOR_SHIFT) * sizeof(int));
 
-	sd_blocksizes = kmalloc((sd_template.dev_max << 4) * sizeof(int), GFP_ATOMIC);
+	sd_blocksizes = kmalloc((sd_template.dev_max << SCSI_MINOR_SHIFT) * sizeof(int), GFP_ATOMIC);
 	if (!sd_blocksizes)
 		goto cleanup_sizes;
 	
-	sd_hardsizes = kmalloc((sd_template.dev_max << 4) * sizeof(int), GFP_ATOMIC);
+	sd_hardsizes = kmalloc((sd_template.dev_max << SCSI_MINOR_SHIFT) * sizeof(int), GFP_ATOMIC);
 	if (!sd_hardsizes)
 		goto cleanup_blocksizes;
 
-	for (i = 0; i < sd_template.dev_max << 4; i++) {
+	for (i = 0; i < sd_template.dev_max << SCSI_MINOR_SHIFT; i++) {
 		sd_blocksizes[i] = 1024;
 		sd_hardsizes[i] = 512;
 	}
 
 	for (i = 0; i < N_USED_SD_MAJORS; i++) {
-		blksize_size[SD_MAJOR(i)] = sd_blocksizes + i * (SCSI_DISKS_PER_MAJOR << 4);
-		hardsect_size[SD_MAJOR(i)] = sd_hardsizes + i * (SCSI_DISKS_PER_MAJOR << 4);
+		blksize_size[SD_MAJOR(i)] = sd_blocksizes + i * (SCSI_DISKS_PER_MAJOR << SCSI_MINOR_SHIFT);
+		hardsect_size[SD_MAJOR(i)] = sd_hardsizes + i * (SCSI_DISKS_PER_MAJOR << SCSI_MINOR_SHIFT);
 	}
-	sd = kmalloc((sd_template.dev_max << 4) *
+	sd = kmalloc((sd_template.dev_max << SCSI_MINOR_SHIFT) *
 					  sizeof(struct hd_struct),
 					  GFP_ATOMIC);
 	if (!sd)
 		goto cleanup_sd;
-	memset(sd, 0, (sd_template.dev_max << 4) * sizeof(struct hd_struct));
+	memset(sd, 0, (sd_template.dev_max << SCSI_MINOR_SHIFT) * sizeof(struct hd_struct));
 
 	if (N_USED_SD_MAJORS > 1)
 		sd_gendisks = kmalloc(N_USED_SD_MAJORS * sizeof(struct gendisk), GFP_ATOMIC);
@@ -1132,10 +1137,10 @@
                         SCSI_DISKS_PER_MAJOR * sizeof *sd_gendisks[i].flags);
 		sd_gendisks[i].major = SD_MAJOR(i);
 		sd_gendisks[i].major_name = "sd";
-		sd_gendisks[i].minor_shift = 4;
-		sd_gendisks[i].max_p = 1 << 4;
-		sd_gendisks[i].part = sd + (i * SCSI_DISKS_PER_MAJOR << 4);
-		sd_gendisks[i].sizes = sd_sizes + (i * SCSI_DISKS_PER_MAJOR << 4);
+		sd_gendisks[i].minor_shift = SCSI_MINOR_SHIFT;
+		sd_gendisks[i].max_p = 1 << SCSI_MINOR_SHIFT;
+		sd_gendisks[i].part = sd + (i * SCSI_DISKS_PER_MAJOR << SCSI_MINOR_SHIFT);
+		sd_gendisks[i].sizes = sd_sizes + (i * SCSI_DISKS_PER_MAJOR << SCSI_MINOR_SHIFT);
 		sd_gendisks[i].nr_real = 0;
 		sd_gendisks[i].next = sd_gendisks + i + 1;
 		sd_gendisks[i].real_devices =
@@ -1191,9 +1196,9 @@
 		if (!rscsi_disks[i].capacity && rscsi_disks[i].device) {
 			sd_init_onedisk(i);
 			if (!rscsi_disks[i].has_part_table) {
-				sd_sizes[i << 4] = rscsi_disks[i].capacity;
+				sd_sizes[i << SCSI_MINOR_SHIFT] = rscsi_disks[i].capacity;
 				register_disk(&SD_GENDISK(i), MKDEV_SD(i),
-						1<<4, &sd_fops,
+						1 << SCSI_MINOR_SHIFT, &sd_fops,
 						rscsi_disks[i].capacity);
 				rscsi_disks[i].has_part_table = 1;
 			}
@@ -1312,7 +1317,7 @@
 #endif
 
 	grok_partitions(&SD_GENDISK(target), target % SCSI_DISKS_PER_MAJOR,
-			1<<4, CAPACITY);
+			1 << SCSI_MINOR_SHIFT, CAPACITY);
 
 	DEVICE_BUSY = 0;
 	return 0;


-- 
=======================================================================
  Andrzej M. Krzysztofowicz               ankry@mif.pg.gda.pl
  phone (48)(58) 347 14 61
Faculty of Applied Phys. & Math.,   Technical University of Gdansk

             reply	other threads:[~2001-05-15 20:36 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-05-15 20:35 Andrzej Krzysztofowicz [this message]
2001-05-15 21:51 ` Martin Dalecki
2001-05-15 21:42 Andrzej Krzysztofowicz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200105152035.WAA23563@green.mif.pg.gda.pl \
    --to=ankry@green.mif.pg.gda.pl \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=torvalds@transmeta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®