From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47540) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5SHg-0004Ob-Vp for qemu-devel@nongnu.org; Mon, 20 Jan 2014 22:45:58 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W5SHb-00014n-5n for qemu-devel@nongnu.org; Mon, 20 Jan 2014 22:45:52 -0500 Received: from mx1.redhat.com ([209.132.183.28]:46546) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W5SHa-00014h-T0 for qemu-devel@nongnu.org; Mon, 20 Jan 2014 22:45:47 -0500 Date: Tue, 21 Jan 2014 11:45:42 +0800 From: Fam Zheng Message-ID: <20140121034542.GH29842@T430.redhat.com> References: <1386862440-8003-1-git-send-email-benoit@irqsave.net> <1386862440-8003-6-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-6-git-send-email-benoit@irqsave.net> Content-Transfer-Encoding: quoted-printable Subject: Re: [Qemu-devel] [PATCH V5 5/7] block: Create authorizations mechanism for external snapshot and resize. 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: > Signed-off-by: Benoit Canet > --- > block.c | 65 +++++++++++++++++++++++++++++++++++++++= +------- > block/blkverify.c | 2 +- > blockdev.c | 2 +- > include/block/block.h | 20 +++++++-------- > include/block/block_int.h | 12 ++++++--- > 5 files changed, 77 insertions(+), 24 deletions(-) >=20 > diff --git a/block.c b/block.c > index 22190a4..57946b7 100644 > --- a/block.c > +++ b/block.c > @@ -4992,21 +4992,68 @@ int bdrv_amend_options(BlockDriverState *bs, QE= MUOptionParameter *options) > return bs->drv->bdrv_amend_options(bs, options); > } > =20 > -ExtSnapshotPerm bdrv_check_ext_snapshot(BlockDriverState *bs) > +/* Used to recurse on single child block filters. > + * Single child block filter will store their child in bs->file. > + */ > +bool bdrv_generic_is_first_non_filter(BlockDriverState *bs, > + BlockDriverState *candidate) > { > - if (bs->drv->bdrv_check_ext_snapshot) { > - return bs->drv->bdrv_check_ext_snapshot(bs); > + if (!bs->drv) { > + return false; > + } > + > + if (!bs->drv->authorizations[BS_IS_A_FILTER]) { > + if (bs =3D=3D candidate) { > + return true; > + } else { > + return false; > + } > + } > + > + if (!bs->drv->authorizations[BS_FILTER_PASS_DOWN]) { > + return false; > } > =20 > - if (bs->file && bs->file->drv && bs->file->drv->bdrv_check_ext_sna= pshot) { > - return bs->file->drv->bdrv_check_ext_snapshot(bs); > + if (!bs->file) { > + return false; > + } > + > + return bdrv_recurse_is_first_non_filter(bs->file, candidate); > +} > + > +bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs, > + BlockDriverState *candidate) > +{ > + if (bs->drv && bs->drv->bdrv_recurse_is_first_non_filter) { > + return bs->drv->bdrv_recurse_is_first_non_filter(bs, candidate= ); > } > =20 > - /* external snapshots are allowed by default */ > - return EXT_SNAPSHOT_ALLOWED; > + return bdrv_generic_is_first_non_filter(bs, candidate); > } > =20 > -ExtSnapshotPerm bdrv_check_ext_snapshot_forbidden(BlockDriverState *bs= ) > +/* This function check if the candidate is the first non filter bs dow= n it's s/check/checks/ > + * bs chain. Since we don't have pointers to parents it explore all bs= chains > + * from the top. Some filters can choose not to pass down the recursio= n. > + */ > +bool bdrv_is_first_non_filter(BlockDriverState *candidate) > { > - return EXT_SNAPSHOT_FORBIDDEN; > + BlockDriverState *bs; > + > + /* walk down the bs forest recursively */ > + QTAILQ_FOREACH(bs, &bdrv_states, device_list) { > + bool perm; > + > + if (!bs->file) { > + continue; > + } > + > + perm =3D bdrv_recurse_is_first_non_filter(bs->file, candidate)= ; > + > + /* candidate is the first non filter */ > + if (perm) { > + return true; > + } > + } > + > + return false; > } > diff --git a/block/blkverify.c b/block/blkverify.c > index 3c63528..853afa9 100644 > --- a/block/blkverify.c > +++ b/block/blkverify.c > @@ -417,7 +417,7 @@ static BlockDriver bdrv_blkverify =3D { > .bdrv_aio_writev =3D blkverify_aio_writev, > .bdrv_aio_flush =3D blkverify_aio_flush, > =20 > - .bdrv_check_ext_snapshot =3D bdrv_check_ext_snapshot_forbidden, > + .authorizations =3D { true, false }, > }; > =20 > static void bdrv_blkverify_init(void) > diff --git a/blockdev.c b/blockdev.c > index 838df50..ebb8f48 100644 > --- a/blockdev.c > +++ b/blockdev.c > @@ -1236,7 +1236,7 @@ static void external_snapshot_prepare(BlkTransact= ionState *common, > } > } > =20 > - if (bdrv_check_ext_snapshot(state->old_bs) !=3D EXT_SNAPSHOT_ALLOW= ED) { > + if (!bdrv_is_first_non_filter(state->old_bs)) { > error_set(errp, QERR_FEATURE_DISABLED, "snapshot"); > return; > } > diff --git a/include/block/block.h b/include/block/block.h > index f7d8017..16812b0 100644 > --- a/include/block/block.h > +++ b/include/block/block.h > @@ -283,16 +283,16 @@ int bdrv_amend_options(BlockDriverState *bs_new, = QEMUOptionParameter *options); > /* external snapshots */ > =20 > typedef enum { > - EXT_SNAPSHOT_ALLOWED, > - EXT_SNAPSHOT_FORBIDDEN, > -} ExtSnapshotPerm; > - > -/* return EXT_SNAPSHOT_ALLOWED if external snapshot is allowed > - * return EXT_SNAPSHOT_FORBIDDEN if external snapshot is forbidden > - */ > -ExtSnapshotPerm bdrv_check_ext_snapshot(BlockDriverState *bs); > -/* helper used to forbid external snapshots like in blkverify */ > -ExtSnapshotPerm bdrv_check_ext_snapshot_forbidden(BlockDriverState *bs= ); > + BS_IS_A_FILTER, > + BS_FILTER_PASS_DOWN, > + BS_AUTHORIZATION_COUNT, > +} BsAuthorization; > + > +bool bdrv_generic_is_first_non_filter(BlockDriverState *bs, > + BlockDriverState *candidate); > +bool bdrv_recurse_is_first_non_filter(BlockDriverState *bs, > + BlockDriverState *candidate); > +bool bdrv_is_first_non_filter(BlockDriverState *candidate); > =20 > /* async block I/O */ > typedef void BlockDriverDirtyHandler(BlockDriverState *bs, int64_t sec= tor, > diff --git a/include/block/block_int.h b/include/block/block_int.h > index bd5220f..7933ecc 100644 > --- a/include/block/block_int.h > +++ b/include/block/block_int.h > @@ -69,10 +69,16 @@ struct BlockDriver { > const char *format_name; > int instance_size; > =20 > - /* if not defined external snapshots are allowed > - * future block filters will query their children to build the res= ponse > + /* this table of boolean contains authorizations for the block ope= rations */ > + bool authorizations[BS_AUTHORIZATION_COUNT]; > + /* for snapshots complex block filter like Quorum can implement th= e > + * following recursive callback instead of BS_IS_A_FILTER. > + * It's purpose is to recurse on the filter children while calling > + * bdrv_recurse_is_first_non_filter on them. > + * For a sample implentation look in the future Quorum block filte= r. s/implentation/implementation/ > */ > - ExtSnapshotPerm (*bdrv_check_ext_snapshot)(BlockDriverState *bs); > + bool (*bdrv_recurse_is_first_non_filter)(BlockDriverState *bs, > + BlockDriverState *candida= te); > =20 > int (*bdrv_probe)(const uint8_t *buf, int buf_size, const char *fi= lename); > int (*bdrv_probe_device)(const char *filename); > --=20 > 1.8.3.2 >=20 >=20