[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 06/48] scsi-generic: let guests recognize readonly=on
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 06/48] scsi-generic: let guests recognize readonly=on on passthrough devices |
Date: |
Tue, 22 Sep 2015 17:05:29 +0200 |
Passed-through SCSI devices can be opened with the readonly=on option.
When this happens, Linux filters away write commands so that the guest
cannot overwrite the contents of the device.
However, the guest does not know that the device is read-only, and
accepts writes. The writes only fail later when the page cache is
flushed.
This patch modifies scsi-generic to modify the MODE SENSE data and
set the read-only bit in the device-specific parameters, so that
the guest OS treats the disk as write protected.
Reviewed-by: Fam Zheng <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/scsi/scsi-generic.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/hw/scsi/scsi-generic.c b/hw/scsi/scsi-generic.c
index 1b6350b..a4626f7 100644
--- a/hw/scsi/scsi-generic.c
+++ b/hw/scsi/scsi-generic.c
@@ -210,6 +210,20 @@ static void scsi_read_complete(void * opaque, int ret)
}
blk_set_guest_block_size(s->conf.blk, s->blocksize);
+ /* Patch MODE SENSE device specific parameters if the BDS is opened
+ * readonly.
+ */
+ if ((s->type == TYPE_DISK || s->type == TYPE_TAPE) &&
+ blk_is_read_only(s->conf.blk) &&
+ (r->req.cmd.buf[0] == MODE_SENSE ||
+ r->req.cmd.buf[0] == MODE_SENSE_10) &&
+ (r->req.cmd.buf[1] & 0x8) == 0) {
+ if (r->req.cmd.buf[0] == MODE_SENSE) {
+ r->buf[2] |= 0x80;
+ } else {
+ r->buf[3] |= 0x80;
+ }
+ }
scsi_req_data(&r->req, len);
scsi_req_unref(&r->req);
}
--
2.5.0
- [Qemu-devel] [PULL 00/48] Misc patches for 2015-09-22, Paolo Bonzini, 2015/09/22
- [Qemu-devel] [PULL 01/48] nbd: convert to use the QAPI SocketAddress object, Paolo Bonzini, 2015/09/22
- [Qemu-devel] [PULL 02/48] qemu-nbd: convert to use the QAPI SocketAddress object, Paolo Bonzini, 2015/09/22
- [Qemu-devel] [PULL 04/48] tests: add some qemu_strtosz() tests, Paolo Bonzini, 2015/09/22
- [Qemu-devel] [PULL 03/48] utils: rename strtosz to use qemu prefix, Paolo Bonzini, 2015/09/22
- [Qemu-devel] [PULL 05/48] checkpatch: do not recommend qemu_strtok over strtok, Paolo Bonzini, 2015/09/22
- [Qemu-devel] [PULL 07/48] Makefile: fix build when VPATH is outside GIT tree, Paolo Bonzini, 2015/09/22
- [Qemu-devel] [PULL 06/48] scsi-generic: let guests recognize readonly=on on passthrough devices,
Paolo Bonzini <=
- [Qemu-devel] [PULL 08/48] vhost-scsi: include linux/vhost.h, Paolo Bonzini, 2015/09/22
- [Qemu-devel] [PULL 10/48] MAINTAINERS: there is no PPC64 TCG backend anymore, Paolo Bonzini, 2015/09/22
- [Qemu-devel] [PULL 09/48] get_maintainer.pl: \C is deprecated, Paolo Bonzini, 2015/09/22
- [Qemu-devel] [PULL 11/48] MAINTAINERS: Add disassemblers to the various backends, Paolo Bonzini, 2015/09/22
- [Qemu-devel] [PULL 12/48] MAINTAINERS: Add more s390 files, Paolo Bonzini, 2015/09/22
- [Qemu-devel] [PULL 15/48] MAINTAINERS: add more devices to the PCI section, Paolo Bonzini, 2015/09/22
- [Qemu-devel] [PULL 16/48] MAINTAINERS: add maintainer for character device front-ends, Paolo Bonzini, 2015/09/22
- [Qemu-devel] [PULL 13/48] MAINTAINERS: add IPack section, Paolo Bonzini, 2015/09/22
- [Qemu-devel] [PULL 17/48] ioapic: coalesce level interrupts, Paolo Bonzini, 2015/09/22
- [Qemu-devel] [PULL 14/48] MAINTAINERS: add more devices to the PC section, Paolo Bonzini, 2015/09/22