Date: Fri, 24 Nov 2006 13:36:45 GMT From: Michael Bushkov <bushman@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 110479 for review Message-ID: <200611241336.kAODajA2031267@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=110479 Change 110479 by bushman@bushman_nss_ldap_cached on 2006/11/24 13:36:39 + some style reworking of nscache.h (to avoid using typedefs) + NSS_MP_CACHE_HANDLING implementation chaged to be more general and flexible - we use the same nss_mp_cache_data structure for all nsswitch databases. + getXXent() calls now don't rewind automatically after reaching the end of the records list Affected files ... .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/gen/getgrent.c#6 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/gen/getpwent.c#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/include/nscache.h#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/include/nscachedcli.h#3 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/getaddrinfo.c#6 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/gethostnamadr.c#6 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/getnetnamadr.c#4 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/getprotoent.c#4 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/getservent.c#4 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/nscache.c#7 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/nscachedcli.c#4 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/nsdispatch.c#7 edit .. //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/rpc/getrpcent.c#3 edit Differences ... ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/gen/getgrent.c#6 (text+ko) ==== @@ -300,9 +300,8 @@ setgrent(void) { #ifdef NS_CACHING - static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( - group, (void *)nss_lt_all, - NULL, NULL); + static const struct nss_cache_info cache_info = + NS_MP_CACHE_INFO_INITIALIZER(group, (void *)nss_lt_all, NULL, NULL); #endif static const ns_dtab dtab[] = { @@ -320,9 +319,8 @@ setgroupent(int stayopen) { #ifdef NS_CACHING - static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( - group, (void *)nss_lt_all, - NULL, NULL); + static const struct nss_cache_info cache_info = + NS_MP_CACHE_INFO_INITIALIZER(group, (void *)nss_lt_all, NULL, NULL); #endif static const ns_dtab dtab[] = { @@ -341,9 +339,8 @@ endgrent(void) { #ifdef NS_CACHING - static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( - group, (void *)nss_lt_all, - NULL, NULL); + static const struct nss_cache_info cache_info = + NS_MP_CACHE_INFO_INITIALIZER(group, (void *)nss_lt_all, NULL, NULL); #endif static const ns_dtab dtab[] = { @@ -361,9 +358,9 @@ struct group **result) { #ifdef NS_CACHING - static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( - group, (void *)nss_lt_all, - grp_marshal_func, grp_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_MP_CACHE_INFO_INITIALIZER(group, (void *)nss_lt_all, + grp_marshal_func, grp_unmarshal_func); #endif static const ns_dtab dtab[] = { @@ -390,10 +387,9 @@ struct group **result) { #ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - group, (void *)nss_lt_name, - grp_id_func, grp_marshal_func, grp_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_COMMON_CACHE_INFO_INITIALIZER(group, (void *)nss_lt_name, + grp_id_func, grp_marshal_func, grp_unmarshal_func); #endif static const ns_dtab dtab[] = { @@ -420,10 +416,9 @@ struct group **result) { #ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - group, (void *)nss_lt_id, - grp_id_func, grp_marshal_func, grp_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_COMMON_CACHE_INFO_INITIALIZER(group, (void *)nss_lt_id, + grp_id_func, grp_marshal_func, grp_unmarshal_func); #endif static const ns_dtab dtab[] = { @@ -535,4 +530,3 @@ key.gid = 0; /* not used */ return (getgr(wrap_getgrent_r, key)); } - ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/gen/getpwent.c#3 (text+ko) ==== @@ -302,9 +302,9 @@ setpwent(void) { #ifdef NS_CACHING - static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( - passwd, (void *)nss_lt_all, - NULL, NULL); + static const struct nss_cache_info cache_info = + NS_MP_CACHE_INFO_INITIALIZER(passwd, (void *)nss_lt_all, + NULL, NULL); #endif static const ns_dtab dtab[] = { @@ -321,9 +321,9 @@ setpassent(int stayopen) { #ifdef NS_CACHING - static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( - passwd, (void *)nss_lt_all, - NULL, NULL); + static const struct nss_cache_info cache_info = + NS_MP_CACHE_INFO_INITIALIZER(passwd, (void *)nss_lt_all, + NULL, NULL); #endif static const ns_dtab dtab[] = { @@ -342,8 +342,8 @@ endpwent(void) { #ifdef NS_CACHING - static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( - passwd, (void *)nss_lt_all, + static const struct nss_cache_info cache_info = + NS_MP_CACHE_INFO_INITIALIZER(passwd, (void *)nss_lt_all, NULL, NULL); #endif @@ -362,9 +362,9 @@ struct passwd **result) { #ifdef NS_CACHING - static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( - passwd, (void *)nss_lt_all, - pwd_marshal_func, pwd_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_MP_CACHE_INFO_INITIALIZER(passwd, (void *)nss_lt_all, + pwd_marshal_func, pwd_unmarshal_func); #endif static const ns_dtab dtab[] = { @@ -392,10 +392,9 @@ struct passwd **result) { #ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - passwd, (void *)nss_lt_name, - pwd_id_func, pwd_marshal_func, pwd_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_COMMON_CACHE_INFO_INITIALIZER(passwd, (void *)nss_lt_name, + pwd_id_func, pwd_marshal_func, pwd_unmarshal_func); #endif static const ns_dtab dtab[] = { @@ -423,10 +422,9 @@ struct passwd **result) { #ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - passwd, (void *)nss_lt_id, - pwd_id_func, pwd_marshal_func, pwd_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_COMMON_CACHE_INFO_INITIALIZER(passwd, (void *)nss_lt_id, + pwd_id_func, pwd_marshal_func, pwd_unmarshal_func); #endif static const ns_dtab dtab[] = { ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/include/nscache.h#3 (text) ==== @@ -31,22 +31,23 @@ #include "nscachedcli.h" -typedef int (*nss_cache_id_func_t)(char *, size_t *, va_list, void *); -typedef int (*nss_cache_marshal_func_t)(char *, size_t *, void *, va_list, +typedef int (*nss_cache_id_func)(char *, size_t *, va_list, void *); +typedef int (*nss_cache_marshal_func)(char *, size_t *, void *, va_list, void *); -typedef int (*nss_cache_unmarshal_func_t)(char *, size_t, void *, va_list, +typedef int (*nss_cache_unmarshal_func)(char *, size_t, void *, va_list, void *); -typedef void (*nss_set_mp_ws_func_t)(cached_mp_write_session); -typedef cached_mp_write_session (*nss_get_mp_ws_func_t)(void); +struct nss_mp_cache_state { + cached_mp_write_session mp_write_session; + cached_mp_read_session mp_read_session; + char *mp_buffer; + size_t mp_bufsize; + int finished; +}; -typedef void (*nss_set_mp_rs_func_t)(cached_mp_read_session); -typedef cached_mp_read_session (*nss_get_mp_rs_func_t)(void); +typedef struct nss_mp_cache_state *(*nss_get_mp_cache_state_func)(void); -typedef void (*nss_set_mp_buffer_func_t)(char *, size_t); -typedef char *(*nss_get_mp_buffer_func_t)(size_t *); - -typedef struct _nss_cache_info { +struct nss_cache_info { char *entry_name; void *mdata; @@ -54,144 +55,64 @@ * These 3 functions should be implemented specifically for each * nsswitch database. */ - nss_cache_id_func_t id_func; /* marshals the request parameters */ - nss_cache_marshal_func_t marshal_func; /* marshals response */ - nss_cache_unmarshal_func_t unmarshal_func; /* unmarshals response */ + nss_cache_id_func id_func; /* marshals the request parameters */ + nss_cache_marshal_func marshal_func; /* marshals response */ + nss_cache_unmarshal_func unmarshal_func; /* unmarshals response */ - /* - * These 4 functions should be generated with NSS_MP_CACHE_HANDLING - * macro. - */ - nss_set_mp_ws_func_t set_mp_ws_func; /* sets current write session */ - nss_get_mp_ws_func_t get_mp_ws_func; /* gets current write session */ + /* Gets thread-specific cache data for get**ent() requests handling */ + nss_get_mp_cache_state_func get_mp_cache_state_func; +}; - nss_set_mp_rs_func_t set_mp_rs_func; /* sets current read session */ - nss_get_mp_rs_func_t get_mp_rs_func; /* gets current read session */ - - nss_set_mp_buffer_func_t set_mp_buffer_func; - nss_get_mp_buffer_func_t get_mp_buffer_func; -} nss_cache_info; - -/* - * NSS_MP_CACHE_HANDLING implements the set_mp_ws, get_mp_ws, set_mp_rs, - * get_mp_rs functions, that are used in _nss_cache_info. It uses - * NSS_TLS_HANDLING macro to organize thread local storage. - */ -#define NSS_MP_CACHE_HANDLING(name) \ -struct name##_mp_state { \ - cached_mp_write_session mp_write_session; \ - cached_mp_read_session mp_read_session; \ - char *mp_buffer; \ - size_t mp_bufsize; \ -}; \ - \ -static void \ -name##_mp_endstate(void *s) { \ - struct name##_mp_state *mp_state; \ - \ - mp_state = (struct name##_mp_state *)s; \ - if (mp_state->mp_write_session != INVALID_CACHED_MP_WRITE_SESSION)\ - __abandon_cached_mp_write_session(mp_state->mp_write_session);\ - \ - if (mp_state->mp_read_session != INVALID_CACHED_MP_READ_SESSION)\ - __close_cached_mp_read_session(mp_state->mp_read_session);\ - \ - free(mp_state->mp_buffer); \ -} \ -NSS_TLS_HANDLING(name##_mp); \ - \ -static void \ -name##_set_mp_ws(cached_mp_write_session ws) \ -{ \ - struct name##_mp_state *mp_state; \ - int res; \ - \ - res = name##_mp_getstate(&mp_state); \ - if (res != 0) \ - return; \ - \ - mp_state->mp_write_session = ws; \ -} \ - \ -static cached_mp_write_session \ -name##_get_mp_ws(void) \ -{ \ - struct name##_mp_state *mp_state; \ - int res; \ - \ - res = name##_mp_getstate(&mp_state); \ - if (res != 0) \ - return (INVALID_CACHED_MP_WRITE_SESSION); \ - \ - return (mp_state->mp_write_session); \ -} \ - \ -static void \ -name##_set_mp_rs(cached_mp_read_session rs) \ -{ \ - struct name##_mp_state *mp_state; \ - int res; \ - \ - res = name##_mp_getstate(&mp_state); \ - if (res != 0) \ - return; \ - \ - mp_state->mp_read_session = rs; \ -} \ - \ -static cached_mp_read_session \ -name##_get_mp_rs(void) \ -{ \ - struct name##_mp_state *mp_state; \ - int res; \ - \ - res = name##_mp_getstate(&mp_state); \ - if (res != 0) \ - return (INVALID_CACHED_MP_READ_SESSION); \ - \ - return (mp_state->mp_read_session); \ -} \ - \ -static void \ -name##_set_mp_buffer(char *buf, size_t bufsize) \ -{ \ - struct name##_mp_state *mp_state; \ - int res; \ - \ - res = name##_mp_getstate(&mp_state); \ - if (res != 0) \ - return; \ - \ - mp_state->mp_buffer = buf; \ - mp_state->mp_bufsize = bufsize; \ -} \ - \ -static char * \ -name##_get_mp_buffer(size_t *bufsize) \ -{ \ - struct name##_mp_state *mp_state; \ - int res; \ - \ - res = name##_mp_getstate(&mp_state); \ - if (res != 0) \ - return (NULL); \ - \ - *bufsize = mp_state->mp_bufsize; \ - return (mp_state->mp_buffer); \ +#define NSS_MP_CACHE_HANDLING(name) \ +static pthread_key_t name##_state_key; \ +static void name##_keyinit(void); \ +static struct nss_mp_cache_state *name##_get_mp_state(void); \ + \ +static void \ +name##_keyinit(void) \ +{ \ + \ + (void)_pthread_key_create(&name##_state_key, \ + __nss_mp_cache_data_end_state); \ +} \ + \ +static struct nss_mp_cache_state * \ +name##_get_mp_state(void) \ +{ \ + static struct nss_mp_cache_state st; \ + static pthread_once_t keyinit = PTHREAD_ONCE_INIT; \ + int rv; \ + struct nss_mp_cache_state *p; \ + \ + if (!__isthreaded || _pthread_main_np() != 0) { \ + return (&st); \ + } \ + rv = _pthread_once(&keyinit, name##_keyinit); \ + if (rv != 0) \ + return (NULL); \ + p = _pthread_getspecific(name##_state_key); \ + if (p != NULL) \ + return (p); \ + p = calloc(1, sizeof(*p)); \ + if (p == NULL) \ + return (NULL); \ + rv = _pthread_setspecific(name##_state_key, p); \ + if (rv != 0) { \ + free(p); \ + return (NULL); \ + } \ + return (p); \ } - /* * These macros should be used to initialize _nss_cache_info structure. For * multipart queries in setXXXent and getXXXent functions mf and uf * (marshal function and unmarshal function) should be both NULL. */ #define NS_COMMON_CACHE_INFO_INITIALIZER(name, mdata, if, mf, uf) \ - {#name, mdata, if, mf, uf, NULL, NULL, NULL, NULL, NULL, NULL} + {#name, mdata, if, mf, uf, NULL} #define NS_MP_CACHE_INFO_INITIALIZER(name, mdata, mf, uf) \ - {#name, mdata, NULL, mf, uf, name##_set_mp_ws, name##_get_mp_ws,\ - name##_set_mp_rs, name##_get_mp_rs, name##_set_mp_buffer,\ - name##_get_mp_buffer } + {#name, mdata, NULL, mf, uf, name##_get_mp_state} /* * Analog of other XXX_CB macros. Has the pointer to _nss_cache_info @@ -210,18 +131,21 @@ #define NS_GET_NEWP(cp, cb, ib) \ ((char *)(cb) + (size_t)(cp) - (size_t)(ib)) -typedef struct _nss_cache_data { +struct nss_cache_data { char *key; size_t key_size; - nss_cache_info const *info; -} nss_cache_data; + struct nss_cache_info const *info; +}; __BEGIN_DECLS /* dummy function, which is needed to make nss_method_lookup happy */ extern int __nss_cache_handler(void *, void *, va_list); +extern void __nss_mp_cache_data_end_state(void *); + #ifdef _NS_PRIVATE + extern int __nss_common_cache_read(void *, void *, va_list); extern int __nss_common_cache_write(void *, void *, va_list); extern int __nss_common_cache_write_negative(void *); ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/include/nscachedcli.h#3 (text) ==== ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/getaddrinfo.c#6 (text+ko) ==== @@ -1654,10 +1654,9 @@ int error = 0; #ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - hosts, NULL, addrinfo_id_func, addrinfo_marshal_func, - addrinfo_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_COMMON_CACHE_INFO_INITIALIZER(hosts, NULL, addrinfo_id_func, + addrinfo_marshal_func, addrinfo_unmarshal_func); #endif static const ns_dtab dtab[] = { #ifdef NS_CACHING ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/gethostnamadr.c#6 (text+ko) ==== @@ -619,10 +619,9 @@ char abuf[MAXDNAME]; #ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - hosts, (void *)nss_lt_name, - host_id_func, host_marshal_func, host_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_COMMON_CACHE_INFO_INITIALIZER(hosts, (void *)nss_lt_name, + host_id_func, host_marshal_func, host_unmarshal_func); #endif static const ns_dtab dtab[] = { #ifdef NS_CACHING @@ -677,10 +676,9 @@ res_state statp; #ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - hosts, (void *)nss_lt_id, - host_id_func, host_marshal_func, host_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_COMMON_CACHE_INFO_INITIALIZER(hosts, (void *)nss_lt_id, + host_id_func, host_marshal_func, host_unmarshal_func); #endif static const ns_dtab dtab[] = { #ifdef NS_CACHING ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/getnetnamadr.c#4 (text+ko) ==== @@ -280,10 +280,9 @@ size_t buflen, struct netent **result, int *h_errorp) { #ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - networks, (void *)nss_lt_name, - net_id_func, net_marshal_func, net_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_COMMON_CACHE_INFO_INITIALIZER(networks, (void *)nss_lt_name, + net_id_func, net_marshal_func, net_unmarshal_func); #endif static const ns_dtab dtab[] = { #ifdef NS_CACHING @@ -305,10 +304,9 @@ size_t buflen, struct netent **result, int *h_errorp) { #ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - networks, (void *)nss_lt_id, - net_id_func, net_marshal_func, net_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_COMMON_CACHE_INFO_INITIALIZER(networks, (void *)nss_lt_id, + net_id_func, net_marshal_func, net_unmarshal_func); #endif static const ns_dtab dtab[] = { #ifdef NS_CACHING ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/getprotoent.c#4 (text+ko) ==== @@ -282,10 +282,9 @@ size_t buflen, struct protoent **result) { #ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - protocols, (void *)nss_lt_name, - __proto_id_func, __proto_marshal_func, __proto_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_COMMON_CACHE_INFO_INITIALIZER(protocols, (void *)nss_lt_name, + __proto_id_func, __proto_marshal_func, __proto_unmarshal_func); #endif static const ns_dtab dtab[] = { #ifdef NS_CACHING @@ -311,10 +310,9 @@ size_t buflen, struct protoent **result) { #ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - protocols, (void *)nss_lt_id, - __proto_id_func, __proto_marshal_func, __proto_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_COMMON_CACHE_INFO_INITIALIZER(protocols, (void *)nss_lt_id, + __proto_id_func, __proto_marshal_func, __proto_unmarshal_func); #endif static const ns_dtab dtab[] = { @@ -342,9 +340,9 @@ struct protoent **result) { #ifdef NS_CACHING - static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( - protocols, (void *)nss_lt_all, - __proto_marshal_func, __proto_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_MP_CACHE_INFO_INITIALIZER(protocols, (void *)nss_lt_all, + __proto_marshal_func, __proto_unmarshal_func); #endif static const ns_dtab dtab[] = { #ifdef NS_CACHING @@ -369,9 +367,9 @@ setprotoent(int stayopen) { #ifdef NS_CACHING - static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( - protocols, (void *)nss_lt_all, - NULL, NULL); + static const struct nss_cache_info cache_info = + NS_MP_CACHE_INFO_INITIALIZER(protocols, (void *)nss_lt_all, + NULL, NULL); #endif static const ns_dtab dtab[] = { @@ -389,9 +387,9 @@ endprotoent(void) { #ifdef NS_CACHING - static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( - protocols, (void *)nss_lt_all, - NULL, NULL); + static const struct nss_cache_info cache_info = + NS_MP_CACHE_INFO_INITIALIZER(protocols, (void *)nss_lt_all, + NULL, NULL); #endif static const ns_dtab dtab[] = { ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/getservent.c#4 (text+ko) ==== @@ -358,10 +358,9 @@ char *buffer, size_t bufsize, struct servent **result) { #ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - services, (void *)nss_lt_name, - serv_id_func, serv_marshal_func, serv_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_COMMON_CACHE_INFO_INITIALIZER(services, (void *)nss_lt_name, + serv_id_func, serv_marshal_func, serv_unmarshal_func); #endif /* NS_CACHING */ static const ns_dtab dtab[] = { #ifdef NS_CACHING @@ -387,10 +386,9 @@ char *buffer, size_t bufsize, struct servent **result) { #ifdef NS_CACHING - static const nss_cache_info cache_info = - NS_COMMON_CACHE_INFO_INITIALIZER( - services, (void *)nss_lt_id, - serv_id_func, serv_marshal_func, serv_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_COMMON_CACHE_INFO_INITIALIZER(services, (void *)nss_lt_id, + serv_id_func, serv_marshal_func, serv_unmarshal_func); #endif static const ns_dtab dtab[] = { #ifdef NS_CACHING @@ -416,9 +414,9 @@ struct servent **result) { #ifdef NS_CACHING - static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( - services, (void *)nss_lt_all, - serv_marshal_func, serv_unmarshal_func); + static const struct nss_cache_info cache_info = + NS_MP_CACHE_INFO_INITIALIZER(services, (void *)nss_lt_all, + serv_marshal_func, serv_unmarshal_func); #endif static const ns_dtab dtab[] = { #ifdef NS_CACHING @@ -443,9 +441,9 @@ setservent(int stayopen) { #ifdef NS_CACHING - static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( - services, (void *)nss_lt_all, - NULL, NULL); + static const struct nss_cache_info cache_info = + NS_MP_CACHE_INFO_INITIALIZER(services, (void *)nss_lt_all, + NULL, NULL); #endif static const ns_dtab dtab[] = { #ifdef NS_CACHING @@ -462,9 +460,9 @@ endservent() { #ifdef NS_CACHING - static const nss_cache_info cache_info = NS_MP_CACHE_INFO_INITIALIZER( - services, (void *)nss_lt_all, - NULL, NULL); + static const struct nss_cache_info cache_info = + NS_MP_CACHE_INFO_INITIALIZER(services, (void *)nss_lt_all, + NULL, NULL); #endif static const ns_dtab dtab[] = { #ifdef NS_CACHING ==== //depot/projects/soc2006/nss_ldap_cached/src/lib/libc/net/nscache.c#7 (text) ==== @@ -50,6 +50,21 @@ return (NS_UNAVAIL); } +void +__nss_mp_cache_data_end_state(void *p) +{ + struct nss_mp_cache_state *mp_state; + + mp_state = p; + if (mp_state->mp_write_session != INVALID_CACHED_MP_WRITE_SESSION) + __abandon_cached_mp_write_session(mp_state->mp_write_session); + + if (mp_state->mp_read_session != INVALID_CACHED_MP_READ_SESSION) + __close_cached_mp_read_session(mp_state->mp_read_session); + + free(mp_state->mp_buffer); +} + int __nss_common_cache_read(void *retval, void *mdata, va_list ap) { @@ -59,18 +74,18 @@ char *buffer; size_t buffer_size, size; - nss_cache_info const *cache_info; - nss_cache_data *cache_data; + struct nss_cache_info const *cache_info; + struct nss_cache_data *cache_data; va_list ap_new; int res; - cache_data = (nss_cache_data *)mdata; + cache_data = mdata; cache_info = cache_data->info; memset(¶ms, 0, sizeof(struct cached_connection_params)); params.socket_path = CACHED_SOCKET_PATH; - cache_data->key = (char *)malloc(NSS_CACHE_KEY_INITIAL_SIZE); + cache_data->key = malloc(NSS_CACHE_KEY_INITIAL_SIZE); if (cache_data->key == NULL) { cache_data->key_size = 0; return (NS_UNAVAIL); @@ -108,7 +123,7 @@ cache_data->key_size = size; buffer_size = NSS_CACHE_BUFFER_INITIAL_SIZE; - buffer = (char *)malloc(NSS_CACHE_BUFFER_INITIAL_SIZE); + buffer = malloc(NSS_CACHE_BUFFER_INITIAL_SIZE); if (buffer == NULL) return (NS_UNAVAIL); @@ -127,7 +142,7 @@ free(buffer); buffer = NULL; } else - buffer = (char *)reallocf(buffer, buffer_size); + buffer = reallocf(buffer, buffer_size); if (buffer == NULL) return (NS_UNAVAIL); @@ -177,12 +192,12 @@ char *buffer; size_t buffer_size; - nss_cache_info const *cache_info; - nss_cache_data *cache_data; + struct nss_cache_info const *cache_info; + struct nss_cache_data *cache_data; va_list ap_new; int res; - cache_data = (nss_cache_data *)mdata; + cache_data = mdata; cache_info = cache_data->info; if (cache_data->key == NULL) @@ -198,7 +213,7 @@ } buffer_size = NSS_CACHE_BUFFER_INITIAL_SIZE; - buffer = (char *)malloc(NSS_CACHE_BUFFER_INITIAL_SIZE); + buffer = malloc(NSS_CACHE_BUFFER_INITIAL_SIZE); if (buffer == NULL) { __close_cached_connection(connection); free(cache_data->key); @@ -220,7 +235,7 @@ buffer_size <<= 1; free(buffer); - buffer = (char *)malloc(buffer_size); + buffer = malloc(buffer_size); if (buffer == NULL) { res = NS_UNAVAIL; break; @@ -252,10 +267,10 @@ cached_connection connection; int res; - nss_cache_info const *cache_info; - nss_cache_data *cache_data; + struct nss_cache_info const *cache_info; + struct nss_cache_data *cache_data; - cache_data = (nss_cache_data *)mdata; + cache_data = mdata; cache_info = cache_data->info; if (cache_data->key == NULL) @@ -282,58 +297,61 @@ __nss_mp_cache_read(void *retval, void *mdata, va_list ap) { struct cached_connection_params params; - cached_mp_read_session rs; char *buffer; size_t buffer_size; - nss_cache_info const *cache_info; - nss_cache_data *cache_data; + struct nss_cache_info const *cache_info; + struct nss_cache_data *cache_data; + struct nss_mp_cache_state *mp_state; va_list ap_new; int res; - cache_data = (nss_cache_data *)mdata; + cache_data = mdata; cache_info = cache_data->info; - if (cache_info->get_mp_ws_func() != INVALID_CACHED_MP_WRITE_SESSION) + mp_state = cache_info->get_mp_cache_state_func(); + if ((mp_state == NULL) || + (mp_state->mp_write_session != INVALID_CACHED_MP_WRITE_SESSION)) return (NS_UNAVAIL); - buffer = cache_info->get_mp_buffer_func(&buffer_size); - if (buffer != NULL) { + if (mp_state->finished != 0) + return (NS_RETURN); + + if (mp_state->mp_buffer != NULL) { + buffer = mp_state->mp_buffer; + buffer_size = mp_state->mp_bufsize; res = 0; goto unmarsh; } - - rs = cache_info->get_mp_rs_func(); - if (rs == INVALID_CACHED_MP_READ_SESSION) { + + if (mp_state->mp_read_session == INVALID_CACHED_MP_READ_SESSION) { memset(¶ms, 0, sizeof(struct cached_connection_params)); params.socket_path = CACHED_SOCKET_PATH; - rs = __open_cached_mp_read_session(¶ms, - cache_info->entry_name); - if (rs == INVALID_CACHED_MP_READ_SESSION) + mp_state->mp_read_session = __open_cached_mp_read_session( + ¶ms, cache_info->entry_name); + if (mp_state->mp_read_session == INVALID_CACHED_MP_READ_SESSION) return (NS_UNAVAIL); - - cache_info->set_mp_rs_func(rs); } buffer_size = NSS_CACHE_BUFFER_INITIAL_SIZE; - buffer = (char *)malloc(NSS_CACHE_BUFFER_INITIAL_SIZE); + buffer = malloc(NSS_CACHE_BUFFER_INITIAL_SIZE); if (buffer == NULL) { - __close_cached_mp_read_session(rs); - rs = INVALID_CACHED_MP_READ_SESSION; - cache_info->set_mp_rs_func(rs); + __close_cached_mp_read_session(mp_state->mp_read_session); + mp_state->mp_read_session = INVALID_CACHED_MP_READ_SESSION; return (NS_UNAVAIL); } do { - res = __cached_mp_read(rs, buffer, &buffer_size); + res = __cached_mp_read(mp_state->mp_read_session, buffer, + &buffer_size); if (res == -2) { if (buffer_size > NSS_CACHE_BUFFER_SIZE_LIMIT) { free(buffer); res = -1; } else { - buffer = (char *)reallocf(buffer, buffer_size); + buffer = reallocf(buffer, buffer_size); if (buffer == NULL) { res = -1; break; @@ -343,7 +361,8 @@ } while (res == -2); unmarsh: - cache_info->set_mp_buffer_func(NULL, 0); + mp_state->mp_buffer = NULL; + mp_state->mp_bufsize = 0; if (res == 0) { va_copy(ap_new, ap); res = cache_info->unmarshal_func(buffer, buffer_size, retval, @@ -351,16 +370,19 @@ va_end(ap_new); if (res != NS_SUCCESS) { - if (res == NS_RETURN) - cache_info->set_mp_buffer_func(buffer, - buffer_size); - else + if (res == NS_RETURN) { + mp_state->mp_buffer = buffer; + mp_state->mp_bufsize = buffer_size; + } else free(buffer); return (res); } else res = 0; } else { free(buffer); + __close_cached_mp_read_session(mp_state->mp_read_session); + mp_state->mp_read_session = INVALID_CACHED_MP_READ_SESSION; + mp_state->finished = 1; return (res == -1 ? NS_RETURN : NS_UNAVAIL); } @@ -372,35 +394,38 @@ __nss_mp_cache_write(void *retval, void *mdata, va_list ap) { struct cached_connection_params params; - cached_mp_write_session ws; char *buffer; size_t buffer_size; - nss_cache_info const *cache_info; - nss_cache_data *cache_data; + struct nss_cache_info const *cache_info; + struct nss_cache_data *cache_data; + struct nss_mp_cache_state *mp_state; va_list ap_new; int res; - cache_data = (nss_cache_data *)mdata; + cache_data = mdata; cache_info = cache_data->info; - + mp_state = cache_info->get_mp_cache_state_func(); + + if ((mp_state == NULL) || + (mp_state->mp_read_session != INVALID_CACHED_MP_READ_SESSION)) + return (NS_UNAVAIL); + buffer_size = NSS_CACHE_BUFFER_INITIAL_SIZE; - buffer = (char *)malloc(NSS_CACHE_BUFFER_INITIAL_SIZE); + buffer = malloc(NSS_CACHE_BUFFER_INITIAL_SIZE); if (buffer == NULL) return (NS_UNAVAIL); - ws = cache_info->get_mp_ws_func(); - if (ws == INVALID_CACHED_MP_WRITE_SESSION) { + if (mp_state->mp_write_session == INVALID_CACHED_MP_WRITE_SESSION) { memset(¶ms, 0, sizeof(struct cached_connection_params)); params.socket_path = CACHED_SOCKET_PATH; - ws = __open_cached_mp_write_session(¶ms, - cache_info->entry_name); - if (ws == INVALID_CACHED_MP_WRITE_SESSION) + mp_state->mp_write_session = __open_cached_mp_write_session( + ¶ms, cache_info->entry_name); + if (mp_state->mp_write_session == + INVALID_CACHED_MP_WRITE_SESSION) return (NS_UNAVAIL); - - cache_info->set_mp_ws_func(ws); } do { @@ -418,7 +443,7 @@ buffer_size <<= 1; free(buffer); - buffer = (char *)malloc(buffer_size); + buffer = malloc(buffer_size); if (buffer == NULL) { res = NS_UNAVAIL; break; @@ -431,7 +456,8 @@ return (res); } - res = __cached_mp_write(ws, buffer, buffer_size); + res = __cached_mp_write(mp_state->mp_write_session, buffer, + buffer_size); free(buffer); return (res == 0 ? NS_SUCCESS : NS_UNAVAIL); @@ -440,48 +466,47 @@ int __nss_mp_cache_write_submit(void *retval, void *mdata, va_list ap) { - cached_mp_write_session ws; + struct nss_cache_info const *cache_info; + struct nss_cache_data *cache_data; + struct nss_mp_cache_state *mp_state; - nss_cache_info const *cache_info; - nss_cache_data *cache_data; - - cache_data = (nss_cache_data *)mdata; + cache_data = mdata; cache_info = cache_data->info; + mp_state = cache_info->get_mp_cache_state_func(); - ws = cache_info->get_mp_ws_func(); - if (ws != INVALID_CACHED_MP_WRITE_SESSION) { - __close_cached_mp_write_session(ws); - ws = INVALID_CACHED_MP_WRITE_SESSION; - cache_info->set_mp_ws_func(ws); + if ((mp_state != NULL) && (mp_state->mp_write_session != + INVALID_CACHED_MP_WRITE_SESSION)) { + __close_cached_mp_write_session(mp_state->mp_write_session); + mp_state->mp_write_session = INVALID_CACHED_MP_WRITE_SESSION; } + return (NS_UNAVAIL); } int >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200611241336.kAODajA2031267>