qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, qemu-devel@nongnu.org, mreitz@redhat.com
Subject: [Qemu-devel] [PATCH 10/10] test-block-iothread: Test AioContext propagation for block jobs
Date: Mon,  6 May 2019 19:18:05 +0200	[thread overview]
Message-ID: <20190506171805.14236-11-kwolf@redhat.com> (raw)
In-Reply-To: <20190506171805.14236-1-kwolf@redhat.com>

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 tests/test-block-iothread.c | 71 +++++++++++++++++++++++++++++++++++++
 1 file changed, 71 insertions(+)

diff --git a/tests/test-block-iothread.c b/tests/test-block-iothread.c
index 938831c9bd..59f692892e 100644
--- a/tests/test-block-iothread.c
+++ b/tests/test-block-iothread.c
@@ -588,6 +588,76 @@ static void test_propagate_diamond(void)
     bdrv_unref(bs_a);
 }
 
+static void test_propagate_mirror(void)
+{
+    IOThread *iothread = iothread_new();
+    AioContext *ctx = iothread_get_aio_context(iothread);
+    AioContext *main_ctx = qemu_get_aio_context();
+    BlockDriverState *src, *target;
+    BlockBackend *blk;
+    Job *job;
+    Error *local_err = NULL;
+
+    /* Create src and target*/
+    src = bdrv_new_open_driver(&bdrv_test, "src", BDRV_O_RDWR, &error_abort);
+    target = bdrv_new_open_driver(&bdrv_test, "target", BDRV_O_RDWR,
+                                  &error_abort);
+
+    /* Start a mirror job */
+    mirror_start("job0", src, target, NULL, JOB_DEFAULT, 0, 0, 0,
+                 MIRROR_SYNC_MODE_NONE, MIRROR_OPEN_BACKING_CHAIN,
+                 BLOCKDEV_ON_ERROR_REPORT, BLOCKDEV_ON_ERROR_REPORT,
+                 false, "filter_node", MIRROR_COPY_MODE_BACKGROUND,
+                 &error_abort);
+    job = job_get("job0");
+
+    /* Change the AioContext of src */
+    bdrv_try_set_aio_context(src, ctx, &error_abort);
+    g_assert(bdrv_get_aio_context(src) == ctx);
+    g_assert(bdrv_get_aio_context(target) == ctx);
+    g_assert(job->aio_context == ctx);
+
+    /* Change the AioContext of target */
+    aio_context_acquire(ctx);
+    bdrv_try_set_aio_context(target, main_ctx, &error_abort);
+    aio_context_release(ctx);
+    g_assert(bdrv_get_aio_context(src) == main_ctx);
+    g_assert(bdrv_get_aio_context(target) == main_ctx);
+
+    /* With a BlockBackend on src, changing target must fail */
+    blk = blk_new(0, BLK_PERM_ALL);
+    blk_insert_bs(blk, src, &error_abort);
+
+    bdrv_try_set_aio_context(target, ctx, &local_err);
+    g_assert(local_err);
+    error_free(local_err);
+
+    g_assert(blk_get_aio_context(blk) == main_ctx);
+    g_assert(bdrv_get_aio_context(src) == main_ctx);
+    g_assert(bdrv_get_aio_context(target) == main_ctx);
+
+    /* ...unless we explicitly allow it */
+    aio_context_acquire(ctx);
+    blk_set_allow_aio_context_change(blk, true);
+    bdrv_try_set_aio_context(target, ctx, &error_abort);
+    aio_context_release(ctx);
+
+    g_assert(blk_get_aio_context(blk) == ctx);
+    g_assert(bdrv_get_aio_context(src) == ctx);
+    g_assert(bdrv_get_aio_context(target) == ctx);
+
+    job_cancel_sync_all();
+
+    aio_context_acquire(ctx);
+    blk_set_aio_context(blk, main_ctx);
+    bdrv_try_set_aio_context(target, main_ctx, &error_abort);
+    aio_context_release(ctx);
+
+    blk_unref(blk);
+    bdrv_unref(src);
+    bdrv_unref(target);
+}
+
 int main(int argc, char **argv)
 {
     int i;
@@ -605,6 +675,7 @@ int main(int argc, char **argv)
     g_test_add_func("/attach/blockjob", test_attach_blockjob);
     g_test_add_func("/propagate/basic", test_propagate_basic);
     g_test_add_func("/propagate/diamond", test_propagate_diamond);
+    g_test_add_func("/propagate/mirror", test_propagate_mirror);
 
     return g_test_run();
 }
-- 
2.20.1



  parent reply	other threads:[~2019-05-06 17:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-06 17:17 [Qemu-devel] [PATCH 00/10] block: AioContext management, part 1 Kevin Wolf
2019-05-06 17:17 ` [Qemu-devel] [PATCH 01/10] block: Add bdrv_try_set_aio_context() Kevin Wolf
2019-05-06 17:17 ` [Qemu-devel] [PATCH 02/10] block: Make bdrv_attach/detach_aio_context() static Kevin Wolf
2019-05-06 17:17 ` [Qemu-devel] [PATCH 03/10] block: Move recursion to bdrv_set_aio_context() Kevin Wolf
2019-05-06 17:17 ` [Qemu-devel] [PATCH 04/10] block: Propagate AioContext change to parents Kevin Wolf
2019-05-06 17:18 ` [Qemu-devel] [PATCH 05/10] test-block-iothread: Test AioContext propagation through the tree Kevin Wolf
2019-05-06 17:18 ` [Qemu-devel] [PATCH 06/10] block: Implement .(can_)set_aio_ctx for BlockBackend Kevin Wolf
2019-05-06 17:18 ` [Qemu-devel] [PATCH 07/10] block: Add blk_set_allow_aio_context_change() Kevin Wolf
2019-05-06 17:18 ` [Qemu-devel] [PATCH 08/10] blockjob: Propagate AioContext change to all job nodes Kevin Wolf
2019-05-06 17:18 ` [Qemu-devel] [PATCH 09/10] blockjob: Remove AioContext notifiers Kevin Wolf
2019-05-06 17:18 ` Kevin Wolf [this message]
2019-05-20 11:08 ` [Qemu-devel] [PATCH 00/10] block: AioContext management, part 1 Kevin Wolf

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=20190506171805.14236-11-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=mreitz@redhat.com \
    --cc=qemu-block@nongnu.org \
    --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).