nbd_get_uri(3)

πŸ’… nbd_get_uri β€” construct an NBD URI for a connection

okay so this is a page from the LIBNBD manual, and honestly? it's a little baddie. it's nbd_get_uri(3) and it's about building you a URI so you can slide back into the same server. let's get into it πŸŽ€


✨ SYNOPSIS ✨

#include <libnbd.h>

char * nbd_get_uri (
         struct nbd_handle *h
       );

that's it. one handle in, one string out. she's simple, she's elegant, she's iconic πŸ’…


🌸 DESCRIPTION 🌸

okay bestie, so what this does is it makes a best effort attempt to construct an NBD URI that you could use to connect back to the same server β€” and you'd do that with nbd_connect_uri(3). cute, right? πŸ¦‹

but here's the tea: sometimes there's just not enough info sitting in the handle to actually pull a URI out of thin air. like, example: if you connected using nbd_connect_socket(3), there's lowkey nothing to work with. in cases like that the call returns NULL β€” and no cap, you're not left hanging, because the further diagnostic info is available via nbd_get_errno(3) and nbd_get_error(3), as usual. 🫢

also, even if a URI does come back? it's not guaranteed to work, and it may not be optimal. so like... don't @ her if it's mid. 😭

oh and if you're a shell-script girlie, the nbdinfo(1) --uri option is a whole way to access this API from your shell scripts. slay for automation ✨


πŸ‘‘ RETURN VALUE πŸ‘‘

this call returns a string. but listen β€” the caller must free the returned string to avoid a memory leak. i'm so serious. free your girl. 🧚


πŸ’€ ERRORS πŸ’€

on error, NULL is returned. that's the whole vibe.

refer to "ERROR HANDLING" in libnbd(3) for how to get further details of the error. iykyk.

also: the following parameters must not be NULL: h. for more info, check "Non-NULL parameters" in libnbd(3). don't pass her a NULL handle, it's giving chaos πŸ™ˆ


πŸ¦‹ HANDLE STATE πŸ¦‹

so there's a whole vibe check on which states you can call nbd_get_uri from. here's the rundown:

  • Handle created, before connecting β€” ❌ error (sorry babe, too early)
  • Connecting β€” βœ… allowed
  • Connecting & handshaking (opt_mode) β€” βœ… allowed
  • Connected to the server β€” βœ… allowed
  • Connection shut down β€” βœ… allowed
  • Handle dead β€” βœ… allowed (yes even then, she's unbothered πŸ’…)

⭐ VERSION ⭐

this function first appeared in libnbd 1.8. periodt.

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

#define LIBNBD_HAVE_NBD_GET_URI 1

🌈 SEE ALSO 🌈

your reading list, bestie, go off:


πŸ’– AUTHORS πŸ’–

  • Eric Blake
  • Richard W.M. Jones

absolute 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


okay that's the whole page, mwah πŸ’‹ this was libnbd-1.25.8, dated 2026-10-13, nbd_get_uri(3) β€” go build your URIs responsibly, bestie, and remember to free your strings πŸ”₯🌸

πŸ“¦ where this page comes from