usr/src/uts/common/fs/zfs/zfs_vnops.c
changeset 5326 6752aa2bd5bc
parent 4863 7b14ad153d91
child 5331 3047ad28a67b
equal deleted inserted replaced
5325:101705820ea0 5326:6752aa2bd5bc
    81  * Morover, the vnode ops must work in both normal and log replay context.
    81  * Morover, the vnode ops must work in both normal and log replay context.
    82  * The ordering of events is important to avoid deadlocks and references
    82  * The ordering of events is important to avoid deadlocks and references
    83  * to freed memory.  The example below illustrates the following Big Rules:
    83  * to freed memory.  The example below illustrates the following Big Rules:
    84  *
    84  *
    85  *  (1) A check must be made in each zfs thread for a mounted file system.
    85  *  (1) A check must be made in each zfs thread for a mounted file system.
    86  *	This is done avoiding races using ZFS_ENTER(zfsvfs).
    86  *	This is done avoiding races using ZFS_ENTER(zfsvfs) or
    87  *	A ZFS_EXIT(zfsvfs) is needed before all returns.
    87  *      ZFS_ENTER_VERIFY(zfsvfs, zp).  A ZFS_EXIT(zfsvfs) is needed before
       
    88  *      all returns.
    88  *
    89  *
    89  *  (2)	VN_RELE() should always be the last thing except for zil_commit()
    90  *  (2)	VN_RELE() should always be the last thing except for zil_commit()
    90  *	(if necessary) and ZFS_EXIT(). This is for 3 reasons:
    91  *	(if necessary) and ZFS_EXIT(). This is for 3 reasons:
    91  *	First, if it's the last reference, the vnode/znode
    92  *	First, if it's the last reference, the vnode/znode
    92  *	can be freed, so the zp may point to freed memory.  Second, the last
    93  *	can be freed, so the zp may point to freed memory.  Second, the last
   237     int *rvalp)
   238     int *rvalp)
   238 {
   239 {
   239 	offset_t off;
   240 	offset_t off;
   240 	int error;
   241 	int error;
   241 	zfsvfs_t *zfsvfs;
   242 	zfsvfs_t *zfsvfs;
       
   243 	znode_t *zp;
   242 
   244 
   243 	switch (com) {
   245 	switch (com) {
   244 	case _FIOFFS:
   246 	case _FIOFFS:
   245 		return (zfs_sync(vp->v_vfsp, 0, cred));
   247 		return (zfs_sync(vp->v_vfsp, 0, cred));
   246 
   248 
   255 	case _FIO_SEEK_DATA:
   257 	case _FIO_SEEK_DATA:
   256 	case _FIO_SEEK_HOLE:
   258 	case _FIO_SEEK_HOLE:
   257 		if (ddi_copyin((void *)data, &off, sizeof (off), flag))
   259 		if (ddi_copyin((void *)data, &off, sizeof (off), flag))
   258 			return (EFAULT);
   260 			return (EFAULT);
   259 
   261 
   260 		zfsvfs = VTOZ(vp)->z_zfsvfs;
   262 		zp = VTOZ(vp);
   261 		ZFS_ENTER(zfsvfs);
   263 		zfsvfs = zp->z_zfsvfs;
       
   264 		ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
   262 
   265 
   263 		/* offset parameter is in/out */
   266 		/* offset parameter is in/out */
   264 		error = zfs_holey(vp, com, &off);
   267 		error = zfs_holey(vp, com, &off);
   265 		ZFS_EXIT(zfsvfs);
   268 		ZFS_EXIT(zfsvfs);
   266 		if (error)
   269 		if (error)
   396 static int
   399 static int
   397 zfs_read(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
   400 zfs_read(vnode_t *vp, uio_t *uio, int ioflag, cred_t *cr, caller_context_t *ct)
   398 {
   401 {
   399 	znode_t		*zp = VTOZ(vp);
   402 	znode_t		*zp = VTOZ(vp);
   400 	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
   403 	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
   401 	objset_t	*os = zfsvfs->z_os;
   404 	objset_t	*os;
   402 	ssize_t		n, nbytes;
   405 	ssize_t		n, nbytes;
   403 	int		error;
   406 	int		error;
   404 	rl_t		*rl;
   407 	rl_t		*rl;
   405 
   408 
   406 	ZFS_ENTER(zfsvfs);
   409 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
       
   410 	os = zfsvfs->z_os;
   407 
   411 
   408 	/*
   412 	/*
   409 	 * Validate file offset
   413 	 * Validate file offset
   410 	 */
   414 	 */
   411 	if (uio->uio_loffset < (offset_t)0) {
   415 	if (uio->uio_loffset < (offset_t)0) {
   566 	ssize_t		start_resid = uio->uio_resid;
   570 	ssize_t		start_resid = uio->uio_resid;
   567 	ssize_t		tx_bytes;
   571 	ssize_t		tx_bytes;
   568 	uint64_t	end_size;
   572 	uint64_t	end_size;
   569 	dmu_tx_t	*tx;
   573 	dmu_tx_t	*tx;
   570 	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
   574 	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
   571 	zilog_t		*zilog = zfsvfs->z_log;
   575 	zilog_t		*zilog;
   572 	offset_t	woff;
   576 	offset_t	woff;
   573 	ssize_t		n, nbytes;
   577 	ssize_t		n, nbytes;
   574 	rl_t		*rl;
   578 	rl_t		*rl;
   575 	int		max_blksz = zfsvfs->z_max_blksz;
   579 	int		max_blksz = zfsvfs->z_max_blksz;
   576 	int		error;
   580 	int		error;
   583 		return (0);
   587 		return (0);
   584 
   588 
   585 	if (limit == RLIM64_INFINITY || limit > MAXOFFSET_T)
   589 	if (limit == RLIM64_INFINITY || limit > MAXOFFSET_T)
   586 		limit = MAXOFFSET_T;
   590 		limit = MAXOFFSET_T;
   587 
   591 
   588 	ZFS_ENTER(zfsvfs);
   592 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
       
   593 	zilog = zfsvfs->z_log;
   589 
   594 
   590 	/*
   595 	/*
   591 	 * Pre-fault the pages to ensure slow (eg NFS) pages
   596 	 * Pre-fault the pages to ensure slow (eg NFS) pages
   592 	 * don't hold up txg.
   597 	 * don't hold up txg.
   593 	 */
   598 	 */
   904 {
   909 {
   905 	znode_t *zp = VTOZ(vp);
   910 	znode_t *zp = VTOZ(vp);
   906 	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
   911 	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
   907 	int error;
   912 	int error;
   908 
   913 
   909 	ZFS_ENTER(zfsvfs);
   914 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
   910 	error = zfs_zaccess_rwx(zp, mode, cr);
   915 	error = zfs_zaccess_rwx(zp, mode, cr);
   911 	ZFS_EXIT(zfsvfs);
   916 	ZFS_EXIT(zfsvfs);
   912 	return (error);
   917 	return (error);
   913 }
   918 }
   914 
   919 
   939 
   944 
   940 	znode_t *zdp = VTOZ(dvp);
   945 	znode_t *zdp = VTOZ(dvp);
   941 	zfsvfs_t *zfsvfs = zdp->z_zfsvfs;
   946 	zfsvfs_t *zfsvfs = zdp->z_zfsvfs;
   942 	int	error;
   947 	int	error;
   943 
   948 
   944 	ZFS_ENTER(zfsvfs);
   949 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zdp);
   945 
   950 
   946 	*vpp = NULL;
   951 	*vpp = NULL;
   947 
   952 
   948 	if (flags & LOOKUP_XATTR) {
   953 	if (flags & LOOKUP_XATTR) {
   949 		/*
   954 		/*
  1042 zfs_create(vnode_t *dvp, char *name, vattr_t *vap, vcexcl_t excl,
  1047 zfs_create(vnode_t *dvp, char *name, vattr_t *vap, vcexcl_t excl,
  1043     int mode, vnode_t **vpp, cred_t *cr, int flag)
  1048     int mode, vnode_t **vpp, cred_t *cr, int flag)
  1044 {
  1049 {
  1045 	znode_t		*zp, *dzp = VTOZ(dvp);
  1050 	znode_t		*zp, *dzp = VTOZ(dvp);
  1046 	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
  1051 	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
  1047 	zilog_t		*zilog = zfsvfs->z_log;
  1052 	zilog_t		*zilog;
  1048 	objset_t	*os = zfsvfs->z_os;
  1053 	objset_t	*os;
  1049 	zfs_dirlock_t	*dl;
  1054 	zfs_dirlock_t	*dl;
  1050 	dmu_tx_t	*tx;
  1055 	dmu_tx_t	*tx;
  1051 	int		error;
  1056 	int		error;
  1052 	uint64_t	zoid;
  1057 	uint64_t	zoid;
  1053 
  1058 
  1054 	ZFS_ENTER(zfsvfs);
  1059 	ZFS_ENTER_VERIFY_ZP(zfsvfs, dzp);
       
  1060 	os = zfsvfs->z_os;
       
  1061 	zilog = zfsvfs->z_log;
  1055 
  1062 
  1056 top:
  1063 top:
  1057 	*vpp = NULL;
  1064 	*vpp = NULL;
  1058 
  1065 
  1059 	if ((vap->va_mode & VSVTX) && secpolicy_vnode_stky_modify(cr))
  1066 	if ((vap->va_mode & VSVTX) && secpolicy_vnode_stky_modify(cr))
  1219 {
  1226 {
  1220 	znode_t		*zp, *dzp = VTOZ(dvp);
  1227 	znode_t		*zp, *dzp = VTOZ(dvp);
  1221 	znode_t		*xzp = NULL;
  1228 	znode_t		*xzp = NULL;
  1222 	vnode_t		*vp;
  1229 	vnode_t		*vp;
  1223 	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
  1230 	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
  1224 	zilog_t		*zilog = zfsvfs->z_log;
  1231 	zilog_t		*zilog;
  1225 	uint64_t	acl_obj, xattr_obj;
  1232 	uint64_t	acl_obj, xattr_obj;
  1226 	zfs_dirlock_t	*dl;
  1233 	zfs_dirlock_t	*dl;
  1227 	dmu_tx_t	*tx;
  1234 	dmu_tx_t	*tx;
  1228 	boolean_t	may_delete_now, delete_now = FALSE;
  1235 	boolean_t	may_delete_now, delete_now = FALSE;
  1229 	boolean_t	unlinked;
  1236 	boolean_t	unlinked;
  1230 	int		error;
  1237 	int		error;
  1231 
  1238 
  1232 	ZFS_ENTER(zfsvfs);
  1239 	ZFS_ENTER_VERIFY_ZP(zfsvfs, dzp);
       
  1240 	zilog = zfsvfs->z_log;
  1233 
  1241 
  1234 top:
  1242 top:
  1235 	/*
  1243 	/*
  1236 	 * Attempt to lock directory; fail if entry doesn't exist.
  1244 	 * Attempt to lock directory; fail if entry doesn't exist.
  1237 	 */
  1245 	 */
  1384 static int
  1392 static int
  1385 zfs_mkdir(vnode_t *dvp, char *dirname, vattr_t *vap, vnode_t **vpp, cred_t *cr)
  1393 zfs_mkdir(vnode_t *dvp, char *dirname, vattr_t *vap, vnode_t **vpp, cred_t *cr)
  1386 {
  1394 {
  1387 	znode_t		*zp, *dzp = VTOZ(dvp);
  1395 	znode_t		*zp, *dzp = VTOZ(dvp);
  1388 	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
  1396 	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
  1389 	zilog_t		*zilog = zfsvfs->z_log;
  1397 	zilog_t		*zilog;
  1390 	zfs_dirlock_t	*dl;
  1398 	zfs_dirlock_t	*dl;
  1391 	uint64_t	zoid = 0;
  1399 	uint64_t	zoid = 0;
  1392 	dmu_tx_t	*tx;
  1400 	dmu_tx_t	*tx;
  1393 	int		error;
  1401 	int		error;
  1394 
  1402 
  1395 	ASSERT(vap->va_type == VDIR);
  1403 	ASSERT(vap->va_type == VDIR);
  1396 
  1404 
  1397 	ZFS_ENTER(zfsvfs);
  1405 	ZFS_ENTER_VERIFY_ZP(zfsvfs, dzp);
       
  1406 	zilog = zfsvfs->z_log;
  1398 
  1407 
  1399 	if (dzp->z_phys->zp_flags & ZFS_XATTR) {
  1408 	if (dzp->z_phys->zp_flags & ZFS_XATTR) {
  1400 		ZFS_EXIT(zfsvfs);
  1409 		ZFS_EXIT(zfsvfs);
  1401 		return (EINVAL);
  1410 		return (EINVAL);
  1402 	}
  1411 	}
  1481 {
  1490 {
  1482 	znode_t		*dzp = VTOZ(dvp);
  1491 	znode_t		*dzp = VTOZ(dvp);
  1483 	znode_t		*zp;
  1492 	znode_t		*zp;
  1484 	vnode_t		*vp;
  1493 	vnode_t		*vp;
  1485 	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
  1494 	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
  1486 	zilog_t		*zilog = zfsvfs->z_log;
  1495 	zilog_t		*zilog;
  1487 	zfs_dirlock_t	*dl;
  1496 	zfs_dirlock_t	*dl;
  1488 	dmu_tx_t	*tx;
  1497 	dmu_tx_t	*tx;
  1489 	int		error;
  1498 	int		error;
  1490 
  1499 
  1491 	ZFS_ENTER(zfsvfs);
  1500 	ZFS_ENTER_VERIFY_ZP(zfsvfs, dzp);
       
  1501 	zilog = zfsvfs->z_log;
  1492 
  1502 
  1493 top:
  1503 top:
  1494 	zp = NULL;
  1504 	zp = NULL;
  1495 
  1505 
  1496 	/*
  1506 	/*
  1611 	int		local_eof;
  1621 	int		local_eof;
  1612 	int		outcount;
  1622 	int		outcount;
  1613 	int		error;
  1623 	int		error;
  1614 	uint8_t		prefetch;
  1624 	uint8_t		prefetch;
  1615 
  1625 
  1616 	ZFS_ENTER(zfsvfs);
  1626 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
  1617 
  1627 
  1618 	/*
  1628 	/*
  1619 	 * If we are not given an eof variable,
  1629 	 * If we are not given an eof variable,
  1620 	 * use a local one.
  1630 	 * use a local one.
  1621 	 */
  1631 	 */
  1810 	    (vp->v_type == VREG) && !(IS_SWAPVP(vp)))
  1820 	    (vp->v_type == VREG) && !(IS_SWAPVP(vp)))
  1811 		(void) VOP_PUTPAGE(vp, (offset_t)0, (size_t)0, B_ASYNC, cr);
  1821 		(void) VOP_PUTPAGE(vp, (offset_t)0, (size_t)0, B_ASYNC, cr);
  1812 
  1822 
  1813 	(void) tsd_set(zfs_fsyncer_key, (void *)zfs_fsync_sync_cnt);
  1823 	(void) tsd_set(zfs_fsyncer_key, (void *)zfs_fsync_sync_cnt);
  1814 
  1824 
  1815 	ZFS_ENTER(zfsvfs);
  1825 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
  1816 	zil_commit(zfsvfs->z_log, zp->z_last_itx, zp->z_id);
  1826 	zil_commit(zfsvfs->z_log, zp->z_last_itx, zp->z_id);
  1817 	ZFS_EXIT(zfsvfs);
  1827 	ZFS_EXIT(zfsvfs);
  1818 	return (0);
  1828 	return (0);
  1819 }
  1829 }
  1820 
  1830 
  1835 static int
  1845 static int
  1836 zfs_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr)
  1846 zfs_getattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr)
  1837 {
  1847 {
  1838 	znode_t *zp = VTOZ(vp);
  1848 	znode_t *zp = VTOZ(vp);
  1839 	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
  1849 	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
  1840 	znode_phys_t *pzp = zp->z_phys;
  1850 	znode_phys_t *pzp;
  1841 	int	error;
  1851 	int	error;
  1842 	uint64_t links;
  1852 	uint64_t links;
  1843 
  1853 
  1844 	ZFS_ENTER(zfsvfs);
  1854 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
       
  1855 	pzp = zp->z_phys;
  1845 
  1856 
  1846 	/*
  1857 	/*
  1847 	 * Return all attributes.  It's cheaper to provide the answer
  1858 	 * Return all attributes.  It's cheaper to provide the answer
  1848 	 * than to determine whether we were asked the question.
  1859 	 * than to determine whether we were asked the question.
  1849 	 */
  1860 	 */
  1915 /* ARGSUSED */
  1926 /* ARGSUSED */
  1916 static int
  1927 static int
  1917 zfs_setattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
  1928 zfs_setattr(vnode_t *vp, vattr_t *vap, int flags, cred_t *cr,
  1918 	caller_context_t *ct)
  1929 	caller_context_t *ct)
  1919 {
  1930 {
  1920 	struct znode	*zp = VTOZ(vp);
  1931 	znode_t		*zp = VTOZ(vp);
  1921 	znode_phys_t	*pzp = zp->z_phys;
  1932 	znode_phys_t	*pzp;
  1922 	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
  1933 	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
  1923 	zilog_t		*zilog = zfsvfs->z_log;
  1934 	zilog_t		*zilog;
  1924 	dmu_tx_t	*tx;
  1935 	dmu_tx_t	*tx;
  1925 	vattr_t		oldva;
  1936 	vattr_t		oldva;
  1926 	uint_t		mask = vap->va_mask;
  1937 	uint_t		mask = vap->va_mask;
  1927 	uint_t		saved_mask;
  1938 	uint_t		saved_mask;
  1928 	int		trim_mask = 0;
  1939 	int		trim_mask = 0;
  1941 		return (EISDIR);
  1952 		return (EISDIR);
  1942 
  1953 
  1943 	if (mask & AT_SIZE && vp->v_type != VREG && vp->v_type != VFIFO)
  1954 	if (mask & AT_SIZE && vp->v_type != VREG && vp->v_type != VFIFO)
  1944 		return (EINVAL);
  1955 		return (EINVAL);
  1945 
  1956 
  1946 	ZFS_ENTER(zfsvfs);
  1957 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
       
  1958 	pzp = zp->z_phys;
       
  1959 	zilog = zfsvfs->z_log;
  1947 
  1960 
  1948 top:
  1961 top:
  1949 	attrzp = NULL;
  1962 	attrzp = NULL;
  1950 
  1963 
  1951 	if (zfsvfs->z_vfs->vfs_flag & VFS_RDONLY) {
  1964 	if (zfsvfs->z_vfs->vfs_flag & VFS_RDONLY) {
  2296 zfs_rename(vnode_t *sdvp, char *snm, vnode_t *tdvp, char *tnm, cred_t *cr)
  2309 zfs_rename(vnode_t *sdvp, char *snm, vnode_t *tdvp, char *tnm, cred_t *cr)
  2297 {
  2310 {
  2298 	znode_t		*tdzp, *szp, *tzp;
  2311 	znode_t		*tdzp, *szp, *tzp;
  2299 	znode_t		*sdzp = VTOZ(sdvp);
  2312 	znode_t		*sdzp = VTOZ(sdvp);
  2300 	zfsvfs_t	*zfsvfs = sdzp->z_zfsvfs;
  2313 	zfsvfs_t	*zfsvfs = sdzp->z_zfsvfs;
  2301 	zilog_t		*zilog = zfsvfs->z_log;
  2314 	zilog_t		*zilog;
  2302 	vnode_t		*realvp;
  2315 	vnode_t		*realvp;
  2303 	zfs_dirlock_t	*sdl, *tdl;
  2316 	zfs_dirlock_t	*sdl, *tdl;
  2304 	dmu_tx_t	*tx;
  2317 	dmu_tx_t	*tx;
  2305 	zfs_zlock_t	*zl;
  2318 	zfs_zlock_t	*zl;
  2306 	int		cmp, serr, terr, error;
  2319 	int		cmp, serr, terr, error;
  2307 
  2320 
  2308 	ZFS_ENTER(zfsvfs);
  2321 	ZFS_ENTER_VERIFY_ZP(zfsvfs, sdzp);
       
  2322 	zilog = zfsvfs->z_log;
  2309 
  2323 
  2310 	/*
  2324 	/*
  2311 	 * Make sure we have the real vp for the target directory.
  2325 	 * Make sure we have the real vp for the target directory.
  2312 	 */
  2326 	 */
  2313 	if (VOP_REALVP(tdvp, &realvp) == 0)
  2327 	if (VOP_REALVP(tdvp, &realvp) == 0)
  2317 		ZFS_EXIT(zfsvfs);
  2331 		ZFS_EXIT(zfsvfs);
  2318 		return (EXDEV);
  2332 		return (EXDEV);
  2319 	}
  2333 	}
  2320 
  2334 
  2321 	tdzp = VTOZ(tdvp);
  2335 	tdzp = VTOZ(tdvp);
       
  2336 	if (!tdzp->z_dbuf_held) {
       
  2337 		ZFS_EXIT(zfsvfs);
       
  2338 		return (EIO);
       
  2339 	}
  2322 top:
  2340 top:
  2323 	szp = NULL;
  2341 	szp = NULL;
  2324 	tzp = NULL;
  2342 	tzp = NULL;
  2325 	zl = NULL;
  2343 	zl = NULL;
  2326 
  2344 
  2527 {
  2545 {
  2528 	znode_t		*zp, *dzp = VTOZ(dvp);
  2546 	znode_t		*zp, *dzp = VTOZ(dvp);
  2529 	zfs_dirlock_t	*dl;
  2547 	zfs_dirlock_t	*dl;
  2530 	dmu_tx_t	*tx;
  2548 	dmu_tx_t	*tx;
  2531 	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
  2549 	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
  2532 	zilog_t		*zilog = zfsvfs->z_log;
  2550 	zilog_t		*zilog;
  2533 	uint64_t	zoid;
  2551 	uint64_t	zoid;
  2534 	int		len = strlen(link);
  2552 	int		len = strlen(link);
  2535 	int		error;
  2553 	int		error;
  2536 
  2554 
  2537 	ASSERT(vap->va_type == VLNK);
  2555 	ASSERT(vap->va_type == VLNK);
  2538 
  2556 
  2539 	ZFS_ENTER(zfsvfs);
  2557 	ZFS_ENTER_VERIFY_ZP(zfsvfs, dzp);
       
  2558 	zilog = zfsvfs->z_log;
  2540 top:
  2559 top:
  2541 	if (error = zfs_zaccess(dzp, ACE_ADD_FILE, cr)) {
  2560 	if (error = zfs_zaccess(dzp, ACE_ADD_FILE, cr)) {
  2542 		ZFS_EXIT(zfsvfs);
  2561 		ZFS_EXIT(zfsvfs);
  2543 		return (error);
  2562 		return (error);
  2544 	}
  2563 	}
  2648 	znode_t		*zp = VTOZ(vp);
  2667 	znode_t		*zp = VTOZ(vp);
  2649 	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
  2668 	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
  2650 	size_t		bufsz;
  2669 	size_t		bufsz;
  2651 	int		error;
  2670 	int		error;
  2652 
  2671 
  2653 	ZFS_ENTER(zfsvfs);
  2672 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
  2654 
  2673 
  2655 	bufsz = (size_t)zp->z_phys->zp_size;
  2674 	bufsz = (size_t)zp->z_phys->zp_size;
  2656 	if (bufsz + sizeof (znode_phys_t) <= zp->z_dbuf->db_size) {
  2675 	if (bufsz + sizeof (znode_phys_t) <= zp->z_dbuf->db_size) {
  2657 		error = uiomove(zp->z_phys + 1,
  2676 		error = uiomove(zp->z_phys + 1,
  2658 		    MIN((size_t)bufsz, uio->uio_resid), UIO_READ, uio);
  2677 		    MIN((size_t)bufsz, uio->uio_resid), UIO_READ, uio);
  2693 zfs_link(vnode_t *tdvp, vnode_t *svp, char *name, cred_t *cr)
  2712 zfs_link(vnode_t *tdvp, vnode_t *svp, char *name, cred_t *cr)
  2694 {
  2713 {
  2695 	znode_t		*dzp = VTOZ(tdvp);
  2714 	znode_t		*dzp = VTOZ(tdvp);
  2696 	znode_t		*tzp, *szp;
  2715 	znode_t		*tzp, *szp;
  2697 	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
  2716 	zfsvfs_t	*zfsvfs = dzp->z_zfsvfs;
  2698 	zilog_t		*zilog = zfsvfs->z_log;
  2717 	zilog_t		*zilog;
  2699 	zfs_dirlock_t	*dl;
  2718 	zfs_dirlock_t	*dl;
  2700 	dmu_tx_t	*tx;
  2719 	dmu_tx_t	*tx;
  2701 	vnode_t		*realvp;
  2720 	vnode_t		*realvp;
  2702 	int		error;
  2721 	int		error;
  2703 
  2722 
  2704 	ASSERT(tdvp->v_type == VDIR);
  2723 	ASSERT(tdvp->v_type == VDIR);
  2705 
  2724 
  2706 	ZFS_ENTER(zfsvfs);
  2725 	ZFS_ENTER_VERIFY_ZP(zfsvfs, dzp);
       
  2726 	zilog = zfsvfs->z_log;
  2707 
  2727 
  2708 	if (VOP_REALVP(svp, &realvp) == 0)
  2728 	if (VOP_REALVP(svp, &realvp) == 0)
  2709 		svp = realvp;
  2729 		svp = realvp;
  2710 
  2730 
  2711 	if (svp->v_vfsp != tdvp->v_vfsp) {
  2731 	if (svp->v_vfsp != tdvp->v_vfsp) {
  2712 		ZFS_EXIT(zfsvfs);
  2732 		ZFS_EXIT(zfsvfs);
  2713 		return (EXDEV);
  2733 		return (EXDEV);
  2714 	}
  2734 	}
  2715 
  2735 
  2716 	szp = VTOZ(svp);
  2736 	szp = VTOZ(svp);
       
  2737 	if (!szp->z_dbuf_held) {
       
  2738 		ZFS_EXIT(zfsvfs);
       
  2739 		return (EIO);
       
  2740 	}
  2717 top:
  2741 top:
  2718 	/*
  2742 	/*
  2719 	 * We do not support links between attributes and non-attributes
  2743 	 * We do not support links between attributes and non-attributes
  2720 	 * because of the potential security risk of creating links
  2744 	 * because of the potential security risk of creating links
  2721 	 * into "normal" file space in order to circumvent restrictions
  2745 	 * into "normal" file space in order to circumvent restrictions
  2945 	size_t		io_len;
  2969 	size_t		io_len;
  2946 	u_offset_t	io_off;
  2970 	u_offset_t	io_off;
  2947 	uint64_t	filesz;
  2971 	uint64_t	filesz;
  2948 	int		error = 0;
  2972 	int		error = 0;
  2949 
  2973 
  2950 	ZFS_ENTER(zfsvfs);
  2974 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
  2951 
  2975 
  2952 	ASSERT(zp->z_dbuf_held && zp->z_phys);
  2976 	ASSERT(zp->z_dbuf_held && zp->z_phys);
  2953 
  2977 
  2954 	if (len == 0) {
  2978 	if (len == 0) {
  2955 		/*
  2979 		/*
  3003 {
  3027 {
  3004 	znode_t	*zp = VTOZ(vp);
  3028 	znode_t	*zp = VTOZ(vp);
  3005 	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
  3029 	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
  3006 	int error;
  3030 	int error;
  3007 
  3031 
  3008 	rw_enter(&zfsvfs->z_unmount_inactive_lock, RW_READER);
  3032 	rw_enter(&zfsvfs->z_teardown_inactive_lock, RW_READER);
  3009 	if (zfsvfs->z_unmounted) {
  3033 	if (zp->z_dbuf_held == 0) {
  3010 		ASSERT(zp->z_dbuf_held == 0);
       
  3011 
       
  3012 		if (vn_has_cached_data(vp)) {
  3034 		if (vn_has_cached_data(vp)) {
  3013 			(void) pvn_vplist_dirty(vp, 0, zfs_null_putapage,
  3035 			(void) pvn_vplist_dirty(vp, 0, zfs_null_putapage,
  3014 			    B_INVAL, cr);
  3036 			    B_INVAL, cr);
  3015 		}
  3037 		}
  3016 
  3038 
  3020 			mutex_exit(&zp->z_lock);
  3042 			mutex_exit(&zp->z_lock);
  3021 			zfs_znode_free(zp);
  3043 			zfs_znode_free(zp);
  3022 		} else {
  3044 		} else {
  3023 			mutex_exit(&zp->z_lock);
  3045 			mutex_exit(&zp->z_lock);
  3024 		}
  3046 		}
  3025 		rw_exit(&zfsvfs->z_unmount_inactive_lock);
  3047 		rw_exit(&zfsvfs->z_teardown_inactive_lock);
  3026 		VFS_RELE(zfsvfs->z_vfs);
  3048 		VFS_RELE(zfsvfs->z_vfs);
  3027 		return;
  3049 		return;
  3028 	}
  3050 	}
  3029 
  3051 
  3030 	/*
  3052 	/*
  3051 			dmu_tx_commit(tx);
  3073 			dmu_tx_commit(tx);
  3052 		}
  3074 		}
  3053 	}
  3075 	}
  3054 
  3076 
  3055 	zfs_zinactive(zp);
  3077 	zfs_zinactive(zp);
  3056 	rw_exit(&zfsvfs->z_unmount_inactive_lock);
  3078 	rw_exit(&zfsvfs->z_teardown_inactive_lock);
  3057 }
  3079 }
  3058 
  3080 
  3059 /*
  3081 /*
  3060  * Bounds-check the seek operation.
  3082  * Bounds-check the seek operation.
  3061  *
  3083  *
  3085 {
  3107 {
  3086 	znode_t *zp = VTOZ(vp);
  3108 	znode_t *zp = VTOZ(vp);
  3087 	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
  3109 	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
  3088 	int error;
  3110 	int error;
  3089 
  3111 
  3090 	ZFS_ENTER(zfsvfs);
  3112 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
  3091 
  3113 
  3092 	/*
  3114 	/*
  3093 	 * We are following the UFS semantics with respect to mapcnt
  3115 	 * We are following the UFS semantics with respect to mapcnt
  3094 	 * here: If we see that the file is mapped already, then we will
  3116 	 * here: If we see that the file is mapped already, then we will
  3095 	 * return an error, but we don't worry about races between this
  3117 	 * return an error, but we don't worry about races between this
  3237 	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
  3259 	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
  3238 	page_t		*pp, **pl0 = pl;
  3260 	page_t		*pp, **pl0 = pl;
  3239 	int		need_unlock = 0, err = 0;
  3261 	int		need_unlock = 0, err = 0;
  3240 	offset_t	orig_off;
  3262 	offset_t	orig_off;
  3241 
  3263 
  3242 	ZFS_ENTER(zfsvfs);
  3264 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
  3243 
  3265 
  3244 	if (protp)
  3266 	if (protp)
  3245 		*protp = PROT_ALL;
  3267 		*protp = PROT_ALL;
  3246 
  3268 
  3247 	ASSERT(zp->z_dbuf_held && zp->z_phys);
  3269 	ASSERT(zp->z_dbuf_held && zp->z_phys);
  3369 	znode_t *zp = VTOZ(vp);
  3391 	znode_t *zp = VTOZ(vp);
  3370 	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
  3392 	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
  3371 	segvn_crargs_t	vn_a;
  3393 	segvn_crargs_t	vn_a;
  3372 	int		error;
  3394 	int		error;
  3373 
  3395 
  3374 	ZFS_ENTER(zfsvfs);
  3396 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
  3375 
  3397 
  3376 	if (vp->v_flag & VNOMAP) {
  3398 	if (vp->v_flag & VNOMAP) {
  3377 		ZFS_EXIT(zfsvfs);
  3399 		ZFS_EXIT(zfsvfs);
  3378 		return (ENOSYS);
  3400 		return (ENOSYS);
  3379 	}
  3401 	}
  3505 	znode_t		*zp = VTOZ(vp);
  3527 	znode_t		*zp = VTOZ(vp);
  3506 	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
  3528 	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
  3507 	uint64_t	off, len;
  3529 	uint64_t	off, len;
  3508 	int		error;
  3530 	int		error;
  3509 
  3531 
  3510 	ZFS_ENTER(zfsvfs);
  3532 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
  3511 
  3533 
  3512 top:
  3534 top:
  3513 	if (cmd != F_FREESP) {
  3535 	if (cmd != F_FREESP) {
  3514 		ZFS_EXIT(zfsvfs);
  3536 		ZFS_EXIT(zfsvfs);
  3515 		return (EINVAL);
  3537 		return (EINVAL);
  3540 static int
  3562 static int
  3541 zfs_fid(vnode_t *vp, fid_t *fidp)
  3563 zfs_fid(vnode_t *vp, fid_t *fidp)
  3542 {
  3564 {
  3543 	znode_t		*zp = VTOZ(vp);
  3565 	znode_t		*zp = VTOZ(vp);
  3544 	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
  3566 	zfsvfs_t	*zfsvfs = zp->z_zfsvfs;
  3545 	uint32_t	gen = (uint32_t)zp->z_phys->zp_gen;
  3567 	uint32_t	gen;
  3546 	uint64_t	object = zp->z_id;
  3568 	uint64_t	object = zp->z_id;
  3547 	zfid_short_t	*zfid;
  3569 	zfid_short_t	*zfid;
  3548 	int		size, i;
  3570 	int		size, i;
  3549 
  3571 
  3550 	ZFS_ENTER(zfsvfs);
  3572 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
       
  3573 	gen = (uint32_t)zp->z_gen;
  3551 
  3574 
  3552 	size = (zfsvfs->z_parent != zfsvfs) ? LONG_FID_LEN : SHORT_FID_LEN;
  3575 	size = (zfsvfs->z_parent != zfsvfs) ? LONG_FID_LEN : SHORT_FID_LEN;
  3553 	if (fidp->fid_len < size) {
  3576 	if (fidp->fid_len < size) {
  3554 		fidp->fid_len = size;
  3577 		fidp->fid_len = size;
  3555 		ZFS_EXIT(zfsvfs);
  3578 		ZFS_EXIT(zfsvfs);
  3605 		return (0);
  3628 		return (0);
  3606 
  3629 
  3607 	case _PC_XATTR_EXISTS:
  3630 	case _PC_XATTR_EXISTS:
  3608 		zp = VTOZ(vp);
  3631 		zp = VTOZ(vp);
  3609 		zfsvfs = zp->z_zfsvfs;
  3632 		zfsvfs = zp->z_zfsvfs;
  3610 		ZFS_ENTER(zfsvfs);
  3633 		ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
  3611 		*valp = 0;
  3634 		*valp = 0;
  3612 		error = zfs_dirent_lock(&dl, zp, "", &xzp,
  3635 		error = zfs_dirent_lock(&dl, zp, "", &xzp,
  3613 		    ZXATTR | ZEXISTS | ZSHARED);
  3636 		    ZXATTR | ZEXISTS | ZSHARED);
  3614 		if (error == 0) {
  3637 		if (error == 0) {
  3615 			zfs_dirent_unlock(dl);
  3638 			zfs_dirent_unlock(dl);
  3645 {
  3668 {
  3646 	znode_t *zp = VTOZ(vp);
  3669 	znode_t *zp = VTOZ(vp);
  3647 	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
  3670 	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
  3648 	int error;
  3671 	int error;
  3649 
  3672 
  3650 	ZFS_ENTER(zfsvfs);
  3673 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
  3651 	error = zfs_getacl(zp, vsecp, cr);
  3674 	error = zfs_getacl(zp, vsecp, cr);
  3652 	ZFS_EXIT(zfsvfs);
  3675 	ZFS_EXIT(zfsvfs);
  3653 
  3676 
  3654 	return (error);
  3677 	return (error);
  3655 }
  3678 }
  3660 {
  3683 {
  3661 	znode_t *zp = VTOZ(vp);
  3684 	znode_t *zp = VTOZ(vp);
  3662 	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
  3685 	zfsvfs_t *zfsvfs = zp->z_zfsvfs;
  3663 	int error;
  3686 	int error;
  3664 
  3687 
  3665 	ZFS_ENTER(zfsvfs);
  3688 	ZFS_ENTER_VERIFY_ZP(zfsvfs, zp);
  3666 	error = zfs_setacl(zp, vsecp, cr);
  3689 	error = zfs_setacl(zp, vsecp, cr);
  3667 	ZFS_EXIT(zfsvfs);
  3690 	ZFS_EXIT(zfsvfs);
  3668 	return (error);
  3691 	return (error);
  3669 }
  3692 }
  3670 
  3693