Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / vfs / nwfs / nwfs_io.c
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 $
33  *
34  */
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/resourcevar.h>    /* defines plimit structure in proc struct */
38 #include <sys/kernel.h>
39 #include <sys/buf.h>
40 #include <sys/proc.h>
41 #include <sys/mount.h>
42 #include <sys/namei.h>
43 #include <sys/vnode.h>
44 #include <sys/dirent.h>
45 #include <sys/signalvar.h>
46 #include <sys/sysctl.h>
47
48 #include <vm/vm.h>
49 #include <vm/vm_page.h>
50 #include <vm/vm_extern.h>
51 #include <vm/vm_object.h>
52 #include <vm/vm_pager.h>
53 #include <vm/vnode_pager.h>
54
55 #include <netncp/ncp.h>
56 #include <netncp/ncp_conn.h>
57 #include <netncp/ncp_subr.h>
58
59 #include <nwfs/nwfs.h>
60 #include <nwfs/nwfs_node.h>
61 #include <nwfs/nwfs_subr.h>
62
63 static int nwfs_fastlookup = 1;
64
65 extern struct linker_set sysctl_vfs_nwfs;
66
67 SYSCTL_DECL(_vfs_nwfs);
68 SYSCTL_INT(_vfs_nwfs, OID_AUTO, fastlookup, CTLFLAG_RW, &nwfs_fastlookup, 0, "");
69
70
71 extern int nwfs_pbuf_freecnt;
72
73 #define DE_SIZE (sizeof(struct dirent))
74 #define NWFS_RWCACHE
75
76 static int
77 nwfs_readvdir(struct vnode *vp, struct uio *uio, struct ucred *cred) {
78         struct nwmount *nmp = VTONWFS(vp);
79         int error, count, i;
80         struct dirent dp;
81         struct nwnode *np = VTONW(vp);
82         struct nw_entry_info fattr;
83         struct vnode *newvp;
84         struct componentname cn;
85         ncpfid fid;
86
87         np = VTONW(vp);
88         NCPVNDEBUG("dirname='%s'\n",np->n_name);
89         if (uio->uio_resid < DE_SIZE || (uio->uio_offset < 0))
90                 return (EINVAL);
91         error = 0;
92         count = 0;
93         i = uio->uio_offset / DE_SIZE; /* offset in directory */
94         if (i == 0) {
95                 error = ncp_initsearch(vp, uio->uio_procp, cred);
96                 if (error) {
97                         NCPVNDEBUG("cannot initialize search, error=%d",error);
98                         return( error );
99                 }
100         }
101
102         for (; uio->uio_resid >= DE_SIZE; i++) {
103                 bzero((char *) &dp, DE_SIZE);
104                 dp.d_reclen = DE_SIZE;
105                 switch (i) {
106                     case 0:             /* `.' */
107                     case 1:             /* `..' */
108                         dp.d_fileno = (i == 0) ? np->n_fid.f_id : np->n_parent.f_id;
109                         if (!dp.d_fileno) dp.d_fileno = NWFS_ROOT_INO;
110                         dp.d_namlen = i + 1;
111                         dp.d_name[0] = '.';
112                         dp.d_name[1] = '.';
113                         dp.d_name[i + 1] = '\0';
114                         dp.d_type = DT_DIR;
115                         break;
116                     default:
117                         error = ncp_search_for_file_or_subdir(nmp, &np->n_seq, &fattr, uio->uio_procp, cred);
118                         if (error && error < 0x80) break;
119                         dp.d_fileno = fattr.dirEntNum;
120                         dp.d_type = (fattr.attributes & aDIR) ? DT_DIR : DT_REG;
121                         dp.d_namlen = fattr.nameLen;
122                         bcopy(fattr.entryName, dp.d_name, dp.d_namlen);
123                         dp.d_name[dp.d_namlen] = '\0';
124 #if 0
125                         if (error && eofflag) {
126                         /*      *eofflag = 1;*/
127                                 break;
128                         }
129 #endif
130                         break;
131                 }
132                 if (nwfs_fastlookup && !error && i > 1) {
133                         fid.f_id = fattr.dirEntNum;
134                         fid.f_parent = np->n_fid.f_id;
135                         error = nwfs_nget(vp->v_mount, fid, &fattr, vp, &newvp);
136                         if (!error) {
137                                 VTONW(newvp)->n_ctime = VTONW(newvp)->n_vattr.va_ctime.tv_sec;
138                                 cn.cn_nameptr = dp.d_name;
139                                 cn.cn_namelen = dp.d_namlen;
140                                 cache_enter(vp, newvp, &cn);
141                                 vput(newvp);
142                         } else
143                                 error = 0;
144                 }
145                 if (error >= 0x80) {
146                     error = 0;
147                     break;
148                 }
149                 if ((error = uiomove((caddr_t)&dp, DE_SIZE, uio)))
150                         break;
151         }
152
153         uio->uio_offset = i * DE_SIZE;
154         return (error);
155 }
156
157 int
158 nwfs_readvnode(struct vnode *vp, struct uio *uiop, struct ucred *cred) {
159         struct nwmount *nmp = VFSTONWFS(vp->v_mount);
160         struct nwnode *np = VTONW(vp);
161         struct proc *p;
162         struct vattr vattr;
163         int error, biosize;
164
165         if (vp->v_type != VREG && vp->v_type != VDIR) {
166                 printf("%s: vn types other than VREG or VDIR are unsupported !\n",__FUNCTION__);
167                 return EIO;
168         }
169         if (uiop->uio_resid == 0) return 0;
170         if (uiop->uio_offset < 0) return EINVAL;
171 /*      if (uiop->uio_offset + uiop->uio_resid > nmp->nm_maxfilesize)
172                 return (EFBIG);*/
173         p = uiop->uio_procp;
174         if (vp->v_type == VDIR) {
175                 error = nwfs_readvdir(vp, uiop, cred);
176                 return error;
177         }
178         biosize = NWFSTOCONN(nmp)->buffer_size;
179         if (np->n_flag & NMODIFIED) {
180                 nwfs_attr_cacheremove(vp);
181                 error = VOP_GETATTR(vp, &vattr, cred, p);
182                 if (error) return (error);
183                 np->n_mtime = vattr.va_mtime.tv_sec;
184         } else {
185                 error = VOP_GETATTR(vp, &vattr, cred, p);
186                 if (error) return (error);
187                 if (np->n_mtime != vattr.va_mtime.tv_sec) {
188                         error = nwfs_vinvalbuf(vp, V_SAVE, cred, p, 1);
189                         if (error) return (error);
190                         np->n_mtime = vattr.va_mtime.tv_sec;
191                 }
192         }
193         error = ncp_read(NWFSTOCONN(nmp), &np->n_fh, uiop,cred);
194         return (error);
195 }
196
197 int
198 nwfs_writevnode(vp, uiop, cred, ioflag)
199         struct vnode *vp;
200         struct uio *uiop;
201         struct ucred *cred;
202         int ioflag;
203 {
204         struct nwmount *nmp = VTONWFS(vp);
205         struct nwnode *np = VTONW(vp);
206         struct proc *p;
207 /*      struct vattr vattr;*/
208         int error = 0;
209
210         if (vp->v_type != VREG) {
211                 printf("%s: vn types other than VREG unsupported !\n",__FUNCTION__);
212                 return EIO;
213         }
214         NCPVNDEBUG("ofs=%d,resid=%d\n",(int)uiop->uio_offset, uiop->uio_resid);
215         if (uiop->uio_offset < 0) return EINVAL;
216 /*      if (uiop->uio_offset + uiop->uio_resid > nmp->nm_maxfilesize)
217                 return (EFBIG);*/
218         p = uiop->uio_procp;
219         if (ioflag & (IO_APPEND | IO_SYNC)) {
220                 if (np->n_flag & NMODIFIED) {
221                         nwfs_attr_cacheremove(vp);
222                         error = nwfs_vinvalbuf(vp, V_SAVE, cred, p, 1);
223                         if (error) return (error);
224                 }
225                 if (ioflag & IO_APPEND) {
226                 /* We can relay only on local information about file size,
227                  * because until file is closed NetWare will not return
228                  * the correct size. */
229 #if notyet
230                         nwfs_attr_cacheremove(vp);
231                         error = VOP_GETATTR(vp, &vattr, cred, p);
232                         if (error) return (error);
233 #endif
234                         uiop->uio_offset = np->n_size;
235                 }
236         }
237         if (uiop->uio_resid == 0) return 0;
238         if (p && uiop->uio_offset + uiop->uio_resid > p->p_rlimit[RLIMIT_FSIZE].rlim_cur) {
239                 psignal(p, SIGXFSZ);
240                 return (EFBIG);
241         }
242         error = ncp_write(NWFSTOCONN(nmp), &np->n_fh, uiop, cred);
243         NCPVNDEBUG("after: ofs=%d,resid=%d\n",(int)uiop->uio_offset, uiop->uio_resid);
244         if (!error) {
245                 if (uiop->uio_offset > np->n_size) {
246                         np->n_vattr.va_size = np->n_size = uiop->uio_offset;
247                         vnode_pager_setsize(vp, np->n_size);
248                 }
249         }
250         return (error);
251 }
252
253 /*
254  * Do an I/O operation to/from a cache block.
255  */
256 int
257 nwfs_doio(bp, cr, p)
258         struct buf *bp;
259         struct ucred *cr;
260         struct proc *p;
261 {
262         struct uio *uiop;
263         struct vnode *vp;
264         struct nwnode *np;
265         struct nwmount *nmp;
266         int error = 0;
267         struct uio uio;
268         struct iovec io;
269
270         vp = bp->b_vp;
271         np = VTONW(vp);
272         nmp = VFSTONWFS(vp->v_mount);
273         uiop = &uio;
274         uiop->uio_iov = &io;
275         uiop->uio_iovcnt = 1;
276         uiop->uio_segflg = UIO_SYSSPACE;
277         uiop->uio_procp = p;
278         if (bp->b_flags & B_READ) {
279             io.iov_len = uiop->uio_resid = bp->b_bcount;
280             io.iov_base = bp->b_data;
281             uiop->uio_rw = UIO_READ;
282             switch (vp->v_type) {
283               case VREG:
284                 uiop->uio_offset = ((off_t)bp->b_blkno) * DEV_BSIZE;
285                 error = ncp_read(NWFSTOCONN(nmp), &np->n_fh, uiop, cr);
286                 if (error)
287                         break;
288                 if (uiop->uio_resid) {
289                         int left = uiop->uio_resid;
290                         int nread = bp->b_bcount - left;
291                         if (left > 0)
292                             bzero((char *)bp->b_data + nread, left);
293                 }
294                 break;
295 /*          case VDIR:
296                 nfsstats.readdir_bios++;
297                 uiop->uio_offset = ((u_quad_t)bp->b_lblkno) * NFS_DIRBLKSIZ;
298                 if (nmp->nm_flag & NFSMNT_RDIRPLUS) {
299                         error = nfs_readdirplusrpc(vp, uiop, cr);
300                         if (error == NFSERR_NOTSUPP)
301                                 nmp->nm_flag &= ~NFSMNT_RDIRPLUS;
302                 }
303                 if ((nmp->nm_flag & NFSMNT_RDIRPLUS) == 0)
304                         error = nfs_readdirrpc(vp, uiop, cr);
305                 if (error == 0 && uiop->uio_resid == bp->b_bcount)
306                         bp->b_flags |= B_INVAL;
307                 break;
308 */
309             default:
310                 printf("nwfs_doio:  type %x unexpected\n",vp->v_type);
311                 break;
312             };
313             if (error) {
314                 bp->b_flags |= B_ERROR;
315                 bp->b_error = error;
316             }
317         } else { /* write */
318             if (((bp->b_blkno * DEV_BSIZE) + bp->b_dirtyend) > np->n_size)
319                 bp->b_dirtyend = np->n_size - (bp->b_blkno * DEV_BSIZE);
320
321             if (bp->b_dirtyend > bp->b_dirtyoff) {
322                 io.iov_len = uiop->uio_resid = bp->b_dirtyend - bp->b_dirtyoff;
323                 uiop->uio_offset = ((off_t)bp->b_blkno) * DEV_BSIZE + bp->b_dirtyoff;
324                 io.iov_base = (char *)bp->b_data + bp->b_dirtyoff;
325                 uiop->uio_rw = UIO_WRITE;
326                 bp->b_flags |= B_WRITEINPROG;
327                 error = ncp_write(NWFSTOCONN(nmp), &np->n_fh, uiop, cr);
328                 bp->b_flags &= ~B_WRITEINPROG;
329
330                 /*
331                  * For an interrupted write, the buffer is still valid
332                  * and the write hasn't been pushed to the server yet,
333                  * so we can't set B_ERROR and report the interruption
334                  * by setting B_EINTR. For the B_ASYNC case, B_EINTR
335                  * is not relevant, so the rpc attempt is essentially
336                  * a noop.  For the case of a V3 write rpc not being
337                  * committed to stable storage, the block is still
338                  * dirty and requires either a commit rpc or another
339                  * write rpc with iomode == NFSV3WRITE_FILESYNC before
340                  * the block is reused. This is indicated by setting
341                  * the B_DELWRI and B_NEEDCOMMIT flags.
342                  */
343                 if (error == EINTR
344                     || (!error && (bp->b_flags & B_NEEDCOMMIT))) {
345                         int s;
346
347                         s = splbio();
348                         bp->b_flags &= ~(B_INVAL|B_NOCACHE);
349                         if ((bp->b_flags & B_ASYNC) == 0)
350                             bp->b_flags |= B_EINTR;
351                         if ((bp->b_flags & B_PAGING) == 0) {
352                             bdirty(bp);
353                             bp->b_flags &= ~B_DONE;
354                         }
355                         if ((bp->b_flags & B_ASYNC) == 0)
356                             bp->b_flags |= B_EINTR;
357                         splx(s);
358                 } else {
359                         if (error) {
360                                 bp->b_flags |= B_ERROR;
361                                 bp->b_error /*= np->n_error */= error;
362 /*                              np->n_flag |= NWRITEERR;*/
363                         }
364                         bp->b_dirtyoff = bp->b_dirtyend = 0;
365                 }
366             } else {
367                 bp->b_resid = 0;
368                 biodone(bp);
369                 return (0);
370             }
371         }
372         bp->b_resid = uiop->uio_resid;
373         biodone(bp);
374         return (error);
375 }
376
377 /*
378  * Vnode op for VM getpages.
379  * Wish wish .... get rid from multiple IO routines
380  */
381 int
382 nwfs_getpages(ap)
383         struct vop_getpages_args /* {
384                 struct vnode *a_vp;
385                 vm_page_t *a_m;
386                 int a_count;
387                 int a_reqpage;
388                 vm_ooffset_t a_offset;
389         } */ *ap;
390 {
391 #ifndef NWFS_RWCACHE
392         return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
393                 ap->a_reqpage);
394 #else
395         int i, error, nextoff, size, toff, npages, count;
396         struct uio uio;
397         struct iovec iov;
398         vm_offset_t kva;
399         struct buf *bp;
400         struct vnode *vp;
401         struct proc *p;
402         struct ucred *cred;
403         struct nwmount *nmp;
404         struct nwnode *np;
405         vm_page_t *pages;
406
407         vp = ap->a_vp;
408         p = curproc;                            /* XXX */
409         cred = curproc->p_ucred;                /* XXX */
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;
433         uio.uio_procp = p;
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  */
500 int
501 nwfs_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;
512         struct vnode *vp = ap->a_vp;
513         struct proc *p;
514         struct ucred *cred;
515
516 #ifndef NWFS_RWCACHE
517         p = curproc;                    /* XXX */
518         cred = p->p_ucred;              /* XXX */
519         VOP_OPEN(vp, FWRITE, cred, p);
520         error = vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
521                 ap->a_sync, ap->a_rtvals);
522         VOP_CLOSE(vp, FWRITE, cred, p);
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
535         p = curproc;                    /* XXX */
536         cred = p->p_ucred;              /* XXX */
537 /*      VOP_OPEN(vp, FWRITE, cred, p);*/
538         np = VTONW(vp);
539         nmp = VFSTONWFS(vp->v_mount);
540         pages = ap->a_m;
541         count = ap->a_count;
542         rtvals = ap->a_rtvals;
543         npages = btoc(count);
544
545         for (i = 0; i < npages; i++) {
546                 rtvals[i] = VM_PAGER_AGAIN;
547         }
548
549         bp = getpbuf(&nwfs_pbuf_freecnt);
550         kva = (vm_offset_t) bp->b_data;
551         pmap_qenter(kva, pages, npages);
552
553         iov.iov_base = (caddr_t) kva;
554         iov.iov_len = count;
555         uio.uio_iov = &iov;
556         uio.uio_iovcnt = 1;
557         uio.uio_offset = IDX_TO_OFF(pages[0]->pindex);
558         uio.uio_resid = count;
559         uio.uio_segflg = UIO_SYSSPACE;
560         uio.uio_rw = UIO_WRITE;
561         uio.uio_procp = p;
562         NCPVNDEBUG("ofs=%d,resid=%d\n",(int)uio.uio_offset, uio.uio_resid);
563
564         error = ncp_write(NWFSTOCONN(nmp), &np->n_fh, &uio, cred);
565 /*      VOP_CLOSE(vp, FWRITE, cred, p);*/
566         NCPVNDEBUG("paged write done: %d\n", error);
567
568         pmap_qremove(kva, npages);
569         relpbuf(bp, &nwfs_pbuf_freecnt);
570
571         if (!error) {
572                 int nwritten = round_page(count - uio.uio_resid) / PAGE_SIZE;
573                 for (i = 0; i < nwritten; i++) {
574                         rtvals[i] = VM_PAGER_OK;
575                         pages[i]->dirty = 0;
576                 }
577         }
578         return rtvals[0];
579 #endif /* NWFS_RWCACHE */
580 }
581 /*
582  * Flush and invalidate all dirty buffers. If another process is already
583  * doing the flush, just wait for completion.
584  */
585 int
586 nwfs_vinvalbuf(vp, flags, cred, p, intrflg)
587         struct vnode *vp;
588         int flags;
589         struct ucred *cred;
590         struct proc *p;
591         int intrflg;
592 {
593         struct nwnode *np = VTONW(vp);
594 /*      struct nwmount *nmp = VTONWFS(vp);*/
595         int error = 0, slpflag, slptimeo;
596
597         if (vp->v_flag & VXLOCK) {
598                 return (0);
599         }
600         if (intrflg) {
601                 slpflag = PCATCH;
602                 slptimeo = 2 * hz;
603         } else {
604                 slpflag = 0;
605                 slptimeo = 0;
606         }
607         while (np->n_flag & NFLUSHINPROG) {
608                 np->n_flag |= NFLUSHWANT;
609                 error = tsleep((caddr_t)&np->n_flag, PRIBIO + 2, "nwfsvinv", slptimeo);
610                 error = ncp_chkintr(NWFSTOCONN(VTONWFS(vp)), p);
611                 if (error == EINTR && intrflg)
612                         return EINTR;
613         }
614         np->n_flag |= NFLUSHINPROG;
615         error = vinvalbuf(vp, flags, cred, p, slpflag, 0);
616         while (error) {
617                 if (intrflg && (error == ERESTART || error == EINTR)) {
618                         np->n_flag &= ~NFLUSHINPROG;
619                         if (np->n_flag & NFLUSHWANT) {
620                                 np->n_flag &= ~NFLUSHWANT;
621                                 wakeup((caddr_t)&np->n_flag);
622                         }
623                         return EINTR;
624                 }
625                 error = vinvalbuf(vp, flags, cred, p, slpflag, 0);
626         }
627         np->n_flag &= ~(NMODIFIED | NFLUSHINPROG);
628         if (np->n_flag & NFLUSHWANT) {
629                 np->n_flag &= ~NFLUSHWANT;
630                 wakeup((caddr_t)&np->n_flag);
631         }
632         return (error);
633 }