From nobody Wed May 1 23:54:51 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.zohomail.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 1500559719862143.2741132651205; Thu, 20 Jul 2017 07:08:39 -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 98784C056827; Thu, 20 Jul 2017 14:08:33 +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 69BB282712; Thu, 20 Jul 2017 14:08: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 209411853E31; Thu, 20 Jul 2017 14:08:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6KE8J4Q023829 for ; Thu, 20 Jul 2017 10:08:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 219EE17F23; Thu, 20 Jul 2017 14:08:19 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-46.phx2.redhat.com [10.3.117.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id DA0D317F3A for ; Thu, 20 Jul 2017 14:08:18 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 98784C056827 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.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 98784C056827 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 20 Jul 2017 10:08:12 -0400 Message-Id: <20170720140815.16411-2-jferlan@redhat.com> In-Reply-To: <20170720140815.16411-1-jferlan@redhat.com> References: <20170720140815.16411-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v6 1/4] nodedev: Alter node device deletion logic 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.32]); Thu, 20 Jul 2017 14:08:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Alter the node device deletion logic to make use of the parent field from the obj->def rather than call virNodeDeviceObjListGetParentHost. As it turns out the saved @def won't have parent_wwnn/wwpn or parent_fabric_wwn, so the only logical path would be to call virNodeDeviceObjListGetParentHostByParent which we can accomplish directly via virNodeDeviceObjListFindByName. Signed-off-by: John Ferlan --- src/node_device/node_device_driver.c | 26 +++++++++++++++++++------- src/test/test_driver.c | 26 +++++++++++++------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 0a19908..f56ff34 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -594,8 +594,9 @@ nodeDeviceDestroy(virNodeDevicePtr device) int ret =3D -1; virNodeDeviceObjPtr obj =3D NULL; virNodeDeviceDefPtr def; + char *parent =3D NULL; char *wwnn =3D NULL, *wwpn =3D NULL; - int parent_host =3D -1; + unsigned int parent_host; =20 if (!(obj =3D nodeDeviceObjFindByName(device->name))) return -1; @@ -609,13 +610,23 @@ nodeDeviceDestroy(virNodeDevicePtr device) if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) < 0) goto cleanup; =20 - /* virNodeDeviceGetParentHost will cause the device object's lock - * 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. */ + /* Because we're about to release the lock and thus run into a race + * possibility (however improbable) with a udevAddOneDevice change + * event which would essentially free the existing @def (obj->def) and + * replace it with something new, we need to grab the parent field + * and then find the parent obj in order to manage the vport */ + if (VIR_STRDUP(parent, def->parent) < 0) + goto cleanup; + virNodeDeviceObjEndAPI(&obj); - if ((parent_host =3D virNodeDeviceObjListGetParentHost(driver->devs, d= ef, - EXISTING_DEVICE))= < 0) + + if (!(obj =3D virNodeDeviceObjListFindByName(driver->devs, parent))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot find parent '%s' definition"), parent); + goto cleanup; + } + + if (virSCSIHostGetNumber(parent, &parent_host) < 0) goto cleanup; =20 if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_DELETE) < 0) @@ -626,6 +637,7 @@ nodeDeviceDestroy(virNodeDevicePtr device) cleanup: nodeDeviceUnlock(); virNodeDeviceObjEndAPI(&obj); + VIR_FREE(parent); VIR_FREE(wwnn); VIR_FREE(wwpn); return ret; diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 83ab9cc..076b17a 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5618,8 +5618,9 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) int ret =3D 0; testDriverPtr driver =3D dev->conn->privateData; virNodeDeviceObjPtr obj =3D NULL; + virNodeDeviceObjPtr parentobj =3D NULL; virNodeDeviceDefPtr def; - char *parent_name =3D NULL, *wwnn =3D NULL, *wwpn =3D NULL; + char *wwnn =3D NULL, *wwpn =3D NULL; virObjectEventPtr event =3D NULL; =20 if (!(obj =3D testNodeDeviceObjFindByName(driver, dev->name))) @@ -5629,22 +5630,22 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) =3D=3D -1) goto cleanup; =20 - if (VIR_STRDUP(parent_name, def->parent) < 0) - goto cleanup; - - /* virNodeDeviceGetParentHost will cause the device object's lock to be - * 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. */ + /* Unlike the real code we cannot run into the udevAddOneDevice race + * which would replace obj->def, so no need to save off the parent, + * but do need to drop the @obj lock so that the FindByName code doesn= 't + * deadlock on ourselves */ virObjectUnlock(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) { + /* We do this just for basic validation and throw away the parentobj + * since there's no vport_delete to be run */ + if (!(parentobj =3D virNodeDeviceObjListFindByName(driver->devs, + def->parent))) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("cannot find parent '%s' definition"), def->paren= t); virObjectLock(obj); goto cleanup; } + virNodeDeviceObjEndAPI(&parentobj); =20 event =3D virNodeDeviceEventLifecycleNew(dev->name, VIR_NODE_DEVICE_EVENT_DELETED, @@ -5658,7 +5659,6 @@ testNodeDeviceDestroy(virNodeDevicePtr dev) cleanup: virNodeDeviceObjEndAPI(&obj); testObjectEventQueue(driver, event); - VIR_FREE(parent_name); VIR_FREE(wwnn); VIR_FREE(wwpn); return ret; --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:54:51 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.zohomail.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 1500559721752876.2391919940445; Thu, 20 Jul 2017 07:08:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 043404A71C; Thu, 20 Jul 2017 14:08:34 +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 CF9FA80A45; Thu, 20 Jul 2017 14:08: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 88E814A491; Thu, 20 Jul 2017 14:08:33 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6KE8Jvx023834 for ; Thu, 20 Jul 2017 10:08:19 -0400 Received: by smtp.corp.redhat.com (Postfix) id 81A4A17F23; Thu, 20 Jul 2017 14:08:19 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-46.phx2.redhat.com [10.3.117.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 42CCB6BF6D for ; Thu, 20 Jul 2017 14:08:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 043404A71C 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 043404A71C From: John Ferlan To: libvir-list@redhat.com Date: Thu, 20 Jul 2017 10:08:13 -0400 Message-Id: <20170720140815.16411-3-jferlan@redhat.com> In-Reply-To: <20170720140815.16411-1-jferlan@redhat.com> References: <20170720140815.16411-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v6 2/4] nodedev: Remove @create from virNodeDeviceObjListGetParentHost 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.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 20 Jul 2017 14:08:34 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" The only callers to this function are from CreateXML paths now, so let's just remove the unnecessary parameter. Signed-off-by: John Ferlan --- src/conf/virnodedeviceobj.c | 5 ++--- src/conf/virnodedeviceobj.h | 3 +-- src/node_device/node_device_driver.c | 3 +-- src/test/test_driver.c | 2 +- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 4c5ee8c..035a56d 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -545,8 +545,7 @@ virNodeDeviceObjListFindVportParentHost(virNodeDeviceOb= jListPtr devs) =20 int virNodeDeviceObjListGetParentHost(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def, - int create) + virNodeDeviceDefPtr def) { int parent_host =3D -1; =20 @@ -561,7 +560,7 @@ virNodeDeviceObjListGetParentHost(virNodeDeviceObjListP= tr devs, parent_host =3D virNodeDeviceObjListGetParentHostByFabricWWN(devs, def->name, def->parent_fabri= c_wwn); - } else if (create =3D=3D CREATE_DEVICE) { + } else { /* Try to find a vport capable scsi_host when no parent supplied */ parent_host =3D virNodeDeviceObjListFindVportParentHost(devs); } diff --git a/src/conf/virnodedeviceobj.h b/src/conf/virnodedeviceobj.h index 788fb66..06f2e9e 100644 --- a/src/conf/virnodedeviceobj.h +++ b/src/conf/virnodedeviceobj.h @@ -75,8 +75,7 @@ virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs, =20 int virNodeDeviceObjListGetParentHost(virNodeDeviceObjListPtr devs, - virNodeDeviceDefPtr def, - int create); + virNodeDeviceDefPtr def); =20 virNodeDeviceObjListPtr virNodeDeviceObjListNew(void); diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index f56ff34..920d877 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -563,8 +563,7 @@ nodeDeviceCreateXML(virConnectPtr conn, if (virNodeDeviceGetWWNs(def, &wwnn, &wwpn) =3D=3D -1) goto cleanup; =20 - if ((parent_host =3D virNodeDeviceObjListGetParentHost(driver->devs, d= ef, - CREATE_DEVICE)) <= 0) + if ((parent_host =3D virNodeDeviceObjListGetParentHost(driver->devs, d= ef)) < 0) goto cleanup; =20 if (virVHBAManageVport(parent_host, wwpn, wwnn, VPORT_CREATE) < 0) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 076b17a..bb2e7ba 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5580,7 +5580,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 (virNodeDeviceObjListGetParentHost(driver->devs, def, CREATE_DEVICE= ) < 0) + if (virNodeDeviceObjListGetParentHost(driver->devs, def) < 0) goto cleanup; =20 /* In the real code, we'd call virVHBAManageVport followed by --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:54:51 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.zohomail.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 1500559724178498.84112299017784; Thu, 20 Jul 2017 07:08:44 -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 343282C153D; Thu, 20 Jul 2017 14:08: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 0C65018232; Thu, 20 Jul 2017 14:08: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 B12A441F76; Thu, 20 Jul 2017 14:08:37 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6KE8Jrq023839 for ; Thu, 20 Jul 2017 10:08:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id EFA5517F3A; Thu, 20 Jul 2017 14:08:19 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-46.phx2.redhat.com [10.3.117.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id A13B917F23 for ; Thu, 20 Jul 2017 14:08:19 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 343282C153D Authentication-Results: ext-mx10.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx10.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 343282C153D From: John Ferlan To: libvir-list@redhat.com Date: Thu, 20 Jul 2017 10:08:14 -0400 Message-Id: <20170720140815.16411-4-jferlan@redhat.com> In-Reply-To: <20170720140815.16411-1-jferlan@redhat.com> References: <20170720140815.16411-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v6 3/4] nodedev: Convert virNodeDeviceObjListPtr to use hash tables 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.39]); Thu, 20 Jul 2017 14:08:38 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Rather than use a forward linked list of elements, it'll be much more efficient to use a hash table to reference the elements by unique name and to perform hash searches. This patch does all the heavy lifting of converting the list object to use a self locking list that contains the hash table. Each of the FindBy functions that do not involve finding the object by it's key (name) is converted to use virHashSearch in order to find the specific object. When searching for the key (name), it's possible to use virHashLookup. For any of the list perusal functions that are required to evaluate each object, the virHashForEach function is used. Signed-off-by: John Ferlan --- src/conf/virnodedeviceobj.c | 575 ++++++++++++++++++++++++++++++----------= ---- 1 file changed, 400 insertions(+), 175 deletions(-) diff --git a/src/conf/virnodedeviceobj.c b/src/conf/virnodedeviceobj.c index 035a56d..58481e7 100644 --- a/src/conf/virnodedeviceobj.c +++ b/src/conf/virnodedeviceobj.c @@ -25,6 +25,7 @@ #include "viralloc.h" #include "virnodedeviceobj.h" #include "virerror.h" +#include "virhash.h" #include "virlog.h" #include "virstring.h" =20 @@ -39,13 +40,19 @@ struct _virNodeDeviceObj { }; =20 struct _virNodeDeviceObjList { - size_t count; - virNodeDeviceObjPtr *objs; + virObjectLockable parent; + + /* name string -> virNodeDeviceObj mapping + * for O(1), lockless lookup-by-uuid */ + virHashTable *objs; + }; =20 =20 static virClassPtr virNodeDeviceObjClass; +static virClassPtr virNodeDeviceObjListClass; static void virNodeDeviceObjDispose(void *opaque); +static void virNodeDeviceObjListDispose(void *opaque); =20 static int virNodeDeviceObjOnceInit(void) @@ -56,6 +63,12 @@ virNodeDeviceObjOnceInit(void) virNodeDeviceObjDispose))) return -1; =20 + if (!(virNodeDeviceObjListClass =3D virClassNew(virClassForObjectLocka= ble(), + "virNodeDeviceObjList", + sizeof(virNodeDeviceObjL= ist), + virNodeDeviceObjListDisp= ose))) + return -1; + return 0; } =20 @@ -211,26 +224,49 @@ virNodeDeviceFindVPORTCapDef(const virNodeDeviceObj *= obj) } =20 =20 +static int +virNodeDeviceObjListFindBySysfsPathCallback(const void *payload, + const void *name ATTRIBUTE_UNU= SED, + const void *opaque) +{ + virNodeDeviceObjPtr obj =3D (virNodeDeviceObjPtr) payload; + virNodeDeviceDefPtr def; + const char *sysfs_path =3D opaque; + int want =3D 0; + + virObjectLock(obj); + def =3D obj->def; + if (STREQ_NULLABLE(def->sysfs_path, sysfs_path)) + want =3D 1; + virObjectUnlock(obj); + return want; +} + + virNodeDeviceObjPtr virNodeDeviceObjListFindBySysfsPath(virNodeDeviceObjListPtr devs, const char *sysfs_path) { - size_t i; + virNodeDeviceObjPtr obj; =20 - for (i =3D 0; i < devs->count; i++) { - virNodeDeviceObjPtr obj =3D devs->objs[i]; - virNodeDeviceDefPtr def; + virObjectLock(devs); + obj =3D virHashSearch(devs->objs, virNodeDeviceObjListFindBySysfsPathC= allback, + (void *)sysfs_path, NULL); + virObjectRef(obj); + virObjectUnlock(devs); =20 + if (obj) virObjectLock(obj); - def =3D obj->def; - if ((def->sysfs_path !=3D NULL) && - (STREQ(def->sysfs_path, sysfs_path))) { - return virObjectRef(obj); - } - virObjectUnlock(obj); - } =20 - return NULL; + return obj; +} + + +static virNodeDeviceObjPtr +virNodeDeviceObjListFindByNameLocked(virNodeDeviceObjListPtr devs, + const char *name) +{ + return virObjectRef(virHashLookup(devs->objs, name)); } =20 =20 @@ -238,20 +274,42 @@ virNodeDeviceObjPtr virNodeDeviceObjListFindByName(virNodeDeviceObjListPtr devs, const char *name) { - size_t i; - - for (i =3D 0; i < devs->count; i++) { - virNodeDeviceObjPtr obj =3D devs->objs[i]; - virNodeDeviceDefPtr def; + virNodeDeviceObjPtr obj; =20 + virObjectLock(devs); + obj =3D virNodeDeviceObjListFindByNameLocked(devs, name); + virObjectUnlock(devs); + if (obj) virObjectLock(obj); - def =3D obj->def; - if (STREQ(def->name, name)) - return virObjectRef(obj); - virObjectUnlock(obj); - } =20 - return NULL; + return obj; +} + + +struct virNodeDeviceObjListFindByWWNsData { + const char *parent_wwnn; + const char *parent_wwpn; +}; + +static int +virNodeDeviceObjListFindByWWNsCallback(const void *payload, + const void *name ATTRIBUTE_UNUSED, + const void *opaque) +{ + virNodeDeviceObjPtr obj =3D (virNodeDeviceObjPtr) payload; + struct virNodeDeviceObjListFindByWWNsData *data =3D + (struct virNodeDeviceObjListFindByWWNsData *) opaque; + virNodeDevCapsDefPtr cap; + int want =3D 0; + + virObjectLock(obj); + if ((cap =3D virNodeDeviceFindFCCapDef(obj)) && + STREQ_NULLABLE(cap->data.scsi_host.wwnn, data->parent_wwnn) && + STREQ_NULLABLE(cap->data.scsi_host.wwpn, data->parent_wwpn) && + virNodeDeviceFindVPORTCapDef(obj)) + want =3D 1; + virObjectUnlock(obj); + return want; } =20 =20 @@ -260,22 +318,40 @@ virNodeDeviceObjListFindByWWNs(virNodeDeviceObjListPt= r devs, const char *parent_wwnn, const char *parent_wwpn) { - size_t i; + virNodeDeviceObjPtr obj; + struct virNodeDeviceObjListFindByWWNsData data =3D { + .parent_wwnn =3D parent_wwnn, .parent_wwpn =3D parent_wwpn }; =20 - for (i =3D 0; i < devs->count; i++) { - virNodeDeviceObjPtr obj =3D devs->objs[i]; - virNodeDevCapsDefPtr cap; + virObjectLock(devs); + obj =3D virHashSearch(devs->objs, virNodeDeviceObjListFindByWWNsCallba= ck, + &data, NULL); + virObjectRef(obj); + virObjectUnlock(devs); =20 + if (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 virObjectRef(obj); - virObjectUnlock(obj); - } =20 - return NULL; + return obj; +} + + +static int +virNodeDeviceObjListFindByFabricWWNCallback(const void *payload, + const void *name ATTRIBUTE_UNU= SED, + const void *opaque) +{ + virNodeDeviceObjPtr obj =3D (virNodeDeviceObjPtr) payload; + const char *matchstr =3D opaque; + virNodeDevCapsDefPtr cap; + int want =3D 0; + + virObjectLock(obj); + if ((cap =3D virNodeDeviceFindFCCapDef(obj)) && + STREQ_NULLABLE(cap->data.scsi_host.fabric_wwn, matchstr) && + virNodeDeviceFindVPORTCapDef(obj)) + want =3D 1; + virObjectUnlock(obj); + return want; } =20 =20 @@ -283,21 +359,35 @@ static virNodeDeviceObjPtr virNodeDeviceObjListFindByFabricWWN(virNodeDeviceObjListPtr devs, const char *parent_fabric_wwn) { - size_t i; + virNodeDeviceObjPtr obj; =20 - for (i =3D 0; i < devs->count; i++) { - virNodeDeviceObjPtr obj =3D devs->objs[i]; - virNodeDevCapsDefPtr cap; + virObjectLock(devs); + obj =3D virHashSearch(devs->objs, virNodeDeviceObjListFindByFabricWWNC= allback, + (void *)parent_fabric_wwn, NULL); + virObjectRef(obj); + virObjectUnlock(devs); =20 + if (obj) virObjectLock(obj); - if ((cap =3D virNodeDeviceFindFCCapDef(obj)) && - STREQ_NULLABLE(cap->data.scsi_host.fabric_wwn, parent_fabric_w= wn) && - virNodeDeviceFindVPORTCapDef(obj)) - return virObjectRef(obj); - virObjectUnlock(obj); - } =20 - return NULL; + return obj; +} + + +static int +virNodeDeviceObjListFindByCapCallback(const void *payload, + const void *name ATTRIBUTE_UNUSED, + const void *opaque) +{ + virNodeDeviceObjPtr obj =3D (virNodeDeviceObjPtr) payload; + const char *matchstr =3D opaque; + int want =3D 0; + + virObjectLock(obj); + if (virNodeDeviceObjHasCap(obj, matchstr)) + want =3D 1; + virObjectUnlock(obj); + return want; } =20 =20 @@ -305,18 +395,59 @@ static virNodeDeviceObjPtr virNodeDeviceObjListFindByCap(virNodeDeviceObjListPtr devs, const char *cap) { - size_t i; + virNodeDeviceObjPtr obj; =20 - for (i =3D 0; i < devs->count; i++) { - virNodeDeviceObjPtr obj =3D devs->objs[i]; + virObjectLock(devs); + obj =3D virHashSearch(devs->objs, virNodeDeviceObjListFindByCapCallbac= k, + (void *)cap, NULL); + virObjectRef(obj); + virObjectUnlock(devs); =20 + if (obj) virObjectLock(obj); - if (virNodeDeviceObjHasCap(obj, cap)) - return virObjectRef(obj); - virObjectUnlock(obj); - } =20 - return NULL; + return obj; +} + + +struct virNodeDeviceObjListFindSCSIHostByWWNsData { + const char *wwnn; + const char *wwpn; +}; + +static int +virNodeDeviceObjListFindSCSIHostByWWNsCallback(const void *payload, + const void *name ATTRIBUTE_= UNUSED, + const void *opaque) +{ + virNodeDeviceObjPtr obj =3D (virNodeDeviceObjPtr) payload; + virNodeDeviceDefPtr def; + struct virNodeDeviceObjListFindSCSIHostByWWNsData *data =3D + (struct virNodeDeviceObjListFindSCSIHostByWWNsData *) opaque; + virNodeDevCapsDefPtr cap; + int want =3D 0; + + virObjectLock(obj); + def =3D obj->def; + cap =3D 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, data->wwnn) && + STREQ(cap->data.scsi_host.wwpn, data->wwpn)) { + want =3D 1; + break; + } + } + } + cap =3D cap->next; + } + + virObjectUnlock(obj); + return want; } =20 =20 @@ -325,31 +456,30 @@ virNodeDeviceObjListFindSCSIHostByWWNs(virNodeDeviceO= bjListPtr devs, const char *wwnn, const char *wwpn) { - size_t i; + virNodeDeviceObjPtr obj; + struct virNodeDeviceObjListFindSCSIHostByWWNsData data =3D { + .wwnn =3D wwnn, .wwpn =3D wwpn }; =20 - for (i =3D 0; i < devs->count; i++) { - virNodeDeviceObjPtr obj =3D devs->objs[i]; - virNodeDevCapsDefPtr cap; + virObjectLock(devs); + obj =3D virHashSearch(devs->objs, + virNodeDeviceObjListFindSCSIHostByWWNsCallback, + &data, NULL); + virObjectRef(obj); + virObjectUnlock(devs); =20 + if (obj) virObjectLock(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 virObjectRef(obj); - } - } - cap =3D cap->next; - } - virObjectUnlock(obj); - } =20 - return NULL; + return obj; +} + + +static void +virNodeDeviceObjListDispose(void *obj) +{ + virNodeDeviceObjListPtr devs =3D obj; + + virHashFree(devs->objs); } =20 =20 @@ -358,8 +488,17 @@ virNodeDeviceObjListNew(void) { virNodeDeviceObjListPtr devs; =20 - if (VIR_ALLOC(devs) < 0) + if (virNodeDeviceObjInitialize() < 0) return NULL; + + if (!(devs =3D virObjectLockableNew(virNodeDeviceObjListClass))) + return NULL; + + if (!(devs->objs =3D virHashCreate(50, virObjectFreeHashData))) { + virObjectUnref(devs); + return NULL; + } + return devs; } =20 @@ -367,11 +506,7 @@ virNodeDeviceObjListNew(void) void virNodeDeviceObjListFree(virNodeDeviceObjListPtr devs) { - size_t i; - for (i =3D 0; i < devs->count; i++) - virObjectUnref(devs->objs[i]); - VIR_FREE(devs->objs); - VIR_FREE(devs); + virObjectUnref(devs); } =20 =20 @@ -381,22 +516,28 @@ virNodeDeviceObjListAssignDef(virNodeDeviceObjListPtr= devs, { virNodeDeviceObjPtr obj; =20 - if ((obj =3D virNodeDeviceObjListFindByName(devs, def->name))) { + virObjectLock(devs); + + if ((obj =3D virNodeDeviceObjListFindByNameLocked(devs, def->name))) { + virObjectLock(obj); virNodeDeviceDefFree(obj->def); obj->def =3D def; - return obj; - } + } else { + if (!(obj =3D virNodeDeviceObjNew())) + goto cleanup; =20 - if (!(obj =3D virNodeDeviceObjNew())) - return NULL; + if (virHashAddEntry(devs->objs, def->name, obj) < 0) { + virNodeDeviceObjEndAPI(&obj); + goto cleanup; + } =20 - if (VIR_APPEND_ELEMENT_COPY(devs->objs, devs->count, obj) < 0) { - virNodeDeviceObjEndAPI(&obj); - return NULL; + obj->def =3D def; + virObjectRef(obj); } - obj->def =3D def; =20 - return virObjectRef(obj); + cleanup: + virObjectUnlock(devs); + return obj; } =20 =20 @@ -404,21 +545,20 @@ void virNodeDeviceObjListRemove(virNodeDeviceObjListPtr devs, virNodeDeviceObjPtr obj) { - size_t i; - - virObjectUnlock(obj); + virNodeDeviceDefPtr def; =20 - for (i =3D 0; i < devs->count; i++) { - virObjectLock(devs->objs[i]); - if (devs->objs[i] =3D=3D obj) { - virObjectUnlock(devs->objs[i]); - virObjectUnref(devs->objs[i]); + if (!obj) + return; + def =3D obj->def; =20 - VIR_DELETE_ELEMENT(devs->objs, i, devs->count); - break; - } - virObjectUnlock(devs->objs[i]); - } + virObjectRef(obj); + virObjectUnlock(obj); + virObjectLock(devs); + virObjectLock(obj); + virHashRemoveEntry(devs->objs, def->name); + virObjectUnlock(obj); + virObjectUnref(obj); + virObjectUnlock(devs); } =20 =20 @@ -619,25 +759,89 @@ virNodeDeviceCapMatch(virNodeDeviceObjPtr obj, } =20 =20 +struct virNodeDeviceCountData { + virConnectPtr conn; + virNodeDeviceObjListFilter aclfilter; + const char *matchstr; + int count; +}; + +static int +virNodeDeviceObjListNumOfDevicesCallback(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *opaque) +{ + virNodeDeviceObjPtr obj =3D payload; + virNodeDeviceDefPtr def; + struct virNodeDeviceCountData *data =3D opaque; + virNodeDeviceObjListFilter aclfilter =3D data->aclfilter; + + virObjectLock(obj); + def =3D obj->def; + if ((!aclfilter || aclfilter(data->conn, def)) && + (!data->matchstr || virNodeDeviceObjHasCap(obj, data->matchstr))) + data->count++; + + virObjectUnlock(obj); + return 0; +} + + int virNodeDeviceObjListNumOfDevices(virNodeDeviceObjListPtr devs, virConnectPtr conn, const char *cap, virNodeDeviceObjListFilter aclfilter) { - size_t i; - int ndevs =3D 0; + struct virNodeDeviceCountData data =3D { + .conn =3D conn, .aclfilter =3D aclfilter, .matchstr =3D cap, .coun= t =3D 0 }; =20 - for (i =3D 0; i < devs->count; i++) { - virNodeDeviceObjPtr obj =3D devs->objs[i]; - virObjectLock(obj); - if ((!aclfilter || aclfilter(conn, obj->def)) && - (!cap || virNodeDeviceObjHasCap(obj, cap))) - ++ndevs; - virObjectUnlock(obj); - } + virObjectLock(devs); + virHashForEach(devs->objs, virNodeDeviceObjListNumOfDevicesCallback, &= data); + virObjectUnlock(devs); + + return data.count; +} + + +struct virNodeDeviceGetNamesData { + virConnectPtr conn; + virNodeDeviceObjListFilter aclfilter; + const char *matchstr; + int nnames; + char **names; + int maxnames; + bool error; +}; + +static int +virNodeDeviceObjListGetNamesCallback(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *opaque) +{ + virNodeDeviceObjPtr obj =3D payload; + virNodeDeviceDefPtr def; + struct virNodeDeviceGetNamesData *data =3D opaque; + virNodeDeviceObjListFilter aclfilter =3D data->aclfilter; + + if (data->error) + return 0; =20 - return ndevs; + virObjectLock(obj); + def =3D obj->def; + + if ((!aclfilter || aclfilter(data->conn, def)) && + (!data->matchstr || virNodeDeviceObjHasCap(obj, data->matchstr))) { + if (VIR_STRDUP(data->names[data->nnames], def->name) < 0) { + data->error =3D true; + goto cleanup; + } + data->nnames++; + } + + cleanup: + virObjectUnlock(obj); + return 0; } =20 =20 @@ -649,28 +853,22 @@ virNodeDeviceObjListGetNames(virNodeDeviceObjListPtr = devs, char **const names, int maxnames) { - int nnames =3D 0; - size_t i; + struct virNodeDeviceGetNamesData data =3D { + .conn =3D conn, .aclfilter =3D aclfilter, .matchstr =3D cap, .name= s =3D names, + .nnames =3D 0, .maxnames =3D maxnames, .error =3D false }; =20 - for (i =3D 0; i < devs->count && nnames < maxnames; i++) { - virNodeDeviceObjPtr obj =3D devs->objs[i]; - virObjectLock(obj); - if ((!aclfilter || aclfilter(conn, obj->def)) && - (!cap || virNodeDeviceObjHasCap(obj, cap))) { - if (VIR_STRDUP(names[nnames], obj->def->name) < 0) { - virObjectUnlock(obj); - goto failure; - } - nnames++; - } - virObjectUnlock(obj); - } + virObjectLock(devs); + virHashForEach(devs->objs, virNodeDeviceObjListGetNamesCallback, &data= ); + virObjectUnlock(devs); + + if (data.error) + goto error; =20 - return nnames; + return data.nnames; =20 - failure: - while (--nnames >=3D 0) - VIR_FREE(names[nnames]); + error: + while (--data.nnames) + VIR_FREE(data.names[data.nnames]); return -1; } =20 @@ -707,6 +905,51 @@ virNodeDeviceMatch(virNodeDeviceObjPtr obj, #undef MATCH =20 =20 +struct virNodeDeviceObjListExportData { + virConnectPtr conn; + virNodeDeviceObjListFilter aclfilter; + unsigned int flags; + virNodeDevicePtr *devices; + int ndevices; + bool error; +}; + +static int +virNodeDeviceObjListExportCallback(void *payload, + const void *name ATTRIBUTE_UNUSED, + void *opaque) +{ + virNodeDeviceObjPtr obj =3D payload; + virNodeDeviceDefPtr def; + struct virNodeDeviceObjListExportData *data =3D opaque; + virNodeDevicePtr device =3D NULL; + + if (data->error) + return 0; + + virObjectLock(obj); + def =3D obj->def; + + if ((!data->aclfilter || data->aclfilter(data->conn, def)) && + virNodeDeviceMatch(obj, data->flags)) { + if (data->devices) { + if (!(device =3D virGetNodeDevice(data->conn, def->name)) || + VIR_STRDUP(device->parent, def->parent) < 0) { + virObjectUnref(device); + data->error =3D true; + goto cleanup; + } + data->devices[data->ndevices] =3D device; + } + data->ndevices++; + } + + cleanup: + virObjectUnlock(obj); + return 0; +} + + int virNodeDeviceObjListExport(virConnectPtr conn, virNodeDeviceObjListPtr devs, @@ -714,49 +957,31 @@ virNodeDeviceObjListExport(virConnectPtr conn, virNodeDeviceObjListFilter aclfilter, unsigned int flags) { - virNodeDevicePtr *tmp_devices =3D NULL; - virNodeDevicePtr device =3D NULL; - int ndevices =3D 0; - int ret =3D -1; - size_t i; + struct virNodeDeviceObjListExportData data =3D { + .conn =3D conn, .aclfilter =3D aclfilter, .flags =3D flags, + .devices =3D NULL, .ndevices =3D 0, .error =3D false }; + + virObjectLock(devs); + if (devices && + VIR_ALLOC_N(data.devices, virHashSize(devs->objs) + 1) < 0) { + virObjectUnlock(devs); + return -1; + } =20 - if (devices && VIR_ALLOC_N(tmp_devices, devs->count + 1) < 0) - goto cleanup; + virHashForEach(devs->objs, virNodeDeviceObjListExportCallback, &data); + virObjectUnlock(devs); =20 - for (i =3D 0; i < devs->count; i++) { - virNodeDeviceObjPtr obj =3D devs->objs[i]; - 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); - virObjectUnlock(obj); - goto cleanup; - } - tmp_devices[ndevices] =3D device; - } - ndevices++; - } - virObjectUnlock(obj); - } + if (data.error) + goto cleanup; =20 - if (tmp_devices) { - /* trim the array to the final size */ - ignore_value(VIR_REALLOC_N(tmp_devices, ndevices + 1)); - *devices =3D tmp_devices; - tmp_devices =3D NULL; - } + if (data.devices) { + ignore_value(VIR_REALLOC_N(data.devices, data.ndevices + 1)); + *devices =3D data.devices; + } =20 - ret =3D ndevices; + return data.ndevices; =20 cleanup: - if (tmp_devices) { - for (i =3D 0; i < ndevices; i++) - virObjectUnref(tmp_devices[i]); - } - - VIR_FREE(tmp_devices); - return ret; + virObjectListFree(data.devices); + return -1; } --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list From nobody Wed May 1 23:54:51 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.zohomail.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 1500559985354245.41565713900434; Thu, 20 Jul 2017 07:13:05 -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 6042BC005748; Thu, 20 Jul 2017 14:13:00 +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 9ECDD7FEB9; Thu, 20 Jul 2017 14:12:59 +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 1C0FC1800C8B; Thu, 20 Jul 2017 14:12:57 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id v6KE8KeC023844 for ; Thu, 20 Jul 2017 10:08:20 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5E1DC17F23; Thu, 20 Jul 2017 14:08:20 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-117-46.phx2.redhat.com [10.3.117.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 251696BF6D for ; Thu, 20 Jul 2017 14:08:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 6042BC005748 Authentication-Results: ext-mx08.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx08.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 6042BC005748 From: John Ferlan To: libvir-list@redhat.com Date: Thu, 20 Jul 2017 10:08:15 -0400 Message-Id: <20170720140815.16411-5-jferlan@redhat.com> In-Reply-To: <20170720140815.16411-1-jferlan@redhat.com> References: <20170720140815.16411-1-jferlan@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v6 4/4] nodedev: Remove driver locks around object list mgmt code 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.32]); Thu, 20 Jul 2017 14:13:01 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Since virnodedeviceobj now has a self-lockable hash table, there's no need to lock the table from the driver for processing. Thus remove the locks from the driver for NodeDeviceObjList mgmt. This includes the test driver as well. Signed-off-by: John Ferlan --- src/node_device/node_device_driver.c | 61 +++++++-------------------------= ---- src/node_device/node_device_hal.c | 16 ++-------- src/node_device/node_device_udev.c | 13 +++----- src/test/test_driver.c | 25 +++------------ 4 files changed, 22 insertions(+), 93 deletions(-) diff --git a/src/node_device/node_device_driver.c b/src/node_device/node_de= vice_driver.c index 920d877..facfeb6 100644 --- a/src/node_device/node_device_driver.c +++ b/src/node_device/node_device_driver.c @@ -174,19 +174,13 @@ nodeNumOfDevices(virConnectPtr conn, const char *cap, unsigned int flags) { - int ndevs =3D 0; - if (virNodeNumOfDevicesEnsureACL(conn) < 0) return -1; =20 virCheckFlags(0, -1); =20 - nodeDeviceLock(); - ndevs =3D virNodeDeviceObjListNumOfDevices(driver->devs, conn, cap, - virNodeNumOfDevicesCheckACL); - nodeDeviceUnlock(); - - return ndevs; + return virNodeDeviceObjListNumOfDevices(driver->devs, conn, cap, + virNodeNumOfDevicesCheckACL); } =20 =20 @@ -197,20 +191,14 @@ nodeListDevices(virConnectPtr conn, int maxnames, unsigned int flags) { - int nnames; - if (virNodeListDevicesEnsureACL(conn) < 0) return -1; =20 virCheckFlags(0, -1); =20 - nodeDeviceLock(); - nnames =3D virNodeDeviceObjListGetNames(driver->devs, conn, - virNodeListDevicesCheckACL, - cap, names, maxnames); - nodeDeviceUnlock(); - - return nnames; + return virNodeDeviceObjListGetNames(driver->devs, conn, + virNodeListDevicesCheckACL, + cap, names, maxnames); } =20 =20 @@ -219,19 +207,14 @@ nodeConnectListAllNodeDevices(virConnectPtr conn, virNodeDevicePtr **devices, unsigned int flags) { - int ret =3D -1; - virCheckFlags(VIR_CONNECT_LIST_NODE_DEVICES_FILTERS_CAP, -1); =20 if (virConnectListAllNodeDevicesEnsureACL(conn) < 0) return -1; =20 - nodeDeviceLock(); - ret =3D virNodeDeviceObjListExport(conn, driver->devs, devices, - virConnectListAllNodeDevicesCheckACL, - flags); - nodeDeviceUnlock(); - return ret; + return virNodeDeviceObjListExport(conn, driver->devs, devices, + virConnectListAllNodeDevicesCheckACL, + flags); } =20 =20 @@ -240,11 +223,7 @@ nodeDeviceObjFindByName(const char *name) { virNodeDeviceObjPtr obj; =20 - nodeDeviceLock(); - obj =3D virNodeDeviceObjListFindByName(driver->devs, name); - nodeDeviceUnlock(); - - if (!obj) { + if (!(obj =3D virNodeDeviceObjListFindByName(driver->devs, name))) { virReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), name); @@ -294,11 +273,8 @@ nodeDeviceLookupSCSIHostByWWN(virConnectPtr conn, =20 virCheckFlags(0, NULL); =20 - nodeDeviceLock(); - obj =3D virNodeDeviceObjListFindSCSIHostByWWNs(driver->devs, wwnn, wwp= n); - nodeDeviceUnlock(); - - if (!obj) + if (!(obj =3D virNodeDeviceObjListFindSCSIHostByWWNs(driver->devs, + wwnn, wwpn))) return NULL; =20 def =3D virNodeDeviceObjGetDef(obj); @@ -509,13 +485,6 @@ nodeDeviceFindNewDevice(virConnectPtr conn, 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 - * must release it in order to allow the device to be created. - * We're not doing anything with the driver pointer at this point, - * so it's safe to release it, assuming that the pointer itself - * doesn't become invalid. */ - nodeDeviceUnlock(); - nodeDeviceGetTime(&start); =20 while ((now - start) < LINUX_NEW_DEVICE_WAIT_TIME) { @@ -532,8 +501,6 @@ nodeDeviceFindNewDevice(virConnectPtr conn, break; } =20 - nodeDeviceLock(); - return device; } =20 @@ -552,8 +519,6 @@ nodeDeviceCreateXML(virConnectPtr conn, virCheckFlags(0, NULL); virt_type =3D virConnectGetType(conn); =20 - nodeDeviceLock(); - if (!(def =3D virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, virt= _type))) goto cleanup; =20 @@ -579,7 +544,6 @@ nodeDeviceCreateXML(virConnectPtr conn, "wwnn '%s' and wwpn '%s'"), def->name, wwnn, wwpn); cleanup: - nodeDeviceUnlock(); virNodeDeviceDefFree(def); VIR_FREE(wwnn); VIR_FREE(wwpn); @@ -601,8 +565,6 @@ nodeDeviceDestroy(virNodeDevicePtr device) return -1; def =3D virNodeDeviceObjGetDef(obj); =20 - nodeDeviceLock(); - if (virNodeDeviceDestroyEnsureACL(device->conn, def) < 0) goto cleanup; =20 @@ -634,7 +596,6 @@ nodeDeviceDestroy(virNodeDevicePtr device) ret =3D 0; =20 cleanup: - nodeDeviceUnlock(); virNodeDeviceObjEndAPI(&obj); VIR_FREE(parent); VIR_FREE(wwnn); diff --git a/src/node_device/node_device_hal.c b/src/node_device/node_devic= e_hal.c index 7f246f0..c19e327 100644 --- a/src/node_device/node_device_hal.c +++ b/src/node_device/node_device_hal.c @@ -508,20 +508,15 @@ dev_refresh(const char *udi) const char *name =3D hal_name(udi); virNodeDeviceObjPtr obj; =20 - nodeDeviceLock(); if ((obj =3D virNodeDeviceObjListFindByName(driver->devs, name))) { /* Simply "rediscover" device -- incrementally handling changes * to sub-capabilities (like net.80203) is nasty ... so avoid it. */ virNodeDeviceObjListRemove(driver->devs, obj); - } else { - VIR_DEBUG("no device named %s", name); - } - nodeDeviceUnlock(); - - if (obj) { virObjectUnref(obj); dev_create(udi); + } else { + VIR_DEBUG("no device named %s", name); } } =20 @@ -541,14 +536,12 @@ device_removed(LibHalContext *ctx ATTRIBUTE_UNUSED, const char *name =3D hal_name(udi); virNodeDeviceObjPtr obj; =20 - nodeDeviceLock(); obj =3D virNodeDeviceObjListFindByName(driver->devs, name); VIR_DEBUG("%s", name); if (obj) virNodeDeviceObjListRemove(driver->devs, obj); else VIR_DEBUG("no device named %s", name); - nodeDeviceUnlock(); virObjectUnref(obj); } =20 @@ -561,11 +554,8 @@ device_cap_added(LibHalContext *ctx, virNodeDeviceObjPtr obj; virNodeDeviceDefPtr def; =20 - nodeDeviceLock(); - obj =3D virNodeDeviceObjListFindByName(driver->devs, name); - nodeDeviceUnlock(); VIR_DEBUG("%s %s", cap, name); - if (obj) { + if ((obj =3D virNodeDeviceObjListFindByName(driver->devs, name))) { def =3D virNodeDeviceObjGetDef(obj); (void)gather_capability(ctx, udi, cap, &def->caps); virNodeDeviceObjEndAPI(&obj); diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index 1b10c16..434efd7 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -1607,7 +1607,6 @@ udevEventHandleCallback(int watch ATTRIBUTE_UNUSED, const char *action =3D NULL; int udev_fd =3D -1; =20 - nodeDeviceLock(); udev_fd =3D udev_monitor_get_fd(udev_monitor); if (fd !=3D udev_fd) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -1639,7 +1638,6 @@ udevEventHandleCallback(int watch ATTRIBUTE_UNUSED, =20 cleanup: udev_device_unref(device); - nodeDeviceUnlock(); return; } =20 @@ -1767,7 +1765,6 @@ nodeStateInitialize(bool privileged, { udevPrivate *priv =3D NULL; struct udev *udev =3D NULL; - int ret =3D -1; =20 if (VIR_ALLOC(priv) < 0) return -1; @@ -1847,18 +1844,16 @@ nodeStateInitialize(bool privileged, goto cleanup; =20 /* Populate with known devices */ - + nodeDeviceUnlock(); if (udevEnumerateDevices(udev) !=3D 0) goto cleanup; =20 - ret =3D 0; + return 0; =20 cleanup: nodeDeviceUnlock(); - - if (ret =3D=3D -1) - nodeStateCleanup(); - return ret; + nodeStateCleanup(); + return -1; } =20 =20 diff --git a/src/test/test_driver.c b/src/test/test_driver.c index bb2e7ba..4702690 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5303,11 +5303,7 @@ testNodeDeviceObjFindByName(testDriverPtr driver, { virNodeDeviceObjPtr obj; =20 - testDriverLock(driver); - obj =3D virNodeDeviceObjListFindByName(driver->devs, name); - testDriverUnlock(driver); - - if (!obj) + if (!(obj =3D virNodeDeviceObjListFindByName(driver->devs, name))) virReportError(VIR_ERR_NO_NODE_DEVICE, _("no node device with matching name '%s'"), name); @@ -5322,15 +5318,10 @@ testNodeNumOfDevices(virConnectPtr conn, unsigned int flags) { testDriverPtr driver =3D conn->privateData; - int ndevs =3D 0; =20 virCheckFlags(0, -1); =20 - testDriverLock(driver); - ndevs =3D virNodeDeviceObjListNumOfDevices(driver->devs, conn, cap, NU= LL); - testDriverUnlock(driver); - - return ndevs; + return virNodeDeviceObjListNumOfDevices(driver->devs, conn, cap, NULL); } =20 =20 @@ -5342,16 +5333,11 @@ testNodeListDevices(virConnectPtr conn, unsigned int flags) { testDriverPtr driver =3D conn->privateData; - int nnames =3D 0; =20 virCheckFlags(0, -1); =20 - testDriverLock(driver); - nnames =3D virNodeDeviceObjListGetNames(driver->devs, conn, NULL, - cap, names, maxnames); - testDriverUnlock(driver); - - return nnames; + return virNodeDeviceObjListGetNames(driver->devs, conn, NULL, + cap, names, maxnames); } =20 =20 @@ -5566,8 +5552,6 @@ testNodeDeviceCreateXML(virConnectPtr conn, =20 virCheckFlags(0, NULL); =20 - testDriverLock(driver); - if (!(def =3D virNodeDeviceDefParseString(xmlDesc, CREATE_DEVICE, NULL= ))) goto cleanup; =20 @@ -5604,7 +5588,6 @@ testNodeDeviceCreateXML(virConnectPtr conn, =20 cleanup: virNodeDeviceObjEndAPI(&obj); - testDriverUnlock(driver); virNodeDeviceDefFree(def); virObjectUnref(dev); VIR_FREE(wwnn); --=20 2.9.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list