qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Fam Zheng <famz@redhat.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] scsi-generic: let guests recognize readonly=on on passthrough devices
Date: Thu, 17 Sep 2015 12:48:56 +0800	[thread overview]
Message-ID: <20150917044856.GA11527@ad.nay.redhat.com> (raw)
In-Reply-To: <1442417379-5626-1-git-send-email-pbonzini@redhat.com>

On Wed, 09/16 17:29, Paolo Bonzini wrote:
> 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.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>  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
> 
> 

Reviewed-by: Fam Zheng <famz@redhat.com>

      reply	other threads:[~2015-09-17  4:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-16 15:29 [Qemu-devel] [PATCH] scsi-generic: let guests recognize readonly=on on passthrough devices Paolo Bonzini
2015-09-17  4:48 ` Fam Zheng [this message]

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=20150917044856.GA11527@ad.nay.redhat.com \
    --to=famz@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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 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).