From nobody Mon Feb 9 19:37:52 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=1614724328; cv=none; d=zohomail.com; s=zohoarc; b=WpJXZ1S20gVGGxZD2Dp6Qy/w8sgox0tSlYNFtnR5dxCqtQ/kpTS33OSAToBrDzG/DFvXUT/Xf52a4uziBVe8E0jhfdIZ05IuM7qXFz6WK2qq6CAX4LpzyFVA60YKH//1VrdAgzyjYIXoDNxLFr1HiStIx7eJj8F+nXQC5mKquCM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1614724328; 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=LRkh15NWjqeh28DYCra1OSUJLoRpBZZV41v3DUcXea8=; b=L9RNsfiZB+2zSvg52MbNMS66MKRXcI/hbkgT9cymceTmZvZJT1ck5m3kw+eBQRgnKNo+tjgFpGbbNo4rm0WaVllJP9oVE3iGcbk0cf9kOsL7CFkuwt0CU0QRZLANdoeCB4tHCqESTqetfF1PzRC/QWMRKKXKOIinIyN/RK1H85g= 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 1614724328521358.0073292893178; Tue, 2 Mar 2021 14:32:08 -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-573-olf7Z2g-OEaVyEXQmMK1jQ-1; Tue, 02 Mar 2021 17:32:04 -0500 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id BB2F5107ACF2; Tue, 2 Mar 2021 22:31:58 +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 9C0CD60C6A; Tue, 2 Mar 2021 22:31:58 +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 6621758093; Tue, 2 Mar 2021 22:31:58 +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 122MVKD2007954 for ; Tue, 2 Mar 2021 17:31:20 -0500 Received: by smtp.corp.redhat.com (Postfix) id B894360C6A; Tue, 2 Mar 2021 22:31:20 +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 73B5760BFA; Tue, 2 Mar 2021 22:31:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1614724327; 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=LRkh15NWjqeh28DYCra1OSUJLoRpBZZV41v3DUcXea8=; b=csYIZAETiqYNteJXY/NwaT3aYo88idtKdPLqhBjA9cLcX6bFXttoHJD/Jg3VhxJOLOKEfX 9QfwsktAFJrFNGMlfTlyelH9reXZL1hWNn9pShdmIlUbtRId4S07xMMlfjQTumm3RPfeYI wo2ffeuc+HH1sxT8HtaOhHBorcEOijo= X-MC-Unique: olf7Z2g-OEaVyEXQmMK1jQ-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v5 29/30] nodedev: factor out function to add mediated devices Date: Tue, 2 Mar 2021 16:31:04 -0600 Message-Id: <20210302223105.314580-30-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.79 on 10.5.11.12 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" To accomodate re-use of this functionality in a following patch, split out the processing of an individual mdev definition into a separate function. --- src/node_device/node_device_driver.c | 103 +++++++++++++++------------ 1 file changed, 57 insertions(+), 46 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index e702b30e54..af7d59809c 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1505,6 +1505,60 @@ removeMissingPersistentMdevs(virNodeDeviceObjPtr obj, } =20 =20 +/* takes ownership of @def and potentially frees it. @def should not be us= ed + * after returning from this function */ +static int +nodeDeviceUpdateMediatedDevice(virNodeDeviceDefPtr def) +{ + virNodeDeviceObjPtr obj; + virObjectEventPtr event; + bool defined =3D false; + g_autoptr(virNodeDeviceDef) owned =3D def; + g_autofree char *name =3D g_strdup(owned->name); + + owned->driver =3D g_strdup("vfio_mdev"); + + if (!(obj =3D virNodeDeviceObjListFindByName(driver->devs, owned->name= ))) { + virNodeDeviceDefPtr d =3D g_steal_pointer(&owned); + if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, d))) { + virNodeDeviceDefFree(d); + return -1; + } + } else { + bool changed; + virNodeDeviceDefPtr olddef =3D virNodeDeviceObjGetDef(obj); + + defined =3D virNodeDeviceObjIsPersistent(obj); + /* Active devices contain some additional information (e.g. sysfs + * path) that is not provided by mdevctl, so re-use the existing + * definition and copy over new mdev data */ + changed =3D nodeDeviceDefCopyFromMdevctl(olddef, owned); + + if (defined && !changed) { + /* if this device was already defined and the definition + * hasn't changed, there's nothing to do for this device */ + virNodeDeviceObjEndAPI(&obj); + return 0; + } + } + + /* all devices returned by virMdevctlListDefined() are persistent */ + virNodeDeviceObjSetPersistent(obj, true); + + if (!defined) + event =3D virNodeDeviceEventLifecycleNew(name, + VIR_NODE_DEVICE_EVENT_DEFIN= ED, + 0); + else + event =3D virNodeDeviceEventUpdateNew(name); + + virNodeDeviceObjEndAPI(&obj); + virObjectEventStateQueue(driver->nodeDeviceEventState, event); + + return 0; +} + + int nodeDeviceUpdateMediatedDevices(void) { @@ -1524,52 +1578,9 @@ nodeDeviceUpdateMediatedDevices(void) virNodeDeviceObjListForEachRemove(driver->devs, removeMissingPersistentMdevs, &data); =20 - for (i =3D 0; i < data.ndefs; i++) { - virNodeDeviceObjPtr obj; - virObjectEventPtr event; - g_autoptr(virNodeDeviceDef) def =3D defs[i]; - g_autofree char *name =3D g_strdup(def->name); - bool defined =3D false; - - def->driver =3D g_strdup("vfio_mdev"); - - if (!(obj =3D virNodeDeviceObjListFindByName(driver->devs, def->na= me))) { - virNodeDeviceDefPtr d =3D g_steal_pointer(&def); - if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, d)))= { - virNodeDeviceDefFree(d); - return -1; - } - } else { - bool changed; - virNodeDeviceDefPtr olddef =3D virNodeDeviceObjGetDef(obj); - - defined =3D virNodeDeviceObjIsPersistent(obj); - /* Active devices contain some additional information (e.g. sy= sfs - * path) that is not provided by mdevctl, so re-use the existi= ng - * definition and copy over new mdev data */ - changed =3D nodeDeviceDefCopyFromMdevctl(olddef, def); - - if (defined && !changed) { - /* if this device was already defined and the definition - * hasn't changed, there's nothing to do for this device */ - virNodeDeviceObjEndAPI(&obj); - continue; - } - } - - /* all devices returned by virMdevctlListDefined() are persistent = */ - virNodeDeviceObjSetPersistent(obj, true); - - if (!defined) - event =3D virNodeDeviceEventLifecycleNew(name, - VIR_NODE_DEVICE_EVENT_D= EFINED, - 0); - else - event =3D virNodeDeviceEventUpdateNew(name); - - virNodeDeviceObjEndAPI(&obj); - virObjectEventStateQueue(driver->nodeDeviceEventState, event); - } + for (i =3D 0; i < data.ndefs; i++) + if (nodeDeviceUpdateMediatedDevice(defs[i]) < 0) + return -1; =20 return 0; } --=20 2.26.2