From 741304503a28fc51a6c0a14a0f3c1c88cc825979 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Mon, 13 Jan 2014 13:02:59 -0800 Subject: [PATCH] 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 Signed-off-by: Michael Martin Closes #2041 --- lib/libzfs/libzfs_dataset.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/libzfs/libzfs_dataset.c b/lib/libzfs/libzfs_dataset.c index 90b6572b15..0acfa7923d 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); }