diff --git a/module/zfs/zfs_znode.c b/module/zfs/zfs_znode.c index 5e9941034c1c..de1c0d60de1d 100644 --- a/module/zfs/zfs_znode.c +++ b/module/zfs/zfs_znode.c @@ -859,19 +859,15 @@ zfs_zget(zfs_sb_t *zsb, uint64_t obj_num, znode_t **zpp) znode_t *zp; int err; sa_handle_t *hdl; - struct inode *ip; *zpp = NULL; again: - ip = ilookup(zsb->z_sb, obj_num); - ZFS_OBJ_HOLD_ENTER(zsb, obj_num); err = sa_buf_hold(zsb->z_os, obj_num, NULL, &db); if (err) { ZFS_OBJ_HOLD_EXIT(zsb, obj_num); - iput(ip); return (err); } @@ -882,25 +878,11 @@ zfs_zget(zfs_sb_t *zsb, uint64_t obj_num, znode_t **zpp) doi.doi_bonus_size < sizeof (znode_phys_t)))) { sa_buf_rele(db, NULL); ZFS_OBJ_HOLD_EXIT(zsb, obj_num); - iput(ip); return (SET_ERROR(EINVAL)); } hdl = dmu_buf_get_user(db); if (hdl != NULL) { - if (ip == NULL) { - /* - * ilookup returned NULL, which means - * the znode is dying - but the SA handle isn't - * quite dead yet, we need to drop any locks - * we're holding, re-schedule the task and try again. - */ - sa_buf_rele(db, NULL); - ZFS_OBJ_HOLD_EXIT(zsb, obj_num); - - schedule(); - goto again; - } zp = sa_get_userdata(hdl); @@ -917,19 +899,29 @@ zfs_zget(zfs_sb_t *zsb, uint64_t obj_num, znode_t **zpp) if (zp->z_unlinked) { err = SET_ERROR(ENOENT); } else { - igrab(ZTOI(zp)); + /* + * igrab returned NULL, which means + * the znode is dying - but the SA handle isn't + * quite dead yet, we need to drop any locks + * we're holding, re-schedule the task and try again. + */ + if (igrab(ZTOI(zp)) == NULL) { + mutex_exit(&zp->z_lock); + sa_buf_rele(db, NULL); + ZFS_OBJ_HOLD_EXIT(zsb, obj_num); + + schedule(); + goto again; + } *zpp = zp; err = 0; } sa_buf_rele(db, NULL); mutex_exit(&zp->z_lock); ZFS_OBJ_HOLD_EXIT(zsb, obj_num); - iput(ip); return (err); } - ASSERT3P(ip, ==, NULL); - /* * Not found create new znode/vnode but only if file exists. *