Blame SOURCES/autofs-5.0.9-amd-lookup-add-cache-partial-match-functions.patch

304803
autofs-5.0.9 - amd lookup add cache partial match functions
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
Partial key matching is used for amd. A prefix is possibly added to the key
304803
and if the map entry key has a trailing /* and matches the initial part of
304803
the key+prefix the match succeeds.
304803
304803
Update the existing partial match functions to help with this.
304803
---
304803
 include/automount.h |    1 +
304803
 lib/cache.c         |   38 +++++++++++++++++++++++++++++++++-----
304803
 2 files changed, 34 insertions(+), 5 deletions(-)
304803
304803
diff --git a/include/automount.h b/include/automount.h
304803
index 37133fe..ac6c4e3 100644
304803
--- a/include/automount.h
304803
+++ b/include/automount.h
304803
@@ -215,6 +215,7 @@ struct mapent *cache_lookup(struct mapent_cache *mc, const char *key);
304803
 struct mapent *cache_lookup_distinct(struct mapent_cache *mc, const char *key);
304803
 struct mapent *cache_lookup_offset(const char *prefix, const char *offset, int start, struct list_head *head);
304803
 struct mapent *cache_partial_match(struct mapent_cache *mc, const char *prefix);
304803
+struct mapent *cache_partial_match_wild(struct mapent_cache *mc, const char *prefix);
304803
 int cache_add(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age);
304803
 int cache_update_offset(struct mapent_cache *mc, const char *mkey, const char *key, const char *mapent, time_t age);
304803
 void cache_update_negative(struct mapent_cache *mc, struct map_source *ms, const char *key, time_t timeout);
304803
diff --git a/lib/cache.c b/lib/cache.c
304803
index 9af1709..8d08094 100644
304803
--- a/lib/cache.c
304803
+++ b/lib/cache.c
304803
@@ -566,7 +566,9 @@ struct mapent *cache_lookup_offset(const char *prefix, const char *offset, int s
304803
 }
304803
 
304803
 /* cache must be read locked by caller */
304803
-struct mapent *cache_partial_match(struct mapent_cache *mc, const char *prefix)
304803
+static struct mapent *__cache_partial_match(struct mapent_cache *mc,
304803
+					    const char *prefix,
304803
+					    unsigned int type)
304803
 {
304803
 	struct mapent *me = NULL;
304803
 	size_t len = strlen(prefix);
304803
@@ -578,20 +580,46 @@ struct mapent *cache_partial_match(struct mapent_cache *mc, const char *prefix)
304803
 			continue;
304803
 
304803
 		if (len < strlen(me->key) &&
304803
-		    (strncmp(prefix, me->key, len) == 0) && me->key[len] == '/')
304803
-			return me;
304803
+		    (strncmp(prefix, me->key, len) == 0) &&
304803
+		     me->key[len] == '/') {
304803
+			if (type == LKP_NORMAL)
304803
+				return me;
304803
+			if (type == LKP_WILD &&
304803
+			    me->key[len] != '\0' &&
304803
+			    me->key[len + 1] == '*')
304803
+				return me;
304803
+		}
304803
 
304803
 		me = me->next;
304803
 		while (me != NULL) {
304803
 			if (len < strlen(me->key) &&
304803
-			    strncmp(prefix, me->key, len) == 0 && me->key[len] == '/')
304803
-				return me;
304803
+			    (strncmp(prefix, me->key, len) == 0 &&
304803
+			    me->key[len] == '/')) {
304803
+				if (type == LKP_NORMAL)
304803
+					return me;
304803
+				if (type == LKP_WILD &&
304803
+				    me->key[len] != '\0' &&
304803
+				    me->key[len + 1] == '*')
304803
+					return me;
304803
+			}
304803
 			me = me->next;
304803
 		}
304803
 	}
304803
 	return NULL;
304803
 }
304803
 
304803
+/* cache must be read locked by caller */
304803
+struct mapent *cache_partial_match(struct mapent_cache *mc, const char *prefix)
304803
+{
304803
+	return __cache_partial_match(mc, prefix, LKP_NORMAL);
304803
+}
304803
+
304803
+/* cache must be read locked by caller */
304803
+struct mapent *cache_partial_match_wild(struct mapent_cache *mc, const char *prefix)
304803
+{
304803
+	return __cache_partial_match(mc, prefix, LKP_WILD);
304803
+}
304803
+
304803
 /* cache must be write locked by caller */
304803
 int cache_add(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age)
304803
 {