Date: Fri, 30 Sep 2005 13:48:41 GMT From: soc-bushman <soc-bushman@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 84550 for review Message-ID: <200509301348.j8UDmfSF051840@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=84550 Change 84550 by soc-bushman@soc-bushman_stinger on 2005/09/30 13:47:57 negative caching fully implemented passwd, services and hosts agents are implemented - soon cached will be able to perform lookups by itself still some problems during self-performed lookups are possible - it requires lot of testing Affected files ... .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/Makefile#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/Makefile.inc#1 add .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/hosts.c#1 add .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/hosts.h#1 add .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/passwd.c#1 add .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/passwd.h#1 add .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/services.c#1 add .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/services.h#1 add .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.8#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf.5#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/hashtable.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/parser.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/parser.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/protocol.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/protocol.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/query.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/query.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/singletons.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/singletons.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/src/include/nscache.h#6 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/getgrent.c#7 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/getpwent.c#9 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/gethostnamadr.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getprotoent.c#8 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getservent.c#18 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nscache.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nsdispatch.c#9 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/rpc/getrpcent.c#9 edit .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/Makefile#3 edit .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/ntp/ntptrace/Makefile#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/pccard/Makefile#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/pmccontrol/pmccontrol.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/powerd/powerd.8#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/powerd/powerd.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/sysinstall/Makefile#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/sysinstall/sysinstall.h#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/syslogd/syslogd.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/getservent.c#6 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscache.c#9 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscache.h#5 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsdispatch.c#9 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsdispatch_test.c#9 edit Differences ... ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/Makefile#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.8#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.c#5 (text+ko) ==== @@ -8,7 +8,7 @@ * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the + * notice, this list of conditions and the following disclaimer in thereg * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND @@ -162,6 +162,7 @@ struct configuration_entry *config_entry; size_t size, i; + int res; TRACE_IN(init_cache_); @@ -176,8 +177,10 @@ * we should register common entries now - multipart entries * would be registered automatically during the queries */ - if (config_entry->c_params->entry_type == CET_COMMON) - register_cache_entry(retval, config_entry->c_params); + res = register_cache_entry(retval, (struct cache_entry_params *) + &config_entry->positive_cache_params); + res = register_cache_entry(retval, (struct cache_entry_params *) + &config_entry->negative_cache_params); } TRACE_OUT(init_cache_); ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf.5#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.c#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.h#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.c#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.h#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.c#5 (text+ko) ==== @@ -48,12 +48,15 @@ static int configuration_entry_cmp(const void *, const void *); static struct configuration_entry *create_configuration_entry(const char *, - uid_t, int, struct timeval const *, struct cache_entry_params const *); + struct timeval const *, struct timeval const *, + struct common_cache_entry_params const *, + struct common_cache_entry_params const *, + struct mp_cache_entry_params const *); static int configuration_entry_cmp(const void *e1, const void *e2) { - struct configuration_entry *entry1; +/* struct configuration_entry *entry1; struct configuration_entry *entry2; int res; @@ -75,23 +78,104 @@ res = 0; } - return (res); + return (res);*/ + return (strcmp((const char *)e1, + (*((struct configuration_entry **)e2))->name + )); } static struct configuration_entry * -create_configuration_entry(const char *name, uid_t desired_euid, - int use_desired_euid, struct timeval const *timeout, - struct cache_entry_params const *params) +create_configuration_entry(const char *name, + struct timeval const *common_timeout, + struct timeval const *mp_timeout, + struct common_cache_entry_params const *positive_params, + struct common_cache_entry_params const *negative_params, + struct mp_cache_entry_params const *mp_params) { - struct configuration_entry *retval; + struct configuration_entry *retval; size_t size; pthread_mutexattr_t attr; - int res; + int res; TRACE_IN(create_configuration_entry); assert(name != NULL); + assert(positive_params != NULL); + assert(negative_params != NULL); + assert(mp_params != NULL); + + + res = pthread_mutexattr_init(&attr); + if (res != 0) { + TRACE_INT(res); + TRACE_OUT(create_configuration_entry); + return (NULL); + } + pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_NORMAL); + + retval = (struct configuration_entry *)malloc( + sizeof(struct configuration_entry)); + assert(retval != NULL); + memset(retval, 0, sizeof(struct configuration_entry)); + + res = pthread_mutex_init(&retval->positive_cache_lock, &attr); + if (res != 0) { + free(retval); + pthread_mutexattr_destroy(&attr); + TRACE_OUT(create_configuration_entry); + return (NULL); + } + + res = pthread_mutex_init(&retval->negative_cache_lock, &attr); + if (res != 0) { + pthread_mutex_destroy(&retval->positive_cache_lock); + free(retval); + pthread_mutexattr_destroy(&attr); + TRACE_OUT(create_configuration_entry); + return (NULL); + } + + res = pthread_mutex_init(&retval->mp_cache_lock, &attr); + if (res != 0) { + pthread_mutex_destroy(&retval->positive_cache_lock); + pthread_mutex_destroy(&retval->negative_cache_lock); + free(retval); + pthread_mutexattr_destroy(&attr); + TRACE_OUT(create_configuration_entry); + return (NULL); + } + + pthread_mutexattr_destroy(&attr); + + memcpy(&retval->positive_cache_params, positive_params, + sizeof(struct common_cache_entry_params)); + memcpy(&retval->negative_cache_params, negative_params, + sizeof(struct common_cache_entry_params)); + memcpy(&retval->mp_cache_params, mp_params, + sizeof(struct mp_cache_entry_params)); - switch (params->entry_type) { + size = strlen(name); + retval->name = (char *)malloc(size + 1); + assert(retval->name != NULL); + memset(retval->name, 0, size + 1); + memcpy(retval->name, name, size); + + memcpy(&retval->common_query_timeout, common_timeout, + sizeof(struct timeval)); + memcpy(&retval->mp_query_timeout, mp_timeout, + sizeof(struct timeval)); + + asprintf(&retval->positive_cache_params.entry_name, "%s+", name); + assert(retval->positive_cache_params.entry_name != NULL); + + asprintf(&retval->negative_cache_params.entry_name, "%s-", name); + assert(retval->negative_cache_params.entry_name != NULL); + + asprintf(&retval->mp_cache_params.entry_name, "%s*", name); + assert(retval->mp_cache_params.entry_name != NULL); + + TRACE_OUT(create_configuration_entry); + return (retval); +/* switch (params->entry_type) { case CET_COMMON: size = sizeof(struct common_cache_entry_params); break; @@ -151,57 +235,52 @@ memcpy(&retval->query_timeout, timeout, sizeof(struct timeval)); TRACE_OUT(create_configuration_entry); - return (retval); + return (retval);*/ } struct configuration_entry * -create_def_configuration_entry(const char *name, enum cache_entry_t type) +create_def_configuration_entry(const char *name) { - struct common_cache_entry_params common_params; + struct common_cache_entry_params positive_params, negative_params; struct mp_cache_entry_params mp_params; - struct timeval default_timeout; + struct timeval default_common_timeout, default_mp_timeout; struct configuration_entry *res = NULL; TRACE_IN(create_def_configuration_entry); - memset(&default_timeout, 0, sizeof(struct timeval)); - switch (type) { - case CET_COMMON: - memset(&common_params, 0, - sizeof(struct common_cache_entry_params)); - common_params.entry_type = CET_COMMON; - common_params.entry_name = (char *)name; - common_params.cache_entries_size = DEFAULT_CACHE_HT_SIZE; - common_params.max_elemsize = 2048; - common_params.satisf_elemsize = 1024; - common_params.max_lifetime.tv_sec = 60 * 60 * 12; - common_params.policy = CPT_LRU; + memset(&positive_params, 0, + sizeof(struct common_cache_entry_params)); + positive_params.entry_type = CET_COMMON; + positive_params.cache_entries_size = DEFAULT_CACHE_HT_SIZE; + positive_params.max_elemsize = 2048; + positive_params.satisf_elemsize = 1024; + positive_params.max_lifetime.tv_sec = 60 * 60 * 12; + positive_params.policy = CPT_LRU; + + memcpy(&negative_params, &positive_params, + sizeof(struct common_cache_entry_params)); + negative_params.max_elemsize = 512; + negative_params.satisf_elemsize = 256; + negative_params.max_lifetime.tv_sec = 60 * 60; + negative_params.policy = CPT_FIFO; - default_timeout.tv_sec = DEFAULT_COMMON_ENTRY_TIMEOUT; + memset(&default_common_timeout, 0, sizeof(struct timeval)); + default_common_timeout.tv_sec = DEFAULT_COMMON_ENTRY_TIMEOUT; + + memset(&default_mp_timeout, 0, sizeof(struct timeval)); + default_mp_timeout.tv_sec = DEFAULT_MP_ENTRY_TIMEOUT; + + memset(&mp_params, 0, + sizeof(struct mp_cache_entry_params)); + mp_params.entry_type = CET_MULTIPART; + mp_params.max_elemsize = 1024 * 8; + mp_params.max_sessions = 1024; + mp_params.max_lifetime.tv_sec = 60 * 60 * 12; - res = create_configuration_entry(name, -1, 0, - &default_timeout, - (struct cache_entry_params *)&common_params); - break; - case CET_MULTIPART: - memset(&mp_params, 0, - sizeof(struct mp_cache_entry_params)); - mp_params.entry_type = CET_MULTIPART; - mp_params.entry_name = (char *)name; - mp_params.max_elemsize = 1024 * 8; - mp_params.max_sessions = 1024; - mp_params.max_lifetime.tv_sec = 60 * 60 * 12; - - default_timeout.tv_sec = DEFAULT_MP_ENTRY_TIMEOUT; - - res = create_configuration_entry(name, -1, 0, - &default_timeout, - (struct cache_entry_params *)&mp_params); - break; - default: - break; - } - + res = create_configuration_entry(name, &default_common_timeout, + &default_mp_timeout, &positive_params, &negative_params, + &mp_params); + TRACE_OUT(create_def_configuration_entry); return (res); } @@ -211,11 +290,14 @@ { TRACE_IN(destroy_configuration_entry); assert(entry != NULL); - pthread_mutex_destroy(&entry->lock); + pthread_mutex_destroy(&entry->positive_cache_lock); + pthread_mutex_destroy(&entry->negative_cache_lock); + pthread_mutex_destroy(&entry->mp_cache_lock); free(entry->name); - if (entry->use_desired_euid != 0) - free(entry->c_params->entry_name); - free(entry->c_params); + free(entry->positive_cache_params.entry_name); + free(entry->negative_cache_params.entry_name); + free(entry->mp_cache_params.entry_name); + free(entry->mp_cache_entries); free(entry); TRACE_OUT(destroy_configuration_entry); } @@ -225,7 +307,9 @@ struct configuration_entry *entry) { TRACE_IN(add_configuration_entry); - if (configuration_find_entry(config, entry) != NULL) { + assert(entry != NULL); + assert(entry->name != NULL); + if (configuration_find_entry(config, entry->name) != NULL) { TRACE_OUT(add_configuration_entry); return (-1); } @@ -558,12 +642,13 @@ struct configuration_entry * configuration_find_entry(struct configuration *config, - struct configuration_entry const *model) + const char *name) { struct configuration_entry **retval; TRACE_IN(configuration_find_entry); - retval = bsearch(&model, config->entries, config->entries_size, + + retval = bsearch(name, config->entries, config->entries_size, sizeof(struct configuration_entry *), configuration_entry_cmp); TRACE_OUT(configuration_find_entry); @@ -595,20 +680,50 @@ } void -configuration_lock_entry(struct configuration_entry *entry) +configuration_lock_entry(struct configuration_entry *entry, + enum config_entry_lock_type lock_type) { TRACE_IN(configuration_lock_entry); assert(entry != NULL); - pthread_mutex_lock(&entry->lock); + + switch (lock_type) { + case CELT_POSITIVE: + pthread_mutex_lock(&entry->positive_cache_lock); + break; + case CELT_NEGATIVE: + pthread_mutex_lock(&entry->negative_cache_lock); + break; + case CELT_MULTIPART: + pthread_mutex_lock(&entry->mp_cache_lock); + break; + default: + /* should be unreachable */ + break; + } TRACE_OUT(configuration_lock_entry); } void -configuration_unlock_entry(struct configuration_entry *entry) +configuration_unlock_entry(struct configuration_entry *entry, + enum config_entry_lock_type lock_type) { TRACE_IN(configuration_unlock_entry); assert(entry != NULL); - pthread_mutex_unlock(&entry->lock); + + switch (lock_type) { + case CELT_POSITIVE: + pthread_mutex_unlock(&entry->positive_cache_lock); + break; + case CELT_NEGATIVE: + pthread_mutex_unlock(&entry->negative_cache_lock); + break; + case CELT_MULTIPART: + pthread_mutex_unlock(&entry->mp_cache_lock); + break; + default: + /* should be unreachable */ + break; + } TRACE_OUT(configuration_unlock_entry); } ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.h#5 (text+ko) ==== @@ -42,15 +42,24 @@ extern const char *c_default_entries[6]; struct configuration_entry { - struct timeval query_timeout; - struct cache_entry_params *c_params; + struct common_cache_entry_params positive_cache_params; + struct common_cache_entry_params negative_cache_params; + struct mp_cache_entry_params mp_cache_params; + + cache_entry positive_cache_entry; + cache_entry negative_cache_entry; + + cache_entry *mp_cache_entries; + size_t mp_cache_entries_size; + + struct timeval common_query_timeout; + struct timeval mp_query_timeout; char *name; - pthread_mutex_t lock; + pthread_mutex_t positive_cache_lock; + pthread_mutex_t negative_cache_lock; + pthread_mutex_t mp_cache_lock; - uid_t desired_euid; - int use_desired_euid; - int perform_actual_lookups; int enabled; }; @@ -73,28 +82,34 @@ int threads_num; }; +enum config_entry_lock_type { + CELT_POSITIVE, + CELT_NEGATIVE, + CELT_MULTIPART +}; + extern struct configuration *init_configuration(void); extern void destroy_configuration(struct configuration *); extern void fill_configuration_defaults(struct configuration *); -/*extern int read_configuration(const char *, struct configuration *, - char const **, int *);*/ extern int add_configuration_entry(struct configuration *, struct configuration_entry *); extern struct configuration_entry *create_def_configuration_entry( - const char *, enum cache_entry_t); + const char *); extern void destroy_configuration_entry(struct configuration_entry *); extern size_t configuration_get_entries_size(struct configuration *); extern struct configuration_entry *configuration_get_entry( struct configuration *, size_t); extern struct configuration_entry *configuration_find_entry( - struct configuration *, struct configuration_entry const *); + struct configuration *, const char *); extern void configuration_lock_rdlock(struct configuration *config); extern void configuration_lock_wrlock(struct configuration *config); extern void configuration_unlock(struct configuration *config); -extern void configuration_lock_entry(struct configuration_entry *); -extern void configuration_unlock_entry(struct configuration_entry *); +extern void configuration_lock_entry(struct configuration_entry *, + enum config_entry_lock_type); +extern void configuration_unlock_entry(struct configuration_entry *, + enum config_entry_lock_type); #endif ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.c#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.h#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/hashtable.h#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.c#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.h#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.c#5 (text+ko) ==== @@ -60,10 +60,11 @@ finalize_comm_element(&qstate->response); if (qstate->mdata != NULL) { - configuration_lock_entry(qstate->config_entry); + configuration_lock_entry(qstate->config_entry, CELT_MULTIPART); close_cache_mp_read_session( (cache_mp_read_session)qstate->mdata); - configuration_unlock_entry(qstate->config_entry); + configuration_unlock_entry(qstate->config_entry, + CELT_MULTIPART); } TRACE_OUT(on_mp_read_session_destroy); } @@ -149,8 +150,8 @@ &qstate->response); c_mp_rs_request = get_cache_mp_read_session_request(&qstate->request); - qstate->config_entry = find_config_entry_by_name_and_euid( - s_configuration, c_mp_rs_request->entry, qstate->euid); + qstate->config_entry = configuration_find_entry( + s_configuration, c_mp_rs_request->entry); if (qstate->config_entry == NULL) { TRACE_MSG("can't find corresponding configuration entry." " aborting request"); @@ -159,7 +160,7 @@ } asprintf(&dec_cache_entry_name, "%s%s", qstate->eid_str, - qstate->config_entry->c_params->entry_name); + qstate->config_entry->mp_cache_params.entry_name); assert(dec_cache_entry_name != NULL); configuration_lock_rdlock(s_configuration); @@ -168,21 +169,22 @@ free(dec_cache_entry_name); if (c_entry != INVALID_CACHE_ENTRY) { - configuration_lock_entry(qstate->config_entry); + configuration_lock_entry(qstate->config_entry, CELT_MULTIPART); rs = open_cache_mp_read_session(c_entry); if (rs == INVALID_CACHE_MP_READ_SESSION) c_mp_rs_response->error_code = -1; else { - qstate->mdata = rs; - qstate->destroy_func = on_mp_read_session_destroy; + qstate->mdata = rs; + qstate->destroy_func = on_mp_read_session_destroy; - if ((qstate->config_entry->query_timeout.tv_sec != 0) || - (qstate->config_entry->query_timeout.tv_usec != 0)) - memcpy(&qstate->timeout, - &qstate->config_entry->query_timeout, - sizeof(struct timeval)); + if ((qstate->config_entry->mp_query_timeout.tv_sec != 0) || + (qstate->config_entry->mp_query_timeout.tv_usec != 0)) + memcpy(&qstate->timeout, + &qstate->config_entry->mp_query_timeout, + sizeof(struct timeval)); } - configuration_unlock_entry(qstate->config_entry); + configuration_unlock_entry(qstate->config_entry, + CELT_MULTIPART); } else c_mp_rs_response->error_code = -1; @@ -271,7 +273,7 @@ read_response = get_cache_mp_read_session_read_response( &qstate->response); - configuration_lock_entry(qstate->config_entry); + configuration_lock_entry(qstate->config_entry, CELT_MULTIPART); read_response->error_code = cache_mp_read( (cache_mp_read_session)qstate->mdata, NULL, &read_response->data_size); @@ -285,7 +287,7 @@ read_response->data, &read_response->data_size); } - configuration_unlock_entry(qstate->config_entry); + configuration_unlock_entry(qstate->config_entry, CELT_MULTIPART); if (read_response->error_code == 0) qstate->kevent_watermark = sizeof(size_t) + sizeof(int); @@ -374,9 +376,9 @@ on_mp_read_session_close_notification(struct query_state *qstate) { TRACE_IN(on_mp_read_session_close_notification); - configuration_lock_entry(qstate->config_entry); + configuration_lock_entry(qstate->config_entry, CELT_MULTIPART); close_cache_mp_read_session((cache_mp_read_session)qstate->mdata); - configuration_unlock_entry(qstate->config_entry); + configuration_unlock_entry(qstate->config_entry, CELT_MULTIPART); qstate->mdata = NULL; qstate->kevent_watermark = 0; qstate->process_func = NULL; ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.h#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.c#5 (text+ko) ==== @@ -62,10 +62,11 @@ finalize_comm_element(&qstate->response); if (qstate->mdata != NULL) { - configuration_lock_entry(qstate->config_entry); + configuration_lock_entry(qstate->config_entry, CELT_MULTIPART); abandon_cache_mp_write_session( (cache_mp_write_session)qstate->mdata); - configuration_unlock_entry(qstate->config_entry); + configuration_unlock_entry(qstate->config_entry, + CELT_MULTIPART); } TRACE_OUT(on_mp_write_session_destroy); } @@ -143,7 +144,7 @@ struct cache_mp_write_session_request *c_mp_ws_request; struct cache_mp_write_session_response *c_mp_ws_response; cache_mp_write_session ws; - cache_entry c_entry; + cache_entry c_entry, *new_mp_entries, *old_mp_entries; char *dec_cache_entry_name, *en_bkp; TRACE_IN(on_mp_write_session_request_process); @@ -152,17 +153,24 @@ &qstate->response); c_mp_ws_request = get_cache_mp_write_session_request(&qstate->request); - qstate->config_entry = find_config_entry_by_name_and_euid( - s_configuration, c_mp_ws_request->entry, qstate->euid); + qstate->config_entry = configuration_find_entry( + s_configuration, c_mp_ws_request->entry); if (qstate->config_entry == NULL) { TRACE_MSG("can't find corresponding configuration entry. " "aborting request"); TRACE_OUT(on_write_request_process); return (-1); } - + + if (qstate->config_entry->perform_actual_lookups != 0) { + TRACE_MSG( + "entry performs lookups by itself: can't write to it"); + TRACE_OUT(on_write_request_process); + return (-1); + } + asprintf(&dec_cache_entry_name, "%s%s", qstate->eid_str, - qstate->config_entry->c_params->entry_name); + qstate->config_entry->mp_cache_params.entry_name); assert(dec_cache_entry_name != NULL); configuration_lock_rdlock(s_configuration); @@ -170,25 +178,44 @@ dec_cache_entry_name); configuration_unlock(s_configuration); if (c_entry == INVALID_CACHE_ENTRY) { + configuration_lock_entry(qstate->config_entry, CELT_MULTIPART); + configuration_lock_wrlock(s_configuration); - configuration_lock_entry(qstate->config_entry); - en_bkp = qstate->config_entry->c_params->entry_name; - qstate->config_entry->c_params->entry_name = + en_bkp = qstate->config_entry->mp_cache_params.entry_name; + qstate->config_entry->mp_cache_params.entry_name = dec_cache_entry_name; - register_cache_entry(s_cache, qstate->config_entry->c_params); - qstate->config_entry->c_params->entry_name = en_bkp; - configuration_unlock_entry(qstate->config_entry); + register_cache_entry(s_cache, (struct cache_entry_params *) + &qstate->config_entry->mp_cache_params); + qstate->config_entry->mp_cache_params.entry_name = en_bkp; configuration_unlock(s_configuration); configuration_lock_rdlock(s_configuration); c_entry = find_cache_entry(s_cache, dec_cache_entry_name); configuration_unlock(s_configuration); + + ++qstate->config_entry->mp_cache_entries_size; + new_mp_entries = (cache_entry *)malloc(sizeof(cache_entry) * + qstate->config_entry->mp_cache_entries_size); + assert(new_mp_entries != NULL); + new_mp_entries[0] = c_entry; + if (qstate->config_entry->mp_cache_entries_size -1 > 0) { + memcpy(new_mp_entries + 1, + qstate->config_entry->mp_cache_entries, + qstate->config_entry->mp_cache_entries_size - 1); + } + + old_mp_entries = qstate->config_entry->mp_cache_entries; + qstate->config_entry->mp_cache_entries = new_mp_entries; + free(old_mp_entries); + + configuration_unlock_entry(qstate->config_entry, + CELT_MULTIPART); } free(dec_cache_entry_name); assert(c_entry != NULL); - configuration_lock_entry(qstate->config_entry); + configuration_lock_entry(qstate->config_entry, CELT_MULTIPART); ws = open_cache_mp_write_session(c_entry); if (ws == INVALID_CACHE_MP_WRITE_SESSION) c_mp_ws_response->error_code = -1; @@ -196,13 +223,13 @@ qstate->mdata = ws; qstate->destroy_func = on_mp_write_session_destroy; - if ((qstate->config_entry->query_timeout.tv_sec != 0) || - (qstate->config_entry->query_timeout.tv_usec != 0)) + if ((qstate->config_entry->mp_query_timeout.tv_sec != 0) || + (qstate->config_entry->mp_query_timeout.tv_usec != 0)) memcpy(&qstate->timeout, - &qstate->config_entry->query_timeout, + &qstate->config_entry->mp_query_timeout, sizeof(struct timeval)); } - configuration_unlock_entry(qstate->config_entry); + configuration_unlock_entry(qstate->config_entry, CELT_MULTIPART); qstate->process_func = on_mp_write_session_response_write1; qstate->kevent_watermark = sizeof(int); @@ -358,12 +385,12 @@ write_request = get_cache_mp_write_session_write_request( &qstate->request); - configuration_lock_entry(qstate->config_entry); + configuration_lock_entry(qstate->config_entry, CELT_MULTIPART); write_response->error_code = cache_mp_write( (cache_mp_write_session)qstate->mdata, write_request->data, write_request->data_size); - configuration_unlock_entry(qstate->config_entry); + configuration_unlock_entry(qstate->config_entry, CELT_MULTIPART); qstate->kevent_watermark = sizeof(int); qstate->process_func = on_mp_write_session_write_response_write1; @@ -409,9 +436,9 @@ on_mp_write_session_abandon_notification(struct query_state *qstate) { TRACE_IN(on_mp_write_session_abandon_notification); - configuration_lock_entry(qstate->config_entry); + configuration_lock_entry(qstate->config_entry, CELT_MULTIPART); abandon_cache_mp_write_session((cache_mp_write_session)qstate->mdata); - configuration_unlock_entry(qstate->config_entry); + configuration_unlock_entry(qstate->config_entry, CELT_MULTIPART); qstate->mdata = INVALID_CACHE_MP_WRITE_SESSION; qstate->kevent_watermark = 0; @@ -424,9 +451,9 @@ on_mp_write_session_close_notification(struct query_state *qstate) { TRACE_IN(on_mp_write_session_close_notification); - configuration_lock_entry(qstate->config_entry); + configuration_lock_entry(qstate->config_entry, CELT_MULTIPART); close_cache_mp_write_session((cache_mp_write_session)qstate->mdata); - configuration_unlock_entry(qstate->config_entry); + configuration_unlock_entry(qstate->config_entry, CELT_MULTIPART); qstate->mdata = INVALID_CACHE_MP_WRITE_SESSION; qstate->kevent_watermark = 0; ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.h#5 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/parser.c#5 (text+ko) ==== @@ -33,16 +33,9 @@ #include "log.h" #include "parser.h" -enum entry_use_type { - EUT_COMMON = 0, - EUT_MULTIPART = 1, - EUT_NEGATIVE = 2, - EUT_MAX = 3 -}; - static void enable_cache(struct configuration *,const char *, int); static struct configuration_entry *find_create_entry(struct configuration *, - const char *, enum entry_use_type); + const char *); static int get_number(const char *, int, int); static enum cache_policy_t get_policy(const char *); static int get_yesno(const char *); @@ -86,61 +79,20 @@ static struct configuration_entry * find_create_entry(struct configuration *config, - const char *entry_name, enum entry_use_type use_type) + const char *entry_name) { struct configuration_entry *entry = NULL; - struct configuration_entry model; - enum cache_entry_t entry_type; int res; - TRACE_IN(find_create_entry); - memset(&model, 0, sizeof(struct configuration_entry)); - switch (use_type) { - case EUT_COMMON: - model.name = (char *)entry_name; - break; - case EUT_MULTIPART: - asprintf(&model.name, "%s_mp", entry_name); - assert(model.name != NULL); - break; - case EUT_NEGATIVE: - asprintf(&model.name, "%s_neg", entry_name); - assert(model.name != NULL); - break; - default: - /* should be unreachable */ - break; - } - - - entry = configuration_find_entry(config, &model); + TRACE_IN(find_create_entry); + entry = configuration_find_entry(config, entry_name); if (entry == NULL) { - switch (use_type) { - case EUT_COMMON: - case EUT_NEGATIVE: - entry_type = CET_COMMON; - break; - case EUT_MULTIPART: - entry_type = CET_MULTIPART; - break; - default: - /* should be unreachable */ - break; - } - entry = create_def_configuration_entry(model.name, entry_type); + entry = create_def_configuration_entry(entry_name); assert( entry != NULL); res = add_configuration_entry(config, entry); assert(res == 0); } - switch (use_type) { - case EUT_MULTIPART: - case EUT_NEGATIVE: - free(model.name); - break; - default: - break; - } TRACE_OUT(find_create_entry); return (entry); } @@ -149,14 +101,10 @@ enable_cache(struct configuration *config, const char *entry_name, int flag) { struct configuration_entry *entry; - int i; TRACE_IN(enable_cache); - for (i = 0; i < EUT_MAX; ++i) { - entry = find_create_entry(config, entry_name, i); - assert(entry != NULL); - entry->enabled = flag; - } + entry = find_create_entry(config, entry_name); + entry->enabled = flag; TRACE_OUT(enable_cache); } @@ -173,17 +121,12 @@ memset(&lifetime, 0, sizeof(struct timeval)); lifetime.tv_sec = ttl; - entry = find_create_entry(config, entry_name, EUT_COMMON); - assert(entry->c_params->entry_type == CET_COMMON); - memcpy(&((struct common_cache_entry_params *) - entry->c_params)->max_lifetime, + entry = find_create_entry(config, entry_name); + memcpy(&entry->positive_cache_params.max_lifetime, + &lifetime, sizeof(struct timeval)); + memcpy(&entry->mp_cache_params.max_lifetime, &lifetime, sizeof(struct timeval)); - entry = find_create_entry(config, entry_name, EUT_MULTIPART); - assert(entry->c_params->entry_type == CET_MULTIPART); - memcpy(&((struct mp_cache_entry_params *)entry->c_params)->max_lifetime, - &lifetime, sizeof(struct timeval)); - TRACE_OUT(set_positive_time_to_live); } @@ -200,12 +143,10 @@ memset(&lifetime, 0, sizeof(struct timeval)); lifetime.tv_sec = nttl; - entry = find_create_entry(config, entry_name, EUT_NEGATIVE); + entry = find_create_entry(config, entry_name); assert(entry != NULL); - assert(entry->c_params->entry_type == CET_COMMON); - memcpy(&((struct common_cache_entry_params *) - entry->c_params)->max_lifetime, - &lifetime, sizeof(struct timeval)); + memcpy(&entry->negative_cache_params.max_lifetime, + &lifetime, sizeof(struct timeval)); TRACE_OUT(set_negative_time_to_live); } @@ -220,17 +161,13 @@ assert(count >= 0); assert(entry_name != NULL); - entry = find_create_entry(config, entry_name, EUT_COMMON); + entry = find_create_entry(config, entry_name); assert(entry != NULL); - assert(entry->c_params->entry_type == CET_COMMON); - ((struct common_cache_entry_params *) - entry->c_params)->max_elemsize = count; + entry->positive_cache_params.max_elemsize = count; - entry = find_create_entry(config, entry_name, EUT_NEGATIVE); + entry = find_create_entry(config, entry_name); assert(entry != NULL); - assert(entry->c_params->entry_type == CET_COMMON); - ((struct common_cache_entry_params *) - entry->c_params)->max_elemsize = count; + entry->negative_cache_params.max_elemsize = count; TRACE_OUT(set_keep_hot_count); } @@ -244,11 +181,9 @@ TRACE_IN(set_positive_policy); assert(entry_name != NULL); - entry = find_create_entry(config, entry_name, EUT_COMMON); + entry = find_create_entry(config, entry_name); assert(entry != NULL); - assert(entry->c_params->entry_type == CET_COMMON); - ((struct common_cache_entry_params *) - entry->c_params)->policy = policy; + entry->positive_cache_params.policy = policy; TRACE_OUT(set_positive_policy); } @@ -262,11 +197,9 @@ TRACE_IN(set_negative_policy); assert(entry_name != NULL); - entry = find_create_entry(config, entry_name, EUT_NEGATIVE); + entry = find_create_entry(config, entry_name); assert(entry != NULL); - assert(entry->c_params->entry_type == CET_COMMON); - ((struct common_cache_entry_params *) - entry->c_params)->policy = policy; + entry->negative_cache_params.policy = policy; >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200509301348.j8UDmfSF051840>