Print this page
filesystem hook framework (August 19th)

Split Close
Expand all
Collapse all
          --- old/usr/src/uts/common/fs/vfs.c
          +++ new/usr/src/uts/common/fs/vfs.c
↓ open down ↓ 76 lines elided ↑ open up ↑
  77   77  #include <sys/policy.h>
  78   78  #include <sys/ctfs.h>
  79   79  #include <sys/objfs.h>
  80   80  #include <sys/console.h>
  81   81  #include <sys/reboot.h>
  82   82  #include <sys/attr.h>
  83   83  #include <sys/zio.h>
  84   84  #include <sys/spa.h>
  85   85  #include <sys/lofi.h>
  86   86  #include <sys/bootprops.h>
       87 +#include <sys/fsh.h>
       88 +#include <sys/fsh_impl.h>
  87   89  
  88   90  #include <vm/page.h>
  89   91  
  90   92  #include <fs/fs_subr.h>
  91   93  /* Private interfaces to create vopstats-related data structures */
  92   94  extern void             initialize_vopstats(vopstats_t *);
  93   95  extern vopstats_t       *get_fstype_vopstats(struct vfs *, struct vfssw *);
  94   96  extern vsk_anchor_t     *get_vskstat_anchor(struct vfs *);
  95   97  
  96   98  static void vfs_clearmntopt_nolock(mntopts_t *, const char *, int);
↓ open down ↓ 112 lines elided ↑ open up ↑
 209  211          (mntopt_t *)&mntopts[0]
 210  212  };
 211  213  
 212  214  /*
 213  215   * File system operation dispatch functions.
 214  216   */
 215  217  
 216  218  int
 217  219  fsop_mount(vfs_t *vfsp, vnode_t *mvp, struct mounta *uap, cred_t *cr)
 218  220  {
 219      -        return (*(vfsp)->vfs_op->vfs_mount)(vfsp, mvp, uap, cr);
      221 +        return (fsh_mount(vfsp, mvp, uap, cr));
 220  222  }
 221  223  
 222  224  int
 223  225  fsop_unmount(vfs_t *vfsp, int flag, cred_t *cr)
 224  226  {
 225      -        return (*(vfsp)->vfs_op->vfs_unmount)(vfsp, flag, cr);
      227 +        return (fsh_unmount(vfsp, flag, cr));
 226  228  }
 227  229  
 228  230  int
 229  231  fsop_root(vfs_t *vfsp, vnode_t **vpp)
 230  232  {
 231  233          refstr_t *mntpt;
 232  234          int ret = (*(vfsp)->vfs_op->vfs_root)(vfsp, vpp);
 233  235          /*
 234  236           * Make sure this root has a path.  With lofs, it is possible to have
 235  237           * a NULL mountpoint.
↓ open down ↓ 1542 lines elided ↑ open up ↑
1778 1780                          if (vskap != NULL) {
1779 1781                                  vfs_lock_wait(vfsp);
1780 1782                                  if (vfsp->vfs_flag & VFS_STATS) {
1781 1783                                          vfsp->vfs_vskap = vskap;
1782 1784                                  }
1783 1785                                  vfs_unlock(vfsp);
1784 1786                          }
1785 1787                  }
1786 1788                  /* Return vfsp to caller. */
1787 1789                  *vfspp = vfsp;
     1790 +                fsh_exec_mount_callbacks(vfsp);
1788 1791          }
1789 1792  errout:
1790 1793          vfs_freeopttbl(&mnt_mntopts);
1791 1794          if (resource != NULL)
1792 1795                  kmem_free(resource, strlen(resource) + 1);
1793 1796          if (mountpt != NULL)
1794 1797                  kmem_free(mountpt, strlen(mountpt) + 1);
1795 1798          /*
1796 1799           * It is possible we errored prior to adding to mount in progress
1797 1800           * table. Must free vnode we acquired with successful lookupname.
↓ open down ↓ 2430 lines elided ↑ open up ↑
4228 4231          /* Create vfs cache */
4229 4232          vfs_cache = kmem_cache_create("vfs_cache", sizeof (struct vfs),
4230 4233              sizeof (uintptr_t), NULL, NULL, NULL, NULL, NULL, 0);
4231 4234  
4232 4235          /* Initialize the vnode cache (file systems may use it during init). */
4233 4236          vn_create_cache();
4234 4237  
4235 4238          /* Setup event monitor framework */
4236 4239          fem_init();
4237 4240  
     4241 +        /* Setup filesystem hook framework */
     4242 +        fsh_init();
     4243 +
4238 4244          /* Initialize the dummy stray file system type. */
4239 4245          error = vfs_setfsops(0, stray_vfsops_template, NULL);
4240 4246  
4241 4247          /* Initialize the dummy EIO file system. */
4242 4248          error = vfs_makefsops(EIO_vfsops_template, &EIO_vfsops);
4243 4249          if (error != 0) {
4244 4250                  cmn_err(CE_WARN, "vfsinit: bad EIO vfs ops template");
4245 4251                  /* Shouldn't happen, but not bad enough to panic */
4246 4252          }
4247 4253  
↓ open down ↓ 64 lines elided ↑ open up ↑
4312 4318           */
4313 4319  
4314 4320          /* If FEM was in use, make sure everything gets cleaned up */
4315 4321          if (vfsp->vfs_femhead) {
4316 4322                  ASSERT(vfsp->vfs_femhead->femh_list == NULL);
4317 4323                  mutex_destroy(&vfsp->vfs_femhead->femh_lock);
4318 4324                  kmem_free(vfsp->vfs_femhead, sizeof (*(vfsp->vfs_femhead)));
4319 4325                  vfsp->vfs_femhead = NULL;
4320 4326          }
4321 4327  
     4328 +        /*
     4329 +         * fsh cleanup
     4330 +         * There's no need here to use atomic operations on vfs_fshrecord.
     4331 +         */
     4332 +        if (vfsp->vfs_fshrecord != NULL) {
     4333 +                fsh_fsrec_destroy(vfsp->vfs_fshrecord);
     4334 +                vfsp->vfs_fshrecord = NULL;
     4335 +        }
     4336 +
4322 4337          if (vfsp->vfs_implp)
4323 4338                  vfsimpl_teardown(vfsp);
4324 4339          sema_destroy(&vfsp->vfs_reflock);
4325 4340          kmem_cache_free(vfs_cache, vfsp);
4326 4341  }
4327 4342  
4328 4343  /*
4329 4344   * Increments the vfs reference count by one atomically.
4330 4345   */
4331 4346  void
↓ open down ↓ 6 lines elided ↑ open up ↑
4338 4353  /*
4339 4354   * Decrements the vfs reference count by one atomically. When
4340 4355   * vfs reference count becomes zero, it calls the file system
4341 4356   * specific vfs_freevfs() to free up the resources.
4342 4357   */
4343 4358  void
4344 4359  vfs_rele(vfs_t *vfsp)
4345 4360  {
4346 4361          ASSERT(vfsp->vfs_count != 0);
4347 4362          if (atomic_add_32_nv(&vfsp->vfs_count, -1) == 0) {
     4363 +                fsh_exec_free_callbacks(vfsp);
4348 4364                  VFS_FREEVFS(vfsp);
4349 4365                  lofi_remove(vfsp);
4350 4366                  if (vfsp->vfs_zone)
4351 4367                          zone_rele_ref(&vfsp->vfs_implp->vi_zone_ref,
4352 4368                              ZONE_REF_VFS);
4353 4369                  vfs_freemnttab(vfsp);
4354 4370                  vfs_free(vfsp);
4355 4371          }
4356 4372  }
4357 4373  
↓ open down ↓ 454 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX