]> git.proxmox.com Git - mirror_zfs.git/commitdiff
Add missing checks to zpl_xattr_* functions
authorJohn Gallagher <jgallag88@gmail.com>
Thu, 2 Aug 2018 21:03:56 +0000 (14:03 -0700)
committerBrian Behlendorf <behlendorf1@llnl.gov>
Thu, 2 Aug 2018 21:03:56 +0000 (14:03 -0700)
Linux specific zpl_* entry points, such as xattrs, must include
the same unmounted and sa handle checks as the common zfs_ entry
points. The additional ZPL_* wrappers are identical to their
ZFS_ counterparts except the errno is negated since they are
expected to be used at the zpl_ layer.

Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: John Gallagher <john.gallagher@delphix.com>
Closes #5866
Closes #7761

include/sys/zfs_znode.h
module/zfs/zpl_xattr.c

index a34d2453263ddf5eb8dab0c1945ffdef466703ec..e82ac9941a2b04951f99cd70b56702eab9eace48 100644 (file)
@@ -259,28 +259,35 @@ zfs_inherit_projid(znode_t *dzp)
 
 #define        S_ISDEV(mode)   (S_ISCHR(mode) || S_ISBLK(mode) || S_ISFIFO(mode))
 
-/* Called on entry to each ZFS vnode and vfs operation  */
-#define        ZFS_ENTER(zfsvfs) \
-       { \
-               rrm_enter_read(&(zfsvfs)->z_teardown_lock, FTAG); \
-               if ((zfsvfs)->z_unmounted) { \
-                       ZFS_EXIT(zfsvfs); \
-                       return (EIO); \
-               } \
-       }
-
-/* Must be called before exiting the vop */
-#define        ZFS_EXIT(zfsvfs) \
-       { \
-               rrm_exit(&(zfsvfs)->z_teardown_lock, FTAG); \
-       }
-
-/* Verifies the znode is valid */
-#define        ZFS_VERIFY_ZP(zp) \
-       if ((zp)->z_sa_hdl == NULL) { \
-               ZFS_EXIT(ZTOZSB(zp)); \
-               return (EIO); \
-       }
+/* Called on entry to each ZFS inode and vfs operation. */
+#define        ZFS_ENTER_ERROR(zfsvfs, error)                          \
+do {                                                           \
+       rrm_enter_read(&(zfsvfs)->z_teardown_lock, FTAG);       \
+       if ((zfsvfs)->z_unmounted) {                            \
+               ZFS_EXIT(zfsvfs);                               \
+               return (error);                                 \
+       }                                                       \
+} while (0)
+#define        ZFS_ENTER(zfsvfs)       ZFS_ENTER_ERROR(zfsvfs, EIO)
+#define        ZPL_ENTER(zfsvfs)       ZFS_ENTER_ERROR(zfsvfs, -EIO)
+
+/* Must be called before exiting the operation. */
+#define        ZFS_EXIT(zfsvfs)                                        \
+do {                                                           \
+       rrm_exit(&(zfsvfs)->z_teardown_lock, FTAG);             \
+} while (0)
+#define        ZPL_EXIT(zfsvfs)        ZFS_EXIT(zfsvfs)
+
+/* Verifies the znode is valid. */
+#define        ZFS_VERIFY_ZP_ERROR(zp, error)                          \
+do {                                                           \
+       if ((zp)->z_sa_hdl == NULL) {                           \
+               ZFS_EXIT(ZTOZSB(zp));                           \
+               return (error);                                 \
+       }                                                       \
+} while (0)
+#define        ZFS_VERIFY_ZP(zp)       ZFS_VERIFY_ZP_ERROR(zp, EIO)
+#define        ZPL_VERIFY_ZP(zp)       ZFS_VERIFY_ZP_ERROR(zp, -EIO)
 
 /*
  * Macros for dealing with dmu_buf_hold
index 09e38ee8bda80a3931a122360c706f68b5da6217..8ee6e9a97f0a4c6c171a2536e457b428a0255151 100644 (file)
@@ -245,7 +245,8 @@ zpl_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
 
        crhold(cr);
        cookie = spl_fstrans_mark();
-       rrm_enter_read(&(zfsvfs)->z_teardown_lock, FTAG);
+       ZPL_ENTER(zfsvfs);
+       ZPL_VERIFY_ZP(zp);
        rw_enter(&zp->z_xattr_lock, RW_READER);
 
        if (zfsvfs->z_use_sa && zp->z_is_sa) {
@@ -262,7 +263,7 @@ zpl_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
 out:
 
        rw_exit(&zp->z_xattr_lock);
-       rrm_exit(&(zfsvfs)->z_teardown_lock, FTAG);
+       ZPL_EXIT(zfsvfs);
        spl_fstrans_unmark(cookie);
        crfree(cr);
 
@@ -418,11 +419,12 @@ zpl_xattr_get(struct inode *ip, const char *name, void *value, size_t size)
 
        crhold(cr);
        cookie = spl_fstrans_mark();
-       rrm_enter_read(&(zfsvfs)->z_teardown_lock, FTAG);
+       ZPL_ENTER(zfsvfs);
+       ZPL_VERIFY_ZP(zp);
        rw_enter(&zp->z_xattr_lock, RW_READER);
        error = __zpl_xattr_get(ip, name, value, size, cr);
        rw_exit(&zp->z_xattr_lock);
-       rrm_exit(&(zfsvfs)->z_teardown_lock, FTAG);
+       ZPL_EXIT(zfsvfs);
        spl_fstrans_unmark(cookie);
        crfree(cr);
 
@@ -590,7 +592,8 @@ zpl_xattr_set(struct inode *ip, const char *name, const void *value,
 
        crhold(cr);
        cookie = spl_fstrans_mark();
-       rrm_enter_read(&(zfsvfs)->z_teardown_lock, FTAG);
+       ZPL_ENTER(zfsvfs);
+       ZPL_VERIFY_ZP(zp);
        rw_enter(&ITOZ(ip)->z_xattr_lock, RW_WRITER);
 
        /*
@@ -643,7 +646,7 @@ zpl_xattr_set(struct inode *ip, const char *name, const void *value,
                zpl_xattr_set_sa(ip, name, NULL, 0, 0, cr);
 out:
        rw_exit(&ITOZ(ip)->z_xattr_lock);
-       rrm_exit(&(zfsvfs)->z_teardown_lock, FTAG);
+       ZPL_EXIT(zfsvfs);
        spl_fstrans_unmark(cookie);
        crfree(cr);
        ASSERT3S(error, <=, 0);