Use atomic op to get next xid. Initialize value with arc4random()
at nfs init time instead system time based trickery intermingled with the runtime code. le bouef: kills last simple_lock from nfs
This commit is contained in:
parent
fb58d5d6ec
commit
ae509fabab
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: nfs_subs.c,v 1.206 2008/09/30 14:29:39 pooka Exp $ */
|
||||
/* $NetBSD: nfs_subs.c,v 1.207 2008/10/09 00:11:39 pooka Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
|
@ -70,7 +70,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.206 2008/09/30 14:29:39 pooka Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.207 2008/10/09 00:11:39 pooka Exp $");
|
||||
|
||||
#include "fs_nfs.h"
|
||||
#include "opt_nfs.h"
|
||||
|
@ -99,6 +99,7 @@ __KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.206 2008/09/30 14:29:39 pooka Exp $")
|
|||
#include <sys/dirent.h>
|
||||
#include <sys/once.h>
|
||||
#include <sys/kauth.h>
|
||||
#include <sys/atomic.h>
|
||||
|
||||
#include <uvm/uvm_extern.h>
|
||||
|
||||
|
@ -119,6 +120,8 @@ __KERNEL_RCSID(0, "$NetBSD: nfs_subs.c,v 1.206 2008/09/30 14:29:39 pooka Exp $")
|
|||
#include <netiso/iso.h>
|
||||
#endif
|
||||
|
||||
static u_int32_t nfs_xid;
|
||||
|
||||
/*
|
||||
* Data items converted to xdr at startup, since they are constant
|
||||
* This is kinda hokey, but may save a little time doing byte swaps
|
||||
|
@ -1539,6 +1542,7 @@ nfs_init0(void)
|
|||
nfs_ticks = (hz * NFS_TICKINTVL + 500) / 1000;
|
||||
if (nfs_ticks < 1)
|
||||
nfs_ticks = 1;
|
||||
nfs_xid = arc4random();
|
||||
#ifdef NFSSERVER
|
||||
vfs_hooks_attach(&nfs_export_hooks);
|
||||
nfsrv_init(0); /* Init server data structures */
|
||||
|
@ -2909,31 +2913,12 @@ nfsrv_errmap(nd, err)
|
|||
u_int32_t
|
||||
nfs_getxid()
|
||||
{
|
||||
static u_int32_t base;
|
||||
static u_int32_t nfs_xid = 0;
|
||||
static struct simplelock nfs_xidlock = SIMPLELOCK_INITIALIZER;
|
||||
u_int32_t newxid;
|
||||
|
||||
simple_lock(&nfs_xidlock);
|
||||
/*
|
||||
* derive initial xid from system time
|
||||
* XXX time is invalid if root not yet mounted
|
||||
*/
|
||||
if (__predict_false(!base && (rootvp))) {
|
||||
struct timeval tv;
|
||||
|
||||
microtime(&tv);
|
||||
base = tv.tv_sec << 12;
|
||||
nfs_xid = base;
|
||||
}
|
||||
|
||||
/*
|
||||
* Skip zero xid if it should ever happen.
|
||||
*/
|
||||
if (__predict_false(++nfs_xid == 0))
|
||||
nfs_xid++;
|
||||
newxid = nfs_xid;
|
||||
simple_unlock(&nfs_xidlock);
|
||||
/* get next xid. skip 0 */
|
||||
do {
|
||||
newxid = atomic_inc_32_nv(&nfs_xid);
|
||||
} while (__predict_false(newxid == 0));
|
||||
|
||||
return txdr_unsigned(newxid);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue