|
|
49b67f |
autofs-5.1.7 - add mount and umount offsets functions
|
|
|
49b67f |
|
|
|
49b67f |
From: Ian Kent <raven@themaw.net>
|
|
|
49b67f |
|
|
|
49b67f |
Add tree_mapent_mount_offsets() and tree_mapent_umount_offsets() to
|
|
|
49b67f |
the mapent tree handling implementation.
|
|
|
49b67f |
|
|
|
49b67f |
Signed-off-by: Ian Kent <raven@themaw.net>
|
|
|
49b67f |
---
|
|
|
49b67f |
CHANGELOG | 1
|
|
|
49b67f |
include/mounts.h | 2
|
|
|
49b67f |
lib/mounts.c | 260 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
49b67f |
3 files changed, 263 insertions(+)
|
|
|
49b67f |
|
|
|
49b67f |
--- autofs-5.1.4.orig/CHANGELOG
|
|
|
49b67f |
+++ autofs-5.1.4/CHANGELOG
|
|
|
49b67f |
@@ -39,6 +39,7 @@
|
|
|
49b67f |
- fix mount_fullpath().
|
|
|
49b67f |
- add tree_mapent_cleanup_offsets().
|
|
|
49b67f |
- add set_offset_tree_catatonic().
|
|
|
49b67f |
+- add mount and umount offsets functions.
|
|
|
49b67f |
|
|
|
49b67f |
xx/xx/2018 autofs-5.1.5
|
|
|
49b67f |
- fix flag file permission.
|
|
|
49b67f |
--- autofs-5.1.4.orig/include/mounts.h
|
|
|
49b67f |
+++ autofs-5.1.4/include/mounts.h
|
|
|
49b67f |
@@ -172,6 +172,8 @@ struct tree_node *tree_mapent_root(struc
|
|
|
49b67f |
int tree_mapent_add_node(struct mapent_cache *mc, const char *base, const char *key);
|
|
|
49b67f |
int tree_mapent_delete_offsets(struct mapent_cache *mc, const char *key);
|
|
|
49b67f |
void tree_mapent_cleanup_offsets(struct mapent *oe);
|
|
|
49b67f |
+int tree_mapent_mount_offsets(struct mapent *oe, int nonstrict);
|
|
|
49b67f |
+int tree_mapent_umount_offsets(struct mapent *oe, int nonstrict);
|
|
|
49b67f |
int unlink_mount_tree(struct autofs_point *ap, const char *mp);
|
|
|
49b67f |
void free_mnt_list(struct mnt_list *list);
|
|
|
49b67f |
int is_mounted(const char *mp, unsigned int type);
|
|
|
49b67f |
--- autofs-5.1.4.orig/lib/mounts.c
|
|
|
49b67f |
+++ autofs-5.1.4/lib/mounts.c
|
|
|
49b67f |
@@ -1692,6 +1692,266 @@ void tree_mapent_cleanup_offsets(struct
|
|
|
49b67f |
}
|
|
|
49b67f |
}
|
|
|
49b67f |
|
|
|
49b67f |
+static int tree_mapent_rmdir_path_offset(struct autofs_point *ap, struct mapent *oe)
|
|
|
49b67f |
+{
|
|
|
49b67f |
+ struct mapent *mm_root = MAPENT(MAPENT_ROOT(oe));
|
|
|
49b67f |
+ char *dir, *path;
|
|
|
49b67f |
+ unsigned int split;
|
|
|
49b67f |
+ int ret;
|
|
|
49b67f |
+
|
|
|
49b67f |
+ if (ap->type == LKP_DIRECT)
|
|
|
49b67f |
+ return rmdir_path(ap, oe->key, mm_root->dev);
|
|
|
49b67f |
+
|
|
|
49b67f |
+ dir = strdup(oe->key);
|
|
|
49b67f |
+
|
|
|
49b67f |
+ if (ap->flags & MOUNT_FLAG_GHOST)
|
|
|
49b67f |
+ split = ap->len + mm_root->len + 1;
|
|
|
49b67f |
+ else
|
|
|
49b67f |
+ split = ap->len;
|
|
|
49b67f |
+
|
|
|
49b67f |
+ dir[split] = '\0';
|
|
|
49b67f |
+ path = &dir[split + 1];
|
|
|
49b67f |
+
|
|
|
49b67f |
+ if (chdir(dir) == -1) {
|
|
|
49b67f |
+ error(ap->logopt, "failed to chdir to %s", dir);
|
|
|
49b67f |
+ free(dir);
|
|
|
49b67f |
+ return -1;
|
|
|
49b67f |
+ }
|
|
|
49b67f |
+
|
|
|
49b67f |
+ ret = rmdir_path(ap, path, ap->dev);
|
|
|
49b67f |
+
|
|
|
49b67f |
+ free(dir);
|
|
|
49b67f |
+
|
|
|
49b67f |
+ if (chdir("/") == -1)
|
|
|
49b67f |
+ error(ap->logopt, "failed to chdir to /");
|
|
|
49b67f |
+
|
|
|
49b67f |
+ return ret;
|
|
|
49b67f |
+}
|
|
|
49b67f |
+
|
|
|
49b67f |
+static int tree_mapent_mount_offset(struct mapent *oe, void *ptr)
|
|
|
49b67f |
+{
|
|
|
49b67f |
+ struct traverse_subtree_context *ctxt = ptr;
|
|
|
49b67f |
+ struct autofs_point *ap = ctxt->ap;
|
|
|
49b67f |
+ int ret;
|
|
|
49b67f |
+
|
|
|
49b67f |
+ debug(ap->logopt, "mount offset %s", oe->key);
|
|
|
49b67f |
+
|
|
|
49b67f |
+ ret = mount_autofs_offset(ap, oe);
|
|
|
49b67f |
+ if (ret < MOUNT_OFFSET_OK) {
|
|
|
49b67f |
+ if (ret != MOUNT_OFFSET_IGNORE) {
|
|
|
49b67f |
+ warn(ap->logopt, "failed to mount offset");
|
|
|
49b67f |
+ return 0;
|
|
|
49b67f |
+ } else {
|
|
|
49b67f |
+ debug(ap->logopt,
|
|
|
49b67f |
+ "ignoring \"nohide\" trigger %s", oe->key);
|
|
|
49b67f |
+ /*
|
|
|
49b67f |
+ * Ok, so we shouldn't modify the mapent but
|
|
|
49b67f |
+ * mount requests are blocked at a point above
|
|
|
49b67f |
+ * this and expire only uses the mapent key or
|
|
|
49b67f |
+ * holds the cache write lock.
|
|
|
49b67f |
+ */
|
|
|
49b67f |
+ free(oe->mapent);
|
|
|
49b67f |
+ oe->mapent = NULL;
|
|
|
49b67f |
+ }
|
|
|
49b67f |
+ }
|
|
|
49b67f |
+
|
|
|
49b67f |
+ return 1;
|
|
|
49b67f |
+}
|
|
|
49b67f |
+
|
|
|
49b67f |
+static int tree_mapent_umount_offset(struct mapent *oe, void *ptr)
|
|
|
49b67f |
+{
|
|
|
49b67f |
+ struct traverse_subtree_context *ctxt = ptr;
|
|
|
49b67f |
+ struct autofs_point *ap = ctxt->ap;
|
|
|
49b67f |
+ int ret = 1;
|
|
|
49b67f |
+
|
|
|
49b67f |
+ /*
|
|
|
49b67f |
+ * Check for and umount subtree offsets resulting from
|
|
|
49b67f |
+ * nonstrict mount fail.
|
|
|
49b67f |
+ */
|
|
|
49b67f |
+ ret = tree_mapent_umount_offsets(oe, ctxt->strict);
|
|
|
49b67f |
+ if (!ret)
|
|
|
49b67f |
+ return 0;
|
|
|
49b67f |
+
|
|
|
49b67f |
+ /*
|
|
|
49b67f |
+ * If an offset that has an active mount has been removed
|
|
|
49b67f |
+ * from the multi-mount we don't want to attempt to trigger
|
|
|
49b67f |
+ * mounts for it. Obviously this is because it has been
|
|
|
49b67f |
+ * removed, but less obvious is the potential strange
|
|
|
49b67f |
+ * behaviour that can result if we do try and mount it
|
|
|
49b67f |
+ * again after it's been expired. For example, if an NFS
|
|
|
49b67f |
+ * file system is no longer exported and is later umounted
|
|
|
49b67f |
+ * it can be mounted again without any error message but
|
|
|
49b67f |
+ * shows as an empty directory. That's going to confuse
|
|
|
49b67f |
+ * people for sure.
|
|
|
49b67f |
+ *
|
|
|
49b67f |
+ * If the mount cannot be umounted (the process is now
|
|
|
49b67f |
+ * using a stale mount) the offset needs to be invalidated
|
|
|
49b67f |
+ * so no further mounts will be attempted but the offset
|
|
|
49b67f |
+ * cache entry must remain so expires can continue to
|
|
|
49b67f |
+ * attempt to umount it. If the mount can be umounted and
|
|
|
49b67f |
+ * the offset is removed, at least for NFS we will get
|
|
|
49b67f |
+ * ESTALE errors when attempting list the directory.
|
|
|
49b67f |
+ */
|
|
|
49b67f |
+ if (oe->ioctlfd != -1 ||
|
|
|
49b67f |
+ is_mounted(oe->key, MNTS_REAL)) {
|
|
|
49b67f |
+ if (umount_ent(ap, oe->key) &&
|
|
|
49b67f |
+ is_mounted(oe->key, MNTS_REAL)) {
|
|
|
49b67f |
+ debug(ap->logopt,
|
|
|
49b67f |
+ "offset %s has active mount, invalidate",
|
|
|
49b67f |
+ oe->key);
|
|
|
49b67f |
+ /*
|
|
|
49b67f |
+ * Ok, so we shouldn't modify the mapent but
|
|
|
49b67f |
+ * mount requests are blocked at a point above
|
|
|
49b67f |
+ * this and expire only uses the mapent key or
|
|
|
49b67f |
+ * holds the cache write lock.
|
|
|
49b67f |
+ */
|
|
|
49b67f |
+ if (oe->mapent) {
|
|
|
49b67f |
+ free(oe->mapent);
|
|
|
49b67f |
+ oe->mapent = NULL;
|
|
|
49b67f |
+ }
|
|
|
49b67f |
+ return 0;
|
|
|
49b67f |
+ }
|
|
|
49b67f |
+ }
|
|
|
49b67f |
+
|
|
|
49b67f |
+ /* Don't bother if there's noting to umount. */
|
|
|
49b67f |
+ if (!is_mounted(oe->key, MNTS_AUTOFS))
|
|
|
49b67f |
+ goto done;
|
|
|
49b67f |
+
|
|
|
49b67f |
+ debug(ap->logopt, "umount offset %s", oe->key);
|
|
|
49b67f |
+
|
|
|
49b67f |
+ if (umount_autofs_offset(ap, oe)) {
|
|
|
49b67f |
+ warn(ap->logopt, "failed to umount offset");
|
|
|
49b67f |
+ ret = 0;
|
|
|
49b67f |
+ } else {
|
|
|
49b67f |
+ struct stat st;
|
|
|
49b67f |
+ int ret;
|
|
|
49b67f |
+
|
|
|
49b67f |
+ if (!(oe->flags & MOUNT_FLAG_DIR_CREATED))
|
|
|
49b67f |
+ goto done;
|
|
|
49b67f |
+
|
|
|
49b67f |
+ /*
|
|
|
49b67f |
+ * An error due to partial directory removal is
|
|
|
49b67f |
+ * ok so only try and remount the offset if the
|
|
|
49b67f |
+ * actual mount point still exists.
|
|
|
49b67f |
+ */
|
|
|
49b67f |
+ ret = tree_mapent_rmdir_path_offset(ap, oe);
|
|
|
49b67f |
+ if (ret == -1 && !stat(oe->key, &st)) {
|
|
|
49b67f |
+ ret = tree_mapent_mount_offset(oe, ctxt);
|
|
|
49b67f |
+ /* But we did origianlly create this */
|
|
|
49b67f |
+ oe->flags |= MOUNT_FLAG_DIR_CREATED;
|
|
|
49b67f |
+ }
|
|
|
49b67f |
+ }
|
|
|
49b67f |
+done:
|
|
|
49b67f |
+ return ret;
|
|
|
49b67f |
+}
|
|
|
49b67f |
+
|
|
|
49b67f |
+static int tree_mapent_mount_offsets_work(struct tree_node *n, void *ptr)
|
|
|
49b67f |
+{
|
|
|
49b67f |
+ struct traverse_subtree_context *ctxt = ptr;
|
|
|
49b67f |
+ struct mapent *oe = MAPENT(n);
|
|
|
49b67f |
+ struct mapent *mm_root = MAPENT(MAPENT_ROOT(oe));
|
|
|
49b67f |
+ struct autofs_point *ap = ctxt->ap;
|
|
|
49b67f |
+ int ret;
|
|
|
49b67f |
+
|
|
|
49b67f |
+ if (!oe->mapent)
|
|
|
49b67f |
+ return 1;
|
|
|
49b67f |
+
|
|
|
49b67f |
+ /* Stale offset, no longer present in the mapent */
|
|
|
49b67f |
+ if (oe->age != mm_root->age) {
|
|
|
49b67f |
+ /* Best effort */
|
|
|
49b67f |
+ tree_mapent_umount_offset(oe, ctxt);
|
|
|
49b67f |
+ return 1;
|
|
|
49b67f |
+ }
|
|
|
49b67f |
+
|
|
|
49b67f |
+ ret = tree_mapent_mount_offset(oe, ctxt);
|
|
|
49b67f |
+
|
|
|
49b67f |
+ /*
|
|
|
49b67f |
+ * If re-constructing a multi-mount it's necessary to walk
|
|
|
49b67f |
+ * into nested mounts, unlike the usual "mount only what's
|
|
|
49b67f |
+ * needed as you go" behavior.
|
|
|
49b67f |
+ */
|
|
|
49b67f |
+ if (ap->state == ST_READMAP && ap->flags & MOUNT_FLAG_REMOUNT) {
|
|
|
49b67f |
+ if (oe->ioctlfd != -1 ||
|
|
|
49b67f |
+ is_mounted(oe->key, MNTS_REAL))
|
|
|
49b67f |
+ /* Best effort */
|
|
|
49b67f |
+ tree_mapent_mount_offsets(oe, !ctxt->strict);
|
|
|
49b67f |
+ }
|
|
|
49b67f |
+
|
|
|
49b67f |
+ return ret;
|
|
|
49b67f |
+}
|
|
|
49b67f |
+
|
|
|
49b67f |
+int tree_mapent_mount_offsets(struct mapent *oe, int nonstrict)
|
|
|
49b67f |
+{
|
|
|
49b67f |
+ struct tree_node *base = MAPENT_NODE(oe);
|
|
|
49b67f |
+ struct traverse_subtree_context ctxt = {
|
|
|
49b67f |
+ .ap = oe->mc->ap,
|
|
|
49b67f |
+ .base = base,
|
|
|
49b67f |
+ .strict = !nonstrict,
|
|
|
49b67f |
+ };
|
|
|
49b67f |
+
|
|
|
49b67f |
+ return tree_mapent_traverse_subtree(base,
|
|
|
49b67f |
+ tree_mapent_mount_offsets_work, &ctxt);
|
|
|
49b67f |
+}
|
|
|
49b67f |
+
|
|
|
49b67f |
+static int tree_mapent_umount_offsets_work(struct tree_node *n, void *ptr)
|
|
|
49b67f |
+{
|
|
|
49b67f |
+ struct mapent *oe = MAPENT(n);
|
|
|
49b67f |
+
|
|
|
49b67f |
+ return tree_mapent_umount_offset(oe, ptr);
|
|
|
49b67f |
+}
|
|
|
49b67f |
+
|
|
|
49b67f |
+int tree_mapent_umount_offsets(struct mapent *oe, int nonstrict)
|
|
|
49b67f |
+{
|
|
|
49b67f |
+ struct tree_node *base = MAPENT_NODE(oe);
|
|
|
49b67f |
+ struct autofs_point *ap = oe->mc->ap;
|
|
|
49b67f |
+ struct traverse_subtree_context ctxt = {
|
|
|
49b67f |
+ .ap = ap,
|
|
|
49b67f |
+ .base = base,
|
|
|
49b67f |
+ .strict = !nonstrict,
|
|
|
49b67f |
+ };
|
|
|
49b67f |
+ int ret;
|
|
|
49b67f |
+
|
|
|
49b67f |
+ ret = tree_mapent_traverse_subtree(base,
|
|
|
49b67f |
+ tree_mapent_umount_offsets_work, &ctxt);
|
|
|
49b67f |
+ if (ret && tree_mapent_is_root(oe)) {
|
|
|
49b67f |
+ char mp[PATH_MAX + 1];
|
|
|
49b67f |
+
|
|
|
49b67f |
+ /*
|
|
|
49b67f |
+ * The map entry cache stores mapent keys. For indirect
|
|
|
49b67f |
+ * mount maps they are single direcory components so when
|
|
|
49b67f |
+ * one of these keys is the root of a multi-mount the mount
|
|
|
49b67f |
+ * path must be constructed.
|
|
|
49b67f |
+ */
|
|
|
49b67f |
+ if (!mount_fullpath(mp, PATH_MAX, ap->path, oe->key)) {
|
|
|
49b67f |
+ error(ap->logopt, "mount path is too long");
|
|
|
49b67f |
+ return 0;
|
|
|
49b67f |
+ }
|
|
|
49b67f |
+
|
|
|
49b67f |
+ /*
|
|
|
49b67f |
+ * Special case.
|
|
|
49b67f |
+ * If we can't umount the root container then we can't
|
|
|
49b67f |
+ * delete the offsets from the cache and we need to put
|
|
|
49b67f |
+ * the offset triggers back.
|
|
|
49b67f |
+ */
|
|
|
49b67f |
+ if (is_mounted(mp, MNTS_REAL)) {
|
|
|
49b67f |
+ info(ap->logopt, "unmounting dir = %s", mp);
|
|
|
49b67f |
+ if (umount_ent(ap, mp) &&
|
|
|
49b67f |
+ is_mounted(mp, MNTS_REAL)) {
|
|
|
49b67f |
+ if (!tree_mapent_mount_offsets(oe, 1))
|
|
|
49b67f |
+ warn(ap->logopt,
|
|
|
49b67f |
+ "failed to remount offset triggers");
|
|
|
49b67f |
+ return 0;
|
|
|
49b67f |
+ }
|
|
|
49b67f |
+ }
|
|
|
49b67f |
+
|
|
|
49b67f |
+ /* check for mounted mount entry and remove it if found */
|
|
|
49b67f |
+ mnts_remove_mount(mp, MNTS_MOUNTED);
|
|
|
49b67f |
+
|
|
|
49b67f |
+ }
|
|
|
49b67f |
+
|
|
|
49b67f |
+ return ret;
|
|
|
49b67f |
+}
|
|
|
49b67f |
+
|
|
|
49b67f |
/* From glibc decode_name() */
|
|
|
49b67f |
/* Since the values in a line are separated by spaces, a name cannot
|
|
|
49b67f |
* contain a space. Therefore some programs encode spaces in names
|