From nobody Sun Feb 8 21:29:12 2026 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=1644422627; cv=none; d=zohomail.com; s=zohoarc; b=iJq5IqG0q+LCHSnfYWnBV2Y8hHJw2m4+vvVZqXCgIs+Ao36rk5x23PMjbIlEQH2vMlxCZ9mH5YX2x7/RC/upZsZ/iWyk0nu5WkCfVpKqlAZOTM4DUS4vCj9PsWO7HiG7+XOxtFT/GlUd2eVn3zfrEZNkOemQo7IciMM6mfcqjfM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1644422627; h=Content-Type:Content-Transfer-Encoding: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=F4e+ceSzhoQOHbwV/QQoesMTH18uWxIRx9PU5nGzYMo=; b=fqzuZAEaWU8GbXPiVKbrkDazXc4DbaK/tRopg2Nf8eddT8bOqogfc+KiDC45f9hUcW26N+yiNlzyuQNow5qcMhW2hXKtJHB2HfUnqNXQlsoNIhAcE75/hDSMC6Ax3GAJZKrRR6RF1IlgpJRHNKocb8c0yr0jqDSsFbJkMrv3fKI= 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 1644422627540794.6842047277858; Wed, 9 Feb 2022 08:03:47 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-516-sinEhz1pNTi910R1b-4Zjw-1; Wed, 09 Feb 2022 11:03:41 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 021DE83DEA6; Wed, 9 Feb 2022 16:03:06 +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 79EE684D00; Wed, 9 Feb 2022 16:03:05 +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 1258E18033AE; Wed, 9 Feb 2022 16:03:05 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 219G2jXf012307 for ; Wed, 9 Feb 2022 11:02:45 -0500 Received: by smtp.corp.redhat.com (Postfix) id 103B77DE56; Wed, 9 Feb 2022 16:02:45 +0000 (UTC) Received: from speedmetal.redhat.com (unknown [10.40.208.41]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6847C7DE40 for ; Wed, 9 Feb 2022 16:02:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1644422626; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to: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=F4e+ceSzhoQOHbwV/QQoesMTH18uWxIRx9PU5nGzYMo=; b=DxIcvX3bZrwdrASBRN1PIAwrOTGO2NuOurnOKZXyaFGmKjAS/KmCqQXVH4W5548Jblua+m IGD3wXE9DxaAJIILRYgWN04iJLtzpjce9UZoZ9M465HrU0pBjFfKlmJ1GkmegvGFijACYC fqeDSY1m0Rt+kNlXFQ0RoqMqgGNcCmI= X-MC-Unique: sinEhz1pNTi910R1b-4Zjw-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 11/27] qemu: hotplug: Extract code for unplugging fdsets Date: Wed, 9 Feb 2022 17:02:03 +0100 Message-Id: <37ed7d429cd70c7312b8804797c45ec0f5f2cfee.1644422239.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@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.13 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: 1644422629574100005 Content-Type: text/plain; charset="utf-8" The code unplugging the fdset for a 'vdpa' network device can be later reused. Extract it into 'qemuHotplugRemoveFDSet'. Signed-off-by: Peter Krempa Reviewed-by: J=C3=A1n Tomko --- src/qemu/qemu_hotplug.c | 69 +++++++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index ac2b07d940..3264f287c3 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -137,6 +137,44 @@ qemuDomainDeleteDevice(virDomainObj *vm, } +/** + * qemuHotplugRemoveFDSet: + * @mon: monitor object + * @fdname: the 'opaque' string used as a name for the FD + * + * Looks up the 'fdset' by looking for a fd inside one of the fdsets which + * has the opaque string set to @fdname. Removes the whole fdset which con= tains + * the fd. + * + * Errors are logged, but this is a best-effort hot-unplug cleanup helper = so it's + * pointless to return a value. + */ +static void +qemuHotplugRemoveFDSet(qemuMonitor *mon, + const char *fdname) +{ + g_autoptr(qemuMonitorFdsets) fdsets =3D NULL; + size_t i; + + if (qemuMonitorQueryFdsets(mon, &fdsets) < 0) + return; + + for (i =3D 0; i < fdsets->nfdsets; i++) { + qemuMonitorFdsetInfo *set =3D &fdsets->fdsets[i]; + size_t j; + + for (j =3D 0; j < set->nfds; j++) { + qemuMonitorFdsetFdInfo *fdinfo =3D &set->fds[j]; + + if (STREQ_NULLABLE(fdinfo->opaque, fdname)) { + ignore_value(qemuMonitorRemoveFdset(mon, set->id)); + return; + } + } + } +} + + static int qemuDomainDetachZPCIDevice(qemuMonitor *mon, virDomainDeviceInfo *info) @@ -4761,38 +4799,9 @@ qemuDomainRemoveNetDevice(virQEMUDriver *driver, */ } } else if (actualType =3D=3D VIR_DOMAIN_NET_TYPE_VDPA) { - int vdpafdset =3D -1; - g_autoptr(qemuMonitorFdsets) fdsets =3D NULL; - - /* query qemu for which fdset is associated with the fd that we pa= ssed - * to qemu via 'add-fd' for this vdpa device. If we don't remove t= he - * fd, qemu will keep it open */ - if (qemuMonitorQueryFdsets(priv->mon, &fdsets) =3D=3D 0) { - for (i =3D 0; i < fdsets->nfdsets && vdpafdset < 0; i++) { - size_t j; - qemuMonitorFdsetInfo *set =3D &fdsets->fdsets[i]; - - for (j =3D 0; j < set->nfds; j++) { - qemuMonitorFdsetFdInfo *fdinfo =3D &set->fds[j]; - if (STREQ_NULLABLE(fdinfo->opaque, net->data.vdpa.devi= cepath)) { - vdpafdset =3D set->id; - break; - } - } - } - } - - if (vdpafdset < 0) { - VIR_WARN("Cannot determine fdset for vdpa device"); - } else { - if (qemuMonitorRemoveFdset(priv->mon, vdpafdset) < 0) { - /* if it fails, there's not much we can do... just carry o= n */ - VIR_WARN("failed to close vdpa device"); - } - } + qemuHotplugRemoveFDSet(priv->mon, net->data.vdpa.devicepath); } - qemuDomainObjExitMonitor(driver, vm); if (QEMU_DOMAIN_NETWORK_PRIVATE(net)->slirp) --=20 2.34.1