]> git.proxmox.com Git - mirror_zfs.git/blobdiff - module/zfs/zfs_znode.c
Fix typo/etc in module/zfs/zfs_ctldir.c
[mirror_zfs.git] / module / zfs / zfs_znode.c
index 4403e3289c9c90266295fddf7b37c6b567c7d5cf..d998e42ab0ba51ae140a0416b76ad0bb8af8e622 100644 (file)
@@ -20,7 +20,7 @@
  */
 /*
  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
- * Copyright (c) 2013 by Delphix. All rights reserved.
+ * Copyright (c) 2012, 2018 by Delphix. All rights reserved.
  */
 
 /* Portions Copyright 2007 Jeremy Teo */
 #include <sys/types.h>
 #include <sys/param.h>
 #include <sys/time.h>
-#include <sys/systm.h>
 #include <sys/sysmacros.h>
-#include <sys/resource.h>
 #include <sys/mntent.h>
-#include <sys/mkdev.h>
 #include <sys/u8_textprep.h>
 #include <sys/dsl_dataset.h>
 #include <sys/vfs.h>
-#include <sys/vfs_opreg.h>
 #include <sys/vnode.h>
 #include <sys/file.h>
 #include <sys/kmem.h>
 #include <sys/errno.h>
-#include <sys/unistd.h>
 #include <sys/mode.h>
 #include <sys/atomic.h>
-#include <vm/pvn.h>
-#include "fs/fs_subr.h"
 #include <sys/zfs_dir.h>
 #include <sys/zfs_acl.h>
 #include <sys/zfs_ioctl.h>
 #include <sys/zfs_ctldir.h>
 #include <sys/dnode.h>
 #include <sys/fs/zfs.h>
-#include <sys/kidmap.h>
 #include <sys/zpl.h>
 #endif /* _KERNEL */
 
 #include <sys/dmu.h>
+#include <sys/dmu_objset.h>
+#include <sys/dmu_tx.h>
 #include <sys/refcount.h>
 #include <sys/stat.h>
 #include <sys/zap.h>
 #include "zfs_prop.h"
 #include "zfs_comutil.h"
 
-/*
- * Define ZNODE_STATS to turn on statistic gathering. By default, it is only
- * turned on when DEBUG is also defined.
- */
-#ifdef DEBUG
-#define        ZNODE_STATS
-#endif /* DEBUG */
-
-#ifdef ZNODE_STATS
-#define        ZNODE_STAT_ADD(stat)                    ((stat)++)
-#else
-#define        ZNODE_STAT_ADD(stat)                    /* nothing */
-#endif /* ZNODE_STATS */
-
 /*
  * Functions needed for userland (ie: libzpool) are not put under
  * #ifdef_KERNEL; the rest of the functions have dependencies
 #ifdef _KERNEL
 
 static kmem_cache_t *znode_cache = NULL;
+static kmem_cache_t *znode_hold_cache = NULL;
+unsigned int zfs_object_mutex_size = ZFS_OBJ_MTX_SZ;
+
+/*
+ * This is used by the test suite so that it can delay znodes from being
+ * freed in order to inspect the unlinked set.
+ */
+int zfs_unlink_suspend_progress = 0;
+
+/*
+ * This callback is invoked when acquiring a RL_WRITER or RL_APPEND lock on
+ * z_rangelock. It will modify the offset and length of the lock to reflect
+ * znode-specific information, and convert RL_APPEND to RL_WRITER.  This is
+ * called with the rangelock_t's rl_lock held, which avoids races.
+ */
+static void
+zfs_rangelock_cb(locked_range_t *new, void *arg)
+{
+       znode_t *zp = arg;
+
+       /*
+        * If in append mode, convert to writer and lock starting at the
+        * current end of file.
+        */
+       if (new->lr_type == RL_APPEND) {
+               new->lr_offset = zp->z_size;
+               new->lr_type = RL_WRITER;
+       }
+
+       /*
+        * If we need to grow the block size then lock the whole file range.
+        */
+       uint64_t end_size = MAX(zp->z_size, new->lr_offset + new->lr_length);
+       if (end_size > zp->z_blksz && (!ISP2(zp->z_blksz) ||
+           zp->z_blksz < ZTOZSB(zp)->z_max_blksz)) {
+               new->lr_offset = 0;
+               new->lr_length = UINT64_MAX;
+       }
+}
 
 /*ARGSUSED*/
 static int
@@ -106,18 +125,16 @@ zfs_znode_cache_constructor(void *buf, void *arg, int kmflags)
 
        mutex_init(&zp->z_lock, NULL, MUTEX_DEFAULT, NULL);
        rw_init(&zp->z_parent_lock, NULL, RW_DEFAULT, NULL);
-       rw_init(&zp->z_name_lock, NULL, RW_DEFAULT, NULL);
+       rw_init(&zp->z_name_lock, NULL, RW_NOLOCKDEP, NULL);
        mutex_init(&zp->z_acl_lock, NULL, MUTEX_DEFAULT, NULL);
        rw_init(&zp->z_xattr_lock, NULL, RW_DEFAULT, NULL);
 
-       mutex_init(&zp->z_range_lock, NULL, MUTEX_DEFAULT, NULL);
-       avl_create(&zp->z_range_avl, zfs_range_compare,
-           sizeof (rl_t), offsetof(rl_t, r_node));
+       rangelock_init(&zp->z_rangelock, zfs_rangelock_cb, zp);
 
        zp->z_dirlocks = NULL;
        zp->z_acl_cached = NULL;
        zp->z_xattr_cached = NULL;
-       zp->z_xattr_parent = NULL;
+       zp->z_xattr_parent = 0;
        zp->z_moved = 0;
        return (0);
 }
@@ -134,25 +151,51 @@ zfs_znode_cache_destructor(void *buf, void *arg)
        rw_destroy(&zp->z_name_lock);
        mutex_destroy(&zp->z_acl_lock);
        rw_destroy(&zp->z_xattr_lock);
-       avl_destroy(&zp->z_range_avl);
-       mutex_destroy(&zp->z_range_lock);
+       rangelock_fini(&zp->z_rangelock);
 
        ASSERT(zp->z_dirlocks == NULL);
        ASSERT(zp->z_acl_cached == NULL);
        ASSERT(zp->z_xattr_cached == NULL);
-       ASSERT(zp->z_xattr_parent == NULL);
+}
+
+static int
+zfs_znode_hold_cache_constructor(void *buf, void *arg, int kmflags)
+{
+       znode_hold_t *zh = buf;
+
+       mutex_init(&zh->zh_lock, NULL, MUTEX_DEFAULT, NULL);
+       zfs_refcount_create(&zh->zh_refcount);
+       zh->zh_obj = ZFS_NO_OBJECT;
+
+       return (0);
+}
+
+static void
+zfs_znode_hold_cache_destructor(void *buf, void *arg)
+{
+       znode_hold_t *zh = buf;
+
+       mutex_destroy(&zh->zh_lock);
+       zfs_refcount_destroy(&zh->zh_refcount);
 }
 
 void
 zfs_znode_init(void)
 {
        /*
-        * Initialize zcache
+        * Initialize zcache.  The KMC_SLAB hint is used in order that it be
+        * backed by kmalloc() when on the Linux slab in order that any
+        * wait_on_bit() operations on the related inode operate properly.
         */
        ASSERT(znode_cache == NULL);
        znode_cache = kmem_cache_create("zfs_znode_cache",
            sizeof (znode_t), 0, zfs_znode_cache_constructor,
-           zfs_znode_cache_destructor, NULL, NULL, NULL, KMC_KMEM);
+           zfs_znode_cache_destructor, NULL, NULL, NULL, KMC_SLAB);
+
+       ASSERT(znode_hold_cache == NULL);
+       znode_hold_cache = kmem_cache_create("zfs_znode_hold_cache",
+           sizeof (znode_hold_t), 0, zfs_znode_hold_cache_constructor,
+           zfs_znode_hold_cache_destructor, NULL, NULL, NULL, 0);
 }
 
 void
@@ -164,68 +207,132 @@ zfs_znode_fini(void)
        if (znode_cache)
                kmem_cache_destroy(znode_cache);
        znode_cache = NULL;
+
+       if (znode_hold_cache)
+               kmem_cache_destroy(znode_hold_cache);
+       znode_hold_cache = NULL;
 }
 
+/*
+ * The zfs_znode_hold_enter() / zfs_znode_hold_exit() functions are used to
+ * serialize access to a znode and its SA buffer while the object is being
+ * created or destroyed.  This kind of locking would normally reside in the
+ * znode itself but in this case that's impossible because the znode and SA
+ * buffer may not yet exist.  Therefore the locking is handled externally
+ * with an array of mutexs and AVLs trees which contain per-object locks.
+ *
+ * In zfs_znode_hold_enter() a per-object lock is created as needed, inserted
+ * in to the correct AVL tree and finally the per-object lock is held.  In
+ * zfs_znode_hold_exit() the process is reversed.  The per-object lock is
+ * released, removed from the AVL tree and destroyed if there are no waiters.
+ *
+ * This scheme has two important properties:
+ *
+ * 1) No memory allocations are performed while holding one of the z_hold_locks.
+ *    This ensures evict(), which can be called from direct memory reclaim, will
+ *    never block waiting on a z_hold_locks which just happens to have hashed
+ *    to the same index.
+ *
+ * 2) All locks used to serialize access to an object are per-object and never
+ *    shared.  This minimizes lock contention without creating a large number
+ *    of dedicated locks.
+ *
+ * On the downside it does require znode_lock_t structures to be frequently
+ * allocated and freed.  However, because these are backed by a kmem cache
+ * and very short lived this cost is minimal.
+ */
 int
-zfs_create_share_dir(zfs_sb_t *zsb, dmu_tx_t *tx)
+zfs_znode_hold_compare(const void *a, const void *b)
 {
-#ifdef HAVE_SMB_SHARE
-       zfs_acl_ids_t acl_ids;
-       vattr_t vattr;
-       znode_t *sharezp;
-       vnode_t *vp;
-       znode_t *zp;
-       int error;
+       const znode_hold_t *zh_a = (const znode_hold_t *)a;
+       const znode_hold_t *zh_b = (const znode_hold_t *)b;
 
-       vattr.va_mask = AT_MODE|AT_UID|AT_GID|AT_TYPE;
-       vattr.va_mode = S_IFDIR | 0555;
-       vattr.va_uid = crgetuid(kcred);
-       vattr.va_gid = crgetgid(kcred);
-
-       sharezp = kmem_cache_alloc(znode_cache, KM_PUSHPAGE);
-       sharezp->z_moved = 0;
-       sharezp->z_unlinked = 0;
-       sharezp->z_atime_dirty = 0;
-       sharezp->z_zfsvfs = zfsvfs;
-       sharezp->z_is_sa = zfsvfs->z_use_sa;
-
-       vp = ZTOV(sharezp);
-       vn_reinit(vp);
-       vp->v_type = VDIR;
-
-       VERIFY(0 == zfs_acl_ids_create(sharezp, IS_ROOT_NODE, &vattr,
-           kcred, NULL, &acl_ids));
-       zfs_mknode(sharezp, &vattr, tx, kcred, IS_ROOT_NODE, &zp, &acl_ids);
-       ASSERT3P(zp, ==, sharezp);
-       ASSERT(!vn_in_dnlc(ZTOV(sharezp))); /* not valid to move */
-       POINTER_INVALIDATE(&sharezp->z_zfsvfs);
-       error = zap_add(zfsvfs->z_os, MASTER_NODE_OBJ,
-           ZFS_SHARES_DIR, 8, 1, &sharezp->z_id, tx);
-       zfsvfs->z_shares_dir = sharezp->z_id;
+       return (AVL_CMP(zh_a->zh_obj, zh_b->zh_obj));
+}
 
-       zfs_acl_ids_free(&acl_ids);
-       // ZTOV(sharezp)->v_count = 0;
-       sa_handle_destroy(sharezp->z_sa_hdl);
-       kmem_cache_free(znode_cache, sharezp);
+boolean_t
+zfs_znode_held(zfsvfs_t *zfsvfs, uint64_t obj)
+{
+       znode_hold_t *zh, search;
+       int i = ZFS_OBJ_HASH(zfsvfs, obj);
+       boolean_t held;
 
-       return (error);
-#else
-       return (0);
-#endif /* HAVE_SMB_SHARE */
+       search.zh_obj = obj;
+
+       mutex_enter(&zfsvfs->z_hold_locks[i]);
+       zh = avl_find(&zfsvfs->z_hold_trees[i], &search, NULL);
+       held = (zh && MUTEX_HELD(&zh->zh_lock)) ? B_TRUE : B_FALSE;
+       mutex_exit(&zfsvfs->z_hold_locks[i]);
+
+       return (held);
+}
+
+static znode_hold_t *
+zfs_znode_hold_enter(zfsvfs_t *zfsvfs, uint64_t obj)
+{
+       znode_hold_t *zh, *zh_new, search;
+       int i = ZFS_OBJ_HASH(zfsvfs, obj);
+       boolean_t found = B_FALSE;
+
+       zh_new = kmem_cache_alloc(znode_hold_cache, KM_SLEEP);
+       zh_new->zh_obj = obj;
+       search.zh_obj = obj;
+
+       mutex_enter(&zfsvfs->z_hold_locks[i]);
+       zh = avl_find(&zfsvfs->z_hold_trees[i], &search, NULL);
+       if (likely(zh == NULL)) {
+               zh = zh_new;
+               avl_add(&zfsvfs->z_hold_trees[i], zh);
+       } else {
+               ASSERT3U(zh->zh_obj, ==, obj);
+               found = B_TRUE;
+       }
+       zfs_refcount_add(&zh->zh_refcount, NULL);
+       mutex_exit(&zfsvfs->z_hold_locks[i]);
+
+       if (found == B_TRUE)
+               kmem_cache_free(znode_hold_cache, zh_new);
+
+       ASSERT(MUTEX_NOT_HELD(&zh->zh_lock));
+       ASSERT3S(zfs_refcount_count(&zh->zh_refcount), >, 0);
+       mutex_enter(&zh->zh_lock);
+
+       return (zh);
+}
+
+static void
+zfs_znode_hold_exit(zfsvfs_t *zfsvfs, znode_hold_t *zh)
+{
+       int i = ZFS_OBJ_HASH(zfsvfs, zh->zh_obj);
+       boolean_t remove = B_FALSE;
+
+       ASSERT(zfs_znode_held(zfsvfs, zh->zh_obj));
+       ASSERT3S(zfs_refcount_count(&zh->zh_refcount), >, 0);
+       mutex_exit(&zh->zh_lock);
+
+       mutex_enter(&zfsvfs->z_hold_locks[i]);
+       if (zfs_refcount_remove(&zh->zh_refcount, NULL) == 0) {
+               avl_remove(&zfsvfs->z_hold_trees[i], zh);
+               remove = B_TRUE;
+       }
+       mutex_exit(&zfsvfs->z_hold_locks[i]);
+
+       if (remove == B_TRUE)
+               kmem_cache_free(znode_hold_cache, zh);
 }
 
 static void
-zfs_znode_sa_init(zfs_sb_t *zsb, znode_t *zp,
+zfs_znode_sa_init(zfsvfs_t *zfsvfs, znode_t *zp,
     dmu_buf_t *db, dmu_object_type_t obj_type, sa_handle_t *sa_hdl)
 {
-       ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(zsb, zp->z_id)));
+       ASSERT(zfs_znode_held(zfsvfs, zp->z_id));
 
        mutex_enter(&zp->z_lock);
 
        ASSERT(zp->z_sa_hdl == NULL);
        ASSERT(zp->z_acl_cached == NULL);
        if (sa_hdl == NULL) {
-               VERIFY(0 == sa_handle_get_from_db(zsb->z_os, db, zp,
+               VERIFY(0 == sa_handle_get_from_db(zfsvfs->z_os, db, zp,
                    SA_HDL_SHARED, &zp->z_sa_hdl));
        } else {
                zp->z_sa_hdl = sa_hdl;
@@ -240,8 +347,7 @@ zfs_znode_sa_init(zfs_sb_t *zsb, znode_t *zp,
 void
 zfs_znode_dmu_fini(znode_t *zp)
 {
-       ASSERT(MUTEX_HELD(ZFS_OBJ_MUTEX(ZTOZSB(zp), zp->z_id)) ||
-           zp->z_unlinked ||
+       ASSERT(zfs_znode_held(ZTOZSB(zp), zp->z_id) || zp->z_unlinked ||
            RW_WRITE_HELD(&ZTOZSB(zp)->z_teardown_inactive_lock));
 
        sa_handle_destroy(zp->z_sa_hdl);
@@ -256,7 +362,7 @@ zfs_inode_alloc(struct super_block *sb, struct inode **ip)
 {
        znode_t *zp;
 
-       zp = kmem_cache_alloc(znode_cache, KM_PUSHPAGE);
+       zp = kmem_cache_alloc(znode_cache, KM_SLEEP);
        *ip = ZTOI(zp);
 
        return (0);
@@ -269,17 +375,14 @@ void
 zfs_inode_destroy(struct inode *ip)
 {
        znode_t *zp = ITOZ(ip);
-       zfs_sb_t *zsb = ZTOZSB(zp);
-
-       if (zfsctl_is_node(ip))
-               zfsctl_inode_destroy(ip);
+       zfsvfs_t *zfsvfs = ZTOZSB(zp);
 
-       mutex_enter(&zsb->z_znodes_lock);
+       mutex_enter(&zfsvfs->z_znodes_lock);
        if (list_link_active(&zp->z_link_node)) {
-               list_remove(&zsb->z_all_znodes, zp);
-               zsb->z_nr_znodes--;
+               list_remove(&zfsvfs->z_all_znodes, zp);
+               zfsvfs->z_nr_znodes--;
        }
-       mutex_exit(&zsb->z_znodes_lock);
+       mutex_exit(&zfsvfs->z_znodes_lock);
 
        if (zp->z_acl_cached) {
                zfs_acl_free(zp->z_acl_cached);
@@ -291,16 +394,11 @@ zfs_inode_destroy(struct inode *ip)
                zp->z_xattr_cached = NULL;
        }
 
-       if (zp->z_xattr_parent) {
-               iput(ZTOI(zp->z_xattr_parent));
-               zp->z_xattr_parent = NULL;
-       }
-
        kmem_cache_free(znode_cache, zp);
 }
 
 static void
-zfs_inode_set_ops(zfs_sb_t *zsb, struct inode *ip)
+zfs_inode_set_ops(zfsvfs_t *zfsvfs, struct inode *ip)
 {
        uint64_t rdev = 0;
 
@@ -326,8 +424,8 @@ zfs_inode_set_ops(zfs_sb_t *zsb, struct inode *ip)
         */
        case S_IFCHR:
        case S_IFBLK:
-               VERIFY(sa_lookup(ITOZ(ip)->z_sa_hdl, SA_ZPL_RDEV(zsb),
-                   &rdev, sizeof (rdev)) == 0);
+               (void) sa_lookup(ITOZ(ip)->z_sa_hdl, SA_ZPL_RDEV(zfsvfs), &rdev,
+                   sizeof (rdev));
                /*FALLTHROUGH*/
        case S_IFIFO:
        case S_IFSOCK:
@@ -336,11 +434,78 @@ zfs_inode_set_ops(zfs_sb_t *zsb, struct inode *ip)
                break;
 
        default:
-               printk("ZFS: Invalid mode: 0x%x\n", ip->i_mode);
-               VERIFY(0);
+               zfs_panic_recover("inode %llu has invalid mode: 0x%x\n",
+                   (u_longlong_t)ip->i_ino, ip->i_mode);
+
+               /* Assume the inode is a file and attempt to continue */
+               ip->i_mode = S_IFREG | 0644;
+               ip->i_op = &zpl_inode_operations;
+               ip->i_fop = &zpl_file_operations;
+               ip->i_mapping->a_ops = &zpl_address_space_operations;
+               break;
        }
 }
 
+void
+zfs_set_inode_flags(znode_t *zp, struct inode *ip)
+{
+       /*
+        * Linux and Solaris have different sets of file attributes, so we
+        * restrict this conversion to the intersection of the two.
+        */
+#ifdef HAVE_INODE_SET_FLAGS
+       unsigned int flags = 0;
+       if (zp->z_pflags & ZFS_IMMUTABLE)
+               flags |= S_IMMUTABLE;
+       if (zp->z_pflags & ZFS_APPENDONLY)
+               flags |= S_APPEND;
+
+       inode_set_flags(ip, flags, S_IMMUTABLE|S_APPEND);
+#else
+       if (zp->z_pflags & ZFS_IMMUTABLE)
+               ip->i_flags |= S_IMMUTABLE;
+       else
+               ip->i_flags &= ~S_IMMUTABLE;
+
+       if (zp->z_pflags & ZFS_APPENDONLY)
+               ip->i_flags |= S_APPEND;
+       else
+               ip->i_flags &= ~S_APPEND;
+#endif
+}
+
+/*
+ * Update the embedded inode given the znode.  We should work toward
+ * eliminating this function as soon as possible by removing values
+ * which are duplicated between the znode and inode.  If the generic
+ * inode has the correct field it should be used, and the ZFS code
+ * updated to access the inode.  This can be done incrementally.
+ */
+void
+zfs_inode_update(znode_t *zp)
+{
+       zfsvfs_t        *zfsvfs;
+       struct inode    *ip;
+       uint32_t        blksize;
+       u_longlong_t    i_blocks;
+
+       ASSERT(zp != NULL);
+       zfsvfs = ZTOZSB(zp);
+       ip = ZTOI(zp);
+
+       /* Skip .zfs control nodes which do not exist on disk. */
+       if (zfsctl_is_node(ip))
+               return;
+
+       dmu_object_size_from_db(sa_get_db(zp->z_sa_hdl), &blksize, &i_blocks);
+
+       spin_lock(&ip->i_lock);
+       ip->i_blocks = i_blocks;
+       i_size_write(ip, zp->z_size);
+       spin_unlock(&ip->i_lock);
+}
+
+
 /*
  * Construct a znode+inode and initialize.
  *
@@ -349,20 +514,24 @@ zfs_inode_set_ops(zfs_sb_t *zsb, struct inode *ip)
  * return the znode
  */
 static znode_t *
-zfs_znode_alloc(zfs_sb_t *zsb, dmu_buf_t *db, int blksz,
-    dmu_object_type_t obj_type, uint64_t obj, sa_handle_t *hdl,
-    struct inode *dip)
+zfs_znode_alloc(zfsvfs_t *zfsvfs, dmu_buf_t *db, int blksz,
+    dmu_object_type_t obj_type, uint64_t obj, sa_handle_t *hdl)
 {
        znode_t *zp;
        struct inode *ip;
        uint64_t mode;
        uint64_t parent;
-       sa_bulk_attr_t bulk[9];
+       uint64_t tmp_gen;
+       uint64_t links;
+       uint64_t z_uid, z_gid;
+       uint64_t atime[2], mtime[2], ctime[2];
+       uint64_t projid = ZFS_DEFAULT_PROJID;
+       sa_bulk_attr_t bulk[11];
        int count = 0;
 
-       ASSERT(zsb != NULL);
+       ASSERT(zfsvfs != NULL);
 
-       ip = new_inode(zsb->z_sb);
+       ip = new_inode(zfsvfs->z_sb);
        if (ip == NULL)
                return (NULL);
 
@@ -370,7 +539,6 @@ zfs_znode_alloc(zfs_sb_t *zsb, dmu_buf_t *db, int blksz,
        ASSERT(zp->z_dirlocks == NULL);
        ASSERT3P(zp->z_acl_cached, ==, NULL);
        ASSERT3P(zp->z_xattr_cached, ==, NULL);
-       ASSERT3P(zp->z_xattr_parent, ==, NULL);
        zp->z_moved = 0;
        zp->z_sa_hdl = NULL;
        zp->z_unlinked = 0;
@@ -380,46 +548,57 @@ zfs_znode_alloc(zfs_sb_t *zsb, dmu_buf_t *db, int blksz,
        zp->z_blksz = blksz;
        zp->z_seq = 0x7A4653;
        zp->z_sync_cnt = 0;
-       zp->z_is_zvol = B_FALSE;
        zp->z_is_mapped = B_FALSE;
        zp->z_is_ctldir = B_FALSE;
        zp->z_is_stale = B_FALSE;
 
-       zfs_znode_sa_init(zsb, zp, db, obj_type, hdl);
+       zfs_znode_sa_init(zfsvfs, zp, db, obj_type, hdl);
 
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zsb), NULL, &mode, 8);
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GEN(zsb), NULL, &zp->z_gen, 8);
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zsb), NULL, &zp->z_size, 8);
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zsb), NULL, &zp->z_links, 8);
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zsb), NULL,
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs), NULL, &mode, 8);
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GEN(zfsvfs), NULL, &tmp_gen, 8);
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs), NULL,
+           &zp->z_size, 8);
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zfsvfs), NULL, &links, 8);
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
            &zp->z_pflags, 8);
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_PARENT(zsb), NULL,
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_PARENT(zfsvfs), NULL,
            &parent, 8);
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zsb), NULL,
-           &zp->z_atime, 16);
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_UID(zsb), NULL, &zp->z_uid, 8);
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GID(zsb), NULL, &zp->z_gid, 8);
-
-       if (sa_bulk_lookup(zp->z_sa_hdl, bulk, count) != 0 || zp->z_gen == 0) {
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_UID(zfsvfs), NULL, &z_uid, 8);
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GID(zfsvfs), NULL, &z_gid, 8);
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zfsvfs), NULL, &atime, 16);
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, &mtime, 16);
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, &ctime, 16);
+
+       if (sa_bulk_lookup(zp->z_sa_hdl, bulk, count) != 0 || tmp_gen == 0 ||
+           (dmu_objset_projectquota_enabled(zfsvfs->z_os) &&
+           (zp->z_pflags & ZFS_PROJID) &&
+           sa_lookup(zp->z_sa_hdl, SA_ZPL_PROJID(zfsvfs), &projid, 8) != 0)) {
                if (hdl == NULL)
                        sa_handle_destroy(zp->z_sa_hdl);
-
+               zp->z_sa_hdl = NULL;
                goto error;
        }
 
-       zp->z_mode = mode;
+       zp->z_projid = projid;
+       zp->z_mode = ip->i_mode = mode;
+       ip->i_generation = (uint32_t)tmp_gen;
+       ip->i_blkbits = SPA_MINBLOCKSHIFT;
+       set_nlink(ip, (uint32_t)links);
+       zfs_uid_write(ip, z_uid);
+       zfs_gid_write(ip, z_gid);
+       zfs_set_inode_flags(zp, ip);
 
-       /*
-        * xattr znodes hold a reference on their unique parent
-        */
-       if (dip && zp->z_pflags & ZFS_XATTR) {
-               igrab(dip);
-               zp->z_xattr_parent = ITOZ(dip);
-       }
+       /* Cache the xattr parent id */
+       if (zp->z_pflags & ZFS_XATTR)
+               zp->z_xattr_parent = parent;
+
+       ZFS_TIME_DECODE(&ip->i_atime, atime);
+       ZFS_TIME_DECODE(&ip->i_mtime, mtime);
+       ZFS_TIME_DECODE(&ip->i_ctime, ctime);
 
        ip->i_ino = obj;
        zfs_inode_update(zp);
-       zfs_inode_set_ops(zsb, ip);
+       zfs_inode_set_ops(zfsvfs, ip);
 
        /*
         * The only way insert_inode_locked() can fail is if the ip->i_ino
@@ -431,86 +610,20 @@ zfs_znode_alloc(zfs_sb_t *zsb, dmu_buf_t *db, int blksz,
         */
        VERIFY3S(insert_inode_locked(ip), ==, 0);
 
-       mutex_enter(&zsb->z_znodes_lock);
-       list_insert_tail(&zsb->z_all_znodes, zp);
-       zsb->z_nr_znodes++;
+       mutex_enter(&zfsvfs->z_znodes_lock);
+       list_insert_tail(&zfsvfs->z_all_znodes, zp);
+       zfsvfs->z_nr_znodes++;
        membar_producer();
-       mutex_exit(&zsb->z_znodes_lock);
+       mutex_exit(&zfsvfs->z_znodes_lock);
 
        unlock_new_inode(ip);
        return (zp);
 
 error:
-       unlock_new_inode(ip);
        iput(ip);
        return (NULL);
 }
 
-void
-zfs_set_inode_flags(znode_t *zp, struct inode *ip)
-{
-       /*
-        * Linux and Solaris have different sets of file attributes, so we
-        * restrict this conversion to the intersection of the two.
-        */
-
-       if (zp->z_pflags & ZFS_IMMUTABLE)
-               ip->i_flags |= S_IMMUTABLE;
-       else
-               ip->i_flags &= ~S_IMMUTABLE;
-
-       if (zp->z_pflags & ZFS_APPENDONLY)
-               ip->i_flags |= S_APPEND;
-       else
-               ip->i_flags &= ~S_APPEND;
-}
-
-/*
- * Update the embedded inode given the znode.  We should work toward
- * eliminating this function as soon as possible by removing values
- * which are duplicated between the znode and inode.  If the generic
- * inode has the correct field it should be used, and the ZFS code
- * updated to access the inode.  This can be done incrementally.
- */
-void
-zfs_inode_update(znode_t *zp)
-{
-       zfs_sb_t        *zsb;
-       struct inode    *ip;
-       uint32_t        blksize;
-       uint64_t        atime[2], mtime[2], ctime[2];
-
-       ASSERT(zp != NULL);
-       zsb = ZTOZSB(zp);
-       ip = ZTOI(zp);
-
-       /* Skip .zfs control nodes which do not exist on disk. */
-       if (zfsctl_is_node(ip))
-               return;
-
-       sa_lookup(zp->z_sa_hdl, SA_ZPL_ATIME(zsb), &atime, 16);
-       sa_lookup(zp->z_sa_hdl, SA_ZPL_MTIME(zsb), &mtime, 16);
-       sa_lookup(zp->z_sa_hdl, SA_ZPL_CTIME(zsb), &ctime, 16);
-
-       spin_lock(&ip->i_lock);
-       ip->i_generation = zp->z_gen;
-       ip->i_uid = SUID_TO_KUID(zp->z_uid);
-       ip->i_gid = SGID_TO_KGID(zp->z_gid);
-       set_nlink(ip, zp->z_links);
-       ip->i_mode = zp->z_mode;
-       zfs_set_inode_flags(zp, ip);
-       ip->i_blkbits = SPA_MINBLOCKSHIFT;
-       dmu_object_size_from_db(sa_get_db(zp->z_sa_hdl), &blksize,
-           (u_longlong_t *)&ip->i_blocks);
-
-       ZFS_TIME_DECODE(&ip->i_atime, atime);
-       ZFS_TIME_DECODE(&ip->i_mtime, mtime);
-       ZFS_TIME_DECODE(&ip->i_ctime, ctime);
-
-       i_size_write(ip, zp->z_size);
-       spin_unlock(&ip->i_lock);
-}
-
 /*
  * Safely mark an inode dirty.  Inodes which are part of a read-only
  * file system or snapshot may not be dirtied.
@@ -518,9 +631,9 @@ zfs_inode_update(znode_t *zp)
 void
 zfs_mark_inode_dirty(struct inode *ip)
 {
-       zfs_sb_t *zsb = ITOZSB(ip);
+       zfsvfs_t *zfsvfs = ITOZSB(ip);
 
-       if (zfs_is_readonly(zsb) || dmu_objset_is_snapshot(zsb->z_os))
+       if (zfs_is_readonly(zfsvfs) || dmu_objset_is_snapshot(zfsvfs->z_os))
                return;
 
        mark_inode_dirty(ip);
@@ -552,32 +665,40 @@ zfs_mknode(znode_t *dzp, vattr_t *vap, dmu_tx_t *tx, cred_t *cr,
 {
        uint64_t        crtime[2], atime[2], mtime[2], ctime[2];
        uint64_t        mode, size, links, parent, pflags;
-       uint64_t        dzp_pflags = 0;
+       uint64_t        projid = ZFS_DEFAULT_PROJID;
        uint64_t        rdev = 0;
-       zfs_sb_t        *zsb = ZTOZSB(dzp);
+       zfsvfs_t        *zfsvfs = ZTOZSB(dzp);
        dmu_buf_t       *db;
-       timestruc_t     now;
+       inode_timespec_t now;
        uint64_t        gen, obj;
        int             bonuslen;
+       int             dnodesize;
        sa_handle_t     *sa_hdl;
        dmu_object_type_t obj_type;
        sa_bulk_attr_t  *sa_attrs;
        int             cnt = 0;
        zfs_acl_locator_cb_t locate = { 0 };
+       znode_hold_t    *zh;
 
-       if (zsb->z_replay) {
+       if (zfsvfs->z_replay) {
                obj = vap->va_nodeid;
                now = vap->va_ctime;            /* see zfs_replay_create() */
                gen = vap->va_nblocks;          /* ditto */
+               dnodesize = vap->va_fsid;       /* ditto */
        } else {
                obj = 0;
                gethrestime(&now);
                gen = dmu_tx_get_txg(tx);
+               dnodesize = dmu_objset_dnodesize(zfsvfs->z_os);
        }
 
-       obj_type = zsb->z_use_sa ? DMU_OT_SA : DMU_OT_ZNODE;
+       if (dnodesize == 0)
+               dnodesize = DNODE_MIN_SIZE;
+
+       obj_type = zfsvfs->z_use_sa ? DMU_OT_SA : DMU_OT_ZNODE;
+
        bonuslen = (obj_type == DMU_OT_SA) ?
-           DN_MAX_BONUSLEN : ZFS_OLD_ZNODE_PHYS_SIZE;
+           DN_BONUS_SIZE(dnodesize) : ZFS_OLD_ZNODE_PHYS_SIZE;
 
        /*
         * Create a new DMU object.
@@ -589,29 +710,29 @@ zfs_mknode(znode_t *dzp, vattr_t *vap, dmu_tx_t *tx, cred_t *cr,
         * assertions below.
         */
        if (S_ISDIR(vap->va_mode)) {
-               if (zsb->z_replay) {
-                       VERIFY0(zap_create_claim_norm(zsb->z_os, obj,
-                           zsb->z_norm, DMU_OT_DIRECTORY_CONTENTS,
-                           obj_type, bonuslen, tx));
+               if (zfsvfs->z_replay) {
+                       VERIFY0(zap_create_claim_norm_dnsize(zfsvfs->z_os, obj,
+                           zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
+                           obj_type, bonuslen, dnodesize, tx));
                } else {
-                       obj = zap_create_norm(zsb->z_os,
-                           zsb->z_norm, DMU_OT_DIRECTORY_CONTENTS,
-                           obj_type, bonuslen, tx);
+                       obj = zap_create_norm_dnsize(zfsvfs->z_os,
+                           zfsvfs->z_norm, DMU_OT_DIRECTORY_CONTENTS,
+                           obj_type, bonuslen, dnodesize, tx);
                }
        } else {
-               if (zsb->z_replay) {
-                       VERIFY0(dmu_object_claim(zsb->z_os, obj,
+               if (zfsvfs->z_replay) {
+                       VERIFY0(dmu_object_claim_dnsize(zfsvfs->z_os, obj,
                            DMU_OT_PLAIN_FILE_CONTENTS, 0,
-                           obj_type, bonuslen, tx));
+                           obj_type, bonuslen, dnodesize, tx));
                } else {
-                       obj = dmu_object_alloc(zsb->z_os,
+                       obj = dmu_object_alloc_dnsize(zfsvfs->z_os,
                            DMU_OT_PLAIN_FILE_CONTENTS, 0,
-                           obj_type, bonuslen, tx);
+                           obj_type, bonuslen, dnodesize, tx);
                }
        }
 
-       ZFS_OBJ_HOLD_ENTER(zsb, obj);
-       VERIFY(0 == sa_buf_hold(zsb->z_os, obj, NULL, &db));
+       zh = zfs_znode_hold_enter(zfsvfs, obj);
+       VERIFY0(sa_buf_hold(zfsvfs->z_os, obj, NULL, &db));
 
        /*
         * If this is the root, fix up the half-initialized parent pointer
@@ -619,27 +740,26 @@ zfs_mknode(znode_t *dzp, vattr_t *vap, dmu_tx_t *tx, cred_t *cr,
         */
        if (flag & IS_ROOT_NODE) {
                dzp->z_id = obj;
-       } else {
-               dzp_pflags = dzp->z_pflags;
        }
 
        /*
         * If parent is an xattr, so am I.
         */
-       if (dzp_pflags & ZFS_XATTR) {
+       if (dzp->z_pflags & ZFS_XATTR) {
                flag |= IS_XATTR;
        }
 
-       if (zsb->z_use_fuids)
+       if (zfsvfs->z_use_fuids)
                pflags = ZFS_ARCHIVE | ZFS_AV_MODIFIED;
        else
                pflags = 0;
 
        if (S_ISDIR(vap->va_mode)) {
                size = 2;               /* contents ("." and "..") */
-               links = (flag & (IS_ROOT_NODE | IS_XATTR)) ? 2 : 1;
+               links = 2;
        } else {
-               size = links = 0;
+               size = 0;
+               links = (flag & IS_TMPFILE) ? 0 : 1;
        }
 
        if (S_ISBLK(vap->va_mode) || S_ISCHR(vap->va_mode))
@@ -650,6 +770,23 @@ zfs_mknode(znode_t *dzp, vattr_t *vap, dmu_tx_t *tx, cred_t *cr,
        if (flag & IS_XATTR)
                pflags |= ZFS_XATTR;
 
+       if (S_ISREG(vap->va_mode) || S_ISDIR(vap->va_mode)) {
+               /*
+                * With ZFS_PROJID flag, we can easily know whether there is
+                * project ID stored on disk or not. See zfs_space_delta_cb().
+                */
+               if (obj_type != DMU_OT_ZNODE &&
+                   dmu_objset_projectquota_enabled(zfsvfs->z_os))
+                       pflags |= ZFS_PROJID;
+
+               /*
+                * Inherit project ID from parent if required.
+                */
+               projid = zfs_inherit_projid(dzp);
+               if (dzp->z_pflags & ZFS_PROJINHERIT)
+                       pflags |= ZFS_PROJINHERIT;
+       }
+
        /*
         * No execs denied will be deterimed when zfs_mode_compute() is called.
         */
@@ -673,7 +810,7 @@ zfs_mknode(znode_t *dzp, vattr_t *vap, dmu_tx_t *tx, cred_t *cr,
        }
 
        /* Now add in all of the "SA" attributes */
-       VERIFY(0 == sa_handle_get_from_db(zsb->z_os, db, NULL, SA_HDL_SHARED,
+       VERIFY(0 == sa_handle_get_from_db(zfsvfs->z_os, db, NULL, SA_HDL_SHARED,
            &sa_hdl));
 
        /*
@@ -682,77 +819,81 @@ zfs_mknode(znode_t *dzp, vattr_t *vap, dmu_tx_t *tx, cred_t *cr,
         * order for  DMU_OT_ZNODE is critical since it needs to be constructed
         * in the old znode_phys_t format.  Don't change this ordering
         */
-       sa_attrs = kmem_alloc(sizeof (sa_bulk_attr_t) * ZPL_END, KM_PUSHPAGE);
+       sa_attrs = kmem_alloc(sizeof (sa_bulk_attr_t) * ZPL_END, KM_SLEEP);
 
        if (obj_type == DMU_OT_ZNODE) {
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_ATIME(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_ATIME(zfsvfs),
                    NULL, &atime, 16);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_MTIME(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_MTIME(zfsvfs),
                    NULL, &mtime, 16);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_CTIME(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_CTIME(zfsvfs),
                    NULL, &ctime, 16);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_CRTIME(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_CRTIME(zfsvfs),
                    NULL, &crtime, 16);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_GEN(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_GEN(zfsvfs),
                    NULL, &gen, 8);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_MODE(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_MODE(zfsvfs),
                    NULL, &mode, 8);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_SIZE(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_SIZE(zfsvfs),
                    NULL, &size, 8);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_PARENT(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_PARENT(zfsvfs),
                    NULL, &parent, 8);
        } else {
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_MODE(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_MODE(zfsvfs),
                    NULL, &mode, 8);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_SIZE(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_SIZE(zfsvfs),
                    NULL, &size, 8);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_GEN(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_GEN(zfsvfs),
                    NULL, &gen, 8);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_UID(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_UID(zfsvfs),
                    NULL, &acl_ids->z_fuid, 8);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_GID(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_GID(zfsvfs),
                    NULL, &acl_ids->z_fgid, 8);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_PARENT(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_PARENT(zfsvfs),
                    NULL, &parent, 8);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_FLAGS(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_FLAGS(zfsvfs),
                    NULL, &pflags, 8);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_ATIME(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_ATIME(zfsvfs),
                    NULL, &atime, 16);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_MTIME(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_MTIME(zfsvfs),
                    NULL, &mtime, 16);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_CTIME(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_CTIME(zfsvfs),
                    NULL, &ctime, 16);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_CRTIME(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_CRTIME(zfsvfs),
                    NULL, &crtime, 16);
        }
 
-       SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_LINKS(zsb), NULL, &links, 8);
+       SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_LINKS(zfsvfs), NULL, &links, 8);
 
        if (obj_type == DMU_OT_ZNODE) {
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_XATTR(zsb), NULL,
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_XATTR(zfsvfs), NULL,
                    &empty_xattr, 8);
+       } else if (dmu_objset_projectquota_enabled(zfsvfs->z_os) &&
+           pflags & ZFS_PROJID) {
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_PROJID(zfsvfs),
+                   NULL, &projid, 8);
        }
        if (obj_type == DMU_OT_ZNODE ||
            (S_ISBLK(vap->va_mode) || S_ISCHR(vap->va_mode))) {
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_RDEV(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_RDEV(zfsvfs),
                    NULL, &rdev, 8);
        }
        if (obj_type == DMU_OT_ZNODE) {
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_FLAGS(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_FLAGS(zfsvfs),
                    NULL, &pflags, 8);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_UID(zsb), NULL,
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_UID(zfsvfs), NULL,
                    &acl_ids->z_fuid, 8);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_GID(zsb), NULL,
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_GID(zfsvfs), NULL,
                    &acl_ids->z_fgid, 8);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_PAD(zsb), NULL, pad,
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_PAD(zfsvfs), NULL, pad,
                    sizeof (uint64_t) * 4);
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_ZNODE_ACL(zsb), NULL,
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_ZNODE_ACL(zfsvfs), NULL,
                    &acl_phys, sizeof (zfs_acl_phys_t));
        } else if (acl_ids->z_aclp->z_version >= ZFS_ACL_VERSION_FUID) {
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_DACL_COUNT(zsb), NULL,
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_DACL_COUNT(zfsvfs), NULL,
                    &acl_ids->z_aclp->z_acl_count, 8);
                locate.cb_aclp = acl_ids->z_aclp;
-               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_DACL_ACES(zsb),
+               SA_ADD_BULK_ATTR(sa_attrs, cnt, SA_ZPL_DACL_ACES(zfsvfs),
                    zfs_acl_data_locator, &locate,
                    acl_ids->z_aclp->z_acl_bytes);
                mode = zfs_mode_compute(mode, acl_ids->z_aclp, &pflags,
@@ -762,8 +903,18 @@ zfs_mknode(znode_t *dzp, vattr_t *vap, dmu_tx_t *tx, cred_t *cr,
        VERIFY(sa_replace_all_by_template(sa_hdl, sa_attrs, cnt, tx) == 0);
 
        if (!(flag & IS_ROOT_NODE)) {
-               *zpp = zfs_znode_alloc(zsb, db, 0, obj_type, obj, sa_hdl,
-                   ZTOI(dzp));
+               /*
+                * The call to zfs_znode_alloc() may fail if memory is low
+                * via the call path: alloc_inode() -> inode_init_always() ->
+                * security_inode_alloc() -> inode_alloc_security().  Since
+                * the existing code is written such that zfs_mknode() can
+                * not fail retry until sufficient memory has been reclaimed.
+                */
+               do {
+                       *zpp = zfs_znode_alloc(zfsvfs, db, 0, obj_type, obj,
+                           sa_hdl);
+               } while (*zpp == NULL);
+
                VERIFY(*zpp != NULL);
                VERIFY(dzp != NULL);
        } else {
@@ -777,14 +928,16 @@ zfs_mknode(znode_t *dzp, vattr_t *vap, dmu_tx_t *tx, cred_t *cr,
        }
 
        (*zpp)->z_pflags = pflags;
-       (*zpp)->z_mode = mode;
+       (*zpp)->z_mode = ZTOI(*zpp)->i_mode = mode;
+       (*zpp)->z_dnodesize = dnodesize;
+       (*zpp)->z_projid = projid;
 
        if (obj_type == DMU_OT_ZNODE ||
            acl_ids->z_aclp->z_version < ZFS_ACL_VERSION_FUID) {
                VERIFY0(zfs_aclset_common(*zpp, acl_ids->z_aclp, cr, tx));
        }
        kmem_free(sa_attrs, sizeof (sa_bulk_attr_t) * ZPL_END);
-       ZFS_OBJ_HOLD_EXIT(zsb, obj);
+       zfs_znode_hold_exit(zfsvfs, zh);
 }
 
 /*
@@ -795,6 +948,7 @@ void
 zfs_xvattr_set(znode_t *zp, xvattr_t *xvap, dmu_tx_t *tx)
 {
        xoptattr_t *xoap;
+       boolean_t update_inode = B_FALSE;
 
        xoap = xva_getxoptattr(xvap);
        ASSERT(xoap);
@@ -830,6 +984,8 @@ zfs_xvattr_set(znode_t *zp, xvattr_t *xvap, dmu_tx_t *tx)
                ZFS_ATTR_SET(zp, ZFS_IMMUTABLE, xoap->xoa_immutable,
                    zp->z_pflags, tx);
                XVA_SET_RTN(xvap, XAT_IMMUTABLE);
+
+               update_inode = B_TRUE;
        }
        if (XVA_ISSET_REQ(xvap, XAT_NOUNLINK)) {
                ZFS_ATTR_SET(zp, ZFS_NOUNLINK, xoap->xoa_nounlink,
@@ -840,6 +996,8 @@ zfs_xvattr_set(znode_t *zp, xvattr_t *xvap, dmu_tx_t *tx)
                ZFS_ATTR_SET(zp, ZFS_APPENDONLY, xoap->xoa_appendonly,
                    zp->z_pflags, tx);
                XVA_SET_RTN(xvap, XAT_APPENDONLY);
+
+               update_inode = B_TRUE;
        }
        if (XVA_ISSET_REQ(xvap, XAT_NODUMP)) {
                ZFS_ATTR_SET(zp, ZFS_NODUMP, xoap->xoa_nodump,
@@ -880,25 +1038,34 @@ zfs_xvattr_set(znode_t *zp, xvattr_t *xvap, dmu_tx_t *tx)
                    zp->z_pflags, tx);
                XVA_SET_RTN(xvap, XAT_SPARSE);
        }
+       if (XVA_ISSET_REQ(xvap, XAT_PROJINHERIT)) {
+               ZFS_ATTR_SET(zp, ZFS_PROJINHERIT, xoap->xoa_projinherit,
+                   zp->z_pflags, tx);
+               XVA_SET_RTN(xvap, XAT_PROJINHERIT);
+       }
+
+       if (update_inode)
+               zfs_set_inode_flags(zp, ZTOI(zp));
 }
 
 int
-zfs_zget(zfs_sb_t *zsb, uint64_t obj_num, znode_t **zpp)
+zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp)
 {
        dmu_object_info_t doi;
        dmu_buf_t       *db;
        znode_t         *zp;
+       znode_hold_t    *zh;
        int err;
        sa_handle_t     *hdl;
 
        *zpp = NULL;
 
 again:
-       ZFS_OBJ_HOLD_ENTER(zsb, obj_num);
+       zh = zfs_znode_hold_enter(zfsvfs, obj_num);
 
-       err = sa_buf_hold(zsb->z_os, obj_num, NULL, &db);
+       err = sa_buf_hold(zfsvfs->z_os, obj_num, NULL, &db);
        if (err) {
-               ZFS_OBJ_HOLD_EXIT(zsb, obj_num);
+               zfs_znode_hold_exit(zfsvfs, zh);
                return (err);
        }
 
@@ -908,7 +1075,7 @@ again:
            (doi.doi_bonus_type == DMU_OT_ZNODE &&
            doi.doi_bonus_size < sizeof (znode_phys_t)))) {
                sa_buf_rele(db, NULL);
-               ZFS_OBJ_HOLD_EXIT(zsb, obj_num);
+               zfs_znode_hold_exit(zfsvfs, zh);
                return (SET_ERROR(EINVAL));
        }
 
@@ -927,35 +1094,33 @@ again:
 
                mutex_enter(&zp->z_lock);
                ASSERT3U(zp->z_id, ==, obj_num);
-               if (zp->z_unlinked) {
-                       err = SET_ERROR(ENOENT);
-               } else {
-                       /*
-                        * If igrab() returns NULL the VFS has independently
-                        * determined the inode should be evicted and has
-                        * called iput_final() to start the eviction process.
-                        * The SA handle is still valid but because the VFS
-                        * requires that the eviction succeed we must drop
-                        * our locks and references to allow the eviction to
-                        * complete.  The zfs_zget() may then be retried.
-                        *
-                        * This unlikely case could be optimized by registering
-                        * a sops->drop_inode() callback.  The callback would
-                        * need to detect the active SA hold thereby informing
-                        * the VFS that this inode should not be evicted.
-                        */
-                       if (igrab(ZTOI(zp)) == NULL) {
-                               mutex_exit(&zp->z_lock);
-                               sa_buf_rele(db, NULL);
-                               ZFS_OBJ_HOLD_EXIT(zsb, obj_num);
-                               goto again;
-                       }
-                       *zpp = zp;
-                       err = 0;
+               /*
+                * If igrab() returns NULL the VFS has independently
+                * determined the inode should be evicted and has
+                * called iput_final() to start the eviction process.
+                * The SA handle is still valid but because the VFS
+                * requires that the eviction succeed we must drop
+                * our locks and references to allow the eviction to
+                * complete.  The zfs_zget() may then be retried.
+                *
+                * This unlikely case could be optimized by registering
+                * a sops->drop_inode() callback.  The callback would
+                * need to detect the active SA hold thereby informing
+                * the VFS that this inode should not be evicted.
+                */
+               if (igrab(ZTOI(zp)) == NULL) {
+                       mutex_exit(&zp->z_lock);
+                       sa_buf_rele(db, NULL);
+                       zfs_znode_hold_exit(zfsvfs, zh);
+                       /* inode might need this to finish evict */
+                       cond_resched();
+                       goto again;
                }
+               *zpp = zp;
+               err = 0;
                mutex_exit(&zp->z_lock);
                sa_buf_rele(db, NULL);
-               ZFS_OBJ_HOLD_EXIT(zsb, obj_num);
+               zfs_znode_hold_exit(zfsvfs, zh);
                return (err);
        }
 
@@ -969,31 +1134,46 @@ again:
         * if zfs_znode_alloc() fails it will drop the hold on the
         * bonus buffer.
         */
-       zp = zfs_znode_alloc(zsb, db, doi.doi_data_block_size,
-           doi.doi_bonus_type, obj_num, NULL, NULL);
+       zp = zfs_znode_alloc(zfsvfs, db, doi.doi_data_block_size,
+           doi.doi_bonus_type, obj_num, NULL);
        if (zp == NULL) {
                err = SET_ERROR(ENOENT);
        } else {
                *zpp = zp;
        }
-       ZFS_OBJ_HOLD_EXIT(zsb, obj_num);
+       zfs_znode_hold_exit(zfsvfs, zh);
        return (err);
 }
 
 int
 zfs_rezget(znode_t *zp)
 {
-       zfs_sb_t *zsb = ZTOZSB(zp);
+       zfsvfs_t *zfsvfs = ZTOZSB(zp);
        dmu_object_info_t doi;
        dmu_buf_t *db;
        uint64_t obj_num = zp->z_id;
        uint64_t mode;
-       sa_bulk_attr_t bulk[8];
+       uint64_t links;
+       sa_bulk_attr_t bulk[10];
        int err;
        int count = 0;
        uint64_t gen;
+       uint64_t z_uid, z_gid;
+       uint64_t atime[2], mtime[2], ctime[2];
+       uint64_t projid = ZFS_DEFAULT_PROJID;
+       znode_hold_t *zh;
+
+       /*
+        * skip ctldir, otherwise they will always get invalidated. This will
+        * cause funny behaviour for the mounted snapdirs. Especially for
+        * Linux >= 3.18, d_invalidate will detach the mountpoint and prevent
+        * anyone automount it again as long as someone is still using the
+        * detached mount.
+        */
+       if (zp->z_is_ctldir)
+               return (0);
 
-       ZFS_OBJ_HOLD_ENTER(zsb, obj_num);
+       zh = zfs_znode_hold_enter(zfsvfs, obj_num);
 
        mutex_enter(&zp->z_acl_lock);
        if (zp->z_acl_cached) {
@@ -1007,17 +1187,12 @@ zfs_rezget(znode_t *zp)
                nvlist_free(zp->z_xattr_cached);
                zp->z_xattr_cached = NULL;
        }
-
-       if (zp->z_xattr_parent) {
-               iput(ZTOI(zp->z_xattr_parent));
-               zp->z_xattr_parent = NULL;
-       }
        rw_exit(&zp->z_xattr_lock);
 
        ASSERT(zp->z_sa_hdl == NULL);
-       err = sa_buf_hold(zsb->z_os, obj_num, NULL, &db);
+       err = sa_buf_hold(zfsvfs->z_os, obj_num, NULL, &db);
        if (err) {
-               ZFS_OBJ_HOLD_EXIT(zsb, obj_num);
+               zfs_znode_hold_exit(zfsvfs, zh);
                return (err);
        }
 
@@ -1027,49 +1202,86 @@ zfs_rezget(znode_t *zp)
            (doi.doi_bonus_type == DMU_OT_ZNODE &&
            doi.doi_bonus_size < sizeof (znode_phys_t)))) {
                sa_buf_rele(db, NULL);
-               ZFS_OBJ_HOLD_EXIT(zsb, obj_num);
+               zfs_znode_hold_exit(zfsvfs, zh);
                return (SET_ERROR(EINVAL));
        }
 
-       zfs_znode_sa_init(zsb, zp, db, doi.doi_bonus_type, NULL);
+       zfs_znode_sa_init(zfsvfs, zp, db, doi.doi_bonus_type, NULL);
 
        /* reload cached values */
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GEN(zsb), NULL,
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GEN(zfsvfs), NULL,
            &gen, sizeof (gen));
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zsb), NULL,
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs), NULL,
            &zp->z_size, sizeof (zp->z_size));
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zsb), NULL,
-           &zp->z_links, sizeof (zp->z_links));
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zsb), NULL,
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_LINKS(zfsvfs), NULL,
+           &links, sizeof (links));
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs), NULL,
            &zp->z_pflags, sizeof (zp->z_pflags));
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zsb), NULL,
-           &zp->z_atime, sizeof (zp->z_atime));
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_UID(zsb), NULL,
-           &zp->z_uid, sizeof (zp->z_uid));
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GID(zsb), NULL,
-           &zp->z_gid, sizeof (zp->z_gid));
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zsb), NULL,
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_UID(zfsvfs), NULL,
+           &z_uid, sizeof (z_uid));
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_GID(zfsvfs), NULL,
+           &z_gid, sizeof (z_gid));
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MODE(zfsvfs), NULL,
            &mode, sizeof (mode));
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_ATIME(zfsvfs), NULL,
+           &atime, 16);
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL,
+           &mtime, 16);
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL,
+           &ctime, 16);
 
        if (sa_bulk_lookup(zp->z_sa_hdl, bulk, count)) {
                zfs_znode_dmu_fini(zp);
-               ZFS_OBJ_HOLD_EXIT(zsb, obj_num);
+               zfs_znode_hold_exit(zfsvfs, zh);
                return (SET_ERROR(EIO));
        }
 
-       zp->z_mode = mode;
+       if (dmu_objset_projectquota_enabled(zfsvfs->z_os)) {
+               err = sa_lookup(zp->z_sa_hdl, SA_ZPL_PROJID(zfsvfs),
+                   &projid, 8);
+               if (err != 0 && err != ENOENT) {
+                       zfs_znode_dmu_fini(zp);
+                       zfs_znode_hold_exit(zfsvfs, zh);
+                       return (SET_ERROR(err));
+               }
+       }
+
+       zp->z_projid = projid;
+       zp->z_mode = ZTOI(zp)->i_mode = mode;
+       zfs_uid_write(ZTOI(zp), z_uid);
+       zfs_gid_write(ZTOI(zp), z_gid);
+
+       ZFS_TIME_DECODE(&ZTOI(zp)->i_atime, atime);
+       ZFS_TIME_DECODE(&ZTOI(zp)->i_mtime, mtime);
+       ZFS_TIME_DECODE(&ZTOI(zp)->i_ctime, ctime);
 
-       if (gen != zp->z_gen) {
+       if (gen != ZTOI(zp)->i_generation) {
                zfs_znode_dmu_fini(zp);
-               ZFS_OBJ_HOLD_EXIT(zsb, obj_num);
+               zfs_znode_hold_exit(zfsvfs, zh);
                return (SET_ERROR(EIO));
        }
 
-       zp->z_unlinked = (zp->z_links == 0);
+       set_nlink(ZTOI(zp), (uint32_t)links);
+       zfs_set_inode_flags(zp, ZTOI(zp));
+
        zp->z_blksz = doi.doi_data_block_size;
+       zp->z_atime_dirty = 0;
        zfs_inode_update(zp);
 
-       ZFS_OBJ_HOLD_EXIT(zsb, obj_num);
+       /*
+        * If the file has zero links, then it has been unlinked on the send
+        * side and it must be in the received unlinked set.
+        * We call zfs_znode_dmu_fini() now to prevent any accesses to the
+        * stale data and to prevent automatical removal of the file in
+        * zfs_zinactive().  The file will be removed either when it is removed
+        * on the send side and the next incremental stream is received or
+        * when the unlinked set gets processed.
+        */
+       zp->z_unlinked = (ZTOI(zp)->i_nlink == 0);
+       if (zp->z_unlinked)
+               zfs_znode_dmu_fini(zp);
+
+       zfs_znode_hold_exit(zfsvfs, zh);
 
        return (0);
 }
@@ -1077,65 +1289,60 @@ zfs_rezget(znode_t *zp)
 void
 zfs_znode_delete(znode_t *zp, dmu_tx_t *tx)
 {
-       zfs_sb_t *zsb = ZTOZSB(zp);
-       objset_t *os = zsb->z_os;
+       zfsvfs_t *zfsvfs = ZTOZSB(zp);
+       objset_t *os = zfsvfs->z_os;
        uint64_t obj = zp->z_id;
        uint64_t acl_obj = zfs_external_acl(zp);
+       znode_hold_t *zh;
 
-       ZFS_OBJ_HOLD_ENTER(zsb, obj);
+       zh = zfs_znode_hold_enter(zfsvfs, obj);
        if (acl_obj) {
                VERIFY(!zp->z_is_sa);
                VERIFY(0 == dmu_object_free(os, acl_obj, tx));
        }
        VERIFY(0 == dmu_object_free(os, obj, tx));
        zfs_znode_dmu_fini(zp);
-       ZFS_OBJ_HOLD_EXIT(zsb, obj);
+       zfs_znode_hold_exit(zfsvfs, zh);
 }
 
 void
 zfs_zinactive(znode_t *zp)
 {
-       zfs_sb_t *zsb = ZTOZSB(zp);
+       zfsvfs_t *zfsvfs = ZTOZSB(zp);
        uint64_t z_id = zp->z_id;
-       boolean_t drop_mutex = 0;
+       znode_hold_t *zh;
 
        ASSERT(zp->z_sa_hdl);
 
        /*
         * Don't allow a zfs_zget() while were trying to release this znode.
-        *
-        * Linux allows direct memory reclaim which means that any KM_SLEEP
-        * allocation may trigger inode eviction.  This can lead to a deadlock
-        * through the ->shrink_icache_memory()->evict()->zfs_inactive()->
-        * zfs_zinactive() call path.  To avoid this deadlock the process
-        * must not reacquire the mutex when it is already holding it.
         */
-       if (!ZFS_OBJ_HOLD_OWNED(zsb, z_id)) {
-               ZFS_OBJ_HOLD_ENTER(zsb, z_id);
-               drop_mutex = 1;
-       }
+       zh = zfs_znode_hold_enter(zfsvfs, z_id);
 
        mutex_enter(&zp->z_lock);
 
        /*
-        * If this was the last reference to a file with no links,
-        * remove the file from the file system.
+        * If this was the last reference to a file with no links, remove
+        * the file from the file system unless the file system is mounted
+        * read-only.  That can happen, for example, if the file system was
+        * originally read-write, the file was opened, then unlinked and
+        * the file system was made read-only before the file was finally
+        * closed.  The file will remain in the unlinked set.
         */
        if (zp->z_unlinked) {
-               mutex_exit(&zp->z_lock);
-
-               if (drop_mutex)
-                       ZFS_OBJ_HOLD_EXIT(zsb, z_id);
-
-               zfs_rmnode(zp);
-               return;
+               ASSERT(!zfsvfs->z_issnap);
+               if (!zfs_is_readonly(zfsvfs) && !zfs_unlink_suspend_progress) {
+                       mutex_exit(&zp->z_lock);
+                       zfs_znode_hold_exit(zfsvfs, zh);
+                       zfs_rmnode(zp);
+                       return;
+               }
        }
 
        mutex_exit(&zp->z_lock);
        zfs_znode_dmu_fini(zp);
 
-       if (drop_mutex)
-               ZFS_OBJ_HOLD_EXIT(zsb, z_id);
+       zfs_znode_hold_exit(zfsvfs, zh);
 }
 
 static inline int
@@ -1150,81 +1357,32 @@ zfs_compare_timespec(struct timespec *t1, struct timespec *t2)
        return (t1->tv_nsec - t2->tv_nsec);
 }
 
-/*
- *  Determine whether the znode's atime must be updated.  The logic mostly
- *  duplicates the Linux kernel's relatime_need_update() functionality.
- *  This function is only called if the underlying filesystem actually has
- *  atime updates enabled.
- */
-static inline boolean_t
-zfs_atime_need_update(znode_t *zp, timestruc_t *now)
-{
-       if (!ZTOZSB(zp)->z_relatime)
-               return (B_TRUE);
-
-       /*
-        * In relatime mode, only update the atime if the previous atime
-        * is earlier than either the ctime or mtime or if at least a day
-        * has passed since the last update of atime.
-        */
-       if (zfs_compare_timespec(&ZTOI(zp)->i_mtime, &ZTOI(zp)->i_atime) >= 0)
-               return (B_TRUE);
-
-       if (zfs_compare_timespec(&ZTOI(zp)->i_ctime, &ZTOI(zp)->i_atime) >= 0)
-               return (B_TRUE);
-
-       if ((long)now->tv_sec - ZTOI(zp)->i_atime.tv_sec >= 24*60*60)
-               return (B_TRUE);
-
-       return (B_FALSE);
-}
-
 /*
  * Prepare to update znode time stamps.
  *
  *     IN:     zp      - znode requiring timestamp update
- *             flag    - ATTR_MTIME, ATTR_CTIME, ATTR_ATIME flags
- *             have_tx - true of caller is creating a new txg
+ *             flag    - ATTR_MTIME, ATTR_CTIME flags
  *
- *     OUT:    zp      - new atime (via underlying inode's i_atime)
+ *     OUT:    zp      - z_seq
  *             mtime   - new mtime
  *             ctime   - new ctime
  *
- * NOTE: The arguments are somewhat redundant.  The following condition
- * is always true:
- *
- *             have_tx == !(flag & ATTR_ATIME)
+ *     Note: We don't update atime here, because we rely on Linux VFS to do
+ *     atime updating.
  */
 void
 zfs_tstamp_update_setup(znode_t *zp, uint_t flag, uint64_t mtime[2],
-    uint64_t ctime[2], boolean_t have_tx)
+    uint64_t ctime[2])
 {
-       timestruc_t     now;
+       inode_timespec_t now;
 
-       ASSERT(have_tx == !(flag & ATTR_ATIME));
        gethrestime(&now);
 
-       /*
-        * NOTE: The following test intentionally does not update z_atime_dirty
-        * in the case where an ATIME update has been requested but for which
-        * the update is omitted due to relatime logic.  The rationale being
-        * that if the flag was set somewhere else, we should leave it alone
-        * here.
-        */
-       if (flag & ATTR_ATIME) {
-               if (zfs_atime_need_update(zp, &now)) {
-                       ZFS_TIME_ENCODE(&now, zp->z_atime);
-                       ZTOI(zp)->i_atime.tv_sec = zp->z_atime[0];
-                       ZTOI(zp)->i_atime.tv_nsec = zp->z_atime[1];
-                       zp->z_atime_dirty = 1;
-               }
-       } else {
-               zp->z_atime_dirty = 0;
-               zp->z_seq++;
-       }
+       zp->z_seq++;
 
        if (flag & ATTR_MTIME) {
                ZFS_TIME_ENCODE(&now, mtime);
+               ZFS_TIME_DECODE(&(ZTOI(zp)->i_mtime), mtime);
                if (ZTOZSB(zp)->z_use_fuids) {
                        zp->z_pflags |= (ZFS_ARCHIVE |
                            ZFS_AV_MODIFIED);
@@ -1233,6 +1391,7 @@ zfs_tstamp_update_setup(znode_t *zp, uint_t flag, uint64_t mtime[2],
 
        if (flag & ATTR_CTIME) {
                ZFS_TIME_ENCODE(&now, ctime);
+               ZFS_TIME_DECODE(&(ZTOI(zp)->i_ctime), ctime);
                if (ZTOZSB(zp)->z_use_fuids)
                        zp->z_pflags |= ZFS_ARCHIVE;
        }
@@ -1280,40 +1439,45 @@ zfs_grow_blocksize(znode_t *zp, uint64_t size, dmu_tx_t *tx)
  *     IN:     zp      - znode of file to free data in.
  *             end     - new end-of-file
  *
- *     RETURN: 0 on success, error code on failure
+ *     RETURN: 0 on success, error code on failure
  */
 static int
 zfs_extend(znode_t *zp, uint64_t end)
 {
-       zfs_sb_t *zsb = ZTOZSB(zp);
+       zfsvfs_t *zfsvfs = ZTOZSB(zp);
        dmu_tx_t *tx;
-       rl_t *rl;
+       locked_range_t *lr;
        uint64_t newblksz;
        int error;
 
        /*
         * We will change zp_size, lock the whole file.
         */
-       rl = zfs_range_lock(zp, 0, UINT64_MAX, RL_WRITER);
+       lr = rangelock_enter(&zp->z_rangelock, 0, UINT64_MAX, RL_WRITER);
 
        /*
         * Nothing to do if file already at desired length.
         */
        if (end <= zp->z_size) {
-               zfs_range_unlock(rl);
+               rangelock_exit(lr);
                return (0);
        }
-       tx = dmu_tx_create(zsb->z_os);
+       tx = dmu_tx_create(zfsvfs->z_os);
        dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
        zfs_sa_upgrade_txholds(tx, zp);
        if (end > zp->z_blksz &&
-           (!ISP2(zp->z_blksz) || zp->z_blksz < zsb->z_max_blksz)) {
+           (!ISP2(zp->z_blksz) || zp->z_blksz < zfsvfs->z_max_blksz)) {
                /*
                 * We are growing the file past the current block size.
                 */
                if (zp->z_blksz > ZTOZSB(zp)->z_max_blksz) {
+                       /*
+                        * File's blocksize is already larger than the
+                        * "recordsize" property.  Only let it grow to
+                        * the next power of 2.
+                        */
                        ASSERT(!ISP2(zp->z_blksz));
-                       newblksz = MIN(end, SPA_MAXBLOCKSIZE);
+                       newblksz = MIN(end, 1 << highbit64(zp->z_blksz));
                } else {
                        newblksz = MIN(end, ZTOZSB(zp)->z_max_blksz);
                }
@@ -1325,7 +1489,7 @@ zfs_extend(znode_t *zp, uint64_t end)
        error = dmu_tx_assign(tx, TXG_WAIT);
        if (error) {
                dmu_tx_abort(tx);
-               zfs_range_unlock(rl);
+               rangelock_exit(lr);
                return (error);
        }
 
@@ -1337,13 +1501,56 @@ zfs_extend(znode_t *zp, uint64_t end)
        VERIFY(0 == sa_update(zp->z_sa_hdl, SA_ZPL_SIZE(ZTOZSB(zp)),
            &zp->z_size, sizeof (zp->z_size), tx));
 
-       zfs_range_unlock(rl);
+       rangelock_exit(lr);
 
        dmu_tx_commit(tx);
 
        return (0);
 }
 
+/*
+ * zfs_zero_partial_page - Modeled after update_pages() but
+ * with different arguments and semantics for use by zfs_freesp().
+ *
+ * Zeroes a piece of a single page cache entry for zp at offset
+ * start and length len.
+ *
+ * Caller must acquire a range lock on the file for the region
+ * being zeroed in order that the ARC and page cache stay in sync.
+ */
+static void
+zfs_zero_partial_page(znode_t *zp, uint64_t start, uint64_t len)
+{
+       struct address_space *mp = ZTOI(zp)->i_mapping;
+       struct page *pp;
+       int64_t off;
+       void *pb;
+
+       ASSERT((start & PAGE_MASK) == ((start + len - 1) & PAGE_MASK));
+
+       off = start & (PAGE_SIZE - 1);
+       start &= PAGE_MASK;
+
+       pp = find_lock_page(mp, start >> PAGE_SHIFT);
+       if (pp) {
+               if (mapping_writably_mapped(mp))
+                       flush_dcache_page(pp);
+
+               pb = kmap(pp);
+               bzero(pb + off, len);
+               kunmap(pp);
+
+               if (mapping_writably_mapped(mp))
+                       flush_dcache_page(pp);
+
+               mark_page_accessed(pp);
+               SetPageUptodate(pp);
+               ClearPageError(pp);
+               unlock_page(pp);
+               put_page(pp);
+       }
+}
+
 /*
  * Free space in a file.
  *
@@ -1351,34 +1558,75 @@ zfs_extend(znode_t *zp, uint64_t end)
  *             off     - start of section to free.
  *             len     - length of section to free.
  *
- *     RETURN: 0 on success, error code on failure
+ *     RETURN: 0 on success, error code on failure
  */
 static int
 zfs_free_range(znode_t *zp, uint64_t off, uint64_t len)
 {
-       zfs_sb_t *zsb = ZTOZSB(zp);
-       rl_t *rl;
+       zfsvfs_t *zfsvfs = ZTOZSB(zp);
+       locked_range_t *lr;
        int error;
 
        /*
         * Lock the range being freed.
         */
-       rl = zfs_range_lock(zp, off, len, RL_WRITER);
+       lr = rangelock_enter(&zp->z_rangelock, off, len, RL_WRITER);
 
        /*
         * Nothing to do if file already at desired length.
         */
        if (off >= zp->z_size) {
-               zfs_range_unlock(rl);
+               rangelock_exit(lr);
                return (0);
        }
 
        if (off + len > zp->z_size)
                len = zp->z_size - off;
 
-       error = dmu_free_long_range(zsb->z_os, zp->z_id, off, len);
+       error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, off, len);
 
-       zfs_range_unlock(rl);
+       /*
+        * Zero partial page cache entries.  This must be done under a
+        * range lock in order to keep the ARC and page cache in sync.
+        */
+       if (zp->z_is_mapped) {
+               loff_t first_page, last_page, page_len;
+               loff_t first_page_offset, last_page_offset;
+
+               /* first possible full page in hole */
+               first_page = (off + PAGE_SIZE - 1) >> PAGE_SHIFT;
+               /* last page of hole */
+               last_page = (off + len) >> PAGE_SHIFT;
+
+               /* offset of first_page */
+               first_page_offset = first_page << PAGE_SHIFT;
+               /* offset of last_page */
+               last_page_offset = last_page << PAGE_SHIFT;
+
+               /* truncate whole pages */
+               if (last_page_offset > first_page_offset) {
+                       truncate_inode_pages_range(ZTOI(zp)->i_mapping,
+                           first_page_offset, last_page_offset - 1);
+               }
+
+               /* truncate sub-page ranges */
+               if (first_page > last_page) {
+                       /* entire punched area within a single page */
+                       zfs_zero_partial_page(zp, off, len);
+               } else {
+                       /* beginning of punched area at the end of a page */
+                       page_len  = first_page_offset - off;
+                       if (page_len > 0)
+                               zfs_zero_partial_page(zp, off, page_len);
+
+                       /* end of punched area at the beginning of a page */
+                       page_len = off + len - last_page_offset;
+                       if (page_len > 0)
+                               zfs_zero_partial_page(zp, last_page_offset,
+                                   page_len);
+               }
+       }
+       rangelock_exit(lr);
 
        return (error);
 }
@@ -1389,14 +1637,14 @@ zfs_free_range(znode_t *zp, uint64_t off, uint64_t len)
  *     IN:     zp      - znode of file to free data in.
  *             end     - new end-of-file.
  *
- *     RETURN: 0 on success, error code on failure
+ *     RETURN: 0 on success, error code on failure
  */
 static int
 zfs_trunc(znode_t *zp, uint64_t end)
 {
-       zfs_sb_t *zsb = ZTOZSB(zp);
+       zfsvfs_t *zfsvfs = ZTOZSB(zp);
        dmu_tx_t *tx;
-       rl_t *rl;
+       locked_range_t *lr;
        int error;
        sa_bulk_attr_t bulk[2];
        int count = 0;
@@ -1404,45 +1652,46 @@ zfs_trunc(znode_t *zp, uint64_t end)
        /*
         * We will change zp_size, lock the whole file.
         */
-       rl = zfs_range_lock(zp, 0, UINT64_MAX, RL_WRITER);
+       lr = rangelock_enter(&zp->z_rangelock, 0, UINT64_MAX, RL_WRITER);
 
        /*
         * Nothing to do if file already at desired length.
         */
        if (end >= zp->z_size) {
-               zfs_range_unlock(rl);
+               rangelock_exit(lr);
                return (0);
        }
 
-       error = dmu_free_long_range(zsb->z_os, zp->z_id, end,  -1);
+       error = dmu_free_long_range(zfsvfs->z_os, zp->z_id, end,
+           DMU_OBJECT_END);
        if (error) {
-               zfs_range_unlock(rl);
+               rangelock_exit(lr);
                return (error);
        }
-       tx = dmu_tx_create(zsb->z_os);
+       tx = dmu_tx_create(zfsvfs->z_os);
        dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
        zfs_sa_upgrade_txholds(tx, zp);
+       dmu_tx_mark_netfree(tx);
        error = dmu_tx_assign(tx, TXG_WAIT);
        if (error) {
                dmu_tx_abort(tx);
-               zfs_range_unlock(rl);
+               rangelock_exit(lr);
                return (error);
        }
 
        zp->z_size = end;
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zsb),
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_SIZE(zfsvfs),
            NULL, &zp->z_size, sizeof (zp->z_size));
 
        if (end == 0) {
                zp->z_pflags &= ~ZFS_SPARSE;
-               SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zsb),
+               SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs),
                    NULL, &zp->z_pflags, 8);
        }
        VERIFY(sa_bulk_update(zp->z_sa_hdl, bulk, count, tx) == 0);
 
        dmu_tx_commit(tx);
-
-       zfs_range_unlock(rl);
+       rangelock_exit(lr);
 
        return (0);
 }
@@ -1456,22 +1705,21 @@ zfs_trunc(znode_t *zp, uint64_t end)
  *             flag    - current file open mode flags.
  *             log     - TRUE if this action should be logged
  *
- *     RETURN: 0 on success, error code on failure
+ *     RETURN: 0 on success, error code on failure
  */
 int
 zfs_freesp(znode_t *zp, uint64_t off, uint64_t len, int flag, boolean_t log)
 {
-       struct inode *ip = ZTOI(zp);
        dmu_tx_t *tx;
-       zfs_sb_t *zsb = ZTOZSB(zp);
-       zilog_t *zilog = zsb->z_log;
+       zfsvfs_t *zfsvfs = ZTOZSB(zp);
+       zilog_t *zilog = zfsvfs->z_log;
        uint64_t mode;
        uint64_t mtime[2], ctime[2];
        sa_bulk_attr_t bulk[3];
        int count = 0;
        int error;
 
-       if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_MODE(zsb), &mode,
+       if ((error = sa_lookup(zp->z_sa_hdl, SA_ZPL_MODE(zfsvfs), &mode,
            sizeof (mode))) != 0)
                return (error);
 
@@ -1479,17 +1727,7 @@ zfs_freesp(znode_t *zp, uint64_t off, uint64_t len, int flag, boolean_t log)
                error =  zfs_extend(zp, off+len);
                if (error == 0 && log)
                        goto log;
-               else
-                       return (error);
-       }
-
-       /*
-        * Check for any locks in the region to be freed.
-        */
-       if (ip->i_flock && mandatory_lock(ip)) {
-               uint64_t length = (len ? len : zp->z_size - off);
-               if (!lock_may_write(ip, off, length))
-                       return (SET_ERROR(EAGAIN));
+               goto out;
        }
 
        if (len == 0) {
@@ -1500,41 +1738,53 @@ zfs_freesp(znode_t *zp, uint64_t off, uint64_t len, int flag, boolean_t log)
                        error = zfs_extend(zp, off+len);
        }
        if (error || !log)
-               return (error);
+               goto out;
 log:
-       tx = dmu_tx_create(zsb->z_os);
+       tx = dmu_tx_create(zfsvfs->z_os);
        dmu_tx_hold_sa(tx, zp->z_sa_hdl, B_FALSE);
        zfs_sa_upgrade_txholds(tx, zp);
        error = dmu_tx_assign(tx, TXG_WAIT);
        if (error) {
                dmu_tx_abort(tx);
-               return (error);
+               goto out;
        }
 
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zsb), NULL, mtime, 16);
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zsb), NULL, ctime, 16);
-       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zsb),
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_MTIME(zfsvfs), NULL, mtime, 16);
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_CTIME(zfsvfs), NULL, ctime, 16);
+       SA_ADD_BULK_ATTR(bulk, count, SA_ZPL_FLAGS(zfsvfs),
            NULL, &zp->z_pflags, 8);
-       zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime, B_TRUE);
+       zfs_tstamp_update_setup(zp, CONTENT_MODIFIED, mtime, ctime);
        error = sa_bulk_update(zp->z_sa_hdl, bulk, count, tx);
        ASSERT(error == 0);
 
        zfs_log_truncate(zilog, tx, TX_TRUNCATE, zp, off, len);
 
        dmu_tx_commit(tx);
+
        zfs_inode_update(zp);
-       return (0);
+       error = 0;
+
+out:
+       /*
+        * Truncate the page cache - for file truncate operations, use
+        * the purpose-built API for truncations.  For punching operations,
+        * the truncation is handled under a range lock in zfs_free_range.
+        */
+       if (len == 0)
+               truncate_setsize(ZTOI(zp), off);
+       return (error);
 }
 
 void
 zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *zplprops, dmu_tx_t *tx)
 {
        struct super_block *sb;
-       zfs_sb_t        *zsb;
+       zfsvfs_t        *zfsvfs;
        uint64_t        moid, obj, sa_obj, version;
        uint64_t        sense = ZFS_CASE_SENSITIVE;
        uint64_t        norm = 0;
        nvpair_t        *elem;
+       int             size;
        int             error;
        int             i;
        znode_t         *rootzp = NULL;
@@ -1603,7 +1853,7 @@ zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *zplprops, dmu_tx_t *tx)
        ASSERT(error == 0);
 
        /*
-        * Create root znode.  Create minimal znode/inode/zsb/sb
+        * Create root znode.  Create minimal znode/inode/zfsvfs/sb
         * to allow zfs_mknode to work.
         */
        vattr.va_mask = ATTR_MODE|ATTR_UID|ATTR_GID;
@@ -1611,27 +1861,28 @@ zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *zplprops, dmu_tx_t *tx)
        vattr.va_uid = crgetuid(cr);
        vattr.va_gid = crgetgid(cr);
 
-       rootzp = kmem_cache_alloc(znode_cache, KM_PUSHPAGE);
+       rootzp = kmem_cache_alloc(znode_cache, KM_SLEEP);
        rootzp->z_moved = 0;
        rootzp->z_unlinked = 0;
        rootzp->z_atime_dirty = 0;
        rootzp->z_is_sa = USE_SA(version, os);
+       rootzp->z_pflags = 0;
 
-       zsb = kmem_zalloc(sizeof (zfs_sb_t), KM_PUSHPAGE | KM_NODEBUG);
-       zsb->z_os = os;
-       zsb->z_parent = zsb;
-       zsb->z_version = version;
-       zsb->z_use_fuids = USE_FUIDS(version, os);
-       zsb->z_use_sa = USE_SA(version, os);
-       zsb->z_norm = norm;
+       zfsvfs = kmem_zalloc(sizeof (zfsvfs_t), KM_SLEEP);
+       zfsvfs->z_os = os;
+       zfsvfs->z_parent = zfsvfs;
+       zfsvfs->z_version = version;
+       zfsvfs->z_use_fuids = USE_FUIDS(version, os);
+       zfsvfs->z_use_sa = USE_SA(version, os);
+       zfsvfs->z_norm = norm;
 
-       sb = kmem_zalloc(sizeof (struct super_block), KM_PUSHPAGE);
-       sb->s_fs_info = zsb;
+       sb = kmem_zalloc(sizeof (struct super_block), KM_SLEEP);
+       sb->s_fs_info = zfsvfs;
 
        ZTOI(rootzp)->i_sb = sb;
 
        error = sa_setup(os, sa_obj, zfs_attr_table, ZPL_END,
-           &zsb->z_attr_table);
+           &zfsvfs->z_attr_table);
 
        ASSERT(error == 0);
 
@@ -1640,14 +1891,22 @@ zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *zplprops, dmu_tx_t *tx)
         * insensitive.
         */
        if (sense == ZFS_CASE_INSENSITIVE || sense == ZFS_CASE_MIXED)
-               zsb->z_norm |= U8_TEXTPREP_TOUPPER;
+               zfsvfs->z_norm |= U8_TEXTPREP_TOUPPER;
 
-       mutex_init(&zsb->z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
-       list_create(&zsb->z_all_znodes, sizeof (znode_t),
+       mutex_init(&zfsvfs->z_znodes_lock, NULL, MUTEX_DEFAULT, NULL);
+       list_create(&zfsvfs->z_all_znodes, sizeof (znode_t),
            offsetof(znode_t, z_link_node));
 
-       for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
-               mutex_init(&zsb->z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
+       size = MIN(1 << (highbit64(zfs_object_mutex_size)-1), ZFS_OBJ_MTX_MAX);
+       zfsvfs->z_hold_size = size;
+       zfsvfs->z_hold_trees = vmem_zalloc(sizeof (avl_tree_t) * size,
+           KM_SLEEP);
+       zfsvfs->z_hold_locks = vmem_zalloc(sizeof (kmutex_t) * size, KM_SLEEP);
+       for (i = 0; i != size; i++) {
+               avl_create(&zfsvfs->z_hold_trees[i], zfs_znode_hold_compare,
+                   sizeof (znode_hold_t), offsetof(znode_hold_t, zh_node));
+               mutex_init(&zfsvfs->z_hold_locks[i], NULL, MUTEX_DEFAULT, NULL);
+       }
 
        VERIFY(0 == zfs_acl_ids_create(rootzp, IS_ROOT_NODE, &vattr,
            cr, NULL, &acl_ids));
@@ -1661,17 +1920,17 @@ zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *zplprops, dmu_tx_t *tx)
        sa_handle_destroy(rootzp->z_sa_hdl);
        kmem_cache_free(znode_cache, rootzp);
 
-       /*
-        * Create shares directory
-        */
-       error = zfs_create_share_dir(zsb, tx);
-       ASSERT(error == 0);
+       for (i = 0; i != size; i++) {
+               avl_destroy(&zfsvfs->z_hold_trees[i]);
+               mutex_destroy(&zfsvfs->z_hold_locks[i]);
+       }
 
-       for (i = 0; i != ZFS_OBJ_MTX_SZ; i++)
-               mutex_destroy(&zsb->z_hold_mtx[i]);
+       mutex_destroy(&zfsvfs->z_znodes_lock);
 
+       vmem_free(zfsvfs->z_hold_trees, sizeof (avl_tree_t) * size);
+       vmem_free(zfsvfs->z_hold_locks, sizeof (kmutex_t) * size);
        kmem_free(sb, sizeof (struct super_block));
-       kmem_free(zsb, sizeof (zfs_sb_t));
+       kmem_free(zfsvfs, sizeof (zfsvfs_t));
 }
 #endif /* _KERNEL */
 
@@ -1729,13 +1988,16 @@ zfs_release_sa_handle(sa_handle_t *hdl, dmu_buf_t *db, void *tag)
  * or not the object is an extended attribute directory.
  */
 static int
-zfs_obj_to_pobj(sa_handle_t *hdl, sa_attr_type_t *sa_table, uint64_t *pobjp,
-    int *is_xattrdir)
+zfs_obj_to_pobj(objset_t *osp, sa_handle_t *hdl, sa_attr_type_t *sa_table,
+    uint64_t *pobjp, int *is_xattrdir)
 {
        uint64_t parent;
        uint64_t pflags;
        uint64_t mode;
+       uint64_t parent_mode;
        sa_bulk_attr_t bulk[3];
+       sa_handle_t *sa_hdl;
+       dmu_buf_t *sa_db;
        int count = 0;
        int error;
 
@@ -1749,9 +2011,32 @@ zfs_obj_to_pobj(sa_handle_t *hdl, sa_attr_type_t *sa_table, uint64_t *pobjp,
        if ((error = sa_bulk_lookup(hdl, bulk, count)) != 0)
                return (error);
 
-       *pobjp = parent;
+       /*
+        * When a link is removed its parent pointer is not changed and will
+        * be invalid.  There are two cases where a link is removed but the
+        * file stays around, when it goes to the delete queue and when there
+        * are additional links.
+        */
+       error = zfs_grab_sa_handle(osp, parent, &sa_hdl, &sa_db, FTAG);
+       if (error != 0)
+               return (error);
+
+       error = sa_lookup(sa_hdl, ZPL_MODE, &parent_mode, sizeof (parent_mode));
+       zfs_release_sa_handle(sa_hdl, sa_db, FTAG);
+       if (error != 0)
+               return (error);
+
        *is_xattrdir = ((pflags & ZFS_XATTR) != 0) && S_ISDIR(mode);
 
+       /*
+        * Extended attributes can be applied to files, directories, etc.
+        * Otherwise the parent must be a directory.
+        */
+       if (!*is_xattrdir && !S_ISDIR(parent_mode))
+               return (SET_ERROR(EINVAL));
+
+       *pobjp = parent;
+
        return (0);
 }
 
@@ -1791,6 +2076,17 @@ zfs_obj_to_path_impl(objset_t *osp, uint64_t obj, sa_handle_t *hdl,
        *path = '\0';
        sa_hdl = hdl;
 
+       uint64_t deleteq_obj;
+       VERIFY0(zap_lookup(osp, MASTER_NODE_OBJ,
+           ZFS_UNLINKED_SET, sizeof (uint64_t), 1, &deleteq_obj));
+       error = zap_lookup_int(osp, deleteq_obj, obj);
+       if (error == 0) {
+               return (ESTALE);
+       } else if (error != ENOENT) {
+               return (error);
+       }
+       error = 0;
+
        for (;;) {
                uint64_t pobj = 0;
                char component[MAXNAMELEN + 2];
@@ -1800,7 +2096,7 @@ zfs_obj_to_path_impl(objset_t *osp, uint64_t obj, sa_handle_t *hdl,
                if (prevdb)
                        zfs_release_sa_handle(prevhdl, prevdb, FTAG);
 
-               if ((error = zfs_obj_to_pobj(sa_hdl, sa_table, &pobj,
+               if ((error = zfs_obj_to_pobj(osp, sa_hdl, sa_table, &pobj,
                    &is_xattrdir)) != 0)
                        break;
 
@@ -1903,7 +2199,14 @@ zfs_obj_to_stats(objset_t *osp, uint64_t obj, zfs_stat_t *sb,
        return (error);
 }
 
-#if defined(_KERNEL) && defined(HAVE_SPL)
+#if defined(_KERNEL)
 EXPORT_SYMBOL(zfs_create_fs);
 EXPORT_SYMBOL(zfs_obj_to_path);
+
+/* CSTYLED */
+module_param(zfs_object_mutex_size, uint, 0644);
+MODULE_PARM_DESC(zfs_object_mutex_size, "Size of znode hold array");
+module_param(zfs_unlink_suspend_progress, int, 0644);
+MODULE_PARM_DESC(zfs_unlink_suspend_progress, "Set to prevent async unlinks "
+"(debug - leaks space into the unlinked set)");
 #endif