NBD_OPT_LIST_META_CONTEXT_QUERIES(3)

πŸ’… nbd_opt_list_meta_context_queries(3) ✨

okay so bestie, welcome to nbd_opt_list_meta_context_queries β€” the libnbd function that lists available meta contexts, using an explicit query list. it's giving "let me ask the server exactly what i want" energy, and honestly? iconic. this page lives in the libnbd manual, section 3, and it's got the whole rundown. πŸŽ€


✨ SYNOPSIS ✨

like, here's the shape of it, don't touch the code, it's literally perfect:

#include <libnbd.h>

typedef struct {
  int (*callback) (void *user_data, const char *name);
  void *user_data;
  void (*free) (void *user_data);
} nbd_context_callback;

int nbd_opt_list_meta_context_queries (
      struct nbd_handle *h, char **queries,
      nbd_context_callback context_callback
    );

that struct? that's your nbd_context_callback. we love her. 🫢


🌸 DESCRIPTION 🌸

so what are we actually doing here? we're asking the server to list the available meta contexts that are attached to the export β€” and "the export" means whichever one you set most recently with nbd_set_export_name(3) or nbd_connect_uri(3). and the twist! you're passing in an explicit list of queries as a parameter. if you'd rather reuse an implicit query list instead, go look at nbd_opt_list_meta_context(3). both are valid, we don't gatekeep. πŸ’–

⚠️ heads up: this can only be used if nbd_set_opt_mode(3) turned on option mode. no option mode, no party. 🚫

now, the NBD protocol lets a client decide how many queries to send to the server. for this function, that list is right there in the queries parameter β€” explicit, out in the open, no guessing. and here's how the server responds:

  • when the list is empty, the server will typically reply with all the contexts it supports β€” the whole buffet, no filter.
  • when the list is non-empty, the server replies only with supported contexts that match what the client asked for. picky, but in a good way.
😭 okay so important caveat: a reply from the server might be encoded to represent several feasible contexts within one string, rather than multiple strings per actual context name that would actually succeed during nbd_opt_go(3). so like... don't celebrate yet. it is still necessary to use nbd_can_meta_context(3) after connecting to see which contexts are actually supported. fr fr. ✨

πŸ¦‹ the callback πŸ¦‹

the context function gets called once per server reply β€” with whatever user_data you passed to this function, and with name supplied by the server. cute, right?

πŸ’€ but listen: it is not safe to call nbd_add_meta_context(3) from inside the context of the callback function. nope. not happening. instead, your code must copy any name needed for later use after this function completes. copy it. own it. take it with you. πŸ™ˆ

at present, the return value of the callback is ignored β€” yeah, kind of rude β€” although a return of -1 should be avoided. don't do it. we're being polite. πŸŽ€

πŸ“ the return value, the vibes, and the chaos πŸ“

for convenience (and honestly, slay), when this function succeeds it returns the number of replies returned by the server. so like, count-y. useful.

now for the messy part, and we're not sugarcoating it:

πŸ’€ not all servers understand this request! and even when it is understood, the server might intentionally send an empty list because it does not support the requested context, or it may encounter a failure after delivering partial results. thus, this function may succeed even when no contexts are reported, or may fail but have a non-empty list. yes. both. it's that kind of function. 😭

likewise, the NBD protocol does not specify an upper bound for the number of replies that might be advertised β€” so client code should be aware that a server may send a lengthy list. like, a long one. be ready. hydrate. 🧚


⭐ RETURN VALUE ⭐

this call returns an integer β‰₯ 0. that's the whole vibe. no cap. πŸ’…


πŸ’œ ERRORS πŸ’œ

on error, -1 is returned. yep.

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

🚨 also, these parameters must not be NULL: h, queries. for more info see "Non-NULL parameters" in libnbd(3). don't pass NULL, bestie, it's not the move.

πŸ‘‘ HANDLE STATE πŸ‘‘

nbd_opt_list_meta_context_queries can be called when the handle is in the following state β€” vibe check those checkmarks:

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

so basically: only during connecting & handshaking in option mode. that's her one window. main character energy, honestly. πŸ‘‘


🌈 VERSION 🌈

this function first appeared in libnbd 1.16. throwback. πŸŽ€

if you need to test whether this function is available at compile time, check if the following macro is defined β€” here it is, verbatim:

#define LIBNBD_HAVE_NBD_OPT_LIST_META_CONTEXT_QUERIES 1

yes, the whole name, yes it's long, no we're not shortening it. 😌


πŸ”₯ SEE ALSO πŸ”₯

go read these, they're all part of the extended universe:


🫢 AUTHORS 🫢

  • Eric Blake
  • Richard W.M. Jones

legends. both of them. πŸ’–


Copyright Red Hat


πŸŽ€ LICENSE πŸŽ€

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, it's kind of the whole deal) ⭐

okay that's the page!! mwah πŸ’‹ this was libnbd-1.25.8, dated 2026-10, filed under nbd_opt_list_meta_context_queries(3) β€” go forth and query those contexts, bestie. πŸ¦‹βœ¨πŸ’…

πŸ“¦ where this page comes from