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