autofs/autofs-5.1.7-remove-obsolete-functions.patch

753 lines
20 KiB
Diff
Raw Normal View History

autofs-5.1.7 - remove obsolete functions
From: Ian Kent <raven@themaw.net>
Remove the code that's no longer used due to the tree mapent
implementation.
Signed-off-by: Ian Kent <raven@themaw.net>
---
CHANGELOG | 1
include/automount.h | 10 --
include/mounts.h | 2
lib/cache.c | 227 -------------------------------------
lib/mounts.c | 311 ---------------------------------------------------
modules/parse_sun.c | 56 ---------
6 files changed, 2 insertions(+), 605 deletions(-)
diff --git a/CHANGELOG b/CHANGELOG
index 5ac09f77..76fccf70 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -41,6 +41,7 @@
- add set_offset_tree_catatonic().
- add mount and umount offsets functions.
- switch to use tree implementation for offsets.
+- remove obsolete functions.
25/01/2021 autofs-5.1.7
- make bind mounts propagation slave by default.
diff --git a/include/automount.h b/include/automount.h
index a71b8674..e33ee8d2 100644
--- a/include/automount.h
+++ b/include/automount.h
@@ -162,16 +162,13 @@ struct stack {
struct mapent {
struct mapent *next;
struct list_head ino_index;
- struct list_head multi_list;
struct mapent_cache *mc;
struct map_source *source;
/* Need to know owner if we're a multi-mount */
struct tree_node *mm_root;
+ /* Parent nesting point within multi-mount */
struct tree_node *mm_parent;
struct tree_node node;
- struct mapent *multi;
- /* Parent nesting point within multi-mount */
- struct mapent *parent;
char *key;
size_t len;
char *mapent;
@@ -209,7 +206,6 @@ struct mapent *cache_lookup_next(struct mapent_cache *mc, struct mapent *me);
struct mapent *cache_lookup_key_next(struct mapent *me);
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);
@@ -217,16 +213,12 @@ int cache_update_offset(struct mapent_cache *mc, const char *mkey, const char *k
int cache_lookup_negative(struct mapent *me, const char *key);
void cache_update_negative(struct mapent_cache *mc, struct map_source *ms, const char *key, time_t timeout);
struct mapent *cache_get_offset_parent(struct mapent_cache *mc, const char *key);
-int cache_set_offset_parent(struct mapent_cache *mc, const char *offset);
int cache_update(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age);
int cache_delete(struct mapent_cache *mc, const char *key);
-int cache_delete_offset(struct mapent_cache *mc, const char *key);
-int cache_delete_offset_list(struct mapent_cache *mc, const char *key);
void cache_release(struct map_source *map);
void cache_clean_null_cache(struct mapent_cache *mc);
void cache_release_null_cache(struct master *master);
struct mapent *cache_enumerate(struct mapent_cache *mc, struct mapent *me);
-char *cache_get_offset(const char *prefix, char *offset, int start, struct list_head *head, struct list_head **pos);
/* Utility functions */
diff --git a/include/mounts.h b/include/mounts.h
index e56f80ba..ec895e1c 100644
--- a/include/mounts.h
+++ b/include/mounts.h
@@ -187,8 +187,6 @@ void set_indirect_mount_tree_catatonic(struct autofs_point *);
void set_direct_mount_tree_catatonic(struct autofs_point *, struct mapent *);
int umount_ent(struct autofs_point *, const char *);
int umount_amd_ext_mount(struct autofs_point *, const char *);
-int mount_multi_triggers(struct autofs_point *, struct mapent *, const char *, unsigned int, const char *);
-int umount_multi_triggers(struct autofs_point *, struct mapent *, char *, const char *);
int clean_stale_multi_triggers(struct autofs_point *, struct mapent *, char *, const char *);
#endif
diff --git a/lib/cache.c b/lib/cache.c
index 93b02daf..ef761739 100644
--- a/lib/cache.c
+++ b/lib/cache.c
@@ -461,30 +461,6 @@ struct mapent *cache_lookup_distinct(struct mapent_cache *mc, const char *key)
return NULL;
}
-/* Lookup an offset within a multi-mount entry */
-struct mapent *cache_lookup_offset(const char *prefix, const char *offset, int start, struct list_head *head)
-{
- struct list_head *p;
- struct mapent *this;
- /* Keys for direct maps may be as long as a path name */
- char o_key[PATH_MAX];
- /* Avoid "//" at the beginning of paths */
- const char *path_prefix = strlen(prefix) > 1 ? prefix : "";
- size_t size;
-
- /* root offset duplicates "/" */
- size = snprintf(o_key, sizeof(o_key), "%s%s", path_prefix, offset);
- if (size >= sizeof(o_key))
- return NULL;
-
- list_for_each(p, head) {
- this = list_entry(p, struct mapent, multi_list);
- if (!strcmp(&this->key[start], o_key))
- return this;
- }
- return NULL;
-}
-
/* cache must be read locked by caller */
static struct mapent *__cache_partial_match(struct mapent_cache *mc,
const char *prefix,
@@ -583,9 +559,6 @@ int cache_add(struct mapent_cache *mc, struct map_source *ms, const char *key, c
me->mm_parent = NULL;
INIT_TREE_NODE(&me->node);
INIT_LIST_HEAD(&me->ino_index);
- INIT_LIST_HEAD(&me->multi_list);
- me->multi = NULL;
- me->parent = NULL;
me->ioctlfd = -1;
me->dev = (dev_t) -1;
me->ino = (ino_t) -1;
@@ -615,33 +588,6 @@ int cache_add(struct mapent_cache *mc, struct map_source *ms, const char *key, c
return CHE_OK;
}
-/* cache must be write locked by caller */
-static void cache_add_ordered_offset(struct mapent *me, struct list_head *head)
-{
- struct list_head *p;
- struct mapent *this;
-
- list_for_each(p, head) {
- size_t tlen;
- int eq;
-
- this = list_entry(p, struct mapent, multi_list);
- tlen = strlen(this->key);
-
- eq = strncmp(this->key, me->key, tlen);
- if (!eq && tlen == strlen(me->key))
- return;
-
- if (eq > 0) {
- list_add_tail(&me->multi_list, p);
- return;
- }
- }
- list_add_tail(&me->multi_list, p);
-
- return;
-}
-
/* cache must be write locked by caller */
int cache_update_offset(struct mapent_cache *mc, const char *mkey, const char *key, const char *mapent, time_t age)
{
@@ -777,25 +723,6 @@ struct mapent *cache_get_offset_parent(struct mapent_cache *mc, const char *key)
return NULL;
}
-int cache_set_offset_parent(struct mapent_cache *mc, const char *offset)
-{
- struct mapent *this, *parent;
-
- this = cache_lookup_distinct(mc, offset);
- if (!this)
- return 0;
- if (!IS_MM(this))
- return 0;
-
- parent = cache_get_offset_parent(mc, offset);
- if (parent)
- this->parent = parent;
- else
- this->parent = MM_ROOT(this);
-
- return 1;
-}
-
/* cache must be write locked by caller */
int cache_update(struct mapent_cache *mc, struct map_source *ms, const char *key, const char *mapent, time_t age)
{
@@ -837,50 +764,6 @@ int cache_update(struct mapent_cache *mc, struct map_source *ms, const char *key
return ret;
}
-/* cache write lock of the multi mount owner must be held by caller */
-int cache_delete_offset(struct mapent_cache *mc, const char *key)
-{
- u_int32_t hashval = hash(key, mc->size);
- struct mapent *me = NULL, *pred;
- int status;
-
- me = mc->hash[hashval];
- if (!me)
- return CHE_FAIL;
-
- if (strcmp(key, me->key) == 0) {
- if (IS_MM(me) && IS_MM_ROOT(me))
- return CHE_FAIL;
- mc->hash[hashval] = me->next;
- goto delete;
- }
-
- while (me->next != NULL) {
- pred = me;
- me = me->next;
- if (strcmp(key, me->key) == 0) {
- if (IS_MM(me) && IS_MM_ROOT(me))
- return CHE_FAIL;
- pred->next = me->next;
- goto delete;
- }
- }
-
- return CHE_FAIL;
-
-delete:
- list_del(&me->multi_list);
- ino_index_lock(mc);
- list_del(&me->ino_index);
- ino_index_unlock(mc);
- free(me->key);
- if (me->mapent)
- free(me->mapent);
- free(me);
-
- return CHE_OK;
-}
-
/* cache must be write locked by caller */
int cache_delete(struct mapent_cache *mc, const char *key)
{
@@ -1054,113 +937,3 @@ struct mapent *cache_enumerate(struct mapent_cache *mc, struct mapent *me)
return cache_lookup_next(mc, me);
}
-
-/*
- * Get each offset from list head under prefix.
- * Maintain traversal current position in pos for subsequent calls.
- * Return each offset into offset.
- */
-/* cache must be read locked by caller */
-char *cache_get_offset(const char *prefix, char *offset, int start,
- struct list_head *head, struct list_head **pos)
-{
- struct list_head *next;
- struct mapent *this;
- size_t plen = strlen(prefix);
- size_t len = 0;
-
- if (*pos == head)
- return NULL;
-
- /* Find an offset */
- *offset = '\0';
- next = *pos ? (*pos)->next : head->next;
- while (next != head) {
- char *offset_start, *pstart, *pend;
-
- this = list_entry(next, struct mapent, multi_list);
- *pos = next;
- next = next->next;
-
- offset_start = &this->key[start];
- if (strlen(offset_start) <= plen)
- continue;
-
- if (!strncmp(prefix, offset_start, plen)) {
- struct mapent *np = NULL;
- char pe[PATH_MAX + 1];
-
- /* "/" doesn't count for root offset */
- if (plen == 1)
- pstart = &offset_start[plen - 1];
- else
- pstart = &offset_start[plen];
-
- /* not part of this sub-tree */
- if (*pstart != '/')
- continue;
-
- /* get next offset */
- pend = pstart;
- while (*pend++) {
- size_t nest_pt_offset;
-
- if (*pend != '/')
- continue;
-
- nest_pt_offset = start + pend - pstart;
- if (plen > 1)
- nest_pt_offset += plen;
- strcpy(pe, this->key);
- pe[nest_pt_offset] = '\0';
-
- np = cache_lookup_distinct(this->mc, pe);
- if (np)
- break;
- }
- if (np)
- continue;
- len = pend - pstart - 1;
- strncpy(offset, pstart, len);
- offset[len] ='\0';
- break;
- }
- }
-
- /* Seek to next offset */
- while (next != head) {
- char *offset_start, *pstart;
-
- this = list_entry(next, struct mapent, multi_list);
-
- offset_start = &this->key[start];
- if (strlen(offset_start) <= plen + len)
- break;
-
- /* "/" doesn't count for root offset */
- if (plen == 1)
- pstart = &offset_start[plen - 1];
- else
- pstart = &offset_start[plen];
-
- /* not part of this sub-tree */
- if (*pstart != '/')
- break;
-
- /* new offset */
- if (!*(pstart + len + 1))
- break;
-
- /* compare offset */
- if (pstart[len] != '/' ||
- strlen(pstart) != len ||
- strncmp(offset, pstart, len))
- break;
-
- *pos = next;
- next = next->next;
- }
-
- return *offset ? offset : NULL;
-}
-
diff --git a/lib/mounts.c b/lib/mounts.c
index 6ca7eff1..c120d2a8 100644
--- a/lib/mounts.c
+++ b/lib/mounts.c
@@ -2853,21 +2853,6 @@ static void set_offset_tree_catatonic(struct autofs_point *ap, struct mapent *me
tree_traverse_inorder(MAPENT_ROOT(me), set_offset_tree_catatonic_work, NULL);
}
-static void set_multi_mount_tree_catatonic(struct autofs_point *ap, struct mapent *me)
-{
- if (!list_empty(&me->multi_list)) {
- struct list_head *head = &me->multi_list;
- struct list_head *p;
-
- list_for_each(p, head) {
- struct mapent *this;
-
- this = list_entry(p, struct mapent, multi_list);
- set_mount_catatonic(ap, this, this->ioctlfd);
- }
- }
-}
-
void set_indirect_mount_tree_catatonic(struct autofs_point *ap)
{
struct master_mapent *entry = ap->entry;
@@ -3034,299 +3019,3 @@ done:
out:
return rv;
}
-
-static int do_mount_autofs_offset(struct autofs_point *ap, struct mapent *oe)
-{
- int mounted = 0;
- int ret;
-
- debug(ap->logopt, "mount offset %s", oe->key);
-
- ret = mount_autofs_offset(ap, oe);
- if (ret >= MOUNT_OFFSET_OK)
- mounted++;
- else {
- if (ret != MOUNT_OFFSET_IGNORE)
- warn(ap->logopt, "failed to mount offset");
- else {
- debug(ap->logopt, "ignoring \"nohide\" trigger %s",
- oe->key);
- /*
- * Ok, so we shouldn't modify the mapent but
- * mount requests are blocked at a point above
- * this and expire only uses the mapent key or
- * holds the cache write lock.
- */
- free(oe->mapent);
- oe->mapent = NULL;
- }
- }
-
- return mounted;
-}
-
-static int rmdir_path_offset(struct autofs_point *ap, struct mapent *oe)
-{
- char *dir, *path;
- unsigned int split;
- int ret;
-
- if (ap->type == LKP_DIRECT)
- return rmdir_path(ap, oe->key, MM_ROOT(oe)->dev);
-
- dir = strdup(oe->key);
-
- if (ap->flags & MOUNT_FLAG_GHOST)
- split = ap->len + strlen(MM_ROOT(oe)->key) + 1;
- else
- split = ap->len;
-
- dir[split] = '\0';
- path = &dir[split + 1];
-
- if (chdir(dir) == -1) {
- error(ap->logopt, "failed to chdir to %s", dir);
- free(dir);
- return -1;
- }
-
- ret = rmdir_path(ap, path, ap->dev);
-
- free(dir);
-
- if (chdir("/") == -1)
- error(ap->logopt, "failed to chdir to /");
-
- return ret;
-}
-
-static int do_umount_offset(struct autofs_point *ap,
- struct mapent *oe, const char *root, int start);
-
-static int do_umount_multi_triggers(struct autofs_point *ap,
- struct mapent *me, const char *root,
- int start, const char *base)
-{
- char path[PATH_MAX + 1];
- char *offset;
- struct mapent *oe;
- struct list_head *mm_root, *pos;
- const char o_root[] = "/";
- const char *mm_base;
- int left;
- unsigned int root_len;
- unsigned int mm_base_len;
-
- left = 0;
-
- mm_root = &me->multi->multi_list;
-
- if (!base)
- mm_base = o_root;
- else
- mm_base = base;
-
- pos = NULL;
- offset = path;
- root_len = start;
- mm_base_len = strlen(mm_base);
-
- while ((offset = cache_get_offset(mm_base, offset, start, mm_root, &pos))) {
- char key[PATH_MAX + 1];
- int key_len = root_len + strlen(offset);
-
- if (mm_base_len > 1)
- key_len += mm_base_len;
-
- if (key_len > PATH_MAX) {
- warn(ap->logopt, "path loo long");
- continue;
- }
-
- strcpy(key, root);
- if (mm_base_len > 1)
- strcat(key, mm_base);
- strcat(key, offset);
-
- oe = cache_lookup_distinct(me->mc, key);
- /* root offset is a special case */
- if (!oe || (strlen(oe->key) - start) == 1)
- continue;
-
- left += do_umount_offset(ap, oe, root, start);
- }
-
- return left;
-}
-
-static int do_umount_offset(struct autofs_point *ap,
- struct mapent *oe, const char *root, int start)
-{
- char *oe_base;
- int left = 0;
-
- /*
- * Check for and umount subtree offsets resulting from
- * nonstrict mount fail.
- */
- oe_base = oe->key + start;
- left += do_umount_multi_triggers(ap, oe, root, start, oe_base);
-
- /*
- * If an offset that has an active mount has been removed
- * from the multi-mount we don't want to attempt to trigger
- * mounts for it. Obviously this is because it has been
- * removed, but less obvious is the potential strange
- * behaviour that can result if we do try and mount it
- * again after it's been expired. For example, if an NFS
- * file system is no longer exported and is later umounted
- * it can be mounted again without any error message but
- * shows as an empty directory. That's going to confuse
- * people for sure.
- *
- * If the mount cannot be umounted (the process is now
- * using a stale mount) the offset needs to be invalidated
- * so no further mounts will be attempted but the offset
- * cache entry must remain so expires can continue to
- * attempt to umount it. If the mount can be umounted and
- * the offset is removed, at least for NFS we will get
- * ESTALE errors when attempting list the directory.
- */
- if (oe->ioctlfd != -1 ||
- is_mounted(oe->key, MNTS_REAL)) {
- if (umount_ent(ap, oe->key) &&
- is_mounted(oe->key, MNTS_REAL)) {
- debug(ap->logopt,
- "offset %s has active mount, invalidate",
- oe->key);
- /*
- * Ok, so we shouldn't modify the mapent but
- * mount requests are blocked at a point above
- * this and expire only uses the mapent key or
- * holds the cache write lock.
- */
- if (oe->mapent) {
- free(oe->mapent);
- oe->mapent = NULL;
- }
- return ++left;
- }
- }
-
- debug(ap->logopt, "umount offset %s", oe->key);
-
- if (umount_autofs_offset(ap, oe)) {
- warn(ap->logopt, "failed to umount offset");
- left++;
- } else {
- struct stat st;
- int ret;
-
- if (!(oe->flags & MOUNT_FLAG_DIR_CREATED))
- return left;
-
- /*
- * An error due to partial directory removal is
- * ok so only try and remount the offset if the
- * actual mount point still exists.
- */
- ret = rmdir_path_offset(ap, oe);
- if (ret == -1 && !stat(oe->key, &st)) {
- ret = do_mount_autofs_offset(ap, oe);
- if (ret)
- left++;
- /* But we did origianlly create this */
- oe->flags |= MOUNT_FLAG_DIR_CREATED;
- }
- }
- return left;
-}
-
-int mount_multi_triggers(struct autofs_point *ap, struct mapent *me,
- const char *root, unsigned int start, const char *base)
-{
- char path[PATH_MAX + 1];
- char *offset = path;
- struct mapent *oe;
- struct list_head *pos = NULL;
- unsigned int root_len = strlen(root);
- int mounted;
-
- mounted = 0;
- offset = cache_get_offset(base, offset, start, &me->multi_list, &pos);
- while (offset) {
- char key[PATH_MAX + 1];
- int key_len = root_len + strlen(offset);
-
- if (key_len > PATH_MAX) {
- warn(ap->logopt, "path loo long");
- goto cont;
- }
-
- /* The root offset is always mounted seperately so the
- * offset path will always be root + offset.
- */
- strcpy(key, root);
- strcat(key, offset);
-
- oe = cache_lookup_distinct(me->mc, key);
- if (!oe || !oe->mapent)
- goto cont;
- if (oe->age != MM_ROOT(me)->age) {
- /* Best effort */
- do_umount_offset(ap, oe, root, start);
- goto cont;
- }
-
- mounted += do_mount_autofs_offset(ap, oe);
-
- /*
- * If re-constructing a multi-mount it's necessary to walk
- * into nested mounts, unlike the usual "mount only what's
- * needed as you go" behavior.
- */
- if (ap->state == ST_READMAP && ap->flags & MOUNT_FLAG_REMOUNT) {
- if (oe->ioctlfd != -1 ||
- is_mounted(oe->key, MNTS_REAL))
- mount_multi_triggers(ap, oe, key, key_len, base);
- }
-cont:
- offset = cache_get_offset(base,
- offset, start, &me->multi_list, &pos);
- }
-
- return mounted;
-}
-
-int umount_multi_triggers(struct autofs_point *ap, struct mapent *me, char *root, const char *base)
-{
- int left, start;
-
- start = strlen(root);
-
- left = do_umount_multi_triggers(ap, me, root, start, base);
-
- if (!left && IS_MM_ROOT(me)) {
- /*
- * Special case.
- * If we can't umount the root container then we can't
- * delete the offsets from the cache and we need to put
- * the offset triggers back.
- */
- if (is_mounted(root, MNTS_REAL)) {
- info(ap->logopt, "unmounting dir = %s", root);
- if (umount_ent(ap, root) &&
- is_mounted(root, MNTS_REAL)) {
- if (mount_multi_triggers(ap, me, root, start, "/") < 0)
- warn(ap->logopt,
- "failed to remount offset triggers");
- return ++left;
- }
- }
-
- /* check for mounted mount entry and remove it if found */
- mnts_remove_mount(root, MNTS_MOUNTED);
- }
-
- return left;
-}
diff --git a/modules/parse_sun.c b/modules/parse_sun.c
index d6ef48b8..ef74eda9 100644
--- a/modules/parse_sun.c
+++ b/modules/parse_sun.c
@@ -1074,62 +1074,6 @@ next:
return (p - ent);
}
-static void cleanup_multi_triggers(struct autofs_point *ap,
- struct mapent *me, const char *root, int start,
- const char *base)
-{
- char path[PATH_MAX + 1];
- char offset[PATH_MAX + 1];
- char *poffset = offset;
- struct mapent *oe;
- struct list_head *mm_root, *pos;
- const char o_root[] = "/";
- const char *mm_base;
- unsigned int root_len;
- unsigned int mm_base_len;
-
- mm_root = &me->multi->multi_list;
-
- if (!base)
- mm_base = o_root;
- else
- mm_base = base;
-
- pos = NULL;
- root_len = strlen(root);
- mm_base_len = strlen(mm_base);
-
- /* Make sure "none" of the offsets have an active mount. */
- while ((poffset = cache_get_offset(mm_base, poffset, start, mm_root, &pos))) {
- unsigned int path_len = root_len + strlen(poffset);
-
- if (mm_base_len > 1)
- path_len += mm_base_len;
-
- if (path_len > PATH_MAX) {
- warn(ap->logopt, "path loo long");
- continue;
- }
-
- strcpy(path, root);
- if (mm_base_len > 1)
- strcat(path, mm_base);
- strcat(path, poffset);
-
- oe = cache_lookup_distinct(me->mc, path);
- /* root offset is a special case */
- if (!oe || !oe->mapent || (strlen(oe->key) - start) == 1)
- continue;
-
- if (umount(path)) {
- error(ap->logopt, "error recovering from mount fail");
- error(ap->logopt, "cannot umount offset %s", path);
- }
- }
-
- return;
-}
-
static int mount_subtree(struct autofs_point *ap, struct mapent_cache *mc,
const char *name, char *loc, char *options, void *ctxt)
{