nbd_aio_cache(3)

πŸ’… nbd_aio_cache β€” the LIBNBD girlie's guide to sending a cache (prefetch) command to the NBD server ✨

okay so bestie, you're looking at nbd_aio_cache(3) from the LIBNBD manual, and honestly? it's a whole vibe. let's get into it πŸŽ€


✨ NAME ✨

nbd_aio_cache β€” send cache (prefetch) command to the NBD server. that's it, that's the function, and she's iconic for it πŸ’–


🌸 SYNOPSIS 🌸

like, here's the actual code, copy it exactly or it won't slay:

#include <libnbd.h>

typedef struct {
  int (*callback) (void *user_data, int *error);
  void *user_data;
  void (*free) (void *user_data);
} nbd_completion_callback;

int64_t nbd_aio_cache (
          struct nbd_handle *h, uint64_t count,
          uint64_t offset,
          nbd_completion_callback completion_callback,
          uint32_t flags
        );

no cap, that's the whole shape of her πŸ¦‹


πŸ’« DESCRIPTION πŸ’«

so what she does: she issues the cache (prefetch) command to the NBD server. periodt. πŸ”₯

now, to check if the command actually completed, you call nbd_aio_command_completed(3). OR β€” and this is the fun part β€” you can supply the optional completion_callback, which gets invoked as described in "Completion callbacks" in libnbd(3). cute, right? 🫢

and the other parameters? they behave exactly as documented in nbd_cache(3). go read that one too, bestie, i'm not gonna retype it for you πŸ’…


πŸ‘‘ RETURN VALUE πŸ‘‘

this call returns the 64 bit cookie of the command. the cookie is β‰₯ 1. and yes, cookies are unique β€” but only per libnbd handle, not globally. so don't go thinking your cookie is special on a universal level, she's just special to her handle πŸ˜­πŸ“


πŸ’€ ERRORS πŸ’€

on error, -1 is returned. rough, i know.

for how to get further details of the error, refer to "ERROR HANDLING" in libnbd(3).

also: the following parameters must not be NULL: h. for more info see "Non-NULL parameters" in libnbd(3). so like... don't pass a NULL handle, that's not the move πŸ™ˆ


⭐ NOTES ⭐

🧚 Strict call 🧚

by default, libnbd will reject attempts to use this function with parameters that are likely to result in server failure β€” such as requesting an unknown command flag. like, she's protecting you from yourself, okay?

and if you want to change that energy? the nbd_set_strict_mode(3) function can be used to alter which scenarios should await a server reply rather than failing fast. iykyk πŸ’œ


🌈 HANDLE STATE 🌈

nbd_aio_cache can be called when the handle is in the following state:

  • Handle created, before connecting β€” ❌ error
  • Connecting β€” ❌ error
  • Connecting & handshaking (opt_mode) β€” ❌ error
  • Connected to the server β€” βœ… allowed
  • Connection shut down β€” ❌ error
  • Handle dead β€” ❌ error

so basically: she only vibes with a handle that's actually connected to the server. everything else? error. the vibe check has been conducted and you did not pass πŸ˜­βœ‹


πŸŽ€ VERSION πŸŽ€

this function first appeared in libnbd 1.0. she's an OG, been here since the beginning, main character energy fr fr πŸ‘‘

if you need to test if this function is available at compile time, check if the following macro is defined:

#define LIBNBD_HAVE_NBD_AIO_CACHE 1

πŸ¦‹ SEE ALSO πŸ¦‹

go be nosy, bestie, these are all linked:

the whole friend group, honestly πŸ«ΆπŸ’–


πŸ’œ AUTHORS πŸ’œ

  • Eric Blake
  • Richard W.M. Jones

shoutout to the icons who made this happen 🌟


Copyright Red Hat


✨ LICENSE ✨

okay, legal moment, but make it cute β€” and keep every word, because this part actually matters:

this library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

this library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. see the GNU Lesser General Public License for more details.

you should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

fr fr read the license, bestie, it's giving "responsible queen" πŸ’…

and that's the page!! brought to you by libnbd-1.25.8, dated 2026-10-13 β€” mwah, love u, go prefetch something πŸ“πŸ’–βœ¨

πŸ“¦ where this page comes from