1libopeniscsiusr.h(3) Library Functions Manual libopeniscsiusr.h(3)
2
3
4
6 libopeniscsiusr.h - iSCSI userspace API.
7
8
10 #include <libopeniscsiusr/libopeniscsiusr.h>
11
12
14 All the libopeniscsiusr public functions ship their own man pages. You
15 may use 'man -k iscsi' to find out and use 'man 3 <function_name>' to
16 check the detail usage.
17
18
20 To use libopeniscsiusr in your project, we suggest to use the 'pkg-con‐
21 fig' way:
22
23 * Add this line into your configure.ac:
24
25 PKG_CHECK_MODULES([LIBISCSIUSR], [libopeniscsiusr])
26
27 * Add these lines into your Makefile.am:
28
29 foo_LDFLAGS += $(LIBISCSIUSR_LIBS)
30 foo_CFLAGS += $(LIBISCSIUSR_CFLAGS)
31
32
34 The log handler function could be set via 'iscsi_con‐
35 text_log_func_set()'. The log priority could be set via 'iscsi_con‐
36 text_log_priority_set()'.
37
38 By default, the log priorities is 'LIBISCSI_LOG_PRIORITY_WARNING'. By
39 default, the log handler is print log to STDERR, and its code is listed
40 below in case you want to take it as an example to create your own log
41 handler.
42
43 #define _ISCSI_LOG_STRERR_ALIGN_WIDTH 80
44
45 void _iscsi_log_stderr(struct iscsi_context *ctx, int priority,
46 const char *file, int line,
47 const char *func_name,
48 const char *format, va_list args)
49 {
50 int printed_bytes = 0;
51
52 printed_bytes += fprintf(stderr, "iSCSI %s: ",
53 iscsi_log_priority_str(prior‐
54 ity));
55 printed_bytes += vfprintf(stderr, format, args);
56
57 if (printed_bytes < _ISCSI_LOG_STRERR_ALIGN_WIDTH) {
58 fprintf(stderr, "%*s # %s:%s():%d0,
59 _ISCSI_LOG_STRERR_ALIGN_WIDTH -
60 printed_bytes,
61 "", file, func_name, line);
62 } else {
63 fprintf(stderr, " # %s:%s():%d0, file,
64 func_name,
65 line);
66 }
67 }
68
69
70
72 struct iscsi_context *ctx = NULL;
73 struct iscsi_session **ses = NULL;
74 uint32_t se_count = 0;
75 uint32_t i = 0;
76 int rc = EXIT_SUCCESS;
77
78 ctx = iscsi_context_new();
79 iscsi_context_log_priority_set(ctx, LIBISCSI_LOG_PRIORITY_DE‐
80 BUG);
81
82 if (iscsi_sessions_get(ctx, &ses, &se_count) != LIBISCSI_OK) {
83 printf("FAILED0);
84 rc = EXIT_FAILURE;
85 } else {
86 printf("0ot %" PRIu32 " iSCSI sessions0, se_count);
87 for (i = 0; i < se_count; ++i)
88 printf("SID is %" PRIu32 "0,
89 iscsi_session_sid_get(ses[i]));
90 iscsi_sessions_free(ses, se_count);
91 }
92 iscsi_context_free(ctx);
93 exit(rc);
94
95
97 LGPLv3+
98
99
101 Please report bug to https://github.com/open-iscsi/open-iscsi/issues
102
103
104
105iSCSI userspace API - libopeniscsiNuosvremMbaenrua2l017 libopeniscsiusr.h(3)