From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33344) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSNHv-0001xg-Nu for qemu-devel@nongnu.org; Mon, 02 Mar 2015 05:09:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YSNHo-0007pK-Jo for qemu-devel@nongnu.org; Mon, 02 Mar 2015 05:09:23 -0500 Received: from mail-we0-x232.google.com ([2a00:1450:400c:c03::232]:44964) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YSNHo-0007ow-BP for qemu-devel@nongnu.org; Mon, 02 Mar 2015 05:09:16 -0500 Received: by wesk11 with SMTP id k11so32187053wes.11 for ; Mon, 02 Mar 2015 02:09:15 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Mon, 2 Mar 2015 11:08:48 +0100 Message-Id: <1425290934-60872-10-git-send-email-pbonzini@redhat.com> In-Reply-To: <1425290934-60872-1-git-send-email-pbonzini@redhat.com> References: <1425290934-60872-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 09/15] iscsi: Handle write protected case in reopen List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Fam Zheng From: Fam Zheng Save the write protected flag and check before reopen. Signed-off-by: Fam Zheng Message-Id: <1424839208-5195-1-git-send-email-famz@redhat.com> [Fixed typo in the name of the new field. - Paolo] Signed-off-by: Paolo Bonzini --- block/iscsi.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/block/iscsi.c b/block/iscsi.c index 12ddbfb..1fa855a 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -65,6 +65,7 @@ typedef struct IscsiLun { unsigned long *allocationmap; int cluster_sectors; bool use_16_for_rw; + bool write_protected; } IscsiLun; typedef struct IscsiTask { @@ -1268,10 +1269,6 @@ out: /* * We support iscsi url's on the form * iscsi://[%@][:]// - * - * Note: flags are currently not used by iscsi_open. If this function - * is changed such that flags are used, please examine iscsi_reopen_prepare() - * to see if needs to be changed as well. */ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, Error **errp) @@ -1385,9 +1382,10 @@ static int iscsi_open(BlockDriverState *bs, QDict *options, int flags, scsi_free_scsi_task(task); task = NULL; + iscsilun->write_protected = iscsi_is_write_protected(iscsilun); /* 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)) { + iscsilun->write_protected) { error_setg(errp, "Cannot open a write protected LUN as read-write"); ret = -EACCES; goto out; @@ -1541,13 +1539,17 @@ static void iscsi_refresh_limits(BlockDriverState *bs, Error **errp) sector_limits_lun2qemu(iscsilun->bl.opt_xfer_len, iscsilun); } -/* Since iscsi_open() ignores bdrv_flags, there is nothing to do here in - * prepare. Note that this will not re-establish a connection with an iSCSI - * target - it is effectively a NOP. */ +/* Note that this will not re-establish a connection with an iSCSI target - it + * is effectively a NOP. */ static int iscsi_reopen_prepare(BDRVReopenState *state, BlockReopenQueue *queue, Error **errp) { - /* NOP */ + IscsiLun *iscsilun = state->bs->opaque; + + if (state->flags & BDRV_O_RDWR && iscsilun->write_protected) { + error_setg(errp, "Cannot open a write protected LUN as read-write"); + return -EACCES; + } return 0; } -- 2.3.0