From nobody Tue Feb 10 01:15:00 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) client-ip=63.128.21.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 63.128.21.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=1612373980; cv=none; d=zohomail.com; s=zohoarc; b=Wl8RdVYdJCA44c6dNmFqqKlcppi+DoSE4TGxPjLXFNz8BcJY92NVCY33WOu+mxP0SSjuKHKpZ7fdY1P4p3y2jwH4znYIlJDJtmVhs+t1VNcCRwFQRC5wgoF5xraf8ztcwv9RDEca7mmlrIzujkioyYwY3sAepZ01MucPzkIQ9WM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1612373980; 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=/Y1esgksCXuAbhUeNcEt2T+S1GIbbR/cgRnwJUwXlKg=; b=g0z8dU2fl0osXO8VIwoc8mp1DjNW28NbW5TGJ9MDIteBRE3q9IIodBeXmkMGM1CU5Z8AMwYAbPQ4Dn+XzW/Uud6aPNO7henpWTxROLcewVU/UsLtcXQF2AB4k0SXbro5hXLZvA0yV7TfsyjWMKW6fZTXE7g8vXRADv4Ld/vGgtI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 63.128.21.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) header.from= Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by mx.zohomail.com with SMTPS id 1612373980486951.10622479247; Wed, 3 Feb 2021 09:39:40 -0800 (PST) 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-578-pwsvQAJ1NPiR1jn0fymWtw-1; Wed, 03 Feb 2021 12:39:36 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 885A3100C613; Wed, 3 Feb 2021 17:39:26 +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 681155D9EF; Wed, 3 Feb 2021 17:39:26 +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 F347357DFF; Wed, 3 Feb 2021 17:39:25 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 113HdIno024323 for ; Wed, 3 Feb 2021 12:39:18 -0500 Received: by smtp.corp.redhat.com (Postfix) id 18FED722C6; Wed, 3 Feb 2021 17:39:18 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-7.phx2.redhat.com [10.3.113.7]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C80E75B4A1; Wed, 3 Feb 2021 17:39:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1612373979; 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=/Y1esgksCXuAbhUeNcEt2T+S1GIbbR/cgRnwJUwXlKg=; b=hVAZSzsB1/nTQVF7yieUv0Ht2RLxnUEo4jMyTtSHNbgcLrTnZPgwx+rrFg1tx9xp3Z+9kx uymKyjr54oklzSuvhIV2ujq1mdaOXwpYLk65Y7F/rQoCjJG3QPKAKJyN4x/4cygmYzAXoA UKNpcsNfY9av2hVhagfVEIuNJuRvz70= X-MC-Unique: pwsvQAJ1NPiR1jn0fymWtw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v4 11/25] nodedev: handle mdevs that disappear from mdevctl Date: Wed, 3 Feb 2021 11:38:55 -0600 Message-Id: <20210203173909.1273000-12-jjongsma@redhat.com> In-Reply-To: <20210203173909.1273000-1-jjongsma@redhat.com> References: <20210203173909.1273000-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Cc: eskultet@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.14 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) Content-Type: text/plain; charset="utf-8" mdevctl does not currently provide any events when the list of defined devices changes, so we will need to poll mdevctl for the list of defined devices periodically. When a mediated device no longer exists from one iteration to the next, we need to treat it as an "undefine" event. When we get such an event, we remove the device from the list if it's not active. Otherwise, we simply mark it as non-persistent. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- src/node_device/node_device_driver.c | 55 +++++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 5 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index fd57dcacc1..598cd865c5 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1182,24 +1182,63 @@ struct _virMdevctlForEachData { }; =20 =20 +/* This function keeps the list of persistent mediated devices consistent + * between the nodedev driver and mdevctl. + * @obj is a device that is currently known by the nodedev driver, and @op= aque + * contains the most recent list of devices defined by mdevctl. If @obj is= no + * longer defined in mdevctl, remove it from the driver as well. */ +static void +removeMissingPersistentMdevs(virNodeDeviceObjPtr obj, + const void *opaque) +{ + const virMdevctlForEachData *data =3D opaque; + size_t i; + virNodeDeviceDefPtr def =3D virNodeDeviceObjGetDef(obj); + virObjectEventPtr event; + + /* transient mdevs are populated via udev, so don't remove them from t= he + * nodedev driver just because they are not reported by by mdevctl */ + if (!virNodeDeviceObjIsPersistent(obj)) + return; + + for (i =3D 0; i < data->ndefs; i++) { + /* OK, this mdev is still defined by mdevctl */ + if (STREQ(data->defs[i]->name, def->name)) + return; + } + + event =3D virNodeDeviceEventLifecycleNew(def->name, + VIR_NODE_DEVICE_EVENT_UNDEFINED, + 0); + + /* The device is active, but no longer defined by mdevctl. Keep the de= vice + * in the list, but mark it as non-persistent */ + if (virNodeDeviceObjIsActive(obj)) + virNodeDeviceObjSetPersistent(obj, false); + else + virNodeDeviceObjListRemoveLocked(driver->devs, obj); + + virObjectEventStateQueue(driver->nodeDeviceEventState, event); +} + + int nodeDeviceUpdateMediatedDevices(void) { - g_autofree virNodeDeviceDefPtr *defs =3D NULL; - int ndefs; + virMdevctlForEachData data =3D { 0, }; GList * tofree =3D NULL; size_t i; =20 - if ((ndefs =3D virMdevctlListDefined(&defs)) < 0) { + if ((data.ndefs =3D virMdevctlListDefined(&data.defs)) < 0) { virReportSystemError(errno, "%s", _("failed to query mdevs from mdevctl")); return -1; } =20 - for (i =3D 0; i < ndefs; i++) { + for (i =3D 0; i < data.ndefs; i++) { virNodeDeviceObjPtr obj; virObjectEventPtr event; - virNodeDeviceDefPtr def =3D defs[i]; + virNodeDeviceDefPtr def =3D data.defs[i]; bool was_defined =3D false; =20 def->driver =3D g_strdup("vfio_mdev"); @@ -1245,8 +1284,14 @@ nodeDeviceUpdateMediatedDevices(void) virObjectEventStateQueue(driver->nodeDeviceEventState, event); } =20 + /* Any mdevs that were previously defined but were not returned the la= test + * mdevctl query should be removed from the device list */ + virNodeDeviceObjListForEachSafe(driver->devs, removeMissingPersistentM= devs, + &data); + cleanup: g_list_free_full(tofree, (GDestroyNotify)virNodeDeviceDefFree); + g_free(data.defs); =20 return 0; } --=20 2.26.2