From nobody Sun May 5 18:38:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496495541415481.2705511181863; Sat, 3 Jun 2017 06:12:21 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 303C180484; Sat, 3 Jun 2017 13:12:19 +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 01EE071C24; Sat, 3 Jun 2017 13:12:19 +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 AFAB6180BAF4; Sat, 3 Jun 2017 13:12:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DC6bF005736 for ; Sat, 3 Jun 2017 09:12:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5F39C179C2; Sat, 3 Jun 2017 13:12:06 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 2097F7BAE1 for ; Sat, 3 Jun 2017 13:12:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 303C180484 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 303C180484 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:11:51 -0400 Message-Id: <20170603131202.17611-2-jferlan@redhat.com> In-Reply-To: <20170603131202.17611-1-jferlan@redhat.com> References: <20170603131202.17611-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 01/12] nodedev: Alter virNodeDeviceObjRemove 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 03 Jun 2017 13:12:19 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than passing the object to be removed by reference, pass by value and then let the caller decide whether or not the object should be free'd. This function should just handle the remove of the object from the list for which it was placed during virNodeDeviceObjAssignDef. One caller in node_device_hal would fail to go through the dev_create path since the @dev would have been NULL after returning from the Remove API. Signed-off-by: John Ferlan --- src/conf/virnodedeviceobj.c | 14 ++++++-------- src/conf/virnodedeviceobj.h | 2 +- src/libvirt_private.syms | 1 + src/node_device/node_device_hal.c | 10 ++++++---- src/node_device/node_device_udev.c | 3 ++- src/test/test_driver.c | 8 ++++++-- 6 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index e78f451..fa73de1 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -301,23 +301,21 @@ virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr dev= s, =20 void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, - virNodeDeviceObjPtr *dev) + virNodeDeviceObjPtr dev) { size_t i; =20 - virNodeDeviceObjUnlock(*dev); + virNodeDeviceObjUnlock(dev); =20 for (i =3D 0; i < devs->count; i++) { - virNodeDeviceObjLock(*dev); - if (devs->objs[i] =3D=3D *dev) { - virNodeDeviceObjUnlock(*dev); - virNodeDeviceObjFree(devs->objs[i]); - *dev =3D NULL; + virNodeDeviceObjLock(devs->objs[i]); + if (devs->objs[i] =3D=3D dev) { + virNodeDeviceObjUnlock(devs->objs[i]); =20 VIR_DELETE_ELEMENT(devs->objs, i, devs->count); break; } - virNodeDeviceObjUnlock(*dev); + virNodeDeviceObjUnlock(devs->objs[i]); } } =20 diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 05a9d11..9bc02ee 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -58,7 +58,7 @@ virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs, =20 void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, - virNodeDeviceObjPtr *dev); + virNodeDeviceObjPtr dev); =20 int virNodeDeviceObjGetParentHost(virNodeDeviceObjListPtr devs, diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 683a232..4a10508 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -959,6 +959,7 @@ virNetworkObjUpdateAssignDef; virNodeDeviceObjAssignDef; virNodeDeviceObjFindByName; virNodeDeviceObjFindBySysfsPath; +virNodeDeviceObjFree; virNodeDeviceObjGetDef; virNodeDeviceObjGetNames; virNodeDeviceObjGetParentHost; diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_devic= e_hal.c index f468e42..c354cd3 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -514,7 +514,7 @@ dev_refresh(const char *udi) /* Simply "rediscover" device -- incrementally handling changes * to sub-capabilities (like net.80203) is nasty ... so avoid it. */ - virNodeDeviceObjRemove(&driver->devs, &dev); + virNodeDeviceObjRemove(&driver->devs, dev); } else { VIR_DEBUG("no device named %s", name); } @@ -543,10 +543,12 @@ device_removed(LibHalContext *ctx ATTRIBUTE_UNUSED, nodeDeviceLock(); dev =3D virNodeDeviceObjFindByName(&driver->devs, name); VIR_DEBUG("%s", name); - if (dev) - virNodeDeviceObjRemove(&driver->devs, &dev); - else + if (dev) { + virNodeDeviceObjRemove(&driver->devs, dev); + virNodeDeviceObjFree(dev); + } else { VIR_DEBUG("no device named %s", name); + } nodeDeviceUnlock(); } =20 diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 174124a..819e4e7 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1333,7 +1333,8 @@ udevRemoveOneDevice(struct udev_device *device) =20 VIR_DEBUG("Removing device '%s' with sysfs path '%s'", def->name, name); - virNodeDeviceObjRemove(&driver->devs, &dev); + virNodeDeviceObjRemove(&driver->devs, dev); + virNodeDeviceObjFree(dev); =20 if (event) virObjectEventStateQueue(driver->nodeDeviceEventState, event); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index e5938f5..e323619 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4530,7 +4530,9 @@ testDestroyVport(testDriverPtr privconn, VIR_NODE_DEVICE_EVENT_DELETED, 0); =20 - virNodeDeviceObjRemove(&privconn->devs, &obj); + virNodeDeviceObjRemove(&privconn->devs, obj); + virNodeDeviceObjFree(obj); + obj =3D NULL; =20 ret =3D 0; =20 @@ -5624,7 +5626,9 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) 0); =20 virNodeDeviceObjLock(obj); - virNodeDeviceObjRemove(&driver->devs, &obj); + virNodeDeviceObjRemove(&driver->devs, obj); + virNodeDeviceObjFree(obj); + obj =3D NULL; =20 out: if (obj) --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:38:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496495545305214.90534258420655; Sat, 3 Jun 2017 06:12:25 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 00C90334590; Sat, 3 Jun 2017 13:12:23 +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 C6E9F71C48; Sat, 3 Jun 2017 13:12:22 +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 7FA644A48E; Sat, 3 Jun 2017 13:12:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DC6ri005741 for ; Sat, 3 Jun 2017 09:12:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id C5E767B8FD; Sat, 3 Jun 2017 13:12:06 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 870DF179C2 for ; Sat, 3 Jun 2017 13:12:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 00C90334590 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 00C90334590 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:11:52 -0400 Message-Id: <20170603131202.17611-3-jferlan@redhat.com> In-Reply-To: <20170603131202.17611-1-jferlan@redhat.com> References: <20170603131202.17611-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 02/12] test: Adjust cleanup/error paths for nodedev test APIs 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 03 Jun 2017 13:12:23 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" - Rather than "goto cleanup;" on failure to virNodeDeviceObjFindByName an @obj, just return directly. This then allows the cleanup: label code to not have to check "if (obj)" before calling virNodeDeviceObjUnlock. This also simplifies some exit logic... - In testNodeDeviceObjFindByName use an error: label to handle the failure and don't do the ncaps++ within the VIR_STRDUP() source target index. Only increment ncaps after success. Easier on eyes at error label too. - In testNodeDeviceDestroy use "cleanup" rather than "out" for the goto Signed-off-by: John Ferlan --- src/test/test_driver.c | 75 +++++++++++++++++++---------------------------= ---- 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index e323619..e91dfa3 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4509,7 +4509,6 @@ testDestroyVport(testDriverPtr privconn, const char *wwnn ATTRIBUTE_UNUSED, const char *wwpn ATTRIBUTE_UNUSED) { - int ret =3D -1; virNodeDeviceObjPtr obj =3D NULL; virObjectEventPtr event =3D NULL; =20 @@ -4523,7 +4522,7 @@ testDestroyVport(testDriverPtr privconn, if (!(obj =3D virNodeDeviceObjFindByName(&privconn->devs, "scsi_host12= "))) { virReportError(VIR_ERR_NO_NODE_DEVICE, "%s", _("no node device with matching name 'scsi_host12'"= )); - goto cleanup; + return -1; } =20 event =3D virNodeDeviceEventLifecycleNew("scsi_host12", @@ -4534,13 +4533,8 @@ testDestroyVport(testDriverPtr privconn, virNodeDeviceObjFree(obj); obj =3D NULL; =20 - ret =3D 0; - - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); testObjectEventQueue(privconn, event); - return ret; + return 0; } =20 =20 @@ -5328,7 +5322,7 @@ testNodeDeviceLookupByName(virConnectPtr conn, const = char *name) virNodeDevicePtr ret =3D NULL; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, name))) - goto cleanup; + return NULL; def =3D virNodeDeviceObjGetDef(obj); =20 if ((ret =3D virGetNodeDevice(conn, name))) { @@ -5338,9 +5332,7 @@ testNodeDeviceLookupByName(virConnectPtr conn, const = char *name) } } =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjUnlock(obj); return ret; } =20 @@ -5355,13 +5347,11 @@ testNodeDeviceGetXMLDesc(virNodeDevicePtr dev, virCheckFlags(0, NULL); =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto cleanup; + return NULL; =20 ret =3D virNodeDeviceDefFormat(virNodeDeviceObjGetDef(obj)); =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjUnlock(obj); return ret; } =20 @@ -5374,7 +5364,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) char *ret =3D NULL; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto cleanup; + return NULL; def =3D virNodeDeviceObjGetDef(obj); =20 if (def->parent) { @@ -5384,9 +5374,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) "%s", _("no parent for this device")); } =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjUnlock(obj); return ret; } =20 @@ -5399,20 +5387,16 @@ testNodeDeviceNumOfCaps(virNodeDevicePtr dev) virNodeDeviceDefPtr def; virNodeDevCapsDefPtr caps; int ncaps =3D 0; - int ret =3D -1; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto cleanup; + return -1; def =3D virNodeDeviceObjGetDef(obj); =20 for (caps =3D def->caps; caps; caps =3D caps->next) ++ncaps; - ret =3D ncaps; =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); - return ret; + virNodeDeviceObjUnlock(obj); + return ncaps; } =20 =20 @@ -5424,27 +5408,26 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char *= *const names, int maxnames) virNodeDeviceDefPtr def; virNodeDevCapsDefPtr caps; int ncaps =3D 0; - int ret =3D -1; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto cleanup; + return -1; def =3D virNodeDeviceObjGetDef(obj); =20 for (caps =3D def->caps; caps && ncaps < maxnames; caps =3D caps->next= ) { - if (VIR_STRDUP(names[ncaps++], virNodeDevCapTypeToString(caps->dat= a.type)) < 0) - goto cleanup; + if (VIR_STRDUP(names[ncaps], + virNodeDevCapTypeToString(caps->data.type)) < 0) + goto error; + ncaps++; } - ret =3D ncaps; =20 - cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); - if (ret =3D=3D -1) { - --ncaps; - while (--ncaps >=3D 0) - VIR_FREE(names[ncaps]); - } - return ret; + virNodeDeviceObjUnlock(obj); + return ncaps; + + error: + while (--ncaps >=3D 0) + VIR_FREE(names[ncaps]); + virNodeDeviceObjUnlock(obj); + return -1; } =20 =20 @@ -5598,14 +5581,14 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) virObjectEventPtr event =3D NULL; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) - goto out; + return -1; def =3D virNodeDeviceObjGetDef(obj); =20 if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) =3D=3D -1) - goto out; + goto cleanup; =20 if (VIR_STRDUP(parent_name, def->parent) < 0) - goto out; + goto cleanup; =20 /* virNodeDeviceGetParentHost will cause the device object's lock to be * taken, so we have to dup the parent's name and drop the lock @@ -5618,7 +5601,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) if (virNodeDeviceObjGetParentHost(&driver->devs, def, EXISTING_DEVICE) < 0) { obj =3D NULL; - goto out; + goto cleanup; } =20 event =3D virNodeDeviceEventLifecycleNew(dev->name, @@ -5630,7 +5613,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) virNodeDeviceObjFree(obj); obj =3D NULL; =20 - out: + cleanup: if (obj) virNodeDeviceObjUnlock(obj); testObjectEventQueue(driver, event); --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:38:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496495549085523.1915342882152; Sat, 3 Jun 2017 06:12:29 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 1F97C804EB; Sat, 3 Jun 2017 13:12:27 +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 ED9E17BAE9; Sat, 3 Jun 2017 13:12:26 +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 23E40180BAFF; Sat, 3 Jun 2017 13:12:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DC79X005746 for ; Sat, 3 Jun 2017 09:12:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id 390B77B8D9; Sat, 3 Jun 2017 13:12:07 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id ED331179C2 for ; Sat, 3 Jun 2017 13:12:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 1F97C804EB Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx03.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 1F97C804EB From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:11:53 -0400 Message-Id: <20170603131202.17611-4-jferlan@redhat.com> In-Reply-To: <20170603131202.17611-1-jferlan@redhat.com> References: <20170603131202.17611-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 03/12] nodedev: Use common naming for virnodedeviceobj 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 03 Jun 2017 13:12:27 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" A virNodeDeviceObjPtr is an @obj A virNodeDeviceObjListPtr is an @devs Signed-off-by: John Ferlan --- src/conf/virnodedeviceobj.c | 124 ++++++++++++++++++++++------------------= ---- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index fa73de1..3aff5ca 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -41,10 +41,10 @@ virNodeDeviceObjGetDef(virNodeDeviceObjPtr obj) =20 =20 static int -virNodeDeviceObjHasCap(const virNodeDeviceObj *dev, +virNodeDeviceObjHasCap(const virNodeDeviceObj *obj, const char *cap) { - virNodeDevCapsDefPtr caps =3D dev->def->caps; + virNodeDevCapsDefPtr caps =3D obj->def->caps; const char *fc_host_cap =3D virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_FC_HOST); const char *vports_cap =3D @@ -105,9 +105,9 @@ virNodeDeviceObjHasCap(const virNodeDeviceObj *dev, * Pointer to the caps or NULL if not found */ static virNodeDevCapsDefPtr -virNodeDeviceFindFCCapDef(const virNodeDeviceObj *dev) +virNodeDeviceFindFCCapDef(const virNodeDeviceObj *obj) { - virNodeDevCapsDefPtr caps =3D dev->def->caps; + virNodeDevCapsDefPtr caps =3D obj->def->caps; =20 while (caps) { if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_SCSI_HOST && @@ -129,9 +129,9 @@ virNodeDeviceFindFCCapDef(const virNodeDeviceObj *dev) * Pointer to the caps or NULL if not found */ static virNodeDevCapsDefPtr -virNodeDeviceFindVPORTCapDef(const virNodeDeviceObj *dev) +virNodeDeviceFindVPORTCapDef(const virNodeDeviceObj *obj) { - virNodeDevCapsDefPtr caps =3D dev->def->caps; + virNodeDevCapsDefPtr caps =3D obj->def->caps; =20 while (caps) { if (caps->data.type =3D=3D VIR_NODE_DEV_CAP_SCSI_HOST && @@ -240,16 +240,16 @@ virNodeDeviceFindByCap(virNodeDeviceObjListPtr devs, =20 =20 void -virNodeDeviceObjFree(virNodeDeviceObjPtr dev) +virNodeDeviceObjFree(virNodeDeviceObjPtr obj) { - if (!dev) + if (!obj) return; =20 - virNodeDeviceDefFree(dev->def); + virNodeDeviceDefFree(obj->def); =20 - virMutexDestroy(&dev->lock); + virMutexDestroy(&obj->lock); =20 - VIR_FREE(dev); + VIR_FREE(obj); } =20 =20 @@ -268,48 +268,48 @@ virNodeDeviceObjPtr virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs, virNodeDeviceDefPtr def) { - virNodeDeviceObjPtr device; + virNodeDeviceObjPtr obj; =20 - if ((device =3D virNodeDeviceObjFindByName(devs, def->name))) { - virNodeDeviceDefFree(device->def); - device->def =3D def; - return device; + if ((obj =3D virNodeDeviceObjFindByName(devs, def->name))) { + virNodeDeviceDefFree(obj->def); + obj->def =3D def; + return obj; } =20 - if (VIR_ALLOC(device) < 0) + if (VIR_ALLOC(obj) < 0) return NULL; =20 - if (virMutexInit(&device->lock) < 0) { + if (virMutexInit(&obj->lock) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot initialize mutex")); - VIR_FREE(device); + VIR_FREE(obj); return NULL; } - virNodeDeviceObjLock(device); + virNodeDeviceObjLock(obj); =20 - if (VIR_APPEND_ELEMENT_COPY(devs->objs, devs->count, device) < 0) { - virNodeDeviceObjUnlock(device); - virNodeDeviceObjFree(device); + if (VIR_APPEND_ELEMENT_COPY(devs->objs, devs->count, obj) < 0) { + virNodeDeviceObjUnlock(obj); + virNodeDeviceObjFree(obj); return NULL; } - device->def =3D def; + obj->def =3D def; =20 - return device; + return obj; =20 } =20 =20 void virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, - virNodeDeviceObjPtr dev) + virNodeDeviceObjPtr obj) { size_t i; =20 - virNodeDeviceObjUnlock(dev); + virNodeDeviceObjUnlock(obj); =20 for (i =3D 0; i < devs->count; i++) { virNodeDeviceObjLock(devs->objs[i]); - if (devs->objs[i] =3D=3D dev) { + if (devs->objs[i] =3D=3D obj) { virNodeDeviceObjUnlock(devs->objs[i]); =20 VIR_DELETE_ELEMENT(devs->objs, i, devs->count); @@ -333,15 +333,15 @@ virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, * parent_host value on success (>=3D 0), -1 otherwise. */ static int -virNodeDeviceFindFCParentHost(virNodeDeviceObjPtr parent) +virNodeDeviceFindFCParentHost(virNodeDeviceObjPtr obj) { - virNodeDevCapsDefPtr cap =3D virNodeDeviceFindVPORTCapDef(parent); + virNodeDevCapsDefPtr cap =3D virNodeDeviceFindVPORTCapDef(obj); =20 if (!cap) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Parent device %s is not capable " "of vport operations"), - parent->def->name); + obj->def->name); return -1; } =20 @@ -354,19 +354,19 @@ virNodeDeviceGetParentHostByParent(virNodeDeviceObjLi= stPtr devs, const char *dev_name, const char *parent_name) { - virNodeDeviceObjPtr parent =3D NULL; + virNodeDeviceObjPtr obj =3D NULL; int ret; =20 - if (!(parent =3D virNodeDeviceObjFindByName(devs, parent_name))) { + if (!(obj =3D virNodeDeviceObjFindByName(devs, parent_name))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find parent device for '%s'"), dev_name); return -1; } =20 - ret =3D virNodeDeviceFindFCParentHost(parent); + ret =3D virNodeDeviceFindFCParentHost(obj); =20 - virNodeDeviceObjUnlock(parent); + virNodeDeviceObjUnlock(obj); =20 return ret; } @@ -378,19 +378,19 @@ virNodeDeviceGetParentHostByWWNs(virNodeDeviceObjList= Ptr devs, const char *parent_wwnn, const char *parent_wwpn) { - virNodeDeviceObjPtr parent =3D NULL; + virNodeDeviceObjPtr obj =3D NULL; int ret; =20 - if (!(parent =3D virNodeDeviceFindByWWNs(devs, parent_wwnn, parent_wwp= n))) { + if (!(obj =3D virNodeDeviceFindByWWNs(devs, parent_wwnn, parent_wwpn))= ) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find parent device for '%s'"), dev_name); return -1; } =20 - ret =3D virNodeDeviceFindFCParentHost(parent); + ret =3D virNodeDeviceFindFCParentHost(obj); =20 - virNodeDeviceObjUnlock(parent); + virNodeDeviceObjUnlock(obj); =20 return ret; } @@ -401,19 +401,19 @@ virNodeDeviceGetParentHostByFabricWWN(virNodeDeviceOb= jListPtr devs, const char *dev_name, const char *parent_fabric_wwn) { - virNodeDeviceObjPtr parent =3D NULL; + virNodeDeviceObjPtr obj =3D NULL; int ret; =20 - if (!(parent =3D virNodeDeviceFindByFabricWWN(devs, parent_fabric_wwn)= )) { + if (!(obj =3D virNodeDeviceFindByFabricWWN(devs, parent_fabric_wwn))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find parent device for '%s'"), dev_name); return -1; } =20 - ret =3D virNodeDeviceFindFCParentHost(parent); + ret =3D virNodeDeviceFindFCParentHost(obj); =20 - virNodeDeviceObjUnlock(parent); + virNodeDeviceObjUnlock(obj); =20 return ret; } @@ -422,19 +422,19 @@ virNodeDeviceGetParentHostByFabricWWN(virNodeDeviceOb= jListPtr devs, static int virNodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs) { - virNodeDeviceObjPtr parent =3D NULL; + virNodeDeviceObjPtr obj =3D NULL; const char *cap =3D virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS); int ret; =20 - if (!(parent =3D virNodeDeviceFindByCap(devs, cap))) { + if (!(obj =3D virNodeDeviceFindByCap(devs, cap))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not find any vport capable device")); return -1; } =20 - ret =3D virNodeDeviceFindFCParentHost(parent); + ret =3D virNodeDeviceFindFCParentHost(obj); =20 - virNodeDeviceObjUnlock(parent); + virNodeDeviceObjUnlock(obj); =20 return ret; } @@ -482,12 +482,12 @@ virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj) =20 =20 static bool -virNodeDeviceCapMatch(virNodeDeviceObjPtr devobj, +virNodeDeviceCapMatch(virNodeDeviceObjPtr obj, int type) { virNodeDevCapsDefPtr cap =3D NULL; =20 - for (cap =3D devobj->def->caps; cap; cap =3D cap->next) { + for (cap =3D obj->def->caps; cap; cap =3D cap->next) { if (type =3D=3D cap->data.type) return true; =20 @@ -588,9 +588,9 @@ virNodeDeviceObjGetNames(virNodeDeviceObjListPtr devs, =20 =20 #define MATCH(FLAG) ((flags & (VIR_CONNECT_LIST_NODE_DEVICES_CAP_ ## FLAG)= ) && \ - virNodeDeviceCapMatch(devobj, VIR_NODE_DEV_CAP_ ## FL= AG)) + virNodeDeviceCapMatch(obj, VIR_NODE_DEV_CAP_ ## FLAG)) static bool -virNodeDeviceMatch(virNodeDeviceObjPtr devobj, +virNodeDeviceMatch(virNodeDeviceObjPtr obj, unsigned int flags) { /* filter by cap type */ @@ -621,7 +621,7 @@ virNodeDeviceMatch(virNodeDeviceObjPtr devobj, =20 int virNodeDeviceObjListExport(virConnectPtr conn, - virNodeDeviceObjListPtr devobjs, + virNodeDeviceObjListPtr devs, virNodeDevicePtr **devices, virNodeDeviceObjListFilter filter, unsigned int flags) @@ -632,26 +632,26 @@ virNodeDeviceObjListExport(virConnectPtr conn, int ret =3D -1; size_t i; =20 - if (devices && VIR_ALLOC_N(tmp_devices, devobjs->count + 1) < 0) + if (devices && VIR_ALLOC_N(tmp_devices, devs->count + 1) < 0) goto cleanup; =20 - for (i =3D 0; i < devobjs->count; i++) { - virNodeDeviceObjPtr devobj =3D devobjs->objs[i]; - virNodeDeviceObjLock(devobj); - if ((!filter || filter(conn, devobj->def)) && - virNodeDeviceMatch(devobj, flags)) { + for (i =3D 0; i < devs->count; i++) { + virNodeDeviceObjPtr obj =3D devs->objs[i]; + virNodeDeviceObjLock(obj); + if ((!filter || filter(conn, obj->def)) && + virNodeDeviceMatch(obj, flags)) { if (devices) { - if (!(device =3D virGetNodeDevice(conn, devobj->def->name)= ) || - VIR_STRDUP(device->parent, devobj->def->parent) < 0) { + if (!(device =3D virGetNodeDevice(conn, obj->def->name)) || + VIR_STRDUP(device->parent, obj->def->parent) < 0) { virObjectUnref(device); - virNodeDeviceObjUnlock(devobj); + virNodeDeviceObjUnlock(obj); goto cleanup; } tmp_devices[ndevices] =3D device; } ndevices++; } - virNodeDeviceObjUnlock(devobj); + virNodeDeviceObjUnlock(obj); } =20 if (tmp_devices) { --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:38:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496495533600577.1644108160863; Sat, 3 Jun 2017 06:12:13 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 097F0232040; Sat, 3 Jun 2017 13:12:11 +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 CE7F382489; Sat, 3 Jun 2017 13:12: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 2E55B4BB7F; Sat, 3 Jun 2017 13:12:09 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DC7U3005751 for ; Sat, 3 Jun 2017 09:12:07 -0400 Received: by smtp.corp.redhat.com (Postfix) id B31B7179C2; Sat, 3 Jun 2017 13:12:07 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6027E7B8FE for ; Sat, 3 Jun 2017 13:12:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 097F0232040 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 097F0232040 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:11:54 -0400 Message-Id: <20170603131202.17611-5-jferlan@redhat.com> In-Reply-To: <20170603131202.17611-1-jferlan@redhat.com> References: <20170603131202.17611-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 04/12] nodedev: Use consistent names for driver variables 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 03 Jun 2017 13:12:11 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" A virNodeDeviceObjPtr is an @obj A virNodeDeviceObjListPtr is a @devs A virNodeDevicePtr is a @device Signed-off-by: John Ferlan --- src/node_device/node_device_driver.c | 74 ++++++++++++++++++--------------= ---- src/node_device/node_device_hal.c | 38 +++++++++--------- src/node_device/node_device_udev.c | 48 +++++++++++------------ 3 files changed, 78 insertions(+), 82 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 760d73a..8153e21 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -260,7 +260,7 @@ nodeDeviceLookupByName(virConnectPtr conn, { virNodeDeviceObjPtr obj; virNodeDeviceDefPtr def; - virNodeDevicePtr ret =3D NULL; + virNodeDevicePtr device =3D NULL; =20 if (!(obj =3D nodeDeviceObjFindByName(name))) return NULL; @@ -269,16 +269,16 @@ nodeDeviceLookupByName(virConnectPtr conn, if (virNodeDeviceLookupByNameEnsureACL(conn, def) < 0) goto cleanup; =20 - if ((ret =3D virGetNodeDevice(conn, name))) { - if (VIR_STRDUP(ret->parent, def->parent) < 0) { - virObjectUnref(ret); - ret =3D NULL; + if ((device =3D virGetNodeDevice(conn, name))) { + if (VIR_STRDUP(device->parent, def->parent) < 0) { + virObjectUnref(device); + device =3D NULL; } } =20 cleanup: virNodeDeviceObjUnlock(obj); - return ret; + return device; } =20 =20 @@ -293,7 +293,7 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, virNodeDevCapsDefPtr cap =3D NULL; virNodeDeviceObjPtr obj =3D NULL; virNodeDeviceDefPtr def; - virNodeDevicePtr dev =3D NULL; + virNodeDevicePtr device =3D NULL; =20 virCheckFlags(0, NULL); =20 @@ -316,10 +316,10 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn= , def) < 0) goto error; =20 - if ((dev =3D virGetNodeDevice(conn, def->name))) { - if (VIR_STRDUP(dev->parent, def->parent) < 0) { - virObjectUnref(dev); - dev =3D NULL; + if ((device =3D virGetNodeDevice(conn, def->name))= ) { + if (VIR_STRDUP(device->parent, def->parent) < = 0) { + virObjectUnref(device); + device =3D NULL; } } virNodeDeviceObjUnlock(obj); @@ -335,7 +335,7 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, =20 out: nodeDeviceUnlock(); - return dev; + return device; =20 error: virNodeDeviceObjUnlock(obj); @@ -344,7 +344,7 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, =20 =20 char * -nodeDeviceGetXMLDesc(virNodeDevicePtr dev, +nodeDeviceGetXMLDesc(virNodeDevicePtr device, unsigned int flags) { virNodeDeviceObjPtr obj; @@ -353,11 +353,11 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr dev, =20 virCheckFlags(0, NULL); =20 - if (!(obj =3D nodeDeviceObjFindByName(dev->name))) + if (!(obj =3D nodeDeviceObjFindByName(device->name))) return NULL; def =3D virNodeDeviceObjGetDef(obj); =20 - if (virNodeDeviceGetXMLDescEnsureACL(dev->conn, def) < 0) + if (virNodeDeviceGetXMLDescEnsureACL(device->conn, def) < 0) goto cleanup; =20 if (nodeDeviceUpdateDriverName(def) < 0) @@ -375,17 +375,17 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr dev, =20 =20 char * -nodeDeviceGetParent(virNodeDevicePtr dev) +nodeDeviceGetParent(virNodeDevicePtr device) { virNodeDeviceObjPtr obj; virNodeDeviceDefPtr def; char *ret =3D NULL; =20 - if (!(obj =3D nodeDeviceObjFindByName(dev->name))) + if (!(obj =3D nodeDeviceObjFindByName(device->name))) return NULL; def =3D virNodeDeviceObjGetDef(obj); =20 - if (virNodeDeviceGetParentEnsureACL(dev->conn, def) < 0) + if (virNodeDeviceGetParentEnsureACL(device->conn, def) < 0) goto cleanup; =20 if (def->parent) { @@ -403,7 +403,7 @@ nodeDeviceGetParent(virNodeDevicePtr dev) =20 =20 int -nodeDeviceNumOfCaps(virNodeDevicePtr dev) +nodeDeviceNumOfCaps(virNodeDevicePtr device) { virNodeDeviceObjPtr obj; virNodeDeviceDefPtr def; @@ -411,11 +411,11 @@ nodeDeviceNumOfCaps(virNodeDevicePtr dev) int ncaps =3D 0; int ret =3D -1; =20 - if (!(obj =3D nodeDeviceObjFindByName(dev->name))) + if (!(obj =3D nodeDeviceObjFindByName(device->name))) return -1; def =3D virNodeDeviceObjGetDef(obj); =20 - if (virNodeDeviceNumOfCapsEnsureACL(dev->conn, def) < 0) + if (virNodeDeviceNumOfCapsEnsureACL(device->conn, def) < 0) goto cleanup; =20 for (caps =3D def->caps; caps; caps =3D caps->next) { @@ -442,7 +442,7 @@ nodeDeviceNumOfCaps(virNodeDevicePtr dev) =20 =20 int -nodeDeviceListCaps(virNodeDevicePtr dev, +nodeDeviceListCaps(virNodeDevicePtr device, char **const names, int maxnames) { @@ -452,11 +452,11 @@ nodeDeviceListCaps(virNodeDevicePtr dev, int ncaps =3D 0; int ret =3D -1; =20 - if (!(obj =3D nodeDeviceObjFindByName(dev->name))) + if (!(obj =3D nodeDeviceObjFindByName(device->name))) return -1; def =3D virNodeDeviceObjGetDef(obj); =20 - if (virNodeDeviceListCapsEnsureACL(dev->conn, def) < 0) + if (virNodeDeviceListCapsEnsureACL(device->conn, def) < 0) goto cleanup; =20 for (caps =3D def->caps; caps && ncaps < maxnames; caps =3D caps->next= ) { @@ -530,7 +530,7 @@ nodeDeviceFindNewDevice(virConnectPtr conn, const char *wwnn, const char *wwpn) { - virNodeDevicePtr dev =3D NULL; + virNodeDevicePtr device =3D NULL; time_t start =3D 0, now =3D 0; =20 /* The thread that creates the device takes the driver lock, so we @@ -546,9 +546,9 @@ nodeDeviceFindNewDevice(virConnectPtr conn, =20 virWaitForDevices(); =20 - dev =3D nodeDeviceLookupSCSIHostByWWN(conn, wwnn, wwpn, 0); + device =3D nodeDeviceLookupSCSIHostByWWN(conn, wwnn, wwpn, 0); =20 - if (dev !=3D NULL) + if (device !=3D NULL) break; =20 sleep(5); @@ -558,7 +558,7 @@ nodeDeviceFindNewDevice(virConnectPtr conn, =20 nodeDeviceLock(); =20 - return dev; + return device; } =20 =20 @@ -570,7 +570,7 @@ nodeDeviceCreateXML(virConnectPtr conn, virNodeDeviceDefPtr def =3D NULL; char *wwnn =3D NULL, *wwpn =3D NULL; int parent_host =3D -1; - virNodeDevicePtr dev =3D NULL; + virNodeDevicePtr device =3D NULL; const char *virt_type =3D NULL; =20 virCheckFlags(0, NULL); @@ -594,11 +594,11 @@ nodeDeviceCreateXML(virConnectPtr conn, if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_CREATE) < 0) goto cleanup; =20 - dev =3D nodeDeviceFindNewDevice(conn, wwnn, wwpn); + device =3D nodeDeviceFindNewDevice(conn, wwnn, wwpn); /* We don't check the return value, because one way or another, * we're returning what we get... */ =20 - if (dev =3D=3D NULL) + if (device =3D=3D NULL) virReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device for '%s' with matching " "wwnn '%s' and wwpn '%s'"), @@ -608,12 +608,12 @@ nodeDeviceCreateXML(virConnectPtr conn, virNodeDeviceDefFree(def); VIR_FREE(wwnn); VIR_FREE(wwpn); - return dev; + return device; } =20 =20 int -nodeDeviceDestroy(virNodeDevicePtr dev) +nodeDeviceDestroy(virNodeDevicePtr device) { int ret =3D -1; virNodeDeviceObjPtr obj =3D NULL; @@ -621,13 +621,13 @@ nodeDeviceDestroy(virNodeDevicePtr dev) char *wwnn =3D NULL, *wwpn =3D NULL; int parent_host =3D -1; =20 - if (!(obj =3D nodeDeviceObjFindByName(dev->name))) + if (!(obj =3D nodeDeviceObjFindByName(device->name))) return -1; def =3D virNodeDeviceObjGetDef(obj); =20 nodeDeviceLock(); =20 - if (virNodeDeviceDestroyEnsureACL(dev->conn, def) < 0) + if (virNodeDeviceDestroyEnsureACL(device->conn, def) < 0) goto cleanup; =20 if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) < 0) @@ -659,7 +659,7 @@ nodeDeviceDestroy(virNodeDevicePtr dev) =20 int nodeConnectNodeDeviceEventRegisterAny(virConnectPtr conn, - virNodeDevicePtr dev, + virNodeDevicePtr device, int eventID, virConnectNodeDeviceEventGenericCall= back callback, void *opaque, @@ -671,7 +671,7 @@ nodeConnectNodeDeviceEventRegisterAny(virConnectPtr con= n, goto cleanup; =20 if (virNodeDeviceEventStateRegisterID(conn, driver->nodeDeviceEventSta= te, - dev, eventID, callback, + device, eventID, callback, opaque, freecb, &callbackID) < 0) callbackID =3D -1; cleanup: diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_devic= e_hal.c index c354cd3..0d9ec18 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -449,7 +449,7 @@ dev_create(const char *udi) { LibHalContext *ctx; char *parent_key =3D NULL; - virNodeDeviceObjPtr dev =3D NULL; + virNodeDeviceObjPtr obj =3D NULL; virNodeDeviceDefPtr def =3D NULL; virNodeDeviceDefPtr objdef; const char *name =3D hal_name(udi); @@ -482,15 +482,15 @@ dev_create(const char *udi) /* Some devices don't have a path in sysfs, so ignore failure */ (void)get_str_prop(ctx, udi, "linux.sysfs_path", &devicePath); =20 - if (!(dev =3D virNodeDeviceObjAssignDef(&driver->devs, def))) { + if (!(obj =3D virNodeDeviceObjAssignDef(&driver->devs, def))) { VIR_FREE(devicePath); goto failure; } - objdef =3D virNodeDeviceObjGetDef(dev); + objdef =3D virNodeDeviceObjGetDef(obj); =20 objdef->sysfs_path =3D devicePath; =20 - virNodeDeviceObjUnlock(dev); + virNodeDeviceObjUnlock(obj); =20 nodeDeviceUnlock(); return; @@ -506,21 +506,21 @@ static void dev_refresh(const char *udi) { const char *name =3D hal_name(udi); - virNodeDeviceObjPtr dev; + virNodeDeviceObjPtr obj; =20 nodeDeviceLock(); - dev =3D virNodeDeviceObjFindByName(&driver->devs, name); - if (dev) { + obj =3D virNodeDeviceObjFindByName(&driver->devs, name); + if (obj) { /* Simply "rediscover" device -- incrementally handling changes * to sub-capabilities (like net.80203) is nasty ... so avoid it. */ - virNodeDeviceObjRemove(&driver->devs, dev); + virNodeDeviceObjRemove(&driver->devs, obj); } else { VIR_DEBUG("no device named %s", name); } nodeDeviceUnlock(); =20 - if (dev) + if (obj) dev_create(udi); } =20 @@ -538,14 +538,14 @@ device_removed(LibHalContext *ctx ATTRIBUTE_UNUSED, const char *udi) { const char *name =3D hal_name(udi); - virNodeDeviceObjPtr dev; + virNodeDeviceObjPtr obj; =20 nodeDeviceLock(); - dev =3D virNodeDeviceObjFindByName(&driver->devs, name); + obj =3D virNodeDeviceObjFindByName(&driver->devs, name); VIR_DEBUG("%s", name); - if (dev) { - virNodeDeviceObjRemove(&driver->devs, dev); - virNodeDeviceObjFree(dev); + if (obj) { + virNodeDeviceObjRemove(&driver->devs, obj); + virNodeDeviceObjFree(obj); } else { VIR_DEBUG("no device named %s", name); } @@ -558,17 +558,17 @@ device_cap_added(LibHalContext *ctx, const char *udi, const char *cap) { const char *name =3D hal_name(udi); - virNodeDeviceObjPtr dev; + virNodeDeviceObjPtr obj; virNodeDeviceDefPtr def; =20 nodeDeviceLock(); - dev =3D virNodeDeviceObjFindByName(&driver->devs, name); + obj =3D virNodeDeviceObjFindByName(&driver->devs, name); nodeDeviceUnlock(); VIR_DEBUG("%s %s", cap, name); - if (dev) { - def =3D virNodeDeviceObjGetDef(dev); + if (obj) { + def =3D virNodeDeviceObjGetDef(obj); (void)gather_capability(ctx, udi, cap, &def->caps); - virNodeDeviceObjUnlock(dev); + virNodeDeviceObjUnlock(obj); } else { VIR_DEBUG("no device named %s", name); } diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 819e4e7..708bc9a 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1312,20 +1312,18 @@ udevGetDeviceDetails(struct udev_device *device, static int udevRemoveOneDevice(struct udev_device *device) { - virNodeDeviceObjPtr dev =3D NULL; + virNodeDeviceObjPtr obj =3D NULL; virNodeDeviceDefPtr def; virObjectEventPtr event =3D NULL; const char *name =3D NULL; =20 name =3D udev_device_get_syspath(device); - dev =3D virNodeDeviceObjFindBySysfsPath(&driver->devs, name); - - if (!dev) { + if (!(obj =3D virNodeDeviceObjFindBySysfsPath(&driver->devs, name))) { VIR_DEBUG("Failed to find device to remove that has udev name '%s'= ", name); return -1; } - def =3D virNodeDeviceObjGetDef(dev); + def =3D virNodeDeviceObjGetDef(obj); =20 event =3D virNodeDeviceEventLifecycleNew(def->name, VIR_NODE_DEVICE_EVENT_DELETED, @@ -1333,8 +1331,8 @@ udevRemoveOneDevice(struct udev_device *device) =20 VIR_DEBUG("Removing device '%s' with sysfs path '%s'", def->name, name); - virNodeDeviceObjRemove(&driver->devs, dev); - virNodeDeviceObjFree(dev); + virNodeDeviceObjRemove(&driver->devs, obj); + virNodeDeviceObjFree(obj); =20 if (event) virObjectEventStateQueue(driver->nodeDeviceEventState, event); @@ -1348,7 +1346,7 @@ udevSetParent(struct udev_device *device, { struct udev_device *parent_device =3D NULL; const char *parent_sysfs_path =3D NULL; - virNodeDeviceObjPtr dev =3D NULL; + virNodeDeviceObjPtr obj =3D NULL; virNodeDeviceDefPtr objdef; int ret =3D -1; =20 @@ -1367,15 +1365,14 @@ udevSetParent(struct udev_device *device, goto cleanup; } =20 - dev =3D virNodeDeviceObjFindBySysfsPath(&driver->devs, - parent_sysfs_path); - if (dev !=3D NULL) { - objdef =3D virNodeDeviceObjGetDef(dev); + if ((obj =3D virNodeDeviceObjFindBySysfsPath(&driver->devs, + parent_sysfs_path))) { + objdef =3D virNodeDeviceObjGetDef(obj); if (VIR_STRDUP(def->parent, objdef->name) < 0) { - virNodeDeviceObjUnlock(dev); + virNodeDeviceObjUnlock(obj); goto cleanup; } - virNodeDeviceObjUnlock(dev); + virNodeDeviceObjUnlock(obj); =20 if (VIR_STRDUP(def->parent_sysfs_path, parent_sysfs_path) < 0) goto cleanup; @@ -1397,7 +1394,7 @@ static int udevAddOneDevice(struct udev_device *device) { virNodeDeviceDefPtr def =3D NULL; - virNodeDeviceObjPtr dev =3D NULL; + virNodeDeviceObjPtr obj =3D NULL; virNodeDeviceDefPtr objdef; virObjectEventPtr event =3D NULL; bool new_device =3D true; @@ -1427,18 +1424,17 @@ udevAddOneDevice(struct udev_device *device) if (udevSetParent(device, def) !=3D 0) goto cleanup; =20 - dev =3D virNodeDeviceObjFindByName(&driver->devs, def->name); - if (dev) { - virNodeDeviceObjUnlock(dev); + obj =3D virNodeDeviceObjFindByName(&driver->devs, def->name); + if (obj) { + virNodeDeviceObjUnlock(obj); new_device =3D false; } =20 /* If this is a device change, the old definition will be freed * and the current definition will take its place. */ - dev =3D virNodeDeviceObjAssignDef(&driver->devs, def); - if (dev =3D=3D NULL) + if (!(obj =3D virNodeDeviceObjAssignDef(&driver->devs, def))) goto cleanup; - objdef =3D virNodeDeviceObjGetDef(dev); + objdef =3D virNodeDeviceObjGetDef(obj); =20 if (new_device) event =3D virNodeDeviceEventLifecycleNew(objdef->name, @@ -1447,7 +1443,7 @@ udevAddOneDevice(struct udev_device *device) else event =3D virNodeDeviceEventUpdateNew(objdef->name); =20 - virNodeDeviceObjUnlock(dev); + virNodeDeviceObjUnlock(obj); =20 ret =3D 0; =20 @@ -1710,7 +1706,7 @@ static int udevSetupSystemDev(void) { virNodeDeviceDefPtr def =3D NULL; - virNodeDeviceObjPtr dev =3D NULL; + virNodeDeviceObjPtr obj =3D NULL; int ret =3D -1; =20 if (VIR_ALLOC(def) < 0) @@ -1726,11 +1722,11 @@ udevSetupSystemDev(void) udevGetDMIData(&def->caps->data.system); #endif =20 - dev =3D virNodeDeviceObjAssignDef(&driver->devs, def); - if (dev =3D=3D NULL) + obj =3D virNodeDeviceObjAssignDef(&driver->devs, def); + if (obj =3D=3D NULL) goto cleanup; =20 - virNodeDeviceObjUnlock(dev); + virNodeDeviceObjUnlock(obj); =20 ret =3D 0; =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:38:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496495553185466.5493728915858; Sat, 3 Jun 2017 06:12:33 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 27DE780487; Sat, 3 Jun 2017 13:12:30 +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 D76887D679; Sat, 3 Jun 2017 13:12:29 +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 894EA4A48D; Sat, 3 Jun 2017 13:12:29 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DC8vG005762 for ; Sat, 3 Jun 2017 09:12:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 27BAF179C2; Sat, 3 Jun 2017 13:12:08 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id DC5AA7B8FE for ; Sat, 3 Jun 2017 13:12:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 27DE780487 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 27DE780487 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:11:55 -0400 Message-Id: <20170603131202.17611-6-jferlan@redhat.com> In-Reply-To: <20170603131202.17611-1-jferlan@redhat.com> References: <20170603131202.17611-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 05/12] nodedev: Introduce virNodeDeviceObjNew 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 03 Jun 2017 13:12:32 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Create an allocator for the virNodeDeviceObjPtr - include setting up the mutex, saving the virNodeDeviceDefPtr, and locking the return object. Signed-off-by: John Ferlan --- src/conf/virnodedeviceobj.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 3aff5ca..3e88daa 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -33,6 +33,27 @@ VIR_LOG_INIT("conf.virnodedeviceobj"); =20 =20 +static virNodeDeviceObjPtr +virNodeDeviceObjNew(virNodeDeviceDefPtr def) +{ + virNodeDeviceObjPtr obj; + + if (VIR_ALLOC(obj) < 0) + return NULL; + + if (virMutexInit(&obj->lock) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + "%s", _("cannot initialize mutex")); + VIR_FREE(obj); + return NULL; + } + virNodeDeviceObjLock(obj); + obj->def =3D def; + + return obj; +} + + virNodeDeviceDefPtr virNodeDeviceObjGetDef(virNodeDeviceObjPtr obj) { @@ -276,26 +297,17 @@ virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr dev= s, return obj; } =20 - if (VIR_ALLOC(obj) < 0) + if (!(obj =3D virNodeDeviceObjNew(def))) return NULL; =20 - if (virMutexInit(&obj->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot initialize mutex")); - VIR_FREE(obj); - return NULL; - } - virNodeDeviceObjLock(obj); - if (VIR_APPEND_ELEMENT_COPY(devs->objs, devs->count, obj) < 0) { + obj->def =3D NULL; virNodeDeviceObjUnlock(obj); virNodeDeviceObjFree(obj); return NULL; } - obj->def =3D def; =20 return obj; - } =20 =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:38:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496495541304810.3273511400889; Sat, 3 Jun 2017 06:12:21 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 61DE365980; Sat, 3 Jun 2017 13:12:19 +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 30EB587E33; Sat, 3 Jun 2017 13:12:19 +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 DA61F180BAF7; Sat, 3 Jun 2017 13:12:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DC8ZY005772 for ; Sat, 3 Jun 2017 09:12:08 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8E47E7B8D9; Sat, 3 Jun 2017 13:12:08 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4F04F179C2 for ; Sat, 3 Jun 2017 13:12:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 61DE365980 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 61DE365980 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:11:56 -0400 Message-Id: <20170603131202.17611-7-jferlan@redhat.com> In-Reply-To: <20170603131202.17611-1-jferlan@redhat.com> References: <20170603131202.17611-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 06/12] nodedev: Introduce virNodeDeviceObjListNew 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 03 Jun 2017 13:12:20 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In preparation to make things private, make the ->devs be pointers to a virNodeDeviceObjList and then manage everything inside virnodedeviceobj Signed-off-by: John Ferlan --- src/conf/virnodedeviceobj.c | 13 ++++++++++++- src/conf/virnodedeviceobj.h | 5 ++++- src/libvirt_private.syms | 1 + src/node_device/node_device_driver.c | 14 +++++++------- src/node_device/node_device_hal.c | 19 +++++++++++-------- src/node_device/node_device_udev.c | 19 +++++++++++-------- src/test/test_driver.c | 29 +++++++++++++++-------------- 7 files changed, 61 insertions(+), 39 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 3e88daa..4a25d95 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -274,6 +274,17 @@ virNodeDeviceObjFree(virNodeDeviceObjPtr obj) } =20 =20 +virNodeDeviceObjListPtr +virNodeDeviceObjListNew(void) +{ + virNodeDeviceObjListPtr devs; + + if (VIR_ALLOC(devs) < 0) + return NULL; + return devs; +} + + void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) { @@ -281,7 +292,7 @@ virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) for (i =3D 0; i < devs->count; i++) virNodeDeviceObjFree(devs->objs[i]); VIR_FREE(devs->objs); - devs->count =3D 0; + VIR_FREE(devs); } =20 =20 diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 9bc02ee..77250a0 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -32,7 +32,7 @@ typedef virNodeDeviceDriverState *virNodeDeviceDriverStat= ePtr; struct _virNodeDeviceDriverState { virMutex lock; =20 - virNodeDeviceObjList devs; /* currently-known devices */ + virNodeDeviceObjListPtr devs; /* currently-known devices */ void *privateData; /* driver-specific private data */ =20 /* Immutable pointer, self-locking APIs */ @@ -68,6 +68,9 @@ virNodeDeviceObjGetParentHost(virNodeDeviceObjListPtr dev= s, void virNodeDeviceObjFree(virNodeDeviceObjPtr dev); =20 +virNodeDeviceObjListPtr +virNodeDeviceObjListNew(void); + void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs); =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 4a10508..77f56c2 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -965,6 +965,7 @@ virNodeDeviceObjGetNames; virNodeDeviceObjGetParentHost; virNodeDeviceObjListExport; virNodeDeviceObjListFree; +virNodeDeviceObjListNew; virNodeDeviceObjLock; virNodeDeviceObjNumOfDevices; virNodeDeviceObjRemove; diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 8153e21..fc9d0b0 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -182,7 +182,7 @@ nodeNumOfDevices(virConnectPtr conn, virCheckFlags(0, -1); =20 nodeDeviceLock(); - ndevs =3D virNodeDeviceObjNumOfDevices(&driver->devs, conn, cap, + ndevs =3D virNodeDeviceObjNumOfDevices(driver->devs, conn, cap, virNodeNumOfDevicesCheckACL); nodeDeviceUnlock(); =20 @@ -205,7 +205,7 @@ nodeListDevices(virConnectPtr conn, virCheckFlags(0, -1); =20 nodeDeviceLock(); - nnames =3D virNodeDeviceObjGetNames(&driver->devs, conn, + nnames =3D virNodeDeviceObjGetNames(driver->devs, conn, virNodeListDevicesCheckACL, cap, names, maxnames); nodeDeviceUnlock(); @@ -227,7 +227,7 @@ nodeConnectListAllNodeDevices(virConnectPtr conn, return -1; =20 nodeDeviceLock(); - ret =3D virNodeDeviceObjListExport(conn, &driver->devs, devices, + ret =3D virNodeDeviceObjListExport(conn, driver->devs, devices, virConnectListAllNodeDevicesCheckACL, flags); nodeDeviceUnlock(); @@ -241,7 +241,7 @@ nodeDeviceObjFindByName(const char *name) virNodeDeviceObjPtr obj; =20 nodeDeviceLock(); - obj =3D virNodeDeviceObjFindByName(&driver->devs, name); + obj =3D virNodeDeviceObjFindByName(driver->devs, name); nodeDeviceUnlock(); =20 if (!obj) { @@ -289,7 +289,7 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, unsigned int flags) { size_t i; - virNodeDeviceObjListPtr devs =3D &driver->devs; + virNodeDeviceObjListPtr devs =3D driver->devs; virNodeDevCapsDefPtr cap =3D NULL; virNodeDeviceObjPtr obj =3D NULL; virNodeDeviceDefPtr def; @@ -587,7 +587,7 @@ nodeDeviceCreateXML(virConnectPtr conn, if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) =3D=3D -1) goto cleanup; =20 - if ((parent_host =3D virNodeDeviceObjGetParentHost(&driver->devs, def, + if ((parent_host =3D virNodeDeviceObjGetParentHost(driver->devs, def, CREATE_DEVICE)) < 0) goto cleanup; =20 @@ -639,7 +639,7 @@ nodeDeviceDestroy(virNodeDevicePtr device) * or parent_fabric_wwn) and drop the object lock. */ virNodeDeviceObjUnlock(obj); obj =3D NULL; - if ((parent_host =3D virNodeDeviceObjGetParentHost(&driver->devs, def, + if ((parent_host =3D virNodeDeviceObjGetParentHost(driver->devs, def, EXISTING_DEVICE)) < 0) goto cleanup; =20 diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_devic= e_hal.c index 0d9ec18..f02fbe4 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -482,7 +482,7 @@ dev_create(const char *udi) /* Some devices don't have a path in sysfs, so ignore failure */ (void)get_str_prop(ctx, udi, "linux.sysfs_path", &devicePath); =20 - if (!(obj =3D virNodeDeviceObjAssignDef(&driver->devs, def))) { + if (!(obj =3D virNodeDeviceObjAssignDef(driver->devs, def))) { VIR_FREE(devicePath); goto failure; } @@ -509,12 +509,12 @@ dev_refresh(const char *udi) virNodeDeviceObjPtr obj; =20 nodeDeviceLock(); - obj =3D virNodeDeviceObjFindByName(&driver->devs, name); + obj =3D virNodeDeviceObjFindByName(driver->devs, name); if (obj) { /* Simply "rediscover" device -- incrementally handling changes * to sub-capabilities (like net.80203) is nasty ... so avoid it. */ - virNodeDeviceObjRemove(&driver->devs, obj); + virNodeDeviceObjRemove(driver->devs, obj); } else { VIR_DEBUG("no device named %s", name); } @@ -541,10 +541,10 @@ device_removed(LibHalContext *ctx ATTRIBUTE_UNUSED, virNodeDeviceObjPtr obj; =20 nodeDeviceLock(); - obj =3D virNodeDeviceObjFindByName(&driver->devs, name); + obj =3D virNodeDeviceObjFindByName(driver->devs, name); VIR_DEBUG("%s", name); if (obj) { - virNodeDeviceObjRemove(&driver->devs, obj); + virNodeDeviceObjRemove(driver->devs, obj); virNodeDeviceObjFree(obj); } else { VIR_DEBUG("no device named %s", name); @@ -562,7 +562,7 @@ device_cap_added(LibHalContext *ctx, virNodeDeviceDefPtr def; =20 nodeDeviceLock(); - obj =3D virNodeDeviceObjFindByName(&driver->devs, name); + obj =3D virNodeDeviceObjFindByName(driver->devs, name); nodeDeviceUnlock(); VIR_DEBUG("%s %s", cap, name); if (obj) { @@ -627,6 +627,9 @@ nodeStateInitialize(bool privileged ATTRIBUTE_UNUSED, } nodeDeviceLock(); =20 + if (!(driver->devs =3D virNodeDeviceObjListNew())) + goto failure; + dbus_error_init(&err); if (!(sysbus =3D virDBusGetSystemBus())) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -701,7 +704,7 @@ nodeStateInitialize(bool privileged ATTRIBUTE_UNUSED, _("%s: %s"), err.name, err.message); dbus_error_free(&err); } - virNodeDeviceObjListFree(&driver->devs); + virNodeDeviceObjListFree(driver->devs); if (hal_ctx) (void)libhal_ctx_free(hal_ctx); nodeDeviceUnlock(); @@ -717,7 +720,7 @@ nodeStateCleanup(void) if (driver) { nodeDeviceLock(); LibHalContext *hal_ctx =3D DRV_STATE_HAL_CTX(driver); - virNodeDeviceObjListFree(&driver->devs); + virNodeDeviceObjListFree(driver->devs); (void)libhal_ctx_shutdown(hal_ctx, NULL); (void)libhal_ctx_free(hal_ctx); nodeDeviceUnlock(); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 708bc9a..40f12e3 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1318,7 +1318,7 @@ udevRemoveOneDevice(struct udev_device *device) const char *name =3D NULL; =20 name =3D udev_device_get_syspath(device); - if (!(obj =3D virNodeDeviceObjFindBySysfsPath(&driver->devs, name))) { + if (!(obj =3D virNodeDeviceObjFindBySysfsPath(driver->devs, name))) { VIR_DEBUG("Failed to find device to remove that has udev name '%s'= ", name); return -1; @@ -1331,7 +1331,7 @@ udevRemoveOneDevice(struct udev_device *device) =20 VIR_DEBUG("Removing device '%s' with sysfs path '%s'", def->name, name); - virNodeDeviceObjRemove(&driver->devs, obj); + virNodeDeviceObjRemove(driver->devs, obj); virNodeDeviceObjFree(obj); =20 if (event) @@ -1365,7 +1365,7 @@ udevSetParent(struct udev_device *device, goto cleanup; } =20 - if ((obj =3D virNodeDeviceObjFindBySysfsPath(&driver->devs, + if ((obj =3D virNodeDeviceObjFindBySysfsPath(driver->devs, parent_sysfs_path))) { objdef =3D virNodeDeviceObjGetDef(obj); if (VIR_STRDUP(def->parent, objdef->name) < 0) { @@ -1424,7 +1424,7 @@ udevAddOneDevice(struct udev_device *device) if (udevSetParent(device, def) !=3D 0) goto cleanup; =20 - obj =3D virNodeDeviceObjFindByName(&driver->devs, def->name); + obj =3D virNodeDeviceObjFindByName(driver->devs, def->name); if (obj) { virNodeDeviceObjUnlock(obj); new_device =3D false; @@ -1432,7 +1432,7 @@ udevAddOneDevice(struct udev_device *device) =20 /* If this is a device change, the old definition will be freed * and the current definition will take its place. */ - if (!(obj =3D virNodeDeviceObjAssignDef(&driver->devs, def))) + if (!(obj =3D virNodeDeviceObjAssignDef(driver->devs, def))) goto cleanup; objdef =3D virNodeDeviceObjGetDef(obj); =20 @@ -1586,7 +1586,7 @@ nodeStateCleanup(void) if (udev !=3D NULL) udev_unref(udev); =20 - virNodeDeviceObjListFree(&driver->devs); + virNodeDeviceObjListFree(driver->devs); nodeDeviceUnlock(); virMutexDestroy(&driver->lock); VIR_FREE(driver); @@ -1722,8 +1722,7 @@ udevSetupSystemDev(void) udevGetDMIData(&def->caps->data.system); #endif =20 - obj =3D virNodeDeviceObjAssignDef(&driver->devs, def); - if (obj =3D=3D NULL) + if (!(obj =3D virNodeDeviceObjAssignDef(driver->devs, def))) goto cleanup; =20 virNodeDeviceObjUnlock(obj); @@ -1792,6 +1791,10 @@ nodeStateInitialize(bool privileged, =20 driver->privateData =3D priv; nodeDeviceLock(); + + if (!(driver->devs =3D virNodeDeviceObjListNew())) + goto cleanup; + driver->nodeDeviceEventState =3D virObjectEventStateNew(); =20 if (udevPCITranslateInit(privileged) < 0) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index e91dfa3..6a74368 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -101,7 +101,7 @@ struct _testDriver { bool transaction_running; virInterfaceObjListPtr backupIfaces; virStoragePoolObjList pools; - virNodeDeviceObjList devs; + virNodeDeviceObjListPtr devs; int numCells; testCell cells[MAX_CELLS]; size_t numAuths; @@ -152,7 +152,7 @@ testDriverFree(testDriverPtr driver) virObjectUnref(driver->caps); virObjectUnref(driver->xmlopt); virObjectUnref(driver->domains); - virNodeDeviceObjListFree(&driver->devs); + virNodeDeviceObjListFree(driver->devs); virObjectUnref(driver->networks); virInterfaceObjListFree(driver->ifaces); virStoragePoolObjListFree(&driver->pools); @@ -418,7 +418,8 @@ testDriverNew(void) !(ret->eventState =3D virObjectEventStateNew()) || !(ret->ifaces =3D virInterfaceObjListNew()) || !(ret->domains =3D virDomainObjListNew()) || - !(ret->networks =3D virNetworkObjListNew())) + !(ret->networks =3D virNetworkObjListNew()) || + !(ret->devs =3D virNodeDeviceObjListNew())) goto error; =20 virAtomicIntSet(&ret->nextDomID, 1); @@ -1169,7 +1170,7 @@ testParseNodedevs(testDriverPtr privconn, if (!def) goto error; =20 - if (!(obj =3D virNodeDeviceObjAssignDef(&privconn->devs, def))) { + if (!(obj =3D virNodeDeviceObjAssignDef(privconn->devs, def))) { virNodeDeviceDefFree(def); goto error; } @@ -4519,7 +4520,7 @@ testDestroyVport(testDriverPtr privconn, * * Reaching across the boundaries of space and time into the * Node Device in order to remove */ - if (!(obj =3D virNodeDeviceObjFindByName(&privconn->devs, "scsi_host12= "))) { + if (!(obj =3D virNodeDeviceObjFindByName(privconn->devs, "scsi_host12"= ))) { virReportError(VIR_ERR_NO_NODE_DEVICE, "%s", _("no node device with matching name 'scsi_host12'"= )); return -1; @@ -4529,7 +4530,7 @@ testDestroyVport(testDriverPtr privconn, VIR_NODE_DEVICE_EVENT_DELETED, 0); =20 - virNodeDeviceObjRemove(&privconn->devs, obj); + virNodeDeviceObjRemove(privconn->devs, obj); virNodeDeviceObjFree(obj); obj =3D NULL; =20 @@ -5262,7 +5263,7 @@ testNodeDeviceObjFindByName(testDriverPtr driver, virNodeDeviceObjPtr obj; =20 testDriverLock(driver); - obj =3D virNodeDeviceObjFindByName(&driver->devs, name); + obj =3D virNodeDeviceObjFindByName(driver->devs, name); testDriverUnlock(driver); =20 if (!obj) @@ -5285,7 +5286,7 @@ testNodeNumOfDevices(virConnectPtr conn, virCheckFlags(0, -1); =20 testDriverLock(driver); - ndevs =3D virNodeDeviceObjNumOfDevices(&driver->devs, conn, cap, NULL); + ndevs =3D virNodeDeviceObjNumOfDevices(driver->devs, conn, cap, NULL); testDriverUnlock(driver); =20 return ndevs; @@ -5305,7 +5306,7 @@ testNodeListDevices(virConnectPtr conn, virCheckFlags(0, -1); =20 testDriverLock(driver); - nnames =3D virNodeDeviceObjGetNames(&driver->devs, conn, NULL, + nnames =3D virNodeDeviceObjGetNames(driver->devs, conn, NULL, cap, names, maxnames); testDriverUnlock(driver); =20 @@ -5452,7 +5453,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, * using the scsi_host11 definition, changing the name and the * scsi_host capability fields before calling virNodeDeviceAssignDef * to add the def to the node device objects list. */ - if (!(objcopy =3D virNodeDeviceObjFindByName(&driver->devs, "scsi_host= 11"))) + if (!(objcopy =3D virNodeDeviceObjFindByName(driver->devs, "scsi_host1= 1"))) goto cleanup; =20 xml =3D virNodeDeviceDefFormat(virNodeDeviceObjGetDef(objcopy)); @@ -5492,7 +5493,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, caps =3D caps->next; } =20 - if (!(obj =3D virNodeDeviceObjAssignDef(&driver->devs, def))) + if (!(obj =3D virNodeDeviceObjAssignDef(driver->devs, def))) goto cleanup; def =3D NULL; objdef =3D virNodeDeviceObjGetDef(obj); @@ -5537,7 +5538,7 @@ testNodeDeviceCreateXML(virConnectPtr conn, /* Unlike the "real" code we don't need the parent_host in order to * call virVHBAManageVport, but still let's make sure the code finds * something valid and no one messed up the mock environment. */ - if (virNodeDeviceObjGetParentHost(&driver->devs, def, CREATE_DEVICE) <= 0) + if (virNodeDeviceObjGetParentHost(driver->devs, def, CREATE_DEVICE) < = 0) goto cleanup; =20 /* In the real code, we'd call virVHBAManageVport followed by @@ -5598,7 +5599,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) =20 /* We do this just for basic validation, but also avoid finding a * vport capable HBA if for some reason our vHBA doesn't exist */ - if (virNodeDeviceObjGetParentHost(&driver->devs, def, + if (virNodeDeviceObjGetParentHost(driver->devs, def, EXISTING_DEVICE) < 0) { obj =3D NULL; goto cleanup; @@ -5609,7 +5610,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) 0); =20 virNodeDeviceObjLock(obj); - virNodeDeviceObjRemove(&driver->devs, obj); + virNodeDeviceObjRemove(driver->devs, obj); virNodeDeviceObjFree(obj); obj =3D NULL; =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:38:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496495545390433.93161132435; Sat, 3 Jun 2017 06:12:25 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 18079C04B941; Sat, 3 Jun 2017 13:12:23 +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 E0ABE9103A; Sat, 3 Jun 2017 13:12:22 +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 94EBE180BAFC; Sat, 3 Jun 2017 13:12:22 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DC9DD005777 for ; Sat, 3 Jun 2017 09:12:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0512B7B8D9; Sat, 3 Jun 2017 13:12:09 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id B58D3179C2 for ; Sat, 3 Jun 2017 13:12:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 18079C04B941 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 18079C04B941 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:11:57 -0400 Message-Id: <20170603131202.17611-8-jferlan@redhat.com> In-Reply-To: <20170603131202.17611-1-jferlan@redhat.com> References: <20170603131202.17611-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 07/12] nodedev: Alter node device obj list function names 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 03 Jun 2017 13:12:23 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Ensure that any function that walks the node device object list is prefixed by virNodeDeviceObjList. Also, modify the @filter param name for virNodeDeviceObjListExport to be @aclfilter. Signed-off-by: John Ferlan --- src/conf/virnodedeviceobj.c | 109 ++++++++++++++++++-------------= ---- src/conf/virnodedeviceobj.h | 42 +++++++------- src/libvirt_private.syms | 14 ++--- src/node_device/node_device_driver.c | 20 +++---- src/node_device/node_device_hal.c | 12 ++-- src/node_device/node_device_udev.c | 14 ++--- src/test/test_driver.c | 28 ++++----- 7 files changed, 121 insertions(+), 118 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 4a25d95..fab1cfd 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -166,8 +166,8 @@ virNodeDeviceFindVPORTCapDef(const virNodeDeviceObj *ob= j) =20 =20 virNodeDeviceObjPtr -virNodeDeviceObjFindBySysfsPath(virNodeDeviceObjListPtr devs, - const char *sysfs_path) +virNodeDeviceObjListFindBySysfsPath(virNodeDeviceObjListPtr devs, + const char *sysfs_path) { size_t i; =20 @@ -185,8 +185,8 @@ virNodeDeviceObjFindBySysfsPath(virNodeDeviceObjListPtr= devs, =20 =20 virNodeDeviceObjPtr -virNodeDeviceObjFindByName(virNodeDeviceObjListPtr devs, - const char *name) +virNodeDeviceObjListFindByName(virNodeDeviceObjListPtr devs, + const char *name) { size_t i; =20 @@ -202,9 +202,9 @@ virNodeDeviceObjFindByName(virNodeDeviceObjListPtr devs, =20 =20 static virNodeDeviceObjPtr -virNodeDeviceFindByWWNs(virNodeDeviceObjListPtr devs, - const char *parent_wwnn, - const char *parent_wwpn) +virNodeDeviceObjListFindByWWNs(virNodeDeviceObjListPtr devs, + const char *parent_wwnn, + const char *parent_wwpn) { size_t i; =20 @@ -224,8 +224,8 @@ virNodeDeviceFindByWWNs(virNodeDeviceObjListPtr devs, =20 =20 static virNodeDeviceObjPtr -virNodeDeviceFindByFabricWWN(virNodeDeviceObjListPtr devs, - const char *parent_fabric_wwn) +virNodeDeviceObjListFindByFabricWWN(virNodeDeviceObjListPtr devs, + const char *parent_fabric_wwn) { size_t i; =20 @@ -244,8 +244,8 @@ virNodeDeviceFindByFabricWWN(virNodeDeviceObjListPtr de= vs, =20 =20 static virNodeDeviceObjPtr -virNodeDeviceFindByCap(virNodeDeviceObjListPtr devs, - const char *cap) +virNodeDeviceObjListFindByCap(virNodeDeviceObjListPtr devs, + const char *cap) { size_t i; =20 @@ -297,12 +297,12 @@ virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) =20 =20 virNodeDeviceObjPtr -virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def) +virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def) { virNodeDeviceObjPtr obj; =20 - if ((obj =3D virNodeDeviceObjFindByName(devs, def->name))) { + if ((obj =3D virNodeDeviceObjListFindByName(devs, def->name))) { virNodeDeviceDefFree(obj->def); obj->def =3D def; return obj; @@ -323,8 +323,8 @@ virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs, =20 =20 void -virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, - virNodeDeviceObjPtr obj) +virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs, + virNodeDeviceObjPtr obj) { size_t i; =20 @@ -373,14 +373,14 @@ virNodeDeviceFindFCParentHost(virNodeDeviceObjPtr obj) =20 =20 static int -virNodeDeviceGetParentHostByParent(virNodeDeviceObjListPtr devs, - const char *dev_name, - const char *parent_name) +virNodeDeviceObjListGetParentHostByParent(virNodeDeviceObjListPtr devs, + const char *dev_name, + const char *parent_name) { virNodeDeviceObjPtr obj =3D NULL; int ret; =20 - if (!(obj =3D virNodeDeviceObjFindByName(devs, parent_name))) { + if (!(obj =3D virNodeDeviceObjListFindByName(devs, parent_name))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find parent device for '%s'"), dev_name); @@ -396,15 +396,16 @@ virNodeDeviceGetParentHostByParent(virNodeDeviceObjLi= stPtr devs, =20 =20 static int -virNodeDeviceGetParentHostByWWNs(virNodeDeviceObjListPtr devs, - const char *dev_name, - const char *parent_wwnn, - const char *parent_wwpn) +virNodeDeviceObjListGetParentHostByWWNs(virNodeDeviceObjListPtr devs, + const char *dev_name, + const char *parent_wwnn, + const char *parent_wwpn) { virNodeDeviceObjPtr obj =3D NULL; int ret; =20 - if (!(obj =3D virNodeDeviceFindByWWNs(devs, parent_wwnn, parent_wwpn))= ) { + if (!(obj =3D virNodeDeviceObjListFindByWWNs(devs, parent_wwnn, + parent_wwpn))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find parent device for '%s'"), dev_name); @@ -420,14 +421,14 @@ virNodeDeviceGetParentHostByWWNs(virNodeDeviceObjList= Ptr devs, =20 =20 static int -virNodeDeviceGetParentHostByFabricWWN(virNodeDeviceObjListPtr devs, - const char *dev_name, - const char *parent_fabric_wwn) +virNodeDeviceObjListGetParentHostByFabricWWN(virNodeDeviceObjListPtr devs, + const char *dev_name, + const char *parent_fabric_wwn) { virNodeDeviceObjPtr obj =3D NULL; int ret; =20 - if (!(obj =3D virNodeDeviceFindByFabricWWN(devs, parent_fabric_wwn))) { + if (!(obj =3D virNodeDeviceObjListFindByFabricWWN(devs, parent_fabric_= wwn))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Could not find parent device for '%s'"), dev_name); @@ -443,13 +444,13 @@ virNodeDeviceGetParentHostByFabricWWN(virNodeDeviceOb= jListPtr devs, =20 =20 static int -virNodeDeviceFindVportParentHost(virNodeDeviceObjListPtr devs) +virNodeDeviceObjListFindVportParentHost(virNodeDeviceObjListPtr devs) { virNodeDeviceObjPtr obj =3D NULL; const char *cap =3D virNodeDevCapTypeToString(VIR_NODE_DEV_CAP_VPORTS); int ret; =20 - if (!(obj =3D virNodeDeviceFindByCap(devs, cap))) { + if (!(obj =3D virNodeDeviceObjListFindByCap(devs, cap))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("Could not find any vport capable device")); return -1; @@ -464,26 +465,26 @@ virNodeDeviceFindVportParentHost(virNodeDeviceObjList= Ptr devs) =20 =20 int -virNodeDeviceObjGetParentHost(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def, - int create) +virNodeDeviceObjListGetParentHost(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def, + int create) { int parent_host =3D -1; =20 if (def->parent) { - parent_host =3D virNodeDeviceGetParentHostByParent(devs, def->name, - def->parent); + parent_host =3D virNodeDeviceObjListGetParentHostByParent(devs, de= f->name, + def->paren= t); } else if (def->parent_wwnn && def->parent_wwpn) { - parent_host =3D virNodeDeviceGetParentHostByWWNs(devs, def->name, - def->parent_wwnn, - def->parent_wwpn); + parent_host =3D virNodeDeviceObjListGetParentHostByWWNs(devs, def-= >name, + def->parent_= wwnn, + def->parent_= wwpn); } else if (def->parent_fabric_wwn) { parent_host =3D - virNodeDeviceGetParentHostByFabricWWN(devs, def->name, - def->parent_fabric_wwn); + virNodeDeviceObjListGetParentHostByFabricWWN(devs, def->name, + def->parent_fabri= c_wwn); } else if (create =3D=3D CREATE_DEVICE) { /* Try to find a vport capable scsi_host when no parent supplied */ - parent_host =3D virNodeDeviceFindVportParentHost(devs); + parent_host =3D virNodeDeviceObjListFindVportParentHost(devs); } =20 return parent_host; @@ -555,10 +556,10 @@ virNodeDeviceCapMatch(virNodeDeviceObjPtr obj, =20 =20 int -virNodeDeviceObjNumOfDevices(virNodeDeviceObjListPtr devs, - virConnectPtr conn, - const char *cap, - virNodeDeviceObjListFilter aclfilter) +virNodeDeviceObjListNumOfDevices(virNodeDeviceObjListPtr devs, + virConnectPtr conn, + const char *cap, + virNodeDeviceObjListFilter aclfilter) { size_t i; int ndevs =3D 0; @@ -577,12 +578,12 @@ virNodeDeviceObjNumOfDevices(virNodeDeviceObjListPtr = devs, =20 =20 int -virNodeDeviceObjGetNames(virNodeDeviceObjListPtr devs, - virConnectPtr conn, - virNodeDeviceObjListFilter aclfilter, - const char *cap, - char **const names, - int maxnames) +virNodeDeviceObjListGetNames(virNodeDeviceObjListPtr devs, + virConnectPtr conn, + virNodeDeviceObjListFilter aclfilter, + const char *cap, + char **const names, + int maxnames) { int nnames =3D 0; size_t i; @@ -646,7 +647,7 @@ int virNodeDeviceObjListExport(virConnectPtr conn, virNodeDeviceObjListPtr devs, virNodeDevicePtr **devices, - virNodeDeviceObjListFilter filter, + virNodeDeviceObjListFilter aclfilter, unsigned int flags) { virNodeDevicePtr *tmp_devices =3D NULL; @@ -661,7 +662,7 @@ virNodeDeviceObjListExport(virConnectPtr conn, for (i =3D 0; i < devs->count; i++) { virNodeDeviceObjPtr obj =3D devs->objs[i]; virNodeDeviceObjLock(obj); - if ((!filter || filter(conn, obj->def)) && + if ((!aclfilter || aclfilter(conn, obj->def)) && virNodeDeviceMatch(obj, flags)) { if (devices) { if (!(device =3D virGetNodeDevice(conn, obj->def->name)) || diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 77250a0..6194c6c 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -44,25 +44,25 @@ virNodeDeviceDefPtr virNodeDeviceObjGetDef(virNodeDeviceObjPtr obj); =20 virNodeDeviceObjPtr -virNodeDeviceObjFindByName(virNodeDeviceObjListPtr devs, - const char *name); +virNodeDeviceObjListFindByName(virNodeDeviceObjListPtr devs, + const char *name); =20 virNodeDeviceObjPtr -virNodeDeviceObjFindBySysfsPath(virNodeDeviceObjListPtr devs, - const char *sysfs_path) +virNodeDeviceObjListFindBySysfsPath(virNodeDeviceObjListPtr devs, + const char *sysfs_path) ATTRIBUTE_NONNULL(2); =20 virNodeDeviceObjPtr -virNodeDeviceObjAssignDef(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def); +virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def); =20 void -virNodeDeviceObjRemove(virNodeDeviceObjListPtr devs, - virNodeDeviceObjPtr dev); +virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs, + virNodeDeviceObjPtr dev); =20 int -virNodeDeviceObjGetParentHost(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def, +virNodeDeviceObjListGetParentHost(virNodeDeviceObjListPtr devs, + virNodeDeviceDefPtr def, int create); =20 void @@ -85,24 +85,24 @@ typedef bool virNodeDeviceDefPtr def); =20 int -virNodeDeviceObjNumOfDevices(virNodeDeviceObjListPtr devs, - virConnectPtr conn, - const char *cap, - virNodeDeviceObjListFilter aclfilter); +virNodeDeviceObjListNumOfDevices(virNodeDeviceObjListPtr devs, + virConnectPtr conn, + const char *cap, + virNodeDeviceObjListFilter aclfilter); =20 int -virNodeDeviceObjGetNames(virNodeDeviceObjListPtr devs, - virConnectPtr conn, - virNodeDeviceObjListFilter aclfilter, - const char *cap, - char **const names, - int maxnames); +virNodeDeviceObjListGetNames(virNodeDeviceObjListPtr devs, + virConnectPtr conn, + virNodeDeviceObjListFilter aclfilter, + const char *cap, + char **const names, + int maxnames); =20 int virNodeDeviceObjListExport(virConnectPtr conn, virNodeDeviceObjListPtr devobjs, virNodeDevicePtr **devices, - virNodeDeviceObjListFilter filter, + virNodeDeviceObjListFilter aclfilter, unsigned int flags); =20 #endif /* __VIRNODEDEVICEOBJ_H__ */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 77f56c2..b511feb 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -956,19 +956,19 @@ virNetworkObjUpdateAssignDef; =20 =20 # conf/virnodedeviceobj.h -virNodeDeviceObjAssignDef; -virNodeDeviceObjFindByName; -virNodeDeviceObjFindBySysfsPath; virNodeDeviceObjFree; virNodeDeviceObjGetDef; -virNodeDeviceObjGetNames; -virNodeDeviceObjGetParentHost; +virNodeDeviceObjListAssignDef; virNodeDeviceObjListExport; +virNodeDeviceObjListFindByName; +virNodeDeviceObjListFindBySysfsPath; virNodeDeviceObjListFree; +virNodeDeviceObjListGetNames; +virNodeDeviceObjListGetParentHost; virNodeDeviceObjListNew; +virNodeDeviceObjListNumOfDevices; +virNodeDeviceObjListRemove; virNodeDeviceObjLock; -virNodeDeviceObjNumOfDevices; -virNodeDeviceObjRemove; virNodeDeviceObjUnlock; =20 =20 diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index fc9d0b0..348539f 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -182,8 +182,8 @@ nodeNumOfDevices(virConnectPtr conn, virCheckFlags(0, -1); =20 nodeDeviceLock(); - ndevs =3D virNodeDeviceObjNumOfDevices(driver->devs, conn, cap, - virNodeNumOfDevicesCheckACL); + ndevs =3D virNodeDeviceObjListNumOfDevices(driver->devs, conn, cap, + virNodeNumOfDevicesCheckACL); nodeDeviceUnlock(); =20 return ndevs; @@ -205,9 +205,9 @@ nodeListDevices(virConnectPtr conn, virCheckFlags(0, -1); =20 nodeDeviceLock(); - nnames =3D virNodeDeviceObjGetNames(driver->devs, conn, - virNodeListDevicesCheckACL, - cap, names, maxnames); + nnames =3D virNodeDeviceObjListGetNames(driver->devs, conn, + virNodeListDevicesCheckACL, + cap, names, maxnames); nodeDeviceUnlock(); =20 return nnames; @@ -241,7 +241,7 @@ nodeDeviceObjFindByName(const char *name) virNodeDeviceObjPtr obj; =20 nodeDeviceLock(); - obj =3D virNodeDeviceObjFindByName(driver->devs, name); + obj =3D virNodeDeviceObjListFindByName(driver->devs, name); nodeDeviceUnlock(); =20 if (!obj) { @@ -587,8 +587,8 @@ nodeDeviceCreateXML(virConnectPtr conn, if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) =3D=3D -1) goto cleanup; =20 - if ((parent_host =3D virNodeDeviceObjGetParentHost(driver->devs, def, - CREATE_DEVICE)) < 0) + if ((parent_host =3D virNodeDeviceObjListGetParentHost(driver->devs, d= ef, + CREATE_DEVICE)) <= 0) goto cleanup; =20 if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_CREATE) < 0) @@ -639,8 +639,8 @@ nodeDeviceDestroy(virNodeDevicePtr device) * or parent_fabric_wwn) and drop the object lock. */ virNodeDeviceObjUnlock(obj); obj =3D NULL; - if ((parent_host =3D virNodeDeviceObjGetParentHost(driver->devs, def, - EXISTING_DEVICE)) < 0) + if ((parent_host =3D virNodeDeviceObjListGetParentHost(driver->devs, d= ef, + EXISTING_DEVICE))= < 0) goto cleanup; =20 if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_DELETE) < 0) diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_devic= e_hal.c index f02fbe4..5521287 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -482,7 +482,7 @@ dev_create(const char *udi) /* Some devices don't have a path in sysfs, so ignore failure */ (void)get_str_prop(ctx, udi, "linux.sysfs_path", &devicePath); =20 - if (!(obj =3D virNodeDeviceObjAssignDef(driver->devs, def))) { + if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, def))) { VIR_FREE(devicePath); goto failure; } @@ -509,12 +509,12 @@ dev_refresh(const char *udi) virNodeDeviceObjPtr obj; =20 nodeDeviceLock(); - obj =3D virNodeDeviceObjFindByName(driver->devs, name); + obj =3D virNodeDeviceObjListFindByName(driver->devs, name); if (obj) { /* Simply "rediscover" device -- incrementally handling changes * to sub-capabilities (like net.80203) is nasty ... so avoid it. */ - virNodeDeviceObjRemove(driver->devs, obj); + virNodeDeviceObjListRemove(driver->devs, obj); } else { VIR_DEBUG("no device named %s", name); } @@ -541,10 +541,10 @@ device_removed(LibHalContext *ctx ATTRIBUTE_UNUSED, virNodeDeviceObjPtr obj; =20 nodeDeviceLock(); - obj =3D virNodeDeviceObjFindByName(driver->devs, name); + obj =3D virNodeDeviceObjListFindByName(driver->devs, name); VIR_DEBUG("%s", name); if (obj) { - virNodeDeviceObjRemove(driver->devs, obj); + virNodeDeviceObjListRemove(driver->devs, obj); virNodeDeviceObjFree(obj); } else { VIR_DEBUG("no device named %s", name); @@ -562,7 +562,7 @@ device_cap_added(LibHalContext *ctx, virNodeDeviceDefPtr def; =20 nodeDeviceLock(); - obj =3D virNodeDeviceObjFindByName(driver->devs, name); + obj =3D virNodeDeviceObjListFindByName(driver->devs, name); nodeDeviceUnlock(); VIR_DEBUG("%s %s", cap, name); if (obj) { diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 40f12e3..a210fe1 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1318,7 +1318,7 @@ udevRemoveOneDevice(struct udev_device *device) const char *name =3D NULL; =20 name =3D udev_device_get_syspath(device); - if (!(obj =3D virNodeDeviceObjFindBySysfsPath(driver->devs, name))) { + if (!(obj =3D virNodeDeviceObjListFindBySysfsPath(driver->devs, name))= ) { VIR_DEBUG("Failed to find device to remove that has udev name '%s'= ", name); return -1; @@ -1331,7 +1331,7 @@ udevRemoveOneDevice(struct udev_device *device) =20 VIR_DEBUG("Removing device '%s' with sysfs path '%s'", def->name, name); - virNodeDeviceObjRemove(driver->devs, obj); + virNodeDeviceObjListRemove(driver->devs, obj); virNodeDeviceObjFree(obj); =20 if (event) @@ -1365,8 +1365,8 @@ udevSetParent(struct udev_device *device, goto cleanup; } =20 - if ((obj =3D virNodeDeviceObjFindBySysfsPath(driver->devs, - parent_sysfs_path))) { + if ((obj =3D virNodeDeviceObjListFindBySysfsPath(driver->devs, + parent_sysfs_path))= ) { objdef =3D virNodeDeviceObjGetDef(obj); if (VIR_STRDUP(def->parent, objdef->name) < 0) { virNodeDeviceObjUnlock(obj); @@ -1424,7 +1424,7 @@ udevAddOneDevice(struct udev_device *device) if (udevSetParent(device, def) !=3D 0) goto cleanup; =20 - obj =3D virNodeDeviceObjFindByName(driver->devs, def->name); + obj =3D virNodeDeviceObjListFindByName(driver->devs, def->name); if (obj) { virNodeDeviceObjUnlock(obj); new_device =3D false; @@ -1432,7 +1432,7 @@ udevAddOneDevice(struct udev_device *device) =20 /* If this is a device change, the old definition will be freed * and the current definition will take its place. */ - if (!(obj =3D virNodeDeviceObjAssignDef(driver->devs, def))) + if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, def))) goto cleanup; objdef =3D virNodeDeviceObjGetDef(obj); =20 @@ -1722,7 +1722,7 @@ udevSetupSystemDev(void) udevGetDMIData(&def->caps->data.system); #endif =20 - if (!(obj =3D virNodeDeviceObjAssignDef(driver->devs, def))) + if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, def))) goto cleanup; =20 virNodeDeviceObjUnlock(obj); diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 6a74368..67fe252 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1170,7 +1170,7 @@ testParseNodedevs(testDriverPtr privconn, if (!def) goto error; =20 - if (!(obj =3D virNodeDeviceObjAssignDef(privconn->devs, def))) { + if (!(obj =3D virNodeDeviceObjListAssignDef(privconn->devs, def)))= { virNodeDeviceDefFree(def); goto error; } @@ -4520,7 +4520,8 @@ testDestroyVport(testDriverPtr privconn, * * Reaching across the boundaries of space and time into the * Node Device in order to remove */ - if (!(obj =3D virNodeDeviceObjFindByName(privconn->devs, "scsi_host12"= ))) { + if (!(obj =3D virNodeDeviceObjListFindByName(privconn->devs, + "scsi_host12"))) { virReportError(VIR_ERR_NO_NODE_DEVICE, "%s", _("no node device with matching name 'scsi_host12'"= )); return -1; @@ -4530,7 +4531,7 @@ testDestroyVport(testDriverPtr privconn, VIR_NODE_DEVICE_EVENT_DELETED, 0); =20 - virNodeDeviceObjRemove(privconn->devs, obj); + virNodeDeviceObjListRemove(privconn->devs, obj); virNodeDeviceObjFree(obj); obj =3D NULL; =20 @@ -5263,7 +5264,7 @@ testNodeDeviceObjFindByName(testDriverPtr driver, virNodeDeviceObjPtr obj; =20 testDriverLock(driver); - obj =3D virNodeDeviceObjFindByName(driver->devs, name); + obj =3D virNodeDeviceObjListFindByName(driver->devs, name); testDriverUnlock(driver); =20 if (!obj) @@ -5286,7 +5287,7 @@ testNodeNumOfDevices(virConnectPtr conn, virCheckFlags(0, -1); =20 testDriverLock(driver); - ndevs =3D virNodeDeviceObjNumOfDevices(driver->devs, conn, cap, NULL); + ndevs =3D virNodeDeviceObjListNumOfDevices(driver->devs, conn, cap, NU= LL); testDriverUnlock(driver); =20 return ndevs; @@ -5306,8 +5307,8 @@ testNodeListDevices(virConnectPtr conn, virCheckFlags(0, -1); =20 testDriverLock(driver); - nnames =3D virNodeDeviceObjGetNames(driver->devs, conn, NULL, - cap, names, maxnames); + nnames =3D virNodeDeviceObjListGetNames(driver->devs, conn, NULL, + cap, names, maxnames); testDriverUnlock(driver); =20 return nnames; @@ -5453,7 +5454,8 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, * using the scsi_host11 definition, changing the name and the * scsi_host capability fields before calling virNodeDeviceAssignDef * to add the def to the node device objects list. */ - if (!(objcopy =3D virNodeDeviceObjFindByName(driver->devs, "scsi_host1= 1"))) + if (!(objcopy =3D virNodeDeviceObjListFindByName(driver->devs, + "scsi_host11"))) goto cleanup; =20 xml =3D virNodeDeviceDefFormat(virNodeDeviceObjGetDef(objcopy)); @@ -5493,7 +5495,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, caps =3D caps->next; } =20 - if (!(obj =3D virNodeDeviceObjAssignDef(driver->devs, def))) + if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, def))) goto cleanup; def =3D NULL; objdef =3D virNodeDeviceObjGetDef(obj); @@ -5538,7 +5540,7 @@ testNodeDeviceCreateXML(virConnectPtr conn, /* Unlike the "real" code we don't need the parent_host in order to * call virVHBAManageVport, but still let's make sure the code finds * something valid and no one messed up the mock environment. */ - if (virNodeDeviceObjGetParentHost(driver->devs, def, CREATE_DEVICE) < = 0) + if (virNodeDeviceObjListGetParentHost(driver->devs, def, CREATE_DEVICE= ) < 0) goto cleanup; =20 /* In the real code, we'd call virVHBAManageVport followed by @@ -5599,8 +5601,8 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) =20 /* We do this just for basic validation, but also avoid finding a * vport capable HBA if for some reason our vHBA doesn't exist */ - if (virNodeDeviceObjGetParentHost(driver->devs, def, - EXISTING_DEVICE) < 0) { + if (virNodeDeviceObjListGetParentHost(driver->devs, def, + EXISTING_DEVICE) < 0) { obj =3D NULL; goto cleanup; } @@ -5610,7 +5612,7 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) 0); =20 virNodeDeviceObjLock(obj); - virNodeDeviceObjRemove(driver->devs, obj); + virNodeDeviceObjListRemove(driver->devs, obj); virNodeDeviceObjFree(obj); obj =3D NULL; =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:38:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496495556524142.0472857557039; Sat, 3 Jun 2017 06:12:36 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id B8E62232041; Sat, 3 Jun 2017 13:12:33 +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 9466C82E23; Sat, 3 Jun 2017 13:12:33 +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 51B514A496; Sat, 3 Jun 2017 13:12:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DC9ad005782 for ; Sat, 3 Jun 2017 09:12:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6876A7B8D9; Sat, 3 Jun 2017 13:12:09 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 29261179C2 for ; Sat, 3 Jun 2017 13:12:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com B8E62232041 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com B8E62232041 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:11:58 -0400 Message-Id: <20170603131202.17611-9-jferlan@redhat.com> In-Reply-To: <20170603131202.17611-1-jferlan@redhat.com> References: <20170603131202.17611-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 08/12] nodedev: Dereference the obj/def in virNodeDeviceObjListFind* APIs 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 03 Jun 2017 13:12:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Create local @obj and @def for the API's rather than referencing the devs->objs[i][->def->]. It'll make future patches easier to read. Signed-off-by: John Ferlan --- src/conf/virnodedeviceobj.c | 60 ++++++++++++++++++++++++++++-------------= ---- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index fab1cfd..a9187be 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -172,12 +172,16 @@ virNodeDeviceObjListFindBySysfsPath(virNodeDeviceObjL= istPtr devs, size_t i; =20 for (i =3D 0; i < devs->count; i++) { - virNodeDeviceObjLock(devs->objs[i]); - if ((devs->objs[i]->def->sysfs_path !=3D NULL) && - (STREQ(devs->objs[i]->def->sysfs_path, sysfs_path))) { - return devs->objs[i]; + virNodeDeviceObjPtr obj =3D devs->objs[i]; + virNodeDeviceDefPtr def; + + virNodeDeviceObjLock(obj); + def =3D obj->def; + if ((def->sysfs_path !=3D NULL) && + (STREQ(def->sysfs_path, sysfs_path))) { + return obj; } - virNodeDeviceObjUnlock(devs->objs[i]); + virNodeDeviceObjUnlock(obj); } =20 return NULL; @@ -191,10 +195,14 @@ virNodeDeviceObjListFindByName(virNodeDeviceObjListPt= r devs, size_t i; =20 for (i =3D 0; i < devs->count; i++) { - virNodeDeviceObjLock(devs->objs[i]); - if (STREQ(devs->objs[i]->def->name, name)) - return devs->objs[i]; - virNodeDeviceObjUnlock(devs->objs[i]); + virNodeDeviceObjPtr obj =3D devs->objs[i]; + virNodeDeviceDefPtr def; + + virNodeDeviceObjLock(obj); + def =3D obj->def; + if (STREQ(def->name, name)) + return obj; + virNodeDeviceObjUnlock(obj); } =20 return NULL; @@ -209,14 +217,16 @@ virNodeDeviceObjListFindByWWNs(virNodeDeviceObjListPt= r devs, size_t i; =20 for (i =3D 0; i < devs->count; i++) { + virNodeDeviceObjPtr obj =3D devs->objs[i]; virNodeDevCapsDefPtr cap; - virNodeDeviceObjLock(devs->objs[i]); - if ((cap =3D virNodeDeviceFindFCCapDef(devs->objs[i])) && + + virNodeDeviceObjLock(obj); + if ((cap =3D virNodeDeviceFindFCCapDef(obj)) && STREQ_NULLABLE(cap->data.scsi_host.wwnn, parent_wwnn) && STREQ_NULLABLE(cap->data.scsi_host.wwpn, parent_wwpn) && - virNodeDeviceFindVPORTCapDef(devs->objs[i])) - return devs->objs[i]; - virNodeDeviceObjUnlock(devs->objs[i]); + virNodeDeviceFindVPORTCapDef(obj)) + return obj; + virNodeDeviceObjUnlock(obj); } =20 return NULL; @@ -230,13 +240,15 @@ virNodeDeviceObjListFindByFabricWWN(virNodeDeviceObjL= istPtr devs, size_t i; =20 for (i =3D 0; i < devs->count; i++) { + virNodeDeviceObjPtr obj =3D devs->objs[i]; virNodeDevCapsDefPtr cap; - virNodeDeviceObjLock(devs->objs[i]); - if ((cap =3D virNodeDeviceFindFCCapDef(devs->objs[i])) && + + virNodeDeviceObjLock(obj); + if ((cap =3D virNodeDeviceFindFCCapDef(obj)) && STREQ_NULLABLE(cap->data.scsi_host.fabric_wwn, parent_fabric_w= wn) && - virNodeDeviceFindVPORTCapDef(devs->objs[i])) - return devs->objs[i]; - virNodeDeviceObjUnlock(devs->objs[i]); + virNodeDeviceFindVPORTCapDef(obj)) + return obj; + virNodeDeviceObjUnlock(obj); } =20 return NULL; @@ -250,10 +262,12 @@ virNodeDeviceObjListFindByCap(virNodeDeviceObjListPtr= devs, size_t i; =20 for (i =3D 0; i < devs->count; i++) { - virNodeDeviceObjLock(devs->objs[i]); - if (virNodeDeviceObjHasCap(devs->objs[i], cap)) - return devs->objs[i]; - virNodeDeviceObjUnlock(devs->objs[i]); + virNodeDeviceObjPtr obj =3D devs->objs[i]; + + virNodeDeviceObjLock(obj); + if (virNodeDeviceObjHasCap(obj, cap)) + return obj; + virNodeDeviceObjUnlock(obj); } =20 return NULL; --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:38:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 149649556136821.253996744248184; Sat, 3 Jun 2017 06:12:41 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 71C3C6198B; Sat, 3 Jun 2017 13:12:38 +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 4BDE082495; Sat, 3 Jun 2017 13:12:38 +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 1565E4A496; Sat, 3 Jun 2017 13:12:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DC9I9005793 for ; Sat, 3 Jun 2017 09:12:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id D002C7B8D9; Sat, 3 Jun 2017 13:12:09 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90203179C2 for ; Sat, 3 Jun 2017 13:12:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 71C3C6198B Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 71C3C6198B From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:11:59 -0400 Message-Id: <20170603131202.17611-10-jferlan@redhat.com> In-Reply-To: <20170603131202.17611-1-jferlan@redhat.com> References: <20170603131202.17611-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 09/12] nodedev: Introduce virNodeDeviceGetSCSIHostCaps 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 03 Jun 2017 13:12:39 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We're about to move the call to nodeDeviceSysfsGetSCSIHostCaps from node_device_driver into virnodedeviceobj, so move the guts of the code from the driver specific node_device_linux_sysfs into its own API since virnodedeviceobj cannot callback into the driver. Nothing in the code deals with sysfs anyway, as that's hidden by the various virSCSIHost* and virVHBA* utility function calls. Signed-off-by: John Ferlan --- src/conf/node_device_conf.c | 82 +++++++++++++++++++++++++++= ++++ src/conf/node_device_conf.h | 3 ++ src/libvirt_private.syms | 1 + src/node_device/node_device_linux_sysfs.c | 77 +--------------------------= -- 4 files changed, 87 insertions(+), 76 deletions(-) diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c index e5947e6..503b129 100644 --- a/src/conf/node_device_conf.c +++ b/src/conf/node_device_conf.c @@ -2483,3 +2483,85 @@ virNodeDeviceDeleteVport(virConnectPtr conn, VIR_FREE(scsi_host_name); return ret; } + + +int +virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host) +{ + char *tmp =3D NULL; + int ret =3D -1; + + if ((scsi_host->unique_id =3D + virSCSIHostGetUniqueId(NULL, scsi_host->host)) < 0) { + VIR_DEBUG("Failed to read unique_id for host%d", scsi_host->host); + scsi_host->unique_id =3D -1; + } + + VIR_DEBUG("Checking if host%d is an FC HBA", scsi_host->host); + + if (virVHBAPathExists(NULL, scsi_host->host)) { + scsi_host->flags |=3D VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST; + + if (!(tmp =3D virVHBAGetConfig(NULL, scsi_host->host, "port_name")= )) { + VIR_WARN("Failed to read WWPN for host%d", scsi_host->host); + goto cleanup; + } + VIR_FREE(scsi_host->wwpn); + VIR_STEAL_PTR(scsi_host->wwpn, tmp); + + if (!(tmp =3D virVHBAGetConfig(NULL, scsi_host->host, "node_name")= )) { + VIR_WARN("Failed to read WWNN for host%d", scsi_host->host); + goto cleanup; + } + VIR_FREE(scsi_host->wwnn); + VIR_STEAL_PTR(scsi_host->wwnn, tmp); + + if ((tmp =3D virVHBAGetConfig(NULL, scsi_host->host, "fabric_name"= ))) { + VIR_FREE(scsi_host->fabric_wwn); + VIR_STEAL_PTR(scsi_host->fabric_wwn, tmp); + } + } + + if (virVHBAIsVportCapable(NULL, scsi_host->host)) { + scsi_host->flags |=3D VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS; + + if (!(tmp =3D virVHBAGetConfig(NULL, scsi_host->host, + "max_npiv_vports"))) { + VIR_WARN("Failed to read max_npiv_vports for host%d", + scsi_host->host); + goto cleanup; + } + + if (virStrToLong_i(tmp, NULL, 10, &scsi_host->max_vports) < 0) { + VIR_WARN("Failed to parse value of max_npiv_vports '%s'", tmp); + goto cleanup; + } + + VIR_FREE(tmp); + if (!(tmp =3D virVHBAGetConfig(NULL, scsi_host->host, + "npiv_vports_inuse"))) { + VIR_WARN("Failed to read npiv_vports_inuse for host%d", + scsi_host->host); + goto cleanup; + } + + if (virStrToLong_i(tmp, NULL, 10, &scsi_host->vports) < 0) { + VIR_WARN("Failed to parse value of npiv_vports_inuse '%s'", tm= p); + goto cleanup; + } + } + + ret =3D 0; + cleanup: + if (ret < 0) { + /* Clear the two flags in case of producing confusing XML output */ + scsi_host->flags &=3D ~(VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST | + VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS); + + VIR_FREE(scsi_host->wwnn); + VIR_FREE(scsi_host->wwpn); + VIR_FREE(scsi_host->fabric_wwn); + } + VIR_FREE(tmp); + return ret; +} diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 0a5e731..90c7e1f 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -408,4 +408,7 @@ int virNodeDeviceDeleteVport(virConnectPtr conn, virStorageAdapterFCHostPtr fchost); =20 +int +virNodeDeviceGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host); + #endif /* __VIR_NODE_DEVICE_CONF_H__ */ diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index b511feb..33fc9fc 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -680,6 +680,7 @@ virNodeDeviceDefParseNode; virNodeDeviceDefParseString; virNodeDeviceDeleteVport; virNodeDeviceGetParentName; +virNodeDeviceGetSCSIHostCaps; virNodeDeviceGetWWNs; =20 =20 diff --git a/src/node_device/node_device_linux_sysfs.c b/src/node_device/no= de_device_linux_sysfs.c index e02c384..6f438e5 100644 --- a/src/node_device/node_device_linux_sysfs.c +++ b/src/node_device/node_device_linux_sysfs.c @@ -48,82 +48,7 @@ VIR_LOG_INIT("node_device.node_device_linux_sysfs"); int nodeDeviceSysfsGetSCSIHostCaps(virNodeDevCapSCSIHostPtr scsi_host) { - char *tmp =3D NULL; - int ret =3D -1; - - if ((scsi_host->unique_id =3D - virSCSIHostGetUniqueId(NULL, scsi_host->host)) < 0) { - VIR_DEBUG("Failed to read unique_id for host%d", scsi_host->host); - scsi_host->unique_id =3D -1; - } - - VIR_DEBUG("Checking if host%d is an FC HBA", scsi_host->host); - - if (virVHBAPathExists(NULL, scsi_host->host)) { - scsi_host->flags |=3D VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST; - - if (!(tmp =3D virVHBAGetConfig(NULL, scsi_host->host, "port_name")= )) { - VIR_WARN("Failed to read WWPN for host%d", scsi_host->host); - goto cleanup; - } - VIR_FREE(scsi_host->wwpn); - VIR_STEAL_PTR(scsi_host->wwpn, tmp); - - if (!(tmp =3D virVHBAGetConfig(NULL, scsi_host->host, "node_name")= )) { - VIR_WARN("Failed to read WWNN for host%d", scsi_host->host); - goto cleanup; - } - VIR_FREE(scsi_host->wwnn); - VIR_STEAL_PTR(scsi_host->wwnn, tmp); - - if ((tmp =3D virVHBAGetConfig(NULL, scsi_host->host, "fabric_name"= ))) { - VIR_FREE(scsi_host->fabric_wwn); - VIR_STEAL_PTR(scsi_host->fabric_wwn, tmp); - } - } - - if (virVHBAIsVportCapable(NULL, scsi_host->host)) { - scsi_host->flags |=3D VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS; - - if (!(tmp =3D virVHBAGetConfig(NULL, scsi_host->host, - "max_npiv_vports"))) { - VIR_WARN("Failed to read max_npiv_vports for host%d", - scsi_host->host); - goto cleanup; - } - - if (virStrToLong_i(tmp, NULL, 10, &scsi_host->max_vports) < 0) { - VIR_WARN("Failed to parse value of max_npiv_vports '%s'", tmp); - goto cleanup; - } - - VIR_FREE(tmp); - if (!(tmp =3D virVHBAGetConfig(NULL, scsi_host->host, - "npiv_vports_inuse"))) { - VIR_WARN("Failed to read npiv_vports_inuse for host%d", - scsi_host->host); - goto cleanup; - } - - if (virStrToLong_i(tmp, NULL, 10, &scsi_host->vports) < 0) { - VIR_WARN("Failed to parse value of npiv_vports_inuse '%s'", tm= p); - goto cleanup; - } - } - - ret =3D 0; - cleanup: - if (ret < 0) { - /* Clear the two flags in case of producing confusing XML output */ - scsi_host->flags &=3D ~(VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST | - VIR_NODE_DEV_CAP_FLAG_HBA_VPORT_OPS); - - VIR_FREE(scsi_host->wwnn); - VIR_FREE(scsi_host->wwpn); - VIR_FREE(scsi_host->fabric_wwn); - } - VIR_FREE(tmp); - return ret; + return virNodeDeviceGetSCSIHostCaps(scsi_host); } =20 =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:38:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496495534368990.6543120135294; Sat, 3 Jun 2017 06:12:14 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 410504E326; Sat, 3 Jun 2017 13:12:12 +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 130987B8FF; Sat, 3 Jun 2017 13:12:12 +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 B88321841C84; Sat, 3 Jun 2017 13:12:11 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DCAHr005805 for ; Sat, 3 Jun 2017 09:12:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id 43CCF7B8D9; Sat, 3 Jun 2017 13:12:10 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0330A179C2 for ; Sat, 3 Jun 2017 13:12:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 410504E326 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 410504E326 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:12:00 -0400 Message-Id: <20170603131202.17611-11-jferlan@redhat.com> In-Reply-To: <20170603131202.17611-1-jferlan@redhat.com> References: <20170603131202.17611-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 10/12] nodedev: Introduce virNodeDeviceObjListFindSCSIHostByWWNs 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 03 Jun 2017 13:12:12 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Alter the nodeDeviceLookupSCSIHostByWWN to use the new API in order to find what it's looking for. Signed-off-by: John Ferlan --- src/conf/virnodedeviceobj.c | 33 +++++++++++++++++++++ src/conf/virnodedeviceobj.h | 5 ++++ src/libvirt_private.syms | 1 + src/node_device/node_device_driver.c | 56 +++++++++++---------------------= ---- 4 files changed, 55 insertions(+), 40 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index a9187be..fa61a2d 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -274,6 +274,39 @@ virNodeDeviceObjListFindByCap(virNodeDeviceObjListPtr = devs, } =20 =20 +virNodeDeviceObjPtr +virNodeDeviceObjListFindSCSIHostByWWNs(virNodeDeviceObjListPtr devs, + const char *wwnn, + const char *wwpn) +{ + size_t i; + + for (i =3D 0; i < devs->count; i++) { + virNodeDeviceObjPtr obj =3D devs->objs[i]; + virNodeDevCapsDefPtr cap; + + virNodeDeviceObjLock(obj); + cap =3D obj->def->caps; + + while (cap) { + if (cap->data.type =3D=3D VIR_NODE_DEV_CAP_SCSI_HOST) { + virNodeDeviceGetSCSIHostCaps(&cap->data.scsi_host); + if (cap->data.scsi_host.flags & + VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) { + if (STREQ(cap->data.scsi_host.wwnn, wwnn) && + STREQ(cap->data.scsi_host.wwpn, wwpn)) + return obj; + } + } + cap =3D cap->next; + } + virNodeDeviceObjUnlock(obj); + } + + return NULL; +} + + void virNodeDeviceObjFree(virNodeDeviceObjPtr obj) { diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 6194c6c..6ec5ee7 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -53,6 +53,11 @@ virNodeDeviceObjListFindBySysfsPath(virNodeDeviceObjList= Ptr devs, ATTRIBUTE_NONNULL(2); =20 virNodeDeviceObjPtr +virNodeDeviceObjListFindSCSIHostByWWNs(virNodeDeviceObjListPtr devs, + const char *wwnn, + const char *wwpn); + +virNodeDeviceObjPtr virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr devs, virNodeDeviceDefPtr def); =20 diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index 33fc9fc..d415888 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -963,6 +963,7 @@ virNodeDeviceObjListAssignDef; virNodeDeviceObjListExport; virNodeDeviceObjListFindByName; virNodeDeviceObjListFindBySysfsPath; +virNodeDeviceObjListFindSCSIHostByWWNs; virNodeDeviceObjListFree; virNodeDeviceObjListGetNames; virNodeDeviceObjListGetParentHost; diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 348539f..4a5f168 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -288,9 +288,6 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, const char *wwpn, unsigned int flags) { - size_t i; - virNodeDeviceObjListPtr devs =3D driver->devs; - virNodeDevCapsDefPtr cap =3D NULL; virNodeDeviceObjPtr obj =3D NULL; virNodeDeviceDefPtr def; virNodeDevicePtr device =3D NULL; @@ -298,48 +295,27 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, virCheckFlags(0, NULL); =20 nodeDeviceLock(); + obj =3D virNodeDeviceObjListFindSCSIHostByWWNs(driver->devs, wwnn, wwp= n); + nodeDeviceUnlock(); =20 - for (i =3D 0; i < devs->count; i++) { - obj =3D devs->objs[i]; - virNodeDeviceObjLock(obj); - def =3D virNodeDeviceObjGetDef(obj); - cap =3D def->caps; - - while (cap) { - if (cap->data.type =3D=3D VIR_NODE_DEV_CAP_SCSI_HOST) { - nodeDeviceSysfsGetSCSIHostCaps(&cap->data.scsi_host); - if (cap->data.scsi_host.flags & - VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) { - if (STREQ(cap->data.scsi_host.wwnn, wwnn) && - STREQ(cap->data.scsi_host.wwpn, wwpn)) { - - if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn= , def) < 0) - goto error; - - if ((device =3D virGetNodeDevice(conn, def->name))= ) { - if (VIR_STRDUP(device->parent, def->parent) < = 0) { - virObjectUnref(device); - device =3D NULL; - } - } - virNodeDeviceObjUnlock(obj); - goto out; - } - } - } - cap =3D cap->next; - } + if (!obj) + return NULL; =20 - virNodeDeviceObjUnlock(obj); - } + def =3D virNodeDeviceObjGetDef(obj); =20 - out: - nodeDeviceUnlock(); - return device; + if (virNodeDeviceLookupSCSIHostByWWNEnsureACL(conn, def) < 0) + goto cleanup; =20 - error: + if ((device =3D virGetNodeDevice(conn, def->name))) { + if (VIR_STRDUP(device->parent, def->parent) < 0) { + virObjectUnref(device); + device =3D NULL; + } + } + + cleanup: virNodeDeviceObjUnlock(obj); - goto out; + return device; } =20 =20 --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:38:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496495541420927.9375094552689; Sat, 3 Jun 2017 06:12:21 -0700 (PDT) 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 mx1.redhat.com (Postfix) with ESMTPS id 2F40B15D9; Sat, 3 Jun 2017 13:12:19 +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 078CA7839B; Sat, 3 Jun 2017 13:12:19 +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 B07464A48E; Sat, 3 Jun 2017 13:12:18 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DCAK3005815 for ; Sat, 3 Jun 2017 09:12:10 -0400 Received: by smtp.corp.redhat.com (Postfix) id AB3CF7B8D9; Sat, 3 Jun 2017 13:12:10 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6AA8A179C2 for ; Sat, 3 Jun 2017 13:12:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 2F40B15D9 Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx05.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 2F40B15D9 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:12:01 -0400 Message-Id: <20170603131202.17611-12-jferlan@redhat.com> In-Reply-To: <20170603131202.17611-1-jferlan@redhat.com> References: <20170603131202.17611-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 11/12] nodedev: Privatize _virNodeDeviceObj and _virNodeDeviceObjList 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 03 Jun 2017 13:12:19 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Move the structures to withing virnodedeviceobj.c Move the typedefs from node_device_conf to virnodedeviceobj.h Signed-off-by: John Ferlan --- src/conf/node_device_conf.h | 17 ----------------- src/conf/virnodedeviceobj.c | 11 +++++++++++ src/conf/virnodedeviceobj.h | 6 ++++++ 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/conf/node_device_conf.h b/src/conf/node_device_conf.h index 90c7e1f..d10683d 100644 --- a/src/conf/node_device_conf.h +++ b/src/conf/node_device_conf.h @@ -328,23 +328,6 @@ struct _virNodeDeviceDef { virNodeDevCapsDefPtr caps; /* optional device capabilities */ }; =20 - -typedef struct _virNodeDeviceObj virNodeDeviceObj; -typedef virNodeDeviceObj *virNodeDeviceObjPtr; -struct _virNodeDeviceObj { - virMutex lock; - - virNodeDeviceDefPtr def; /* device definition */ - -}; - -typedef struct _virNodeDeviceObjList virNodeDeviceObjList; -typedef virNodeDeviceObjList *virNodeDeviceObjListPtr; -struct _virNodeDeviceObjList { - size_t count; - virNodeDeviceObjPtr *objs; -}; - char * virNodeDeviceDefFormat(const virNodeDeviceDef *def); =20 diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index fa61a2d..c19f1e4 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -32,6 +32,17 @@ =20 VIR_LOG_INIT("conf.virnodedeviceobj"); =20 +struct _virNodeDeviceObj { + virMutex lock; + + virNodeDeviceDefPtr def; /* device definition */ +}; + +struct _virNodeDeviceObjList { + size_t count; + virNodeDeviceObjPtr *objs; +}; + =20 static virNodeDeviceObjPtr virNodeDeviceObjNew(virNodeDeviceDefPtr def) diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 6ec5ee7..1122b67 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -27,6 +27,12 @@ # include "object_event.h" =20 =20 +typedef struct _virNodeDeviceObj virNodeDeviceObj; +typedef virNodeDeviceObj *virNodeDeviceObjPtr; + +typedef struct _virNodeDeviceObjList virNodeDeviceObjList; +typedef virNodeDeviceObjList *virNodeDeviceObjListPtr; + typedef struct _virNodeDeviceDriverState virNodeDeviceDriverState; typedef virNodeDeviceDriverState *virNodeDeviceDriverStatePtr; struct _virNodeDeviceDriverState { --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Sun May 5 18:38:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1496495548835215.9748319645821; Sat, 3 Jun 2017 06:12:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E300480491; Sat, 3 Jun 2017 13:12:26 +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 AD21594C41; Sat, 3 Jun 2017 13:12:26 +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 0B93E180BAFD; Sat, 3 Jun 2017 13:12:26 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v53DCBWS005825 for ; Sat, 3 Jun 2017 09:12:11 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1D6057B8D9; Sat, 3 Jun 2017 13:12:11 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-116-124.phx2.redhat.com [10.3.116.124]) by smtp.corp.redhat.com (Postfix) with ESMTP id D24C6179C2 for ; Sat, 3 Jun 2017 13:12:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E300480491 Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx04.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=libvir-list-bounces@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com E300480491 From: John Ferlan To: libvir-list@redhat.com Date: Sat, 3 Jun 2017 09:12:02 -0400 Message-Id: <20170603131202.17611-13-jferlan@redhat.com> In-Reply-To: <20170603131202.17611-1-jferlan@redhat.com> References: <20170603131202.17611-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v3 12/12] nodedev: Convert virNodeDeviceObj to use virObjectLockable 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-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 03 Jun 2017 13:12:27 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Now that we have a bit more control, let's convert our object into a lockable object and let that magic handle the create and lock/unlock. This also involves creating a virNodeDeviceEndAPI in order to handle the object cleaup for API's that use the Add or Find API's in order to get a locked/reffed object. The EndAPI will unlock and unref the object returning NULL to indicate to the caller to not use the obj. For now this also involves a forward reference to the Unlock, but that'll be removed shortly when the object is convert to use the virObjectLockable shortly. Signed-off-by: John Ferlan --- src/conf/virnodedeviceobj.c | 156 ++++++++++++++++++-------------= ---- src/conf/virnodedeviceobj.h | 11 +-- src/libvirt_private.syms | 4 +- src/node_device/node_device_driver.c | 17 ++-- src/node_device/node_device_hal.c | 6 +- src/node_device/node_device_udev.c | 12 +-- src/test/test_driver.c | 40 ++++----- 7 files changed, 122 insertions(+), 124 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index c19f1e4..3787b23 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -33,7 +33,7 @@ VIR_LOG_INIT("conf.virnodedeviceobj"); =20 struct _virNodeDeviceObj { - virMutex lock; + virObjectLockable parent; =20 virNodeDeviceDefPtr def; /* device definition */ }; @@ -44,27 +44,63 @@ struct _virNodeDeviceObjList { }; =20 =20 +static virClassPtr virNodeDeviceObjClass; +static void virNodeDeviceObjDispose(void *opaque); + +static int +virNodeDeviceObjOnceInit(void) +{ + if (!(virNodeDeviceObjClass =3D virClassNew(virClassForObjectLockable(= ), + "virNodeDeviceObj", + sizeof(virNodeDeviceObj), + virNodeDeviceObjDispose))) + return -1; + + return 0; +} + +VIR_ONCE_GLOBAL_INIT(virNodeDeviceObj) + + +static void +virNodeDeviceObjDispose(void *opaque) +{ + virNodeDeviceObjPtr obj =3D opaque; + + virNodeDeviceDefFree(obj->def); +} + + static virNodeDeviceObjPtr virNodeDeviceObjNew(virNodeDeviceDefPtr def) { virNodeDeviceObjPtr obj; =20 - if (VIR_ALLOC(obj) < 0) + if (virNodeDeviceObjInitialize() < 0) return NULL; =20 - if (virMutexInit(&obj->lock) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - "%s", _("cannot initialize mutex")); - VIR_FREE(obj); + if (!(obj =3D virObjectLockableNew(virNodeDeviceObjClass))) return NULL; - } - virNodeDeviceObjLock(obj); + + virObjectLock(obj); obj->def =3D def; =20 return obj; } =20 =20 +void +virNodeDeviceObjEndAPI(virNodeDeviceObjPtr *obj) +{ + if (!*obj) + return; + + virObjectUnlock(*obj); + virObjectUnref(*obj); + *obj =3D NULL; +} + + virNodeDeviceDefPtr virNodeDeviceObjGetDef(virNodeDeviceObjPtr obj) { @@ -186,13 +222,13 @@ virNodeDeviceObjListFindBySysfsPath(virNodeDeviceObjL= istPtr devs, virNodeDeviceObjPtr obj =3D devs->objs[i]; virNodeDeviceDefPtr def; =20 - virNodeDeviceObjLock(obj); + virObjectLock(obj); def =3D obj->def; if ((def->sysfs_path !=3D NULL) && (STREQ(def->sysfs_path, sysfs_path))) { - return obj; + return virObjectRef(obj); } - virNodeDeviceObjUnlock(obj); + virObjectUnlock(obj); } =20 return NULL; @@ -209,11 +245,11 @@ virNodeDeviceObjListFindByName(virNodeDeviceObjListPt= r devs, virNodeDeviceObjPtr obj =3D devs->objs[i]; virNodeDeviceDefPtr def; =20 - virNodeDeviceObjLock(obj); + virObjectLock(obj); def =3D obj->def; if (STREQ(def->name, name)) - return obj; - virNodeDeviceObjUnlock(obj); + return virObjectRef(obj); + virObjectUnlock(obj); } =20 return NULL; @@ -231,13 +267,13 @@ virNodeDeviceObjListFindByWWNs(virNodeDeviceObjListPt= r devs, virNodeDeviceObjPtr obj =3D devs->objs[i]; virNodeDevCapsDefPtr cap; =20 - virNodeDeviceObjLock(obj); + virObjectLock(obj); if ((cap =3D virNodeDeviceFindFCCapDef(obj)) && STREQ_NULLABLE(cap->data.scsi_host.wwnn, parent_wwnn) && STREQ_NULLABLE(cap->data.scsi_host.wwpn, parent_wwpn) && virNodeDeviceFindVPORTCapDef(obj)) - return obj; - virNodeDeviceObjUnlock(obj); + return virObjectRef(obj); + virObjectUnlock(obj); } =20 return NULL; @@ -254,12 +290,12 @@ virNodeDeviceObjListFindByFabricWWN(virNodeDeviceObjL= istPtr devs, virNodeDeviceObjPtr obj =3D devs->objs[i]; virNodeDevCapsDefPtr cap; =20 - virNodeDeviceObjLock(obj); + virObjectLock(obj); if ((cap =3D virNodeDeviceFindFCCapDef(obj)) && STREQ_NULLABLE(cap->data.scsi_host.fabric_wwn, parent_fabric_w= wn) && virNodeDeviceFindVPORTCapDef(obj)) - return obj; - virNodeDeviceObjUnlock(obj); + return virObjectRef(obj); + virObjectUnlock(obj); } =20 return NULL; @@ -275,10 +311,10 @@ virNodeDeviceObjListFindByCap(virNodeDeviceObjListPtr= devs, for (i =3D 0; i < devs->count; i++) { virNodeDeviceObjPtr obj =3D devs->objs[i]; =20 - virNodeDeviceObjLock(obj); + virObjectLock(obj); if (virNodeDeviceObjHasCap(obj, cap)) - return obj; - virNodeDeviceObjUnlock(obj); + return virObjectRef(obj); + virObjectUnlock(obj); } =20 return NULL; @@ -296,7 +332,7 @@ virNodeDeviceObjListFindSCSIHostByWWNs(virNodeDeviceObj= ListPtr devs, virNodeDeviceObjPtr obj =3D devs->objs[i]; virNodeDevCapsDefPtr cap; =20 - virNodeDeviceObjLock(obj); + virObjectLock(obj); cap =3D obj->def->caps; =20 while (cap) { @@ -306,32 +342,18 @@ virNodeDeviceObjListFindSCSIHostByWWNs(virNodeDeviceO= bjListPtr devs, VIR_NODE_DEV_CAP_FLAG_HBA_FC_HOST) { if (STREQ(cap->data.scsi_host.wwnn, wwnn) && STREQ(cap->data.scsi_host.wwpn, wwpn)) - return obj; + return virObjectRef(obj); } } cap =3D cap->next; } - virNodeDeviceObjUnlock(obj); + virObjectUnlock(obj); } =20 return NULL; } =20 =20 -void -virNodeDeviceObjFree(virNodeDeviceObjPtr obj) -{ - if (!obj) - return; - - virNodeDeviceDefFree(obj->def); - - virMutexDestroy(&obj->lock); - - VIR_FREE(obj); -} - - virNodeDeviceObjListPtr virNodeDeviceObjListNew(void) { @@ -348,7 +370,7 @@ virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) { size_t i; for (i =3D 0; i < devs->count; i++) - virNodeDeviceObjFree(devs->objs[i]); + virObjectUnref(devs->objs[i]); VIR_FREE(devs->objs); VIR_FREE(devs); } @@ -371,12 +393,11 @@ virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr= devs, =20 if (VIR_APPEND_ELEMENT_COPY(devs->objs, devs->count, obj) < 0) { obj->def =3D NULL; - virNodeDeviceObjUnlock(obj); - virNodeDeviceObjFree(obj); + virNodeDeviceObjEndAPI(&obj); return NULL; } =20 - return obj; + return virObjectRef(obj); } =20 =20 @@ -386,17 +407,18 @@ virNodeDeviceObjListRemove(virNodeDeviceObjListPtr de= vs, { size_t i; =20 - virNodeDeviceObjUnlock(obj); + virObjectUnlock(obj); =20 for (i =3D 0; i < devs->count; i++) { - virNodeDeviceObjLock(devs->objs[i]); + virObjectLock(devs->objs[i]); if (devs->objs[i] =3D=3D obj) { - virNodeDeviceObjUnlock(devs->objs[i]); + virObjectUnlock(devs->objs[i]); + virObjectUnref(devs->objs[i]); =20 VIR_DELETE_ELEMENT(devs->objs, i, devs->count); break; } - virNodeDeviceObjUnlock(devs->objs[i]); + virObjectUnlock(devs->objs[i]); } } =20 @@ -447,7 +469,7 @@ virNodeDeviceObjListGetParentHostByParent(virNodeDevice= ObjListPtr devs, =20 ret =3D virNodeDeviceFindFCParentHost(obj); =20 - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); =20 return ret; } @@ -472,7 +494,7 @@ virNodeDeviceObjListGetParentHostByWWNs(virNodeDeviceOb= jListPtr devs, =20 ret =3D virNodeDeviceFindFCParentHost(obj); =20 - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); =20 return ret; } @@ -495,7 +517,7 @@ virNodeDeviceObjListGetParentHostByFabricWWN(virNodeDev= iceObjListPtr devs, =20 ret =3D virNodeDeviceFindFCParentHost(obj); =20 - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); =20 return ret; } @@ -516,7 +538,7 @@ virNodeDeviceObjListFindVportParentHost(virNodeDeviceOb= jListPtr devs) =20 ret =3D virNodeDeviceFindFCParentHost(obj); =20 - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); =20 return ret; } @@ -549,20 +571,6 @@ virNodeDeviceObjListGetParentHost(virNodeDeviceObjList= Ptr devs, } =20 =20 -void -virNodeDeviceObjLock(virNodeDeviceObjPtr obj) -{ - virMutexLock(&obj->lock); -} - - -void -virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj) -{ - virMutexUnlock(&obj->lock); -} - - static bool virNodeDeviceCapMatch(virNodeDeviceObjPtr obj, int type) @@ -624,11 +632,11 @@ virNodeDeviceObjListNumOfDevices(virNodeDeviceObjList= Ptr devs, =20 for (i =3D 0; i < devs->count; i++) { virNodeDeviceObjPtr obj =3D devs->objs[i]; - virNodeDeviceObjLock(obj); + virObjectLock(obj); if ((!aclfilter || aclfilter(conn, obj->def)) && (!cap || virNodeDeviceObjHasCap(obj, cap))) ++ndevs; - virNodeDeviceObjUnlock(obj); + virObjectUnlock(obj); } =20 return ndevs; @@ -648,16 +656,16 @@ virNodeDeviceObjListGetNames(virNodeDeviceObjListPtr = devs, =20 for (i =3D 0; i < devs->count && nnames < maxnames; i++) { virNodeDeviceObjPtr obj =3D devs->objs[i]; - virNodeDeviceObjLock(obj); + virObjectLock(obj); if ((!aclfilter || aclfilter(conn, obj->def)) && (!cap || virNodeDeviceObjHasCap(obj, cap))) { if (VIR_STRDUP(names[nnames], obj->def->name) < 0) { - virNodeDeviceObjUnlock(obj); + virObjectUnlock(obj); goto failure; } nnames++; } - virNodeDeviceObjUnlock(obj); + virObjectUnlock(obj); } =20 return nnames; @@ -719,21 +727,21 @@ virNodeDeviceObjListExport(virConnectPtr conn, =20 for (i =3D 0; i < devs->count; i++) { virNodeDeviceObjPtr obj =3D devs->objs[i]; - virNodeDeviceObjLock(obj); + virObjectLock(obj); if ((!aclfilter || aclfilter(conn, obj->def)) && virNodeDeviceMatch(obj, flags)) { if (devices) { if (!(device =3D virGetNodeDevice(conn, obj->def->name)) || VIR_STRDUP(device->parent, obj->def->parent) < 0) { virObjectUnref(device); - virNodeDeviceObjUnlock(obj); + virObjectUnlock(obj); goto cleanup; } tmp_devices[ndevices] =3D device; } ndevices++; } - virNodeDeviceObjUnlock(obj); + virObjectUnlock(obj); } =20 if (tmp_devices) { diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 1122b67..788fb66 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -45,6 +45,8 @@ struct _virNodeDeviceDriverState { virObjectEventStatePtr nodeDeviceEventState; }; =20 +void +virNodeDeviceObjEndAPI(virNodeDeviceObjPtr *obj); =20 virNodeDeviceDefPtr virNodeDeviceObjGetDef(virNodeDeviceObjPtr obj); @@ -76,21 +78,12 @@ virNodeDeviceObjListGetParentHost(virNodeDeviceObjListP= tr devs, virNodeDeviceDefPtr def, int create); =20 -void -virNodeDeviceObjFree(virNodeDeviceObjPtr dev); - virNodeDeviceObjListPtr virNodeDeviceObjListNew(void); =20 void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs); =20 -void -virNodeDeviceObjLock(virNodeDeviceObjPtr obj); - -void -virNodeDeviceObjUnlock(virNodeDeviceObjPtr obj); - typedef bool (*virNodeDeviceObjListFilter)(virConnectPtr conn, virNodeDeviceDefPtr def); diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index d415888..1eb4502 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -957,7 +957,7 @@ virNetworkObjUpdateAssignDef; =20 =20 # conf/virnodedeviceobj.h -virNodeDeviceObjFree; +virNodeDeviceObjEndAPI; virNodeDeviceObjGetDef; virNodeDeviceObjListAssignDef; virNodeDeviceObjListExport; @@ -970,8 +970,6 @@ virNodeDeviceObjListGetParentHost; virNodeDeviceObjListNew; virNodeDeviceObjListNumOfDevices; virNodeDeviceObjListRemove; -virNodeDeviceObjLock; -virNodeDeviceObjUnlock; =20 =20 # conf/virnwfilterobj.h diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 4a5f168..788b8bc 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -277,7 +277,7 @@ nodeDeviceLookupByName(virConnectPtr conn, } =20 cleanup: - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); return device; } =20 @@ -314,7 +314,7 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, } =20 cleanup: - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); return device; } =20 @@ -345,7 +345,7 @@ nodeDeviceGetXMLDesc(virNodeDevicePtr device, ret =3D virNodeDeviceDefFormat(def); =20 cleanup: - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); return ret; } =20 @@ -373,7 +373,7 @@ nodeDeviceGetParent(virNodeDevicePtr device) } =20 cleanup: - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); return ret; } =20 @@ -411,7 +411,7 @@ nodeDeviceNumOfCaps(virNodeDevicePtr device) ret =3D ncaps; =20 cleanup: - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); return ret; } =20 @@ -460,7 +460,7 @@ nodeDeviceListCaps(virNodeDevicePtr device, ret =3D ncaps; =20 cleanup: - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); if (ret =3D=3D -1) { --ncaps; while (--ncaps >=3D 0) @@ -613,8 +613,7 @@ nodeDeviceDestroy(virNodeDevicePtr device) * to be taken, so grab the object def which will have the various * fields used to search (name, parent, parent_wwnn, parent_wwpn, * or parent_fabric_wwn) and drop the object lock. */ - virNodeDeviceObjUnlock(obj); - obj =3D NULL; + virNodeDeviceObjEndAPI(&obj); if ((parent_host =3D virNodeDeviceObjListGetParentHost(driver->devs, d= ef, EXISTING_DEVICE))= < 0) goto cleanup; @@ -626,7 +625,7 @@ nodeDeviceDestroy(virNodeDevicePtr device) =20 cleanup: nodeDeviceUnlock(); - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); VIR_FREE(wwnn); VIR_FREE(wwpn); return ret; diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_devic= e_hal.c index 5521287..d92b47a 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -490,7 +490,7 @@ dev_create(const char *udi) =20 objdef->sysfs_path =3D devicePath; =20 - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); =20 nodeDeviceUnlock(); return; @@ -545,7 +545,7 @@ device_removed(LibHalContext *ctx ATTRIBUTE_UNUSED, VIR_DEBUG("%s", name); if (obj) { virNodeDeviceObjListRemove(driver->devs, obj); - virNodeDeviceObjFree(obj); + virObjectUnref(obj); } else { VIR_DEBUG("no device named %s", name); } @@ -568,7 +568,7 @@ device_cap_added(LibHalContext *ctx, if (obj) { def =3D virNodeDeviceObjGetDef(obj); (void)gather_capability(ctx, udi, cap, &def->caps); - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); } else { VIR_DEBUG("no device named %s", name); } diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index a210fe1..8016d17 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1332,7 +1332,7 @@ udevRemoveOneDevice(struct udev_device *device) VIR_DEBUG("Removing device '%s' with sysfs path '%s'", def->name, name); virNodeDeviceObjListRemove(driver->devs, obj); - virNodeDeviceObjFree(obj); + virObjectUnlock(obj); =20 if (event) virObjectEventStateQueue(driver->nodeDeviceEventState, event); @@ -1369,10 +1369,10 @@ udevSetParent(struct udev_device *device, parent_sysfs_path))= ) { objdef =3D virNodeDeviceObjGetDef(obj); if (VIR_STRDUP(def->parent, objdef->name) < 0) { - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); goto cleanup; } - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); =20 if (VIR_STRDUP(def->parent_sysfs_path, parent_sysfs_path) < 0) goto cleanup; @@ -1426,7 +1426,7 @@ udevAddOneDevice(struct udev_device *device) =20 obj =3D virNodeDeviceObjListFindByName(driver->devs, def->name); if (obj) { - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); new_device =3D false; } =20 @@ -1443,7 +1443,7 @@ udevAddOneDevice(struct udev_device *device) else event =3D virNodeDeviceEventUpdateNew(objdef->name); =20 - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); =20 ret =3D 0; =20 @@ -1725,7 +1725,7 @@ udevSetupSystemDev(void) if (!(obj =3D virNodeDeviceObjListAssignDef(driver->devs, def))) goto cleanup; =20 - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); =20 ret =3D 0; =20 diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 67fe252..7b67523 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -1175,7 +1175,7 @@ testParseNodedevs(testDriverPtr privconn, goto error; } =20 - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); } =20 ret =3D 0; @@ -4320,7 +4320,7 @@ testCreateVport(testDriverPtr driver, * create the vHBA. In the long run the result is the same. */ if (!(obj =3D testNodeDeviceMockCreateVport(driver, wwnn, wwpn))) return -1; - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); =20 return 0; } @@ -4532,7 +4532,7 @@ testDestroyVport(testDriverPtr privconn, 0); =20 virNodeDeviceObjListRemove(privconn->devs, obj); - virNodeDeviceObjFree(obj); + virObjectUnref(obj); obj =3D NULL; =20 testObjectEventQueue(privconn, event); @@ -5334,7 +5334,7 @@ testNodeDeviceLookupByName(virConnectPtr conn, const = char *name) } } =20 - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); return ret; } =20 @@ -5353,7 +5353,7 @@ testNodeDeviceGetXMLDesc(virNodeDevicePtr dev, =20 ret =3D virNodeDeviceDefFormat(virNodeDeviceObjGetDef(obj)); =20 - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); return ret; } =20 @@ -5376,7 +5376,7 @@ testNodeDeviceGetParent(virNodeDevicePtr dev) "%s", _("no parent for this device")); } =20 - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); return ret; } =20 @@ -5397,7 +5397,7 @@ testNodeDeviceNumOfCaps(virNodeDevicePtr dev) for (caps =3D def->caps; caps; caps =3D caps->next) ++ncaps; =20 - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); return ncaps; } =20 @@ -5422,13 +5422,13 @@ testNodeDeviceListCaps(virNodeDevicePtr dev, char *= *const names, int maxnames) ncaps++; } =20 - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); return ncaps; =20 error: while (--ncaps >=3D 0) VIR_FREE(names[ncaps]); - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); return -1; } =20 @@ -5459,7 +5459,7 @@ testNodeDeviceMockCreateVport(testDriverPtr driver, goto cleanup; =20 xml =3D virNodeDeviceDefFormat(virNodeDeviceObjGetDef(objcopy)); - virNodeDeviceObjUnlock(objcopy); + virNodeDeviceObjEndAPI(&objcopy); if (!xml) goto cleanup; =20 @@ -5563,8 +5563,7 @@ testNodeDeviceCreateXML(virConnectPtr conn, dev =3D NULL; =20 cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); testDriverUnlock(driver); virNodeDeviceDefFree(def); virObjectUnref(dev); @@ -5597,28 +5596,29 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) * taken, so we have to dup the parent's name and drop the lock * before calling it. We don't need the reference to the object * any more once we have the parent's name. */ - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); =20 /* We do this just for basic validation, but also avoid finding a * vport capable HBA if for some reason our vHBA doesn't exist */ if (virNodeDeviceObjListGetParentHost(driver->devs, def, - EXISTING_DEVICE) < 0) { - obj =3D NULL; + EXISTING_DEVICE) < 0) goto cleanup; - } =20 event =3D virNodeDeviceEventLifecycleNew(dev->name, VIR_NODE_DEVICE_EVENT_DELETED, 0); =20 - virNodeDeviceObjLock(obj); + /* + * + * REVIEW THIS + * + */ virNodeDeviceObjListRemove(driver->devs, obj); - virNodeDeviceObjFree(obj); + virObjectUnref(obj); obj =3D NULL; =20 cleanup: - if (obj) - virNodeDeviceObjUnlock(obj); + virNodeDeviceObjEndAPI(&obj); testObjectEventQueue(driver, event); VIR_FREE(parent_name); VIR_FREE(wwnn); --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list