]> granicus.if.org Git - zfs/commitdiff
Prevent duplicate mnttab cache entries
authorBrian Behlendorf <behlendorf1@llnl.gov>
Mon, 13 Jan 2014 21:02:59 +0000 (13:02 -0800)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Tue, 14 Jan 2014 18:27:12 +0000 (10:27 -0800)
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 <behlendorf1@llnl.gov>
Signed-off-by: Michael Martin <mgmartin.mgm@gmail.com>
Closes #2041

lib/libzfs/libzfs_dataset.c

index 90b6572b15c0a4c5855e5bc80830a441d6c652e4..0acfa7923d0a035069c0f39c0d2bf20ff9e7c52f 100644 (file)
@@ -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);
        }