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 duringnbd_opt_go(3). so like... don't celebrate yet. it is still necessary to usenbd_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 callnbd_add_meta_context(3)from inside the context of the callback function. nope. not happening. instead, your code must copy anynameneeded 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 beNULL: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:
nbd_add_meta_context(3)nbd_aio_opt_list_meta_context_queries(3)nbd_can_meta_context(3)nbd_connect_uri(3)nbd_create(3)nbd_opt_go(3)nbd_opt_list_meta_context(3)nbd_set_export_name(3)nbd_set_opt_mode(3)libnbd(3)
π«Ά AUTHORS π«Ά
- Eric Blake
- Richard W.M. Jones
legends. both of them. π
πΈ COPYRIGHT πΈ
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
- centos-stream 10: libnbd-devel 1.25.8-1.el10 Β· LGPL-2.0-or-later AND BSD-3-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms