Print this page
8115 parallel zfs mount

Split Close
Expand all
Collapse all
          --- old/usr/src/lib/libzfs/common/libzfs_dataset.c
          +++ new/usr/src/lib/libzfs/common/libzfs_dataset.c
↓ open down ↓ 46 lines elided ↑ open up ↑
  47   47  #include <sys/mntent.h>
  48   48  #include <sys/mount.h>
  49   49  #include <priv.h>
  50   50  #include <pwd.h>
  51   51  #include <grp.h>
  52   52  #include <stddef.h>
  53   53  #include <ucred.h>
  54   54  #include <idmap.h>
  55   55  #include <aclutils.h>
  56   56  #include <directory.h>
       57 +#include <time.h>
  57   58  
  58   59  #include <sys/dnode.h>
  59   60  #include <sys/spa.h>
  60   61  #include <sys/zap.h>
  61   62  #include <libzfs.h>
  62   63  
  63   64  #include "zfs_namecheck.h"
  64   65  #include "zfs_prop.h"
  65   66  #include "libzfs_impl.h"
  66   67  #include "zfs_deleg.h"
↓ open down ↓ 711 lines elided ↑ open up ↑
 778  779          rv = strcmp(mtn1->mtn_mt.mnt_special, mtn2->mtn_mt.mnt_special);
 779  780  
 780  781          if (rv == 0)
 781  782                  return (0);
 782  783          return (rv > 0 ? 1 : -1);
 783  784  }
 784  785  
 785  786  void
 786  787  libzfs_mnttab_init(libzfs_handle_t *hdl)
 787  788  {
      789 +        (void) mutex_init(&hdl->libzfs_mnttab_cache_lock, MUTEX_DEFAULT, NULL);
 788  790          assert(avl_numnodes(&hdl->libzfs_mnttab_cache) == 0);
 789  791          avl_create(&hdl->libzfs_mnttab_cache, libzfs_mnttab_cache_compare,
 790  792              sizeof (mnttab_node_t), offsetof(mnttab_node_t, mtn_node));
 791  793  }
 792  794  
 793  795  void
 794  796  libzfs_mnttab_update(libzfs_handle_t *hdl)
 795  797  {
 796  798          struct mnttab entry;
 797  799  
↓ open down ↓ 20 lines elided ↑ open up ↑
 818  820  
 819  821          while ((mtn = avl_destroy_nodes(&hdl->libzfs_mnttab_cache, &cookie))
 820  822              != NULL) {
 821  823                  free(mtn->mtn_mt.mnt_special);
 822  824                  free(mtn->mtn_mt.mnt_mountp);
 823  825                  free(mtn->mtn_mt.mnt_fstype);
 824  826                  free(mtn->mtn_mt.mnt_mntopts);
 825  827                  free(mtn);
 826  828          }
 827  829          avl_destroy(&hdl->libzfs_mnttab_cache);
      830 +        (void) mutex_destroy(&hdl->libzfs_mnttab_cache_lock);
 828  831  }
 829  832  
 830  833  void
 831  834  libzfs_mnttab_cache(libzfs_handle_t *hdl, boolean_t enable)
 832  835  {
 833  836          hdl->libzfs_mnttab_enable = enable;
 834  837  }
 835  838  
 836  839  int
 837  840  libzfs_mnttab_find(libzfs_handle_t *hdl, const char *fsname,
 838  841      struct mnttab *entry)
 839  842  {
 840  843          mnttab_node_t find;
 841  844          mnttab_node_t *mtn;
      845 +        int ret = ENOENT;
 842  846  
 843  847          if (!hdl->libzfs_mnttab_enable) {
 844  848                  struct mnttab srch = { 0 };
 845  849  
 846  850                  if (avl_numnodes(&hdl->libzfs_mnttab_cache))
 847  851                          libzfs_mnttab_fini(hdl);
 848  852                  rewind(hdl->libzfs_mnttab);
 849  853                  srch.mnt_special = (char *)fsname;
 850  854                  srch.mnt_fstype = MNTTYPE_ZFS;
 851  855                  if (getmntany(hdl->libzfs_mnttab, entry, &srch) == 0)
 852      -                        return (0);
 853      -                else
 854      -                        return (ENOENT);
      856 +                        ret = 0;
      857 +                return (ret);
 855  858          }
 856  859  
      860 +        (void) mutex_lock(&hdl->libzfs_mnttab_cache_lock);
 857  861          if (avl_numnodes(&hdl->libzfs_mnttab_cache) == 0)
 858  862                  libzfs_mnttab_update(hdl);
 859  863  
 860  864          find.mtn_mt.mnt_special = (char *)fsname;
 861  865          mtn = avl_find(&hdl->libzfs_mnttab_cache, &find, NULL);
 862  866          if (mtn) {
 863  867                  *entry = mtn->mtn_mt;
 864      -                return (0);
      868 +                ret = 0;
 865  869          }
 866      -        return (ENOENT);
      870 +        (void) mutex_unlock(&hdl->libzfs_mnttab_cache_lock);
      871 +        return (ret);
 867  872  }
 868  873  
 869  874  void
 870  875  libzfs_mnttab_add(libzfs_handle_t *hdl, const char *special,
 871  876      const char *mountp, const char *mntopts)
 872  877  {
 873  878          mnttab_node_t *mtn;
 874  879  
 875      -        if (avl_numnodes(&hdl->libzfs_mnttab_cache) == 0)
 876      -                return;
 877      -        mtn = zfs_alloc(hdl, sizeof (mnttab_node_t));
 878      -        mtn->mtn_mt.mnt_special = zfs_strdup(hdl, special);
 879      -        mtn->mtn_mt.mnt_mountp = zfs_strdup(hdl, mountp);
 880      -        mtn->mtn_mt.mnt_fstype = zfs_strdup(hdl, MNTTYPE_ZFS);
 881      -        mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, mntopts);
 882      -        avl_add(&hdl->libzfs_mnttab_cache, mtn);
      880 +        (void) mutex_lock(&hdl->libzfs_mnttab_cache_lock);
      881 +        if (avl_numnodes(&hdl->libzfs_mnttab_cache) != 0) {
      882 +                mtn = zfs_alloc(hdl, sizeof (mnttab_node_t));
      883 +                mtn->mtn_mt.mnt_special = zfs_strdup(hdl, special);
      884 +                mtn->mtn_mt.mnt_mountp = zfs_strdup(hdl, mountp);
      885 +                mtn->mtn_mt.mnt_fstype = zfs_strdup(hdl, MNTTYPE_ZFS);
      886 +                mtn->mtn_mt.mnt_mntopts = zfs_strdup(hdl, mntopts);
      887 +                avl_add(&hdl->libzfs_mnttab_cache, mtn);
      888 +        }
      889 +        (void) mutex_unlock(&hdl->libzfs_mnttab_cache_lock);
 883  890  }
 884  891  
 885  892  void
 886  893  libzfs_mnttab_remove(libzfs_handle_t *hdl, const char *fsname)
 887  894  {
 888  895          mnttab_node_t find;
 889  896          mnttab_node_t *ret;
 890  897  
      898 +        (void) mutex_lock(&hdl->libzfs_mnttab_cache_lock);
 891  899          find.mtn_mt.mnt_special = (char *)fsname;
 892  900          if ((ret = avl_find(&hdl->libzfs_mnttab_cache, (void *)&find, NULL))
 893  901              != NULL) {
 894  902                  avl_remove(&hdl->libzfs_mnttab_cache, ret);
 895  903                  free(ret->mtn_mt.mnt_special);
 896  904                  free(ret->mtn_mt.mnt_mountp);
 897  905                  free(ret->mtn_mt.mnt_fstype);
 898  906                  free(ret->mtn_mt.mnt_mntopts);
 899  907                  free(ret);
 900  908          }
      909 +        (void) mutex_unlock(&hdl->libzfs_mnttab_cache_lock);
 901  910  }
 902  911  
 903  912  int
 904  913  zfs_spa_version(zfs_handle_t *zhp, int *spa_version)
 905  914  {
 906  915          zpool_handle_t *zpool_handle = zhp->zpool_hdl;
 907  916  
 908  917          if (zpool_handle == NULL)
 909  918                  return (-1);
 910  919  
↓ open down ↓ 4043 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX