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

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