Blame SOURCES/autofs-5.1.6-make-external-mounts-independent-of-amd_entry.patch

49b67f
autofs-5.1.6 - make external mounts independent of amd_entry
49b67f
49b67f
From: Ian Kent <raven@themaw.net>
49b67f
49b67f
The external mounts used by amd map entries should not depend
49b67f
on the amd map entry.
49b67f
49b67f
The external mounts list is keyed by the external mount path
49b67f
and this should be what's used to locate them.
49b67f
49b67f
Signed-off-by: Ian Kent <raven@themaw.net>
49b67f
---
49b67f
 CHANGELOG           |    1 
49b67f
 daemon/automount.c  |    4 -
49b67f
 include/mounts.h    |    6 +-
49b67f
 include/parse_amd.h |    1 
49b67f
 lib/master.c        |    3 -
49b67f
 lib/mounts.c        |  114 ++++++++++++++++++++++++++++++----------------------
49b67f
 modules/parse_amd.c |   14 +++---
49b67f
 7 files changed, 80 insertions(+), 63 deletions(-)
49b67f
49b67f
--- autofs-5.1.4.orig/CHANGELOG
49b67f
+++ autofs-5.1.4/CHANGELOG
49b67f
@@ -119,6 +119,7 @@ xx/xx/2018 autofs-5.1.5
49b67f
 - update list.h.
49b67f
 - add hashtable implementation.
49b67f
 - change mountpoint to mp in struct ext_mount.
49b67f
+- make external mounts independent of amd_entry.
49b67f
 
49b67f
 19/12/2017 autofs-5.1.4
49b67f
 - fix spec file url.
49b67f
--- autofs-5.1.4.orig/daemon/automount.c
49b67f
+++ autofs-5.1.4/daemon/automount.c
49b67f
@@ -613,7 +613,7 @@ static int umount_subtree_mounts(struct
49b67f
 		}
49b67f
 		list_del(&entry->entries);
49b67f
 		mounts_mutex_unlock(ap);
49b67f
-		umount_amd_ext_mount(ap, entry);
49b67f
+		umount_amd_ext_mount(ap, entry->fs);
49b67f
 		free_amd_entry(entry);
49b67f
 	}
49b67f
 done:
49b67f
@@ -679,7 +679,7 @@ int umount_multi(struct autofs_point *ap
49b67f
 		}
49b67f
 		list_del(&entry->entries);
49b67f
 		mounts_mutex_unlock(ap);
49b67f
-		umount_amd_ext_mount(ap, entry);
49b67f
+		umount_amd_ext_mount(ap, entry->fs);
49b67f
 		free_amd_entry(entry);
49b67f
 		return 0;
49b67f
 	}
49b67f
--- autofs-5.1.4.orig/include/mounts.h
49b67f
+++ autofs-5.1.4/include/mounts.h
49b67f
@@ -97,8 +97,8 @@ unsigned int get_kver_minor(void);
49b67f
 char *make_options_string(char *path, int pipefd,
49b67f
 			  const char *type, unsigned int flags);
49b67f
 char *make_mnt_name_string(char *path);
49b67f
-int ext_mount_add(struct list_head *, const char *, unsigned int);
49b67f
-int ext_mount_remove(struct list_head *, const char *);
49b67f
+int ext_mount_add(const char *, const char *);
49b67f
+int ext_mount_remove(const char *);
49b67f
 int ext_mount_inuse(const char *);
49b67f
 struct mnt_list *get_mnt_list(const char *path, int include);
49b67f
 int unlink_mount_tree(struct autofs_point *ap, const char *mp);
49b67f
@@ -118,7 +118,7 @@ int try_remount(struct autofs_point *, s
49b67f
 void set_indirect_mount_tree_catatonic(struct autofs_point *);
49b67f
 void set_direct_mount_tree_catatonic(struct autofs_point *, struct mapent *);
49b67f
 int umount_ent(struct autofs_point *, const char *);
49b67f
-int umount_amd_ext_mount(struct autofs_point *, struct amd_entry *);
49b67f
+int umount_amd_ext_mount(struct autofs_point *, const char *);
49b67f
 int mount_multi_triggers(struct autofs_point *, struct mapent *, const char *, unsigned int, const char *);
49b67f
 int umount_multi_triggers(struct autofs_point *, struct mapent *, char *, const char *);
49b67f
 int clean_stale_multi_triggers(struct autofs_point *, struct mapent *, char *, const char *);
49b67f
--- autofs-5.1.4.orig/include/parse_amd.h
49b67f
+++ autofs-5.1.4/include/parse_amd.h
49b67f
@@ -66,7 +66,6 @@ struct amd_entry {
49b67f
 	struct selector *selector;
49b67f
 	struct list_head list;
49b67f
 	struct list_head entries;
49b67f
-	struct list_head ext_mount;
49b67f
 };
49b67f
 
49b67f
 int amd_parse_list(struct autofs_point *,
49b67f
--- autofs-5.1.4.orig/lib/master.c
49b67f
+++ autofs-5.1.4/lib/master.c
49b67f
@@ -154,10 +154,9 @@ void master_free_autofs_point(struct aut
49b67f
 	while (p != head) {
49b67f
 		struct amd_entry *entry = list_entry(p, struct amd_entry, entries);
49b67f
 		p = p->next;
49b67f
-		if (!list_empty(&entry->ext_mount))
49b67f
-			ext_mount_remove(&entry->ext_mount, entry->fs);
49b67f
 		if (!list_empty(&entry->entries))
49b67f
 			list_del(&entry->entries);
49b67f
+		ext_mount_remove(entry->fs);
49b67f
 		free_amd_entry(entry);
49b67f
 	}
49b67f
 	mounts_mutex_unlock(ap);
49b67f
--- autofs-5.1.4.orig/lib/mounts.c
49b67f
+++ autofs-5.1.4/lib/mounts.c
49b67f
@@ -54,10 +54,10 @@ static size_t maxgrpbuf = 0;
49b67f
 #define EXT_MOUNTS_HASH_SIZE    50
49b67f
 
49b67f
 struct ext_mount {
49b67f
+	unsigned int ref;
49b67f
 	char *mp;
49b67f
-	unsigned int umount;
49b67f
+	char *umount;
49b67f
 	struct list_head mount;
49b67f
-	struct list_head mounts;
49b67f
 };
49b67f
 static struct list_head ext_mounts_hash[EXT_MOUNTS_HASH_SIZE];
49b67f
 static unsigned int ext_mounts_hash_init_done = 0;
49b67f
@@ -542,7 +542,6 @@ struct amd_entry *new_amd_entry(const st
49b67f
 	new->path = path;
49b67f
 	INIT_LIST_HEAD(&new->list);
49b67f
 	INIT_LIST_HEAD(&new->entries);
49b67f
-	INIT_LIST_HEAD(&new->ext_mount);
49b67f
 
49b67f
 	return new;
49b67f
 }
49b67f
@@ -763,7 +762,7 @@ static struct ext_mount *ext_mount_looku
49b67f
 	return NULL;
49b67f
 }
49b67f
 
49b67f
-int ext_mount_add(struct list_head *entry, const char *path, unsigned int umount)
49b67f
+int ext_mount_add(const char *path, const char *umount)
49b67f
 {
49b67f
 	struct ext_mount *em;
49b67f
 	u_int32_t hval;
49b67f
@@ -773,13 +772,7 @@ int ext_mount_add(struct list_head *entr
49b67f
 
49b67f
 	em = ext_mount_lookup(path);
49b67f
 	if (em) {
49b67f
-		struct list_head *p, *head;
49b67f
-		head = &em->mounts;
49b67f
-		list_for_each(p, head) {
49b67f
-			if (p == entry)
49b67f
-				goto done;
49b67f
-		}
49b67f
-		list_add_tail(entry, &em->mounts);
49b67f
+		em->ref++;
49b67f
 		ret = 1;
49b67f
 		goto done;
49b67f
 	}
49b67f
@@ -787,28 +780,34 @@ int ext_mount_add(struct list_head *entr
49b67f
 	em = malloc(sizeof(struct ext_mount));
49b67f
 	if (!em)
49b67f
 		goto done;
49b67f
+	memset(em, 0, sizeof(*em));
49b67f
 
49b67f
 	em->mp = strdup(path);
49b67f
 	if (!em->mp) {
49b67f
 		free(em);
49b67f
 		goto done;
49b67f
 	}
49b67f
-	em->umount = umount;
49b67f
+	if (umount) {
49b67f
+		em->umount = strdup(umount);
49b67f
+		if (!em->umount) {
49b67f
+			free(em->mp);
49b67f
+			free(em);
49b67f
+			goto done;
49b67f
+		}
49b67f
+	}
49b67f
+	em->ref = 1;
49b67f
 	INIT_LIST_HEAD(&em->mount);
49b67f
-	INIT_LIST_HEAD(&em->mounts);
49b67f
 
49b67f
 	hval = hash(path, EXT_MOUNTS_HASH_SIZE);
49b67f
 	list_add_tail(&em->mount, &ext_mounts_hash[hval]);
49b67f
 
49b67f
-	list_add_tail(entry, &em->mounts);
49b67f
-
49b67f
 	ret = 1;
49b67f
 done:
49b67f
 	pthread_mutex_unlock(&ext_mount_hash_mutex);
49b67f
 	return ret;
49b67f
 }
49b67f
 
49b67f
-int ext_mount_remove(struct list_head *entry, const char *path)
49b67f
+int ext_mount_remove(const char *path)
49b67f
 {
49b67f
 	struct ext_mount *em;
49b67f
 	int ret = 0;
49b67f
@@ -819,18 +818,18 @@ int ext_mount_remove(struct list_head *e
49b67f
 	if (!em)
49b67f
 		goto done;
49b67f
 
49b67f
-	list_del_init(entry);
49b67f
-
49b67f
-	if (!list_empty(&em->mounts))
49b67f
+	em->ref--;
49b67f
+	if (em->ref)
49b67f
 		goto done;
49b67f
 	else {
49b67f
 		list_del_init(&em->mount);
49b67f
-		if (em->umount)
49b67f
-			ret = 1;
49b67f
 		if (list_empty(&em->mount)) {
49b67f
 			free(em->mp);
49b67f
+			if (em->umount)
49b67f
+				free(em->umount);
49b67f
 			free(em);
49b67f
 		}
49b67f
+		ret = 1;
49b67f
 	}
49b67f
 done:
49b67f
 	pthread_mutex_unlock(&ext_mount_hash_mutex);
49b67f
@@ -846,9 +845,7 @@ int ext_mount_inuse(const char *path)
49b67f
 	em = ext_mount_lookup(path);
49b67f
 	if (!em)
49b67f
 		goto done;
49b67f
-
49b67f
-	if (!list_empty(&em->mounts))
49b67f
-		ret = 1;
49b67f
+	ret = em->ref;
49b67f
 done:
49b67f
 	pthread_mutex_unlock(&ext_mount_hash_mutex);
49b67f
 	return ret;
49b67f
@@ -2092,29 +2089,49 @@ int umount_ent(struct autofs_point *ap,
49b67f
 	return rv;
49b67f
 }
49b67f
 
49b67f
-int umount_amd_ext_mount(struct autofs_point *ap, struct amd_entry *entry)
49b67f
+int umount_amd_ext_mount(struct autofs_point *ap, const char *path)
49b67f
 {
49b67f
+	struct ext_mount *em;
49b67f
+	char *umount = NULL;
49b67f
+	char *mp;
49b67f
 	int rv = 1;
49b67f
 
49b67f
-	if (entry->umount) {
49b67f
-		char *prog, *str;
49b67f
-		char **argv;
49b67f
-		int argc = -1;
49b67f
+	pthread_mutex_lock(&ext_mount_hash_mutex);
49b67f
 
49b67f
-		str = strdup(entry->umount);
49b67f
-		if (!str)
49b67f
+	em = ext_mount_lookup(path);
49b67f
+	if (!em) {
49b67f
+		pthread_mutex_unlock(&ext_mount_hash_mutex);
49b67f
+		goto out;
49b67f
+	}
49b67f
+	mp = strdup(em->mp);
49b67f
+	if (!mp) {
49b67f
+		pthread_mutex_unlock(&ext_mount_hash_mutex);
49b67f
+		goto out;
49b67f
+	}
49b67f
+	if (em->umount) {
49b67f
+		umount = strdup(em->umount);
49b67f
+		if (!umount) {
49b67f
+			pthread_mutex_unlock(&ext_mount_hash_mutex);
49b67f
+			free(mp);
49b67f
 			goto out;
49b67f
+		}
49b67f
+	}
49b67f
+
49b67f
+	pthread_mutex_unlock(&ext_mount_hash_mutex);
49b67f
+
49b67f
+	if (umount) {
49b67f
+		char *prog;
49b67f
+		char **argv;
49b67f
+		int argc = -1;
49b67f
 
49b67f
 		prog = NULL;
49b67f
 		argv = NULL;
49b67f
 
49b67f
-		argc = construct_argv(str, &prog, &argv);
49b67f
-		if (argc == -1) {
49b67f
-			free(str);
49b67f
-			goto out;
49b67f
-		}
49b67f
+		argc = construct_argv(umount, &prog, &argv);
49b67f
+		if (argc == -1)
49b67f
+			goto done;
49b67f
 
49b67f
-		if (!ext_mount_remove(&entry->ext_mount, entry->fs)) {
49b67f
+		if (!ext_mount_remove(mp)) {
49b67f
 			rv =0;
49b67f
 			goto out_free;
49b67f
 		}
49b67f
@@ -2122,29 +2139,30 @@ int umount_amd_ext_mount(struct autofs_p
49b67f
 		rv = spawnv(ap->logopt, prog, (const char * const *) argv);
49b67f
 		if (rv == -1 || (WIFEXITED(rv) && WEXITSTATUS(rv)))
49b67f
 			error(ap->logopt,
49b67f
-			     "failed to umount program mount at %s", entry->fs);
49b67f
+			     "failed to umount program mount at %s", mp);
49b67f
 		else {
49b67f
 			rv = 0;
49b67f
-			debug(ap->logopt,
49b67f
-			      "umounted program mount at %s", entry->fs);
49b67f
-			rmdir_path(ap, entry->fs, ap->dev);
49b67f
+			debug(ap->logopt, "umounted program mount at %s", mp);
49b67f
+			rmdir_path(ap, mp, ap->dev);
49b67f
 		}
49b67f
 out_free:
49b67f
 		free_argv(argc, (const char **) argv);
49b67f
-		free(str);
49b67f
 
49b67f
-		goto out;
49b67f
+		goto done;
49b67f
 	}
49b67f
 
49b67f
-	if (ext_mount_remove(&entry->ext_mount, entry->fs)) {
49b67f
-		rv = umount_ent(ap, entry->fs);
49b67f
+	if (ext_mount_remove(mp)) {
49b67f
+		rv = umount_ent(ap, mp);
49b67f
 		if (rv)
49b67f
 			error(ap->logopt,
49b67f
-			      "failed to umount external mount %s", entry->fs);
49b67f
+			      "failed to umount external mount %s", mp);
49b67f
 		else
49b67f
-			debug(ap->logopt,
49b67f
-			      "umounted external mount %s", entry->fs);
49b67f
+			debug(ap->logopt, "umounted external mount %s", mp);
49b67f
 	}
49b67f
+done:
49b67f
+	if (umount)
49b67f
+		free(umount);
49b67f
+	free(mp);
49b67f
 out:
49b67f
 	return rv;
49b67f
 }
49b67f
--- autofs-5.1.4.orig/modules/parse_amd.c
49b67f
+++ autofs-5.1.4/modules/parse_amd.c
49b67f
@@ -1136,7 +1136,7 @@ symlink:
49b67f
 
49b67f
 	if (entry->sublink) {
49b67f
 		/* failed to complete sublink mount */
49b67f
-		umount_amd_ext_mount(ap, entry);
49b67f
+		umount_amd_ext_mount(ap, entry->fs);
49b67f
 	}
49b67f
 out:
49b67f
 	return ret;
49b67f
@@ -1183,8 +1183,8 @@ static int do_generic_mount(struct autof
49b67f
 				goto out;
49b67f
 			umount = 1;
49b67f
 		}
49b67f
-		/* We have an external mount */
49b67f
-		if (!ext_mount_add(&entry->ext_mount, entry->fs, umount)) {
49b67f
+		/* If we have an external mount add it to the list */
49b67f
+		if (umount && !ext_mount_add(entry->fs, entry->umount)) {
49b67f
 			umount_ent(ap, entry->fs);
49b67f
 			error(ap->logopt, MODPREFIX
49b67f
 			      "error: could not add external mount %s",
49b67f
@@ -1235,7 +1235,7 @@ static int do_nfs_mount(struct autofs_po
49b67f
 			umount = 1;
49b67f
 		}
49b67f
 		/* We might be using an external mount */
49b67f
-		if (!ext_mount_add(&entry->ext_mount, entry->fs, umount)) {
49b67f
+		if (umount && !ext_mount_add(entry->fs, entry->umount)) {
49b67f
 			umount_ent(ap, entry->fs);
49b67f
 			error(ap->logopt, MODPREFIX
49b67f
 			      "error: could not add external mount %s", entry->fs);
49b67f
@@ -1429,7 +1429,7 @@ static int do_program_mount(struct autof
49b67f
 		/* An external mount with path entry->fs exists
49b67f
 		 * so ext_mount_add() won't fail.
49b67f
 		 */
49b67f
-		ext_mount_add(&entry->ext_mount, entry->fs, 1);
49b67f
+		ext_mount_add(entry->fs, entry->umount);
49b67f
 	} else {
49b67f
 		rv = mkdir_path(entry->fs, mp_mode);
49b67f
 		if (rv && errno != EEXIST) {
49b67f
@@ -1445,7 +1445,7 @@ static int do_program_mount(struct autof
49b67f
 
49b67f
 		rv = spawnv(ap->logopt, prog, (const char * const *) argv);
49b67f
 		if (WIFEXITED(rv) && !WEXITSTATUS(rv)) {
49b67f
-			if (ext_mount_add(&entry->ext_mount, entry->fs, 1)) {
49b67f
+			if (ext_mount_add(entry->fs, entry->umount)) {
49b67f
 				rv = 0;
49b67f
 				debug(ap->logopt, MODPREFIX
49b67f
 				     "%s: mounted %s", entry->type, entry->fs);
49b67f
@@ -1470,7 +1470,7 @@ do_free:
49b67f
 	if (!rv)
49b67f
 		goto out;
49b67f
 
49b67f
-	if (umount_amd_ext_mount(ap, entry)) {
49b67f
+	if (umount_amd_ext_mount(ap, entry->fs)) {
49b67f
 		if (!ext_mount_inuse(entry->fs))
49b67f
 			rmdir_path(ap, entry->fs, ap->dev);
49b67f
 		debug(ap->logopt, MODPREFIX