diff options
author | avg <avg@FreeBSD.org> | 2012-11-04 14:50:08 +0000 |
---|---|---|
committer | avg <avg@FreeBSD.org> | 2012-11-04 14:50:08 +0000 |
commit | 8dd87fbeafa02eafc24091cd792697c50306cf5b (patch) | |
tree | 103e5852a908909ae6e8135437cdf3d4445f2530 /sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_dir.c | |
parent | e1ad987110cc0b5b293db2e1f8822a3341a2c355 (diff) | |
download | FreeBSD-src-8dd87fbeafa02eafc24091cd792697c50306cf5b.zip FreeBSD-src-8dd87fbeafa02eafc24091cd792697c50306cf5b.tar.gz |
zfs_dirlook: bailout early if directory is unlinked
Otherwise we could fail with an incorrect error if e.g. parent
object id is removed too or we can even return a wrong vnode if
parent object has been already re-used.
Discussed with: pjd
Also see: http://article.gmane.org/gmane.os.freebsd.devel.file-systems/13863
MFC after: 26 days
Diffstat (limited to 'sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_dir.c')
-rw-r--r-- | sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_dir.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_dir.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_dir.c index 6ff9339..9ef5e39 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_dir.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_dir.c @@ -374,8 +374,15 @@ zfs_dirlook(znode_t *dzp, char *name, vnode_t **vpp, int flags, znode_t *zp; int error = 0; uint64_t parent; + int unlinked; if (name[0] == 0 || (name[0] == '.' && name[1] == 0)) { + mutex_enter(&dzp->z_lock); + unlinked = dzp->z_unlinked; + mutex_exit(&dzp->z_lock); + if (unlinked) + return (ENOENT); + *vpp = ZTOV(dzp); VN_HOLD(*vpp); } else if (name[0] == '.' && name[1] == '.' && name[2] == 0) { @@ -394,6 +401,13 @@ zfs_dirlook(znode_t *dzp, char *name, vnode_t **vpp, int flags, NULL, NULL, NULL); return (error); } + + mutex_enter(&dzp->z_lock); + unlinked = dzp->z_unlinked; + mutex_exit(&dzp->z_lock); + if (unlinked) + return (ENOENT); + rw_enter(&dzp->z_parent_lock, RW_READER); error = zfs_zget(zfsvfs, parent, &zp); if (error == 0) |