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

	printf("Request received: ");
	g_print_bio(bp);
	printf("\\n");

	sc = bp->bio_to->geom->softc;
	if (sc == NULL) {
		g_io_deliver(bp, ENXIO);
		return;
	}

	/* Let's clone our bio request. */
	cbp = g_clone_bio(bp);
	if (cbp == NULL) {
		g_io_deliver(bp, ENOMEM);
		return;
	}
	cbp->bio_done = g_std_done;	/* Standard 'done' function. */

	/* Ok, schedule it down. */
	/*
	 * The consumer can be obtained from
	 * LIST_FIRST(&bp->bio_to->geom->consumers) as well,
	 * if there is only one in our geom.
	 */
	g_io_request(cbp, sc->ex_consumer);
}
.Ed
.Sh SEE ALSO
.Xr geom 4 ,
.Xr DECLARE_GEOM_CLASS 9 ,
.Xr g_access 9 ,
.Xr g_attach 9 ,
.Xr g_consumer 9 ,
.Xr g_data 9 ,
.Xr g_event 9 ,
.Xr g_geom 9 ,
.Xr g_provider 9 ,
.Xr g_provider_by_name 9 ,
.Xr g_wither_geom 9
.Sh AUTHORS
.An -nosplit
This manual page was written by
.An Pawel Jakub Dawidek Aq pjd@FreeBSD.org .
OpenPOWER on IntegriCloud