Blob Blame History Raw
commit 3e1aa84e7f9f38815f5db9cd7654b1a9497cf6e4
Author: Ulrich Drepper <drepper@gmail.com>
Date:   Fri Jan 20 22:39:54 2012 -0500

    Do not cache negative results in nscd if these are transient

diff -rup a/nscd/aicache.c b/nscd/aicache.c
--- a/nscd/aicache.c	2012-01-24 20:32:58.906826425 -0700
+++ b/nscd/aicache.c	2012-01-24 20:42:17.663968882 -0700
@@ -511,9 +511,17 @@ next_nip:
       if (fd != -1)
 	TEMP_FAILURE_RETRY (send (fd, &notfound, total, MSG_NOSIGNAL));
 
-      dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len, 1);
-      /* If we cannot permanently store the result, so be it.  */
-      if (dataset != NULL)
+      /* If we have a transient error or cannot permanently store the
+	 result, so be it.  */
+      if (rc4 == EAGAIN || __builtin_expect (db->negtimeout == 0, 0))
+	{
+	  /* Mark the old entry as obsolete.  */
+	  if (dh != NULL)
+	    dh->usable = false;
+	  dataset = NULL;
+	}
+      else if ((dataset = mempool_alloc (db, (sizeof (struct dataset)
+					      + req->key_len), 1)) != NULL)
 	{
 	  dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
 	  dataset->head.recsize = total;
diff -rup a/nscd/grpcache.c b/nscd/grpcache.c
--- a/nscd/grpcache.c	2012-01-24 20:32:58.910826427 -0700
+++ b/nscd/grpcache.c	2012-01-24 20:42:17.666968883 -0700
@@ -114,13 +114,21 @@ cache_addgr (struct database_dyn *db, in
 	     case.  */
 	  total = sizeof (notfound);
 
-	  written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
-					      MSG_NOSIGNAL));
+	  if (fd != -1)
+	    written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
+						MSG_NOSIGNAL));
+	  else
+	    written = total;
 
-	  dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
-				   1);
-	  /* If we cannot permanently store the result, so be it.  */
-	  if (dataset != NULL)
+	  /* If we have a transient error or cannot permanently store
+	     the result, so be it.  */
+	  if (errno == EAGAIN || __builtin_expect (db->negtimeout == 0, 0))
+	    {
+	      /* Mark the old entry as obsolete.  */
+	      if (dh != NULL)
+		dh->usable = false;
+	    }
+	  else if ((dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len, 1)) != NULL)
 	    {
 	      dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
 	      dataset->head.recsize = total;
diff -rup a/nscd/hstcache.c b/nscd/hstcache.c
--- a/nscd/hstcache.c	2012-01-24 20:32:58.911826427 -0700
+++ b/nscd/hstcache.c	2012-01-24 20:42:17.668968883 -0700
@@ -141,10 +141,16 @@ cache_addhst (struct database_dyn *db, i
 					MSG_NOSIGNAL)) != total)
 	    all_written = false;
 
-	  dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
-				   1);
-	  /* If we cannot permanently store the result, so be it.  */
-	  if (dataset != NULL)
+	  /* If we have a transient error or cannot permanently store
+	     the result, so be it.  */
+	  if (errval == EAGAIN || __builtin_expect (db->negtimeout == 0, 0))
+	    {
+	      /* Mark the old entry as obsolete.  */
+	      if (dh != NULL)
+		dh->usable = false;
+	    }
+	  else if ((dataset = mempool_alloc (db, (sizeof (struct dataset)
+						  + req->key_len), 1)) != NULL)
 	    {
 	      dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
 	      dataset->head.recsize = total;
diff -rup a/nscd/initgrcache.c b/nscd/initgrcache.c
--- a/nscd/initgrcache.c	2012-01-24 20:32:58.912826427 -0700
+++ b/nscd/initgrcache.c	2012-01-24 20:42:17.671968883 -0700
@@ -202,10 +202,16 @@ addinitgroupsX (struct database_dyn *db,
 	    written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
 						MSG_NOSIGNAL));
 
-	  dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
-				   1);
-	  /* If we cannot permanently store the result, so be it.  */
-	  if (dataset != NULL)
+	  /* If we have a transient error or cannot permanently store
+	     the result, so be it.  */
+	  if (all_tryagain || __builtin_expect (db->negtimeout == 0, 0))
+	    {
+	      /* Mark the old entry as obsolete.  */
+	      if (dh != NULL)
+		dh->usable = false;
+	    }
+	  else if ((dataset = mempool_alloc (db, (sizeof (struct dataset)
+						  + req->key_len), 1)) != NULL)
 	    {
 	      dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
 	      dataset->head.recsize = total;
diff -rup a/nscd/pwdcache.c b/nscd/pwdcache.c
--- a/nscd/pwdcache.c	2012-01-24 20:32:58.914826427 -0700
+++ b/nscd/pwdcache.c	2012-01-24 20:42:17.671968883 -0700
@@ -124,10 +124,16 @@ cache_addpw (struct database_dyn *db, in
 	    written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
 						MSG_NOSIGNAL));
 
-	  dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
-				   1);
-	  /* If we cannot permanently store the result, so be it.  */
-	  if (dataset != NULL)
+	  /* If we have a transient error or cannot permanently store
+	     the result, so be it.  */
+	  if (errno == EAGAIN || __builtin_expect (db->negtimeout == 0, 0))
+	    {
+	      /* Mark the old entry as obsolete.  */
+	      if (dh != NULL)
+		dh->usable = false;
+	    }
+	  else if ((dataset = mempool_alloc (db, (sizeof (struct dataset)
+						  + req->key_len), 1)) != NULL)
 	    {
 	      dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
 	      dataset->head.recsize = total;
diff -rup a/nscd/servicescache.c b/nscd/servicescache.c
--- a/nscd/servicescache.c	2012-01-24 20:32:58.915826427 -0700
+++ b/nscd/servicescache.c	2012-01-24 20:42:17.672968884 -0700
@@ -102,15 +102,22 @@ cache_addserv (struct database_dyn *db,
 	{
 	  /* We have no data.  This means we send the standard reply for this
 	     case.  */
-	  total = sizeof (notfound);
+	  written = total = sizeof (notfound);
 
-	  written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
-					      MSG_NOSIGNAL));
+	  if (fd != -1)
+	    written = TEMP_FAILURE_RETRY (send (fd, &notfound, total,
+						MSG_NOSIGNAL));
 
-	  dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
-				   1);
-	  /* If we cannot permanently store the result, so be it.  */
-	  if (dataset != NULL)
+	  /* If we have a transient error or cannot permanently store
+	     the result, so be it.  */
+	  if (errval == EAGAIN || __builtin_expect (db->negtimeout == 0, 0))
+	    {
+	      /* Mark the old entry as obsolete.  */
+	      if (dh != NULL)
+		dh->usable = false;
+	    }
+	  else if ((dataset = mempool_alloc (db, (sizeof (struct dataset)
+						  + req->key_len), 1)) != NULL)
 	    {
 	      dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
 	      dataset->head.recsize = total;