- Use m_get2() instead of nfsm_reqhead().

- Use m_get(), m_getcl() instead of historic macros.

Sponsored by:	Nginx, Inc.
This commit is contained in:
Gleb Smirnoff 2013-03-12 12:23:47 +00:00
parent 4bc80a3402
commit 8e7e03d327
4 changed files with 45 additions and 88 deletions

View File

@ -171,23 +171,6 @@ nfs_xid_gen(void)
return xid;
}
/*
* Create the header for an rpc request packet
* The hsiz is the size of the rest of the nfs request header.
* (just used to decide if a cluster is a good idea)
*/
struct mbuf *
nfsm_reqhead(struct vnode *vp, u_long procid, int hsiz)
{
struct mbuf *mb;
MGET(mb, M_WAITOK, MT_DATA);
if (hsiz >= MINCLSIZE)
MCLGET(mb, M_WAITOK);
mb->m_len = 0;
return (mb);
}
/*
* copies a uio scatter/gather list to an mbuf chain.
* NOTE: can ony handle iovcnt == 1
@ -218,10 +201,10 @@ nfsm_uiotombuf(struct uio *uiop, struct mbuf **mq, int siz, caddr_t *bpos)
while (left > 0) {
mlen = M_TRAILINGSPACE(mp);
if (mlen == 0) {
MGET(mp, M_WAITOK, MT_DATA);
if (clflg)
MCLGET(mp, M_WAITOK);
mp->m_len = 0;
mp = m_getcl(M_WAITOK, MT_DATA, 0);
else
mp = m_get(M_WAITOK, MT_DATA);
mp2->m_next = mp;
mp2 = mp;
mlen = M_TRAILINGSPACE(mp);
@ -251,8 +234,7 @@ nfsm_uiotombuf(struct uio *uiop, struct mbuf **mq, int siz, caddr_t *bpos)
}
if (rem > 0) {
if (rem > M_TRAILINGSPACE(mp)) {
MGET(mp, M_WAITOK, MT_DATA);
mp->m_len = 0;
mp = m_get(M_WAITOK, MT_DATA);
mp2->m_next = mp;
}
cp = mtod(mp, caddr_t)+mp->m_len;
@ -296,10 +278,13 @@ nfsm_strtmbuf(struct mbuf **mb, char **bpos, const char *cp, long siz)
}
/* Loop around adding mbufs */
while (siz > 0) {
MGET(m1, M_WAITOK, MT_DATA);
if (siz > MLEN)
MCLGET(m1, M_WAITOK);
m1->m_len = NFSMSIZ(m1);
if (siz > MLEN) {
m1 = m_getcl(M_WAITOK, MT_DATA, 0);
m1->m_len = MCLBYTES;
} else {
m1 = m_get(M_WAITOK, MT_DATA);
m1->m_len = MLEN;
}
m2->m_next = m1;
m2 = m1;
tl = mtod(m1, u_int32_t *);

View File

@ -298,7 +298,7 @@ nfs_statfs(struct mount *mp, struct statfs *sbp)
} else
mtx_unlock(&nmp->nm_mtx);
nfsstats.rpccnt[NFSPROC_FSSTAT]++;
mreq = nfsm_reqhead(vp, NFSPROC_FSSTAT, NFSX_FH(v3));
mreq = m_get2(M_WAITOK, MT_DATA, 0, NFSX_FH(v3));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(vp, v3);
@ -356,7 +356,7 @@ nfs_fsinfo(struct nfsmount *nmp, struct vnode *vp, struct ucred *cred,
u_int64_t maxfsize;
nfsstats.rpccnt[NFSPROC_FSINFO]++;
mreq = nfsm_reqhead(vp, NFSPROC_FSINFO, NFSX_FH(1));
mreq = m_get2(M_WAITOK, MT_DATA, 0, NFSX_FH(1));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(vp, 1);

View File

@ -294,7 +294,7 @@ nfs3_access_otw(struct vnode *vp, int wmode, struct thread *td,
struct nfsnode *np = VTONFS(vp);
nfsstats.rpccnt[NFSPROC_ACCESS]++;
mreq = nfsm_reqhead(vp, NFSPROC_ACCESS, NFSX_FH(v3) + NFSX_UNSIGNED);
mreq = m_get2(M_WAITOK, MT_DATA, 0, NFSX_FH(v3) + NFSX_UNSIGNED);
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(vp, v3);
@ -714,7 +714,7 @@ nfs_getattr(struct vop_getattr_args *ap)
goto nfsmout;
}
nfsstats.rpccnt[NFSPROC_GETATTR]++;
mreq = nfsm_reqhead(vp, NFSPROC_GETATTR, NFSX_FH(v3));
mreq = m_get2(M_WAITOK, MT_DATA, 0, NFSX_FH(v3));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(vp, v3);
@ -873,7 +873,7 @@ nfs_setattrrpc(struct vnode *vp, struct vattr *vap, struct ucred *cred)
int v3 = NFS_ISV3(vp);
nfsstats.rpccnt[NFSPROC_SETATTR]++;
mreq = nfsm_reqhead(vp, NFSPROC_SETATTR, NFSX_FH(v3) + NFSX_SATTR(v3));
mreq = m_get2(M_WAITOK, MT_DATA, 0, NFSX_FH(v3) + NFSX_SATTR(v3));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(vp, v3);
@ -1037,8 +1037,8 @@ nfs_lookup(struct vop_lookup_args *ap)
nfsstats.lookupcache_misses++;
nfsstats.rpccnt[NFSPROC_LOOKUP]++;
len = cnp->cn_namelen;
mreq = nfsm_reqhead(dvp, NFSPROC_LOOKUP,
NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(len));
mreq = m_get2(M_WAITOK, MT_DATA, 0,
NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(len));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(dvp, v3);
@ -1251,7 +1251,7 @@ nfs_readlinkrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred)
int v3 = NFS_ISV3(vp);
nfsstats.rpccnt[NFSPROC_READLINK]++;
mreq = nfsm_reqhead(vp, NFSPROC_READLINK, NFSX_FH(v3));
mreq = m_get2(M_WAITOK, MT_DATA, 0, NFSX_FH(v3));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(vp, v3);
@ -1306,7 +1306,8 @@ nfs_readrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred)
while (tsiz > 0) {
nfsstats.rpccnt[NFSPROC_READ]++;
len = (tsiz > rsize) ? rsize : tsiz;
mreq = nfsm_reqhead(vp, NFSPROC_READ, NFSX_FH(v3) + NFSX_UNSIGNED * 3);
mreq = m_get2(M_WAITOK, MT_DATA, 0,
NFSX_FH(v3) + NFSX_UNSIGNED * 3);
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(vp, v3);
@ -1378,8 +1379,8 @@ nfs_writerpc(struct vnode *vp, struct uio *uiop, struct ucred *cred,
while (tsiz > 0) {
nfsstats.rpccnt[NFSPROC_WRITE]++;
len = (tsiz > wsize) ? wsize : tsiz;
mreq = nfsm_reqhead(vp, NFSPROC_WRITE,
NFSX_FH(v3) + 5 * NFSX_UNSIGNED + nfsm_rndup(len));
mreq = m_get2(M_WAITOK, MT_DATA, 0,
NFSX_FH(v3) + 5 * NFSX_UNSIGNED + nfsm_rndup(len));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(vp, v3);
@ -1501,8 +1502,8 @@ nfs_mknodrpc(struct vnode *dvp, struct vnode **vpp, struct componentname *cnp,
if ((error = VOP_GETATTR(dvp, &vattr, cnp->cn_cred)) != 0)
return (error);
nfsstats.rpccnt[NFSPROC_MKNOD]++;
mreq = nfsm_reqhead(dvp, NFSPROC_MKNOD, NFSX_FH(v3) + 4 * NFSX_UNSIGNED +
+ nfsm_rndup(cnp->cn_namelen) + NFSX_SATTR(v3));
mreq = m_get2(M_WAITOK, MT_DATA, 0, NFSX_FH(v3) + 4 * NFSX_UNSIGNED +
nfsm_rndup(cnp->cn_namelen) + NFSX_SATTR(v3));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(dvp, v3);
@ -1605,8 +1606,8 @@ nfs_create(struct vop_create_args *ap)
fmode |= O_EXCL;
again:
nfsstats.rpccnt[NFSPROC_CREATE]++;
mreq = nfsm_reqhead(dvp, NFSPROC_CREATE, NFSX_FH(v3) + 2 * NFSX_UNSIGNED +
nfsm_rndup(cnp->cn_namelen) + NFSX_SATTR(v3));
mreq = m_get2(M_WAITOK, MT_DATA, 0, NFSX_FH(v3) + 2 * NFSX_UNSIGNED +
nfsm_rndup(cnp->cn_namelen) + NFSX_SATTR(v3));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(dvp, v3);
@ -1787,8 +1788,8 @@ nfs_removerpc(struct vnode *dvp, const char *name, int namelen,
int v3 = NFS_ISV3(dvp);
nfsstats.rpccnt[NFSPROC_REMOVE]++;
mreq = nfsm_reqhead(dvp, NFSPROC_REMOVE,
NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(namelen));
mreq = m_get2(M_WAITOK, MT_DATA, 0,
NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(namelen));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(dvp, v3);
@ -1923,9 +1924,8 @@ nfs_renamerpc(struct vnode *fdvp, const char *fnameptr, int fnamelen,
int v3 = NFS_ISV3(fdvp);
nfsstats.rpccnt[NFSPROC_RENAME]++;
mreq = nfsm_reqhead(fdvp, NFSPROC_RENAME,
(NFSX_FH(v3) + NFSX_UNSIGNED)*2 + nfsm_rndup(fnamelen) +
nfsm_rndup(tnamelen));
mreq = m_get2(M_WAITOK, MT_DATA, 0, (NFSX_FH(v3) + NFSX_UNSIGNED)*2 +
nfsm_rndup(fnamelen) + nfsm_rndup(tnamelen));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(fdvp, v3);
@ -1983,8 +1983,8 @@ nfs_link(struct vop_link_args *ap)
v3 = NFS_ISV3(vp);
nfsstats.rpccnt[NFSPROC_LINK]++;
mreq = nfsm_reqhead(vp, NFSPROC_LINK,
NFSX_FH(v3)*2 + NFSX_UNSIGNED + nfsm_rndup(cnp->cn_namelen));
mreq = m_get2(M_WAITOK, MT_DATA, 0,
NFSX_FH(v3)*2 + NFSX_UNSIGNED + nfsm_rndup(cnp->cn_namelen));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(vp, v3);
@ -2029,7 +2029,7 @@ nfs_symlink(struct vop_symlink_args *ap)
nfsstats.rpccnt[NFSPROC_SYMLINK]++;
slen = strlen(ap->a_target);
mreq = nfsm_reqhead(dvp, NFSPROC_SYMLINK, NFSX_FH(v3) + 2*NFSX_UNSIGNED +
mreq = m_get2(M_WAITOK, MT_DATA, 0, NFSX_FH(v3) + 2*NFSX_UNSIGNED +
nfsm_rndup(cnp->cn_namelen) + nfsm_rndup(slen) + NFSX_SATTR(v3));
mb = mreq;
bpos = mtod(mb, caddr_t);
@ -2123,8 +2123,8 @@ nfs_mkdir(struct vop_mkdir_args *ap)
return (error);
len = cnp->cn_namelen;
nfsstats.rpccnt[NFSPROC_MKDIR]++;
mreq = nfsm_reqhead(dvp, NFSPROC_MKDIR,
NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(len) + NFSX_SATTR(v3));
mreq = m_get2(M_WAITOK, MT_DATA, 0,
NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(len) + NFSX_SATTR(v3));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(dvp, v3);
@ -2188,8 +2188,8 @@ nfs_rmdir(struct vop_rmdir_args *ap)
if (dvp == vp)
return (EINVAL);
nfsstats.rpccnt[NFSPROC_RMDIR]++;
mreq = nfsm_reqhead(dvp, NFSPROC_RMDIR,
NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(cnp->cn_namelen));
mreq = m_get2(M_WAITOK, MT_DATA, 0,
NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(cnp->cn_namelen));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(dvp, v3);
@ -2307,8 +2307,8 @@ nfs_readdirrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred)
*/
while (more_dirs && bigenough) {
nfsstats.rpccnt[NFSPROC_READDIR]++;
mreq = nfsm_reqhead(vp, NFSPROC_READDIR, NFSX_FH(v3) +
NFSX_READDIR(v3));
mreq = m_get2(M_WAITOK, MT_DATA, 0,
NFSX_FH(v3) + NFSX_READDIR(v3));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(vp, v3);
@ -2513,8 +2513,8 @@ nfs_readdirplusrpc(struct vnode *vp, struct uio *uiop, struct ucred *cred)
*/
while (more_dirs && bigenough) {
nfsstats.rpccnt[NFSPROC_READDIRPLUS]++;
mreq = nfsm_reqhead(vp, NFSPROC_READDIRPLUS,
NFSX_FH(1) + 6 * NFSX_UNSIGNED);
mreq = m_get2(M_WAITOK, MT_DATA, 0,
NFSX_FH(1) + 6 * NFSX_UNSIGNED);
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(vp, 1);
@ -2818,8 +2818,8 @@ nfs_lookitup(struct vnode *dvp, const char *name, int len, struct ucred *cred,
int v3 = NFS_ISV3(dvp);
nfsstats.rpccnt[NFSPROC_LOOKUP]++;
mreq = nfsm_reqhead(dvp, NFSPROC_LOOKUP,
NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(len));
mreq = m_get2(M_WAITOK, MT_DATA, 0,
NFSX_FH(v3) + NFSX_UNSIGNED + nfsm_rndup(len));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(dvp, v3);
@ -2897,7 +2897,7 @@ nfs_commit(struct vnode *vp, u_quad_t offset, int cnt, struct ucred *cred,
}
mtx_unlock(&nmp->nm_mtx);
nfsstats.rpccnt[NFSPROC_COMMIT]++;
mreq = nfsm_reqhead(vp, NFSPROC_COMMIT, NFSX_FH(1));
mreq = m_get2(M_WAITOK, MT_DATA, 0, NFSX_FH(1));
mb = mreq;
bpos = mtod(mb, caddr_t);
nfsm_fhtom(vp, 1);

View File

@ -53,34 +53,6 @@ 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);
#define M_HASCL(m) ((m)->m_flags & M_EXT)
#define NFSMINOFF(m) \
do { \
if (M_HASCL(m)) \
(m)->m_data = (m)->m_ext.ext_buf; \
else if ((m)->m_flags & M_PKTHDR) \
(m)->m_data = (m)->m_pktdat; \
else \
(m)->m_data = (m)->m_dat; \
} while (0)
#define NFSMSIZ(m) ((M_HASCL(m))?MCLBYTES: \
(((m)->m_flags & M_PKTHDR)?MHLEN:MLEN))
/*
* Now for the macros that do the simple stuff and call the functions
* for the hard stuff.
* These macros use several vars. declared in nfsm_reqhead and these
* vars. must not be used elsewhere unless you are careful not to corrupt
* them. The vars. starting with pN and tN (N=1,2,3,..) are temporaries
* that may be used so long as the value is not expected to retained
* after a macro.
* I know, this is kind of dorkey, but it makes the actual op functions
* fairly clean and deals with the mess caused by the xdr discriminating
* unions.
*/
/* *********************************** */
/* Request generation phase macros */