public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scsi_debug: scale virtual_gb with sector_size properly
@ 2009-12-16  0:58 Jeff Mahoney
  2009-12-17 19:57 ` Douglas Gilbert
  0 siblings, 1 reply; 2+ messages in thread
From: Jeff Mahoney @ 2009-12-16  0:58 UTC (permalink / raw)
  To: Linux SCSI Mailing List

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

 The scsi_debug virtual_gb feature currently assumes that the sector size
 is always 512 bytes and scales the capacity of virtual_gb based on that
 assumption.

 When passed a different sector size, the capacity of the disk is scaled
 incorrectly higher than it should be.

 For example, modprobe scsi_debug virtual_gb=1 sector_size=4096 results
 in an 8 GB device.

 This patch scales it appropriately. I chose to scale down the sectors-per-GB
 value and then multiply so that if virtual_gb is changed to allow devices that
 can max out sector_t, it will just work.

 References: https://bugzilla.novell.com/show_bug.cgi?id=535939

Signed-off-by: Jeff Mahoney <jeffm@suse.com>
- ---
 drivers/scsi/scsi_debug.c |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

- --- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -154,6 +154,7 @@ static int scsi_debug_virtual_gb = DEF_V
 static int scsi_debug_fake_rw = DEF_FAKE_RW;
 static int scsi_debug_vpd_use_hostno = DEF_VPD_USE_HOSTNO;
 static int scsi_debug_sector_size = DEF_SECTOR_SIZE;
+static int scsi_debug_sector_size_bits = ilog2(DEF_SECTOR_SIZE);
 static int scsi_debug_dix = DEF_DIX;
 static int scsi_debug_dif = DEF_DIF;
 static int scsi_debug_guard = DEF_GUARD;
@@ -895,9 +896,11 @@ static int resp_start_stop(struct scsi_c
 
 static sector_t get_sdebug_capacity(void)
 {
- -	if (scsi_debug_virtual_gb > 0)
- -		return 2048 * 1024 * (sector_t)scsi_debug_virtual_gb;
- -	else
+	if (scsi_debug_virtual_gb > 0) {
+		sector_t sectors = 2 * 1024 * 1024;
+		sectors >>= (scsi_debug_sector_size_bits - 9);
+		return sectors * (sector_t)scsi_debug_virtual_gb;
+	} else
 		return sdebug_store_sectors;
 }
 
@@ -2861,6 +2864,7 @@ static int __init scsi_debug_init(void)
 	case 1024:
 	case 2048:
 	case 4096:
+		scsi_debug_sector_size_bits = ilog2(scsi_debug_sector_size);
 		break;
 	default:
 		printk(KERN_ERR "scsi_debug_init: invalid sector_size %d\n",
- -- 
Jeff Mahoney
SuSE Labs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.12 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/

iEYEARECAAYFAksoMM8ACgkQLPWxlyuTD7JX5wCePXEPr9nsTescewxkCVnMKZ5e
GQ8An3sSVP1UhWAQ4O6LlKznvEWMg+tH
=CEfl
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-12-17 19:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-16  0:58 [PATCH] scsi_debug: scale virtual_gb with sector_size properly Jeff Mahoney
2009-12-17 19:57 ` Douglas Gilbert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox