Blame SOURCES/autofs-5.1.7-switch-to-use-tree-implementation-for-offsets.patch

49b67f
autofs-5.1.7 - switch to use tree implementation for offsets
49b67f
49b67f
From: Ian Kent <raven@themaw.net>
49b67f
49b67f
Change to use the tree mapent implementation for the handling
49b67f
of offset mounts.
49b67f
49b67f
Signed-off-by: Ian Kent <raven@themaw.net>
49b67f
---
49b67f
 CHANGELOG                |    1 
49b67f
 daemon/automount.c       |   25 ++----------
49b67f
 daemon/lookup.c          |    2 -
49b67f
 include/automount.h      |    8 ++--
49b67f
 lib/cache.c              |   67 ---------------------------------
49b67f
 lib/mounts.c             |    4 +-
49b67f
 modules/lookup_program.c |    2 -
49b67f
 modules/parse_sun.c      |   94 ++++++++++++-----------------------------------
49b67f
 8 files changed, 39 insertions(+), 164 deletions(-)
49b67f
49b67f
--- autofs-5.1.4.orig/CHANGELOG
49b67f
+++ autofs-5.1.4/CHANGELOG
49b67f
@@ -40,6 +40,7 @@
49b67f
 - add tree_mapent_cleanup_offsets().
49b67f
 - add set_offset_tree_catatonic().
49b67f
 - add mount and umount offsets functions.
49b67f
+- switch to use tree implementation for offsets.
49b67f
 
49b67f
 xx/xx/2018 autofs-5.1.5
49b67f
 - fix flag file permission.
49b67f
--- autofs-5.1.4.orig/daemon/automount.c
49b67f
+++ autofs-5.1.4/daemon/automount.c
49b67f
@@ -551,29 +551,15 @@ static int umount_subtree_mounts(struct
49b67f
 	left = 0;
49b67f
 
49b67f
 	if (me && IS_MM(me)) {
49b67f
-		char root[PATH_MAX + 1];
49b67f
 		char key[PATH_MAX + 1];
49b67f
 		struct mapent *tmp;
49b67f
-		int status;
49b67f
-		char *base;
49b67f
+		int ret;
49b67f
 
49b67f
-		if (!strchr(MM_ROOT(me)->key, '/'))
49b67f
-			/* Indirect multi-mount root */
49b67f
-			/* sprintf okay - if it's mounted, it's
49b67f
-			 * PATH_MAX or less bytes */
49b67f
-			sprintf(root, "%s/%s", ap->path, MM_ROOT(me)->key);
49b67f
-		else
49b67f
-			strcpy(root, MM_ROOT(me)->key);
49b67f
-
49b67f
-		if (IS_MM_ROOT(me))
49b67f
-			base = NULL;
49b67f
-		else
49b67f
-			base = me->key + strlen(root);
49b67f
-
49b67f
-		left = umount_multi_triggers(ap, me, root, base);
49b67f
-		if (left) {
49b67f
+		ret = tree_mapent_umount_offsets(me, 1);
49b67f
+		if (!ret) {
49b67f
 			warn(ap->logopt,
49b67f
 			     "some offset mounts still present under %s", path);
49b67f
+			left++;
49b67f
 		}
49b67f
 
49b67f
 		strcpy(key, me->key);
49b67f
@@ -589,8 +575,7 @@ static int umount_subtree_mounts(struct
49b67f
 		}
49b67f
 
49b67f
 		if (!left && IS_MM_ROOT(me)) {
49b67f
-			status = cache_delete_offset_list(mc, me->key);
49b67f
-			if (status != CHE_OK) {
49b67f
+			if (!tree_mapent_delete_offsets(mc, me->key)) {
49b67f
 				warn(ap->logopt, "couldn't delete offset list");
49b67f
 				left++;
49b67f
 			}
49b67f
--- autofs-5.1.4.orig/daemon/lookup.c
49b67f
+++ autofs-5.1.4/daemon/lookup.c
49b67f
@@ -851,7 +851,7 @@ static int lookup_amd_instance(struct au
49b67f
 		return NSS_STATUS_UNKNOWN;
49b67f
 	}
49b67f
 
49b67f
-	m_key = malloc(ap->len + strlen(MM_ROOT(me)->key) + 2);
49b67f
+	m_key = malloc(ap->len + MM_ROOT(me)->len + 2);
49b67f
 	if (!m_key) {
49b67f
 		error(ap->logopt,
49b67f
 		     "failed to allocate storage for search key");
49b67f
--- autofs-5.1.4.orig/include/automount.h
49b67f
+++ autofs-5.1.4/include/automount.h
49b67f
@@ -187,10 +187,10 @@ struct mapent {
49b67f
 	ino_t ino;
49b67f
 };
49b67f
 
49b67f
-#define IS_MM(me)	(me->multi)
49b67f
-#define IS_MM_ROOT(me)	(me->multi == me)
49b67f
-#define MM_ROOT(me)	(me->multi)
49b67f
-#define MM_PARENT(me)	(me->parent)
49b67f
+#define IS_MM(me)	(me->mm_root)
49b67f
+#define IS_MM_ROOT(me)	(me->mm_root == &me->node)
49b67f
+#define MM_ROOT(me)	(MAPENT(me->mm_root))
49b67f
+#define MM_PARENT(me)	(MAPENT(me->mm_parent))
49b67f
 
49b67f
 void cache_lock_cleanup(void *arg);
49b67f
 void cache_readlock(struct mapent_cache *mc);
49b67f
--- autofs-5.1.4.orig/lib/cache.c
49b67f
+++ autofs-5.1.4/lib/cache.c
49b67f
@@ -682,14 +682,6 @@ int cache_update_offset(struct mapent_ca
49b67f
 		return CHE_FAIL;
49b67f
 	}
49b67f
 
49b67f
-	me = cache_lookup_distinct(mc, key);
49b67f
-	if (me) {
49b67f
-		cache_add_ordered_offset(me, &owner->multi_list);
49b67f
-		MM_ROOT(me) = owner;
49b67f
-		goto done;
49b67f
-	}
49b67f
-	ret = CHE_FAIL;
49b67f
-done:
49b67f
 	return ret; 
49b67f
 }
49b67f
 
49b67f
@@ -928,65 +920,6 @@ done:
49b67f
 	return ret;
49b67f
 }
49b67f
 
49b67f
-/* cache must be write locked by caller */
49b67f
-int cache_delete_offset_list(struct mapent_cache *mc, const char *key)
49b67f
-{
49b67f
-	unsigned logopt = mc->ap ? mc->ap->logopt : master_get_logopt();
49b67f
-	struct mapent *me;
49b67f
-	struct mapent *this;
49b67f
-	struct list_head *head, *next;
49b67f
-	int remain = 0;
49b67f
-	int status;
49b67f
-
49b67f
-	me = cache_lookup_distinct(mc, key);
49b67f
-	if (!me)
49b67f
-		return CHE_FAIL;
49b67f
-
49b67f
-	/* Not offset list owner */
49b67f
-	if (!IS_MM_ROOT(me))
49b67f
-		return CHE_FAIL;
49b67f
-
49b67f
-	head = &me->multi_list;
49b67f
-	next = head->next;
49b67f
-	while (next != head) {
49b67f
-		this = list_entry(next, struct mapent, multi_list);
49b67f
-		next = next->next;
49b67f
-		if (this->ioctlfd != -1) {
49b67f
-			error(logopt,
49b67f
-			      "active offset mount key %s", this->key);
49b67f
-			return CHE_FAIL;
49b67f
-		}
49b67f
-	}
49b67f
-
49b67f
-	head = &me->multi_list;
49b67f
-	next = head->next;
49b67f
-	while (next != head) {
49b67f
-		this = list_entry(next, struct mapent, multi_list);
49b67f
-		next = next->next;
49b67f
-		list_del_init(&this->multi_list);
49b67f
-		MM_ROOT(this) = NULL;
49b67f
-		debug(logopt, "deleting offset key %s", this->key);
49b67f
-		status = cache_delete(mc, this->key);
49b67f
-		if (status == CHE_FAIL) {
49b67f
-			warn(logopt,
49b67f
-			     "failed to delete offset %s", this->key);
49b67f
-			MM_ROOT(this) = me;
49b67f
-			/* TODO: add list back in */
49b67f
-			remain++;
49b67f
-		}
49b67f
-	}
49b67f
-
49b67f
-	if (!remain) {
49b67f
-		list_del_init(&me->multi_list);
49b67f
-		MM_ROOT(me) = NULL;
49b67f
-	}
49b67f
-
49b67f
-	if (remain)
49b67f
-		return CHE_FAIL;
49b67f
-
49b67f
-	return CHE_OK;
49b67f
-}
49b67f
-
49b67f
 void cache_release(struct map_source *map)
49b67f
 {
49b67f
 	struct mapent_cache *mc;
49b67f
--- autofs-5.1.4.orig/lib/mounts.c
49b67f
+++ autofs-5.1.4/lib/mounts.c
49b67f
@@ -2889,7 +2889,7 @@ void set_indirect_mount_tree_catatonic(s
49b67f
 
49b67f
 			/* Only need to set offset mounts catatonic */
49b67f
 			if (IS_MM(me) && IS_MM_ROOT(me))
49b67f
-				set_multi_mount_tree_catatonic(ap, me);
49b67f
+				set_offset_tree_catatonic(ap, me);
49b67f
 next:
49b67f
 			me = cache_enumerate(mc, me);
49b67f
 		}
49b67f
@@ -2909,7 +2909,7 @@ void set_direct_mount_tree_catatonic(str
49b67f
 {
49b67f
 	/* Set offset mounts catatonic for this mapent */
49b67f
 	if (IS_MM(me) && IS_MM_ROOT(me))
49b67f
-		set_multi_mount_tree_catatonic(ap, me);
49b67f
+		set_offset_tree_catatonic(ap, me);
49b67f
 	set_mount_catatonic(ap, me, me->ioctlfd);
49b67f
 }
49b67f
 
49b67f
--- autofs-5.1.4.orig/modules/lookup_program.c
49b67f
+++ autofs-5.1.4/modules/lookup_program.c
49b67f
@@ -676,7 +676,7 @@ int lookup_mount(struct autofs_point *ap
49b67f
 			me = cache_lookup_distinct(mc, name);
49b67f
 			if (me) {
49b67f
 				if (IS_MM(me))
49b67f
-					cache_delete_offset_list(mc, name);
49b67f
+					tree_mapent_delete_offsets(mc, name);
49b67f
 				cache_delete(mc, name);
49b67f
 			}
49b67f
 			cache_unlock(mc);
49b67f
--- autofs-5.1.4.orig/modules/parse_sun.c
49b67f
+++ autofs-5.1.4/modules/parse_sun.c
49b67f
@@ -856,8 +856,8 @@ update_offset_entry(struct autofs_point
49b67f
 	cache_writelock(mc);
49b67f
 	ret = cache_update_offset(mc, name, m_key, m_mapent, age);
49b67f
 
49b67f
-	if (!cache_set_offset_parent(mc, m_key))
49b67f
-		error(ap->logopt, "failed to set offset parent");
49b67f
+	if (!tree_mapent_add_node(mc, name, m_key))
49b67f
+		error(ap->logopt, "failed to add offset %s to tree", m_key);
49b67f
 	cache_unlock(mc);
49b67f
 
49b67f
 	if (ret == CHE_DUPLICATE) {
49b67f
@@ -1136,10 +1136,7 @@ static int mount_subtree(struct autofs_p
49b67f
 			 const char *name, char *loc, char *options, void *ctxt)
49b67f
 {
49b67f
 	struct mapent *me;
49b67f
-	struct mapent *ro;
49b67f
-	char *mm_root, *mm_base, *mm_key;
49b67f
-	unsigned int mm_root_len;
49b67f
-	int start, ret = 0, rv;
49b67f
+	int ret = 0, rv;
49b67f
 
49b67f
 	cache_readlock(mc);
49b67f
 	me = cache_lookup_distinct(mc, name);
49b67f
@@ -1150,34 +1147,18 @@ static int mount_subtree(struct autofs_p
49b67f
 
49b67f
 	rv = 0;
49b67f
 
49b67f
-	mm_key = MM_ROOT(me)->key;
49b67f
-
49b67f
-	if (*mm_key == '/') {
49b67f
-		mm_root = mm_key;
49b67f
-		start = strlen(mm_key);
49b67f
-	} else {
49b67f
-		start = ap->len + strlen(mm_key) + 1;
49b67f
-		mm_root = alloca(start + 3);
49b67f
-		strcpy(mm_root, ap->path);
49b67f
-		strcat(mm_root, "/");
49b67f
-		strcat(mm_root, mm_key);
49b67f
-	}
49b67f
-	mm_root_len = strlen(mm_root);
49b67f
-
49b67f
 	if (IS_MM_ROOT(me)) {
49b67f
 		char key[PATH_MAX + 1];
49b67f
+		struct mapent *ro;
49b67f
+		size_t len;
49b67f
 
49b67f
-		if (mm_root_len + 1 > PATH_MAX) {
49b67f
+		len = mount_fullpath(key, PATH_MAX, ap->path, me->key);
49b67f
+		if (!len) {
49b67f
 			warn(ap->logopt, "path loo long");
49b67f
 			return 1;
49b67f
 		}
49b67f
-
49b67f
-		/* name = NULL */
49b67f
-		/* destination = mm_root */
49b67f
-		mm_base = "/";
49b67f
-
49b67f
-		strcpy(key, mm_root);
49b67f
-		strcat(key, mm_base);
49b67f
+		key[len] = '/';
49b67f
+		key[len + 1] = 0;
49b67f
 
49b67f
 		/* Mount root offset if it exists */
49b67f
 		ro = cache_lookup_distinct(me->mc, key);
49b67f
@@ -1196,7 +1177,7 @@ static int mount_subtree(struct autofs_p
49b67f
 				warn(ap->logopt,
49b67f
 				      MODPREFIX "failed to parse root offset");
49b67f
 				cache_writelock(mc);
49b67f
-				cache_delete_offset_list(mc, name);
49b67f
+				tree_mapent_delete_offsets(mc, name);
49b67f
 				cache_unlock(mc);
49b67f
 				return 1;
49b67f
 			}
49b67f
@@ -1211,10 +1192,10 @@ static int mount_subtree(struct autofs_p
49b67f
 				free(ro_loc);
49b67f
 		}
49b67f
 
49b67f
-		if ((ro && rv == 0) || rv <= 0) {
49b67f
-			ret = mount_multi_triggers(ap, me, mm_root, start, mm_base);
49b67f
-			if (ret == -1) {
49b67f
-				cleanup_multi_triggers(ap, me, mm_root, start, mm_base);
49b67f
+		if (rv <= 0) {
49b67f
+			ret = tree_mapent_mount_offsets(me, 1);
49b67f
+			if (!ret) {
49b67f
+				tree_mapent_cleanup_offsets(me);
49b67f
 				cache_unlock(mc);
49b67f
 				error(ap->logopt, MODPREFIX
49b67f
 					 "failed to mount offset triggers");
49b67f
@@ -1225,39 +1206,14 @@ static int mount_subtree(struct autofs_p
49b67f
 		int loclen = strlen(loc);
49b67f
 		int namelen = strlen(name);
49b67f
 
49b67f
-		/* name = mm_root + mm_base */
49b67f
-		/* destination = mm_root + mm_base = name */
49b67f
-		mm_base = &me->key[start];
49b67f
-
49b67f
+		/* Mounts at nesting points must succeed for subtree
49b67f
+		 * offsets to be mounted.
49b67f
+		 */
49b67f
 		rv = sun_mount(ap, name, name, namelen, loc, loclen, options, ctxt);
49b67f
 		if (rv == 0) {
49b67f
-			ret = mount_multi_triggers(ap, me->multi, name, start, mm_base);
49b67f
-			if (ret == -1) {
49b67f
-				cleanup_multi_triggers(ap, me, name, start, mm_base);
49b67f
-				cache_unlock(mc);
49b67f
-				error(ap->logopt, MODPREFIX
49b67f
-					 "failed to mount offset triggers");
49b67f
-				return 1;
49b67f
-			}
49b67f
-		} else if (rv < 0) {
49b67f
-			char mm_root_base[PATH_MAX + 1];
49b67f
-			unsigned int mm_root_base_len = mm_root_len + strlen(mm_base) + 1;
49b67f
-	
49b67f
-			if (mm_root_base_len > PATH_MAX) {
49b67f
-				cache_unlock(mc);
49b67f
-				warn(ap->logopt, MODPREFIX "path too long");
49b67f
-				cache_writelock(mc);
49b67f
-				cache_delete_offset_list(mc, name);
49b67f
-				cache_unlock(mc);
49b67f
-				return 1;
49b67f
-			}
49b67f
-
49b67f
-			strcpy(mm_root_base, mm_root);
49b67f
-			strcat(mm_root_base, mm_base);
49b67f
-
49b67f
-			ret = mount_multi_triggers(ap, me->multi, mm_root_base, start, mm_base);
49b67f
-			if (ret == -1) {
49b67f
-				cleanup_multi_triggers(ap, me, mm_root, start, mm_base);
49b67f
+			ret = tree_mapent_mount_offsets(me, 1);
49b67f
+			if (!ret) {
49b67f
+				tree_mapent_cleanup_offsets(me);
49b67f
 				cache_unlock(mc);
49b67f
 				error(ap->logopt, MODPREFIX
49b67f
 					 "failed to mount offset triggers");
49b67f
@@ -1267,7 +1223,7 @@ static int mount_subtree(struct autofs_p
49b67f
 	}
49b67f
 	cache_unlock(mc);
49b67f
 
49b67f
-	/* Mount for base of tree failed */
49b67f
+	/* strict mount failed */
49b67f
 	if (rv > 0)
49b67f
 		return rv;
49b67f
 
49b67f
@@ -1508,7 +1464,7 @@ dont_expand:
49b67f
 
49b67f
 		/* So we know we're the multi-mount root */
49b67f
 		if (!IS_MM(me))
49b67f
-			me->multi = me;
49b67f
+			MAPENT_SET_ROOT(me, tree_mapent_root(me))
49b67f
 		else {
49b67f
 			/*
49b67f
 			 * The amd host mount type assumes the lookup name
49b67f
@@ -1558,7 +1514,7 @@ dont_expand:
49b67f
 			if (!m_offset) {
49b67f
 				warn(ap->logopt, MODPREFIX "null path or out of memory");
49b67f
 				cache_writelock(mc);
49b67f
-				cache_delete_offset_list(mc, name);
49b67f
+				tree_mapent_delete_offsets(mc, name);
49b67f
 				cache_unlock(mc);
49b67f
 				free(options);
49b67f
 				free(pmapent);
49b67f
@@ -1575,7 +1531,7 @@ dont_expand:
49b67f
 			l = parse_mapent(p, options, &myoptions, &loc, ap->logopt);
49b67f
 			if (!l) {
49b67f
 				cache_writelock(mc);
49b67f
-				cache_delete_offset_list(mc, name);
49b67f
+				tree_mapent_delete_offsets(mc, name);
49b67f
 				cache_unlock(mc);
49b67f
 				free(m_offset);
49b67f
 				free(options);
49b67f
@@ -1594,7 +1550,7 @@ dont_expand:
49b67f
 			if (status != CHE_OK) {
49b67f
 				warn(ap->logopt, MODPREFIX "error adding multi-mount");
49b67f
 				cache_writelock(mc);
49b67f
-				cache_delete_offset_list(mc, name);
49b67f
+				tree_mapent_delete_offsets(mc, name);
49b67f
 				cache_unlock(mc);
49b67f
 				free(m_offset);
49b67f
 				free(options);