Convert some more lists and queues.

This commit is contained in:
mycroft 1994-08-17 14:43:47 +00:00
parent 7b8734f3e8
commit 8743009944
5 changed files with 102 additions and 120 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfs.h,v 1.5 1994/08/17 11:41:36 mycroft Exp $ */
/* $NetBSD: nfs.h,v 1.6 1994/08/17 14:43:47 mycroft Exp $ */
/*
* Copyright (c) 1989, 1993
@ -214,7 +214,8 @@ struct nfsstats nfsstats;
* and uid hash lists.
*/
#define NUIDHASHSIZ 32
#define NUIDHASH(uid) ((uid) & (NUIDHASHSIZ - 1))
#define NUIDHASH(sock, uid) \
(&(sock)->ns_uidhashtbl[(uid) & (sock)->ns_uidhash])
/*
* Network address hash list element
@ -225,10 +226,8 @@ union nethostaddr {
};
struct nfsuid {
struct nfsuid *nu_lrunext; /* MUST be first */
struct nfsuid *nu_lruprev;
struct nfsuid *nu_hnext;
struct nfsuid *nu_hprev;
TAILQ_ENTRY(nfsuid) nu_lru; /* LRU chain */
LIST_ENTRY(nfsuid) nu_hash; /* Hash list */
int nu_flag; /* Flags */
uid_t nu_uid; /* Uid mapped by this entry */
union nethostaddr nu_haddr; /* Host addr. for dgram sockets */
@ -241,10 +240,11 @@ struct nfsuid {
#define NU_INETADDR 0x1
struct nfssvc_sock {
struct nfsuid *ns_lrunext; /* MUST be first */
struct nfsuid *ns_lruprev;
struct nfssvc_sock *ns_next;
struct nfssvc_sock *ns_prev;
TAILQ_ENTRY(nfssvc_sock) ns_chain; /* List of all nfssvc_sock's */
TAILQ_HEAD(nfsuidlru, nfsuid) ns_uidlruhead;
LIST_HEAD(nfsuidhash, nfsuid) *ns_uidhashtbl;
u_long ns_uidhash;
int ns_flag;
u_long ns_sref;
struct file *ns_fp;
@ -258,7 +258,6 @@ struct nfssvc_sock {
struct mbuf *ns_rec;
struct mbuf *ns_recend;
int ns_numuids;
struct nfsuid *ns_uidh[NUIDHASHSIZ];
};
/* Bits for "ns_flag" */
@ -267,17 +266,18 @@ struct nfssvc_sock {
#define SLP_NEEDQ 0x04
#define SLP_DISCONN 0x08
#define SLP_GETSTREAM 0x10
#define SLP_INIT 0x20
#define SLP_WANTINIT 0x40
#define SLP_ALLFLAGS 0xff
TAILQ_HEAD(nfssvc_socks, nfssvc_sock) nfssvc_sockhead;
int nfssvc_sockhead_flag;
#define SLP_INIT 0x01
#define SLP_WANTINIT 0x02
/*
* One of these structures is allocated for each nfsd.
*/
struct nfsd {
struct nfsd *nd_next; /* Must be first */
struct nfsd *nd_prev;
TAILQ_ENTRY(nfsd) nd_chain; /* List of all nfsd's */
int nd_flag; /* NFSD_ flags */
struct nfssvc_sock *nd_slp; /* Current socket */
struct mbuf *nd_nam; /* Client addr for datagram req. */
@ -295,9 +295,14 @@ struct nfsd {
struct proc *nd_procp; /* Proc ptr */
};
/* Bits for "nd_flag" */
#define NFSD_WAITING 0x01
#define NFSD_CHECKSLP 0x02
#define NFSD_REQINPROG 0x04
#define NFSD_NEEDAUTH 0x08
#define NFSD_AUTHFAIL 0x10
#define NFSD_REQINPROG 0x02
#define NFSD_NEEDAUTH 0x04
#define NFSD_AUTHFAIL 0x08
TAILQ_HEAD(nfsds, nfsd) nfsd_head;
int nfsd_head_flag;
#define NFSD_CHECKSLP 0x01
#endif /* KERNEL */

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfs_nqlease.c,v 1.3 1994/08/17 11:41:39 mycroft Exp $ */
/* $NetBSD: nfs_nqlease.c,v 1.4 1994/08/17 14:43:49 mycroft Exp $ */
/*
* Copyright (c) 1992, 1993
@ -129,7 +129,6 @@ int nnnnnn = sizeof (struct nqlease);
int oooooo = sizeof (struct nfsnode);
extern nfstype nfs_type[9];
extern struct nfssvc_sock *nfs_udpsock, *nfs_cltpsock;
extern struct nfsd nfsd_head;
extern int nfsd_waiting;
#define TRUE 1

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfs_socket.c,v 1.16 1994/08/17 11:41:42 mycroft Exp $ */
/* $NetBSD: nfs_socket.c,v 1.17 1994/08/17 14:43:51 mycroft Exp $ */
/*
* Copyright (c) 1989, 1991, 1993
@ -159,7 +159,6 @@ void nfs_rcvunlock(), nqnfs_serverd(), nqnfs_clientlease();
struct mbuf *nfsm_rpchead();
int nfsrtton = 0;
struct nfsrtt nfsrtt;
struct nfsd nfsd_head;
/*
* Initialize sockets and congestion for a new NFS connection.
@ -1966,11 +1965,11 @@ void
nfsrv_wakenfsd(slp)
struct nfssvc_sock *slp;
{
register struct nfsd *nd = nfsd_head.nd_next;
register struct nfsd *nd;
if ((slp->ns_flag & SLP_VALID) == 0)
return;
while (nd != (struct nfsd *)&nfsd_head) {
for (nd = nfsd_head.tqh_first; nd != 0; nd = nd->nd_chain.tqe_next) {
if (nd->nd_flag & NFSD_WAITING) {
nd->nd_flag &= ~NFSD_WAITING;
if (nd->nd_slp)
@ -1980,9 +1979,8 @@ nfsrv_wakenfsd(slp)
wakeup((caddr_t)nd);
return;
}
nd = nd->nd_next;
}
slp->ns_flag |= SLP_DOREC;
nfsd_head.nd_flag |= NFSD_CHECKSLP;
nfsd_head_flag |= NFSD_CHECKSLP;
}
#endif /* NFSSERVER */

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfs_subs.c,v 1.16 1994/08/17 11:41:44 mycroft Exp $ */
/* $NetBSD: nfs_subs.c,v 1.17 1994/08/17 14:43:53 mycroft Exp $ */
/*
* Copyright (c) 1989, 1993
@ -1065,21 +1065,19 @@ nfsrv_fhtovp(fhp, lockflag, vpp, cred, slp, nam, rdonlyp)
* Check/setup credentials.
*/
if (exflags & MNT_EXKERB) {
uidp = slp->ns_uidh[NUIDHASH(cred->cr_uid)];
while (uidp) {
for (uidp = NUIDHASH(slp, cred->cr_uid)->lh_first; uidp != 0;
uidp = uidp->nu_hash.le_next) {
if (uidp->nu_uid == cred->cr_uid)
break;
uidp = uidp->nu_hnext;
}
if (uidp) {
cred->cr_uid = uidp->nu_cr.cr_uid;
for (i = 0; i < uidp->nu_cr.cr_ngroups; i++)
cred->cr_groups[i] = uidp->nu_cr.cr_groups[i];
cred->cr_ngroups = i;
} else {
if (uidp == 0) {
vput(*vpp);
return (NQNFS_AUTHERR);
}
cred->cr_uid = uidp->nu_cr.cr_uid;
for (i = 0; i < uidp->nu_cr.cr_ngroups; i++)
cred->cr_groups[i] = uidp->nu_cr.cr_groups[i];
cred->cr_ngroups = i;
} else if (cred->cr_uid == 0 || (exflags & MNT_EXPORTANON)) {
cred->cr_uid = credanon->cr_uid;
for (i = 0; i < credanon->cr_ngroups && i < NGROUPS; i++)

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfs_syscalls.c,v 1.11 1994/06/29 06:42:24 cgd Exp $ */
/* $NetBSD: nfs_syscalls.c,v 1.12 1994/08/17 14:43:56 mycroft Exp $ */
/*
* Copyright (c) 1989, 1993
@ -77,8 +77,6 @@ extern int (*nfsrv_procs[NFS_NPROCS])();
extern struct proc *nfs_iodwant[NFS_MAXASYNCDAEMON];
extern int nfs_numasync;
extern time_t nqnfsstarttime;
extern struct nfsrv_req nsrvq_head;
extern struct nfsd nfsd_head;
extern int nqsrv_writeslack;
extern int nfsrtton;
struct nfssvc_sock *nfs_udpsock, *nfs_cltpsock;
@ -137,8 +135,6 @@ getfh(p, uap, retval)
return (error);
}
static struct nfssvc_sock nfssvc_sockhead;
/*
* Nfs server psuedo system call for the nfsd's
* Based on the flag value it either:
@ -172,8 +168,8 @@ nfssvc(p, uap, retval)
*/
if (error = suser(p->p_ucred, &p->p_acflag))
return (error);
while (nfssvc_sockhead.ns_flag & SLP_INIT) {
nfssvc_sockhead.ns_flag |= SLP_WANTINIT;
while (nfssvc_sockhead_flag & SLP_INIT) {
nfssvc_sockhead_flag |= SLP_WANTINIT;
(void) tsleep((caddr_t)&nfssvc_sockhead, PSOCK, "nfsd init", 0);
}
if (uap->flag & NFSSVC_BIOD) {
@ -238,13 +234,12 @@ nfssvc(p, uap, retval)
* First check to see if another nfsd has already
* added this credential.
*/
nuidp = slp->ns_uidh[NUIDHASH(nsd->nsd_uid)];
while (nuidp) {
for (nuidp = NUIDHASH(slp, nsd->nsd_uid)->lh_first;
nuidp != 0; nuidp = nuidp->nu_hash.le_next) {
if (nuidp->nu_uid == nsd->nsd_uid)
break;
nuidp = nuidp->nu_hnext;
}
if (!nuidp) {
if (nuidp == 0) {
/*
* Nope, so we will.
*/
@ -260,26 +255,20 @@ nfssvc(p, uap, retval)
free((caddr_t)nuidp, M_NFSUID);
} else {
if (nuidp == (struct nfsuid *)0) {
nuidp = slp->ns_lruprev;
remque(nuidp);
if (nuidp->nu_hprev)
nuidp->nu_hprev->nu_hnext =
nuidp->nu_hnext;
if (nuidp->nu_hnext)
nuidp->nu_hnext->nu_hprev =
nuidp->nu_hprev;
nuidp = slp->ns_uidlruhead.tqh_first;
LIST_REMOVE(nuidp, nu_hash);
TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp,
nu_lru);
}
nuidp->nu_cr = nsd->nsd_cr;
if (nuidp->nu_cr.cr_ngroups > NGROUPS)
nuidp->nu_cr.cr_ngroups = NGROUPS;
nuidp->nu_cr.cr_ref = 1;
nuidp->nu_uid = nsd->nsd_uid;
insque(nuidp, (struct nfsuid *)slp);
nuh = &slp->ns_uidh[NUIDHASH(nsd->nsd_uid)];
if (nuidp->nu_hnext = *nuh)
nuidp->nu_hnext->nu_hprev = nuidp;
nuidp->nu_hprev = (struct nfsuid *)0;
*nuh = nuidp;
TAILQ_INSERT_TAIL(&slp->ns_uidlruhead, nuidp,
nu_lru);
LIST_INSERT_HEAD(NUIDHASH(slp, nsd->nsd_uid),
nuidp, nu_hash);
}
}
}
@ -365,11 +354,10 @@ nfssvc_addsock(fp, mynam)
slp = (struct nfssvc_sock *)
malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK);
bzero((caddr_t)slp, sizeof (struct nfssvc_sock));
slp->ns_prev = nfssvc_sockhead.ns_prev;
slp->ns_prev->ns_next = slp;
slp->ns_next = &nfssvc_sockhead;
nfssvc_sockhead.ns_prev = slp;
slp->ns_lrunext = slp->ns_lruprev = (struct nfsuid *)slp;
slp->ns_uidhashtbl =
hashinit(NUIDHASHSIZ, M_NFSSVC, &slp->ns_uidhash);
TAILQ_INIT(&slp->ns_uidlruhead);
TAILQ_INSERT_TAIL(&nfssvc_sockhead, slp, ns_chain);
}
slp->ns_so = so;
slp->ns_nam = mynam;
@ -412,7 +400,7 @@ nfssvc_nfsd(nsd, argp, p)
bzero((caddr_t)nd, sizeof (struct nfsd));
nd->nd_procp = p;
nd->nd_cr.cr_ref = 1;
insque(nd, &nfsd_head);
TAILQ_INSERT_TAIL(&nfsd_head, nd, nd_chain);
nd->nd_nqlflag = NQL_NOVAL;
nfs_numnfsd++;
}
@ -422,7 +410,7 @@ nfssvc_nfsd(nsd, argp, p)
for (;;) {
if ((nd->nd_flag & NFSD_REQINPROG) == 0) {
while (nd->nd_slp == (struct nfssvc_sock *)0 &&
(nfsd_head.nd_flag & NFSD_CHECKSLP) == 0) {
(nfsd_head_flag & NFSD_CHECKSLP) == 0) {
nd->nd_flag |= NFSD_WAITING;
nfsd_waiting++;
error = tsleep((caddr_t)nd, PSOCK | PCATCH, "nfsd", 0);
@ -431,9 +419,9 @@ nfssvc_nfsd(nsd, argp, p)
goto done;
}
if (nd->nd_slp == (struct nfssvc_sock *)0 &&
(nfsd_head.nd_flag & NFSD_CHECKSLP)) {
slp = nfssvc_sockhead.ns_next;
while (slp != &nfssvc_sockhead) {
(nfsd_head_flag & NFSD_CHECKSLP) != 0) {
for (slp = nfssvc_sockhead.tqh_first; slp != 0;
slp = slp->ns_chain.tqe_next) {
if ((slp->ns_flag & (SLP_VALID | SLP_DOREC))
== (SLP_VALID | SLP_DOREC)) {
slp->ns_flag &= ~SLP_DOREC;
@ -441,10 +429,9 @@ nfssvc_nfsd(nsd, argp, p)
nd->nd_slp = slp;
break;
}
slp = slp->ns_next;
}
if (slp == &nfssvc_sockhead)
nfsd_head.nd_flag &= ~NFSD_CHECKSLP;
if (slp == 0)
nfsd_head_flag &= ~NFSD_CHECKSLP;
}
if ((slp = nd->nd_slp) == (struct nfssvc_sock *)0)
continue;
@ -503,13 +490,12 @@ nfssvc_nfsd(nsd, argp, p)
/*
* Check for a mapping already installed.
*/
uidp = slp->ns_uidh[NUIDHASH(nd->nd_cr.cr_uid)];
while (uidp) {
for (uidp = NUIDHASH(slp, nd->nd_cr.cr_uid)->lh_first;
uidp != 0; uidp = uidp->nu_hash.le_next) {
if (uidp->nu_uid == nd->nd_cr.cr_uid)
break;
uidp = uidp->nu_hnext;
}
if (!uidp) {
if (uidp == 0) {
nsd->nsd_uid = nd->nd_cr.cr_uid;
if (nam2 && logauth++ == 0)
log(LOG_WARNING, "Kerberized NFS using UDP\n");
@ -636,7 +622,7 @@ nfssvc_nfsd(nsd, argp, p)
}
}
done:
remque(nd);
TAILQ_REMOVE(&nfsd_head, nd, nd_chain);
splx(s);
free((caddr_t)nd, M_NFSD);
nsd->nsd_nfsd = (struct nfsd *)0;
@ -655,7 +641,7 @@ done:
nfsrv_zapsock(slp)
register struct nfssvc_sock *slp;
{
register struct nfsuid *nuidp, *onuidp;
register struct nfsuid *nuidp, *nnuidp;
register int i;
struct socket *so;
struct file *fp;
@ -672,15 +658,13 @@ nfsrv_zapsock(slp)
MFREE(slp->ns_nam, m);
m_freem(slp->ns_raw);
m_freem(slp->ns_rec);
nuidp = slp->ns_lrunext;
while (nuidp != (struct nfsuid *)slp) {
onuidp = nuidp;
nuidp = nuidp->nu_lrunext;
free((caddr_t)onuidp, M_NFSUID);
for (nuidp = slp->ns_uidlruhead.tqh_first; nuidp != 0;
nuidp = nnuidp) {
nnuidp = nuidp->nu_lru.tqe_next;
LIST_REMOVE(nuidp, nu_hash);
TAILQ_REMOVE(&slp->ns_uidlruhead, nuidp, nu_lru);
free((caddr_t)nuidp, M_NFSUID);
}
slp->ns_lrunext = slp->ns_lruprev = (struct nfsuid *)slp;
for (i = 0; i < NUIDHASHSIZ; i++)
slp->ns_uidh[i] = (struct nfsuid *)0;
}
}
@ -693,8 +677,7 @@ nfsrv_slpderef(slp)
register struct nfssvc_sock *slp;
{
if (--(slp->ns_sref) == 0 && (slp->ns_flag & SLP_VALID) == 0) {
slp->ns_prev->ns_next = slp->ns_next;
slp->ns_next->ns_prev = slp->ns_prev;
TAILQ_REMOVE(&nfssvc_sockhead, slp, ns_chain);
free((caddr_t)slp, M_NFSSVC);
}
}
@ -708,48 +691,47 @@ void
nfsrv_init(terminating)
int terminating;
{
register struct nfssvc_sock *slp;
struct nfssvc_sock *oslp;
register struct nfssvc_sock *slp, *nslp;
if (nfssvc_sockhead.ns_flag & SLP_INIT)
if (nfssvc_sockhead_flag & SLP_INIT)
panic("nfsd init");
nfssvc_sockhead.ns_flag |= SLP_INIT;
nfssvc_sockhead_flag |= SLP_INIT;
if (terminating) {
slp = nfssvc_sockhead.ns_next;
while (slp != &nfssvc_sockhead) {
for (slp = nfssvc_sockhead.tqh_first; slp != 0; slp = nslp) {
nslp = slp->ns_chain.tqe_next;
if (slp->ns_flag & SLP_VALID)
nfsrv_zapsock(slp);
slp->ns_next->ns_prev = slp->ns_prev;
slp->ns_prev->ns_next = slp->ns_next;
oslp = slp;
slp = slp->ns_next;
free((caddr_t)oslp, M_NFSSVC);
TAILQ_REMOVE(&nfssvc_sockhead, slp, ns_chain);
free((caddr_t)slp, M_NFSSVC);
}
nfsrv_cleancache(); /* And clear out server cache */
}
TAILQ_INIT(&nfssvc_sockhead);
nfssvc_sockhead_flag &= ~SLP_INIT;
if (nfssvc_sockhead_flag & SLP_WANTINIT) {
nfssvc_sockhead_flag &= ~SLP_WANTINIT;
wakeup((caddr_t)&nfssvc_sockhead);
}
TAILQ_INIT(&nfsd_head);
nfsd_head_flag &= ~NFSD_CHECKSLP;
nfs_udpsock = (struct nfssvc_sock *)
malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK);
bzero((caddr_t)nfs_udpsock, sizeof (struct nfssvc_sock));
nfs_udpsock->ns_uidhashtbl =
hashinit(NUIDHASHSIZ, M_NFSSVC, &nfs_udpsock->ns_uidhash);
TAILQ_INIT(&nfs_udpsock->ns_uidlruhead);
TAILQ_INSERT_HEAD(&nfssvc_sockhead, nfs_udpsock, ns_chain);
nfs_cltpsock = (struct nfssvc_sock *)
malloc(sizeof (struct nfssvc_sock), M_NFSSVC, M_WAITOK);
bzero((caddr_t)nfs_cltpsock, sizeof (struct nfssvc_sock));
nfssvc_sockhead.ns_next = nfs_udpsock;
nfs_udpsock->ns_next = nfs_cltpsock;
nfs_cltpsock->ns_next = &nfssvc_sockhead;
nfssvc_sockhead.ns_prev = nfs_cltpsock;
nfs_cltpsock->ns_prev = nfs_udpsock;
nfs_udpsock->ns_prev = &nfssvc_sockhead;
nfs_udpsock->ns_lrunext = nfs_udpsock->ns_lruprev =
(struct nfsuid *)nfs_udpsock;
nfs_cltpsock->ns_lrunext = nfs_cltpsock->ns_lruprev =
(struct nfsuid *)nfs_cltpsock;
nfsd_head.nd_next = nfsd_head.nd_prev = &nfsd_head;
nfsd_head.nd_flag = 0;
nfssvc_sockhead.ns_flag &= ~SLP_INIT;
if (nfssvc_sockhead.ns_flag & SLP_WANTINIT) {
nfssvc_sockhead.ns_flag &= ~SLP_WANTINIT;
wakeup((caddr_t)&nfssvc_sockhead);
}
nfs_cltpsock->ns_uidhashtbl =
hashinit(NUIDHASHSIZ, M_NFSSVC, &nfs_cltpsock->ns_uidhash);
TAILQ_INIT(&nfs_cltpsock->ns_uidlruhead);
TAILQ_INSERT_TAIL(&nfssvc_sockhead, nfs_cltpsock, ns_chain);
}
/*