All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Lieven <pl@kamp.de>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, ronniesahlberg@gmail.com, stefanha@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3 01/19] block: generalize BlockLimits handling to cover bdrv_aio_discard too
Date: Mon, 25 Nov 2013 10:09:29 +0100	[thread overview]
Message-ID: <529313C9.5000609@kamp.de> (raw)
In-Reply-To: <1385124001-3576-2-git-send-email-pbonzini@redhat.com>

On 22.11.2013 13:39, Paolo Bonzini wrote:
> bdrv_co_discard is only covering drivers which have a .bdrv_co_discard()
> implementation, but not those with .bdrv_aio_discard(). Not very nice,
> and easy to avoid.
>
> Suggested-by: Kevin Wolf <kwolf@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
>   block.c | 80 +++++++++++++++++++++++++++++++++--------------------------------
>   1 file changed, 41 insertions(+), 39 deletions(-)
>
> diff --git a/block.c b/block.c
> index e22b55f..1b3e8b2 100644
> --- a/block.c
> +++ b/block.c
> @@ -4288,6 +4288,8 @@ static void coroutine_fn bdrv_discard_co_entry(void *opaque)
>   int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
>                                    int nb_sectors)
>   {
> +    int max_discard;
> +
>       if (!bs->drv) {
>           return -ENOMEDIUM;
>       } else if (bdrv_check_request(bs, sector_num, nb_sectors)) {
> @@ -4305,55 +4307,55 @@ int coroutine_fn bdrv_co_discard(BlockDriverState *bs, int64_t sector_num,
>           return 0;
>       }
>   
> -    if (bs->drv->bdrv_co_discard) {
> -        int max_discard = bs->bl.max_discard ?
> -                          bs->bl.max_discard : MAX_DISCARD_DEFAULT;
> +    if (!bs->drv->bdrv_co_discard && !bs->drv->bdrv_aio_discard) {
> +        return 0;
> +    }
>   
> -        while (nb_sectors > 0) {
> -            int ret;
> -            int num = nb_sectors;
> +    max_discard = bs->bl.max_discard ?  bs->bl.max_discard : MAX_DISCARD_DEFAULT;
> +    while (nb_sectors > 0) {
> +        int ret;
> +        int num = nb_sectors;
>   
> -            /* align request */
> -            if (bs->bl.discard_alignment &&
> -                num >= bs->bl.discard_alignment &&
> -                sector_num % bs->bl.discard_alignment) {
> -                if (num > bs->bl.discard_alignment) {
> -                    num = bs->bl.discard_alignment;
> -                }
> -                num -= sector_num % bs->bl.discard_alignment;
> +        /* align request */
> +        if (bs->bl.discard_alignment &&
> +            num >= bs->bl.discard_alignment &&
> +            sector_num % bs->bl.discard_alignment) {
> +            if (num > bs->bl.discard_alignment) {
> +                num = bs->bl.discard_alignment;
>               }
> +            num -= sector_num % bs->bl.discard_alignment;
> +        }
>   
> -            /* limit request size */
> -            if (num > max_discard) {
> -                num = max_discard;
> -            }
> +        /* limit request size */
> +        if (num > max_discard) {
> +            num = max_discard;
> +        }
>   
> +        if (bs->drv->bdrv_co_discard) {
>               ret = bs->drv->bdrv_co_discard(bs, sector_num, num);
> -            if (ret) {
> -                return ret;
> +        } else {
> +            BlockDriverAIOCB *acb;
> +            CoroutineIOCompletion co = {
> +                .coroutine = qemu_coroutine_self(),
> +            };
> +
> +            acb = bs->drv->bdrv_aio_discard(bs, sector_num, nb_sectors,
> +                                            bdrv_co_io_em_complete, &co);
> +            if (acb == NULL) {
> +                return -EIO;
> +            } else {
> +                qemu_coroutine_yield();
> +                ret = co.ret;
>               }
> -
> -            sector_num += num;
> -            nb_sectors -= num;
>           }
> -        return 0;
> -    } else if (bs->drv->bdrv_aio_discard) {
> -        BlockDriverAIOCB *acb;
> -        CoroutineIOCompletion co = {
> -            .coroutine = qemu_coroutine_self(),
> -        };
> -
> -        acb = bs->drv->bdrv_aio_discard(bs, sector_num, nb_sectors,
> -                                        bdrv_co_io_em_complete, &co);
> -        if (acb == NULL) {
> -            return -EIO;
> -        } else {
> -            qemu_coroutine_yield();
> -            return co.ret;
> +        if (ret) {
> +            return ret;
>           }
> -    } else {
> -        return 0;
> +
> +        sector_num += num;
> +        nb_sectors -= num;
>       }
> +    return 0;
>   }
>   
>   int bdrv_discard(BlockDriverState *bs, int64_t sector_num, int nb_sectors)
Reviewed-by: Peter Lieven <pl@kamp.de>

  reply	other threads:[~2013-11-25  9:09 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-22 12:39 [Qemu-devel] [PATCH v3 00/19] block & scsi: write_zeroes support through the whole stack Paolo Bonzini
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 01/19] block: generalize BlockLimits handling to cover bdrv_aio_discard too Paolo Bonzini
2013-11-25  9:09   ` Peter Lieven [this message]
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 02/19] block: add flags to BlockRequest Paolo Bonzini
2013-11-25  9:11   ` Peter Lieven
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 03/19] block: add flags argument to bdrv_co_write_zeroes tracepoint Paolo Bonzini
2013-11-25  9:12   ` Peter Lieven
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 04/19] block: add bdrv_aio_write_zeroes Paolo Bonzini
2013-11-25  9:13   ` Peter Lieven
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 05/19] block: handle ENOTSUP from discard in generic code Paolo Bonzini
2013-11-25 10:06   ` Peter Lieven
2013-11-25 10:16     ` Paolo Bonzini
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 06/19] block: make bdrv_co_do_write_zeroes stricter in producing aligned requests Paolo Bonzini
2013-11-25 10:23   ` Peter Lieven
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 07/19] vpc, vhdx: add get_info Paolo Bonzini
2013-11-25 10:27   ` Peter Lieven
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 08/19] block drivers: add discard/write_zeroes properties to bdrv_get_info implementation Paolo Bonzini
2013-11-25 10:29   ` Peter Lieven
2013-12-03 15:09   ` Kevin Wolf
2013-12-03 15:21     ` Paolo Bonzini
2013-12-03 17:10       ` Peter Lieven
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 09/19] block drivers: expose requirement for write same alignment from formats Paolo Bonzini
2013-11-25 10:33   ` Peter Lieven
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 10/19] block/iscsi: remove .bdrv_has_zero_init Paolo Bonzini
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 11/19] block/iscsi: updated copyright Paolo Bonzini
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 12/19] block/iscsi: check WRITE SAME support differently depending on MAY_UNMAP Paolo Bonzini
2013-11-25 10:34   ` Peter Lieven
2013-11-25 10:42     ` Paolo Bonzini
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 13/19] raw-posix: implement write_zeroes with MAY_UNMAP for files Paolo Bonzini
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 14/19] raw-posix: implement write_zeroes with MAY_UNMAP for block devices Paolo Bonzini
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 15/19] raw-posix: add support for write_zeroes on XFS and " Paolo Bonzini
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 16/19] qemu-iotests: 033 is fast Paolo Bonzini
2013-11-22 12:39 ` [Qemu-devel] [PATCH v3 17/19] scsi-disk: catch write protection errors in UNMAP Paolo Bonzini
2013-11-22 12:40 ` [Qemu-devel] [PATCH v3 18/19] scsi-disk: reject ANCHOR=1 for UNMAP and WRITE SAME commands Paolo Bonzini
2013-11-22 12:40 ` [Qemu-devel] [PATCH v3 19/19] scsi-disk: correctly implement WRITE SAME Paolo Bonzini
2013-12-03 14:29 ` [Qemu-devel] [PATCH v3 00/19] block & scsi: write_zeroes support through the whole stack Stefan Hajnoczi

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=529313C9.5000609@kamp.de \
    --to=pl@kamp.de \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --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.