summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBrian Behlendorf <[email protected]>2014-01-13 13:02:59 -0800
committerBrian Behlendorf <[email protected]>2014-01-14 10:27:12 -0800
commit741304503a28fc51a6c0a14a0f3c1c88cc825979 (patch)
treebf8a14489f05b8bd8df9471fea1799bdd49e08f4 /lib
parentfd23720ae14dca926800ae70e6c8f4b4f82efc08 (diff)
Prevent duplicate mnttab cache entries
Under Linux its possible to mount the same filesystem multiple times in the namespace. This can be done either with bind mounts or simply with multiple mount points. Unfortunately, the mnttab cache code is implemented using an AVL tree which does not support duplicate entries. To avoid this issue this patch updates the code to check for a duplicate entry before adding a new one. Signed-off-by: Brian Behlendorf <[email protected]> Signed-off-by: Michael Martin <[email protected]> Closes #2041
Diffstat (limited to 'lib')
-rw-r--r--lib/libzfs/libzfs_dataset.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c
index 90b6572b1..0acfa7923 100644
--- a/lib/libzfs/libzfs_dataset.c
+++ b/lib/libzfs/libzfs_dataset.c
@@ -640,14 +640,27 @@ libzfs_mnttab_update(libzfs_handle_t *hdl)
while (getmntent(hdl->libzfs_mnttab, &entry) == 0) {
mnttab_node_t *mtn;
+ avl_index_t where;
if (strcmp(entry.mnt_fstype, MNTTYPE_ZFS) != 0)
continue;
+
mtn = zfs_alloc(hdl, sizeof (mnttab_node_t));
mtn->mtn_mt.mnt_special = zfs_strdup(hdl, entry.mnt_special);
mtn->mtn_mt.mnt_mountp = zfs_strdup(hdl, entry.mnt_mountp);
mtn->mtn_mt.mnt_fstype = zfs_strdup(hdl, entry.mnt_fstype);
mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, entry.mnt_mntopts);
+
+ /* Exclude duplicate mounts */
+ if (avl_find(&hdl->libzfs_mnttab_cache, mtn, &where) != NULL) {
+ free(mtn->mtn_mt.mnt_special);
+ free(mtn->mtn_mt.mnt_mountp);
+ free(mtn->mtn_mt.mnt_fstype);
+ free(mtn->mtn_mt.mnt_mntopts);
+ free(mtn);
+ continue;
+ }
+
avl_add(&hdl->libzfs_mnttab_cache, mtn);
}