nbd_set_debug_callback(3)

πŸ’– nbd_set_debug_callback β€” like, the libnbd page for setting your debug callback ✨

okay bestie, so this is a page from libnbd(3) β€” the Network Block Device library β€” and it's all about one li'l function: nbd_set_debug_callback. It's giving "let me spy on my own library" energy and honestly? Iconic.


🌸 SYNOPSIS 🌸

fr fr, here's the whole shape of it β€” don't touch, just vibe:

#include <libnbd.h>

typedef struct {
  int (*callback) (void *user_data, const char *context,
                   const char *msg);
  void *user_data;
  void (*free) (void *user_data);
} nbd_debug_callback;

int nbd_set_debug_callback (
      struct nbd_handle *h,
      nbd_debug_callback debug_callback
    );

Like, you pass in a handle h and a whole nbd_debug_callback struct, and it returns an int. Simple, clean, slay. πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

So what does it do? It sets the debug callback. Groundbreaking, I know. 😭

This callback gets called when the library emits debug messages β€” specifically when debugging is enabled on a handle. The callback's parameters are:

  • "user_data" β€” the thing you passed to this function, your little personal stash of whatever
  • "context" β€” the name of the libnbd function that's emitting the debug message
  • "msg" β€” the message itself, the actual tea β˜•

And listen: if no debug callback is set on a handle, then messages are just printed on "stderr". No callback, no problem β€” it still tells you stuff, just the default way.

⚠️ okay this part is IMPORTANT bestie, do not skip: the callback should not call nbd_* APIs on the same handle. Why? Because it can be called while holding the handle lock, and that will cause a deadlock. πŸ’€ Like, you'll just sit there forever waiting on yourself. Not the main character energy we want. Do not do it.

πŸŽ€ RETURN VALUE πŸŽ€

If the call is successful, the function returns 0. That's it. Zero. The good zero. 🫢


πŸ”₯ ERRORS πŸ”₯

On error, -1 is returned. 😭 The bad one.

Refer to "ERROR HANDLING" in libnbd(3) for how to get further details of the error β€” that's where the actual explanation lives, iykyk.

Also, heads up: the following parameters must not be NULL: "h". For more info, see "Non-NULL parameters" in libnbd(3). Don't be passing NULL handles around like it's cute, because it is not.


⭐ VERSION ⭐

This function first appeared in libnbd 1.0. OG behavior, honestly. πŸ‘‘

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

#define LIBNBD_HAVE_NBD_SET_DEBUG_CALLBACK 1

🌈 SEE ALSO 🌈

  • nbd_create(3)
  • libnbd(3)

Go read those too, bestie, they're part of the lore. πŸ“š


πŸ‘‘ AUTHORS πŸ‘‘

  • Eric Blake
  • Richard W.M. Jones

Legends. Respect. πŸ’œ


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


aaand that's the whole page!! πŸŽ‰ this was libnbd-1.25.8, dated 2026-10-13, and the manual page is nbd_set_debug_callback(3) β€” go forth and debug, bestie, you've got this πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from