Blame SOURCES/autofs-5.1.7-add-tree_mapent_cleanup_offsets.patch

29d2b9
autofs-5.1.7 - add tree_mapent_cleanup_offsets()
29d2b9
29d2b9
From: Ian Kent <raven@themaw.net>
29d2b9
29d2b9
Add function tree_mapent_cleanup_offsets() to the mapent tree handling
29d2b9
implementation.
29d2b9
29d2b9
Signed-off-by: Ian Kent <raven@themaw.net>
29d2b9
---
29d2b9
 CHANGELOG        |    1 +
29d2b9
 include/mounts.h |    1 +
29d2b9
 lib/mounts.c     |   45 +++++++++++++++++++++++++++++++++++++++++++++
29d2b9
 3 files changed, 47 insertions(+)
29d2b9
29d2b9
diff --git a/CHANGELOG b/CHANGELOG
29d2b9
index e2fd532c..89d4cfa0 100644
29d2b9
--- a/CHANGELOG
29d2b9
+++ b/CHANGELOG
29d2b9
@@ -37,6 +37,7 @@
29d2b9
 - add tree_mapent_delete_offsets().
29d2b9
 - add tree_mapent_traverse_subtree().
29d2b9
 - fix mount_fullpath().
29d2b9
+- add tree_mapent_cleanup_offsets().
29d2b9
 
29d2b9
 25/01/2021 autofs-5.1.7
29d2b9
 - make bind mounts propagation slave by default.
29d2b9
diff --git a/include/mounts.h b/include/mounts.h
29d2b9
index b5a1193b..5441ee0e 100644
29d2b9
--- a/include/mounts.h
29d2b9
+++ b/include/mounts.h
29d2b9
@@ -171,6 +171,7 @@ void mnts_set_mounted_mount(struct autofs_point *ap, const char *name, unsigned
29d2b9
 struct tree_node *tree_mapent_root(struct mapent *me);
29d2b9
 int tree_mapent_add_node(struct mapent_cache *mc, const char *base, const char *key);
29d2b9
 int tree_mapent_delete_offsets(struct mapent_cache *mc, const char *key);
29d2b9
+void tree_mapent_cleanup_offsets(struct mapent *oe);
29d2b9
 int unlink_mount_tree(struct autofs_point *ap, const char *mp);
29d2b9
 void free_mnt_list(struct mnt_list *list);
29d2b9
 int is_mounted(const char *mp, unsigned int type);
29d2b9
diff --git a/lib/mounts.c b/lib/mounts.c
29d2b9
index 497c28c9..ba573b9a 100644
29d2b9
--- a/lib/mounts.c
29d2b9
+++ b/lib/mounts.c
29d2b9
@@ -1647,6 +1647,51 @@ int tree_mapent_delete_offsets(struct mapent_cache *mc, const char *key)
29d2b9
 	return 1;
29d2b9
 }
29d2b9
 
29d2b9
+static void tree_mapent_umount_mount(struct autofs_point *ap, const char *mp)
29d2b9
+{
29d2b9
+	if (is_mounted(mp, MNTS_ALL)) {
29d2b9
+		if (umount(mp)) {
29d2b9
+			error(ap->logopt, "error recovering from mount fail");
29d2b9
+			error(ap->logopt, "cannot umount %s", mp);
29d2b9
+		}
29d2b9
+	}
29d2b9
+}
29d2b9
+
29d2b9
+static int tree_mapent_cleanup_offsets_work(struct tree_node *n, void *ptr)
29d2b9
+{
29d2b9
+	struct mapent *oe = MAPENT(n);
29d2b9
+	struct traverse_subtree_context *ctxt = ptr;
29d2b9
+
29d2b9
+	tree_mapent_umount_mount(ctxt->ap, oe->key);
29d2b9
+
29d2b9
+	return 1;
29d2b9
+}
29d2b9
+
29d2b9
+void tree_mapent_cleanup_offsets(struct mapent *oe)
29d2b9
+{
29d2b9
+	struct tree_node *base = MAPENT_NODE(oe);
29d2b9
+	struct traverse_subtree_context ctxt = {
29d2b9
+		.ap = oe->mc->ap,
29d2b9
+		.base = base,
29d2b9
+		.strict = 0,
29d2b9
+	};
29d2b9
+	struct autofs_point *ap = oe->mc->ap;
29d2b9
+
29d2b9
+	tree_mapent_traverse_subtree(base, tree_mapent_cleanup_offsets_work, &ctxt);
29d2b9
+
29d2b9
+	/* Cleanup base mount after offsets have been cleaned up */
29d2b9
+	if (*oe->key == '/')
29d2b9
+		tree_mapent_umount_mount(ap, oe->key);
29d2b9
+	else {
29d2b9
+		char mp[PATH_MAX + 1];
29d2b9
+
29d2b9
+		if (!mount_fullpath(mp, PATH_MAX, ap->path, oe->key))
29d2b9
+			error(ap->logopt, "mount path is too long");
29d2b9
+		else
29d2b9
+			tree_mapent_umount_mount(ap, mp);
29d2b9
+	}
29d2b9
+}
29d2b9
+
29d2b9
 /* From glibc decode_name() */
29d2b9
 /* Since the values in a line are separated by spaces, a name cannot
29d2b9
  * contain a space.  Therefore some programs encode spaces in names