Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 23 Jan 2013 13:38:38 -0500
From:      John Baldwin <jhb@freebsd.org>
To:        fs@freebsd.org
Cc:        Rick Macklem <rmacklem@freebsd.org>, bde@freebsd.org
Subject:   [PATCH] More time cleanups in the NFS code
Message-ID:  <201301231338.39056.jhb@freebsd.org>

next in thread | raw e-mail | index | archive | help
This patch removes all calls to get*time().  Most of them it replaces with 
time_uptime (especially ones that are attempting to handle time intervals for 
which time_uptime is far better suited than time_second).  One specific case 
it replaces with nanotime() as suggested by Bruce previously.  A few of the 
timestamps were not used (nd_starttime and the curtime in the lease expiry 
function).

Index: fs/nfs/nfsport.h
===================================================================
--- fs/nfs/nfsport.h	(revision 245742)
+++ fs/nfs/nfsport.h	(working copy)
@@ -588,12 +588,6 @@
 #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 \
Index: fs/nfs/nfs_commonkrpc.c
===================================================================
--- fs/nfs/nfs_commonkrpc.c	(revision 245742)
+++ fs/nfs/nfs_commonkrpc.c	(working copy)
@@ -459,18 +459,17 @@
 {
 	struct nfs_feedback_arg *nf = (struct nfs_feedback_arg *) arg;
 	struct nfsmount *nmp = nf->nf_mount;
-	struct timeval now;
+	time_t now;
 
-	getmicrouptime(&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 @@
 	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 @@
 		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));
 	}
 
Index: fs/nfs/nfs.h
===================================================================
--- fs/nfs/nfs.h	(revision 245742)
+++ fs/nfs/nfs.h	(working copy)
@@ -523,7 +523,6 @@
 	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 */
Index: fs/nfsclient/nfs_clstate.c
===================================================================
--- fs/nfsclient/nfs_clstate.c	(revision 245742)
+++ fs/nfsclient/nfs_clstate.c	(working copy)
@@ -2447,7 +2447,7 @@
 	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 @@
 		 * 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 @@
 	}
 	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();
Index: fs/nfsserver/nfs_nfsdkrpc.c
===================================================================
--- fs/nfsserver/nfs_nfsdkrpc.c	(revision 245742)
+++ fs/nfsserver/nfs_nfsdkrpc.c	(working copy)
@@ -310,7 +310,6 @@
 	} else {
 		isdgram = 1;
 	}
-	NFSGETTIME(&nd->nd_starttime);
 
 	/*
 	 * Two cases:
Index: fs/nfsserver/nfs_nfsdstate.c
===================================================================
--- fs/nfsserver/nfs_nfsdstate.c	(revision 245742)
+++ fs/nfsserver/nfs_nfsdstate.c	(working copy)
@@ -3967,7 +3967,6 @@
 	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 @@
 	/*
 	 * 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,7 +4648,7 @@
 APPLESTATIC void
 nfsd_recalldelegation(vnode_t vp, NFSPROC_T *p)
 {
-	struct timespec mytime;
+	time_t mytime;
 	int32_t starttime;
 	int error;
 
@@ -4675,8 +4673,8 @@
 	 * 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;
+	mytime = NFSD_MONOSEC;
+	starttime = (u_int32_t)mytime;
 	do {
 		if (NFSVOPLOCK(vp, LK_EXCLUSIVE) == 0) {
 			error = nfsrv_checkremove(vp, 0, p);
@@ -4684,11 +4682,9 @@
 		} 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)
+			mytime = NFSD_MONOSEC;
+			if (((u_int32_t)mytime - starttime) > NFS_REMOVETIMEO &&
+			    ((u_int32_t)mytime - starttime) < 100000)
 				break;
 			/* Sleep for a short period of time */
 			(void) nfs_catnap(PZERO, 0, "nfsremove");
@@ -4949,9 +4945,7 @@
 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);
Index: nfsclient/nfs_krpc.c
===================================================================
--- nfsclient/nfs_krpc.c	(revision 245742)
+++ nfsclient/nfs_krpc.c	(working copy)
@@ -394,18 +394,17 @@
 {
 	struct nfs_feedback_arg *nf = (struct nfs_feedback_arg *) arg;
 	struct nfsmount *nmp = nf->nf_mount;
-	struct timeval now;
+	time_t now;
 
-	getmicrouptime(&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 @@
 	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 @@
 	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));
 
 	/*

-- 
John Baldwin



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