G_EVENT(9)
π G_EVENT(9) β like, the GEOM events manual, bestie
okay so this is a page from the Kernel Developer's Manual and it's literally all about g_post_event, g_waitfor_event, g_cancel_event β the GEOM events management girlies π if you're writing GEOM classes you're gonna want this, iykyk.
β¨ NAME β¨
g_post_event, g_waitfor_event, g_cancel_event β GEOM events management π
π¦ SYNOPSIS π¦
#include <geom/geom.h>
int
g_post_event(g_event_t *func, void *arg, int flag, ...);
int
g_waitfor_event(g_event_t *func, void *arg, int flag, ...);
void
g_cancel_event(void *ref);
struct g_event *
g_alloc_event(int flag);
void
g_post_event_ep(g_event_t *func, void *arg, struct g_event *ep, ...);
πΈ DESCRIPTION πΈ
so the GEOM framework has its own event queue, right? it uses it to tell classes about important events β main character energy fr fr π and like, GEOM classes can totally use it too for their own stuff, for example to work around some restrictions in the I/O path where sleeping, heavy weight tasks, etc. are not permitted. no cap, that's the whole point.
π quick vibe check: sleeping and heavy lifting in the I/O path = not allowed. that's why the event queue exists.
g_post_event()β tells the GEOM framework to call functionfuncwith argumentargfrom the event queue. theflagargument gets passed tomalloc(9)for memory allocations inside ofg_post_event(). the only allowed flags areM_WAITOKandM_NOWAIT. the rest of the arguments are used as references to identify the event. an event can be canceled by using any of the given references as an argument tog_cancel_event(). and the list of references has to end with aNULLvalue β don't forget or it's giving chaos πg_waitfor_event()β the blocking version ofg_post_event(). it waits until the event is finished or canceled and then returns. patient queen π«Άg_post_event_ep()β posts the event with a pre-allocatedstruct g_event. an event may be pre-allocated withg_alloc_event(). efficient icon βg_cancel_event()β cancels all event(s) identified byref. and here's the slay: cancellation is equivalent to calling the requested function with requested arguments and argumentflagset toEV_CANCEL. π
π§ RESTRICTIONS/CONDITIONS π§
okay bestie, read this part, it's literally the rules β¨
g_post_event()
- the argument
flaghas to beM_WAITOKorM_NOWAIT. - the list of references has to end with a
NULLvalue.
g_waitfor_event()
- the argument
flaghas to beM_WAITOKorM_NOWAIT. - the list of references has to end with a
NULLvalue. - the
g_waitfor_event()function cannot be called from an event, since doing so would result in a deadlock. π©Έ like, do not do it, that's not the vibe at all.
g_alloc_event()
- the argument
flaghas to beM_WAITOKorM_NOWAIT. - the returned
struct g_event *must be freed withg_free()ifg_post_event_ep()is not called. π literally don't leak it, that's so not cute
π RETURN VALUES π
the g_post_event() and g_waitfor_event() functions return 0 if successful; otherwise an error code is returned. simple as that π
π§ EXAMPLES π§
here's an example of a function called from the event queue β periodt:
void
example_event(void *arg, int flag)
{
if (flag == EV_CANCEL) {
printf("Event with argument %p canceled.\n", arg);
return;
}
printf("Event with argument %p called.\n", arg);
}
see how it handles the EV_CANCEL case first? that's the self-care check π
π ERRORS π
possible errors for the g_post_event() function:
[ENOMEM]β theflagargument was set toM_NOWAITand there was insufficient memory. π
possible errors for the g_waitfor_event() function:
[EAGAIN]β the event was canceled. π[ENOMEM]β theflagargument was set toM_NOWAITand there was insufficient memory. π
π₯ SEE ALSO π₯
geom(4), DECLARE_GEOM_CLASS(9), g_access(9), g_attach(9), g_bio(9), g_consumer(9), g_data(9), g_geom(9), g_provider(9), g_provider_by_name(9), g_wither_geom(9)
like, the whole friend group honestly π«Ά go read them all
π AUTHORS π
this manual page was written by Pawel Jakub Dawidek <pjd@FreeBSD.org>. iconic behavior, we stan π
and that's the page, bestie! πΈ this Debian build dropped on July 23, 2021 and it's filed under G_EVENT(9) β go forth and queue your events responsibly, mwah πβ¨
π¦ where this page comes from
- freebsd 14.5: base 14.5
- freebsd 15.1: base 15.1
- Copyright (c) 2004 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