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

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