Blame SOURCES/autofs-5.1.6-use-mnt_list-for-amdmounts.patch

49b67f
autofs-5.1.6 - use mnt_list for amdmounts
49b67f
49b67f
From: Ian Kent <raven@themaw.net>
49b67f
49b67f
Use struct mnt_list objects for the list of amd mounts instead of
49b67f
struct amd_entry.
49b67f
49b67f
Signed-off-by: Ian Kent <raven@themaw.net>
49b67f
---
49b67f
 CHANGELOG              |    1 
49b67f
 daemon/automount.c     |   48 ++++++++++------------
49b67f
 daemon/lookup.c        |   18 +++++---
49b67f
 include/automount.h    |    2 
49b67f
 include/master.h       |    2 
49b67f
 include/mounts.h       |   12 +++++
49b67f
 include/parse_amd.h    |    1 
49b67f
 lib/master.c           |   36 +----------------
49b67f
 lib/mounts.c           |  103 ++++++++++++++++++++++++++++++++++++++++++++++++-
49b67f
 modules/mount_autofs.c |   15 ++++---
49b67f
 modules/parse_amd.c    |   43 +++++++++++++++-----
49b67f
 11 files changed, 193 insertions(+), 88 deletions(-)
49b67f
49b67f
--- autofs-5.1.4.orig/CHANGELOG
49b67f
+++ autofs-5.1.4/CHANGELOG
49b67f
@@ -123,6 +123,7 @@ xx/xx/2018 autofs-5.1.5
49b67f
 - make external mounts use simpler hashtable.
49b67f
 - add a hash index to mnt_list.
49b67f
 - use mnt_list for submounts.
49b67f
+- use mnt_list for amdmounts.
49b67f
 
49b67f
 19/12/2017 autofs-5.1.4
49b67f
 - fix spec file url.
49b67f
--- autofs-5.1.4.orig/daemon/automount.c
49b67f
+++ autofs-5.1.4/daemon/automount.c
49b67f
@@ -595,7 +595,8 @@ static int umount_subtree_mounts(struct
49b67f
 	 * it already to ensure it's ok to remove any offset triggers.
49b67f
 	 */
49b67f
 	if (!is_mm_root && is_mounted(path, MNTS_REAL)) {
49b67f
-		struct amd_entry *entry;
49b67f
+		struct mnt_list *mnt;
49b67f
+
49b67f
 		debug(ap->logopt, "unmounting dir = %s", path);
49b67f
 		if (umount_ent(ap, path) &&
49b67f
 		    is_mounted(path, MNTS_REAL)) {
49b67f
@@ -605,16 +606,12 @@ static int umount_subtree_mounts(struct
49b67f
 		}
49b67f
 
49b67f
 		/* Check for an external mount and umount if possible */
49b67f
-		mounts_mutex_lock(ap);
49b67f
-		entry = __master_find_amdmount(ap, path);
49b67f
-		if (!entry) {
49b67f
-			mounts_mutex_unlock(ap);
49b67f
-			goto done;
49b67f
+		mnt = mnts_find_amdmount(path);
49b67f
+		if (mnt) {
49b67f
+			umount_amd_ext_mount(ap, mnt->ext_mp);
49b67f
+			mnts_remove_amdmount(path);
49b67f
+			mnts_put_mount(mnt);
49b67f
 		}
49b67f
-		list_del(&entry->entries);
49b67f
-		mounts_mutex_unlock(ap);
49b67f
-		umount_amd_ext_mount(ap, entry->fs);
49b67f
-		free_amd_entry(entry);
49b67f
 	}
49b67f
 done:
49b67f
 	return left;
49b67f
@@ -639,7 +636,8 @@ int umount_multi(struct autofs_point *ap
49b67f
 
49b67f
 	/* if this is a symlink we can handle it now */
49b67f
 	if (S_ISLNK(st.st_mode)) {
49b67f
-		struct amd_entry *entry;
49b67f
+		struct mnt_list *mnt;
49b67f
+
49b67f
 		if (st.st_dev != ap->dev) {
49b67f
 			crit(ap->logopt,
49b67f
 			     "symlink %s has the wrong device, "
49b67f
@@ -671,17 +669,15 @@ int umount_multi(struct autofs_point *ap
49b67f
 				     "mkdir_path %s failed: %s", path, estr);
49b67f
 			}
49b67f
 		}
49b67f
+
49b67f
 		/* Check for an external mount and attempt umount if needed */
49b67f
-		mounts_mutex_lock(ap);
49b67f
-		entry = __master_find_amdmount(ap, path);
49b67f
-		if (!entry) {
49b67f
-			mounts_mutex_unlock(ap);
49b67f
-			return 0;
49b67f
-		}
49b67f
-		list_del(&entry->entries);
49b67f
-		mounts_mutex_unlock(ap);
49b67f
-		umount_amd_ext_mount(ap, entry->fs);
49b67f
-		free_amd_entry(entry);
49b67f
+		mnt = mnts_find_amdmount(path);
49b67f
+		if (mnt) {
49b67f
+			umount_amd_ext_mount(ap, mnt->ext_mp);
49b67f
+			mnts_remove_amdmount(path);
49b67f
+			mnts_put_mount(mnt);
49b67f
+		}
49b67f
+
49b67f
 		return 0;
49b67f
 	}
49b67f
 
49b67f
@@ -1720,17 +1716,17 @@ static void handle_mounts_cleanup(void *
49b67f
 		clean = 1;
49b67f
 
49b67f
 	if (submount) {
49b67f
-		struct amd_entry *am;
49b67f
+		struct mnt_list *mnt;
49b67f
 
49b67f
 		/* We are finishing up */
49b67f
 		ap->parent->submnt_count--;
49b67f
 
49b67f
 		/* Submount at ap->path belongs to parent submount list. */
49b67f
 		mnts_remove_submount(ap->path);
49b67f
-		am = __master_find_amdmount(ap->parent, ap->path);
49b67f
-		if (am) {
49b67f
-			list_del_init(&am->entries);
49b67f
-			free_amd_entry(am);
49b67f
+		mnt = mnts_find_amdmount(ap->path);
49b67f
+		if (mnt) {
49b67f
+			mnts_remove_amdmount(ap->path);
49b67f
+			mnts_put_mount(mnt);
49b67f
 		}
49b67f
 	}
49b67f
 
49b67f
--- autofs-5.1.4.orig/daemon/lookup.c
49b67f
+++ autofs-5.1.4/daemon/lookup.c
49b67f
@@ -838,7 +838,7 @@ static int lookup_amd_instance(struct au
49b67f
 			       const char *name, int name_len)
49b67f
 {
49b67f
 	struct map_source *instance;
49b67f
-	struct amd_entry *entry;
49b67f
+	struct mnt_list *mnt;
49b67f
 	const char *argv[2];
49b67f
 	const char **pargv = NULL;
49b67f
 	int argc = 0;
49b67f
@@ -861,21 +861,23 @@ static int lookup_amd_instance(struct au
49b67f
 	strcpy(m_key, ap->path);
49b67f
 	strcat(m_key, "/");
49b67f
 	strcat(m_key, me->multi->key);
49b67f
-	entry = master_find_amdmount(ap, m_key);
49b67f
+
49b67f
+	mnt = mnts_find_amdmount(m_key);
49b67f
 	free(m_key);
49b67f
 
49b67f
-	if (!entry) {
49b67f
+	if (!mnt) {
49b67f
 		error(ap->logopt, "expected amd mount entry not found");
49b67f
 		return NSS_STATUS_UNKNOWN;
49b67f
 	}
49b67f
 
49b67f
-	if (strcmp(entry->type, "host")) {
49b67f
-		error(ap->logopt, "unexpected map type %s", entry->type);
49b67f
+	if (strcmp(mnt->amd_type, "host")) {
49b67f
+		error(ap->logopt, "unexpected map type %s", mnt->amd_type);
49b67f
+		mnts_put_mount(mnt);
49b67f
 		return NSS_STATUS_UNKNOWN;
49b67f
 	}
49b67f
 
49b67f
-	if (entry->opts && *entry->opts) {
49b67f
-		argv[0] = entry->opts;
49b67f
+	if (mnt->amd_opts && *mnt->amd_opts) {
49b67f
+		argv[0] = mnt->amd_opts;
49b67f
 		argv[1] = NULL;
49b67f
 		pargv = argv;
49b67f
 		argc = 1;
49b67f
@@ -894,9 +896,11 @@ static int lookup_amd_instance(struct au
49b67f
 		}
49b67f
 	}
49b67f
 	if (!instance) {
49b67f
+		mnts_put_mount(mnt);
49b67f
 		error(ap->logopt, "expected hosts map instance not found");
49b67f
 		return NSS_STATUS_UNKNOWN;
49b67f
 	}
49b67f
+	mnts_put_mount(mnt);
49b67f
 
49b67f
 	return do_lookup_mount(ap, instance, name, name_len);
49b67f
 }
49b67f
--- autofs-5.1.4.orig/include/automount.h
49b67f
+++ autofs-5.1.4/include/automount.h
49b67f
@@ -568,10 +568,10 @@ struct autofs_point {
49b67f
 	struct autofs_point *parent;	/* Owner of mounts list for submount */
49b67f
 	pthread_mutex_t mounts_mutex;	/* Protect mount lists */
49b67f
 	struct list_head mounts;	/* List of autofs mounts at current level */
49b67f
-	struct list_head amdmounts;	/* List of non submount amd mounts */
49b67f
 	unsigned int submount;		/* Is this a submount */
49b67f
 	unsigned int submnt_count;	/* Number of submounts */
49b67f
 	struct list_head submounts;	/* List of child submounts */
49b67f
+	struct list_head amdmounts;	/* List of non submount amd mounts */
49b67f
 	unsigned int shutdown;		/* Shutdown notification */
49b67f
 };
49b67f
 
49b67f
--- autofs-5.1.4.orig/include/master.h
49b67f
+++ autofs-5.1.4/include/master.h
49b67f
@@ -109,8 +109,6 @@ void master_source_current_wait(struct m
49b67f
 void master_source_current_signal(struct master_mapent *);
49b67f
 struct master_mapent *master_find_mapent(struct master *, const char *);
49b67f
 unsigned int master_partial_match_mapent(struct master *, const char *);
49b67f
-struct amd_entry *__master_find_amdmount(struct autofs_point *, const char *);
49b67f
-struct amd_entry *master_find_amdmount(struct autofs_point *, const char *);
49b67f
 struct master_mapent *master_new_mapent(struct master *, const char *, time_t);
49b67f
 void master_add_mapent(struct master *, struct master_mapent *);
49b67f
 void master_remove_mapent(struct master_mapent *);
49b67f
--- autofs-5.1.4.orig/include/mounts.h
49b67f
+++ autofs-5.1.4/include/mounts.h
49b67f
@@ -38,6 +38,7 @@
49b67f
 #define MNTS_INDIRECT	0x0008
49b67f
 #define MNTS_DIRECT	0x0010
49b67f
 #define MNTS_OFFSET	0x0020
49b67f
+#define MNTS_AMD_MOUNT	0x0040
49b67f
 
49b67f
 #define REMOUNT_SUCCESS		0x0000
49b67f
 #define REMOUNT_FAIL		0x0001
49b67f
@@ -64,6 +65,14 @@ struct mnt_list {
49b67f
 	struct list_head submount;
49b67f
 	struct list_head submount_work;
49b67f
 
49b67f
+	/* List of amd-mounts of an autofs_point */
49b67f
+	char *ext_mp;
49b67f
+	char *amd_pref;
49b67f
+	char *amd_type;
49b67f
+	char *amd_opts;
49b67f
+	unsigned int amd_cache_opts;
49b67f
+	struct list_head amdmount;
49b67f
+
49b67f
 	/*
49b67f
 	 * List operations ie. get_mnt_list.
49b67f
 	 */
49b67f
@@ -118,6 +127,9 @@ struct mnt_list *mnts_add_submount(struc
49b67f
 void mnts_remove_submount(const char *mp);
49b67f
 void mnts_get_submount_list(struct list_head *mnts, struct autofs_point *ap);
49b67f
 void mnts_put_submount_list(struct list_head *mnts);
49b67f
+struct mnt_list *mnts_find_amdmount(const char *path);
49b67f
+struct mnt_list *mnts_add_amdmount(struct autofs_point *ap, struct amd_entry *entry);
49b67f
+void mnts_remove_amdmount(const char *mp);
49b67f
 struct mnt_list *get_mnt_list(const char *path, int include);
49b67f
 int unlink_mount_tree(struct autofs_point *ap, const char *mp);
49b67f
 void free_mnt_list(struct mnt_list *list);
49b67f
--- autofs-5.1.4.orig/include/parse_amd.h
49b67f
+++ autofs-5.1.4/include/parse_amd.h
49b67f
@@ -65,7 +65,6 @@ struct amd_entry {
49b67f
 	char *umount;
49b67f
 	struct selector *selector;
49b67f
 	struct list_head list;
49b67f
-	struct list_head entries;
49b67f
 };
49b67f
 
49b67f
 int amd_parse_list(struct autofs_point *,
49b67f
--- autofs-5.1.4.orig/lib/master.c
49b67f
+++ autofs-5.1.4/lib/master.c
49b67f
@@ -152,12 +152,10 @@ void master_free_autofs_point(struct aut
49b67f
 	head = &ap->amdmounts;
49b67f
 	p = head->next;
49b67f
 	while (p != head) {
49b67f
-		struct amd_entry *entry = list_entry(p, struct amd_entry, entries);
49b67f
+		struct mnt_list *mnt = list_entry(p, struct mnt_list, amdmount);
49b67f
 		p = p->next;
49b67f
-		if (!list_empty(&entry->entries))
49b67f
-			list_del(&entry->entries);
49b67f
-		ext_mount_remove(entry->fs);
49b67f
-		free_amd_entry(entry);
49b67f
+		ext_mount_remove(mnt->ext_mp);
49b67f
+		mnts_remove_amdmount(mnt->mp);
49b67f
 	}
49b67f
 	mounts_mutex_unlock(ap);
49b67f
 
49b67f
@@ -761,34 +759,6 @@ unsigned int master_partial_match_mapent
49b67f
 	return ret;
49b67f
 }
49b67f
 
49b67f
-struct amd_entry *__master_find_amdmount(struct autofs_point *ap, const char *path)
49b67f
-{
49b67f
-	struct list_head *head, *p;
49b67f
-
49b67f
-	head = &ap->amdmounts;
49b67f
-	list_for_each(p, head) {
49b67f
-		struct amd_entry *entry;
49b67f
-
49b67f
-		entry = list_entry(p, struct amd_entry, entries);
49b67f
-
49b67f
-		if (!strcmp(entry->path, path))
49b67f
-			return entry;
49b67f
-	}
49b67f
-
49b67f
-	return NULL;
49b67f
-}
49b67f
-
49b67f
-struct amd_entry *master_find_amdmount(struct autofs_point *ap, const char *path)
49b67f
-{
49b67f
-	struct amd_entry *entry;
49b67f
-
49b67f
-	mounts_mutex_lock(ap);
49b67f
-	entry = __master_find_amdmount(ap, path);
49b67f
-	mounts_mutex_unlock(ap);
49b67f
-
49b67f
-	return entry;
49b67f
-}
49b67f
-
49b67f
 struct master_mapent *master_new_mapent(struct master *master, const char *path, time_t age)
49b67f
 {
49b67f
 	struct master_mapent *entry;
49b67f
--- autofs-5.1.4.orig/lib/mounts.c
49b67f
+++ autofs-5.1.4/lib/mounts.c
49b67f
@@ -546,7 +546,6 @@ struct amd_entry *new_amd_entry(const st
49b67f
 	memset(new, 0, sizeof(*new));
49b67f
 	new->path = path;
49b67f
 	INIT_LIST_HEAD(&new->list);
49b67f
-	INIT_LIST_HEAD(&new->entries);
49b67f
 
49b67f
 	return new;
49b67f
 }
49b67f
@@ -887,6 +886,7 @@ static struct mnt_list *mnts_alloc_mount
49b67f
 	INIT_HLIST_NODE(&this->hash);
49b67f
 	INIT_LIST_HEAD(&this->submount);
49b67f
 	INIT_LIST_HEAD(&this->submount_work);
49b67f
+	INIT_LIST_HEAD(&this->amdmount);
49b67f
 done:
49b67f
 	return this;
49b67f
 }
49b67f
@@ -1048,6 +1048,107 @@ void mnts_put_submount_list(struct list_
49b67f
 	mnts_hash_mutex_unlock();
49b67f
 }
49b67f
 
49b67f
+struct mnt_list *mnts_find_amdmount(const char *path)
49b67f
+{
49b67f
+	struct mnt_list *mnt;
49b67f
+
49b67f
+	mnt = mnts_lookup_mount(path);
49b67f
+	if (mnt && mnt->flags & MNTS_AMD_MOUNT)
49b67f
+		return mnt;
49b67f
+	mnts_put_mount(mnt);
49b67f
+	return NULL;
49b67f
+}
49b67f
+
49b67f
+struct mnt_list *mnts_add_amdmount(struct autofs_point *ap, struct amd_entry *entry)
49b67f
+{
49b67f
+	struct mnt_list *this;
49b67f
+	char *type, *ext_mp, *pref, *opts;
49b67f
+
49b67f
+	ext_mp = pref = type = opts = NULL;
49b67f
+
49b67f
+	if (entry->fs) {
49b67f
+		ext_mp = strdup(entry->fs);
49b67f
+		if (!ext_mp)
49b67f
+			goto fail;
49b67f
+	}
49b67f
+
49b67f
+	if (entry->pref) {
49b67f
+		pref = strdup(entry->pref);
49b67f
+		if (!pref)
49b67f
+			goto fail;
49b67f
+	}
49b67f
+
49b67f
+	if (entry->type) {
49b67f
+		type = strdup(entry->type);
49b67f
+		if (!type)
49b67f
+			goto fail;
49b67f
+	}
49b67f
+
49b67f
+	if (entry->opts) {
49b67f
+		opts = strdup(entry->opts);
49b67f
+		if (!opts)
49b67f
+			goto fail;
49b67f
+	}
49b67f
+
49b67f
+	mnts_hash_mutex_lock();
49b67f
+	this = mnts_get_mount(entry->path);
49b67f
+	if (this) {
49b67f
+		this->ext_mp = ext_mp;
49b67f
+		this->amd_pref = pref;
49b67f
+		this->amd_type = type;
49b67f
+		this->amd_opts = opts;
49b67f
+		this->amd_cache_opts = entry->cache_opts;
49b67f
+		this->flags |= MNTS_AMD_MOUNT;
49b67f
+		if (list_empty(&this->amdmount))
49b67f
+			list_add_tail(&this->amdmount, &ap->amdmounts);
49b67f
+	}
49b67f
+	mnts_hash_mutex_unlock();
49b67f
+
49b67f
+	return this;
49b67f
+fail:
49b67f
+	if (ext_mp)
49b67f
+		free(ext_mp);
49b67f
+	if (pref)
49b67f
+		free(pref);
49b67f
+	if (type)
49b67f
+		free(type);
49b67f
+	if (opts)
49b67f
+		free(opts);
49b67f
+	return NULL;
49b67f
+}
49b67f
+
49b67f
+void mnts_remove_amdmount(const char *mp)
49b67f
+{
49b67f
+	struct mnt_list *this;
49b67f
+
49b67f
+	mnts_hash_mutex_lock();
49b67f
+	this = mnts_lookup(mp);
49b67f
+	if (!(this && this->flags & MNTS_AMD_MOUNT))
49b67f
+		goto done;
49b67f
+	this->flags &= ~MNTS_AMD_MOUNT;
49b67f
+	list_del_init(&this->submount);
49b67f
+	if (this->ext_mp) {
49b67f
+		free(this->ext_mp);
49b67f
+		this->ext_mp = NULL;
49b67f
+	}
49b67f
+	if (this->amd_type) {
49b67f
+		free(this->amd_type);
49b67f
+		this->amd_type = NULL;
49b67f
+	}
49b67f
+	if (this->amd_pref) {
49b67f
+		free(this->amd_pref);
49b67f
+		this->amd_pref = NULL;
49b67f
+	}
49b67f
+	if (this->amd_opts) {
49b67f
+		free(this->amd_opts);
49b67f
+		this->amd_opts = NULL;
49b67f
+	}
49b67f
+	this->amd_cache_opts = 0;
49b67f
+	__mnts_put_mount(this);
49b67f
+done:
49b67f
+	mnts_hash_mutex_unlock();
49b67f
+}
49b67f
+
49b67f
 /* From glibc decode_name() */
49b67f
 /* Since the values in a line are separated by spaces, a name cannot
49b67f
  * contain a space.  Therefore some programs encode spaces in names
49b67f
--- autofs-5.1.4.orig/modules/mount_autofs.c
49b67f
+++ autofs-5.1.4/modules/mount_autofs.c
49b67f
@@ -286,16 +286,19 @@ int mount_mount(struct autofs_point *ap,
49b67f
 	mounts_mutex_lock(ap);
49b67f
 
49b67f
 	if (source->flags & MAP_FLAG_FORMAT_AMD) {
49b67f
-		struct amd_entry *am_entry = __master_find_amdmount(ap, entry->path);
49b67f
+		struct mnt_list *mnt;
49b67f
 
49b67f
-		if (am_entry) {
49b67f
-			if (am_entry->pref) {
49b67f
-				nap->pref = am_entry->pref;
49b67f
-				am_entry->pref = NULL;
49b67f
+		mnt = mnts_find_amdmount(entry->path);
49b67f
+		if (mnt) {
49b67f
+			if (mnt->amd_pref) {
49b67f
+				nap->pref = mnt->amd_pref;
49b67f
+				mnt->amd_pref = NULL;
49b67f
 			}
49b67f
 
49b67f
-			if (am_entry->cache_opts & AMD_CACHE_OPTION_ALL)
49b67f
+			if (mnt->amd_cache_opts & AMD_CACHE_OPTION_ALL)
49b67f
 				nap->flags |= MOUNT_FLAG_AMD_CACHE_ALL;
49b67f
+
49b67f
+			mnts_put_mount(mnt);
49b67f
 		}
49b67f
 	}
49b67f
 
49b67f
--- autofs-5.1.4.orig/modules/parse_amd.c
49b67f
+++ autofs-5.1.4/modules/parse_amd.c
49b67f
@@ -1300,6 +1300,7 @@ static int do_host_mount(struct autofs_p
49b67f
 {
49b67f
 	struct lookup_mod *lookup;
49b67f
 	struct map_source *instance;
49b67f
+	struct mnt_list *mnt = NULL;
49b67f
 	struct mapent *me;
49b67f
 	const char *argv[2];
49b67f
 	const char **pargv = NULL;
49b67f
@@ -1316,7 +1317,9 @@ static int do_host_mount(struct autofs_p
49b67f
 	 */
49b67f
 	if (strcmp(name, entry->rhost)) {
49b67f
 		char *target;
49b67f
-		size_t len = strlen(ap->path) + strlen(entry->rhost) + 2;
49b67f
+		size_t len;
49b67f
+
49b67f
+		len = strlen(ap->path) + strlen(entry->rhost) + 2;
49b67f
 		target = malloc(len);
49b67f
 		if (!target) {
49b67f
 			warn(ap->logopt, MODPREFIX
49b67f
@@ -1329,6 +1332,15 @@ static int do_host_mount(struct autofs_p
49b67f
 		if (entry->path)
49b67f
 			free(entry->path);
49b67f
 		entry->path = target;
49b67f
+
49b67f
+		/* Add an mnt_list entry for the updated path. */
49b67f
+		mnt = mnts_add_amdmount(ap, entry);
49b67f
+		if (!mnt) {
49b67f
+			error(ap->logopt, MODPREFIX
49b67f
+			      "failed to update mount mnt_list entry");
49b67f
+			goto out;
49b67f
+		}
49b67f
+
49b67f
 		/*
49b67f
 		 * Wait for any expire before racing to mount the
49b67f
 		 * export tree or bail out if we're shutting down.
49b67f
@@ -1388,6 +1400,8 @@ static int do_host_mount(struct autofs_p
49b67f
 		warn(ap->logopt, MODPREFIX
49b67f
 		     "failed to create symlink to hosts mount base");
49b67f
 out:
49b67f
+	if (ret && mnt)
49b67f
+		mnts_remove_amdmount(mnt->mp);
49b67f
 	return ret;
49b67f
 }
49b67f
 
49b67f
@@ -2204,6 +2218,7 @@ int parse_mount(struct autofs_point *ap,
49b67f
 	struct list_head entries, *p, *head;
49b67f
 	struct amd_entry *defaults_entry;
49b67f
 	struct amd_entry *cur_defaults;
49b67f
+	struct mnt_list *mnt;
49b67f
 	int rv = 1;
49b67f
 	int cur_state;
49b67f
 	int ret;
49b67f
@@ -2313,21 +2328,27 @@ int parse_mount(struct autofs_point *ap,
49b67f
 		 * add parsed entry to parent amd mount list and remove
49b67f
 		 * on mount fail.
49b67f
 		 */
49b67f
-		mounts_mutex_lock(ap);
49b67f
-		list_add_tail(&this->entries, &ap->amdmounts);
49b67f
-		mounts_mutex_unlock(ap);
49b67f
+		mnt = mnts_add_amdmount(ap, this);
49b67f
+		if (!mnt) {
49b67f
+			error(ap->logopt, MODPREFIX
49b67f
+			      "failed to add mount to mnt_list");
49b67f
+			break;
49b67f
+		}
49b67f
 
49b67f
 		rv = amd_mount(ap, name, this, source, sv, flags, ctxt);
49b67f
-		mounts_mutex_lock(ap);
49b67f
 		if (!rv) {
49b67f
-			/* Mounted, remove entry from parsed list */
49b67f
-			list_del_init(&this->list);
49b67f
-			mounts_mutex_unlock(ap);
49b67f
+			/*
49b67f
+			 * If entry->path doesn't match the mnt->mp then
49b67f
+			 * the mount point path has changed and a new
49b67f
+			 * mnt_list entry added for it, so remove the
49b67f
+			 * original.
49b67f
+			 */
49b67f
+			if (strcmp(this->path, mnt->mp))
49b67f
+				mnts_remove_amdmount(this->path);
49b67f
 			break;
49b67f
 		}
49b67f
-		/* Not mounted, remove entry from the parent list */
49b67f
-		list_del_init(&this->entries);
49b67f
-		mounts_mutex_unlock(ap);
49b67f
+		/* Not mounted, remove the mnt_list entry from amdmount list */
49b67f
+		mnts_remove_amdmount(this->path);
49b67f
 	}
49b67f
 	free_amd_entry(cur_defaults);
49b67f