From 50158f95525ca59459a90f2a7bc65ceb892a0807 Mon Sep 17 00:00:00 2001 From: Andreas Schwab Date: Thu, 16 Jul 2009 09:57:32 -0700 Subject: Use correct release semantic in list update. nscd uses lockfree lists and we need to ensure the correct release semantics is used when adding to the list. --- nscd/cache.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'nscd') diff --git a/nscd/cache.c b/nscd/cache.c index ab842efc29..3e6793df2f 100644 --- a/nscd/cache.c +++ b/nscd/cache.c @@ -179,7 +179,7 @@ cache_add (int type, const void *key, size_t len, struct datahead *packet, /* Put the new entry in the first position. */ do newp->next = table->head->array[hash]; - while (atomic_compare_and_exchange_bool_acq (&table->head->array[hash], + while (atomic_compare_and_exchange_bool_rel (&table->head->array[hash], (ref_t) ((char *) newp - table->data), (ref_t) newp->next)); -- cgit v1.2.3 From 137028b4d7e50f71906c1656c27079eac5a1d085 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Thu, 16 Jul 2009 10:10:10 -0700 Subject: Fix lock handling in memory hander of nscd. The commit 20e498bd removes the pthread_mutex_rdlock() calls, but not the corresponding pthread_mutex_unlock() calls. Also, the database lock is never unlocked in one branch of the mempool_alloc() if. I think unreproducible random assert(dh->usable) crashes in prune_cache() were caused by this. But an easy way to make nscd threads hang with the broken locking was. --- ChangeLog | 11 +++++++++++ nscd/aicache.c | 2 -- nscd/grpcache.c | 6 +----- nscd/hstcache.c | 4 ---- nscd/initgrcache.c | 4 ---- nscd/mem.c | 6 +++--- nscd/pwdcache.c | 6 +----- nscd/servicescache.c | 4 ---- 8 files changed, 16 insertions(+), 27 deletions(-) (limited to 'nscd') diff --git a/ChangeLog b/ChangeLog index a81c5b46fb..37f20a4b8b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2009-07-16 Petr Baudis + + * nscd/mem.c (mempool_alloc): Fix unlock missing in the else branch. + * nscd/aicache.c: Remove bogus db->lock unlock. + * nscd/grpcache.c: Likewise. + * nscd/hstcache.c: Likewise. + * nscd/initgrcache.c: Likewise. + * nscd/pwdcache.c: Likewise. + * nscd/servicescache.c: Likewise. + 2009-07-16 Ulrich Drepper * nscd/cache.c (cache_add): Use atomic_compare_and_exchange_bool_rel @@ -5,6 +15,7 @@ is written before the list head update. Patch by Andreas Schwab . +2009-07-16 Ulrich Drepper Jakub Jelinek * malloc/malloc.c [ATOMIC_FASTBINS] (_int_free): Make check for diff --git a/nscd/aicache.c b/nscd/aicache.c index 524c0a63af..8dac48e5c2 100644 --- a/nscd/aicache.c +++ b/nscd/aicache.c @@ -543,8 +543,6 @@ next_nip: (void) cache_add (req->type, key_copy, req->key_len, &dataset->head, true, db, uid, he == NULL); - pthread_rwlock_unlock (&db->lock); - /* Mark the old entry as obsolete. */ if (dh != NULL) dh->usable = false; diff --git a/nscd/grpcache.c b/nscd/grpcache.c index 184d53898c..fc2008449e 100644 --- a/nscd/grpcache.c +++ b/nscd/grpcache.c @@ -146,8 +146,6 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req, (void) cache_add (req->type, &dataset->strdata, req->key_len, &dataset->head, true, db, owner, he == NULL); - pthread_rwlock_unlock (&db->lock); - /* Mark the old entry as obsolete. */ if (dh != NULL) dh->usable = false; @@ -367,12 +365,10 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req, (void) cache_add (GETGRBYGID, cp, key_offset, &dataset->head, false, db, owner, false); } - - out: - pthread_rwlock_unlock (&db->lock); } } +out: if (__builtin_expect (written != total, 0) && debug_level > 0) { char buf[256]; diff --git a/nscd/hstcache.c b/nscd/hstcache.c index 51e2273960..77ffcdf880 100644 --- a/nscd/hstcache.c +++ b/nscd/hstcache.c @@ -153,8 +153,6 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req, (void) cache_add (req->type, &dataset->strdata, req->key_len, &dataset->head, true, db, owner, he == NULL); - pthread_rwlock_unlock (&db->lock); - /* Mark the old entry as obsolete. */ if (dh != NULL) dh->usable = false; @@ -404,8 +402,6 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req, (void) cache_add (req->type, key_copy, req->key_len, &dataset->head, true, db, owner, he == NULL); - - pthread_rwlock_unlock (&db->lock); } } diff --git a/nscd/initgrcache.c b/nscd/initgrcache.c index c33aaf315f..f8d4742d16 100644 --- a/nscd/initgrcache.c +++ b/nscd/initgrcache.c @@ -230,8 +230,6 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req, (void) cache_add (req->type, key_copy, req->key_len, &dataset->head, true, db, uid, he == NULL); - pthread_rwlock_unlock (&db->lock); - /* Mark the old entry as obsolete. */ if (dh != NULL) dh->usable = false; @@ -388,8 +386,6 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req, (void) cache_add (INITGROUPS, cp, req->key_len, &dataset->head, true, db, uid, he == NULL); - - pthread_rwlock_unlock (&db->lock); } } diff --git a/nscd/mem.c b/nscd/mem.c index fcea6dbd03..80ea951146 100644 --- a/nscd/mem.c +++ b/nscd/mem.c @@ -566,9 +566,6 @@ mempool_alloc (struct database_dyn *db, size_t len, int data_alloc) } } - if (data_alloc) - pthread_rwlock_unlock (&db->lock); - if (! db->last_alloc_failed) { dbg_log (_("no more memory for database '%s'"), dbnames[db - dbs]); @@ -591,5 +588,8 @@ mempool_alloc (struct database_dyn *db, size_t len, int data_alloc) pthread_mutex_unlock (&db->memlock); + if (data_alloc) + pthread_rwlock_unlock (&db->lock); + return res; } diff --git a/nscd/pwdcache.c b/nscd/pwdcache.c index 2338e7e1e0..fc5b44eef0 100644 --- a/nscd/pwdcache.c +++ b/nscd/pwdcache.c @@ -153,8 +153,6 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req, (void) cache_add (req->type, key_copy, req->key_len, &dataset->head, true, db, owner, he == NULL); - pthread_rwlock_unlock (&db->lock); - /* Mark the old entry as obsolete. */ if (dh != NULL) dh->usable = false; @@ -362,12 +360,10 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req, (void) cache_add (GETPWBYUID, cp, key_offset, &dataset->head, false, db, owner, false); } - - out: - pthread_rwlock_unlock (&db->lock); } } +out: if (__builtin_expect (written != total, 0) && debug_level > 0) { char buf[256]; diff --git a/nscd/servicescache.c b/nscd/servicescache.c index dc98d3005a..c965c972a3 100644 --- a/nscd/servicescache.c +++ b/nscd/servicescache.c @@ -136,8 +136,6 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req, (void) cache_add (req->type, &dataset->strdata, req->key_len, &dataset->head, true, db, owner, he == NULL); - pthread_rwlock_unlock (&db->lock); - /* Mark the old entry as obsolete. */ if (dh != NULL) dh->usable = false; @@ -317,8 +315,6 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req, (void) cache_add (req->type, key_copy, req->key_len, &dataset->head, true, db, owner, he == NULL); - - pthread_rwlock_unlock (&db->lock); } } -- cgit v1.2.3 From 00ebd7ed58df389a78e41dece058048725cb585e Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Fri, 17 Jul 2009 07:49:16 -0700 Subject: Revert "Fix lock handling in memory hander of nscd." This reverts commit 137028b4d7e50f71906c1656c27079eac5a1d085. Conflicts: ChangeLog --- ChangeLog | 11 ----------- nscd/aicache.c | 2 ++ nscd/grpcache.c | 6 +++++- nscd/hstcache.c | 4 ++++ nscd/initgrcache.c | 4 ++++ nscd/mem.c | 6 +++--- nscd/pwdcache.c | 6 +++++- nscd/servicescache.c | 4 ++++ 8 files changed, 27 insertions(+), 16 deletions(-) (limited to 'nscd') diff --git a/ChangeLog b/ChangeLog index 6418f866f4..dce8cbc232 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,17 +4,6 @@ * resolv/res-mkquery.c (__res_nopt): If anslen is > 0xffff store 0xffff in the EDNS0 record. -2009-07-16 Petr Baudis - - [BZ #10402] - * nscd/mem.c (mempool_alloc): Fix unlock missing in the else branch. - * nscd/aicache.c: Remove bogus db->lock unlock. - * nscd/grpcache.c: Likewise. - * nscd/hstcache.c: Likewise. - * nscd/initgrcache.c: Likewise. - * nscd/pwdcache.c: Likewise. - * nscd/servicescache.c: Likewise. - 2009-07-16 Ulrich Drepper * nscd/cache.c (cache_add): Use atomic_compare_and_exchange_bool_rel diff --git a/nscd/aicache.c b/nscd/aicache.c index 8dac48e5c2..524c0a63af 100644 --- a/nscd/aicache.c +++ b/nscd/aicache.c @@ -543,6 +543,8 @@ next_nip: (void) cache_add (req->type, key_copy, req->key_len, &dataset->head, true, db, uid, he == NULL); + pthread_rwlock_unlock (&db->lock); + /* Mark the old entry as obsolete. */ if (dh != NULL) dh->usable = false; diff --git a/nscd/grpcache.c b/nscd/grpcache.c index fc2008449e..184d53898c 100644 --- a/nscd/grpcache.c +++ b/nscd/grpcache.c @@ -146,6 +146,8 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req, (void) cache_add (req->type, &dataset->strdata, req->key_len, &dataset->head, true, db, owner, he == NULL); + pthread_rwlock_unlock (&db->lock); + /* Mark the old entry as obsolete. */ if (dh != NULL) dh->usable = false; @@ -365,10 +367,12 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req, (void) cache_add (GETGRBYGID, cp, key_offset, &dataset->head, false, db, owner, false); } + + out: + pthread_rwlock_unlock (&db->lock); } } -out: if (__builtin_expect (written != total, 0) && debug_level > 0) { char buf[256]; diff --git a/nscd/hstcache.c b/nscd/hstcache.c index 77ffcdf880..51e2273960 100644 --- a/nscd/hstcache.c +++ b/nscd/hstcache.c @@ -153,6 +153,8 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req, (void) cache_add (req->type, &dataset->strdata, req->key_len, &dataset->head, true, db, owner, he == NULL); + pthread_rwlock_unlock (&db->lock); + /* Mark the old entry as obsolete. */ if (dh != NULL) dh->usable = false; @@ -402,6 +404,8 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req, (void) cache_add (req->type, key_copy, req->key_len, &dataset->head, true, db, owner, he == NULL); + + pthread_rwlock_unlock (&db->lock); } } diff --git a/nscd/initgrcache.c b/nscd/initgrcache.c index f8d4742d16..c33aaf315f 100644 --- a/nscd/initgrcache.c +++ b/nscd/initgrcache.c @@ -230,6 +230,8 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req, (void) cache_add (req->type, key_copy, req->key_len, &dataset->head, true, db, uid, he == NULL); + pthread_rwlock_unlock (&db->lock); + /* Mark the old entry as obsolete. */ if (dh != NULL) dh->usable = false; @@ -386,6 +388,8 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req, (void) cache_add (INITGROUPS, cp, req->key_len, &dataset->head, true, db, uid, he == NULL); + + pthread_rwlock_unlock (&db->lock); } } diff --git a/nscd/mem.c b/nscd/mem.c index 80ea951146..fcea6dbd03 100644 --- a/nscd/mem.c +++ b/nscd/mem.c @@ -566,6 +566,9 @@ mempool_alloc (struct database_dyn *db, size_t len, int data_alloc) } } + if (data_alloc) + pthread_rwlock_unlock (&db->lock); + if (! db->last_alloc_failed) { dbg_log (_("no more memory for database '%s'"), dbnames[db - dbs]); @@ -588,8 +591,5 @@ mempool_alloc (struct database_dyn *db, size_t len, int data_alloc) pthread_mutex_unlock (&db->memlock); - if (data_alloc) - pthread_rwlock_unlock (&db->lock); - return res; } diff --git a/nscd/pwdcache.c b/nscd/pwdcache.c index fc5b44eef0..2338e7e1e0 100644 --- a/nscd/pwdcache.c +++ b/nscd/pwdcache.c @@ -153,6 +153,8 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req, (void) cache_add (req->type, key_copy, req->key_len, &dataset->head, true, db, owner, he == NULL); + pthread_rwlock_unlock (&db->lock); + /* Mark the old entry as obsolete. */ if (dh != NULL) dh->usable = false; @@ -360,10 +362,12 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req, (void) cache_add (GETPWBYUID, cp, key_offset, &dataset->head, false, db, owner, false); } + + out: + pthread_rwlock_unlock (&db->lock); } } -out: if (__builtin_expect (written != total, 0) && debug_level > 0) { char buf[256]; diff --git a/nscd/servicescache.c b/nscd/servicescache.c index c965c972a3..dc98d3005a 100644 --- a/nscd/servicescache.c +++ b/nscd/servicescache.c @@ -136,6 +136,8 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req, (void) cache_add (req->type, &dataset->strdata, req->key_len, &dataset->head, true, db, owner, he == NULL); + pthread_rwlock_unlock (&db->lock); + /* Mark the old entry as obsolete. */ if (dh != NULL) dh->usable = false; @@ -315,6 +317,8 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req, (void) cache_add (req->type, key_copy, req->key_len, &dataset->head, true, db, owner, he == NULL); + + pthread_rwlock_unlock (&db->lock); } } -- cgit v1.2.3