From: Patrick Mansfield <patmans@us.ibm.com>
To: Pat LaVarre <p.lavarre@ieee.org>
Cc: stern@rowland.harvard.edu, ronald@kuetemeier.com,
linux-scsi@vger.kernel.org, usb-storage@one-eyed-alien.net,
james.bottomley@steeleye.com
Subject: [PATCH/RFT] mode sense madness always use page 8
Date: Thu, 30 Oct 2003 10:05:01 -0800 [thread overview]
Message-ID: <20031030100501.A7250@beaverton.ibm.com> (raw)
In-Reply-To: <1067535485.6411.42.camel@pathost1.iomegacorp.com>; from p.lavarre@ieee.org on Thu, Oct 30, 2003 at 10:38:05AM -0700
Here's a patch, per Pat Lavarre's suggestion, this can't go in without
others verifying and testing it, and without input or comment from others
(at least James).
Again no USB testing here, tested on 2 sets of SPI attached disks, and 2
sets of FCP attached disks. It really needs testing on removable media to
actually hit the write protect check.
Ronald does this work for you?
------
Use MODE SENSE page 8 whether asking for write protect information or
cache type. Always use the exact size of the expected result.
diff -uprN -X /home/patman/dontdiff bl-25/drivers/scsi/scsi_lib.c use_page8_always-bl-2.5/drivers/scsi/scsi_lib.c
--- bl-25/drivers/scsi/scsi_lib.c Mon Sep 29 12:21:09 2003
+++ use_page8_always-bl-2.5/drivers/scsi/scsi_lib.c Thu Oct 30 09:23:19 2003
@@ -1377,6 +1377,11 @@ __scsi_mode_sense(struct scsi_request *s
if (use_10_for_ms) {
if (len < 8)
len = 8;
+ else if (len > 28)
+ /*
+ * 20 bytes + 8 byte header
+ */
+ len = 28;
cmd[0] = MODE_SENSE_10;
cmd[8] = len;
@@ -1384,6 +1389,11 @@ __scsi_mode_sense(struct scsi_request *s
} else {
if (len < 4)
len = 4;
+ else if (len > 24)
+ /*
+ * 20 bytes + 4 byte header
+ */
+ len = 24;
cmd[0] = MODE_SENSE;
cmd[4] = len;
diff -uprN -X /home/patman/dontdiff bl-25/drivers/scsi/sd.c use_page8_always-bl-2.5/drivers/scsi/sd.c
--- bl-25/drivers/scsi/sd.c Mon Oct 27 14:28:18 2003
+++ use_page8_always-bl-2.5/drivers/scsi/sd.c Thu Oct 30 09:35:53 2003
@@ -1085,8 +1085,10 @@ sd_do_mode_sense(struct scsi_request *SR
*/
static void
sd_read_write_protect_flag(struct scsi_disk *sdkp, char *diskname,
- struct scsi_request *SRpnt, unsigned char *buffer) {
+ struct scsi_request *SRpnt, unsigned char *buffer)
+{
int res;
+ int len;
struct scsi_mode_data data;
if (sdkp->device->skip_ms_page_3f) {
@@ -1094,26 +1096,16 @@ sd_read_write_protect_flag(struct scsi_d
return;
}
- /*
- * First attempt: ask for all pages (0x3F), but only 4 bytes.
- * We have to start carefully: some devices hang if we ask
- * for more than is available.
- */
- res = sd_do_mode_sense(SRpnt, 0, 0x3F, buffer, 4, &data);
-
- /*
- * Second attempt: ask for page 0
- * When only page 0 is implemented, a request for page 3F may return
- * Sense Key 5: Illegal Request, Sense Code 24: Invalid field in CDB.
- */
- if (!scsi_status_is_good(res))
- res = sd_do_mode_sense(SRpnt, 0, 0, buffer, 4, &data);
-
- /*
- * Third attempt: ask 255 bytes, as we did earlier.
- */
- if (!scsi_status_is_good(res))
- res = sd_do_mode_sense(SRpnt, 0, 0x3F, buffer, 255, &data);
+ if (sdkp->device->use_10_for_ms)
+ /*
+ * __mode_sense auto-retries with a size of 24 if it
+ * switches to a 6 byte command.
+ */
+ len = 28; /* 20 + 8 byte header */
+ else
+ len = 24; /* 20 + 4 byte header */
+
+ res = sd_do_mode_sense(SRpnt, 0, 8, buffer, len, &data);
if (!scsi_status_is_good(res)) {
printk(KERN_WARNING
@@ -1130,42 +1122,36 @@ sd_read_write_protect_flag(struct scsi_d
/*
* sd_read_cache_type - called only from sd_revalidate_disk()
* called with buffer of length 512
+ *
+ * XXX Combine this with sd_read_write_protect_flag, so we only get the
+ * page once.
*/
static void
sd_read_cache_type(struct scsi_disk *sdkp, char *diskname,
- struct scsi_request *SRpnt, unsigned char *buffer) {
+ struct scsi_request *SRpnt, unsigned char *buffer)
+{
int len = 0, res;
-
- const int dbd = 0; /* DBD */
- const int modepage = 0x08; /* current values, cache page */
struct scsi_mode_data data;
- if (sdkp->device->skip_ms_page_8)
- goto defaults;
-
- /* cautiously ask */
- res = sd_do_mode_sense(SRpnt, dbd, modepage, buffer, 4, &data);
-
- if (!scsi_status_is_good(res))
- goto bad_sense;
+ sdkp->WCE = 0;
+ sdkp->RCD = 0;
- /* that went OK, now ask for the proper length */
- len = data.length;
-
- /*
- * We're only interested in the first three bytes, actually.
- * But the data cache page is defined for the first 20.
- */
- if (len < 3)
- goto bad_sense;
- if (len > 20)
- len = 20;
+ if (sdkp->device->skip_ms_page_8) {
+ printk(KERN_ERR "%s: assuming drive cache: write through\n",
+ diskname);
+ return;
+ }
- /* Take headers and block descriptors into account */
- len += data.header_length + data.block_descriptor_length;
+ if (sdkp->device->use_10_for_ms)
+ /*
+ * __mode_sense auto-retries with a size of 24 if it
+ * switches to a 6 byte command.
+ */
+ len = 28; /* 20 + 8 byte header */
+ else
+ len = 24; /* 20 + 4 byte header */
- /* Get the data */
- res = sd_do_mode_sense(SRpnt, dbd, modepage, buffer, len, &data);
+ res = sd_do_mode_sense(SRpnt, 0, 8, buffer, len, &data);
if (scsi_status_is_good(res)) {
const char *types[] = {
@@ -1185,10 +1171,7 @@ sd_read_cache_type(struct scsi_disk *sdk
diskname, types[ct]);
return;
- }
-
-bad_sense:
- if ((SRpnt->sr_sense_buffer[0] & 0x70) == 0x70
+ } else if ((SRpnt->sr_sense_buffer[0] & 0x70) == 0x70
&& (SRpnt->sr_sense_buffer[2] & 0x0f) == ILLEGAL_REQUEST
/* ASC 0x24 ASCQ 0x00: Invalid field in CDB */
&& SRpnt->sr_sense_buffer[12] == 0x24
@@ -1199,12 +1182,6 @@ bad_sense:
printk(KERN_ERR "%s: asking for cache data failed\n",
diskname);
}
-
-defaults:
- printk(KERN_ERR "%s: assuming drive cache: write through\n",
- diskname);
- sdkp->WCE = 0;
- sdkp->RCD = 0;
}
/**
next prev parent reply other threads:[~2003-10-30 18:06 UTC|newest]
Thread overview: 55+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <1067293080.1075.8.camel@ronald.kuetemeier.com>
[not found] ` <20031027145531.A2130@beaverton.ibm.com>
2003-10-28 3:51 ` [PATCH] SCSI: limit mode sense usage Ronald Kuetemeier
2003-10-28 15:03 ` [usb-storage] " Alan Stern
2003-10-28 15:16 ` Patrick Mansfield
2003-10-28 15:40 ` Alan Stern
2003-10-28 15:55 ` Ronald Kuetemeier
2003-10-28 16:15 ` Ronald Kuetemeier
2003-10-28 19:17 ` Alan Stern
2003-10-28 19:55 ` Ronald Kuetemeier
2003-10-28 20:29 ` Alan Stern
2003-10-28 21:33 ` Ronald Kuetemeier
2003-10-28 22:49 ` Alan Stern
2003-10-28 23:37 ` Pat LaVarre
2003-10-29 1:51 ` Patrick Mansfield
2003-10-29 2:16 ` Ronald Kuetemeier
2003-10-29 7:27 ` Patrick Mansfield
2003-10-29 7:21 ` Patrick Mansfield
2003-10-29 15:16 ` Alan Stern
2003-10-29 16:04 ` Ronald Kuetemeier
2003-10-29 15:09 ` Alan Stern
2003-10-29 15:53 ` Ronald Kuetemeier
2003-10-29 16:30 ` Patrick Mansfield
2003-10-28 15:42 ` Ronald Kuetemeier
2003-10-29 16:46 ` [PATCH/RFT] check non-scsi part of status in scsi_status_is_good Patrick Mansfield
2003-10-29 17:53 ` Ronald Kuetemeier
2003-10-29 23:16 ` Patrick Mansfield
2003-10-30 15:11 ` Alan Stern
2003-10-30 16:35 ` Pat LaVarre
2003-10-30 17:18 ` Patrick Mansfield
2003-10-30 17:38 ` Pat LaVarre
2003-10-30 18:05 ` Patrick Mansfield [this message]
2003-10-30 18:14 ` [PATCH/RFT] mode sense madness always use page 8 Ronald Kuetemeier
2003-10-30 18:25 ` Patrick Mansfield
2003-10-30 18:15 ` Pat LaVarre
2003-10-30 18:56 ` Alan Stern
2003-10-30 19:06 ` Pat LaVarre
2003-10-30 20:00 ` Alan Stern
2003-10-31 20:47 ` Pat LaVarre
2003-10-30 19:26 ` Patrick Mansfield
2003-10-31 20:38 ` Pat LaVarre
2003-11-03 21:40 ` Pat LaVarre
2003-10-30 19:25 ` Ronald Kuetemeier
2003-10-30 19:39 ` Pat LaVarre
2003-10-30 21:48 ` Patrick Mansfield
2003-10-30 21:58 ` Ronald Kuetemeier
2003-10-30 23:59 ` Pat LaVarre
2003-10-31 18:16 ` Patrick Mansfield
2003-10-31 23:11 ` Pat LaVarre
2003-11-06 23:11 ` Douglas Gilbert
2003-11-07 16:13 ` Pat LaVarre
2003-10-28 15:38 ` [PATCH] SCSI: limit mode sense usage Pat LaVarre
2003-10-28 20:56 ` Pat LaVarre
2003-10-28 22:28 ` Alan Stern
2003-10-28 22:54 ` Pat LaVarre
2003-10-29 14:49 ` Alan Stern
2003-10-29 15:43 ` Pat LaVarre
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=20031030100501.A7250@beaverton.ibm.com \
--to=patmans@us.ibm.com \
--cc=james.bottomley@steeleye.com \
--cc=linux-scsi@vger.kernel.org \
--cc=p.lavarre@ieee.org \
--cc=ronald@kuetemeier.com \
--cc=stern@rowland.harvard.edu \
--cc=usb-storage@one-eyed-alien.net \
/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).