From nobody Tue Feb 10 04:14:28 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=1616777372; cv=none; d=zohomail.com; s=zohoarc; b=UZj5zQuiIOuykNSpd62L6M0+LVq3RwY4drIOL0BZvv3OtjEOmiXB4jx7a9FzgZjBVrFieit3LRBgd7B9kFWelWHYG35RI8tBHZCU5scsOVYOdLSBLX8q6x03XqM9DDRN+sc5ZykuecfH/K0OrPlWZp6m0eyyuNvxtUykr3ffRUM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1616777372; 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=jlqzlXra53IPYqcZgvZpR8dqB3gbxdXlVjsGplez1f8=; b=P3xJ8ClzI4v6XCToDrPuuhkJAQm5HZzhBiozeL20s1tt7PtrJ6rASKT55YEVvQtTGNLoD78d+LPSk+aHAbPfC79biDgKK8+vPesmF2Lp3RgOmFHiakmC7RfQwzMkDTAWNsFcfE9ruhykAP4XMYdgstX3WqQLuO3zpiZciTRwI0M= 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 1616777372576486.4947014564708; Fri, 26 Mar 2021 09:49:32 -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-457-A2NmavK6MFS4aSjXUeeAPA-1; Fri, 26 Mar 2021 12:49:27 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 320CAE49E2; Fri, 26 Mar 2021 16:49:21 +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 102895D756; Fri, 26 Mar 2021 16:49:21 +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 C6AD31818467; Fri, 26 Mar 2021 16:49:20 +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 12QGmhOM003127 for ; Fri, 26 Mar 2021 12:48:43 -0400 Received: by smtp.corp.redhat.com (Postfix) id 905BE5D72E; Fri, 26 Mar 2021 16:48:43 +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 585365D6DC; Fri, 26 Mar 2021 16:48:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1616777369; 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=jlqzlXra53IPYqcZgvZpR8dqB3gbxdXlVjsGplez1f8=; b=e7g3nzvBKdiG6ZtiT+rGiC8Z8aXm4e+GoPQNyRT3FfYgKyMe4+NsuGRF4WhlahLNYxpYcI 8F3t0NrJTcLEmQCsdFj597cbPb/VZK7rrm+OZ9H94+4R66P64WxCMp8kQLUO4jbJsVL0tG v2/dH2/W08lOpaPw8+SCpj2eDKAbj3E= X-MC-Unique: A2NmavK6MFS4aSjXUeeAPA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH v6 29/30] nodedev: factor out function to add mediated devices Date: Fri, 26 Mar 2021 11:48:25 -0500 Message-Id: <20210326164826.1720062-30-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.15 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 31322e3afb..35db24817a 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1506,6 +1506,60 @@ removeMissingPersistentMdevs(virNodeDeviceObj *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(virNodeDeviceDef *def) +{ + virNodeDeviceObj *obj; + virObjectEvent *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= ))) { + virNodeDeviceDef *d =3D g_steal_pointer(&owned); + if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, d))) { + virNodeDeviceDefFree(d); + return -1; + } + } else { + bool changed; + virNodeDeviceDef *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) { @@ -1525,52 +1579,9 @@ nodeDeviceUpdateMediatedDevices(void) virNodeDeviceObjListForEachRemove(driver->devs, removeMissingPersistentMdevs, &data); =20 - for (i =3D 0; i < data.ndefs; i++) { - virNodeDeviceObj *obj; - virObjectEvent *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))) { - virNodeDeviceDef *d =3D g_steal_pointer(&def); - if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, d)))= { - virNodeDeviceDefFree(d); - return -1; - } - } else { - bool changed; - virNodeDeviceDef *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.3