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

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