From nobody Mon Feb 9 10:27:18 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 207.211.31.81 as permitted sender) client-ip=207.211.31.81; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-1.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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=1594938195; cv=none; d=zohomail.com; s=zohoarc; b=b1g6z2LNw8IWULhSDz/7GG/mWyK1Y3D9WgMDMStlTKF5qSm8TKb1BpREAg0B6Pwl8ggeXSkfchE9qQL5PrhqVpJSAKzk+D63gtbjAP0QWcmkLXWSJQeZM54XqBi0jFPioc1Oe5xJB81rAVp2P3HrV98vrdSh0p3827VQVlfSGrs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1594938195; 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=N98L004KBaENz7l3bVZgG3GsiLqeZHlo7B+Q4Mc89qo=; b=AFZXlG6ROY79U1ejae5ci4ViyTiVY2rtnv4W0TBO8S3Q2xOF09yN06IMyJQPreeFUeyR5QV971J4TnQnghtwh4k98lMaKvQQEXgPJWKitLNdc90dedCrjXDHzzXM6C2iWf2QGqy4YGcmvSb6xezhwFFSDFsyas94BB5bB+9QTOs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 207.211.31.81 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-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by mx.zohomail.com with SMTPS id 1594938195124977.3863944928054; Thu, 16 Jul 2020 15:23:15 -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-61-g6bAMw4xPICWJVJdEUcblg-1; Thu, 16 Jul 2020 18:22:21 -0400 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 EFACB100CCC2; Thu, 16 Jul 2020 22:22:14 +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 BEC891001B07; Thu, 16 Jul 2020 22:22:14 +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 57700180530B; Thu, 16 Jul 2020 22:22:14 +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 06GMLqwB022295 for ; Thu, 16 Jul 2020 18:21:52 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2F95D71664; 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 01B9A6FED1 for ; Thu, 16 Jul 2020 22:21:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1594938193; 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=N98L004KBaENz7l3bVZgG3GsiLqeZHlo7B+Q4Mc89qo=; b=Vc8vNGVyaAk2EFDlVioQI3CYCbuXw9hcdPPQJ8jh/hQZ3z3YV3G1lL8t7hInYpz4t9vnD0 YyHyJ3XsQ80muYpFerJ+AZ1ZpItpya5kPDEgxKQTAphdUFbRbKvffO6udfZvVnCSXHJi45 07AuRmzBPn1oyNO2Sr07sN5+5vsaPNs= X-MC-Unique: g6bAMw4xPICWJVJdEUcblg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 06/16] nodedev: add STOPPED/STARTED lifecycle events Date: Thu, 16 Jul 2020 17:21:36 -0500 Message-Id: <20200716222146.1241-7-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.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" Since a mediated device can be persistently defined by the mdevctl backend, we need additional lifecycle events beyond CREATED/DELETED to indicate that e.g. the device has been stopped but the device definition still exists. Signed-off-by: Jonathon Jongsma --- examples/c/misc/event-test.c | 4 ++++ include/libvirt/libvirt-nodedev.h | 2 ++ src/conf/node_device_conf.h | 1 + src/node_device/node_device_driver.c | 1 + src/node_device/node_device_udev.c | 25 +++++++++++++++++++++++-- tools/virsh-nodedev.c | 4 +++- 6 files changed, 34 insertions(+), 3 deletions(-) diff --git a/examples/c/misc/event-test.c b/examples/c/misc/event-test.c index 52caa8ffa8..c40819969c 100644 --- a/examples/c/misc/event-test.c +++ b/examples/c/misc/event-test.c @@ -381,6 +381,10 @@ nodeDeviceEventToString(int event) return "Created"; case VIR_NODE_DEVICE_EVENT_DELETED: return "Deleted"; + case VIR_NODE_DEVICE_EVENT_STOPPED: + return "Stopped"; + case VIR_NODE_DEVICE_EVENT_STARTED: + return "Started"; case VIR_NODE_DEVICE_EVENT_LAST: break; } diff --git a/include/libvirt/libvirt-nodedev.h b/include/libvirt/libvirt-no= dedev.h index 98a972e60d..423a583d45 100644 --- a/include/libvirt/libvirt-nodedev.h +++ b/include/libvirt/libvirt-nodedev.h @@ -192,6 +192,8 @@ int virConnectNodeDeviceEventDeregisterAny(virConnectPt= r conn, typedef enum { VIR_NODE_DEVICE_EVENT_CREATED =3D 0, VIR_NODE_DEVICE_EVENT_DELETED =3D 1, + VIR_NODE_DEVICE_EVENT_STOPPED =3D 2, + VIR_NODE_DEVICE_EVENT_STARTED =3D 3, =20 # ifdef VIR_ENUM_SENTINELS VIR_NODE_DEVICE_EVENT_LAST diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 353dbebaf0..7e825ca6a9 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -144,6 +144,7 @@ struct _virNodeDevCapMdev { char *uuid; virMediatedDeviceAttrPtr *attributes; size_t nattributes; + bool persistent; }; =20 typedef struct _virNodeDevCapPCIDev virNodeDevCapPCIDev; diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index cb8965a6d9..c5092ff657 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -893,6 +893,7 @@ nodeDeviceParseMdevctlJSON(const char *jsonstring, child->caps->data.type =3D VIR_NODE_DEV_CAP_MDEV; =20 mdev =3D &child->caps->data.mdev; + mdev->persistent =3D true; mdev->uuid =3D g_strdup(uuid); mdev->type =3D g_strdup(virJSONValueObjectGetString(props, "mdev_type= ")); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 93b74b1f24..ac7986bc70 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1213,6 +1213,8 @@ udevRemoveOneDeviceSysPath(const char *path) virNodeDeviceObjPtr obj =3D NULL; virNodeDeviceDefPtr def; virObjectEventPtr event =3D NULL; + virNodeDevCapsDefPtr cap; + int event_type =3D VIR_NODE_DEVICE_EVENT_DELETED; =20 if (!(obj =3D virNodeDeviceObjListFindBySysfsPath(driver->devs, path))= ) { VIR_DEBUG("Failed to find device to remove that has udev path '%s'= ", @@ -1221,13 +1223,32 @@ udevRemoveOneDeviceSysPath(const char *path) } def =3D virNodeDeviceObjGetDef(obj); =20 + /* If the device is a mediated device that has been 'stopped', it may = still + * be defined by mdevctl and can therefore be started again. Don't dro= p it + * from the list of node devices */ + cap =3D def->caps; + while (cap !=3D NULL) { + if (cap->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV) { + if (cap->data.mdev.persistent) { + VIR_FREE(def->sysfs_path); + event_type =3D VIR_NODE_DEVICE_EVENT_STOPPED; + break; + } + } + cap =3D cap->next; + } + event =3D virNodeDeviceEventLifecycleNew(def->name, - VIR_NODE_DEVICE_EVENT_DELETED, + event_type, 0); =20 VIR_DEBUG("Removing device '%s' with sysfs path '%s'", def->name, path); - virNodeDeviceObjListRemove(driver->devs, obj); + + if (event_type =3D=3D VIR_NODE_DEVICE_EVENT_DELETED) + virNodeDeviceObjListRemove(driver->devs, obj); + else + virNodeDeviceObjSetActive(obj, false); virNodeDeviceObjEndAPI(&obj); =20 virObjectEventStateQueue(driver->nodeDeviceEventState, event); diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index 2fb6be504b..75542530da 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -788,7 +788,9 @@ VIR_ENUM_DECL(virshNodeDeviceEvent); VIR_ENUM_IMPL(virshNodeDeviceEvent, VIR_NODE_DEVICE_EVENT_LAST, N_("Created"), - N_("Deleted")); + N_("Deleted"), + N_("Stopped"), + N_("Started")); =20 static const char * virshNodeDeviceEventToString(int event) --=20 2.21.3