From nobody Mon Feb 9 11:47:28 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 205.139.110.120 as permitted sender) client-ip=205.139.110.120; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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=1594938127; cv=none; d=zohomail.com; s=zohoarc; b=nNQ1YTaQpjuP73ugYZj4rxBCRhL+e3ETi5OipAf73xX9uUaAZvh+m3IWXLTvtiohD8HBzXy1UkT0dxw4tCiif51IEUkTYu7WzDBbtPnqKXN0mNEtKk1SA4hYjL+B6QxElw7lmDOh/3eCe5NPaBg+Acyg/85WYc+Gi1lU0KhvueE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594938127; 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=ET0EWWcHIfKpUBa3U5ph4epBydLqSqR3OXOMLuUVuKc=; b=kRfJmLR4b8kQrZSJgd8c2a0lhgO0z9BJ9eprV0xJdpevsQx3B2E+YumATEOFbyr3JkVxy7PHFgZDqki7eJM2MNM+vNPMtFcTbRG/iPHGY0QZlnZwgrYjD8+fmqYAYTsZ2s6VTFu6A6jt3OyPr7auuFaVdaZ5FGO1AxVwGoNVyaQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 205.139.110.120 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-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by mx.zohomail.com with SMTPS id 1594938127428378.88367299769686; Thu, 16 Jul 2020 15:22:07 -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-148-EXLX_oHFMD2rdmxQDXLpIg-1; Thu, 16 Jul 2020 18:22:38 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E03651081; Thu, 16 Jul 2020 22:21:57 +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 89DD019C58; Thu, 16 Jul 2020 22:21:57 +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 555E61809561; Thu, 16 Jul 2020 22:21:57 +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 06GMLqi6022305 for ; Thu, 16 Jul 2020 18:21:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id C625A71664; Thu, 16 Jul 2020 22:21:52 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-112-38.phx2.redhat.com [10.3.112.38]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 984566FED1 for ; Thu, 16 Jul 2020 22:21:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594938126; 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=ET0EWWcHIfKpUBa3U5ph4epBydLqSqR3OXOMLuUVuKc=; b=g0qOjLSJL6mqEYSObSpcHzBHDfPDxDoZF21LysI0Po+a8aIwBVk70XvHZ838aQoWdkqw2w jF7E4ko/c7QvrJx/s0+cpEystltJpNCsBfDWJp/YLupjwfU2n1CRMBB59WkDS5eIoTflMX 7YtsVvzil+5+zMUF66UrVGxjwnkEo04= X-MC-Unique: EXLX_oHFMD2rdmxQDXLpIg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 08/16] nodedev: handle mdevs that disappear from mdevctl Date: Thu, 16 Jul 2020 17:21:38 -0500 Message-Id: <20200716222146.1241-9-jjongsma@redhat.com> In-Reply-To: <20200716222146.1241-1-jjongsma@redhat.com> References: <20200716222146.1241-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 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.23 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 | 61 ++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 9d07ff0e38..032e7f42fa 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1087,6 +1087,37 @@ nodeDeviceGenerateName(virNodeDeviceDefPtr def, } } =20 +static bool +mdevMatchPersistentDevices(virConnectPtr conn G_GNUC_UNUSED, + virNodeDeviceDefPtr def) +{ + return (def->caps->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV && + def->caps->data.mdev.persistent); + + +} + +/* returns a null-terminated array of strings. Free with virStringListFree= () */ +static char ** +nodeDeviceGetMdevPersistentDevices(virNodeDeviceObjListPtr devlist) +{ + char **ret =3D NULL; + int ndevs =3D virNodeDeviceObjListNumOfDevices(devlist, + NULL, + "mdev", + mdevMatchPersistentDevice= s); + if (VIR_ALLOC_N(ret, ndevs+1) < 0) + return NULL; + + if (virNodeDeviceObjListGetNames(devlist, NULL, + mdevMatchPersistentDevices, + "mdev", + ret, + ndevs) < 0) + VIR_FREE(ret); + + return ret; +} =20 static int virMdevctlListDefined(virNodeDeviceDefPtr **devs) @@ -1110,6 +1141,7 @@ mdevctlEnumerateDevices(void) { g_autofree virNodeDeviceDefPtr *devs =3D NULL; int ndevs; + char **oldmdevs =3D nodeDeviceGetMdevPersistentDevices(driver->devs); =20 if ((ndevs =3D virMdevctlListDefined(&devs)) < 0) { virReportSystemError(errno, "%s", @@ -1157,7 +1189,36 @@ mdevctlEnumerateDevices(void) event =3D virNodeDeviceEventUpdateNew(dev->name); virNodeDeviceObjEndAPI(&obj); virObjectEventStateQueue(driver->nodeDeviceEventState, event); + + virStringListRemove(&oldmdevs, dev->name); + } + + /* Any mdevs that were previously defined but were not returned by mde= vctl + * this time will need to be checked to see if they should be removed = from + * the device list */ + for (int i =3D 0; i < virStringListLength((const char **)oldmdevs); i+= +) { + const char *name =3D oldmdevs[i]; + virNodeDeviceObjPtr obj =3D NULL; + if ((obj =3D virNodeDeviceObjListFindByName(driver->devs, name))) { + if (!virNodeDeviceObjIsActive(obj)) { + /* An existing device is not active and is no longer defin= ed by + * mdevctl, so remove it */ + virObjectEventPtr event =3D virNodeDeviceEventLifecycleNew= (name, + V= IR_NODE_DEVICE_EVENT_DELETED, + 0= ); + + virNodeDeviceObjListRemove(driver->devs, obj); + virObjectEventStateQueue(driver->nodeDeviceEventState, eve= nt); + } else { + /* An existing device is active, but no longer defined. Ke= ep + * the device in the list, but mark it as non-persistent */ + virNodeDeviceDefPtr def =3D virNodeDeviceObjGetDef(obj); + def->caps->data.mdev.persistent =3D false; + } + virNodeDeviceObjEndAPI(&obj); + } } + virStringListFree(oldmdevs); =20 return 0; } --=20 2.21.3