Print this page
8115 parallel zfs mount

@@ -52,10 +52,11 @@
 #include <stddef.h>
 #include <ucred.h>
 #include <idmap.h>
 #include <aclutils.h>
 #include <directory.h>
+#include <time.h>
 
 #include <sys/dnode.h>
 #include <sys/spa.h>
 #include <sys/zap.h>
 #include <libzfs.h>

@@ -783,10 +784,11 @@
 }
 
 void
 libzfs_mnttab_init(libzfs_handle_t *hdl)
 {
+        (void) mutex_init(&hdl->libzfs_mnttab_cache_lock, USYNC_THREAD, NULL);
         assert(avl_numnodes(&hdl->libzfs_mnttab_cache) == 0);
         avl_create(&hdl->libzfs_mnttab_cache, libzfs_mnttab_cache_compare,
             sizeof (mnttab_node_t), offsetof(mnttab_node_t, mtn_node));
 }
 

@@ -823,10 +825,11 @@
                 free(mtn->mtn_mt.mnt_fstype);
                 free(mtn->mtn_mt.mnt_mntopts);
                 free(mtn);
         }
         avl_destroy(&hdl->libzfs_mnttab_cache);
+        (void) mutex_destroy(&hdl->libzfs_mnttab_cache_lock);
 }
 
 void
 libzfs_mnttab_cache(libzfs_handle_t *hdl, boolean_t enable)
 {

@@ -837,10 +840,11 @@
 libzfs_mnttab_find(libzfs_handle_t *hdl, const char *fsname,
     struct mnttab *entry)
 {
         mnttab_node_t find;
         mnttab_node_t *mtn;
+        int ret = ENOENT;
 
         if (!hdl->libzfs_mnttab_enable) {
                 struct mnttab srch = { 0 };
 
                 if (avl_numnodes(&hdl->libzfs_mnttab_cache))

@@ -847,49 +851,53 @@
                         libzfs_mnttab_fini(hdl);
                 rewind(hdl->libzfs_mnttab);
                 srch.mnt_special = (char *)fsname;
                 srch.mnt_fstype = MNTTYPE_ZFS;
                 if (getmntany(hdl->libzfs_mnttab, entry, &srch) == 0)
-                        return (0);
-                else
-                        return (ENOENT);
+                        ret = 0;
+                return (ret);
         }
 
+        (void) mutex_lock(&hdl->libzfs_mnttab_cache_lock);
         if (avl_numnodes(&hdl->libzfs_mnttab_cache) == 0)
                 libzfs_mnttab_update(hdl);
 
         find.mtn_mt.mnt_special = (char *)fsname;
         mtn = avl_find(&hdl->libzfs_mnttab_cache, &find, NULL);
         if (mtn) {
                 *entry = mtn->mtn_mt;
-                return (0);
+                ret = 0;
         }
-        return (ENOENT);
+        (void) mutex_unlock(&hdl->libzfs_mnttab_cache_lock);
+        return (ret);
 }
 
 void
 libzfs_mnttab_add(libzfs_handle_t *hdl, const char *special,
     const char *mountp, const char *mntopts)
 {
         mnttab_node_t *mtn;
 
-        if (avl_numnodes(&hdl->libzfs_mnttab_cache) == 0)
-                return;
+        (void) mutex_lock(&hdl->libzfs_mnttab_cache_lock);
+        if (avl_numnodes(&hdl->libzfs_mnttab_cache) != 0) {
         mtn = zfs_alloc(hdl, sizeof (mnttab_node_t));
         mtn->mtn_mt.mnt_special = zfs_strdup(hdl, special);
         mtn->mtn_mt.mnt_mountp = zfs_strdup(hdl, mountp);
         mtn->mtn_mt.mnt_fstype = zfs_strdup(hdl, MNTTYPE_ZFS);
         mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, mntopts);
         avl_add(&hdl->libzfs_mnttab_cache, mtn);
+        }
+        (void) mutex_unlock(&hdl->libzfs_mnttab_cache_lock);
 }
 
 void
 libzfs_mnttab_remove(libzfs_handle_t *hdl, const char *fsname)
 {
         mnttab_node_t find;
         mnttab_node_t *ret;
 
+        (void) mutex_lock(&hdl->libzfs_mnttab_cache_lock);
         find.mtn_mt.mnt_special = (char *)fsname;
         if ((ret = avl_find(&hdl->libzfs_mnttab_cache, (void *)&find, NULL))
             != NULL) {
                 avl_remove(&hdl->libzfs_mnttab_cache, ret);
                 free(ret->mtn_mt.mnt_special);

@@ -896,10 +904,11 @@
                 free(ret->mtn_mt.mnt_mountp);
                 free(ret->mtn_mt.mnt_fstype);
                 free(ret->mtn_mt.mnt_mntopts);
                 free(ret);
         }
+        (void) mutex_unlock(&hdl->libzfs_mnttab_cache_lock);
 }
 
 int
 zfs_spa_version(zfs_handle_t *zhp, int *spa_version)
 {