Blame SOURCES/autofs-5.0.9-amd-lookup-dont-umount-admin-mounted-external-mounts.patch

304803
autofs-5.0.9 - amd lookup dont umount admin mounted external mounts
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
If an autofs doesn't mount an external mount then it shouldn't
304803
umount it.
304803
---
304803
 include/mounts.h    |    2 +-
304803
 lib/mounts.c        |    7 +++++--
304803
 modules/parse_amd.c |    8 ++++++--
304803
 3 files changed, 12 insertions(+), 5 deletions(-)
304803
304803
diff --git a/include/mounts.h b/include/mounts.h
304803
index 07a8c3b..17cae31 100644
304803
--- a/include/mounts.h
304803
+++ b/include/mounts.h
304803
@@ -101,7 +101,7 @@ unsigned int get_kver_major(void);
304803
 unsigned int get_kver_minor(void);
304803
 char *make_options_string(char *path, int kernel_pipefd, const char *extra);
304803
 char *make_mnt_name_string(char *path);
304803
-int ext_mount_add(struct list_head *, const char *);
304803
+int ext_mount_add(struct list_head *, const char *, unsigned int);
304803
 int ext_mount_remove(struct list_head *, const char *);
304803
 struct mnt_list *get_mnt_list(const char *table, const char *path, int include);
304803
 struct mnt_list *reverse_mnt_list(struct mnt_list *list);
304803
diff --git a/lib/mounts.c b/lib/mounts.c
304803
index d8357d0..c9e1237 100644
304803
--- a/lib/mounts.c
304803
+++ b/lib/mounts.c
304803
@@ -51,6 +51,7 @@ static const char kver_options_template[]  = "fd=%d,pgrp=%u,minproto=3,maxproto=
304803
 
304803
 struct ext_mount {
304803
 	char *mountpoint;
304803
+	unsigned int umount;
304803
 	struct list_head mount;
304803
 	struct list_head mounts;
304803
 };
304803
@@ -619,7 +620,7 @@ static struct ext_mount *ext_mount_lookup(const char *mountpoint)
304803
 	return NULL;
304803
 }
304803
 
304803
-int ext_mount_add(struct list_head *entry, const char *path)
304803
+int ext_mount_add(struct list_head *entry, const char *path, unsigned int umount)
304803
 {
304803
 	struct ext_mount *em;
304803
 	char *auto_dir;
304803
@@ -661,6 +662,7 @@ int ext_mount_add(struct list_head *entry, const char *path)
304803
 		ret = -1;
304803
 		goto done;
304803
 	}
304803
+	em->umount = umount;
304803
 	INIT_LIST_HEAD(&em->mount);
304803
 	INIT_LIST_HEAD(&em->mounts);
304803
 
304803
@@ -701,11 +703,12 @@ int ext_mount_remove(struct list_head *entry, const char *path)
304803
 		goto done;
304803
 	else {
304803
 		list_del_init(&em->mount);
304803
+		if (em->umount)
304803
+			ret = 1;
304803
 		if (list_empty(&em->mount)) {
304803
 			free(em->mountpoint);
304803
 			free(em);
304803
 		}
304803
-		ret = 1;
304803
 	}
304803
 done:
304803
 	pthread_mutex_unlock(&ext_mount_hash_mutex);
304803
diff --git a/modules/parse_amd.c b/modules/parse_amd.c
304803
index fa0f75d..bc056a7 100644
304803
--- a/modules/parse_amd.c
304803
+++ b/modules/parse_amd.c
304803
@@ -978,6 +978,7 @@ static int do_generic_mount(struct autofs_point *ap, const char *name,
304803
 			    struct amd_entry *entry, const char *target,
304803
 			    unsigned int flags)
304803
 {
304803
+	unsigned int umount = 0;
304803
 	int ret = 0;
304803
 
304803
 	if (!entry->sublink) {
304803
@@ -994,9 +995,10 @@ static int do_generic_mount(struct autofs_point *ap, const char *name,
304803
 				       target, entry->type, entry->opts);
304803
 			if (ret)
304803
 				goto out;
304803
+			umount = 1;
304803
 		}
304803
 		/* We might be using an external mount */
304803
-		ext_mount_add(&entry->ext_mount, entry->fs);
304803
+		ext_mount_add(&entry->ext_mount, entry->fs, umount);
304803
 		ret = do_link_mount(ap, name, entry, flags);
304803
 	}
304803
 out:
304803
@@ -1009,6 +1011,7 @@ static int do_nfs_mount(struct autofs_point *ap, const char *name,
304803
 	char target[PATH_MAX + 1];
304803
 	unsigned int proximity;
304803
 	char *opts = entry->opts;
304803
+	unsigned int umount = 0;
304803
 	int ret = 0;
304803
 
304803
 	strcpy(target, entry->rhost);
304803
@@ -1030,9 +1033,10 @@ static int do_nfs_mount(struct autofs_point *ap, const char *name,
304803
 						mount_nfs->context);
304803
 			if (ret)
304803
 				goto out;
304803
+			umount = 1;
304803
 		}
304803
 		/* We might be using an external mount */
304803
-		ext_mount_add(&entry->ext_mount, entry->fs);
304803
+		ext_mount_add(&entry->ext_mount, entry->fs, umount);
304803
 		ret = do_link_mount(ap, name, entry, flags);
304803
 	}
304803
 out: