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

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