[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 20/35] iscsi: Refuse to open as writable if the LUN i
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 20/35] iscsi: Refuse to open as writable if the LUN is write protected |
Date: |
Fri, 31 Oct 2014 18:25:58 +0100 |
From: Fam Zheng <address@hidden>
Before, when a write protected iSCSI target is attached as scsi-disk
with BDRV_O_RDWR, we report it as writable, while in fact all writes
will fail.
One way to improve this is to report write protect flag as true to
guest, but a even better way is to refuse using a write protected LUN to
guest.
Target write protect flag is checked with a mode sense query.
Signed-off-by: Fam Zheng <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
block/iscsi.c | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/block/iscsi.c b/block/iscsi.c
index 233f462..3485d62 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -1219,6 +1219,40 @@ static void iscsi_attach_aio_context(BlockDriverState
*bs,
qemu_clock_get_ms(QEMU_CLOCK_REALTIME) + NOP_INTERVAL);
}
+static bool iscsi_is_write_protected(IscsiLun *iscsilun)
+{
+ struct scsi_task *task;
+ struct scsi_mode_sense *ms = NULL;
+ bool wrprotected = false;
+
+ task = iscsi_modesense6_sync(iscsilun->iscsi, iscsilun->lun,
+ 1, SCSI_MODESENSE_PC_CURRENT,
+ 0x3F, 0, 255);
+ if (task == NULL) {
+ error_report("iSCSI: Failed to send MODE_SENSE(6) command: %s",
+ iscsi_get_error(iscsilun->iscsi));
+ goto out;
+ }
+
+ if (task->status != SCSI_STATUS_GOOD) {
+ error_report("iSCSI: Failed MODE_SENSE(6), LUN assumed writable");
+ goto out;
+ }
+ ms = scsi_datain_unmarshall(task);
+ if (!ms) {
+ error_report("iSCSI: Failed to unmarshall MODE_SENSE(6) data: %s",
+ iscsi_get_error(iscsilun->iscsi));
+ goto out;
+ }
+ wrprotected = ms->device_specific_parameter & 0x80;
+
+out:
+ if (task) {
+ scsi_free_scsi_task(task);
+ }
+ return wrprotected;
+}
+
/*
* We support iscsi url's on the form
* iscsi://[<username>%<password>@]<host>[:<port>]/<targetname>/<lun>
@@ -1339,6 +1373,14 @@ static int iscsi_open(BlockDriverState *bs, QDict
*options, int flags,
scsi_free_scsi_task(task);
task = NULL;
+ /* Check the write protect flag of the LUN if we want to write */
+ if (iscsilun->type == TYPE_DISK && (flags & BDRV_O_RDWR) &&
+ iscsi_is_write_protected(iscsilun)) {
+ error_setg(errp, "Cannot open a write protected LUN as read-write");
+ ret = -EACCES;
+ goto out;
+ }
+
iscsi_readcapacity_sync(iscsilun, &local_err);
if (local_err != NULL) {
error_propagate(errp, local_err);
--
1.8.3.1
- [Qemu-devel] [PULL 10/35] megasas: Clear unit attention on initial reset, (continued)
- [Qemu-devel] [PULL 10/35] megasas: Clear unit attention on initial reset, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 11/35] megasas: Ignore duplicate init_firmware commands, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 12/35] megasas: Implement DCMD_CLUSTER_RESET_LD, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 13/35] megasas: Update queue logging, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 14/35] megasas: Rework frame queueing algorithm, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 15/35] megasas: Fixup MSI-X handling, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 16/35] -machine vmport=off: Allow disabling of VMWare ioport emulation, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 17/35] Add skip_dump flag to ignore memory region during dump, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 18/35] vl.c: Fix Coverity complaining for vmstate_dump_file, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 19/35] kvmvapic: patch_instruction fix, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 20/35] iscsi: Refuse to open as writable if the LUN is write protected,
Paolo Bonzini <=
- [Qemu-devel] [PULL 21/35] virtio-scsi: Fix memory leak when realize failed, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 22/35] scsi: devirtualize unrealize of SCSI devices, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 23/35] virtio-scsi: Fix num_queue input validation, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 24/35] kvm_stat: Only consider online cpus, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 25/35] kvm_stat: Fix the non-x86 exit reasons, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 26/35] kvm_stat: Rework platform detection, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 27/35] kvm_stat: Abstract ioctl numbers, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 28/35] kvm_stat: Add powerpc support, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 29/35] i386: fix breakpoints handling in icount mode, Paolo Bonzini, 2014/10/31
- [Qemu-devel] [PULL 32/35] ivshmem: Fix potential OOB r/w access, Paolo Bonzini, 2014/10/31