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

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