linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Akinobu Mita <akinobu.mita@gmail.com>
To: linux-scsi@vger.kernel.org
Cc: Akinobu Mita <akinobu.mita@gmail.com>,
	"James E.J. Bottomley" <JBottomley@parallels.com>,
	Douglas Gilbert <dgilbert@interlog.com>,
	"Martin K. Petersen" <martin.petersen@oracle.com>
Subject: [PATCH 4/4] scsi_debug: fix out of range access by Get_LBA_status with virtual_gb > 0
Date: Mon, 15 Jul 2013 20:52:07 +0900	[thread overview]
Message-ID: <1373889127-17083-5-git-send-email-akinobu.mita@gmail.com> (raw)
In-Reply-To: <1373889127-17083-1-git-send-email-akinobu.mita@gmail.com>

With logical block provisioning support enabled, the provisioning map
(map_storep) keeps track of the provisioning status (mapped or unmapped)
for actual ramdisk storage range (fake_storep).  The provisioning status
for out of fake_storep range with module parameter virtual_gb > 0 is
not tracked, and it should be assumed always mapped.  It is reasonable,
because Unmap commands for such virtual range are always ignored.

Unfortunately, Get_LBA_status command for virtual range accesses out of
map_storep range.  This fixes invalid access and makes it return correct
provisioning status.

Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Cc: "James E.J. Bottomley" <JBottomley@parallels.com>
Cc: Douglas Gilbert <dgilbert@interlog.com>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: linux-scsi@vger.kernel.org
---
 drivers/scsi/scsi_debug.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 1e25c1e..c519c9f 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -2014,6 +2014,7 @@ static sector_t map_index_to_lba(unsigned long index)
 	return lba;
 }
 
+/* LBA from sdebug_store_sectors to sdebug_capacity is assumed mapped */
 static unsigned int map_state(sector_t lba, unsigned int *num)
 {
 	sector_t end;
@@ -2022,6 +2023,10 @@ static unsigned int map_state(sector_t lba, unsigned int *num)
 	unsigned long next;
 
 	index = lba_to_map_index(lba);
+	if (index >= map_size) {
+		*num = sdebug_capacity - lba;
+		return 1;
+	}
 	mapped = test_bit(index, map_storep);
 
 	if (mapped)
@@ -2029,7 +2034,11 @@ static unsigned int map_state(sector_t lba, unsigned int *num)
 	else
 		next = find_next_bit(map_storep, map_size, index);
 
-	end = min_t(sector_t, sdebug_store_sectors,  map_index_to_lba(next));
+	if (next >= map_size)
+		end = mapped ? sdebug_capacity : sdebug_store_sectors;
+	else
+		end = map_index_to_lba(next);
+
 	*num = end - lba;
 
 	return mapped;
-- 
1.8.3.1


      parent reply	other threads:[~2013-07-15 11:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-15 11:52 [PATCH 0/4] scsi_debug: fix bugs with certain module parameters Akinobu Mita
2013-07-15 11:52 ` [PATCH 1/4] scsi_debug: fix endianness bug in sdebug_build_parts() Akinobu Mita
2013-07-25 17:10   ` Martin Peschke
2013-07-25 20:16     ` Douglas Gilbert
2013-07-26 17:07     ` Akinobu Mita
2013-07-29 10:53       ` Martin Peschke
2013-07-15 11:52 ` [PATCH 2/4] scsi_debug: fix logical block provisioning support when unmap_alignment != 0 Akinobu Mita
2013-08-19 14:16   ` Akinobu Mita
2013-08-20 20:56     ` Douglas Gilbert
2013-08-21 13:58       ` Akinobu Mita
2013-08-22  1:29       ` Martin K. Petersen
2013-07-15 11:52 ` [PATCH 3/4] scsi_debug: fix WRITE_SAME with virtual_gb > 0 Akinobu Mita
2013-07-15 11:52 ` Akinobu Mita [this message]

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=1373889127-17083-5-git-send-email-akinobu.mita@gmail.com \
    --to=akinobu.mita@gmail.com \
    --cc=JBottomley@parallels.com \
    --cc=dgilbert@interlog.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.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;
as well as URLs for NNTP newsgroup(s).