PERFORCE change 87074 for review

soc-bushman soc-bushman at FreeBSD.org
Tue Nov 22 06:36:38 PST 2005


http://perforce.freebsd.org/chv.cgi?CH=87074

Change 87074 by soc-bushman at soc-bushman_stinger on 2005/11/22 14:36:04

	comments added to the libc sources
	several significant bugfixes in the daemon

Affected files ...

.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/Makefile#10 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/Makefile#15 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agent.c#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agent.h#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/Makefile.inc#10 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/group.c#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/group.h#7 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/hosts.c#10 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/hosts.h#10 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/passwd.c#10 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/passwd.h#10 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/services.c#10 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/services.h#10 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.8#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.c#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf.5#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.c#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.h#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.c#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.h#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.c#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.h#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.c#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.h#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/hashtable.h#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.c#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.h#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.c#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.h#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.c#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.h#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/parser.c#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/parser.h#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/protocol.c#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/protocol.h#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/query.c#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/query.h#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/singletons.c#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/singletons.h#14 edit
.. //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/startup/cached#9 edit
.. //depot/projects/soc2005/nsswitch_cached/src/include/nscache.h#7 edit
.. //depot/projects/soc2005/nsswitch_cached/src/include/nscachedcli.h#5 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nscache.c#7 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nscachedcli.c#7 edit
.. //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nsdispatch.c#11 edit

Differences ...

==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/Makefile#10 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/Makefile#15 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agent.c#7 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agent.h#7 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/Makefile.inc#10 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/group.c#7 (text+ko) ====

@@ -128,16 +128,14 @@
 	assert(buffer != NULL);
 	assert(buffer_size != NULL);
 
-	TRACE_INT(key_size);
 	if (key_size < sizeof(enum nss_lookup_type)) {
 		TRACE_OUT(group_lookup_func);
 		return (NS_UNAVAIL);
 	}
 	memcpy(&lookup_type, key, sizeof(enum nss_lookup_type));
-	TRACE_INT(lookup_type);
+
 	switch (lookup_type) {
 	case nss_lt_name:
-		TRACE_POINT();
 		size = key_size - sizeof(enum nss_lookup_type)	+ 1;
 		name = (char *)malloc(size);
 		assert(name != NULL);
@@ -145,18 +143,15 @@
 		memcpy(name, key + sizeof(enum nss_lookup_type), size - 1);
 		break;
 	case nss_lt_id:
-		TRACE_POINT();
 		if (key_size < sizeof(enum nss_lookup_type) +
 			sizeof(gid_t)) {
 			TRACE_OUT(passwd_lookup_func);
 			return (NS_UNAVAIL);
 		}
 		
-		TRACE_POINT();
 		memcpy(&gid, key + sizeof(enum nss_lookup_type), sizeof(gid_t));
 		break;
 	default:
-		TRACE_POINT();
 		TRACE_OUT(group_lookup_func);
 		return (NS_UNAVAIL);
 	}
@@ -168,7 +163,6 @@
 		free(name);
 		break;
 	case nss_lt_id:
-		TRACE_INT(gid);
 		result = getgrgid(gid);
 		break;
 	default:
@@ -177,7 +171,6 @@
 	}
 	
 	if (result != NULL) {
-		TRACE_POINT();
 		group_marshal_func(result, NULL, buffer_size);
 		*buffer = (char *)malloc(*buffer_size);
 		assert(*buffer != NULL);

==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/group.h#7 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/hosts.c#10 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/hosts.h#10 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/passwd.c#10 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/passwd.h#10 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/services.c#10 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/agents/services.h#10 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.8#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.c#14 (text+ko) ====

@@ -253,7 +253,7 @@
 	retval->queue = kqueue();
 	assert(retval->queue != -1);
 	
-	EV_SET(&eventlist, retval->sockfd, EVFILT_READ, EV_ADD | EV_CLEAR,
+	EV_SET(&eventlist, retval->sockfd, EVFILT_READ, EV_ADD | EV_ONESHOT,
 		0, 0, 0);
 	memset(&timeout, 0, sizeof(struct timespec));
 	kevent(retval->queue, &eventlist, 1, NULL, 0, &timeout);		
@@ -281,8 +281,6 @@
 	struct timespec	timeout;
 	struct query_state	*qstate;
 	
-	struct sockaddr	addr;
-	socklen_t addr_len;
 	int	fd;
 	int	res;
 	
@@ -290,11 +288,10 @@
 	gid_t	egid;
 		
 	TRACE_IN(accept_connection);
-	addr_len = sizeof(struct sockaddr);
-	fd = accept(event_data->ident, &addr, &addr_len);
+	fd = accept(event_data->ident, NULL, NULL);
 	if (fd == -1) {
 		LOG_ERR_2("accept_connection", "error %d during accept()", 
-			errno);
+		    errno);
 		TRACE_OUT(accept_connection);
 		return;
 	}
@@ -319,7 +316,7 @@
 	EV_SET(&eventlist[1], fd, EVFILT_READ, EV_ADD | EV_ONESHOT, 
 		NOTE_LOWAT, qstate->kevent_watermark, qstate);
 	res = kevent(env->queue, eventlist, 2, NULL, 0, &timeout);	
-	
+		
 	TRACE_OUT(accept_connection);
 }
 
@@ -519,7 +516,7 @@
 	struct query_state	*qstate;
 		
 	TRACE_IN(process_timer_event);
-	LOG_MSG_2("processing_timer_event", "timer event received - "
+	LOG_MSG_2("process_timer_event", "timer event received - "
 		"abandoning request");
 	qstate = (struct query_state *)event_data->udata;
 	destroy_query_state(qstate);
@@ -538,7 +535,7 @@
 	struct timespec timeout;
 	const int eventlist_size = 1;
 	struct kevent eventlist[eventlist_size];
-	int nevents;
+	int nevents, i;
 	
 	TRACE_MSG("=> processing_loop");
 	memset(&timeout, 0, sizeof(struct timespec));
@@ -555,9 +552,19 @@
 			struct kevent *event_data;
 			event_data = &eventlist[0];
 					
-			if (event_data->ident == env->sockfd)
-				accept_connection(event_data, env, config);
-			else {
+			if (event_data->ident == env->sockfd) {
+				for (i = 0; i < event_data->data; ++i)
+				    accept_connection(event_data, env, config);
+				
+					EV_SET(eventlist, s_runtime_env->sockfd, 
+					    EVFILT_READ, EV_ADD | EV_ONESHOT,
+					    0, 0, 0);
+					memset(&timeout, 0, 
+					    sizeof(struct timespec));
+					kevent(s_runtime_env->queue, eventlist,
+					    1, NULL, 0, &timeout);		
+				
+			} else {
 				switch (event_data->filter) {
 				case EVFILT_READ:
 				case EVFILT_WRITE:

==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf#14 (text+ko) ====

@@ -1,7 +1,6 @@
 #
 # Default caching daemon configuration file
 #
-
 enable-cache passwd yes
 enable-cache group yes
 enable-cache hosts yes

==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cached.conf.5#14 (text+ko) ====

@@ -97,4 +97,4 @@
 .Aq bushman at rsu.ru
 .Sh "BUGS"
 To report bugs or suggestions please mail me 
-.Aq bushman at rsu.ru.
+.Aq bushman at rsu.ru

==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.c#14 (text+ko) ====

@@ -381,7 +381,6 @@
 	item = policy->get_first_item_func(policy);
 	while ((item != NULL) && (continue_func(entry, item) == 1)) {
 		next_item = policy->get_next_item_func(policy, item);
-		TRACE_PTR(next_item);
 				
 		connected_item = item->connected_item;
 		policy->remove_item_func(policy, item);
@@ -390,30 +389,20 @@
 		ht_key.key = item->key;
 		ht_key.key_size = item->key_size;
 
-		TRACE_POINT();
 		hash = HASHTABLE_CALCULATE_HASH(cache_ht_, &entry->items, 
 			&ht_key);
 		assert(hash >= 0);
 		assert(hash < HASHTABLE_ENTRIES_COUNT(&entry->items));
 				
-		TRACE_POINT();
 		ht_item = HASHTABLE_GET_ENTRY(&(entry->items), hash);
-		TRACE_POINT();
 		ht_item_data = HASHTABLE_ENTRY_FIND(cache_ht_, ht_item, 
 			&ht_key);
 		assert(ht_item_data != NULL);
-		TRACE_POINT();
-		TRACE_POINT();
-		TRACE_PTR(ht_item_data->key);
-		TRACE_INT(ht_item_data->key_size);
 		free(ht_item_data->key);
-		TRACE_POINT();
 		free(ht_item_data->value);
-		TRACE_POINT();
 		HASHTABLE_ENTRY_REMOVE(cache_ht_, ht_item, ht_item_data);
 		--entry->items_size;
 
-		TRACE_POINT();
 		policy->destroy_item_func(item);
 		
 		if (connected_item != NULL) {
@@ -756,7 +745,6 @@
 				
 			free(find_res->key);
 			free(find_res->value);
-			HASHTABLE_ENTRY_REMOVE(cache_ht_, item, find_res);
 					
 			connected_item = 
 			    find_res->fifo_policy_item->connected_item;
@@ -774,6 +762,7 @@
 			common_entry->policies[0]->destroy_item_func(
 				find_res->fifo_policy_item);
 			
+			HASHTABLE_ENTRY_REMOVE(cache_ht_, item, find_res);
 			--common_entry->items_size;
 		}
 	}
@@ -1213,7 +1202,6 @@
 			if (ht_item_data != NULL) {
 			    item = ht_item_data->fifo_policy_item;
 			    connected_item = item->connected_item;
-			
 						
 			    common_entry->policies[0]->remove_item_func(
 				common_entry->policies[0],

==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cachelib.h#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.c#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/cacheplcs.h#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.c#14 (text+ko) ====

@@ -353,10 +353,12 @@
 		config_entry->mp_cache_entries_size);
 	assert(new_mp_entries != NULL);
 	new_mp_entries[0] = c_entry;
+
 	if (config_entry->mp_cache_entries_size - 1 > 0) {
 		memcpy(new_mp_entries + 1, 
 		    config_entry->mp_cache_entries,
-		    config_entry->mp_cache_entries_size - 1);
+		    (config_entry->mp_cache_entries_size - 1) * 
+		    sizeof(cache_entry));
 	}
 
 	old_mp_entries = config_entry->mp_cache_entries;
@@ -369,7 +371,6 @@
 		configuration_entry_cache_mp_sort_cmp);
 	
 	TRACE_OUT(configuration_entry_add_mp_cache_entry);
-
 	return (0);
 }
 

==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/config.h#14 (text+ko) ====

@@ -40,16 +40,16 @@
 
 #define DEFAULT_COMMON_ENTRY_TIMEOUT	10
 #define DEFAULT_MP_ENTRY_TIMEOUT	60
-#define DEFAULT_CACHE_HT_SIZE		1 //257
+#define DEFAULT_CACHE_HT_SIZE		257
 
 #define INITIAL_ENTRIES_CAPACITY	8
 #define DEFAULT_SOCKET_PATH		"/var/run/cached"
 #define DEFAULT_PIDFILE_PATH		"/var/run/cached.pid"
 
-#define DEFAULT_POSITIVE_ELEMENTS_SIZE	1 // (2048)
+#define DEFAULT_POSITIVE_ELEMENTS_SIZE	(2048)
 #define DEFAULT_POSITIVE_LIFETIME 	(60 * 60 * 12)
 
-#define DEFAULT_NEGATIVE_ELEMENTS_SIZE	2 // (512)
+#define DEFAULT_NEGATIVE_ELEMENTS_SIZE	(512)
 #define DEFAULT_NEGATIVE_LIFETIME	(60 * 60)
 
 #define DEFAULT_MULTIPART_ELEMENTS_SIZE	(1024 * 8)

==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.c#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/debug.h#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/hashtable.h#14 (text+ko) ====

@@ -191,7 +191,7 @@
 									\
 	memmove(del_elm, del_elm + 1, 					\
 		(&the_entry->field.values[--the_entry->field.size] - del_elm) *\
-			sizeof(type));					\
+		sizeof(type));						\
 }
 
 /*

==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.c#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/log.h#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.c#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_rs_query.h#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.c#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/mp_ws_query.h#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/parser.c#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/parser.h#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/protocol.c#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/protocol.h#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/query.c#14 (text+ko) ====

@@ -132,7 +132,6 @@
 			CTT_CLEAR, eid_str, eid_str_length, KPPT_LEFT);	
 	configuration_unlock_entry(config_entry, CELT_NEGATIVE);
 	
-
 	configuration_lock_entry(config_entry, CELT_MULTIPART);	
 	if (configuration_entry_find_mp_cache_entries(config_entry,
 		eid_str, &start, &finish) == 0) {
@@ -950,21 +949,15 @@
 	switch (transform_request->transformation_type) {
 	case TT_USER:
 		if (transform_request->entry == NULL) {
-			configuration_lock_rdlock(s_configuration);
-			
 			size = configuration_get_entries_size(s_configuration);
 			for (i = 0; i < size; ++i) {			    
 			    clear_config_entry_part(configuration_get_entry(
 				s_configuration, i), qstate->eid_str,
 				qstate->eid_str_length);	
 			}
-			
-			configuration_unlock(s_configuration);			
 		} else {
-			configuration_lock_rdlock(s_configuration);
 			qstate->config_entry = configuration_find_entry(
 				s_configuration, transform_request->entry);				
-			configuration_unlock(s_configuration);
 			
 			if (qstate->config_entry == NULL) {
 				LOG_ERR_2("transform_request",
@@ -984,8 +977,6 @@
 			transform_response->error_code = -1;
 		else {
 			if (transform_request->entry == NULL) {
-				configuration_lock_rdlock(s_configuration);
-			
 				size = configuration_get_entries_size(
 					s_configuration);
 				for (i = 0; i < size; ++i) {			    
@@ -993,14 +984,10 @@
 					configuration_get_entry(
 						s_configuration, i));	
 				}
-			
-				configuration_unlock(s_configuration);	
 			} else {
-				configuration_lock_rdlock(s_configuration);
 				qstate->config_entry = configuration_find_entry(
 					s_configuration, 
 					transform_request->entry);
-				configuration_unlock(s_configuration);
 				
 				if (qstate->config_entry == NULL) {
 					LOG_ERR_2("transform_request",

==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/query.h#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/singletons.c#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/cached/singletons.h#14 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/release/cached-0.2/startup/cached#9 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/src/include/nscache.h#7 (text+ko) ====

@@ -34,27 +34,40 @@
 typedef int (*nss_cache_unmarshal_func_t)(char *, size_t, void *, va_list, 
 	void *);
 
-typedef	void	(*nss_set_mp_ws_func_t)(cached_mp_write_session);
+typedef	void (*nss_set_mp_ws_func_t)(cached_mp_write_session);
 typedef	cached_mp_write_session	(*nss_get_mp_ws_func_t)(void);
 
-typedef void	(*nss_set_mp_rs_func_t)(cached_mp_read_session);
+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_cache_info {
 	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;
+	/* 
+	 * 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_set_mp_ws_func_t set_mp_ws_func;
-	nss_get_mp_ws_func_t get_mp_ws_func;
+	/* 
+	 * 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 */
 	
-	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; /* sets current read session */
+	nss_get_mp_rs_func_t get_mp_rs_func; /* gets current read session */
 } 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;			\
@@ -126,12 +139,21 @@
 	return (mp_state->mp_read_session);				\
 }																				
 
+/*
+ * 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}
 #define NS_MP_CACHE_INFO_INITIALIZER(name, mdata, mf, uf)		\
-	{#name, mdata, NULL, mf, uf, name##_set_mp_ws, name##_get_mp_ws, \
+	{#name, mdata, NULL, mf, uf, name##_set_mp_ws, name##_get_mp_ws,\
 		name##_set_mp_rs, name##_get_mp_rs }
 
+/*
+ * Analog of other XXX_CB macros. Has the pointer to _nss_cache_info
+ * structure as the only argument.
+ */
 #define NS_CACHE_CB(cinfo) {NSSRC_CACHE, nss_cache_handler, (void *)(cinfo) },
 
 /* args are: current pointer, current buffer, initial buffer, pointer type */
@@ -139,7 +161,7 @@
 	if ((cp) != NULL)														\
 		(cp) = (p_type)((char *)(cb) + (size_t)(cp) - (size_t)(ib))
 /* 
- * gets new pointer from the marshalled buffer by uisng initial address 	
+ * Gets new pointer from the marshalled buffer by uisng initial address 	
  * and initial buffer address 
  */
 #define NS_GET_NEWP(cp, cb, ib)						\
@@ -153,6 +175,7 @@
 } nss_cache_data;
 
 __BEGIN_DECLS
+/* dummy function, which is needed to make nss_method_lookup happy */
 extern	int	nss_cache_handler(void *, void *, va_list);
 
 #ifdef _NS_PRIVATE

==== //depot/projects/soc2005/nsswitch_cached/src/include/nscachedcli.h#5 (text+ko) ====

@@ -58,16 +58,17 @@
 
 struct cached_connection_ {
 	int	sockfd;
-	int read_queue;
-	int write_queue;
+	int	read_queue;
+	int	write_queue;
 	
-	int	mp_flag;
+	int	mp_flag;	/* shows if the connection is used for 
+				 * multipart operations */
 };
 
 /* simple abstractions for not to write "struct" every time */
-typedef struct cached_connection_		*cached_connection;
-typedef struct cached_connection_		*cached_mp_write_session;
-typedef struct cached_connection_		*cached_mp_read_session;
+typedef struct cached_connection_	*cached_connection;
+typedef struct cached_connection_	*cached_mp_write_session;
+typedef struct cached_connection_	*cached_mp_read_session;
 	
 #define	INVALID_CACHED_CONNECTION	(NULL)
 #define INVALID_CACHED_MP_WRITE_SESSION	(NULL)
@@ -76,27 +77,27 @@
 __BEGIN_DECLS
 
 /* initialization/destruction routines */
-extern	cached_connection	open_cached_connection(
+extern	cached_connection open_cached_connection(
 	struct cached_connection_params const *);
-extern	void	close_cached_connection(cached_connection);
+extern	void close_cached_connection(cached_connection);
 	
 /* simple read/write operations */
-extern	int	cached_write(cached_connection, const char *, const char *, 
+extern	int cached_write(cached_connection, const char *, const char *, 
 	size_t, const char *, size_t);
 extern	int cached_read(cached_connection, const char *, const char *, 
 	size_t, char *, size_t *);
 
 /* multipart read/write operations */
-extern	cached_mp_write_session	open_cached_mp_write_session(
+extern	cached_mp_write_session open_cached_mp_write_session(
 	struct cached_connection_params const *, const char *);
-extern	int	cached_mp_write(cached_mp_write_session, const char *, size_t);
-extern	int	abandon_cached_mp_write_session(cached_mp_write_session);
-extern	int	close_cached_mp_write_session(cached_mp_write_session);
+extern	int cached_mp_write(cached_mp_write_session, const char *, size_t);
+extern	int abandon_cached_mp_write_session(cached_mp_write_session);
+extern	int close_cached_mp_write_session(cached_mp_write_session);
 
 extern	cached_mp_read_session	open_cached_mp_read_session(
 	struct cached_connection_params const *, const char *);
-extern	int	cached_mp_read(cached_mp_read_session, char *, size_t *);
-extern	int	close_cached_mp_read_session(cached_mp_read_session);
+extern	int cached_mp_read(cached_mp_read_session, char *, size_t *);
+extern	int close_cached_mp_read_session(cached_mp_read_session);
 
 __END_DECLS
 

==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nscache.c#7 (text+ko) ====


==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nscachedcli.c#7 (text+ko) ====

@@ -45,6 +45,12 @@
 static int safe_read(struct cached_connection_ *, void *, size_t);
 static int send_credentials(struct cached_connection_ *, int);
 	
+/*
+ * safe_write writes data to the specified connection and tries to do it in
+ * the very safe manner. We ensure, that we can write to the socket with
+ * kevent. If the data_size can't be send in one piece, then it would be
+ * splitted.
+ */
 static int
 safe_write(struct cached_connection_ *connection, const void *data, 
 	size_t data_size)
@@ -82,6 +88,12 @@
 	return (0);	
 }
 
+/*
+ * safe_read reads data from connection and tries to do it in the very safe
+ * and stable way. It uses kevent to ensure, that the data are availabe for
+ * reading. If the amount of data to be read is too large, then they would
+ * be splitted.
+ */
 static int
 safe_read(struct cached_connection_ *connection, void *data, size_t data_size)
 {
@@ -118,6 +130,10 @@
 	return (0);
 }
 
+/*
+ * Sends the credentials information to the connection along with the 
+ * communication element type.
+ */
 static int
 send_credentials(struct cached_connection_ *connection, int type)
 {
@@ -164,6 +180,9 @@
 		return (-1);
 }
 
+/*
+ * Opens the connection with the specified params. Initializes all kqueues.
+ */
 struct cached_connection_ *
 open_cached_connection(struct cached_connection_params const *params)
 {
@@ -224,6 +243,11 @@
 	free(connection);
 }
 
+/*
+ * This function is very close to the cache_write function of the caching
+ * library, which is used in the caching daemon. It caches the data with the
+ * specified key in the cache entry with entry_name.
+ */
 int
 cached_write(struct cached_connection_ *connection, const char *entry_name, 
 	const char *key, size_t key_size, const char *data, size_t data_size)
@@ -271,6 +295,11 @@
 	return (error_code);
 }
 
+/*
+ * This function is very close to the cache_read function of the caching
+ * library, which is used in the caching daemon. It reads cached data with the
+ * specified key from the cache entry with entry_name.
+ */
 int
 cached_read(struct cached_connection_ *connection, const char *entry_name, 
 	const char *key, size_t key_size, char *data, size_t *data_size)
@@ -334,6 +363,13 @@
 	return (error_code);
 }
 
+/*
+ * Initializes the mp_write_session. For such a session the new connection
+ * would be opened. The data should be written to the session with
+ * cached_mp_write function. The close_cached_mp_write_session function
+ * should be used to submit session and abandon_cached_mp_write_session - to
+ * abandon it. When the session is submitted, the whole se
+ */
 struct cached_connection_ *
 open_cached_mp_write_session(struct cached_connection_params const *params, 
     const char *entry_name)

==== //depot/projects/soc2005/nsswitch_cached/src/lib/libc/net/nsdispatch.c#11 (text+ko) ====



More information about the p4-projects mailing list