From e21577707152c10017dcf4d3340e83b100057355 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Tue, 9 Mar 2021 13:18:14 +0100 Subject: storage-daemon: Call job_cancel_sync_all() on shutdown bdrv_close_all() asserts that no jobs are running any more, so we need to cancel all jobs first to avoid failing the assertion. Fixes: b55a3c8860b763b62b2cc2f4a6f55379977bbde5 Reported-by: Nini Gu Signed-off-by: Kevin Wolf Message-Id: <20210309121814.31078-1-kwolf@redhat.com> Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- tests/qemu-iotests/tests/qsd-jobs | 66 +++++++++++++++++++++++++++++++++++ tests/qemu-iotests/tests/qsd-jobs.out | 22 ++++++++++++ 2 files changed, 88 insertions(+) create mode 100755 tests/qemu-iotests/tests/qsd-jobs create mode 100644 tests/qemu-iotests/tests/qsd-jobs.out (limited to 'tests') diff --git a/tests/qemu-iotests/tests/qsd-jobs b/tests/qemu-iotests/tests/qsd-jobs new file mode 100755 index 0000000..1a1c534 --- /dev/null +++ b/tests/qemu-iotests/tests/qsd-jobs @@ -0,0 +1,66 @@ +#!/usr/bin/env bash +# group: rw auto quick qsd +# +# Job tests related specifically to qemu-storage-daemon +# +# Copyright (C) 2021 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +# creator +owner=kwolf@redhat.com + +seq="$(basename $0)" +echo "QA output created by $seq" + +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +cd .. +. ./common.rc +. ./common.filter + +_supported_fmt qcow2 +_supported_proto generic + +size=128M + +TEST_IMG="$TEST_IMG.base" _make_test_img $size +_make_test_img -b "$TEST_IMG.base" -F $IMGFMT + +echo +echo "=== Job still present at shutdown ===" +echo + +# Just make sure that this doesn't crash +$QSD --chardev stdio,id=stdio --monitor chardev=stdio \ + --blockdev node-name=file0,driver=file,filename="$TEST_IMG" \ + --blockdev node-name=fmt0,driver=qcow2,file=file0 < Date: Tue, 9 Mar 2021 18:34:51 +0100 Subject: stream: Don't crash when node permission is denied The image streaming block job restricts shared permissions of the nodes it accesses. This can obviously fail when other users already got these permissions. &error_abort is therefore wrong and can crash. Handle these errors gracefully and just fail starting the block job. Reported-by: Nini Gu Signed-off-by: Kevin Wolf Message-Id: <20210309173451.45152-1-kwolf@redhat.com> Reviewed-by: Eric Blake Reviewed-by: Alberto Garcia Signed-off-by: Kevin Wolf --- tests/qemu-iotests/tests/qsd-jobs | 20 ++++++++++++++++++++ tests/qemu-iotests/tests/qsd-jobs.out | 10 ++++++++++ 2 files changed, 30 insertions(+) (limited to 'tests') diff --git a/tests/qemu-iotests/tests/qsd-jobs b/tests/qemu-iotests/tests/qsd-jobs index 1a1c534..972b6b3 100755 --- a/tests/qemu-iotests/tests/qsd-jobs +++ b/tests/qemu-iotests/tests/qsd-jobs @@ -30,6 +30,7 @@ status=1 # failure is the default! _cleanup() { _cleanup_test_img + rm -f "$SOCK_DIR/nbd.sock" } trap "_cleanup; exit \$status" 0 1 2 3 15 @@ -59,6 +60,25 @@ $QSD --chardev stdio,id=stdio --monitor chardev=stdio \ {"execute": "quit"} EOF +echo +echo "=== Streaming can't get permission on base node ===" +echo + +# Just make sure that this doesn't crash +$QSD --chardev stdio,id=stdio --monitor chardev=stdio \ + --blockdev node-name=file_base,driver=file,filename="$TEST_IMG.base" \ + --blockdev node-name=fmt_base,driver=qcow2,file=file_base \ + --blockdev node-name=file_overlay,driver=file,filename="$TEST_IMG" \ + --blockdev node-name=fmt_overlay,driver=qcow2,file=file_overlay,backing=fmt_base \ + --nbd-server addr.type=unix,addr.path="$SOCK_DIR/nbd.sock" \ + --export type=nbd,id=export1,node-name=fmt_base,writable=on,name=export1 \ + < Date: Fri, 27 Nov 2020 17:40:21 +0100 Subject: tests: Drop 'props' from object-add calls The 'props' option has been deprecated in 5.0 in favour of a flattened object-add command. Time to change our test cases to drop the deprecated option. Signed-off-by: Kevin Wolf Acked-by: Paolo Bonzini Acked-by: Peter Krempa Reviewed-by: Eric Blake --- tests/qtest/qmp-cmd-test.c | 16 ++++++------- tests/qtest/test-netfilter.c | 54 ++++++++++++++++++++------------------------ 2 files changed, 32 insertions(+), 38 deletions(-) (limited to 'tests') diff --git a/tests/qtest/qmp-cmd-test.c b/tests/qtest/qmp-cmd-test.c index 1c7186e..c98b78d 100644 --- a/tests/qtest/qmp-cmd-test.c +++ b/tests/qtest/qmp-cmd-test.c @@ -230,14 +230,14 @@ static void test_object_add_failure_modes(void) /* attempt to create 2 objects with duplicate id */ resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" " {'qom-type': 'memory-backend-ram', 'id': 'ram1'," - " 'props': {'size': 1048576 } } }"); + " 'size': 1048576 } }"); g_assert_nonnull(resp); g_assert(qdict_haskey(resp, "return")); qobject_unref(resp); resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" " {'qom-type': 'memory-backend-ram', 'id': 'ram1'," - " 'props': {'size': 1048576 } } }"); + " 'size': 1048576 } }"); g_assert_nonnull(resp); qmp_expect_error_and_unref(resp, "GenericError"); @@ -251,14 +251,14 @@ static void test_object_add_failure_modes(void) /* attempt to create an object with a property of a wrong type */ resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" " {'qom-type': 'memory-backend-ram', 'id': 'ram1'," - " 'props': {'size': '1048576' } } }"); + " 'size': '1048576' } }"); g_assert_nonnull(resp); /* now do it right */ qmp_expect_error_and_unref(resp, "GenericError"); resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" " {'qom-type': 'memory-backend-ram', 'id': 'ram1'," - " 'props': {'size': 1048576 } } }"); + " 'size': 1048576 } }"); g_assert_nonnull(resp); g_assert(qdict_haskey(resp, "return")); qobject_unref(resp); @@ -273,14 +273,14 @@ static void test_object_add_failure_modes(void) /* attempt to create an object without the id */ resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" " {'qom-type': 'memory-backend-ram'," - " 'props': {'size': 1048576 } } }"); + " 'size': 1048576 } }"); g_assert_nonnull(resp); qmp_expect_error_and_unref(resp, "GenericError"); /* now do it right */ resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" " {'qom-type': 'memory-backend-ram', 'id': 'ram1'," - " 'props': {'size': 1048576 } } }"); + " 'size': 1048576 } }"); g_assert_nonnull(resp); g_assert(qdict_haskey(resp, "return")); qobject_unref(resp); @@ -295,14 +295,14 @@ static void test_object_add_failure_modes(void) /* attempt to set a non existing property */ resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" " {'qom-type': 'memory-backend-ram', 'id': 'ram1'," - " 'props': {'sized': 1048576 } } }"); + " 'sized': 1048576 } }"); g_assert_nonnull(resp); qmp_expect_error_and_unref(resp, "GenericError"); /* now do it right */ resp = qtest_qmp(qts, "{'execute': 'object-add', 'arguments':" " {'qom-type': 'memory-backend-ram', 'id': 'ram1'," - " 'props': {'size': 1048576 } } }"); + " 'size': 1048576 } }"); g_assert_nonnull(resp); g_assert(qdict_haskey(resp, "return")); qobject_unref(resp); diff --git a/tests/qtest/test-netfilter.c b/tests/qtest/test-netfilter.c index 22927ee..785b6f3 100644 --- a/tests/qtest/test-netfilter.c +++ b/tests/qtest/test-netfilter.c @@ -21,11 +21,10 @@ static void add_one_netfilter(void) " 'arguments': {" " 'qom-type': 'filter-buffer'," " 'id': 'qtest-f0'," - " 'props': {" - " 'netdev': 'qtest-bn0'," - " 'queue': 'rx'," - " 'interval': 1000" - "}}}"); + " 'netdev': 'qtest-bn0'," + " 'queue': 'rx'," + " 'interval': 1000" + "}}"); g_assert(response); g_assert(!qdict_haskey(response, "error")); @@ -49,11 +48,10 @@ static void remove_netdev_with_one_netfilter(void) " 'arguments': {" " 'qom-type': 'filter-buffer'," " 'id': 'qtest-f0'," - " 'props': {" - " 'netdev': 'qtest-bn0'," - " 'queue': 'rx'," - " 'interval': 1000" - "}}}"); + " 'netdev': 'qtest-bn0'," + " 'queue': 'rx'," + " 'interval': 1000" + "}}"); g_assert(response); g_assert(!qdict_haskey(response, "error")); @@ -87,11 +85,10 @@ static void add_multi_netfilter(void) " 'arguments': {" " 'qom-type': 'filter-buffer'," " 'id': 'qtest-f0'," - " 'props': {" - " 'netdev': 'qtest-bn0'," - " 'queue': 'rx'," - " 'interval': 1000" - "}}}"); + " 'netdev': 'qtest-bn0'," + " 'queue': 'rx'," + " 'interval': 1000" + "}}"); g_assert(response); g_assert(!qdict_haskey(response, "error")); @@ -101,11 +98,10 @@ static void add_multi_netfilter(void) " 'arguments': {" " 'qom-type': 'filter-buffer'," " 'id': 'qtest-f1'," - " 'props': {" - " 'netdev': 'qtest-bn0'," - " 'queue': 'rx'," - " 'interval': 1000" - "}}}"); + " 'netdev': 'qtest-bn0'," + " 'queue': 'rx'," + " 'interval': 1000" + "}}"); g_assert(response); g_assert(!qdict_haskey(response, "error")); @@ -137,11 +133,10 @@ static void remove_netdev_with_multi_netfilter(void) " 'arguments': {" " 'qom-type': 'filter-buffer'," " 'id': 'qtest-f0'," - " 'props': {" - " 'netdev': 'qtest-bn0'," - " 'queue': 'rx'," - " 'interval': 1000" - "}}}"); + " 'netdev': 'qtest-bn0'," + " 'queue': 'rx'," + " 'interval': 1000" + "}}"); g_assert(response); g_assert(!qdict_haskey(response, "error")); @@ -151,11 +146,10 @@ static void remove_netdev_with_multi_netfilter(void) " 'arguments': {" " 'qom-type': 'filter-buffer'," " 'id': 'qtest-f1'," - " 'props': {" - " 'netdev': 'qtest-bn0'," - " 'queue': 'rx'," - " 'interval': 1000" - "}}}"); + " 'netdev': 'qtest-bn0'," + " 'queue': 'rx'," + " 'interval': 1000" + "}}"); g_assert(response); g_assert(!qdict_haskey(response, "error")); -- cgit v1.1 From 5965243641d797b2270082c5a4eab49cb81fc8f0 Mon Sep 17 00:00:00 2001 From: Kevin Wolf Date: Thu, 11 Mar 2021 17:42:52 +0100 Subject: char: Deprecate backend aliases 'tty' and 'parport' QAPI doesn't know the aliases 'tty' and 'parport' and there is no reason to prefer them to the real names of the backends 'serial' and 'parallel'. Since warnings are not allowed in 'make check' output, we can't test the deprecated alias any more. Remove it from test-char. Signed-off-by: Kevin Wolf Acked-by: Paolo Bonzini Message-Id: <20210311164253.338723-3-kwolf@redhat.com> Reviewed-by: Markus Armbruster Signed-off-by: Kevin Wolf --- tests/unit/test-char.c | 6 ------ 1 file changed, 6 deletions(-) (limited to 'tests') diff --git a/tests/unit/test-char.c b/tests/unit/test-char.c index 755d54c..5b3b48e 100644 --- a/tests/unit/test-char.c +++ b/tests/unit/test-char.c @@ -1199,12 +1199,6 @@ static void char_serial_test(void) /* TODO: add more tests with a pty */ object_unparent(OBJECT(chr)); - /* test tty alias */ - qemu_opt_set(opts, "backend", "tty", &error_abort); - chr = qemu_chr_new_from_opts(opts, NULL, &error_abort); - g_assert_nonnull(chr); - object_unparent(OBJECT(chr)); - qemu_opts_del(opts); } #endif -- cgit v1.1 From 53c9956d8b3f5eb621fb15c6e6ea67e12f9677e7 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Fri, 12 Mar 2021 12:35:45 -0500 Subject: tests: convert check-qom-proplist to keyval The command-line creation test is using QemuOpts. Switch it to keyval, since the emulator has some special needs and thus the last user of user_creatable_add_opts will go away with the next patch. Reviewed-by: Kevin Wolf Signed-off-by: Paolo Bonzini Message-Id: <20210312173547.1283477-2-pbonzini@redhat.com> Signed-off-by: Kevin Wolf --- tests/unit/check-qom-proplist.c | 77 +++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 22 deletions(-) (limited to 'tests') diff --git a/tests/unit/check-qom-proplist.c b/tests/unit/check-qom-proplist.c index 1b76581..48503e0 100644 --- a/tests/unit/check-qom-proplist.c +++ b/tests/unit/check-qom-proplist.c @@ -21,6 +21,9 @@ #include "qemu/osdep.h" #include "qapi/error.h" +#include "qapi/qobject-input-visitor.h" +#include "qapi/qmp/qdict.h" +#include "qapi/qmp/qobject.h" #include "qom/object.h" #include "qemu/module.h" #include "qemu/option.h" @@ -398,44 +401,74 @@ static void test_dummy_createlist(void) object_unparent(OBJECT(dobj)); } +static bool test_create_obj(QDict *qdict, Error **errp) +{ + Visitor *v = qobject_input_visitor_new_keyval(QOBJECT(qdict)); + Object *obj = user_creatable_add_type(TYPE_DUMMY, "dev0", qdict, v, errp); + + visit_free(v); + object_unref(obj); + return !!obj; +} + static void test_dummy_createcmdl(void) { - QemuOpts *opts; + QDict *qdict; DummyObject *dobj; Error *err = NULL; - const char *params = TYPE_DUMMY \ - ",id=dev0," \ - "bv=yes,sv=Hiss hiss hiss,av=platypus"; + bool created, help; + const char *params = "bv=yes,sv=Hiss hiss hiss,av=platypus"; + /* Needed for user_creatable_del. */ qemu_add_opts(&qemu_object_opts); - opts = qemu_opts_parse(&qemu_object_opts, params, true, &err); + + qdict = keyval_parse(params, "qom-type", &help, &err); g_assert(err == NULL); - g_assert(opts); + g_assert(qdict); + g_assert(!help); - dobj = DUMMY_OBJECT(user_creatable_add_opts(opts, &err)); + created = test_create_obj(qdict, &err); + g_assert(created); g_assert(err == NULL); + qobject_unref(qdict); + + dobj = DUMMY_OBJECT(object_resolve_path_component(object_get_objects_root(), + "dev0")); g_assert(dobj); g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss"); g_assert(dobj->bv == true); g_assert(dobj->av == DUMMY_PLATYPUS); + qdict = keyval_parse(params, "qom-type", &help, &err); + created = test_create_obj(qdict, &err); + g_assert(!created); + g_assert(err); + g_assert(object_resolve_path_component(object_get_objects_root(), "dev0") + == OBJECT(dobj)); + qobject_unref(qdict); + error_free(err); + err = NULL; + + qdict = keyval_parse(params, "qom-type", &help, &err); user_creatable_del("dev0", &error_abort); + g_assert(object_resolve_path_component(object_get_objects_root(), "dev0") + == NULL); - object_unref(OBJECT(dobj)); - - /* - * cmdline-parsing via qemu_opts_parse() results in a QemuOpts entry - * corresponding to the Object's ID to be added to the QemuOptsList - * for objects. To avoid having this entry conflict with future - * Objects using the same ID (which can happen in cases where - * qemu_opts_parse() is used to parse the object params, such as - * with hmp_object_add() at the time of this comment), we need to - * check for this in user_creatable_del() and remove the QemuOpts if - * it is present. - * - * The below check ensures this works as expected. - */ - g_assert_null(qemu_opts_find(&qemu_object_opts, "dev0")); + created = test_create_obj(qdict, &err); + g_assert(created); + g_assert(err == NULL); + qobject_unref(qdict); + + dobj = DUMMY_OBJECT(object_resolve_path_component(object_get_objects_root(), + "dev0")); + g_assert(dobj); + g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss"); + g_assert(dobj->bv == true); + g_assert(dobj->av == DUMMY_PLATYPUS); + g_assert(object_resolve_path_component(object_get_objects_root(), "dev0") + == OBJECT(dobj)); + + object_unparent(OBJECT(dobj)); } static void test_dummy_badenum(void) -- cgit v1.1