NFS write gathering defers execution of NFS server write requests to wait

to see if additional write requests will arrive that can be coalesced and
clustered with earlier ones.  When doing so, it must determine whether
the two requests are made by credentials with the same access writes, so
as not to coalesce improperly.  NFSW_SAMECRED() implements a test of two
credentials using a binary compare.

Replace NFSW_SAMECRED() macro with nfsrv_samecred() function, which is
aware of the contents and layout of a struct ucred, rather than a simple
binary compare.  While the binary compare works when ucred is simply a
zero'd and embedded 'struct ucred' in the NFS descriptor, it will work
less well when the ucred associated with an NFS descriptor is "real", so
has defined and populated reference count, mutex, etc.

MFC after:	1 week
Obtained from:	TrustedBSD Project
This commit is contained in:
Robert Watson 2005-04-17 16:25:36 +00:00
parent c632f6dbda
commit ad77d81512
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=145197
2 changed files with 23 additions and 5 deletions

View File

@ -275,10 +275,6 @@ extern int nfsd_head_flag;
((o)->nd_eoff >= (n)->nd_off && \
!bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, NFSX_V3FH))
#define NFSW_SAMECRED(o, n) \
(!bcmp((caddr_t)&(o)->nd_cr, (caddr_t)&(n)->nd_cr, \
sizeof (struct ucred)))
/*
* Defines for WebNFS
*/

View File

@ -1300,6 +1300,28 @@ nfsrv_write(struct nfsrv_descript *nfsd, struct nfssvc_sock *slp,
return(error);
}
/*
* For the purposes of write gathering, we must decide if the credential
* associated with two pending requests have equivilent privileges. Since
* NFS only uses a subset of the BSD ucred -- the effective uid and group
* IDs -- we have a compare routine that checks only the relevant fields.
*/
static int
nfsrv_samecred(struct ucred *cr1, struct ucred *cr2)
{
int i;
if (cr1->cr_uid != cr2->cr_uid)
return (0);
if (cr1->cr_ngroups != cr2->cr_ngroups)
return (0);
for (i = 0; i < cr1->cr_ngroups; i++) {
if (cr1->cr_groups[i] != cr2->cr_groups[i])
return (0);
}
return (1);
}
/*
* NFS write service with write gathering support. Called when
* nfsrvw_procrastinate > 0.
@ -1451,7 +1473,7 @@ nfsrv_writegather(struct nfsrv_descript **ndp, struct nfssvc_sock *slp,
*/
for(; nfsd && NFSW_CONTIG(owp, nfsd); nfsd = wp) {
wp = LIST_NEXT(nfsd, nd_hash);
if (NFSW_SAMECRED(owp, nfsd))
if (nfsrv_samecred(&owp->nd_cr, &nfsd->nd_cr))
nfsrvw_coalesce(owp, nfsd);
}
} else {