From: Kevin Wolf <kwolf@redhat.com>
To: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 2/2] block: Convert bdrv_first to QTAILQ
Date: Fri, 09 Apr 2010 18:47:35 +0200 [thread overview]
Message-ID: <4BBF5A27.8090701@redhat.com> (raw)
In-Reply-To: <1270822934-8623-3-git-send-email-stefanha@linux.vnet.ibm.com>
Am 09.04.2010 16:22, schrieb Stefan Hajnoczi:
> Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
> ---
> block.c | 44 +++++++++++++++++++++++---------------------
> block_int.h | 3 ++-
> 2 files changed, 25 insertions(+), 22 deletions(-)
>
> diff --git a/block.c b/block.c
> index 61da183..86d2504 100644
> --- a/block.c
> +++ b/block.c
> @@ -55,7 +55,8 @@ static int bdrv_read_em(BlockDriverState *bs, int64_t sector_num,
> static int bdrv_write_em(BlockDriverState *bs, int64_t sector_num,
> const uint8_t *buf, int nb_sectors);
>
> -static BlockDriverState *bdrv_first;
> +static QTAILQ_HEAD(, BlockDriverState) bdrv_states =
> + QTAILQ_HEAD_INITIALIZER(bdrv_states);
>
> static BlockDriver *first_drv;
>
> @@ -148,16 +149,12 @@ void bdrv_register(BlockDriver *bdrv)
> /* create a new block device (by default it is empty) */
> BlockDriverState *bdrv_new(const char *device_name)
> {
> - BlockDriverState **pbs, *bs;
> + BlockDriverState *bs;
>
> bs = qemu_mallocz(sizeof(BlockDriverState));
> pstrcpy(bs->device_name, sizeof(bs->device_name), device_name);
> if (device_name[0] != '\0') {
> - /* insert at the end */
> - pbs = &bdrv_first;
> - while (*pbs != NULL)
> - pbs = &(*pbs)->next;
> - *pbs = bs;
> + QTAILQ_INSERT_TAIL(&bdrv_states, bs, list);
> }
> return bs;
> }
> @@ -545,13 +542,15 @@ void bdrv_close(BlockDriverState *bs)
>
> void bdrv_delete(BlockDriverState *bs)
> {
> - BlockDriverState **pbs;
> + BlockDriverState *bs1;
>
> - pbs = &bdrv_first;
> - while (*pbs != bs && *pbs != NULL)
> - pbs = &(*pbs)->next;
> - if (*pbs == bs)
> - *pbs = bs->next;
> + /* remove from list, if necessary */
> + QTAILQ_FOREACH(bs1, &bdrv_states, list) {
> + if (bs1 == bs) {
> + QTAILQ_REMOVE(&bdrv_states, bs, list);
> + break;
> + }
> + }
This loop looks strange, what is it used for? We had only a next pointer
previously, so we needed to search the element. A QTAILQ has both prev
and next pointers though, so you should be able to directly use
QTAILQ_REMOVE.
The rest of it looks good.
Kevin
next prev parent reply other threads:[~2010-04-09 16:48 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-04-09 14:22 [Qemu-devel] [PATCH 0/2] block: Cleanups Stefan Hajnoczi
2010-04-09 14:22 ` [Qemu-devel] [PATCH 1/2] block: Do not export bdrv_first Stefan Hajnoczi
2010-04-09 16:50 ` Kevin Wolf
2010-04-09 14:22 ` [Qemu-devel] [PATCH 2/2] block: Convert bdrv_first to QTAILQ Stefan Hajnoczi
2010-04-09 16:47 ` Kevin Wolf [this message]
2010-04-09 18:17 ` Stefan Hajnoczi
2010-04-10 6:04 ` Stefan Hajnoczi
2010-04-10 7:56 ` Kevin Wolf
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=4BBF5A27.8090701@redhat.com \
--to=kwolf@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@linux.vnet.ibm.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).