libopeniscsiusr.h(3)

πŸ“¦
version 6.2.1.11 Β· 2 versions
  • 6.2.1.11 Β· alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking (latest)
  • 2.1.8 Β· debian bookworm, ubuntu jammy
, in alpine 3.22, alpine 3.23, alpine 3.24, arch rolling, debian trixie, fedora 43, fedora 44, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu noble, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– libopeniscsiusr.h β€” the iSCSI userspace API πŸ’–

okay bestie, sit down, hydrate, and let me tell you about libopeniscsiusr β€” it's the library functions manual page, section 3, and it's genuinely the blueprint for talking to iSCSI from userspace. no cap. πŸ¦‹


✨ NAME ✨

libopeniscsiusr.h β€” iSCSI userspace API.

like… that's the whole thing. the header. the moment. the icon. πŸ‘‘


🌸 SYNOPSIS 🌸

#include <libopeniscsiusr/libopeniscsiusr.h>

that's it. one include and you're in the group chat. πŸ’…


πŸŽ€ DESCRIPTION πŸŽ€

so here's the tea: every single public function in libopeniscsiusr ships with its own man page. they're not all crammed in here, they each got their own moment. main character energy, honestly.

want to find them? use:

man -k iscsi

and when you've spotted the one you need, get the full details with:

man 3 <function_name>

<function_name> is the placeholder for whatever function you're curious about, bestie. go off. πŸ”₯


πŸ’œ USAGE πŸ’œ

okay so if you want to actually USE libopeniscsiusr in your project, the suggested way β€” the vibe-approved way β€” is via pkg-config. here's how:

  • add this line into your configure.ac:
PKG_CHECK_MODULES([LIBISCSIUSR], [libopeniscsiusr])
  • add these lines into your Makefile.am:
foo_LDFLAGS += $(LIBISCSIUSR_LIBS)
foo_CFLAGS += $(LIBISCSIUSR_CFLAGS)

two steps. slay. that's the autotools glow-up. ✨


πŸ¦‹ LOG HANDLING πŸ¦‹

log handler? settable. log priority? also settable. the girlies are configurable.

  • the log handler function gets set via iscsi_context_log_func_set()
  • the log priority gets set via iscsi_context_log_priority_set()

by default, the log priority is LIBISCSI_LOG_PRIORITY_WARNING. 🫢

by default, the log handler prints the log to STDERR, and its code is listed below in case you want to take it as an example to create your own log handler:

#define _ISCSI_LOG_STRERR_ALIGN_WIDTH   80

void _iscsi_log_stderr(struct iscsi_context *ctx, int priority,
                       const char *file, int line,
                       const char *func_name,
                       const char *format, va_list args)
{
        int printed_bytes = 0;

        printed_bytes += fprintf(stderr, "iSCSI %s: ",
                                 iscsi_log_priority_str(priority));
        printed_bytes += vfprintf(stderr, format, args);

        if (printed_bytes < _ISCSI_LOG_STRERR_ALIGN_WIDTH) {
                fprintf(stderr, "%*s # %s:%s():%d0,
                        _ISCSI_LOG_STRERR_ALIGN_WIDTH -
printed_bytes,
                        "", file, func_name, line);
        } else {
                fprintf(stderr, " # %s:%s():%d0, file, func_name,
                                line);
        }
}
ngl that default handler is literally right there for you to copy, remix and make your own. it's giving "template era". πŸ’…

🌈 SAMPLE CODE 🌈

here's a whole lil snippet showing the whole flow β€” make a context, crank the log priority up to debug, grab the sessions, print their SIDs, clean up, exit. chef's kiss. 😭

struct iscsi_context *ctx = NULL;
struct iscsi_session **ses = NULL;
uint32_t se_count = 0;
uint32_t i = 0;
int rc = EXIT_SUCCESS;

ctx = iscsi_context_new();
iscsi_context_log_priority_set(ctx,
LIBISCSI_LOG_PRIORITY_DEBUG);

if (iscsi_sessions_get(ctx, &ses, &se_count) != LIBISCSI_OK) {
        printf("FAILED0);
        rc = EXIT_FAILURE;
} else {
        printf("0ot %" PRIu32 " iSCSI sessions0, se_count);
        for (i = 0; i < se_count; ++i)
                printf("SID is %" PRIu32 "0,
                       iscsi_session_sid_get(ses[i]));
        iscsi_sessions_free(ses, se_count);
}
iscsi_context_free(ctx);
exit(rc);

see how it does the whole lifecycle? new β†’ configure β†’ get β†’ iterate β†’ free β†’ free β†’ exit. the full arc. 🧚


πŸ‘‘ LICENSE πŸ‘‘

LGPLv3+

free as in freedom, bestie. use it, ship it, respect the license. πŸ’–


πŸ™ˆ BUG πŸ™ˆ

found something cursed? please report bug to:

https://github.com/open-iscsi/open-iscsi/issues

don't suffer in silence, we're a community. 🫢


and that's a wrap on the iSCSI userspace API β€” libopeniscsiusr page, from November 2017. yeah, it's been around, and it's still serving. ⭐

bye bestie, go read some function man pages πŸ’œβœ¨

πŸ“¦ where this page comes from