| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: genfs_io.c,v 1.9 2009/03/23 11:48:33 pooka Exp $ */ | | 1 | /* $NetBSD: genfs_io.c,v 1.10 2009/03/26 08:22:22 pooka Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2007 Antti Kantee. All Rights Reserved. | | 4 | * Copyright (c) 2007 Antti Kantee. All Rights Reserved. |
5 | * | | 5 | * |
6 | * Development of this software was supported by Google Summer of Code | | 6 | * Development of this software was supported by Google Summer of Code |
7 | * and the Finnish Cultural Foundation. | | 7 | * and the Finnish Cultural Foundation. |
8 | * | | 8 | * |
9 | * Redistribution and use in source and binary forms, with or without | | 9 | * Redistribution and use in source and binary forms, with or without |
10 | * modification, are permitted provided that the following conditions | | 10 | * modification, are permitted provided that the following conditions |
11 | * are met: | | 11 | * are met: |
12 | * 1. Redistributions of source code must retain the above copyright | | 12 | * 1. Redistributions of source code must retain the above copyright |
13 | * notice, this list of conditions and the following disclaimer. | | 13 | * notice, this list of conditions and the following disclaimer. |
14 | * 2. Redistributions in binary form must reproduce the above copyright | | 14 | * 2. Redistributions in binary form must reproduce the above copyright |
| @@ -19,27 +19,27 @@ | | | @@ -19,27 +19,27 @@ |
19 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | | 19 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | | 20 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | | 21 | * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 22 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | | 23 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 24 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 25 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 26 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 27 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
28 | * SUCH DAMAGE. | | 28 | * SUCH DAMAGE. |
29 | */ | | 29 | */ |
30 | | | 30 | |
31 | #include <sys/cdefs.h> | | 31 | #include <sys/cdefs.h> |
32 | __KERNEL_RCSID(0, "$NetBSD: genfs_io.c,v 1.9 2009/03/23 11:48:33 pooka Exp $"); | | 32 | __KERNEL_RCSID(0, "$NetBSD: genfs_io.c,v 1.10 2009/03/26 08:22:22 pooka Exp $"); |
33 | | | 33 | |
34 | #include <sys/param.h> | | 34 | #include <sys/param.h> |
35 | #include <sys/buf.h> | | 35 | #include <sys/buf.h> |
36 | #include <sys/kmem.h> | | 36 | #include <sys/kmem.h> |
37 | #include <sys/lock.h> | | 37 | #include <sys/lock.h> |
38 | #include <sys/vnode.h> | | 38 | #include <sys/vnode.h> |
39 | | | 39 | |
40 | #include <miscfs/genfs/genfs_node.h> | | 40 | #include <miscfs/genfs/genfs_node.h> |
41 | #include <miscfs/genfs/genfs.h> | | 41 | #include <miscfs/genfs/genfs.h> |
42 | | | 42 | |
43 | #include "rump_private.h" | | 43 | #include "rump_private.h" |
44 | | | 44 | |
45 | void | | 45 | void |
| @@ -366,39 +366,39 @@ genfs_do_putpages(struct vnode *vp, off_ | | | @@ -366,39 +366,39 @@ genfs_do_putpages(struct vnode *vp, off_ |
366 | | | 366 | |
367 | curva = datap + (curoff-smallest); | | 367 | curva = datap + (curoff-smallest); |
368 | memcpy(curva, (void *)pg->uanon, PAGE_SIZE); | | 368 | memcpy(curva, (void *)pg->uanon, PAGE_SIZE); |
369 | rumpvm_enterva((vaddr_t)curva, pg); | | 369 | rumpvm_enterva((vaddr_t)curva, pg); |
370 | | | 370 | |
371 | pg->flags |= PG_CLEAN | PG_BUSY; | | 371 | pg->flags |= PG_CLEAN | PG_BUSY; |
372 | } | | 372 | } |
373 | KASSERT(curoff > smallest); | | 373 | KASSERT(curoff > smallest); |
374 | mutex_exit(&uobj->vmobjlock); | | 374 | mutex_exit(&uobj->vmobjlock); |
375 | | | 375 | |
376 | mbp = getiobuf(vp, true); | | 376 | mbp = getiobuf(vp, true); |
377 | mbp->b_bufsize = MAXPHYS; | | 377 | mbp->b_bufsize = MAXPHYS; |
378 | mbp->b_data = datap; | | 378 | mbp->b_data = datap; |
379 | mbp->b_resid = mbp->b_bcount = curoff-smallest; | | 379 | mbp->b_resid = mbp->b_bcount = MIN(curoff,eof)-smallest; |
380 | mbp->b_cflags |= BC_BUSY; | | 380 | mbp->b_cflags |= BC_BUSY; |
381 | mbp->b_flags = B_WRITE; | | 381 | mbp->b_flags = B_WRITE; |
382 | if (async) { | | 382 | if (async) { |
383 | mbp->b_flags |= B_ASYNC; | | 383 | mbp->b_flags |= B_ASYNC; |
384 | mbp->b_iodone = rump_putiodone; | | 384 | mbp->b_iodone = rump_putiodone; |
385 | } | | 385 | } |
386 | mutex_enter(&vp->v_interlock); | | 386 | mutex_enter(&vp->v_interlock); |
387 | ++vp->v_numoutput; | | 387 | ++vp->v_numoutput; |
388 | mutex_exit(&vp->v_interlock); | | 388 | mutex_exit(&vp->v_interlock); |
389 | | | 389 | |
390 | /* then we write */ | | 390 | /* then we write */ |
391 | for (bufoff = 0; bufoff < curoff-smallest; bufoff+=xfersize) { | | 391 | for (bufoff = 0; bufoff < MIN(curoff,eof)-smallest; bufoff+=xfersize) { |
392 | struct vnode *devvp; | | 392 | struct vnode *devvp; |
393 | daddr_t bn, lbn; | | 393 | daddr_t bn, lbn; |
394 | size_t iotodo; | | 394 | size_t iotodo; |
395 | int run, error; | | 395 | int run, error; |
396 | | | 396 | |
397 | lbn = (smallest + bufoff) >> bshift; | | 397 | lbn = (smallest + bufoff) >> bshift; |
398 | error = VOP_BMAP(vp, lbn, &devvp, &bn, &run); | | 398 | error = VOP_BMAP(vp, lbn, &devvp, &bn, &run); |
399 | if (error) | | 399 | if (error) |
400 | panic("%s: VOP_BMAP lazy bum: %d", __func__, error); | | 400 | panic("%s: VOP_BMAP lazy bum: %d", __func__, error); |
401 | | | 401 | |
402 | xfersize = MIN(((lbn+1+run) << bshift) - (smallest+bufoff), | | 402 | xfersize = MIN(((lbn+1+run) << bshift) - (smallest+bufoff), |
403 | curoff - (smallest+bufoff)); | | 403 | curoff - (smallest+bufoff)); |
404 | | | 404 | |
| @@ -409,32 +409,26 @@ genfs_do_putpages(struct vnode *vp, off_ | | | @@ -409,32 +409,26 @@ genfs_do_putpages(struct vnode *vp, off_ |
409 | * enlarged the file. So just ignore those ranges. | | 409 | * enlarged the file. So just ignore those ranges. |
410 | */ | | 410 | */ |
411 | if (bn == -1) { | | 411 | if (bn == -1) { |
412 | skipbytes += xfersize; | | 412 | skipbytes += xfersize; |
413 | continue; | | 413 | continue; |
414 | } | | 414 | } |
415 | | | 415 | |
416 | /* only write max what we are allowed to write */ | | 416 | /* only write max what we are allowed to write */ |
417 | iotodo = xfersize; | | 417 | iotodo = xfersize; |
418 | if (smallest + bufoff + xfersize > eof) | | 418 | if (smallest + bufoff + xfersize > eof) |
419 | iotodo -= (smallest+bufoff+xfersize) - eof; | | 419 | iotodo -= (smallest+bufoff+xfersize) - eof; |
420 | iotodo = (iotodo + DEV_BSIZE-1) & ~(DEV_BSIZE-1); | | 420 | iotodo = (iotodo + DEV_BSIZE-1) & ~(DEV_BSIZE-1); |
421 | | | 421 | |
422 | /* | | | |
423 | * Compensate for potentially smaller write. This will | | | |
424 | * be zero except near eof. | | | |
425 | */ | | | |
426 | skipbytes += xfersize - iotodo; | | | |
427 | | | | |
428 | KASSERT(iotodo > 0); | | 422 | KASSERT(iotodo > 0); |
429 | KASSERT(smallest >= 0); | | 423 | KASSERT(smallest >= 0); |
430 | | | 424 | |
431 | DPRINTF(("putpages writing from %x to %x (vp size %x)\n", | | 425 | DPRINTF(("putpages writing from %x to %x (vp size %x)\n", |
432 | (int)(smallest + bufoff), | | 426 | (int)(smallest + bufoff), |
433 | (int)(smallest + bufoff + iotodo), | | 427 | (int)(smallest + bufoff + iotodo), |
434 | (int)eof)); | | 428 | (int)eof)); |
435 | | | 429 | |
436 | bp = getiobuf(vp, true); | | 430 | bp = getiobuf(vp, true); |
437 | nestiobuf_setup(mbp, bp, bufoff, iotodo); | | 431 | nestiobuf_setup(mbp, bp, bufoff, iotodo); |
438 | bp->b_lblkno = 0; | | 432 | bp->b_lblkno = 0; |
439 | bp->b_blkno = bn + (((smallest+bufoff)&(bsize-1))>>DEV_BSHIFT); | | 433 | bp->b_blkno = bn + (((smallest+bufoff)&(bsize-1))>>DEV_BSHIFT); |
440 | | | 434 | |