[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [RFC PATCH 2/4] hw/scsi/scsi-disk: Use automatic AIO context lock
From: |
Dr. David Alan Gilbert |
Subject: |
Re: [RFC PATCH 2/4] hw/scsi/scsi-disk: Use automatic AIO context lock |
Date: |
Wed, 6 Oct 2021 17:51:44 +0100 |
User-agent: |
Mutt/2.0.7 (2021-05-04) |
* Philippe Mathieu-Daudé (philmd@redhat.com) wrote:
> Use the automatic AIO context acquire/release in scsi_block_realize().
>
> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
I'll let the AIO people reply more thoroughly to this; but this patch is
the case I really like this mechanism for; removing the need for the
goto's and cleanup.
Dave
> ---
> hw/scsi/scsi-disk.c | 13 ++++---------
> 1 file changed, 4 insertions(+), 9 deletions(-)
>
> diff --git a/hw/scsi/scsi-disk.c b/hw/scsi/scsi-disk.c
> index e8a547dbb7d..fa2d8543718 100644
> --- a/hw/scsi/scsi-disk.c
> +++ b/hw/scsi/scsi-disk.c
> @@ -2605,7 +2605,6 @@ static int get_device_type(SCSIDiskState *s)
> static void scsi_block_realize(SCSIDevice *dev, Error **errp)
> {
> SCSIDiskState *s = DO_UPCAST(SCSIDiskState, qdev, dev);
> - AioContext *ctx;
> int sg_version;
> int rc;
>
> @@ -2620,8 +2619,7 @@ static void scsi_block_realize(SCSIDevice *dev, Error
> **errp)
> "be removed in a future version");
> }
>
> - ctx = blk_get_aio_context(s->qdev.conf.blk);
> - aio_context_acquire(ctx);
> + AIO_CONTEXT_ACQUIRE_GUARD(blk_get_aio_context(dev->conf.blk));
>
> /* check we are using a driver managing SG_IO (version 3 and after) */
> rc = blk_ioctl(s->qdev.conf.blk, SG_GET_VERSION_NUM, &sg_version);
> @@ -2630,18 +2628,18 @@ static void scsi_block_realize(SCSIDevice *dev, Error
> **errp)
> if (rc != -EPERM) {
> error_append_hint(errp, "Is this a SCSI device?\n");
> }
> - goto out;
> + return;
> }
> if (sg_version < 30000) {
> error_setg(errp, "scsi generic interface too old");
> - goto out;
> + return;
> }
>
> /* get device type from INQUIRY data */
> rc = get_device_type(s);
> if (rc < 0) {
> error_setg(errp, "INQUIRY failed");
> - goto out;
> + return;
> }
>
> /* Make a guess for the block size, we'll fix it when the guest sends.
> @@ -2661,9 +2659,6 @@ static void scsi_block_realize(SCSIDevice *dev, Error
> **errp)
>
> scsi_realize(&s->qdev, errp);
> scsi_generic_read_device_inquiry(&s->qdev);
> -
> -out:
> - aio_context_release(ctx);
> }
>
> typedef struct SCSIBlockReq {
> --
> 2.31.1
>
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK
- [RFC PATCH 0/4] aio: AIO_CONTEXT_ACQUIRE_GUARD() macro experiment, Philippe Mathieu-Daudé, 2021/10/05
- [RFC PATCH 1/4] block/aio: Add automatically released aio_context variants, Philippe Mathieu-Daudé, 2021/10/05
- [RFC PATCH 2/4] hw/scsi/scsi-disk: Use automatic AIO context lock, Philippe Mathieu-Daudé, 2021/10/05
- Re: [RFC PATCH 2/4] hw/scsi/scsi-disk: Use automatic AIO context lock,
Dr. David Alan Gilbert <=
- [RFC PATCH 3/4] hw/scsi/scsi-generic: Use automatic AIO context lock, Philippe Mathieu-Daudé, 2021/10/05
- [RFC PATCH 4/4] hw/block/virtio-blk: Use automatic AIO context lock, Philippe Mathieu-Daudé, 2021/10/05
- Re: [RFC PATCH 0/4] aio: AIO_CONTEXT_ACQUIRE_GUARD() macro experiment, Stefan Hajnoczi, 2021/10/07