Blame SOURCES/autofs-5.0.8-pass-map_source-as-function-paramter-where-possible.patch

304803
autofs-5.0.8 - pass map_source as function paramter where possible
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
Some unnecessary complexity has been added along the way when passing
304803
the map source to functions in lookup modules. Improve that where
304803
possible.
304803
---
304803
 CHANGELOG                |    1 
304803
 modules/lookup_file.c    |   82 +++++++++++++++--------------------------------
304803
 modules/lookup_ldap.c    |   37 ++++++---------------
304803
 modules/lookup_nisplus.c |   36 ++++----------------
304803
 modules/lookup_yp.c      |   36 ++++----------------
304803
 5 files changed, 56 insertions(+), 136 deletions(-)
304803
304803
--- autofs-5.0.7.orig/CHANGELOG
304803
+++ autofs-5.0.7/CHANGELOG
304803
@@ -84,6 +84,7 @@
304803
 - fix cache readlock not taken on lookup.
304803
 - fix compilation of lookup_ldap.c without sasl.
304803
 - fix undefined authtype_requires_creds err if ldap enabled but without sasl.
304803
+- pass map_source as function paramter where possible.
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
--- autofs-5.0.7.orig/modules/lookup_file.c
304803
+++ autofs-5.0.7/modules/lookup_file.c
304803
@@ -529,21 +529,17 @@ static int check_self_include(const char
304803
 
304803
 static struct map_source *
304803
 prepare_plus_include(struct autofs_point *ap,
304803
+		     struct map_source *source,
304803
 		     time_t age, char *key, unsigned int inc,
304803
 		     struct lookup_context *ctxt)
304803
 {
304803
-	struct map_source *current;
304803
-	struct map_source *source;
304803
+	struct map_source *new;
304803
 	struct map_type_info *info;
304803
 	const char *argv[2];
304803
 	char **tmp_argv, **tmp_opts;
304803
 	int argc;
304803
 	char *buf;
304803
 
304803
-	current = ap->entry->current;
304803
-	ap->entry->current = NULL;
304803
-	master_source_current_signal(ap->entry);
304803
-
304803
 	/*
304803
 	 * TODO:
304803
 	 * Initially just consider the passed in key to be a simple map
304803
@@ -596,21 +592,21 @@ prepare_plus_include(struct autofs_point
304803
 	}
304803
 	argc += ctxt->opts_argc;
304803
 
304803
-	source = master_find_source_instance(current,
304803
-					     info->type, info->format,
304803
-					     argc, (const char **) tmp_argv);
304803
-	if (source) {
304803
+	new = master_find_source_instance(source,
304803
+					  info->type, info->format,
304803
+					  argc, (const char **) tmp_argv);
304803
+	if (new) {
304803
 		/*
304803
 		 * Make sure included map age is in sync with its owner
304803
 		 * or we could incorrectly wipe out its entries.
304803
 		 */
304803
-		source->age = age;
304803
-		source->stale = 1;
304803
+		new->age = age;
304803
+		new->stale = 1;
304803
 	} else {
304803
-		source = master_add_source_instance(current,
304803
-						    info->type, info->format, age,
304803
-						    argc, (const char **) tmp_argv);
304803
-		if (!source) {
304803
+		new = master_add_source_instance(source,
304803
+						 info->type, info->format, age,
304803
+						 argc, (const char **) tmp_argv);
304803
+		if (!new) {
304803
 			free_argv(argc, (const char **) tmp_argv);
304803
 			free_map_type_info(info);
304803
 			free(buf);
304803
@@ -620,14 +616,14 @@ prepare_plus_include(struct autofs_point
304803
 	}
304803
 	free_argv(argc, (const char **) tmp_argv);
304803
 
304803
-	source->depth = current->depth + 1;
304803
+	new->depth = source->depth + 1;
304803
 	if (inc)
304803
-		source->recurse = 1;
304803
+		new->recurse = 1;
304803
 
304803
 	free_map_type_info(info);
304803
 	free(buf);
304803
 
304803
-	return source;
304803
+	return new;
304803
 }
304803
 
304803
 int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
304803
@@ -689,10 +685,8 @@ int lookup_read_map(struct autofs_point
304803
 
304803
 			inc = check_self_include(key, ctxt);
304803
 
304803
-			master_source_current_wait(ap->entry);
304803
-			ap->entry->current = source;
304803
-
304803
-			inc_source = prepare_plus_include(ap, age, key, inc, ctxt);
304803
+			inc_source = prepare_plus_include(ap, source,
304803
+							  age, key, inc, ctxt);
304803
 			if (!inc_source) {
304803
 				debug(ap->logopt,
304803
 				      "failed to select included map %s", key);
304803
@@ -731,10 +725,10 @@ int lookup_read_map(struct autofs_point
304803
 }
304803
 
304803
 static int lookup_one(struct autofs_point *ap,
304803
+		      struct map_source *source,
304803
 		      const char *key, int key_len,
304803
 		      struct lookup_context *ctxt)
304803
 {
304803
-	struct map_source *source;
304803
 	struct mapent_cache *mc;
304803
 	char mkey[KEY_MAX_LEN + 1];
304803
 	char mapent[MAPENT_MAX_LEN + 1];
304803
@@ -743,10 +737,6 @@ static int lookup_one(struct autofs_poin
304803
 	unsigned int k_len, m_len;
304803
 	int entry, ret;
304803
 
304803
-	source = ap->entry->current;
304803
-	ap->entry->current = NULL;
304803
-	master_source_current_signal(ap->entry);
304803
-
304803
 	mc = source->mc;
304803
 
304803
 	f = open_fopen_r(ctxt->mapname);
304803
@@ -773,10 +763,8 @@ static int lookup_one(struct autofs_poin
304803
 
304803
 				inc = check_self_include(mkey, ctxt);
304803
 
304803
-				master_source_current_wait(ap->entry);
304803
-				ap->entry->current = source;
304803
-
304803
-				inc_source = prepare_plus_include(ap, age, mkey, inc, ctxt);
304803
+				inc_source = prepare_plus_include(ap, source,
304803
+								  age, mkey, inc, ctxt);
304803
 				if (!inc_source) {
304803
 					debug(ap->logopt,
304803
 					      MODPREFIX
304803
@@ -837,9 +825,9 @@ static int lookup_one(struct autofs_poin
304803
 	return CHE_MISSING;
304803
 }
304803
 
304803
-static int lookup_wild(struct autofs_point *ap, struct lookup_context *ctxt)
304803
+static int lookup_wild(struct autofs_point *ap,
304803
+		       struct map_source *source, struct lookup_context *ctxt)
304803
 {
304803
-	struct map_source *source;
304803
 	struct mapent_cache *mc;
304803
 	char mkey[KEY_MAX_LEN + 1];
304803
 	char mapent[MAPENT_MAX_LEN + 1];
304803
@@ -848,10 +836,6 @@ static int lookup_wild(struct autofs_poi
304803
 	unsigned int k_len, m_len;
304803
 	int entry, ret;
304803
 
304803
-	source = ap->entry->current;
304803
-	ap->entry->current = NULL;
304803
-	master_source_current_signal(ap->entry);
304803
-
304803
 	mc = source->mc;
304803
 
304803
 	f = open_fopen_r(ctxt->mapname);
304803
@@ -895,24 +879,17 @@ static int lookup_wild(struct autofs_poi
304803
 }
304803
 
304803
 static int check_map_indirect(struct autofs_point *ap,
304803
+			      struct map_source *source,
304803
 			      char *key, int key_len,
304803
 			      struct lookup_context *ctxt)
304803
 {
304803
-	struct map_source *source;
304803
 	struct mapent_cache *mc;
304803
 	struct mapent *exists;
304803
 	int ret = CHE_OK;
304803
 
304803
-	source = ap->entry->current;
304803
-	ap->entry->current = NULL;
304803
-	master_source_current_signal(ap->entry);
304803
-
304803
 	mc = source->mc;
304803
 
304803
-	master_source_current_wait(ap->entry);
304803
-	ap->entry->current = source;
304803
-
304803
-	ret = lookup_one(ap, key, key_len, ctxt);
304803
+	ret = lookup_one(ap, source, key, key_len, ctxt);
304803
 	if (ret == CHE_COMPLETED)
304803
 		return NSS_STATUS_COMPLETED;
304803
 
304803
@@ -935,10 +912,7 @@ static int check_map_indirect(struct aut
304803
 		struct mapent *we;
304803
 		int wild = CHE_MISSING;
304803
 
304803
-		master_source_current_wait(ap->entry);
304803
-		ap->entry->current = source;
304803
-
304803
-		wild = lookup_wild(ap, ctxt);
304803
+		wild = lookup_wild(ap, source, ctxt);
304803
 		/*
304803
 		 * Check for map change and update as needed for
304803
 		 * following cache lookup.
304803
@@ -1072,10 +1046,8 @@ int lookup_mount(struct autofs_point *ap
304803
 		if (!lkp_key)
304803
 			return NSS_STATUS_UNKNOWN;
304803
 
304803
-		master_source_current_wait(ap->entry);
304803
-		ap->entry->current = source;
304803
-
304803
-		status = check_map_indirect(ap, lkp_key, strlen(lkp_key), ctxt);
304803
+		status = check_map_indirect(ap, source,
304803
+					    lkp_key, strlen(lkp_key), ctxt);
304803
 		free(lkp_key);
304803
 		if (status) {
304803
 			if (status == NSS_STATUS_COMPLETED)
304803
--- autofs-5.0.7.orig/modules/lookup_ldap.c
304803
+++ autofs-5.0.7/modules/lookup_ldap.c
304803
@@ -2321,20 +2321,16 @@ next:
304803
 
304803
 
304803
 static int read_one_map(struct autofs_point *ap,
304803
+			struct map_source *source,
304803
 			struct lookup_context *ctxt,
304803
 			time_t age, int *result_ldap)
304803
 {
304803
-	struct map_source *source;
304803
 	struct ldap_search_params sp;
304803
 	char buf[MAX_ERR_BUF];
304803
 	char *class, *info, *entry;
304803
 	char *attrs[3];
304803
 	int rv, l;
304803
 
304803
-	source = ap->entry->current;
304803
-	ap->entry->current = NULL;
304803
-	master_source_current_signal(ap->entry);
304803
-
304803
 	/*
304803
 	 * If we don't need to create directories then there's no use
304803
 	 * reading the map. We always need to read the whole map for
304803
@@ -2453,11 +2449,16 @@ static int read_one_map(struct autofs_po
304803
 int lookup_read_map(struct autofs_point *ap, time_t age, void *context)
304803
 {
304803
 	struct lookup_context *ctxt = (struct lookup_context *) context;
304803
+	struct map_source *source;
304803
 	int rv = LDAP_SUCCESS;
304803
 	int ret, cur_state;
304803
 
304803
+	source = ap->entry->current;
304803
+	ap->entry->current = NULL;
304803
+	master_source_current_signal(ap->entry);
304803
+
304803
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
304803
-	ret = read_one_map(ap, ctxt, age, &rv;;
304803
+	ret = read_one_map(ap, source, ctxt, age, &rv;;
304803
 	if (ret != NSS_STATUS_SUCCESS) {
304803
 		switch (rv) {
304803
 		case LDAP_SIZELIMIT_EXCEEDED:
304803
@@ -2474,10 +2475,9 @@ int lookup_read_map(struct autofs_point
304803
 	return ret;
304803
 }
304803
 
304803
-static int lookup_one(struct autofs_point *ap,
304803
+static int lookup_one(struct autofs_point *ap, struct map_source *source,
304803
 		char *qKey, int qKey_len, struct lookup_context *ctxt)
304803
 {
304803
-	struct map_source *source;
304803
 	struct mapent_cache *mc;
304803
 	int rv, i, l, ql, count;
304803
 	char buf[MAX_ERR_BUF];
304803
@@ -2496,10 +2496,6 @@ static int lookup_one(struct autofs_poin
304803
 	unsigned int wild = 0;
304803
 	int ret = CHE_MISSING;
304803
 
304803
-	source = ap->entry->current;
304803
-	ap->entry->current = NULL;
304803
-	master_source_current_signal(ap->entry);
304803
-
304803
 	mc = source->mc;
304803
 
304803
 	if (ctxt == NULL) {
304803
@@ -2834,27 +2830,20 @@ next:
304803
 }
304803
 
304803
 static int check_map_indirect(struct autofs_point *ap,
304803
+			      struct map_source *source,
304803
 			      char *key, int key_len,
304803
 			      struct lookup_context *ctxt)
304803
 {
304803
-	struct map_source *source;
304803
 	struct mapent_cache *mc;
304803
 	struct mapent *me;
304803
 	time_t now = time(NULL);
304803
 	time_t t_last_read;
304803
 	int ret, cur_state;
304803
 
304803
-	source = ap->entry->current;
304803
-	ap->entry->current = NULL;
304803
-	master_source_current_signal(ap->entry);
304803
-
304803
 	mc = source->mc;
304803
 
304803
-	master_source_current_wait(ap->entry);
304803
-	ap->entry->current = source;
304803
-
304803
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
304803
-	ret = lookup_one(ap, key, key_len, ctxt);
304803
+	ret = lookup_one(ap, source, key, key_len, ctxt);
304803
 	if (ret == CHE_FAIL) {
304803
 		pthread_setcancelstate(cur_state, NULL);
304803
 		return NSS_STATUS_NOTFOUND;
304803
@@ -2974,10 +2963,8 @@ int lookup_mount(struct autofs_point *ap
304803
 		if (!lkp_key)
304803
 			return NSS_STATUS_UNKNOWN;
304803
 
304803
-		master_source_current_wait(ap->entry);
304803
-		ap->entry->current = source;
304803
-
304803
-		status = check_map_indirect(ap, lkp_key, strlen(lkp_key), ctxt);
304803
+		status = check_map_indirect(ap, source,
304803
+					    lkp_key, strlen(lkp_key), ctxt);
304803
 		free(lkp_key);
304803
 		if (status)
304803
 			return status;
304803
--- autofs-5.0.7.orig/modules/lookup_nisplus.c
304803
+++ autofs-5.0.7/modules/lookup_nisplus.c
304803
@@ -267,10 +267,10 @@ int lookup_read_map(struct autofs_point
304803
 }
304803
 
304803
 static int lookup_one(struct autofs_point *ap,
304803
+		      struct map_source *source,
304803
 		      const char *key, int key_len,
304803
 		      struct lookup_context *ctxt)
304803
 {
304803
-	struct map_source *source;
304803
 	struct mapent_cache *mc;
304803
 	char *tablename;
304803
 	nis_result *result;
304803
@@ -280,10 +280,6 @@ static int lookup_one(struct autofs_poin
304803
 	int ret, cur_state;
304803
 	char buf[MAX_ERR_BUF];
304803
 
304803
-	source = ap->entry->current;
304803
-	ap->entry->current = NULL;
304803
-	master_source_current_signal(ap->entry);
304803
-
304803
 	mc = source->mc;
304803
 
304803
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
304803
@@ -326,9 +322,9 @@ static int lookup_one(struct autofs_poin
304803
 	return ret;
304803
 }
304803
 
304803
-static int lookup_wild(struct autofs_point *ap, struct lookup_context *ctxt)
304803
+static int lookup_wild(struct autofs_point *ap,
304803
+		       struct map_source *source, struct lookup_context *ctxt)
304803
 {
304803
-	struct map_source *source;
304803
 	struct mapent_cache *mc;
304803
 	char *tablename;
304803
 	nis_result *result;
304803
@@ -338,10 +334,6 @@ static int lookup_wild(struct autofs_poi
304803
 	int ret, cur_state;
304803
 	char buf[MAX_ERR_BUF];
304803
 
304803
-	source = ap->entry->current;
304803
-	ap->entry->current = NULL;
304803
-	master_source_current_signal(ap->entry);
304803
-
304803
 	mc = source->mc;
304803
 
304803
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cur_state);
304803
@@ -383,27 +375,20 @@ static int lookup_wild(struct autofs_poi
304803
 }
304803
 
304803
 static int check_map_indirect(struct autofs_point *ap,
304803
+			      struct map_source *source,
304803
 			      char *key, int key_len,
304803
 			      struct lookup_context *ctxt)
304803
 {
304803
-	struct map_source *source;
304803
 	struct mapent_cache *mc;
304803
 	struct mapent *me, *exists;
304803
 	time_t now = time(NULL);
304803
 	time_t t_last_read;
304803
 	int ret = 0;
304803
 
304803
-	source = ap->entry->current;
304803
-	ap->entry->current = NULL;
304803
-	master_source_current_signal(ap->entry);
304803
-
304803
 	mc = source->mc;
304803
 
304803
-	master_source_current_wait(ap->entry);
304803
-	ap->entry->current = source;
304803
-
304803
 	/* check map and if change is detected re-read map */
304803
-	ret = lookup_one(ap, key, key_len, ctxt);
304803
+	ret = lookup_one(ap, source, key, key_len, ctxt);
304803
 	if (ret == CHE_FAIL)
304803
 		return NSS_STATUS_NOTFOUND;
304803
 
304803
@@ -452,10 +437,7 @@ static int check_map_indirect(struct aut
304803
 		int wild = CHE_MISSING;
304803
 		struct mapent *we;
304803
 
304803
-		master_source_current_wait(ap->entry);
304803
-		ap->entry->current = source;
304803
-
304803
-		wild = lookup_wild(ap, ctxt);
304803
+		wild = lookup_wild(ap, source, ctxt);
304803
 		/*
304803
 		 * Check for map change and update as needed for
304803
 		 * following cache lookup.
304803
@@ -553,10 +535,8 @@ int lookup_mount(struct autofs_point *ap
304803
 		if (!lkp_key)
304803
 			return NSS_STATUS_UNKNOWN;
304803
 
304803
-		master_source_current_wait(ap->entry);
304803
-		ap->entry->current = source;
304803
-
304803
-		status = check_map_indirect(ap, lkp_key, strlen(lkp_key), ctxt);
304803
+		status = check_map_indirect(ap, source,
304803
+					    lkp_key, strlen(lkp_key), ctxt);
304803
 		if (status)
304803
 			return status;
304803
 	}
304803
--- autofs-5.0.7.orig/modules/lookup_yp.c
304803
+++ autofs-5.0.7/modules/lookup_yp.c
304803
@@ -377,10 +377,10 @@ int lookup_read_map(struct autofs_point
304803
 }
304803
 
304803
 static int lookup_one(struct autofs_point *ap,
304803
+		      struct map_source *source,
304803
 		      const char *key, int key_len,
304803
 		      struct lookup_context *ctxt)
304803
 {
304803
-	struct map_source *source;
304803
 	struct mapent_cache *mc;
304803
 	char *mapname;
304803
 	char *mapent;
304803
@@ -388,10 +388,6 @@ static int lookup_one(struct autofs_poin
304803
 	time_t age = time(NULL);
304803
 	int ret;
304803
 
304803
-	source = ap->entry->current;
304803
-	ap->entry->current = NULL;
304803
-	master_source_current_signal(ap->entry);
304803
-
304803
 	mc = source->mc;
304803
 
304803
 	mapname = alloca(strlen(ctxt->mapname) + 1);
304803
@@ -436,9 +432,9 @@ static int lookup_one(struct autofs_poin
304803
 	return ret;
304803
 }
304803
 
304803
-static int lookup_wild(struct autofs_point *ap, struct lookup_context *ctxt)
304803
+static int lookup_wild(struct autofs_point *ap,
304803
+		       struct map_source *source, struct lookup_context *ctxt)
304803
 {
304803
-	struct map_source *source;
304803
 	struct mapent_cache *mc;
304803
 	char *mapname;
304803
 	char *mapent;
304803
@@ -446,10 +442,6 @@ static int lookup_wild(struct autofs_poi
304803
 	time_t age = time(NULL);
304803
 	int ret;
304803
 
304803
-	source = ap->entry->current;
304803
-	ap->entry->current = NULL;
304803
-	master_source_current_signal(ap->entry);
304803
-
304803
 	mc = source->mc;
304803
 
304803
 	mapname = alloca(strlen(ctxt->mapname) + 1);
304803
@@ -489,26 +481,19 @@ static int lookup_wild(struct autofs_poi
304803
 }
304803
 
304803
 static int check_map_indirect(struct autofs_point *ap,
304803
+			      struct map_source *source,
304803
 			      char *key, int key_len,
304803
 			      struct lookup_context *ctxt)
304803
 {
304803
-	struct map_source *source;
304803
 	struct mapent_cache *mc;
304803
 	struct mapent *exists;
304803
 	unsigned int map_order;
304803
 	int ret = 0;
304803
 
304803
-	source = ap->entry->current;
304803
-	ap->entry->current = NULL;
304803
-	master_source_current_signal(ap->entry);
304803
-
304803
 	mc = source->mc;
304803
 
304803
-	master_source_current_wait(ap->entry);
304803
-	ap->entry->current = source;
304803
-
304803
 	/* check map and if change is detected re-read map */
304803
-	ret = lookup_one(ap, key, key_len, ctxt);
304803
+	ret = lookup_one(ap, source, key, key_len, ctxt);
304803
 	if (ret == CHE_FAIL)
304803
 		return NSS_STATUS_NOTFOUND;
304803
 
304803
@@ -556,10 +541,7 @@ static int check_map_indirect(struct aut
304803
 		struct mapent *we;
304803
 		int wild = CHE_MISSING;
304803
 
304803
-		master_source_current_wait(ap->entry);
304803
-		ap->entry->current = source;
304803
-
304803
-		wild = lookup_wild(ap, ctxt);
304803
+		wild = lookup_wild(ap, source, ctxt);
304803
 		/*
304803
 		 * Check for map change and update as needed for
304803
 		 * following cache lookup.
304803
@@ -657,10 +639,8 @@ int lookup_mount(struct autofs_point *ap
304803
 		if (!lkp_key)
304803
 			return NSS_STATUS_UNKNOWN;
304803
 
304803
-		master_source_current_wait(ap->entry);
304803
-		ap->entry->current = source;
304803
-
304803
-		status = check_map_indirect(ap, lkp_key, strlen(lkp_key), ctxt);
304803
+		status = check_map_indirect(ap, source,
304803
+					    lkp_key, strlen(lkp_key), ctxt);
304803
 		free(lkp_key);
304803
 		if (status)
304803
 			return status;