From patchwork Thu Sep 24 14:16:01 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 34223 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 40504B7B69 for ; Fri, 25 Sep 2009 00:18:17 +1000 (EST) Received: from localhost ([127.0.0.1]:58497 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mqp9C-0007FS-AR for incoming@patchwork.ozlabs.org; Thu, 24 Sep 2009 10:18:14 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mqp7H-0006Vy-Jq for qemu-devel@nongnu.org; Thu, 24 Sep 2009 10:16:15 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mqp7C-0006SP-Jx for qemu-devel@nongnu.org; Thu, 24 Sep 2009 10:16:14 -0400 Received: from [199.232.76.173] (port=57926 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mqp7C-0006SH-Ay for qemu-devel@nongnu.org; Thu, 24 Sep 2009 10:16:10 -0400 Received: from mx1.redhat.com ([209.132.183.28]:1911) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mqp7B-0003IT-TQ for qemu-devel@nongnu.org; Thu, 24 Sep 2009 10:16:10 -0400 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n8OEG89V027568 for ; Thu, 24 Sep 2009 10:16:08 -0400 Received: from doriath (vpn-12-255.rdu.redhat.com [10.11.12.255]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id n8OEG4A2031207 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Thu, 24 Sep 2009 10:16:07 -0400 Date: Thu, 24 Sep 2009 11:16:01 -0300 From: Luiz Capitulino To: qemu-devel@nongnu.org Message-ID: <20090924111601.1d3668d2@doriath> Organization: Red Hat Mime-Version: 1.0 X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH] Fix exit on 'pci_add' Monitor command X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org If the user issues one of the following commands to the Monitor: pci_add pci_addr=auto nic model=None pci_add pci_addr=auto nic model=? QEMU will exit, because the function used to perform sanity checks (qemu_check_nic_model_list()) exits on error. This function is used by the startup code, where it makes sense to exit on error, but in the Monitor it doesn't. Changing qemu_check_nic_model_list() to not exit on error is not possible though, as it's used by the board init code (the PC one), where all board specific code must have void return. The way I've chosen to fix this was to introduce a new function called pci_nic_supported(), which checks if the NIC is supported and returns true or false accordingly. The new function is used only by the Monitor, it performs the necessary check and returns an error in case the NIC is not supported, thus qemu_check_nic_model_list()'s exit is never trigged. The following should be observed: 1. Only the specified NIC is checked, the default one is assumed to be supported 2. The NIC query command (model=?) won't work with pci_add, the right way to do this with the Monitor is to add a new command Signed-off-by: Luiz Capitulino --- hw/pci-hotplug.c | 4 ++++ hw/pci.c | 11 +++++++++++ hw/pci.h | 1 + 3 files changed, 16 insertions(+), 0 deletions(-) diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c index f3dc421..89974a0 100644 --- a/hw/pci-hotplug.c +++ b/hw/pci-hotplug.c @@ -46,6 +46,10 @@ static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, monitor_printf(mon, "Parameter addr not supported\n"); return NULL; } + + if (nd_table[ret].model && !pci_nic_supported(nd_table[ret].model)) + return NULL; + return pci_nic_init(&nd_table[ret], "rtl8139", devaddr); } diff --git a/hw/pci.c b/hw/pci.c index 64d70ed..c5975bc 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -806,6 +806,17 @@ static const char * const pci_nic_names[] = { NULL }; +int pci_nic_supported(const char *model) +{ + int i; + + for (i = 0; pci_nic_names[i]; i++) + if (strcmp(model, pci_nic_names[i]) == 0) + return 1; + + return 0; +} + /* Initialize a PCI NIC. */ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model, const char *default_devaddr) diff --git a/hw/pci.h b/hw/pci.h index caba5c8..ba748ff 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -252,6 +252,7 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq, void *irq_opaque, int devfn_min, int nirq); +int pci_nic_supported(const char *model); PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model, const char *default_devaddr); void pci_data_write(void *opaque, uint32_t addr, uint32_t val, int len);