| G_BIO(9) | Kernel Developer's Manual | G_BIO(9) |
g_new_bio,
g_clone_bio, g_destroy_bio,
g_print_bio, g_reset_bio
— GEOM bio controlling functions
#include
<sys/bio.h>
#include <geom/geom.h>
struct bio *
g_new_bio(void);
struct bio *
g_alloc_bio(void);
struct bio *
g_clone_bio(struct
bio *bp);
struct bio *
g_duplicate_bio(struct
bio *bp);
void
g_destroy_bio(struct
bio *bp);
void
g_print_bio(struct
bio *bp);
void
g_reset_bio(struct
bio *bp);
A struct bio is used by GEOM to describe I/O requests, its most important fields are described below:
BIO_READBIO_WRITEBIO_DELETEBIO_GETATTRBIO_FLUSHBIO_ERROR is set.BIO_GETATTR request.The
g_new_bio()
function allocates a new, empty bio structure.
g_alloc_bio()
- same as g_new_bio(), but always succeeds
(allocates bio with the M_WAITOK malloc flag).
The
g_clone_bio()
function allocates a new bio structure and copies the
following fields from the bio given as an argument to
clone: bio_cmd, bio_length,
bio_offset, bio_data,
bio_attribute. The field
bio_parent in the clone points to the passed
bio and the field bio_children
in the passed bio is incremented.
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:
g_duplicate_bio()
- same as g_clone_bio(), but always succeeds
(allocates bio with the M_WAITOK malloc flag).
The
g_destroy_bio()
function deallocates and destroys the given bio
structure.
The
g_print_bio()
function prints information about the given bio
structure (for debugging purposes).
The
g_reset_bio()
function resets the given bio structure back to its
initial state. g_reset_bio() preserves internal data
structures, while setting all user visible fields to their initial values.
When reusing a bio obtained from
g_new_bio(), g_alloc_bio(),
g_clone_bio(), or
g_duplicate_bio() for multiple transactions,
g_reset_bio() must be called between the
transactions in lieu of
bzero().
While not strictly required for a bio structure
created by other means, g_reset_bio() should be used
to initialize it and between transactions.
The g_new_bio() and
g_clone_bio() functions return a pointer to the
allocated bio, or NULL if an
error occurred.
Implementation of
“NULL-transformation”, meaning that an
I/O request is cloned and scheduled down without any modifications. Let us
assume that field ex_consumer in structure
example_softc contains a consumer attached to the
provider we want to operate on.
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->consumer) as well,
* if there is only one in our geom.
*/
g_io_request(cbp, sc->ex_consumer);
}
geom(4), DECLARE_GEOM_CLASS(9), g_access(9), g_attach(9), g_consumer(9), g_data(9), g_event(9), g_geom(9), g_provider(9), g_provider_by_name(9), g_wither_geom(9)
This manual page was written by Pawel Jakub Dawidek <pjd@FreeBSD.org>.
| March 7, 2018 | Debian |