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