From nobody Sat Oct 25 08:50:07 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1520365763443931.6778979300277; Tue, 6 Mar 2018 11:49:23 -0800 (PST) Received: from localhost ([::1]:57805 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etIaQ-0008SO-PA for importer@patchew.org; Tue, 06 Mar 2018 14:49:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59345) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1etIXH-00068l-FV for qemu-devel@nongnu.org; Tue, 06 Mar 2018 14:46:08 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1etIXG-0001ZY-HD for qemu-devel@nongnu.org; Tue, 06 Mar 2018 14:46:07 -0500 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]:43597) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1etIXG-0001ZR-AG for qemu-devel@nongnu.org; Tue, 06 Mar 2018 14:46:06 -0500 Received: by mail-wr0-x241.google.com with SMTP id u49so22157008wrc.10 for ; Tue, 06 Mar 2018 11:46:06 -0800 (PST) Received: from donizetti.lan (94-36-191-219.adsl-ull.clienti.tiscali.it. [94.36.191.219]) by smtp.gmail.com with ESMTPSA id f206sm2104942wmf.26.2018.03.06.11.46.03 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 06 Mar 2018 11:46:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=42RN1shk4v1jxkF/+r5Amfj9L9p9f2pda7+zLB3ksOU=; b=TKZ8ghodNHQuDuIdtiP0DoQLAt67/7Twpl33bdQzfwosffIuGTvEZRMmJmQLIyBKOA CEQo0zweCHK/LahtCE0gNPQ7KDifBYCBm7xrFzbon5oAHONvkEd3uWaRGJJMED9yeUwY 8wZM0TMKvZOzLoQeF1Jm0/InSQbG8Yndpq1XQdzLlJtoM5ibGjRZdNqy0pqHBnBeQ/eq YiR3PK+lyl9XEe7xVDi4XFtKWmV32iOsFZtn6C2bKi+Qky8PlHfRYFyqFbebZfad+9UL iOvMWtd0oWWp+BGh7ZwgFQZ61786KIPcdj+I5Ff0w4gUxTcIGkiqc5E567EgaGiYmDN+ ZfRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=42RN1shk4v1jxkF/+r5Amfj9L9p9f2pda7+zLB3ksOU=; b=JHfOd2bhQfaHPENsrGzwcyVFFA6q/RiTWXoQlt6v4TcpnKWV8k7NJLVZDCZDPZN4Qt GOAKUG1JSLWtxcjzwR30ZJ0G6GW152LBrZ9tVGE4tKT1/X/Lmrm9st3ig+NxCOmRFa/c CS2T0S7lYDIoaG+NpEU9DmQmd48hFr5gRwOxu4lIsLrl2Pyh3apSjttJyT+hTWPq25n1 g2vVzD1wHGZ+RwVXzqAR3I+HFQ5B3bUCTeQ7XTVkDsg5oKqC9iylg/K0U3O/4pSm5hsH IIA53qlzUpz6DO1YzZgCXnmapJ9bJi3S+yTRMmpM/YjpIE/ZIRcOxNHbcEFnW9O5psf7 k23g== X-Gm-Message-State: APf1xPAV9PkMXNTPKQyJzWMMQKq7WUy0nuEIr5rviWPvVrITV7K0QQNs E+xQ+fIPwsShLwIBS1hTWebuCcIm X-Google-Smtp-Source: AG47ELsB8PvwLqYu5zyQWc0a8uS3LFezUGMKPyXQ9HKkFyk1JuPfTMGkTDPkYU40OpSFqF8f8wtEhQ== X-Received: by 10.223.130.76 with SMTP id 70mr16530628wrb.95.1520365564763; Tue, 06 Mar 2018 11:46:04 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Tue, 6 Mar 2018 20:45:59 +0100 Message-Id: <20180306194600.9650-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180306194600.9650-1-pbonzini@redhat.com> References: <20180306194600.9650-1-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::241 Subject: [Qemu-devel] [PATCH 2/3] net: allow using any PCI NICs in -net or -nic X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Huth , Jason Wang Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Remove the hard-coded list of PCI NIC names; instead, fill an array using all PCI devices listed under DEVICE_CATEGORY_NETWORK. Keep the old shortcut "virtio" for virtio-net-pci. Suggested-by: Thomas Huth Cc: Jason Wang Signed-off-by: Paolo Bonzini --- hw/pci/pci.c | 61 ++++++++++++++++++++++++++++++--------------------------= ---- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 2174c254eb..aa24a26680 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1815,49 +1815,48 @@ PciInfoList *qmp_query_pci(Error **errp) return head; } =20 -static const char * const pci_nic_models[] =3D { - "ne2k_pci", - "i82551", - "i82557b", - "i82559er", - "rtl8139", - "e1000", - "pcnet", - "virtio", - "sungem", - NULL -}; - -static const char * const pci_nic_names[] =3D { - "ne2k_pci", - "i82551", - "i82557b", - "i82559er", - "rtl8139", - "e1000", - "pcnet", - "virtio-net-pci", - "sungem", - NULL -}; - /* Initialize a PCI NIC. */ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *rootbus, const char *default_model, const char *default_devaddr) { const char *devaddr =3D nd->devaddr ? nd->devaddr : default_devaddr; + GSList *list; + GPtrArray *pci_nic_models; PCIBus *bus; PCIDevice *pci_dev; DeviceState *dev; int devfn; int i; =20 - if (qemu_show_nic_models(nd->model, pci_nic_models)) { + if (!strcmp(nd->model, "virtio")) { + g_free(nd->model); + nd->model =3D g_strdup("virtio-net-pci"); + } + + list =3D object_class_get_list_sorted(TYPE_PCI_DEVICE, false); + pci_nic_models =3D g_ptr_array_new_with_free_func(g_free); + while (list) { + DeviceClass *dc =3D OBJECT_CLASS_CHECK(DeviceClass, list->data, + TYPE_DEVICE); + GSList *next; + if (test_bit(DEVICE_CATEGORY_NETWORK, dc->categories) && + dc->user_creatable) { + const char *name =3D object_class_get_name(list->data) ; + g_ptr_array_add(pci_nic_models, (gpointer)name); + } + next =3D list->next; + g_slist_free_1(list); + list =3D next; + } + g_ptr_array_add(pci_nic_models, NULL); + + if (qemu_show_nic_models(nd->model, (const char **)pci_nic_models->pda= ta)) { exit(0); } =20 - i =3D qemu_find_nic_model(nd, pci_nic_models, default_model); + i =3D qemu_find_nic_model(nd, (const char **)pci_nic_models->pdata, + default_model); if (i < 0) { exit(1); } @@ -1865,15 +1864,15 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus = *rootbus, bus =3D pci_get_bus_devfn(&devfn, rootbus, devaddr); if (!bus) { error_report("Invalid PCI device address %s for device %s", - devaddr, pci_nic_names[i]); + devaddr, nd->model); exit(1); } =20 - pci_dev =3D pci_create(bus, devfn, pci_nic_names[i]); + pci_dev =3D pci_create(bus, devfn, nd->model); dev =3D &pci_dev->qdev; qdev_set_nic_properties(dev, nd); qdev_init_nofail(dev); - + g_ptr_array_free(pci_nic_models, true); return pci_dev; } =20 --=20 2.14.3