Skip to content

Commit

Permalink
Break out of zfs_zget early if unlinked znode
Browse files Browse the repository at this point in the history
If zp->z_unlinked is set, we're working with a znode that has been
marked for deletion. If that's the case, we can skip the "goto again"
loop and return ENOENT, as the znode should not be discovered.

Reviewed-by: Richard Yao <ryao@gentoo.org>
Reviewed-by: Matt Ahrens <mahrens@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Heitor Alves de Siqueira <halves@canonical.com>
Closes openzfs#9583
  • Loading branch information
hrasiq authored and behlendorf committed Nov 15, 2019
1 parent cc1a1e1 commit 41e1aa2
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions module/os/linux/zfs/zfs_znode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,9 @@ zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp)
mutex_enter(&zp->z_lock);
ASSERT3U(zp->z_id, ==, obj_num);
/*
* If zp->z_unlinked is set, the znode is already marked
* for deletion and should not be discovered.
*
* If igrab() returns NULL the VFS has independently
* determined the inode should be evicted and has
* called iput_final() to start the eviction process.
Expand All @@ -1107,19 +1110,24 @@ zfs_zget(zfsvfs_t *zfsvfs, uint64_t obj_num, znode_t **zpp)
* 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;
if (zp->z_unlinked) {
err = SET_ERROR(ENOENT);
} else if (igrab(ZTOI(zp)) == NULL) {
err = SET_ERROR(EAGAIN);
} else {
*zpp = zp;
err = 0;
}
*zpp = zp;
err = 0;

mutex_exit(&zp->z_lock);
sa_buf_rele(db, NULL);
zfs_znode_hold_exit(zfsvfs, zh);

if (err == EAGAIN) {
/* inode might need this to finish evict */
cond_resched();
goto again;
}
return (err);
}

Expand Down

0 comments on commit 41e1aa2

Please sign in to comment.