nbd_opt_set_meta_context(3)
πΈ nbd_opt_set_meta_context(3) πΈ
okay bestie, so this little cutie lives in the libnbd manual (yep, that's the manual name, she's famous), and she's here to let you hand-pick meta contexts with the ~implicit query list~. it's giving backstage-pass energy. let's get into it π
β¨ NAME β¨
nbd_opt_set_meta_context β select specific meta contexts, using implicit query list
π SYNOPSIS π
#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_set_meta_context (
struct nbd_handle *h,
nbd_context_callback context_callback
);
π¦ DESCRIPTION π¦
so the whole vibe here: you're asking the server to supply, like, all the recognized meta contexts that got registered through prior calls to nbd_add_meta_context(3) β and it does this together with the export you already specified via the most recent nbd_set_export_name(3) or nbd_connect_uri(3). iconic behavior.
heads up though: you can only use this if nbd_set_opt_mode(3) has enabled option mode. no opt mode, no party π
ngl, normally this function is redundant β nbd_opt_go(3) automatically does the exact same task if structured replies or extended headers have already been negotiated. but likeβ¦ manual control over meta context requests? lowkey useful for fine-grained testing of how a server handles unusual negotiation sequences. it's giving "let me poke the server and see what happens" energy fr fr. often, you'll pair this function with nbd_set_request_meta_context(3) to bypass the automatic context request that nbd_opt_go(3) normally performs. team effort π«Ά
the NBD protocol lets a client decide how many queries to ask the server. instead of taking that list of queries as a parameter to this function, libnbd reuses the current list of requested meta contexts as set by nbd_add_meta_context(3). and if you want a different list of queries, you can use nbd_clear_meta_contexts(3) to set it up (and psst β see nbd_opt_set_meta_context_queries(3) if you'd rather pass an explicit list of contexts instead). since this function is primarily designed for testing servers, libnbd does not prevent you from using it on an empty list, or when nbd_set_request_structured_replies(3) has disabled structured replies β all so you can see how a server behaves. chaotic but valid π
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. also, each server name stays visible through nbd_can_meta_context(3) until the next attempt at nbd_set_export_name(3) or nbd_opt_set_meta_context(3), as well as nbd_opt_go(3) or nbd_opt_info(3) that trigger an automatic meta context request. π
β οΈ bestie, remember: it is not safe to call any"nbd_*"APIs from within the context of the callback function. at present, the return value of the callback is ignored, although a return of-1should be avoided. don't do it, i'm begging π
for convenience (she's thoughtful like that π), when this function succeeds, it returns the number of replies returned by the server.
not all servers understand this request, and even when it is understood, the server might intentionally send an empty list because it doesn't support the requested context, or it may encounter a failure after delivering partial results. so likeβ¦ this function may succeed even when no contexts are reported, or it may fail but have a non-empty list. main character plot twist, honestly π
π₯ RETURN VALUE π₯
this call returns an integer β₯ 0. slay.
π ERRORS π
on error -1 is returned.
refer to "ERROR HANDLING" in libnbd(3) for how to get further details of the error.
the following parameters must not be NULL: "h". for more information see "Non-NULL parameters" in libnbd(3).
π HANDLE STATE π
nbd_opt_set_meta_context can be called when the handle is in the following state:
- 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 yeah, she's picky β only the handshake window works π§
β VERSION β
this function first appeared in libnbd 1.16.
if you need to test if this function is available at compile time, check if the following macro is defined:
#define LIBNBD_HAVE_NBD_OPT_SET_META_CONTEXT 1
π SEE ALSO π
nbd_add_meta_context(3), nbd_aio_opt_set_meta_context(3), nbd_can_meta_context(3), nbd_clear_meta_contexts(3), nbd_connect_uri(3), nbd_create(3), nbd_opt_go(3), nbd_opt_info(3), nbd_opt_list_meta_context(3), nbd_opt_set_meta_context(3), nbd_opt_set_meta_context_queries(3), nbd_set_export_name(3), nbd_set_opt_mode(3), nbd_set_request_meta_context(3), nbd_set_request_structured_replies(3), libnbd(3).
π AUTHORS π
Eric Blake
Richard W.M. Jones
πΈ 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
and that's the whole page, bestie π«Ά this one's from libnbd-1.25.8, dated 2026-10-13, and it's filed under nbd_opt_set_meta_context(3). go forth and negotiate those meta contexts β periodt π
β¨
π¦ 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