svn commit: r245909 - in head/sys: fs/nfs fs/nfsclient fs/nfsserver nfsclient

John Baldwin jhb at FreeBSD.org
Fri Jan 25 15:25:27 UTC 2013


Author: jhb
Date: Fri Jan 25 15:25:24 2013
New Revision: 245909
URL: http://svnweb.freebsd.org/changeset/base/245909

Log:
  Further cleanups to use of timestamps in NFS:
  - Use NFSD_MONOSEC (which maps to time_uptime) instead of the seconds
    portion of wall-time stamps to manage timeouts on events.
  - Remove unused nd_starttime from the per-request structure in the new
    NFS server.
  - Use nanotime() for the modification time on a delegation to get as
    precise a time as possible.
  - Use time_second instead of extracting the second from a call to
    getmicrotime().
  
  Submitted by:	bde (3)
  Reviewed by:	bde, rmacklem
  MFC after:	2 weeks

Modified:
  head/sys/fs/nfs/nfs.h
  head/sys/fs/nfs/nfs_commonkrpc.c
  head/sys/fs/nfs/nfsport.h
  head/sys/fs/nfsclient/nfs_clstate.c
  head/sys/fs/nfsserver/nfs_nfsdkrpc.c
  head/sys/fs/nfsserver/nfs_nfsdstate.c
  head/sys/nfsclient/nfs_krpc.c

Modified: head/sys/fs/nfs/nfs.h
==============================================================================
--- head/sys/fs/nfs/nfs.h	Fri Jan 25 14:40:54 2013	(r245908)
+++ head/sys/fs/nfs/nfs.h	Fri Jan 25 15:25:24 2013	(r245909)
@@ -523,7 +523,6 @@ struct nfsrv_descript {
 	int			*nd_errp;	/* Pointer to ret status */
 	u_int32_t		nd_retxid;	/* Reply xid */
 	struct nfsrvcache	*nd_rp;		/* Assoc. cache entry */
-	struct timeval		nd_starttime;	/* Time RPC initiated */
 	fhandle_t		nd_fh;		/* File handle */
 	struct ucred		*nd_cred;	/* Credentials */
 	uid_t			nd_saveduid;	/* Saved uid */

Modified: head/sys/fs/nfs/nfs_commonkrpc.c
==============================================================================
--- head/sys/fs/nfs/nfs_commonkrpc.c	Fri Jan 25 14:40:54 2013	(r245908)
+++ head/sys/fs/nfs/nfs_commonkrpc.c	Fri Jan 25 15:25:24 2013	(r245909)
@@ -459,18 +459,17 @@ nfs_feedback(int type, int proc, void *a
 {
 	struct nfs_feedback_arg *nf = (struct nfs_feedback_arg *) arg;
 	struct nfsmount *nmp = nf->nf_mount;
-	struct timeval now;
-
-	getmicrouptime(&now);
+	time_t now;
 
 	switch (type) {
 	case FEEDBACK_REXMIT2:
 	case FEEDBACK_RECONNECT:
-		if (nf->nf_lastmsg + nmp->nm_tprintf_delay < now.tv_sec) {
+		now = NFSD_MONOSEC;
+		if (nf->nf_lastmsg + nmp->nm_tprintf_delay < now) {
 			nfs_down(nmp, nf->nf_td,
 			    "not responding", 0, NFSSTA_TIMEO);
 			nf->nf_tprintfmsg = TRUE;
-			nf->nf_lastmsg = now.tv_sec;
+			nf->nf_lastmsg = now;
 		}
 		break;
 
@@ -501,7 +500,7 @@ newnfs_request(struct nfsrv_descript *nd
 	u_int16_t procnum;
 	u_int trylater_delay = 1;
 	struct nfs_feedback_arg nf;
-	struct timeval timo, now;
+	struct timeval timo;
 	AUTH *auth;
 	struct rpc_callextra ext;
 	enum clnt_stat stat;
@@ -617,8 +616,7 @@ newnfs_request(struct nfsrv_descript *nd
 		bzero(&nf, sizeof(struct nfs_feedback_arg));
 		nf.nf_mount = nmp;
 		nf.nf_td = td;
-		getmicrouptime(&now);
-		nf.nf_lastmsg = now.tv_sec -
+		nf.nf_lastmsg = NFSD_MONOSEC -
 		    ((nmp->nm_tprintf_delay)-(nmp->nm_tprintf_initial_delay));
 	}
 

Modified: head/sys/fs/nfs/nfsport.h
==============================================================================
--- head/sys/fs/nfs/nfsport.h	Fri Jan 25 14:40:54 2013	(r245908)
+++ head/sys/fs/nfs/nfsport.h	Fri Jan 25 15:25:24 2013	(r245909)
@@ -588,12 +588,6 @@ void nfsrvd_rcv(struct socket *, void *,
 #define	NCHNAMLEN	9999999
 
 /*
- * Define these to use the time of day clock.
- */
-#define	NFSGETTIME(t)		(getmicrotime(t))
-#define	NFSGETNANOTIME(t)	(getnanotime(t))
-
-/*
  * These macros are defined to initialize and set the timer routine.
  */
 #define	NFS_TIMERINIT \

Modified: head/sys/fs/nfsclient/nfs_clstate.c
==============================================================================
--- head/sys/fs/nfsclient/nfs_clstate.c	Fri Jan 25 14:40:54 2013	(r245908)
+++ head/sys/fs/nfsclient/nfs_clstate.c	Fri Jan 25 15:25:24 2013	(r245909)
@@ -2447,7 +2447,7 @@ nfscl_renewthread(struct nfsclclient *cl
 	u_int32_t clidrev;
 	int error, cbpathdown, islept, igotlock, ret, clearok;
 	uint32_t recover_done_time = 0;
-	struct timespec mytime;
+	time_t mytime;
 	static time_t prevsec = 0;
 	struct nfscllockownerfh *lfhp, *nlfhp;
 	struct nfscllockownerfhhead lfh;
@@ -2720,9 +2720,9 @@ tryagain2:
 		 * Call nfscl_cleanupkext() once per second to check for
 		 * open/lock owners where the process has exited.
 		 */
-		NFSGETNANOTIME(&mytime);
-		if (prevsec != mytime.tv_sec) {
-			prevsec = mytime.tv_sec;
+		mytime = NFSD_MONOSEC;
+		if (prevsec != mytime) {
+			prevsec = mytime;
 			nfscl_cleanupkext(clp, &lfh);
 		}
 
@@ -4611,7 +4611,7 @@ nfscl_delegmodtime(vnode_t vp)
 	}
 	dp = nfscl_finddeleg(clp, np->n_fhp->nfh_fh, np->n_fhp->nfh_len);
 	if (dp != NULL && (dp->nfsdl_flags & NFSCLDL_WRITE)) {
-		NFSGETNANOTIME(&dp->nfsdl_modtime);
+		nanotime(&dp->nfsdl_modtime);
 		dp->nfsdl_flags |= NFSCLDL_MODTIMESET;
 	}
 	NFSUNLOCKCLSTATE();

Modified: head/sys/fs/nfsserver/nfs_nfsdkrpc.c
==============================================================================
--- head/sys/fs/nfsserver/nfs_nfsdkrpc.c	Fri Jan 25 14:40:54 2013	(r245908)
+++ head/sys/fs/nfsserver/nfs_nfsdkrpc.c	Fri Jan 25 15:25:24 2013	(r245909)
@@ -310,7 +310,6 @@ nfs_proc(struct nfsrv_descript *nd, u_in
 	} else {
 		isdgram = 1;
 	}
-	NFSGETTIME(&nd->nd_starttime);
 
 	/*
 	 * Two cases:

Modified: head/sys/fs/nfsserver/nfs_nfsdstate.c
==============================================================================
--- head/sys/fs/nfsserver/nfs_nfsdstate.c	Fri Jan 25 14:40:54 2013	(r245908)
+++ head/sys/fs/nfsserver/nfs_nfsdstate.c	Fri Jan 25 15:25:24 2013	(r245909)
@@ -3967,7 +3967,6 @@ nfsrv_setupstable(NFSPROC_T *p)
 	int error, i, tryagain;
 	off_t off = 0;
 	ssize_t aresid, len;
-	struct timeval curtime;
 
 	/*
 	 * If NFSNSF_UPDATEDONE is set, this is a restart of the nfsds without
@@ -3978,8 +3977,7 @@ nfsrv_setupstable(NFSPROC_T *p)
 	/*
 	 * Set Grace over just until the file reads successfully.
 	 */
-	NFSGETTIME(&curtime);
-	nfsrvboottime = curtime.tv_sec;
+	nfsrvboottime = time_second;
 	LIST_INIT(&sf->nsf_head);
 	sf->nsf_flags = (NFSNSF_GRACEOVER | NFSNSF_NEEDLOCK);
 	sf->nsf_eograce = NFSD_MONOSEC + NFSRV_LEASEDELTA;
@@ -4650,8 +4648,7 @@ out:
 APPLESTATIC void
 nfsd_recalldelegation(vnode_t vp, NFSPROC_T *p)
 {
-	struct timespec mytime;
-	int32_t starttime;
+	time_t starttime;
 	int error;
 
 	/*
@@ -4675,8 +4672,7 @@ nfsd_recalldelegation(vnode_t vp, NFSPRO
 	 * Now, call nfsrv_checkremove() in a loop while it returns
 	 * NFSERR_DELAY. Return upon any other error or when timed out.
 	 */
-	NFSGETNANOTIME(&mytime);
-	starttime = (u_int32_t)mytime.tv_sec;
+	starttime = NFSD_MONOSEC;
 	do {
 		if (NFSVOPLOCK(vp, LK_EXCLUSIVE) == 0) {
 			error = nfsrv_checkremove(vp, 0, p);
@@ -4684,11 +4680,7 @@ nfsd_recalldelegation(vnode_t vp, NFSPRO
 		} else
 			error = EPERM;
 		if (error == NFSERR_DELAY) {
-			NFSGETNANOTIME(&mytime);
-			if (((u_int32_t)mytime.tv_sec - starttime) >
-			    NFS_REMOVETIMEO &&
-			    ((u_int32_t)mytime.tv_sec - starttime) <
-			    100000)
+			if (NFSD_MONOSEC - starttime > NFS_REMOVETIMEO)
 				break;
 			/* Sleep for a short period of time */
 			(void) nfs_catnap(PZERO, 0, "nfsremove");
@@ -4949,9 +4941,7 @@ nfsrv_notsamecredname(struct nfsrv_descr
 static time_t
 nfsrv_leaseexpiry(void)
 {
-	struct timeval curtime;
 
-	NFSGETTIME(&curtime);
 	if (nfsrv_stablefirst.nsf_eograce > NFSD_MONOSEC)
 		return (NFSD_MONOSEC + 2 * (nfsrv_lease + NFSRV_LEASEDELTA));
 	return (NFSD_MONOSEC + nfsrv_lease + NFSRV_LEASEDELTA);

Modified: head/sys/nfsclient/nfs_krpc.c
==============================================================================
--- head/sys/nfsclient/nfs_krpc.c	Fri Jan 25 14:40:54 2013	(r245908)
+++ head/sys/nfsclient/nfs_krpc.c	Fri Jan 25 15:25:24 2013	(r245909)
@@ -394,18 +394,17 @@ nfs_feedback(int type, int proc, void *a
 {
 	struct nfs_feedback_arg *nf = (struct nfs_feedback_arg *) arg;
 	struct nfsmount *nmp = nf->nf_mount;
-	struct timeval now;
-
-	getmicrouptime(&now);
+	time_t now;
 
 	switch (type) {
 	case FEEDBACK_REXMIT2:
 	case FEEDBACK_RECONNECT:
-		if (nf->nf_lastmsg + nmp->nm_tprintf_delay < now.tv_sec) {
+		now = time_uptime;
+		if (nf->nf_lastmsg + nmp->nm_tprintf_delay < now) {
 			nfs_down(nmp, nf->nf_td,
 			    "not responding", 0, NFSSTA_TIMEO);
 			nf->nf_tprintfmsg = TRUE;
-			nf->nf_lastmsg = now.tv_sec;
+			nf->nf_lastmsg = now;
 		}
 		break;
 
@@ -438,7 +437,6 @@ nfs_request(struct vnode *vp, struct mbu
 	time_t waituntil;
 	caddr_t dpos;
 	int error = 0, timeo;
-	struct timeval now;
 	AUTH *auth = NULL;
 	enum nfs_rto_timer_t timer;
 	struct nfs_feedback_arg nf;
@@ -455,8 +453,7 @@ nfs_request(struct vnode *vp, struct mbu
 	bzero(&nf, sizeof(struct nfs_feedback_arg));
 	nf.nf_mount = nmp;
 	nf.nf_td = td;
-	getmicrouptime(&now);
-	nf.nf_lastmsg = now.tv_sec -
+	nf.nf_lastmsg = time_uptime -
 	    ((nmp->nm_tprintf_delay) - (nmp->nm_tprintf_initial_delay));
 
 	/*


More information about the svn-src-head mailing list