Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 08 Jul 2011 15:49:39 +0000
From:      gk@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r224050 - in soc2011/gk/ino64-head/sys: fs/nfs fs/nfsclient fs/nfsserver nfsclient nfsserver
Message-ID:  <20110708154939.BB272106566B@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: gk
Date: Fri Jul  8 15:49:39 2011
New Revision: 224050
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=224050

Log:
  Remove readdir cookies and set d_off in NFS

Modified:
  soc2011/gk/ino64-head/sys/fs/nfs/nfs.h
  soc2011/gk/ino64-head/sys/fs/nfs/nfs_commonport.c
  soc2011/gk/ino64-head/sys/fs/nfs/nfs_commonsubs.c
  soc2011/gk/ino64-head/sys/fs/nfs/nfs_var.h
  soc2011/gk/ino64-head/sys/fs/nfs/nfsport.h
  soc2011/gk/ino64-head/sys/fs/nfsclient/nfs_clrpcops.c
  soc2011/gk/ino64-head/sys/fs/nfsserver/nfs_nfsdport.c
  soc2011/gk/ino64-head/sys/fs/nfsserver/nfs_nfsdsubs.c
  soc2011/gk/ino64-head/sys/nfsclient/nfs_vnops.c
  soc2011/gk/ino64-head/sys/nfsserver/nfs_serv.c

Modified: soc2011/gk/ino64-head/sys/fs/nfs/nfs.h
==============================================================================
--- soc2011/gk/ino64-head/sys/fs/nfs/nfs.h	Fri Jul  8 14:30:06 2011	(r224049)
+++ soc2011/gk/ino64-head/sys/fs/nfs/nfs.h	Fri Jul  8 15:49:39 2011	(r224050)
@@ -251,7 +251,7 @@
 	u_char		*nfr_srvlist;	/* List of servers */
 	int		nfr_srvcnt;	/* number of servers */
 	vnode_t		nfr_vp;	/* vnode for referral */
-	u_int32_t	nfr_dfileno;	/* assigned dir inode# */
+	u_int64_t	nfr_dfileno;	/* assigned dir inode# */
 };
 
 /*

Modified: soc2011/gk/ino64-head/sys/fs/nfs/nfs_commonport.c
==============================================================================
--- soc2011/gk/ino64-head/sys/fs/nfs/nfs_commonport.c	Fri Jul  8 14:30:06 2011	(r224049)
+++ soc2011/gk/ino64-head/sys/fs/nfs/nfs_commonport.c	Fri Jul  8 15:49:39 2011	(r224050)
@@ -291,7 +291,7 @@
 
 /* Fake nfsrv_atroot. Just return 0 */
 int
-nfsrv_atroot(struct vnode *vp, long *retp)
+nfsrv_atroot(struct vnode *vp, ino_t *retp)
 {
 
 	return (0);
@@ -372,7 +372,7 @@
  * Get referral. For now, just fail.
  */
 struct nfsreferral *
-nfsv4root_getreferral(struct vnode *vp, struct vnode *dvp, u_int32_t fileno)
+nfsv4root_getreferral(struct vnode *vp, struct vnode *dvp, u_int64_t fileno)
 {
 
 	return (NULL);

Modified: soc2011/gk/ino64-head/sys/fs/nfs/nfs_commonsubs.c
==============================================================================
--- soc2011/gk/ino64-head/sys/fs/nfs/nfs_commonsubs.c	Fri Jul  8 14:30:06 2011	(r224049)
+++ soc2011/gk/ino64-head/sys/fs/nfs/nfs_commonsubs.c	Fri Jul  8 15:49:39 2011	(r224050)
@@ -767,7 +767,7 @@
 	struct timespec temptime;
 	uid_t uid;
 	gid_t gid;
-	long fid;
+	ino_t fid;
 	u_int32_t freenum = 0, tuint;
 	u_int64_t uquad = 0, thyp, thyp2;
 #ifdef QUOTA
@@ -1671,7 +1671,7 @@
 				} else {
 					if (!vp || !nfsrv_atroot(vp, &fid))
 						fid = nap->na_fileid;
-					if ((u_int64_t)fid != thyp)
+					if (fid != thyp)
 						*retcmpp = NFSERR_NOTSAME;
 				}
 			    }

Modified: soc2011/gk/ino64-head/sys/fs/nfs/nfs_var.h
==============================================================================
--- soc2011/gk/ino64-head/sys/fs/nfs/nfs_var.h	Fri Jul  8 14:30:06 2011	(r224049)
+++ soc2011/gk/ino64-head/sys/fs/nfs/nfs_var.h	Fri Jul  8 15:49:39 2011	(r224050)
@@ -324,8 +324,8 @@
 struct ucred *newnfs_getcred(void);
 void newnfs_setroot(struct ucred *);
 int nfs_catnap(int, int, const char *);
-struct nfsreferral *nfsv4root_getreferral(vnode_t, vnode_t, u_int32_t);
-int nfsrv_atroot(vnode_t, long *);
+struct nfsreferral *nfsv4root_getreferral(vnode_t, vnode_t, u_int64_t);
+int nfsrv_atroot(vnode_t, ino_t *);
 void newnfs_timer(void *);
 int nfs_supportsnfsv4acls(vnode_t);
 

Modified: soc2011/gk/ino64-head/sys/fs/nfs/nfsport.h
==============================================================================
--- soc2011/gk/ino64-head/sys/fs/nfs/nfsport.h	Fri Jul  8 14:30:06 2011	(r224049)
+++ soc2011/gk/ino64-head/sys/fs/nfs/nfsport.h	Fri Jul  8 15:49:39 2011	(r224050)
@@ -385,7 +385,7 @@
 struct nfsvattr {
 	struct vattr	na_vattr;
 	nfsattrbit_t	na_suppattr;
-	u_int32_t	na_mntonfileno;
+	u_int64_t	na_mntonfileno;
 	u_int64_t	na_filesid[2];
 };
 

Modified: soc2011/gk/ino64-head/sys/fs/nfsclient/nfs_clrpcops.c
==============================================================================
--- soc2011/gk/ino64-head/sys/fs/nfsclient/nfs_clrpcops.c	Fri Jul  8 14:30:06 2011	(r224049)
+++ soc2011/gk/ino64-head/sys/fs/nfsclient/nfs_clrpcops.c	Fri Jul  8 15:49:39 2011	(r224050)
@@ -2635,6 +2635,7 @@
 			dp->d_name[0] = '.';
 			dp->d_name[1] = '\0';
 			dp->d_reclen = DIRENT_SIZE(dp) + NFSX_HYPER;
+			dp->d_off = 0;
 			/*
 			 * Just make these offset cookie 0.
 			 */
@@ -2654,6 +2655,7 @@
 			dp->d_name[1] = '.';
 			dp->d_name[2] = '\0';
 			dp->d_reclen = DIRENT_SIZE(dp) + NFSX_HYPER;
+			dp->d_off = 0;
 			/*
 			 * Just make these offset cookie 0.
 			 */
@@ -2764,6 +2766,7 @@
 				uio_iov_len_add(uiop, -(left));
 				uio_uio_resid_add(uiop, -(left));
 				uiop->uio_offset += left;
+				dp->d_off = uiop->uio_offset;
 				blksiz = 0;
 			}
 			if ((int)(tlen + DIRHDSIZ + NFSX_HYPER) > uio_uio_resid(uiop))
@@ -2792,6 +2795,7 @@
 				uio_iov_len_add(uiop, -(tlen + NFSX_HYPER));
 				uio_uio_resid_add(uiop, -(tlen + NFSX_HYPER));
 				uiop->uio_offset += (tlen + NFSX_HYPER);
+				dp->d_off = uiop->uio_offset;
 			} else {
 				error = nfsm_advance(nd, NFSM_RNDUP(len), -1);
 				if (error)
@@ -2878,6 +2882,7 @@
 		uio_iov_len_add(uiop, -(left));
 		uio_uio_resid_add(uiop, -(left));
 		uiop->uio_offset += left;
+		dp->d_off = uiop->uio_offset;
 	}
 
 	/*
@@ -2902,6 +2907,7 @@
 		dp = (struct dirent *) CAST_DOWN(caddr_t, uio_iov_base(uiop));
 		dp->d_type = DT_UNKNOWN;
 		dp->d_fileno = 0;
+		dp->d_off = 0;
 		dp->d_namlen = 0;
 		dp->d_name[0] = '\0';
 		tl = (u_int32_t *)&dp->d_name[4];

Modified: soc2011/gk/ino64-head/sys/fs/nfsserver/nfs_nfsdport.c
==============================================================================
--- soc2011/gk/ino64-head/sys/fs/nfsserver/nfs_nfsdport.c	Fri Jul  8 14:30:06 2011	(r224049)
+++ soc2011/gk/ino64-head/sys/fs/nfsserver/nfs_nfsdport.c	Fri Jul  8 15:49:39 2011	(r224050)
@@ -1456,12 +1456,10 @@
 	char *cpos, *cend, *rbuf;
 	struct nfsvattr at;
 	int nlen, error = 0, getret = 1;
-	int siz, cnt, fullsiz, eofflag, ncookies;
+	int siz, cnt, fullsiz, eofflag;
 	u_int64_t off, toff, verf;
-	u_long *cookies = NULL, *cookiep;
 	struct uio io;
 	struct iovec iv;
-	int not_zfs;
 
 	if (nd->nd_repstat) {
 		nfsrv_postopattr(nd, getret, &at);
@@ -1514,14 +1512,8 @@
 			nfsrv_postopattr(nd, getret, &at);
 		return (0);
 	}
-	not_zfs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "zfs");
 	MALLOC(rbuf, caddr_t, siz, M_TEMP, M_WAITOK);
-again:
 	eofflag = 0;
-	if (cookies) {
-		free((caddr_t)cookies, M_TEMP);
-		cookies = NULL;
-	}
 
 	iv.iov_base = rbuf;
 	iv.iov_len = siz;
@@ -1532,14 +1524,11 @@
 	io.uio_segflg = UIO_SYSSPACE;
 	io.uio_rw = UIO_READ;
 	io.uio_td = NULL;
-	nd->nd_repstat = VOP_READDIR(vp, &io, nd->nd_cred, &eofflag, &ncookies,
-	    &cookies);
+	nd->nd_repstat = VOP_READDIR(vp, &io, nd->nd_cred, &eofflag);
 	off = (u_int64_t)io.uio_offset;
 	if (io.uio_resid)
 		siz -= io.uio_resid;
 
-	if (!cookies && !nd->nd_repstat)
-		nd->nd_repstat = NFSERR_PERM;
 	if (nd->nd_flag & ND_NFSV3) {
 		getret = nfsvno_getattr(vp, &at, nd->nd_cred, p, 1);
 		if (!nd->nd_repstat)
@@ -1552,8 +1541,6 @@
 	if (nd->nd_repstat) {
 		vput(vp);
 		free((caddr_t)rbuf, M_TEMP);
-		if (cookies)
-			free((caddr_t)cookies, M_TEMP);
 		if (nd->nd_flag & ND_NFSV3)
 			nfsrv_postopattr(nd, getret, &at);
 		return (0);
@@ -1575,7 +1562,6 @@
 		*tl++ = newnfs_false;
 		*tl = newnfs_true;
 		FREE((caddr_t)rbuf, M_TEMP);
-		FREE((caddr_t)cookies, M_TEMP);
 		return (0);
 	}
 
@@ -1586,30 +1572,7 @@
 	cpos = rbuf;
 	cend = rbuf + siz;
 	dp = (struct dirent *)cpos;
-	cookiep = cookies;
 
-	/*
-	 * For some reason FreeBSD's ufs_readdir() chooses to back the
-	 * directory offset up to a block boundary, so it is necessary to
-	 * skip over the records that precede the requested offset. This
-	 * requires the assumption that file offset cookies monotonically
-	 * increase.
-	 * Since the offset cookies don't monotonically increase for ZFS,
-	 * this is not done when ZFS is the file system.
-	 */
-	while (cpos < cend && ncookies > 0 &&
-	    (dp->d_fileno == 0 || dp->d_type == DT_WHT ||
-	     (not_zfs != 0 && ((u_quad_t)(*cookiep)) <= toff))) {
-		cpos += dp->d_reclen;
-		dp = (struct dirent *)cpos;
-		cookiep++;
-		ncookies--;
-	}
-	if (cpos >= cend || ncookies == 0) {
-		siz = fullsiz;
-		toff = off;
-		goto again;
-	}
 	vput(vp);
 
 	/*
@@ -1628,7 +1591,7 @@
 	}
 
 	/* Loop through the records and build reply */
-	while (cpos < cend && ncookies > 0) {
+	while (cpos < cend) {
 		nlen = dp->d_namlen;
 		if (dp->d_fileno != 0 && dp->d_type != DT_WHT &&
 			nlen <= NFS_MAXNAMLEN) {
@@ -1648,24 +1611,23 @@
 			if (nd->nd_flag & ND_NFSV3) {
 				NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
 				*tl++ = newnfs_true;
-				*tl++ = 0;
+				txdr_hyper(dp->d_fileno, tl);
 			} else {
 				NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
 				*tl++ = newnfs_true;
+				*tl = txdr_unsigned(dp->d_fileno);
 			}
-			*tl = txdr_unsigned(dp->d_fileno);
 			(void) nfsm_strtom(nd, dp->d_name, nlen);
 			if (nd->nd_flag & ND_NFSV3) {
 				NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
-				*tl++ = 0;
-			} else
+				txdr_hyper(dp->d_off, tl);
+			} else {
 				NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
-			*tl = txdr_unsigned(*cookiep);
+				*tl = txdr_unsigned(dp->d_off);
+			}
 		}
 		cpos += dp->d_reclen;
 		dp = (struct dirent *)cpos;
-		cookiep++;
-		ncookies--;
 	}
 	if (cpos < cend)
 		eofflag = 0;
@@ -1676,7 +1638,6 @@
 	else
 		*tl = newnfs_false;
 	FREE((caddr_t)rbuf, M_TEMP);
-	FREE((caddr_t)cookies, M_TEMP);
 	return (0);
 nfsmout:
 	vput(vp);
@@ -1700,15 +1661,14 @@
 	struct mbuf *mb0, *mb1;
 	struct nfsreferral *refp;
 	int nlen, r, error = 0, getret = 1, usevget = 1;
-	int siz, cnt, fullsiz, eofflag, ncookies, entrycnt;
+	int siz, cnt, fullsiz, eofflag, entrycnt;
 	caddr_t bpos0, bpos1;
 	u_int64_t off, toff, verf;
-	u_long *cookies = NULL, *cookiep;
 	nfsattrbit_t attrbits, rderrbits, savbits;
 	struct uio io;
 	struct iovec iv;
 	struct componentname cn;
-	int at_root, needs_unbusy, not_zfs, supports_nfsv4acls;
+	int at_root, needs_unbusy, supports_nfsv4acls;
 	struct mount *mp, *new_mp;
 	uint64_t mounted_on_fileno;
 
@@ -1788,15 +1748,9 @@
 			nfsrv_postopattr(nd, getret, &at);
 		return (0);
 	}
-	not_zfs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "zfs");
 
 	MALLOC(rbuf, caddr_t, siz, M_TEMP, M_WAITOK);
-again:
 	eofflag = 0;
-	if (cookies) {
-		free((caddr_t)cookies, M_TEMP);
-		cookies = NULL;
-	}
 
 	iv.iov_base = rbuf;
 	iv.iov_len = siz;
@@ -1807,22 +1761,17 @@
 	io.uio_segflg = UIO_SYSSPACE;
 	io.uio_rw = UIO_READ;
 	io.uio_td = NULL;
-	nd->nd_repstat = VOP_READDIR(vp, &io, nd->nd_cred, &eofflag, &ncookies,
-	    &cookies);
+	nd->nd_repstat = VOP_READDIR(vp, &io, nd->nd_cred, &eofflag);
 	off = (u_int64_t)io.uio_offset;
 	if (io.uio_resid)
 		siz -= io.uio_resid;
 
 	getret = nfsvno_getattr(vp, &at, nd->nd_cred, p, 1);
 
-	if (!cookies && !nd->nd_repstat)
-		nd->nd_repstat = NFSERR_PERM;
 	if (!nd->nd_repstat)
 		nd->nd_repstat = getret;
 	if (nd->nd_repstat) {
 		vput(vp);
-		if (cookies)
-			free((caddr_t)cookies, M_TEMP);
 		free((caddr_t)rbuf, M_TEMP);
 		if (nd->nd_flag & ND_NFSV3)
 			nfsrv_postopattr(nd, getret, &at);
@@ -1841,7 +1790,6 @@
 		tl += 2;
 		*tl++ = newnfs_false;
 		*tl = newnfs_true;
-		free((caddr_t)cookies, M_TEMP);
 		free((caddr_t)rbuf, M_TEMP);
 		return (0);
 	}
@@ -1853,33 +1801,6 @@
 	cpos = rbuf;
 	cend = rbuf + siz;
 	dp = (struct dirent *)cpos;
-	cookiep = cookies;
-
-	/*
-	 * For some reason FreeBSD's ufs_readdir() chooses to back the
-	 * directory offset up to a block boundary, so it is necessary to
-	 * skip over the records that precede the requested offset. This
-	 * requires the assumption that file offset cookies monotonically
-	 * increase.
-	 * Since the offset cookies don't monotonically increase for ZFS,
-	 * this is not done when ZFS is the file system.
-	 */
-	while (cpos < cend && ncookies > 0 &&
-	  (dp->d_fileno == 0 || dp->d_type == DT_WHT ||
-	   (not_zfs != 0 && ((u_quad_t)(*cookiep)) <= toff) ||
-	   ((nd->nd_flag & ND_NFSV4) &&
-	    ((dp->d_namlen == 1 && dp->d_name[0] == '.') ||
-	     (dp->d_namlen==2 && dp->d_name[0]=='.' && dp->d_name[1]=='.'))))) {
-		cpos += dp->d_reclen;
-		dp = (struct dirent *)cpos;
-		cookiep++;
-		ncookies--;
-	}
-	if (cpos >= cend || ncookies == 0) {
-		siz = fullsiz;
-		toff = off;
-		goto again;
-	}
 
 	/*
 	 * Busy the file system so that the mount point won't go away
@@ -1892,7 +1813,6 @@
 	vfs_rel(mp);
 	if (nd->nd_repstat != 0) {
 		vrele(vp);
-		free(cookies, M_TEMP);
 		free(rbuf, M_TEMP);
 		if (nd->nd_flag & ND_NFSV3)
 			nfsrv_postopattr(nd, getret, &at);
@@ -1929,7 +1849,7 @@
 
 	/* Loop through the records and build reply */
 	entrycnt = 0;
-	while (cpos < cend && ncookies > 0 && dirlen < cnt) {
+	while (cpos < cend && dirlen < cnt) {
 		nlen = dp->d_namlen;
 		if (dp->d_fileno != 0 && dp->d_type != DT_WHT &&
 		    nlen <= NFS_MAXNAMLEN &&
@@ -2060,12 +1980,12 @@
 			if (nd->nd_flag & ND_NFSV3) {
 				NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
 				*tl++ = newnfs_true;
-				*tl++ = 0;
-				*tl = txdr_unsigned(dp->d_fileno);
+				txdr_hyper(dp->d_fileno, tl);
+				tl += 2;
 				dirlen += nfsm_strtom(nd, dp->d_name, nlen);
 				NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
-				*tl++ = 0;
-				*tl = txdr_unsigned(*cookiep);
+				txdr_hyper(dp->d_off, tl);
+				tl += 2;
 				nfsrv_postopattr(nd, 0, nvap);
 				dirlen += nfsm_fhtom(nd,(u_int8_t *)&nfh,0,1);
 				dirlen += (5*NFSX_UNSIGNED+NFSX_V3POSTOPATTR);
@@ -2074,8 +1994,8 @@
 			} else {
 				NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
 				*tl++ = newnfs_true;
-				*tl++ = 0;
-				*tl = txdr_unsigned(*cookiep);
+				txdr_hyper(dp->d_off, tl);
+				tl += 2;
 				dirlen += nfsm_strtom(nd, dp->d_name, nlen);
 				if (nvp != NULL) {
 					supports_nfsv4acls =
@@ -2118,8 +2038,6 @@
 		}
 		cpos += dp->d_reclen;
 		dp = (struct dirent *)cpos;
-		cookiep++;
-		ncookies--;
 	}
 	vrele(vp);
 	vfs_unbusy(mp);
@@ -2146,7 +2064,6 @@
 		else
 			*tl = newnfs_false;
 	}
-	FREE((caddr_t)cookies, M_TEMP);
 	FREE((caddr_t)rbuf, M_TEMP);
 	return (0);
 nfsmout:

Modified: soc2011/gk/ino64-head/sys/fs/nfsserver/nfs_nfsdsubs.c
==============================================================================
--- soc2011/gk/ino64-head/sys/fs/nfsserver/nfs_nfsdsubs.c	Fri Jul  8 14:30:06 2011	(r224049)
+++ soc2011/gk/ino64-head/sys/fs/nfsserver/nfs_nfsdsubs.c	Fri Jul  8 15:49:39 2011	(r224050)
@@ -1751,8 +1751,8 @@
 			break;
 		case NFSATTRBIT_MOUNTEDONFILEID:
 			NFSM_BUILD(tl, u_int32_t *, NFSX_HYPER);
-			*tl++ = 0;
-			*tl = txdr_unsigned(refp->nfr_dfileno);
+			txdr_hyper(refp->nfr_dfileno, tl);
+			tl += 2;
 			retnum += NFSX_HYPER;
 			break;
 		default:

Modified: soc2011/gk/ino64-head/sys/nfsclient/nfs_vnops.c
==============================================================================
--- soc2011/gk/ino64-head/sys/nfsclient/nfs_vnops.c	Fri Jul  8 14:30:06 2011	(r224049)
+++ soc2011/gk/ino64-head/sys/nfsclient/nfs_vnops.c	Fri Jul  8 15:49:39 2011	(r224050)
@@ -2364,13 +2364,14 @@
 				uiop->uio_iov->iov_len -= left;
 				uiop->uio_offset += left;
 				uiop->uio_resid -= left;
+				dp->d_off = uiop->uio_offset;
 				blksiz = 0;
 			}
 			if ((tlen + DIRHDSIZ) > uiop->uio_resid)
 				bigenough = 0;
 			if (bigenough) {
 				dp = (struct dirent *)uiop->uio_iov->iov_base;
-				dp->d_fileno = (int)fileno;
+				dp->d_fileno = fileno;
 				dp->d_namlen = len;
 				dp->d_reclen = tlen + DIRHDSIZ;
 				dp->d_type = DT_UNKNOWN;
@@ -2391,6 +2392,7 @@
 				uiop->uio_iov->iov_len -= tlen;
 				uiop->uio_offset += tlen;
 				uiop->uio_resid -= tlen;
+				dp->d_off = uiop->uio_offset;
 			} else
 				nfsm_adv(nfsm_rndup(len));
 			if (v3) {
@@ -2431,6 +2433,7 @@
 		uiop->uio_iov->iov_len -= left;
 		uiop->uio_offset += left;
 		uiop->uio_resid -= left;
+		dp->d_off = uiop->uio_offset;
 	}
 
 	/*
@@ -2558,7 +2561,7 @@
 				bigenough = 0;
 			if (bigenough) {
 				dp = (struct dirent *)uiop->uio_iov->iov_base;
-				dp->d_fileno = (int)fileno;
+				dp->d_fileno = fileno;
 				dp->d_namlen = len;
 				dp->d_reclen = tlen + DIRHDSIZ;
 				dp->d_type = DT_UNKNOWN;

Modified: soc2011/gk/ino64-head/sys/nfsserver/nfs_serv.c
==============================================================================
--- soc2011/gk/ino64-head/sys/nfsserver/nfs_serv.c	Fri Jul  8 14:30:06 2011	(r224049)
+++ soc2011/gk/ino64-head/sys/nfsserver/nfs_serv.c	Fri Jul  8 15:49:39 2011	(r224050)
@@ -2735,11 +2735,10 @@
 	struct uio io;
 	struct iovec iv;
 	int len, nlen, rem, xfer, tsiz, i, error = 0, getret = 1;
-	int siz, cnt, fullsiz, eofflag, rdonly, ncookies;
+	int siz, cnt, fullsiz, eofflag, rdonly;
 	int v3 = (nfsd->nd_flag & ND_NFSV3);
 	u_quad_t off, toff, verf;
-	u_long *cookies = NULL, *cookiep; /* needs to be int64_t or off_t */
-	int vfslocked, not_zfs;
+	int vfslocked;
 
 	nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
 	vfslocked = 0;
@@ -2803,14 +2802,12 @@
 		error = 0;
 		goto nfsmout;
 	}
-	not_zfs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "zfs") != 0;
 	VOP_UNLOCK(vp, 0);
 
 	/*
 	 * end section.  Allocate rbuf and continue
 	 */
 	rbuf = malloc(siz, M_TEMP, M_WAITOK);
-again:
 	iv.iov_base = rbuf;
 	iv.iov_len = fullsiz;
 	io.uio_iov = &iv;
@@ -2821,15 +2818,9 @@
 	io.uio_rw = UIO_READ;
 	io.uio_td = NULL;
 	eofflag = 0;
-	if (cookies) {
-		free((caddr_t)cookies, M_TEMP);
-		cookies = NULL;
-	}
 	vn_lock(vp, LK_SHARED | LK_RETRY);
-	error = VOP_READDIR(vp, &io, cred, &eofflag, &ncookies, &cookies);
+	error = VOP_READDIR(vp, &io, cred, &eofflag);
 	off = (off_t)io.uio_offset;
-	if (!cookies && !error)
-		error = NFSERR_PERM;
 	if (v3) {
 		getret = VOP_GETATTR(vp, &at, cred);
 		if (!error)
@@ -2840,8 +2831,6 @@
 		vrele(vp);
 		vp = NULL;
 		free((caddr_t)rbuf, M_TEMP);
-		if (cookies)
-			free((caddr_t)cookies, M_TEMP);
 		nfsm_reply(NFSX_POSTOPATTR(v3));
 		if (v3)
 			nfsm_srvpostop_attr(getret, &at);
@@ -2870,7 +2859,6 @@
 			*tl++ = nfsrv_nfs_false;
 			*tl = nfsrv_nfs_true;
 			free((caddr_t)rbuf, M_TEMP);
-			free((caddr_t)cookies, M_TEMP);
 			error = 0;
 			goto nfsmout;
 		}
@@ -2883,29 +2871,6 @@
 	cpos = rbuf;
 	cend = rbuf + siz;
 	dp = (struct dirent *)cpos;
-	cookiep = cookies;
-	/*
-	 * For some reason FreeBSD's ufs_readdir() chooses to back the
-	 * directory offset up to a block boundary, so it is necessary to
-	 * skip over the records that precede the requested offset. This
-	 * requires the assumption that file offset cookies monotonically
-	 * increase.
-	 * Since the offset cookies don't monotonically increase for ZFS,
-	 * this is not done when ZFS is the file system.
-	 */
-	while (cpos < cend && ncookies > 0 &&
-		(dp->d_fileno == 0 || dp->d_type == DT_WHT ||
-		 (not_zfs != 0 && ((u_quad_t)(*cookiep)) <= toff))) {
-		cpos += dp->d_reclen;
-		dp = (struct dirent *)cpos;
-		cookiep++;
-		ncookies--;
-	}
-	if (cpos >= cend || ncookies == 0) {
-		toff = off;
-		siz = fullsiz;
-		goto again;
-	}
 
 	len = 3 * NFSX_UNSIGNED;	/* paranoia, probably can be 0 */
 	nfsm_reply(NFSX_POSTOPATTR(v3) + NFSX_COOKIEVERF(v3) + siz);
@@ -2919,7 +2884,7 @@
 	be = bp + M_TRAILINGSPACE(mp);
 
 	/* Loop through the records and build reply */
-	while (cpos < cend && ncookies > 0) {
+	while (cpos < cend) {
 		if (dp->d_fileno != 0 && dp->d_type != DT_WHT) {
 			nlen = dp->d_namlen;
 			rem = nfsm_rndup(nlen) - nlen;
@@ -2937,15 +2902,15 @@
 			nfsm_clget;
 			*tl = nfsrv_nfs_true;
 			bp += NFSX_UNSIGNED;
+			nfsm_clget;
 			if (v3) {
-				nfsm_clget;
-				*tl = 0;
+				txdr_hyper(dp->d_fileno, tl);
+				bp += 2 * NFSX_UNSIGNED;
+			} else {
+				*tl = txdr_unsigned(dp->d_fileno);
 				bp += NFSX_UNSIGNED;
 			}
 			nfsm_clget;
-			*tl = txdr_unsigned(dp->d_fileno);
-			bp += NFSX_UNSIGNED;
-			nfsm_clget;
 			*tl = txdr_unsigned(nlen);
 			bp += NFSX_UNSIGNED;
 
@@ -2971,17 +2936,16 @@
 
 			/* Finish off the record */
 			if (v3) {
-				*tl = 0;
-				bp += NFSX_UNSIGNED;
+				txdr_hyper(dp->d_off, tl);
+				bp += 2 * NFSX_UNSIGNED;
 				nfsm_clget;
+			} else {
+				*tl = txdr_unsigned(dp->d_off);
+				bp += NFSX_UNSIGNED;
 			}
-			*tl = txdr_unsigned(*cookiep);
-			bp += NFSX_UNSIGNED;
 		}
 		cpos += dp->d_reclen;
 		dp = (struct dirent *)cpos;
-		cookiep++;
-		ncookies--;
 	}
 	vrele(vp);
 	vp = NULL;
@@ -3000,7 +2964,6 @@
 	} else
 		mp->m_len += bp - bpos;
 	free((caddr_t)rbuf, M_TEMP);
-	free((caddr_t)cookies, M_TEMP);
 
 nfsmout:
 	if (vp)
@@ -3035,14 +2998,12 @@
 	struct nfs_fattr *fp;
 	int len, nlen, rem, xfer, tsiz, i, error = 0, error1, getret = 1;
 	int vp_locked;
-	int siz, cnt, fullsiz, eofflag, rdonly, dirlen, ncookies;
+	int siz, cnt, fullsiz, eofflag, rdonly, dirlen;
 	u_quad_t off, toff, verf;
-	u_long *cookies = NULL, *cookiep; /* needs to be int64_t or off_t */
 	int v3 = (nfsd->nd_flag & ND_NFSV3);
 	int usevget = 1, vfslocked;
 	struct componentname cn;
 	struct mount *mntp = NULL;
-	int not_zfs;
 
 	nfsdbprintf(("%s %d\n", __FILE__, __LINE__));
 	vfslocked = 0;
@@ -3103,11 +3064,9 @@
 		error = 0;
 		goto nfsmout;
 	}
-	not_zfs = strcmp(vp->v_mount->mnt_vfc->vfc_name, "zfs") != 0;
 	VOP_UNLOCK(vp, 0);
 	vp_locked = 0;
 	rbuf = malloc(siz, M_TEMP, M_WAITOK);
-again:
 	iv.iov_base = rbuf;
 	iv.iov_len = fullsiz;
 	io.uio_iov = &iv;
@@ -3119,25 +3078,17 @@
 	io.uio_td = NULL;
 	eofflag = 0;
 	vp_locked = 1;
-	if (cookies) {
-		free((caddr_t)cookies, M_TEMP);
-		cookies = NULL;
-	}
 	vn_lock(vp, LK_SHARED | LK_RETRY);
-	error = VOP_READDIR(vp, &io, cred, &eofflag, &ncookies, &cookies);
+	error = VOP_READDIR(vp, &io, cred, &eofflag);
 	off = (u_quad_t)io.uio_offset;
 	getret = VOP_GETATTR(vp, &at, cred);
 	VOP_UNLOCK(vp, 0);
 	vp_locked = 0;
-	if (!cookies && !error)
-		error = NFSERR_PERM;
 	if (!error)
 		error = getret;
 	if (error) {
 		vrele(vp);
 		vp = NULL;
-		if (cookies)
-			free((caddr_t)cookies, M_TEMP);
 		free((caddr_t)rbuf, M_TEMP);
 		nfsm_reply(NFSX_V3POSTOPATTR);
 		nfsm_srvpostop_attr(getret, &at);
@@ -3162,7 +3113,6 @@
 			tl += 2;
 			*tl++ = nfsrv_nfs_false;
 			*tl = nfsrv_nfs_true;
-			free((caddr_t)cookies, M_TEMP);
 			free((caddr_t)rbuf, M_TEMP);
 			error = 0;
 			goto nfsmout;
@@ -3176,29 +3126,6 @@
 	cpos = rbuf;
 	cend = rbuf + siz;
 	dp = (struct dirent *)cpos;
-	cookiep = cookies;
-	/*
-	 * For some reason FreeBSD's ufs_readdir() chooses to back the
-	 * directory offset up to a block boundary, so it is necessary to
-	 * skip over the records that precede the requested offset. This
-	 * requires the assumption that file offset cookies monotonically
-	 * increase.
-	 * Since the offset cookies don't monotonically increase for ZFS,
-	 * this is not done when ZFS is the file system.
-	 */
-	while (cpos < cend && ncookies > 0 &&
-		(dp->d_fileno == 0 || dp->d_type == DT_WHT ||
-		 (not_zfs != 0 && ((u_quad_t)(*cookiep)) <= toff))) {
-		cpos += dp->d_reclen;
-		dp = (struct dirent *)cpos;
-		cookiep++;
-		ncookies--;
-	}
-	if (cpos >= cend || ncookies == 0) {
-		toff = off;
-		siz = fullsiz;
-		goto again;
-	}
 
 	dirlen = len = NFSX_V3POSTOPATTR + NFSX_V3COOKIEVERF +
 	    2 * NFSX_UNSIGNED;
@@ -3211,7 +3138,7 @@
 	be = bp + M_TRAILINGSPACE(mp);
 
 	/* Loop through the records and build reply */
-	while (cpos < cend && ncookies > 0) {
+	while (cpos < cend) {
 		if (dp->d_fileno != 0 && dp->d_type != DT_WHT) {
 			nlen = dp->d_namlen;
 			rem = nfsm_rndup(nlen)-nlen;
@@ -3298,18 +3225,14 @@
 			fl.fl_fhsize = txdr_unsigned(NFSX_V3FH);
 			fl.fl_fhok = nfsrv_nfs_true;
 			fl.fl_postopok = nfsrv_nfs_true;
-			fl.fl_off.nfsuquad[0] = 0;
-			fl.fl_off.nfsuquad[1] = txdr_unsigned(*cookiep);
+			txdr_hyper(dp->d_off, &fl.fl_off);
 
 			nfsm_clget;
 			*tl = nfsrv_nfs_true;
 			bp += NFSX_UNSIGNED;
 			nfsm_clget;
-			*tl = 0;
-			bp += NFSX_UNSIGNED;
-			nfsm_clget;
-			*tl = txdr_unsigned(dp->d_fileno);
-			bp += NFSX_UNSIGNED;
+			txdr_hyper(dp->d_fileno, tl);
+			bp += 2 * NFSX_UNSIGNED;
 			nfsm_clget;
 			*tl = txdr_unsigned(nlen);
 			bp += NFSX_UNSIGNED;
@@ -3354,8 +3277,6 @@
 invalid:
 		cpos += dp->d_reclen;
 		dp = (struct dirent *)cpos;
-		cookiep++;
-		ncookies--;
 	}
 	if (!usevget && vp_locked)
 		vput(vp);
@@ -3376,7 +3297,6 @@
 			mp->m_len = bp - mtod(mp, caddr_t);
 	} else
 		mp->m_len += bp - bpos;
-	free((caddr_t)cookies, M_TEMP);
 	free((caddr_t)rbuf, M_TEMP);
 nfsmout:
 	if (vp)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110708154939.BB272106566B>