Unwind some more macros. NFSMADV() was kinda silly since it was right

next to equivalent m_len adjustments.  Move the nfsm_subs.h macros
into groups depending on which phase they are used in, since that
affects the error recovery requirements.  Collect some of the common error
checking into a single macro as preparation for unwinding some more.
Have nfs_rephead return a value instead of secretly modifying args.
Remove some unused function arguments that were being passed around.
Clarify nfsm_reply()'s error handling (I hope).
This commit is contained in:
Peter Wemm 2001-09-28 04:37:08 +00:00
parent ac25bcab72
commit b9b0e19206
10 changed files with 188 additions and 220 deletions

View File

@ -209,7 +209,7 @@ nfsm_disct(struct mbuf **mdp, caddr_t *dposp, int siz, int left)
xfer = (siz2 > mp2->m_len) ? mp2->m_len : siz2;
if (xfer > 0) {
bcopy(mtod(mp2, caddr_t), ptr, xfer);
NFSMADV(mp2, xfer);
mp2->m_data += xfer;
mp2->m_len -= xfer;
ptr += xfer;
siz2 -= xfer;

View File

@ -50,33 +50,52 @@ extern nfstype nfsv3_type[];
#define nfsv3tov_type(a) nv3tov_type[fxdr_unsigned(u_int32_t,(a))&0x7]
#define vtonfsv3_type(a) txdr_unsigned(nfsv3_type[((int32_t)(a))])
#define NFSMADV(m, s) \
do { \
(m)->m_data += (s); \
} while (0)
int nfs_adv(struct mbuf **, caddr_t *, int, int);
void *nfsm_build_xx(int s, struct mbuf **mb, caddr_t *bpos);
void *nfsm_dissect_xx(int s, struct mbuf **md, caddr_t *dpos);
int nfsm_strsiz_xx(int *s, int m, u_int32_t **tl, struct mbuf **mb,
caddr_t *bpos);
int nfsm_adv_xx(int s, u_int32_t **tl, struct mbuf **md, caddr_t *dpos);
u_quad_t nfs_curusec(void);
void *nfsm_disct(struct mbuf **, caddr_t *, int, int);
/* ****************************** */
/* Build request/reply phase macros */
void *nfsm_build_xx(int s, struct mbuf **mb, caddr_t *bpos);
#define nfsm_build(c, s) \
(c)nfsm_build_xx((s), &mb, &bpos)
/* ****************************** */
/* Interpretation phase macros */
void *nfsm_dissect_xx(int s, struct mbuf **md, caddr_t *dpos);
int nfsm_strsiz_xx(int *s, int m, u_int32_t **tl, struct mbuf **md,
caddr_t *dpos);
int nfsm_adv_xx(int s, u_int32_t **tl, struct mbuf **md, caddr_t *dpos);
/* Error check helpers */
#define nfsm_dcheck(t1, mrep) \
do { \
if (t1 != 0) { \
error = t1; \
m_freem((mrep)); \
(mrep) = NULL; \
goto nfsmout; \
} \
} while (0)
#define nfsm_dcheckp(retp, mrep) \
do { \
if (retp == NULL) { \
error = EBADRPC; \
m_freem((mrep)); \
(mrep) = NULL; \
goto nfsmout; \
} \
} while (0)
#define nfsm_dissect(c, s) \
({ \
void *ret; \
ret = nfsm_dissect_xx((s), &md, &dpos); \
if (ret == NULL) { \
error = EBADRPC; \
m_freem(mrep); \
mrep = NULL; \
goto nfsmout; \
} \
nfsm_dcheckp(ret, mrep); \
(c)ret; \
})
@ -84,23 +103,15 @@ void *nfsm_disct(struct mbuf **, caddr_t *, int, int);
do { \
int t1; \
t1 = nfsm_strsiz_xx(&(s), (m), &tl, &md, &dpos); \
if (t1) { \
error = t1; \
m_freem(mrep); \
mrep = NULL; \
goto nfsmout; \
} \
nfsm_dcheck(t1, mrep); \
} while(0)
#define nfsm_mtouio(p,s) \
do {\
int32_t t1; \
if ((s) > 0 && (t1 = nfsm_mbuftouio(&md, (p), (s), &dpos)) != 0) { \
error = t1; \
m_freem(mrep); \
mrep = NULL; \
goto nfsmout; \
} \
int32_t t1 = 0; \
if ((s) > 0) \
t1 = nfsm_mbuftouio(&md, (p), (s), &dpos); \
nfsm_dcheck(t1, mrep); \
} while (0)
#define nfsm_rndup(a) (((a)+3)&(~0x3))
@ -109,12 +120,7 @@ do {\
do { \
int t1; \
t1 = nfsm_adv_xx((s), &tl, &md, &dpos); \
if (t1) { \
error = t1; \
m_freem(mrep); \
mrep = NULL; \
goto nfsmout; \
} \
nfsm_dcheck(t1, mrep); \
} while (0)
#endif

View File

@ -88,110 +88,54 @@ struct mbuf *nfsm_rpchead(struct ucred *cr, int nmflag, int procid,
* unions.
*/
/* *********************************** */
/* Request generation phase macros */
int nfsm_fhtom_xx(struct vnode *v, int v3, u_int32_t **tl,
struct mbuf **mb, caddr_t *bpos);
int nfsm_mtofh_xx(struct vnode *d, struct vnode **v, int v3, int *f,
u_int32_t **tl, struct mbuf **md, caddr_t *dpos);
int nfsm_getfh_xx(nfsfh_t **f, int *s, int v3, u_int32_t **tl,
struct mbuf **md, caddr_t *dpos);
void nfsm_v3attrbuild_xx(struct vattr *va, int full, u_int32_t **tl,
struct mbuf **mb, caddr_t *bpos);
int nfsm_loadattr_xx(struct vnode **v, struct vattr *va, u_int32_t **tl,
struct mbuf **md, caddr_t *dpos);
int nfsm_postop_attr_xx(struct vnode **v, int *f, u_int32_t **tl,
struct mbuf **md, caddr_t *dpos);
int nfsm_wcc_data_xx(struct vnode **v, int *f, u_int32_t **tl,
struct mbuf **md, caddr_t *dpos);
int nfsm_strtom_xx(const char *a, int s, int m, u_int32_t **tl,
struct mbuf **mb, caddr_t *bpos);
#define nfsm_bcheck(t1, mreq) \
do { \
if (t1) { \
error = t1; \
m_freem(mreq); \
goto nfsmout; \
} \
} while (0)
#define nfsm_fhtom(v, v3) \
do { \
int32_t t1; \
t1 = nfsm_fhtom_xx((v), (v3), &tl, &mb, &bpos); \
if (t1) { \
error = t1; \
m_freem(mreq); \
goto nfsmout; \
} \
} while (0)
#define nfsm_mtofh(d, v, v3, f) \
do { \
int32_t t1; \
t1 = nfsm_mtofh_xx((d), &(v), (v3), &(f), &tl, &md, &dpos); \
if (t1) { \
error = t1; \
m_freem(mrep); \
goto nfsmout; \
} \
} while (0)
#define nfsm_getfh(f, s, v3) \
do { \
int32_t t1; \
t1 = nfsm_getfh_xx(&(f), &(s), (v3), &tl, &md, &dpos); \
if (t1) { \
error = t1; \
m_freem(mrep); \
goto nfsmout; \
} \
} while (0)
#define nfsm_loadattr(v, a) \
do { \
int32_t t1; \
t1 = nfsm_loadattr_xx(&v, a, &tl, &md, &dpos); \
if (t1 != 0) { \
error = t1; \
m_freem(mrep); \
goto nfsmout; \
} \
} while (0)
#define nfsm_postop_attr(v, f) \
do { \
int32_t t1; \
t1 = nfsm_postop_attr_xx(&v, &f, &tl, &md, &dpos); \
if (t1 != 0) { \
error = t1; \
m_freem(mrep); \
goto nfsmout; \
} \
} while (0)
/* Used as (f) for nfsm_wcc_data() */
#define NFSV3_WCCRATTR 0
#define NFSV3_WCCCHK 1
#define nfsm_wcc_data(v, f) \
do { \
int32_t t1; \
t1 = nfsm_wcc_data_xx(&v, &f, &tl, &md, &dpos); \
if (t1 != 0) { \
error = t1; \
m_freem(mrep); \
goto nfsmout; \
} \
nfsm_bcheck(t1, mreq); \
} while (0)
/* If full is true, set all fields, otherwise just set mode and time fields */
#define nfsm_v3attrbuild(a, full) \
do { \
nfsm_v3attrbuild_xx(a, full, &tl, &mb, &bpos); \
} while(0)
nfsm_v3attrbuild_xx(a, full, &tl, &mb, &bpos)
#define nfsm_uiotom(p, s) \
do { \
int t1; \
t1 = nfsm_uiotombuf((p), &mb, (s), &bpos); \
if (t1 != 0) { \
error = t1; \
m_freem(mreq); \
goto nfsmout; \
} \
nfsm_bcheck(t1, mreq); \
} while (0)
#define nfsm_strtom(a, s, m) \
do { \
int t1; \
t1 = nfsm_strtom_xx((a), (s), (m), &tl, &mb, &bpos); \
nfsm_bcheck(t1, mreq); \
} while (0)
/* *********************************** */
/* Send the request */
#define nfsm_request(v, t, p, c) \
do { \
error = nfs_request((v), mreq, (t), (p), (c), &mrep, &md, &dpos); \
@ -203,15 +147,57 @@ do { \
} \
} while (0)
#define nfsm_strtom(a, s, m) \
/* *********************************** */
/* Reply interpretation phase macros */
int nfsm_mtofh_xx(struct vnode *d, struct vnode **v, int v3, int *f,
u_int32_t **tl, struct mbuf **md, caddr_t *dpos);
int nfsm_getfh_xx(nfsfh_t **f, int *s, int v3, u_int32_t **tl,
struct mbuf **md, caddr_t *dpos);
int nfsm_loadattr_xx(struct vnode **v, struct vattr *va, u_int32_t **tl,
struct mbuf **md, caddr_t *dpos);
int nfsm_postop_attr_xx(struct vnode **v, int *f, u_int32_t **tl,
struct mbuf **md, caddr_t *dpos);
int nfsm_wcc_data_xx(struct vnode **v, int *f, u_int32_t **tl,
struct mbuf **md, caddr_t *dpos);
#define nfsm_mtofh(d, v, v3, f) \
do { \
int t1; \
t1 = nfsm_strtom_xx((a), (s), (m), &tl, &mb, &bpos); \
if (t1 != 0) { \
error = t1; \
m_freem(mreq); \
goto nfsmout; \
} \
int32_t t1; \
t1 = nfsm_mtofh_xx((d), &(v), (v3), &(f), &tl, &md, &dpos); \
nfsm_dcheck(t1, mrep); \
} while (0)
#define nfsm_getfh(f, s, v3) \
do { \
int32_t t1; \
t1 = nfsm_getfh_xx(&(f), &(s), (v3), &tl, &md, &dpos); \
nfsm_dcheck(t1, mrep); \
} while (0)
#define nfsm_loadattr(v, a) \
do { \
int32_t t1; \
t1 = nfsm_loadattr_xx(&v, a, &tl, &md, &dpos); \
nfsm_dcheck(t1, mrep); \
} while (0)
#define nfsm_postop_attr(v, f) \
do { \
int32_t t1; \
t1 = nfsm_postop_attr_xx(&v, &f, &tl, &md, &dpos); \
nfsm_dcheck(t1, mrep); \
} while (0)
/* Used as (f) for nfsm_wcc_data() */
#define NFSV3_WCCRATTR 0
#define NFSV3_WCCCHK 1
#define nfsm_wcc_data(v, f) \
do { \
int32_t t1; \
t1 = nfsm_wcc_data_xx(&v, &f, &tl, &md, &dpos); \
nfsm_dcheck(t1, mrep); \
} while (0)
#endif

View File

@ -346,8 +346,8 @@ extern int nfs_debug;
int nfs_getreq(struct nfsrv_descript *, struct nfsd *, int);
int nfsrv_send(struct socket *, struct sockaddr *, struct mbuf *);
void nfs_rephead(int, struct nfsrv_descript *, struct nfssvc_sock *,
int, struct mbuf **, struct mbuf **, caddr_t *);
struct mbuf *nfs_rephead(int, struct nfsrv_descript *, int, struct mbuf **,
caddr_t *);
int nfs_slplock(struct nfssvc_sock *, int);
void nfs_slpunlock(struct nfssvc_sock *);
void nfsm_srvfattr(struct nfsrv_descript *, struct vattr *,
@ -363,11 +363,10 @@ int nfs_namei(struct nameidata *, fhandle_t *, int,
void nfsm_adj(struct mbuf *, int, int);
int nfsm_mbuftouio(struct mbuf **, struct uio *, int, caddr_t *);
void nfsrv_initcache(void);
void nfsrv_timer(void*);
void nfsrv_timer(void *);
int nfsrv_dorec(struct nfssvc_sock *, struct nfsd *,
struct nfsrv_descript **);
int nfsrv_getcache(struct nfsrv_descript *, struct nfssvc_sock *,
struct mbuf **);
int nfsrv_getcache(struct nfsrv_descript *, struct mbuf **);
void nfsrv_updatecache(struct nfsrv_descript *, int, struct mbuf *);
void nfsrv_cleancache(void);
void nfsrv_init(int);

View File

@ -1055,7 +1055,7 @@ nfsrv_write(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
adjust = dpos - mtod(mp, caddr_t);
mp->m_len -= adjust;
if (mp->m_len > 0 && adjust > 0)
NFSMADV(mp, adjust);
mp->m_data += adjust;
}
if (zeroing)
mp->m_len = 0;
@ -1273,7 +1273,7 @@ nfsrv_writegather(struct nfsrv_descript **ndp, struct nfssvc_sock *slp,
adjust = dpos - mtod(mp, caddr_t);
mp->m_len -= adjust;
if (mp->m_len > 0 && adjust > 0)
NFSMADV(mp, adjust);
mp->m_data += adjust;
}
if (zeroing)
mp->m_len = 0;

View File

@ -150,8 +150,7 @@ nfsrv_initcache(void)
* Update/add new request at end of lru list
*/
int
nfsrv_getcache(struct nfsrv_descript *nd, struct nfssvc_sock *slp,
struct mbuf **repp)
nfsrv_getcache(struct nfsrv_descript *nd, struct mbuf **repp)
{
struct nfsrvcache *rp;
struct mbuf *mb;
@ -188,8 +187,8 @@ loop:
ret = RC_DROPIT;
} else if (rp->rc_flag & RC_REPSTATUS) {
nfsrvstats.srvcache_nonidemdonehits++;
nfs_rephead(0, nd, slp, rp->rc_status,
repp, &mb, &bpos);
*repp = nfs_rephead(0, nd, rp->rc_status,
&mb, &bpos);
ret = RC_REPLY;
} else if (rp->rc_flag & RC_REPMBUF) {
nfsrvstats.srvcache_nonidemdonehits++;

View File

@ -136,9 +136,9 @@ int (*nfsrv3_procs[NFS_NPROCS])(struct nfsrv_descript *nd,
* Generate the rpc reply header
* siz arg. is used to decide if adding a cluster is worthwhile
*/
void
nfs_rephead(int siz, struct nfsrv_descript *nd, struct nfssvc_sock *slp,
int err, struct mbuf **mrq, struct mbuf **mbp, caddr_t *bposp)
struct mbuf *
nfs_rephead(int siz, struct nfsrv_descript *nd, int err,
struct mbuf **mbp, caddr_t *bposp)
{
u_int32_t *tl;
struct mbuf *mreq;
@ -148,7 +148,6 @@ nfs_rephead(int siz, struct nfsrv_descript *nd, struct nfssvc_sock *slp,
nd->nd_repstat = err;
if (err && (nd->nd_flag & ND_NFSV3) == 0) /* XXX recheck */
siz = 0;
MGETHDR(mreq, M_TRYWAIT, MT_DATA);
mb = mreq;
/*
@ -179,7 +178,6 @@ nfs_rephead(int siz, struct nfsrv_descript *nd, struct nfssvc_sock *slp,
}
} else {
*tl++ = rpc_msgaccepted;
/*
* Send a RPCAUTH_NULL verifier - no Kerberos.
*/
@ -211,15 +209,13 @@ nfs_rephead(int siz, struct nfsrv_descript *nd, struct nfssvc_sock *slp,
*tl = 0;
}
break;
};
}
}
if (mrq != NULL)
*mrq = mreq;
*mbp = mb;
*bposp = bpos;
if (err != 0 && err != NFSERR_RETVOID)
nfsrvstats.srvrpc_errs++;
return mreq;
}

View File

@ -1376,17 +1376,3 @@ nfsm_srvsattr_xx(struct vattr *a,
}
return 0;
}
void
nfs_rephead_xx(int s, struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
int error, struct mbuf **mrq, struct mbuf **mb,
struct mbuf **mreq, struct mbuf **mrep, caddr_t *bpos)
{
nfs_rephead(s, nfsd, slp, error, mrq, mb, bpos);
if (*mrep != NULL) {
m_freem(*mrep);
*mrep = NULL;
}
*mreq = *mrq;
}

View File

@ -376,7 +376,7 @@ nfssvc_nfsd(struct nfsd_srvargs *nsd, caddr_t argp, struct thread *td)
/*
* Check to see if authorization is needed.
*/
cacherep = nfsrv_getcache(nd, slp, &mreq);
cacherep = nfsrv_getcache(nd, &mreq);
if (nfs_privport) {
/* Check if source port is privileged */

View File

@ -55,10 +55,6 @@
*/
#define M_HASCL(m) ((m)->m_flags & M_EXT)
#define NFSMADV(m, s) \
do { \
(m)->m_data += (s); \
} while (0)
#define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \
(((m)->m_flags & M_PKTHDR)?MHLEN:MLEN))
@ -76,36 +72,19 @@
*/
/* Helpers for macros */
void nfsm_srvfhtom_xx(fhandle_t *f, int v3, u_int32_t **tl, struct mbuf **mb,
caddr_t *bpos);
void nfsm_srvpostop_fh_xx(fhandle_t *f, u_int32_t **tl, struct mbuf **mb,
caddr_t *bpos);
/* ************************************* */
/* Dissection phase macros */
int nfsm_srvstrsiz_xx(int *s, int m, u_int32_t **tl, struct mbuf **md,
caddr_t *dpos);
int nfsm_srvnamesiz_xx(int *s, u_int32_t **tl, struct mbuf **md,
caddr_t *dpos);
void nfs_rephead_xx(int s, struct nfsrv_descript *nfsd,
struct nfssvc_sock *slp, int error, struct mbuf **mrq,
struct mbuf **mb, struct mbuf **mreq, struct mbuf **mrep,
caddr_t *bpos);
int nfsm_srvmtofh_xx(fhandle_t *f, struct nfsrv_descript *nfsd,
u_int32_t **tl, struct mbuf **md, caddr_t *dpos);
void nfsm_clget_xx(u_int32_t **tl, struct mbuf *mb, struct mbuf **mp,
char **bp, char **be, caddr_t bpos);
int nfsm_srvsattr_xx(struct vattr *a, u_int32_t **tl, struct mbuf **md,
caddr_t *dpos);
#define nfsm_srvfhtom(f, v3) \
do { \
nfsm_srvfhtom_xx((f), (v3), &tl, &mb, &bpos); \
} while (0)
#define nfsm_srvpostop_fh(f) \
do { \
nfsm_srvpostop_fh_xx((f), &tl, &mb, &bpos); \
} while (0)
#define nfsm_srvstrsiz(s, m) \
do { \
int t1; \
@ -126,20 +105,6 @@ do { \
} \
} while (0)
#define nfsm_reply(s) \
do { \
nfs_rephead_xx((s), nfsd, slp, error, mrq, &mb, &mreq, &mrep, &bpos); \
if (error && error == EBADRPC) { \
error = 0; \
goto nfsmout; \
} \
} while (0)
#define nfsm_writereply(s) \
do { \
nfs_rephead((s), nfsd, slp, error, &mreq, &mb, &bpos); \
} while (0)
#define nfsm_srvmtofh(f) \
do { \
int t1; \
@ -150,26 +115,7 @@ do { \
} \
} while (0)
#define nfsm_clget \
do { \
nfsm_clget_xx(&tl, mb, &mp, &bp, &be, bpos); \
} while (0)
#define nfsm_srvfillattr(a, f) \
do { \
nfsm_srvfattr(nfsd, (a), (f)); \
} while (0)
#define nfsm_srvwcc_data(br, b, ar, a) \
do { \
nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos); \
} while (0)
#define nfsm_srvpostop_attr(r, a) \
do { \
nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos); \
} while (0)
/* XXX why is this different? */
#define nfsm_srvsattr(a) \
do { \
int t1; \
@ -182,4 +128,54 @@ do { \
} \
} while (0)
/* ************************************* */
/* Prepare the reply */
#define nfsm_reply(s) \
do { \
if (mrep != NULL) { \
m_freem(mrep); \
mrep = NULL; \
} \
if (error == EBADRPC) { \
error = 0; \
goto nfsmout; \
} \
mreq = nfs_rephead((s), nfsd, error, &mb, &bpos); \
*mrq = mreq; \
} while (0)
#define nfsm_writereply(s) \
do { \
mreq = nfs_rephead((s), nfsd, error, &mb, &bpos); \
} while(0)
/* ************************************* */
/* Reply phase macros - add additional reply info */
void nfsm_srvfhtom_xx(fhandle_t *f, int v3, u_int32_t **tl, struct mbuf **mb,
caddr_t *bpos);
void nfsm_srvpostop_fh_xx(fhandle_t *f, u_int32_t **tl, struct mbuf **mb,
caddr_t *bpos);
void nfsm_clget_xx(u_int32_t **tl, struct mbuf *mb, struct mbuf **mp,
char **bp, char **be, caddr_t bpos);
#define nfsm_srvfhtom(f, v3) \
nfsm_srvfhtom_xx((f), (v3), &tl, &mb, &bpos)
#define nfsm_srvpostop_fh(f) \
nfsm_srvpostop_fh_xx((f), &tl, &mb, &bpos)
#define nfsm_srvwcc_data(br, b, ar, a) \
nfsm_srvwcc(nfsd, (br), (b), (ar), (a), &mb, &bpos)
#define nfsm_srvpostop_attr(r, a) \
nfsm_srvpostopattr(nfsd, (r), (a), &mb, &bpos)
#define nfsm_srvfillattr(a, f) \
nfsm_srvfattr(nfsd, (a), (f))
#define nfsm_clget \
nfsm_clget_xx(&tl, mb, &mp, &bp, &be, bpos)
#endif