mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-10 07:10:06 +00:00
[BZ #5381]
2009-02-13 Ulrich Drepper <drepper@redhat.com> [BZ #5381] * nscd/nscd.h: Remove definitions and declarations for mem_in_flight. Change mempool_alloc prototype. * nscd/mem.c (gc): Don't handle mem_in_flight. (mempool_alloc): Third parameter now only indicates whether this is the first call (to allocate data) or not. If it is, get db rdlock. Release it on error. Don't handle mem_in_flight. * nscd/aicache.c (addhstaiX): Mark he parameter as const. Adjust third parameter of mempool_alloc calls. Nothing to do here in case mempool_alloc fails. Avoid local variable shadowing parameter. No need to get db rdlock before calling cache_add. * nscd/cache.c (cache_add): Adjust call to mempool_alloc. There is no mem_in_flight array anymore. * nscd/connections.c: Remove definition and handling of mem_in_flight. * nscd/grpcache.c (cache_addgr): Adjust third parameter of mempool_alloc calls. Mark he parameter as const. Nothing to do here in case mempool_alloc fails. No need to get db rdlock before calling cache_add. * nscd/hstcache.c (cache_addhst): Likewise. * nscd/initgrcache.c (addinitgroupsX): Likewise. * nscd/servicescache.c (cache_addserv): Likewise. * nscd/pwdcache.c (cache_addpw): Likewise. Remove some debugging code.
This commit is contained in:
parent
d8111eac54
commit
20e498bdb0
26
ChangeLog
26
ChangeLog
@ -1,3 +1,29 @@
|
||||
2009-02-13 Ulrich Drepper <drepper@redhat.com>
|
||||
|
||||
[BZ #5381]
|
||||
* nscd/nscd.h: Remove definitions and declarations for mem_in_flight.
|
||||
Change mempool_alloc prototype.
|
||||
* nscd/mem.c (gc): Don't handle mem_in_flight.
|
||||
(mempool_alloc): Third parameter now only indicates whether this is the
|
||||
first call (to allocate data) or not. If it is, get db rdlock.
|
||||
Release it on error. Don't handle mem_in_flight.
|
||||
* nscd/aicache.c (addhstaiX): Mark he parameter as const.
|
||||
Adjust third parameter of mempool_alloc calls.
|
||||
Nothing to do here in case mempool_alloc fails.
|
||||
Avoid local variable shadowing parameter. No need to get db rdlock
|
||||
before calling cache_add.
|
||||
* nscd/cache.c (cache_add): Adjust call to mempool_alloc. There is
|
||||
no mem_in_flight array anymore.
|
||||
* nscd/connections.c: Remove definition and handling of mem_in_flight.
|
||||
* nscd/grpcache.c (cache_addgr): Adjust third parameter of
|
||||
mempool_alloc calls. Mark he parameter as const. Nothing to do here
|
||||
in case mempool_alloc fails. No need to get db rdlock before calling
|
||||
cache_add.
|
||||
* nscd/hstcache.c (cache_addhst): Likewise.
|
||||
* nscd/initgrcache.c (addinitgroupsX): Likewise.
|
||||
* nscd/servicescache.c (cache_addserv): Likewise.
|
||||
* nscd/pwdcache.c (cache_addpw): Likewise. Remove some debugging code.
|
||||
|
||||
2009-02-11 Ulrich Drepper <drepper@redhat.com>
|
||||
|
||||
* po/lt.po: Update from translation team.
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Cache handling for host lookup.
|
||||
Copyright (C) 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 2004-2008, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
|
||||
|
||||
@ -60,7 +60,8 @@ static const ai_response_header notfound =
|
||||
|
||||
static void
|
||||
addhstaiX (struct database_dyn *db, int fd, request_header *req,
|
||||
void *key, uid_t uid, struct hashentry *he, struct datahead *dh)
|
||||
void *key, uid_t uid, struct hashentry *const he,
|
||||
struct datahead *dh)
|
||||
{
|
||||
/* Search for the entry matching the key. Please note that we don't
|
||||
look again in the table whether the dataset is now available. We
|
||||
@ -172,13 +173,8 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
|
||||
/* Now we can allocate the data structure. If the TTL of the
|
||||
entry is reported as zero do not cache the entry at all. */
|
||||
if (ttl != 0 && he == NULL)
|
||||
{
|
||||
dataset = (struct dataset *) mempool_alloc (db, total
|
||||
+ req->key_len,
|
||||
IDX_result_data);
|
||||
if (dataset == NULL)
|
||||
++db->head->addfailed;
|
||||
}
|
||||
dataset = (struct dataset *) mempool_alloc (db, total
|
||||
+ req->key_len, 1);
|
||||
|
||||
if (dataset == NULL)
|
||||
{
|
||||
@ -300,9 +296,9 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
|
||||
}
|
||||
else
|
||||
{
|
||||
struct hostent *he = NULL;
|
||||
struct hostent *hstent = NULL;
|
||||
int herrno;
|
||||
struct hostent he_mem;
|
||||
struct hostent hstent_mem;
|
||||
void *addr;
|
||||
size_t addrlen;
|
||||
int addrfamily;
|
||||
@ -326,8 +322,8 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
|
||||
while (1)
|
||||
{
|
||||
rc = __gethostbyaddr2_r (addr, addrlen, addrfamily,
|
||||
&he_mem, tmpbuf, tmpbuflen,
|
||||
&he, &herrno, NULL);
|
||||
&hstent_mem, tmpbuf, tmpbuflen,
|
||||
&hstent, &herrno, NULL);
|
||||
if (rc != ERANGE || herrno != NETDB_INTERNAL)
|
||||
break;
|
||||
tmpbuf = extend_alloca (tmpbuf, tmpbuflen,
|
||||
@ -336,8 +332,8 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
|
||||
|
||||
if (rc == 0)
|
||||
{
|
||||
if (he != NULL)
|
||||
canon = he->h_name;
|
||||
if (hstent != NULL)
|
||||
canon = hstent->h_name;
|
||||
else
|
||||
canon = key;
|
||||
}
|
||||
@ -352,13 +348,8 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
|
||||
/* Now we can allocate the data structure. If the TTL of the
|
||||
entry is reported as zero do not cache the entry at all. */
|
||||
if (ttl != 0 && he == NULL)
|
||||
{
|
||||
dataset = (struct dataset *) mempool_alloc (db, total
|
||||
+ req->key_len,
|
||||
IDX_result_data);
|
||||
if (dataset == NULL)
|
||||
++db->head->addfailed;
|
||||
}
|
||||
dataset = (struct dataset *) mempool_alloc (db, total
|
||||
+ req->key_len, 1);
|
||||
|
||||
if (dataset == NULL)
|
||||
{
|
||||
@ -436,7 +427,7 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
|
||||
appropriate memory and copy it. */
|
||||
struct dataset *newp
|
||||
= (struct dataset *) mempool_alloc (db, total + req->key_len,
|
||||
IDX_result_data);
|
||||
1);
|
||||
if (__builtin_expect (newp != NULL, 1))
|
||||
{
|
||||
/* Adjust pointer into the memory block. */
|
||||
@ -445,8 +436,6 @@ addhstaiX (struct database_dyn *db, int fd, request_header *req,
|
||||
dataset = memcpy (newp, dataset, total + req->key_len);
|
||||
alloca_used = false;
|
||||
}
|
||||
else
|
||||
++db->head->addfailed;
|
||||
|
||||
/* Mark the old record as obsolete. */
|
||||
dh->usable = false;
|
||||
@ -515,8 +504,7 @@ next_nip:
|
||||
if (fd != -1)
|
||||
TEMP_FAILURE_RETRY (send (fd, ¬found, total, MSG_NOSIGNAL));
|
||||
|
||||
dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
|
||||
IDX_result_data);
|
||||
dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len, 1);
|
||||
/* If we cannot permanently store the result, so be it. */
|
||||
if (dataset != NULL)
|
||||
{
|
||||
@ -535,8 +523,6 @@ next_nip:
|
||||
/* Copy the key data. */
|
||||
key_copy = memcpy (dataset->strdata, key, req->key_len);
|
||||
}
|
||||
else
|
||||
++db->head->addfailed;
|
||||
}
|
||||
|
||||
out:
|
||||
@ -554,9 +540,6 @@ next_nip:
|
||||
MS_ASYNC);
|
||||
}
|
||||
|
||||
/* Now get the lock to safely insert the records. */
|
||||
pthread_rwlock_rdlock (&db->lock);
|
||||
|
||||
(void) cache_add (req->type, key_copy, req->key_len, &dataset->head,
|
||||
true, db, uid, he == NULL);
|
||||
|
||||
|
14
nscd/cache.c
14
nscd/cache.c
@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 1998, 1999, 2003-2007, 2008 Free Software Foundation, Inc.
|
||||
/* Copyright (c) 1998, 1999, 2003-2008, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
|
||||
|
||||
@ -155,21 +155,15 @@ cache_add (int type, const void *key, size_t len, struct datahead *packet,
|
||||
unsigned long int hash = __nis_hash (key, len) % table->head->module;
|
||||
struct hashentry *newp;
|
||||
|
||||
newp = mempool_alloc (table, sizeof (struct hashentry), IDX_record_data);
|
||||
newp = mempool_alloc (table, sizeof (struct hashentry), 0);
|
||||
/* If we cannot allocate memory, just do not do anything. */
|
||||
if (newp == NULL)
|
||||
{
|
||||
++table->head->addfailed;
|
||||
|
||||
/* If necessary mark the entry as unusable so that lookups will
|
||||
not use it. */
|
||||
if (first)
|
||||
packet->usable = false;
|
||||
|
||||
/* Mark the in-flight memory as unused. */
|
||||
for (enum in_flight idx = 0; idx < IDX_record_data; ++idx)
|
||||
mem_in_flight.block[idx].dbidx = -1;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -234,10 +228,6 @@ cache_add (int type, const void *key, size_t len, struct datahead *packet,
|
||||
pthread_cond_signal (&table->prune_cond);
|
||||
}
|
||||
|
||||
/* Mark the in-flight memory as unused. */
|
||||
for (enum in_flight idx = 0; idx < IDX_last; ++idx)
|
||||
mem_in_flight.block[idx].dbidx = -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -250,11 +250,6 @@ static int have_accept4;
|
||||
/* Number of times clients had to wait. */
|
||||
unsigned long int client_queued;
|
||||
|
||||
/* Data structure for recording in-flight memory allocation. */
|
||||
__thread struct mem_in_flight mem_in_flight attribute_tls_model_ie;
|
||||
/* Global list of the mem_in_flight variables of all the threads. */
|
||||
struct mem_in_flight *mem_in_flight_list;
|
||||
|
||||
|
||||
ssize_t
|
||||
writeall (int fd, const void *buf, size_t len)
|
||||
@ -1584,16 +1579,6 @@ nscd_run_worker (void *p)
|
||||
{
|
||||
char buf[256];
|
||||
|
||||
/* Initialize the memory-in-flight list. */
|
||||
for (enum in_flight idx = 0; idx < IDX_last; ++idx)
|
||||
mem_in_flight.block[idx].dbidx = -1;
|
||||
/* And queue this threads structure. */
|
||||
do
|
||||
mem_in_flight.next = mem_in_flight_list;
|
||||
while (atomic_compare_and_exchange_bool_acq (&mem_in_flight_list,
|
||||
&mem_in_flight,
|
||||
mem_in_flight.next) != 0);
|
||||
|
||||
/* Initial locking. */
|
||||
pthread_mutex_lock (&readylist_lock);
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Cache handling for group lookup.
|
||||
Copyright (C) 1998-2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 1998-2008, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
|
||||
|
||||
@ -74,7 +74,7 @@ static const gr_response_header notfound =
|
||||
static void
|
||||
cache_addgr (struct database_dyn *db, int fd, request_header *req,
|
||||
const void *key, struct group *grp, uid_t owner,
|
||||
struct hashentry *he, struct datahead *dh, int errval)
|
||||
struct hashentry *const he, struct datahead *dh, int errval)
|
||||
{
|
||||
ssize_t total;
|
||||
ssize_t written;
|
||||
@ -114,7 +114,7 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
|
||||
MSG_NOSIGNAL));
|
||||
|
||||
dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
|
||||
IDX_result_data);
|
||||
1);
|
||||
/* If we cannot permanently store the result, so be it. */
|
||||
if (dataset != NULL)
|
||||
{
|
||||
@ -143,9 +143,6 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
|
||||
+ sizeof (struct dataset) + req->key_len, MS_ASYNC);
|
||||
}
|
||||
|
||||
/* Now get the lock to safely insert the records. */
|
||||
pthread_rwlock_rdlock (&db->lock);
|
||||
|
||||
(void) cache_add (req->type, &dataset->strdata, req->key_len,
|
||||
&dataset->head, true, db, owner, he == NULL);
|
||||
|
||||
@ -155,8 +152,6 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
|
||||
if (dh != NULL)
|
||||
dh->usable = false;
|
||||
}
|
||||
else
|
||||
++db->head->addfailed;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -202,12 +197,7 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
|
||||
dataset = NULL;
|
||||
|
||||
if (he == NULL)
|
||||
{
|
||||
dataset = (struct dataset *) mempool_alloc (db, total + n,
|
||||
IDX_result_data);
|
||||
if (dataset == NULL)
|
||||
++db->head->addfailed;
|
||||
}
|
||||
dataset = (struct dataset *) mempool_alloc (db, total + n, 1);
|
||||
|
||||
if (dataset == NULL)
|
||||
{
|
||||
@ -277,8 +267,7 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
|
||||
/* We have to create a new record. Just allocate
|
||||
appropriate memory and copy it. */
|
||||
struct dataset *newp
|
||||
= (struct dataset *) mempool_alloc (db, total + n,
|
||||
IDX_result_data);
|
||||
= (struct dataset *) mempool_alloc (db, total + n, 1);
|
||||
if (newp != NULL)
|
||||
{
|
||||
/* Adjust pointers into the memory block. */
|
||||
@ -289,8 +278,6 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
|
||||
dataset = memcpy (newp, dataset, total + n);
|
||||
alloca_used = false;
|
||||
}
|
||||
else
|
||||
++db->head->addfailed;
|
||||
|
||||
/* Mark the old record as obsolete. */
|
||||
dh->usable = false;
|
||||
@ -343,9 +330,6 @@ cache_addgr (struct database_dyn *db, int fd, request_header *req,
|
||||
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
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Cache handling for host lookup.
|
||||
Copyright (C) 1998-2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 1998-2008, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
|
||||
|
||||
@ -80,7 +80,7 @@ static const hst_response_header notfound =
|
||||
static void
|
||||
cache_addhst (struct database_dyn *db, int fd, request_header *req,
|
||||
const void *key, struct hostent *hst, uid_t owner,
|
||||
struct hashentry *he, struct datahead *dh, int errval,
|
||||
struct hashentry *const he, struct datahead *dh, int errval,
|
||||
int32_t ttl)
|
||||
{
|
||||
bool all_written = true;
|
||||
@ -120,7 +120,7 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req,
|
||||
all_written = false;
|
||||
|
||||
dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
|
||||
IDX_result_data);
|
||||
1);
|
||||
/* If we cannot permanently store the result, so be it. */
|
||||
if (dataset != NULL)
|
||||
{
|
||||
@ -150,9 +150,6 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req,
|
||||
+ sizeof (struct dataset) + req->key_len, MS_ASYNC);
|
||||
}
|
||||
|
||||
/* Now get the lock to safely insert the records. */
|
||||
pthread_rwlock_rdlock (&db->lock);
|
||||
|
||||
(void) cache_add (req->type, &dataset->strdata, req->key_len,
|
||||
&dataset->head, true, db, owner, he == NULL);
|
||||
|
||||
@ -162,8 +159,6 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req,
|
||||
if (dh != NULL)
|
||||
dh->usable = false;
|
||||
}
|
||||
else
|
||||
++db->head->addfailed;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -221,13 +216,8 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req,
|
||||
questionable whether it is worthwhile complicating the cache
|
||||
handling just for handling such a special case. */
|
||||
if (he == NULL && h_addr_list_cnt == 1)
|
||||
{
|
||||
dataset = (struct dataset *) mempool_alloc (db,
|
||||
total + req->key_len,
|
||||
IDX_result_data);
|
||||
if (dataset == NULL)
|
||||
++db->head->addfailed;
|
||||
}
|
||||
dataset = (struct dataset *) mempool_alloc (db, total + req->key_len,
|
||||
1);
|
||||
|
||||
if (dataset == NULL)
|
||||
{
|
||||
@ -316,7 +306,7 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req,
|
||||
struct dataset *newp
|
||||
= (struct dataset *) mempool_alloc (db,
|
||||
total + req->key_len,
|
||||
IDX_result_data);
|
||||
1);
|
||||
if (newp != NULL)
|
||||
{
|
||||
/* Adjust pointers into the memory block. */
|
||||
@ -329,8 +319,6 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req,
|
||||
dataset = memcpy (newp, dataset, total + req->key_len);
|
||||
alloca_used = false;
|
||||
}
|
||||
else
|
||||
++db->head->addfailed;
|
||||
}
|
||||
|
||||
/* Mark the old record as obsolete. */
|
||||
@ -400,9 +388,6 @@ cache_addhst (struct database_dyn *db, int fd, request_header *req,
|
||||
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
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Cache handling for host lookup.
|
||||
Copyright (C) 2004, 2005, 2006, 2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 2004, 2005, 2006, 2008, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@redhat.com>, 2004.
|
||||
|
||||
@ -54,7 +54,7 @@ static const initgr_response_header notfound =
|
||||
|
||||
static void
|
||||
addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
|
||||
void *key, uid_t uid, struct hashentry *he,
|
||||
void *key, uid_t uid, struct hashentry *const he,
|
||||
struct datahead *dh)
|
||||
{
|
||||
/* Search for the entry matching the key. Please note that we don't
|
||||
@ -198,7 +198,7 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
|
||||
MSG_NOSIGNAL));
|
||||
|
||||
dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
|
||||
IDX_result_data);
|
||||
1);
|
||||
/* If we cannot permanently store the result, so be it. */
|
||||
if (dataset != NULL)
|
||||
{
|
||||
@ -227,9 +227,6 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
|
||||
+ sizeof (struct dataset) + req->key_len, MS_ASYNC);
|
||||
}
|
||||
|
||||
/* Now get the lock to safely insert the records. */
|
||||
pthread_rwlock_rdlock (&db->lock);
|
||||
|
||||
(void) cache_add (req->type, key_copy, req->key_len,
|
||||
&dataset->head, true, db, uid, he == NULL);
|
||||
|
||||
@ -239,8 +236,6 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
|
||||
if (dh != NULL)
|
||||
dh->usable = false;
|
||||
}
|
||||
else
|
||||
++db->head->addfailed;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -257,13 +252,8 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
|
||||
dataset = NULL;
|
||||
|
||||
if (he == NULL)
|
||||
{
|
||||
dataset = (struct dataset *) mempool_alloc (db,
|
||||
total + req->key_len,
|
||||
IDX_result_data);
|
||||
if (dataset == NULL)
|
||||
++db->head->addfailed;
|
||||
}
|
||||
dataset = (struct dataset *) mempool_alloc (db, total + req->key_len,
|
||||
1);
|
||||
|
||||
if (dataset == NULL)
|
||||
{
|
||||
@ -334,7 +324,7 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
|
||||
appropriate memory and copy it. */
|
||||
struct dataset *newp
|
||||
= (struct dataset *) mempool_alloc (db, total + req->key_len,
|
||||
IDX_result_data);
|
||||
1);
|
||||
if (newp != NULL)
|
||||
{
|
||||
/* Adjust pointer into the memory block. */
|
||||
@ -343,8 +333,6 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
|
||||
dataset = memcpy (newp, dataset, total + req->key_len);
|
||||
alloca_used = false;
|
||||
}
|
||||
else
|
||||
++db->head->addfailed;
|
||||
|
||||
/* Mark the old record as obsolete. */
|
||||
dh->usable = false;
|
||||
@ -398,9 +386,6 @@ addinitgroupsX (struct database_dyn *db, int fd, request_header *req,
|
||||
req->key_len, MS_ASYNC);
|
||||
}
|
||||
|
||||
/* Now get the lock to safely insert the records. */
|
||||
pthread_rwlock_rdlock (&db->lock);
|
||||
|
||||
(void) cache_add (INITGROUPS, cp, req->key_len, &dataset->head, true,
|
||||
db, uid, he == NULL);
|
||||
|
||||
|
42
nscd/mem.c
42
nscd/mem.c
@ -197,32 +197,6 @@ gc (struct database_dyn *db)
|
||||
}
|
||||
assert (cnt == db->head->nentries);
|
||||
|
||||
/* Go through the list of in-flight memory blocks. */
|
||||
struct mem_in_flight *mrunp = mem_in_flight_list;
|
||||
while (mrunp != NULL)
|
||||
{
|
||||
/* NB: There can be no race between this test and another thread
|
||||
setting the field to the index we are looking for because
|
||||
this would require the other thread to also have the memlock
|
||||
for the database.
|
||||
|
||||
NB2: we do not have to look at latter blocks (higher indices) if
|
||||
earlier blocks are not in flight. They are always allocated in
|
||||
sequence. */
|
||||
for (enum in_flight idx = IDX_result_data;
|
||||
idx < IDX_last && mrunp->block[idx].dbidx == db - dbs; ++idx)
|
||||
{
|
||||
assert (mrunp->block[idx].blockoff >= 0);
|
||||
assert (mrunp->block[idx].blocklen < db->memsize);
|
||||
assert (mrunp->block[idx].blockoff
|
||||
+ mrunp->block[0].blocklen <= db->memsize);
|
||||
markrange (mark, mrunp->block[idx].blockoff,
|
||||
mrunp->block[idx].blocklen);
|
||||
}
|
||||
|
||||
mrunp = mrunp->next;
|
||||
}
|
||||
|
||||
/* Sort the entries by the addresses of the referenced data. All
|
||||
the entries pointing to the same DATAHEAD object will have the
|
||||
same key. Stability of the sorting is unimportant. */
|
||||
@ -540,13 +514,16 @@ gc (struct database_dyn *db)
|
||||
|
||||
|
||||
void *
|
||||
mempool_alloc (struct database_dyn *db, size_t len, enum in_flight idx)
|
||||
mempool_alloc (struct database_dyn *db, size_t len, int data_alloc)
|
||||
{
|
||||
/* Make sure LEN is a multiple of our maximum alignment so we can
|
||||
keep track of used memory is multiples of this alignment value. */
|
||||
if ((len & BLOCK_ALIGN_M1) != 0)
|
||||
len += BLOCK_ALIGN - (len & BLOCK_ALIGN_M1);
|
||||
|
||||
if (data_alloc)
|
||||
pthread_rwlock_rdlock (&db->lock);
|
||||
|
||||
pthread_mutex_lock (&db->memlock);
|
||||
|
||||
assert ((db->head->first_free & BLOCK_ALIGN_M1) == 0);
|
||||
@ -589,6 +566,9 @@ mempool_alloc (struct database_dyn *db, size_t len, enum in_flight idx)
|
||||
}
|
||||
}
|
||||
|
||||
if (data_alloc)
|
||||
pthread_rwlock_unlock (&db->lock);
|
||||
|
||||
if (! db->last_alloc_failed)
|
||||
{
|
||||
dbg_log (_("no more memory for database '%s'"), dbnames[db - dbs]);
|
||||
@ -596,17 +576,13 @@ mempool_alloc (struct database_dyn *db, size_t len, enum in_flight idx)
|
||||
db->last_alloc_failed = true;
|
||||
}
|
||||
|
||||
++db->head->addfailed;
|
||||
|
||||
/* No luck. */
|
||||
res = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Remember that we have allocated this memory. */
|
||||
assert (idx >= 0 && idx < IDX_last);
|
||||
mem_in_flight.block[idx].dbidx = db - dbs;
|
||||
mem_in_flight.block[idx].blocklen = len;
|
||||
mem_in_flight.block[idx].blockoff = db->head->first_free;
|
||||
|
||||
db->head->first_free += len;
|
||||
|
||||
db->last_alloc_failed = false;
|
||||
|
30
nscd/nscd.h
30
nscd/nscd.h
@ -1,5 +1,4 @@
|
||||
/* Copyright (c) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008
|
||||
Free Software Foundation, Inc.
|
||||
/* Copyright (c) 1998-2001, 2003-2008, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Thorsten Kukuk <kukuk@suse.de>, 1998.
|
||||
|
||||
@ -184,31 +183,6 @@ extern uid_t old_uid;
|
||||
extern gid_t old_gid;
|
||||
|
||||
|
||||
/* Memory allocation in flight. Each thread can have a limited number
|
||||
of allocation in flight. No need to create dynamic data
|
||||
structures. We use fixed indices. */
|
||||
enum in_flight
|
||||
{
|
||||
IDX_result_data = 0,
|
||||
/* Keep the IDX_record_data entry last at all times. */
|
||||
IDX_record_data = 1,
|
||||
IDX_last
|
||||
};
|
||||
extern __thread struct mem_in_flight
|
||||
{
|
||||
struct
|
||||
{
|
||||
int dbidx;
|
||||
nscd_ssize_t blocklen;
|
||||
nscd_ssize_t blockoff;
|
||||
} block[IDX_last];
|
||||
|
||||
struct mem_in_flight *next;
|
||||
} mem_in_flight attribute_tls_model_ie;
|
||||
/* Global list of the mem_in_flight variables of all the threads. */
|
||||
extern struct mem_in_flight *mem_in_flight_list;
|
||||
|
||||
|
||||
/* Prototypes for global functions. */
|
||||
|
||||
/* nscd.c */
|
||||
@ -301,7 +275,7 @@ extern void readdservbyport (struct database_dyn *db, struct hashentry *he,
|
||||
|
||||
/* mem.c */
|
||||
extern void *mempool_alloc (struct database_dyn *db, size_t len,
|
||||
enum in_flight idx);
|
||||
int data_alloc);
|
||||
extern void gc (struct database_dyn *db);
|
||||
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Cache handling for passwd lookup.
|
||||
Copyright (C) 1998-2005, 2006, 2007, 2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 1998-2008, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
|
||||
|
||||
@ -80,7 +80,7 @@ static const pw_response_header notfound =
|
||||
static void
|
||||
cache_addpw (struct database_dyn *db, int fd, request_header *req,
|
||||
const void *key, struct passwd *pwd, uid_t owner,
|
||||
struct hashentry *he, struct datahead *dh, int errval)
|
||||
struct hashentry *const he, struct datahead *dh, int errval)
|
||||
{
|
||||
ssize_t total;
|
||||
ssize_t written;
|
||||
@ -121,7 +121,7 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
|
||||
MSG_NOSIGNAL));
|
||||
|
||||
dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
|
||||
IDX_result_data);
|
||||
1);
|
||||
/* If we cannot permanently store the result, so be it. */
|
||||
if (dataset != NULL)
|
||||
{
|
||||
@ -150,9 +150,6 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
|
||||
+ sizeof (struct dataset) + req->key_len, MS_ASYNC);
|
||||
}
|
||||
|
||||
/* Now get the lock to safely insert the records. */
|
||||
pthread_rwlock_rdlock (&db->lock);
|
||||
|
||||
(void) cache_add (req->type, key_copy, req->key_len,
|
||||
&dataset->head, true, db, owner, he == NULL);
|
||||
|
||||
@ -162,8 +159,6 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
|
||||
if (dh != NULL)
|
||||
dh->usable = false;
|
||||
}
|
||||
else
|
||||
++db->head->addfailed;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -197,12 +192,7 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
|
||||
dataset = NULL;
|
||||
|
||||
if (he == NULL)
|
||||
{
|
||||
dataset = (struct dataset *) mempool_alloc (db, total + n,
|
||||
IDX_result_data);
|
||||
if (dataset == NULL)
|
||||
++db->head->addfailed;
|
||||
}
|
||||
dataset = (struct dataset *) mempool_alloc (db, total + n, 1);
|
||||
|
||||
if (dataset == NULL)
|
||||
{
|
||||
@ -257,19 +247,10 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
|
||||
{
|
||||
assert (fd == -1);
|
||||
|
||||
#if 0
|
||||
if (dataset->head.datasize == dh->allocsize
|
||||
if (dataset->head.allocsize == dh->allocsize
|
||||
&& dataset->head.recsize == dh->recsize
|
||||
&& memcmp (&dataset->resp, dh->data,
|
||||
dh->allocsize - offsetof (struct dataset, resp)) == 0)
|
||||
#else
|
||||
if (dataset->head.allocsize != dh->allocsize)
|
||||
goto nnn;
|
||||
if (dataset->head.recsize != dh->recsize)
|
||||
goto nnn;
|
||||
if(memcmp (&dataset->resp, dh->data,
|
||||
dh->allocsize - offsetof (struct dataset, resp)) == 0)
|
||||
#endif
|
||||
{
|
||||
/* The data has not changed. We will just bump the
|
||||
timeout value. Note that the new record has been
|
||||
@ -279,12 +260,10 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
|
||||
}
|
||||
else
|
||||
{
|
||||
nnn:;
|
||||
/* We have to create a new record. Just allocate
|
||||
appropriate memory and copy it. */
|
||||
struct dataset *newp
|
||||
= (struct dataset *) mempool_alloc (db, total + n,
|
||||
IDX_result_data);
|
||||
= (struct dataset *) mempool_alloc (db, total + n, 1);
|
||||
if (newp != NULL)
|
||||
{
|
||||
/* Adjust pointer into the memory block. */
|
||||
@ -294,8 +273,6 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
|
||||
dataset = memcpy (newp, dataset, total + n);
|
||||
alloca_used = false;
|
||||
}
|
||||
else
|
||||
++db->head->addfailed;
|
||||
|
||||
/* Mark the old record as obsolete. */
|
||||
dh->usable = false;
|
||||
@ -349,9 +326,6 @@ cache_addpw (struct database_dyn *db, int fd, request_header *req,
|
||||
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
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Cache handling for services lookup.
|
||||
Copyright (C) 2007, 2008 Free Software Foundation, Inc.
|
||||
Copyright (C) 2007, 2008, 2009 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Contributed by Ulrich Drepper <drepper@drepper.com>, 2007.
|
||||
|
||||
@ -64,7 +64,7 @@ static const serv_response_header notfound =
|
||||
static void
|
||||
cache_addserv (struct database_dyn *db, int fd, request_header *req,
|
||||
const void *key, struct servent *serv, uid_t owner,
|
||||
struct hashentry *he, struct datahead *dh, int errval)
|
||||
struct hashentry *const he, struct datahead *dh, int errval)
|
||||
{
|
||||
ssize_t total;
|
||||
ssize_t written;
|
||||
@ -104,7 +104,7 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req,
|
||||
MSG_NOSIGNAL));
|
||||
|
||||
dataset = mempool_alloc (db, sizeof (struct dataset) + req->key_len,
|
||||
IDX_result_data);
|
||||
1);
|
||||
/* If we cannot permanently store the result, so be it. */
|
||||
if (dataset != NULL)
|
||||
{
|
||||
@ -133,9 +133,6 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req,
|
||||
+ sizeof (struct dataset) + req->key_len, MS_ASYNC);
|
||||
}
|
||||
|
||||
/* Now get the lock to safely insert the records. */
|
||||
pthread_rwlock_rdlock (&db->lock);
|
||||
|
||||
(void) cache_add (req->type, &dataset->strdata, req->key_len,
|
||||
&dataset->head, true, db, owner, he == NULL);
|
||||
|
||||
@ -145,8 +142,6 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req,
|
||||
if (dh != NULL)
|
||||
dh->usable = false;
|
||||
}
|
||||
else
|
||||
++db->head->addfailed;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -187,13 +182,8 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req,
|
||||
dataset = NULL;
|
||||
|
||||
if (he == NULL)
|
||||
{
|
||||
dataset = (struct dataset *) mempool_alloc (db,
|
||||
total + req->key_len,
|
||||
IDX_result_data);
|
||||
if (dataset == NULL)
|
||||
++db->head->addfailed;
|
||||
}
|
||||
dataset = (struct dataset *) mempool_alloc (db, total + req->key_len,
|
||||
1);
|
||||
|
||||
if (dataset == NULL)
|
||||
{
|
||||
@ -262,7 +252,7 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req,
|
||||
appropriate memory and copy it. */
|
||||
struct dataset *newp
|
||||
= (struct dataset *) mempool_alloc (db, total + req->key_len,
|
||||
IDX_result_data);
|
||||
1);
|
||||
if (newp != NULL)
|
||||
{
|
||||
/* Adjust pointers into the memory block. */
|
||||
@ -273,8 +263,6 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req,
|
||||
dataset = memcpy (newp, dataset, total + req->key_len);
|
||||
alloca_used = false;
|
||||
}
|
||||
else
|
||||
++db->head->addfailed;
|
||||
|
||||
/* Mark the old record as obsolete. */
|
||||
dh->usable = false;
|
||||
@ -327,9 +315,6 @@ cache_addserv (struct database_dyn *db, int fd, request_header *req,
|
||||
+ total + req->key_len, MS_ASYNC);
|
||||
}
|
||||
|
||||
/* Now get the lock to safely insert the records. */
|
||||
pthread_rwlock_rdlock (&db->lock);
|
||||
|
||||
(void) cache_add (req->type, key_copy, req->key_len,
|
||||
&dataset->head, true, db, owner, he == NULL);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user