]> git.proxmox.com Git - mirror_zfs-debian.git/blobdiff - module/zfs/zfs_acl.c
Imported Upstream version 0.6.5.8
[mirror_zfs-debian.git] / module / zfs / zfs_acl.c
index a208dea15e5aca0ea52e79afb3577c7a8a2dd41a..bbb01930fa79e4a55f496c4e1ca52384c5aaa052 100644 (file)
@@ -2473,53 +2473,33 @@ zfs_zaccess(znode_t *zp, int mode, int flags, boolean_t skipaclchk, cred_t *cr)
 {
        uint32_t        working_mode;
        int             error;
-       boolean_t       check_privs;
-       znode_t         *check_zp = zp;
+       int             is_attr;
+       boolean_t       check_privs;
+       znode_t         *xzp;
+       znode_t         *check_zp = zp;
        mode_t          needed_bits;
        uid_t           owner;
 
+       is_attr = ((zp->z_pflags & ZFS_XATTR) && S_ISDIR(ZTOI(zp)->i_mode));
+
        /*
         * If attribute then validate against base file
         */
-       if ((zp->z_pflags & ZFS_XATTR) && S_ISDIR(ZTOI(zp)->i_mode)) {
+       if (is_attr) {
                uint64_t        parent;
 
-               rw_enter(&zp->z_xattr_lock, RW_READER);
-               if (zp->z_xattr_parent) {
-                       check_zp = zp->z_xattr_parent;
-                       rw_exit(&zp->z_xattr_lock);
-
-                       /*
-                        * Verify a lookup yields the same znode.
-                        */
-                       ASSERT3S(sa_lookup(zp->z_sa_hdl, SA_ZPL_PARENT(
-                           ZTOZSB(zp)), &parent, sizeof (parent)), ==, 0);
-                       ASSERT3U(check_zp->z_id, ==, parent);
-               } else {
-                       rw_exit(&zp->z_xattr_lock);
-
-                       error = sa_lookup(zp->z_sa_hdl, SA_ZPL_PARENT(
-                           ZTOZSB(zp)), &parent, sizeof (parent));
-                       if (error)
-                               return (error);
+               if ((error = sa_lookup(zp->z_sa_hdl,
+                   SA_ZPL_PARENT(ZTOZSB(zp)), &parent,
+                   sizeof (parent))) != 0)
+                       return (error);
 
-                       /*
-                        * Cache the lookup on the parent file znode as
-                        * zp->z_xattr_parent and hold a reference.  This
-                        * effectively pins the parent in memory until all
-                        * child xattr znodes have been destroyed and
-                        * release their references in zfs_inode_destroy().
-                        */
-                       error = zfs_zget(ZTOZSB(zp), parent, &check_zp);
-                       if (error)
-                               return (error);
-
-                       rw_enter(&zp->z_xattr_lock, RW_WRITER);
-                       if (zp->z_xattr_parent == NULL)
-                               zp->z_xattr_parent = check_zp;
-                       rw_exit(&zp->z_xattr_lock);
+               if ((error = zfs_zget(ZTOZSB(zp),
+                   parent, &xzp)) != 0)        {
+                       return (error);
                }
 
+               check_zp = xzp;
+
                /*
                 * fixup mode to map to xattr perms
                 */
@@ -2561,11 +2541,15 @@ zfs_zaccess(znode_t *zp, int mode, int flags, boolean_t skipaclchk, cred_t *cr)
 
        if ((error = zfs_zaccess_common(check_zp, mode, &working_mode,
            &check_privs, skipaclchk, cr)) == 0) {
+               if (is_attr)
+                       iput(ZTOI(xzp));
                return (secpolicy_vnode_access2(cr, ZTOI(zp), owner,
                    needed_bits, needed_bits));
        }
 
        if (error && !check_privs) {
+               if (is_attr)
+                       iput(ZTOI(xzp));
                return (error);
        }
 
@@ -2626,6 +2610,9 @@ zfs_zaccess(znode_t *zp, int mode, int flags, boolean_t skipaclchk, cred_t *cr)
                    needed_bits, needed_bits);
        }
 
+       if (is_attr)
+               iput(ZTOI(xzp));
+
        return (error);
 }