From nobody Tue Feb 10 02:49:18 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=1627058462; cv=none; d=zohomail.com; s=zohoarc; b=ACwp5JZ46et52lQcEZex2yyaKCjJw/mnhSCTP16iEKD8fKK9llaZ2lX2YDQp+Drf4j4kLPn2g8hMcyp7O2iOZRJHhP0utXQiMCOuzPnulNsQu+v2uN6SZL97fsIVZYoM70geShrSSMgfD6N9ra2r7TSGwFgSXp38mw8/olj7nuM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627058462; 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=87Y5aYY47Ov+pyGHbgUBLwGTactEhLrcNka4VjFj3WI=; b=eRqhvbDDk9J4AdCs7qtbV3+/DQUeRXEL1XZICcWYDW0bqszkii8x+28pPHzjqhgzON1uONGdMH10NnO4N39R6QREcbOryOKoX4XbpYivG6JxoATyHMbwcWET7htsy+qCR17XoxKoS+2WXSYBqbi2WkvOCRu0wdr9ZBefrGSWvKE= 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) 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 1627058462881146.55250700811337; Fri, 23 Jul 2021 09:41:02 -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-345-Kg5NnimHODWPsIDg6W84HA-1; Fri, 23 Jul 2021 12:41:00 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8A4548042E5; Fri, 23 Jul 2021 16:40:53 +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 2EFA65D9C6; Fri, 23 Jul 2021 16:40:53 +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 9414D180BAB0; Fri, 23 Jul 2021 16:40:51 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 16NGemaW001314 for ; Fri, 23 Jul 2021 12:40:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 588996091B; Fri, 23 Jul 2021 16:40:48 +0000 (UTC) Received: from himantopus.redhat.com (ovpn-114-96.phx2.redhat.com [10.3.114.96]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2B005687D5 for ; Fri, 23 Jul 2021 16:40:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627058461; 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=87Y5aYY47Ov+pyGHbgUBLwGTactEhLrcNka4VjFj3WI=; b=f2W22CUnb1sdpLT8nLFShBcmiW8J2SoqbfGfRaOrerDQlQK719EfeC1r8iAtlCNcZJXB56 sWBPhO0DtjMmCgu59C3OF+ZT2HjJfpsbX43RbMFe/BcoFpgAWl7MrtZgBgHgrMxbtWvvId iDK3hgjWtBTalOWMyYQafFsXQql62fE= X-MC-Unique: Kg5NnimHODWPsIDg6W84HA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 3/7] nodedev: cache parent address in mdev caps Date: Fri, 23 Jul 2021 11:40:38 -0500 Message-Id: <20210723164042.1334799-4-jjongsma@redhat.com> In-Reply-To: <20210723164042.1334799-1-jjongsma@redhat.com> References: <20210723164042.1334799-1-jjongsma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 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.79 on 10.5.11.14 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) X-ZM-MESSAGEID: 1627058464626100001 Content-Type: text/plain; charset="utf-8" mdevctl can report multiple defined devices with the same UUID but different parents, including parents that don't actually exist on the host machine. Libvirt sets the parent to the 'computer' device for all of the mdevs that have nonexistent parents. Because of this, it's possible that there are multiple devices with the same UUID and the same 'computer' device as their parent, so the combination of uuid and parent 'nodedev name is not guaranteed to be a unique name. We need to ensure that each nodedev has a unique name. If we can't use the UUID as a unique nodedev name, and we can't use the combination of UUID and nodedev parent name, we need to find another solution. By caching and using the parent name reported by mdevctl in combination with the UUID, we can achieve a unique name. mdevctl guarantees that its uuid/parent combination is unique. This value will be used to set the mdev nodedev name in a following commit. Signed-off-by: Jonathon Jongsma --- src/conf/node_device_conf.h | 1 + src/node_device/node_device_driver.c | 1 + src/node_device/node_device_udev.c | 16 ++++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index a60562e4fe..556878b9a8 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -153,6 +153,7 @@ struct _virNodeDevCapMdev { char *uuid; virMediatedDeviceAttr **attributes; size_t nattributes; + char *parent_addr; }; =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 a3a261f08b..ad2ca2a614 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1088,6 +1088,7 @@ nodeDeviceParseMdevctlChildDevice(const char *parent, =20 mdev =3D &child->caps->data.mdev; mdev->uuid =3D g_strdup(uuid); + mdev->parent_addr =3D g_strdup(parent); mdev->type =3D g_strdup(virJSONValueObjectGetString(props, "mdev_type")); =20 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index f99578414d..e7db74b325 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1024,6 +1024,7 @@ udevProcessMediatedDevice(struct udev_device *dev, char *linkpath =3D NULL; char *canonicalpath =3D NULL; virNodeDevCapMdev *data =3D &def->caps->data.mdev; + struct udev_device *parent_device =3D NULL; =20 /* Because of a kernel uevent race, we might get the 'add' event prior= to * the sysfs tree being ready, so any attempt to access any sysfs attr= ibute @@ -1051,6 +1052,21 @@ udevProcessMediatedDevice(struct udev_device *dev, if ((iommugrp =3D virMediatedDeviceGetIOMMUGroupNum(data->uuid)) < 0) goto cleanup; =20 + /* lookup the address of parent device */ + parent_device =3D udev_device_get_parent(dev); + if (parent_device) { + const char *parent_sysfs_path =3D udev_device_get_syspath(parent_d= evice); + if (parent_sysfs_path) + data->parent_addr =3D g_path_get_basename(parent_sysfs_path); + } + + if (!data->parent_addr) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("Could not get parent of '%s'"), + udev_device_get_syspath(dev)); + return -1; + } + udevGenerateDeviceName(dev, def, NULL); =20 data->iommuGroupNumber =3D iommugrp; --=20 2.31.1