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 -1 should 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 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