1 1.6 rin /* $NetBSD: nfs_srvsocket.c,v 1.6 2024/07/05 04:31:54 rin Exp $ */ 2 1.1 ad 3 1.1 ad /* 4 1.1 ad * Copyright (c) 1989, 1991, 1993, 1995 5 1.1 ad * The Regents of the University of California. All rights reserved. 6 1.1 ad * 7 1.1 ad * This code is derived from software contributed to Berkeley by 8 1.1 ad * Rick Macklem at The University of Guelph. 9 1.1 ad * 10 1.1 ad * Redistribution and use in source and binary forms, with or without 11 1.1 ad * modification, are permitted provided that the following conditions 12 1.1 ad * are met: 13 1.1 ad * 1. Redistributions of source code must retain the above copyright 14 1.1 ad * notice, this list of conditions and the following disclaimer. 15 1.1 ad * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 ad * notice, this list of conditions and the following disclaimer in the 17 1.1 ad * documentation and/or other materials provided with the distribution. 18 1.1 ad * 3. Neither the name of the University nor the names of its contributors 19 1.1 ad * may be used to endorse or promote products derived from this software 20 1.1 ad * without specific prior written permission. 21 1.1 ad * 22 1.1 ad * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 1.1 ad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 1.1 ad * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 1.1 ad * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 1.1 ad * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 1.1 ad * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 1.1 ad * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 1.1 ad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 1.1 ad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 1.1 ad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 1.1 ad * SUCH DAMAGE. 33 1.1 ad * 34 1.1 ad * @(#)nfs_socket.c 8.5 (Berkeley) 3/30/95 35 1.1 ad */ 36 1.1 ad 37 1.1 ad /* 38 1.1 ad * Socket operations for use by nfs 39 1.1 ad */ 40 1.1 ad 41 1.1 ad #include <sys/cdefs.h> 42 1.6 rin __KERNEL_RCSID(0, "$NetBSD: nfs_srvsocket.c,v 1.6 2024/07/05 04:31:54 rin Exp $"); 43 1.1 ad 44 1.1 ad #include <sys/param.h> 45 1.1 ad #include <sys/systm.h> 46 1.1 ad #include <sys/evcnt.h> 47 1.1 ad #include <sys/callout.h> 48 1.1 ad #include <sys/proc.h> 49 1.1 ad #include <sys/mount.h> 50 1.1 ad #include <sys/kernel.h> 51 1.1 ad #include <sys/kmem.h> 52 1.1 ad #include <sys/mbuf.h> 53 1.1 ad #include <sys/vnode.h> 54 1.1 ad #include <sys/domain.h> 55 1.1 ad #include <sys/protosw.h> 56 1.1 ad #include <sys/socket.h> 57 1.1 ad #include <sys/socketvar.h> 58 1.1 ad #include <sys/syslog.h> 59 1.1 ad #include <sys/tprintf.h> 60 1.1 ad #include <sys/namei.h> 61 1.1 ad #include <sys/signal.h> 62 1.1 ad #include <sys/signalvar.h> 63 1.1 ad #include <sys/kauth.h> 64 1.1 ad 65 1.1 ad #include <netinet/in.h> 66 1.1 ad #include <netinet/tcp.h> 67 1.1 ad 68 1.1 ad #include <nfs/rpcv2.h> 69 1.1 ad #include <nfs/nfsproto.h> 70 1.1 ad #include <nfs/nfs.h> 71 1.1 ad #include <nfs/xdr_subs.h> 72 1.1 ad #include <nfs/nfsm_subs.h> 73 1.1 ad #include <nfs/nfsmount.h> 74 1.1 ad #include <nfs/nfsnode.h> 75 1.1 ad #include <nfs/nfsrtt.h> 76 1.1 ad #include <nfs/nfs_var.h> 77 1.1 ad 78 1.1 ad static void nfsrv_wakenfsd_locked(struct nfssvc_sock *); 79 1.1 ad 80 1.2 dsl int (*nfsrv3_procs[NFS_NPROCS])(struct nfsrv_descript *, 81 1.1 ad struct nfssvc_sock *, struct lwp *, 82 1.2 dsl struct mbuf **) = { 83 1.1 ad nfsrv_null, 84 1.1 ad nfsrv_getattr, 85 1.1 ad nfsrv_setattr, 86 1.1 ad nfsrv_lookup, 87 1.1 ad nfsrv3_access, 88 1.1 ad nfsrv_readlink, 89 1.1 ad nfsrv_read, 90 1.1 ad nfsrv_write, 91 1.1 ad nfsrv_create, 92 1.1 ad nfsrv_mkdir, 93 1.1 ad nfsrv_symlink, 94 1.1 ad nfsrv_mknod, 95 1.1 ad nfsrv_remove, 96 1.1 ad nfsrv_rmdir, 97 1.1 ad nfsrv_rename, 98 1.1 ad nfsrv_link, 99 1.1 ad nfsrv_readdir, 100 1.1 ad nfsrv_readdirplus, 101 1.1 ad nfsrv_statfs, 102 1.1 ad nfsrv_fsinfo, 103 1.1 ad nfsrv_pathconf, 104 1.1 ad nfsrv_commit, 105 1.1 ad nfsrv_noop 106 1.1 ad }; 107 1.1 ad 108 1.1 ad /* 109 1.1 ad * Socket upcall routine for the nfsd sockets. 110 1.1 ad * The void *arg is a pointer to the "struct nfssvc_sock". 111 1.1 ad */ 112 1.1 ad void 113 1.4 tls nfsrv_soupcall(struct socket *so, void *arg, int events, int waitflag) 114 1.1 ad { 115 1.1 ad struct nfssvc_sock *slp = (struct nfssvc_sock *)arg; 116 1.1 ad 117 1.1 ad nfsdsock_setbits(slp, SLP_A_NEEDQ); 118 1.1 ad nfsrv_wakenfsd(slp); 119 1.1 ad } 120 1.1 ad 121 1.1 ad void 122 1.1 ad nfsrv_rcv(struct nfssvc_sock *slp) 123 1.1 ad { 124 1.1 ad struct socket *so; 125 1.1 ad struct mbuf *m; 126 1.1 ad struct mbuf *mp, *nam; 127 1.1 ad struct uio auio; 128 1.1 ad int flags; 129 1.1 ad int error; 130 1.1 ad int setflags = 0; 131 1.1 ad 132 1.1 ad error = nfsdsock_lock(slp, true); 133 1.1 ad if (error) { 134 1.1 ad setflags |= SLP_A_NEEDQ; 135 1.1 ad goto dorecs_unlocked; 136 1.1 ad } 137 1.1 ad 138 1.1 ad nfsdsock_clearbits(slp, SLP_A_NEEDQ); 139 1.1 ad 140 1.1 ad so = slp->ns_so; 141 1.1 ad if (so->so_type == SOCK_STREAM) { 142 1.1 ad /* 143 1.1 ad * Do soreceive(). 144 1.1 ad */ 145 1.1 ad auio.uio_resid = 1000000000; 146 1.1 ad /* not need to setup uio_vmspace */ 147 1.1 ad flags = MSG_DONTWAIT; 148 1.1 ad error = (*so->so_receive)(so, &nam, &auio, &mp, NULL, &flags); 149 1.1 ad if (error || mp == NULL) { 150 1.1 ad if (error == EWOULDBLOCK) 151 1.1 ad setflags |= SLP_A_NEEDQ; 152 1.1 ad else 153 1.1 ad setflags |= SLP_A_DISCONN; 154 1.1 ad goto dorecs; 155 1.1 ad } 156 1.1 ad m = mp; 157 1.1 ad m_claimm(m, &nfs_mowner); 158 1.1 ad if (slp->ns_rawend) { 159 1.1 ad slp->ns_rawend->m_next = m; 160 1.1 ad slp->ns_cc += 1000000000 - auio.uio_resid; 161 1.1 ad } else { 162 1.1 ad slp->ns_raw = m; 163 1.1 ad slp->ns_cc = 1000000000 - auio.uio_resid; 164 1.1 ad } 165 1.1 ad while (m->m_next) 166 1.1 ad m = m->m_next; 167 1.1 ad slp->ns_rawend = m; 168 1.1 ad 169 1.1 ad /* 170 1.1 ad * Now try and parse record(s) out of the raw stream data. 171 1.1 ad */ 172 1.1 ad error = nfsrv_getstream(slp, M_WAIT); 173 1.1 ad if (error) { 174 1.1 ad if (error == EPERM) 175 1.1 ad setflags |= SLP_A_DISCONN; 176 1.1 ad else 177 1.1 ad setflags |= SLP_A_NEEDQ; 178 1.1 ad } 179 1.1 ad } else { 180 1.1 ad do { 181 1.1 ad auio.uio_resid = 1000000000; 182 1.1 ad /* not need to setup uio_vmspace */ 183 1.1 ad flags = MSG_DONTWAIT; 184 1.1 ad error = (*so->so_receive)(so, &nam, &auio, &mp, NULL, 185 1.1 ad &flags); 186 1.1 ad if (mp) { 187 1.1 ad if (nam) { 188 1.1 ad m = nam; 189 1.1 ad m->m_next = mp; 190 1.1 ad } else 191 1.1 ad m = mp; 192 1.1 ad m_claimm(m, &nfs_mowner); 193 1.1 ad if (slp->ns_recend) 194 1.1 ad slp->ns_recend->m_nextpkt = m; 195 1.1 ad else 196 1.1 ad slp->ns_rec = m; 197 1.1 ad slp->ns_recend = m; 198 1.1 ad m->m_nextpkt = (struct mbuf *)0; 199 1.1 ad } 200 1.1 ad if (error) { 201 1.1 ad if ((so->so_proto->pr_flags & PR_CONNREQUIRED) 202 1.1 ad && error != EWOULDBLOCK) { 203 1.1 ad setflags |= SLP_A_DISCONN; 204 1.1 ad goto dorecs; 205 1.1 ad } 206 1.1 ad } 207 1.1 ad } while (mp); 208 1.1 ad } 209 1.1 ad dorecs: 210 1.1 ad nfsdsock_unlock(slp); 211 1.1 ad 212 1.1 ad dorecs_unlocked: 213 1.1 ad if (setflags) { 214 1.1 ad nfsdsock_setbits(slp, setflags); 215 1.1 ad } 216 1.1 ad } 217 1.1 ad 218 1.1 ad int 219 1.1 ad nfsdsock_lock(struct nfssvc_sock *slp, bool waitok) 220 1.1 ad { 221 1.1 ad 222 1.1 ad mutex_enter(&slp->ns_lock); 223 1.1 ad while ((~slp->ns_flags & (SLP_BUSY|SLP_VALID)) == 0) { 224 1.1 ad if (!waitok) { 225 1.1 ad mutex_exit(&slp->ns_lock); 226 1.1 ad return EWOULDBLOCK; 227 1.1 ad } 228 1.1 ad cv_wait(&slp->ns_cv, &slp->ns_lock); 229 1.1 ad } 230 1.1 ad if ((slp->ns_flags & SLP_VALID) == 0) { 231 1.1 ad mutex_exit(&slp->ns_lock); 232 1.1 ad return EINVAL; 233 1.1 ad } 234 1.1 ad KASSERT((slp->ns_flags & SLP_BUSY) == 0); 235 1.1 ad slp->ns_flags |= SLP_BUSY; 236 1.1 ad mutex_exit(&slp->ns_lock); 237 1.1 ad 238 1.1 ad return 0; 239 1.1 ad } 240 1.1 ad 241 1.1 ad void 242 1.1 ad nfsdsock_unlock(struct nfssvc_sock *slp) 243 1.1 ad { 244 1.1 ad 245 1.1 ad mutex_enter(&slp->ns_lock); 246 1.1 ad KASSERT((slp->ns_flags & SLP_BUSY) != 0); 247 1.1 ad cv_broadcast(&slp->ns_cv); 248 1.1 ad slp->ns_flags &= ~SLP_BUSY; 249 1.1 ad mutex_exit(&slp->ns_lock); 250 1.1 ad } 251 1.1 ad 252 1.1 ad int 253 1.1 ad nfsdsock_drain(struct nfssvc_sock *slp) 254 1.1 ad { 255 1.1 ad int error = 0; 256 1.1 ad 257 1.1 ad mutex_enter(&slp->ns_lock); 258 1.1 ad if ((slp->ns_flags & SLP_VALID) == 0) { 259 1.1 ad error = EINVAL; 260 1.1 ad goto done; 261 1.1 ad } 262 1.1 ad slp->ns_flags &= ~SLP_VALID; 263 1.1 ad while ((slp->ns_flags & SLP_BUSY) != 0) { 264 1.1 ad cv_wait(&slp->ns_cv, &slp->ns_lock); 265 1.1 ad } 266 1.1 ad done: 267 1.1 ad mutex_exit(&slp->ns_lock); 268 1.1 ad 269 1.1 ad return error; 270 1.1 ad } 271 1.1 ad 272 1.1 ad /* 273 1.1 ad * Try and extract an RPC request from the mbuf data list received on a 274 1.1 ad * stream socket. The "waitflag" argument indicates whether or not it 275 1.1 ad * can sleep. 276 1.1 ad */ 277 1.1 ad int 278 1.3 dsl nfsrv_getstream(struct nfssvc_sock *slp, int waitflag) 279 1.1 ad { 280 1.1 ad struct mbuf *m, **mpp; 281 1.1 ad struct mbuf *recm; 282 1.1 ad u_int32_t recmark; 283 1.1 ad int error = 0; 284 1.1 ad 285 1.1 ad KASSERT((slp->ns_flags & SLP_BUSY) != 0); 286 1.1 ad for (;;) { 287 1.1 ad if (slp->ns_reclen == 0) { 288 1.1 ad if (slp->ns_cc < NFSX_UNSIGNED) { 289 1.1 ad break; 290 1.1 ad } 291 1.1 ad m = slp->ns_raw; 292 1.1 ad m_copydata(m, 0, NFSX_UNSIGNED, (void *)&recmark); 293 1.1 ad m_adj(m, NFSX_UNSIGNED); 294 1.1 ad slp->ns_cc -= NFSX_UNSIGNED; 295 1.1 ad recmark = ntohl(recmark); 296 1.1 ad slp->ns_reclen = recmark & ~0x80000000; 297 1.1 ad if (recmark & 0x80000000) 298 1.1 ad slp->ns_sflags |= SLP_S_LASTFRAG; 299 1.1 ad else 300 1.1 ad slp->ns_sflags &= ~SLP_S_LASTFRAG; 301 1.1 ad if (slp->ns_reclen > NFS_MAXPACKET) { 302 1.1 ad error = EPERM; 303 1.1 ad break; 304 1.1 ad } 305 1.1 ad } 306 1.1 ad 307 1.1 ad /* 308 1.1 ad * Now get the record part. 309 1.1 ad * 310 1.1 ad * Note that slp->ns_reclen may be 0. Linux sometimes 311 1.1 ad * generates 0-length records. 312 1.1 ad */ 313 1.1 ad if (slp->ns_cc == slp->ns_reclen) { 314 1.1 ad recm = slp->ns_raw; 315 1.1 ad slp->ns_raw = slp->ns_rawend = (struct mbuf *)0; 316 1.1 ad slp->ns_cc = slp->ns_reclen = 0; 317 1.1 ad } else if (slp->ns_cc > slp->ns_reclen) { 318 1.1 ad recm = slp->ns_raw; 319 1.1 ad m = m_split(recm, slp->ns_reclen, waitflag); 320 1.1 ad if (m == NULL) { 321 1.1 ad error = EWOULDBLOCK; 322 1.1 ad break; 323 1.1 ad } 324 1.1 ad m_claimm(recm, &nfs_mowner); 325 1.1 ad slp->ns_raw = m; 326 1.5 hannken while (m->m_next) 327 1.5 hannken m = m->m_next; 328 1.5 hannken slp->ns_rawend = m; 329 1.1 ad slp->ns_cc -= slp->ns_reclen; 330 1.1 ad slp->ns_reclen = 0; 331 1.1 ad } else { 332 1.1 ad break; 333 1.1 ad } 334 1.1 ad 335 1.1 ad /* 336 1.1 ad * Accumulate the fragments into a record. 337 1.1 ad */ 338 1.1 ad mpp = &slp->ns_frag; 339 1.1 ad while (*mpp) 340 1.1 ad mpp = &((*mpp)->m_next); 341 1.1 ad *mpp = recm; 342 1.1 ad if (slp->ns_sflags & SLP_S_LASTFRAG) { 343 1.1 ad if (slp->ns_recend) 344 1.1 ad slp->ns_recend->m_nextpkt = slp->ns_frag; 345 1.1 ad else 346 1.1 ad slp->ns_rec = slp->ns_frag; 347 1.1 ad slp->ns_recend = slp->ns_frag; 348 1.1 ad slp->ns_frag = NULL; 349 1.1 ad } 350 1.1 ad } 351 1.1 ad 352 1.1 ad return error; 353 1.1 ad } 354 1.1 ad 355 1.1 ad /* 356 1.1 ad * Parse an RPC header. 357 1.1 ad */ 358 1.1 ad int 359 1.1 ad nfsrv_dorec(struct nfssvc_sock *slp, struct nfsd *nfsd, 360 1.1 ad struct nfsrv_descript **ndp, bool *more) 361 1.1 ad { 362 1.1 ad struct mbuf *m, *nam; 363 1.1 ad struct nfsrv_descript *nd; 364 1.1 ad int error; 365 1.1 ad 366 1.1 ad *ndp = NULL; 367 1.1 ad *more = false; 368 1.1 ad 369 1.1 ad if (nfsdsock_lock(slp, true)) { 370 1.1 ad return ENOBUFS; 371 1.1 ad } 372 1.1 ad m = slp->ns_rec; 373 1.1 ad if (m == NULL) { 374 1.1 ad nfsdsock_unlock(slp); 375 1.1 ad return ENOBUFS; 376 1.1 ad } 377 1.1 ad slp->ns_rec = m->m_nextpkt; 378 1.1 ad if (slp->ns_rec) { 379 1.1 ad m->m_nextpkt = NULL; 380 1.1 ad *more = true; 381 1.1 ad } else { 382 1.1 ad slp->ns_recend = NULL; 383 1.1 ad } 384 1.1 ad nfsdsock_unlock(slp); 385 1.1 ad 386 1.1 ad if (m->m_type == MT_SONAME) { 387 1.1 ad nam = m; 388 1.1 ad m = m->m_next; 389 1.1 ad nam->m_next = NULL; 390 1.1 ad } else 391 1.1 ad nam = NULL; 392 1.1 ad nd = nfsdreq_alloc(); 393 1.1 ad nd->nd_md = nd->nd_mrep = m; 394 1.1 ad nd->nd_nam2 = nam; 395 1.1 ad nd->nd_dpos = mtod(m, void *); 396 1.1 ad error = nfs_getreq(nd, nfsd, true); 397 1.1 ad if (error) { 398 1.1 ad m_freem(nam); 399 1.1 ad nfsdreq_free(nd); 400 1.1 ad return (error); 401 1.1 ad } 402 1.1 ad *ndp = nd; 403 1.1 ad nfsd->nfsd_nd = nd; 404 1.1 ad return (0); 405 1.1 ad } 406 1.1 ad 407 1.1 ad bool 408 1.1 ad nfsrv_timer(void) 409 1.1 ad { 410 1.1 ad struct timeval tv; 411 1.1 ad struct nfssvc_sock *slp; 412 1.1 ad u_quad_t cur_usec; 413 1.1 ad struct nfsrv_descript *nd; 414 1.1 ad bool more; 415 1.1 ad 416 1.1 ad /* 417 1.1 ad * Scan the write gathering queues for writes that need to be 418 1.1 ad * completed now. 419 1.1 ad */ 420 1.1 ad getmicrotime(&tv); 421 1.1 ad cur_usec = (u_quad_t)tv.tv_sec * 1000000 + (u_quad_t)tv.tv_usec; 422 1.1 ad more = false; 423 1.1 ad mutex_enter(&nfsd_lock); 424 1.1 ad TAILQ_FOREACH(slp, &nfssvc_sockhead, ns_chain) { 425 1.1 ad nd = LIST_FIRST(&slp->ns_tq); 426 1.1 ad if (nd != NULL) { 427 1.1 ad if (nd->nd_time <= cur_usec) { 428 1.1 ad nfsrv_wakenfsd_locked(slp); 429 1.1 ad } 430 1.1 ad more = true; 431 1.1 ad } 432 1.1 ad } 433 1.1 ad mutex_exit(&nfsd_lock); 434 1.1 ad return more; 435 1.1 ad } 436 1.1 ad 437 1.1 ad /* 438 1.1 ad * Search for a sleeping nfsd and wake it up. 439 1.1 ad * SIDE EFFECT: If none found, set NFSD_CHECKSLP flag, so that one of the 440 1.1 ad * running nfsds will go look for the work in the nfssvc_sock list. 441 1.1 ad */ 442 1.1 ad static void 443 1.1 ad nfsrv_wakenfsd_locked(struct nfssvc_sock *slp) 444 1.1 ad { 445 1.1 ad struct nfsd *nd; 446 1.1 ad 447 1.1 ad KASSERT(mutex_owned(&nfsd_lock)); 448 1.1 ad 449 1.1 ad if ((slp->ns_flags & SLP_VALID) == 0) 450 1.1 ad return; 451 1.1 ad if (slp->ns_gflags & SLP_G_DOREC) 452 1.1 ad return; 453 1.1 ad nd = SLIST_FIRST(&nfsd_idle_head); 454 1.1 ad if (nd) { 455 1.1 ad SLIST_REMOVE_HEAD(&nfsd_idle_head, nfsd_idle); 456 1.1 ad if (nd->nfsd_slp) 457 1.1 ad panic("nfsd wakeup"); 458 1.1 ad slp->ns_sref++; 459 1.1 ad KASSERT(slp->ns_sref > 0); 460 1.1 ad nd->nfsd_slp = slp; 461 1.1 ad cv_signal(&nd->nfsd_cv); 462 1.1 ad } else { 463 1.1 ad slp->ns_gflags |= SLP_G_DOREC; 464 1.1 ad nfsd_head_flag |= NFSD_CHECKSLP; 465 1.1 ad TAILQ_INSERT_TAIL(&nfssvc_sockpending, slp, ns_pending); 466 1.1 ad } 467 1.1 ad } 468 1.1 ad 469 1.1 ad void 470 1.1 ad nfsrv_wakenfsd(struct nfssvc_sock *slp) 471 1.1 ad { 472 1.1 ad 473 1.1 ad mutex_enter(&nfsd_lock); 474 1.1 ad nfsrv_wakenfsd_locked(slp); 475 1.1 ad mutex_exit(&nfsd_lock); 476 1.1 ad } 477 1.1 ad 478 1.1 ad int 479 1.1 ad nfsdsock_sendreply(struct nfssvc_sock *slp, struct nfsrv_descript *nd) 480 1.1 ad { 481 1.1 ad int error; 482 1.1 ad 483 1.6 rin m_freem(nd->nd_mrep); 484 1.6 rin nd->nd_mrep = NULL; 485 1.1 ad 486 1.1 ad mutex_enter(&slp->ns_lock); 487 1.1 ad if ((slp->ns_flags & SLP_SENDING) != 0) { 488 1.1 ad SIMPLEQ_INSERT_TAIL(&slp->ns_sendq, nd, nd_sendq); 489 1.1 ad mutex_exit(&slp->ns_lock); 490 1.1 ad return 0; 491 1.1 ad } 492 1.1 ad KASSERT(SIMPLEQ_EMPTY(&slp->ns_sendq)); 493 1.1 ad slp->ns_flags |= SLP_SENDING; 494 1.1 ad mutex_exit(&slp->ns_lock); 495 1.1 ad 496 1.1 ad again: 497 1.1 ad error = nfs_send(slp->ns_so, nd->nd_nam2, nd->nd_mreq, NULL, curlwp); 498 1.1 ad if (nd->nd_nam2) { 499 1.1 ad m_free(nd->nd_nam2); 500 1.1 ad } 501 1.1 ad nfsdreq_free(nd); 502 1.1 ad 503 1.1 ad mutex_enter(&slp->ns_lock); 504 1.1 ad KASSERT((slp->ns_flags & SLP_SENDING) != 0); 505 1.1 ad nd = SIMPLEQ_FIRST(&slp->ns_sendq); 506 1.1 ad if (nd != NULL) { 507 1.1 ad SIMPLEQ_REMOVE_HEAD(&slp->ns_sendq, nd_sendq); 508 1.1 ad mutex_exit(&slp->ns_lock); 509 1.1 ad goto again; 510 1.1 ad } 511 1.1 ad slp->ns_flags &= ~SLP_SENDING; 512 1.1 ad mutex_exit(&slp->ns_lock); 513 1.1 ad 514 1.1 ad return error; 515 1.1 ad } 516 1.1 ad 517 1.1 ad void 518 1.1 ad nfsdsock_setbits(struct nfssvc_sock *slp, int bits) 519 1.1 ad { 520 1.1 ad 521 1.1 ad mutex_enter(&slp->ns_alock); 522 1.1 ad slp->ns_aflags |= bits; 523 1.1 ad mutex_exit(&slp->ns_alock); 524 1.1 ad } 525 1.1 ad 526 1.1 ad void 527 1.1 ad nfsdsock_clearbits(struct nfssvc_sock *slp, int bits) 528 1.1 ad { 529 1.1 ad 530 1.1 ad mutex_enter(&slp->ns_alock); 531 1.1 ad slp->ns_aflags &= ~bits; 532 1.1 ad mutex_exit(&slp->ns_alock); 533 1.1 ad } 534 1.1 ad 535 1.1 ad bool 536 1.1 ad nfsdsock_testbits(struct nfssvc_sock *slp, int bits) 537 1.1 ad { 538 1.1 ad 539 1.1 ad return (slp->ns_aflags & bits); 540 1.1 ad } 541