From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46690) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VeWat-0002m9-ST for qemu-devel@nongnu.org; Thu, 07 Nov 2013 15:54:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VeWao-0006ZS-O7 for qemu-devel@nongnu.org; Thu, 07 Nov 2013 15:54:23 -0500 Received: from mx1.redhat.com ([209.132.183.28]:20161) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VeWao-0006YO-D7 for qemu-devel@nongnu.org; Thu, 07 Nov 2013 15:54:18 -0500 Date: Thu, 7 Nov 2013 15:54:09 -0500 From: Jeff Cody Message-ID: <20131107205409.GA19612@localhost.localdomain> References: <1383836503-25447-1-git-send-email-benoit@irqsave.net> <1383836503-25447-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: <1383836503-25447-2-git-send-email-benoit@irqsave.net> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH 1/2] 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, famz@redhat.com, qemu-devel@nongnu.org, stefanha@redhat.com, armbru@redhat.com On Thu, Nov 07, 2013 at 04:01:42PM +0100, Beno=EEt Canet wrote: > Add the minimum of code to prepare the followings patches. >=20 > If no node_name is provided to bdrv_new the bs->node_name is set to "un= defined". > This will allow to have some default string to communicate in QMP and H= MP. > This also make "undefined" a reserved string for bs->node_name. Hi Beno=EEt, Is it necessary to have a reserved string, or would an empty null-terminated string be able to implicitly denote the name as undefined? >=20 > Signed-off-by: Benoit Canet > --- > block.c | 70 +++++++++++++++++++++++++++++++++++----= -------- > block/blkverify.c | 2 +- > block/iscsi.c | 2 +- > block/vmdk.c | 2 +- > block/vvfat.c | 4 +-- > blockdev.c | 8 +++--- > hw/block/xen_disk.c | 2 +- > include/block/block.h | 3 +- > include/block/block_int.h | 9 +++++- > qemu-img.c | 6 ++-- > qemu-io.c | 2 +- > qemu-nbd.c | 2 +- > 12 files changed, 77 insertions(+), 35 deletions(-) >=20 > diff --git a/block.c b/block.c > index fd05a80..230e71a 100644 > --- a/block.c > +++ b/block.c > @@ -89,6 +89,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 > @@ -318,14 +321,26 @@ void bdrv_register(BlockDriver *bdrv) > } > =20 > /* create a new block device (by default it is empty) */ > -BlockDriverState *bdrv_new(const char *device_name) > +BlockDriverState *bdrv_new(const char *device_name, const char *node_n= ame) > { > BlockDriverState *bs; > =20 > bs =3D g_malloc0(sizeof(BlockDriverState)); > 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); > + } > + /* if node name is given store it in bs and insert bs in the graph= bs list > + * note: undefined is a reserved node name > + */ > + if (node_name && > + node_name[0] !=3D '\0' && > + strcmp(node_name, "undefined")) { > + pstrcpy(bs->node_name, sizeof(bs->node_name), node_name); > + QTAILQ_INSERT_TAIL(&graph_bdrv_states, bs, node_list); > + /* else set the bs node name to undefined for QMP and HMP */ > + } else { > + sprintf(bs->node_name, "undefined"); > } > bdrv_iostatus_disable(bs); > notifier_list_init(&bs->close_notifiers); > @@ -870,7 +885,7 @@ int bdrv_file_open(BlockDriverState **pbs, const ch= ar *filename, > options =3D qdict_new(); > } > =20 > - bs =3D bdrv_new(""); > + bs =3D bdrv_new("", NULL); > bs->options =3D options; > options =3D qdict_clone_shallow(options); > =20 > @@ -992,7 +1007,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, Q= Dict *options, Error **errp) > sizeof(backing_filename)); > } > =20 > - bs->backing_hd =3D bdrv_new(""); > + bs->backing_hd =3D bdrv_new("", NULL); > =20 > if (bs->backing_format[0] !=3D '\0') { > back_drv =3D bdrv_find_format(bs->backing_format); > @@ -1062,7 +1077,7 @@ int bdrv_open(BlockDriverState *bs, const char *f= ilename, QDict *options, > instead of opening 'filename' directly */ > =20 > /* if there is a backing file, use it */ > - bs1 =3D bdrv_new(""); > + bs1 =3D bdrv_new("", NULL); > ret =3D bdrv_open(bs1, filename, NULL, 0, drv, &local_err); > if (ret < 0) { > bdrv_unref(bs1); > @@ -1495,7 +1510,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); > } > } > @@ -1524,7 +1539,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; > } > @@ -1554,7 +1569,7 @@ void bdrv_drain_all(void) > /* FIXME: We do not have timer support here, so this is effect= ively > * a busy wait. > */ > - QTAILQ_FOREACH(bs, &bdrv_states, list) { > + QTAILQ_FOREACH(bs, &bdrv_states, device_list) { > if (bdrv_start_throttled_reqs(bs)) { > busy =3D true; > } > @@ -1570,7 +1585,7 @@ void bdrv_drain_all(void) > 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'; Do you need to do anything here to remove the BDS from your graph list? e.g. QTAILQ_REMOVE(&graph_bdrv_states, bs, node_list) > } > @@ -1626,7 +1641,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 */ > + pstrcpy(bs_dest->node_name, sizeof(bs_dest->node_name), > + bs_src->node_name); > + bs_dest->node_list =3D bs_src->node_list; > } > =20 > /* > @@ -1950,7 +1970,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) { > @@ -3017,11 +3037,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; > } > @@ -3029,19 +3050,32 @@ 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; > + > + 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); > } > } > @@ -3061,7 +3095,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; > @@ -4127,7 +4161,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); > } > } > @@ -4136,7 +4170,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); > } > } > @@ -4582,7 +4616,7 @@ void bdrv_img_create(const char *filename, const = char *fmt, > back_flags =3D > flags & ~(BDRV_O_RDWR | BDRV_O_SNAPSHOT | BDRV_O_NO_BA= CKING); > =20 > - bs =3D bdrv_new(""); > + bs =3D bdrv_new("", NULL); > =20 > ret =3D bdrv_open(bs, backing_file->value.s, NULL, back_fl= ags, > backing_drv, &local_err); > diff --git a/block/blkverify.c b/block/blkverify.c > index 55819a0..674b6a5 100644 > --- a/block/blkverify.c > +++ b/block/blkverify.c > @@ -155,7 +155,7 @@ static int blkverify_open(BlockDriverState *bs, QDi= ct *options, int flags, > goto fail; > } > =20 > - s->test_file =3D bdrv_new(""); > + s->test_file =3D bdrv_new("", NULL); > ret =3D bdrv_open(s->test_file, filename, NULL, flags, NULL, &loca= l_err); > if (ret < 0) { > error_propagate(errp, local_err); > diff --git a/block/iscsi.c b/block/iscsi.c > index a2a961e..5031593 100644 > --- a/block/iscsi.c > +++ b/block/iscsi.c > @@ -1461,7 +1461,7 @@ static int iscsi_create(const char *filename, QEM= UOptionParameter *options, > IscsiLun *iscsilun =3D NULL; > QDict *bs_options; > =20 > - bs =3D bdrv_new(""); > + bs =3D bdrv_new("", NULL); > =20 > /* Read out options */ > while (options && options->name) { > diff --git a/block/vmdk.c b/block/vmdk.c > index 32ec8b77..97801c2 100644 > --- a/block/vmdk.c > +++ b/block/vmdk.c > @@ -1672,7 +1672,7 @@ static int vmdk_create(const char *filename, QEMU= OptionParameter *options, > return -ENOTSUP; > } > if (backing_file) { > - BlockDriverState *bs =3D bdrv_new(""); > + BlockDriverState *bs =3D bdrv_new("", NULL); > ret =3D bdrv_open(bs, backing_file, NULL, 0, NULL, errp); > if (ret !=3D 0) { > bdrv_unref(bs); > diff --git a/block/vvfat.c b/block/vvfat.c > index 3ddaa0b..a8b6011 100644 > --- a/block/vvfat.c > +++ b/block/vvfat.c > @@ -2935,7 +2935,7 @@ static int enable_write_target(BDRVVVFATState *s) > goto err; > } > =20 > - s->qcow =3D bdrv_new(""); > + s->qcow =3D bdrv_new("", NULL); > =20 > ret =3D bdrv_open(s->qcow, s->qcow_filename, NULL, > BDRV_O_RDWR | BDRV_O_CACHE_WB | BDRV_O_NO_FLUSH, bdrv_qcow= , > @@ -2951,7 +2951,7 @@ static int enable_write_target(BDRVVVFATState *s) > unlink(s->qcow_filename); > #endif > =20 > - s->bs->backing_hd =3D bdrv_new(""); > + s->bs->backing_hd =3D bdrv_new("", NULL); > s->bs->backing_hd->drv =3D &vvfat_write_target; > s->bs->backing_hd->opaque =3D g_malloc(sizeof(void*)); > *(void**)s->bs->backing_hd->opaque =3D s; > diff --git a/blockdev.c b/blockdev.c > index b260477..ac47413 100644 > --- a/blockdev.c > +++ b/blockdev.c > @@ -469,7 +469,7 @@ static DriveInfo *blockdev_init(QDict *bs_opts, > /* init */ > dinfo =3D g_malloc0(sizeof(*dinfo)); > dinfo->id =3D g_strdup(qemu_opts_id(opts)); > - dinfo->bdrv =3D bdrv_new(dinfo->id); > + dinfo->bdrv =3D bdrv_new(dinfo->id, NULL); > dinfo->bdrv->open_flags =3D snapshot ? BDRV_O_SNAPSHOT : 0; > dinfo->bdrv->read_only =3D ro; > dinfo->type =3D type; > @@ -1254,7 +1254,7 @@ static void external_snapshot_prepare(BlkTransact= ionState *common, > } > =20 > /* We will manually add the backing_hd field to the bs later */ > - state->new_bs =3D bdrv_new(""); > + state->new_bs =3D bdrv_new("", NULL); > /* TODO Inherit bs->options or only take explicit options with an > * extended QMP command? */ > ret =3D bdrv_open(state->new_bs, new_image_file, NULL, > @@ -1921,7 +1921,7 @@ void qmp_drive_backup(const char *device, const c= har *target, > return; > } > =20 > - target_bs =3D bdrv_new(""); > + target_bs =3D bdrv_new("", NULL); > ret =3D bdrv_open(target_bs, target, NULL, flags, drv, &local_err)= ; > if (ret < 0) { > bdrv_unref(target_bs); > @@ -2055,7 +2055,7 @@ void qmp_drive_mirror(const char *device, const c= har *target, > /* Mirroring takes care of copy-on-write using the source's backin= g > * file. > */ > - target_bs =3D bdrv_new(""); > + target_bs =3D bdrv_new("", NULL); > ret =3D bdrv_open(target_bs, target, NULL, flags | BDRV_O_NO_BACKI= NG, drv, > &local_err); > if (ret < 0) { > diff --git a/hw/block/xen_disk.c b/hw/block/xen_disk.c > index 098f6c6..d89e025 100644 > --- a/hw/block/xen_disk.c > +++ b/hw/block/xen_disk.c > @@ -808,7 +808,7 @@ static int blk_connect(struct XenDevice *xendev) > if (!blkdev->dinfo) { > /* setup via xenbus -> create new block driver instance */ > xen_be_printf(&blkdev->xendev, 2, "create new bdrv (xenbus set= up)\n"); > - blkdev->bs =3D bdrv_new(blkdev->dev); > + blkdev->bs =3D bdrv_new(blkdev->dev, NULL); > if (blkdev->bs) { > Error *local_err =3D NULL; > BlockDriver *drv =3D bdrv_find_whitelisted_format(blkdev->= fileproto, > diff --git a/include/block/block.h b/include/block/block.h > index 3560deb..2d27bd9 100644 > --- a/include/block/block.h > +++ b/include/block/block.h > @@ -149,7 +149,7 @@ int bdrv_create(BlockDriver *drv, const char* filen= ame, > QEMUOptionParameter *options, Error **errp); > int bdrv_create_file(const char* filename, QEMUOptionParameter *option= s, > Error **errp); > -BlockDriverState *bdrv_new(const char *device_name); > +BlockDriverState *bdrv_new(const char *device_name, const char *node_n= ame); > void bdrv_make_anon(BlockDriverState *bs); > void bdrv_swap(BlockDriverState *bs_new, BlockDriverState *bs_old); > void bdrv_append(BlockDriverState *bs_new, BlockDriverState *bs_top); > @@ -339,6 +339,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 a48731d..9e44136 100644 > --- a/include/block/block_int.h > +++ b/include/block/block_int.h > @@ -297,11 +297,18 @@ struct BlockDriverState { > BlockdevOnError on_read_error, on_write_error; > bool iostatus_enabled; > BlockDeviceIoStatus iostatus; > + > + /* the following member give a name to every node on the BlockDriv= erState > + * graph. > + */ > + char node_name[32]; > + QTAILQ_ENTRY(BlockDriverState) node_list; > + /* Device name is the name associated with the "drive" the guest s= ee */ > char device_name[32]; > + QTAILQ_ENTRY(BlockDriverState) device_list; > HBitmap *dirty_bitmap; > int refcnt; > int in_use; /* users other than guest access, eg. block migration = */ > - QTAILQ_ENTRY(BlockDriverState) list; > =20 > QLIST_HEAD(, BdrvTrackedRequest) tracked_requests; > =20 > diff --git a/qemu-img.c b/qemu-img.c > index 926f0a0..215b7b2 100644 > --- a/qemu-img.c > +++ b/qemu-img.c > @@ -269,7 +269,7 @@ static BlockDriverState *bdrv_new_open(const char *= filename, > Error *local_err =3D NULL; > int ret; > =20 > - bs =3D bdrv_new("image"); > + bs =3D bdrv_new("image", NULL); > =20 > if (fmt) { > drv =3D bdrv_find_format(fmt); > @@ -2225,7 +2225,7 @@ static int img_rebase(int argc, char **argv) > } else { > char backing_name[1024]; > =20 > - bs_old_backing =3D bdrv_new("old_backing"); > + bs_old_backing =3D bdrv_new("old_backing", NULL); > bdrv_get_backing_filename(bs, backing_name, sizeof(backing_nam= e)); > ret =3D bdrv_open(bs_old_backing, backing_name, NULL, BDRV_O_F= LAGS, > old_backing_drv, &local_err); > @@ -2236,7 +2236,7 @@ static int img_rebase(int argc, char **argv) > goto out; > } > if (out_baseimg[0]) { > - bs_new_backing =3D bdrv_new("new_backing"); > + bs_new_backing =3D bdrv_new("new_backing", NULL); > ret =3D bdrv_open(bs_new_backing, out_baseimg, NULL, BDRV_= O_FLAGS, > new_backing_drv, &local_err); > if (ret) { > diff --git a/qemu-io.c b/qemu-io.c > index 3b3340a..3e1ea88 100644 > --- a/qemu-io.c > +++ b/qemu-io.c > @@ -63,7 +63,7 @@ static int openfile(char *name, int flags, int growab= le, QDict *opts) > return 1; > } > } else { > - qemuio_bs =3D bdrv_new("hda"); > + qemuio_bs =3D bdrv_new("hda", NULL); > =20 > if (bdrv_open(qemuio_bs, name, opts, flags, NULL, &local_err) = < 0) { > fprintf(stderr, "%s: can't open device %s: %s\n", progname= , name, > diff --git a/qemu-nbd.c b/qemu-nbd.c > index c26c98e..35ef57c 100644 > --- a/qemu-nbd.c > +++ b/qemu-nbd.c > @@ -572,7 +572,7 @@ int main(int argc, char **argv) > drv =3D NULL; > } > =20 > - bs =3D bdrv_new("hda"); > + bs =3D bdrv_new("hda", NULL); > srcpath =3D argv[optind]; > ret =3D bdrv_open(bs, srcpath, NULL, flags, drv, &local_err); > if (ret < 0) { > --=20 > 1.8.3.2 >=20 >=20