Move four functions in nfscl.ko to nfscommon.ko.

Four functions nfscl_reqstart(), nfscl_fillsattr(), nfsm_stateidtom()
and nfsmnt_mdssession() are now called from within the nfsd.
As such, they needed to be moved from nfscl.ko to nfscommon.ko so that
nfsd.ko would load when nfscl.ko wasn't loaded.

Reported by:	herbert@gojira.at
This commit is contained in:
Rick Macklem 2018-06-14 10:00:19 +00:00
parent a4f647571f
commit c338c94d20
6 changed files with 384 additions and 384 deletions

View File

@ -79,6 +79,7 @@ extern struct mtx nfsrv_dslock_mtx;
extern volatile int nfsrv_devidcnt;
extern int nfscl_debuglevel;
extern struct nfsdevicehead nfsrv_devidhead;
extern struct nfsstatsv1 nfsstatsv1;
SYSCTL_DECL(_vfs_nfs);
SYSCTL_INT(_vfs_nfs, OID_AUTO, enable_uidtostring, CTLFLAG_RW,
@ -189,7 +190,7 @@ static struct nfsrv_lughash *nfsgroupnamehash;
* marked 0 in this array, the code will still work, just not quite as
* efficiently.)
*/
int nfs_bigreply[NFSV41_NPROCS] = { 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0,
static int nfs_bigreply[NFSV41_NPROCS] = { 0, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 };
@ -204,6 +205,362 @@ static int nfsrv_getrefstr(struct nfsrv_descript *, u_char **, u_char **,
int *, int *);
static void nfsrv_refstrbigenough(int, u_char **, u_char **, int *);
static struct {
int op;
int opcnt;
const u_char *tag;
int taglen;
} nfsv4_opmap[NFSV41_NPROCS] = {
{ 0, 1, "Null", 4 },
{ NFSV4OP_GETATTR, 1, "Getattr", 7, },
{ NFSV4OP_SETATTR, 2, "Setattr", 7, },
{ NFSV4OP_LOOKUP, 3, "Lookup", 6, },
{ NFSV4OP_ACCESS, 2, "Access", 6, },
{ NFSV4OP_READLINK, 2, "Readlink", 8, },
{ NFSV4OP_READ, 1, "Read", 4, },
{ NFSV4OP_WRITE, 2, "Write", 5, },
{ NFSV4OP_OPEN, 5, "Open", 4, },
{ NFSV4OP_CREATE, 5, "Create", 6, },
{ NFSV4OP_CREATE, 1, "Create", 6, },
{ NFSV4OP_CREATE, 3, "Create", 6, },
{ NFSV4OP_REMOVE, 1, "Remove", 6, },
{ NFSV4OP_REMOVE, 1, "Remove", 6, },
{ NFSV4OP_SAVEFH, 5, "Rename", 6, },
{ NFSV4OP_SAVEFH, 4, "Link", 4, },
{ NFSV4OP_READDIR, 2, "Readdir", 7, },
{ NFSV4OP_READDIR, 2, "Readdir", 7, },
{ NFSV4OP_GETATTR, 1, "Getattr", 7, },
{ NFSV4OP_GETATTR, 1, "Getattr", 7, },
{ NFSV4OP_GETATTR, 1, "Getattr", 7, },
{ NFSV4OP_COMMIT, 2, "Commit", 6, },
{ NFSV4OP_LOOKUPP, 3, "Lookupp", 7, },
{ NFSV4OP_SETCLIENTID, 1, "SetClientID", 11, },
{ NFSV4OP_SETCLIENTIDCFRM, 1, "SetClientIDConfirm", 18, },
{ NFSV4OP_LOCK, 1, "Lock", 4, },
{ NFSV4OP_LOCKU, 1, "LockU", 5, },
{ NFSV4OP_OPEN, 2, "Open", 4, },
{ NFSV4OP_CLOSE, 1, "Close", 5, },
{ NFSV4OP_OPENCONFIRM, 1, "Openconfirm", 11, },
{ NFSV4OP_LOCKT, 1, "LockT", 5, },
{ NFSV4OP_OPENDOWNGRADE, 1, "Opendowngrade", 13, },
{ NFSV4OP_RENEW, 1, "Renew", 5, },
{ NFSV4OP_PUTROOTFH, 1, "Dirpath", 7, },
{ NFSV4OP_RELEASELCKOWN, 1, "Rellckown", 9, },
{ NFSV4OP_DELEGRETURN, 1, "Delegret", 8, },
{ NFSV4OP_DELEGRETURN, 3, "DelegRemove", 11, },
{ NFSV4OP_DELEGRETURN, 7, "DelegRename1", 12, },
{ NFSV4OP_DELEGRETURN, 9, "DelegRename2", 12, },
{ NFSV4OP_GETATTR, 1, "Getacl", 6, },
{ NFSV4OP_SETATTR, 1, "Setacl", 6, },
{ NFSV4OP_EXCHANGEID, 1, "ExchangeID", 10, },
{ NFSV4OP_CREATESESSION, 1, "CreateSession", 13, },
{ NFSV4OP_DESTROYSESSION, 1, "DestroySession", 14, },
{ NFSV4OP_DESTROYCLIENTID, 1, "DestroyClient", 13, },
{ NFSV4OP_FREESTATEID, 1, "FreeStateID", 11, },
{ NFSV4OP_LAYOUTGET, 1, "LayoutGet", 9, },
{ NFSV4OP_GETDEVINFO, 1, "GetDeviceInfo", 13, },
{ NFSV4OP_LAYOUTCOMMIT, 1, "LayoutCommit", 12, },
{ NFSV4OP_LAYOUTRETURN, 1, "LayoutReturn", 12, },
{ NFSV4OP_RECLAIMCOMPL, 1, "ReclaimComplete", 15, },
{ NFSV4OP_WRITE, 1, "WriteDS", 7, },
{ NFSV4OP_READ, 1, "ReadDS", 6, },
{ NFSV4OP_COMMIT, 1, "CommitDS", 8, },
{ NFSV4OP_OPEN, 3, "OpenLayoutGet", 13, },
{ NFSV4OP_OPEN, 8, "CreateLayGet", 12, },
};
/*
* NFS RPCS that have large request message size.
*/
static int nfs_bigrequest[NFSV41_NPROCS] = {
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0
};
/*
* Start building a request. Mostly just put the first file handle in
* place.
*/
APPLESTATIC void
nfscl_reqstart(struct nfsrv_descript *nd, int procnum, struct nfsmount *nmp,
u_int8_t *nfhp, int fhlen, u_int32_t **opcntpp, struct nfsclsession *sep,
int vers, int minorvers)
{
struct mbuf *mb;
u_int32_t *tl;
int opcnt;
nfsattrbit_t attrbits;
/*
* First, fill in some of the fields of nd.
*/
nd->nd_slotseq = NULL;
if (vers == NFS_VER4) {
nd->nd_flag = ND_NFSV4 | ND_NFSCL;
if (minorvers == NFSV41_MINORVERSION)
nd->nd_flag |= ND_NFSV41;
} else if (vers == NFS_VER3)
nd->nd_flag = ND_NFSV3 | ND_NFSCL;
else {
if (NFSHASNFSV4(nmp)) {
nd->nd_flag = ND_NFSV4 | ND_NFSCL;
if (NFSHASNFSV4N(nmp))
nd->nd_flag |= ND_NFSV41;
} else if (NFSHASNFSV3(nmp))
nd->nd_flag = ND_NFSV3 | ND_NFSCL;
else
nd->nd_flag = ND_NFSV2 | ND_NFSCL;
}
nd->nd_procnum = procnum;
nd->nd_repstat = 0;
/*
* Get the first mbuf for the request.
*/
if (nfs_bigrequest[procnum])
NFSMCLGET(mb, M_WAITOK);
else
NFSMGET(mb);
mbuf_setlen(mb, 0);
nd->nd_mreq = nd->nd_mb = mb;
nd->nd_bpos = NFSMTOD(mb, caddr_t);
/*
* And fill the first file handle into the request.
*/
if (nd->nd_flag & ND_NFSV4) {
opcnt = nfsv4_opmap[procnum].opcnt +
nfsv4_opflag[nfsv4_opmap[procnum].op].needscfh;
if ((nd->nd_flag & ND_NFSV41) != 0) {
opcnt += nfsv4_opflag[nfsv4_opmap[procnum].op].needsseq;
if (procnum == NFSPROC_RENEW)
/*
* For the special case of Renew, just do a
* Sequence Op.
*/
opcnt = 1;
else if (procnum == NFSPROC_WRITEDS ||
procnum == NFSPROC_COMMITDS)
/*
* For the special case of a Writeor Commit to
* a DS, the opcnt == 3, for Sequence, PutFH,
* Write/Commit.
*/
opcnt = 3;
}
/*
* What should the tag really be?
*/
(void) nfsm_strtom(nd, nfsv4_opmap[procnum].tag,
nfsv4_opmap[procnum].taglen);
NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
if ((nd->nd_flag & ND_NFSV41) != 0)
*tl++ = txdr_unsigned(NFSV41_MINORVERSION);
else
*tl++ = txdr_unsigned(NFSV4_MINORVERSION);
if (opcntpp != NULL)
*opcntpp = tl;
*tl = txdr_unsigned(opcnt);
if ((nd->nd_flag & ND_NFSV41) != 0 &&
nfsv4_opflag[nfsv4_opmap[procnum].op].needsseq > 0) {
if (nfsv4_opflag[nfsv4_opmap[procnum].op].loopbadsess >
0)
nd->nd_flag |= ND_LOOPBADSESS;
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = txdr_unsigned(NFSV4OP_SEQUENCE);
if (sep == NULL) {
sep = nfsmnt_mdssession(nmp);
nfsv4_setsequence(nmp, nd, sep,
nfs_bigreply[procnum]);
} else
nfsv4_setsequence(nmp, nd, sep,
nfs_bigreply[procnum]);
}
if (nfsv4_opflag[nfsv4_opmap[procnum].op].needscfh > 0) {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = txdr_unsigned(NFSV4OP_PUTFH);
(void) nfsm_fhtom(nd, nfhp, fhlen, 0);
if (nfsv4_opflag[nfsv4_opmap[procnum].op].needscfh
== 2 && procnum != NFSPROC_WRITEDS &&
procnum != NFSPROC_COMMITDS) {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = txdr_unsigned(NFSV4OP_GETATTR);
/*
* For Lookup Ops, we want all the directory
* attributes, so we can load the name cache.
*/
if (procnum == NFSPROC_LOOKUP ||
procnum == NFSPROC_LOOKUPP)
NFSGETATTR_ATTRBIT(&attrbits);
else {
NFSWCCATTR_ATTRBIT(&attrbits);
nd->nd_flag |= ND_V4WCCATTR;
}
(void) nfsrv_putattrbit(nd, &attrbits);
}
}
if (procnum != NFSPROC_RENEW ||
(nd->nd_flag & ND_NFSV41) == 0) {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = txdr_unsigned(nfsv4_opmap[procnum].op);
}
} else {
(void) nfsm_fhtom(nd, nfhp, fhlen, 0);
}
if (procnum < NFSV41_NPROCS)
NFSINCRGLOBAL(nfsstatsv1.rpccnt[procnum]);
}
/*
* Put a state Id in the mbuf list.
*/
APPLESTATIC void
nfsm_stateidtom(struct nfsrv_descript *nd, nfsv4stateid_t *stateidp, int flag)
{
nfsv4stateid_t *st;
NFSM_BUILD(st, nfsv4stateid_t *, NFSX_STATEID);
if (flag == NFSSTATEID_PUTALLZERO) {
st->seqid = 0;
st->other[0] = 0;
st->other[1] = 0;
st->other[2] = 0;
} else if (flag == NFSSTATEID_PUTALLONE) {
st->seqid = 0xffffffff;
st->other[0] = 0xffffffff;
st->other[1] = 0xffffffff;
st->other[2] = 0xffffffff;
} else if (flag == NFSSTATEID_PUTSEQIDZERO) {
st->seqid = 0;
st->other[0] = stateidp->other[0];
st->other[1] = stateidp->other[1];
st->other[2] = stateidp->other[2];
} else {
st->seqid = stateidp->seqid;
st->other[0] = stateidp->other[0];
st->other[1] = stateidp->other[1];
st->other[2] = stateidp->other[2];
}
}
/*
* Fill in the setable attributes. The full argument indicates whether
* to fill in them all or just mode and time.
*/
void
nfscl_fillsattr(struct nfsrv_descript *nd, struct vattr *vap,
struct vnode *vp, int flags, u_int32_t rdev)
{
u_int32_t *tl;
struct nfsv2_sattr *sp;
nfsattrbit_t attrbits;
switch (nd->nd_flag & (ND_NFSV2 | ND_NFSV3 | ND_NFSV4)) {
case ND_NFSV2:
NFSM_BUILD(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
if (vap->va_mode == (mode_t)VNOVAL)
sp->sa_mode = newnfs_xdrneg1;
else
sp->sa_mode = vtonfsv2_mode(vap->va_type, vap->va_mode);
if (vap->va_uid == (uid_t)VNOVAL)
sp->sa_uid = newnfs_xdrneg1;
else
sp->sa_uid = txdr_unsigned(vap->va_uid);
if (vap->va_gid == (gid_t)VNOVAL)
sp->sa_gid = newnfs_xdrneg1;
else
sp->sa_gid = txdr_unsigned(vap->va_gid);
if (flags & NFSSATTR_SIZE0)
sp->sa_size = 0;
else if (flags & NFSSATTR_SIZENEG1)
sp->sa_size = newnfs_xdrneg1;
else if (flags & NFSSATTR_SIZERDEV)
sp->sa_size = txdr_unsigned(rdev);
else
sp->sa_size = txdr_unsigned(vap->va_size);
txdr_nfsv2time(&vap->va_atime, &sp->sa_atime);
txdr_nfsv2time(&vap->va_mtime, &sp->sa_mtime);
break;
case ND_NFSV3:
if (vap->va_mode != (mode_t)VNOVAL) {
NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
*tl++ = newnfs_true;
*tl = txdr_unsigned(vap->va_mode);
} else {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = newnfs_false;
}
if ((flags & NFSSATTR_FULL) && vap->va_uid != (uid_t)VNOVAL) {
NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
*tl++ = newnfs_true;
*tl = txdr_unsigned(vap->va_uid);
} else {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = newnfs_false;
}
if ((flags & NFSSATTR_FULL) && vap->va_gid != (gid_t)VNOVAL) {
NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
*tl++ = newnfs_true;
*tl = txdr_unsigned(vap->va_gid);
} else {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = newnfs_false;
}
if ((flags & NFSSATTR_FULL) && vap->va_size != VNOVAL) {
NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
*tl++ = newnfs_true;
txdr_hyper(vap->va_size, tl);
} else {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = newnfs_false;
}
if (vap->va_atime.tv_sec != VNOVAL) {
if ((vap->va_vaflags & VA_UTIMES_NULL) == 0) {
NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
*tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);
txdr_nfsv3time(&vap->va_atime, tl);
} else {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER);
}
} else {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE);
}
if (vap->va_mtime.tv_sec != VNOVAL) {
if ((vap->va_vaflags & VA_UTIMES_NULL) == 0) {
NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
*tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);
txdr_nfsv3time(&vap->va_mtime, tl);
} else {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER);
}
} else {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE);
}
break;
case ND_NFSV4:
NFSZERO_ATTRBIT(&attrbits);
if (vap->va_mode != (mode_t)VNOVAL)
NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_MODE);
if ((flags & NFSSATTR_FULL) && vap->va_uid != (uid_t)VNOVAL)
NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_OWNER);
if ((flags & NFSSATTR_FULL) && vap->va_gid != (gid_t)VNOVAL)
NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_OWNERGROUP);
if ((flags & NFSSATTR_FULL) && vap->va_size != VNOVAL)
NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_SIZE);
if (vap->va_atime.tv_sec != VNOVAL)
NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_TIMEACCESSSET);
if (vap->va_mtime.tv_sec != VNOVAL)
NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_TIMEMODIFYSET);
(void) nfsv4_fillattr(nd, vp->v_mount, vp, NULL, vap, NULL, 0,
&attrbits, NULL, NULL, 0, 0, 0, 0, (uint64_t)0, NULL);
break;
}
}
#ifndef APPLE
/*

View File

@ -298,6 +298,11 @@ void nfsrvd_delcache(struct nfsrvcache *);
void nfsrc_trimcache(uint64_t, uint32_t, int);
/* nfs_commonsubs.c */
void nfscl_reqstart(struct nfsrv_descript *, int, struct nfsmount *,
u_int8_t *, int, u_int32_t **, struct nfsclsession *, int, int);
void nfsm_stateidtom(struct nfsrv_descript *, nfsv4stateid_t *, int);
void nfscl_fillsattr(struct nfsrv_descript *, struct vattr *,
vnode_t, int, u_int32_t);
void newnfs_init(void);
int nfsaddr_match(int, union nethostaddr *, NFSSOCKADDR_T);
int nfsaddr2_match(NFSSOCKADDR_T, NFSSOCKADDR_T);
@ -347,11 +352,7 @@ struct nfsdevice *nfsv4_findmirror(struct nfsmount *);
/* nfs_clcomsubs.c */
void nfsm_uiombuf(struct nfsrv_descript *, struct uio *, int);
struct mbuf *nfsm_uiombuflist(struct uio *, int, struct mbuf **, char **);
void nfscl_reqstart(struct nfsrv_descript *, int, struct nfsmount *,
u_int8_t *, int, u_int32_t **, struct nfsclsession *, int, int);
nfsuint64 *nfscl_getcookie(struct nfsnode *, off_t off, int);
void nfscl_fillsattr(struct nfsrv_descript *, struct vattr *,
vnode_t, int, u_int32_t);
u_int8_t *nfscl_getmyip(struct nfsmount *, struct in6_addr *, int *);
int nfsm_getfh(struct nfsrv_descript *, struct nfsfh **);
int nfscl_mtofh(struct nfsrv_descript *, struct nfsfh **,
@ -363,7 +364,6 @@ int nfscl_wcc_data(struct nfsrv_descript *, vnode_t,
int nfsm_loadattr(struct nfsrv_descript *, struct nfsvattr *);
int nfscl_request(struct nfsrv_descript *, vnode_t,
NFSPROC_T *, struct ucred *, void *);
void nfsm_stateidtom(struct nfsrv_descript *, nfsv4stateid_t *, int);
/* nfs_nfsdsubs.c */
void nfsd_fhtovp(struct nfsrv_descript *, struct nfsrvfh *, int,

View File

@ -1054,6 +1054,27 @@ extern const char nfs_vnode_tag[];
*/
#define nfsds_failerr(e) ((e) == ENXIO || (e) == EIO)
/*
* Get a pointer to the MDS session, which is always the first element
* in the list.
* This macro can only be safely used when the NFSLOCKMNT() lock is held.
* The inline function can be used when the lock isn't held.
*/
#define NFSMNT_MDSSESSION(m) (&(TAILQ_FIRST(&((m)->nm_sess))->nfsclds_sess))
static __inline struct nfsclsession *
nfsmnt_mdssession(struct nfsmount *nmp)
{
struct nfsclsession *tsep;
tsep = NULL;
mtx_lock(&nmp->nm_mtx);
if (TAILQ_FIRST(&nmp->nm_sess) != NULL)
tsep = NFSMNT_MDSSESSION(nmp);
mtx_unlock(&nmp->nm_mtx);
return (tsep);
}
#endif /* _KERNEL */
#endif /* _NFS_NFSPORT_H */

View File

@ -49,217 +49,10 @@ extern struct nfsv4_opflag nfsv4_opflag[NFSV41_NOPS];
extern int ncl_mbuf_mlen;
extern enum vtype newnv2tov_type[8];
extern enum vtype nv34tov_type[8];
extern int nfs_bigreply[NFSV41_NPROCS];
NFSCLSTATEMUTEX;
#endif /* !APPLEKEXT */
static nfsuint64 nfs_nullcookie = {{ 0, 0 }};
static struct {
int op;
int opcnt;
const u_char *tag;
int taglen;
} nfsv4_opmap[NFSV41_NPROCS] = {
{ 0, 1, "Null", 4 },
{ NFSV4OP_GETATTR, 1, "Getattr", 7, },
{ NFSV4OP_SETATTR, 2, "Setattr", 7, },
{ NFSV4OP_LOOKUP, 3, "Lookup", 6, },
{ NFSV4OP_ACCESS, 2, "Access", 6, },
{ NFSV4OP_READLINK, 2, "Readlink", 8, },
{ NFSV4OP_READ, 1, "Read", 4, },
{ NFSV4OP_WRITE, 2, "Write", 5, },
{ NFSV4OP_OPEN, 5, "Open", 4, },
{ NFSV4OP_CREATE, 5, "Create", 6, },
{ NFSV4OP_CREATE, 1, "Create", 6, },
{ NFSV4OP_CREATE, 3, "Create", 6, },
{ NFSV4OP_REMOVE, 1, "Remove", 6, },
{ NFSV4OP_REMOVE, 1, "Remove", 6, },
{ NFSV4OP_SAVEFH, 5, "Rename", 6, },
{ NFSV4OP_SAVEFH, 4, "Link", 4, },
{ NFSV4OP_READDIR, 2, "Readdir", 7, },
{ NFSV4OP_READDIR, 2, "Readdir", 7, },
{ NFSV4OP_GETATTR, 1, "Getattr", 7, },
{ NFSV4OP_GETATTR, 1, "Getattr", 7, },
{ NFSV4OP_GETATTR, 1, "Getattr", 7, },
{ NFSV4OP_COMMIT, 2, "Commit", 6, },
{ NFSV4OP_LOOKUPP, 3, "Lookupp", 7, },
{ NFSV4OP_SETCLIENTID, 1, "SetClientID", 11, },
{ NFSV4OP_SETCLIENTIDCFRM, 1, "SetClientIDConfirm", 18, },
{ NFSV4OP_LOCK, 1, "Lock", 4, },
{ NFSV4OP_LOCKU, 1, "LockU", 5, },
{ NFSV4OP_OPEN, 2, "Open", 4, },
{ NFSV4OP_CLOSE, 1, "Close", 5, },
{ NFSV4OP_OPENCONFIRM, 1, "Openconfirm", 11, },
{ NFSV4OP_LOCKT, 1, "LockT", 5, },
{ NFSV4OP_OPENDOWNGRADE, 1, "Opendowngrade", 13, },
{ NFSV4OP_RENEW, 1, "Renew", 5, },
{ NFSV4OP_PUTROOTFH, 1, "Dirpath", 7, },
{ NFSV4OP_RELEASELCKOWN, 1, "Rellckown", 9, },
{ NFSV4OP_DELEGRETURN, 1, "Delegret", 8, },
{ NFSV4OP_DELEGRETURN, 3, "DelegRemove", 11, },
{ NFSV4OP_DELEGRETURN, 7, "DelegRename1", 12, },
{ NFSV4OP_DELEGRETURN, 9, "DelegRename2", 12, },
{ NFSV4OP_GETATTR, 1, "Getacl", 6, },
{ NFSV4OP_SETATTR, 1, "Setacl", 6, },
{ NFSV4OP_EXCHANGEID, 1, "ExchangeID", 10, },
{ NFSV4OP_CREATESESSION, 1, "CreateSession", 13, },
{ NFSV4OP_DESTROYSESSION, 1, "DestroySession", 14, },
{ NFSV4OP_DESTROYCLIENTID, 1, "DestroyClient", 13, },
{ NFSV4OP_FREESTATEID, 1, "FreeStateID", 11, },
{ NFSV4OP_LAYOUTGET, 1, "LayoutGet", 9, },
{ NFSV4OP_GETDEVINFO, 1, "GetDeviceInfo", 13, },
{ NFSV4OP_LAYOUTCOMMIT, 1, "LayoutCommit", 12, },
{ NFSV4OP_LAYOUTRETURN, 1, "LayoutReturn", 12, },
{ NFSV4OP_RECLAIMCOMPL, 1, "ReclaimComplete", 15, },
{ NFSV4OP_WRITE, 1, "WriteDS", 7, },
{ NFSV4OP_READ, 1, "ReadDS", 6, },
{ NFSV4OP_COMMIT, 1, "CommitDS", 8, },
{ NFSV4OP_OPEN, 3, "OpenLayoutGet", 13, },
{ NFSV4OP_OPEN, 8, "CreateLayGet", 12, },
};
/*
* NFS RPCS that have large request message size.
*/
static int nfs_bigrequest[NFSV41_NPROCS] = {
0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0
};
/*
* Start building a request. Mostly just put the first file handle in
* place.
*/
APPLESTATIC void
nfscl_reqstart(struct nfsrv_descript *nd, int procnum, struct nfsmount *nmp,
u_int8_t *nfhp, int fhlen, u_int32_t **opcntpp, struct nfsclsession *sep,
int vers, int minorvers)
{
struct mbuf *mb;
u_int32_t *tl;
int opcnt;
nfsattrbit_t attrbits;
/*
* First, fill in some of the fields of nd.
*/
nd->nd_slotseq = NULL;
if (vers == NFS_VER4) {
nd->nd_flag = ND_NFSV4 | ND_NFSCL;
if (minorvers == NFSV41_MINORVERSION)
nd->nd_flag |= ND_NFSV41;
} else if (vers == NFS_VER3)
nd->nd_flag = ND_NFSV3 | ND_NFSCL;
else {
if (NFSHASNFSV4(nmp)) {
nd->nd_flag = ND_NFSV4 | ND_NFSCL;
if (NFSHASNFSV4N(nmp))
nd->nd_flag |= ND_NFSV41;
} else if (NFSHASNFSV3(nmp))
nd->nd_flag = ND_NFSV3 | ND_NFSCL;
else
nd->nd_flag = ND_NFSV2 | ND_NFSCL;
}
nd->nd_procnum = procnum;
nd->nd_repstat = 0;
/*
* Get the first mbuf for the request.
*/
if (nfs_bigrequest[procnum])
NFSMCLGET(mb, M_WAITOK);
else
NFSMGET(mb);
mbuf_setlen(mb, 0);
nd->nd_mreq = nd->nd_mb = mb;
nd->nd_bpos = NFSMTOD(mb, caddr_t);
/*
* And fill the first file handle into the request.
*/
if (nd->nd_flag & ND_NFSV4) {
opcnt = nfsv4_opmap[procnum].opcnt +
nfsv4_opflag[nfsv4_opmap[procnum].op].needscfh;
if ((nd->nd_flag & ND_NFSV41) != 0) {
opcnt += nfsv4_opflag[nfsv4_opmap[procnum].op].needsseq;
if (procnum == NFSPROC_RENEW)
/*
* For the special case of Renew, just do a
* Sequence Op.
*/
opcnt = 1;
else if (procnum == NFSPROC_WRITEDS ||
procnum == NFSPROC_COMMITDS)
/*
* For the special case of a Writeor Commit to
* a DS, the opcnt == 3, for Sequence, PutFH,
* Write/Commit.
*/
opcnt = 3;
}
/*
* What should the tag really be?
*/
(void) nfsm_strtom(nd, nfsv4_opmap[procnum].tag,
nfsv4_opmap[procnum].taglen);
NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
if ((nd->nd_flag & ND_NFSV41) != 0)
*tl++ = txdr_unsigned(NFSV41_MINORVERSION);
else
*tl++ = txdr_unsigned(NFSV4_MINORVERSION);
if (opcntpp != NULL)
*opcntpp = tl;
*tl = txdr_unsigned(opcnt);
if ((nd->nd_flag & ND_NFSV41) != 0 &&
nfsv4_opflag[nfsv4_opmap[procnum].op].needsseq > 0) {
if (nfsv4_opflag[nfsv4_opmap[procnum].op].loopbadsess >
0)
nd->nd_flag |= ND_LOOPBADSESS;
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = txdr_unsigned(NFSV4OP_SEQUENCE);
if (sep == NULL) {
sep = nfsmnt_mdssession(nmp);
nfsv4_setsequence(nmp, nd, sep,
nfs_bigreply[procnum]);
} else
nfsv4_setsequence(nmp, nd, sep,
nfs_bigreply[procnum]);
}
if (nfsv4_opflag[nfsv4_opmap[procnum].op].needscfh > 0) {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = txdr_unsigned(NFSV4OP_PUTFH);
(void) nfsm_fhtom(nd, nfhp, fhlen, 0);
if (nfsv4_opflag[nfsv4_opmap[procnum].op].needscfh
== 2 && procnum != NFSPROC_WRITEDS &&
procnum != NFSPROC_COMMITDS) {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = txdr_unsigned(NFSV4OP_GETATTR);
/*
* For Lookup Ops, we want all the directory
* attributes, so we can load the name cache.
*/
if (procnum == NFSPROC_LOOKUP ||
procnum == NFSPROC_LOOKUPP)
NFSGETATTR_ATTRBIT(&attrbits);
else {
NFSWCCATTR_ATTRBIT(&attrbits);
nd->nd_flag |= ND_V4WCCATTR;
}
(void) nfsrv_putattrbit(nd, &attrbits);
}
}
if (procnum != NFSPROC_RENEW ||
(nd->nd_flag & ND_NFSV41) == 0) {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = txdr_unsigned(nfsv4_opmap[procnum].op);
}
} else {
(void) nfsm_fhtom(nd, nfhp, fhlen, 0);
}
if (procnum < NFSV41_NPROCS)
NFSINCRGLOBAL(nfsstatsv1.rpccnt[procnum]);
}
/*
* copies a uio scatter/gather list to an mbuf chain.
@ -594,38 +387,6 @@ nfscl_mtofh(struct nfsrv_descript *nd, struct nfsfh **nfhpp,
return (error);
}
/*
* Put a state Id in the mbuf list.
*/
APPLESTATIC void
nfsm_stateidtom(struct nfsrv_descript *nd, nfsv4stateid_t *stateidp, int flag)
{
nfsv4stateid_t *st;
NFSM_BUILD(st, nfsv4stateid_t *, NFSX_STATEID);
if (flag == NFSSTATEID_PUTALLZERO) {
st->seqid = 0;
st->other[0] = 0;
st->other[1] = 0;
st->other[2] = 0;
} else if (flag == NFSSTATEID_PUTALLONE) {
st->seqid = 0xffffffff;
st->other[0] = 0xffffffff;
st->other[1] = 0xffffffff;
st->other[2] = 0xffffffff;
} else if (flag == NFSSTATEID_PUTSEQIDZERO) {
st->seqid = 0;
st->other[0] = stateidp->other[0];
st->other[1] = stateidp->other[1];
st->other[2] = stateidp->other[2];
} else {
st->seqid = stateidp->seqid;
st->other[0] = stateidp->other[0];
st->other[1] = stateidp->other[1];
st->other[2] = stateidp->other[2];
}
}
/*
* Initialize the owner/delegation sleep lock.
*/

View File

@ -818,124 +818,6 @@ nfscl_postop_attr(struct nfsrv_descript *nd, struct nfsvattr *nap, int *retp,
return (error);
}
/*
* Fill in the setable attributes. The full argument indicates whether
* to fill in them all or just mode and time.
*/
void
nfscl_fillsattr(struct nfsrv_descript *nd, struct vattr *vap,
struct vnode *vp, int flags, u_int32_t rdev)
{
u_int32_t *tl;
struct nfsv2_sattr *sp;
nfsattrbit_t attrbits;
switch (nd->nd_flag & (ND_NFSV2 | ND_NFSV3 | ND_NFSV4)) {
case ND_NFSV2:
NFSM_BUILD(sp, struct nfsv2_sattr *, NFSX_V2SATTR);
if (vap->va_mode == (mode_t)VNOVAL)
sp->sa_mode = newnfs_xdrneg1;
else
sp->sa_mode = vtonfsv2_mode(vap->va_type, vap->va_mode);
if (vap->va_uid == (uid_t)VNOVAL)
sp->sa_uid = newnfs_xdrneg1;
else
sp->sa_uid = txdr_unsigned(vap->va_uid);
if (vap->va_gid == (gid_t)VNOVAL)
sp->sa_gid = newnfs_xdrneg1;
else
sp->sa_gid = txdr_unsigned(vap->va_gid);
if (flags & NFSSATTR_SIZE0)
sp->sa_size = 0;
else if (flags & NFSSATTR_SIZENEG1)
sp->sa_size = newnfs_xdrneg1;
else if (flags & NFSSATTR_SIZERDEV)
sp->sa_size = txdr_unsigned(rdev);
else
sp->sa_size = txdr_unsigned(vap->va_size);
txdr_nfsv2time(&vap->va_atime, &sp->sa_atime);
txdr_nfsv2time(&vap->va_mtime, &sp->sa_mtime);
break;
case ND_NFSV3:
if (vap->va_mode != (mode_t)VNOVAL) {
NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
*tl++ = newnfs_true;
*tl = txdr_unsigned(vap->va_mode);
} else {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = newnfs_false;
}
if ((flags & NFSSATTR_FULL) && vap->va_uid != (uid_t)VNOVAL) {
NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
*tl++ = newnfs_true;
*tl = txdr_unsigned(vap->va_uid);
} else {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = newnfs_false;
}
if ((flags & NFSSATTR_FULL) && vap->va_gid != (gid_t)VNOVAL) {
NFSM_BUILD(tl, u_int32_t *, 2 * NFSX_UNSIGNED);
*tl++ = newnfs_true;
*tl = txdr_unsigned(vap->va_gid);
} else {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = newnfs_false;
}
if ((flags & NFSSATTR_FULL) && vap->va_size != VNOVAL) {
NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
*tl++ = newnfs_true;
txdr_hyper(vap->va_size, tl);
} else {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = newnfs_false;
}
if (vap->va_atime.tv_sec != VNOVAL) {
if ((vap->va_vaflags & VA_UTIMES_NULL) == 0) {
NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
*tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);
txdr_nfsv3time(&vap->va_atime, tl);
} else {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER);
}
} else {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE);
}
if (vap->va_mtime.tv_sec != VNOVAL) {
if ((vap->va_vaflags & VA_UTIMES_NULL) == 0) {
NFSM_BUILD(tl, u_int32_t *, 3 * NFSX_UNSIGNED);
*tl++ = txdr_unsigned(NFSV3SATTRTIME_TOCLIENT);
txdr_nfsv3time(&vap->va_mtime, tl);
} else {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = txdr_unsigned(NFSV3SATTRTIME_TOSERVER);
}
} else {
NFSM_BUILD(tl, u_int32_t *, NFSX_UNSIGNED);
*tl = txdr_unsigned(NFSV3SATTRTIME_DONTCHANGE);
}
break;
case ND_NFSV4:
NFSZERO_ATTRBIT(&attrbits);
if (vap->va_mode != (mode_t)VNOVAL)
NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_MODE);
if ((flags & NFSSATTR_FULL) && vap->va_uid != (uid_t)VNOVAL)
NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_OWNER);
if ((flags & NFSSATTR_FULL) && vap->va_gid != (gid_t)VNOVAL)
NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_OWNERGROUP);
if ((flags & NFSSATTR_FULL) && vap->va_size != VNOVAL)
NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_SIZE);
if (vap->va_atime.tv_sec != VNOVAL)
NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_TIMEACCESSSET);
if (vap->va_mtime.tv_sec != VNOVAL)
NFSSETBIT_ATTRBIT(&attrbits, NFSATTRBIT_TIMEMODIFYSET);
(void) nfsv4_fillattr(nd, vp->v_mount, vp, NULL, vap, NULL, 0,
&attrbits, NULL, NULL, 0, 0, 0, 0, (uint64_t)0, NULL);
break;
}
}
/*
* nfscl_request() - mostly a wrapper for newnfs_request().
*/

View File

@ -116,27 +116,6 @@ struct nfsmount {
*/
#define VFSTONFS(mp) ((struct nfsmount *)((mp)->mnt_data))
/*
* Get a pointer to the MDS session, which is always the first element
* in the list.
* This macro can only be safely used when the NFSLOCKMNT() lock is held.
* The inline function can be used when the lock isn't held.
*/
#define NFSMNT_MDSSESSION(m) (&(TAILQ_FIRST(&((m)->nm_sess))->nfsclds_sess))
static __inline struct nfsclsession *
nfsmnt_mdssession(struct nfsmount *nmp)
{
struct nfsclsession *tsep;
tsep = NULL;
mtx_lock(&nmp->nm_mtx);
if (TAILQ_FIRST(&nmp->nm_sess) != NULL)
tsep = NFSMNT_MDSSESSION(nmp);
mtx_unlock(&nmp->nm_mtx);
return (tsep);
}
#ifndef NFS_DEFAULT_NAMETIMEO
#define NFS_DEFAULT_NAMETIMEO 60
#endif