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

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