From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39579) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJpLy-0000U4-Nh for qemu-devel@nongnu.org; Wed, 11 Sep 2013 14:41:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJpLo-0006nj-4L for qemu-devel@nongnu.org; Wed, 11 Sep 2013 14:41:26 -0400 Received: from mail-ea0-x236.google.com ([2a00:1450:4013:c01::236]:53248) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJpLn-0006me-Sv for qemu-devel@nongnu.org; Wed, 11 Sep 2013 14:41:16 -0400 Received: by mail-ea0-f182.google.com with SMTP id o10so4830338eaj.13 for ; Wed, 11 Sep 2013 11:41:14 -0700 (PDT) Message-ID: <1378924880.2186.11.camel@localhost.localdomain> From: Marcel Apfelbaum Date: Wed, 11 Sep 2013 21:41:20 +0300 In-Reply-To: <1378924006-14057-1-git-send-email-marcel.a@redhat.com> References: <1378924006-14057-1-git-send-email-marcel.a@redhat.com> Content-Type: text/plain; charset="UTF-8" Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] qdev-monitor: Avoid exiting when hot-plugging two devices with the same bootindex value List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: pbonzini@redhat.com, aliguori@us.ibm.com, afaerber@suse.de, sw@weilnetz.de On Wed, 2013-09-11 at 21:26 +0300, Marcel Apfelbaum wrote: > Qemu is expected to quit if the same boot index value is used by two devices. > However, hot-plugging a device with a bootindex value already used should > fail with a friendly message rather than quitting a running VM. > > Signed-off-by: Marcel Apfelbaum > --- > qdev-monitor.c | 33 +++++++++++++++++++++++++++++++++ > 1 file changed, 33 insertions(+) > > diff --git a/qdev-monitor.c b/qdev-monitor.c > index 410cdcb..654d086 100644 > --- a/qdev-monitor.c > +++ b/qdev-monitor.c > @@ -24,6 +24,7 @@ > #include "qmp-commands.h" > #include "sysemu/arch_init.h" > #include "qemu/config-file.h" > +#include "sysemu/sysemu.h" > > /* > * Aliases were a bad idea from the start. Let's keep them > @@ -442,6 +443,31 @@ static BusState *qbus_find(const char *path) > } > } > > +#define OBJ_PROP_BOOTINDEX "bootindex" A drawback of this patch is that is based on the assumption that all devices supporting boot ordering will have a property with the same name: bootindex. A more robust approach would be to have some kind of interface for such devices with a single "getter" method: bootindex() Any thoughts? Thanks, Marcel > + > +static bool bootindex_colision(Object *obj, QemuOpts *opts) > +{ > + int32_t bootindex; > + > + if (!object_property_find(obj, OBJ_PROP_BOOTINDEX, NULL)) { > + return false; > + } > + > + /* avoid parsing by setting the property and then getting it typed */ > + object_property_parse(obj, qemu_opt_get(opts, OBJ_PROP_BOOTINDEX), > + OBJ_PROP_BOOTINDEX, NULL); > + bootindex = (int32_t)object_property_get_int(obj, OBJ_PROP_BOOTINDEX, > + NULL); > + > + if (bootindex >= 0) { > + if (get_boot_device(bootindex)) { > + return true; > + } > + } > + > + return false; > +} > + > DeviceState *qdev_device_add(QemuOpts *opts) > { > ObjectClass *obj; > @@ -502,6 +528,13 @@ DeviceState *qdev_device_add(QemuOpts *opts) > /* create device, set properties */ > qdev = DEVICE(object_new(driver)); > > + if (qdev_hotplug && bootindex_colision(OBJECT(qdev), opts)) { > + qerror_report(QERR_INVALID_PARAMETER_VALUE, > + "bootindex", "an unused boot index value"); > + qdev_free(qdev); > + return NULL; > + } > + > if (bus) { > qdev_set_parent_bus(qdev, bus); > }