G_BIO(9)
hey bestie π this is G_BIO(9) from the Kernel Developer's Manual β aka the GEOM bio controlling functions page, and we're gonna make it make sense β¨
πΈ NAME πΈ
g_new_bio, g_clone_bio, g_destroy_bio, g_format_bio, g_print_bio, g_reset_bio β GEOM bio controlling functions. That's the whole vibe: managing bios in GEOM π
β¨ SYNOPSIS β¨
#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_format_bio(struct sbuf *sb, const struct bio *bp);
void
g_print_bio(struct sbuf *sb, const char *prefix, const struct bio *bp,
const char *fmtsuffix, ...);
void
g_reset_bio(struct bio *bp);
π¦ DESCRIPTION π¦
okay so a struct bio is what GEOM uses to describe I/O requests, and its most important fields are right here β no cap, every single one matters:
bio_cmdβ I/O request command. There are five I/O requests available in GEOM:BIO_READβ A read request.BIO_WRITEβ A write request.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.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 thebio_attributefield.BIO_FLUSHβ Tells underlying providers to flush their write caches.
bio_flagsβ Available flags:BIO_ERRORβ Request failed (error value is stored inbio_errorfield).BIO_DONEβ Request finished.
bio_cflagsβ Private use by the consumer.bio_pflagsβ Private use by the provider.bio_offsetβ Offset into provider.bio_dataβ Pointer to data buffer.bio_errorβ Error value whenBIO_ERRORis set.bio_doneβ Pointer to function which will be called when the request is finished.bio_driver1β Private use by the provider.bio_driver2β Private use by the provider.bio_caller1β Private use by the consumer.bio_caller2β Private use by the consumer.bio_attributeβ Attribute string forBIO_GETATTRrequest.bio_fromβ Consumer to use for request (attached to provider stored inbio_tofield) (typically read-only for a class).bio_toβ Destination provider (typically read-only for a class).bio_lengthβ Request length in bytes.bio_completedβ Number of bytes completed, but they may not be completed from the front of the request.bio_childrenβ Number of bio clones (typically read-only for a class).bio_inbedβ Number of finished bio clones.bio_parentβ Pointer to parent bio.
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). It's giving "no failures, bestie" energy β¨
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:
- Clone the received
struct bio. - Modify the clone.
- Schedule the clone on its own consumer.
g_duplicate_bio() β same as g_clone_bio(), but always succeeds (allocates bio with the M_WAITOK malloc flag). Iconic, honestly π
The g_destroy_bio() function deallocates and destroys the given bio structure. bye-bye bio π
The g_format_bio() function prints information about the given bio structure into the provided sbuf.
The g_print_bio() function is a convenience wrapper around g_format_bio() that can be used for debugging purposes. It prints a provided prefix string, followed by the formatted bio, followed by a fmtsuffix in the style of printf(9). Any of the prefix or suffix strings may be the empty string. g_print_bio() always prints a newline character at the end of the line.
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. periodt π
π₯ RETURN VALUES π₯
The g_new_bio() and g_clone_bio() functions return a pointer to the allocated bio, or NULL if an error occurred. That's the return-value tea, bestie ββ¨
π EXAMPLES π
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;
g_print_bio("Request received: ", bp, "");
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);
}
π SEE ALSO π
dtrace_io(4), 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) β go read these too, bestie π«Ά
π AUTHORS π
This manual page was written by Pawel Jakub Dawidek <pjd@FreeBSD.org>. Absolute icon behavior π
okay that's the whole page, bestie! This one is from Debian, dated October 26, 2025, for G_BIO(9) β bye! πβ¨π¦
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2004-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms