[{"id":1800546,"web_url":"http://patchwork.ozlabs.org/comment/1800546/","msgid":"<20171107151705.34ae33a7.cohuck@redhat.com>","list_archive_url":null,"date":"2017-11-07T14:17:05","subject":"Re: [Qemu-devel] [PATCH v3 2/2] qdev: Check for the availability of\n\ta hotplug controller before adding a device","submitter":{"id":71914,"url":"http://patchwork.ozlabs.org/api/people/71914/","name":"Cornelia Huck","email":"cohuck@redhat.com"},"content":"On Thu,  2 Nov 2017 11:10:06 +0100\nThomas Huth <thuth@redhat.com> wrote:\n\n> The qdev_unplug() function contains a g_assert(hotplug_ctrl) statement,\n> so QEMU crashes when the user tries to device_add + device_del a device\n> that does not have a corresponding hotplug controller. This could be\n> provoked for a couple of devices in the past (see commit 4c93950659487c7ad\n> or 84ebd3e8c7d4fe955 for example), and can currently for example also be\n> triggered like this:\n> \n> $ s390x-softmmu/qemu-system-s390x -M none -nographic \n> QEMU 2.10.50 monitor - type 'help' for more information\n> (qemu) device_add qemu-s390x-cpu,id=x\n> (qemu) device_del x\n> **\n> ERROR:qemu/qdev-monitor.c:872:qdev_unplug: assertion failed: (hotplug_ctrl)\n> Aborted (core dumped)\n> \n> So devices clearly need a hotplug controller when they should be usable\n> with device_add.\n> The code in qdev_device_add() already checks whether the bus has a proper\n> hotplug controller, but for devices that do not have a corresponding bus,\n> there is no appropriate check available yet. In that case we should check\n> whether the machine itself provides a suitable hotplug controller and\n> refuse to plug the device if none is available.\n> \n> Reviewed-by: Igor Mammedov <imammedo@redhat.com>\n> Signed-off-by: Thomas Huth <thuth@redhat.com>\n> ---\n>  hw/core/qdev.c         | 28 ++++++++++++++++++++--------\n>  include/hw/qdev-core.h |  1 +\n>  qdev-monitor.c         |  5 +++++\n>  3 files changed, 26 insertions(+), 8 deletions(-)\n\nReviewed-by: Cornelia Huck <cohuck@redhat.com>","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","ext-mx09.extmail.prod.ext.phx2.redhat.com;\n\tdmarc=none (p=none dis=none) header.from=redhat.com","ext-mx09.extmail.prod.ext.phx2.redhat.com;\n\tspf=fail smtp.mailfrom=cohuck@redhat.com"],"Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3yWWjq31pjz9ryk\n\tfor <incoming@patchwork.ozlabs.org>;\n\tWed,  8 Nov 2017 01:18:05 +1100 (AEDT)","from localhost ([::1]:53652 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1eC4hW-0004GT-NZ\n\tfor incoming@patchwork.ozlabs.org; Tue, 07 Nov 2017 09:18:02 -0500","from eggs.gnu.org ([2001:4830:134:3::10]:48899)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <cohuck@redhat.com>) id 1eC4go-00045B-6r\n\tfor qemu-devel@nongnu.org; Tue, 07 Nov 2017 09:17:19 -0500","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <cohuck@redhat.com>) id 1eC4gk-00027W-Js\n\tfor qemu-devel@nongnu.org; Tue, 07 Nov 2017 09:17:17 -0500","from mx1.redhat.com ([209.132.183.28]:41072)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <cohuck@redhat.com>) id 1eC4gk-000278-D8\n\tfor qemu-devel@nongnu.org; Tue, 07 Nov 2017 09:17:14 -0500","from smtp.corp.redhat.com\n\t(int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 3723F4AFC\n\tfor <qemu-devel@nongnu.org>; Tue,  7 Nov 2017 14:17:13 +0000 (UTC)","from gondolin (ovpn-117-156.ams2.redhat.com [10.36.117.156])\n\tby smtp.corp.redhat.com (Postfix) with ESMTP id 7260660BE3;\n\tTue,  7 Nov 2017 14:17:08 +0000 (UTC)"],"DMARC-Filter":"OpenDMARC Filter v1.3.2 mx1.redhat.com 3723F4AFC","Date":"Tue, 7 Nov 2017 15:17:05 +0100","From":"Cornelia Huck <cohuck@redhat.com>","To":"Thomas Huth <thuth@redhat.com>","Message-ID":"<20171107151705.34ae33a7.cohuck@redhat.com>","In-Reply-To":"<1509617407-21191-3-git-send-email-thuth@redhat.com>","References":"<1509617407-21191-1-git-send-email-thuth@redhat.com>\n\t<1509617407-21191-3-git-send-email-thuth@redhat.com>","Organization":"Red Hat GmbH","MIME-Version":"1.0","Content-Type":"text/plain; charset=US-ASCII","Content-Transfer-Encoding":"7bit","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.12","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.38]);\n\tTue, 07 Nov 2017 14:17:13 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] [PATCH v3 2/2] qdev: Check for the availability of\n\ta hotplug controller before adding a device","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Eduardo Habkost <ehabkost@redhat.com>, david@redhat.com,\n\tMarkus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org,\n\tPaolo Bonzini <pbonzini@redhat.com>,\n\tIgor Mammedov <imammedo@redhat.com>, \n\t\"Dr. David Alan Gilbert\" <dgilbert@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1803717,"web_url":"http://patchwork.ozlabs.org/comment/1803717/","msgid":"<87vaiecm8s.fsf@dusky.pond.sub.org>","list_archive_url":null,"date":"2017-11-13T14:00:03","subject":"Re: [Qemu-devel] [PATCH v3 2/2] qdev: Check for the availability of\n\ta hotplug controller before adding a device","submitter":{"id":2645,"url":"http://patchwork.ozlabs.org/api/people/2645/","name":"Markus Armbruster","email":"armbru@redhat.com"},"content":"Thomas Huth <thuth@redhat.com> writes:\n\n> The qdev_unplug() function contains a g_assert(hotplug_ctrl) statement,\n> so QEMU crashes when the user tries to device_add + device_del a device\n> that does not have a corresponding hotplug controller. This could be\n> provoked for a couple of devices in the past (see commit 4c93950659487c7ad\n> or 84ebd3e8c7d4fe955 for example), and can currently for example also be\n> triggered like this:\n>\n> $ s390x-softmmu/qemu-system-s390x -M none -nographic \n> QEMU 2.10.50 monitor - type 'help' for more information\n> (qemu) device_add qemu-s390x-cpu,id=x\n> (qemu) device_del x\n> **\n> ERROR:qemu/qdev-monitor.c:872:qdev_unplug: assertion failed: (hotplug_ctrl)\n> Aborted (core dumped)\n>\n> So devices clearly need a hotplug controller when they should be usable\n> with device_add.\n> The code in qdev_device_add() already checks whether the bus has a proper\n> hotplug controller,\n\nWhere?  Hmm, I guess it's this one:\n\n    if (qdev_hotplug && bus && !qbus_is_hotpluggable(bus)) {\n        error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name);\n        return NULL;\n    }\n\n>                     but for devices that do not have a corresponding bus,\n> there is no appropriate check available yet. In that case we should check\n> whether the machine itself provides a suitable hotplug controller and\n> refuse to plug the device if none is available.\n>\n> Reviewed-by: Igor Mammedov <imammedo@redhat.com>\n> Signed-off-by: Thomas Huth <thuth@redhat.com>\n> ---\n>  hw/core/qdev.c         | 28 ++++++++++++++++++++--------\n>  include/hw/qdev-core.h |  1 +\n>  qdev-monitor.c         |  5 +++++\n>  3 files changed, 26 insertions(+), 8 deletions(-)\n>\n> diff --git a/hw/core/qdev.c b/hw/core/qdev.c\n> index 1111295..f739753 100644\n> --- a/hw/core/qdev.c\n> +++ b/hw/core/qdev.c\n> @@ -253,19 +253,31 @@ void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,\n>      dev->alias_required_for_version = required_for_version;\n>  }\n>  \n> +HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev)\n> +{\n> +    MachineState *machine;\n> +    MachineClass *mc;\n> +    Object *m_obj = qdev_get_machine();\n> +\n> +    if (object_dynamic_cast(m_obj, TYPE_MACHINE)) {\n> +        machine = MACHINE(m_obj);\n> +        mc = MACHINE_GET_CLASS(machine);\n> +        if (mc->get_hotplug_handler) {\n> +            return mc->get_hotplug_handler(machine, dev);\n> +        }\n> +    }\n> +\n> +    return NULL;\n> +}\n> +\n>  HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev)\n>  {\n> -    HotplugHandler *hotplug_ctrl = NULL;\n> +    HotplugHandler *hotplug_ctrl;\n>  \n>      if (dev->parent_bus && dev->parent_bus->hotplug_handler) {\n>          hotplug_ctrl = dev->parent_bus->hotplug_handler;\n> -    } else if (object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) {\n> -        MachineState *machine = MACHINE(qdev_get_machine());\n> -        MachineClass *mc = MACHINE_GET_CLASS(machine);\n> -\n> -        if (mc->get_hotplug_handler) {\n> -            hotplug_ctrl = mc->get_hotplug_handler(machine, dev);\n> -        }\n> +    } else {\n> +        hotplug_ctrl = qdev_get_machine_hotplug_handler(dev);\n>      }\n>      return hotplug_ctrl;\n>  }\n\nqdev_get_machine_hotplug_handler() factored out of\nqdev_get_hotplug_handler().  Okay.  Announcing it in the commit message\ncould've saved me a few review brainwaves.\n\n> diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h\n> index 0a71bf8..51473ee 100644\n> --- a/include/hw/qdev-core.h\n> +++ b/include/hw/qdev-core.h\n> @@ -286,6 +286,7 @@ DeviceState *qdev_try_create(BusState *bus, const char *name);\n>  void qdev_init_nofail(DeviceState *dev);\n>  void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id,\n>                                   int required_for_version);\n> +HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev);\n>  HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev);\n>  void qdev_unplug(DeviceState *dev, Error **errp);\n>  void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev,\n> diff --git a/qdev-monitor.c b/qdev-monitor.c\n> index 9188d20..38c0fc2 100644\n> --- a/qdev-monitor.c\n> +++ b/qdev-monitor.c\n> @@ -614,6 +614,11 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)\n>  \n       if (qdev_hotplug && bus && !qbus_is_hotpluggable(bus)) {\n           error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name);\n           return NULL;\n       }\n\n       if (!migration_is_idle()) {\n           error_setg(errp, \"device_add not allowed while migrating\");\n           return NULL;\n       }\n\n       /* create device */\n       dev = DEVICE(object_new(driver));\n\n>      if (bus) {\n>          qdev_set_parent_bus(dev, bus);\n> +    } else if (qdev_hotplug && !qdev_get_machine_hotplug_handler(dev)) {\n> +        /* No bus, no machine hotplug handler --> device is not hotpluggable */\n\nLong line.\n\n> +        error_setg(&err, \"Device '%s' can not be hotplugged on this machine\",\n> +                   driver);\n> +        goto err_del_dev;\n>      }\n>  \n>      qdev_set_id(dev, qemu_opts_id(opts));\n\nHmm.  We need to check \"can hotplug\" in two separate ways, with bus and\nwithout bus.  Can we keep the two ways on one place?  Something like\n\n       if (qdev_hotplug) {\n           if (bus && !qbus_is_hotpluggable(bus)) {\n               error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name);\n               return NULL;\n           }\n           if (!bus && !qdev_get_machine_hotplug_handler(dev)) {\n               error_setg(&err,\n                          \"Machine doesn't support hot-plugging device '%s'\"\n                          driver);\n               return NULL;\n           }\n      }","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3ybC3N3F0Sz9s8J\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 14 Nov 2017 01:01:04 +1100 (AEDT)","from localhost ([::1]:54542 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1eEFIM-00087w-Id\n\tfor incoming@patchwork.ozlabs.org; Mon, 13 Nov 2017 09:01:02 -0500","from eggs.gnu.org ([2001:4830:134:3::10]:44205)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <armbru@redhat.com>) id 1eEFHl-00084q-7e\n\tfor qemu-devel@nongnu.org; Mon, 13 Nov 2017 09:00:30 -0500","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <armbru@redhat.com>) id 1eEFHh-0003Gb-0U\n\tfor qemu-devel@nongnu.org; Mon, 13 Nov 2017 09:00:25 -0500","from mx1.redhat.com ([209.132.183.28]:43004)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <armbru@redhat.com>) id 1eEFHg-0003GB-L0\n\tfor qemu-devel@nongnu.org; Mon, 13 Nov 2017 09:00:20 -0500","from smtp.corp.redhat.com\n\t(int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id B73CE7EA9A\n\tfor <qemu-devel@nongnu.org>; Mon, 13 Nov 2017 14:00:19 +0000 (UTC)","from blackfin.pond.sub.org (ovpn-116-30.ams2.redhat.com\n\t[10.36.116.30])\n\tby smtp.corp.redhat.com (Postfix) with ESMTPS id B65277FB65;\n\tMon, 13 Nov 2017 14:00:05 +0000 (UTC)","by blackfin.pond.sub.org (Postfix, from userid 1000)\n\tid CF7A31138647; Mon, 13 Nov 2017 15:00:03 +0100 (CET)"],"From":"Markus Armbruster <armbru@redhat.com>","To":"Thomas Huth <thuth@redhat.com>","References":"<1509617407-21191-1-git-send-email-thuth@redhat.com>\n\t<1509617407-21191-3-git-send-email-thuth@redhat.com>","Date":"Mon, 13 Nov 2017 15:00:03 +0100","In-Reply-To":"<1509617407-21191-3-git-send-email-thuth@redhat.com> (Thomas\n\tHuth's message of \"Thu, 2 Nov 2017 11:10:06 +0100\")","Message-ID":"<87vaiecm8s.fsf@dusky.pond.sub.org>","User-Agent":"Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)","MIME-Version":"1.0","Content-Type":"text/plain","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.11","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.28]);\n\tMon, 13 Nov 2017 14:00:19 +0000 (UTC)","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] [PATCH v3 2/2] qdev: Check for the availability of\n\ta hotplug controller before adding a device","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Eduardo Habkost <ehabkost@redhat.com>, david@redhat.com,\n\tqemu-devel@nongnu.org, \"Dr. David Alan Gilbert\" <dgilbert@redhat.com>,\n\tPaolo Bonzini <pbonzini@redhat.com>, Igor Mammedov <imammedo@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}},{"id":1803728,"web_url":"http://patchwork.ozlabs.org/comment/1803728/","msgid":"<4ca401d1-4e3b-01c7-ab56-71aa524d49c1@redhat.com>","list_archive_url":null,"date":"2017-11-13T14:12:31","subject":"Re: [Qemu-devel] [PATCH v3 2/2] qdev: Check for the availability of\n\ta hotplug controller before adding a device","submitter":{"id":66152,"url":"http://patchwork.ozlabs.org/api/people/66152/","name":"Thomas Huth","email":"thuth@redhat.com"},"content":"On 13.11.2017 15:00, Markus Armbruster wrote:\n> Thomas Huth <thuth@redhat.com> writes:\n> \n>> The qdev_unplug() function contains a g_assert(hotplug_ctrl) statement,\n>> so QEMU crashes when the user tries to device_add + device_del a device\n>> that does not have a corresponding hotplug controller. This could be\n>> provoked for a couple of devices in the past (see commit 4c93950659487c7ad\n>> or 84ebd3e8c7d4fe955 for example), and can currently for example also be\n>> triggered like this:\n>>\n>> $ s390x-softmmu/qemu-system-s390x -M none -nographic \n>> QEMU 2.10.50 monitor - type 'help' for more information\n>> (qemu) device_add qemu-s390x-cpu,id=x\n>> (qemu) device_del x\n>> **\n>> ERROR:qemu/qdev-monitor.c:872:qdev_unplug: assertion failed: (hotplug_ctrl)\n>> Aborted (core dumped)\n>>\n>> So devices clearly need a hotplug controller when they should be usable\n>> with device_add.\n>> The code in qdev_device_add() already checks whether the bus has a proper\n>> hotplug controller,\n> \n> Where?  Hmm, I guess it's this one:\n> \n>     if (qdev_hotplug && bus && !qbus_is_hotpluggable(bus)) {\n>         error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name);\n>         return NULL;\n>     }\n\nRight.\n\n>>                     but for devices that do not have a corresponding bus,\n>> there is no appropriate check available yet. In that case we should check\n>> whether the machine itself provides a suitable hotplug controller and\n>> refuse to plug the device if none is available.\n[...]\n>> diff --git a/qdev-monitor.c b/qdev-monitor.c\n>> index 9188d20..38c0fc2 100644\n>> --- a/qdev-monitor.c\n>> +++ b/qdev-monitor.c\n>> @@ -614,6 +614,11 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **errp)\n>>  \n>        if (qdev_hotplug && bus && !qbus_is_hotpluggable(bus)) {\n>            error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name);\n>            return NULL;\n>        }\n> \n>        if (!migration_is_idle()) {\n>            error_setg(errp, \"device_add not allowed while migrating\");\n>            return NULL;\n>        }\n> \n>        /* create device */\n>        dev = DEVICE(object_new(driver));\n> \n>>      if (bus) {\n>>          qdev_set_parent_bus(dev, bus);\n>> +    } else if (qdev_hotplug && !qdev_get_machine_hotplug_handler(dev)) {\n>> +        /* No bus, no machine hotplug handler --> device is not hotpluggable */\n> \n> Long line.\n\nLess than 80 columns, so that's fine.\n\n>> +        error_setg(&err, \"Device '%s' can not be hotplugged on this machine\",\n>> +                   driver);\n>> +        goto err_del_dev;\n>>      }\n>>  \n>>      qdev_set_id(dev, qemu_opts_id(opts));\n> \n> Hmm.  We need to check \"can hotplug\" in two separate ways, with bus and\n> without bus.  Can we keep the two ways on one place?  Something like\n> \n>        if (qdev_hotplug) {\n>            if (bus && !qbus_is_hotpluggable(bus)) {\n>                error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name);\n>                return NULL;\n>            }\n>            if (!bus && !qdev_get_machine_hotplug_handler(dev)) {\n>                error_setg(&err,\n>                           \"Machine doesn't support hot-plugging device '%s'\"\n>                           driver);\n>                return NULL;\n>            }\n>       }\n\nWe likely could ... but I don't like that change since in that case\nyou've got to always do \"dev = DEVICE(object_new(driver))\" (and the code\nneeds to be at the end of the function, so it would need \"goto\nerr_del_dev\" instead of \"return NULL\"). If we keep the checks separate,\nthe first check can bail out without creating the device first, so I'd\nreally prefer to keep my patch that way.\n\n Thomas","headers":{"Return-Path":"<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":"ozlabs.org;\n\tspf=pass (mailfrom) smtp.mailfrom=nongnu.org\n\t(client-ip=2001:4830:134:3::11; helo=lists.gnu.org;\n\tenvelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org;\n\treceiver=<UNKNOWN>)","Received":["from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11])\n\t(using TLSv1 with cipher AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3ybCMC1H3xz9s8J\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 14 Nov 2017 01:14:47 +1100 (AEDT)","from localhost ([::1]:54628 helo=lists.gnu.org)\n\tby lists.gnu.org with esmtp (Exim 4.71) (envelope-from\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>)\n\tid 1eEFVd-00077j-5H\n\tfor incoming@patchwork.ozlabs.org; Mon, 13 Nov 2017 09:14:45 -0500","from eggs.gnu.org ([2001:4830:134:3::10]:48423)\n\tby lists.gnu.org with esmtp (Exim 4.71)\n\t(envelope-from <thuth@redhat.com>) id 1eEFTq-00067q-JC\n\tfor qemu-devel@nongnu.org; Mon, 13 Nov 2017 09:13:00 -0500","from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)\n\t(envelope-from <thuth@redhat.com>) id 1eEFTl-0000Ee-GI\n\tfor qemu-devel@nongnu.org; Mon, 13 Nov 2017 09:12:54 -0500","from mx1.redhat.com ([209.132.183.28]:37208)\n\tby eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32)\n\t(Exim 4.71) (envelope-from <thuth@redhat.com>) id 1eEFTl-0000Dr-7Y\n\tfor qemu-devel@nongnu.org; Mon, 13 Nov 2017 09:12:49 -0500","from smtp.corp.redhat.com\n\t(int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16])\n\t(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))\n\t(No client certificate requested)\n\tby mx1.redhat.com (Postfix) with ESMTPS id 747A6C0587FA\n\tfor <qemu-devel@nongnu.org>; Mon, 13 Nov 2017 14:12:48 +0000 (UTC)","from [10.36.116.94] (ovpn-116-94.ams2.redhat.com [10.36.116.94])\n\tby smtp.corp.redhat.com (Postfix) with ESMTPS id 05DED7B121;\n\tMon, 13 Nov 2017 14:12:32 +0000 (UTC)"],"To":"Markus Armbruster <armbru@redhat.com>","References":"<1509617407-21191-1-git-send-email-thuth@redhat.com>\n\t<1509617407-21191-3-git-send-email-thuth@redhat.com>\n\t<87vaiecm8s.fsf@dusky.pond.sub.org>","From":"Thomas Huth <thuth@redhat.com>","Message-ID":"<4ca401d1-4e3b-01c7-ab56-71aa524d49c1@redhat.com>","Date":"Mon, 13 Nov 2017 15:12:31 +0100","User-Agent":"Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101\n\tThunderbird/52.4.0","MIME-Version":"1.0","In-Reply-To":"<87vaiecm8s.fsf@dusky.pond.sub.org>","Content-Type":"text/plain; charset=utf-8","Content-Language":"en-US","X-Scanned-By":"MIMEDefang 2.79 on 10.5.11.16","X-Greylist":"Sender IP whitelisted, not delayed by milter-greylist-4.5.16\n\t(mx1.redhat.com [10.5.110.32]);\n\tMon, 13 Nov 2017 14:12:48 +0000 (UTC)","Content-Transfer-Encoding":"quoted-printable","X-detected-operating-system":"by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]\n\t[fuzzy]","X-Received-From":"209.132.183.28","Subject":"Re: [Qemu-devel] [PATCH v3 2/2] qdev: Check for the availability of\n\ta hotplug controller before adding a device","X-BeenThere":"qemu-devel@nongnu.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"<qemu-devel.nongnu.org>","List-Unsubscribe":"<https://lists.nongnu.org/mailman/options/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>","List-Archive":"<http://lists.nongnu.org/archive/html/qemu-devel/>","List-Post":"<mailto:qemu-devel@nongnu.org>","List-Help":"<mailto:qemu-devel-request@nongnu.org?subject=help>","List-Subscribe":"<https://lists.nongnu.org/mailman/listinfo/qemu-devel>,\n\t<mailto:qemu-devel-request@nongnu.org?subject=subscribe>","Cc":"Eduardo Habkost <ehabkost@redhat.com>, david@redhat.com,\n\tqemu-devel@nongnu.org, \"Dr. David Alan Gilbert\" <dgilbert@redhat.com>,\n\tPaolo Bonzini <pbonzini@redhat.com>, Igor Mammedov <imammedo@redhat.com>","Errors-To":"qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org","Sender":"\"Qemu-devel\"\n\t<qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org>"}}]