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