aboutsummaryrefslogtreecommitdiff
path: root/sys/nfsclient/nfs_subs.c
diff options
context:
space:
mode:
authorJohn Baldwin <jhb@FreeBSD.org>2008-02-13 00:04:58 +0000
committerJohn Baldwin <jhb@FreeBSD.org>2008-02-13 00:04:58 +0000
commit3156ea2d33e580ab1db7faeaa94410a527a71429 (patch)
tree0ef5649ac7717cfb42b956a31f3b920f3f25680c /sys/nfsclient/nfs_subs.c
parentb0c2bc946df1468166f0c0362fd541403332610d (diff)
downloadsrc-3156ea2d33e580ab1db7faeaa94410a527a71429.tar.gz
src-3156ea2d33e580ab1db7faeaa94410a527a71429.zip
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)
Notes
Notes: svn path=/head/; revision=176224
Diffstat (limited to 'sys/nfsclient/nfs_subs.c')
-rw-r--r--sys/nfsclient/nfs_subs.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/sys/nfsclient/nfs_subs.c b/sys/nfsclient/nfs_subs.c
index f8cefb51c9e6..d3a5c089ced7 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);