summaryrefslogtreecommitdiffstats
path: root/sys/nfsserver
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1998-03-30 09:56:58 +0000
committerphk <phk@FreeBSD.org>1998-03-30 09:56:58 +0000
commit9b703b14551addf9806978973e2ddc427d4908b4 (patch)
tree91f2de8432f719153d0de9465a9ebeee33c29077 /sys/nfsserver
parentadd2782c4ec0d7c4447da2b33d1413a2754f8a3e (diff)
downloadFreeBSD-src-9b703b14551addf9806978973e2ddc427d4908b4.zip
FreeBSD-src-9b703b14551addf9806978973e2ddc427d4908b4.tar.gz
Eradicate the variable "time" from the kernel, using various measures.
"time" wasn't a atomic variable, so splfoo() protection were needed around any access to it, unless you just wanted the seconds part. Most uses of time.tv_sec now uses the new variable time_second instead. gettime() changed to getmicrotime(0. Remove a couple of unneeded splfoo() protections, the new getmicrotime() is atomic, (until Bruce sets a breakpoint in it). A couple of places needed random data, so use read_random() instead of mucking about with time which isn't random. Add a new nfs_curusec() function. Mark a couple of bogosities involving the now disappeard time variable. Update ffs_update() to avoid the weird "== &time" checks, by fixing the one remaining call that passwd &time as args. Change profiling in ncr.c to use ticks instead of time. Resolution is the same. Add new function "tvtohz()" to avoid the bogus "splfoo(), add time, call hzto() which subtracts time" sequences. Reviewed by: bde
Diffstat (limited to 'sys/nfsserver')
-rw-r--r--sys/nfsserver/nfs.h9
-rw-r--r--sys/nfsserver/nfs_serv.c6
-rw-r--r--sys/nfsserver/nfs_srvsock.c20
-rw-r--r--sys/nfsserver/nfs_srvsubs.c15
-rw-r--r--sys/nfsserver/nfs_syscalls.c35
-rw-r--r--sys/nfsserver/nfsm_subs.h22
-rw-r--r--sys/nfsserver/nfsrvstats.h9
7 files changed, 64 insertions, 52 deletions
diff --git a/sys/nfsserver/nfs.h b/sys/nfsserver/nfs.h
index 9f057a3..8b28c00 100644
--- a/sys/nfsserver/nfs.h
+++ b/sys/nfsserver/nfs.h
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)nfs.h 8.4 (Berkeley) 5/1/95
- * $Id: nfs.h,v 1.32 1997/10/12 20:25:38 phk Exp $
+ * $Id: nfs.h,v 1.33 1998/02/01 21:23:29 bde Exp $
*/
#ifndef _NFS_NFS_H_
@@ -108,9 +108,9 @@
*/
#define NFS_ATTRTIMEO(np) \
((((np)->n_flag & NMODIFIED) || \
- (time.tv_sec - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \
- ((time.tv_sec - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \
- (time.tv_sec - (np)->n_mtime) / 10))
+ (time_second - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \
+ ((time_second - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \
+ (time_second - (np)->n_mtime) / 10))
/*
* Expected allocation sizes for major data structures. If the actual size
@@ -571,6 +571,7 @@ extern int nfs_debug;
#endif
+u_quad_t nfs_curusec __P((void));
int nfs_init __P((struct vfsconf *vfsp));
int nfs_reply __P((struct nfsreq *));
int nfs_getreq __P((struct nfsrv_descript *,struct nfsd *,int));
diff --git a/sys/nfsserver/nfs_serv.c b/sys/nfsserver/nfs_serv.c
index 19d09f4..4b577cb 100644
--- a/sys/nfsserver/nfs_serv.c
+++ b/sys/nfsserver/nfs_serv.c
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)nfs_serv.c 8.3 (Berkeley) 1/12/94
- * $Id: nfs_serv.c,v 1.57 1998/02/06 12:13:56 eivind Exp $
+ * $Id: nfs_serv.c,v 1.58 1998/02/09 06:10:35 eivind Exp $
*/
/*
@@ -979,7 +979,7 @@ nfsrv_writegather(ndp, slp, procp, mrq)
LIST_INIT(&nfsd->nd_coalesce);
nfsd->nd_mreq = NULL;
nfsd->nd_stable = NFSV3WRITE_FILESYNC;
- cur_usec = (u_quad_t)time.tv_sec * 1000000 + (u_quad_t)time.tv_usec;
+ cur_usec = nfs_curusec();
nfsd->nd_time = cur_usec +
(v3 ? nfsrvw_procrastinate_v3 : nfsrvw_procrastinate);
@@ -1095,7 +1095,7 @@ nfsmout:
* and generate the associated reply mbuf list(s).
*/
loop1:
- cur_usec = (u_quad_t)time.tv_sec * 1000000 + (u_quad_t)time.tv_usec;
+ cur_usec = nfs_curusec();
s = splsoftclock();
for (nfsd = slp->ns_tq.lh_first; nfsd; nfsd = owp) {
owp = nfsd->nd_tq.le_next;
diff --git a/sys/nfsserver/nfs_srvsock.c b/sys/nfsserver/nfs_srvsock.c
index ed23c69..5c084b7 100644
--- a/sys/nfsserver/nfs_srvsock.c
+++ b/sys/nfsserver/nfs_srvsock.c
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)nfs_socket.c 8.5 (Berkeley) 3/30/95
- * $Id: nfs_socket.c,v 1.29 1997/10/12 20:25:44 phk Exp $
+ * $Id: nfs_socket.c,v 1.30 1997/10/28 15:59:07 bde Exp $
*/
/*
@@ -769,7 +769,7 @@ nfsmout:
rt->srtt = nmp->nm_srtt[proct[rep->r_procnum] - 1];
rt->sdrtt = nmp->nm_sdrtt[proct[rep->r_procnum] - 1];
rt->fsid = nmp->nm_mountp->mnt_stat.f_fsid;
- gettime(&rt->tstamp);
+ getmicrotime(&rt->tstamp);
if (rep->r_flags & R_TIMING)
rt->rtt = rep->r_rtt;
else
@@ -952,7 +952,7 @@ tryagain:
TAILQ_INSERT_TAIL(&nfs_reqq, rep, r_chain);
/* Get send time for nqnfs */
- reqtime = time.tv_sec;
+ reqtime = time_second;
/*
* If backing off another request or avoiding congestion, don't
@@ -1062,8 +1062,8 @@ tryagain:
error == NFSERR_TRYLATER) {
m_freem(mrep);
error = 0;
- waituntil = time.tv_sec + trylater_delay;
- while (time.tv_sec < waituntil)
+ waituntil = time_second + trylater_delay;
+ while (time_second < waituntil)
(void) tsleep((caddr_t)&lbolt,
PSOCK, "nqnfstry", 0);
trylater_delay *= nfs_backoff[trylater_cnt];
@@ -1101,7 +1101,7 @@ tryagain:
nfsm_dissect(tl, u_long *, 4*NFSX_UNSIGNED);
cachable = fxdr_unsigned(int, *tl++);
reqtime += fxdr_unsigned(int, *tl++);
- if (reqtime > time.tv_sec) {
+ if (reqtime > time_second) {
fxdr_hyper(tl, &frev);
nqnfs_clientlease(nmp, np, nqlflag,
cachable, reqtime, frev);
@@ -1395,8 +1395,8 @@ nfs_timer(arg)
/*
* Call the nqnfs server timer once a second to handle leases.
*/
- if (lasttime != time.tv_sec) {
- lasttime = time.tv_sec;
+ if (lasttime != time_second) {
+ lasttime = time_second;
nqnfs_serverd();
}
@@ -1404,7 +1404,7 @@ nfs_timer(arg)
* Scan the write gathering queues for writes that need to be
* completed now.
*/
- cur_usec = (u_quad_t)time.tv_sec * 1000000 + (u_quad_t)time.tv_usec;
+ cur_usec = nfs_curusec();
for (slp = nfssvc_sockhead.tqh_first; slp != 0;
slp = slp->ns_chain.tqe_next) {
if (slp->ns_tq.lh_first && slp->ns_tq.lh_first->nd_time<=cur_usec)
@@ -2125,7 +2125,7 @@ nfs_getreq(nd, nfsd, has_header)
tvout.tv_sec = fxdr_unsigned(long, tvout.tv_sec);
tvout.tv_usec = fxdr_unsigned(long, tvout.tv_usec);
- if (nuidp->nu_expire < time.tv_sec ||
+ if (nuidp->nu_expire < time_second ||
nuidp->nu_timestamp.tv_sec > tvout.tv_sec ||
(nuidp->nu_timestamp.tv_sec == tvout.tv_sec &&
nuidp->nu_timestamp.tv_usec > tvout.tv_usec)) {
diff --git a/sys/nfsserver/nfs_srvsubs.c b/sys/nfsserver/nfs_srvsubs.c
index b75dd93..b34c874 100644
--- a/sys/nfsserver/nfs_srvsubs.c
+++ b/sys/nfsserver/nfs_srvsubs.c
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)nfs_subs.c 8.3 (Berkeley) 1/4/94
- * $Id: nfs_subs.c,v 1.50 1998/02/04 22:33:15 eivind Exp $
+ * $Id: nfs_subs.c,v 1.51 1998/02/06 12:13:57 eivind Exp $
*/
/*
@@ -558,6 +558,15 @@ LIST_HEAD(nfsnodehashhead, nfsnode);
int nfs_webnamei __P((struct nameidata *, struct vnode *, struct proc *));
+u_quad_t
+nfs_curusec()
+{
+ struct timeval tv;
+
+ getmicrotime(&tv);
+ return ((u_quad_t)tv.tv_sec * 1000000 + (u_quad_t)tv.tv_usec);
+}
+
/*
* Create the header for an rpc request packet
* The hsiz is the size of the rest of the nfs request header.
@@ -1348,7 +1357,7 @@ nfs_loadattrcache(vpp, mdp, dposp, vaper)
} else
np->n_size = vap->va_size;
}
- np->n_attrstamp = time.tv_sec;
+ np->n_attrstamp = time_second;
if (vaper != NULL) {
bcopy((caddr_t)vap, (caddr_t)vaper, sizeof(*vap));
if (np->n_flag & NCHG) {
@@ -1374,7 +1383,7 @@ nfs_getattrcache(vp, vaper)
register struct nfsnode *np = VTONFS(vp);
register struct vattr *vap;
- if ((time.tv_sec - np->n_attrstamp) >= NFS_ATTRTIMEO(np)) {
+ if ((time_second - np->n_attrstamp) >= NFS_ATTRTIMEO(np)) {
nfsstats.attrcache_misses++;
return (ENOENT);
}
diff --git a/sys/nfsserver/nfs_syscalls.c b/sys/nfsserver/nfs_syscalls.c
index ba460fc..c2f9071 100644
--- a/sys/nfsserver/nfs_syscalls.c
+++ b/sys/nfsserver/nfs_syscalls.c
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)nfs_syscalls.c 8.5 (Berkeley) 3/30/95
- * $Id: nfs_syscalls.c,v 1.35 1998/02/06 12:13:57 eivind Exp $
+ * $Id: nfs_syscalls.c,v 1.36 1998/02/09 06:10:37 eivind Exp $
*/
#include <sys/param.h>
@@ -300,7 +300,7 @@ nfssvc(p, uap)
nuidp->nu_cr.cr_ngroups = NGROUPS;
nuidp->nu_cr.cr_ref = 1;
nuidp->nu_timestamp = nsd->nsd_timestamp;
- nuidp->nu_expire = time.tv_sec + nsd->nsd_ttl;
+ nuidp->nu_expire = time_second + nsd->nsd_ttl;
/*
* and save the session key in nu_key.
*/
@@ -520,8 +520,7 @@ nfssvc_nfsd(nsd, argp, p)
nfs_sndunlock(&slp->ns_solock);
}
error = nfsrv_dorec(slp, nfsd, &nd);
- cur_usec = (u_quad_t)time.tv_sec * 1000000 +
- (u_quad_t)time.tv_usec;
+ cur_usec = nfs_curusec();
if (error && slp->ns_tq.lh_first &&
slp->ns_tq.lh_first->nd_time <= cur_usec) {
error = 0;
@@ -553,7 +552,7 @@ nfssvc_nfsd(nsd, argp, p)
else
solockp = (int *)0;
if (nd) {
- gettime(&nd->nd_starttime);
+ getmicrotime(&nd->nd_starttime);
if (nd->nd_nam2)
nd->nd_nam = nd->nd_nam2;
else
@@ -583,9 +582,9 @@ nfssvc_nfsd(nsd, argp, p)
* Check for just starting up for NQNFS and send
* fake "try again later" replies to the NQNFS clients.
*/
- if (notstarted && nqnfsstarttime <= time.tv_sec) {
+ if (notstarted && nqnfsstarttime <= time_second) {
if (modify_flag) {
- nqnfsstarttime = time.tv_sec + nqsrv_writeslack;
+ nqnfsstarttime = time_second + nqsrv_writeslack;
modify_flag = 0;
} else
notstarted = 0;
@@ -718,8 +717,7 @@ nfssvc_nfsd(nsd, argp, p)
* Check to see if there are outstanding writes that
* need to be serviced.
*/
- cur_usec = (u_quad_t)time.tv_sec * 1000000 +
- (u_quad_t)time.tv_usec;
+ cur_usec = nfs_curusec();
s = splsoftclock();
if (slp->ns_tq.lh_first &&
slp->ns_tq.lh_first->nd_time <= cur_usec) {
@@ -972,7 +970,7 @@ nfs_getnickauth(nmp, cred, auth_str, auth_len, verf_str, verf_len)
if (nuidp->nu_cr.cr_uid == cred->cr_uid)
break;
}
- if (!nuidp || nuidp->nu_expire < time.tv_sec)
+ if (!nuidp || nuidp->nu_expire < time_second)
return (EACCES);
/*
@@ -992,10 +990,10 @@ nfs_getnickauth(nmp, cred, auth_str, auth_len, verf_str, verf_len)
*/
verfp = (u_long *)verf_str;
*verfp++ = txdr_unsigned(RPCAKN_NICKNAME);
- if (time.tv_sec > nuidp->nu_timestamp.tv_sec ||
- (time.tv_sec == nuidp->nu_timestamp.tv_sec &&
- time.tv_usec > nuidp->nu_timestamp.tv_usec))
- gettime(&nuidp->nu_timestamp);
+ if (time_second > nuidp->nu_timestamp.tv_sec ||
+ (time_second == nuidp->nu_timestamp.tv_sec &&
+ time_second > nuidp->nu_timestamp.tv_usec))
+ getmicrotime(&nuidp->nu_timestamp);
else
nuidp->nu_timestamp.tv_usec++;
ktvin.tv_sec = txdr_unsigned(nuidp->nu_timestamp.tv_sec);
@@ -1051,7 +1049,7 @@ nfs_savenickauth(nmp, cred, len, key, mdp, dposp, mrep)
#endif
ktvout.tv_sec = fxdr_unsigned(long, ktvout.tv_sec);
ktvout.tv_usec = fxdr_unsigned(long, ktvout.tv_usec);
- deltasec = time.tv_sec - ktvout.tv_sec;
+ deltasec = time_second - ktvout.tv_sec;
if (deltasec < 0)
deltasec = -deltasec;
/*
@@ -1071,7 +1069,7 @@ nfs_savenickauth(nmp, cred, len, key, mdp, dposp, mrep)
}
nuidp->nu_flag = 0;
nuidp->nu_cr.cr_uid = cred->cr_uid;
- nuidp->nu_expire = time.tv_sec + NFS_KERBTTL;
+ nuidp->nu_expire = time_second + NFS_KERBTTL;
nuidp->nu_timestamp = ktvout;
nuidp->nu_nickname = nick;
bcopy(key, nuidp->nu_key, sizeof (key));
@@ -1184,9 +1182,8 @@ nfsd_rt(sotype, nd, cacherep)
rt->ipadr = ((struct sockaddr_in *)nd->nd_nam)->sin_addr.s_addr;
else
rt->ipadr = INADDR_ANY;
- rt->resptime = ((time.tv_sec - nd->nd_starttime.tv_sec) * 1000000) +
- (time.tv_usec - nd->nd_starttime.tv_usec);
- gettime(&rt->tstamp);
+ rt->resptime = nfs_curusec() - (nd->nd_starttime.tv_sec * 1000000 + nd->nd_starttime.tv_usec);
+ getmicrotime(&rt->tstamp);
nfsdrt.pos = (nfsdrt.pos + 1) % NFSRTTLOGSIZ;
}
#endif /* NFS_NOSERVER */
diff --git a/sys/nfsserver/nfsm_subs.h b/sys/nfsserver/nfsm_subs.h
index f8830a5..be06591 100644
--- a/sys/nfsserver/nfsm_subs.h
+++ b/sys/nfsserver/nfsm_subs.h
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)nfsm_subs.h 8.2 (Berkeley) 3/30/95
- * $Id: nfsm_subs.h,v 1.13 1997/07/16 09:06:30 dfr Exp $
+ * $Id: nfsm_subs.h,v 1.14 1998/02/03 21:51:56 bde Exp $
*/
@@ -434,10 +434,12 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid,
nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \
fxdr_nfsv3time(tl, &(a)->va_atime); \
break; \
- case NFSV3SATTRTIME_TOSERVER: \
- (a)->va_atime.tv_sec = time.tv_sec; \
- (a)->va_atime.tv_nsec = time.tv_usec * 1000; \
- break; \
+ case NFSV3SATTRTIME_TOSERVER: { \
+ struct timeval tv; \
+ getmicrotime(&tv); \
+ (a)->va_atime.tv_sec = tv.tv_sec; \
+ (a)->va_atime.tv_nsec = tv.tv_usec * 1000; \
+ break; } \
}; \
nfsm_dissect(tl, u_long *, NFSX_UNSIGNED); \
switch (fxdr_unsigned(int, *tl)) { \
@@ -445,10 +447,12 @@ struct mbuf *nfsm_rpchead __P((struct ucred *cr, int nmflag, int procid,
nfsm_dissect(tl, u_long *, 2 * NFSX_UNSIGNED); \
fxdr_nfsv3time(tl, &(a)->va_mtime); \
break; \
- case NFSV3SATTRTIME_TOSERVER: \
- (a)->va_mtime.tv_sec = time.tv_sec; \
- (a)->va_mtime.tv_nsec = time.tv_usec * 1000; \
- break; \
+ case NFSV3SATTRTIME_TOSERVER: { \
+ struct timeval tv; \
+ getmicrotime(&tv); \
+ (a)->va_mtime.tv_sec = tv.tv_sec; \
+ (a)->va_mtime.tv_nsec = tv.tv_usec * 1000; \
+ break; } \
}; }
#endif
diff --git a/sys/nfsserver/nfsrvstats.h b/sys/nfsserver/nfsrvstats.h
index 9f057a3..8b28c00 100644
--- a/sys/nfsserver/nfsrvstats.h
+++ b/sys/nfsserver/nfsrvstats.h
@@ -34,7 +34,7 @@
* SUCH DAMAGE.
*
* @(#)nfs.h 8.4 (Berkeley) 5/1/95
- * $Id: nfs.h,v 1.32 1997/10/12 20:25:38 phk Exp $
+ * $Id: nfs.h,v 1.33 1998/02/01 21:23:29 bde Exp $
*/
#ifndef _NFS_NFS_H_
@@ -108,9 +108,9 @@
*/
#define NFS_ATTRTIMEO(np) \
((((np)->n_flag & NMODIFIED) || \
- (time.tv_sec - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \
- ((time.tv_sec - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \
- (time.tv_sec - (np)->n_mtime) / 10))
+ (time_second - (np)->n_mtime) / 10 < NFS_MINATTRTIMO) ? NFS_MINATTRTIMO : \
+ ((time_second - (np)->n_mtime) / 10 > NFS_MAXATTRTIMO ? NFS_MAXATTRTIMO : \
+ (time_second - (np)->n_mtime) / 10))
/*
* Expected allocation sizes for major data structures. If the actual size
@@ -571,6 +571,7 @@ extern int nfs_debug;
#endif
+u_quad_t nfs_curusec __P((void));
int nfs_init __P((struct vfsconf *vfsp));
int nfs_reply __P((struct nfsreq *));
int nfs_getreq __P((struct nfsrv_descript *,struct nfsd *,int));
OpenPOWER on IntegriCloud