From nobody Wed Jan 15 11:53:59 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1676612739; cv=none; d=zohomail.com; s=zohoarc; b=ALAjd5CoTAlYNIkiTBtGvJm15yHJ5tm/upAaIjkcPW3VZYfhwSX6bJ1FMQzlAKqWsuvvGaQyZODcDjJHBx1LrNGFLZGwxo9ZuII5PvXLyUfVASLftyuQjrI+PzMj/qg2ddrS4QL2IdyN3JYnQKxGi/4j7lHmm8ekbwQExpB8faU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1676612739; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Xz/5bAkleicl62MdzztWocE2YfMrKDcRo4PcgO3ivss=; b=fMGtG9IqYQmNzQiNawpCBNvc72xrHC00uGjKFJFUYnex4wULz0jrc5PipKDWF89bgBnXhRd/WUxUt8bXGJxvRJLdhkUjP9t1h98fOwlcMFgUGPZjZWtc29fjjsT92sOSSigCnCaB5RNCqMRm12745y3N42Ijr7bD/B7TWhDfd0U= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1676612738873420.59022847610936; Thu, 16 Feb 2023 21:45:38 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pStXP-0000aZ-RC; Fri, 17 Feb 2023 00:44:03 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pStXH-0000Xw-14 for qemu-devel@nongnu.org; Fri, 17 Feb 2023 00:43:55 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pStXF-0001Mv-Fg for qemu-devel@nongnu.org; Fri, 17 Feb 2023 00:43:54 -0500 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-365-id2zVPdlNqakwu8sM773BQ-1; Fri, 17 Feb 2023 00:43:43 -0500 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id C8BCA1C04B77; Fri, 17 Feb 2023 05:43:42 +0000 (UTC) Received: from localhost.localdomain (ovpn-12-47.pek2.redhat.com [10.72.12.47]) by smtp.corp.redhat.com (Postfix) with ESMTP id BE218492B15; Fri, 17 Feb 2023 05:43:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1676612632; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Xz/5bAkleicl62MdzztWocE2YfMrKDcRo4PcgO3ivss=; b=F0q41SSOe5O3f+pKtAS70AKdCXd+Us1BhvdU3Xo6fPttIGaQM2iquhZWWPC9MOeBE3DmSG 9ueVP9uFOdNBFp6j6Vk98zIgaLoxQQ6FZd1Fmh+Zsbg5m8a/K6JjRxe00Q5u1PgpGn/F1U dTGorbSuLFwMO3DVVet0oBp0AInH1YM= X-MC-Unique: id2zVPdlNqakwu8sM773BQ-1 From: Jason Wang To: peter.maydell@linaro.org Cc: qemu-devel@nongnu.org, Thomas Huth , Jason Wang Subject: [PULL V3 1/9] net: Move the code to collect available NIC models to a separate function Date: Fri, 17 Feb 2023 13:43:27 +0800 Message-Id: <20230217054335.57595-2-jasowang@redhat.com> In-Reply-To: <20230217054335.57595-1-jasowang@redhat.com> References: <20230217054335.57595-1-jasowang@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=jasowang@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1676612740707100003 Content-Type: text/plain; charset="utf-8" From: Thomas Huth The code that collects the available NIC models is not really specific to PCI anymore and will be required in the next patch, too, so let's move this into a new separate function in net.c instead. Signed-off-by: Thomas Huth Signed-off-by: Jason Wang --- hw/pci/pci.c | 29 +---------------------------- include/net/net.h | 14 ++++++++++++++ net/net.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+), 28 deletions(-) diff --git a/hw/pci/pci.c b/hw/pci/pci.c index 208c16f..cc51f98 100644 --- a/hw/pci/pci.c +++ b/hw/pci/pci.c @@ -1789,7 +1789,6 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *r= ootbus, 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; @@ -1804,33 +1803,7 @@ PCIDevice *pci_nic_init_nofail(NICInfo *nd, PCIBus *= rootbus, nd->model =3D g_strdup("virtio-net-pci"); } =20 - list =3D object_class_get_list_sorted(TYPE_PCI_DEVICE, false); - pci_nic_models =3D g_ptr_array_new(); - 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); - /* - * A network device might also be something else than a NIC, s= ee - * e.g. the "rocker" device. Thus we have to look for the "net= dev" - * property, too. Unfortunately, some devices like virtio-net = only - * create this property during instance_init, so we have to cr= eate - * a temporary instance here to be able to check it. - */ - Object *obj =3D object_new_with_class(OBJECT_CLASS(dc)); - if (object_property_find(obj, "netdev")) { - g_ptr_array_add(pci_nic_models, (gpointer)name); - } - object_unref(obj); - } - next =3D list->next; - g_slist_free_1(list); - list =3D next; - } - g_ptr_array_add(pci_nic_models, NULL); + pci_nic_models =3D qemu_get_nic_models(TYPE_PCI_DEVICE); =20 if (qemu_show_nic_models(nd->model, (const char **)pci_nic_models->pda= ta)) { exit(0); diff --git a/include/net/net.h b/include/net/net.h index fad589c..1d88621 100644 --- a/include/net/net.h +++ b/include/net/net.h @@ -203,6 +203,20 @@ void net_socket_rs_init(SocketReadState *rs, bool vnet_hdr); NetClientState *qemu_get_peer(NetClientState *nc, int queue_index); =20 +/** + * qemu_get_nic_models: + * @device_type: Defines which devices should be taken into consideration + * (e.g. TYPE_DEVICE for all devices, or TYPE_PCI_DEVICE for= PCI) + * + * Get an array of pointers to names of NIC devices that are available in + * the QEMU binary. The array is terminated with a NULL pointer entry. + * The caller is responsible for freeing the memory when it is not required + * anymore, e.g. with g_ptr_array_free(..., true). + * + * Returns: Pointer to the array that contains the pointers to the names. + */ +GPtrArray *qemu_get_nic_models(const char *device_type); + /* NIC info */ =20 #define MAX_NICS 8 diff --git a/net/net.c b/net/net.c index 251fc5a..476a4b7 100644 --- a/net/net.c +++ b/net/net.c @@ -899,6 +899,40 @@ static int nic_get_free_idx(void) return -1; } =20 +GPtrArray *qemu_get_nic_models(const char *device_type) +{ + GPtrArray *nic_models =3D g_ptr_array_new(); + GSList *list =3D object_class_get_list_sorted(device_type, false); + + 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); + /* + * A network device might also be something else than a NIC, s= ee + * e.g. the "rocker" device. Thus we have to look for the "net= dev" + * property, too. Unfortunately, some devices like virtio-net = only + * create this property during instance_init, so we have to cr= eate + * a temporary instance here to be able to check it. + */ + Object *obj =3D object_new_with_class(OBJECT_CLASS(dc)); + if (object_property_find(obj, "netdev")) { + g_ptr_array_add(nic_models, (gpointer)name); + } + object_unref(obj); + } + next =3D list->next; + g_slist_free_1(list); + list =3D next; + } + g_ptr_array_add(nic_models, NULL); + + return nic_models; +} + int qemu_show_nic_models(const char *arg, const char *const *models) { int i; --=20 2.7.4