qemu-block
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-block] [Qemu-devel] [PATCH for-4.1] scsi-cd: Fix inserting rea


From: Christophe de Dinechin
Subject: Re: [Qemu-block] [Qemu-devel] [PATCH for-4.1] scsi-cd: Fix inserting read-only media in empty drive
Date: Tue, 30 Jul 2019 11:00:00 +0200
User-agent: mu4e 1.3.2; emacs 26.2

Kevin Wolf writes:

> scsi-disks decides whether it has a read-only device by looking at
> whether the BlockBackend specified as drive=... is read-only. In the
> case of an anonymous BlockBackend (with a node name specified in
> drive=...), this is the read-only flag of the attached node. In the case
> of an empty anonymous BlockBackend, it's always read-write because
> nothing prevented it from being read-write.
>
> This is a problem because scsi-cd would take write permissions on the
> anonymous BlockBackend of an empty drive created without a drive=...
> option. Using blockdev-insert-medium with a read-only node fails then
> with the error message "Block node is read-only".
>
> Fix scsi_realize() so that scsi-cd devices always take read-only
> permissions on their BlockBackend instead.
>
> Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1733920
> Signed-off-by: Kevin Wolf <address@hidden>
> ---
>  hw/scsi/scsi-disk.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
> index 8e95e3e38d..af3e622dc5 100644
> --- a/hw/scsi/scsi-disk.c
> +++ b/hw/scsi/scsi-disk.c
> @@ -2318,6 +2318,7 @@ static void 
> scsi_disk_unit_attention_reported(SCSIDevice *dev)
>  static void scsi_realize(SCSIDevice *dev, Error **errp)
>  {
>      SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
> +    bool read_only;
>
>      if (!s->qdev.conf.blk) {
>          error_setg(errp, "drive property not set");
> @@ -2351,8 +2352,13 @@ static void scsi_realize(SCSIDevice *dev, Error **errp)
>              return;
>          }
>      }
> -    if (!blkconf_apply_backend_options(&dev->conf,
> -                                       blk_is_read_only(s->qdev.conf.blk),
> +
> +    read_only = blk_is_read_only(s->qdev.conf.blk);
> +    if (dev->type == TYPE_ROM) {
> +        read_only = true;
> +    }

Is there a reason to check blk_is_read_only even for CD-ROM?
If not, why not make it a "else"?

> +
> +    if (!blkconf_apply_backend_options(&dev->conf, read_only,
>                                         dev->type == TYPE_DISK, errp)) {
>          return;
>      }


--
Cheers,
Christophe de Dinechin (IRC c3d)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]