[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH v5 03/10] block: simplify bdrv_find_base() and b
From: |
Benoît Canet |
Subject: |
Re: [Qemu-devel] [PATCH v5 03/10] block: simplify bdrv_find_base() and bdrv_find_overlay() |
Date: |
Mon, 16 Jun 2014 16:25:51 +0200 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
The Friday 13 Jun 2014 à 14:52:31 (-0400), Jeff Cody wrote :
> This simplifies the function bdrv_find_overlay(). With this change,
> bdrv_find_base() is just a subset of usage of bdrv_find_overlay(),
> so this also takes advantage of that.
>
> Reviewed-by: Eric Blake <address@hidden>
> Signed-off-by: Jeff Cody <address@hidden>
> ---
> block.c | 45 ++++++++++-----------------------------------
> 1 file changed, 10 insertions(+), 35 deletions(-)
>
> diff --git a/block.c b/block.c
> index f9ea1b4..83996e3 100644
> --- a/block.c
> +++ b/block.c
> @@ -2569,32 +2569,23 @@ int bdrv_change_backing_file(BlockDriverState *bs,
> *
> * Returns NULL if bs is not found in active's image chain,
> * or if active == bs.
> + *
> + * Returns the bottommost base image if bs == NULL.
> */
> BlockDriverState *bdrv_find_overlay(BlockDriverState *active,
> BlockDriverState *bs)
> {
> - BlockDriverState *overlay = NULL;
> - BlockDriverState *intermediate;
> -
> - assert(active != NULL);
> - assert(bs != NULL);
> -
> - /* if bs is the same as active, then by definition it has no overlay
> - */
> - if (active == bs) {
> - return NULL;
> + while (active && bs != active->backing_hd) {
> + active = active->backing_hd;
> }
>
> - intermediate = active;
> - while (intermediate->backing_hd) {
> - if (intermediate->backing_hd == bs) {
> - overlay = intermediate;
> - break;
> - }
> - intermediate = intermediate->backing_hd;
> - }
> + return active;
> +}
>
> - return overlay;
> +/* Given a BDS, searches for the base layer. */
> +BlockDriverState *bdrv_find_base(BlockDriverState *bs)
> +{
> + return bdrv_find_overlay(bs, NULL);
> }
>
> typedef struct BlkIntermediateStates {
> @@ -4376,22 +4367,6 @@ int bdrv_get_backing_file_depth(BlockDriverState *bs)
> return 1 + bdrv_get_backing_file_depth(bs->backing_hd);
> }
>
> -BlockDriverState *bdrv_find_base(BlockDriverState *bs)
> -{
> - BlockDriverState *curr_bs = NULL;
> -
> - if (!bs) {
> - return NULL;
> - }
> -
> - curr_bs = bs;
> -
> - while (curr_bs->backing_hd) {
> - curr_bs = curr_bs->backing_hd;
> - }
> - return curr_bs;
> -}
> -
> /**************************************************************/
> /* async I/Os */
>
> --
> 1.8.3.1
>
>
That is a neat simplification.
Reviewed-by: Benoit Canet <address@hidden>
- [Qemu-devel] [PATCH v5 00/10] Modify block jobs to use node-names, Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 01/10] block: Auto-generate node_names for each BDS entry, Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 02/10] block: add helper function to determine if a BDS is in a chain, Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 03/10] block: simplify bdrv_find_base() and bdrv_find_overlay(), Jeff Cody, 2014/06/13
- Re: [Qemu-devel] [PATCH v5 03/10] block: simplify bdrv_find_base() and bdrv_find_overlay(),
Benoît Canet <=
- [Qemu-devel] [PATCH v5 04/10] block: make 'top' argument to block-commit optional, Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 06/10] block: extend block-commit to accept a string for the backing file, Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 05/10] block: Accept node-name arguments for block-commit, Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 07/10] block: add ability for block-stream to use node-name, Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 08/10] block: add backing-file option to block-stream, Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 09/10] block: Add QMP documentation for block-stream, Jeff Cody, 2014/06/13
- [Qemu-devel] [PATCH v5 10/10] block: add QAPI command to allow live backing file change, Jeff Cody, 2014/06/13
- Re: [Qemu-devel] [PATCH v5 00/10] Modify block jobs to use node-names, Eric Blake, 2014/06/17