Date: Fri, 23 Sep 2005 14:47:25 GMT From: soc-bushman <soc-bushman@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 84166 for review Message-ID: <200509231447.j8NElPrj093163@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=84166 Change 84166 by soc-bushman@soc-bushman_stinger on 2005/09/23 14:46:58 all *_id functions are now working with data buffers instead of strings the additional "size" argument was added to cached_read and cached_write functions to support this behaviour Affected files ... .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/Makefile#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/Makefile#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.8#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf.5#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/hashtable.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/parser.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/parser.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/protocol.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/protocol.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/query.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/query.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/singletons.c#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/singletons.h#2 edit .. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/startup/cached#2 edit .. //depot/projects/soc2005/nsswitch_cached/src/include/nscache.h#4 edit .. //depot/projects/soc2005/nsswitch_cached/src/include/nscachedcli.h#4 edit .. //depot/projects/soc2005/nsswitch_cached/src/include/resolv.h#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/include/stdlib.h#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/include/string.h#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/compat-43/gethostid.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/compat-43/sethostid.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/db/man/dbopen.3#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/Makefile.inc#4 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/daemon.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/devname.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/getcwd.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/getgrent.c#6 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/gethostname.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/getosreldate.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/getpagesize.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/getpwent.c#7 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/glob.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/readdir.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/sethostname.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/gen/strtofflags.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/i386/gen/_set_tp.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/i386/gen/ldexp.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/include/libc_private.h#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/locale/runetype.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/locale/tolower.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/locale/toupper.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getaddrinfo.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getprotoent.c#7 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/getservent.c#17 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/name6.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nscache.c#4 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nscachedcli.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nsdispatch.c#7 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/posix1e/extattr.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/quad/quad.h#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/regex/regex2.h#4 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/rpc/Makefile.inc#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/rpc/getrpcent.c#8 edit .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/stdio/fgets.3#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/stdio/fgetwln.3#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/stdio/local.h#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/stdio/makebuf.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/stdio/printf.3#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/stdio/tmpnam.3#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/stdlib/abort.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/stdlib/exit.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/stdlib/strfmon.c#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/stdtime/time2posix.3#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/string/Makefile.inc#4 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/string/memchr.3#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/string/memmem.3#1 branch .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/string/memmem.c#1 branch .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/string/strcat.3#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/string/strchr.3#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/string/strcpy.3#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/string/strcspn.3#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/string/strspn.3#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/string/strstr.3#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/sys/listen.2#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/sys/umask.2#3 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/Makefile#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/asf/asf.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/bluetooth/l2ping/l2ping.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/chkgrp/chkgrp.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/cron/cron/cron.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/cron/cron/cron.h#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/cron/cron/do_command.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/cron/lib/misc.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/daemon/Makefile#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/daemon/daemon.8#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/daemon/daemon.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/i4b/isdnd/log.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/i4b/isdnmonitor/main.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/inetd/inetd.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/mountd/Makefile#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/mountd/mountd.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/moused/Makefile#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/moused/moused.8#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/moused/moused.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/pmcstat/pmcstat.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/pmcstat/pmcstat_log.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/portsnap/make_index/make_index.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/portsnap/phttpget/phttpget.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/portsnap/portsnap/portsnap.8#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/portsnap/portsnap/portsnap.sh#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/powerd/Makefile#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/powerd/powerd.8#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/powerd/powerd.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/ppp/README.devel#2 delete .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/ppp/ppp.8.m4#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/sysinstall/dist.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/sysinstall/menus.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/syslogd/syslogd.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/vidcontrol/vidcontrol.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/watch/watch.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/watchdogd/Makefile#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/watchdogd/watchdogd.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/src/usr.sbin/wpa/wpa_supplicant/driver_freebsd.c#2 integrate .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/Makefile#6 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/getservent.c#5 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscache.c#7 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscache.h#3 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscachedcli.c#4 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nscachedcli.h#3 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsdispatch.c#6 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsdispatch_test.c#8 edit .. //depot/projects/soc2005/nsswitch_cached/tests/nsdispatch_test/nsswitch.h#4 edit Differences ... ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/Makefile#2 (text+ko) ==== @@ -1,4 +1,4 @@ # $FreeBSD$ -SUBDIR+="test" "cachelib" "bin" +SUBDIR+="cached" .include <bsd.subdir.mk> ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/Makefile#2 (text+ko) ==== @@ -5,11 +5,11 @@ MAN=cached.conf.5 cached.8 WARNS?=2 -SRCS=cached.c debug.c log.c config.c query.c mp_ws_query.c mp_rs_query.c\ - singletons.c protocol.c parser.c -CFLAGS+= -I${.CURDIR}/../ -DCONFIG_PATH="\"${PREFIX}/etc/cached.conf\"" +SRCS= agent.c cached.c cachelib.c cacheplcs.c debug.c log.c config.c query.c\ + mp_ws_query.c mp_rs_query.c singletons.c protocol.c parser.c +CFLAGS+= -DCONFIG_PATH="\"${PREFIX}/etc/cached.conf\"" DPADD+=${LIBM} ${LIBPTHREAD} -LDADD+=${.OBJDIR}/../cachelib/libcachelib.a -lm -lpthread +LDADD+=${LIBM} ${LIBPTHREAD} FILESGROUPS=STARTUP CONF @@ -21,4 +21,7 @@ CONFMODE=${SHAREMODE} CONF+=${.CURDIR}/cached.conf +.PATH: ./agents +.include "agents/Makefile.inc" + .include <bsd.prog.mk> ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.8#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.c#2 (text+ko) ==== @@ -39,7 +39,8 @@ #include <string.h> #include <unistd.h> -#include <cachelib/include/cachelib.h> +#include "agents/passwd.h" +#include "cachelib.h" #include "config.h" #include "debug.h" #include "log.h" @@ -638,6 +639,10 @@ LOG_MSG_1("main", "global timer initialization failed"); return (-1); } + + s_agent_table = init_agent_table(); + register_agent(s_agent_table, init_passwd_agent()); + register_agent(s_agent_table, init_passwd_mp_agent()); /* configuration initialization */ s_configuration = init_configuration(); @@ -732,6 +737,9 @@ /* configuration destruction */ destroy_configuration(s_configuration); + /* agents table destruction */ + destroy_agent_table(s_agent_table); + /* global timer destruction */ destroy_global_timer(); ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf.5#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.c#2 (text+ko) ==== @@ -29,13 +29,20 @@ #include <assert.h> #include <stdlib.h> #include <string.h> -#include "../test/debug.h" -#include "include/cachelib.h" -#include "hashfuncs.h" +#include "cachelib.h" +#include "debug.h" #define INITIAL_ENTRIES_CAPACITY 32 #define ENTRIES_CAPACITY_STEP 32 +#define STRING_SIMPLE_HASH_BODY(in_var, var, a, M) \ + for ((var) = 0; *(in_var) != '\0'; ++(in_var)) \ + (var) = ((a)*(var) + *(in_var)) % (M) + +#define STRING_SIMPLE_MP2_HASH_BODY(in_var, var, a, M) \ + for ((var) = 0; *(in_var) != 0; ++(in_var)) \ + (var) = ((a)*(var) + *(in_var)) & (M - 1) + static int cache_elemsize_common_continue_func(struct cache_common_entry_ *, struct cache_policy_item_ *); static int cache_lifetime_common_continue_func(struct cache_common_entry_ *, @@ -59,25 +66,35 @@ static int ht_items_cmp_func(const void *p1, const void *p2) { - assert(((struct cache_ht_item_data_ *)p1)->key != NULL); - assert(((struct cache_ht_item_data_ *)p2)->key != NULL); + struct cache_ht_item_data_ *hp1, *hp2; + + hp1 = (struct cache_ht_item_data_ *)p1; + hp2 = (struct cache_ht_item_data_ *)p2; + + assert(hp1->key != NULL); + assert(hp2->key != NULL); + + if (hp1->key_size != hp2->key_size) + return (-1); - return (strcmp(((struct cache_ht_item_data_ *)p1)->key, - ((struct cache_ht_item_data_ *)p2)->key)); + return (memcmp(hp1->key, hp2->key, hp1->key_size)); } static hashtable_index_t ht_item_hash_func(const void *p) { - char const *key_var; + struct cache_ht_item_data_ *hp; + size_t i; + hashtable_index_t retval; + + hp = (struct cache_ht_item_data_ *)p; + assert(hp->key != NULL); - key_var = ((struct cache_ht_item_data_ *)p)->key; - assert(key_var != NULL); + retval = 0; + for (i = 0; i < hp->key_size; ++i) + retval = (127 * retval + (unsigned char)hp->key[i]) % CACHE_HT_SIZE; - retval = 0; - STRING_SIMPLE_HASH_BODY(key_var, retval, 127, CACHE_HT_SIZE); - return retval; } @@ -304,7 +321,8 @@ policy->remove_item_func(policy, item); memset(&ht_key, 0, sizeof(struct cache_ht_item_data_)); - ht_key.key = (char *)item->mdata; + ht_key.key = item->key; + ht_key.key_size = item->key_size; hash = HASHTABLE_CALCULATE_HASH(cache_ht_, &ht_key); assert(hash >= 0); @@ -341,7 +359,7 @@ if (entry->params->entry_type == CET_COMMON) { common_entry = (struct cache_common_entry_ *)entry; if ((common_entry->common_params.max_lifetime.tv_sec != 0) || - (common_entry->common_params.max_lifetime.tv_usec != 0)) { + (common_entry->common_params.max_lifetime.tv_usec != 0)) { policy = common_entry->policies[0]; if (common_entry->policies_size > 1) @@ -608,8 +626,8 @@ } int -cache_read(struct cache_entry_ *entry, const char *key, char *value, - size_t *value_size) +cache_read(struct cache_entry_ *entry, const char *key, size_t key_size, + char *value, size_t *value_size) { struct cache_common_entry_ *common_entry; struct cache_ht_item_data_ item_data, *find_res; @@ -626,7 +644,9 @@ common_entry = (struct cache_common_entry_ *)entry; memset(&item_data, 0, sizeof(struct cache_ht_item_data_)); + /* TODO: can't avoid the cast here */ item_data.key = (char *)key; + item_data.key_size = key_size; hash = HASHTABLE_CALCULATE_HASH(cache_ht_, &item_data); assert(hash >= 0); @@ -640,35 +660,35 @@ } if ((common_entry->common_params.max_lifetime.tv_sec != 0) || - (common_entry->common_params.max_lifetime.tv_usec != 0)) { + (common_entry->common_params.max_lifetime.tv_usec != 0)) { - if (find_res->fifo_policy_item->last_request_time.tv_sec - - find_res->fifo_policy_item->creation_time.tv_sec > - common_entry->common_params.max_lifetime.tv_sec) { + if (find_res->fifo_policy_item->last_request_time.tv_sec - + find_res->fifo_policy_item->creation_time.tv_sec > + common_entry->common_params.max_lifetime.tv_sec) { - HASHTABLE_ENTRY_REMOVE(cache_ht_, item, find_res); - free(find_res->key); - free(find_res->value); + HASHTABLE_ENTRY_REMOVE(cache_ht_, item, find_res); + free(find_res->key); + free(find_res->value); - connected_item = - find_res->fifo_policy_item->connected_item; - if (connected_item != NULL) { - common_entry->policies[1]->remove_item_func( - common_entry->policies[1], - connected_item); - common_entry->policies[1]->destroy_item_func( - connected_item); - } + connected_item = + find_res->fifo_policy_item->connected_item; + if (connected_item != NULL) { + common_entry->policies[1]->remove_item_func( + common_entry->policies[1], + connected_item); + common_entry->policies[1]->destroy_item_func( + connected_item); + } - common_entry->policies[0]->remove_item_func( - common_entry->policies[0], - find_res->fifo_policy_item); - common_entry->policies[0]->destroy_item_func( + common_entry->policies[0]->remove_item_func( + common_entry->policies[0], find_res->fifo_policy_item); - - --common_entry->items_size; - } + common_entry->policies[0]->destroy_item_func( + find_res->fifo_policy_item); + + --common_entry->items_size; } + } if ((*value_size < find_res->value_size) || (value == NULL)) { *value_size = find_res->value_size; @@ -702,8 +722,8 @@ } int -cache_write(struct cache_entry_ *entry, const char *key, char const *value, - size_t value_size) +cache_write(struct cache_entry_ *entry, const char *key, size_t key_size, + char const *value, size_t value_size) { struct cache_common_entry_ *common_entry; struct cache_ht_item_data_ item_data, *find_res; @@ -723,7 +743,9 @@ common_entry = (struct cache_common_entry_ *)entry; memset(&item_data, 0, sizeof(struct cache_ht_item_data_)); + /* TODO: can't avoid the cast here */ item_data.key = (char *)key; + item_data.key_size = key_size; hash = HASHTABLE_CALCULATE_HASH(cache_ht_, &item_data); assert(hash >= 0); @@ -736,10 +758,10 @@ return (-1); } - /* TODO: optimize the strlen calls */ - item_data.key = (char *)malloc(strlen(key)+1); - memset(item_data.key, 0, strlen(key)+1); - strncpy(item_data.key, key, strlen(key)); + item_data.key = (char *)malloc(key_size); + memcpy(item_data.key, key, key_size); +// memset(item_data.key, 0, strlen(key)+1); +// strncpy(item_data.key, key, strlen(key)); item_data.value = (char *)malloc(value_size); assert(item_data.value != NULL); @@ -749,7 +771,8 @@ item_data.value_size = value_size; policy_item = common_entry->policies[0]->create_item_func(); - policy_item->mdata = (void *)item_data.key; + policy_item->key = item_data.key; + policy_item->key_size = item_data.key_size; common_entry->get_time_func(&policy_item->creation_time); if (common_entry->policies_size > 1) { @@ -758,7 +781,8 @@ memcpy(&connected_policy_item->creation_time, &policy_item->creation_time, sizeof(struct timeval)); - connected_policy_item->mdata = policy_item->mdata; + connected_policy_item->key = policy_item->key; + connected_policy_item->key_size = policy_item->key_size; connected_policy_item->connected_item = policy_item; policy_item->connected_item = connected_policy_item; ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.h#2 (text+ko) ==== @@ -25,14 +25,14 @@ * */ -#ifndef __CACHELIB_INCLUDE_CACHELIB_H__ -#define __CACHELIB_INCLUDE_CACHELIB_H__ +#ifndef __CACHED_CACHELIB_H__ +#define __CACHED_CACHELIB_H__ #include <sys/queue.h> #include <sys/time.h> #include <stdlib.h> -#include "../hashtable.h" -#include "../policies.h" +#include "hashtable.h" +#include "cacheplcs.h" #define CACHE_HT_SIZE 256 @@ -108,7 +108,9 @@ struct cache_ht_item_data_ { + /* key is the bytes sequence only - not the null-terminated string */ char *key; + size_t key_size; char *value; size_t value_size; @@ -219,8 +221,8 @@ extern cache_entry find_cache_entry(cache, const char *); /* read/write operations used on common entries */ -extern int cache_read(cache_entry, const char *, char *, size_t *); -extern int cache_write(cache_entry, const char *, char const *, size_t); +extern int cache_read(cache_entry, const char *, size_t, char *, size_t *); +extern int cache_write(cache_entry, const char *, size_t, char const *, size_t); /* read/write operations used on multipart entries */ extern cache_mp_write_session open_cache_mp_write_session(cache_entry); ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.c#2 (text+ko) ==== @@ -27,8 +27,8 @@ #include <assert.h> #include <string.h> -#include "../test/debug.h" -#include "policies.h" +#include "cacheplcs.h" +#include "debug.h" static void cache_fifo_policy_update_item(struct cache_policy_ *, struct cache_policy_item_ *); ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.h#2 (text+ko) ==== @@ -25,8 +25,8 @@ * */ -#ifndef __CACHELIB_POLICIES_H__ -#define __CACHELIB_POLICIES_H__ +#ifndef __CACHED_CACHEPLCS_H__ +#define __CACHED_CACHEPLCS_H__ #include <sys/queue.h> #include <sys/time.h> @@ -37,7 +37,8 @@ struct cache_policy_item_ { - void *mdata; + char *key; + size_t key_size; size_t request_count; struct timeval last_request_time; ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.c#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.h#2 (text+ko) ==== @@ -32,8 +32,7 @@ #include <sys/types.h> #include <pthread.h> #include <unistd.h> - -#include <cachelib/include/cachelib.h> +#include "cachelib.h" struct configuration_entry { struct timeval query_timeout; ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.c#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.h#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/hashtable.h#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.c#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.h#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.c#2 (text+ko) ==== @@ -34,7 +34,7 @@ #include <string.h> #include <stdio.h> -#include <cachelib/include/cachelib.h> +#include "cachelib.h" #include "config.h" #include "debug.h" #include "log.h" ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.h#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.c#2 (text+ko) ==== @@ -34,7 +34,7 @@ #include <string.h> #include <stdio.h> -#include <cachelib/include/cachelib.h> +#include "cachelib.h" #include "config.h" #include "debug.h" #include "log.h" ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.h#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/parser.c#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/parser.h#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/protocol.c#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/protocol.h#2 (text+ko) ==== @@ -44,7 +44,7 @@ char *data; size_t entry_length; - size_t cache_key_length; + size_t cache_key_size; size_t data_size; }; @@ -59,7 +59,7 @@ char *cache_key; size_t entry_length; - size_t cache_key_length; + size_t cache_key_size; }; struct cache_read_response ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/query.c#2 (text+ko) ==== @@ -31,6 +31,7 @@ #include <sys/event.h> #include <assert.h> #include <errno.h> +#include <nsswitch.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -42,25 +43,25 @@ #include "mp_rs_query.h" #include "singletons.h" -extern void get_time_func(struct timeval *); +extern void get_time_func(struct timeval *); -static int on_query_startup(struct query_state *); -static void on_query_destroy(struct query_state *); +static int on_query_startup(struct query_state *); +static void on_query_destroy(struct query_state *); -static int on_read_request_read1(struct query_state *); -static int on_read_request_read2(struct query_state *); -static int on_read_request_process(struct query_state *); -static int on_read_response_write1(struct query_state *); -static int on_read_response_write2(struct query_state *); +static int on_read_request_read1(struct query_state *); +static int on_read_request_read2(struct query_state *); +static int on_read_request_process(struct query_state *); +static int on_read_response_write1(struct query_state *); +static int on_read_response_write2(struct query_state *); -static int on_rw_mapper(struct query_state *); +static int on_rw_mapper(struct query_state *); -static int on_transform_request_read1(struct query_state *); +static int on_transform_request_read1(struct query_state *); -static int on_write_request_read1(struct query_state *); -static int on_write_request_read2(struct query_state *); -static int on_write_request_process(struct query_state *); -static int on_write_response_write1(struct query_state *); +static int on_write_request_read1(struct query_state *); +static int on_write_request_read2(struct query_state *); +static int on_write_request_process(struct query_state *); +static int on_write_response_write1(struct query_state *); static int on_query_startup(struct query_state *qstate) @@ -207,7 +208,7 @@ result = qstate->read_func(qstate, &write_request->entry_length, sizeof(size_t)); result += qstate->read_func(qstate, - &write_request->cache_key_length, sizeof(size_t)); + &write_request->cache_key_size, sizeof(size_t)); result += qstate->read_func(qstate, &write_request->data_size, sizeof(size_t)); @@ -218,7 +219,7 @@ } if (BUFSIZE_INVALID(write_request->entry_length) || - BUFSIZE_INVALID(write_request->cache_key_length) || + BUFSIZE_INVALID(write_request->cache_key_size) || BUFSIZE_INVALID(write_request->data_size)) { TRACE_OUT(on_write_request_read1); return (-1); @@ -230,20 +231,20 @@ memset(write_request->entry, 0, write_request->entry_length + 1); write_request->cache_key = (char *)malloc( - write_request->cache_key_length + - qstate->eid_str_length + 1); + write_request->cache_key_size + + qstate->eid_str_length); assert(write_request->cache_key != NULL); memcpy(write_request->cache_key, qstate->eid_str, qstate->eid_str_length); memset(write_request->cache_key + qstate->eid_str_length, 0, - write_request->cache_key_length + 1); + write_request->cache_key_size); write_request->data = (char *)malloc(write_request->data_size); assert(write_request->data != NULL); memset(write_request->data, 0, write_request->data_size); qstate->kevent_watermark = write_request->entry_length + - write_request->cache_key_length + + write_request->cache_key_size + write_request->data_size; qstate->process_func = on_write_request_read2; } @@ -264,7 +265,7 @@ result = qstate->read_func(qstate, write_request->entry, write_request->entry_length); result += qstate->read_func(qstate, write_request->cache_key + - qstate->eid_str_length, write_request->cache_key_length); + qstate->eid_str_length, write_request->cache_key_size); result += qstate->read_func(qstate, write_request->data, write_request->data_size); @@ -272,7 +273,8 @@ TRACE_INT(result); TRACE_OUT(on_write_request_read2); return (-1); - } + } + write_request->cache_key_size += qstate->eid_str_length; qstate->kevent_watermark = 0; qstate->process_func = on_write_request_process; @@ -294,8 +296,8 @@ TRACE_INT(write_request->entry_length); TRACE_STR(write_request->entry); - TRACE_INT(write_request->cache_key_length); - TRACE_STR(write_request->cache_key); + TRACE_INT(write_request->cache_key_size); +// TRACE_STR(write_request->cache_key); TRACE_INT(write_request->data_size); qstate->config_entry = find_config_entry_by_name_and_euid( @@ -312,10 +314,12 @@ qstate->config_entry->c_params->entry_name); configuration_unlock(s_configuration); if (c_entry != NULL) { - TRACE_STR(write_request->cache_key); + //TRACE_STR(write_request->cache_key); configuration_lock_entry(qstate->config_entry); write_response->error_code = cache_write(c_entry, - write_request->cache_key, write_request->data, + write_request->cache_key, + write_request->cache_key_size, + write_request->data, write_request->data_size); configuration_unlock_entry(qstate->config_entry); @@ -379,7 +383,7 @@ result = qstate->read_func(qstate, &read_request->entry_length, sizeof(size_t)); result += qstate->read_func(qstate, - &read_request->cache_key_length, sizeof(size_t)); + &read_request->cache_key_size, sizeof(size_t)); if (result != sizeof(size_t) * 2) { TRACE_INT(result); @@ -388,7 +392,7 @@ } if (BUFSIZE_INVALID(read_request->entry_length) || - BUFSIZE_INVALID(read_request->cache_key_length)) { + BUFSIZE_INVALID(read_request->cache_key_size)) { TRACE_OUT(on_read_request_read1); return (-1); } @@ -399,16 +403,16 @@ memset(read_request->entry, 0, read_request->entry_length + 1); read_request->cache_key = (char *)malloc( - read_request->cache_key_length + - qstate->eid_str_length + 1); + read_request->cache_key_size + + qstate->eid_str_length); assert(read_request->cache_key != NULL); memcpy(read_request->cache_key, qstate->eid_str, qstate->eid_str_length); memset(read_request->cache_key + qstate->eid_str_length, 0, - read_request->cache_key_length + 1); + read_request->cache_key_size); qstate->kevent_watermark = read_request->entry_length + - read_request->cache_key_length; + read_request->cache_key_size; qstate->process_func = on_read_request_read2; } @@ -429,13 +433,14 @@ read_request->entry_length); result += qstate->read_func(qstate, read_request->cache_key + qstate->eid_str_length, - read_request->cache_key_length); + read_request->cache_key_size); if (result != qstate->kevent_watermark) { TRACE_INT(result); TRACE_OUT(on_read_request_read2); return (-1); } + read_request->cache_key_size += qstate->eid_str_length; qstate->kevent_watermark = 0; qstate->process_func = on_read_request_process; @@ -447,9 +452,10 @@ static int on_read_request_process(struct query_state *qstate) { - struct cache_read_request *read_request; - struct cache_read_response *read_response; - cache_entry c_entry; + struct cache_read_request *read_request; + struct cache_read_response *read_response; + cache_entry c_entry; + struct agent *lookup_agent; TRACE_IN(on_read_request_process); init_comm_element(&qstate->response, CET_READ_RESPONSE); @@ -458,8 +464,8 @@ TRACE_INT(read_request->entry_length); TRACE_STR(read_request->entry); - TRACE_INT(read_request->cache_key_length); - TRACE_STR(read_request->cache_key); + TRACE_INT(read_request->cache_key_size); +// TRACE_STR(read_request->cache_key); qstate->config_entry = find_config_entry_by_name_and_euid( s_configuration, read_request->entry, qstate->euid); @@ -476,10 +482,11 @@ configuration_unlock(s_configuration); if (c_entry != NULL) { TRACE_POINT(); - TRACE_STR(read_request->cache_key); + //TRACE_STR(read_request->cache_key); configuration_lock_entry(qstate->config_entry); read_response->error_code = cache_read(c_entry, - read_request->cache_key, NULL, + read_request->cache_key, + read_request->cache_key_size, NULL, &read_response->data_size); if (read_response->error_code == -2) { @@ -488,8 +495,41 @@ read_response->data_size); assert(read_response != NULL); read_response->error_code = cache_read(c_entry, - read_request->cache_key, read_response->data, - &read_response->data_size); + read_request->cache_key, + read_request->cache_key_size, + read_response->data, + &read_response->data_size); + } + + if (read_response->error_code == -1) { + free(read_response->data); + read_response->data = NULL; + read_response->data_size = 0; + + lookup_agent = find_agent(s_agent_table, + read_request->entry); + + if ((lookup_agent != NULL) && + (lookup_agent->type == COMMON_AGENT)) { + struct common_agent *c_agent; + int res; + + c_agent = (struct common_agent *)lookup_agent; + res = c_agent->lookup_func( + read_request->cache_key + qstate->eid_str_length, + read_request->cache_key_size - qstate->eid_str_length, + &read_response->data, + &read_response->data_size); + + if (res == NS_SUCCESS) { + read_response->error_code = 0; + cache_write(c_entry, + read_request->cache_key, + read_request->cache_key_size, + read_response->data, + read_response->data_size); + } + } } configuration_unlock_entry(qstate->config_entry); ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/query.h#2 (text+ko) ==== @@ -28,10 +28,10 @@ #ifndef __CACHED_QUERY_H__ #define __CACHED_QUERY_H__ -#include <cachelib/include/cachelib.h> #include <sys/types.h> #include <stdlib.h> #include <unistd.h> +#include "cachelib.h" #include "config.h" #include "protocol.h" ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/singletons.c#2 (text+ko) ==== @@ -28,5 +28,6 @@ #include "singletons.h" struct configuration *s_configuration = NULL; -cache s_cache; /* TODO: initializer needed? */ -struct runtime_env *s_runtime_env = NULL; +cache s_cache = INVALID_CACHE; +struct runtime_env *s_runtime_env = NULL; +struct agent_table *s_agent_table = NULL; ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/singletons.h#2 (text+ko) ==== @@ -28,8 +28,9 @@ #ifndef __CACHED_SINGLETONS_H__ #define __CACHED_SINGLETONS_H__ -#include <cachelib/include/cachelib.h> +#include "cachelib.h" #include "config.h" +#include "agent.h" struct runtime_env { int queue; @@ -40,5 +41,6 @@ extern struct configuration *s_configuration; extern cache s_cache; extern struct runtime_env *s_runtime_env; +extern struct agent_table *s_agent_table; #endif ==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/startup/cached#2 (text+ko) ==== ==== //depot/projects/soc2005/nsswitch_cached/src/include/nscache.h#4 (text+ko) ==== @@ -41,18 +41,18 @@ typedef cached_mp_read_session (*nss_get_mp_rs_func_t)(void); typedef struct _nss_cache_info { - char *entry_name; - void *mdata; + char *entry_name; + void *mdata; - nss_cache_id_func_t id_func; - nss_cache_marshal_func_t marshal_func; - nss_cache_unmarshal_func_t unmarshal_func; + nss_cache_id_func_t id_func; + nss_cache_marshal_func_t marshal_func; + nss_cache_unmarshal_func_t unmarshal_func; - nss_set_mp_ws_func_t set_mp_ws_func; - nss_get_mp_ws_func_t get_mp_ws_func; + nss_set_mp_ws_func_t set_mp_ws_func; + nss_get_mp_ws_func_t get_mp_ws_func; - nss_set_mp_rs_func_t set_mp_rs_func; - nss_get_mp_rs_func_t get_mp_rs_func; + nss_set_mp_rs_func_t set_mp_rs_func; + nss_get_mp_rs_func_t get_mp_rs_func; } nss_cache_info; #define NSS_MP_CACHE_HANDLING(name) \ ==== //depot/projects/soc2005/nsswitch_cached/src/include/nscachedcli.h#4 (text+ko) ==== @@ -82,9 +82,9 @@ /* simple read/write operations */ extern int cached_write(cached_connection, const char *, const char *, - const char *, size_t); + size_t, const char *, size_t); extern int cached_read(cached_connection, const char *, const char *, - char *, size_t *); + size_t, char *, size_t *); /* multipart read/write operations */ >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200509231447.j8NElPrj093163>