From: Hannes Reinecke <hare@suse.de>
To: James Bottomley <jbottomley@parallels.com>
Cc: Christoph Hellwig <hch@infradead.org>,
Ewan Milne <emilne@redhat.com>,
linux-scsi@vger.kernel.org, Hannes Reinecke <hare@suse.de>
Subject: [PATCH 6/6] scsi_scan: Fixup scsilun_to_int()
Date: Sat, 31 May 2014 11:01:18 +0200 [thread overview]
Message-ID: <1401526878-119472-7-git-send-email-hare@suse.de> (raw)
In-Reply-To: <1401526878-119472-1-git-send-email-hare@suse.de>
scsilun_to_int() has an error which prevents it from generating
correct LUN numbers for 64bit values.
Also we should remove the misleading comment about portions of
the LUN being ignored; the initiator should treat the LUN as
an opaque value.
And, finally, the example given should use the correct
prefix (here: extended flat space addressing scheme).
Suggested-by: Doug Gilbert <dgilbert@interlog.com>
Signed-off-by: Hannes Reinecke <hare@suse.de>
---
drivers/scsi/scsi_scan.c | 29 ++++++++++++-----------------
1 file changed, 12 insertions(+), 17 deletions(-)
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index fa57a04..42843ec 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -1263,25 +1263,23 @@ static void scsi_sequential_lun_scan(struct scsi_target *starget,
* truncation before using this function.
*
* Notes:
- * The struct scsi_lun is assumed to be four levels, with each level
- * effectively containing a SCSI byte-ordered (big endian) short; the
- * addressing bits of each level are ignored (the highest two bits).
* For a description of the LUN format, post SCSI-3 see the SCSI
* Architecture Model, for SCSI-3 see the SCSI Controller Commands.
*
- * Given a struct scsi_lun of: 0a 04 0b 03 00 00 00 00, this function returns
- * the integer: 0x0b030a04
+ * Given a struct scsi_lun of: d2 04 0b 03 00 00 00 00, this function
+ * returns the integer: 0x0b03d204
**/
u64 scsilun_to_int(struct scsi_lun *scsilun)
{
- int i;
- u64 lun;
+ const unsigned char * cp;
+ uint64_t res;
- lun = 0;
- for (i = 0; i < sizeof(lun); i += 2)
- lun = lun | (((scsilun->scsi_lun[i] << 8) |
- scsilun->scsi_lun[i + 1]) << (i * 8));
- return lun;
+ res = (scsilun->scsi_lun[6] << 8) + scsilun->scsi_lun[7];
+ for (cp = scsilun->scsi_lun + 4; cp >= scsilun->scsi_lun; cp -= 2) {
+ res <<= 16;
+ res += (*cp << 8) + *(cp + 1);
+ }
+ return res;
}
EXPORT_SYMBOL(scsilun_to_int);
@@ -1294,13 +1292,10 @@ EXPORT_SYMBOL(scsilun_to_int);
* Reverts the functionality of the scsilun_to_int, which packed
* an 8-byte lun value into an int. This routine unpacks the int
* back into the lun value.
- * Note: the scsilun_to_int() routine does not truly handle all
- * 8bytes of the lun value. This functions restores only as much
- * as was set by the routine.
*
* Notes:
- * Given an integer : 0x0b030a04, this function returns a
- * scsi_lun of : struct scsi_lun of: 0a 04 0b 03 00 00 00 00
+ * Given an integer : 0x0b03d204, this function returns a
+ * scsi_lun of : struct scsi_lun of: d2 04 0b 03 00 00 00 00
*
**/
void int_to_scsilun(u64 lun, struct scsi_lun *scsilun)
--
1.7.12.4
next prev parent reply other threads:[~2014-05-31 9:01 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-31 9:01 [PATCHv3 0/6] Support 64-bit LUNs Hannes Reinecke
2014-05-31 9:01 ` [PATCH 1/6] scsi: Remove CONFIG_SCSI_MULTI_LUN Hannes Reinecke
2014-05-31 9:01 ` [PATCH 2/6] scsi_scan: Restrict sequential scan to 256 LUNs Hannes Reinecke
2014-05-31 9:01 ` [PATCH 3/6] qla2xxx: Restrict max_lun to 16-bit for older HBAs Hannes Reinecke
2014-05-31 9:01 ` [PATCH 4/6] scsi: use 64-bit LUNs Hannes Reinecke
2014-06-02 16:13 ` Bart Van Assche
2014-05-31 9:01 ` [PATCH 5/6] scsi: use 64-bit value for 'max_luns' Hannes Reinecke
2014-05-31 9:01 ` Hannes Reinecke [this message]
2014-06-02 16:03 ` [PATCH 6/6] scsi_scan: Fixup scsilun_to_int() James Bottomley
2014-06-02 16:16 ` Bart Van Assche
2014-06-02 8:15 ` [PATCHv3 0/6] Support 64-bit LUNs Christoph Hellwig
-- strict thread matches above, loose matches on Subject: below --
2014-06-03 8:58 [PATCHv4 " Hannes Reinecke
2014-06-03 8:58 ` [PATCH 6/6] scsi_scan: Fixup scsilun_to_int() Hannes Reinecke
2014-06-10 11:37 ` Bart Van Assche
2014-06-10 13:41 ` Douglas Gilbert
2014-06-10 14:06 ` James Bottomley
2014-06-10 14:48 ` Bart Van Assche
2014-06-10 15:01 ` James Bottomley
2014-06-10 16:08 ` Bart Van Assche
2014-06-10 14:55 ` Douglas Gilbert
2014-06-25 11:20 Hannes Reinecke
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=1401526878-119472-7-git-send-email-hare@suse.de \
--to=hare@suse.de \
--cc=emilne@redhat.com \
--cc=hch@infradead.org \
--cc=jbottomley@parallels.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;
as well as URLs for NNTP newsgroup(s).