diff options
author | pjd <pjd@FreeBSD.org> | 2009-11-10 22:25:46 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2009-11-10 22:25:46 +0000 |
commit | 2ddc47c4fb2f99ae402613fc0eae23355bb69ee6 (patch) | |
tree | 180678ab257f5c18811f56ee469cc6999204885d /sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c | |
parent | f38c10832c726b4405fcd6db37d53f83b30e2bd3 (diff) | |
download | FreeBSD-src-2ddc47c4fb2f99ae402613fc0eae23355bb69ee6.zip FreeBSD-src-2ddc47c4fb2f99ae402613fc0eae23355bb69ee6.tar.gz |
Avoid passing invalid mountpoint to getnewvnode().
Reported by: rwatson
Tested by: rwatson
MFC after: 3 days
Diffstat (limited to 'sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c')
-rw-r--r-- | sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c | 39 |
1 files changed, 18 insertions, 21 deletions
diff --git a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c index c43a850..7157930 100644 --- a/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c +++ b/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_znode.c @@ -143,16 +143,19 @@ zfs_znode_cache_constructor(void *buf, void *arg, int kmflags) POINTER_INVALIDATE(&zp->z_zfsvfs); ASSERT(!POINTER_IS_VALID(zp->z_zfsvfs)); - ASSERT(vfsp != NULL); - error = getnewvnode("zfs", vfsp, &zfs_vnodeops, &vp); - if (error != 0 && (kmflags & KM_NOSLEEP)) - return (-1); - ASSERT(error == 0); - vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); - zp->z_vnode = vp; - vp->v_data = (caddr_t)zp; - VN_LOCK_AREC(vp); + if (vfsp != NULL) { + error = getnewvnode("zfs", vfsp, &zfs_vnodeops, &vp); + if (error != 0 && (kmflags & KM_NOSLEEP)) + return (-1); + ASSERT(error == 0); + vn_lock(vp, LK_EXCLUSIVE | LK_RETRY); + zp->z_vnode = vp; + vp->v_data = (caddr_t)zp; + VN_LOCK_AREC(vp); + } else { + zp->z_vnode = NULL; + } list_link_init(&zp->z_link_node); @@ -1435,7 +1438,7 @@ zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *zplprops, dmu_tx_t *tx) nvpair_t *elem; int error; znode_t *rootzp = NULL; - vnode_t *vp; + vnode_t vnode; vattr_t vattr; znode_t *zp; @@ -1504,13 +1507,13 @@ zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *zplprops, dmu_tx_t *tx) vattr.va_gid = crgetgid(cr); rootzp = kmem_cache_alloc(znode_cache, KM_SLEEP); - zfs_znode_cache_constructor(rootzp, &zfsvfs, 0); + zfs_znode_cache_constructor(rootzp, NULL, 0); rootzp->z_unlinked = 0; rootzp->z_atime_dirty = 0; - vp = ZTOV(rootzp); - vp->v_type = VDIR; - VN_LOCK_ASHARE(vp); + vnode.v_type = VDIR; + vnode.v_data = rootzp; + rootzp->z_vnode = &vnode; bzero(&zfsvfs, sizeof (zfsvfs_t)); @@ -1539,16 +1542,10 @@ zfs_create_fs(objset_t *os, cred_t *cr, nvlist_t *zplprops, dmu_tx_t *tx) ASSERT(error == 0); POINTER_INVALIDATE(&rootzp->z_zfsvfs); - VI_LOCK(vp); - ZTOV(rootzp)->v_data = NULL; - ZTOV(rootzp)->v_count = 0; - ZTOV(rootzp)->v_holdcnt = 0; - rootzp->z_vnode = NULL; - VOP_UNLOCK(vp, 0); - vdestroy(vp); dmu_buf_rele(rootzp->z_dbuf, NULL); rootzp->z_dbuf = NULL; mutex_destroy(&zfsvfs.z_znodes_lock); + rootzp->z_vnode = NULL; kmem_cache_free(znode_cache, rootzp); } |