From nobody Tue Feb 10 07:21:15 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=1614724308; cv=none; d=zohomail.com; s=zohoarc; b=XlOUtmgRVt1iTnl9p0ktA9JoLwTLH8okYPNvsv3bd4R1Bp4whxUgJByMmKcH3VKjrOHIXovMlfcBLV6CZJdF+0cKAO4UxotqSIgxmdO0eBj7CEsXTf/1lgl8ByOITyi/0s2zR7laz+XLyFnS2LufZM/JerhZfdDfN+LNHo2j1p4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614724308; 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=4tGWD+RP0bA7qE4LNrh1X3ceDDm/ThXgvIHPXVUNgUA=; b=Kg2jdyKCVoLxIE7Ycz4jzcFypgYrZ3WqyBy+aLjulXmXHKDkRomOpsmofJlctZ1umyXkj3cftA6Cega6Ict0FF4alyGv+89/icFpihBGSsMjo0oQK6PKFLokRM4GIgHmJ+/uj8uUbkPYZwQ7W55M48rgQEIYFqn0kvG+tGXumpY= 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 1614724308652418.1577826072887; Tue, 2 Mar 2021 14:31:48 -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-198-c6FytNTuOfO1dsMpIuo0Ug-1; Tue, 02 Mar 2021 17:31:44 -0500 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 3FDB91868404; Tue, 2 Mar 2021 22:31:39 +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 151F2100AE31; Tue, 2 Mar 2021 22:31:39 +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 D1C6658077; Tue, 2 Mar 2021 22:31:38 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 122MVEgs007803 for ; Tue, 2 Mar 2021 17:31:14 -0500 Received: by smtp.corp.redhat.com (Postfix) id 710C060C6D; Tue, 2 Mar 2021 22:31:14 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-115-28.phx2.redhat.com [10.3.115.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2BCD360BFA; Tue, 2 Mar 2021 22:31:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614724307; 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=4tGWD+RP0bA7qE4LNrh1X3ceDDm/ThXgvIHPXVUNgUA=; b=HJc2LRZQO3jZchL92uwUCVDE0ghuKoVH8g1xJvAhRATN7FxERkFlW3wKudA8gI9pXewqjr pfT2f7HuSaWcHQjjUobpD8xSLnrQk0Vi+H7Zs60XEBFsyA38QHZpycWIgjYD9U5q7CxRiw xlJdBBRm1+3ylu04R48+TGMBAy0j2QQ= X-MC-Unique: c6FytNTuOfO1dsMpIuo0Ug-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v5 13/30] nodedev: handle mdevs that disappear from mdevctl Date: Tue, 2 Mar 2021 16:30:48 -0600 Message-Id: <20210302223105.314580-14-jjongsma@redhat.com> In-Reply-To: <20210302223105.314580-1-jjongsma@redhat.com> References: <20210302223105.314580-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 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.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) 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 --- src/node_device/node_device_driver.c | 67 ++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index ad21565adb..318ad43b9f 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1183,20 +1183,81 @@ virMdevctlListDefined(virNodeDeviceDefPtr **devs) } =20 =20 +typedef struct _virMdevctlForEachData virMdevctlForEachData; +struct _virMdevctlForEachData { + int ndefs; + virNodeDeviceDefPtr *defs; +}; + + +/* 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, mark it as undefined and possibly remove it = from + * the driver as well. Returning 'true' from this function indicates that = the + * device should be removed from the nodedev driver list. */ +static bool +removeMissingPersistentMdevs(virNodeDeviceObjPtr obj, + const void *opaque) +{ + bool remove =3D false; + const virMdevctlForEachData *data =3D opaque; + size_t i; + virNodeDeviceDefPtr def =3D virNodeDeviceObjGetDef(obj); + virObjectEventPtr event; + + if (def->caps->data.type !=3D VIR_NODE_DEV_CAP_MDEV) + return false; + + /* 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 false; + + 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 false; + } + + 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 + remove =3D true; + + virObjectEventStateQueue(driver->nodeDeviceEventState, event); + + return remove; +} + + int nodeDeviceUpdateMediatedDevices(void) { g_autofree virNodeDeviceDefPtr *defs =3D NULL; - int ndefs; + virMdevctlForEachData data =3D { 0, }; size_t i; =20 - if ((ndefs =3D virMdevctlListDefined(&defs)) < 0) { + if ((data.ndefs =3D virMdevctlListDefined(&defs)) < 0) { virReportSystemError(errno, "%s", _("failed to query mdevs from mdevctl")); return -1; } =20 - for (i =3D 0; i < ndefs; i++) { + /* Any mdevs that were previously defined but were not returned in the + * latest mdevctl query should be removed from the device list */ + data.defs =3D defs; + virNodeDeviceObjListForEachRemove(driver->devs, + removeMissingPersistentMdevs, &data); + + for (i =3D 0; i < data.ndefs; i++) { virNodeDeviceObjPtr obj; virObjectEventPtr event; g_autoptr(virNodeDeviceDef) def =3D defs[i]; --=20 2.26.2