G_EVENT(9)

πŸ’– G_EVENT(9) πŸ’–

ok so bestie, welcome to the Kernel Developer's Manual page for g_event β€” like, the GEOM events management situation. this is the g_post_event, g_waitfor_event, and g_cancel_event trio and they're literally the group chat of the GEOM framework fr fr πŸ¦‹


✨ NAME ✨

g_post_event, g_waitfor_event, g_cancel_event β€” GEOM events management, periodt πŸ’…


✨ 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);

✨ DESCRIPTION ✨

okay so picture this: the GEOM framework has its own lil event queue so it can tell its classes about important stuff that's happening. it's giving main character energy honestly πŸ‘‘

and plot twist β€” GEOM classes can use that same event queue themselves too! like, for working around some restrictions in the I/O path, where sleeping, heavy weight tasks, etc. are just not permitted. no cap. 😀

🌸 g_post_event()

this one tells the GEOM framework to call the function func with the argument arg, from the event queue. the flag argument gets passed along to malloc(9) for the memory allocations happening inside of g_post_event(). the only allowed flags are M_WAITOK and M_NOWAIT, so don't get creative bestie.

the rest of the arguments are used as references to identify the event. you can cancel an event by using any of the given references as an argument to g_cancel_event(). and β€” super important β€” the list of references has to end with a NULL value. like, it's mandatory, no exceptions 🚨

🌸 g_waitfor_event()

this is literally just the blocking version of g_post_event(). it waits until the event is finished or canceled, and then it returns. the way that it just... sits there and waits. patient king behavior πŸ’œ

🌸 g_cancel_event()

cancels all event(s) identified by ref. and here's the vibe: cancellation is equivalent to calling the requested function with the requested arguments and the argument flag set to EV_CANCEL. slay.


✨ RESTRICTIONS/CONDITIONS ✨

okay these are the rules, and they are NOT optional πŸŽ€

πŸ’… g_post_event():

  • The argument flag has to be M_WAITOK or M_NOWAIT.
  • The list of references has to end with a NULL value.

πŸ’… g_waitfor_event():

  • The argument flag has to be M_WAITOK or M_NOWAIT.
  • The list of references has to end with a NULL value.
  • The g_waitfor_event() function cannot be called from an event, since doing so would result in a deadlock. like, do not do this. it's giving disaster. πŸ’€

✨ RETURN VALUES ✨

The g_post_event() and g_waitfor_event() functions return 0 if successful; otherwise an error code is returned. simple as that bestie 🫢


✨ EXAMPLES ✨

here's an example of a function called from the event queue. she's iconic, she's serving ✨

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);
}

✨ ERRORS ✨

possible errors for the g_post_event() function:

  • [ENOMEM] β€” The flag argument was set to M_NOWAIT and there was insufficient memory. 😭

possible errors for the g_waitfor_event() function:

  • [EAGAIN] β€” The event was canceled.
  • [ENOMEM] β€” The flag argument was set to M_NOWAIT and 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) 🌈


✨ AUTHORS ✨

This manual page was written by Pawel Jakub Dawidek <pjd@FreeBSD.org>. tysm for your service king πŸ«‘πŸ’–


and that's the whole page bestie!! Debian, dated January 16, 2004, G_EVENT(9) β€” mwah, go forth and manage your events responsibly πŸ’…πŸŒΈβœ¨

πŸ“¦ where this page comes from