From nobody Thu Apr 18 05:19:34 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1633700290; cv=none; d=zohomail.com; s=zohoarc; b=EYCCHJapajhKcBtfe/7tEwOHlUYzuWyRHdxiCSkto64/JWSCwyU/9OAyWbT/vwFHUXSpo5SgFYxX27/oS70rr7Mae0geudXZGBaRrFOMLWFBdRiVjVnImRCu0OVjKQ4pvWJL/XmkcPoYLw3kKuYmv9c6nJr7/WaeSluOD+quW04= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633700290; 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=vY4a62ePc63cIuS7orJe5ZWW2RAAJqboKAPLP4+Fe1w=; b=O3Xtuhwmo501FNdCLOJEfDFtNqxZTTaXc6bC6T1OzIQkaebJLZvvbWeI3bKbe1GEqbhxKsSXUw9Byb5uwBwlkDYOTSxhOXXspfY+yk1TbzKmPbOU7GHGu8ldFCCVv3UCiMJUUDscLGCVa1yUAP/N5/sI+xj2tc9N2xhf34eJ8tI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1633700290864127.51239160632622; Fri, 8 Oct 2021 06:38:10 -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-210-3bGE0hIjOXWUH-I53bm_zg-1; Fri, 08 Oct 2021 09:38:08 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D5C1FC8441; Fri, 8 Oct 2021 13:37:02 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B78F110013C1; Fri, 8 Oct 2021 13:37:02 +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 84B9F1801241; Fri, 8 Oct 2021 13:37:02 +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 198Db1G3026324 for ; Fri, 8 Oct 2021 09:37:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id 495C52B3AB; Fri, 8 Oct 2021 13:37:01 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.204]) by smtp.corp.redhat.com (Postfix) with ESMTP id 37CBF2708F; Fri, 8 Oct 2021 13:36:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633700289; 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=vY4a62ePc63cIuS7orJe5ZWW2RAAJqboKAPLP4+Fe1w=; b=HDF6PZHi6PiOxGWVnybThk3mbt9QV8jTIhUhZq8Auay/FKHa42Lp2nu1n+bx6+A3reRVi3 I+gnKTEO5U2cXsoMWLu+LQssj+zCvnRhuS2KHtyIW/Eet3NC7mKa4TzM9p22gAtcdrh9SZ z37BK6PMoVYTxUUWroP5x9RdoMkFzVw= X-MC-Unique: 3bGE0hIjOXWUH-I53bm_zg-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH v2 12/15] virtio-net: Store failover primary opts pointer locally Date: Fri, 8 Oct 2021 15:34:39 +0200 Message-Id: <20211008133442.141332-13-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.84 on 10.5.11.22 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: 1633700292624100002 Content-Type: text/plain; charset="utf-8" Instead of accessing the global QemuOptsList, which really belong to the command line parser and shouldn't be accessed from devices, store a pointer to the QemuOpts in a new VirtIONet field. This is not the final state, but just an intermediate step to get rid of QemuOpts in devices. It will later be replaced with an options QDict. Before this patch, two "primary" devices could be hidden for the same standby device, but only one of them would actually be enabled and the other one would be kept hidden forever, so this doesn't make sense. After this patch, configuring a second primary device is an error. Signed-off-by: Kevin Wolf --- include/hw/virtio/virtio-net.h | 1 + hw/net/virtio-net.c | 26 ++++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/include/hw/virtio/virtio-net.h b/include/hw/virtio/virtio-net.h index 824a69c23f..d118c95f69 100644 --- a/include/hw/virtio/virtio-net.h +++ b/include/hw/virtio/virtio-net.h @@ -209,6 +209,7 @@ struct VirtIONet { bool failover_primary_hidden; bool failover; DeviceListener primary_listener; + QemuOpts *primary_opts; Notifier migration_state; VirtioNetRssData rss_data; struct NetRxPkt *rx_pkt; diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index a17d5739fc..ed9a9012e9 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -858,27 +858,24 @@ static DeviceState *failover_find_primary_device(Virt= IONet *n) static void failover_add_primary(VirtIONet *n, Error **errp) { Error *err =3D NULL; - QemuOpts *opts; - char *id; DeviceState *dev =3D failover_find_primary_device(n); =20 if (dev) { return; } =20 - id =3D failover_find_primary_device_id(n); - if (!id) { + if (!n->primary_opts) { error_setg(errp, "Primary device not found"); error_append_hint(errp, "Virtio-net failover will not work. Make " "sure primary device has parameter" " failover_pair_id=3D%s\n", n->netclient_name); return; } - opts =3D qemu_opts_find(qemu_find_opts("device"), id); - g_assert(opts); /* cannot be NULL because id was found using opts list= */ - dev =3D qdev_device_add(opts, &err); + + dev =3D qdev_device_add(n->primary_opts, &err); if (err) { - qemu_opts_del(opts); + qemu_opts_del(n->primary_opts); + n->primary_opts =3D NULL; } else { object_unref(OBJECT(dev)); } @@ -3317,6 +3314,19 @@ static bool failover_hide_primary_device(DeviceListe= ner *listener, return false; } =20 + if (n->primary_opts) { + error_setg(errp, "Cannot attach more than one primary device to '%= s'", + n->netclient_name); + return false; + } + + /* + * Having a weak reference here should be okay because a device can't = be + * deleted while it's hidden. This will be replaced soon with a QDict = that + * has a clearer ownership model. + */ + n->primary_opts =3D device_opts; + /* failover_primary_hidden is set during feature negotiation */ return qatomic_read(&n->failover_primary_hidden); } --=20 2.31.1