| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | .\" $NetBSD: bufferio.9,v 1.5 2015/03/29 21:08:36 riastradh Exp $ | | 1 | .\" $NetBSD: bufferio.9,v 1.6 2015/03/30 13:10:04 riastradh Exp $ |
2 | .\" | | 2 | .\" |
3 | .\" Copyright (c) 2015 The NetBSD Foundation, Inc. | | 3 | .\" Copyright (c) 2015 The NetBSD Foundation, Inc. |
4 | .\" All rights reserved. | | 4 | .\" All rights reserved. |
5 | .\" | | 5 | .\" |
6 | .\" This code is derived from software contributed to The NetBSD Foundation | | 6 | .\" This code is derived from software contributed to The NetBSD Foundation |
7 | .\" by Taylor R. Campbell. | | 7 | .\" by Taylor R. Campbell. |
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 |
| @@ -81,88 +81,99 @@ The parameters to an I/O transfer descri | | | @@ -81,88 +81,99 @@ The parameters to an I/O transfer descri |
81 | .Fa bp | | 81 | .Fa bp |
82 | are specified by the following | | 82 | are specified by the following |
83 | .Vt "struct buf" | | 83 | .Vt "struct buf" |
84 | fields: | | 84 | fields: |
85 | .Bl -tag -offset abcd | | 85 | .Bl -tag -offset abcd |
86 | .It Fa bp Ns Li "->b_flags" | | 86 | .It Fa bp Ns Li "->b_flags" |
87 | Flags specifying the type of transfer. | | 87 | Flags specifying the type of transfer. |
88 | .Bl -tag -compact | | 88 | .Bl -tag -compact |
89 | .It Dv B_READ | | 89 | .It Dv B_READ |
90 | Transfer is read from device. | | 90 | Transfer is read from device. |
91 | If not set, transfer is write to device. | | 91 | If not set, transfer is write to device. |
92 | .It Dv B_ASYNC | | 92 | .It Dv B_ASYNC |
93 | Asynchronous I/O. | | 93 | Asynchronous I/O. |
94 | Caller must provide | | 94 | Caller must not provide |
95 | .Fa bp Ns Li "->b_iodone" | | 95 | .Fa bp Ns Li "->b_iodone" |
96 | and must not call | | 96 | and must not call |
97 | .Fn biowait bp . | | 97 | .Fn biowait bp . |
98 | .El | | 98 | .El |
99 | For legibility, callers should indicate writes by passing the | | 99 | For legibility, callers should indicate writes by passing the |
100 | pseudo-flag | | 100 | pseudo-flag |
101 | .Dv B_WRITE , | | 101 | .Dv B_WRITE , |
102 | which is zero. | | 102 | which is zero. |
103 | .It Fa bp Ns Li "->b_data" | | 103 | .It Fa bp Ns Li "->b_data" |
104 | Pointer to kernel virtual address of source/target for transfer. | | 104 | Pointer to kernel virtual address of source/target for transfer. |
105 | .It Fa bp Ns Li "->b_bcount" | | 105 | .It Fa bp Ns Li "->b_bcount" |
106 | Nonnegative number of bytes requested for transfer. | | 106 | Nonnegative number of bytes requested for transfer. |
107 | .It Fa bp Ns Li "->b_blkno" | | 107 | .It Fa bp Ns Li "->b_blkno" |
108 | Block number at which to do transfer. | | 108 | Block number at which to do transfer. |
109 | .It Fa bp Ns Li "->b_iodone" | | 109 | .It Fa bp Ns Li "->b_iodone" |
110 | If | | 110 | I/O completion callback. |
111 | .Dv B_ASYNC | | 111 | .Dv B_ASYNC |
112 | is set in | | 112 | must not be set in |
113 | .Fa bp Ns Li "->b_flags" , | | 113 | .Fa bp Ns Li "->b_flags" . |
114 | an I/O completion callback. | | | |
115 | .El | | 114 | .El |
116 | .Pp | | 115 | .Pp |
117 | Additionally, if the I/O transfer is a write associated with a | | 116 | Additionally, if the I/O transfer is a write associated with a |
118 | .Xr vnode 9 | | 117 | .Xr vnode 9 |
119 | .Fa vp , | | 118 | .Fa vp , |
120 | then before the user submits it to a block device, the user must | | 119 | then before the user submits it to a block device, the user must |
121 | increment | | 120 | increment |
122 | .Fa vp Ns Li "->v_numoutput" . | | 121 | .Fa vp Ns Li "->v_numoutput" . |
123 | The user must not acquire | | 122 | The user must not acquire |
124 | .Fa vp Ns Ap s | | 123 | .Fa vp Ns Ap s |
125 | vnode lock between incrementing | | 124 | vnode lock between incrementing |
126 | .Fa vp Ns Li "->v_numoutput" | | 125 | .Fa vp Ns Li "->v_numoutput" |
127 | and submitting | | 126 | and submitting |
128 | .Fa bp | | 127 | .Fa bp |
129 | to a block device -- doing so will likely cause deadlock with the | | 128 | to a block device -- doing so will likely cause deadlock with the |
130 | syncer. | | 129 | syncer. |
131 | .Pp | | 130 | .Pp |
132 | Block I/O transfers may be synchronous or asynchronous: | | 131 | Block I/O transfer completion may be notified by the |
| | | 132 | .Fa bp Ns Li "->b_iodone" |
| | | 133 | callback, by signalling |
| | | 134 | .Fn biowait |
| | | 135 | waiters, or not at all in the |
| | | 136 | .Dv B_ASYNC |
| | | 137 | case. |
133 | .Bl -dash | | 138 | .Bl -dash |
134 | .It | | 139 | .It |
135 | If synchronous, after submitting the transfer to a block device, the | | 140 | If the user sets the |
136 | user must call | | 141 | .Fa bp Ns Li "->b_iodone" |
| | | 142 | callback to a nonnull function pointer, it will be called in soft |
| | | 143 | interrupt context when the I/O transfer is complete. |
| | | 144 | The user |
| | | 145 | .Em may not |
| | | 146 | call |
137 | .Fn biowait bp | | 147 | .Fn biowait bp |
138 | in order to wait until the transfer has completed. | | 148 | in this case. |
139 | .It | | 149 | .It |
140 | If asynchronous, the user must set | | 150 | If |
141 | .Dv B_ASYNC | | 151 | .Dv B_ASYNC |
142 | in | | 152 | is set, then the I/O transfer is asynchronous and the user will not be |
143 | .Fa bp Ns Li "->b_flags" | | 153 | notified when it is completed. |
144 | and provide | | | |
145 | .Fa bp Ns Li "->b_iodone" . | | | |
146 | After submitting the transfer to a block device, | | | |
147 | .Fa bp Ns Li "->b_iodone" | | | |
148 | will eventually be called with | | | |
149 | .Fa bp | | | |
150 | as its argument when the transfer has completed. | | | |
151 | The user | | 154 | The user |
152 | .Em may not | | 155 | .Em may not |
153 | call | | 156 | call |
154 | .Fn biowait bp | | 157 | .Fn biowait bp |
155 | in this case. | | 158 | in this case. |
| | | 159 | .It |
| | | 160 | Otherwise, if |
| | | 161 | .Fa bp Ns Li "->b_iodone" |
| | | 162 | is null and |
| | | 163 | .Dv B_ASYNC |
| | | 164 | is not specified, the user may wait for the I/O transfer to complete |
| | | 165 | with |
| | | 166 | .Fn biowait bp . |
156 | .El | | 167 | .El |
157 | .Sh NESTED I/O TRANSFERS | | 168 | .Sh NESTED I/O TRANSFERS |
158 | Sometimes an I/O transfer from a single buffer in memory cannot go to a | | 169 | Sometimes an I/O transfer from a single buffer in memory cannot go to a |
159 | single location on a block device: it must be split up into smaller | | 170 | single location on a block device: it must be split up into smaller |
160 | transfers for each segment of the memory buffer. | | 171 | transfers for each segment of the memory buffer. |
161 | .Pp | | 172 | .Pp |
162 | After initializing the | | 173 | After initializing the |
163 | .Li b_flags , | | 174 | .Li b_flags , |
164 | .Li b_data , | | 175 | .Li b_data , |
165 | and | | 176 | and |
166 | .Li b_bcount | | 177 | .Li b_bcount |
167 | parameters of an I/O transfer for the buffer, called the | | 178 | parameters of an I/O transfer for the buffer, called the |
168 | .Em master | | 179 | .Em master |
| @@ -319,52 +330,61 @@ to an error code and | | | @@ -319,52 +330,61 @@ to an error code and |
319 | .Fa bp Ns Li "->b_resid" | | 330 | .Fa bp Ns Li "->b_resid" |
320 | to the number of bytes remaining to transfer. | | 331 | to the number of bytes remaining to transfer. |
321 | .It Fn biowait bp | | 332 | .It Fn biowait bp |
322 | Wait for the synchronous I/O transfer described by | | 333 | Wait for the synchronous I/O transfer described by |
323 | .Fa bp | | 334 | .Fa bp |
324 | to complete. | | 335 | to complete. |
325 | Returns the value of | | 336 | Returns the value of |
326 | .Fa bp Ns Li "->b_error" . | | 337 | .Fa bp Ns Li "->b_error" . |
327 | .Pp | | 338 | .Pp |
328 | To be called by a user requesting the I/O transfer. | | 339 | To be called by a user requesting the I/O transfer. |
329 | .Pp | | 340 | .Pp |
330 | May not be called if | | 341 | May not be called if |
331 | .Fa bp | | 342 | .Fa bp |
332 | represents an asynchronous transfer, i.e. if | | 343 | has a callback or is asynchronous -- that is, if |
| | | 344 | .Fa bp Ns Li "->b_iodone" |
| | | 345 | is set, or if |
333 | .Dv B_ASYNC | | 346 | .Dv B_ASYNC |
334 | is set in | | 347 | is set in |
335 | .Fa bp Ns Li "->b_flags" . | | 348 | .Fa bp Ns Li "->b_flags" . |
336 | .It Fn getiobuf vp waitok | | 349 | .It Fn getiobuf vp waitok |
337 | Allocate a | | 350 | Allocate a |
338 | .Fa struct buf | | 351 | .Fa struct buf |
339 | for an I/O transfer. | | 352 | for an I/O transfer. |
340 | If | | 353 | If |
341 | .Fa vp | | 354 | .Fa vp |
342 | is nonnull, the transfer is associated with it. | | 355 | is nonnull, the transfer is associated with it. |
343 | If | | 356 | If |
344 | .Fa waitok | | 357 | .Fa waitok |
345 | is false, | | 358 | is false, |
346 | returns null if none can be allocated immediately. | | 359 | returns null if none can be allocated immediately. |
347 | .Pp | | 360 | .Pp |
348 | The resulting | | 361 | The resulting |
349 | .Li struct buf | | 362 | .Li struct buf |
350 | pointer must eventually be passed to | | 363 | pointer must eventually be passed to |
351 | .Fn putiobuf | | 364 | .Fn putiobuf |
352 | to release it. | | 365 | to release it. |
353 | Do | | 366 | Do |
354 | .Em not | | 367 | .Em not |
355 | use | | 368 | use |
356 | .Xr brelse 9 . | | 369 | .Xr brelse 9 . |
357 | .Pp | | 370 | .Pp |
| | | 371 | The buffer may not be used for an asynchronous I/O transfer, because |
| | | 372 | there is no way to know when it is completed and may be safely passed |
| | | 373 | to |
| | | 374 | .Fn putiobuf . |
| | | 375 | Asynchronous I/O transfers are allowed only for buffers in the |
| | | 376 | .Xr buffercache 9 . |
| | | 377 | .Pp |
358 | May sleep if | | 378 | May sleep if |
359 | .Fa waitok | | 379 | .Fa waitok |
360 | is true. | | 380 | is true. |
361 | .It Fn putiobuf bp | | 381 | .It Fn putiobuf bp |
362 | Free | | 382 | Free |
363 | .Fa bp , | | 383 | .Fa bp , |
364 | which must have been allocated by | | 384 | which must have been allocated by |
365 | .Fn getiobuf . | | 385 | .Fn getiobuf . |
366 | Either | | 386 | Either |
367 | .Fa bp | | 387 | .Fa bp |
368 | must never have been submitted to a block device, or the I/O transfer | | 388 | must never have been submitted to a block device, or the I/O transfer |
369 | must have completed. | | 389 | must have completed. |
370 | .El | | 390 | .El |