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

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