proc->thread stage 4: rework the VFS and DEVICE subsystems to take thread
[dragonfly.git] / sys / vfs / nwfs / nwfs_io.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1999, Boris Popov
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Boris Popov.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 *
32 * $FreeBSD: src/sys/nwfs/nwfs_io.c,v 1.6.2.1 2000/10/25 02:11:10 bp Exp $
dadab5e9 33 * $DragonFly: src/sys/vfs/nwfs/nwfs_io.c,v 1.3 2003/06/25 03:56:08 dillon Exp $
984263bc
MD
34 *
35 */
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/resourcevar.h> /* defines plimit structure in proc struct */
39#include <sys/kernel.h>
40#include <sys/buf.h>
41#include <sys/proc.h>
42#include <sys/mount.h>
43#include <sys/namei.h>
44#include <sys/vnode.h>
45#include <sys/dirent.h>
46#include <sys/signalvar.h>
47#include <sys/sysctl.h>
48
49#include <vm/vm.h>
50#include <vm/vm_page.h>
51#include <vm/vm_extern.h>
52#include <vm/vm_object.h>
53#include <vm/vm_pager.h>
54#include <vm/vnode_pager.h>
55
56#include <netncp/ncp.h>
57#include <netncp/ncp_conn.h>
58#include <netncp/ncp_subr.h>
59
60#include <nwfs/nwfs.h>
61#include <nwfs/nwfs_node.h>
62#include <nwfs/nwfs_subr.h>
63
64static int nwfs_fastlookup = 1;
65
66extern struct linker_set sysctl_vfs_nwfs;
67
68SYSCTL_DECL(_vfs_nwfs);
69SYSCTL_INT(_vfs_nwfs, OID_AUTO, fastlookup, CTLFLAG_RW, &nwfs_fastlookup, 0, "");
70
71
72extern int nwfs_pbuf_freecnt;
73
74#define DE_SIZE (sizeof(struct dirent))
75#define NWFS_RWCACHE
76
77static int
78nwfs_readvdir(struct vnode *vp, struct uio *uio, struct ucred *cred) {
79 struct nwmount *nmp = VTONWFS(vp);
80 int error, count, i;
81 struct dirent dp;
82 struct nwnode *np = VTONW(vp);
83 struct nw_entry_info fattr;
84 struct vnode *newvp;
85 struct componentname cn;
86 ncpfid fid;
87
88 np = VTONW(vp);
89 NCPVNDEBUG("dirname='%s'\n",np->n_name);
90 if (uio->uio_resid < DE_SIZE || (uio->uio_offset < 0))
91 return (EINVAL);
92 error = 0;
93 count = 0;
94 i = uio->uio_offset / DE_SIZE; /* offset in directory */
95 if (i == 0) {
dadab5e9 96 error = ncp_initsearch(vp, uio->uio_td, cred);
984263bc
MD
97 if (error) {
98 NCPVNDEBUG("cannot initialize search, error=%d",error);
99 return( error );
100 }
101 }
102
103 for (; uio->uio_resid >= DE_SIZE; i++) {
104 bzero((char *) &dp, DE_SIZE);
105 dp.d_reclen = DE_SIZE;
106 switch (i) {
107 case 0: /* `.' */
108 case 1: /* `..' */
109 dp.d_fileno = (i == 0) ? np->n_fid.f_id : np->n_parent.f_id;
110 if (!dp.d_fileno) dp.d_fileno = NWFS_ROOT_INO;
111 dp.d_namlen = i + 1;
112 dp.d_name[0] = '.';
113 dp.d_name[1] = '.';
114 dp.d_name[i + 1] = '\0';
115 dp.d_type = DT_DIR;
116 break;
117 default:
dadab5e9 118 error = ncp_search_for_file_or_subdir(nmp, &np->n_seq, &fattr, uio->uio_td, cred);
984263bc
MD
119 if (error && error < 0x80) break;
120 dp.d_fileno = fattr.dirEntNum;
121 dp.d_type = (fattr.attributes & aDIR) ? DT_DIR : DT_REG;
122 dp.d_namlen = fattr.nameLen;
123 bcopy(fattr.entryName, dp.d_name, dp.d_namlen);
124 dp.d_name[dp.d_namlen] = '\0';
125#if 0
126 if (error && eofflag) {
127 /* *eofflag = 1;*/
128 break;
129 }
130#endif
131 break;
132 }
133 if (nwfs_fastlookup && !error && i > 1) {
134 fid.f_id = fattr.dirEntNum;
135 fid.f_parent = np->n_fid.f_id;
136 error = nwfs_nget(vp->v_mount, fid, &fattr, vp, &newvp);
137 if (!error) {
138 VTONW(newvp)->n_ctime = VTONW(newvp)->n_vattr.va_ctime.tv_sec;
139 cn.cn_nameptr = dp.d_name;
140 cn.cn_namelen = dp.d_namlen;
141 cache_enter(vp, newvp, &cn);
142 vput(newvp);
143 } else
144 error = 0;
145 }
146 if (error >= 0x80) {
147 error = 0;
148 break;
149 }
150 if ((error = uiomove((caddr_t)&dp, DE_SIZE, uio)))
151 break;
152 }
153
154 uio->uio_offset = i * DE_SIZE;
155 return (error);
156}
157
158int
159nwfs_readvnode(struct vnode *vp, struct uio *uiop, struct ucred *cred) {
160 struct nwmount *nmp = VFSTONWFS(vp->v_mount);
161 struct nwnode *np = VTONW(vp);
dadab5e9 162 struct thread *td;
984263bc
MD
163 struct vattr vattr;
164 int error, biosize;
165
166 if (vp->v_type != VREG && vp->v_type != VDIR) {
167 printf("%s: vn types other than VREG or VDIR are unsupported !\n",__FUNCTION__);
168 return EIO;
169 }
170 if (uiop->uio_resid == 0) return 0;
171 if (uiop->uio_offset < 0) return EINVAL;
172/* if (uiop->uio_offset + uiop->uio_resid > nmp->nm_maxfilesize)
173 return (EFBIG);*/
dadab5e9 174 td = uiop->uio_td;
984263bc
MD
175 if (vp->v_type == VDIR) {
176 error = nwfs_readvdir(vp, uiop, cred);
177 return error;
178 }
179 biosize = NWFSTOCONN(nmp)->buffer_size;
180 if (np->n_flag & NMODIFIED) {
181 nwfs_attr_cacheremove(vp);
dadab5e9 182 error = VOP_GETATTR(vp, &vattr, cred, td);
984263bc
MD
183 if (error) return (error);
184 np->n_mtime = vattr.va_mtime.tv_sec;
185 } else {
dadab5e9 186 error = VOP_GETATTR(vp, &vattr, cred, td);
984263bc
MD
187 if (error) return (error);
188 if (np->n_mtime != vattr.va_mtime.tv_sec) {
dadab5e9 189 error = nwfs_vinvalbuf(vp, V_SAVE, cred, td, 1);
984263bc
MD
190 if (error) return (error);
191 np->n_mtime = vattr.va_mtime.tv_sec;
192 }
193 }
194 error = ncp_read(NWFSTOCONN(nmp), &np->n_fh, uiop,cred);
195 return (error);
196}
197
198int
199nwfs_writevnode(vp, uiop, cred, ioflag)
200 struct vnode *vp;
201 struct uio *uiop;
202 struct ucred *cred;
203 int ioflag;
204{
205 struct nwmount *nmp = VTONWFS(vp);
206 struct nwnode *np = VTONW(vp);
dadab5e9 207 struct thread *td;
984263bc
MD
208/* struct vattr vattr;*/
209 int error = 0;
210
211 if (vp->v_type != VREG) {
212 printf("%s: vn types other than VREG unsupported !\n",__FUNCTION__);
213 return EIO;
214 }
215 NCPVNDEBUG("ofs=%d,resid=%d\n",(int)uiop->uio_offset, uiop->uio_resid);
216 if (uiop->uio_offset < 0) return EINVAL;
217/* if (uiop->uio_offset + uiop->uio_resid > nmp->nm_maxfilesize)
218 return (EFBIG);*/
dadab5e9 219 td = uiop->uio_td;
984263bc
MD
220 if (ioflag & (IO_APPEND | IO_SYNC)) {
221 if (np->n_flag & NMODIFIED) {
222 nwfs_attr_cacheremove(vp);
dadab5e9 223 error = nwfs_vinvalbuf(vp, V_SAVE, cred, td, 1);
984263bc
MD
224 if (error) return (error);
225 }
226 if (ioflag & IO_APPEND) {
227 /* We can relay only on local information about file size,
228 * because until file is closed NetWare will not return
229 * the correct size. */
230#if notyet
231 nwfs_attr_cacheremove(vp);
dadab5e9 232 error = VOP_GETATTR(vp, &vattr, cred, td);
984263bc
MD
233 if (error) return (error);
234#endif
235 uiop->uio_offset = np->n_size;
236 }
237 }
238 if (uiop->uio_resid == 0) return 0;
dadab5e9
MD
239 if (td->td_proc && uiop->uio_offset + uiop->uio_resid >
240 td->td_proc->p_rlimit[RLIMIT_FSIZE].rlim_cur) {
241 psignal(td->td_proc, SIGXFSZ);
984263bc
MD
242 return (EFBIG);
243 }
244 error = ncp_write(NWFSTOCONN(nmp), &np->n_fh, uiop, cred);
245 NCPVNDEBUG("after: ofs=%d,resid=%d\n",(int)uiop->uio_offset, uiop->uio_resid);
246 if (!error) {
247 if (uiop->uio_offset > np->n_size) {
248 np->n_vattr.va_size = np->n_size = uiop->uio_offset;
249 vnode_pager_setsize(vp, np->n_size);
250 }
251 }
252 return (error);
253}
254
255/*
256 * Do an I/O operation to/from a cache block.
257 */
258int
dadab5e9 259nwfs_doio(struct buf *bp, struct ucred *cr, struct thread *td)
984263bc
MD
260{
261 struct uio *uiop;
262 struct vnode *vp;
263 struct nwnode *np;
264 struct nwmount *nmp;
265 int error = 0;
266 struct uio uio;
267 struct iovec io;
268
269 vp = bp->b_vp;
270 np = VTONW(vp);
271 nmp = VFSTONWFS(vp->v_mount);
272 uiop = &uio;
273 uiop->uio_iov = &io;
274 uiop->uio_iovcnt = 1;
275 uiop->uio_segflg = UIO_SYSSPACE;
dadab5e9 276 uiop->uio_td = td;
984263bc
MD
277 if (bp->b_flags & B_READ) {
278 io.iov_len = uiop->uio_resid = bp->b_bcount;
279 io.iov_base = bp->b_data;
280 uiop->uio_rw = UIO_READ;
281 switch (vp->v_type) {
282 case VREG:
283 uiop->uio_offset = ((off_t)bp->b_blkno) * DEV_BSIZE;
284 error = ncp_read(NWFSTOCONN(nmp), &np->n_fh, uiop, cr);
285 if (error)
286 break;
287 if (uiop->uio_resid) {
288 int left = uiop->uio_resid;
289 int nread = bp->b_bcount - left;
290 if (left > 0)
291 bzero((char *)bp->b_data + nread, left);
292 }
293 break;
294/* case VDIR:
295 nfsstats.readdir_bios++;
296 uiop->uio_offset = ((u_quad_t)bp->b_lblkno) * NFS_DIRBLKSIZ;
297 if (nmp->nm_flag & NFSMNT_RDIRPLUS) {
298 error = nfs_readdirplusrpc(vp, uiop, cr);
299 if (error == NFSERR_NOTSUPP)
300 nmp->nm_flag &= ~NFSMNT_RDIRPLUS;
301 }
302 if ((nmp->nm_flag & NFSMNT_RDIRPLUS) == 0)
303 error = nfs_readdirrpc(vp, uiop, cr);
304 if (error == 0 && uiop->uio_resid == bp->b_bcount)
305 bp->b_flags |= B_INVAL;
306 break;
307*/
308 default:
309 printf("nwfs_doio: type %x unexpected\n",vp->v_type);
310 break;
311 };
312 if (error) {
313 bp->b_flags |= B_ERROR;
314 bp->b_error = error;
315 }
316 } else { /* write */
317 if (((bp->b_blkno * DEV_BSIZE) + bp->b_dirtyend) > np->n_size)
318 bp->b_dirtyend = np->n_size - (bp->b_blkno * DEV_BSIZE);
319
320 if (bp->b_dirtyend > bp->b_dirtyoff) {
321 io.iov_len = uiop->uio_resid = bp->b_dirtyend - bp->b_dirtyoff;
322 uiop->uio_offset = ((off_t)bp->b_blkno) * DEV_BSIZE + bp->b_dirtyoff;
323 io.iov_base = (char *)bp->b_data + bp->b_dirtyoff;
324 uiop->uio_rw = UIO_WRITE;
325 bp->b_flags |= B_WRITEINPROG;
326 error = ncp_write(NWFSTOCONN(nmp), &np->n_fh, uiop, cr);
327 bp->b_flags &= ~B_WRITEINPROG;
328
329 /*
330 * For an interrupted write, the buffer is still valid
331 * and the write hasn't been pushed to the server yet,
332 * so we can't set B_ERROR and report the interruption
333 * by setting B_EINTR. For the B_ASYNC case, B_EINTR
334 * is not relevant, so the rpc attempt is essentially
335 * a noop. For the case of a V3 write rpc not being
336 * committed to stable storage, the block is still
337 * dirty and requires either a commit rpc or another
338 * write rpc with iomode == NFSV3WRITE_FILESYNC before
339 * the block is reused. This is indicated by setting
340 * the B_DELWRI and B_NEEDCOMMIT flags.
341 */
342 if (error == EINTR
343 || (!error && (bp->b_flags & B_NEEDCOMMIT))) {
344 int s;
345
346 s = splbio();
347 bp->b_flags &= ~(B_INVAL|B_NOCACHE);
348 if ((bp->b_flags & B_ASYNC) == 0)
349 bp->b_flags |= B_EINTR;
350 if ((bp->b_flags & B_PAGING) == 0) {
351 bdirty(bp);
352 bp->b_flags &= ~B_DONE;
353 }
354 if ((bp->b_flags & B_ASYNC) == 0)
355 bp->b_flags |= B_EINTR;
356 splx(s);
357 } else {
358 if (error) {
359 bp->b_flags |= B_ERROR;
360 bp->b_error /*= np->n_error */= error;
361/* np->n_flag |= NWRITEERR;*/
362 }
363 bp->b_dirtyoff = bp->b_dirtyend = 0;
364 }
365 } else {
366 bp->b_resid = 0;
367 biodone(bp);
368 return (0);
369 }
370 }
371 bp->b_resid = uiop->uio_resid;
372 biodone(bp);
373 return (error);
374}
375
376/*
377 * Vnode op for VM getpages.
378 * Wish wish .... get rid from multiple IO routines
379 */
380int
381nwfs_getpages(ap)
382 struct vop_getpages_args /* {
383 struct vnode *a_vp;
384 vm_page_t *a_m;
385 int a_count;
386 int a_reqpage;
387 vm_ooffset_t a_offset;
388 } */ *ap;
389{
390#ifndef NWFS_RWCACHE
391 return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
392 ap->a_reqpage);
393#else
394 int i, error, nextoff, size, toff, npages, count;
395 struct uio uio;
396 struct iovec iov;
397 vm_offset_t kva;
398 struct buf *bp;
399 struct vnode *vp;
dadab5e9 400 struct thread *td = curthread; /* XXX */
984263bc
MD
401 struct ucred *cred;
402 struct nwmount *nmp;
403 struct nwnode *np;
404 vm_page_t *pages;
405
dadab5e9
MD
406 KKASSERT(td->td_proc);
407 cred = td->td_proc->p_ucred;
408
984263bc 409 vp = ap->a_vp;
984263bc
MD
410 np = VTONW(vp);
411 nmp = VFSTONWFS(vp->v_mount);
412 pages = ap->a_m;
413 count = ap->a_count;
414
415 if (vp->v_object == NULL) {
416 printf("nwfs_getpages: called with non-merged cache vnode??\n");
417 return VM_PAGER_ERROR;
418 }
419
420 bp = getpbuf(&nwfs_pbuf_freecnt);
421 npages = btoc(count);
422 kva = (vm_offset_t) bp->b_data;
423 pmap_qenter(kva, pages, npages);
424
425 iov.iov_base = (caddr_t) kva;
426 iov.iov_len = count;
427 uio.uio_iov = &iov;
428 uio.uio_iovcnt = 1;
429 uio.uio_offset = IDX_TO_OFF(pages[0]->pindex);
430 uio.uio_resid = count;
431 uio.uio_segflg = UIO_SYSSPACE;
432 uio.uio_rw = UIO_READ;
dadab5e9 433 uio.uio_td = td;
984263bc
MD
434
435 error = ncp_read(NWFSTOCONN(nmp), &np->n_fh, &uio,cred);
436 pmap_qremove(kva, npages);
437
438 relpbuf(bp, &nwfs_pbuf_freecnt);
439
440 if (error && (uio.uio_resid == count)) {
441 printf("nwfs_getpages: error %d\n",error);
442 for (i = 0; i < npages; i++) {
443 if (ap->a_reqpage != i)
444 vnode_pager_freepage(pages[i]);
445 }
446 return VM_PAGER_ERROR;
447 }
448
449 size = count - uio.uio_resid;
450
451 for (i = 0, toff = 0; i < npages; i++, toff = nextoff) {
452 vm_page_t m;
453 nextoff = toff + PAGE_SIZE;
454 m = pages[i];
455
456 m->flags &= ~PG_ZERO;
457
458 if (nextoff <= size) {
459 m->valid = VM_PAGE_BITS_ALL;
460 m->dirty = 0;
461 } else {
462 int nvalid = ((size + DEV_BSIZE - 1) - toff) & ~(DEV_BSIZE - 1);
463 vm_page_set_validclean(m, 0, nvalid);
464 }
465
466 if (i != ap->a_reqpage) {
467 /*
468 * Whether or not to leave the page activated is up in
469 * the air, but we should put the page on a page queue
470 * somewhere (it already is in the object). Result:
471 * It appears that emperical results show that
472 * deactivating pages is best.
473 */
474
475 /*
476 * Just in case someone was asking for this page we
477 * now tell them that it is ok to use.
478 */
479 if (!error) {
480 if (m->flags & PG_WANTED)
481 vm_page_activate(m);
482 else
483 vm_page_deactivate(m);
484 vm_page_wakeup(m);
485 } else {
486 vnode_pager_freepage(m);
487 }
488 }
489 }
490 return 0;
491#endif /* NWFS_RWCACHE */
492}
493
494/*
495 * Vnode op for VM putpages.
496 * possible bug: all IO done in sync mode
497 * Note that vop_close always invalidate pages before close, so it's
498 * not necessary to open vnode.
499 */
500int
501nwfs_putpages(ap)
502 struct vop_putpages_args /* {
503 struct vnode *a_vp;
504 vm_page_t *a_m;
505 int a_count;
506 int a_sync;
507 int *a_rtvals;
508 vm_ooffset_t a_offset;
509 } */ *ap;
510{
511 int error;
dadab5e9 512 struct thread *td = curthread; /* XXX */
984263bc 513 struct vnode *vp = ap->a_vp;
984263bc
MD
514 struct ucred *cred;
515
516#ifndef NWFS_RWCACHE
dadab5e9
MD
517 KKASSERT(td->td_proc);
518 cred = td->td_proc->p_ucred; /* XXX */
519 VOP_OPEN(vp, FWRITE, cred, td);
984263bc
MD
520 error = vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
521 ap->a_sync, ap->a_rtvals);
dadab5e9 522 VOP_CLOSE(vp, FWRITE, cred, td);
984263bc
MD
523 return error;
524#else
525 struct uio uio;
526 struct iovec iov;
527 vm_offset_t kva;
528 struct buf *bp;
529 int i, npages, count;
530 int *rtvals;
531 struct nwmount *nmp;
532 struct nwnode *np;
533 vm_page_t *pages;
534
dadab5e9
MD
535 KKASSERT(td->td_proc);
536 cred = td->td_proc->p_ucred; /* XXX */
537
538/* VOP_OPEN(vp, FWRITE, cred, td);*/
984263bc
MD
539 np = VTONW(vp);
540 nmp = VFSTONWFS(vp->v_mount);
541 pages = ap->a_m;
542 count = ap->a_count;
543 rtvals = ap->a_rtvals;
544 npages = btoc(count);
545
546 for (i = 0; i < npages; i++) {
547 rtvals[i] = VM_PAGER_AGAIN;
548 }
549
550 bp = getpbuf(&nwfs_pbuf_freecnt);
551 kva = (vm_offset_t) bp->b_data;
552 pmap_qenter(kva, pages, npages);
553
554 iov.iov_base = (caddr_t) kva;
555 iov.iov_len = count;
556 uio.uio_iov = &iov;
557 uio.uio_iovcnt = 1;
558 uio.uio_offset = IDX_TO_OFF(pages[0]->pindex);
559 uio.uio_resid = count;
560 uio.uio_segflg = UIO_SYSSPACE;
561 uio.uio_rw = UIO_WRITE;
dadab5e9 562 uio.uio_td = td;
984263bc
MD
563 NCPVNDEBUG("ofs=%d,resid=%d\n",(int)uio.uio_offset, uio.uio_resid);
564
565 error = ncp_write(NWFSTOCONN(nmp), &np->n_fh, &uio, cred);
dadab5e9 566/* VOP_CLOSE(vp, FWRITE, cred, td);*/
984263bc
MD
567 NCPVNDEBUG("paged write done: %d\n", error);
568
569 pmap_qremove(kva, npages);
570 relpbuf(bp, &nwfs_pbuf_freecnt);
571
572 if (!error) {
573 int nwritten = round_page(count - uio.uio_resid) / PAGE_SIZE;
574 for (i = 0; i < nwritten; i++) {
575 rtvals[i] = VM_PAGER_OK;
576 pages[i]->dirty = 0;
577 }
578 }
579 return rtvals[0];
580#endif /* NWFS_RWCACHE */
581}
582/*
583 * Flush and invalidate all dirty buffers. If another process is already
584 * doing the flush, just wait for completion.
585 */
586int
dadab5e9 587nwfs_vinvalbuf(vp, flags, cred, td, intrflg)
984263bc
MD
588 struct vnode *vp;
589 int flags;
590 struct ucred *cred;
dadab5e9 591 struct thread *td;
984263bc
MD
592 int intrflg;
593{
594 struct nwnode *np = VTONW(vp);
595/* struct nwmount *nmp = VTONWFS(vp);*/
596 int error = 0, slpflag, slptimeo;
597
598 if (vp->v_flag & VXLOCK) {
599 return (0);
600 }
601 if (intrflg) {
602 slpflag = PCATCH;
603 slptimeo = 2 * hz;
604 } else {
605 slpflag = 0;
606 slptimeo = 0;
607 }
608 while (np->n_flag & NFLUSHINPROG) {
609 np->n_flag |= NFLUSHWANT;
610 error = tsleep((caddr_t)&np->n_flag, PRIBIO + 2, "nwfsvinv", slptimeo);
dadab5e9 611 error = ncp_chkintr(NWFSTOCONN(VTONWFS(vp)), td);
984263bc
MD
612 if (error == EINTR && intrflg)
613 return EINTR;
614 }
615 np->n_flag |= NFLUSHINPROG;
dadab5e9 616 error = vinvalbuf(vp, flags, cred, td, slpflag, 0);
984263bc
MD
617 while (error) {
618 if (intrflg && (error == ERESTART || error == EINTR)) {
619 np->n_flag &= ~NFLUSHINPROG;
620 if (np->n_flag & NFLUSHWANT) {
621 np->n_flag &= ~NFLUSHWANT;
622 wakeup((caddr_t)&np->n_flag);
623 }
624 return EINTR;
625 }
dadab5e9 626 error = vinvalbuf(vp, flags, cred, td, slpflag, 0);
984263bc
MD
627 }
628 np->n_flag &= ~(NMODIFIED | NFLUSHINPROG);
629 if (np->n_flag & NFLUSHWANT) {
630 np->n_flag &= ~NFLUSHWANT;
631 wakeup((caddr_t)&np->n_flag);
632 }
633 return (error);
634}