All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Fam Zheng <famz@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>, Peter Lieven <pl@kamp.de>,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Ronnie Sahlberg <ronniesahlberg@gmail.com>
Subject: Re: [Qemu-devel] [PATCH] iscsi: Refuse to open as writable if the LUN is write protected
Date: Wed, 29 Oct 2014 14:31:06 +0100	[thread overview]
Message-ID: <5450EC1A.9020502@redhat.com> (raw)
In-Reply-To: <1414588414-633-1-git-send-email-famz@redhat.com>



On 10/29/2014 02:13 PM, Fam Zheng wrote:
> 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 <famz@redhat.com>
> ---
>  block/iscsi.c | 30 ++++++++++++++++++++++++++++++
>  1 file changed, 30 insertions(+)
> 
> diff --git a/block/iscsi.c b/block/iscsi.c
> index 233f462..c154928 100644
> --- a/block/iscsi.c
> +++ b/block/iscsi.c
> @@ -1339,6 +1339,36 @@ 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 (flags & BDRV_O_RDWR) {
> +        struct scsi_mode_sense *ms;
> +
> +        task = iscsi_modesense6_sync(iscsilun->iscsi, iscsilun->lun,
> +                                      1, SCSI_MODESENSE_PC_CURRENT,
> +                                      0x3F,
> +                                      0, 255);
> +
> +        if (task == NULL) {
> +            error_setg(errp, "Failed to send MODE_SENSE10 command: %s\n",

This is MODE SENSE(6).  Fixed and applied.

Paolo

> +                       iscsi_get_error(iscsilun->iscsi));
> +            ret = -EINVAL;
> +            goto out;
> +        }
> +
> +        if (task->status != SCSI_STATUS_GOOD) {
> +            error_setg(errp, "MODE_SENSE10 failed: %s\n",
> +                       iscsi_get_error(iscsi));
> +            ret = -EINVAL;
> +            goto out;
> +        }
> +        ms = scsi_datain_unmarshall(task);
> +        if (ms->device_specific_parameter & 0x80) {
> +            error_setg(errp, "Cannot open a write protected LUN as read-write");
> +            ret = -EPERM;
> +            goto out;
> +        }
> +    }
> +
>      iscsi_readcapacity_sync(iscsilun, &local_err);
>      if (local_err != NULL) {
>          error_propagate(errp, local_err);
> 

  reply	other threads:[~2014-10-29 13:31 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-29 13:13 [Qemu-devel] [PATCH] iscsi: Refuse to open as writable if the LUN is write protected Fam Zheng
2014-10-29 13:31 ` Paolo Bonzini [this message]
2014-10-29 16:18   ` Peter Lieven
2014-10-29 18:28     ` Paolo Bonzini
2014-10-29 21:12       ` Peter Lieven
2014-10-30 10:27       ` Peter Lieven
2014-10-30 10:50         ` Fam Zheng
2014-10-30 10:52           ` Peter Lieven

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=5450EC1A.9020502@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=famz@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=pl@kamp.de \
    --cc=qemu-devel@nongnu.org \
    --cc=ronniesahlberg@gmail.com \
    --cc=stefanha@redhat.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.