|
|
1bdc94 |
From d365fdc837cbf347d8575592aeb96097b6a85923 Mon Sep 17 00:00:00 2001
|
|
|
1bdc94 |
From: Kevin Wolf <kwolf@redhat.com>
|
|
|
1bdc94 |
Date: Fri, 14 Sep 2018 10:55:11 +0200
|
|
|
1bdc94 |
Subject: [PATCH 20/49] test-bdrv-drain: Graph change through parent callback
|
|
|
1bdc94 |
|
|
|
1bdc94 |
RH-Author: Kevin Wolf <kwolf@redhat.com>
|
|
|
1bdc94 |
Message-id: <20180914105540.18077-14-kwolf@redhat.com>
|
|
|
1bdc94 |
Patchwork-id: 82165
|
|
|
1bdc94 |
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 13/42] test-bdrv-drain: Graph change through parent callback
|
|
|
1bdc94 |
Bugzilla: 1601212
|
|
|
1bdc94 |
RH-Acked-by: John Snow <jsnow@redhat.com>
|
|
|
1bdc94 |
RH-Acked-by: Max Reitz <mreitz@redhat.com>
|
|
|
1bdc94 |
RH-Acked-by: Fam Zheng <famz@redhat.com>
|
|
|
1bdc94 |
|
|
|
1bdc94 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
1bdc94 |
(cherry picked from commit 231281ab42dad2b407b941e36ad11cbc6586e937)
|
|
|
1bdc94 |
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
|
|
|
1bdc94 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
1bdc94 |
---
|
|
|
1bdc94 |
tests/test-bdrv-drain.c | 130 ++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
1bdc94 |
1 file changed, 130 insertions(+)
|
|
|
1bdc94 |
|
|
|
1bdc94 |
diff --git a/tests/test-bdrv-drain.c b/tests/test-bdrv-drain.c
|
|
|
1bdc94 |
index 38706b0..f786326 100644
|
|
|
1bdc94 |
--- a/tests/test-bdrv-drain.c
|
|
|
1bdc94 |
+++ b/tests/test-bdrv-drain.c
|
|
|
1bdc94 |
@@ -977,6 +977,135 @@ static void test_detach_by_drain_subtree(void)
|
|
|
1bdc94 |
}
|
|
|
1bdc94 |
|
|
|
1bdc94 |
|
|
|
1bdc94 |
+struct detach_by_parent_data {
|
|
|
1bdc94 |
+ BlockDriverState *parent_b;
|
|
|
1bdc94 |
+ BdrvChild *child_b;
|
|
|
1bdc94 |
+ BlockDriverState *c;
|
|
|
1bdc94 |
+ BdrvChild *child_c;
|
|
|
1bdc94 |
+};
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+static void detach_by_parent_aio_cb(void *opaque, int ret)
|
|
|
1bdc94 |
+{
|
|
|
1bdc94 |
+ struct detach_by_parent_data *data = opaque;
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ g_assert_cmpint(ret, ==, 0);
|
|
|
1bdc94 |
+ bdrv_unref_child(data->parent_b, data->child_b);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ bdrv_ref(data->c);
|
|
|
1bdc94 |
+ data->child_c = bdrv_attach_child(data->parent_b, data->c, "PB-C",
|
|
|
1bdc94 |
+ &child_file, &error_abort);
|
|
|
1bdc94 |
+}
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+/*
|
|
|
1bdc94 |
+ * Initial graph:
|
|
|
1bdc94 |
+ *
|
|
|
1bdc94 |
+ * PA PB
|
|
|
1bdc94 |
+ * \ / \
|
|
|
1bdc94 |
+ * A B C
|
|
|
1bdc94 |
+ *
|
|
|
1bdc94 |
+ * PA has a pending write request whose callback changes the child nodes of PB:
|
|
|
1bdc94 |
+ * It removes B and adds C instead. The subtree of PB is drained, which will
|
|
|
1bdc94 |
+ * indirectly drain the write request, too.
|
|
|
1bdc94 |
+ */
|
|
|
1bdc94 |
+static void test_detach_by_parent_cb(void)
|
|
|
1bdc94 |
+{
|
|
|
1bdc94 |
+ BlockBackend *blk;
|
|
|
1bdc94 |
+ BlockDriverState *parent_a, *parent_b, *a, *b, *c;
|
|
|
1bdc94 |
+ BdrvChild *child_a, *child_b;
|
|
|
1bdc94 |
+ BlockAIOCB *acb;
|
|
|
1bdc94 |
+ struct detach_by_parent_data data;
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ QEMUIOVector qiov;
|
|
|
1bdc94 |
+ struct iovec iov = {
|
|
|
1bdc94 |
+ .iov_base = NULL,
|
|
|
1bdc94 |
+ .iov_len = 0,
|
|
|
1bdc94 |
+ };
|
|
|
1bdc94 |
+ qemu_iovec_init_external(&qiov, &iov, 1);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ /* Create all involved nodes */
|
|
|
1bdc94 |
+ parent_a = bdrv_new_open_driver(&bdrv_test, "parent-a", BDRV_O_RDWR,
|
|
|
1bdc94 |
+ &error_abort);
|
|
|
1bdc94 |
+ parent_b = bdrv_new_open_driver(&bdrv_test, "parent-b", 0,
|
|
|
1bdc94 |
+ &error_abort);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ a = bdrv_new_open_driver(&bdrv_test, "a", BDRV_O_RDWR, &error_abort);
|
|
|
1bdc94 |
+ b = bdrv_new_open_driver(&bdrv_test, "b", BDRV_O_RDWR, &error_abort);
|
|
|
1bdc94 |
+ c = bdrv_new_open_driver(&bdrv_test, "c", BDRV_O_RDWR, &error_abort);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ /* blk is a BB for parent-a */
|
|
|
1bdc94 |
+ blk = blk_new(BLK_PERM_ALL, BLK_PERM_ALL);
|
|
|
1bdc94 |
+ blk_insert_bs(blk, parent_a, &error_abort);
|
|
|
1bdc94 |
+ bdrv_unref(parent_a);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ /* Set child relationships */
|
|
|
1bdc94 |
+ bdrv_ref(b);
|
|
|
1bdc94 |
+ bdrv_ref(a);
|
|
|
1bdc94 |
+ child_b = bdrv_attach_child(parent_b, b, "PB-B", &child_file, &error_abort);
|
|
|
1bdc94 |
+ child_a = bdrv_attach_child(parent_b, a, "PB-A", &child_backing, &error_abort);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ bdrv_ref(a);
|
|
|
1bdc94 |
+ bdrv_attach_child(parent_a, a, "PA-A", &child_file, &error_abort);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ g_assert_cmpint(parent_a->refcnt, ==, 1);
|
|
|
1bdc94 |
+ g_assert_cmpint(parent_b->refcnt, ==, 1);
|
|
|
1bdc94 |
+ g_assert_cmpint(a->refcnt, ==, 3);
|
|
|
1bdc94 |
+ g_assert_cmpint(b->refcnt, ==, 2);
|
|
|
1bdc94 |
+ g_assert_cmpint(c->refcnt, ==, 1);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ g_assert(QLIST_FIRST(&parent_b->children) == child_a);
|
|
|
1bdc94 |
+ g_assert(QLIST_NEXT(child_a, next) == child_b);
|
|
|
1bdc94 |
+ g_assert(QLIST_NEXT(child_b, next) == NULL);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ /* Start the evil write request */
|
|
|
1bdc94 |
+ data = (struct detach_by_parent_data) {
|
|
|
1bdc94 |
+ .parent_b = parent_b,
|
|
|
1bdc94 |
+ .child_b = child_b,
|
|
|
1bdc94 |
+ .c = c,
|
|
|
1bdc94 |
+ };
|
|
|
1bdc94 |
+ acb = blk_aio_preadv(blk, 0, &qiov, 0, detach_by_parent_aio_cb, &data);
|
|
|
1bdc94 |
+ g_assert(acb != NULL);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ /* Drain and check the expected result */
|
|
|
1bdc94 |
+ bdrv_subtree_drained_begin(parent_b);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ g_assert(data.child_c != NULL);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ g_assert_cmpint(parent_a->refcnt, ==, 1);
|
|
|
1bdc94 |
+ g_assert_cmpint(parent_b->refcnt, ==, 1);
|
|
|
1bdc94 |
+ g_assert_cmpint(a->refcnt, ==, 3);
|
|
|
1bdc94 |
+ g_assert_cmpint(b->refcnt, ==, 1);
|
|
|
1bdc94 |
+ g_assert_cmpint(c->refcnt, ==, 2);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ g_assert(QLIST_FIRST(&parent_b->children) == data.child_c);
|
|
|
1bdc94 |
+ g_assert(QLIST_NEXT(data.child_c, next) == child_a);
|
|
|
1bdc94 |
+ g_assert(QLIST_NEXT(child_a, next) == NULL);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ g_assert_cmpint(parent_a->quiesce_counter, ==, 1);
|
|
|
1bdc94 |
+ g_assert_cmpint(parent_b->quiesce_counter, ==, 1);
|
|
|
1bdc94 |
+ g_assert_cmpint(a->quiesce_counter, ==, 1);
|
|
|
1bdc94 |
+ g_assert_cmpint(b->quiesce_counter, ==, 0);
|
|
|
1bdc94 |
+ g_assert_cmpint(c->quiesce_counter, ==, 1);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ bdrv_subtree_drained_end(parent_b);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ bdrv_unref(parent_b);
|
|
|
1bdc94 |
+ blk_unref(blk);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ /* XXX Once bdrv_close() unref's children instead of just detaching them,
|
|
|
1bdc94 |
+ * this won't be necessary any more. */
|
|
|
1bdc94 |
+ bdrv_unref(a);
|
|
|
1bdc94 |
+ bdrv_unref(a);
|
|
|
1bdc94 |
+ bdrv_unref(c);
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+ g_assert_cmpint(a->refcnt, ==, 1);
|
|
|
1bdc94 |
+ g_assert_cmpint(b->refcnt, ==, 1);
|
|
|
1bdc94 |
+ g_assert_cmpint(c->refcnt, ==, 1);
|
|
|
1bdc94 |
+ bdrv_unref(a);
|
|
|
1bdc94 |
+ bdrv_unref(b);
|
|
|
1bdc94 |
+ bdrv_unref(c);
|
|
|
1bdc94 |
+}
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
+
|
|
|
1bdc94 |
int main(int argc, char **argv)
|
|
|
1bdc94 |
{
|
|
|
1bdc94 |
int ret;
|
|
|
1bdc94 |
@@ -1027,6 +1156,7 @@ int main(int argc, char **argv)
|
|
|
1bdc94 |
g_test_add_func("/bdrv-drain/deletion/drain", test_delete_by_drain);
|
|
|
1bdc94 |
g_test_add_func("/bdrv-drain/detach/drain", test_detach_by_drain);
|
|
|
1bdc94 |
g_test_add_func("/bdrv-drain/detach/drain_subtree", test_detach_by_drain_subtree);
|
|
|
1bdc94 |
+ g_test_add_func("/bdrv-drain/detach/parent_cb", test_detach_by_parent_cb);
|
|
|
1bdc94 |
|
|
|
1bdc94 |
ret = g_test_run();
|
|
|
1bdc94 |
qemu_event_destroy(&done_event);
|
|
|
1bdc94 |
--
|
|
|
1bdc94 |
1.8.3.1
|
|
|
1bdc94 |
|