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

49b67f
autofs-5.1.7 - add tree_mapent_delete_offsets()
49b67f
49b67f
From: Ian Kent <raven@themaw.net>
49b67f
49b67f
Add function tree_mapent_delete_offsets() to the mapent tree handling
49b67f
implementation.
49b67f
49b67f
Signed-off-by: Ian Kent <raven@themaw.net>
49b67f
---
49b67f
 CHANGELOG        |    1 
49b67f
 include/mounts.h |    1 
49b67f
 lib/mounts.c     |   70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
49b67f
 3 files changed, 72 insertions(+)
49b67f
49b67f
--- autofs-5.1.4.orig/CHANGELOG
49b67f
+++ autofs-5.1.4/CHANGELOG
49b67f
@@ -34,6 +34,7 @@
49b67f
 - make tree implementation data independent.
49b67f
 - add mapent tree implementation.
49b67f
 - add tree_mapent_add_node().
49b67f
+- add tree_mapent_delete_offsets().
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
@@ -170,6 +170,7 @@ void mnts_put_expire_list(struct list_he
49b67f
 void mnts_set_mounted_mount(struct autofs_point *ap, const char *name, unsigned int flags);
49b67f
 struct tree_node *tree_mapent_root(struct mapent *me);
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
 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
@@ -1528,6 +1528,76 @@ int tree_mapent_add_node(struct mapent_c
49b67f
 	return 1;
49b67f
 }
49b67f
 
49b67f
+static int tree_mapent_delete_offset_tree(struct tree_node *root)
49b67f
+{
49b67f
+	struct mapent *me = MAPENT(root);
49b67f
+	unsigned int logopt = me->mc->ap->logopt;
49b67f
+	int ret = CHE_OK;
49b67f
+
49b67f
+	if (root->left) {
49b67f
+		ret = tree_mapent_delete_offset_tree(root->left);
49b67f
+		if (!ret)
49b67f
+			return 0;
49b67f
+		root->left = NULL;
49b67f
+	}
49b67f
+	if (root->right) {
49b67f
+		ret = tree_mapent_delete_offset_tree(root->right);
49b67f
+		if (!ret)
49b67f
+			return 0;
49b67f
+		root->right = NULL;
49b67f
+	}
49b67f
+
49b67f
+	/* Keep the owner of the multi-mount offset tree and clear
49b67f
+	 * the root and parent when done.
49b67f
+	 */
49b67f
+	if (MAPENT_ROOT(me) != MAPENT_NODE(me)) {
49b67f
+		struct tree_node *root = MAPENT_ROOT(me);
49b67f
+
49b67f
+		debug(logopt, "deleting offset key %s", me->key);
49b67f
+
49b67f
+		/* cache_delete won't delete an active offset */
49b67f
+		MAPENT_SET_ROOT(me, NULL);
49b67f
+		ret = cache_delete(me->mc, me->key);
49b67f
+		if (ret != CHE_OK) {
49b67f
+			MAPENT_SET_ROOT(me, root);
49b67f
+			warn(logopt, "failed to delete offset %s", me->key);
49b67f
+		}
49b67f
+	} else {
49b67f
+		MAPENT_SET_ROOT(me, NULL);
49b67f
+		MAPENT_SET_PARENT(me, NULL);
49b67f
+	}
49b67f
+
49b67f
+	return ret == CHE_OK ? 1 : 0;
49b67f
+}
49b67f
+
49b67f
+int tree_mapent_delete_offsets(struct mapent_cache *mc, const char *key)
49b67f
+{
49b67f
+	unsigned int logopt = mc->ap->logopt;
49b67f
+	struct mapent *me;
49b67f
+
49b67f
+	me = cache_lookup_distinct(mc, key);
49b67f
+	if (!me) {
49b67f
+		error(logopt,
49b67f
+		     "failed to find multi-mount root for key %s", key);
49b67f
+		return 0;
49b67f
+	}
49b67f
+
49b67f
+	/* Not offset list owner */
49b67f
+	if (MAPENT_ROOT(me) != MAPENT_NODE(me)) {
49b67f
+		error(logopt,
49b67f
+		     "mapent for key %s is not multi-mount owner", key);
49b67f
+		return 0;
49b67f
+	}
49b67f
+
49b67f
+	if (!tree_mapent_delete_offset_tree(MAPENT_ROOT(me))) {
49b67f
+		error(logopt,
49b67f
+		     "could not delete map entry offsets for key %s", key);
49b67f
+		return 0;
49b67f
+	}
49b67f
+
49b67f
+	return 1;
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