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

# [NAME](#NAME)

libopeniscsiusr.h - iSCSI userspace API.

# [SYNOPSIS](#SYNOPSIS)

#include &lt;libopeniscsiusr/libopeniscsiusr.h&gt;

# [DESCRIPTION](#DESCRIPTION)

All the libopeniscsiusr public functions ship their own man pages. You may use 'man -k iscsi' to find out and use 'man 3 &lt;function\_name&gt;' to check the detail usage.

# [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](#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 &lt; \_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](#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 &lt; 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](#LICENSE)

LGPLv3+

# [BUG](#BUG)

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

November 2017 iSCSI userspace API - libopeniscsiusr Manual

---

Document: libopeniscsiusr.h(3) from open-iscsi 2.1.13-r3 (Chainguard OS)
Source: https://github.com/open-iscsi/open-iscsi
