From nobody Sun Apr 28 19:02:49 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) client-ip=209.132.183.25; envelope-from=libvir-list-bounces@redhat.com; helo=mx4-phx2.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.25 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx4-phx2.redhat.com (mx4-phx2.redhat.com [209.132.183.25]) by mx.zohomail.com with SMTPS id 1486591643536356.19032199463607; Wed, 8 Feb 2017 14:07:23 -0800 (PST) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by mx4-phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v18M3uLP023807; Wed, 8 Feb 2017 17:03:57 -0500 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v18M3te8030693 for ; Wed, 8 Feb 2017 17:03:55 -0500 Received: from localhost.localdomain.com (ovpn-116-47.phx2.redhat.com [10.3.116.47]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v18M3srj025420 for ; Wed, 8 Feb 2017 17:03:54 -0500 From: John Ferlan To: libvir-list@redhat.com Date: Wed, 8 Feb 2017 17:03:52 -0500 Message-Id: <1486591432-12613-1-git-send-email-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] nodedev: Return the parent for a virNodeDevicePtr struct 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: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" When the 'parent' was added to the virNodeDevicePtr structure by commit id 'e8a4ea75a' the 'parent' field was not properly filled in when a virGetNodeDevice call was made within driver/config code. Only the device name was ever filled in. Fetching the parent required a second trip via virNodeDeviceGetParent into the node device lookup code was required in order to retrieve the specific parent field (and still the parent field was never filled in although it was free'd). Since we have the data when we initially call virGetNodeDevice from within driver/node_config code - let's just fill in the parent field as well for anyone that wants it without requiring another trip into the node_device lookup just to get the parent. This will allow API's such as virConnectListAllNodeDevices, virNodeDeviceLookupByName, and virNodeDeviceLookupSCSIHostByWWN to retrieve both name and parent in the returned virNodeDevicePtr. Signed-off-by: John Ferlan --- Found this while working on some vHBA in the domain code when I was thinking about using a virConnectListAllNodeDevices... The returned structures didn't have the ->parent filled in...=20 src/conf/node_device_conf.c | 4 ++-- src/node_device/node_device_driver.c | 10 ++++++++-- src/test/test_driver.c | 6 +++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index 4d3268f..f6d7692 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2158,8 +2158,8 @@ virNodeDeviceObjListExport(virConnectPtr conn, if ((!filter || filter(conn, devobj->def)) && virNodeDeviceMatch(devobj, flags)) { if (devices) { - if (!(device =3D virGetNodeDevice(conn, - devobj->def->name))) { + if (!(device =3D virGetNodeDevice(conn, devobj->def->name)= ) || + VIR_STRDUP(device->parent, devobj->def->parent) < 0) { virNodeDeviceObjUnlock(devobj); goto cleanup; } diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 5238e23..4900e32 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -261,7 +261,10 @@ nodeDeviceLookupByName(virConnectPtr conn, const char = *name) if (virNodeDeviceLookupByNameEnsureACL(conn, obj->def) < 0) goto cleanup; =20 - ret =3D virGetNodeDevice(conn, name); + if ((ret =3D virGetNodeDevice(conn, name))) { + if (VIR_STRDUP(ret->parent, obj->def->parent) < 0) + virObjectUnref(ret); + } =20 cleanup: if (obj) @@ -302,7 +305,10 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn= , obj->def) < 0) goto out; =20 - dev =3D virGetNodeDevice(conn, obj->def->name); + if ((dev =3D virGetNodeDevice(conn, obj->def->name= ))) { + if (VIR_STRDUP(dev->parent, obj->def->parent) = < 0) + virObjectUnref(dev); + } virNodeDeviceObjUnlock(obj); goto out; } diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 6820298..8dd738b 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5450,7 +5450,10 @@ testNodeDeviceLookupByName(virConnectPtr conn, const= char *name) goto cleanup; } =20 - ret =3D virGetNodeDevice(conn, name); + if ((ret =3D virGetNodeDevice(conn, name))) { + if (VIR_STRDUP(ret->parent, obj->def->parent) < 0) + virObjectUnref(ret); + } =20 cleanup: if (obj) @@ -5648,6 +5651,7 @@ testNodeDeviceCreateXML(virConnectPtr conn, 0); =20 dev =3D virGetNodeDevice(conn, def->name); + ignore_value(VIR_STRDUP(def->parent, def->parent)); def =3D NULL; cleanup: testDriverUnlock(driver); --=20 2.7.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list