summaryrefslogtreecommitdiffstats
path: root/sys/nfsclient
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2008-02-13 00:04:58 +0000
committerjhb <jhb@FreeBSD.org>2008-02-13 00:04:58 +0000
commite83bd487c4e08b9525923b1cfb1870fb16b86535 (patch)
tree0ef5649ac7717cfb42b956a31f3b920f3f25680c /sys/nfsclient
parent06a30b50ee14d137e2cf4755c15388c7e21ef5ed (diff)
downloadFreeBSD-src-e83bd487c4e08b9525923b1cfb1870fb16b86535.zip
FreeBSD-src-e83bd487c4e08b9525923b1cfb1870fb16b86535.tar.gz
Consolidate the code to generate a new XID for a NFS request into a
nfs_xid_gen() function instead of duplicating the logic in both nfsm_rpchead() and the NFS3ERR_JUKEBOX handling in nfs_request(). MFC after: 1 week Submitted by: mohans (a long while ago)
Diffstat (limited to 'sys/nfsclient')
-rw-r--r--sys/nfsclient/nfs_socket.c9
-rw-r--r--sys/nfsclient/nfs_subs.c37
-rw-r--r--sys/nfsclient/nfsm_subs.h1
3 files changed, 25 insertions, 22 deletions
diff --git a/sys/nfsclient/nfs_socket.c b/sys/nfsclient/nfs_socket.c
index 9edd157..3975577 100644
--- a/sys/nfsclient/nfs_socket.c
+++ b/sys/nfsclient/nfs_socket.c
@@ -77,9 +77,6 @@ __FBSDID("$FreeBSD$");
#define TRUE 1
#define FALSE 0
-extern u_int32_t nfs_xid;
-extern struct mtx nfs_xid_mtx;
-
static int nfs_realign_test;
static int nfs_realign_count;
static int nfs_bufpackets = 4;
@@ -1351,11 +1348,7 @@ wait_for_pinned_req:
while (time_second < waituntil) {
(void) tsleep(&lbolt, PSOCK, "nqnfstry", 0);
}
- mtx_lock(&nfs_xid_mtx);
- if (++nfs_xid == 0)
- nfs_xid++;
- rep->r_xid = *xidp = txdr_unsigned(nfs_xid);
- mtx_unlock(&nfs_xid_mtx);
+ rep->r_xid = *xidp = txdr_unsigned(nfs_xid_gen());
goto tryagain;
}
diff --git a/sys/nfsclient/nfs_subs.c b/sys/nfsclient/nfs_subs.c
index f8cefb5..d3a5c08 100644
--- a/sys/nfsclient/nfs_subs.c
+++ b/sys/nfsclient/nfs_subs.c
@@ -91,7 +91,7 @@ u_int32_t rpc_call, rpc_vers, rpc_reply, rpc_msgdenied, rpc_autherr,
u_int32_t nfs_true, nfs_false;
/* And other global data */
-u_int32_t nfs_xid = 0;
+static u_int32_t nfs_xid = 0;
static enum vtype nv2tov_type[8]= {
VNON, VREG, VDIR, VBLK, VCHR, VLNK, VNON, VNON
};
@@ -102,7 +102,7 @@ int nfs_pbuf_freecnt = -1; /* start out unlimited */
struct nfs_reqq nfs_reqq;
struct mtx nfs_reqq_mtx;
struct nfs_bufq nfs_bufq;
-struct mtx nfs_xid_mtx;
+static struct mtx nfs_xid_mtx;
/*
* and the reverse mapping from generic to Version 2 procedure numbers
@@ -135,6 +135,26 @@ int nfsv2_procid[NFS_NPROCS] = {
LIST_HEAD(nfsnodehashhead, nfsnode);
+u_int32_t
+nfs_xid_gen(void)
+{
+ uint32_t xid;
+
+ mtx_lock(&nfs_xid_mtx);
+
+ /* Get a pretty random xid to start with */
+ if (!nfs_xid)
+ nfs_xid = random();
+ /*
+ * Skip zero xid if it should ever happen.
+ */
+ if (++nfs_xid == 0)
+ nfs_xid++;
+ xid = nfs_xid;
+ mtx_unlock(&nfs_xid_mtx);
+ return xid;
+}
+
/*
* Create the header for an rpc request packet
* The hsiz is the size of the rest of the nfs request header.
@@ -188,19 +208,8 @@ nfsm_rpchead(struct ucred *cr, int nmflag, int procid, int auth_type,
*/
tl = nfsm_build(u_int32_t *, 8 * NFSX_UNSIGNED);
- mtx_lock(&nfs_xid_mtx);
- /* Get a pretty random xid to start with */
- if (!nfs_xid)
- nfs_xid = random();
- /*
- * Skip zero xid if it should ever happen.
- */
- if (++nfs_xid == 0)
- nfs_xid++;
-
*xidpp = tl;
- *tl++ = txdr_unsigned(nfs_xid);
- mtx_unlock(&nfs_xid_mtx);
+ *tl++ = txdr_unsigned(nfs_xid_gen());
*tl++ = rpc_call;
*tl++ = rpc_vers;
*tl++ = txdr_unsigned(NFS_PROG);
diff --git a/sys/nfsclient/nfsm_subs.h b/sys/nfsclient/nfsm_subs.h
index 62666a5..3dd817f 100644
--- a/sys/nfsclient/nfsm_subs.h
+++ b/sys/nfsclient/nfsm_subs.h
@@ -52,6 +52,7 @@ struct vnode;
/*
* First define what the actual subs. return
*/
+u_int32_t nfs_xid_gen(void);
struct mbuf *nfsm_reqhead(struct vnode *vp, u_long procid, int hsiz);
struct mbuf *nfsm_rpchead(struct ucred *cr, int nmflag, int procid,
int auth_type, int auth_len,
OpenPOWER on IntegriCloud