Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / vfs / smbfs / smbfs_io.c
1 /*
2  * Copyright (c) 2000-2001, 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/fs/smbfs/smbfs_io.c,v 1.3.2.3 2003/01/17 08:20:26 tjr 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/proc.h>
40 #include <sys/fcntl.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 <sys/ioccom.h>
56 */
57 #include <netsmb/smb.h>
58 #include <netsmb/smb_conn.h>
59 #include <netsmb/smb_subr.h>
60
61 #include <fs/smbfs/smbfs.h>
62 #include <fs/smbfs/smbfs_node.h>
63 #include <fs/smbfs/smbfs_subr.h>
64
65 #include <sys/buf.h>
66
67 /*#define SMBFS_RWGENERIC*/
68
69 extern int smbfs_pbuf_freecnt;
70
71 static int smbfs_fastlookup = 1;
72
73 extern struct linker_set sysctl_vfs_smbfs;
74
75 SYSCTL_DECL(_vfs_smbfs);
76 SYSCTL_INT(_vfs_smbfs, OID_AUTO, fastlookup, CTLFLAG_RW, &smbfs_fastlookup, 0, "");
77
78
79 #define DE_SIZE (sizeof(struct dirent))
80
81 static int
82 smbfs_readvdir(struct vnode *vp, struct uio *uio, struct ucred *cred)
83 {
84         struct dirent de;
85         struct componentname cn;
86         struct smb_cred scred;
87         struct smbfs_fctx *ctx;
88         struct vnode *newvp;
89         struct smbnode *np = VTOSMB(vp);
90         int error/*, *eofflag = ap->a_eofflag*/;
91         long offset, limit;
92
93         np = VTOSMB(vp);
94         SMBVDEBUG("dirname='%s'\n", np->n_name);
95         smb_makescred(&scred, uio->uio_procp, cred);
96         offset = uio->uio_offset / DE_SIZE;     /* offset in the directory */
97         limit = uio->uio_resid / DE_SIZE;
98         if (uio->uio_resid < DE_SIZE || uio->uio_offset < 0)
99                 return EINVAL;
100         while (limit && offset < 2) {
101                 limit--;
102                 bzero((caddr_t)&de, DE_SIZE);
103                 de.d_reclen = DE_SIZE;
104                 de.d_fileno = (offset == 0) ? np->n_ino :
105                     (np->n_parent ? VTOSMB(np->n_parent)->n_ino : 2);
106                 if (de.d_fileno == 0)
107                         de.d_fileno = 0x7ffffffd + offset;
108                 de.d_namlen = offset + 1;
109                 de.d_name[0] = '.';
110                 de.d_name[1] = '.';
111                 de.d_name[offset + 1] = '\0';
112                 de.d_type = DT_DIR;
113                 error = uiomove((caddr_t)&de, DE_SIZE, uio);
114                 if (error)
115                         return error;
116                 offset++;
117                 uio->uio_offset += DE_SIZE;
118         }
119         if (limit == 0)
120                 return 0;
121         if (offset != np->n_dirofs || np->n_dirseq == NULL) {
122                 SMBVDEBUG("Reopening search %ld:%ld\n", offset, np->n_dirofs);
123                 if (np->n_dirseq) {
124                         smbfs_findclose(np->n_dirseq, &scred);
125                         np->n_dirseq = NULL;
126                 }
127                 np->n_dirofs = 2;
128                 error = smbfs_findopen(np, "*", 1,
129                     SMB_FA_SYSTEM | SMB_FA_HIDDEN | SMB_FA_DIR,
130                     &scred, &ctx);
131                 if (error) {
132                         SMBVDEBUG("can not open search, error = %d", error);
133                         return error;
134                 }
135                 np->n_dirseq = ctx;
136         } else
137                 ctx = np->n_dirseq;
138         while (np->n_dirofs < offset) {
139                 error = smbfs_findnext(ctx, offset - np->n_dirofs++, &scred);
140                 if (error) {
141                         smbfs_findclose(np->n_dirseq, &scred);
142                         np->n_dirseq = NULL;
143                         return error == ENOENT ? 0 : error;
144                 }
145         }
146         error = 0;
147         for (; limit; limit--, offset++) {
148                 error = smbfs_findnext(ctx, limit, &scred);
149                 if (error)
150                         break;
151                 np->n_dirofs++;
152                 bzero((caddr_t)&de, DE_SIZE);
153                 de.d_reclen = DE_SIZE;
154                 de.d_fileno = ctx->f_attr.fa_ino;
155                 de.d_type = (ctx->f_attr.fa_attr & SMB_FA_DIR) ? DT_DIR : DT_REG;
156                 de.d_namlen = ctx->f_nmlen;
157                 bcopy(ctx->f_name, de.d_name, de.d_namlen);
158                 de.d_name[de.d_namlen] = '\0';
159                 if (smbfs_fastlookup) {
160                         error = smbfs_nget(vp->v_mount, vp, ctx->f_name,
161                             ctx->f_nmlen, &ctx->f_attr, &newvp);
162                         if (!error) {
163                                 cn.cn_nameptr = de.d_name;
164                                 cn.cn_namelen = de.d_namlen;
165                                 cache_enter(vp, newvp, &cn);
166                                 vput(newvp);
167                         }
168                 }
169                 error = uiomove((caddr_t)&de, DE_SIZE, uio);
170                 if (error)
171                         break;
172         }
173         if (error == ENOENT)
174                 error = 0;
175         uio->uio_offset = offset * DE_SIZE;
176         return error;
177 }
178
179 int
180 smbfs_readvnode(struct vnode *vp, struct uio *uiop, struct ucred *cred)
181 {
182         struct smbmount *smp = VFSTOSMBFS(vp->v_mount);
183         struct smbnode *np = VTOSMB(vp);
184         struct proc *p;
185         struct vattr vattr;
186         struct smb_cred scred;
187         int error, lks;
188
189         /*
190          * Protect against method which is not supported for now
191          */
192         if (uiop->uio_segflg == UIO_NOCOPY)
193                 return EOPNOTSUPP;
194
195         if (vp->v_type != VREG && vp->v_type != VDIR) {
196                 SMBFSERR("vn types other than VREG or VDIR are unsupported !\n");
197                 return EIO;
198         }
199         if (uiop->uio_resid == 0)
200                 return 0;
201         if (uiop->uio_offset < 0)
202                 return EINVAL;
203 /*      if (uiop->uio_offset + uiop->uio_resid > smp->nm_maxfilesize)
204                 return EFBIG;*/
205         p = uiop->uio_procp;
206         if (vp->v_type == VDIR) {
207                 lks = LK_EXCLUSIVE;/*lockstatus(&vp->v_lock, p);*/
208                 if (lks == LK_SHARED)
209                         vn_lock(vp, LK_UPGRADE | LK_RETRY, p);
210                 error = smbfs_readvdir(vp, uiop, cred);
211                 if (lks == LK_SHARED)
212                         vn_lock(vp, LK_DOWNGRADE | LK_RETRY, p);
213                 return error;
214         }
215
216 /*      biosize = SSTOCN(smp->sm_share)->sc_txmax;*/
217         if (np->n_flag & NMODIFIED) {
218                 smbfs_attr_cacheremove(vp);
219                 error = VOP_GETATTR(vp, &vattr, cred, p);
220                 if (error)
221                         return error;
222                 np->n_mtime.tv_sec = vattr.va_mtime.tv_sec;
223         } else {
224                 error = VOP_GETATTR(vp, &vattr, cred, p);
225                 if (error)
226                         return error;
227                 if (np->n_mtime.tv_sec != vattr.va_mtime.tv_sec) {
228                         error = smbfs_vinvalbuf(vp, V_SAVE, cred, p, 1);
229                         if (error)
230                                 return error;
231                         np->n_mtime.tv_sec = vattr.va_mtime.tv_sec;
232                 }
233         }
234         smb_makescred(&scred, p, cred);
235         return smb_read(smp->sm_share, np->n_fid, uiop, &scred);
236 }
237
238 int
239 smbfs_writevnode(struct vnode *vp, struct uio *uiop,
240         struct ucred *cred, int ioflag)
241 {
242         struct smbmount *smp = VTOSMBFS(vp);
243         struct smbnode *np = VTOSMB(vp);
244         struct smb_cred scred;
245         struct proc *p;
246         int error = 0;
247
248         if (vp->v_type != VREG) {
249                 SMBERROR("vn types other than VREG unsupported !\n");
250                 return EIO;
251         }
252         SMBVDEBUG("ofs=%d,resid=%d\n",(int)uiop->uio_offset, uiop->uio_resid);
253         if (uiop->uio_offset < 0)
254                 return EINVAL;
255 /*      if (uiop->uio_offset + uiop->uio_resid > smp->nm_maxfilesize)
256                 return (EFBIG);*/
257         p = uiop->uio_procp;
258         if (ioflag & (IO_APPEND | IO_SYNC)) {
259                 if (np->n_flag & NMODIFIED) {
260                         smbfs_attr_cacheremove(vp);
261                         error = smbfs_vinvalbuf(vp, V_SAVE, cred, p, 1);
262                         if (error)
263                                 return error;
264                 }
265                 if (ioflag & IO_APPEND) {
266 #if notyet
267                         /*
268                          * File size can be changed by another client
269                          */
270                         smbfs_attr_cacheremove(vp);
271                         error = VOP_GETATTR(vp, &vattr, cred, p);
272                         if (error) return (error);
273 #endif
274                         uiop->uio_offset = np->n_size;
275                 }
276         }
277         if (uiop->uio_resid == 0)
278                 return 0;
279         if (p && uiop->uio_offset + uiop->uio_resid > p->p_rlimit[RLIMIT_FSIZE].rlim_cur) {
280                 psignal(p, SIGXFSZ);
281                 return EFBIG;
282         }
283         smb_makescred(&scred, p, cred);
284         error = smb_write(smp->sm_share, np->n_fid, uiop, &scred);
285         SMBVDEBUG("after: ofs=%d,resid=%d\n",(int)uiop->uio_offset, uiop->uio_resid);
286         if (!error) {
287                 if (uiop->uio_offset > np->n_size) {
288                         np->n_size = uiop->uio_offset;
289                         vnode_pager_setsize(vp, np->n_size);
290                 }
291         }
292         return error;
293 }
294
295 /*
296  * Do an I/O operation to/from a cache block.
297  */
298 int
299 smbfs_doio(struct buf *bp, struct ucred *cr, struct proc *p)
300 {
301         struct vnode *vp = bp->b_vp;
302         struct smbmount *smp = VFSTOSMBFS(vp->v_mount);
303         struct smbnode *np = VTOSMB(vp);
304         struct uio uio, *uiop = &uio;
305         struct iovec io;
306         struct smb_cred scred;
307         int error = 0;
308
309         uiop->uio_iov = &io;
310         uiop->uio_iovcnt = 1;
311         uiop->uio_segflg = UIO_SYSSPACE;
312         uiop->uio_procp = p;
313
314         smb_makescred(&scred, p, cr);
315
316         if (bp->b_flags & B_READ) {
317             io.iov_len = uiop->uio_resid = bp->b_bcount;
318             io.iov_base = bp->b_data;
319             uiop->uio_rw = UIO_READ;
320             switch (vp->v_type) {
321               case VREG:
322                 uiop->uio_offset = ((off_t)bp->b_blkno) * DEV_BSIZE;
323                 error = smb_read(smp->sm_share, np->n_fid, uiop, &scred);
324                 if (error)
325                         break;
326                 if (uiop->uio_resid) {
327                         int left = uiop->uio_resid;
328                         int nread = bp->b_bcount - left;
329                         if (left > 0)
330                             bzero((char *)bp->b_data + nread, left);
331                 }
332                 break;
333             default:
334                 printf("smbfs_doio:  type %x unexpected\n",vp->v_type);
335                 break;
336             };
337             if (error) {
338                 bp->b_error = error;
339                 bp->b_flags |= B_ERROR;
340             }
341         } else { /* write */
342             if (((bp->b_blkno * DEV_BSIZE) + bp->b_dirtyend) > np->n_size)
343                 bp->b_dirtyend = np->n_size - (bp->b_blkno * DEV_BSIZE);
344
345             if (bp->b_dirtyend > bp->b_dirtyoff) {
346                 io.iov_len = uiop->uio_resid = bp->b_dirtyend - bp->b_dirtyoff;
347                 uiop->uio_offset = ((off_t)bp->b_blkno) * DEV_BSIZE + bp->b_dirtyoff;
348                 io.iov_base = (char *)bp->b_data + bp->b_dirtyoff;
349                 uiop->uio_rw = UIO_WRITE;
350                 bp->b_flags |= B_WRITEINPROG;
351                 error = smb_write(smp->sm_share, np->n_fid, uiop, &scred);
352                 bp->b_flags &= ~B_WRITEINPROG;
353
354                 /*
355                  * For an interrupted write, the buffer is still valid
356                  * and the write hasn't been pushed to the server yet,
357                  * so we can't set BIO_ERROR and report the interruption
358                  * by setting B_EINTR. For the B_ASYNC case, B_EINTR
359                  * is not relevant, so the rpc attempt is essentially
360                  * a noop.  For the case of a V3 write rpc not being
361                  * committed to stable storage, the block is still
362                  * dirty and requires either a commit rpc or another
363                  * write rpc with iomode == NFSV3WRITE_FILESYNC before
364                  * the block is reused. This is indicated by setting
365                  * the B_DELWRI and B_NEEDCOMMIT flags.
366                  */
367                 if (error == EINTR
368                     || (!error && (bp->b_flags & B_NEEDCOMMIT))) {
369                         int s;
370
371                         s = splbio();
372                         bp->b_flags &= ~(B_INVAL|B_NOCACHE);
373                         if ((bp->b_flags & B_ASYNC) == 0)
374                             bp->b_flags |= B_EINTR;
375                         if ((bp->b_flags & B_PAGING) == 0) {
376                             bdirty(bp);
377                             bp->b_flags &= ~B_DONE;
378                         }
379                         if ((bp->b_flags & B_ASYNC) == 0)
380                             bp->b_flags |= B_EINTR;
381                         splx(s);
382                 } else {
383                         if (error) {
384                                 bp->b_flags |= B_ERROR;
385                                 bp->b_error = error;
386                         }
387                         bp->b_dirtyoff = bp->b_dirtyend = 0;
388                 }
389             } else {
390                 bp->b_resid = 0;
391                 biodone(bp);
392                 return 0;
393             }
394         }
395         bp->b_resid = uiop->uio_resid;
396         biodone(bp);
397         return error;
398 }
399
400 /*
401  * Vnode op for VM getpages.
402  * Wish wish .... get rid from multiple IO routines
403  */
404 int
405 smbfs_getpages(ap)
406         struct vop_getpages_args /* {
407                 struct vnode *a_vp;
408                 vm_page_t *a_m;
409                 int a_count;
410                 int a_reqpage;
411                 vm_ooffset_t a_offset;
412         } */ *ap;
413 {
414 #ifdef SMBFS_RWGENERIC
415         return vnode_pager_generic_getpages(ap->a_vp, ap->a_m, ap->a_count,
416                 ap->a_reqpage);
417 #else
418         int i, error, nextoff, size, toff, npages, count;
419         struct uio uio;
420         struct iovec iov;
421         vm_offset_t kva;
422         struct buf *bp;
423         struct vnode *vp;
424         struct proc *p;
425         struct ucred *cred;
426         struct smbmount *smp;
427         struct smbnode *np;
428         struct smb_cred scred;
429         vm_page_t *pages;
430
431         vp = ap->a_vp;
432         p = curproc;                            /* XXX */
433         cred = curproc->p_ucred;                /* XXX */
434         np = VTOSMB(vp);
435         smp = VFSTOSMBFS(vp->v_mount);
436         pages = ap->a_m;
437         count = ap->a_count;
438
439         if (vp->v_object == NULL) {
440                 printf("smbfs_getpages: called with non-merged cache vnode??\n");
441                 return VM_PAGER_ERROR;
442         }
443         smb_makescred(&scred, p, cred);
444
445         bp = getpbuf(&smbfs_pbuf_freecnt);
446         npages = btoc(count);
447         kva = (vm_offset_t) bp->b_data;
448         pmap_qenter(kva, pages, npages);
449
450         iov.iov_base = (caddr_t) kva;
451         iov.iov_len = count;
452         uio.uio_iov = &iov;
453         uio.uio_iovcnt = 1;
454         uio.uio_offset = IDX_TO_OFF(pages[0]->pindex);
455         uio.uio_resid = count;
456         uio.uio_segflg = UIO_SYSSPACE;
457         uio.uio_rw = UIO_READ;
458         uio.uio_procp = p;
459
460         error = smb_read(smp->sm_share, np->n_fid, &uio, &scred);
461         pmap_qremove(kva, npages);
462
463         relpbuf(bp, &smbfs_pbuf_freecnt);
464
465         if (error && (uio.uio_resid == count)) {
466                 printf("smbfs_getpages: error %d\n",error);
467                 for (i = 0; i < npages; i++) {
468                         if (ap->a_reqpage != i)
469                                 vnode_pager_freepage(pages[i]);
470                 }
471                 return VM_PAGER_ERROR;
472         }
473
474         size = count - uio.uio_resid;
475
476         for (i = 0, toff = 0; i < npages; i++, toff = nextoff) {
477                 vm_page_t m;
478                 nextoff = toff + PAGE_SIZE;
479                 m = pages[i];
480
481                 m->flags &= ~PG_ZERO;
482
483                 if (nextoff <= size) {
484                         m->valid = VM_PAGE_BITS_ALL;
485                         m->dirty = 0;
486                 } else {
487                         int nvalid = ((size + DEV_BSIZE - 1) - toff) & ~(DEV_BSIZE - 1);
488                         vm_page_set_validclean(m, 0, nvalid);
489                 }
490                 
491                 if (i != ap->a_reqpage) {
492                         /*
493                          * Whether or not to leave the page activated is up in
494                          * the air, but we should put the page on a page queue
495                          * somewhere (it already is in the object).  Result:
496                          * It appears that emperical results show that
497                          * deactivating pages is best.
498                          */
499
500                         /*
501                          * Just in case someone was asking for this page we
502                          * now tell them that it is ok to use.
503                          */
504                         if (!error) {
505                                 if (m->flags & PG_WANTED)
506                                         vm_page_activate(m);
507                                 else
508                                         vm_page_deactivate(m);
509                                 vm_page_wakeup(m);
510                         } else {
511                                 vnode_pager_freepage(m);
512                         }
513                 }
514         }
515         return 0;
516 #endif /* SMBFS_RWGENERIC */
517 }
518
519 /*
520  * Vnode op for VM putpages.
521  * possible bug: all IO done in sync mode
522  * Note that vop_close always invalidate pages before close, so it's
523  * not necessary to open vnode.
524  */
525 int
526 smbfs_putpages(ap)
527         struct vop_putpages_args /* {
528                 struct vnode *a_vp;
529                 vm_page_t *a_m;
530                 int a_count;
531                 int a_sync;
532                 int *a_rtvals;
533                 vm_ooffset_t a_offset;
534         } */ *ap;
535 {
536         int error;
537         struct vnode *vp = ap->a_vp;
538         struct proc *p;
539         struct ucred *cred;
540
541 #ifdef SMBFS_RWGENERIC
542         p = curproc;                    /* XXX */
543         cred = p->p_ucred;              /* XXX */
544         VOP_OPEN(vp, FWRITE, cred, p);
545         error = vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
546                 ap->a_sync, ap->a_rtvals);
547         VOP_CLOSE(vp, FWRITE, cred, p);
548         return error;
549 #else
550         struct uio uio;
551         struct iovec iov;
552         vm_offset_t kva;
553         struct buf *bp;
554         int i, npages, count;
555         int *rtvals;
556         struct smbmount *smp;
557         struct smbnode *np;
558         struct smb_cred scred;
559         vm_page_t *pages;
560
561         p = curproc;                    /* XXX */
562         cred = p->p_ucred;              /* XXX */
563 /*      VOP_OPEN(vp, FWRITE, cred, p);*/
564         np = VTOSMB(vp);
565         smp = VFSTOSMBFS(vp->v_mount);
566         pages = ap->a_m;
567         count = ap->a_count;
568         rtvals = ap->a_rtvals;
569         npages = btoc(count);
570
571         for (i = 0; i < npages; i++) {
572                 rtvals[i] = VM_PAGER_AGAIN;
573         }
574
575         bp = getpbuf(&smbfs_pbuf_freecnt);
576         kva = (vm_offset_t) bp->b_data;
577         pmap_qenter(kva, pages, npages);
578
579         iov.iov_base = (caddr_t) kva;
580         iov.iov_len = count;
581         uio.uio_iov = &iov;
582         uio.uio_iovcnt = 1;
583         uio.uio_offset = IDX_TO_OFF(pages[0]->pindex);
584         uio.uio_resid = count;
585         uio.uio_segflg = UIO_SYSSPACE;
586         uio.uio_rw = UIO_WRITE;
587         uio.uio_procp = p;
588         SMBVDEBUG("ofs=%d,resid=%d\n",(int)uio.uio_offset, uio.uio_resid);
589
590         smb_makescred(&scred, p, cred);
591         error = smb_write(smp->sm_share, np->n_fid, &uio, &scred);
592 /*      VOP_CLOSE(vp, FWRITE, cred, p);*/
593         SMBVDEBUG("paged write done: %d\n", error);
594
595         pmap_qremove(kva, npages);
596         relpbuf(bp, &smbfs_pbuf_freecnt);
597
598         if (!error) {
599                 int nwritten = round_page(count - uio.uio_resid) / PAGE_SIZE;
600                 for (i = 0; i < nwritten; i++) {
601                         rtvals[i] = VM_PAGER_OK;
602                         pages[i]->dirty = 0;
603                 }
604         }
605         return rtvals[0];
606 #endif /* SMBFS_RWGENERIC */
607 }
608
609 /*
610  * Flush and invalidate all dirty buffers. If another process is already
611  * doing the flush, just wait for completion.
612  */
613 int
614 smbfs_vinvalbuf(vp, flags, cred, p, intrflg)
615         struct vnode *vp;
616         int flags;
617         struct ucred *cred;
618         struct proc *p;
619         int intrflg;
620 {
621         struct smbnode *np = VTOSMB(vp);
622         int error = 0, slpflag, slptimeo;
623
624         if (vp->v_flag & VXLOCK)
625                 return 0;
626         if (intrflg) {
627                 slpflag = PCATCH;
628                 slptimeo = 2 * hz;
629         } else {
630                 slpflag = 0;
631                 slptimeo = 0;
632         }
633         while (np->n_flag & NFLUSHINPROG) {
634                 np->n_flag |= NFLUSHWANT;
635                 error = tsleep((caddr_t)&np->n_flag, PRIBIO + 2, "smfsvinv", slptimeo);
636                 error = smb_proc_intr(p);
637                 if (error == EINTR && intrflg)
638                         return EINTR;
639         }
640         np->n_flag |= NFLUSHINPROG;
641         error = vinvalbuf(vp, flags, cred, p, slpflag, 0);
642         while (error) {
643                 if (intrflg && (error == ERESTART || error == EINTR)) {
644                         np->n_flag &= ~NFLUSHINPROG;
645                         if (np->n_flag & NFLUSHWANT) {
646                                 np->n_flag &= ~NFLUSHWANT;
647                                 wakeup((caddr_t)&np->n_flag);
648                         }
649                         return EINTR;
650                 }
651                 error = vinvalbuf(vp, flags, cred, p, slpflag, 0);
652         }
653         np->n_flag &= ~(NMODIFIED | NFLUSHINPROG);
654         if (np->n_flag & NFLUSHWANT) {
655                 np->n_flag &= ~NFLUSHWANT;
656                 wakeup((caddr_t)&np->n_flag);
657         }
658         return (error);
659 }