G_BIO(9)
π G_BIO(9) π
okay so bestie, welcome to G_BIO(9), from the Kernel Developer's Manual π β this is the page about all the little bio-wrangling functions GEOM uses to boss around I/O requests. grab a snack, we're getting into it π
β¨ NAME β¨
g_new_bio, g_clone_bio, g_destroy_bio, g_print_bio, g_reset_bio β the GEOM bio controlling functions, aka the girlies who make, copy, yeet, show off and reset bios π¦
πΈ 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_print_bio(struct bio *bp);
void
g_reset_bio(struct bio *bp);
π DESCRIPTION π
So a struct bio is what GEOM uses to describe I/O requests. Its most important fields are giving main character energy, and here they all are π:
bio_cmdβ the 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β says 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β the available flags:BIO_ERRORβ request failed (error value is stored in thebio_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. fresh out the box, no notes β¨
g_alloc_bio() β same as g_new_bio(), but always succeeds (allocates bio with the M_WAITOK malloc flag). she does not miss π―
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. it's giving identical twins fr π―
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.
like, in that order. don't freestyle it bestie π
g_duplicate_bio() β same as g_clone_bio(), but always succeeds (allocates bio with the M_WAITOK malloc flag). no cap π
The g_destroy_bio() function deallocates and destroys the given bio structure. bye girl ππ
The g_print_bio() function prints information about the given bio structure (for debugging purposes). it's literally just here so you can snoop π΅οΈ
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. glow-up-and-restart energy πβ¨
π RETURN VALUES π
The g_new_bio() and g_clone_bio() functions return a pointer to the allocated bio, or NULL if an error occurred. either she ate or she didn't, no in-between π
π 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;
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);
}
π¦ SEE ALSO π¦
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) β the whole friend group, go read them too π
π AUTHORS π
This manual page was written by Pawel Jakub Dawidek <pjd@FreeBSD.org>. king behaviour, we love him π
and that's the whole page bestie, you're officially bio-literate, slay π β¨
this icon was brought to you by Debian, version stamped Mar 7, 2018, page G_BIO(9) β mwah, go forth and schedule responsibly π«Άπ
π¦ where this page comes from
- debian bookworm: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- debian trixie: freebsd-manpages 12.2-2 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu jammy: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu noble: freebsd-manpages 12.2-1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu questing: freebsd-manpages 12.2-2
- ubuntu resolute: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- ubuntu stonking: freebsd-manpages 12.2-2build1 Β· BSD-2-Clause-FreeBSD AND BSD-4-Clause
- Copyright (c) 2004-2006 Pawel Jakub Dawidek <pjd@FreeBSD.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms