From: Stefan Hajnoczi <stefanha@redhat.com>
To: Max Reitz <mreitz@redhat.com>
Cc: Kevin Wolf <kwolf@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 3/4] blockdev: acquire AioContext in QMP 'transaction' actions
Date: Mon, 24 Nov 2014 13:57:19 +0000 [thread overview]
Message-ID: <20141124135719.GI4596@stefanha-thinkpad.redhat.com> (raw)
In-Reply-To: <546F4362.3030608@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 4560 bytes --]
On Fri, Nov 21, 2014 at 02:51:30PM +0100, Max Reitz wrote:
> On 2014-11-21 at 11:48, Stefan Hajnoczi wrote:
> >The transaction QMP command performs operations atomically on a group of
> >drives. This command needs to acquire AioContext in order to work
> >safely when virtio-blk dataplane IOThreads are accessing drives.
> >
> >The transactional nature of the command means that actions are split
> >into prepare, commit, abort, and clean functions. Acquire the
> >AioContext in prepare and don't release it until one of the other
> >functions is called. This prevents the IOThread from running the
> >AioContext before the transaction has completed.
> >
> >Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> >---
> > blockdev.c | 52 ++++++++++++++++++++++++++++++++++++++++-
> > hw/block/dataplane/virtio-blk.c | 2 ++
> > 2 files changed, 53 insertions(+), 1 deletion(-)
> >
> >diff --git a/blockdev.c b/blockdev.c
> >index 0d06983..90cb33d 100644
> >--- a/blockdev.c
> >+++ b/blockdev.c
> >@@ -1193,6 +1193,7 @@ struct BlkTransactionState {
> > typedef struct InternalSnapshotState {
> > BlkTransactionState common;
> > BlockDriverState *bs;
> >+ AioContext *aio_context;
> > QEMUSnapshotInfo sn;
> > } InternalSnapshotState;
> >@@ -1226,6 +1227,10 @@ static void internal_snapshot_prepare(BlkTransactionState *common,
> > return;
> > }
> >+ /* AioContext is released in .clean() */
> >+ state->aio_context = bdrv_get_aio_context(bs);
> >+ aio_context_acquire(state->aio_context);
> >+
> > if (!bdrv_is_inserted(bs)) {
> > error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
> > return;
> >@@ -1303,11 +1308,22 @@ static void internal_snapshot_abort(BlkTransactionState *common)
> > }
> > }
> >+static void internal_snapshot_clean(BlkTransactionState *common)
> >+{
> >+ InternalSnapshotState *state = DO_UPCAST(InternalSnapshotState,
> >+ common, common);
> >+
> >+ if (state->aio_context) {
> >+ aio_context_release(state->aio_context);
> >+ }
> >+}
> >+
> > /* external snapshot private data */
> > typedef struct ExternalSnapshotState {
> > BlkTransactionState common;
> > BlockDriverState *old_bs;
> > BlockDriverState *new_bs;
> >+ AioContext *aio_context;
> > } ExternalSnapshotState;
> > static void external_snapshot_prepare(BlkTransactionState *common,
> >@@ -1374,6 +1390,10 @@ static void external_snapshot_prepare(BlkTransactionState *common,
> > return;
> > }
> >+ /* Acquire AioContext now so any threads operating on old_bs stop */
>
> Any reason why this comment differs so much from the one for internal
> snapshots?
>
> >+ state->aio_context = bdrv_get_aio_context(state->old_bs);
> >+ aio_context_acquire(state->aio_context);
> >+
> > if (!bdrv_is_inserted(state->old_bs)) {
> > error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
> > return;
> >@@ -1432,6 +1452,8 @@ static void external_snapshot_commit(BlkTransactionState *common)
> > ExternalSnapshotState *state =
> > DO_UPCAST(ExternalSnapshotState, common, common);
> >+ bdrv_set_aio_context(state->new_bs, state->aio_context);
> >+
> > /* This removes our old bs and adds the new bs */
> > bdrv_append(state->new_bs, state->old_bs);
> > /* We don't need (or want) to use the transactional
> >@@ -1439,6 +1461,8 @@ static void external_snapshot_commit(BlkTransactionState *common)
> > * don't want to abort all of them if one of them fails the reopen */
> > bdrv_reopen(state->new_bs, state->new_bs->open_flags & ~BDRV_O_RDWR,
> > NULL);
> >+
> >+ aio_context_release(state->aio_context);
> > }
> > static void external_snapshot_abort(BlkTransactionState *common)
> >@@ -1448,23 +1472,38 @@ static void external_snapshot_abort(BlkTransactionState *common)
> > if (state->new_bs) {
> > bdrv_unref(state->new_bs);
> > }
> >+ if (state->aio_context) {
> >+ aio_context_release(state->aio_context);
> >+ }
> > }
>
> It does work this way, but I would have gone for adding
> external_snapshot_clean() here, too.
This is why the comment differs :). Since we already have these two
functions I didn't add a separate .clean(). It could be done either way
but unless anyone feels strongly about it, I'd like to do it like this.
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
next prev parent reply other threads:[~2014-11-24 13:57 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-11-21 10:48 [Qemu-devel] [PATCH 0/4] blockdev: support dataplane in QMP 'transaction' command Stefan Hajnoczi
2014-11-21 10:48 ` [Qemu-devel] [PATCH 1/4] blockdev: update outdated qmp_transaction() comments Stefan Hajnoczi
2014-11-21 13:22 ` Max Reitz
2014-11-21 13:30 ` Max Reitz
2014-11-21 10:48 ` [Qemu-devel] [PATCH 2/4] blockdev: drop unnecessary DriveBackupState field assignment Stefan Hajnoczi
2014-11-21 13:25 ` Max Reitz
2014-11-21 10:48 ` [Qemu-devel] [PATCH 3/4] blockdev: acquire AioContext in QMP 'transaction' actions Stefan Hajnoczi
2014-11-21 13:51 ` Max Reitz
2014-11-24 13:57 ` Stefan Hajnoczi [this message]
2014-11-21 10:49 ` [Qemu-devel] [PATCH 4/4] blockdev: check for BLOCK_OP_TYPE_EXTERNAL_SNAPSHOT Stefan Hajnoczi
2014-11-21 11:58 ` Paolo Bonzini
2014-11-24 13:58 ` Stefan Hajnoczi
2014-11-24 16:13 ` Max Reitz
2014-11-26 16:41 ` [Qemu-devel] [PATCH 0/4] blockdev: support dataplane in QMP 'transaction' command Stefan Hajnoczi
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=20141124135719.GI4596@stefanha-thinkpad.redhat.com \
--to=stefanha@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).