From patchwork Wed Sep 11 18:26:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcel Apfelbaum X-Patchwork-Id: 274350 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 79E8A2C0201 for ; Thu, 12 Sep 2013 04:27:11 +1000 (EST) Received: from localhost ([::1]:37431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJp88-0004zL-B9 for incoming@patchwork.ozlabs.org; Wed, 11 Sep 2013 14:27:08 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:34914) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJp7n-0004z7-47 for qemu-devel@nongnu.org; Wed, 11 Sep 2013 14:26:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJp7g-0001mF-V2 for qemu-devel@nongnu.org; Wed, 11 Sep 2013 14:26:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44855) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJp7g-0001lw-LM for qemu-devel@nongnu.org; Wed, 11 Sep 2013 14:26:40 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8BIQds6018459 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 11 Sep 2013 14:26:39 -0400 Received: from localhost.localdomain.com (vpn-203-95.tlv.redhat.com [10.35.203.95]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r8BIQaZc014529; Wed, 11 Sep 2013 14:26:37 -0400 From: Marcel Apfelbaum To: qemu-devel@nongnu.org Date: Wed, 11 Sep 2013 21:26:46 +0300 Message-Id: <1378924006-14057-1-git-send-email-marcel.a@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: pbonzini@redhat.com, aliguori@us.ibm.com, afaerber@suse.de, sw@weilnetz.de Subject: [Qemu-devel] [PATCH] qdev-monitor: Avoid exiting when hot-plugging two devices with the same bootindex value X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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" + +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); }