From: Max Reitz <mreitz@redhat.com>
To: Fam Zheng <famz@redhat.com>, qemu-devel@nongnu.org
Cc: Kevin Wolf <kwolf@redhat.com>,
qemu-block@nongnu.org, jcody@redhat.com, armbru@redhat.com,
Stefan Hajnoczi <stefanha@redhat.com>,
pbonzini@redhat.com
Subject: Re: [Qemu-devel] [PATCH v3 02/12] block: Add op blocker notifier list
Date: Mon, 18 May 2015 19:22:48 +0200 [thread overview]
Message-ID: <555A1FE8.9020905@redhat.com> (raw)
In-Reply-To: <1431669868-26804-3-git-send-email-famz@redhat.com>
On 15.05.2015 08:04, Fam Zheng wrote:
> BDS users can register a notifier and get notified about op blocker
> changes.
>
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
> block.c | 35 +++++++++++++++++++++++++++++++++++
> include/block/block.h | 8 ++++++++
> include/block/block_int.h | 3 +++
> 3 files changed, 46 insertions(+)
>
> diff --git a/block.c b/block.c
> index 7904098..178e186 100644
> --- a/block.c
> +++ b/block.c
> @@ -3375,6 +3375,19 @@ struct BdrvOpBlocker {
> QLIST_ENTRY(BdrvOpBlocker) list;
> };
>
> +/* Add a notifier which will be notified when the first blocker of some type is
> + * added to bs, or when the last blocker is removed. The notifier handler
> + * should receive a BlockOpEvent data.
> + *
> + * Caller must hold bs->aio_context; the notifier handler is also called with
> + * it hold.
*held (I think)
With that fixed:
Reviewed-by: Max Reitz <mreitz@redhat.com>
(Although I'm missing a place where the notifiers are freed (on
bdrv_delete()/bdrv_close()), but maybe that's done in a different patch)
> + */
> +void bdrv_op_blocker_add_notifier(BlockDriverState *bs,
> + Notifier *notifier)
> +{
> + notifier_list_add(&bs->op_blocker_notifiers, notifier);
> +}
> +
> bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp)
> {
> BdrvOpBlocker *blocker;
> @@ -3391,26 +3404,48 @@ bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp)
> return false;
> }
>
> +static void bdrv_op_blocker_notify(BlockDriverState *bs, BlockOpType op,
> + Error *reason, bool blocking)
> +{
> + BlockOpEvent event = (BlockOpEvent) {
> + op = op,
> + reason = reason,
> + blocking = blocking,
> + };
> +
> + notifier_list_notify(&bs->op_blocker_notifiers, &event);
> +}
> +
> void bdrv_op_block(BlockDriverState *bs, BlockOpType op, Error *reason)
> {
> + bool blocked;
> BdrvOpBlocker *blocker;
> assert((int) op >= 0 && op < BLOCK_OP_TYPE_MAX);
>
> blocker = g_new0(BdrvOpBlocker, 1);
> blocker->reason = reason;
> + blocked = !QLIST_EMPTY(&bs->op_blockers[op]);
> QLIST_INSERT_HEAD(&bs->op_blockers[op], blocker, list);
> + if (!blocked) {
> + bdrv_op_blocker_notify(bs, op, reason, true);
> + }
> }
>
> void bdrv_op_unblock(BlockDriverState *bs, BlockOpType op, Error *reason)
> {
> + bool blocked;
> BdrvOpBlocker *blocker, *next;
> assert((int) op >= 0 && op < BLOCK_OP_TYPE_MAX);
> + blocked = !QLIST_EMPTY(&bs->op_blockers[op]);
> QLIST_FOREACH_SAFE(blocker, &bs->op_blockers[op], list, next) {
> if (blocker->reason == reason) {
> QLIST_REMOVE(blocker, list);
> g_free(blocker);
> }
> }
> + if (blocked && QLIST_EMPTY(&bs->op_blockers[op])) {
> + bdrv_op_blocker_notify(bs, op, reason, false);
> + }
> }
>
> void bdrv_op_block_all(BlockDriverState *bs, Error *reason)
> diff --git a/include/block/block.h b/include/block/block.h
> index 906fb31..3420b2c 100644
> --- a/include/block/block.h
> +++ b/include/block/block.h
> @@ -163,6 +163,12 @@ typedef enum BlockOpType {
> BLOCK_OP_TYPE_MAX,
> } BlockOpType;
>
> +typedef struct {
> + BlockOpType type;
> + Error *reason;
> + bool blocking;
> +} BlockOpEvent;
> +
> void bdrv_iostatus_enable(BlockDriverState *bs);
> void bdrv_iostatus_reset(BlockDriverState *bs);
> void bdrv_iostatus_disable(BlockDriverState *bs);
> @@ -491,6 +497,8 @@ void bdrv_disable_copy_on_read(BlockDriverState *bs);
> void bdrv_ref(BlockDriverState *bs);
> void bdrv_unref(BlockDriverState *bs);
>
> +void bdrv_op_blocker_add_notifier(BlockDriverState *bs,
> + Notifier *notifier);
> bool bdrv_op_is_blocked(BlockDriverState *bs, BlockOpType op, Error **errp);
> void bdrv_op_block(BlockDriverState *bs, BlockOpType op, Error *reason);
> void bdrv_op_unblock(BlockDriverState *bs, BlockOpType op, Error *reason);
> diff --git a/include/block/block_int.h b/include/block/block_int.h
> index db29b74..29d1c84 100644
> --- a/include/block/block_int.h
> +++ b/include/block/block_int.h
> @@ -418,6 +418,9 @@ struct BlockDriverState {
> /* operation blockers */
> QLIST_HEAD(, BdrvOpBlocker) op_blockers[BLOCK_OP_TYPE_MAX];
>
> + /* Callback when one list in op_blockers has "empty" status change. */
> + NotifierList op_blocker_notifiers;
> +
> /* long-running background operation */
> BlockJob *job;
>
next prev parent reply other threads:[~2015-05-18 17:23 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-15 6:04 [Qemu-devel] [PATCH v3 00/12] Fix transactional snapshot with dataplane and NBD export Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 01/12] block: Add op blocker type "device IO" Fam Zheng
2015-05-15 6:22 ` Wen Congyang
2015-05-15 7:06 ` Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 02/12] block: Add op blocker notifier list Fam Zheng
2015-05-18 17:22 ` Max Reitz [this message]
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 03/12] block-backend: Add blk_op_blocker_add_notifier Fam Zheng
2015-05-18 17:24 ` Max Reitz
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 04/12] virtio-blk: Move complete_request to 'ops' structure Fam Zheng
2015-05-18 17:38 ` Max Reitz
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 05/12] virtio-blk: Don't handle output when there is "device IO" op blocker Fam Zheng
2015-05-18 18:19 ` Max Reitz
2015-05-19 2:58 ` Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 06/12] nbd-server: Clear "can_read" when "device io" blocker is set Fam Zheng
2015-05-18 18:35 ` Max Reitz
2015-05-19 2:26 ` Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 07/12] blockdev: Block device IO during internal snapshot transaction Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 08/12] blockdev: Block device IO during external " Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 09/12] blockdev: Block device IO during drive-backup transaction Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 10/12] blockdev: Block device IO during blockdev-backup transaction Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 11/12] block: Block "device IO" during bdrv_drain and bdrv_drain_all Fam Zheng
2015-05-15 6:04 ` [Qemu-devel] [PATCH v3 12/12] virtio-scsi-dataplane: Add "device IO" op blocker listener Fam Zheng
2015-05-15 6:50 ` Paolo Bonzini
2015-05-15 7:03 ` Fam Zheng
2015-05-15 7:26 ` Paolo Bonzini
2015-05-15 7:57 ` Fam Zheng
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=555A1FE8.9020905@redhat.com \
--to=mreitz@redhat.com \
--cc=armbru@redhat.com \
--cc=famz@redhat.com \
--cc=jcody@redhat.com \
--cc=kwolf@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.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).