From nobody Thu Mar 28 11:54:09 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1633700284; cv=none; d=zohomail.com; s=zohoarc; b=BDmhaGpF7PhRoBxXxKyH1+AGzyz2lTv/HKDsJuxWhxS2N7SiKPivoXg8ZUyFtjyExhOv0c2m1ygk5MK6FJBelKZPm8u9spYUAjQJu09iQduiyq1bySZStcyXUi8hQnFaOIWwPQZyL9Gxnleaqolf88Sb69D9+MYP6hVDiFVK/rA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633700284; 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=VmseW1kD7E1NVWTGOvi7Ke0PCyOsZ7SHfytx9T9f3xU=; b=Fam9Ub5/i4ECXivPO69XR4wja7Zh4bi12FtbjdJz3/qxuAh29Q1ACuVZ2WFf9Kkv1EUjDCEfeRnO2yL/m4xJ7ObXK6SKuE/IAOmAMJu2kSMVqB3I4Kd2W/6nSkpiToirCQ/bfY4CGOCrqcfKuUGQ27T0deV1hSaYBOVwuEm0imI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by mx.zohomail.com with SMTPS id 1633700284546489.8073033674332; Fri, 8 Oct 2021 06:38:04 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-293-GLWr4cxtNy-Cq9OzSUizcg-1; Fri, 08 Oct 2021 09:37:54 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 44A4F94D1BD; Fri, 8 Oct 2021 13:37:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 1E99B5FCA9; Fri, 8 Oct 2021 13:37:06 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id D6FEE4EA2A; Fri, 8 Oct 2021 13:37:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 198Db4en026367 for ; Fri, 8 Oct 2021 09:37:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3C7691973B; Fri, 8 Oct 2021 13:37:04 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.204]) by smtp.corp.redhat.com (Postfix) with ESMTP id E2B39271AE; Fri, 8 Oct 2021 13:37:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633700283; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=VmseW1kD7E1NVWTGOvi7Ke0PCyOsZ7SHfytx9T9f3xU=; b=KzScoeJbgupDSZ1rz6CRRSKuc/Qr6q3fM23k8xvyOI9HF7UlXTFcYb5dItk5vfYQiV9Pim 6LLFud606tmhjZcx/I2JzkKXey5H9G5UlKc4cV/93VffmyUMEJRidU14EIqxvXwjE1CI3s LnoYvWudOFTJFkc1UMxCaSHO8KWkx/g= X-MC-Unique: GLWr4cxtNy-Cq9OzSUizcg-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH v2 13/15] virtio-net: Avoid QemuOpts in failover_find_primary_device() Date: Fri, 8 Oct 2021 15:34:40 +0200 Message-Id: <20211008133442.141332-14-kwolf@redhat.com> In-Reply-To: <20211008133442.141332-1-kwolf@redhat.com> References: <20211008133442.141332-1-kwolf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Cc: kwolf@redhat.com, damien.hedde@greensocs.com, pkrempa@redhat.com, ehabkost@redhat.com, qemu-block@nongnu.org, mst@redhat.com, libvir-list@redhat.com, jasowang@redhat.com, quintela@redhat.com, armbru@redhat.com, vsementsov@virtuozzo.com, lvivier@redhat.com, its@irrelevant.dk, pbonzini@redhat.com, eblake@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1633700286075100001 Content-Type: text/plain; charset="utf-8" Don't go through the global QemuOptsList, it is state of the legacy command line parser and we will create devices that are not contained in it. It is also just the command line configuration and not necessarily the current runtime state. Instead, look at the qdev device tree which has the current state of all existing devices. Signed-off-by: Kevin Wolf --- hw/net/virtio-net.c | 52 +++++++++++++++++---------------------------- 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index ed9a9012e9..f503f28c00 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -796,48 +796,34 @@ static inline uint64_t virtio_net_supported_guest_off= loads(VirtIONet *n) =20 typedef struct { VirtIONet *n; - char *id; -} FailoverId; + DeviceState *dev; +} FailoverDevice; =20 /** - * Set the id of the failover primary device + * Set the failover primary device * * @opaque: FailoverId to setup * @opts: opts for device we are handling * @errp: returns an error if this function fails */ -static int failover_set_primary(void *opaque, QemuOpts *opts, Error **errp) +static int failover_set_primary(DeviceState *dev, void *opaque) { - FailoverId *fid =3D opaque; - const char *standby_id =3D qemu_opt_get(opts, "failover_pair_id"); + FailoverDevice *fdev =3D opaque; + PCIDevice *pci_dev =3D (PCIDevice *) + object_dynamic_cast(OBJECT(dev), TYPE_PCI_DEVICE); =20 - if (g_strcmp0(standby_id, fid->n->netclient_name) =3D=3D 0) { - fid->id =3D g_strdup(opts->id); + if (!pci_dev) { + return 0; + } + + if (!g_strcmp0(pci_dev->failover_pair_id, fdev->n->netclient_name)) { + fdev->dev =3D dev; return 1; } =20 return 0; } =20 -/** - * Find the primary device id for this failover virtio-net - * - * @n: VirtIONet device - * @errp: returns an error if this function fails - */ -static char *failover_find_primary_device_id(VirtIONet *n) -{ - Error *err =3D NULL; - FailoverId fid; - - fid.n =3D n; - if (!qemu_opts_foreach(qemu_find_opts("device"), - failover_set_primary, &fid, &err)) { - return NULL; - } - return fid.id; -} - /** * Find the primary device for this failover virtio-net * @@ -846,13 +832,13 @@ static char *failover_find_primary_device_id(VirtIONe= t *n) */ static DeviceState *failover_find_primary_device(VirtIONet *n) { - char *id =3D failover_find_primary_device_id(n); - - if (!id) { - return NULL; - } + FailoverDevice fdev =3D { + .n =3D n, + }; =20 - return qdev_find_recursive(sysbus_get_default(), id); + qbus_walk_children(sysbus_get_default(), failover_set_primary, NULL, + NULL, NULL, &fdev); + return fdev.dev; } =20 static void failover_add_primary(VirtIONet *n, Error **errp) --=20 2.31.1