]>
git.saurik.com Git - apple/xnu.git/blob - bsd/vfs/vfs_cluster.c
07f0dbbd57c4bd708e8c25f7af49055d0f7ab200
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
25 * The Regents of the University of California. All rights reserved.
27 * Redistribution and use in source and binary forms, with or without
28 * modification, are permitted provided that the following conditions
30 * 1. Redistributions of source code must retain the above copyright
31 * notice, this list of conditions and the following disclaimer.
32 * 2. Redistributions in binary form must reproduce the above copyright
33 * notice, this list of conditions and the following disclaimer in the
34 * documentation and/or other materials provided with the distribution.
35 * 3. All advertising materials mentioning features or use of this software
36 * must display the following acknowledgement:
37 * This product includes software developed by the University of
38 * California, Berkeley and its contributors.
39 * 4. Neither the name of the University nor the names of its contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 * @(#)vfs_cluster.c 8.10 (Berkeley) 3/28/95
58 #include <sys/param.h>
61 #include <sys/vnode.h>
62 #include <sys/mount.h>
63 #include <sys/trace.h>
64 #include <sys/malloc.h>
65 #include <sys/resourcevar.h>
66 #include <libkern/libkern.h>
69 #include <vm/vm_pageout.h>
71 #include <sys/kdebug.h>
75 #define CL_COMMIT 0x04
77 #define CL_PAGEOUT 0x10
80 #define CL_NOZERO 0x80
81 #define CL_PAGEIN 0x100
82 #define CL_DEV_MEMORY 0x200
85 * throttle the number of async writes that
86 * can be outstanding on a single vnode
87 * before we issue a synchronous write
89 #define ASYNC_THROTTLE 9
102 struct buf
*cbp_head
;
103 struct buf
*cbp_next
;
110 cbp_head
= (struct buf
*)(bp
->b_trans_head
);
112 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 20)) | DBG_FUNC_START
,
113 cbp_head
, bp
->b_lblkno
, bp
->b_bcount
, bp
->b_flags
, 0);
115 for (cbp
= cbp_head
; cbp
; cbp
= cbp
->b_trans_next
) {
117 * all I/O requests that are part of this transaction
118 * have to complete before we can process it
120 if ( !(cbp
->b_flags
& B_DONE
)) {
122 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 20)) | DBG_FUNC_END
,
123 cbp_head
, cbp
, cbp
->b_bcount
, cbp
->b_flags
, 0);
133 upl_offset
= cbp
->b_uploffset
;
134 upl
= cbp
->b_pagelist
;
135 b_flags
= cbp
->b_flags
;
136 real_bp
= cbp
->b_real_bp
;
140 if (cbp
->b_vectorcount
> 1)
141 _FREE(cbp
->b_vectorlist
, M_SEGMENT
);
143 if ((cbp
->b_flags
& B_ERROR
) && error
== 0)
144 error
= cbp
->b_error
;
146 total_resid
+= cbp
->b_resid
;
147 total_size
+= cbp
->b_bcount
;
149 cbp_next
= cbp
->b_trans_next
;
155 if ((vp
->v_flag
& VTHROTTLED
) && (vp
->v_numoutput
<= (ASYNC_THROTTLE
/ 3))) {
156 vp
->v_flag
&= ~VTHROTTLED
;
157 wakeup((caddr_t
)&vp
->v_numoutput
);
159 if ((b_flags
& B_NEED_IODONE
) && real_bp
) {
161 real_bp
->b_flags
|= B_ERROR
;
162 real_bp
->b_error
= error
;
164 real_bp
->b_resid
= total_resid
;
168 if (error
== 0 && total_resid
)
171 if (b_flags
& B_COMMIT_UPL
) {
172 pg_offset
= upl_offset
& PAGE_MASK
;
173 commit_size
= (((pg_offset
+ total_size
) + (PAGE_SIZE
- 1)) / PAGE_SIZE
) * PAGE_SIZE
;
175 if (error
|| (b_flags
& B_NOCACHE
)) {
178 if (b_flags
& B_PAGEOUT
)
179 upl_abort_code
= UPL_ABORT_FREE_ON_EMPTY
;
180 else if (b_flags
& B_PGIN
)
181 upl_abort_code
= UPL_ABORT_FREE_ON_EMPTY
| UPL_ABORT_ERROR
;
183 upl_abort_code
= UPL_ABORT_FREE_ON_EMPTY
| UPL_ABORT_DUMP_PAGES
;
185 ubc_upl_abort_range(upl
, upl_offset
- pg_offset
, commit_size
,
188 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 20)) | DBG_FUNC_END
,
189 upl
, upl_offset
- pg_offset
, commit_size
,
190 0x80000000|upl_abort_code
, 0);
193 int upl_commit_flags
= UPL_COMMIT_FREE_ON_EMPTY
;
195 if ( !(b_flags
& B_PAGEOUT
))
196 upl_commit_flags
|= UPL_COMMIT_CLEAR_DIRTY
;
198 upl_commit_flags
|= UPL_COMMIT_INACTIVATE
;
200 ubc_upl_commit_range(upl
, upl_offset
- pg_offset
, commit_size
,
203 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 20)) | DBG_FUNC_END
,
204 upl
, upl_offset
- pg_offset
, commit_size
,
205 upl_commit_flags
, 0);
208 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 20)) | DBG_FUNC_END
,
209 upl
, upl_offset
, 0, error
, 0);
216 cluster_zero(upl
, upl_offset
, size
, flags
, bp
)
218 vm_offset_t upl_offset
;
223 vm_offset_t io_addr
= 0;
226 if ( !(flags
& CL_NOMAP
)) {
227 kret
= ubc_upl_map(upl
, &io_addr
);
229 if (kret
!= KERN_SUCCESS
)
230 panic("cluster_zero: ubc_upl_map() failed with (%d)", kret
);
232 panic("cluster_zero: ubc_upl_map() mapped 0");
234 io_addr
= (vm_offset_t
)bp
->b_data
;
235 bzero((caddr_t
)(io_addr
+ upl_offset
), size
);
237 if ( !(flags
& CL_NOMAP
)) {
238 kret
= ubc_upl_unmap(upl
);
240 if (kret
!= KERN_SUCCESS
)
241 panic("cluster_zero: kernel_upl_unmap failed");
246 cluster_io(vp
, upl
, upl_offset
, f_offset
, size
, flags
, real_bp
)
249 vm_offset_t upl_offset
;
260 struct buf
*cbp_head
= 0;
261 struct buf
*cbp_tail
= 0;
269 if (flags
& CL_READ
) {
270 io_flags
= (B_VECTORLIST
| B_READ
);
272 vfs_io_attributes(vp
, B_READ
, &max_iosize
, &max_vectors
);
274 io_flags
= (B_VECTORLIST
| B_WRITEINPROG
);
276 vfs_io_attributes(vp
, B_WRITE
, &max_iosize
, &max_vectors
);
278 pl
= ubc_upl_pageinfo(upl
);
280 if (flags
& CL_ASYNC
)
281 io_flags
|= (B_CALL
| B_ASYNC
);
285 io_flags
|= B_NOCACHE
;
286 if (flags
& CL_PAGEIN
)
290 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 22)) | DBG_FUNC_START
,
291 (int)f_offset
, size
, upl_offset
, flags
, 0);
293 if ((flags
& CL_READ
) && ((upl_offset
+ size
) & PAGE_MASK
) && (!(flags
& CL_NOZERO
))) {
295 * then we are going to end up
296 * with a page that we can't complete (the file size wasn't a multiple
297 * of PAGE_SIZE and we're trying to read to the end of the file
298 * so we'll go ahead and zero out the portion of the page we can't
299 * read in from the file
301 cluster_zero(upl
, upl_offset
+ size
, PAGE_SIZE
- ((upl_offset
+ size
) & PAGE_MASK
), flags
, real_bp
);
303 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 23)) | DBG_FUNC_NONE
,
304 upl_offset
+ size
, PAGE_SIZE
- ((upl_offset
+ size
) & PAGE_MASK
),
317 if (size
> max_iosize
)
318 io_size
= max_iosize
;
322 if (error
= VOP_CMAP(vp
, f_offset
, io_size
, &blkno
, &io_size
, NULL
)) {
323 if (error
== EOPNOTSUPP
)
324 panic("VOP_CMAP Unimplemented");
328 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 24)) | DBG_FUNC_NONE
,
329 (int)f_offset
, (int)blkno
, io_size
, 0, 0);
331 if ( (!(flags
& CL_READ
) && (long)blkno
== -1) || io_size
== 0) {
332 if (flags
& CL_PAGEOUT
) {
337 /* Try paging out the page individually before
338 giving up entirely and dumping it (it could
339 be mapped in a "hole" and require allocation
342 ubc_upl_abort_range(upl
, upl_offset
, PAGE_SIZE_64
, UPL_ABORT_FREE_ON_EMPTY
);
343 if (ubc_pushdirty_range(vp
, f_offset
, PAGE_SIZE_64
) == 0) {
348 upl_offset
+= PAGE_SIZE_64
;
349 f_offset
+= PAGE_SIZE_64
;
350 size
-= PAGE_SIZE_64
;
353 lblkno
= (daddr_t
)(f_offset
/ PAGE_SIZE_64
);
355 * we have now figured out how much I/O we can do - this is in 'io_size'
356 * pl_index represents the first page in the 'upl' that the I/O will occur for
357 * pg_offset is the starting point in the first page for the I/O
358 * pg_count is the number of full and partial pages that 'io_size' encompasses
360 pl_index
= upl_offset
/ PAGE_SIZE
;
361 pg_offset
= upl_offset
& PAGE_MASK
;
362 pg_count
= (io_size
+ pg_offset
+ (PAGE_SIZE
- 1)) / PAGE_SIZE
;
364 if (flags
& CL_DEV_MEMORY
) {
366 * currently, can't deal with reading 'holes' in file
368 if ((long)blkno
== -1) {
373 * treat physical requests as one 'giant' page
377 if ((flags
& CL_READ
) && (long)blkno
== -1) {
379 * if we're reading and blkno == -1, then we've got a
380 * 'hole' in the file that we need to deal with by zeroing
381 * out the affected area in the upl
383 cluster_zero(upl
, upl_offset
, io_size
, flags
, real_bp
);
385 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 23)) | DBG_FUNC_NONE
,
386 upl_offset
, io_size
, flags
, real_bp
, 0);
388 pg_count
= (io_size
- pg_offset
) / PAGE_SIZE
;
390 if (io_size
== size
&& ((upl_offset
+ io_size
) & PAGE_MASK
))
395 pg_resid
= PAGE_SIZE
- pg_offset
;
398 if (flags
& CL_COMMIT
)
399 ubc_upl_commit_range(upl
,
400 upl_offset
+ pg_resid
,
401 pg_count
* PAGE_SIZE
,
402 UPL_COMMIT_CLEAR_DIRTY
| UPL_COMMIT_FREE_ON_EMPTY
);
404 upl_offset
+= io_size
;
408 if (cbp_head
&& pg_count
)
411 } else if (real_bp
&& (real_bp
->b_blkno
== real_bp
->b_lblkno
)) {
412 real_bp
->b_blkno
= blkno
;
416 if (pg_count
> max_vectors
) {
417 io_size
-= (pg_count
- max_vectors
) * PAGE_SIZE
;
420 io_size
= PAGE_SIZE
- pg_offset
;
423 pg_count
= max_vectors
;
426 * we need to allocate space for the vector list
429 iovp
= (struct iovec
*)_MALLOC(sizeof(struct iovec
) * pg_count
,
430 M_SEGMENT
, M_NOWAIT
);
432 if (iovp
== (struct iovec
*) 0) {
434 * if the allocation fails, then throttle down to a single page
436 io_size
= PAGE_SIZE
- pg_offset
;
442 /* Throttle the speculative IO */
443 if ((flags
& CL_ASYNC
) && !(flags
& CL_PAGEOUT
))
448 cbp
= alloc_io_buf(vp
, priv
);
452 * we use the io vector that's reserved in the buffer header
453 * this insures we can always issue an I/O even in a low memory
454 * condition that prevents the _MALLOC from succeeding... this
455 * is necessary to prevent deadlocks with the pager
457 iovp
= (struct iovec
*)(&cbp
->b_vects
[0]);
459 cbp
->b_vectorlist
= (void *)iovp
;
460 cbp
->b_vectorcount
= pg_count
;
462 if (flags
& CL_DEV_MEMORY
) {
464 iovp
->iov_len
= io_size
;
465 iovp
->iov_base
= (caddr_t
)upl_phys_page(pl
, 0);
467 if (iovp
->iov_base
== (caddr_t
) 0) {
471 iovp
->iov_base
+= upl_offset
;
474 for (i
= 0, vsize
= io_size
; i
< pg_count
; i
++, iovp
++) {
477 psize
= PAGE_SIZE
- pg_offset
;
482 iovp
->iov_len
= psize
;
483 iovp
->iov_base
= (caddr_t
)upl_phys_page(pl
, pl_index
+ i
);
485 if (iovp
->iov_base
== (caddr_t
) 0) {
487 _FREE(cbp
->b_vectorlist
, M_SEGMENT
);
493 iovp
->iov_base
+= pg_offset
;
496 if (flags
& CL_PAGEOUT
) {
501 if (bp
= incore(vp
, lblkno
+ i
)) {
502 if (!ISSET(bp
->b_flags
, B_BUSY
)) {
504 SET(bp
->b_flags
, (B_BUSY
| B_INVAL
));
508 panic("BUSY bp found in cluster_io");
518 if (flags
& CL_ASYNC
)
519 cbp
->b_iodone
= (void *)cluster_iodone
;
520 cbp
->b_flags
|= io_flags
;
522 cbp
->b_lblkno
= lblkno
;
523 cbp
->b_blkno
= blkno
;
524 cbp
->b_bcount
= io_size
;
525 cbp
->b_pagelist
= upl
;
526 cbp
->b_uploffset
= upl_offset
;
527 cbp
->b_trans_next
= (struct buf
*)0;
530 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 26)) | DBG_FUNC_NONE
,
531 cbp
->b_lblkno
, cbp
->b_blkno
, upl_offset
, io_size
, 0);
533 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 27)) | DBG_FUNC_NONE
,
534 cbp
->b_lblkno
, cbp
->b_blkno
, upl_offset
, io_size
, 0);
537 cbp_tail
->b_trans_next
= cbp
;
543 (struct buf
*)(cbp
->b_trans_head
) = cbp_head
;
545 upl_offset
+= io_size
;
549 if ( (!(upl_offset
& PAGE_MASK
) && !(flags
& CL_DEV_MEMORY
)) || size
== 0) {
551 * if we have no more I/O to issue or
552 * the current I/O we've prepared fully
553 * completes the last page in this request
554 * or it's been completed via a zero-fill
555 * due to a 'hole' in the file
556 * then go ahead and issue the I/O
559 if (flags
& CL_COMMIT
)
560 cbp_head
->b_flags
|= B_COMMIT_UPL
;
561 if (flags
& CL_PAGEOUT
)
562 cbp_head
->b_flags
|= B_PAGEOUT
;
563 if (flags
& CL_PAGEIN
)
564 cbp_head
->b_flags
|= B_PGIN
;
567 cbp_head
->b_flags
|= B_NEED_IODONE
;
568 cbp_head
->b_real_bp
= real_bp
;
571 for (cbp
= cbp_head
; cbp
;) {
572 struct buf
* cbp_next
;
574 if (io_flags
& B_WRITEINPROG
)
575 cbp
->b_vp
->v_numoutput
++;
577 cbp_next
= cbp
->b_trans_next
;
579 (void) VOP_STRATEGY(cbp
);
582 if ( !(flags
& CL_ASYNC
)) {
583 for (cbp
= cbp_head
; cbp
; cbp
= cbp
->b_trans_next
)
586 if (error
= cluster_iodone(cbp_head
)) {
591 cbp_head
= (struct buf
*)0;
592 cbp_tail
= (struct buf
*)0;
598 for (cbp
= cbp_head
; cbp
;) {
599 struct buf
* cbp_next
;
601 if (cbp
->b_vectorcount
> 1)
602 _FREE(cbp
->b_vectorlist
, M_SEGMENT
);
603 upl_offset
-= cbp
->b_bcount
;
604 size
+= cbp
->b_bcount
;
606 cbp_next
= cbp
->b_trans_next
;
610 pg_offset
= upl_offset
& PAGE_MASK
;
611 abort_size
= ((size
+ pg_offset
+ (PAGE_SIZE
- 1)) / PAGE_SIZE
) * PAGE_SIZE
;
613 if (flags
& CL_COMMIT
) {
616 if (flags
& CL_PAGEOUT
)
617 upl_abort_code
= UPL_ABORT_FREE_ON_EMPTY
;
618 else if (flags
& CL_PAGEIN
)
619 upl_abort_code
= UPL_ABORT_FREE_ON_EMPTY
| UPL_ABORT_ERROR
;
621 upl_abort_code
= UPL_ABORT_FREE_ON_EMPTY
| UPL_ABORT_DUMP_PAGES
;
623 ubc_upl_abort_range(upl
, upl_offset
- pg_offset
, abort_size
,
626 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 28)) | DBG_FUNC_NONE
,
627 upl
, upl_offset
- pg_offset
, abort_size
, error
, 0);
630 real_bp
->b_flags
|= B_ERROR
;
631 real_bp
->b_error
= error
;
638 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 22)) | DBG_FUNC_END
,
639 (int)f_offset
, size
, upl_offset
, retval
, 0);
646 cluster_rd_prefetch(vp
, f_offset
, size
, filesize
, devblocksize
)
662 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 49)) | DBG_FUNC_START
,
663 (int)f_offset
, size
, (int)filesize
, 0, 0);
665 if (f_offset
>= filesize
) {
666 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 49)) | DBG_FUNC_END
,
667 (int)f_offset
, 0, 0, 0, 0);
670 if (ubc_page_op(vp
, f_offset
, 0, 0, 0) == KERN_SUCCESS
) {
671 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 49)) | DBG_FUNC_END
,
672 (int)f_offset
, 0, 0, 0, 0);
675 if (size
> (MAX_UPL_TRANSFER
* PAGE_SIZE
))
676 size
= MAX_UPL_TRANSFER
* PAGE_SIZE
;
678 size
= (size
+ (PAGE_SIZE
- 1)) & ~(PAGE_SIZE
- 1);
680 if ((off_t
)size
> (filesize
- f_offset
))
681 size
= ((filesize
- f_offset
) + (devblocksize
- 1)) & ~(devblocksize
- 1);
683 pages_in_upl
= (size
+ (PAGE_SIZE
- 1)) / PAGE_SIZE
;
687 pages_in_upl
* PAGE_SIZE
,
692 if (upl
== (upl_t
) 0)
696 * scan from the beginning of the upl looking for the first
697 * non-valid page.... this will become the first page in
698 * the request we're going to make to 'cluster_io'... if all
699 * of the pages are valid, we won't call through to 'cluster_io'
701 for (start_pg
= 0; start_pg
< pages_in_upl
; start_pg
++) {
702 if (!upl_valid_page(pl
, start_pg
))
707 * scan from the starting invalid page looking for a valid
708 * page before the end of the upl is reached, if we
709 * find one, then it will be the last page of the request to
712 for (last_pg
= start_pg
; last_pg
< pages_in_upl
; last_pg
++) {
713 if (upl_valid_page(pl
, last_pg
))
718 * if we find any more free valid pages at the tail of the upl
719 * than update maxra accordingly....
721 for (last_valid
= last_pg
; last_valid
< pages_in_upl
; last_valid
++) {
722 if (!upl_valid_page(pl
, last_valid
))
725 if (start_pg
< last_pg
) {
726 vm_offset_t upl_offset
;
729 * we found a range of 'invalid' pages that must be filled
730 * 'size' has already been clipped to the LEOF
731 * make sure it's at least a multiple of the device block size
733 upl_offset
= start_pg
* PAGE_SIZE
;
734 io_size
= (last_pg
- start_pg
) * PAGE_SIZE
;
736 if ((upl_offset
+ io_size
) > size
) {
737 io_size
= size
- upl_offset
;
739 KERNEL_DEBUG(0xd001000, upl_offset
, size
, io_size
, 0, 0);
741 cluster_io(vp
, upl
, upl_offset
, f_offset
+ upl_offset
, io_size
,
742 CL_READ
| CL_COMMIT
| CL_ASYNC
| CL_AGE
, (struct buf
*)0);
746 * start_pg of non-zero indicates we found some already valid pages
747 * at the beginning of the upl.... we need to release these without
748 * modifying there state
750 ubc_upl_abort_range(upl
, 0, start_pg
* PAGE_SIZE
, UPL_ABORT_FREE_ON_EMPTY
);
752 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 50)) | DBG_FUNC_NONE
,
753 upl
, 0, start_pg
* PAGE_SIZE
, 0, 0);
755 if (last_pg
< pages_in_upl
) {
757 * the set of pages that we issued an I/O for did not extend all the
758 * way to the end of the upl... so just release them without modifying
761 ubc_upl_abort_range(upl
, last_pg
* PAGE_SIZE
, (pages_in_upl
- last_pg
) * PAGE_SIZE
,
762 UPL_ABORT_FREE_ON_EMPTY
);
764 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 50)) | DBG_FUNC_NONE
,
765 upl
, last_pg
* PAGE_SIZE
, (pages_in_upl
- last_pg
) * PAGE_SIZE
, 0, 0);
768 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 49)) | DBG_FUNC_END
,
769 (int)f_offset
+ (last_valid
* PAGE_SIZE
), 0, 0, 0, 0);
777 cluster_rd_ahead(vp
, b_lblkno
, e_lblkno
, filesize
, devblocksize
)
786 int size_of_prefetch
;
789 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 48)) | DBG_FUNC_START
,
790 b_lblkno
, e_lblkno
, vp
->v_lastr
, 0, 0);
792 if (b_lblkno
== vp
->v_lastr
&& b_lblkno
== e_lblkno
) {
793 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 48)) | DBG_FUNC_END
,
794 vp
->v_ralen
, vp
->v_maxra
, vp
->v_lastr
, 0, 0);
798 if (vp
->v_lastr
== -1 || (b_lblkno
!= vp
->v_lastr
&& b_lblkno
!= (vp
->v_lastr
+ 1) && b_lblkno
!= (vp
->v_maxra
+ 1))) {
802 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 48)) | DBG_FUNC_END
,
803 vp
->v_ralen
, vp
->v_maxra
, vp
->v_lastr
, 1, 0);
807 max_pages
= MAX_UPL_TRANSFER
;
809 vp
->v_ralen
= vp
->v_ralen
? min(max_pages
, vp
->v_ralen
<< 1) : 1;
811 if (((e_lblkno
+ 1) - b_lblkno
) > vp
->v_ralen
)
812 vp
->v_ralen
= min(max_pages
, (e_lblkno
+ 1) - b_lblkno
);
814 if (e_lblkno
< vp
->v_maxra
) {
815 if ((vp
->v_maxra
- e_lblkno
) > (max_pages
/ 4)) {
817 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 48)) | DBG_FUNC_END
,
818 vp
->v_ralen
, vp
->v_maxra
, vp
->v_lastr
, 2, 0);
822 r_lblkno
= max(e_lblkno
, vp
->v_maxra
) + 1;
823 f_offset
= (off_t
)r_lblkno
* PAGE_SIZE_64
;
825 size_of_prefetch
= cluster_rd_prefetch(vp
, f_offset
, vp
->v_ralen
* PAGE_SIZE
, filesize
, devblocksize
);
827 if (size_of_prefetch
)
828 vp
->v_maxra
= r_lblkno
+ (size_of_prefetch
- 1);
830 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 48)) | DBG_FUNC_END
,
831 vp
->v_ralen
, vp
->v_maxra
, vp
->v_lastr
, 3, 0);
835 cluster_pageout(vp
, upl
, upl_offset
, f_offset
, size
, filesize
, devblocksize
, flags
)
838 vm_offset_t upl_offset
;
848 int local_flags
= CL_PAGEOUT
;
850 if ((flags
& UPL_IOSYNC
) == 0)
851 local_flags
|= CL_ASYNC
;
852 if ((flags
& UPL_NOCOMMIT
) == 0)
853 local_flags
|= CL_COMMIT
;
855 if (upl
== (upl_t
) 0)
856 panic("cluster_pageout: can't handle NULL upl yet\n");
859 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 52)) | DBG_FUNC_NONE
,
860 (int)f_offset
, size
, (int)filesize
, local_flags
, 0);
863 * If they didn't specify any I/O, then we are done...
864 * we can't issue an abort because we don't know how
865 * big the upl really is
870 if (vp
->v_mount
->mnt_flag
& MNT_RDONLY
) {
871 if (local_flags
& CL_COMMIT
)
872 ubc_upl_abort_range(upl
, upl_offset
, size
,
873 UPL_ABORT_FREE_ON_EMPTY
);
877 * can't page-in from a negative offset
878 * or if we're starting beyond the EOF
879 * or if the file offset isn't page aligned
880 * or the size requested isn't a multiple of PAGE_SIZE
882 if (f_offset
< 0 || f_offset
>= filesize
||
883 (f_offset
& PAGE_MASK_64
) || (size
& PAGE_MASK
)) {
884 if (local_flags
& CL_COMMIT
)
885 ubc_upl_abort_range(upl
, upl_offset
, size
, UPL_ABORT_FREE_ON_EMPTY
);
888 max_size
= filesize
- f_offset
;
893 io_size
= (max_size
+ (devblocksize
- 1)) & ~(devblocksize
- 1);
895 pg_size
= (io_size
+ (PAGE_SIZE
- 1)) & ~PAGE_MASK
;
897 if (size
> pg_size
) {
898 if (local_flags
& CL_COMMIT
)
899 ubc_upl_abort_range(upl
, upl_offset
+ pg_size
, size
- pg_size
,
900 UPL_ABORT_FREE_ON_EMPTY
);
902 while (vp
->v_numoutput
>= ASYNC_THROTTLE
) {
903 vp
->v_flag
|= VTHROTTLED
;
904 tsleep((caddr_t
)&vp
->v_numoutput
, PRIBIO
+ 1, "cluster_pageout", 0);
907 return (cluster_io(vp
, upl
, upl_offset
, f_offset
, io_size
,
908 local_flags
, (struct buf
*)0));
912 cluster_pagein(vp
, upl
, upl_offset
, f_offset
, size
, filesize
, devblocksize
, flags
)
915 vm_offset_t upl_offset
;
930 * If they didn't ask for any data, then we are done...
931 * we can't issue an abort because we don't know how
932 * big the upl really is
937 if ((flags
& UPL_NOCOMMIT
) == 0)
938 local_flags
= CL_COMMIT
;
940 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 56)) | DBG_FUNC_NONE
,
941 (int)f_offset
, size
, (int)filesize
, local_flags
, 0);
944 * can't page-in from a negative offset
945 * or if we're starting beyond the EOF
946 * or if the file offset isn't page aligned
947 * or the size requested isn't a multiple of PAGE_SIZE
949 if (f_offset
< 0 || f_offset
>= filesize
||
950 (f_offset
& PAGE_MASK_64
) || (size
& PAGE_MASK
)) {
951 if (local_flags
& CL_COMMIT
)
952 ubc_upl_abort_range(upl
, upl_offset
, size
,
953 UPL_ABORT_ERROR
| UPL_ABORT_FREE_ON_EMPTY
);
956 max_size
= filesize
- f_offset
;
961 io_size
= (max_size
+ (devblocksize
- 1)) & ~(devblocksize
- 1);
963 pg_size
= (io_size
+ (PAGE_SIZE
- 1)) & ~PAGE_MASK
;
965 if (upl
== (upl_t
) 0) {
973 if (upl
== (upl_t
) 0)
976 upl_offset
= (vm_offset_t
)0;
979 if (size
> pg_size
) {
980 if (local_flags
& CL_COMMIT
)
981 ubc_upl_abort_range(upl
, upl_offset
+ pg_size
, size
- pg_size
,
982 UPL_ABORT_FREE_ON_EMPTY
);
985 retval
= cluster_io(vp
, upl
, upl_offset
, f_offset
, io_size
,
986 local_flags
| CL_READ
| CL_PAGEIN
, (struct buf
*)0);
992 b_lblkno
= (int)(f_offset
/ PAGE_SIZE_64
);
994 ((f_offset
+ ((off_t
)io_size
- 1)) / PAGE_SIZE_64
);
996 if (!(flags
& UPL_NORDAHEAD
) && !(vp
->v_flag
& VRAOFF
)) {
998 * we haven't read the last page in of the file yet
999 * so let's try to read ahead if we're in
1000 * a sequential access pattern
1002 cluster_rd_ahead(vp
, b_lblkno
, e_lblkno
, filesize
, devblocksize
);
1004 vp
->v_lastr
= e_lblkno
;
1016 if (bp
->b_pagelist
== (upl_t
) 0)
1017 panic("cluster_bp: can't handle NULL upl yet\n");
1018 if (bp
->b_flags
& B_READ
)
1019 flags
= CL_ASYNC
| CL_NOMAP
| CL_READ
;
1021 flags
= CL_ASYNC
| CL_NOMAP
;
1023 f_offset
= ubc_blktooff(bp
->b_vp
, bp
->b_lblkno
);
1025 return (cluster_io(bp
->b_vp
, bp
->b_pagelist
, 0, f_offset
, bp
->b_bcount
, flags
, bp
));
1029 cluster_write(vp
, uio
, oldEOF
, newEOF
, headOff
, tailOff
, devblocksize
, flags
)
1043 vm_offset_t upl_offset
;
1046 upl_page_info_t
*pl
;
1052 if ((!uio
) || (uio
->uio_segflg
!= UIO_USERSPACE
) || (!(vp
->v_flag
& VNOCACHE_DATA
)))
1054 retval
= cluster_write_x(vp
, uio
, oldEOF
, newEOF
, headOff
, tailOff
, devblocksize
, flags
);
1058 while (uio
->uio_resid
&& uio
->uio_offset
< newEOF
&& retval
== 0)
1060 /* we know we have a resid, so this is safe */
1062 while (iov
->iov_len
== 0) {
1069 * We check every vector target and if it is physically
1070 * contiguous space, we skip the sanity checks.
1073 upl_offset
= (vm_offset_t
)iov
->iov_base
& ~PAGE_MASK
;
1074 upl_size
= (upl_offset
+ PAGE_SIZE
+(PAGE_SIZE
-1)) & ~PAGE_MASK
;
1076 upl_flags
= UPL_QUERY_OBJECT_TYPE
;
1077 if ((vm_map_get_upl(current_map(),
1078 (vm_offset_t
)iov
->iov_base
& ~PAGE_MASK
,
1079 &upl_size
, &upl
, NULL
, &pages_in_pl
, &upl_flags
, 0)) != KERN_SUCCESS
)
1082 * the user app must have passed in an invalid address
1087 if (upl_flags
& UPL_PHYS_CONTIG
)
1090 * since the interface to the IOKit below us uses physical block #'s and
1091 * block counts to specify the I/O, we can't handle anything that isn't
1092 * devblocksize aligned
1094 if ((uio
->uio_offset
& (devblocksize
- 1)) || (uio
->uio_resid
& (devblocksize
- 1)))
1097 if (flags
& IO_HEADZEROFILL
)
1099 flags
&= ~IO_HEADZEROFILL
;
1101 if (retval
= cluster_write_x(vp
, (struct uio
*)0, 0, uio
->uio_offset
, headOff
, 0, devblocksize
, IO_HEADZEROFILL
))
1105 retval
= cluster_phys_write(vp
, uio
);
1107 if (uio
->uio_resid
== 0 && (flags
& IO_TAILZEROFILL
))
1109 retval
= cluster_write_x(vp
, (struct uio
*)0, 0, tailOff
, uio
->uio_offset
, 0, devblocksize
, IO_HEADZEROFILL
);
1113 else if ((uio
->uio_resid
< 4 * PAGE_SIZE
) || (flags
& (IO_TAILZEROFILL
| IO_HEADZEROFILL
)))
1116 * We set a threshhold of 4 pages to decide if the nocopy
1117 * write loop is worth the trouble...
1118 * we also come here if we're trying to zero the head and/or tail
1119 * of a partially written page, and the user source is not a physically contiguous region
1121 retval
= cluster_write_x(vp
, uio
, oldEOF
, newEOF
, headOff
, tailOff
, devblocksize
, flags
);
1124 else if (uio
->uio_offset
& PAGE_MASK_64
)
1126 /* Bring the file offset write up to a pagesize boundary */
1127 clip_size
= (PAGE_SIZE
- (uio
->uio_offset
& PAGE_MASK_64
));
1128 if (uio
->uio_resid
< clip_size
)
1129 clip_size
= uio
->uio_resid
;
1131 * Fake the resid going into the cluster_write_x call
1132 * and restore it on the way out.
1134 prev_resid
= uio
->uio_resid
;
1135 uio
->uio_resid
= clip_size
;
1136 retval
= cluster_write_x(vp
, uio
, oldEOF
, newEOF
, headOff
, tailOff
, devblocksize
, flags
);
1137 uio
->uio_resid
= prev_resid
- (clip_size
- uio
->uio_resid
);
1139 else if ((int)iov
->iov_base
& PAGE_MASK_64
)
1141 clip_size
= iov
->iov_len
;
1142 prev_resid
= uio
->uio_resid
;
1143 uio
->uio_resid
= clip_size
;
1144 retval
= cluster_write_x(vp
, uio
, oldEOF
, newEOF
, headOff
, tailOff
, devblocksize
, flags
);
1145 uio
->uio_resid
= prev_resid
- (clip_size
- uio
->uio_resid
);
1150 * If we come in here, we know the offset into
1151 * the file is on a pagesize boundary
1154 max_io_size
= newEOF
- uio
->uio_offset
;
1155 clip_size
= uio
->uio_resid
;
1156 if (iov
->iov_len
< clip_size
)
1157 clip_size
= iov
->iov_len
;
1158 if (max_io_size
< clip_size
)
1159 clip_size
= max_io_size
;
1161 if (clip_size
< PAGE_SIZE
)
1164 * Take care of tail end of write in this vector
1166 prev_resid
= uio
->uio_resid
;
1167 uio
->uio_resid
= clip_size
;
1168 retval
= cluster_write_x(vp
, uio
, oldEOF
, newEOF
, headOff
, tailOff
, devblocksize
, flags
);
1169 uio
->uio_resid
= prev_resid
- (clip_size
- uio
->uio_resid
);
1173 /* round clip_size down to a multiple of pagesize */
1174 clip_size
= clip_size
& ~(PAGE_MASK
);
1175 prev_resid
= uio
->uio_resid
;
1176 uio
->uio_resid
= clip_size
;
1177 retval
= cluster_nocopy_write(vp
, uio
, newEOF
, devblocksize
, flags
);
1178 if ((retval
== 0) && uio
->uio_resid
)
1179 retval
= cluster_write_x(vp
, uio
, oldEOF
, newEOF
, headOff
, tailOff
, devblocksize
, flags
);
1180 uio
->uio_resid
= prev_resid
- (clip_size
- uio
->uio_resid
);
1188 cluster_nocopy_write(vp
, uio
, newEOF
, devblocksize
, flags
)
1196 upl_page_info_t
*pl
;
1198 vm_offset_t upl_offset
;
1202 int upl_needed_size
;
1208 int force_data_sync
;
1211 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 75)) | DBG_FUNC_START
,
1212 (int)uio
->uio_offset
, (int)uio
->uio_resid
,
1213 (int)newEOF
, devblocksize
, 0);
1216 * When we enter this routine, we know
1217 * -- the offset into the file is on a pagesize boundary
1218 * -- the resid is a page multiple
1219 * -- the resid will not exceed iov_len
1224 while (uio
->uio_resid
&& uio
->uio_offset
< newEOF
&& error
== 0) {
1225 io_size
= uio
->uio_resid
;
1227 if (io_size
> (MAX_UPL_TRANSFER
* PAGE_SIZE
))
1228 io_size
= MAX_UPL_TRANSFER
* PAGE_SIZE
;
1230 upl_offset
= (vm_offset_t
)iov
->iov_base
& PAGE_MASK_64
;
1231 upl_needed_size
= (upl_offset
+ io_size
+ (PAGE_SIZE
-1)) & ~PAGE_MASK
;
1233 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 76)) | DBG_FUNC_START
,
1234 (int)upl_offset
, upl_needed_size
, iov
->iov_base
, io_size
, 0);
1236 for (force_data_sync
= 0; force_data_sync
< 3; force_data_sync
++)
1239 upl_size
= upl_needed_size
;
1240 upl_flags
= UPL_COPYOUT_FROM
| UPL_NO_SYNC
| UPL_CLEAN_IN_PLACE
| UPL_SET_INTERNAL
;
1242 kret
= vm_map_get_upl(current_map(),
1243 (vm_offset_t
)iov
->iov_base
& ~PAGE_MASK
,
1251 if (kret
!= KERN_SUCCESS
)
1253 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 76)) | DBG_FUNC_END
,
1256 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 75)) | DBG_FUNC_END
,
1257 (int)uio
->uio_offset
, (int)uio
->uio_resid
, kret
, 1, 0);
1259 /* cluster_nocopy_write: failed to get pagelist */
1260 /* do not return kret here */
1264 pl
= UPL_GET_INTERNAL_PAGE_LIST(upl
);
1265 pages_in_pl
= upl_size
/ PAGE_SIZE
;
1267 for(i
=0; i
< pages_in_pl
; i
++)
1269 if (!upl_valid_page(pl
, i
))
1273 if (i
== pages_in_pl
)
1276 ubc_upl_abort_range(upl
, (upl_offset
& ~PAGE_MASK
), upl_size
,
1277 UPL_ABORT_FREE_ON_EMPTY
);
1280 if (force_data_sync
>= 3)
1282 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 76)) | DBG_FUNC_END
,
1283 i
, pages_in_pl
, upl_size
, kret
, 0);
1285 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 75)) | DBG_FUNC_END
,
1286 (int)uio
->uio_offset
, (int)uio
->uio_resid
, kret
, 2, 0);
1291 * Consider the possibility that upl_size wasn't satisfied.
1293 if (upl_size
!= upl_needed_size
)
1294 io_size
= (upl_size
- (int)upl_offset
) & ~PAGE_MASK
;
1296 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 76)) | DBG_FUNC_END
,
1297 (int)upl_offset
, upl_size
, iov
->iov_base
, io_size
, 0);
1301 ubc_upl_abort_range(upl
, (upl_offset
& ~PAGE_MASK
), upl_size
,
1302 UPL_ABORT_FREE_ON_EMPTY
);
1303 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 75)) | DBG_FUNC_END
,
1304 (int)uio
->uio_offset
, uio
->uio_resid
, 0, 3, 0);
1310 * Now look for pages already in the cache
1311 * and throw them away.
1314 upl_f_offset
= uio
->uio_offset
; /* this is page aligned in the file */
1315 max_io_size
= io_size
;
1317 while (max_io_size
) {
1320 * Flag UPL_POP_DUMP says if the page is found
1321 * in the page cache it must be thrown away.
1325 UPL_POP_SET
| UPL_POP_BUSY
| UPL_POP_DUMP
,
1327 max_io_size
-= PAGE_SIZE
;
1328 upl_f_offset
+= PAGE_SIZE
;
1332 * issue a synchronous write to cluster_io
1335 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 77)) | DBG_FUNC_START
,
1336 (int)upl_offset
, (int)uio
->uio_offset
, io_size
, 0, 0);
1338 error
= cluster_io(vp
, upl
, upl_offset
, uio
->uio_offset
,
1339 io_size
, 0, (struct buf
*)0);
1343 * The cluster_io write completed successfully,
1344 * update the uio structure.
1346 iov
->iov_base
+= io_size
;
1347 iov
->iov_len
-= io_size
;
1348 uio
->uio_resid
-= io_size
;
1349 uio
->uio_offset
+= io_size
;
1352 * always 'commit' the I/O via the abort primitive whether the I/O
1353 * succeeded cleanly or not... this is necessary to insure that
1354 * we preserve the state of the DIRTY flag on the pages used to
1355 * provide the data for the I/O... the state of this flag SHOULD
1356 * NOT be changed by a write
1358 ubc_upl_abort_range(upl
, (upl_offset
& ~PAGE_MASK
), upl_size
,
1359 UPL_ABORT_FREE_ON_EMPTY
);
1362 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 77)) | DBG_FUNC_END
,
1363 (int)upl_offset
, (int)uio
->uio_offset
, (int)uio
->uio_resid
, error
, 0);
1368 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 75)) | DBG_FUNC_END
,
1369 (int)uio
->uio_offset
, (int)uio
->uio_resid
, error
, 4, 0);
1375 cluster_phys_write(vp
, uio
)
1380 vm_offset_t upl_offset
;
1383 int upl_needed_size
;
1391 * When we enter this routine, we know
1392 * -- the resid will not exceed iov_len
1393 * -- the vector target address is physcially contiguous
1397 io_size
= iov
->iov_len
;
1398 upl_offset
= (vm_offset_t
)iov
->iov_base
& PAGE_MASK_64
;
1399 upl_needed_size
= upl_offset
+ io_size
;
1402 upl_size
= upl_needed_size
;
1403 upl_flags
= UPL_COPYOUT_FROM
| UPL_NO_SYNC
| UPL_CLEAN_IN_PLACE
| UPL_SET_INTERNAL
;
1405 kret
= vm_map_get_upl(current_map(),
1406 (vm_offset_t
)iov
->iov_base
& ~PAGE_MASK
,
1407 &upl_size
, &upl
, NULL
, &pages_in_pl
, &upl_flags
, 0);
1409 if (kret
!= KERN_SUCCESS
)
1411 /* cluster_phys_write: failed to get pagelist */
1412 /* note: return kret here */
1417 * Consider the possibility that upl_size wasn't satisfied.
1418 * This is a failure in the physical memory case.
1420 if (upl_size
< upl_needed_size
)
1422 kernel_upl_abort_range(upl
, 0, upl_size
, UPL_ABORT_FREE_ON_EMPTY
);
1427 * issue a synchronous write to cluster_io
1430 error
= cluster_io(vp
, upl
, upl_offset
, uio
->uio_offset
,
1431 io_size
, CL_DEV_MEMORY
, (struct buf
*)0);
1435 * The cluster_io write completed successfully,
1436 * update the uio structure and commit.
1439 ubc_upl_commit_range(upl
, 0, upl_size
, UPL_COMMIT_FREE_ON_EMPTY
);
1441 iov
->iov_base
+= io_size
;
1442 iov
->iov_len
-= io_size
;
1443 uio
->uio_resid
-= io_size
;
1444 uio
->uio_offset
+= io_size
;
1447 ubc_upl_abort_range(upl
, 0, upl_size
, UPL_ABORT_FREE_ON_EMPTY
);
1453 cluster_write_x(vp
, uio
, oldEOF
, newEOF
, headOff
, tailOff
, devblocksize
, flags
)
1463 upl_page_info_t
*pl
;
1465 vm_offset_t upl_offset
;
1472 int io_size_before_rounding
;
1474 vm_offset_t io_address
;
1481 long long total_size
;
1484 long long zero_cnt1
;
1486 daddr_t start_blkno
;
1490 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 40)) | DBG_FUNC_START
,
1491 (int)uio
->uio_offset
, uio
->uio_resid
, (int)oldEOF
, (int)newEOF
, 0);
1493 uio_resid
= uio
->uio_resid
;
1495 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 40)) | DBG_FUNC_START
,
1496 0, 0, (int)oldEOF
, (int)newEOF
, 0);
1503 if (flags
& IO_HEADZEROFILL
) {
1505 * some filesystems (HFS is one) don't support unallocated holes within a file...
1506 * so we zero fill the intervening space between the old EOF and the offset
1507 * where the next chunk of real data begins.... ftruncate will also use this
1508 * routine to zero fill to the new EOF when growing a file... in this case, the
1509 * uio structure will not be provided
1512 if (headOff
< uio
->uio_offset
) {
1513 zero_cnt
= uio
->uio_offset
- headOff
;
1516 } else if (headOff
< newEOF
) {
1517 zero_cnt
= newEOF
- headOff
;
1521 if (flags
& IO_TAILZEROFILL
) {
1523 zero_off1
= uio
->uio_offset
+ uio
->uio_resid
;
1525 if (zero_off1
< tailOff
)
1526 zero_cnt1
= tailOff
- zero_off1
;
1529 if (zero_cnt
== 0 && uio
== (struct uio
*) 0)
1531 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 40)) | DBG_FUNC_END
,
1532 retval
, 0, 0, 0, 0);
1536 while ((total_size
= (uio_resid
+ zero_cnt
+ zero_cnt1
)) && retval
== 0) {
1538 * for this iteration of the loop, figure out where our starting point is
1541 start_offset
= (int)(zero_off
& PAGE_MASK_64
);
1542 upl_f_offset
= zero_off
- start_offset
;
1543 } else if (uio_resid
) {
1544 start_offset
= (int)(uio
->uio_offset
& PAGE_MASK_64
);
1545 upl_f_offset
= uio
->uio_offset
- start_offset
;
1547 start_offset
= (int)(zero_off1
& PAGE_MASK_64
);
1548 upl_f_offset
= zero_off1
- start_offset
;
1550 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 46)) | DBG_FUNC_NONE
,
1551 (int)zero_off
, (int)zero_cnt
, (int)zero_off1
, (int)zero_cnt1
, 0);
1553 if (total_size
> (MAX_UPL_TRANSFER
* PAGE_SIZE
))
1554 total_size
= MAX_UPL_TRANSFER
* PAGE_SIZE
;
1557 * compute the size of the upl needed to encompass
1558 * the requested write... limit each call to cluster_io
1559 * to the maximum UPL size... cluster_io will clip if
1560 * this exceeds the maximum io_size for the device,
1561 * make sure to account for
1562 * a starting offset that's not page aligned
1564 upl_size
= (start_offset
+ total_size
+ (PAGE_SIZE
- 1)) & ~PAGE_MASK
;
1566 if (upl_size
> (MAX_UPL_TRANSFER
* PAGE_SIZE
))
1567 upl_size
= MAX_UPL_TRANSFER
* PAGE_SIZE
;
1569 pages_in_upl
= upl_size
/ PAGE_SIZE
;
1570 io_size
= upl_size
- start_offset
;
1572 if ((long long)io_size
> total_size
)
1573 io_size
= total_size
;
1575 start_blkno
= (daddr_t
)(upl_f_offset
/ PAGE_SIZE_64
);
1576 last_blkno
= start_blkno
+ pages_in_upl
;
1578 kret
= ubc_create_upl(vp
,
1584 if (kret
!= KERN_SUCCESS
)
1585 panic("cluster_write: failed to get pagelist");
1587 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 41)) | DBG_FUNC_NONE
,
1588 upl
, (int)upl_f_offset
, upl_size
, start_offset
, 0);
1590 if (start_offset
&& !upl_valid_page(pl
, 0)) {
1594 * we're starting in the middle of the first page of the upl
1595 * and the page isn't currently valid, so we're going to have
1596 * to read it in first... this is a synchronous operation
1598 read_size
= PAGE_SIZE
;
1600 if ((upl_f_offset
+ read_size
) > newEOF
) {
1601 read_size
= newEOF
- upl_f_offset
;
1602 read_size
= (read_size
+ (devblocksize
- 1)) & ~(devblocksize
- 1);
1604 retval
= cluster_io(vp
, upl
, 0, upl_f_offset
, read_size
,
1605 CL_READ
, (struct buf
*)0);
1608 * we had an error during the read which causes us to abort
1609 * the current cluster_write request... before we do, we need
1610 * to release the rest of the pages in the upl without modifying
1611 * there state and mark the failed page in error
1613 ubc_upl_abort_range(upl
, 0, PAGE_SIZE
, UPL_ABORT_DUMP_PAGES
);
1614 ubc_upl_abort(upl
, 0);
1616 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 45)) | DBG_FUNC_NONE
,
1617 upl
, 0, 0, retval
, 0);
1621 if ((start_offset
== 0 || upl_size
> PAGE_SIZE
) && ((start_offset
+ io_size
) & PAGE_MASK
)) {
1623 * the last offset we're writing to in this upl does not end on a page
1624 * boundary... if it's not beyond the old EOF, then we'll also need to
1625 * pre-read this page in if it isn't already valid
1627 upl_offset
= upl_size
- PAGE_SIZE
;
1629 if ((upl_f_offset
+ start_offset
+ io_size
) < oldEOF
&&
1630 !upl_valid_page(pl
, upl_offset
/ PAGE_SIZE
)) {
1633 read_size
= PAGE_SIZE
;
1635 if ((upl_f_offset
+ upl_offset
+ read_size
) > newEOF
) {
1636 read_size
= newEOF
- (upl_f_offset
+ upl_offset
);
1637 read_size
= (read_size
+ (devblocksize
- 1)) & ~(devblocksize
- 1);
1639 retval
= cluster_io(vp
, upl
, upl_offset
, upl_f_offset
+ upl_offset
, read_size
,
1640 CL_READ
, (struct buf
*)0);
1643 * we had an error during the read which causes us to abort
1644 * the current cluster_write request... before we do, we
1645 * need to release the rest of the pages in the upl without
1646 * modifying there state and mark the failed page in error
1648 ubc_upl_abort_range(upl
, upl_offset
, PAGE_SIZE
,
1649 UPL_ABORT_DUMP_PAGES
);
1650 ubc_upl_abort(upl
, 0);
1652 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 45)) | DBG_FUNC_NONE
,
1653 upl
, 0, 0, retval
, 0);
1658 if ((kret
= ubc_upl_map(upl
, &io_address
)) != KERN_SUCCESS
)
1659 panic("cluster_write: ubc_upl_map failed\n");
1660 xfer_resid
= io_size
;
1661 io_offset
= start_offset
;
1663 while (zero_cnt
&& xfer_resid
) {
1665 if (zero_cnt
< (long long)xfer_resid
)
1666 bytes_to_zero
= zero_cnt
;
1668 bytes_to_zero
= xfer_resid
;
1670 if ( !(flags
& IO_NOZEROVALID
)) {
1671 bzero((caddr_t
)(io_address
+ io_offset
), bytes_to_zero
);
1673 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 43)) | DBG_FUNC_NONE
,
1674 (int)upl_f_offset
+ io_offset
, bytes_to_zero
,
1675 (int)zero_cnt
, xfer_resid
, 0);
1677 bytes_to_zero
= min(bytes_to_zero
, PAGE_SIZE
- (int)(zero_off
& PAGE_MASK_64
));
1679 if ( !upl_valid_page(pl
, (int)(zero_off
/ PAGE_SIZE_64
))) {
1680 bzero((caddr_t
)(io_address
+ io_offset
), bytes_to_zero
);
1682 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 43)) | DBG_FUNC_NONE
,
1683 (int)upl_f_offset
+ io_offset
, bytes_to_zero
,
1684 (int)zero_cnt
, xfer_resid
, 0);
1687 xfer_resid
-= bytes_to_zero
;
1688 zero_cnt
-= bytes_to_zero
;
1689 zero_off
+= bytes_to_zero
;
1690 io_offset
+= bytes_to_zero
;
1692 if (xfer_resid
&& uio_resid
) {
1693 bytes_to_move
= min(uio_resid
, xfer_resid
);
1695 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 42)) | DBG_FUNC_NONE
,
1696 (int)uio
->uio_offset
, bytes_to_move
, uio_resid
, xfer_resid
, 0);
1698 retval
= uiomove((caddr_t
)(io_address
+ io_offset
), bytes_to_move
, uio
);
1701 if ((kret
= ubc_upl_unmap(upl
)) != KERN_SUCCESS
)
1702 panic("cluster_write: kernel_upl_unmap failed\n");
1703 ubc_upl_abort(upl
, UPL_ABORT_DUMP_PAGES
);
1705 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 45)) | DBG_FUNC_NONE
,
1706 upl
, 0, 0, retval
, 0);
1708 uio_resid
-= bytes_to_move
;
1709 xfer_resid
-= bytes_to_move
;
1710 io_offset
+= bytes_to_move
;
1713 while (xfer_resid
&& zero_cnt1
&& retval
== 0) {
1715 if (zero_cnt1
< (long long)xfer_resid
)
1716 bytes_to_zero
= zero_cnt1
;
1718 bytes_to_zero
= xfer_resid
;
1720 if ( !(flags
& IO_NOZEROVALID
)) {
1721 bzero((caddr_t
)(io_address
+ io_offset
), bytes_to_zero
);
1723 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 43)) | DBG_FUNC_NONE
,
1724 (int)upl_f_offset
+ io_offset
,
1725 bytes_to_zero
, (int)zero_cnt1
, xfer_resid
, 0);
1727 bytes_to_zero
= min(bytes_to_zero
, PAGE_SIZE
- (int)(zero_off1
& PAGE_MASK_64
));
1728 if ( !upl_valid_page(pl
, (int)(zero_off1
/ PAGE_SIZE_64
))) {
1729 bzero((caddr_t
)(io_address
+ io_offset
), bytes_to_zero
);
1731 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 43)) | DBG_FUNC_NONE
,
1732 (int)upl_f_offset
+ io_offset
,
1733 bytes_to_zero
, (int)zero_cnt1
, xfer_resid
, 0);
1736 xfer_resid
-= bytes_to_zero
;
1737 zero_cnt1
-= bytes_to_zero
;
1738 zero_off1
+= bytes_to_zero
;
1739 io_offset
+= bytes_to_zero
;
1746 io_size
+= start_offset
;
1748 if ((upl_f_offset
+ io_size
) == newEOF
&& io_size
< upl_size
) {
1750 * if we're extending the file with this write
1751 * we'll zero fill the rest of the page so that
1752 * if the file gets extended again in such a way as to leave a
1753 * hole starting at this EOF, we'll have zero's in the correct spot
1755 bzero((caddr_t
)(io_address
+ io_size
), upl_size
- io_size
);
1757 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 43)) | DBG_FUNC_NONE
,
1758 (int)upl_f_offset
+ io_size
,
1759 upl_size
- io_size
, 0, 0, 0);
1761 if ((kret
= ubc_upl_unmap(upl
)) != KERN_SUCCESS
)
1762 panic("cluster_write: kernel_upl_unmap failed\n");
1764 io_size_before_rounding
= io_size
;
1766 if (io_size
& (devblocksize
- 1))
1767 io_size
= (io_size
+ (devblocksize
- 1)) & ~(devblocksize
- 1);
1776 * we have an existing cluster... see if this write will extend it nicely
1778 if (start_blkno
>= vp
->v_cstart
) {
1779 if (last_blkno
<= (vp
->v_cstart
+ vp
->v_clen
)) {
1781 * we have a write that fits entirely
1782 * within the existing cluster limits
1784 if (last_blkno
>= vp
->v_lastw
) {
1786 * if we're extending the dirty region within the cluster
1787 * we need to update the cluster info... we check for blkno
1788 * equality because we may be extending the file with a
1789 * partial write.... this in turn changes our idea of how
1790 * much data to write out (v_ciosiz) for the last page
1792 vp
->v_lastw
= last_blkno
;
1793 newsize
= io_size
+ ((start_blkno
- vp
->v_cstart
) * PAGE_SIZE
);
1795 if (newsize
> vp
->v_ciosiz
)
1796 vp
->v_ciosiz
= newsize
;
1801 if (start_blkno
< (vp
->v_cstart
+ vp
->v_clen
)) {
1803 * we have a write that starts in the middle of the current cluster
1804 * but extends beyond the cluster's limit
1805 * we'll clip the current cluster if we actually
1806 * overlap with the new write and then push it out
1807 * and start a new cluster with the current write
1809 if (vp
->v_lastw
> start_blkno
) {
1810 vp
->v_lastw
= start_blkno
;
1811 vp
->v_ciosiz
= (vp
->v_lastw
- vp
->v_cstart
) * PAGE_SIZE
;
1815 * we also get here for the case where the current write starts
1816 * beyond the limit of the existing cluster
1822 * the current write starts in front of the current cluster
1824 if (last_blkno
> vp
->v_cstart
) {
1826 * the current write extends into the existing cluster
1828 if ((vp
->v_lastw
- start_blkno
) > vp
->v_clen
) {
1830 * if we were to combine this write with the current cluster
1831 * we would exceed the cluster size limit....
1832 * clip the current cluster by moving the start position
1833 * to where the current write ends, and then push it
1835 vp
->v_ciosiz
-= (last_blkno
- vp
->v_cstart
) * PAGE_SIZE
;
1836 vp
->v_cstart
= last_blkno
;
1839 * round up the io_size to the nearest page size
1840 * since we've coalesced with at least 1 pre-existing
1841 * page in the current cluster... this write may have ended in the
1842 * middle of the page which would cause io_size to give us an
1843 * inaccurate view of how much I/O we actually need to do
1845 io_size
= (io_size
+ (PAGE_SIZE
- 1)) & ~PAGE_MASK
;
1851 * we can coalesce the current write with the existing cluster
1852 * adjust the cluster info to reflect this
1854 if (last_blkno
> vp
->v_lastw
) {
1856 * the current write completey overlaps
1857 * the existing cluster
1859 vp
->v_lastw
= last_blkno
;
1860 vp
->v_ciosiz
= io_size
;
1862 vp
->v_ciosiz
+= (vp
->v_cstart
- start_blkno
) * PAGE_SIZE
;
1864 if (io_size
> vp
->v_ciosiz
)
1865 vp
->v_ciosiz
= io_size
;
1867 vp
->v_cstart
= start_blkno
;
1872 * this I/O range is entirely in front of the current cluster
1873 * so we need to push the current cluster out before beginning
1882 if (io_size_before_rounding
< (MAX_UPL_TRANSFER
* PAGE_SIZE
) && !(flags
& IO_SYNC
)) {
1883 vp
->v_clen
= MAX_UPL_TRANSFER
;
1884 vp
->v_cstart
= start_blkno
;
1885 vp
->v_lastw
= last_blkno
;
1886 vp
->v_ciosiz
= io_size
;
1892 ubc_upl_commit_range(upl
, 0, upl_size
,
1893 UPL_COMMIT_SET_DIRTY
| UPL_COMMIT_FREE_ON_EMPTY
);
1896 if (flags
& IO_SYNC
)
1897 io_flags
= CL_COMMIT
| CL_AGE
;
1899 io_flags
= CL_COMMIT
| CL_AGE
| CL_ASYNC
;
1901 if (vp
->v_flag
& VNOCACHE_DATA
)
1902 io_flags
|= CL_DUMP
;
1904 while (vp
->v_numoutput
>= ASYNC_THROTTLE
) {
1905 vp
->v_flag
|= VTHROTTLED
;
1906 tsleep((caddr_t
)&vp
->v_numoutput
, PRIBIO
+ 1, "cluster_write", 0);
1908 retval
= cluster_io(vp
, upl
, 0, upl_f_offset
, io_size
,
1909 io_flags
, (struct buf
*)0);
1912 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 40)) | DBG_FUNC_END
,
1913 retval
, 0, 0, 0, 0);
1918 cluster_read(vp
, uio
, filesize
, devblocksize
, flags
)
1929 vm_offset_t upl_offset
;
1932 upl_page_info_t
*pl
;
1937 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 32)) | DBG_FUNC_START
,
1938 (int)uio
->uio_offset
, uio
->uio_resid
, (int)filesize
, devblocksize
, 0);
1941 * We set a threshhold of 4 pages to decide if the nocopy
1942 * read loop is worth the trouble...
1945 if (!((vp
->v_flag
& VNOCACHE_DATA
) && (uio
->uio_segflg
== UIO_USERSPACE
)))
1947 retval
= cluster_read_x(vp
, uio
, filesize
, devblocksize
, flags
);
1948 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 32)) | DBG_FUNC_END
,
1949 (int)uio
->uio_offset
, uio
->uio_resid
, vp
->v_lastr
, retval
, 0);
1953 while (uio
->uio_resid
&& uio
->uio_offset
< filesize
&& retval
== 0)
1955 /* we know we have a resid, so this is safe */
1957 while (iov
->iov_len
== 0) {
1964 * We check every vector target and if it is physically
1965 * contiguous space, we skip the sanity checks.
1968 upl_offset
= (vm_offset_t
)iov
->iov_base
& ~PAGE_MASK
;
1969 upl_size
= (upl_offset
+ PAGE_SIZE
+(PAGE_SIZE
-1)) & ~PAGE_MASK
;
1971 upl_flags
= UPL_QUERY_OBJECT_TYPE
;
1972 if((vm_map_get_upl(current_map(),
1973 (vm_offset_t
)iov
->iov_base
& ~PAGE_MASK
,
1974 &upl_size
, &upl
, NULL
, &pages_in_pl
, &upl_flags
, 0)) != KERN_SUCCESS
)
1977 * the user app must have passed in an invalid address
1982 if (upl_flags
& UPL_PHYS_CONTIG
)
1984 retval
= cluster_phys_read(vp
, uio
, filesize
);
1986 else if (uio
->uio_resid
< 4 * PAGE_SIZE
)
1989 * We set a threshhold of 4 pages to decide if the nocopy
1990 * read loop is worth the trouble...
1992 retval
= cluster_read_x(vp
, uio
, filesize
, devblocksize
, flags
);
1993 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 32)) | DBG_FUNC_END
,
1994 (int)uio
->uio_offset
, uio
->uio_resid
, vp
->v_lastr
, retval
, 0);
1997 else if (uio
->uio_offset
& PAGE_MASK_64
)
1999 /* Bring the file offset read up to a pagesize boundary */
2000 clip_size
= (PAGE_SIZE
- (int)(uio
->uio_offset
& PAGE_MASK_64
));
2001 if (uio
->uio_resid
< clip_size
)
2002 clip_size
= uio
->uio_resid
;
2004 * Fake the resid going into the cluster_read_x call
2005 * and restore it on the way out.
2007 prev_resid
= uio
->uio_resid
;
2008 uio
->uio_resid
= clip_size
;
2009 retval
= cluster_read_x(vp
, uio
, filesize
, devblocksize
, flags
);
2010 uio
->uio_resid
= prev_resid
- (clip_size
- uio
->uio_resid
);
2012 else if ((int)iov
->iov_base
& PAGE_MASK_64
)
2014 clip_size
= iov
->iov_len
;
2015 prev_resid
= uio
->uio_resid
;
2016 uio
->uio_resid
= clip_size
;
2017 retval
= cluster_read_x(vp
, uio
, filesize
, devblocksize
, flags
);
2018 uio
->uio_resid
= prev_resid
- (clip_size
- uio
->uio_resid
);
2023 * If we come in here, we know the offset into
2024 * the file is on a pagesize boundary
2027 max_io_size
= filesize
- uio
->uio_offset
;
2028 clip_size
= uio
->uio_resid
;
2029 if (iov
->iov_len
< clip_size
)
2030 clip_size
= iov
->iov_len
;
2031 if (max_io_size
< clip_size
)
2032 clip_size
= (int)max_io_size
;
2034 if (clip_size
< PAGE_SIZE
)
2037 * Take care of the tail end of the read in this vector.
2039 prev_resid
= uio
->uio_resid
;
2040 uio
->uio_resid
= clip_size
;
2041 retval
= cluster_read_x(vp
, uio
, filesize
, devblocksize
, flags
);
2042 uio
->uio_resid
= prev_resid
- (clip_size
- uio
->uio_resid
);
2046 /* round clip_size down to a multiple of pagesize */
2047 clip_size
= clip_size
& ~(PAGE_MASK
);
2048 prev_resid
= uio
->uio_resid
;
2049 uio
->uio_resid
= clip_size
;
2050 retval
= cluster_nocopy_read(vp
, uio
, filesize
, devblocksize
, flags
);
2051 if ((retval
==0) && uio
->uio_resid
)
2052 retval
= cluster_read_x(vp
, uio
, filesize
, devblocksize
, flags
);
2053 uio
->uio_resid
= prev_resid
- (clip_size
- uio
->uio_resid
);
2058 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 32)) | DBG_FUNC_END
,
2059 (int)uio
->uio_offset
, uio
->uio_resid
, vp
->v_lastr
, retval
, 0);
2065 cluster_read_x(vp
, uio
, filesize
, devblocksize
, flags
)
2072 upl_page_info_t
*pl
;
2074 vm_offset_t upl_offset
;
2084 vm_offset_t io_address
;
2092 b_lblkno
= (int)(uio
->uio_offset
/ PAGE_SIZE_64
);
2094 while (uio
->uio_resid
&& uio
->uio_offset
< filesize
&& retval
== 0) {
2096 * compute the size of the upl needed to encompass
2097 * the requested read... limit each call to cluster_io
2098 * to the maximum UPL size... cluster_io will clip if
2099 * this exceeds the maximum io_size for the device,
2100 * make sure to account for
2101 * a starting offset that's not page aligned
2103 start_offset
= (int)(uio
->uio_offset
& PAGE_MASK_64
);
2104 upl_f_offset
= uio
->uio_offset
- (off_t
)start_offset
;
2105 max_size
= filesize
- uio
->uio_offset
;
2107 if ((off_t
)((unsigned int)uio
->uio_resid
) < max_size
)
2108 io_size
= uio
->uio_resid
;
2112 if (uio
->uio_segflg
== UIO_USERSPACE
&& !(vp
->v_flag
& VNOCACHE_DATA
)) {
2113 segflg
= uio
->uio_segflg
;
2115 uio
->uio_segflg
= UIO_PHYS_USERSPACE
;
2117 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 34)) | DBG_FUNC_START
,
2118 (int)uio
->uio_offset
, io_size
, uio
->uio_resid
, 0, 0);
2120 while (io_size
&& retval
== 0) {
2126 UPL_POP_SET
| UPL_POP_BUSY
,
2127 &paddr
, 0) != KERN_SUCCESS
)
2130 xsize
= PAGE_SIZE
- start_offset
;
2132 if (xsize
> io_size
)
2135 retval
= uiomove((caddr_t
)(paddr
+ start_offset
), xsize
, uio
);
2137 ubc_page_op(vp
, upl_f_offset
,
2138 UPL_POP_CLR
| UPL_POP_BUSY
, 0, 0);
2141 start_offset
= (int)
2142 (uio
->uio_offset
& PAGE_MASK_64
);
2143 upl_f_offset
= uio
->uio_offset
- start_offset
;
2145 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 34)) | DBG_FUNC_END
,
2146 (int)uio
->uio_offset
, io_size
, uio
->uio_resid
, 0, 0);
2148 uio
->uio_segflg
= segflg
;
2155 * we're already finished with this read request
2156 * let's see if we should do a read-ahead
2159 ((uio
->uio_offset
- 1) / PAGE_SIZE_64
);
2161 if (!(vp
->v_flag
& VRAOFF
))
2163 * let's try to read ahead if we're in
2164 * a sequential access pattern
2166 cluster_rd_ahead(vp
, b_lblkno
, e_lblkno
, filesize
, devblocksize
);
2167 vp
->v_lastr
= e_lblkno
;
2171 max_size
= filesize
- uio
->uio_offset
;
2174 upl_size
= (start_offset
+ io_size
+ (PAGE_SIZE
- 1)) & ~PAGE_MASK
;
2175 if (upl_size
> (MAX_UPL_TRANSFER
* PAGE_SIZE
))
2176 upl_size
= MAX_UPL_TRANSFER
* PAGE_SIZE
;
2177 pages_in_upl
= upl_size
/ PAGE_SIZE
;
2179 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 33)) | DBG_FUNC_START
,
2180 upl
, (int)upl_f_offset
, upl_size
, start_offset
, 0);
2182 kret
= ubc_create_upl(vp
,
2188 if (kret
!= KERN_SUCCESS
)
2189 panic("cluster_read: failed to get pagelist");
2191 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 33)) | DBG_FUNC_END
,
2192 upl
, (int)upl_f_offset
, upl_size
, start_offset
, 0);
2195 * scan from the beginning of the upl looking for the first
2196 * non-valid page.... this will become the first page in
2197 * the request we're going to make to 'cluster_io'... if all
2198 * of the pages are valid, we won't call through to 'cluster_io'
2200 for (start_pg
= 0; start_pg
< pages_in_upl
; start_pg
++) {
2201 if (!upl_valid_page(pl
, start_pg
))
2206 * scan from the starting invalid page looking for a valid
2207 * page before the end of the upl is reached, if we
2208 * find one, then it will be the last page of the request to
2211 for (last_pg
= start_pg
; last_pg
< pages_in_upl
; last_pg
++) {
2212 if (upl_valid_page(pl
, last_pg
))
2216 if (start_pg
< last_pg
) {
2218 * we found a range of 'invalid' pages that must be filled
2219 * if the last page in this range is the last page of the file
2220 * we may have to clip the size of it to keep from reading past
2221 * the end of the last physical block associated with the file
2223 upl_offset
= start_pg
* PAGE_SIZE
;
2224 io_size
= (last_pg
- start_pg
) * PAGE_SIZE
;
2226 if ((upl_f_offset
+ upl_offset
+ io_size
) > filesize
) {
2227 io_size
= filesize
- (upl_f_offset
+ upl_offset
);
2228 io_size
= (io_size
+ (devblocksize
- 1)) & ~(devblocksize
- 1);
2231 * issue a synchronous read to cluster_io
2234 error
= cluster_io(vp
, upl
, upl_offset
, upl_f_offset
+ upl_offset
,
2235 io_size
, CL_READ
, (struct buf
*)0);
2239 * if the read completed successfully, or there was no I/O request
2240 * issued, than map the upl into kernel address space and
2241 * move the data into user land.... we'll first add on any 'valid'
2242 * pages that were present in the upl when we acquired it.
2245 u_int size_of_prefetch
;
2247 for (uio_last
= last_pg
; uio_last
< pages_in_upl
; uio_last
++) {
2248 if (!upl_valid_page(pl
, uio_last
))
2252 * compute size to transfer this round, if uio->uio_resid is
2253 * still non-zero after this uiomove, we'll loop around and
2254 * set up for another I/O.
2256 val_size
= (uio_last
* PAGE_SIZE
) - start_offset
;
2258 if (max_size
< val_size
)
2259 val_size
= max_size
;
2261 if (uio
->uio_resid
< val_size
)
2262 val_size
= uio
->uio_resid
;
2264 e_lblkno
= (int)((uio
->uio_offset
+ ((off_t
)val_size
- 1)) / PAGE_SIZE_64
);
2266 if (size_of_prefetch
= (uio
->uio_resid
- val_size
)) {
2268 * if there's still I/O left to do for this request, then issue a
2269 * pre-fetch I/O... the I/O wait time will overlap
2270 * with the copying of the data
2272 cluster_rd_prefetch(vp
, uio
->uio_offset
+ val_size
, size_of_prefetch
, filesize
, devblocksize
);
2274 if (!(vp
->v_flag
& VRAOFF
) && !(vp
->v_flag
& VNOCACHE_DATA
))
2276 * let's try to read ahead if we're in
2277 * a sequential access pattern
2279 cluster_rd_ahead(vp
, b_lblkno
, e_lblkno
, filesize
, devblocksize
);
2280 vp
->v_lastr
= e_lblkno
;
2283 if (uio
->uio_segflg
== UIO_USERSPACE
) {
2286 segflg
= uio
->uio_segflg
;
2288 uio
->uio_segflg
= UIO_PHYS_USERSPACE
;
2291 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 34)) | DBG_FUNC_START
,
2292 (int)uio
->uio_offset
, val_size
, uio
->uio_resid
, 0, 0);
2294 offset
= start_offset
;
2296 while (val_size
&& retval
== 0) {
2301 i
= offset
/ PAGE_SIZE
;
2302 csize
= min(PAGE_SIZE
- start_offset
, val_size
);
2304 paddr
= (caddr_t
)upl_phys_page(pl
, i
) + start_offset
;
2306 retval
= uiomove(paddr
, csize
, uio
);
2310 start_offset
= offset
& PAGE_MASK
;
2312 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 34)) | DBG_FUNC_END
,
2313 (int)uio
->uio_offset
, val_size
, uio
->uio_resid
, 0, 0);
2315 uio
->uio_segflg
= segflg
;
2319 if ((kret
= ubc_upl_map(upl
, &io_address
)) != KERN_SUCCESS
)
2320 panic("cluster_read: ubc_upl_map() failed\n");
2322 retval
= uiomove((caddr_t
)(io_address
+ start_offset
), val_size
, uio
);
2324 if ((kret
= ubc_upl_unmap(upl
)) != KERN_SUCCESS
)
2325 panic("cluster_read: ubc_upl_unmap() failed\n");
2328 if (start_pg
< last_pg
) {
2330 * compute the range of pages that we actually issued an I/O for
2331 * and either commit them as valid if the I/O succeeded
2332 * or abort them if the I/O failed
2334 io_size
= (last_pg
- start_pg
) * PAGE_SIZE
;
2336 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 35)) | DBG_FUNC_START
,
2337 upl
, start_pg
* PAGE_SIZE
, io_size
, error
, 0);
2339 if (error
|| (vp
->v_flag
& VNOCACHE_DATA
))
2340 ubc_upl_abort_range(upl
, start_pg
* PAGE_SIZE
, io_size
,
2341 UPL_ABORT_DUMP_PAGES
| UPL_ABORT_FREE_ON_EMPTY
);
2343 ubc_upl_commit_range(upl
, start_pg
* PAGE_SIZE
, io_size
,
2344 UPL_COMMIT_CLEAR_DIRTY
2345 | UPL_COMMIT_FREE_ON_EMPTY
2346 | UPL_COMMIT_INACTIVATE
);
2348 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 35)) | DBG_FUNC_END
,
2349 upl
, start_pg
* PAGE_SIZE
, io_size
, error
, 0);
2351 if ((last_pg
- start_pg
) < pages_in_upl
) {
2356 * the set of pages that we issued an I/O for did not encompass
2357 * the entire upl... so just release these without modifying
2361 ubc_upl_abort(upl
, 0);
2363 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 35)) | DBG_FUNC_START
,
2364 upl
, -1, pages_in_upl
- (last_pg
- start_pg
), 0, 0);
2368 * we found some already valid pages at the beginning of
2369 * the upl commit these back to the inactive list with
2372 for (cur_pg
= 0; cur_pg
< start_pg
; cur_pg
++) {
2373 commit_flags
= UPL_COMMIT_FREE_ON_EMPTY
2374 | UPL_COMMIT_INACTIVATE
;
2376 if (upl_dirty_page(pl
, cur_pg
))
2377 commit_flags
|= UPL_COMMIT_SET_DIRTY
;
2379 if ( !(commit_flags
& UPL_COMMIT_SET_DIRTY
) && (vp
->v_flag
& VNOCACHE_DATA
))
2380 ubc_upl_abort_range(upl
, cur_pg
* PAGE_SIZE
, PAGE_SIZE
,
2381 UPL_ABORT_DUMP_PAGES
| UPL_ABORT_FREE_ON_EMPTY
);
2383 ubc_upl_commit_range(upl
, cur_pg
* PAGE_SIZE
,
2384 PAGE_SIZE
, commit_flags
);
2387 if (last_pg
< uio_last
) {
2389 * we found some already valid pages immediately after the
2390 * pages we issued I/O for, commit these back to the
2391 * inactive list with reference cleared
2393 for (cur_pg
= last_pg
; cur_pg
< uio_last
; cur_pg
++) {
2394 commit_flags
= UPL_COMMIT_FREE_ON_EMPTY
2395 | UPL_COMMIT_INACTIVATE
;
2397 if (upl_dirty_page(pl
, cur_pg
))
2398 commit_flags
|= UPL_COMMIT_SET_DIRTY
;
2400 if ( !(commit_flags
& UPL_COMMIT_SET_DIRTY
) && (vp
->v_flag
& VNOCACHE_DATA
))
2401 ubc_upl_abort_range(upl
, cur_pg
* PAGE_SIZE
, PAGE_SIZE
,
2402 UPL_ABORT_DUMP_PAGES
| UPL_ABORT_FREE_ON_EMPTY
);
2404 ubc_upl_commit_range(upl
, cur_pg
* PAGE_SIZE
,
2405 PAGE_SIZE
, commit_flags
);
2408 if (uio_last
< pages_in_upl
) {
2410 * there were some invalid pages beyond the valid pages
2411 * that we didn't issue an I/O for, just release them
2414 ubc_upl_abort(upl
, 0);
2417 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 35)) | DBG_FUNC_END
,
2429 cluster_nocopy_read(vp
, uio
, filesize
, devblocksize
, flags
)
2437 upl_page_info_t
*pl
;
2439 vm_offset_t upl_offset
;
2440 off_t start_upl_f_offset
;
2444 int upl_needed_size
;
2452 int force_data_sync
;
2456 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 70)) | DBG_FUNC_START
,
2457 (int)uio
->uio_offset
, uio
->uio_resid
, (int)filesize
, devblocksize
, 0);
2460 * When we enter this routine, we know
2461 * -- the offset into the file is on a pagesize boundary
2462 * -- the resid is a page multiple
2463 * -- the resid will not exceed iov_len
2467 while (uio
->uio_resid
&& uio
->uio_offset
< filesize
&& retval
== 0) {
2469 max_io_size
= filesize
- uio
->uio_offset
;
2471 if (max_io_size
< (off_t
)((unsigned int)uio
->uio_resid
))
2472 io_size
= max_io_size
;
2474 io_size
= uio
->uio_resid
;
2477 * We don't come into this routine unless
2478 * UIO_USERSPACE is set.
2480 segflg
= uio
->uio_segflg
;
2482 uio
->uio_segflg
= UIO_PHYS_USERSPACE
;
2485 * First look for pages already in the cache
2486 * and move them to user space.
2488 while (io_size
&& (retval
== 0)) {
2489 upl_f_offset
= uio
->uio_offset
;
2492 * If this call fails, it means the page is not
2493 * in the page cache.
2495 if (ubc_page_op(vp
, upl_f_offset
,
2496 UPL_POP_SET
| UPL_POP_BUSY
, &paddr
, 0) != KERN_SUCCESS
)
2499 retval
= uiomove((caddr_t
)(paddr
), PAGE_SIZE
, uio
);
2501 ubc_page_op(vp
, upl_f_offset
,
2502 UPL_POP_CLR
| UPL_POP_BUSY
, 0, 0);
2504 io_size
-= PAGE_SIZE
;
2505 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 71)) | DBG_FUNC_NONE
,
2506 (int)uio
->uio_offset
, io_size
, uio
->uio_resid
, 0, 0);
2509 uio
->uio_segflg
= segflg
;
2513 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 70)) | DBG_FUNC_END
,
2514 (int)uio
->uio_offset
, uio
->uio_resid
, 2, retval
, 0);
2518 /* If we are already finished with this read, then return */
2522 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 70)) | DBG_FUNC_END
,
2523 (int)uio
->uio_offset
, uio
->uio_resid
, 3, io_size
, 0);
2527 max_io_size
= io_size
;
2528 if (max_io_size
> (MAX_UPL_TRANSFER
* PAGE_SIZE
))
2529 max_io_size
= MAX_UPL_TRANSFER
* PAGE_SIZE
;
2531 start_upl_f_offset
= uio
->uio_offset
; /* this is page aligned in the file */
2532 upl_f_offset
= start_upl_f_offset
;
2535 while(io_size
< max_io_size
)
2538 if(ubc_page_op(vp
, upl_f_offset
,
2539 UPL_POP_SET
| UPL_POP_BUSY
, &paddr
, 0) == KERN_SUCCESS
)
2541 ubc_page_op(vp
, upl_f_offset
,
2542 UPL_POP_CLR
| UPL_POP_BUSY
, 0, 0);
2547 * Build up the io request parameters.
2550 io_size
+= PAGE_SIZE
;
2551 upl_f_offset
+= PAGE_SIZE
;
2557 upl_offset
= (vm_offset_t
)iov
->iov_base
& PAGE_MASK_64
;
2558 upl_needed_size
= (upl_offset
+ io_size
+ (PAGE_SIZE
-1)) & ~PAGE_MASK
;
2560 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 72)) | DBG_FUNC_START
,
2561 (int)upl_offset
, upl_needed_size
, iov
->iov_base
, io_size
, 0);
2563 for (force_data_sync
= 0; force_data_sync
< 3; force_data_sync
++)
2566 upl_size
= upl_needed_size
;
2567 upl_flags
= UPL_NO_SYNC
| UPL_CLEAN_IN_PLACE
| UPL_SET_INTERNAL
;
2569 kret
= vm_map_get_upl(current_map(),
2570 (vm_offset_t
)iov
->iov_base
& ~PAGE_MASK
,
2571 &upl_size
, &upl
, NULL
, &pages_in_pl
, &upl_flags
, force_data_sync
);
2573 if (kret
!= KERN_SUCCESS
)
2575 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 72)) | DBG_FUNC_END
,
2576 (int)upl_offset
, upl_size
, io_size
, kret
, 0);
2578 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 70)) | DBG_FUNC_END
,
2579 (int)uio
->uio_offset
, uio
->uio_resid
, 4, retval
, 0);
2581 /* cluster_nocopy_read: failed to get pagelist */
2582 /* do not return kret here */
2586 pages_in_pl
= upl_size
/ PAGE_SIZE
;
2587 pl
= UPL_GET_INTERNAL_PAGE_LIST(upl
);
2589 for(i
=0; i
< pages_in_pl
; i
++)
2591 if (!upl_valid_page(pl
, i
))
2594 if (i
== pages_in_pl
)
2597 ubc_upl_abort_range(upl
, (upl_offset
& ~PAGE_MASK
), upl_size
,
2598 UPL_ABORT_FREE_ON_EMPTY
);
2601 if (force_data_sync
>= 3)
2603 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 72)) | DBG_FUNC_END
,
2604 (int)upl_offset
, upl_size
, io_size
, kret
, 0);
2606 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 70)) | DBG_FUNC_END
,
2607 (int)uio
->uio_offset
, uio
->uio_resid
, 5, retval
, 0);
2611 * Consider the possibility that upl_size wasn't satisfied.
2613 if (upl_size
!= upl_needed_size
)
2614 io_size
= (upl_size
- (int)upl_offset
) & ~PAGE_MASK
;
2618 ubc_upl_abort_range(upl
, (upl_offset
& ~PAGE_MASK
), upl_size
,
2619 UPL_ABORT_FREE_ON_EMPTY
);
2623 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 72)) | DBG_FUNC_END
,
2624 (int)upl_offset
, upl_size
, io_size
, kret
, 0);
2627 * issue a synchronous read to cluster_io
2630 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 73)) | DBG_FUNC_START
,
2631 upl
, (int)upl_offset
, (int)start_upl_f_offset
, io_size
, 0);
2633 error
= cluster_io(vp
, upl
, upl_offset
, start_upl_f_offset
,
2634 io_size
, CL_READ
| CL_NOZERO
, (struct buf
*)0);
2638 * The cluster_io read completed successfully,
2639 * update the uio structure and commit.
2642 ubc_upl_commit_range(upl
, (upl_offset
& ~PAGE_MASK
), upl_size
,
2643 UPL_COMMIT_SET_DIRTY
| UPL_COMMIT_FREE_ON_EMPTY
);
2645 iov
->iov_base
+= io_size
;
2646 iov
->iov_len
-= io_size
;
2647 uio
->uio_resid
-= io_size
;
2648 uio
->uio_offset
+= io_size
;
2651 ubc_upl_abort_range(upl
, (upl_offset
& ~PAGE_MASK
), upl_size
,
2652 UPL_ABORT_FREE_ON_EMPTY
);
2655 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 73)) | DBG_FUNC_END
,
2656 upl
, (int)uio
->uio_offset
, (int)uio
->uio_resid
, error
, 0);
2664 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 70)) | DBG_FUNC_END
,
2665 (int)uio
->uio_offset
, (int)uio
->uio_resid
, 6, retval
, 0);
2672 cluster_phys_read(vp
, uio
, filesize
)
2678 vm_offset_t upl_offset
;
2682 int upl_needed_size
;
2690 * When we enter this routine, we know
2691 * -- the resid will not exceed iov_len
2692 * -- the target address is physically contiguous
2697 max_size
= filesize
- uio
->uio_offset
;
2699 if (max_size
< (off_t
)((unsigned int)iov
->iov_len
))
2702 io_size
= iov
->iov_len
;
2704 upl_offset
= (vm_offset_t
)iov
->iov_base
& PAGE_MASK_64
;
2705 upl_needed_size
= upl_offset
+ io_size
;
2708 upl_size
= upl_needed_size
;
2709 upl_flags
= UPL_NO_SYNC
| UPL_CLEAN_IN_PLACE
| UPL_SET_INTERNAL
;
2711 kret
= vm_map_get_upl(current_map(),
2712 (vm_offset_t
)iov
->iov_base
& ~PAGE_MASK
,
2713 &upl_size
, &upl
, NULL
, &pages_in_pl
, &upl_flags
, 0);
2715 if (kret
!= KERN_SUCCESS
)
2717 /* cluster_phys_read: failed to get pagelist */
2722 * Consider the possibility that upl_size wasn't satisfied.
2724 if (upl_size
< upl_needed_size
)
2726 ubc_upl_abort_range(upl
, 0, upl_size
, UPL_ABORT_FREE_ON_EMPTY
);
2731 * issue a synchronous read to cluster_io
2734 error
= cluster_io(vp
, upl
, upl_offset
, uio
->uio_offset
,
2735 io_size
, CL_READ
| CL_NOZERO
| CL_DEV_MEMORY
, (struct buf
*)0);
2740 * The cluster_io read completed successfully,
2741 * update the uio structure and commit.
2744 ubc_upl_commit_range(upl
, 0, upl_size
, UPL_COMMIT_FREE_ON_EMPTY
);
2746 iov
->iov_base
+= io_size
;
2747 iov
->iov_len
-= io_size
;
2748 uio
->uio_resid
-= io_size
;
2749 uio
->uio_offset
+= io_size
;
2752 ubc_upl_abort_range(upl
, 0, upl_size
, UPL_ABORT_FREE_ON_EMPTY
);
2758 * generate advisory I/O's in the largest chunks possible
2759 * the completed pages will be released into the VM cache
2761 advisory_read(vp
, filesize
, f_offset
, resid
, devblocksize
)
2768 upl_page_info_t
*pl
;
2770 vm_offset_t upl_offset
;
2783 if (!UBCINFOEXISTS(vp
))
2786 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 60)) | DBG_FUNC_START
,
2787 (int)f_offset
, resid
, (int)filesize
, devblocksize
, 0);
2789 while (resid
&& f_offset
< filesize
&& retval
== 0) {
2791 * compute the size of the upl needed to encompass
2792 * the requested read... limit each call to cluster_io
2793 * to the maximum UPL size... cluster_io will clip if
2794 * this exceeds the maximum io_size for the device,
2795 * make sure to account for
2796 * a starting offset that's not page aligned
2798 start_offset
= (int)(f_offset
& PAGE_MASK_64
);
2799 upl_f_offset
= f_offset
- (off_t
)start_offset
;
2800 max_size
= filesize
- f_offset
;
2802 if (resid
< max_size
)
2807 upl_size
= (start_offset
+ io_size
+ (PAGE_SIZE
- 1)) & ~PAGE_MASK
;
2808 if (upl_size
> (MAX_UPL_TRANSFER
* PAGE_SIZE
))
2809 upl_size
= MAX_UPL_TRANSFER
* PAGE_SIZE
;
2810 pages_in_upl
= upl_size
/ PAGE_SIZE
;
2812 kret
= ubc_create_upl(vp
,
2818 if (kret
!= KERN_SUCCESS
)
2819 panic("advisory_read: failed to get pagelist");
2822 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 61)) | DBG_FUNC_NONE
,
2823 upl
, (int)upl_f_offset
, upl_size
, start_offset
, 0);
2826 * scan from the beginning of the upl looking for the first
2827 * non-valid page.... this will become the first page in
2828 * the request we're going to make to 'cluster_io'... if all
2829 * of the pages are valid, we won't call through to 'cluster_io'
2831 for (start_pg
= 0; start_pg
< pages_in_upl
; start_pg
++) {
2832 if (!upl_valid_page(pl
, start_pg
))
2837 * scan from the starting invalid page looking for a valid
2838 * page before the end of the upl is reached, if we
2839 * find one, then it will be the last page of the request to
2842 for (last_pg
= start_pg
; last_pg
< pages_in_upl
; last_pg
++) {
2843 if (upl_valid_page(pl
, last_pg
))
2847 if (start_pg
< last_pg
) {
2849 * we found a range of 'invalid' pages that must be filled
2850 * if the last page in this range is the last page of the file
2851 * we may have to clip the size of it to keep from reading past
2852 * the end of the last physical block associated with the file
2854 upl_offset
= start_pg
* PAGE_SIZE
;
2855 io_size
= (last_pg
- start_pg
) * PAGE_SIZE
;
2857 if ((upl_f_offset
+ upl_offset
+ io_size
) > filesize
) {
2858 io_size
= filesize
- (upl_f_offset
+ upl_offset
);
2859 io_size
= (io_size
+ (devblocksize
- 1)) & ~(devblocksize
- 1);
2862 * issue an asynchronous read to cluster_io
2864 retval
= cluster_io(vp
, upl
, upl_offset
, upl_f_offset
+ upl_offset
, io_size
,
2865 CL_ASYNC
| CL_READ
| CL_COMMIT
| CL_AGE
, (struct buf
*)0);
2869 * start_pg of non-zero indicates we found some already valid pages
2870 * at the beginning of the upl.... we need to release these without
2871 * modifying there state
2873 ubc_upl_abort_range(upl
, 0, start_pg
* PAGE_SIZE
,
2874 UPL_ABORT_FREE_ON_EMPTY
);
2876 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 62)) | DBG_FUNC_NONE
,
2877 upl
, 0, start_pg
* PAGE_SIZE
, 0, 0);
2879 if (last_pg
< pages_in_upl
) {
2881 * the set of pages that we issued an I/O for did not extend all the
2882 * way to the end of the upl..so just release them without modifying
2885 ubc_upl_abort_range(upl
, last_pg
* PAGE_SIZE
, (pages_in_upl
- last_pg
) * PAGE_SIZE
,
2886 UPL_ABORT_FREE_ON_EMPTY
);
2888 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 63)) | DBG_FUNC_NONE
,
2889 upl
, last_pg
* PAGE_SIZE
,
2890 (pages_in_upl
- last_pg
) * PAGE_SIZE
, 0, 0);
2892 io_size
= (last_pg
* PAGE_SIZE
) - start_offset
;
2894 if (io_size
> resid
)
2896 f_offset
+= io_size
;
2899 KERNEL_DEBUG((FSDBG_CODE(DBG_FSRW
, 60)) | DBG_FUNC_END
,
2900 (int)f_offset
, resid
, retval
, 0, 0);
2909 upl_page_info_t
*pl
;
2911 vm_offset_t upl_offset
;
2923 if (!UBCINFOEXISTS(vp
))
2926 if (vp
->v_clen
== 0 || (pages_in_upl
= vp
->v_lastw
- vp
->v_cstart
) == 0)
2928 upl_size
= pages_in_upl
* PAGE_SIZE
;
2929 upl_f_offset
= ((off_t
)vp
->v_cstart
) * PAGE_SIZE_64
;
2930 size
= vp
->v_ciosiz
;
2933 if (size
> upl_size
|| (upl_size
- size
) > PAGE_SIZE
)
2934 panic("cluster_push: v_ciosiz doesn't match size of cluster\n");
2936 kret
= ubc_create_upl(vp
,
2942 if (kret
!= KERN_SUCCESS
)
2943 panic("cluster_push: failed to get pagelist");
2949 for (start_pg
= last_pg
; start_pg
< pages_in_upl
; start_pg
++) {
2950 if (upl_valid_page(pl
, start_pg
) && upl_dirty_page(pl
, start_pg
))
2953 if (start_pg
> last_pg
) {
2954 io_size
= (start_pg
- last_pg
) * PAGE_SIZE
;
2956 ubc_upl_abort_range(upl
, last_pg
* PAGE_SIZE
, io_size
,
2957 UPL_ABORT_FREE_ON_EMPTY
);
2964 for (last_pg
= start_pg
; last_pg
< pages_in_upl
; last_pg
++) {
2965 if (!upl_valid_page(pl
, last_pg
) || !upl_dirty_page(pl
, last_pg
))
2968 upl_offset
= start_pg
* PAGE_SIZE
;
2970 io_size
= min(size
, (last_pg
- start_pg
) * PAGE_SIZE
);
2972 if (vp
->v_flag
& VNOCACHE_DATA
)
2973 io_flags
= CL_COMMIT
| CL_AGE
| CL_ASYNC
| CL_DUMP
;
2975 io_flags
= CL_COMMIT
| CL_AGE
| CL_ASYNC
;
2977 while (vp
->v_numoutput
>= ASYNC_THROTTLE
) {
2978 vp
->v_flag
|= VTHROTTLED
;
2979 tsleep((caddr_t
)&vp
->v_numoutput
, PRIBIO
+ 1, "cluster_push", 0);
2981 cluster_io(vp
, upl
, upl_offset
, upl_f_offset
+ upl_offset
, io_size
, io_flags
, (struct buf
*)0);