NFS - Remove old nfsiod, start adding new kernel thread infrastructure
[dragonfly.git] / sys / vfs / nfs / nfs_iod.c
blob7ec8ea5f7ecc727cec603f6128533b86a667d22a
1 /*
2 * Copyright (c) 2009 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
35 * NFSIOD operations - now built into the kernel.
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/proc.h>
40 #include <sys/malloc.h>
41 #include <sys/mount.h>
42 #include <sys/kernel.h>
43 #include <sys/mbuf.h>
44 #include <sys/vnode.h>
45 #include <sys/fcntl.h>
46 #include <sys/protosw.h>
47 #include <sys/resourcevar.h>
48 #include <sys/socket.h>
49 #include <sys/socketvar.h>
50 #include <sys/socketops.h>
51 #include <sys/syslog.h>
52 #include <sys/thread.h>
53 #include <sys/tprintf.h>
54 #include <sys/sysctl.h>
55 #include <sys/signalvar.h>
56 #include <sys/mutex.h>
58 #include <sys/signal2.h>
59 #include <sys/mutex2.h>
61 #include <netinet/in.h>
62 #include <netinet/tcp.h>
63 #include <sys/thread2.h>
65 #include "rpcv2.h"
66 #include "nfsproto.h"
67 #include "nfs.h"
68 #include "xdr_subs.h"
69 #include "nfsm_subs.h"
70 #include "nfsmount.h"
71 #include "nfsnode.h"
72 #include "nfsrtt.h"
74 void
75 nfssvc_iod_reader(void *arg)
77 struct nfsmount *nmp = arg;
79 if (nmp->nm_rxstate == NFSSVC_INIT)
80 nmp->nm_rxstate = NFSSVC_PENDING;
81 for (;;) {
82 if (nmp->nm_rxstate == NFSSVC_WAITING) {
83 tsleep(&nmp->nm_rxstate, 0, "nfsidl", 0);
84 continue;
86 if (nmp->nm_rxstate != NFSSVC_PENDING)
87 break;
88 nmp->nm_rxstate = NFSSVC_WAITING;
90 #if 0
91 error = tsleep((caddr_t)&nfs_iodwant[myiod],
92 PCATCH, "nfsidl", 0);
93 #endif
95 nmp->nm_rxthread = NULL;
96 nmp->nm_rxstate = NFSSVC_DONE;
97 wakeup(&nmp->nm_rxthread);
101 * The writer sits on the send side of the client's socket and
102 * does both the initial processing of BIOs and also transmission
103 * and retransmission of nfsreq's.
105 void
106 nfssvc_iod_writer(void *arg)
108 struct nfsmount *nmp = arg;
109 struct bio *bio;
110 struct vnode *vp;
112 if (nmp->nm_txstate == NFSSVC_INIT)
113 nmp->nm_txstate = NFSSVC_PENDING;
114 for (;;) {
115 if (nmp->nm_txstate == NFSSVC_WAITING) {
116 tsleep(&nmp->nm_txstate, 0, "nfsidl", 0);
117 continue;
119 if (nmp->nm_txstate != NFSSVC_PENDING)
120 break;
121 nmp->nm_txstate = NFSSVC_WAITING;
123 while (nmp->nm_bioqlen && nmp->nm_reqqlen < 32) {
124 bio = TAILQ_FIRST(&nmp->nm_bioq);
125 KKASSERT(bio);
126 TAILQ_REMOVE(&nmp->nm_bioq, bio, bio_act);
127 nmp->nm_bioqlen--;
128 vp = bio->bio_driver_info;
129 nfs_doio(vp, bio, NULL);
132 nmp->nm_txthread = NULL;
133 nmp->nm_txstate = NFSSVC_DONE;
134 wakeup(&nmp->nm_txthread);
137 void
138 nfssvc_iod_stop(struct nfsmount *nmp)
140 nmp->nm_txstate = NFSSVC_STOPPING;
141 wakeup(&nmp->nm_txstate);
142 while (nmp->nm_txthread)
143 tsleep(&nmp->nm_txthread, 0, "nfssttx", 0);
145 nmp->nm_rxstate = NFSSVC_STOPPING;
146 wakeup(&nmp->nm_rxstate);
147 while (nmp->nm_rxthread)
148 tsleep(&nmp->nm_rxthread, 0, "nfsstrx", 0);
151 void
152 nfssvc_iod_writer_wakeup(struct nfsmount *nmp)
154 if (nmp->nm_txstate == NFSSVC_WAITING) {
155 nmp->nm_txstate = NFSSVC_PENDING;
156 wakeup(&nmp->nm_txstate);