From nobody Mon Feb 9 20:10:26 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1616777464; cv=none; d=zohomail.com; s=zohoarc; b=HusBZ8qbx480sNJ7s9ruBv+MzefliwEMOWlM4SMdCPOUQ2RQBg4YjmZAs/w7EtZeSS6KJ+cgBlL64hy8tw8VDfDk8FtyTxCVPuIvSPcpidoXjOWHW1XjJga+PI7ACF7MJS1wd/1whrbjKQ7o9Kvgsi/FTLM4994PHbKGFtI7p1o= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777464; 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=DeAA7cjFkWOEFxc6xBy8T747EyOv+4mOVis5ORbXpyQ=; b=OOBELL0oPIc5RSHhmxXQe9zNbof8W+ww1zXWo/vSAocYoXpWywdjbxR8zcK0YeYATB+A5Wv6stMQCG09DITGYf7aeD3cmu6xLS/NAKZ9VEPGSLnSbpi+wq9nCK12k2LnrdmbC111J4wfNs57H4Rwum8fp2PjLzjUInuehEJW0b4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1616777464305849.3400030870741; Fri, 26 Mar 2021 09:51:04 -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-175-n4eef9zyNPae7qY1g8bIOw-1; Fri, 26 Mar 2021 12:49:11 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E85DD10866BC; Fri, 26 Mar 2021 16:49:04 +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 C11A3679E7; Fri, 26 Mar 2021 16:49:04 +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 80C884A71E; Fri, 26 Mar 2021 16:49:04 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 12QGmbgt002989 for ; Fri, 26 Mar 2021 12:48:37 -0400 Received: by smtp.corp.redhat.com (Postfix) id B0BBB5D755; Fri, 26 Mar 2021 16:48:37 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-113-51.phx2.redhat.com [10.3.113.51]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 76F605D6DC; Fri, 26 Mar 2021 16:48:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777463; 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=DeAA7cjFkWOEFxc6xBy8T747EyOv+4mOVis5ORbXpyQ=; b=EXK6aKOm6L7z6nrLx2SQG8f6DehKpNXRXI0B5w96pCeswFfFVaczCxTh+T/jRHX8NqN13f S1uc2xKJ/LYXd3AWrcOubCAZ1ceMlZYIJ1jqTRXDF0erUkVcTtNVK5+Y04t1bSPBG6+twd Q0ueqnu3bj4nn1LMbqdSUNY4/sP5R3g= X-MC-Unique: n4eef9zyNPae7qY1g8bIOw-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 12/30] nodedev: add helper functions to remove node devices Date: Fri, 26 Mar 2021 11:48:08 -0500 Message-Id: <20210326164826.1720062-13-jjongsma@redhat.com> In-Reply-To: <20210326164826.1720062-1-jjongsma@redhat.com> References: <20210326164826.1720062-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 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.16 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" When a mediated device is stopped or undefined by an application outside of libvirt, we need to remove it from our list of node devices within libvirt. This patch introduces virNodeDeviceObjListRemoveLocked() and virNodeDeviceObjListForEachRemove() (which are analogous to other types of object lists in libvirt) to facilitate that. They will be used in coming commits. Signed-off-by: Jonathon Jongsma Reviewed-by: Erik Skultety --- src/conf/virnodedeviceobj.c | 58 ++++++++++++++++++++++++++++++++++--- src/conf/virnodedeviceobj.h | 11 +++++++ src/libvirt_private.syms | 2 ++ 3 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index ce84e4d8c1..97e7d7ab11 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -507,23 +507,29 @@ void virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs, virNodeDeviceObjPtr obj) { - virNodeDeviceDefPtr def; - if (!obj) return; - def =3D obj->def; =20 virObjectRef(obj); virObjectUnlock(obj); virObjectRWLockWrite(devs); virObjectLock(obj); - virHashRemoveEntry(devs->objs, def->name); + virNodeDeviceObjListRemoveLocked(devs, obj); virObjectUnlock(obj); virObjectUnref(obj); virObjectRWUnlock(devs); } =20 =20 +/* The caller must hold lock on 'devs' */ +void +virNodeDeviceObjListRemoveLocked(virNodeDeviceObjList *devs, + virNodeDeviceObj *dev) +{ + virHashRemoveEntry(devs->objs, dev->def->name); +} + + /* * Return the NPIV dev's parent device name */ @@ -1019,3 +1025,47 @@ virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj, { obj->persistent =3D persistent; } + + +struct virNodeDeviceObjListRemoveData +{ + virNodeDeviceObjListRemoveIter iter; + void *opaque; +}; + +static int virNodeDeviceObjListRemoveCb(void *key G_GNUC_UNUSED, + void *value, + void *opaque) +{ + struct virNodeDeviceObjListRemoveData *data =3D opaque; + + return data->iter(value, data->opaque); +} + + +/** + * virNodeDeviceObjListForEachRemove + * @devs: Pointer to object list + * @iter: function to call for each device object + * @opaque: Opaque data to use as argument to helper + * + * For each object in @devs, call the @iter helper using @opaque as + * an argument. If @iter returns true, that item will be removed from the + * object list. + */ +void +virNodeDeviceObjListForEachRemove(virNodeDeviceObjList *devs, + virNodeDeviceObjListRemoveIter iter, + void *opaque) +{ + struct virNodeDeviceObjListRemoveData data =3D { + .iter =3D iter, + .opaque =3D opaque + }; + + virObjectRWLockWrite(devs); + g_hash_table_foreach_remove(devs->objs, + virNodeDeviceObjListRemoveCb, + &data); + virObjectRWUnlock(devs); +} diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 7f682b9dca..249115cf68 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -80,6 +80,10 @@ void virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs, virNodeDeviceObjPtr dev); =20 +void +virNodeDeviceObjListRemoveLocked(virNodeDeviceObjList *devs, + virNodeDeviceObj *dev); + int virNodeDeviceObjListGetParentHost(virNodeDeviceObjListPtr devs, virNodeDeviceDefPtr def); @@ -134,3 +138,10 @@ virNodeDeviceObjIsPersistent(virNodeDeviceObj *obj); void virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj, bool persistent); + +typedef bool (*virNodeDeviceObjListRemoveIter)(virNodeDeviceObj *obj, + const void *opaque); + +void virNodeDeviceObjListForEachRemove(virNodeDeviceObjList *devs, + virNodeDeviceObjListRemoveIter iter, + void *opaque); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 047314ec19..f36400b5f6 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1280,12 +1280,14 @@ virNodeDeviceObjListFindByName; virNodeDeviceObjListFindBySysfsPath; virNodeDeviceObjListFindMediatedDeviceByUUID; virNodeDeviceObjListFindSCSIHostByWWNs; +virNodeDeviceObjListForEachRemove; virNodeDeviceObjListFree; virNodeDeviceObjListGetNames; virNodeDeviceObjListGetParentHost; virNodeDeviceObjListNew; virNodeDeviceObjListNumOfDevices; virNodeDeviceObjListRemove; +virNodeDeviceObjListRemoveLocked; virNodeDeviceObjSetActive; virNodeDeviceObjSetPersistent; =20 --=20 2.26.3