From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42145) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5Rjo-0003AW-L1 for qemu-devel@nongnu.org; Mon, 20 Jan 2014 22:10:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W5Rjh-0007HC-1v for qemu-devel@nongnu.org; Mon, 20 Jan 2014 22:10:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:25292) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5Rjg-0007Go-PC for qemu-devel@nongnu.org; Mon, 20 Jan 2014 22:10:44 -0500 Date: Tue, 21 Jan 2014 11:10:34 +0800 From: Fam Zheng Message-ID: <20140121031034.GD29842@T430.redhat.com> References: <1386862440-8003-1-git-send-email-benoit@irqsave.net> <1386862440-8003-2-git-send-email-benoit@irqsave.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1386862440-8003-2-git-send-email-benoit@irqsave.net> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH V5 1/7] block: Add bs->node_name to hold the name of a bs node of the bs graph. List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: =?iso-8859-1?Q?Beno=EEt?= Canet Cc: kwolf@redhat.com, jcody@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, armbru@redhat.com On Thu, 12/12 16:33, Beno=EEt Canet wrote: > Add the minimum of code to prepare for the following patches. >=20 > Signed-off-by: Benoit Canet > --- > block.c | 57 +++++++++++++++++++++++++++++++++++----= -------- > include/block/block.h | 1 + > include/block/block_int.h | 9 +++++++- > 3 files changed, 52 insertions(+), 15 deletions(-) >=20 > diff --git a/block.c b/block.c > index 64e7d22..481d566 100644 > --- a/block.c > +++ b/block.c > @@ -90,6 +90,9 @@ static int coroutine_fn bdrv_co_do_write_zeroes(Block= DriverState *bs, > static QTAILQ_HEAD(, BlockDriverState) bdrv_states =3D > QTAILQ_HEAD_INITIALIZER(bdrv_states); > =20 > +static QTAILQ_HEAD(, BlockDriverState) graph_bdrv_states =3D > + QTAILQ_HEAD_INITIALIZER(graph_bdrv_states); > + > static QLIST_HEAD(, BlockDriver) bdrv_drivers =3D > QLIST_HEAD_INITIALIZER(bdrv_drivers); > =20 > @@ -327,7 +330,7 @@ BlockDriverState *bdrv_new(const char *device_name) > QLIST_INIT(&bs->dirty_bitmaps); > pstrcpy(bs->device_name, sizeof(bs->device_name), device_name); > if (device_name[0] !=3D '\0') { > - QTAILQ_INSERT_TAIL(&bdrv_states, bs, list); > + QTAILQ_INSERT_TAIL(&bdrv_states, bs, device_list); > } > bdrv_iostatus_disable(bs); > notifier_list_init(&bs->close_notifiers); > @@ -1501,7 +1504,7 @@ void bdrv_close_all(void) > { > BlockDriverState *bs; > =20 > - QTAILQ_FOREACH(bs, &bdrv_states, list) { > + QTAILQ_FOREACH(bs, &bdrv_states, device_list) { > bdrv_close(bs); > } > } > @@ -1530,7 +1533,7 @@ static bool bdrv_requests_pending(BlockDriverStat= e *bs) > static bool bdrv_requests_pending_all(void) > { > BlockDriverState *bs; > - QTAILQ_FOREACH(bs, &bdrv_states, list) { > + QTAILQ_FOREACH(bs, &bdrv_states, device_list) { > if (bdrv_requests_pending(bs)) { > return true; > } > @@ -1557,7 +1560,7 @@ void bdrv_drain_all(void) > BlockDriverState *bs; > =20 > while (busy) { > - QTAILQ_FOREACH(bs, &bdrv_states, list) { > + QTAILQ_FOREACH(bs, &bdrv_states, device_list) { > bdrv_start_throttled_reqs(bs); > } > =20 > @@ -1566,14 +1569,19 @@ void bdrv_drain_all(void) > } > } > =20 > -/* make a BlockDriverState anonymous by removing from bdrv_state list. > +/* make a BlockDriverState anonymous by removing from bdrv_state and > + * graph_bdrv_state list. > Also, NULL terminate the device_name to prevent double remove */ > void bdrv_make_anon(BlockDriverState *bs) > { > if (bs->device_name[0] !=3D '\0') { > - QTAILQ_REMOVE(&bdrv_states, bs, list); > + QTAILQ_REMOVE(&bdrv_states, bs, device_list); > } > bs->device_name[0] =3D '\0'; > + if (bs->node_name[0] !=3D '\0') { > + QTAILQ_REMOVE(&graph_bdrv_states, bs, node_list); > + } > + bs->node_name[0] =3D '\0'; > } > =20 > static void bdrv_rebind(BlockDriverState *bs) > @@ -1627,7 +1635,12 @@ static void bdrv_move_feature_fields(BlockDriver= State *bs_dest, > /* keep the same entry in bdrv_states */ > pstrcpy(bs_dest->device_name, sizeof(bs_dest->device_name), > bs_src->device_name); > - bs_dest->list =3D bs_src->list; > + bs_dest->device_list =3D bs_src->device_list; > + > + /* keep the same entry in graph_bdrv_states > + * We do want to swap name but don't want to swap linked list entr= ies > + */ > + bs_dest->node_list =3D bs_src->node_list; > } > =20 > /* > @@ -1952,7 +1965,7 @@ int bdrv_commit_all(void) > { > BlockDriverState *bs; > =20 > - QTAILQ_FOREACH(bs, &bdrv_states, list) { > + QTAILQ_FOREACH(bs, &bdrv_states, device_list) { > if (bs->drv && bs->backing_hd) { > int ret =3D bdrv_commit(bs); > if (ret < 0) { > @@ -3110,11 +3123,12 @@ void bdrv_iterate_format(void (*it)(void *opaqu= e, const char *name), > } > } > =20 > +/* This function is to find block backend bs */ > BlockDriverState *bdrv_find(const char *name) > { > BlockDriverState *bs; > =20 > - QTAILQ_FOREACH(bs, &bdrv_states, list) { > + QTAILQ_FOREACH(bs, &bdrv_states, device_list) { > if (!strcmp(name, bs->device_name)) { > return bs; > } > @@ -3122,19 +3136,34 @@ BlockDriverState *bdrv_find(const char *name) > return NULL; > } > =20 > +/* This function is to find a node in the bs graph */ > +BlockDriverState *bdrv_find_node(const char *node_name) > +{ > + BlockDriverState *bs; > + > + assert(node_name); > + > + QTAILQ_FOREACH(bs, &graph_bdrv_states, node_list) { > + if (!strcmp(node_name, bs->node_name)) { > + return bs; > + } > + } > + return NULL; > +} > + > BlockDriverState *bdrv_next(BlockDriverState *bs) > { > if (!bs) { > return QTAILQ_FIRST(&bdrv_states); > } > - return QTAILQ_NEXT(bs, list); > + return QTAILQ_NEXT(bs, device_list); > } > =20 > void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs), void= *opaque) > { > BlockDriverState *bs; > =20 > - QTAILQ_FOREACH(bs, &bdrv_states, list) { > + QTAILQ_FOREACH(bs, &bdrv_states, device_list) { > it(opaque, bs); > } > } > @@ -3154,7 +3183,7 @@ int bdrv_flush_all(void) > BlockDriverState *bs; > int result =3D 0; > =20 > - QTAILQ_FOREACH(bs, &bdrv_states, list) { > + QTAILQ_FOREACH(bs, &bdrv_states, device_list) { > int ret =3D bdrv_flush(bs); > if (ret < 0 && !result) { > result =3D ret; > @@ -4278,7 +4307,7 @@ void bdrv_invalidate_cache_all(void) > { > BlockDriverState *bs; > =20 > - QTAILQ_FOREACH(bs, &bdrv_states, list) { > + QTAILQ_FOREACH(bs, &bdrv_states, device_list) { > bdrv_invalidate_cache(bs); > } > } > @@ -4287,7 +4316,7 @@ void bdrv_clear_incoming_migration_all(void) > { > BlockDriverState *bs; > =20 > - QTAILQ_FOREACH(bs, &bdrv_states, list) { > + QTAILQ_FOREACH(bs, &bdrv_states, device_list) { > bs->open_flags =3D bs->open_flags & ~(BDRV_O_INCOMING); > } > } > diff --git a/include/block/block.h b/include/block/block.h > index 36efaea..834abf9 100644 > --- a/include/block/block.h > +++ b/include/block/block.h > @@ -374,6 +374,7 @@ void bdrv_lock_medium(BlockDriverState *bs, bool lo= cked); > void bdrv_eject(BlockDriverState *bs, bool eject_flag); > const char *bdrv_get_format_name(BlockDriverState *bs); > BlockDriverState *bdrv_find(const char *name); > +BlockDriverState *bdrv_find_node(const char *node_name); > BlockDriverState *bdrv_next(BlockDriverState *bs); > void bdrv_iterate(void (*it)(void *opaque, BlockDriverState *bs), > void *opaque); > diff --git a/include/block/block_int.h b/include/block/block_int.h > index 8b132d7..bd5220f 100644 > --- a/include/block/block_int.h > +++ b/include/block/block_int.h > @@ -325,11 +325,18 @@ struct BlockDriverState { > BlockdevOnError on_read_error, on_write_error; > bool iostatus_enabled; > BlockDeviceIoStatus iostatus; > + > + /* the following member gives a name to every node on the bs graph= . */ > + char node_name[32]; > + /* element of the list of named nodes building the graph */ > + QTAILQ_ENTRY(BlockDriverState) node_list; > + /* Device name is the name associated with the "drive" the guest s= ees */ > char device_name[32]; > + /* element of the list of "drives" the guest sees */ > + QTAILQ_ENTRY(BlockDriverState) device_list; > QLIST_HEAD(, BdrvDirtyBitmap) dirty_bitmaps; > int refcnt; > int in_use; /* users other than guest access, eg. block migration = */ > - QTAILQ_ENTRY(BlockDriverState) list; > =20 > QLIST_HEAD(, BdrvTrackedRequest) tracked_requests; > =20 > --=20 > 1.8.3.2 >=20 >=20 Reviewed-by: Fam Zheng