Blob Blame History Raw
autofs-5.1.5 - always use PROC_MOUNTS to make mount lists

From: Ian Kent <raven@themaw.net>

If it's necessary to read a mount table then always use the proc file
system mount table.

This could be very inefficient for cases where the mtab (_PATH_MOUNTED)
is specified but the mtab has been a symlink to the proc mount tables
for quite a while now so it doesn't make any difference always using
the proc tables.

Signed-off-by: Ian Kent <raven@themaw.net>
---
 CHANGELOG           |    1 +
 daemon/automount.c  |    6 +++---
 daemon/direct.c     |   14 +++++++-------
 daemon/indirect.c   |    8 ++++----
 daemon/lookup.c     |    4 ++--
 daemon/spawn.c      |    2 +-
 daemon/state.c      |    2 +-
 include/mounts.h    |    6 +++---
 lib/mounts.c        |   32 ++++++++++++++++----------------
 modules/parse_amd.c |    4 ++--
 10 files changed, 40 insertions(+), 39 deletions(-)

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