Blame SOURCES/autofs-5.1.5-always-use-PROC_MOUNTS-to-make-mount-lists.patch

304803
autofs-5.1.5 - always use PROC_MOUNTS to make mount lists
304803
304803
From: Ian Kent <raven@themaw.net>
304803
304803
If it's necessary to read a mount table then always use the proc file
304803
system mount table.
304803
304803
This could be very inefficient for cases where the mtab (_PATH_MOUNTED)
304803
is specified but the mtab has been a symlink to the proc mount tables
304803
for quite a while now so it doesn't make any difference always using
304803
the proc tables.
304803
304803
Signed-off-by: Ian Kent <raven@themaw.net>
304803
---
304803
 CHANGELOG           |    1 +
304803
 daemon/automount.c  |    6 +++---
304803
 daemon/direct.c     |   14 +++++++-------
304803
 daemon/indirect.c   |    8 ++++----
304803
 daemon/lookup.c     |    4 ++--
304803
 daemon/spawn.c      |    2 +-
304803
 daemon/state.c      |    2 +-
304803
 include/mounts.h    |    6 +++---
304803
 lib/mounts.c        |   32 ++++++++++++++++----------------
304803
 modules/parse_amd.c |    4 ++--
304803
 10 files changed, 40 insertions(+), 39 deletions(-)
304803
304803
--- autofs-5.0.7.orig/CHANGELOG
304803
+++ autofs-5.0.7/CHANGELOG
304803
@@ -339,6 +339,7 @@
304803
 - add config option for "ignore" mount option
304803
 - use bit flags for autofs mount types in mnt_list.
304803
 - use mp instead of path in mnt_list entries.
304803
+- always use PROC_MOUNTS to make mount lists.
304803
 
304803
 25/07/2012 autofs-5.0.7
304803
 =======================
304803
--- autofs-5.0.7.orig/daemon/automount.c
304803
+++ autofs-5.0.7/daemon/automount.c
304803
@@ -331,7 +331,7 @@ static int walk_tree(const char *base, i
304803
 	struct stat st, *pst = &st;
304803
 	int ret;
304803
 
304803
-	if (!is_mounted(_PATH_MOUNTED, base, MNTS_REAL))
304803
+	if (!is_mounted(base, MNTS_REAL))
304803
 		ret = lstat(base, pst);
304803
 	else {
304803
 		pst = NULL;
304803
@@ -595,11 +595,11 @@ static int umount_subtree_mounts(struct
304803
 	 * If this is the root of a multi-mount we've had to umount
304803
 	 * it already to ensure it's ok to remove any offset triggers.
304803
 	 */
304803
-	if (!is_mm_root && is_mounted(_PATH_MOUNTED, path, MNTS_REAL)) {
304803
+	if (!is_mm_root && is_mounted(path, MNTS_REAL)) {
304803
 		struct amd_entry *entry;
304803
 		debug(ap->logopt, "unmounting dir = %s", path);
304803
 		if (umount_ent(ap, path) &&
304803
-		    is_mounted(_PATH_MOUNTED, path, MNTS_REAL)) {
304803
+		    is_mounted(path, MNTS_REAL)) {
304803
 			warn(ap->logopt, "could not umount dir %s", path);
304803
 			left++;
304803
 			goto done;
304803
--- autofs-5.0.7.orig/daemon/direct.c
304803
+++ autofs-5.0.7/daemon/direct.c
304803
@@ -207,7 +207,7 @@ int umount_autofs_direct(struct autofs_p
304803
 	struct mnt_list *mnts;
304803
 	struct mapent *me, *ne;
304803
 
304803
-	mnts = tree_make_mnt_tree(_PROC_MOUNTS, "/");
304803
+	mnts = tree_make_mnt_tree("/");
304803
 	pthread_cleanup_push(mnts_cleanup, mnts);
304803
 	nc = ap->entry->master->nc;
304803
 	cache_readlock(nc);
304803
@@ -521,7 +521,7 @@ int mount_autofs_direct(struct autofs_po
304803
 		return -1;
304803
 	}
304803
 
304803
-	mnts = tree_make_mnt_tree(_PROC_MOUNTS, "/");
304803
+	mnts = tree_make_mnt_tree("/");
304803
 	pthread_cleanup_push(mnts_cleanup, mnts);
304803
 	pthread_cleanup_push(master_source_lock_cleanup, ap->entry);
304803
 	master_source_readlock(ap->entry);
304803
@@ -589,7 +589,7 @@ int umount_autofs_offset(struct autofs_p
304803
 	int opened = 0;
304803
 
304803
 	if (me->ioctlfd != -1) {
304803
-		if (is_mounted(_PATH_MOUNTED, me->key, MNTS_REAL)) {
304803
+		if (is_mounted(me->key, MNTS_REAL)) {
304803
 			error(ap->logopt,
304803
 			      "attempt to umount busy offset %s", me->key);
304803
 			return 1;
304803
@@ -597,7 +597,7 @@ int umount_autofs_offset(struct autofs_p
304803
 		ioctlfd = me->ioctlfd;
304803
 	} else {
304803
 		/* offset isn't mounted, return success and try to recover */
304803
-		if (!is_mounted(_PROC_MOUNTS, me->key, MNTS_AUTOFS)) {
304803
+		if (!is_mounted(me->key, MNTS_AUTOFS)) {
304803
 			debug(ap->logopt,
304803
 			      "offset %s not mounted",
304803
 			      me->key);
304803
@@ -713,7 +713,7 @@ int mount_autofs_offset(struct autofs_po
304803
 		if (!(ret == -1 && errno == ENOENT))
304803
 			return MOUNT_OFFSET_FAIL;
304803
 	} else {
304803
-		if (is_mounted(_PROC_MOUNTS, me->key, MNTS_AUTOFS)) {
304803
+		if (is_mounted(me->key, MNTS_AUTOFS)) {
304803
 			if (ap->state != ST_READMAP)
304803
 				warn(ap->logopt,
304803
 				     "trigger %s already mounted", me->key);
304803
@@ -767,7 +767,7 @@ int mount_autofs_offset(struct autofs_po
304803
 			 * the kernel NFS client.
304803
 			 */
304803
 			if (me->multi != me &&
304803
-			    is_mounted(_PROC_MOUNTS, mountpoint, MNTS_REAL))
304803
+			    is_mounted(mountpoint, MNTS_REAL))
304803
 				return MOUNT_OFFSET_IGNORE;
304803
 
304803
 			/* 
304803
@@ -887,7 +887,7 @@ void *expire_proc_direct(void *arg)
304803
 
304803
 	left = 0;
304803
 
304803
-	mnts = tree_make_mnt_tree(_PROC_MOUNTS, "/");
304803
+	mnts = tree_make_mnt_tree("/");
304803
 	pthread_cleanup_push(mnts_cleanup, mnts);
304803
 
304803
 	/* Get a list of mounts select real ones and expire them if possible */
304803
--- autofs-5.0.7.orig/daemon/indirect.c
304803
+++ autofs-5.0.7/daemon/indirect.c
304803
@@ -103,7 +103,7 @@ static int do_mount_autofs_indirect(stru
304803
 		if (ret == 0)
304803
 			return -1;
304803
 	} else {
304803
-		mnts = get_mnt_list(_PROC_MOUNTS, ap->path, 1);
304803
+		mnts = get_mnt_list(ap->path, 1);
304803
 		if (mnts) {
304803
 			ret = unlink_mount_tree(ap, mnts);
304803
 			free_mnt_list(mnts);
304803
@@ -429,7 +429,7 @@ void *expire_proc_indirect(void *arg)
304803
 	left = 0;
304803
 
304803
 	/* Get a list of real mounts and expire them if possible */
304803
-	mnts = get_mnt_list(_PROC_MOUNTS, ap->path, 0);
304803
+	mnts = get_mnt_list(ap->path, 0);
304803
 	pthread_cleanup_push(mnts_cleanup, mnts);
304803
 	for (next = mnts; next; next = next->next) {
304803
 		char *ind_key;
304803
@@ -450,7 +450,7 @@ void *expire_proc_indirect(void *arg)
304803
 				struct stat st;
304803
 
304803
 				/* It's got a mount, deal with in the outer loop */
304803
-				if (is_mounted(_PATH_MOUNTED, next->mp, MNTS_REAL)) {
304803
+				if (is_mounted(next->mp, MNTS_REAL)) {
304803
 					pthread_setcancelstate(cur_state, NULL);
304803
 					continue;
304803
 				}
304803
@@ -559,7 +559,7 @@ void *expire_proc_indirect(void *arg)
304803
 	pthread_cleanup_pop(1);
304803
 
304803
 	count = offsets = submnts = 0;
304803
-	mnts = get_mnt_list(_PROC_MOUNTS, ap->path, 0);
304803
+	mnts = get_mnt_list(ap->path, 0);
304803
 	pthread_cleanup_push(mnts_cleanup, mnts);
304803
 	/* Are there any real mounts left */
304803
 	for (next = mnts; next; next = next->next) {
304803
--- autofs-5.0.7.orig/daemon/lookup.c
304803
+++ autofs-5.0.7/daemon/lookup.c
304803
@@ -1419,7 +1419,7 @@ void lookup_prune_one_cache(struct autof
304803
 			valid = NULL;
304803
 		}
304803
 		if (!valid &&
304803
-		    is_mounted(_PATH_MOUNTED, path, MNTS_REAL)) {
304803
+		    is_mounted(path, MNTS_REAL)) {
304803
 			debug(ap->logopt, "prune posponed, %s mounted", path);
304803
 			free(key);
304803
 			free(path);
304803
@@ -1442,7 +1442,7 @@ void lookup_prune_one_cache(struct autof
304803
 
304803
 		if (valid)
304803
 			cache_delete(mc, key);
304803
-		else if (!is_mounted(_PROC_MOUNTS, path, MNTS_AUTOFS)) {
304803
+		else if (!is_mounted(path, MNTS_AUTOFS)) {
304803
 			dev_t devid = ap->dev;
304803
 			status = CHE_FAIL;
304803
 			if (ap->type == LKP_DIRECT)
304803
--- autofs-5.0.7.orig/daemon/spawn.c
304803
+++ autofs-5.0.7/daemon/spawn.c
304803
@@ -406,7 +406,7 @@ static int do_spawn(unsigned logopt, uns
304803
 			if (!is_bind)
304803
 				goto done;
304803
 
304803
-			if (is_mounted(_PROC_MOUNTS, argv[loc], MNTS_AUTOFS)) {
304803
+			if (is_mounted(argv[loc], MNTS_AUTOFS)) {
304803
 				fprintf(stderr,
304803
 				     "error: can't bind to an autofs mount\n");
304803
 				close(STDOUT_FILENO);
304803
--- autofs-5.0.7.orig/daemon/state.c
304803
+++ autofs-5.0.7/daemon/state.c
304803
@@ -499,7 +499,7 @@ static void *do_readmap(void *arg)
304803
 		struct mapent *me;
304803
 		unsigned int append_alarm = !ap->exp_runfreq;
304803
 
304803
-		mnts = tree_make_mnt_tree(_PROC_MOUNTS, "/");
304803
+		mnts = tree_make_mnt_tree("/");
304803
 		pthread_cleanup_push(tree_mnts_cleanup, mnts);
304803
 		nc = ap->entry->master->nc;
304803
 		cache_readlock(nc);
304803
--- autofs-5.0.7.orig/include/mounts.h
304803
+++ autofs-5.0.7/include/mounts.h
304803
@@ -99,11 +99,11 @@ char *make_mnt_name_string(char *path);
304803
 int ext_mount_add(struct list_head *, const char *, unsigned int);
304803
 int ext_mount_remove(struct list_head *, const char *);
304803
 int ext_mount_inuse(const char *);
304803
-struct mnt_list *get_mnt_list(const char *table, const char *path, int include);
304803
+struct mnt_list *get_mnt_list(const char *path, int include);
304803
 void free_mnt_list(struct mnt_list *list);
304803
-int is_mounted(const char *table, const char *mp, unsigned int type);
304803
+int is_mounted(const char *mp, unsigned int type);
304803
 void tree_free_mnt_tree(struct mnt_list *tree);
304803
-struct mnt_list *tree_make_mnt_tree(const char *table, const char *path);
304803
+struct mnt_list *tree_make_mnt_tree(const char *path);
304803
 int tree_get_mnt_list(struct mnt_list *mnts, struct list_head *list, const char *path, int include);
304803
 int tree_get_mnt_sublist(struct mnt_list *mnts, struct list_head *list, const char *path, int include);
304803
 int tree_find_mnt_ents(struct mnt_list *mnts, struct list_head *list, const char *path);
304803
--- autofs-5.0.7.orig/lib/mounts.c
304803
+++ autofs-5.0.7/lib/mounts.c
304803
@@ -790,7 +790,7 @@ done:
304803
 /*
304803
  * Get list of mounts under path in longest->shortest order
304803
  */
304803
-struct mnt_list *get_mnt_list(const char *table, const char *path, int include)
304803
+struct mnt_list *get_mnt_list(const char *path, int include)
304803
 {
304803
 	FILE *tab;
304803
 	size_t pathlen = strlen(path);
304803
@@ -804,7 +804,7 @@ struct mnt_list *get_mnt_list(const char
304803
 	if (!path || !pathlen || pathlen > PATH_MAX)
304803
 		return NULL;
304803
 
304803
-	tab = open_setmntent_r(table);
304803
+	tab = open_setmntent_r(_PROC_MOUNTS);
304803
 	if (!tab) {
304803
 		char *estr = strerror_r(errno, buf, PATH_MAX - 1);
304803
 		logerr("setmntent: %s", estr);
304803
@@ -893,7 +893,7 @@ void free_mnt_list(struct mnt_list *list
304803
 	}
304803
 }
304803
 
304803
-static int table_is_mounted(const char *table, const char *mp, unsigned int type)
304803
+static int table_is_mounted(const char *mp, unsigned int type)
304803
 {
304803
 	struct mntent *mnt;
304803
 	struct mntent mnt_wrk;
304803
@@ -905,7 +905,7 @@ static int table_is_mounted(const char *
304803
 	if (!mp || !mp_len || mp_len >= PATH_MAX)
304803
 		return 0;
304803
 
304803
-	tab = open_setmntent_r(table);
304803
+	tab = open_setmntent_r(_PROC_MOUNTS);
304803
 	if (!tab) {
304803
 		char *estr = strerror_r(errno, buf, PATH_MAX - 1);
304803
 		logerr("setmntent: %s", estr);
304803
@@ -958,14 +958,14 @@ static int ioctl_is_mounted(const char *
304803
 	return 0;
304803
 }
304803
 
304803
-int is_mounted(const char *table, const char *mp, unsigned int type)
304803
+int is_mounted(const char *mp, unsigned int type)
304803
 {
304803
 	struct ioctl_ops *ops = get_ioctl_ops();
304803
 
304803
 	if (ops->ismountpoint)
304803
 		return ioctl_is_mounted(mp, type);
304803
 	else
304803
-		return table_is_mounted(table, mp, type);
304803
+		return table_is_mounted(mp, type);
304803
 }
304803
 
304803
 /*
304803
@@ -1012,7 +1012,7 @@ void tree_free_mnt_tree(struct mnt_list
304803
 /*
304803
  * Make tree of system mounts in /proc/mounts.
304803
  */
304803
-struct mnt_list *tree_make_mnt_tree(const char *table, const char *path)
304803
+struct mnt_list *tree_make_mnt_tree(const char *path)
304803
 {
304803
 	FILE *tab;
304803
 	struct mntent mnt_wrk;
304803
@@ -1023,7 +1023,7 @@ struct mnt_list *tree_make_mnt_tree(cons
304803
 	size_t plen;
304803
 	int eq;
304803
 
304803
-	tab = open_setmntent_r(table);
304803
+	tab = open_setmntent_r(_PROC_MOUNTS);
304803
 	if (!tab) {
304803
 		char *estr = strerror_r(errno, buf, PATH_MAX - 1);
304803
 		logerr("setmntent: %s", estr);
304803
@@ -1851,7 +1851,7 @@ void set_indirect_mount_tree_catatonic(s
304803
 	struct mapent_cache *mc;
304803
 	struct mapent *me;
304803
 
304803
-	if (!is_mounted(_PROC_MOUNTS, ap->path, MNTS_AUTOFS))
304803
+	if (!is_mounted(ap->path, MNTS_AUTOFS))
304803
 		return;
304803
 
304803
 	map = entry->maps;
304803
@@ -1915,7 +1915,7 @@ int umount_ent(struct autofs_point *ap,
304803
 		 * so that we do not try to call rmdir_path on the
304803
 		 * directory.
304803
 		 */
304803
-		if (!rv && is_mounted(_PATH_MOUNTED, path, MNTS_REAL)) {
304803
+		if (!rv && is_mounted(path, MNTS_REAL)) {
304803
 			crit(ap->logopt,
304803
 			     "the umount binary reported that %s was "
304803
 			     "unmounted, but there is still something "
304803
@@ -2048,7 +2048,7 @@ int mount_multi_triggers(struct autofs_p
304803
 		 */
304803
 		if (ap->state == ST_READMAP && ap->flags & MOUNT_FLAG_REMOUNT) {
304803
 			if (oe->ioctlfd != -1 ||
304803
-			    is_mounted(_PROC_MOUNTS, oe->key, MNTS_REAL)) {
304803
+			    is_mounted(oe->key, MNTS_REAL)) {
304803
 				char oe_root[PATH_MAX + 1];
304803
 				strcpy(oe_root, root);
304803
 				strcat(oe_root, offset); 
304803
@@ -2137,7 +2137,7 @@ int umount_multi_triggers(struct autofs_
304803
 		left += umount_multi_triggers(ap, oe, root, oe_base);
304803
 
304803
 		if (oe->ioctlfd != -1 ||
304803
-		    is_mounted(_PROC_MOUNTS, oe->key, MNTS_REAL)) {
304803
+		    is_mounted(oe->key, MNTS_REAL)) {
304803
 			left++;
304803
 			continue;
304803
 		}
304803
@@ -2180,10 +2180,10 @@ int umount_multi_triggers(struct autofs_
304803
 		 * delete the offsets from the cache and we need to put
304803
 		 * the offset triggers back.
304803
 		 */
304803
-		if (is_mounted(_PATH_MOUNTED, root, MNTS_REAL)) {
304803
+		if (is_mounted(root, MNTS_REAL)) {
304803
 			info(ap->logopt, "unmounting dir = %s", root);
304803
 			if (umount_ent(ap, root) &&
304803
-			    is_mounted(_PATH_MOUNTED, root, MNTS_REAL)) {
304803
+			    is_mounted(root, MNTS_REAL)) {
304803
 				if (mount_multi_triggers(ap, me, root, strlen(root), "/") < 0)
304803
 					warn(ap->logopt,
304803
 					     "failed to remount offset triggers");
304803
@@ -2283,9 +2283,9 @@ int clean_stale_multi_triggers(struct au
304803
 		 * ESTALE errors when attempting list the directory.
304803
 		 */
304803
 		if (oe->ioctlfd != -1 ||
304803
-		    is_mounted(_PROC_MOUNTS, oe->key, MNTS_REAL)) {
304803
+		    is_mounted(oe->key, MNTS_REAL)) {
304803
 			if (umount_ent(ap, oe->key) &&
304803
-			    is_mounted(_PROC_MOUNTS, oe->key, MNTS_REAL)) {
304803
+			    is_mounted(oe->key, MNTS_REAL)) {
304803
 				debug(ap->logopt,
304803
 				      "offset %s has active mount, invalidate",
304803
 				      oe->key);
304803
--- autofs-5.0.7.orig/modules/parse_amd.c
304803
+++ autofs-5.0.7/modules/parse_amd.c
304803
@@ -1175,7 +1175,7 @@ static int do_generic_mount(struct autof
304803
 		 * multiple times since they are outside of
304803
 		 * the automount filesystem.
304803
 		 */
304803
-		if (!is_mounted(_PATH_MOUNTED, entry->fs, MNTS_REAL)) {
304803
+		if (!is_mounted(entry->fs, MNTS_REAL)) {
304803
 			ret = do_mount(ap, entry->fs, "/", 1,
304803
 				       target, entry->type, opts);
304803
 			if (ret)
304803
@@ -1218,7 +1218,7 @@ static int do_nfs_mount(struct autofs_po
304803
 					     target, entry->type, opts,
304803
 					     mount_nfs->context);
304803
 	} else {
304803
-		if (!is_mounted(_PATH_MOUNTED, entry->fs, MNTS_REAL)) {
304803
+		if (!is_mounted(entry->fs, MNTS_REAL)) {
304803
 			ret = mount_nfs->mount_mount(ap, entry->fs, "/", 1,
304803
 						target, entry->type, opts,
304803
 						mount_nfs->context);