1 .\" 2 .\" Copyright (c) 2004-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org> 3 .\" All rights reserved. 4 .\" 5 .\" Redistribution and use in source and binary forms, with or without 6 .\" modification, are permitted provided that the following conditions 7 .\" are met: 8 .\" 1. Redistributions of source code must retain the above copyright 9 .\" notice, this list of conditions and the following disclaimer. 10 .\" 2. Redistributions in binary form must reproduce the above copyright 11 .\" notice, this list of conditions and the following disclaimer in the 12 .\" documentation and/or other materials provided with the distribution. 13 .\" 14 .\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR 15 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17 .\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT, 18 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 .\" 25 .Dd August 7, 2019 26 .Dt G_BIO 9 27 .Os 28 .Sh NAME 29 .Nm g_new_bio , 30 .Nm g_clone_bio , 31 .Nm g_destroy_bio , 32 .Nm g_format_bio , 33 .Nm g_print_bio , 34 .Nm g_reset_bio 35 .Nd "GEOM bio controlling functions" 36 .Sh SYNOPSIS 37 .In sys/bio.h 38 .In geom/geom.h 39 .Ft "struct bio *" 40 .Fn g_new_bio void 41 .Ft "struct bio *" 42 .Fn g_alloc_bio void 43 .Ft "struct bio *" 44 .Fn g_clone_bio "struct bio *bp" 45 .Ft "struct bio *" 46 .Fn g_duplicate_bio "struct bio *bp" 47 .Ft void 48 .Fn g_destroy_bio "struct bio *bp" 49 .Ft void 50 .Fn g_format_bio "struct sbuf *sb" "const struct bio *bp" 51 .Ft void 52 .Fo g_print_bio 53 .Fa "struct sbuf *sb" "const char *prefix" "const struct bio *bp" 54 .Fa "const char *fmtsuffix" ... 55 .Fc 56 .Ft void 57 .Fn g_reset_bio "struct bio *bp" 58 .Sh DESCRIPTION 59 A 60 .Vt "struct bio" 61 is used by GEOM to describe I/O requests, its 62 most important fields are described below: 63 .Bl -tag -width ".Va bio_attribute" 64 .It Va bio_cmd 65 I/O request command. 66 There are five I/O requests available in GEOM: 67 .Bl -tag -width ".Dv BIO_GETATTR" 68 .It Dv BIO_READ 69 A read request. 70 .It Dv BIO_WRITE 71 A write request. 72 .It Dv BIO_DELETE 73 Indicates that a certain range of data is no longer used and that 74 it can be erased or freed as the underlying technology supports. 75 Technologies like flash adaptation layers can arrange to erase the relevant 76 blocks before they will become reassigned and cryptographic devices may 77 want to fill random bits into the range to reduce the amount of data 78 available for attack. 79 .It Dv BIO_GETATTR 80 Inspect and manipulate out-of-band 81 attributes on a particular provider or path. 82 Attributes are named by ascii strings and are stored in the 83 .Va bio_attribute 84 field. 85 .It Dv BIO_FLUSH 86 Tells underlying providers to flush their write caches. 87 .El 88 .It Va bio_flags 89 Available flags: 90 .Bl -tag -width ".Dv BIO_ERROR" 91 .It Dv BIO_ERROR 92 Request failed (error value is stored in 93 .Va bio_error 94 field). 95 .It Dv BIO_DONE 96 Request finished. 97 .El 98 .It Va bio_cflags 99 Private use by the consumer. 100 .It Va bio_pflags 101 Private use by the provider. 102 .It Va bio_offset 103 Offset into provider. 104 .It Va bio_data 105 Pointer to data buffer. 106 .It Va bio_error 107 Error value when 108 .Dv BIO_ERROR 109 is set. 110 .It Va bio_done 111 Pointer to function which will be called when the request is finished. 112 .It Va bio_driver1 113 Private use by the provider. 114 .It Va bio_driver2 115 Private use by the provider. 116 .It Va bio_caller1 117 Private use by the consumer. 118 .It Va bio_caller2 119 Private use by the consumer. 120 .It Va bio_attribute 121 Attribute string for 122 .Dv BIO_GETATTR 123 request. 124 .It Va bio_from 125 Consumer to use for request (attached to provider stored in 126 .Va bio_to 127 field) (typically read-only for a class). 128 .It Va bio_to 129 Destination provider (typically read-only for a class). 130 .It Va bio_length 131 Request length in bytes. 132 .It Va bio_completed 133 Number of bytes completed, but they may not be completed from 134 the front of the request. 135 .It Va bio_children 136 Number of 137 .Vt bio 138 clones (typically read-only for a class). 139 .It Va bio_inbed 140 Number of finished 141 .Vt bio 142 clones. 143 .It Va bio_parent 144 Pointer to parent 145 .Vt bio . 146 .El 147 .Pp 148 The 149 .Fn g_new_bio 150 function allocates a new, empty 151 .Vt bio 152 structure. 153 .Pp 154 .Fn g_alloc_bio 155 - same as 156 .Fn g_new_bio , 157 but always succeeds (allocates bio with the 158 .Dv M_WAITOK 159 malloc flag). 160 .Pp 161 The 162 .Fn g_clone_bio 163 function allocates a new 164 .Vt bio 165 structure and copies the following fields from the 166 .Vt bio 167 given as an argument to clone: 168 .Va bio_cmd , 169 .Va bio_length , 170 .Va bio_offset , 171 .Va bio_data , 172 .Va bio_attribute . 173 The field 174 .Va bio_parent 175 in the clone points to the passed 176 .Vt bio 177 and the field 178 .Va bio_children 179 in the passed 180 .Vt bio 181 is incremented. 182 .Pp 183 This function should be used for every request which enters through 184 the provider of a particular geom and needs to be scheduled down. 185 Proper order is: 186 .Pp 187 .Bl -enum -compact 188 .It 189 Clone the received 190 .Vt "struct bio" . 191 .It 192 Modify the clone. 193 .It 194 Schedule the clone on its own consumer. 195 .El 196 .Pp 197 .Fn g_duplicate_bio 198 - same as 199 .Fn g_clone_bio , 200 but always succeeds (allocates bio with the 201 .Dv M_WAITOK 202 malloc flag). 203 .Pp 204 The 205 .Fn g_destroy_bio 206 function deallocates and destroys the given 207 .Vt bio 208 structure. 209 .Pp 210 The 211 .Fn g_format_bio 212 function prints information about the given 213 .Vt bio 214 structure into the provided 215 .Vt sbuf . 216 .Pp 217 The 218 .Fn g_print_bio 219 function is a convenience wrapper around 220 .Fn g_format_bio 221 that can be used for debugging purposes. 222 It prints a provided 223 .Fa prefix 224 string, followed by the formatted 225 .Vt bio , 226 followed by a 227 .Fa fmtsuffix 228 in the style of 229 .Xr printf 9 . 230 Any of the prefix or suffix strings may be the empty string. 231 .Fn g_print_bio 232 always prints a newline character at the end of the line. 233 .Pp 234 The 235 .Fn g_reset_bio 236 function resets the given 237 .Vt bio 238 structure back to its initial state. 239 .Fn g_reset_bio 240 preserves internal data structures, while setting all 241 user visible fields to their initial values. 242 When reusing a 243 .Vt bio 244 obtained from 245 .Fn g_new_bio , 246 .Fn g_alloc_bio , 247 .Fn g_clone_bio , 248 or 249 .Fn g_duplicate_bio 250 for multiple transactions, 251 .Fn g_reset_bio 252 must be called between the transactions in lieu of 253 .Fn bzero . 254 While not strictly required for a 255 .Vt bio 256 structure created by other means, 257 .Fn g_reset_bio 258 should be used to initialize it and between transactions. 259 .Sh RETURN VALUES 260 The 261 .Fn g_new_bio 262 and 263 .Fn g_clone_bio 264 functions return a pointer to the allocated 265 .Vt bio , 266 or 267 .Dv NULL 268 if an error occurred. 269 .Sh EXAMPLES 270 Implementation of 271 .Dq Dv NULL Ns -transformation , 272 meaning that an I/O request is cloned and scheduled down without any 273 modifications. 274 Let us assume that field 275 .Va ex_consumer 276 in structure 277 .Vt example_softc 278 contains a consumer attached to the provider we want to operate on. 279 .Bd -literal -offset indent 280 void 281 example_start(struct bio *bp) 282 { 283 struct example_softc *sc; 284 struct bio *cbp; 285 286 g_print_bio("Request received: ", bp, ""); 287 288 sc = bp->bio_to->geom->softc; 289 if (sc == NULL) { 290 g_io_deliver(bp, ENXIO); 291 return; 292 } 293 294 /* Let's clone our bio request. */ 295 cbp = g_clone_bio(bp); 296 if (cbp == NULL) { 297 g_io_deliver(bp, ENOMEM); 298 return; 299 } 300 cbp->bio_done = g_std_done; /* Standard 'done' function. */ 301 302 /* Ok, schedule it down. */ 303 /* 304 * The consumer can be obtained from 305 * LIST_FIRST(&bp->bio_to->geom->consumer) as well, 306 * if there is only one in our geom. 307 */ 308 g_io_request(cbp, sc->ex_consumer); 309 } 310 .Ed 311 .Sh SEE ALSO 312 .Xr geom 4 , 313 .Xr DECLARE_GEOM_CLASS 9 , 314 .Xr g_access 9 , 315 .Xr g_attach 9 , 316 .Xr g_consumer 9 , 317 .Xr g_data 9 , 318 .Xr g_event 9 , 319 .Xr g_geom 9 , 320 .Xr g_provider 9 , 321 .Xr g_provider_by_name 9 , 322 .Xr g_wither_geom 9 323 .Sh AUTHORS 324 .An -nosplit 325 This manual page was written by 326 .An Pawel Jakub Dawidek Aq Mt pjd@FreeBSD.org . 327