|
|
9a499a |
autofs-5.1.7 - eliminate clean_stale_multi_triggers()
|
|
|
9a499a |
|
|
|
9a499a |
From: Ian Kent <raven@themaw.net>
|
|
|
9a499a |
|
|
|
9a499a |
Eliminate clean_stale_multi_triggers() by checking for stale offsets at
|
|
|
9a499a |
the time mount_subtree() is called.
|
|
|
9a499a |
|
|
|
9a499a |
This should result in the same behaviour but eliminate an additional
|
|
|
9a499a |
seperate traversal of the offset list.
|
|
|
9a499a |
|
|
|
9a499a |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
9a499a |
---
|
|
|
9a499a |
CHANGELOG | 1
|
|
|
9a499a |
lib/mounts.c | 209 ++++++++++------------------------------------------
|
|
|
9a499a |
modules/parse_sun.c | 10 --
|
|
|
9a499a |
3 files changed, 43 insertions(+), 177 deletions(-)
|
|
|
9a499a |
|
|
|
9a499a |
--- autofs-5.1.4.orig/CHANGELOG
|
|
|
9a499a |
+++ autofs-5.1.4/CHANGELOG
|
|
|
9a499a |
@@ -11,6 +11,7 @@
|
|
|
9a499a |
- remove redundant variables from mount_autofs_offset().
|
|
|
9a499a |
- remove unused parameter form do_mount_autofs_offset().
|
|
|
9a499a |
- refactor umount_multi_triggers().
|
|
|
9a499a |
+- eliminate clean_stale_multi_triggers().
|
|
|
9a499a |
|
|
|
9a499a |
xx/xx/2018 autofs-5.1.5
|
|
|
9a499a |
- fix flag file permission.
|
|
|
9a499a |
--- autofs-5.1.4.orig/lib/mounts.c
|
|
|
9a499a |
+++ autofs-5.1.4/lib/mounts.c
|
|
|
9a499a |
@@ -2595,10 +2595,44 @@ static int do_umount_offset(struct autof
|
|
|
9a499a |
oe_base = oe->key + strlen(root);
|
|
|
9a499a |
left += do_umount_multi_triggers(ap, oe, root, oe_base);
|
|
|
9a499a |
|
|
|
9a499a |
+ /*
|
|
|
9a499a |
+ * If an offset that has an active mount has been removed
|
|
|
9a499a |
+ * from the multi-mount we don't want to attempt to trigger
|
|
|
9a499a |
+ * mounts for it. Obviously this is because it has been
|
|
|
9a499a |
+ * removed, but less obvious is the potential strange
|
|
|
9a499a |
+ * behaviour that can result if we do try and mount it
|
|
|
9a499a |
+ * again after it's been expired. For example, if an NFS
|
|
|
9a499a |
+ * file system is no longer exported and is later umounted
|
|
|
9a499a |
+ * it can be mounted again without any error message but
|
|
|
9a499a |
+ * shows as an empty directory. That's going to confuse
|
|
|
9a499a |
+ * people for sure.
|
|
|
9a499a |
+ *
|
|
|
9a499a |
+ * If the mount cannot be umounted (the process is now
|
|
|
9a499a |
+ * using a stale mount) the offset needs to be invalidated
|
|
|
9a499a |
+ * so no further mounts will be attempted but the offset
|
|
|
9a499a |
+ * cache entry must remain so expires can continue to
|
|
|
9a499a |
+ * attempt to umount it. If the mount can be umounted and
|
|
|
9a499a |
+ * the offset is removed, at least for NFS we will get
|
|
|
9a499a |
+ * ESTALE errors when attempting list the directory.
|
|
|
9a499a |
+ */
|
|
|
9a499a |
if (oe->ioctlfd != -1 ||
|
|
|
9a499a |
is_mounted(oe->key, MNTS_REAL)) {
|
|
|
9a499a |
- left++;
|
|
|
9a499a |
- return left;
|
|
|
9a499a |
+ if (umount_ent(ap, oe->key) &&
|
|
|
9a499a |
+ is_mounted(oe->key, MNTS_REAL)) {
|
|
|
9a499a |
+ debug(ap->logopt,
|
|
|
9a499a |
+ "offset %s has active mount, invalidate",
|
|
|
9a499a |
+ oe->key);
|
|
|
9a499a |
+ /*
|
|
|
9a499a |
+ * Ok, so we shouldn't modify the mapent but
|
|
|
9a499a |
+ * mount requests are blocked at a point above
|
|
|
9a499a |
+ * this and expire only uses the mapent key.
|
|
|
9a499a |
+ */
|
|
|
9a499a |
+ if (oe->mapent) {
|
|
|
9a499a |
+ free(oe->mapent);
|
|
|
9a499a |
+ oe->mapent = NULL;
|
|
|
9a499a |
+ }
|
|
|
9a499a |
+ return ++left;
|
|
|
9a499a |
+ }
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
debug(ap->logopt, "umount offset %s", oe->key);
|
|
|
9a499a |
@@ -2660,6 +2694,11 @@ int mount_multi_triggers(struct autofs_p
|
|
|
9a499a |
oe = cache_lookup_distinct(me->mc, key);
|
|
|
9a499a |
if (!oe || !oe->mapent)
|
|
|
9a499a |
goto cont;
|
|
|
9a499a |
+ if (oe->age != me->multi->age) {
|
|
|
9a499a |
+ /* Best effort */
|
|
|
9a499a |
+ do_umount_offset(ap, oe, root);
|
|
|
9a499a |
+ goto cont;
|
|
|
9a499a |
+ }
|
|
|
9a499a |
|
|
|
9a499a |
mounted += do_mount_autofs_offset(ap, oe, root);
|
|
|
9a499a |
|
|
|
9a499a |
@@ -2718,170 +2757,4 @@ int umount_multi_triggers(struct autofs_
|
|
|
9a499a |
}
|
|
|
9a499a |
|
|
|
9a499a |
return left;
|
|
|
9a499a |
-}
|
|
|
9a499a |
-
|
|
|
9a499a |
-int clean_stale_multi_triggers(struct autofs_point *ap,
|
|
|
9a499a |
- struct mapent *me, char *top, const char *base)
|
|
|
9a499a |
-{
|
|
|
9a499a |
- char *root;
|
|
|
9a499a |
- char mm_top[PATH_MAX + 1];
|
|
|
9a499a |
- char path[PATH_MAX + 1];
|
|
|
9a499a |
- char *offset;
|
|
|
9a499a |
- struct mapent *oe;
|
|
|
9a499a |
- struct list_head *mm_root, *pos;
|
|
|
9a499a |
- const char o_root[] = "/";
|
|
|
9a499a |
- const char *mm_base;
|
|
|
9a499a |
- int left, start;
|
|
|
9a499a |
- unsigned int root_len;
|
|
|
9a499a |
- unsigned int mm_base_len;
|
|
|
9a499a |
- time_t age;
|
|
|
9a499a |
-
|
|
|
9a499a |
- if (top)
|
|
|
9a499a |
- root = top;
|
|
|
9a499a |
- else {
|
|
|
9a499a |
- if (!strchr(me->multi->key, '/'))
|
|
|
9a499a |
- /* Indirect multi-mount root */
|
|
|
9a499a |
- /* sprintf okay - if it's mounted, it's
|
|
|
9a499a |
- * PATH_MAX or less bytes */
|
|
|
9a499a |
- sprintf(mm_top, "%s/%s", ap->path, me->multi->key);
|
|
|
9a499a |
- else
|
|
|
9a499a |
- strcpy(mm_top, me->multi->key);
|
|
|
9a499a |
- root = mm_top;
|
|
|
9a499a |
- }
|
|
|
9a499a |
-
|
|
|
9a499a |
- left = 0;
|
|
|
9a499a |
- start = strlen(root);
|
|
|
9a499a |
-
|
|
|
9a499a |
- mm_root = &me->multi->multi_list;
|
|
|
9a499a |
-
|
|
|
9a499a |
- if (!base)
|
|
|
9a499a |
- mm_base = o_root;
|
|
|
9a499a |
- else
|
|
|
9a499a |
- mm_base = base;
|
|
|
9a499a |
-
|
|
|
9a499a |
- pos = NULL;
|
|
|
9a499a |
- offset = path;
|
|
|
9a499a |
- root_len = start;
|
|
|
9a499a |
- mm_base_len = strlen(mm_base);
|
|
|
9a499a |
- age = me->multi->age;
|
|
|
9a499a |
-
|
|
|
9a499a |
- while ((offset = cache_get_offset(mm_base, offset, start, mm_root, &pos))) {
|
|
|
9a499a |
- char key[PATH_MAX + 1];
|
|
|
9a499a |
- int key_len = root_len + strlen(offset);
|
|
|
9a499a |
- char *oe_base;
|
|
|
9a499a |
- int ret;
|
|
|
9a499a |
-
|
|
|
9a499a |
- if (mm_base_len > 1)
|
|
|
9a499a |
- key_len += mm_base_len;
|
|
|
9a499a |
-
|
|
|
9a499a |
- if (key_len > PATH_MAX) {
|
|
|
9a499a |
- warn(ap->logopt, "path loo long");
|
|
|
9a499a |
- continue;
|
|
|
9a499a |
- }
|
|
|
9a499a |
-
|
|
|
9a499a |
- strcpy(key, root);
|
|
|
9a499a |
- if (mm_base_len > 1)
|
|
|
9a499a |
- strcat(key, mm_base);
|
|
|
9a499a |
- strcat(key, offset);
|
|
|
9a499a |
-
|
|
|
9a499a |
- oe = cache_lookup_distinct(me->mc, key);
|
|
|
9a499a |
- /* root offset is a special case */
|
|
|
9a499a |
- if (!oe || (strlen(oe->key) - start) == 1)
|
|
|
9a499a |
- continue;
|
|
|
9a499a |
-
|
|
|
9a499a |
- /* Check for and umount stale subtree offsets */
|
|
|
9a499a |
- oe_base = oe->key + strlen(root);
|
|
|
9a499a |
- ret = clean_stale_multi_triggers(ap, oe, root, oe_base);
|
|
|
9a499a |
- left += ret;
|
|
|
9a499a |
- if (ret)
|
|
|
9a499a |
- continue;
|
|
|
9a499a |
-
|
|
|
9a499a |
- if (oe->age == age)
|
|
|
9a499a |
- continue;
|
|
|
9a499a |
-
|
|
|
9a499a |
- /*
|
|
|
9a499a |
- * If an offset that has an active mount has been removed
|
|
|
9a499a |
- * from the multi-mount we don't want to attempt to trigger
|
|
|
9a499a |
- * mounts for it. Obviously this is because it has been
|
|
|
9a499a |
- * removed, but less obvious is the potential strange
|
|
|
9a499a |
- * behaviour that can result if we do try and mount it
|
|
|
9a499a |
- * again after it's been expired. For example, if an NFS
|
|
|
9a499a |
- * file system is no longer exported and is later umounted
|
|
|
9a499a |
- * it can be mounted again without any error message but
|
|
|
9a499a |
- * shows as an empty directory. That's going to confuse
|
|
|
9a499a |
- * people for sure.
|
|
|
9a499a |
- *
|
|
|
9a499a |
- * If the mount cannot be umounted (the process is now
|
|
|
9a499a |
- * using a stale mount) the offset needs to be invalidated
|
|
|
9a499a |
- * so no further mounts will be attempted but the offset
|
|
|
9a499a |
- * cache entry must remain so expires can continue to
|
|
|
9a499a |
- * attempt to umount it. If the mount can be umounted and
|
|
|
9a499a |
- * the offset is removed, at least for NFS we will get
|
|
|
9a499a |
- * ESTALE errors when attempting list the directory.
|
|
|
9a499a |
- */
|
|
|
9a499a |
- if (oe->ioctlfd != -1 ||
|
|
|
9a499a |
- is_mounted(oe->key, MNTS_REAL)) {
|
|
|
9a499a |
- if (umount_ent(ap, oe->key) &&
|
|
|
9a499a |
- is_mounted(oe->key, MNTS_REAL)) {
|
|
|
9a499a |
- debug(ap->logopt,
|
|
|
9a499a |
- "offset %s has active mount, invalidate",
|
|
|
9a499a |
- oe->key);
|
|
|
9a499a |
- if (oe->mapent) {
|
|
|
9a499a |
- free(oe->mapent);
|
|
|
9a499a |
- oe->mapent = NULL;
|
|
|
9a499a |
- }
|
|
|
9a499a |
- left++;
|
|
|
9a499a |
- continue;
|
|
|
9a499a |
- }
|
|
|
9a499a |
- }
|
|
|
9a499a |
-
|
|
|
9a499a |
- debug(ap->logopt, "umount offset %s", oe->key);
|
|
|
9a499a |
-
|
|
|
9a499a |
- if (umount_autofs_offset(ap, oe)) {
|
|
|
9a499a |
- warn(ap->logopt, "failed to umount offset %s", key);
|
|
|
9a499a |
- left++;
|
|
|
9a499a |
- } else {
|
|
|
9a499a |
- struct stat st;
|
|
|
9a499a |
-
|
|
|
9a499a |
- /* Mount point not ours to delete ? */
|
|
|
9a499a |
- if (!(oe->flags & MOUNT_FLAG_DIR_CREATED)) {
|
|
|
9a499a |
- debug(ap->logopt, "delete offset key %s", key);
|
|
|
9a499a |
- if (cache_delete_offset(oe->mc, key) == CHE_FAIL)
|
|
|
9a499a |
- error(ap->logopt,
|
|
|
9a499a |
- "failed to delete offset key %s", key);
|
|
|
9a499a |
- continue;
|
|
|
9a499a |
- }
|
|
|
9a499a |
-
|
|
|
9a499a |
- /*
|
|
|
9a499a |
- * An error due to partial directory removal is
|
|
|
9a499a |
- * ok so only try and remount the offset if the
|
|
|
9a499a |
- * actual mount point still exists.
|
|
|
9a499a |
- */
|
|
|
9a499a |
- ret = rmdir_path_offset(ap, oe);
|
|
|
9a499a |
- if (ret == -1 && !stat(oe->key, &st)) {
|
|
|
9a499a |
- ret = do_mount_autofs_offset(ap, oe, root);
|
|
|
9a499a |
- if (ret) {
|
|
|
9a499a |
- left++;
|
|
|
9a499a |
- /* But we did origianlly create this */
|
|
|
9a499a |
- oe->flags |= MOUNT_FLAG_DIR_CREATED;
|
|
|
9a499a |
- continue;
|
|
|
9a499a |
- }
|
|
|
9a499a |
- /*
|
|
|
9a499a |
- * Fall through if the trigger can't be mounted
|
|
|
9a499a |
- * again, since there is no offset there can't
|
|
|
9a499a |
- * be any mount requests so remove the map
|
|
|
9a499a |
- * entry from the cache. There's now a dead
|
|
|
9a499a |
- * offset mount, but what else can we do ....
|
|
|
9a499a |
- */
|
|
|
9a499a |
- }
|
|
|
9a499a |
-
|
|
|
9a499a |
- debug(ap->logopt, "delete offset key %s", key);
|
|
|
9a499a |
-
|
|
|
9a499a |
- if (cache_delete_offset(oe->mc, key) == CHE_FAIL)
|
|
|
9a499a |
- error(ap->logopt,
|
|
|
9a499a |
- "failed to delete offset key %s", key);
|
|
|
9a499a |
- }
|
|
|
9a499a |
- }
|
|
|
9a499a |
-
|
|
|
9a499a |
- return left;
|
|
|
9a499a |
}
|
|
|
9a499a |
--- autofs-5.1.4.orig/modules/parse_sun.c
|
|
|
9a499a |
+++ autofs-5.1.4/modules/parse_sun.c
|
|
|
9a499a |
@@ -1178,7 +1178,7 @@ static int mount_subtree(struct autofs_p
|
|
|
9a499a |
|
|
|
9a499a |
/* Mount root offset if it exists */
|
|
|
9a499a |
ro = cache_lookup_distinct(me->mc, key);
|
|
|
9a499a |
- if (ro) {
|
|
|
9a499a |
+ if (ro && ro->age == me->multi->age) {
|
|
|
9a499a |
char *myoptions, *ro_loc;
|
|
|
9a499a |
int namelen = name ? strlen(name) : 0;
|
|
|
9a499a |
int ro_len;
|
|
|
9a499a |
@@ -1612,14 +1612,6 @@ dont_expand:
|
|
|
9a499a |
free(myoptions);
|
|
|
9a499a |
} while (*p == '/' || (*p == '"' && *(p + 1) == '/'));
|
|
|
9a499a |
|
|
|
9a499a |
- /*
|
|
|
9a499a |
- * We've got the ordered list of multi-mount entries so go
|
|
|
9a499a |
- * through and remove any stale entries if this is the top
|
|
|
9a499a |
- * of the multi-mount and set the parent entry of each.
|
|
|
9a499a |
- */
|
|
|
9a499a |
- if (me == me->multi)
|
|
|
9a499a |
- clean_stale_multi_triggers(ap, me, NULL, NULL);
|
|
|
9a499a |
-
|
|
|
9a499a |
rv = mount_subtree(ap, me, name, NULL, options, ctxt);
|
|
|
9a499a |
|
|
|
9a499a |
cache_multi_unlock(me);
|