Mostly fix nullfs. There are still namespace race issues between
[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  * $DragonFly: src/sys/vfs/nwfs/nwfs_io.c,v 1.17 2005/08/16 19:16:39 joerg Exp $
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 <netproto/ncp/ncp.h>
57 #include <netproto/ncp/ncp_conn.h>
58 #include <netproto/ncp/ncp_subr.h>
59
60 #include <sys/thread2.h>
61
62 #include <machine/limits.h>
63
64 #include "nwfs.h"
65 #include "nwfs_node.h"
66 #include "nwfs_subr.h"
67
68 static int nwfs_fastlookup = 1;
69
70 SYSCTL_DECL(_vfs_nwfs);
71 SYSCTL_INT(_vfs_nwfs, OID_AUTO, fastlookup, CTLFLAG_RW, &nwfs_fastlookup, 0, "");
72
73
74 extern int nwfs_pbuf_freecnt;
75
76 #define NWFS_RWCACHE
77
78 static int
79 nwfs_readvdir(struct vnode *vp, struct uio *uio, struct ucred *cred)
80 {
81         struct nwmount *nmp = VTONWFS(vp);
82         int error, count, i;
83         struct nwnode *np = VTONW(vp);
84         struct nw_entry_info fattr;
85         struct vnode *newvp;
86         ncpfid fid;
87         ino_t d_ino;
88         size_t d_namlen;
89         const char *d_name;
90         uint8_t d_type;
91
92         np = VTONW(vp);
93         NCPVNDEBUG("dirname='%s'\n",np->n_name);
94         if (uio->uio_resid < 0 || uio->uio_offset < 0 || uio->uio_offset > INT_MAX)
95                 return (EINVAL);
96         error = 0;
97         count = 0;
98         i = uio->uio_offset; /* offset in directory */
99         if (i == 0) {
100                 error = ncp_initsearch(vp, uio->uio_td, cred);
101                 if (error) {
102                         NCPVNDEBUG("cannot initialize search, error=%d",error);
103                         return( error );
104                 }
105         }
106
107         for (; !error && uio->uio_resid > 0; i++) {
108                 switch (i) {
109                     case 0:             /* `.' */
110                         d_ino = np->n_fid.f_id;
111                         if (d_ino == 0)
112                                 d_ino = NWFS_ROOT_INO;
113                         d_namlen = 1;
114                         d_name = ".";
115                         d_type = DT_DIR;
116                         break;
117                     case 1:             /* `..' */
118                         d_ino = np->n_parent.f_id;
119                         if (d_ino == 0)
120                                 d_ino = NWFS_ROOT_INO;
121                         d_namlen = 2;
122                         d_name = "..";
123                         d_type = DT_DIR;
124                         break;
125                     default:
126                         error = ncp_search_for_file_or_subdir(nmp, &np->n_seq, &fattr, uio->uio_td, cred);
127                         if (error && error < 0x80)
128                                 goto done;
129                         d_ino = fattr.dirEntNum;
130                         d_type = (fattr.attributes & aDIR) ? DT_DIR : DT_REG;
131                         d_namlen = fattr.nameLen;
132                         d_name = fattr.entryName;
133 #if 0
134                         if (error && eofflag) {
135                         /*      *eofflag = 1;*/
136                                 break;
137                         }
138 #endif
139                         break;
140                 }
141                 if (nwfs_fastlookup && !error && i > 1) {
142                         fid.f_id = fattr.dirEntNum;
143                         fid.f_parent = np->n_fid.f_id;
144                         error = nwfs_nget(vp->v_mount, fid, &fattr, vp, &newvp);
145                         if (!error) {
146                                 VTONW(newvp)->n_ctime = VTONW(newvp)->n_vattr.va_ctime.tv_sec;
147                                 vput(newvp);
148                         } else
149                                 error = 0;
150                 }
151                 if (error >= 0x80) {
152                     error = 0;
153                     break;
154                 }
155                 if (vop_write_dirent(&error, uio, d_ino, d_type, d_namlen, d_name))
156                         break;
157         }
158 done:
159         uio->uio_offset = i;
160         return (error);
161 }
162
163 int
164 nwfs_readvnode(struct vnode *vp, struct uio *uiop, struct ucred *cred)
165 {
166         struct nwmount *nmp = VFSTONWFS(vp->v_mount);
167         struct nwnode *np = VTONW(vp);
168         struct thread *td;
169         struct vattr vattr;
170         int error, biosize;
171
172         if (vp->v_type != VREG && vp->v_type != VDIR) {
173                 printf("%s: vn types other than VREG or VDIR are unsupported !\n",__func__);
174                 return EIO;
175         }
176         if (uiop->uio_resid == 0) return 0;
177         if (uiop->uio_offset < 0) return EINVAL;
178 /*      if (uiop->uio_offset + uiop->uio_resid > nmp->nm_maxfilesize)
179                 return (EFBIG);*/
180         td = uiop->uio_td;
181         if (vp->v_type == VDIR) {
182                 error = nwfs_readvdir(vp, uiop, cred);
183                 return error;
184         }
185         biosize = NWFSTOCONN(nmp)->buffer_size;
186         if (np->n_flag & NMODIFIED) {
187                 nwfs_attr_cacheremove(vp);
188                 error = VOP_GETATTR(vp, &vattr, td);
189                 if (error) return (error);
190                 np->n_mtime = vattr.va_mtime.tv_sec;
191         } else {
192                 error = VOP_GETATTR(vp, &vattr, td);
193                 if (error) return (error);
194                 if (np->n_mtime != vattr.va_mtime.tv_sec) {
195                         error = nwfs_vinvalbuf(vp, V_SAVE, td, 1);
196                         if (error) return (error);
197                         np->n_mtime = vattr.va_mtime.tv_sec;
198                 }
199         }
200         error = ncp_read(NWFSTOCONN(nmp), &np->n_fh, uiop,cred);
201         return (error);
202 }
203
204 int
205 nwfs_writevnode(struct vnode *vp, struct uio *uiop, struct ucred *cred,
206                 int ioflag)
207 {
208         struct nwmount *nmp = VTONWFS(vp);
209         struct nwnode *np = VTONW(vp);
210         struct thread *td;
211 /*      struct vattr vattr;*/
212         int error = 0;
213
214         if (vp->v_type != VREG) {
215                 printf("%s: vn types other than VREG unsupported !\n",__func__);
216                 return EIO;
217         }
218         NCPVNDEBUG("ofs=%d,resid=%d\n",(int)uiop->uio_offset, uiop->uio_resid);
219         if (uiop->uio_offset < 0) return EINVAL;
220 /*      if (uiop->uio_offset + uiop->uio_resid > nmp->nm_maxfilesize)
221                 return (EFBIG);*/
222         td = uiop->uio_td;
223         if (ioflag & (IO_APPEND | IO_SYNC)) {
224                 if (np->n_flag & NMODIFIED) {
225                         nwfs_attr_cacheremove(vp);
226                         error = nwfs_vinvalbuf(vp, V_SAVE, td, 1);
227                         if (error) return (error);
228                 }
229                 if (ioflag & IO_APPEND) {
230                 /* We can relay only on local information about file size,
231                  * because until file is closed NetWare will not return
232                  * the correct size. */
233 #if notyet
234                         nwfs_attr_cacheremove(vp);
235                         error = VOP_GETATTR(vp, &vattr, td);
236                         if (error) return (error);
237 #endif
238                         uiop->uio_offset = np->n_size;
239                 }
240         }
241         if (uiop->uio_resid == 0) return 0;
242         if (td->td_proc && uiop->uio_offset + uiop->uio_resid > 
243             td->td_proc->p_rlimit[RLIMIT_FSIZE].rlim_cur) {
244                 psignal(td->td_proc, SIGXFSZ);
245                 return (EFBIG);
246         }
247         error = ncp_write(NWFSTOCONN(nmp), &np->n_fh, uiop, cred);
248         NCPVNDEBUG("after: ofs=%d,resid=%d\n",(int)uiop->uio_offset, uiop->uio_resid);
249         if (!error) {
250                 if (uiop->uio_offset > np->n_size) {
251                         np->n_vattr.va_size = np->n_size = uiop->uio_offset;
252                         vnode_pager_setsize(vp, np->n_size);
253                 }
254         }
255         return (error);
256 }
257
258 /*
259  * Do an I/O operation to/from a cache block.
260  */
261 int
262 nwfs_doio(struct buf *bp, struct ucred *cr, struct thread *td)
263 {
264         struct uio *uiop;
265         struct vnode *vp;
266         struct nwnode *np;
267         struct nwmount *nmp;
268         int error = 0;
269         struct uio uio;
270         struct iovec io;
271
272         vp = bp->b_vp;
273         np = VTONW(vp);
274         nmp = VFSTONWFS(vp->v_mount);
275         uiop = &uio;
276         uiop->uio_iov = &io;
277         uiop->uio_iovcnt = 1;
278         uiop->uio_segflg = UIO_SYSSPACE;
279         uiop->uio_td = td;
280         if (bp->b_flags & B_READ) {
281             io.iov_len = uiop->uio_resid = bp->b_bcount;
282             io.iov_base = bp->b_data;
283             uiop->uio_rw = UIO_READ;
284             switch (vp->v_type) {
285               case VREG:
286                 uiop->uio_offset = ((off_t)bp->b_blkno) * DEV_BSIZE;
287                 error = ncp_read(NWFSTOCONN(nmp), &np->n_fh, uiop, cr);
288                 if (error)
289                         break;
290                 if (uiop->uio_resid) {
291                         int left = uiop->uio_resid;
292                         int nread = bp->b_bcount - left;
293                         if (left > 0)
294                             bzero((char *)bp->b_data + nread, left);
295                 }
296                 break;
297 /*          case VDIR:
298                 nfsstats.readdir_bios++;
299                 uiop->uio_offset = ((u_quad_t)bp->b_lblkno) * NFS_DIRBLKSIZ;
300                 if (nmp->nm_flag & NFSMNT_RDIRPLUS) {
301                         error = nfs_readdirplusrpc(vp, uiop, cr);
302                         if (error == NFSERR_NOTSUPP)
303                                 nmp->nm_flag &= ~NFSMNT_RDIRPLUS;
304                 }
305                 if ((nmp->nm_flag & NFSMNT_RDIRPLUS) == 0)
306                         error = nfs_readdirrpc(vp, uiop, cr);
307                 if (error == 0 && uiop->uio_resid == bp->b_bcount)
308                         bp->b_flags |= B_INVAL;
309                 break;
310 */
311             default:
312                 printf("nwfs_doio:  type %x unexpected\n",vp->v_type);
313                 break;
314             };
315             if (error) {
316                 bp->b_flags |= B_ERROR;
317                 bp->b_error = error;
318             }
319         } else { /* write */
320             if (((bp->b_blkno * DEV_BSIZE) + bp->b_dirtyend) > np->n_size)
321                 bp->b_dirtyend = np->n_size - (bp->b_blkno * DEV_BSIZE);
322
323             if (bp->b_dirtyend > bp->b_dirtyoff) {
324                 io.iov_len = uiop->uio_resid = bp->b_dirtyend - bp->b_dirtyoff;
325                 uiop->uio_offset = ((off_t)bp->b_blkno) * DEV_BSIZE + bp->b_dirtyoff;
326                 io.iov_base = (char *)bp->b_data + bp->b_dirtyoff;
327                 uiop->uio_rw = UIO_WRITE;
328                 error = ncp_write(NWFSTOCONN(nmp), &np->n_fh, uiop, cr);
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
346                         crit_enter();
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                         crit_exit();
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  *
380  * nwfs_getpages(struct vnode *a_vp, vm_page_t *a_m, int a_count,
381  *               int a_reqpage, vm_ooffset_t a_offset)
382  */
383 int
384 nwfs_getpages(struct vop_getpages_args *ap)
385 {
386 #ifndef NWFS_RWCACHE
387         return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
388                 ap->a_reqpage);
389 #else
390         int i, error, nextoff, size, toff, npages, count;
391         struct uio uio;
392         struct iovec iov;
393         vm_offset_t kva;
394         struct buf *bp;
395         struct vnode *vp;
396         struct thread *td = curthread;  /* XXX */
397         struct ucred *cred;
398         struct nwmount *nmp;
399         struct nwnode *np;
400         vm_page_t *pages;
401
402         KKASSERT(td->td_proc);
403         cred = td->td_proc->p_ucred;
404
405         vp = ap->a_vp;
406         np = VTONW(vp);
407         nmp = VFSTONWFS(vp->v_mount);
408         pages = ap->a_m;
409         count = ap->a_count;
410
411         if (vp->v_object == NULL) {
412                 printf("nwfs_getpages: called with non-merged cache vnode??\n");
413                 return VM_PAGER_ERROR;
414         }
415
416         bp = getpbuf(&nwfs_pbuf_freecnt);
417         npages = btoc(count);
418         kva = (vm_offset_t) bp->b_data;
419         pmap_qenter(kva, pages, npages);
420
421         iov.iov_base = (caddr_t) kva;
422         iov.iov_len = count;
423         uio.uio_iov = &iov;
424         uio.uio_iovcnt = 1;
425         uio.uio_offset = IDX_TO_OFF(pages[0]->pindex);
426         uio.uio_resid = count;
427         uio.uio_segflg = UIO_SYSSPACE;
428         uio.uio_rw = UIO_READ;
429         uio.uio_td = td;
430
431         error = ncp_read(NWFSTOCONN(nmp), &np->n_fh, &uio,cred);
432         pmap_qremove(kva, npages);
433
434         relpbuf(bp, &nwfs_pbuf_freecnt);
435
436         if (error && (uio.uio_resid == count)) {
437                 printf("nwfs_getpages: error %d\n",error);
438                 for (i = 0; i < npages; i++) {
439                         if (ap->a_reqpage != i)
440                                 vnode_pager_freepage(pages[i]);
441                 }
442                 return VM_PAGER_ERROR;
443         }
444
445         size = count - uio.uio_resid;
446
447         for (i = 0, toff = 0; i < npages; i++, toff = nextoff) {
448                 vm_page_t m;
449                 nextoff = toff + PAGE_SIZE;
450                 m = pages[i];
451
452                 m->flags &= ~PG_ZERO;
453
454                 if (nextoff <= size) {
455                         m->valid = VM_PAGE_BITS_ALL;
456                         m->dirty = 0;
457                 } else {
458                         int nvalid = ((size + DEV_BSIZE - 1) - toff) & ~(DEV_BSIZE - 1);
459                         vm_page_set_validclean(m, 0, nvalid);
460                 }
461                 
462                 if (i != ap->a_reqpage) {
463                         /*
464                          * Whether or not to leave the page activated is up in
465                          * the air, but we should put the page on a page queue
466                          * somewhere (it already is in the object).  Result:
467                          * It appears that emperical results show that
468                          * deactivating pages is best.
469                          */
470
471                         /*
472                          * Just in case someone was asking for this page we
473                          * now tell them that it is ok to use.
474                          */
475                         if (!error) {
476                                 if (m->flags & PG_WANTED)
477                                         vm_page_activate(m);
478                                 else
479                                         vm_page_deactivate(m);
480                                 vm_page_wakeup(m);
481                         } else {
482                                 vnode_pager_freepage(m);
483                         }
484                 }
485         }
486         return 0;
487 #endif /* NWFS_RWCACHE */
488 }
489
490 /*
491  * Vnode op for VM putpages.
492  * possible bug: all IO done in sync mode
493  * Note that vop_close always invalidate pages before close, so it's
494  * not necessary to open vnode.
495  *
496  * nwfs_putpages(struct vnode *a_vp, vm_page_t *a_m, int a_count,
497  *               int a_sync, int *a_rtvals, vm_ooffset_t a_offset)
498  */
499 int
500 nwfs_putpages(struct vop_putpages_args *ap)
501 {
502         int error;
503         struct thread *td = curthread;  /* XXX */
504         struct vnode *vp = ap->a_vp;
505         struct ucred *cred;
506
507 #ifndef NWFS_RWCACHE
508         KKASSERT(td->td_proc);
509         cred = td->td_proc->p_ucred;            /* XXX */
510         VOP_OPEN(vp, FWRITE, cred, NULL, td);
511         error = vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
512                 ap->a_sync, ap->a_rtvals);
513         VOP_CLOSE(vp, FWRITE, cred, td);
514         return error;
515 #else
516         struct uio uio;
517         struct iovec iov;
518         vm_offset_t kva;
519         struct buf *bp;
520         int i, npages, count;
521         int *rtvals;
522         struct nwmount *nmp;
523         struct nwnode *np;
524         vm_page_t *pages;
525
526         KKASSERT(td->td_proc);
527         cred = td->td_proc->p_ucred;            /* XXX */
528
529 /*      VOP_OPEN(vp, FWRITE, cred, td);*/
530         np = VTONW(vp);
531         nmp = VFSTONWFS(vp->v_mount);
532         pages = ap->a_m;
533         count = ap->a_count;
534         rtvals = ap->a_rtvals;
535         npages = btoc(count);
536
537         for (i = 0; i < npages; i++) {
538                 rtvals[i] = VM_PAGER_AGAIN;
539         }
540
541         bp = getpbuf(&nwfs_pbuf_freecnt);
542         kva = (vm_offset_t) bp->b_data;
543         pmap_qenter(kva, pages, npages);
544
545         iov.iov_base = (caddr_t) kva;
546         iov.iov_len = count;
547         uio.uio_iov = &iov;
548         uio.uio_iovcnt = 1;
549         uio.uio_offset = IDX_TO_OFF(pages[0]->pindex);
550         uio.uio_resid = count;
551         uio.uio_segflg = UIO_SYSSPACE;
552         uio.uio_rw = UIO_WRITE;
553         uio.uio_td = td;
554         NCPVNDEBUG("ofs=%d,resid=%d\n",(int)uio.uio_offset, uio.uio_resid);
555
556         error = ncp_write(NWFSTOCONN(nmp), &np->n_fh, &uio, cred);
557 /*      VOP_CLOSE(vp, FWRITE, cred, td);*/
558         NCPVNDEBUG("paged write done: %d\n", error);
559
560         pmap_qremove(kva, npages);
561         relpbuf(bp, &nwfs_pbuf_freecnt);
562
563         if (!error) {
564                 int nwritten = round_page(count - uio.uio_resid) / PAGE_SIZE;
565                 for (i = 0; i < nwritten; i++) {
566                         rtvals[i] = VM_PAGER_OK;
567                         pages[i]->dirty = 0;
568                 }
569         }
570         return rtvals[0];
571 #endif /* NWFS_RWCACHE */
572 }
573 /*
574  * Flush and invalidate all dirty buffers. If another process is already
575  * doing the flush, just wait for completion.
576  */
577 int
578 nwfs_vinvalbuf(struct vnode *vp, int flags, struct thread *td, int intrflg)
579 {
580         struct nwnode *np = VTONW(vp);
581 /*      struct nwmount *nmp = VTONWFS(vp);*/
582         int error = 0, slpflag, slptimeo;
583
584         if (vp->v_flag & VRECLAIMED) {
585                 return (0);
586         }
587         if (intrflg) {
588                 slpflag = PCATCH;
589                 slptimeo = 2 * hz;
590         } else {
591                 slpflag = 0;
592                 slptimeo = 0;
593         }
594         while (np->n_flag & NFLUSHINPROG) {
595                 np->n_flag |= NFLUSHWANT;
596                 error = tsleep((caddr_t)&np->n_flag, 0, "nwfsvinv", slptimeo);
597                 error = ncp_chkintr(NWFSTOCONN(VTONWFS(vp)), td);
598                 if (error == EINTR && intrflg)
599                         return EINTR;
600         }
601         np->n_flag |= NFLUSHINPROG;
602         error = vinvalbuf(vp, flags, td, slpflag, 0);
603         while (error) {
604                 if (intrflg && (error == ERESTART || error == EINTR)) {
605                         np->n_flag &= ~NFLUSHINPROG;
606                         if (np->n_flag & NFLUSHWANT) {
607                                 np->n_flag &= ~NFLUSHWANT;
608                                 wakeup((caddr_t)&np->n_flag);
609                         }
610                         return EINTR;
611                 }
612                 error = vinvalbuf(vp, flags, td, slpflag, 0);
613         }
614         np->n_flag &= ~(NMODIFIED | NFLUSHINPROG);
615         if (np->n_flag & NFLUSHWANT) {
616                 np->n_flag &= ~NFLUSHWANT;
617                 wakeup((caddr_t)&np->n_flag);
618         }
619         return (error);
620 }