public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Jeff Mahoney <jeffm@suse.com>
To: Linux SCSI Mailing List <linux-scsi@vger.kernel.org>
Subject: [PATCH] scsi_debug: scale virtual_gb with sector_size properly
Date: Tue, 15 Dec 2009 19:58:55 -0500	[thread overview]
Message-ID: <4B2830CF.2020203@suse.com> (raw)

-----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-----

             reply	other threads:[~2009-12-16  0:59 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-16  0:58 Jeff Mahoney [this message]
2009-12-17 19:57 ` [PATCH] scsi_debug: scale virtual_gb with sector_size properly Douglas Gilbert

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=4B2830CF.2020203@suse.com \
    --to=jeffm@suse.com \
    --cc=linux-scsi@vger.kernel.org \
    /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