From nobody Sat Apr 27 00:15:56 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=1633700258; cv=none; d=zohomail.com; s=zohoarc; b=S9+PZpQjzALQSy6Gt35UM+lLqV/qHSWWzNL3On5xI3tcLPaw9NTkbcMIX8k2liooJZLIXoM+gB/QbefpTGyufd8VFki0deJnx0PC9RFd5WC9qJRl7tot/VKdSzgPU0NL2FJeE377b/9nIC09z5AspoHu/PWLMQxm6MwVxMt+/Dg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1633700258; 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=+WjBdz/6j8bBjxLCB04zzlXvVueacn5cmIOmGJiyL/I=; b=A+L720U7M/emiVIUtn9Yv+asUTvdlSdGxUIb52NsjLXlWKO9tvDh7wVkPFY39h7sgcNsx9h48+yyGtuSo8qBPj6ctcC/jqJq+9YZD9G8zdPPpJaSnNksW34MQ8W335dXqcwTcxQHjI0tnbUIrJRXDIjUOeswxeaOjS68Z5TsRCo= 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 1633700258538761.9373591888476; Fri, 8 Oct 2021 06:37:38 -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-191-hqEOtUaGNYOaODdJeco13g-1; Fri, 08 Oct 2021 09:37:36 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DF8C6804170; Fri, 8 Oct 2021 13:36:58 +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 BEE7F5F4E7; Fri, 8 Oct 2021 13:36:58 +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 8A8051801241; Fri, 8 Oct 2021 13:36:58 +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 198DavRx026308 for ; Fri, 8 Oct 2021 09:36:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0B0E426FD7; Fri, 8 Oct 2021 13:36:57 +0000 (UTC) Received: from merkur.redhat.com (unknown [10.39.193.204]) by smtp.corp.redhat.com (Postfix) with ESMTP id 063B019724; Fri, 8 Oct 2021 13:36:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1633700257; 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=+WjBdz/6j8bBjxLCB04zzlXvVueacn5cmIOmGJiyL/I=; b=ioqOaFH+a5t3fLXt4ljXKASzPKoBUwl484dg0AxZ55OqYujPaqdK4541E5dXosmmJWsTJq Gpf1m5HKHgsat4XvsQ3DbbaIfgTXoc1sXjpXIGfHSWbyA8X82xQTvEF9gcSOSjrvG2A2eQ AKn6ep4yfGjmNKUjrbtC3lbn313/SDU= X-MC-Unique: hqEOtUaGNYOaODdJeco13g-1 From: Kevin Wolf To: qemu-devel@nongnu.org Subject: [PATCH v2 11/15] qdev: Add Error parameter to hide_device() callbacks Date: Fri, 8 Oct 2021 15:34:38 +0200 Message-Id: <20211008133442.141332-12-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.15 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: 1633700260598100001 Content-Type: text/plain; charset="utf-8" hide_device() is used for virtio-net failover, where the standby virtio device delays creation of the primary device. It only makes sense to have a single primary device for each standby device. Adding a second one should result in an error instead of hiding it and never using it afterwards. Prepare for this by adding an Error parameter to the hide_device() callback where virtio-net is informed about adding a primary device. Signed-off-by: Kevin Wolf --- include/hw/qdev-core.h | 8 ++++++-- hw/core/qdev.c | 7 +++++-- hw/net/virtio-net.c | 2 +- softmmu/qdev-monitor.c | 5 ++++- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 5a073fc368..74d8b614a7 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -201,8 +201,12 @@ struct DeviceListener { * informs qdev if a device should be visible or hidden. We can * hide a failover device depending for example on the device * opts. + * + * On errors, it returns false and errp is set. Device creation + * should fail in this case. */ - bool (*hide_device)(DeviceListener *listener, QemuOpts *device_opts); + bool (*hide_device)(DeviceListener *listener, QemuOpts *device_opts, + Error **errp); QTAILQ_ENTRY(DeviceListener) link; }; =20 @@ -837,7 +841,7 @@ void device_listener_unregister(DeviceListener *listene= r); * When a device is added via qdev_device_add() this will be called, * and return if the device should be added now or not. */ -bool qdev_should_hide_device(QemuOpts *opts); +bool qdev_should_hide_device(QemuOpts *opts, Error **errp); =20 typedef enum MachineInitPhase { /* current_machine is NULL. */ diff --git a/hw/core/qdev.c b/hw/core/qdev.c index d918b50a1d..c3a021c444 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -211,14 +211,17 @@ void device_listener_unregister(DeviceListener *liste= ner) QTAILQ_REMOVE(&device_listeners, listener, link); } =20 -bool qdev_should_hide_device(QemuOpts *opts) +bool qdev_should_hide_device(QemuOpts *opts, Error **errp) { + ERRP_GUARD(); DeviceListener *listener; =20 QTAILQ_FOREACH(listener, &device_listeners, link) { if (listener->hide_device) { - if (listener->hide_device(listener, opts)) { + if (listener->hide_device(listener, opts, errp)) { return true; + } else if (*errp) { + return false; } } } diff --git a/hw/net/virtio-net.c b/hw/net/virtio-net.c index f205331dcf..a17d5739fc 100644 --- a/hw/net/virtio-net.c +++ b/hw/net/virtio-net.c @@ -3304,7 +3304,7 @@ static void virtio_net_migration_state_notifier(Notif= ier *notifier, void *data) } =20 static bool failover_hide_primary_device(DeviceListener *listener, - QemuOpts *device_opts) + QemuOpts *device_opts, Error **er= rp) { VirtIONet *n =3D container_of(listener, VirtIONet, primary_listener); const char *standby_id; diff --git a/softmmu/qdev-monitor.c b/softmmu/qdev-monitor.c index feb15818e6..ccc3c11563 100644 --- a/softmmu/qdev-monitor.c +++ b/softmmu/qdev-monitor.c @@ -625,6 +625,7 @@ const char *qdev_set_id(DeviceState *dev, char *id, Err= or **errp) =20 DeviceState *qdev_device_add(QemuOpts *opts, Error **errp) { + ERRP_GUARD(); DeviceClass *dc; const char *driver, *path; DeviceState *dev =3D NULL; @@ -668,11 +669,13 @@ DeviceState *qdev_device_add(QemuOpts *opts, Error **= errp) error_setg(errp, "Device with failover_pair_id don't have id"); return NULL; } - if (qdev_should_hide_device(opts)) { + if (qdev_should_hide_device(opts, errp)) { if (bus && !qbus_is_hotpluggable(bus)) { error_setg(errp, QERR_BUS_NO_HOTPLUG, bus->name); } return NULL; + } else if (*errp) { + return NULL; } } =20 --=20 2.31.1