Scroll to navigation

libopeniscsiusr.h(3) Library Functions Manual libopeniscsiusr.h(3)

NAME

libopeniscsiusr.h - iSCSI userspace API.

SYNOPSIS

#include <libopeniscsiusr/libopeniscsiusr.h>

DESCRIPTION

All the libopeniscsiusr public functions ship their own man pages. You may use 'man -k iscsi' to find out and use 'man 3 <function_name>' to check the detail usage.

USAGE

To use libopeniscsiusr in your project, we suggest to use the 'pkg-config' way:


* 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)

LOG HANDLING

The log handler function could be set via 'iscsi_context_log_func_set()'. The log priority could be set via 'iscsi_context_log_priority_set()'.

By default, the log priorities is 'LIBISCSI_LOG_PRIORITY_WARNING'. By default, the log handler is print 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);
}
}

SAMPLE CODE


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);

LICENSE

LGPLv3+

BUG

Please report bug to https://github.com/open-iscsi/open-iscsi/issues

November 2017 iSCSI userspace API - libopeniscsiusr Manual