From f6f55affd1f1a1e297296922a6cc1a1b0d922c95 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 9 May 2017 12:56:01 +0200 Subject: [PATCH 1/4] block: Clarify documentation of BlockInfo member io-status Say "SCSI except scsi-generic" instead of "scsi-disk", because scsi-disk could mean either scsi-disk.c (which is correct) or device model scsi-disk (which would be incorrect). Signed-off-by: Markus Armbruster Message-Id: <1494327362-30727-2-git-send-email-armbru@redhat.com> Acked-by: Paolo Bonzini --- qapi/block-core.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qapi/block-core.json b/qapi/block-core.json index 88a7471a23..f85c2235c7 100644 --- a/qapi/block-core.json +++ b/qapi/block-core.json @@ -449,7 +449,8 @@ # # @io-status: @BlockDeviceIoStatus. Only present if the device # supports it and the VM is configured to stop on errors -# (supported device models: virtio-blk, ide, scsi-disk) +# (supported device models: virtio-blk, IDE, SCSI except +# scsi-generic) # # @inserted: @BlockDeviceInfo describing the device if media is # present From 8ee47a886fdae906e9b8734a7b0dc0a4c72d0aca Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 9 May 2017 12:56:02 +0200 Subject: [PATCH 2/4] virtio-scsi-test: Use scsi-hd instead of legacy scsi-disk Signed-off-by: Markus Armbruster Message-Id: <1494327362-30727-3-git-send-email-armbru@redhat.com> Acked-by: Paolo Bonzini --- tests/virtio-scsi-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/virtio-scsi-test.c b/tests/virtio-scsi-test.c index 8b0f77a63e..eff71df81f 100644 --- a/tests/virtio-scsi-test.c +++ b/tests/virtio-scsi-test.c @@ -149,7 +149,7 @@ static QVirtIOSCSI *qvirtio_scsi_pci_init(int slot) vs->qs = qvirtio_scsi_start("-drive file=blkdebug::null-co://," "if=none,id=dr1,format=raw,file.align=4k " - "-device scsi-disk,drive=dr1,lun=0,scsi-id=1"); + "-device scsi-hd,drive=dr1,lun=0,scsi-id=1"); dev = qvirtio_pci_device_find(vs->qs->pcibus, VIRTIO_ID_SCSI); vs->dev = (QVirtioDevice *)dev; g_assert(dev != NULL); From a1af255f065ccf3f47a7bfe88f1dbc9eeca36935 Mon Sep 17 00:00:00 2001 From: Michael Roth Date: Sat, 3 Jun 2017 18:13:31 -0500 Subject: [PATCH 3/4] tests: check-qom-proplist: add checks for cmdline-created objects check-qom-proplist originally added tests for verifying that object-creation helpers object_new_with_{props,propv} behaved in similar fashion to the "traditional" method involving setting each individual property separately after object creation rather than via a single call. Another similar "helper" for creating Objects exists in the form of objects specified via -object command-line parameters. By that rationale, we extend check-qom-proplist to include similar checks for command-line-created objects by employing the same qemu_opts_parse()-based parsing the vl.c employs. This parser has a side-effect of parsing the object's options into a QemuOpt structure and registering this in the global QemuOptsList using the Object's ID. This can conflict with future Object instances that attempt to use the same ID if we don't ensure this is cleaned up as part of Object finalization, so we include a FIXME stub to test for this case, which will then be resolved in a subsequent patch. Suggested-by: Daniel Berrange Cc: "Dr. David Alan Gilbert" Cc: Markus Armbruster Cc: Eric Blake Cc: Daniel Berrange Cc: qemu-stable@nongnu.org Signed-off-by: Michael Roth Reviewed-by: Markus Armbruster Message-Id: <1496531612-22166-2-git-send-email-mdroth@linux.vnet.ibm.com> [Comment formatting tidied up] Signed-off-by: Markus Armbruster --- tests/check-qom-proplist.c | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c index a16cefca73..e3b3ae473e 100644 --- a/tests/check-qom-proplist.c +++ b/tests/check-qom-proplist.c @@ -23,6 +23,9 @@ #include "qapi/error.h" #include "qom/object.h" #include "qemu/module.h" +#include "qemu/option.h" +#include "qemu/config-file.h" +#include "qom/object_interfaces.h" #define TYPE_DUMMY "qemu-dummy" @@ -162,6 +165,10 @@ static const TypeInfo dummy_info = { .instance_finalize = dummy_finalize, .class_size = sizeof(DummyObjectClass), .class_init = dummy_class_init, + .interfaces = (InterfaceInfo[]) { + { TYPE_USER_CREATABLE }, + { } + } }; @@ -320,6 +327,14 @@ static const TypeInfo dummy_backend_info = { .class_size = sizeof(DummyBackendClass), }; +static QemuOptsList qemu_object_opts = { + .name = "object", + .implied_opt_name = "qom-type", + .head = QTAILQ_HEAD_INITIALIZER(qemu_object_opts.head), + .desc = { + { } + }, +}; static void test_dummy_createv(void) @@ -388,6 +403,46 @@ static void test_dummy_createlist(void) object_unparent(OBJECT(dobj)); } +static void test_dummy_createcmdl(void) +{ + QemuOpts *opts; + DummyObject *dobj; + Error *err = NULL; + const char *params = TYPE_DUMMY \ + ",id=dev0," \ + "bv=yes,sv=Hiss hiss hiss,av=platypus"; + + qemu_add_opts(&qemu_object_opts); + opts = qemu_opts_parse(&qemu_object_opts, params, true, &err); + g_assert(err == NULL); + g_assert(opts); + + dobj = DUMMY_OBJECT(user_creatable_add_opts(opts, &err)); + g_assert(err == NULL); + g_assert(dobj); + g_assert_cmpstr(dobj->sv, ==, "Hiss hiss hiss"); + g_assert(dobj->bv == true); + g_assert(dobj->av == DUMMY_PLATYPUS); + + user_creatable_del("dev0", &err); + g_assert(err == NULL); + error_free(err); + + /* + * 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. + * + * FIXME: add an assert to verify that the QemuOpts is cleaned up + * once the corresponding cleanup code is added. + */ +} + static void test_dummy_badenum(void) { Error *err = NULL; @@ -525,6 +580,7 @@ int main(int argc, char **argv) g_test_add_func("/qom/proplist/createlist", test_dummy_createlist); g_test_add_func("/qom/proplist/createv", test_dummy_createv); + g_test_add_func("/qom/proplist/createcmdline", test_dummy_createcmdl); g_test_add_func("/qom/proplist/badenum", test_dummy_badenum); g_test_add_func("/qom/proplist/getenum", test_dummy_getenum); g_test_add_func("/qom/proplist/iterator", test_dummy_iterator); From c645d5acee0ae022534cb609184277ec2b4a8577 Mon Sep 17 00:00:00 2001 From: Michael Roth Date: Sat, 3 Jun 2017 18:13:32 -0500 Subject: [PATCH 4/4] monitor: fix object_del for command-line-created objects Currently objects specified on the command-line are only partially cleaned up when 'object_del' is issued in either HMP or QMP: the object itself is fully finalized, but the QemuOpts are not removed. This results in the following behavior: x86_64-softmmu/qemu-system-x86_64 -monitor stdio \ -object memory-backend-ram,id=ram1,size=256M QEMU 2.7.91 monitor - type 'help' for more information (qemu) object_del ram1 (qemu) object_del ram1 object 'ram1' not found (qemu) object_add memory-backend-ram,id=ram1,size=256M Duplicate ID 'ram1' for object Try "help object_add" for more information which can be an issue for use-cases like memory hotplug. This happens on the HMP side because hmp_object_add() attempts to create a temporary QemuOpts entry with ID 'ram1', which ends up conflicting with the command-line-created entry, since it was never cleaned up during the previous hmp_object_del() call. We address this by adding a check in user_creatable_del(), which is called by both qmp_object_del() and hmp_object_del() to handle the actual object cleanup, to determine whether an option group entry matching the object's ID is present and removing it if it is. Note that qmp_object_add() never attempts to create a temporary QemuOpts entry, so it does not encounter the duplicate ID error, which is why this isn't generally visible in libvirt. Cc: "Dr. David Alan Gilbert" Cc: Markus Armbruster Cc: Eric Blake Cc: Daniel Berrange Cc: qemu-stable@nongnu.org Signed-off-by: Michael Roth Reviewed-by: Daniel P. Berrange Reviewed-by: Markus Armbruster Message-Id: <1496531612-22166-3-git-send-email-mdroth@linux.vnet.ibm.com> Signed-off-by: Markus Armbruster --- qom/object_interfaces.c | 9 +++++++++ tests/check-qom-proplist.c | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/qom/object_interfaces.c b/qom/object_interfaces.c index d4253a88de..ff27e0669e 100644 --- a/qom/object_interfaces.c +++ b/qom/object_interfaces.c @@ -4,6 +4,7 @@ #include "qemu/module.h" #include "qapi-visit.h" #include "qapi/opts-visitor.h" +#include "qemu/config-file.h" void user_creatable_complete(Object *obj, Error **errp) { @@ -181,6 +182,14 @@ void user_creatable_del(const char *id, Error **errp) error_setg(errp, "object '%s' is in use, can not be deleted", id); return; } + + /* + * if object was defined on the command-line, remove its corresponding + * option group entry + */ + qemu_opts_del(qemu_opts_find(qemu_find_opts_err("object", &error_abort), + id)); + object_unparent(obj); } diff --git a/tests/check-qom-proplist.c b/tests/check-qom-proplist.c index e3b3ae473e..8e432e9ab6 100644 --- a/tests/check-qom-proplist.c +++ b/tests/check-qom-proplist.c @@ -438,9 +438,9 @@ static void test_dummy_createcmdl(void) * check for this in user_creatable_del() and remove the QemuOpts if * it is present. * - * FIXME: add an assert to verify that the QemuOpts is cleaned up - * once the corresponding cleanup code is added. + * The below check ensures this works as expected. */ + g_assert_null(qemu_opts_find(&qemu_object_opts, "dev0")); } static void test_dummy_badenum(void)