kern_physio.c revision 1.80.2.7 1 1.80.2.7 ad /* $NetBSD: kern_physio.c,v 1.80.2.7 2007/10/09 13:44:27 ad Exp $ */
2 1.20 cgd
3 1.20 cgd /*-
4 1.20 cgd * Copyright (c) 1982, 1986, 1990, 1993
5 1.20 cgd * The Regents of the University of California. All rights reserved.
6 1.20 cgd * (c) UNIX System Laboratories, Inc.
7 1.20 cgd * All or some portions of this file are derived from material licensed
8 1.20 cgd * to the University of California by American Telephone and Telegraph
9 1.20 cgd * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 1.20 cgd * the permission of UNIX System Laboratories, Inc.
11 1.20 cgd *
12 1.20 cgd * Redistribution and use in source and binary forms, with or without
13 1.20 cgd * modification, are permitted provided that the following conditions
14 1.20 cgd * are met:
15 1.20 cgd * 1. Redistributions of source code must retain the above copyright
16 1.20 cgd * notice, this list of conditions and the following disclaimer.
17 1.20 cgd * 2. Redistributions in binary form must reproduce the above copyright
18 1.20 cgd * notice, this list of conditions and the following disclaimer in the
19 1.20 cgd * documentation and/or other materials provided with the distribution.
20 1.57 agc * 3. Neither the name of the University nor the names of its contributors
21 1.57 agc * may be used to endorse or promote products derived from this software
22 1.57 agc * without specific prior written permission.
23 1.57 agc *
24 1.57 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.57 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.57 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.57 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.57 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.57 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.57 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.57 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.57 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.57 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.57 agc * SUCH DAMAGE.
35 1.57 agc *
36 1.57 agc * @(#)kern_physio.c 8.1 (Berkeley) 6/10/93
37 1.57 agc */
38 1.57 agc
39 1.57 agc /*-
40 1.57 agc * Copyright (c) 1994 Christopher G. Demetriou
41 1.57 agc *
42 1.57 agc * Redistribution and use in source and binary forms, with or without
43 1.57 agc * modification, are permitted provided that the following conditions
44 1.57 agc * are met:
45 1.57 agc * 1. Redistributions of source code must retain the above copyright
46 1.57 agc * notice, this list of conditions and the following disclaimer.
47 1.57 agc * 2. Redistributions in binary form must reproduce the above copyright
48 1.57 agc * notice, this list of conditions and the following disclaimer in the
49 1.57 agc * documentation and/or other materials provided with the distribution.
50 1.20 cgd * 3. All advertising materials mentioning features or use of this software
51 1.20 cgd * must display the following acknowledgement:
52 1.20 cgd * This product includes software developed by the University of
53 1.20 cgd * California, Berkeley and its contributors.
54 1.20 cgd * 4. Neither the name of the University nor the names of its contributors
55 1.20 cgd * may be used to endorse or promote products derived from this software
56 1.20 cgd * without specific prior written permission.
57 1.20 cgd *
58 1.20 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 1.20 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 1.20 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 1.20 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 1.20 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 1.20 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 1.20 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 1.20 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 1.20 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 1.20 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 1.20 cgd * SUCH DAMAGE.
69 1.20 cgd *
70 1.20 cgd * @(#)kern_physio.c 8.1 (Berkeley) 6/10/93
71 1.20 cgd */
72 1.51 lukem
73 1.51 lukem #include <sys/cdefs.h>
74 1.80.2.7 ad __KERNEL_RCSID(0, "$NetBSD: kern_physio.c,v 1.80.2.7 2007/10/09 13:44:27 ad Exp $");
75 1.30 mrg
76 1.20 cgd #include <sys/param.h>
77 1.20 cgd #include <sys/systm.h>
78 1.20 cgd #include <sys/buf.h>
79 1.20 cgd #include <sys/proc.h>
80 1.62 yamt #include <sys/once.h>
81 1.62 yamt #include <sys/workqueue.h>
82 1.80.2.7 ad #include <sys/kmem.h>
83 1.26 christos
84 1.29 mrg #include <uvm/uvm_extern.h>
85 1.29 mrg
86 1.62 yamt ONCE_DECL(physio_initialized);
87 1.62 yamt struct workqueue *physio_workqueue;
88 1.62 yamt
89 1.20 cgd /*
90 1.20 cgd * The routines implemented in this file are described in:
91 1.20 cgd * Leffler, et al.: The Design and Implementation of the 4.3BSD
92 1.20 cgd * UNIX Operating System (Addison Welley, 1989)
93 1.20 cgd * on pages 231-233.
94 1.20 cgd *
95 1.20 cgd * The routines "getphysbuf" and "putphysbuf" steal and return a swap
96 1.20 cgd * buffer. Leffler, et al., says that swap buffers are used to do the
97 1.61 thorpej * I/O, so raw I/O requests don't have to be single-threaded. Of course,
98 1.61 thorpej * NetBSD doesn't use "swap buffers" -- we have our own memory pool for
99 1.61 thorpej * buffer descriptors.
100 1.20 cgd */
101 1.20 cgd
102 1.70 yamt /* #define PHYSIO_DEBUG */
103 1.70 yamt #if defined(PHYSIO_DEBUG)
104 1.70 yamt #define DPRINTF(a) printf a
105 1.70 yamt #else /* defined(PHYSIO_DEBUG) */
106 1.70 yamt #define DPRINTF(a) /* nothing */
107 1.70 yamt #endif /* defined(PHYSIO_DEBUG) */
108 1.70 yamt
109 1.65 yamt /* abuse these members/flags of struct buf */
110 1.65 yamt #define b_running b_freelistindex
111 1.66 yamt #define b_endoffset b_lblkno
112 1.80.2.6 ad #define BC_DONTFREE BC_AGE
113 1.65 yamt
114 1.61 thorpej /*
115 1.61 thorpej * allocate a buffer structure for use in physical I/O.
116 1.61 thorpej */
117 1.61 thorpej static struct buf *
118 1.61 thorpej getphysbuf(void)
119 1.61 thorpej {
120 1.61 thorpej struct buf *bp;
121 1.61 thorpej
122 1.80.2.6 ad bp = getiobuf(NULL, true);
123 1.62 yamt bp->b_error = 0;
124 1.80.2.6 ad bp->b_cflags = BC_BUSY;
125 1.61 thorpej return(bp);
126 1.61 thorpej }
127 1.61 thorpej
128 1.61 thorpej /*
129 1.61 thorpej * get rid of a swap buffer structure which has been used in physical I/O.
130 1.61 thorpej */
131 1.61 thorpej static void
132 1.61 thorpej putphysbuf(struct buf *bp)
133 1.61 thorpej {
134 1.61 thorpej
135 1.80.2.6 ad if ((bp->b_cflags & BC_DONTFREE) != 0) {
136 1.65 yamt return;
137 1.65 yamt }
138 1.65 yamt
139 1.80.2.6 ad if (__predict_false((bp->b_cflags & BC_WANTED) != 0))
140 1.80.2.6 ad panic("putphysbuf: private buf wanted");
141 1.71 yamt putiobuf(bp);
142 1.61 thorpej }
143 1.20 cgd
144 1.62 yamt static void
145 1.76 yamt physio_done(struct work *wk, void *dummy)
146 1.62 yamt {
147 1.62 yamt struct buf *bp = (void *)wk;
148 1.62 yamt size_t todo = bp->b_bufsize;
149 1.66 yamt size_t done = bp->b_bcount - bp->b_resid;
150 1.80.2.7 ad struct physio_stat *ps = bp->b_private;
151 1.62 yamt
152 1.62 yamt KASSERT(&bp->b_work == wk);
153 1.62 yamt KASSERT(bp->b_bcount <= todo);
154 1.62 yamt KASSERT(bp->b_resid <= bp->b_bcount);
155 1.62 yamt KASSERT((bp->b_flags & B_PHYS) != 0);
156 1.62 yamt KASSERT(dummy == NULL);
157 1.62 yamt
158 1.62 yamt vunmapbuf(bp, todo);
159 1.74 chs uvm_vsunlock(bp->b_proc->p_vmspace, bp->b_data, todo);
160 1.62 yamt
161 1.80.2.6 ad mutex_enter(mbp->b_objlock);
162 1.66 yamt if (__predict_false(done != todo)) {
163 1.66 yamt off_t endoffset = dbtob(bp->b_blkno) + done;
164 1.66 yamt
165 1.70 yamt /*
166 1.70 yamt * we got an error or hit EOM.
167 1.70 yamt *
168 1.70 yamt * we only care about the first one.
169 1.70 yamt * ie. the one at the lowest offset.
170 1.70 yamt */
171 1.70 yamt
172 1.70 yamt KASSERT(mbp->b_endoffset != endoffset);
173 1.70 yamt DPRINTF(("%s: error=%d at %" PRIu64 " - %" PRIu64
174 1.70 yamt ", blkno=%" PRIu64 ", bcount=%d, flags=0x%x\n",
175 1.70 yamt __func__, bp->b_error, dbtob(bp->b_blkno), endoffset,
176 1.70 yamt bp->b_blkno, bp->b_bcount, bp->b_flags));
177 1.70 yamt
178 1.80.2.5 ad mbp->b_flags = EIO;
179 1.66 yamt if (mbp->b_endoffset == -1 || endoffset < mbp->b_endoffset) {
180 1.70 yamt DPRINTF(("%s: mbp=%p, error %d -> %d, endoff %" PRIu64
181 1.70 yamt " -> %" PRIu64 "\n",
182 1.70 yamt __func__, mbp,
183 1.80.2.5 ad mbp->b_error, bp->b_error,
184 1.70 yamt mbp->b_endoffset, endoffset));
185 1.66 yamt
186 1.70 yamt mbp->b_endoffset = endoffset;
187 1.80.2.5 ad mbp->b_error = bp->b_error;
188 1.62 yamt }
189 1.70 yamt } else {
190 1.80.2.5 ad KASSERT(bp->b_error == 0);
191 1.62 yamt }
192 1.67 yamt
193 1.62 yamt mbp->b_running--;
194 1.80.2.6 ad cv_broadcast(&mbp->b_done);
195 1.80.2.6 ad mutex_exit(mbp->b_objlock);
196 1.62 yamt
197 1.62 yamt putphysbuf(bp);
198 1.62 yamt }
199 1.62 yamt
200 1.62 yamt static void
201 1.62 yamt physio_biodone(struct buf *bp)
202 1.62 yamt {
203 1.63 yamt #if defined(DIAGNOSTIC)
204 1.80.2.7 ad struct physio_stat *ps = bp->b_private;
205 1.62 yamt size_t todo = bp->b_bufsize;
206 1.62 yamt
207 1.80.2.7 ad KASSERT(ps->ps_running > 0);
208 1.62 yamt KASSERT(bp->b_bcount <= todo);
209 1.62 yamt KASSERT(bp->b_resid <= bp->b_bcount);
210 1.63 yamt #endif /* defined(DIAGNOSTIC) */
211 1.62 yamt
212 1.80.2.4 ad workqueue_enqueue(physio_workqueue, &bp->b_work, NULL);
213 1.62 yamt }
214 1.62 yamt
215 1.80.2.6 ad static void
216 1.80.2.6 ad physio_wait(struct buf *bp, int n)
217 1.62 yamt {
218 1.62 yamt
219 1.80.2.6 ad KASSERT(mutex_owned(bp->b_objlock));
220 1.62 yamt
221 1.80.2.6 ad while ((bp->b_oflags & BO_DONE) == 0 && bp->b_running > n)
222 1.80.2.6 ad cv_wait(&bp->b_done, bp->b_objlock);
223 1.62 yamt }
224 1.62 yamt
225 1.72 yamt static int
226 1.62 yamt physio_init(void)
227 1.62 yamt {
228 1.72 yamt int error;
229 1.62 yamt
230 1.62 yamt KASSERT(physio_workqueue == NULL);
231 1.62 yamt
232 1.72 yamt error = workqueue_create(&physio_workqueue, "physiod",
233 1.80.2.3 ad physio_done, NULL, PRIBIO, IPL_NONE, 0);
234 1.72 yamt
235 1.72 yamt return error;
236 1.62 yamt }
237 1.62 yamt
238 1.62 yamt #define PHYSIO_CONCURRENCY 16 /* XXX tune */
239 1.62 yamt
240 1.20 cgd /*
241 1.20 cgd * Do "physical I/O" on behalf of a user. "Physical I/O" is I/O directly
242 1.20 cgd * from the raw device to user buffers, and bypasses the buffer cache.
243 1.20 cgd *
244 1.20 cgd * Comments in brackets are from Leffler, et al.'s pseudo-code implementation.
245 1.20 cgd */
246 1.20 cgd int
247 1.62 yamt physio(void (*strategy)(struct buf *), struct buf *obp, dev_t dev, int flags,
248 1.61 thorpej void (*min_phys)(struct buf *), struct uio *uio)
249 1.20 cgd {
250 1.20 cgd struct iovec *iovp;
251 1.54 thorpej struct lwp *l = curlwp;
252 1.54 thorpej struct proc *p = l->l_proc;
253 1.80.2.1 ad int i;
254 1.72 yamt int error;
255 1.62 yamt struct buf *bp = NULL;
256 1.62 yamt struct buf *mbp;
257 1.65 yamt int concurrency = PHYSIO_CONCURRENCY - 1;
258 1.62 yamt
259 1.72 yamt error = RUN_ONCE(&physio_initialized, physio_init);
260 1.72 yamt if (__predict_false(error != 0)) {
261 1.72 yamt return error;
262 1.72 yamt }
263 1.20 cgd
264 1.70 yamt DPRINTF(("%s: called: off=%" PRIu64 ", resid=%zu\n",
265 1.70 yamt __func__, uio->uio_offset, uio->uio_resid));
266 1.70 yamt
267 1.53 hannken flags &= B_READ | B_WRITE;
268 1.20 cgd
269 1.80.2.7 ad if ((ps = kmem_zalloc(sizeof(*ps), KM_SLEEP)) == NULL)
270 1.80.2.7 ad return ENOMEM;
271 1.80.2.7 ad /* ps->ps_running = 0; */
272 1.80.2.7 ad /* ps->ps_error = 0; */
273 1.80.2.7 ad /* ps->ps_failed = 0; */
274 1.80.2.7 ad ps->ps_endoffset = -1;
275 1.80.2.7 ad mutex_init(&ps->ps_lock, MUTEX_DEFAULT, IPL_NONE);
276 1.80.2.7 ad cv_init(&ps->ps_cv, "physio");
277 1.80.2.7 ad
278 1.20 cgd /* Make sure we have a buffer, creating one if necessary. */
279 1.62 yamt if (obp != NULL) {
280 1.80.2.6 ad mutex_enter(&bufcache_lock);
281 1.80.2.6 ad while (bbusy(obp, false, 0) == EPASSTHROUGH)
282 1.80.2.6 ad ;
283 1.29 mrg /* Mark it busy, so nobody else will use it. */
284 1.80.2.6 ad obp->b_cflags = BC_DONTFREE;
285 1.80.2.6 ad mutex_exit(&bufcache_lock);
286 1.65 yamt
287 1.65 yamt concurrency = 0; /* see "XXXkludge" comment below */
288 1.29 mrg }
289 1.20 cgd
290 1.80.2.2 ad uvm_lwp_hold(l);
291 1.20 cgd
292 1.20 cgd for (i = 0; i < uio->uio_iovcnt; i++) {
293 1.79 thorpej bool sync = true;
294 1.68 yamt
295 1.20 cgd iovp = &uio->uio_iov[i];
296 1.20 cgd while (iovp->iov_len > 0) {
297 1.68 yamt size_t todo;
298 1.69 yamt vaddr_t endp;
299 1.68 yamt
300 1.80.2.6 ad mutex_enter(mbp->b_objlock);
301 1.80.2.6 ad physio_wait(mbp, sync ? 0 : concurrency);
302 1.80.2.5 ad if (mbp->b_error != 0) {
303 1.62 yamt goto done_locked;
304 1.62 yamt }
305 1.80.2.6 ad mutex_exit(mbp->b_objlock);
306 1.65 yamt if (obp != NULL) {
307 1.65 yamt /*
308 1.65 yamt * XXXkludge
309 1.65 yamt * some drivers use "obp" as an identifier.
310 1.65 yamt */
311 1.65 yamt bp = obp;
312 1.65 yamt } else {
313 1.65 yamt bp = getphysbuf();
314 1.65 yamt }
315 1.62 yamt bp->b_dev = dev;
316 1.62 yamt bp->b_proc = p;
317 1.80.2.7 ad bp->b_private = ps;
318 1.62 yamt bp->b_vp = NULL;
319 1.47 chs
320 1.20 cgd /*
321 1.20 cgd * [mark the buffer busy for physical I/O]
322 1.20 cgd * (i.e. set B_PHYS (because it's an I/O to user
323 1.20 cgd * memory, and B_RAW, because B_RAW is to be
324 1.20 cgd * "Set by physio for raw transfers.", in addition
325 1.20 cgd * to the "busy" and read/write flag.)
326 1.20 cgd */
327 1.80.2.6 ad bp->b_oflags = 0;
328 1.80.2.6 ad bp->b_cflags = (bp->b_cflags & BC_DONTFREE) | BC_BUSY;
329 1.80.2.6 ad bp->b_flags = flags | B_PHYS | B_RAW;
330 1.62 yamt bp->b_iodone = physio_biodone;
331 1.20 cgd
332 1.20 cgd /* [set up the buffer for a maximum-sized transfer] */
333 1.20 cgd bp->b_blkno = btodb(uio->uio_offset);
334 1.62 yamt if (dbtob(bp->b_blkno) != uio->uio_offset) {
335 1.62 yamt error = EINVAL;
336 1.62 yamt goto done;
337 1.62 yamt }
338 1.62 yamt bp->b_bcount = MIN(MAXPHYS, iovp->iov_len);
339 1.20 cgd bp->b_data = iovp->iov_base;
340 1.24 mycroft
341 1.20 cgd /*
342 1.48 wiz * [call minphys to bound the transfer size]
343 1.20 cgd * and remember the amount of data to transfer,
344 1.20 cgd * for later comparison.
345 1.20 cgd */
346 1.59 simonb (*min_phys)(bp);
347 1.69 yamt todo = bp->b_bufsize = bp->b_bcount;
348 1.62 yamt #if defined(DIAGNOSTIC)
349 1.69 yamt if (todo > MAXPHYS)
350 1.62 yamt panic("todo(%zu) > MAXPHYS; minphys broken",
351 1.69 yamt todo);
352 1.62 yamt #endif /* defined(DIAGNOSTIC) */
353 1.20 cgd
354 1.79 thorpej sync = false;
355 1.69 yamt endp = (vaddr_t)bp->b_data + todo;
356 1.69 yamt if (trunc_page(endp) != endp) {
357 1.69 yamt /*
358 1.69 yamt * following requests can overlap.
359 1.69 yamt * note that uvm_vslock does round_page.
360 1.69 yamt */
361 1.79 thorpej sync = true;
362 1.68 yamt }
363 1.68 yamt
364 1.20 cgd /*
365 1.20 cgd * [lock the part of the user address space involved
366 1.20 cgd * in the transfer]
367 1.20 cgd * Beware vmapbuf(); it clobbers b_data and
368 1.20 cgd * saves it in b_saveaddr. However, vunmapbuf()
369 1.20 cgd * restores it.
370 1.20 cgd */
371 1.74 chs error = uvm_vslock(p->p_vmspace, bp->b_data, todo,
372 1.62 yamt (flags & B_READ) ? VM_PROT_WRITE : VM_PROT_READ);
373 1.47 chs if (error) {
374 1.62 yamt goto done;
375 1.37 thorpej }
376 1.20 cgd vmapbuf(bp, todo);
377 1.20 cgd
378 1.58 yamt BIO_SETPRIO(bp, BPRIO_TIMECRITICAL);
379 1.58 yamt
380 1.80.2.6 ad mutex_enter(mbp->b_objlock);
381 1.62 yamt mbp->b_running++;
382 1.80.2.6 ad mutex_exit(mbp->b_objlock);
383 1.62 yamt
384 1.20 cgd /* [call strategy to start the transfer] */
385 1.20 cgd (*strategy)(bp);
386 1.62 yamt bp = NULL;
387 1.20 cgd
388 1.62 yamt iovp->iov_len -= todo;
389 1.80 christos iovp->iov_base = (char *)iovp->iov_base + todo;
390 1.62 yamt uio->uio_offset += todo;
391 1.62 yamt uio->uio_resid -= todo;
392 1.20 cgd }
393 1.20 cgd }
394 1.20 cgd
395 1.20 cgd done:
396 1.80.2.6 ad mutex_enter(mbp->b_objlock);
397 1.62 yamt done_locked:
398 1.80.2.6 ad physio_wait(mbp, 0);
399 1.80.2.6 ad mutex_exit(mbp->b_objlock);
400 1.66 yamt
401 1.80.2.5 ad if (mbp->b_error != 0) {
402 1.70 yamt off_t delta;
403 1.70 yamt
404 1.70 yamt delta = uio->uio_offset - mbp->b_endoffset;
405 1.70 yamt KASSERT(delta > 0);
406 1.70 yamt uio->uio_resid += delta;
407 1.70 yamt /* uio->uio_offset = mbp->b_endoffset; */
408 1.66 yamt } else {
409 1.66 yamt KASSERT(mbp->b_endoffset == -1);
410 1.62 yamt }
411 1.62 yamt if (bp != NULL) {
412 1.62 yamt putphysbuf(bp);
413 1.62 yamt }
414 1.62 yamt if (error == 0) {
415 1.62 yamt error = mbp->b_error;
416 1.62 yamt }
417 1.62 yamt putphysbuf(mbp);
418 1.62 yamt
419 1.20 cgd /*
420 1.20 cgd * [clean up the state of the buffer]
421 1.20 cgd * Remember if somebody wants it, so we can wake them up below.
422 1.20 cgd * Also, if we had to steal it, give it back.
423 1.20 cgd */
424 1.62 yamt if (obp != NULL) {
425 1.80.2.6 ad KASSERT((obp->b_cflags & BC_BUSY) != 0);
426 1.80.2.6 ad KASSERT((obp->b_cflags & BC_DONTFREE) != 0);
427 1.65 yamt
428 1.20 cgd /*
429 1.20 cgd * [if another process is waiting for the raw I/O buffer,
430 1.20 cgd * wake up processes waiting to do physical I/O;
431 1.20 cgd */
432 1.80.2.6 ad mutex_enter(&bufcache_lock);
433 1.80.2.6 ad obp->b_cflags &= ~(BC_DONTFREE | BC_BUSY);
434 1.80.2.6 ad obp->b_flags &= ~(B_PHYS | B_RAW);
435 1.80.2.6 ad obp->b_iodone = NULL;
436 1.80.2.6 ad cv_broadcast(&obp->b_busy);
437 1.80.2.6 ad mutex_exit(&bufcache_lock);
438 1.20 cgd }
439 1.80.2.2 ad uvm_lwp_rele(l);
440 1.20 cgd
441 1.70 yamt DPRINTF(("%s: done: off=%" PRIu64 ", resid=%zu\n",
442 1.70 yamt __func__, uio->uio_offset, uio->uio_resid));
443 1.70 yamt
444 1.62 yamt return error;
445 1.20 cgd }
446 1.20 cgd
447 1.20 cgd /*
448 1.20 cgd * Leffler, et al., says on p. 231:
449 1.20 cgd * "The minphys() routine is called by physio() to adjust the
450 1.20 cgd * size of each I/O transfer before the latter is passed to
451 1.24 mycroft * the strategy routine..."
452 1.20 cgd *
453 1.20 cgd * so, just adjust the buffer's count accounting to MAXPHYS here,
454 1.20 cgd * and return the new count;
455 1.20 cgd */
456 1.24 mycroft void
457 1.61 thorpej minphys(struct buf *bp)
458 1.20 cgd {
459 1.20 cgd
460 1.24 mycroft if (bp->b_bcount > MAXPHYS)
461 1.24 mycroft bp->b_bcount = MAXPHYS;
462 1.20 cgd }
463