All of lore.kernel.org
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Ronnie Sahlberg <ronniesahlberg@gmail.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] SCSI: Fail medium writes with proper sense for readonly LUNs
Date: Mon, 16 Jul 2012 08:58:28 +0200	[thread overview]
Message-ID: <5003BB94.20603@redhat.com> (raw)
In-Reply-To: <1342215040-16128-2-git-send-email-ronniesahlberg@gmail.com>

Il 13/07/2012 23:30, Ronnie Sahlberg ha scritto:
> Add sense code for DATA_PROTECT/WRITE_PROTECTED and return this error
> for any WRITE*/WRITE_VERIFY* calls if the device is readonly=on,
> i.e. write-protected
> 
> Signed-off-by: Ronnie Sahlberg <ronniesahlberg@gmail.com>

Applied, thanks!

Paolo

> ---
>  hw/scsi-bus.c  |    5 +++++
>  hw/scsi-disk.c |   16 +++++++++++++---
>  hw/scsi.h      |    2 ++
>  3 files changed, 20 insertions(+), 3 deletions(-)
> 
> diff --git a/hw/scsi-bus.c b/hw/scsi-bus.c
> index 5ad1013..6299094 100644
> --- a/hw/scsi-bus.c
> +++ b/hw/scsi-bus.c
> @@ -1172,6 +1172,11 @@ const struct SCSISense sense_code_DEVICE_INTERNAL_RESET = {
>      .key = UNIT_ATTENTION, .asc = 0x29, .ascq = 0x04
>  };
>  
> +/* Data Protection, Write Protected */
> +const struct SCSISense sense_code_WRITE_PROTECTED = {
> +    .key = DATA_PROTECT, .asc = 0x27, .ascq = 0x00
> +};
> +
>  /*
>   * scsi_build_sense
>   *
> diff --git a/hw/scsi-disk.c b/hw/scsi-disk.c
> index 2c2be33..0aca383 100644
> --- a/hw/scsi-disk.c
> +++ b/hw/scsi-disk.c
> @@ -1565,9 +1565,6 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf)
>          r->sector = r->req.cmd.lba * (s->qdev.blocksize / 512);
>          r->sector_count = len * (s->qdev.blocksize / 512);
>          break;
> -    case VERIFY_10:
> -    case VERIFY_12:
> -    case VERIFY_16:
>      case WRITE_6:
>      case WRITE_10:
>      case WRITE_12:
> @@ -1575,6 +1572,13 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf)
>      case WRITE_VERIFY_10:
>      case WRITE_VERIFY_12:
>      case WRITE_VERIFY_16:
> +        if (bdrv_is_read_only(s->qdev.conf.bs)) {
> +            goto write_protect;
> +        }
> +        /* fallthough */
> +    case VERIFY_10:
> +    case VERIFY_12:
> +    case VERIFY_16:
>          len = r->req.cmd.xfer / s->qdev.blocksize;
>          DPRINTF("Write %s(sector %" PRId64 ", count %d)\n",
>                  (command & 0xe) == 0xe ? "And Verify " : "",
> @@ -1621,6 +1625,9 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf)
>          DPRINTF("WRITE SAME() (sector %" PRId64 ", count %d)\n",
>                  r->req.cmd.lba, len);
>  
> +        if (bdrv_is_read_only(s->qdev.conf.bs)) {
> +            goto write_protect;
> +        }
>          if (r->req.cmd.lba > s->qdev.max_lba) {
>              goto illegal_lba;
>          }
> @@ -1651,6 +1658,9 @@ static int32_t scsi_send_command(SCSIRequest *req, uint8_t *buf)
>      illegal_lba:
>          scsi_check_condition(r, SENSE_CODE(LBA_OUT_OF_RANGE));
>          return 0;
> +    write_protect:
> +        scsi_check_condition(r, SENSE_CODE(WRITE_PROTECTED));
> +        return 0;
>      }
>      if (r->sector_count == 0 && r->iov.iov_len == 0) {
>          scsi_req_complete(&r->req, GOOD);
> diff --git a/hw/scsi.h b/hw/scsi.h
> index 76f06d4..94d2962 100644
> --- a/hw/scsi.h
> +++ b/hw/scsi.h
> @@ -202,6 +202,8 @@ extern const struct SCSISense sense_code_MEDIUM_CHANGED;
>  extern const struct SCSISense sense_code_REPORTED_LUNS_CHANGED;
>  /* Unit attention, Device internal reset */
>  extern const struct SCSISense sense_code_DEVICE_INTERNAL_RESET;
> +/* Data Protection, Write Protected */
> +extern const struct SCSISense sense_code_WRITE_PROTECTED;
>  
>  #define SENSE_CODE(x) sense_code_ ## x
>  
> 

      reply	other threads:[~2012-07-16  6:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-13 21:30 [Qemu-devel] [PATCH] SCSI: Make write commands fail if the device is readonly Ronnie Sahlberg
2012-07-13 21:30 ` [Qemu-devel] [PATCH] SCSI: Fail medium writes with proper sense for readonly LUNs Ronnie Sahlberg
2012-07-16  6:58   ` Paolo Bonzini [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=5003BB94.20603@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=ronniesahlberg@gmail.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.