[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH RFC v2 1/4] block: refactor bdrv_next_node for r
From: |
Stefan Hajnoczi |
Subject: |
Re: [Qemu-devel] [PATCH RFC v2 1/4] block: refactor bdrv_next_node for readability |
Date: |
Mon, 19 Dec 2016 14:19:38 +0000 |
User-agent: |
Mutt/1.7.1 (2016-10-04) |
On Mon, Dec 19, 2016 at 04:51:23PM +0800, Dou Liyang wrote:
> make the bdrv_next_node() clearly and add some comments.
>
> Signed-off-by: Dou Liyang <address@hidden>
> ---
> block.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/block.c b/block.c
> index 39ddea3..01c9e51 100644
> --- a/block.c
> +++ b/block.c
> @@ -2931,12 +2931,20 @@ bool bdrv_chain_contains(BlockDriverState *top,
> BlockDriverState *base)
> return top != NULL;
> }
>
> +/*
> + * Return the BlockDriverStates of all the named nodes.
This sentence describes how this function is used in a loop. The
semantics of one call to this function are different: only a *single*
named node's BlockDriverState is returned.
> + * If @bs is null, return the first one.
> + * Else, return @bs's next sibling, which may be null.
> + *
> + * To iterate over all BlockDriverStates, do
> + * for (bs = bdrv_next_node(NULL); bs; bs = bdrv_next_node(blk)) {
> + * ...
> + * }
> + */
> BlockDriverState *bdrv_next_node(BlockDriverState *bs)
> {
> - if (!bs) {
> - return QTAILQ_FIRST(&graph_bdrv_states);
> - }
> - return QTAILQ_NEXT(bs, node_list);
> + return bs ? QTAILQ_NEXT(bs, node_list)
> + : QTAILQ_FIRST(&graph_bdrv_states);
The conditional operator (?:) is often considered harder to read than an
if statement. I see no reason to modify the code.
signature.asc
Description: PGP signature
- [Qemu-devel] [PATCH RFC v2 0/4] block/qapi: refactor and optimize the qmp_query_blockstats(), Dou Liyang, 2016/12/19
- [Qemu-devel] [PATCH RFC v2 3/4] block/qapi: acquire a reference instead of a lock during querying blockstats, Dou Liyang, 2016/12/19
- [Qemu-devel] [PATCH RFC v2 2/4] block/qapi: reduce the coupling between the bdrv_query_stats and bdrv_query_bds_stats, Dou Liyang, 2016/12/19
- [Qemu-devel] [PATCH RFC v2 1/4] block: refactor bdrv_next_node for readability, Dou Liyang, 2016/12/19
- Re: [Qemu-devel] [PATCH RFC v2 1/4] block: refactor bdrv_next_node for readability,
Stefan Hajnoczi <=
- [Qemu-devel] [PATCH RFC v2 4/4] block/qapi: optimize the query function of the blockstats, Dou Liyang, 2016/12/19
- Re: [Qemu-devel] [PATCH RFC v2 0/4] block/qapi: refactor and optimize the qmp_query_blockstats(), Stefan Hajnoczi, 2016/12/19
- Re: [Qemu-devel] [PATCH RFC v2 0/4] block/qapi: refactor and optimize the qmp_query_blockstats(), Fam Zheng, 2016/12/19
- Re: [Qemu-devel] [PATCH RFC v2 0/4] block/qapi: refactor and optimize the qmp_query_blockstats(), Stefan Hajnoczi, 2016/12/20
- Re: [Qemu-devel] [PATCH RFC v2 0/4] block/qapi: refactor and optimize the qmp_query_blockstats(), Dou Liyang, 2016/12/20
- Re: [Qemu-devel] [PATCH RFC v2 0/4] block/qapi: refactor and optimize the qmp_query_blockstats(), Stefan Hajnoczi, 2016/12/20
- Re: [Qemu-devel] [PATCH RFC v2 0/4] block/qapi: refactor and optimize the qmp_query_blockstats(), Dou Liyang, 2016/12/20
- Re: [Qemu-devel] [PATCH RFC v2 0/4] block/qapi: refactor and optimize the qmp_query_blockstats(), Stefan Hajnoczi, 2016/12/20
- Re: [Qemu-devel] [PATCH RFC v2 0/4] block/qapi: refactor and optimize the qmp_query_blockstats(), Dou Liyang, 2016/12/21
- Re: [Qemu-devel] [PATCH RFC v2 0/4] block/qapi: refactor and optimize the qmp_query_blockstats(), Stefan Hajnoczi, 2016/12/21