* [PATCH v2] scsi: sd: Keep disk read-only when re-reading partition
@ 2018-03-06 21:47 Jeremy Cline
2018-03-07 3:13 ` Martin K. Petersen
0 siblings, 1 reply; 2+ messages in thread
From: Jeremy Cline @ 2018-03-06 21:47 UTC (permalink / raw)
To: James E . J . Bottomley, Martin K . Petersen
Cc: linux-scsi, linux-kernel, lining916740672, Jeremy Cline
If the read-only flag is true on a SCSI disk, re-reading the partition
table sets the flag back to false.
To observe this bug, you can run:
1. blockdev --setro /dev/sda
2. blockdev --rereadpt /dev/sda
3. blockdev --getro /dev/sda
This commit reads the disk's old state and combines it with the device
disk-reported state rather than unconditionally marking it as RW.
Reported-by: Li Ning <lining916740672@icloud.com>
Signed-off-by: Jeremy Cline <jeremy@jcline.org>
---
Sorry about this, but there's a bug in the first version of this patch.
I'm not sure what the protocol is for sending revised patches when the
earlier version got accepted, but I don't see the first version in
4.16/scsi-fixes yet. If I should make a patch on top of the v1 patch,
just let me know.
Changes in v2:
- Don't save the value of "get_disk_ro" to "sdkp->write_prot" since,
as Li Ning noticed, that causes a second bug: when you make the disk
writable again with "blockdev --setrw /dev/sda" it isn't possible to
write to the disk until the partition is re-read.
drivers/scsi/sd.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index bff21e636ddd..3541caf3fceb 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -2595,6 +2595,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer)
int res;
struct scsi_device *sdp = sdkp->device;
struct scsi_mode_data data;
+ int disk_ro = get_disk_ro(sdkp->disk);
int old_wp = sdkp->write_prot;
set_disk_ro(sdkp->disk, 0);
@@ -2635,7 +2636,7 @@ sd_read_write_protect_flag(struct scsi_disk *sdkp, unsigned char *buffer)
"Test WP failed, assume Write Enabled\n");
} else {
sdkp->write_prot = ((data.device_specific & 0x80) != 0);
- set_disk_ro(sdkp->disk, sdkp->write_prot);
+ set_disk_ro(sdkp->disk, sdkp->write_prot || disk_ro);
if (sdkp->first_scan || old_wp != sdkp->write_prot) {
sd_printk(KERN_NOTICE, sdkp, "Write Protect is %s\n",
sdkp->write_prot ? "on" : "off");
--
2.16.2
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] scsi: sd: Keep disk read-only when re-reading partition
2018-03-06 21:47 [PATCH v2] scsi: sd: Keep disk read-only when re-reading partition Jeremy Cline
@ 2018-03-07 3:13 ` Martin K. Petersen
0 siblings, 0 replies; 2+ messages in thread
From: Martin K. Petersen @ 2018-03-07 3:13 UTC (permalink / raw)
To: Jeremy Cline
Cc: James E . J . Bottomley, Martin K . Petersen, linux-scsi,
linux-kernel, lining916740672
Jeremy,
> Sorry about this, but there's a bug in the first version of this patch.
> I'm not sure what the protocol is for sending revised patches when the
> earlier version got accepted, but I don't see the first version in
> 4.16/scsi-fixes yet.
It's your lucky day! I botched fixing up something the other day and as
a result the tree was never pushed.
v2 added to 4.16/scsi-fixes.
Thanks!
--
Martin K. Petersen Oracle Linux Engineering
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-03-07 3:13 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-06 21:47 [PATCH v2] scsi: sd: Keep disk read-only when re-reading partition Jeremy Cline
2018-03-07 3:13 ` Martin K. Petersen
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).