diff --git a/module/os/linux/zfs/zfs_znode.c b/module/os/linux/zfs/zfs_znode.c
index 53ba1f63ed..a476e58dd8 100644
--- a/module/os/linux/zfs/zfs_znode.c
+++ b/module/os/linux/zfs/zfs_znode.c
@@ -1094,7 +1094,8 @@ again:
 		ASSERT3U(zp->z_id, ==, obj_num);
 		/*
 		 * If zp->z_unlinked is set, the znode is already marked
-		 * for deletion and should not be discovered.
+		 * for deletion and should not be discovered. Check this
+		 * after checking igrab() due to fsetxattr() & O_TMPFILE.
 		 *
 		 * If igrab() returns NULL the VFS has independently
 		 * determined the inode should be evicted and has
@@ -1109,10 +1110,11 @@ again:
 		 * need to detect the active SA hold thereby informing
 		 * the VFS that this inode should not be evicted.
 		 */
-		if (zp->z_unlinked) {
-			err = SET_ERROR(ENOENT);
-		} else if (igrab(ZTOI(zp)) == NULL) {
-			err = SET_ERROR(EAGAIN);
+		if (igrab(ZTOI(zp)) == NULL) {
+			if (zp->z_unlinked)
+				err = SET_ERROR(ENOENT);
+			else
+				err = SET_ERROR(EAGAIN);
 		} else {
 			*zpp = zp;
 			err = 0;