From nobody Tue Feb 10 16:18:25 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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 170.10.133.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=1627058484; cv=none; d=zohomail.com; s=zohoarc; b=KtlXZxY6Y4W0pLE1pJAf8X5YLbY4Nygs776ru1Bz7m+nDsPfjhbF/a1jybfT3XNmkJf5X46QUywWFx2Gv3sKGaypX9Dixy+FnUMPoQLgkAW/u9obl21wnu/Wax+5fnTJU+t29aN0duV5nQL3mc3Fa9qcBFEuVeD0Xl8/WvOXyL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627058484; 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=Bw5lNp/DLH9eiImLMw14fLY2IgQtyEPgzBFVJM6hXD0=; b=nlKUSZddy1NsbVGh4w35I9rQiUEndgDNQb12MYdyX32DkUNw7uAqU0dcXEjGjoDb1RL3k6YbJ9CGKIvcAjg04qGNSOdS/8PEpBCX576NWtxsTG/MB+VLG94rXjVbssPHzEdH+sS1U8jy/iNIKiNBjoAFuVV0ptkLJ902xkL0i+M= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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 [170.10.133.124]) by mx.zohomail.com with SMTPS id 1627058484253422.7146097271233; Fri, 23 Jul 2021 09:41:24 -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-600-onrE8kwxMpCCYcei91fNeA-1; Fri, 23 Jul 2021 12:41:21 -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 A26BB3488C; Fri, 23 Jul 2021 16:41:10 +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 84F2F5C1D5; Fri, 23 Jul 2021 16:41:10 +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 50069180BAD0; Fri, 23 Jul 2021 16:41:10 +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 16NGenan001349 for ; Fri, 23 Jul 2021 12:40:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id A0CEC6091B; Fri, 23 Jul 2021 16:40:49 +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 718766A057 for ; Fri, 23 Jul 2021 16:40:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627058483; 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=Bw5lNp/DLH9eiImLMw14fLY2IgQtyEPgzBFVJM6hXD0=; b=e5EbC6Jz6HWFVCHqRqdpWyQ1ritgtLn0Im2NrV6jXxZ4JgSy/jVvo2GwYsTR6viuxGsnbD 6zNKtj6oZLzizk4KCJ/I9y0j7WhFyxCc96cB/ZgvLegOjcpikYCYw5sbIAkUuNMSnj1ary 4Mqi81gv4H98DTmKsgJrwn90l9qLRuM= X-MC-Unique: onrE8kwxMpCCYcei91fNeA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 7/7] nodedev: look up mdevs by UUID and parent Date: Fri, 23 Jul 2021 11:40:42 -0500 Message-Id: <20210723164042.1334799-8-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.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) X-ZM-MESSAGEID: 1627058485556100001 Content-Type: text/plain; charset="utf-8" Since UUID is not guaranteed to be unique by mdevctl, we may have more than one nodedev with the same UUID. Therefore, we need to disambiguate when looking up mdevs by specifying the UUID and parent address, which mdevctl guarantees to be a unique combination. Signed-off-by: Jonathon Jongsma --- src/conf/virnodedeviceobj.c | 18 ++++++++++++++---- src/conf/virnodedeviceobj.h | 3 ++- src/node_device/node_device_driver.c | 24 ++++++++++++++++-------- 3 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 6e7b354f96..d1d23fc857 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -401,13 +401,20 @@ virNodeDeviceObjListFindSCSIHostByWWNs(virNodeDeviceO= bjList *devs, &data); } =20 + +typedef struct { + const char *uuid; + const char *parent_addr; +} FindMediatedDeviceData; + + static int virNodeDeviceObjListFindMediatedDeviceByUUIDCallback(const void *payload, const char *name G_GN= UC_UNUSED, const void *opaque) { virNodeDeviceObj *obj =3D (virNodeDeviceObj *) payload; - const char *uuid =3D (const char *) opaque; + const FindMediatedDeviceData* data =3D opaque; virNodeDevCapsDef *cap; int want =3D 0; =20 @@ -415,7 +422,8 @@ virNodeDeviceObjListFindMediatedDeviceByUUIDCallback(co= nst void *payload, =20 for (cap =3D obj->def->caps; cap !=3D NULL; cap =3D cap->next) { if (cap->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV) { - if (STREQ(cap->data.mdev.uuid, uuid)) { + if (STREQ(cap->data.mdev.uuid, data->uuid) && + STREQ(cap->data.mdev.parent_addr, data->parent_addr)) { want =3D 1; break; } @@ -429,11 +437,13 @@ virNodeDeviceObjListFindMediatedDeviceByUUIDCallback(= const void *payload, =20 virNodeDeviceObj * virNodeDeviceObjListFindMediatedDeviceByUUID(virNodeDeviceObjList *devs, - const char *uuid) + const char *uuid, + const char *parent_addr) { + const FindMediatedDeviceData data =3D {uuid, parent_addr}; return virNodeDeviceObjListSearch(devs, virNodeDeviceObjListFindMediatedDevi= ceByUUIDCallback, - uuid); + &data); } =20 static void diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 1fdd4f65da..068c7c6f34 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -122,7 +122,8 @@ virNodeDeviceObjSetSkipUpdateCaps(virNodeDeviceObj *obj, bool skipUpdateCaps); virNodeDeviceObj * virNodeDeviceObjListFindMediatedDeviceByUUID(virNodeDeviceObjList *devs, - const char *uuid); + const char *uuid, + const char *parent_addr); =20 bool virNodeDeviceObjIsActive(virNodeDeviceObj *obj); diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 4e676bfd56..ddb9a9bca7 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -321,6 +321,7 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, static virNodeDevicePtr nodeDeviceLookupMediatedDeviceByUUID(virConnectPtr conn, const char *uuid, + const char *parent_addr, unsigned int flags) { virNodeDeviceObj *obj =3D NULL; @@ -330,7 +331,7 @@ nodeDeviceLookupMediatedDeviceByUUID(virConnectPtr conn, virCheckFlags(0, NULL); =20 if (!(obj =3D virNodeDeviceObjListFindMediatedDeviceByUUID(driver->dev= s, - uuid))) + uuid, parent_= addr))) return NULL; =20 def =3D virNodeDeviceObjGetDef(obj); @@ -542,23 +543,29 @@ nodeDeviceFindNewDevice(virConnectPtr conn, } =20 =20 +typedef struct { + const char *uuid; + const char *parent_addr; +} NewMediatedDeviceData; + static virNodeDevicePtr nodeDeviceFindNewMediatedDeviceFunc(virConnectPtr conn, const void *opaque) { - const char *uuid =3D opaque; + const NewMediatedDeviceData *data =3D opaque; =20 - return nodeDeviceLookupMediatedDeviceByUUID(conn, uuid, 0); + return nodeDeviceLookupMediatedDeviceByUUID(conn, data->uuid, data->pa= rent_addr, 0); } =20 =20 static virNodeDevicePtr nodeDeviceFindNewMediatedDevice(virConnectPtr conn, - const char *mdev_uuid) + const char *mdev_uuid, + const char *parent_addr) { - return nodeDeviceFindNewDevice(conn, - nodeDeviceFindNewMediatedDeviceFunc, - mdev_uuid); + NewMediatedDeviceData data =3D {mdev_uuid, parent_addr}; + return nodeDeviceFindNewDevice(conn, nodeDeviceFindNewMediatedDeviceFu= nc, + &data); } =20 =20 @@ -867,7 +874,8 @@ nodeDeviceCreateXMLMdev(virConnectPtr conn, def->caps->data.mdev.uuid =3D g_steal_pointer(&uuid); } =20 - return nodeDeviceFindNewMediatedDevice(conn, def->caps->data.mdev.uuid= ); + return nodeDeviceFindNewMediatedDevice(conn, def->caps->data.mdev.uuid, + def->caps->data.mdev.parent_add= r); } =20 =20 --=20 2.31.1