File glibc-2.6-nscd-gclock.diff of Package glibc
Index: nscd/aicache.c
===================================================================
--- nscd/aicache.c.orig
+++ nscd/aicache.c
@@ -260,11 +260,15 @@ addhstaiX (struct database_dyn *db, int
entry at all. */
if (ttl != 0 && he == NULL)
{
+ pthread_rwlock_rdlock (&db->lock);
dataset = (struct dataset *) mempool_alloc (db,
total
+ req->key_len);
if (dataset == NULL)
- ++db->head->addfailed;
+ {
+ ++db->head->addfailed;
+ pthread_rwlock_unlock (&db->lock);
+ }
}
if (dataset == NULL)
@@ -335,6 +339,8 @@ addhstaiX (struct database_dyn *db, int
{
/* We have to create a new record. Just allocate
appropriate memory and copy it. */
+ if (alloca_used)
+ pthread_rwlock_rdlock (&db->lock);
struct dataset *newp
= (struct dataset *) mempool_alloc (db,
total
@@ -350,7 +356,11 @@ addhstaiX (struct database_dyn *db, int
alloca_used = false;
}
else
- ++db->head->addfailed;
+ {
+ ++db->head->addfailed;
+ if (alloca_used)
+ pthread_rwlock_unlock (&db->lock);
+ }
/* Mark the old record as obsolete. */
dh->usable = false;
@@ -430,27 +440,35 @@ addhstaiX (struct database_dyn *db, int
/* Mark the old entry as obsolete. */
if (dh != NULL)
dh->usable = false;
- dataset = NULL;
+ assert(dataset == NULL);
}
- else if ((dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len)) == NULL)
- {
- dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
- dataset->head.recsize = total;
- dataset->head.notfound = true;
- dataset->head.nreloads = 0;
- dataset->head.usable = true;
+ else
+ {
+ pthread_rwlock_rdlock (&db->lock);
+ dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len);
+ if (dataset != NULL)
+ {
+ dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
+ dataset->head.recsize = total;
+ dataset->head.notfound = true;
+ dataset->head.nreloads = 0;
+ dataset->head.usable = true;
- /* Compute the timeout time. */
- dataset->head.timeout = time (NULL) + db->negtimeout;
+ /* Compute the timeout time. */
+ dataset->head.timeout = time (NULL) + db->negtimeout;
- /* This is the reply. */
- memcpy (&dataset->resp, ¬found, total);
+ /* This is the reply. */
+ memcpy (&dataset->resp, ¬found, total);
- /* Copy the key data. */
- key_copy = memcpy (dataset->strdata, key, req->key_len);
+ /* Copy the key data. */
+ key_copy = memcpy (dataset->strdata, key, req->key_len);
+ }
+ else
+ {
+ pthread_rwlock_unlock (&db->lock);
+ ++db->head->addfailed;
+ }
}
- else
- ++db->head->addfailed;
}
out:
@@ -468,9 +486,6 @@ addhstaiX (struct database_dyn *db, int
MS_ASYNC);
}
- /* Now get the lock to safely insert the records. */
- pthread_rwlock_rdlock (&db->lock);
-
if (cache_add (req->type, key_copy, req->key_len, &dataset->head, true,
db, uid) < 0)
/* Ensure the data can be recovered. */
Index: nscd/grpcache.c
===================================================================
--- nscd/grpcache.c.orig
+++ nscd/grpcache.c
@@ -120,49 +120,52 @@ cache_addgr (struct database_dyn *db, in
if (dh != NULL)
dh->usable = false;
}
- else if ((dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len)) != NULL)
+ else
{
- dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
- dataset->head.recsize = total;
- dataset->head.notfound = true;
- dataset->head.nreloads = 0;
- dataset->head.usable = true;
-
- /* Compute the timeout time. */
- dataset->head.timeout = t + db->negtimeout;
-
- /* This is the reply. */
- memcpy (&dataset->resp, ¬found, total);
-
- /* Copy the key data. */
- memcpy (dataset->strdata, key, req->key_len);
+ pthread_rwlock_rdlock (&db->lock);
- /* If necessary, we also propagate the data to disk. */
- if (db->persistent)
+ dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len);
+ if (dataset != NULL)
{
- // XXX async OK?
- uintptr_t pval = (uintptr_t) dataset & ~pagesize_m1;
- msync ((void *) pval,
- ((uintptr_t) dataset & pagesize_m1)
- + sizeof (struct dataset) + req->key_len, MS_ASYNC);
+ dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
+ dataset->head.recsize = total;
+ dataset->head.notfound = true;
+ dataset->head.nreloads = 0;
+ dataset->head.usable = true;
+
+ /* Compute the timeout time. */
+ dataset->head.timeout = t + db->negtimeout;
+
+ /* This is the reply. */
+ memcpy (&dataset->resp, ¬found, total);
+
+ /* Copy the key data. */
+ memcpy (dataset->strdata, key, req->key_len);
+
+ /* If necessary, we also propagate the data to disk. */
+ if (db->persistent)
+ {
+ // XXX async OK?
+ uintptr_t pval = (uintptr_t) dataset & ~pagesize_m1;
+ msync ((void *) pval,
+ ((uintptr_t) dataset & pagesize_m1)
+ + sizeof (struct dataset) + req->key_len, MS_ASYNC);
+ }
+
+ if (cache_add (req->type, &dataset->strdata, req->key_len,
+ &dataset->head, true, db, owner) < 0)
+ /* Ensure the data can be recovered. */
+ dataset->head.usable = false;
+
+ /* Mark the old entry as obsolete. */
+ if (dh != NULL)
+ dh->usable = false;
}
-
- /* Now get the lock to safely insert the records. */
- pthread_rwlock_rdlock (&db->lock);
-
- if (cache_add (req->type, &dataset->strdata, req->key_len,
- &dataset->head, true, db, owner) < 0)
- /* Ensure the data can be recovered. */
- dataset->head.usable = false;
+ else
+ ++db->head->addfailed;
pthread_rwlock_unlock (&db->lock);
-
- /* Mark the old entry as obsolete. */
- if (dh != NULL)
- dh->usable = false;
}
- else
- ++db->head->addfailed;
}
}
else
@@ -209,9 +212,13 @@ cache_addgr (struct database_dyn *db, in
if (he == NULL)
{
+ pthread_rwlock_rdlock (&db->lock);
dataset = (struct dataset *) mempool_alloc (db, total + n);
if (dataset == NULL)
- ++db->head->addfailed;
+ {
+ pthread_rwlock_unlock (&db->lock);
+ ++db->head->addfailed;
+ }
}
if (dataset == NULL)
@@ -278,6 +285,8 @@ cache_addgr (struct database_dyn *db, in
{
/* We have to create a new record. Just allocate
appropriate memory and copy it. */
+ if (alloca_used)
+ pthread_rwlock_rdlock (&db->lock);
struct dataset *newp
= (struct dataset *) mempool_alloc (db, total + n);
if (newp != NULL)
@@ -291,7 +300,11 @@ cache_addgr (struct database_dyn *db, in
alloca_used = false;
}
else
- ++db->head->addfailed;
+ {
+ ++db->head->addfailed;
+ if (alloca_used)
+ pthread_rwlock_unlock (&db->lock);
+ }
/* Mark the old record as obsolete. */
dh->usable = false;
@@ -344,9 +357,6 @@ cache_addgr (struct database_dyn *db, in
MS_ASYNC);
}
- /* Now get the lock to safely insert the records. */
- pthread_rwlock_rdlock (&db->lock);
-
/* NB: in the following code we always must add the entry
marked with FIRST first. Otherwise we end up with
dangling "pointers" in case a latter hash entry cannot be
Index: nscd/hstcache.c
===================================================================
--- nscd/hstcache.c.orig
+++ nscd/hstcache.c
@@ -127,50 +127,53 @@ cache_addhst (struct database_dyn *db, i
if (dh != NULL)
dh->usable = false;
}
- else if ((dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len)) != NULL)
+ else
{
- dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
- dataset->head.recsize = total;
- dataset->head.notfound = true;
- dataset->head.nreloads = 0;
- dataset->head.usable = true;
+ pthread_rwlock_rdlock (&db->lock);
- /* Compute the timeout time. */
- dataset->head.timeout = t + (ttl == INT32_MAX
- ? db->negtimeout : ttl);
+ dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len);
+ if (dataset != NULL)
+ {
+ dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
+ dataset->head.recsize = total;
+ dataset->head.notfound = true;
+ dataset->head.nreloads = 0;
+ dataset->head.usable = true;
- /* This is the reply. */
- memcpy (&dataset->resp, ¬found, total);
+ /* Compute the timeout time. */
+ dataset->head.timeout = t + (ttl == INT32_MAX
+ ? db->negtimeout : ttl);
- /* Copy the key data. */
- memcpy (dataset->strdata, key, req->key_len);
+ /* This is the reply. */
+ memcpy (&dataset->resp, ¬found, total);
- /* If necessary, we also propagate the data to disk. */
- if (db->persistent)
- {
- // XXX async OK?
- uintptr_t pval = (uintptr_t) dataset & ~pagesize_m1;
- msync ((void *) pval,
- ((uintptr_t) dataset & pagesize_m1)
- + sizeof (struct dataset) + req->key_len, MS_ASYNC);
- }
+ /* Copy the key data. */
+ memcpy (dataset->strdata, key, req->key_len);
- /* Now get the lock to safely insert the records. */
- pthread_rwlock_rdlock (&db->lock);
+ /* If necessary, we also propagate the data to disk. */
+ if (db->persistent)
+ {
+ // XXX async OK?
+ uintptr_t pval = (uintptr_t) dataset & ~pagesize_m1;
+ msync ((void *) pval,
+ ((uintptr_t) dataset & pagesize_m1)
+ + sizeof (struct dataset) + req->key_len, MS_ASYNC);
+ }
- if (cache_add (req->type, &dataset->strdata, req->key_len,
- &dataset->head, true, db, owner) < 0)
- /* Ensure the data can be recovered. */
- dataset->head.usable = false;
+ if (cache_add (req->type, &dataset->strdata, req->key_len,
+ &dataset->head, true, db, owner) < 0)
+ /* Ensure the data can be recovered. */
+ dataset->head.usable = false;
+
+ /* Mark the old entry as obsolete. */
+ if (dh != NULL)
+ dh->usable = false;
+ }
+ else
+ ++db->head->addfailed;
pthread_rwlock_unlock (&db->lock);
-
- /* Mark the old entry as obsolete. */
- if (dh != NULL)
- dh->usable = false;
}
- else
- ++db->head->addfailed;
}
}
else
@@ -229,10 +232,14 @@ cache_addhst (struct database_dyn *db, i
handling just for handling such a special case. */
if (he == NULL && h_addr_list_cnt == 1)
{
+ pthread_rwlock_rdlock (&db->lock);
dataset = (struct dataset *) mempool_alloc (db,
total + req->key_len);
if (dataset == NULL)
- ++db->head->addfailed;
+ {
+ pthread_rwlock_unlock (&db->lock);
+ ++db->head->addfailed;
+ }
}
if (dataset == NULL)
@@ -312,6 +319,8 @@ cache_addhst (struct database_dyn *db, i
{
if (h_addr_list_cnt == 1)
{
+ if (alloca_used)
+ pthread_rwlock_rdlock (&db->lock);
/* We have to create a new record. Just allocate
appropriate memory and copy it. */
struct dataset *newp
@@ -330,7 +339,11 @@ cache_addhst (struct database_dyn *db, i
alloca_used = false;
}
else
- ++db->head->addfailed;
+ {
+ ++db->head->addfailed;
+ if (alloca_used)
+ pthread_rwlock_unlock (&db->lock);
+ }
}
/* Mark the old record as obsolete. */
@@ -393,9 +406,6 @@ cache_addhst (struct database_dyn *db, i
addr_list_type = (hst->h_length == NS_INADDRSZ
? GETHOSTBYADDR : GETHOSTBYADDRv6);
- /* Now get the lock to safely insert the records. */
- pthread_rwlock_rdlock (&db->lock);
-
/* NB: the following code is really complicated. It has
seemlingly duplicated code paths which do the same. The
problem is that we always must add the hash table entry
Index: nscd/initgrcache.c
===================================================================
--- nscd/initgrcache.c.orig
+++ nscd/initgrcache.c
@@ -204,49 +204,52 @@ addinitgroupsX (struct database_dyn *db,
if (dh != NULL)
dh->usable = false;
}
- else if ((dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len)) != NULL)
+ else
{
- dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
- dataset->head.recsize = total;
- dataset->head.notfound = true;
- dataset->head.nreloads = 0;
- dataset->head.usable = true;
-
- /* Compute the timeout time. */
- dataset->head.timeout = time (NULL) + db->negtimeout;
-
- /* This is the reply. */
- memcpy (&dataset->resp, ¬found, total);
-
- /* Copy the key data. */
- char *key_copy = memcpy (dataset->strdata, key, req->key_len);
+ pthread_rwlock_rdlock (&db->lock);
- /* If necessary, we also propagate the data to disk. */
- if (db->persistent)
+ dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len);
+ if (dataset != NULL)
{
- // XXX async OK?
- uintptr_t pval = (uintptr_t) dataset & ~pagesize_m1;
- msync ((void *) pval,
- ((uintptr_t) dataset & pagesize_m1)
- + sizeof (struct dataset) + req->key_len, MS_ASYNC);
+ dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
+ dataset->head.recsize = total;
+ dataset->head.notfound = true;
+ dataset->head.nreloads = 0;
+ dataset->head.usable = true;
+
+ /* Compute the timeout time. */
+ dataset->head.timeout = time (NULL) + db->negtimeout;
+
+ /* This is the reply. */
+ memcpy (&dataset->resp, ¬found, total);
+
+ /* Copy the key data. */
+ char *key_copy = memcpy (dataset->strdata, key, req->key_len);
+
+ /* If necessary, we also propagate the data to disk. */
+ if (db->persistent)
+ {
+ // XXX async OK?
+ uintptr_t pval = (uintptr_t) dataset & ~pagesize_m1;
+ msync ((void *) pval,
+ ((uintptr_t) dataset & pagesize_m1)
+ + sizeof (struct dataset) + req->key_len, MS_ASYNC);
+ }
+
+ if (cache_add (req->type, key_copy, req->key_len,
+ &dataset->head, true, db, uid) < 0)
+ /* Ensure the data can be recovered. */
+ dataset->head.usable = false;
+
+ /* Mark the old entry as obsolete. */
+ if (dh != NULL)
+ dh->usable = false;
}
-
- /* Now get the lock to safely insert the records. */
- pthread_rwlock_rdlock (&db->lock);
-
- if (cache_add (req->type, key_copy, req->key_len,
- &dataset->head, true, db, uid) < 0)
- /* Ensure the data can be recovered. */
- dataset->head.usable = false;
+ else
+ ++db->head->addfailed;
pthread_rwlock_unlock (&db->lock);
-
- /* Mark the old entry as obsolete. */
- if (dh != NULL)
- dh->usable = false;
}
- else
- ++db->head->addfailed;
}
}
else
@@ -263,10 +266,14 @@ addinitgroupsX (struct database_dyn *db,
if (he == NULL)
{
+ pthread_rwlock_rdlock (&db->lock);
dataset = (struct dataset *) mempool_alloc (db,
total + req->key_len);
if (dataset == NULL)
- ++db->head->addfailed;
+ {
+ pthread_rwlock_unlock (&db->lock);
+ ++db->head->addfailed;
+ }
}
if (dataset == NULL)
@@ -331,6 +338,8 @@ addinitgroupsX (struct database_dyn *db,
}
else
{
+ if (alloca_used)
+ pthread_rwlock_rdlock (&db->lock);
/* We have to create a new record. Just allocate
appropriate memory and copy it. */
struct dataset *newp
@@ -344,7 +353,11 @@ addinitgroupsX (struct database_dyn *db,
alloca_used = false;
}
else
- ++db->head->addfailed;
+ {
+ ++db->head->addfailed;
+ if (alloca_used)
+ pthread_rwlock_unlock (&db->lock);
+ }
/* Mark the old record as obsolete. */
dh->usable = false;
@@ -398,9 +411,6 @@ addinitgroupsX (struct database_dyn *db,
req->key_len, MS_ASYNC);
}
- /* Now get the lock to safely insert the records. */
- pthread_rwlock_rdlock (&db->lock);
-
if (cache_add (INITGROUPS, cp, req->key_len, &dataset->head, true,
db, uid) < 0)
/* Could not allocate memory. Make sure the data gets
Index: nscd/pwdcache.c
===================================================================
--- nscd/pwdcache.c.orig
+++ nscd/pwdcache.c
@@ -127,50 +127,52 @@ cache_addpw (struct database_dyn *db, in
if (dh != NULL)
dh->usable = false;
}
- else if ((dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len)) != NULL)
+ else
{
- dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
- dataset->head.recsize = total;
- dataset->head.notfound = true;
- dataset->head.nreloads = 0;
- dataset->head.usable = true;
-
- /* Compute the timeout time. */
- dataset->head.timeout = t + db->negtimeout;
-
- /* This is the reply. */
- memcpy (&dataset->resp, ¬found, total);
-
- /* Copy the key data. */
- char *key_copy = memcpy (dataset->strdata, key, req->key_len);
+ pthread_rwlock_rdlock (&db->lock);
- /* If necessary, we also propagate the data to disk. */
- if (db->persistent)
+ dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len);
+ if (dataset != NULL)
{
- // XXX async OK?
- uintptr_t pval = (uintptr_t) dataset & ~pagesize_m1;
- msync ((void *) pval,
- ((uintptr_t) dataset & pagesize_m1)
- + sizeof (struct dataset) + req->key_len, MS_ASYNC);
+ dataset->head.allocsize = sizeof (struct dataset) + req->key_len;
+ dataset->head.recsize = total;
+ dataset->head.notfound = true;
+ dataset->head.nreloads = 0;
+ dataset->head.usable = true;
+
+ /* Compute the timeout time. */
+ dataset->head.timeout = t + db->negtimeout;
+
+ /* This is the reply. */
+ memcpy (&dataset->resp, ¬found, total);
+
+ /* Copy the key data. */
+ char *key_copy = memcpy (dataset->strdata, key, req->key_len);
+
+ /* If necessary, we also propagate the data to disk. */
+ if (db->persistent)
+ {
+ // XXX async OK?
+ uintptr_t pval = (uintptr_t) dataset & ~pagesize_m1;
+ msync ((void *) pval,
+ ((uintptr_t) dataset & pagesize_m1)
+ + sizeof (struct dataset) + req->key_len, MS_ASYNC);
+ }
+
+ if (cache_add (req->type, key_copy, req->key_len,
+ &dataset->head, true, db, owner) < 0)
+ /* Ensure the data can be recovered. */
+ dataset->head.usable = false;
+
+ /* Mark the old entry as obsolete. */
+ if (dh != NULL)
+ dh->usable = false;
}
-
- /* Now get the lock to safely insert the records. */
- pthread_rwlock_rdlock (&db->lock);
-
- if (cache_add (req->type, key_copy, req->key_len,
- &dataset->head, true, db, owner) < 0)
- /* Ensure the data can be recovered. */
- dataset->head.usable = false;
-
+ else
+ ++db->head->addfailed;
pthread_rwlock_unlock (&db->lock);
-
- /* Mark the old entry as obsolete. */
- if (dh != NULL)
- dh->usable = false;
}
- else
- ++db->head->addfailed;
}
}
else
@@ -204,9 +206,13 @@ cache_addpw (struct database_dyn *db, in
if (he == NULL)
{
+ pthread_rwlock_rdlock (&db->lock);
dataset = (struct dataset *) mempool_alloc (db, total + n);
if (dataset == NULL)
- ++db->head->addfailed;
+ {
+ pthread_rwlock_unlock (&db->lock);
+ ++db->head->addfailed;
+ }
}
if (dataset == NULL)
@@ -272,6 +278,8 @@ cache_addpw (struct database_dyn *db, in
}
else
{
+ if (alloca_used)
+ pthread_rwlock_rdlock (&db->lock);
/* We have to create a new record. Just allocate
appropriate memory and copy it. */
struct dataset *newp
@@ -286,7 +294,11 @@ cache_addpw (struct database_dyn *db, in
alloca_used = false;
}
else
- ++db->head->addfailed;
+ {
+ ++db->head->addfailed;
+ if (alloca_used)
+ pthread_rwlock_unlock (&db->lock);
+ }
/* Mark the old record as obsolete. */
dh->usable = false;
@@ -340,9 +352,6 @@ cache_addpw (struct database_dyn *db, in
MS_ASYNC);
}
- /* Now get the lock to safely insert the records. */
- pthread_rwlock_rdlock (&db->lock);
-
/* NB: in the following code we always must add the entry
marked with FIRST first. Otherwise we end up with
dangling "pointers" in case a latter hash entry cannot be