From nobody Thu May 2 19:37:03 2024 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=1627058472; cv=none; d=zohomail.com; s=zohoarc; b=Xm/nV8VLEuLO/GPfGVQdJ5V1wxUxyH581eEtT4MFBjCKEr8c0wR+hQ4KdH1Lus5hhoGeAgMCrzBJvCbOU8NmFVphClO3aGPWPzazgG+hyf/nG8VAHj6vgDs7U+0QVZGTCTWi4eMasqDOI/g7r7mRCiq6cvWphgPaVYbChBVVBYg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627058472; 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=WJaY2B6N9+CSMioGPDKozsDCb5CtuRKIvIUq2v0lQjo=; b=DccEfVIUNnNlq3Nnzifq7/pGSk4jh/j/fFzMl0F/3UkW3jSuyHURSCNRedV/1Cb+nXlp/V8zITGINqm9+Ah7jCmPOobwoeH8xm4BLW24RQuA9jfsF2bElSZzGjV95dCkj0A40gpqYK+PlfpENA+yWiKdMWSmV+aA4ItyDVpiZmc= 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 162705847219581.57391254827769; Fri, 23 Jul 2021 09:41:12 -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-433-L2ZSMjPvPoKqjGx5CiPoTg-1; Fri, 23 Jul 2021 12:41:09 -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 3526C8042E9; Fri, 23 Jul 2021 16:41: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 15CBE5C22B; Fri, 23 Jul 2021 16:41: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 CCD274A7CA; Fri, 23 Jul 2021 16:41:03 +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 16NGelPk001304 for ; Fri, 23 Jul 2021 12:40:47 -0400 Received: by smtp.corp.redhat.com (Postfix) id AA315687D5; Fri, 23 Jul 2021 16:40:47 +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 7C6126091B for ; Fri, 23 Jul 2021 16:40:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627058471; 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=WJaY2B6N9+CSMioGPDKozsDCb5CtuRKIvIUq2v0lQjo=; b=AjGVsYoErcLqzQA1vsdXcP4egCBAqJYXPd4IImC59Be5oPgHnNtFOHPFUJragl/oOf4E47 Vo3gd1jmXzFKHjnLyzsjckvyAlGLJa37t5H6ECP/A6/J+cznJUmdkcP28rDMvYJ1fBNrNs GPXXwOW0QiR2oE6GVRDHnfWhgkpN3zY= X-MC-Unique: L2ZSMjPvPoKqjGx5CiPoTg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 1/7] nodedev: add internal virNodeDeviceObjListFind() Date: Fri, 23 Jul 2021 11:40:36 -0500 Message-Id: <20210723164042.1334799-2-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: 1627058474085100001 Content-Type: text/plain; charset="utf-8" This is a generic function that you can provide your own predicate function to search for a particular device. It will be used in an upcoming commit. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/conf/virnodedeviceobj.c | 53 +++++++++++++++++++++++++++++++------ src/conf/virnodedeviceobj.h | 11 +++++--- src/libvirt_private.syms | 1 + 3 files changed, 54 insertions(+), 11 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index b213592b56..6e7b354f96 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -1026,19 +1026,19 @@ virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj, } =20 =20 -struct virNodeDeviceObjListRemoveHelperData +typedef struct { - virNodeDeviceObjListRemoveIterator callback; + virNodeDeviceObjListPredicate predicate; void *opaque; -}; +} PredicateHelperData; =20 static int virNodeDeviceObjListRemoveHelper(void *key G_GNUC_UNUSED, void *value, void *opaque) { - struct virNodeDeviceObjListRemoveHelperData *data =3D opaque; + PredicateHelperData *data =3D opaque; =20 - return data->callback(value, data->opaque); + return data->predicate(value, data->opaque); } =20 =20 @@ -1054,11 +1054,11 @@ static int virNodeDeviceObjListRemoveHelper(void *k= ey G_GNUC_UNUSED, */ void virNodeDeviceObjListForEachRemove(virNodeDeviceObjList *devs, - virNodeDeviceObjListRemoveIterator callb= ack, + virNodeDeviceObjListPredicate callback, void *opaque) { - struct virNodeDeviceObjListRemoveHelperData data =3D { - .callback =3D callback, + PredicateHelperData data =3D { + .predicate =3D callback, .opaque =3D opaque }; =20 @@ -1068,3 +1068,40 @@ virNodeDeviceObjListForEachRemove(virNodeDeviceObjLi= st *devs, &data); virObjectRWUnlock(devs); } + + +static int virNodeDeviceObjListFindHelper(const void *payload, + const char *name G_GNUC_UNUSED, + const void *opaque) +{ + PredicateHelperData *data =3D (PredicateHelperData *) opaque; + virNodeDeviceObj *obj =3D (virNodeDeviceObj *) payload; + + return data->predicate(obj, data->opaque); +} + + +/** + * virNodeDeviceObjListFind + * @devs: Pointer to object list + * @predicate: function to test the device for a certain property + * @opaque: Opaque data to use as argument to helper + * + * For each object in @devs, call the @predicate helper using @opaque as + * an argument until it returns TRUE. The list may not be modified while + * iterating. + */ +virNodeDeviceObj * +virNodeDeviceObjListFind(virNodeDeviceObjList *devs, + virNodeDeviceObjListPredicate predicate, + void *opaque) +{ + PredicateHelperData data =3D { + .predicate =3D predicate, + .opaque =3D opaque + }; + + return virNodeDeviceObjListSearch(devs, + virNodeDeviceObjListFindHelper, + &data); +} diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 7353e4619b..0cb78748a4 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -136,9 +136,14 @@ void virNodeDeviceObjSetPersistent(virNodeDeviceObj *obj, bool persistent); =20 -typedef bool (*virNodeDeviceObjListRemoveIterator)(virNodeDeviceObj *obj, - const void *opaque); +typedef bool (*virNodeDeviceObjListPredicate)(virNodeDeviceObj *obj, + const void *opaque); =20 void virNodeDeviceObjListForEachRemove(virNodeDeviceObjList *devs, - virNodeDeviceObjListRemoveIterator = callback, + virNodeDeviceObjListPredicate callb= ack, void *opaque); + +virNodeDeviceObj * +virNodeDeviceObjListFind(virNodeDeviceObjList *devs, + virNodeDeviceObjListPredicate callback, + void *opaque); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 4bc2974e7f..9d16d7c6b3 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1287,6 +1287,7 @@ virNodeDeviceObjIsActive; virNodeDeviceObjIsPersistent; virNodeDeviceObjListAssignDef; virNodeDeviceObjListExport; +virNodeDeviceObjListFind; virNodeDeviceObjListFindByName; virNodeDeviceObjListFindBySysfsPath; virNodeDeviceObjListFindMediatedDeviceByUUID; --=20 2.31.1 From nobody Thu May 2 19:37:03 2024 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=1627058482; cv=none; d=zohomail.com; s=zohoarc; b=Q9OLRzlUsSOFIgjNcgNmYe1abCXokcpB2Ohpap1HHmpOuhAVtB0nsMhRgU1PhuRKRzHD+7tP1J9QJoF8mxk6W/+a0AFFCMJLUMQPg5Kaia/gBpBePc98WEBtmXwJHFWldgIRmUpmbzwJ4JdlUwzdle7oBTyP7BJIMDxvC62itMA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627058482; 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=TBqXPGjPQM4E43ttyNTdC+zCxPTLfe3/cTb4k4xprLM=; b=mB3vcH24wpXpQcYvor8pNSCYQ1grpjbGxvDQAiXv+bRaS+mMSgdwqsiRbwie3ADgZtKL83etAfHWg/8PZ48ydueRiLNN/th537IXoQ6u50Cwy5kZLAzEf/EN1E+kZgPl6Nb6IQReqBU+VO4VNSseQLsyo5TP1nwqAvARcqWAbrQ= 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 1627058482124408.08741412280096; Fri, 23 Jul 2021 09:41:22 -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-579-2LFhrhnuP9qaeTGSdg-Aqg-1; Fri, 23 Jul 2021 12:41:19 -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 3729A34834; Fri, 23 Jul 2021 16:41:08 +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 625FF1ABDF; Fri, 23 Jul 2021 16:41:07 +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 2DB2E4A706; Fri, 23 Jul 2021 16:41:07 +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 16NGem0Q001309 for ; Fri, 23 Jul 2021 12:40:48 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0E8BF6091B; 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 C6A9D6A05B for ; Fri, 23 Jul 2021 16:40:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1627058481; 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=TBqXPGjPQM4E43ttyNTdC+zCxPTLfe3/cTb4k4xprLM=; b=GkyEKj/OKBvsdL52nV+4Thma3AOtOncsRxNSP+EeIrB0353NLZgQXffURlj8iQDpma/+1A /gJt4TREcxrJgm1mxPTOS1wiZSkAxvW9lPgZygeLY0NIDEzcDJEnC5j56cXXkT89qE8bOi xtFGeRMYvjwoaw3xq8VXz/lFcusd0mY= X-MC-Unique: 2LFhrhnuP9qaeTGSdg-Aqg-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 2/7] nodedev: fix xml output for mdev parents in test suite Date: Fri, 23 Jul 2021 11:40:37 -0500 Message-Id: <20210723164042.1334799-3-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.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) X-ZM-MESSAGEID: 1627058483135100001 Content-Type: text/plain; charset="utf-8" Commit 51fbbfdce8 attempted to get the proper nodedev name for the parent of an defined mdev by traversing the filesystem and looking for a device that had the appropriate sysfs path. This works, but it would be cleaner to to avoid mucking around in the filesystem and instead just just examine the list of devices we have in memory. We already had a function nodeDeviceFindAddressByName() which constructs an address for parent device in a format that can be used with mdevctl. So if we refactor this function into a a function that simply formats an address for an arbitrary virNodeDeviceObj*, then we can use this function as a predicate for our new virNodeDeviceObjListFind() function from the previous commit. This will search our list of devices for one whose address matches the address we get from mdevctl. One nice benefit of this approach is that our test cases will now display xml output with the proper parent name for mdevs (assuming that we've added the appropriate mock parent devices to the test driver). Previously they just displayed 'computer' for the parent because the alternative would have required specially constructing a mock filesystem environment with a sysfs that mapped to the appropriate parent. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/node_device/node_device_driver.c | 55 ++++++++++--------- .../mdevctl-list-multiple.out.xml | 8 +-- tests/nodedevmdevctltest.c | 28 +++++++++- 3 files changed, 59 insertions(+), 32 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 6f8968f1f0..a3a261f08b 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -648,17 +648,11 @@ nodeDeviceDefToMdevctlConfig(virNodeDeviceDef *def, c= har **buf) =20 =20 static char * -nodeDeviceFindAddressByName(const char *name) +nodeDeviceObjFormatAddress(virNodeDeviceObj *obj) { - virNodeDeviceDef *def =3D NULL; virNodeDevCapsDef *caps =3D NULL; char *addr =3D NULL; - virNodeDeviceObj *dev =3D virNodeDeviceObjListFindByName(driver->devs,= name); - - if (!dev) - return NULL; - - def =3D virNodeDeviceObjGetDef(dev); + virNodeDeviceDef *def =3D virNodeDeviceObjGetDef(obj); for (caps =3D def->caps; caps !=3D NULL; caps =3D caps->next) { switch (caps->data.type) { case VIR_NODE_DEV_CAP_PCI_DEV: { @@ -714,8 +708,6 @@ nodeDeviceFindAddressByName(const char *name) break; } =20 - virNodeDeviceObjEndAPI(&dev); - return addr; } =20 @@ -730,6 +722,7 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def, g_autoptr(virCommand) cmd =3D NULL; const char *subcommand =3D virMdevctlCommandTypeToString(cmd_type); g_autofree char *inbuf =3D NULL; + virNodeDeviceObj *parent_obj =3D NULL; =20 switch (cmd_type) { case MDEVCTL_CMD_CREATE: @@ -754,7 +747,10 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def, switch (cmd_type) { case MDEVCTL_CMD_CREATE: case MDEVCTL_CMD_DEFINE: - parent_addr =3D nodeDeviceFindAddressByName(def->parent); + if ((parent_obj =3D nodeDeviceObjFindByName(def->parent))) { + parent_addr =3D nodeDeviceObjFormatAddress(parent_obj); + virNodeDeviceObjEndAPI(&parent_obj); + } =20 if (!parent_addr) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1042,6 +1038,21 @@ static void mdevGenerateDeviceName(virNodeDeviceDef = *dev) } =20 =20 +static bool +matchDeviceAddress(virNodeDeviceObj *obj, + const void *opaque) +{ + g_autofree char *addr =3D NULL; + bool want =3D false; + + virObjectLock(obj); + addr =3D nodeDeviceObjFormatAddress(obj); + want =3D STREQ_NULLABLE(addr, opaque); + virObjectUnlock(obj); + return want; +} + + static virNodeDeviceDef* nodeDeviceParseMdevctlChildDevice(const char *parent, virJSONValue *json) @@ -1051,7 +1062,7 @@ nodeDeviceParseMdevctlChildDevice(const char *parent, virJSONValue *props; virJSONValue *attrs; g_autoptr(virNodeDeviceDef) child =3D g_new0(virNodeDeviceDef, 1); - g_autofree char *parent_sysfs_path =3D NULL; + virNodeDeviceObj *parent_obj; =20 /* the child object should have a single key equal to its uuid. * The value is an object describing the properties of the mdev */ @@ -1064,20 +1075,12 @@ nodeDeviceParseMdevctlChildDevice(const char *paren= t, /* Look up id of parent device. mdevctl supports defining mdevs for pa= rent * devices that are not present on the system (to support starting mde= vs on * hotplug, etc) so the parent may not actually exist. */ - parent_sysfs_path =3D g_strdup_printf("/sys/class/mdev_bus/%s", parent= ); - if (virFileExists(parent_sysfs_path)) { - g_autofree char *canon_syspath =3D virFileCanonicalizePath(parent_= sysfs_path); - virNodeDeviceObj *parentobj =3D NULL; - - if ((parentobj =3D virNodeDeviceObjListFindBySysfsPath(driver->dev= s, - canon_syspath= ))) { - virNodeDeviceDef *parentdef =3D virNodeDeviceObjGetDef(parento= bj); - child->parent =3D g_strdup(parentdef->name); - virNodeDeviceObjEndAPI(&parentobj); - - child->parent_sysfs_path =3D g_steal_pointer(&canon_syspath); - } - } + if ((parent_obj =3D virNodeDeviceObjListFind(driver->devs, matchDevice= Address, + (void *)parent))) { + virNodeDeviceDef *parentdef =3D virNodeDeviceObjGetDef(parent_obj); + child->parent =3D g_strdup(parentdef->name); + virNodeDeviceObjEndAPI(&parent_obj); + }; if (!child->parent) child->parent =3D g_strdup("computer"); child->caps =3D g_new0(virNodeDevCapsDef, 1); diff --git a/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml b/tests= /nodedevmdevctldata/mdevctl-list-multiple.out.xml index eead6f2a40..c23a3130c1 100644 --- a/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml +++ b/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml @@ -1,6 +1,6 @@ mdev_200f228a_c80a_4d50_bfb7_f5a0e4e34045 - computer + pci_0000_00_02_0 200f228a-c80a-4d50-bfb7-f5a0e4e34045 @@ -9,7 +9,7 @@ mdev_de807ffc_1923_4d5f_b6c9_b20ecebc6d4b - computer + pci_0000_00_02_0 de807ffc-1923-4d5f-b6c9-b20ecebc6d4b @@ -18,7 +18,7 @@ mdev_435722ea_5f43_468a_874f_da34f1217f13 - computer + pci_0000_00_02_0 435722ea-5f43-468a-874f-da34f1217f13 @@ -28,7 +28,7 @@ mdev_783e6dbb_ea0e_411f_94e2_717eaad438bf - computer + matrix_matrix 783e6dbb-ea0e-411f-94e2-717eaad438bf diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index e246de4d87..7af89ab5f1 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -231,7 +231,7 @@ fakeRootDevice(void) * parent of the mdev, and it needs a PCI address */ static virNodeDeviceDef * -fakeParentDevice(void) +fakePCIDevice(void) { virNodeDeviceDef *def =3D NULL; virNodeDevCapPCIDev *pci_dev; @@ -252,6 +252,29 @@ fakeParentDevice(void) return def; } =20 + +/* Add a fake matrix device that can be used as a parent device for mediat= ed + * devices. For our purposes, it only needs to have a name that matches the + * parent of the mdev, and it needs the proper name + */ +static virNodeDeviceDef * +fakeMatrixDevice(void) +{ + virNodeDeviceDef *def =3D NULL; + virNodeDevCapAPMatrix *cap; + + def =3D g_new0(virNodeDeviceDef, 1); + def->caps =3D g_new0(virNodeDevCapsDef, 1); + + def->name =3D g_strdup("matrix_matrix"); + def->parent =3D g_strdup("computer"); + + def->caps->data.type =3D VIR_NODE_DEV_CAP_AP_MATRIX; + cap =3D &def->caps->data.ap_matrix; + cap->addr =3D g_strdup("matrix"); + + return def; +} static int addDevice(virNodeDeviceDef *def) { @@ -274,7 +297,8 @@ static int nodedevTestDriverAddTestDevices(void) { if (addDevice(fakeRootDevice()) < 0 || - addDevice(fakeParentDevice()) < 0) + addDevice(fakePCIDevice()) < 0 || + addDevice(fakeMatrixDevice()) < 0) return -1; =20 return 0; --=20 2.31.1 From nobody Thu May 2 19:37:03 2024 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 Reviewed-by: Michal Privoznik --- 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 From nobody Thu May 2 19:37:03 2024 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=1627058472; cv=none; d=zohomail.com; s=zohoarc; b=IbIBvMf9JY7UybfleTJtJF2dhE9OejSKflKK0yxo63sByyBKlHC88XUEb2zbERKzRnvnDbm/Q7EVskPushSUDo8ULsqcfTMxU+KiSz3C8nlOuuKoE4X/7HohUsAVJXDzA+HfsHqzURWw8SE1V2fzK9CKRdLV0mqY2UF+Fa5PEDo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627058472; 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=qPCLjBhyUBUCL79Rz3JNBP+/DN15TZmV7JnyIuEdeX8=; b=IicUQMcoEbSaftIJnXzRijQSeg2B6EBGObG8cyyxHFt+aDLjOnXm59h8iNeF34JQGNG+nUJiKMC/+Lar854/FDWcIReyaWu/l0EkftQ7+mjbZR+1w/VuwHRCh/MHXMUHbHw/UMEfbhyTXEL+AsRj56vTJ0NfSHEZJxSU6EKNRcc= 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 1627058472256902.5953784811292; Fri, 23 Jul 2021 09:41:12 -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-388-BlTyeR1oNESI4wdapsaE8Q-1; Fri, 23 Jul 2021 12:41:09 -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 42453107B788; Fri, 23 Jul 2021 16:41: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 2090C5D9D5; Fri, 23 Jul 2021 16:41: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 DCEA24A7C9; Fri, 23 Jul 2021 16:41:03 +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 16NGenIv001329 for ; Fri, 23 Jul 2021 12:40:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0646A687D5; 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 75BB56091B 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=1627058471; 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=qPCLjBhyUBUCL79Rz3JNBP+/DN15TZmV7JnyIuEdeX8=; b=EENi9IvZ4RJ17Afc6ZG8Ed6wpj0fth33ao7vmtISEwbvPBSy9Rr7ZasGT9fX8a1k8XYDo3 h5jgnltz6jzBKR6SAiWJfiAFzGjRJOfHSrrvoXw6eZUgyZwbh9onnkvLYb4566nX6G8VZL /8fYKjW/fyqhUptkM+o/Xl/hRDHtIL0= X-MC-Unique: BlTyeR1oNESI4wdapsaE8Q-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 4/7] nodedev: Add parser validation for node devices Date: Fri, 23 Jul 2021 11:40:39 -0500 Message-Id: <20210723164042.1334799-5-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: 1627058474093100002 Content-Type: text/plain; charset="utf-8" At the moment, this is only for mediated devices. When a new mediated device is created or defined, the xml is expected specify the nodedev name of an existing device as its parent. We were not previously validating this and were simply accepting any string here. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/conf/node_device_conf.c | 30 +++++++++--- src/conf/node_device_conf.h | 20 +++++++- src/conf/virnodedeviceobj.h | 1 + src/hypervisor/domain_driver.c | 7 +-- src/node_device/node_device_driver.c | 68 +++++++++++++++++++++++++++- src/node_device/node_device_driver.h | 3 ++ src/node_device/node_device_udev.c | 2 + src/test/test_driver.c | 6 ++- tests/nodedevmdevctltest.c | 7 ++- tests/nodedevxml2xmltest.c | 3 +- 10 files changed, 129 insertions(+), 18 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 332b12f997..cd1c07092d 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2174,10 +2174,12 @@ static virNodeDeviceDef * virNodeDeviceDefParse(const char *str, const char *filename, int create, - const char *virt_type) + const char *virt_type, + virNodeDeviceDefParserCallbacks *parserCallbacks, + void *opaque) { xmlDocPtr xml; - virNodeDeviceDef *def =3D NULL; + g_autoptr(virNodeDeviceDef) def =3D NULL; =20 if ((xml =3D virXMLParse(filename, str, _("(node_device_definition)"))= )) { def =3D virNodeDeviceDefParseNode(xml, xmlDocGetRootElement(xml), @@ -2185,25 +2187,39 @@ virNodeDeviceDefParse(const char *str, xmlFreeDoc(xml); } =20 - return def; + if (parserCallbacks) { + int ret =3D 0; + /* validate definition */ + if (parserCallbacks->validate) { + ret =3D parserCallbacks->validate(def, opaque); + if (ret < 0) + return NULL; + } + } + + return g_steal_pointer(&def); } =20 =20 virNodeDeviceDef * virNodeDeviceDefParseString(const char *str, int create, - const char *virt_type) + const char *virt_type, + virNodeDeviceDefParserCallbacks *parserCallbac= ks, + void *opaque) { - return virNodeDeviceDefParse(str, NULL, create, virt_type); + return virNodeDeviceDefParse(str, NULL, create, virt_type, parserCallb= acks, opaque); } =20 =20 virNodeDeviceDef * virNodeDeviceDefParseFile(const char *filename, int create, - const char *virt_type) + const char *virt_type, + virNodeDeviceDefParserCallbacks *parserCallbacks, + void *opaque) { - return virNodeDeviceDefParse(NULL, filename, create, virt_type); + return virNodeDeviceDefParse(NULL, filename, create, virt_type, parser= Callbacks, opaque); } =20 =20 diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 556878b9a8..786de85060 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -349,15 +349,31 @@ struct _virNodeDeviceDef { char * virNodeDeviceDefFormat(const virNodeDeviceDef *def); =20 + +typedef int (*virNodeDeviceDefPostParseCallback)(virNodeDeviceDef *dev, + void *opaque); + +typedef int (*virNodeDeviceDefValidateCallback)(virNodeDeviceDef *dev, + void *opaque); + +typedef struct _virNodeDeviceDefParserCallbacks { + virNodeDeviceDefPostParseCallback postParse; + virNodeDeviceDefValidateCallback validate; +} virNodeDeviceDefParserCallbacks; + virNodeDeviceDef * virNodeDeviceDefParseString(const char *str, int create, - const char *virt_type); + const char *virt_type, + virNodeDeviceDefParserCallbacks *callbacks, + void *opaque); =20 virNodeDeviceDef * virNodeDeviceDefParseFile(const char *filename, int create, - const char *virt_type); + const char *virt_type, + virNodeDeviceDefParserCallbacks *callbacks, + void *opaque); =20 virNodeDeviceDef * virNodeDeviceDefParseNode(xmlDocPtr xml, diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 0cb78748a4..1fdd4f65da 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -47,6 +47,7 @@ struct _virNodeDeviceDriverState { =20 /* Immutable pointer, self-locking APIs */ virObjectEventState *nodeDeviceEventState; + virNodeDeviceDefParserCallbacks parserCallbacks; }; =20 void diff --git a/src/hypervisor/domain_driver.c b/src/hypervisor/domain_driver.c index 29e11c0447..2969d55173 100644 --- a/src/hypervisor/domain_driver.c +++ b/src/hypervisor/domain_driver.c @@ -395,7 +395,8 @@ virDomainDriverNodeDeviceReset(virNodeDevicePtr dev, if (!xml) return -1; =20 - def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL); + def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL, + NULL, NULL); if (!def) return -1; =20 @@ -440,7 +441,7 @@ virDomainDriverNodeDeviceReAttach(virNodeDevicePtr dev, if (!xml) return -1; =20 - def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL); + def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL, NULL, = NULL); if (!def) return -1; =20 @@ -488,7 +489,7 @@ virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr d= ev, if (!xml) return -1; =20 - def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL); + def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL, NULL, = NULL); if (!def) return -1; =20 diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index ad2ca2a614..8f39d79c68 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -896,7 +896,8 @@ nodeDeviceCreateXML(virConnectPtr conn, =20 virt_type =3D virConnectGetType(conn); =20 - if (!(def =3D virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, virt= _type))) + if (!(def =3D virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, virt= _type, + &driver->parserCallbacks, NULL= ))) return NULL; =20 if (virNodeDeviceCreateXMLEnsureACL(conn, def) < 0) @@ -1376,7 +1377,8 @@ nodeDeviceDefineXML(virConnect *conn, =20 virt_type =3D virConnectGetType(conn); =20 - if (!(def =3D virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, virt= _type))) + if (!(def =3D virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, virt= _type, + &driver->parserCallbacks, NULL= ))) return NULL; =20 if (virNodeDeviceDefineXMLEnsureACL(conn, def) < 0) @@ -1761,3 +1763,65 @@ nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, =20 return ret; } + + +/* validate that parent exists */ +static int nodeDeviceDefValidateMdev(virNodeDeviceDef *def, + G_GNUC_UNUSED virNodeDevCapMdev *mdev, + G_GNUC_UNUSED void *opaque) +{ + virNodeDeviceObj *obj =3D NULL; + if (!def->parent) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("missing parent device")); + return -1; + } + obj =3D virNodeDeviceObjListFindByName(driver->devs, def->parent); + if (!obj) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, + _("invalid parent device '%s'"), + def->parent); + return -1; + } + + virNodeDeviceObjEndAPI(&obj); + return 0; +} + +int nodeDeviceDefValidate(virNodeDeviceDef *def, + G_GNUC_UNUSED void *opaque) +{ + virNodeDevCapsDef *caps =3D NULL; + for (caps =3D def->caps; caps !=3D NULL; caps =3D caps->next) { + switch (caps->data.type) { + case VIR_NODE_DEV_CAP_MDEV: + if (nodeDeviceDefValidateMdev(def, &caps->data.mdev, opaqu= e) < 0) + return -1; + break; + + case VIR_NODE_DEV_CAP_SYSTEM: + case VIR_NODE_DEV_CAP_PCI_DEV: + case VIR_NODE_DEV_CAP_USB_DEV: + case VIR_NODE_DEV_CAP_USB_INTERFACE: + case VIR_NODE_DEV_CAP_NET: + case VIR_NODE_DEV_CAP_SCSI_HOST: + case VIR_NODE_DEV_CAP_SCSI_TARGET: + case VIR_NODE_DEV_CAP_SCSI: + case VIR_NODE_DEV_CAP_STORAGE: + case VIR_NODE_DEV_CAP_FC_HOST: + case VIR_NODE_DEV_CAP_VPORTS: + case VIR_NODE_DEV_CAP_SCSI_GENERIC: + case VIR_NODE_DEV_CAP_DRM: + case VIR_NODE_DEV_CAP_MDEV_TYPES: + case VIR_NODE_DEV_CAP_CCW_DEV: + case VIR_NODE_DEV_CAP_CSS_DEV: + case VIR_NODE_DEV_CAP_VDPA: + case VIR_NODE_DEV_CAP_AP_CARD: + case VIR_NODE_DEV_CAP_AP_QUEUE: + case VIR_NODE_DEV_CAP_AP_MATRIX: + case VIR_NODE_DEV_CAP_LAST: + break; + } + } + return 0; +} diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index edd763f0e4..d9b9b7a961 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -171,3 +171,6 @@ bool nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, int nodeDeviceCreate(virNodeDevice *dev, unsigned int flags); + +int nodeDeviceDefValidate(virNodeDeviceDef *def, + void *opaque); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index e7db74b325..ccf94d8e7d 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2243,6 +2243,8 @@ nodeStateInitialize(bool privileged, driver->privateData =3D priv; driver->nodeDeviceEventState =3D virObjectEventStateNew(); =20 + driver->parserCallbacks.validate =3D nodeDeviceDefValidate; + if (udevPCITranslateInit(privileged) < 0) goto unlock; =20 diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 892dc978f2..c2d642ff6b 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -7481,7 +7481,8 @@ testNodeDeviceMockCreateVport(testDriver *driver, if (!xml) goto cleanup; =20 - if (!(def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL))) + if (!(def =3D virNodeDeviceDefParseString(xml, EXISTING_DEVICE, NULL, = NULL, + NULL))) goto cleanup; =20 VIR_FREE(def->name); @@ -7543,7 +7544,8 @@ testNodeDeviceCreateXML(virConnectPtr conn, =20 virCheckFlags(0, NULL); =20 - if (!(def =3D virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, NULL= ))) + if (!(def =3D virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, NULL, + NULL, NULL))) goto cleanup; =20 /* We run this simply for validation - it essentially validates that diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index 7af89ab5f1..bf1d7b4984 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -12,6 +12,10 @@ =20 #define VIRT_TYPE "QEMU" =20 +static virNodeDeviceDefParserCallbacks parser_callbacks =3D { + .validate =3D nodeDeviceDefValidate +}; + struct TestInfo { const char *filename; virMdevctlCommand command; @@ -66,7 +70,8 @@ testMdevctlCmd(virMdevctlCommand cmd_type, return -1; } =20 - if (!(def =3D virNodeDeviceDefParseFile(mdevxml, create, VIRT_TYPE))) + if (!(def =3D virNodeDeviceDefParseFile(mdevxml, create, VIRT_TYPE, + &parser_callbacks, NULL))) return -1; =20 /* this function will set a stdin buffer containing the json configura= tion diff --git a/tests/nodedevxml2xmltest.c b/tests/nodedevxml2xmltest.c index e9716726d7..d8f81456ee 100644 --- a/tests/nodedevxml2xmltest.c +++ b/tests/nodedevxml2xmltest.c @@ -25,7 +25,8 @@ testCompareXMLToXMLFiles(const char *xml, const char *out= file) if (virTestLoadFile(xml, &xmlData) < 0) goto fail; =20 - if (!(dev =3D virNodeDeviceDefParseString(xmlData, EXISTING_DEVICE, NU= LL))) + if (!(dev =3D virNodeDeviceDefParseString(xmlData, EXISTING_DEVICE, NU= LL, + NULL, NULL))) goto fail; =20 /* Calculate some things that are not read in */ --=20 2.31.1 From nobody Thu May 2 19:37:03 2024 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=1627058482; cv=none; d=zohomail.com; s=zohoarc; b=P2K4PG2+BLJSMsQvR9YLjAGozLbH5QUKVeAnarKt5Sy0cSU+XVAdLmacE2jygBHm9c8XWVP4C6mjcExohARhVg2hcNirrtBI4xfqQlw/qwlUWELvGYtElBubLGkR2x/Kva5Xr5p72aB+mVxv8lS0Y0XHBCUDJp43lQAIXh2xBOw= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627058482; 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=IxvGCkkFvekLITndg5r+sKAfB+Ql+qoV3kUp6sG1ny8=; b=X7P/bDHtYtbgazPhVWQ1H+/yZujybjmo+8NOYxloD2c19RXTKJ3jqP4404u+LemT1xJaeryh+47bdAZu4ggUr+oCp24Y31x5KsQulhvUuosfxUz/i3PYUB4CDb+9h31FhiXZtUcxBjTz0VKRPJAw+RAOopE8/O9qnK4jHjg+eTg= 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 1627058482340596.5322703662865; Fri, 23 Jul 2021 09:41:22 -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-338--B9A6vsZNSelkuUYbTjJ4g-1; Fri, 23 Jul 2021 12:41:19 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 7B40C3487A; 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 5D3F860939; 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 24997180BABF; 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 16NGentW001330 for ; Fri, 23 Jul 2021 12:40:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0A7656091B; 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 CEF0F6A05F 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=1627058481; 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=IxvGCkkFvekLITndg5r+sKAfB+Ql+qoV3kUp6sG1ny8=; b=Gia4kjtzWjZnlisi0MV0Y2UiOMIbHCE0cqk2ImtT67C/rFGgGzeBJRK8E/6KFKLK3U+db0 JN6e//GBBcRQLr4YotTnvGY7nHLP7Sx91+U818nVwzZ2+gf+pA+quQ8c0jk1WXaGTj5+IG 2xd6DnmbeOzZMAQ5dA6usKWQd5dzyRM= X-MC-Unique: -B9A6vsZNSelkuUYbTjJ4g-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 5/7] nodedev: add PostParse callback for nodedev parsing Date: Fri, 23 Jul 2021 11:40:40 -0500 Message-Id: <20210723164042.1334799-6-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.13 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: 1627058483183100002 Content-Type: text/plain; charset="utf-8" This can be used similarly to other postparse callbacks in libvirt -- filling in additional information that can be determined by using the information provided in the XML. In this case, we determine the address of the parent device and cache it in the mdev caps so that we can use it for generating a unique name and interacting with mdevctl. Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/conf/node_device_conf.c | 7 +++++ src/node_device/node_device_driver.c | 45 +++++++++++++++++++++------- src/node_device/node_device_driver.h | 3 ++ src/node_device/node_device_udev.c | 1 + tests/nodedevmdevctltest.c | 1 + 5 files changed, 46 insertions(+), 11 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index cd1c07092d..a7cd90b9e6 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2189,6 +2189,13 @@ virNodeDeviceDefParse(const char *str, =20 if (parserCallbacks) { int ret =3D 0; + /* fill in backend-specific aspects */ + if (parserCallbacks->postParse) { + ret =3D parserCallbacks->postParse(def, opaque); + if (ret < 0) + return NULL; + } + /* validate definition */ if (parserCallbacks->validate) { ret =3D parserCallbacks->validate(def, opaque); diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 8f39d79c68..d76268285f 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -718,11 +718,9 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def, char **outbuf, char **errbuf) { - g_autofree char *parent_addr =3D NULL; g_autoptr(virCommand) cmd =3D NULL; const char *subcommand =3D virMdevctlCommandTypeToString(cmd_type); g_autofree char *inbuf =3D NULL; - virNodeDeviceObj *parent_obj =3D NULL; =20 switch (cmd_type) { case MDEVCTL_CMD_CREATE: @@ -747,12 +745,7 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def, switch (cmd_type) { case MDEVCTL_CMD_CREATE: case MDEVCTL_CMD_DEFINE: - if ((parent_obj =3D nodeDeviceObjFindByName(def->parent))) { - parent_addr =3D nodeDeviceObjFormatAddress(parent_obj); - virNodeDeviceObjEndAPI(&parent_obj); - } - - if (!parent_addr) { + if (!def->caps->data.mdev.parent_addr) { virReportError(VIR_ERR_INTERNAL_ERROR, _("unable to find parent device '%s'"), def->pa= rent); return NULL; @@ -764,7 +757,7 @@ nodeDeviceGetMdevctlCommand(virNodeDeviceDef *def, return NULL; } =20 - virCommandAddArgPair(cmd, "--parent", parent_addr); + virCommandAddArgPair(cmd, "--parent", def->caps->data.mdev.parent_= addr); virCommandAddArgPair(cmd, "--jsonfile", "/dev/stdin"); =20 virCommandSetInputBuffer(cmd, inbuf); @@ -1765,9 +1758,30 @@ nodeDeviceDefCopyFromMdevctl(virNodeDeviceDef *dst, } =20 =20 +int nodeDeviceDefPostParse(virNodeDeviceDef *def, + G_GNUC_UNUSED void *opaque) +{ + virNodeDevCapsDef *caps =3D NULL; + for (caps =3D def->caps; caps !=3D NULL; caps =3D caps->next) { + if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_MDEV) { + virNodeDeviceObj *obj =3D NULL; + + if (def->parent) + obj =3D virNodeDeviceObjListFindByName(driver->devs, def->= parent); + + if (obj) { + caps->data.mdev.parent_addr =3D nodeDeviceObjFormatAddress= (obj); + virNodeDeviceObjEndAPI(&obj); + } + } + } + return 0; +} + + /* validate that parent exists */ static int nodeDeviceDefValidateMdev(virNodeDeviceDef *def, - G_GNUC_UNUSED virNodeDevCapMdev *mdev, + virNodeDevCapMdev *mdev, G_GNUC_UNUSED void *opaque) { virNodeDeviceObj *obj =3D NULL; @@ -1783,8 +1797,17 @@ static int nodeDeviceDefValidateMdev(virNodeDeviceDe= f *def, def->parent); return -1; } - virNodeDeviceObjEndAPI(&obj); + + /* the post-parse callback should have found the address of the parent + * device and stored it in the mdev caps */ + if (!mdev->parent_addr) { + virReportError(VIR_ERR_PARSE_FAILED, + _("Unable to find address for parent device '%s'"), + def->parent); + return -1; + } + return 0; } =20 diff --git a/src/node_device/node_device_driver.h b/src/node_device/node_de= vice_driver.h index d9b9b7a961..fdc92b8aef 100644 --- a/src/node_device/node_device_driver.h +++ b/src/node_device/node_device_driver.h @@ -172,5 +172,8 @@ int nodeDeviceCreate(virNodeDevice *dev, unsigned int flags); =20 +int nodeDeviceDefPostParse(virNodeDeviceDef *def, + void *opaque); + int nodeDeviceDefValidate(virNodeDeviceDef *def, void *opaque); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index ccf94d8e7d..81037d8139 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -2243,6 +2243,7 @@ nodeStateInitialize(bool privileged, driver->privateData =3D priv; driver->nodeDeviceEventState =3D virObjectEventStateNew(); =20 + driver->parserCallbacks.postParse =3D nodeDeviceDefPostParse; driver->parserCallbacks.validate =3D nodeDeviceDefValidate; =20 if (udevPCITranslateInit(privileged) < 0) diff --git a/tests/nodedevmdevctltest.c b/tests/nodedevmdevctltest.c index bf1d7b4984..d88e08f485 100644 --- a/tests/nodedevmdevctltest.c +++ b/tests/nodedevmdevctltest.c @@ -13,6 +13,7 @@ #define VIRT_TYPE "QEMU" =20 static virNodeDeviceDefParserCallbacks parser_callbacks =3D { + .postParse =3D nodeDeviceDefPostParse, .validate =3D nodeDeviceDefValidate }; =20 --=20 2.31.1 From nobody Thu May 2 19:37:03 2024 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=1627058478; cv=none; d=zohomail.com; s=zohoarc; b=mf3jCd2JKAo4YhDB8i0A6BnFAfrEH/xAyz/IurGSHA1ufO+bUfZAV7XPpHgt6HPtgxII9mpBYwKMKYQ5SjISod5I2yTpyvr1PA9jAKz5+bEyyHCkDOFvgDFxIye3lmymQphqYbHMtQWKIjj4PsKxmX64xwwa8JNmHAAEFQsji7s= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1627058478; 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=tS9E7008OQ9f0AlDjIlo159btHknz1ErRZBNszwMaMo=; b=JXMtcd8jp2E/7kvL7eNr5vZTROf0mwIgzgTch50wL89lHmqM3YCyCLu3yShppIN62ZlUPxlrAfzuxPINXocKwIZ0LqilG2wuu5znGWY9UMWCyeoo37wsG9+aCBNMrt4RloY407/PijzBq8W1dZhdstPeZsjZFCUdr3n3AH/H7bg= 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 1627058478687996.314741072376; Fri, 23 Jul 2021 09:41:18 -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-231-CWIi7L2xOGeJysUFDAjlfA-1; Fri, 23 Jul 2021 12:41:13 -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 9373618C43C6; Fri, 23 Jul 2021 16:41:07 +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 667E669320; Fri, 23 Jul 2021 16:41:07 +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 2F43D180BAB2; Fri, 23 Jul 2021 16:41:07 +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 16NGengk001339 for ; Fri, 23 Jul 2021 12:40:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 543D3687D5; 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 258796091B 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=1627058477; 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=tS9E7008OQ9f0AlDjIlo159btHknz1ErRZBNszwMaMo=; b=SV0+m8HRH9lHYJIHbUPrL/CRNQXGIrxYdZf1gIm3flea+tmGdJOiTzj6GKMMI9XSG7f3Yb z8ivYIEKQuaUrqbAR6aTyT+BHtj5FQ1fRisSnq6A7AD6Xjbl8g5DrxCp25SgypX/61eCEa 7loW4itEYXIdfmQ3ylm7UylTFQm0viI= X-MC-Unique: CWIi7L2xOGeJysUFDAjlfA-1 From: Jonathon Jongsma To: libvir-list@redhat.com Subject: [libvirt PATCH 6/7] nodedev: Handle inactive mdevs with the same UUID Date: Fri, 23 Jul 2021 11:40:41 -0500 Message-Id: <20210723164042.1334799-7-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.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) X-ZM-MESSAGEID: 1627058480737100001 Content-Type: text/plain; charset="utf-8" Unfortunately, mdevctl supports defining more than one mdev with the same UUID as long as they have different parent devices. (Only one of these devices can be active at any given time). This means that we can't use the UUID alone as a way to uniquely identify mdev node devices. Append the parent address to ensure uniqueness. For example: Before: mdev_88a6b868_46bd_4015_8e5b_26107f82da38 After: mdev_88a6b868_46bd_4015_8e5b_26107f82da38_0000_00_02_0 Related: https://bugzilla.redhat.com/show_bug.cgi?id=3D1979440 Signed-off-by: Jonathon Jongsma Reviewed-by: Michal Privoznik --- src/node_device/node_device_driver.c | 3 ++- src/node_device/node_device_udev.c | 2 +- tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml | 8 ++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index d76268285f..4e676bfd56 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -1028,7 +1028,8 @@ nodeDeviceGetMdevctlListCommand(bool defined, =20 static void mdevGenerateDeviceName(virNodeDeviceDef *dev) { - nodeDeviceGenerateName(dev, "mdev", dev->caps->data.mdev.uuid, NULL); + nodeDeviceGenerateName(dev, "mdev", dev->caps->data.mdev.uuid, + dev->caps->data.mdev.parent_addr); } =20 =20 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 81037d8139..90a64f16b0 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1067,7 +1067,7 @@ udevProcessMediatedDevice(struct udev_device *dev, return -1; } =20 - udevGenerateDeviceName(dev, def, NULL); + udevGenerateDeviceName(dev, def, data->parent_addr); =20 data->iommuGroupNumber =3D iommugrp; =20 diff --git a/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml b/tests= /nodedevmdevctldata/mdevctl-list-multiple.out.xml index c23a3130c1..3971898549 100644 --- a/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml +++ b/tests/nodedevmdevctldata/mdevctl-list-multiple.out.xml @@ -1,5 +1,5 @@ - mdev_200f228a_c80a_4d50_bfb7_f5a0e4e34045 + mdev_200f228a_c80a_4d50_bfb7_f5a0e4e34045_0000_00_02_0 pci_0000_00_02_0 @@ -8,7 +8,7 @@ - mdev_de807ffc_1923_4d5f_b6c9_b20ecebc6d4b + mdev_de807ffc_1923_4d5f_b6c9_b20ecebc6d4b_0000_00_02_0 pci_0000_00_02_0 @@ -17,7 +17,7 @@ - mdev_435722ea_5f43_468a_874f_da34f1217f13 + mdev_435722ea_5f43_468a_874f_da34f1217f13_0000_00_02_0 pci_0000_00_02_0 @@ -27,7 +27,7 @@ - mdev_783e6dbb_ea0e_411f_94e2_717eaad438bf + mdev_783e6dbb_ea0e_411f_94e2_717eaad438bf_matrix matrix_matrix --=20 2.31.1 From nobody Thu May 2 19:37:03 2024 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 Reviewed-by: Michal Privoznik --- 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