changeset 6722:f307a66e01cd

6674553 getpwuid are slow with fix for CR6540209 - native ldap client config w/compat and use of netgroups
author mj162486
date Tue, 27 May 2008 13:50:08 -0700
parents fd0cd3c2a8c6
children 95f33d4e0a04
files usr/src/lib/libsldap/common/ns_connect.c usr/src/lib/libsldap/common/ns_reads.c
diffstat 2 files changed, 60 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/lib/libsldap/common/ns_connect.c	Tue May 27 11:31:22 2008 -0700
+++ b/usr/src/lib/libsldap/common/ns_connect.c	Tue May 27 13:50:08 2008 -0700
@@ -1706,6 +1706,11 @@
 	Connection *cp;
 	int id;
 	int use_lock = !fini;
+	struct timeval	zerotime;
+	LDAPMessage	*res;
+
+	zerotime.tv_sec = zerotime.tv_usec = 0L;
+
 #ifdef DEBUG
 	thread_t t = thr_self();
 #endif /* DEBUG */
@@ -1754,6 +1759,17 @@
 			cp->shared--;
 		cp->usedBit = B_FALSE;
 		cp->threadID = 0;	/* unmark the threadID */
+		/*
+		 * Do sanity cleanup of remaining results if connection is not
+		 * shared by any requests.
+		 */
+		if (cp->shared <= 0) {
+			while (ldap_result(cp->ld, LDAP_RES_ANY, LDAP_MSG_ALL,
+			    &zerotime, &res) > 0) {
+				if (res != NULL)
+					(void) ldap_msgfree(res);
+			}
+		}
 		if (use_lock)
 			(void) rw_unlock(&sessionPoolLock);
 	} else {
--- a/usr/src/lib/libsldap/common/ns_reads.c	Tue May 27 11:31:22 2008 -0700
+++ b/usr/src/lib/libsldap/common/ns_reads.c	Tue May 27 13:50:08 2008 -0700
@@ -2038,6 +2038,49 @@
 }
 
 /*
+ * clear_results(ns_ldap_cookie_t):
+ *
+ * Attempt to obtain remnants of ldap responses and free them.  If remnants are
+ * not obtained within a certain time period tell the server we wish to abandon
+ * the request.
+ *
+ * Note that we do not initially tell the server to abandon the request as that
+ * can be an expensive operation for the server, while it is cheap for us to
+ * just flush the input.
+ *
+ * If something was to remain in libldap queue as a result of some error then
+ * it would be freed later during drop connection call or when no other
+ * requests share the connection.
+ */
+static void
+clear_results(ns_ldap_cookie_t *cookie)
+{
+	int rc;
+	if (cookie->conn != NULL && cookie->conn->ld != NULL &&
+	    cookie->connectionId != -1 && cookie->msgId != 0) {
+		/*
+		 * We need to cleanup the rest of response (if there is such)
+		 * and LDAP abandon is too heavy for LDAP servers, so we will
+		 * wait for the rest of response till timeout and "process" it.
+		 */
+		rc = ldap_result(cookie->conn->ld, cookie->msgId, LDAP_MSG_ALL,
+		    (struct timeval *)&cookie->search_timeout,
+		    &cookie->resultMsg);
+		if (rc != -1 && rc != 0 && cookie->resultMsg != NULL)
+			(void) ldap_msgfree(cookie->resultMsg);
+		/*
+		 * If there was timeout then we will send  ABANDON request to
+		 * LDAP server to decrease load.
+		 */
+		if (rc == 0)
+			(void) ldap_abandon_ext(cookie->conn->ld, cookie->msgId,
+			    NULL, NULL);
+		/* Disassociate cookie with msgId */
+		cookie->msgId = 0;
+	}
+}
+
+/*
  * This state machine performs one or more LDAP searches to a given
  * directory server using service search descriptors and schema
  * mapping as appropriate.  The approximate pseudocode for
@@ -2078,12 +2121,7 @@
 	for (;;) {
 		switch (cookie->state) {
 		case CLEAR_RESULTS:
-			if (cookie->conn != NULL && cookie->conn->ld != NULL &&
-			    cookie->connectionId != -1 && cookie->msgId != 0) {
-				(void) ldap_abandon_ext(cookie->conn->ld,
-				    cookie->msgId, NULL, NULL);
-				cookie->msgId = 0;
-			}
+			clear_results(cookie);
 			cookie->new_state = EXIT;
 			break;
 		case GET_ACCT_MGMT_INFO: