summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGris Ge <fge@redhat.com>2018-01-18 21:55:39 +0800
committerGris Ge <fge@redhat.com>2018-01-22 18:26:06 +0800
commit36204c711526162b68fc9c0228bfb48ad8b1d5c0 (patch)
treeb5300f8bdb41200e29b5a1af7c3a4fd24111135e
parentf86c167662e7bf7b950b11b6a2f2939f3a38881c (diff)
downloadopen-iscsi-36204c711526162b68fc9c0228bfb48ad8b1d5c0.tar.gz
libopeniscsiusr: Use libopeniscsiusr in iscsiadm
* Use libopeniscsiusr for `iscsiadm -m session -P <0-3>` command. * Use libopeniscsiusr for iSCSI session information used by `iscsiadm -m node -H <host_no> -P <2 - 4>`command. * Since `/sys/class/iscsi_session/session1/username` require root permission, this patch require `iscsiadm` been ran with root privilege. Signed-off-by: Gris Ge <fge@redhat.com>
-rw-r--r--usr/Makefile36
-rw-r--r--usr/host.c66
-rw-r--r--usr/host.h5
-rw-r--r--usr/iface.c49
-rw-r--r--usr/iface.h4
-rw-r--r--usr/iscsiadm.c86
-rw-r--r--usr/session_info.c279
-rw-r--r--usr/session_info.h12
-rw-r--r--utils/fwparam_ibft/Makefile12
9 files changed, 368 insertions, 181 deletions
diff --git a/usr/Makefile b/usr/Makefile
index df67d47..8fbac4a 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -1,8 +1,42 @@
# This Makefile will work only with GNU make.
+ifeq ($(TOPDIR),)
+ TOPDIR = ..
+endif
+
+OSNAME=$(shell uname -s)
+
+# allow users to override these
+# eg to compile for a kernel that you aren't currently running
+KERNELRELEASE ?= $(shell uname -r)
+KSRC ?= /lib/modules/$(KERNELRELEASE)/build
+
+KSUBLEVEL=$(shell cat $(KSRC)/Makefile | awk -F= '/^SUBLEVEL =/ {print $$2}' | \
+ sed 's/^[ \t]*//;s/[ \t]*$$//')
+
+ifeq ($(OSNAME),Linux)
+ ifeq ($(KSUBLEVEL),11)
+ IPC_CFLAGS=-DNETLINK_ISCSI=12 -D_GNU_SOURCE
+ else
+ ifeq ($(KSUBLEVEL),12)
+ IPC_CFLAGS=-DNETLINK_ISCSI=12 -D_GNU_SOURCE
+ else
+ IPC_CFLAGS=-DNETLINK_ISCSI=8 -D_GNU_SOURCE
+ endif
+ endif
+IPC_OBJ=netlink.o
+else
+ifeq ($(OSNAME),FreeBSD)
+IPC_CFLAGS=
+IPC_OBJ=ioctl.o
+endif
+endif
+
CFLAGS ?= -O2 -g
WARNFLAGS ?= -Wall -Wstrict-prototypes
-CFLAGS += $(WARNFLAGS) -I../include -I. -D_GNU_SOURCE
+CFLAGS += $(WARNFLAGS) -I../include -I. -D_GNU_SOURCE \
+ -I$(TOPDIR)/libopeniscsiusr
+LDFLAGS += -L$(TOPDIR)/libopeniscsiusr -lopeniscsiusr
PROGRAMS = iscsid iscsiadm iscsistart
# libc compat files
diff --git a/usr/host.c b/usr/host.c
index 7e88e57..62bf111 100644
--- a/usr/host.c
+++ b/usr/host.c
@@ -36,16 +36,24 @@
#include "iscsi_err.h"
#include "iscsi_netlink.h"
-static int match_host_to_session(void *data, struct session_info *info)
+struct _host_info_print_tree_arg {
+ unsigned int flags;
+ struct iscsi_session **ses;
+ uint32_t se_count;
+};
+
+static int match_host_to_session(uint32_t host_no, struct iscsi_session *se)
{
- uint32_t host_no = *(uint32_t *) data;
+ uint32_t sid = 0;
uint32_t info_host_no;
int rc;
- info_host_no = iscsi_sysfs_get_host_no_from_sid(info->sid, &rc);
+ sid = iscsi_session_sid_get(se);
+
+ info_host_no = iscsi_sysfs_get_host_no_from_sid(sid, &rc);
if (rc) {
log_error("could not get host_no for session%d err %d.",
- info->sid, rc);
+ sid, rc);
return 0;
}
@@ -217,14 +225,21 @@ static void print_host_ifaces(struct host_info *hinfo, char *prefix)
static int host_info_print_tree(void *data, struct host_info *hinfo)
{
- struct list_head sessions;
- struct session_link_info link_info;
- int err, num_found = 0;
- unsigned int session_info_flags = *(unsigned int *)data;
+ unsigned int session_info_flags = 0;
+ struct _host_info_print_tree_arg *arg = data;
+ struct iscsi_session **ses = NULL;
+ struct iscsi_session **matched_ses = NULL;
+ uint32_t se_count = 0;
+ uint32_t matched_se_count = 0;
+ uint32_t i = 0;
char state[SCSI_MAX_STATE_VALUE];
- INIT_LIST_HEAD(&sessions);
+ if (arg == NULL)
+ return -EINVAL;
+ session_info_flags = arg->flags;
+ ses = arg->ses;
+ se_count = arg->se_count;
printf("Host Number: %u\n", hinfo->host_no);
if (!iscsi_sysfs_get_host_state(state, hinfo->host_no))
@@ -235,32 +250,38 @@ static int host_info_print_tree(void *data, struct host_info *hinfo)
print_host_ifaces(hinfo, "\t");
- if (!session_info_flags)
+ if ((!session_info_flags) || (!se_count))
return 0;
- link_info.list = &sessions;
- link_info.match_fn = match_host_to_session;
- link_info.data = &hinfo->host_no;
+ matched_ses = calloc(se_count, sizeof(struct iscsi_session *));
+ if (matched_ses == NULL)
+ return -ENOMEM;
- err = iscsi_sysfs_for_each_session(&link_info, &num_found,
- session_info_create_list, 0);
- if (err || !num_found)
+ for (i = 0; i < se_count; ++i)
+ if (match_host_to_session(hinfo->host_no, ses[i]))
+ matched_ses[matched_se_count++] = ses[i];
+
+ if (!matched_se_count)
return 0;
printf("\t*********\n");
printf("\tSessions:\n");
printf("\t*********\n");
+ session_info_print_tree(matched_ses, matched_se_count, "\t",
+ session_info_flags, 0/* don't show password */);
- session_info_print_tree(&sessions, "\t", session_info_flags, 0, -1);
- session_info_free_list(&sessions);
+ free(matched_ses);
return 0;
}
-int host_info_print(int info_level, uint32_t host_no)
+int host_info_print(int info_level, uint32_t host_no,
+ struct iscsi_session **ses, uint32_t se_count)
+
{
int num_found = 0, err = 0;
char *version;
unsigned int flags = 0;
+ struct _host_info_print_tree_arg arg;
switch (info_level) {
case 0:
@@ -286,19 +307,22 @@ int host_info_print(int info_level, uint32_t host_no)
flags |= SESSION_INFO_ISCSI_STATE | SESSION_INFO_IFACE;
/* fall through */
case 1:
+ arg.flags = flags;
+ arg.ses = ses;
+ arg.se_count = se_count;
if (host_no != -1) {
struct host_info hinfo;
memset(&hinfo, 0, sizeof(struct host_info));
hinfo.host_no = host_no;
iscsi_sysfs_get_hostinfo_by_host_no(&hinfo);
- host_info_print_tree(&flags, &hinfo);
+ host_info_print_tree(&arg, &hinfo);
num_found = 1;
break;
}
transport_probe_for_offload();
- err = iscsi_sysfs_for_each_host(&flags, &num_found,
+ err = iscsi_sysfs_for_each_host(&arg, &num_found,
host_info_print_tree);
break;
default:
diff --git a/usr/host.h b/usr/host.h
index 149aa0d..f521fd2 100644
--- a/usr/host.h
+++ b/usr/host.h
@@ -2,6 +2,8 @@
#define ISCSI_HOST_H
#include <sys/types.h>
+#include <libopeniscsiusr/libopeniscsiusr.h>
+
#include "types.h"
#include "config.h"
@@ -16,7 +18,8 @@ struct host_info {
uint32_t host_no;
};
-extern int host_info_print(int info_level, uint32_t host_no);
+extern int host_info_print(int info_level, uint32_t host_no,
+ struct iscsi_session **ses, uint32_t se_count);
extern int chap_build_config(struct iscsi_chap_rec *crec, struct iovec *iovs);
#endif
diff --git a/usr/iface.c b/usr/iface.c
index af0708a..44c0986 100644
--- a/usr/iface.c
+++ b/usr/iface.c
@@ -27,6 +27,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <arpa/inet.h>
+#include <libopeniscsiusr/libopeniscsiusr.h>
#include "log.h"
#include "list.h"
@@ -782,40 +783,36 @@ int iface_is_bound_by_ipaddr(struct iface_rec *iface)
return 0;
}
-void iface_print(struct iface_rec *iface, char *prefix)
+void iface_print(struct iscsi_iface *iface, char *prefix)
{
- if (strlen(iface->name))
- printf("%sIface Name: %s\n", prefix, iface->name);
- else
- printf("%sIface Name: %s\n", prefix, UNKNOWN_VALUE);
+ const char *ipaddress = iscsi_iface_ipaddress_get(iface);
- if (strlen(iface->transport_name))
- printf("%sIface Transport: %s\n", prefix,
- iface->transport_name);
- else
- printf("%sIface Transport: %s\n", prefix, UNKNOWN_VALUE);
+ printf("%sIface Name: %s\n", prefix,
+ (strlen(iscsi_iface_name_get(iface)) > 0) ?
+ iscsi_iface_name_get(iface) : UNKNOWN_VALUE);
- if (strlen(iface->iname))
- printf("%sIface Initiatorname: %s\n", prefix, iface->iname);
- else
- printf("%sIface Initiatorname: %s\n", prefix, UNKNOWN_VALUE);
+ printf("%sIface Transport: %s\n", prefix,
+ (strlen(iscsi_iface_transport_name_get(iface)) > 0) ?
+ iscsi_iface_transport_name_get(iface) : UNKNOWN_VALUE);
- if (!strlen(iface->ipaddress))
+ printf("%sIface Initiatorname: %s\n", prefix,
+ (strlen(iscsi_iface_iname_get(iface)) > 0) ?
+ iscsi_iface_iname_get(iface) : UNKNOWN_VALUE);
+
+ if (!strlen(ipaddress))
printf("%sIface IPaddress: %s\n", prefix, UNKNOWN_VALUE);
- else if (strchr(iface->ipaddress, '.'))
- printf("%sIface IPaddress: %s\n", prefix, iface->ipaddress);
+ else if (strchr(ipaddress, '.'))
+ printf("%sIface IPaddress: %s\n", prefix, ipaddress);
else
- printf("%sIface IPaddress: [%s]\n", prefix, iface->ipaddress);
+ printf("%sIface IPaddress: [%s]\n", prefix, ipaddress);
- if (strlen(iface->hwaddress))
- printf("%sIface HWaddress: %s\n", prefix, iface->hwaddress);
- else
- printf("%sIface HWaddress: %s\n", prefix, UNKNOWN_VALUE);
+ printf("%sIface HWaddress: %s\n", prefix,
+ (strlen(iscsi_iface_hwaddress_get(iface)) > 0) ?
+ iscsi_iface_hwaddress_get(iface) : UNKNOWN_VALUE);
- if (strlen(iface->netdev))
- printf("%sIface Netdev: %s\n", prefix, iface->netdev);
- else
- printf("%sIface Netdev: %s\n", prefix, UNKNOWN_VALUE);
+ printf("%sIface Netdev: %s\n", prefix,
+ (strlen(iscsi_iface_netdev_get(iface)) > 0) ?
+ iscsi_iface_netdev_get(iface) : UNKNOWN_VALUE);
}
struct iface_print_node_data {
diff --git a/usr/iface.h b/usr/iface.h
index 01f7074..e3c1b68 100644
--- a/usr/iface.h
+++ b/usr/iface.h
@@ -20,6 +20,8 @@
#ifndef ISCSI_IFACE_H
#define ISCSI_IFACE_H
+#include <libopeniscsiusr/libopeniscsiusr.h>
+
#define IFACE_CONFIG_DIR ISCSI_CONFIG_ROOT"ifaces"
struct iface_rec;
@@ -37,7 +39,7 @@ extern int iface_is_bound_by_ipaddr(struct iface_rec *iface);
typedef int (iface_op_fn)(void *data, struct iface_rec *iface);
extern int iface_for_each_iface(void *data, int skip_def, int *nr_found,
iface_op_fn *fn);
-extern void iface_print(struct iface_rec *iface, char *prefix);
+extern void iface_print(struct iscsi_iface *iface, char *prefix);
extern int iface_print_flat(void *data, struct iface_rec *iface);
extern int iface_print_tree(void *data, struct iface_rec *iface);
extern void iface_setup_host_bindings(void);
diff --git a/usr/iscsiadm.c b/usr/iscsiadm.c
index b30518a..c5652da 100644
--- a/usr/iscsiadm.c
+++ b/usr/iscsiadm.c
@@ -30,6 +30,8 @@
#include <time.h>
#include <sys/stat.h>
+#include <libopeniscsiusr/libopeniscsiusr.h>
+
#include "initiator.h"
#include "discovery.h"
#include "log.h"
@@ -3276,6 +3278,17 @@ main(int argc, char **argv)
uint64_t index = ULLONG_MAX;
struct user_param *param;
struct list_head params;
+ struct iscsi_context *ctx = NULL;
+ int librc = LIBISCSI_OK;
+ struct iscsi_session **ses = NULL;
+ uint32_t se_count = 0;
+ struct iscsi_session *se = NULL;
+
+ ctx = iscsi_context_new();
+ if (ctx == NULL) {
+ log_error("No memory");
+ goto out;
+ }
INIT_LIST_HEAD(&params);
INIT_LIST_HEAD(&ifaces);
@@ -3371,6 +3384,18 @@ main(int argc, char **argv)
break;
case 'd':
log_level = atoi(optarg);
+ if (log_level >= 8)
+ iscsi_context_log_priority_set
+ (ctx, LIBISCSI_LOG_PRIORITY_DEBUG);
+ else if (log_level >= 4)
+ iscsi_context_log_priority_set
+ (ctx, LIBISCSI_LOG_PRIORITY_INFO);
+ else if (log_level >= 2)
+ iscsi_context_log_priority_set
+ (ctx, LIBISCSI_LOG_PRIORITY_WARNING);
+ else
+ iscsi_context_log_priority_set
+ (ctx, LIBISCSI_LOG_PRIORITY_ERROR);
break;
case 'm':
mode = str_to_mode(optarg);
@@ -3532,8 +3557,22 @@ main(int argc, char **argv)
log_error("Invalid Sub Mode");
break;
}
- } else
- rc = host_info_print(info_level, host_no);
+ } else {
+ librc = iscsi_sessions_get(ctx, &ses, &se_count);
+
+ if (librc != LIBISCSI_OK) {
+ log_error("Failed to query iSCSI sessions, "
+ "error %d: %s", librc,
+ iscsi_strerror(librc));
+ /* libopeniscsiusr rc is one-to-one map to iscsiadm
+ * rc
+ */
+ rc = librc;
+ goto out;
+ }
+ rc = host_info_print(info_level, host_no, ses,
+ se_count);
+ }
break;
case MODE_IFACE:
iface_setup_host_bindings();
@@ -3667,8 +3706,23 @@ main(int argc, char **argv)
if (!do_logout && !do_rescan && !do_stats &&
op == OP_NOOP && info_level > 0) {
- rc = session_info_print(info_level, info,
- do_show);
+ librc = iscsi_session_get
+ (ctx, sid & UINT32_MAX, &se);
+ if (librc != LIBISCSI_OK) {
+ log_error("Failed to query iSCSI "
+ "session %d, error %d: %s",
+ sid, librc,
+ iscsi_strerror(librc));
+ rc = ISCSI_ERR_INVAL;
+ goto out;
+ }
+ ses = (struct iscsi_session **)
+ calloc(1,
+ sizeof(struct iscsi_session *));
+ ses[0] = se;
+ se_count = 1;
+ rc = session_info_print(info_level, ses,
+ se_count, do_show);
goto free_info;
}
@@ -3715,7 +3769,27 @@ free_info:
goto out;
}
- rc = session_info_print(info_level, NULL, do_show);
+ librc = iscsi_sessions_get(ctx, &ses, &se_count);
+
+ if (librc != LIBISCSI_OK) {
+ log_error("Failed to query iSCSI sessions, "
+ "error %d: %s", librc,
+ iscsi_strerror(librc));
+ /* libopeniscsiusr rc is one-to-one map to iscsiadm
+ * rc
+ */
+ rc = librc;
+ goto out;
+ }
+ if (se_count == 0) {
+ log_error("No active sessions.");
+ rc =ISCSI_ERR_NO_OBJS_FOUND;
+ goto out;
+ }
+
+ rc = session_info_print(info_level, ses, se_count,
+ do_show);
+
}
break;
default:
@@ -3724,8 +3798,10 @@ free_info:
}
out:
+ iscsi_context_free(ctx);
if (rec)
free(rec);
+ iscsi_sessions_free(ses, se_count);
idbm_terminate();
free_ifaces:
list_for_each_entry_safe(iface, tmp, &ifaces, list) {
diff --git a/usr/session_info.c b/usr/session_info.c
index c1b98ef..0dae82f 100644
--- a/usr/session_info.c
+++ b/usr/session_info.c
@@ -1,6 +1,10 @@
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
+#include <stdint.h>
+#include <inttypes.h>
+
+#include <libopeniscsiusr/libopeniscsiusr.h>
#include "list.h"
#include "log.h"
@@ -15,6 +19,8 @@
#include "iscsid_req.h"
#include "iscsi_err.h"
+static int session_info_print_flat(struct iscsi_session *se);
+
int session_info_create_list(void *data, struct session_info *info)
{
struct session_link_info *link_info = data;
@@ -64,9 +70,9 @@ void session_info_free_list(struct list_head *list)
}
}
-static char *get_iscsi_node_type(struct session_info *info)
+static char *get_iscsi_node_type(uint32_t sid)
{
- int pid = iscsi_sysfs_session_user_created(info->sid);
+ int pid = iscsi_sysfs_session_user_created((int) sid);
if (!pid)
return "flash";
@@ -74,22 +80,31 @@ static char *get_iscsi_node_type(struct session_info *info)
return "non-flash";
}
-static int session_info_print_flat(void *data, struct session_info *info)
+static int session_info_print_flat(struct iscsi_session *se)
{
- struct iscsi_transport *t = iscsi_sysfs_get_transport_by_sid(info->sid);
+ uint32_t sid = 0;
+ struct iscsi_transport *t = NULL;
+
+ sid = iscsi_session_sid_get(se);
+ t = iscsi_sysfs_get_transport_by_sid((int) sid);
- if (strchr(info->persistent_address, '.'))
- printf("%s: [%d] %s:%d,%d %s (%s)\n",
+ if (strchr(iscsi_session_persistent_address_get(se), '.'))
+ printf("%s: [%" PRIu32 "] %s:%" PRIi32 ",%"PRIi32 " %s (%s)\n",
t ? t->name : UNKNOWN_VALUE,
- info->sid, info->persistent_address,
- info->persistent_port, info->tpgt, info->targetname,
- get_iscsi_node_type(info));
+ sid, iscsi_session_persistent_address_get(se),
+ iscsi_session_persistent_port_get(se),
+ iscsi_session_tpgt_get(se),
+ iscsi_session_target_name_get(se),
+ get_iscsi_node_type(sid));
else
- printf("%s: [%d] [%s]:%d,%d %s (%s)\n",
+ printf("%s: [%" PRIu32 "] [%s]:%" PRIi32 ",%" PRIi32
+ " %s (%s)\n",
t ? t->name : UNKNOWN_VALUE,
- info->sid, info->persistent_address,
- info->persistent_port, info->tpgt, info->targetname,
- get_iscsi_node_type(info));
+ sid, iscsi_session_persistent_address_get(se),
+ iscsi_session_persistent_port_get(se),
+ iscsi_session_tpgt_get(se),
+ iscsi_session_target_name_get(se),
+ get_iscsi_node_type(sid));
return 0;
}
@@ -235,62 +250,111 @@ static int print_scsi_state(int sid, char *prefix, unsigned int flags)
return 0;
}
-void session_info_print_tree(struct list_head *list, char *prefix,
- unsigned int flags, int do_show, int tmo)
+void session_info_print_tree(struct iscsi_session **ses, uint32_t se_count,
+ char *prefix, unsigned int flags, int do_show)
{
- struct session_info *curr, *prev = NULL;
+ struct iscsi_session *curr = NULL;
+ struct iscsi_session *prev = NULL;
+ const char *curr_targetname = NULL;
+ const char *curr_address = NULL;
+ const char *persistent_address = NULL;
+ const char *prev_targetname = NULL;
+ const char *prev_address = NULL;
+ int32_t curr_port = 0;
+ int32_t prev_port = 0;
+ uint32_t i = 0;
+ uint32_t sid = 0;
+ char *new_prefix = NULL;
+ int32_t tgt_reset_tmo = -1;
+ int32_t lu_reset_tmo = -1;
+ int32_t abort_tmo = -1;
+ const char *pass = NULL;
+
+ for (i = 0; i < se_count; ++i) {
+ curr = ses[i];
+ curr_targetname = iscsi_session_target_name_get(curr);
+ sid = iscsi_session_sid_get(curr);
+ if (prev != NULL)
+ prev_targetname = iscsi_session_target_name_get(prev);
+ else
+ prev_targetname = NULL;
- list_for_each_entry(curr, list, list) {
- if (!prev || strcmp(prev->targetname, curr->targetname)) {
- printf("%sTarget: %s (%s)\n", prefix, curr->targetname,
- get_iscsi_node_type(curr));
+ if (! ((prev_targetname != NULL) &&
+ (curr_targetname != NULL) &&
+ (strcmp(prev_targetname, curr_targetname) == 0))) {
+ printf("%sTarget: %s (%s)\n", prefix, curr_targetname,
+ get_iscsi_node_type(sid));
prev = NULL;
}
-
- if (!prev || (strcmp(prev->address, curr->address) ||
- prev->port != curr->port)) {
- if (strchr(curr->address, '.'))
- printf("%s\tCurrent Portal: %s:%d,%d\n",
- prefix, curr->address, curr->port,
- curr->tpgt);
+ curr_address = iscsi_session_address_get(curr);
+ curr_port = iscsi_session_port_get(curr);
+
+ if (prev != NULL) {
+ prev_address = iscsi_session_address_get(prev);
+ prev_port = iscsi_session_port_get(prev);
+ } else {
+ prev_address = NULL;
+ prev_port = 0;
+ }
+ if (! ((prev_address != NULL) &&
+ (curr_address != NULL) &&
+ (prev_port != 0) &&
+ (curr_port != 0) &&
+ (strcmp(prev_address, curr_address) == 0) &&
+ (curr_port == prev_port))) {
+ if (strchr(curr_address, '.'))
+ printf("%s\tCurrent Portal: %s:%" PRIi32
+ ",%" PRIi32 "\n",
+ prefix, curr_address, curr_port,
+ iscsi_session_tpgt_get(curr));
else
- printf("%s\tCurrent Portal: [%s]:%d,%d\n",
- prefix, curr->address, curr->port,
- curr->tpgt);
-
- if (strchr(curr->persistent_address, '.'))
- printf("%s\tPersistent Portal: %s:%d,%d\n",
- prefix, curr->persistent_address,
- curr->persistent_port, curr->tpgt);
+ printf("%s\tCurrent Portal: [%s]:%" PRIi32
+ ",%" PRIi32 "\n",
+ prefix, curr_address, curr_port,
+ iscsi_session_tpgt_get(curr));
+ persistent_address =
+ iscsi_session_persistent_address_get(curr);
+
+ if (strchr(persistent_address, '.'))
+ printf("%s\tPersistent Portal: %s:%" PRIi32
+ ",%" PRIi32 "\n",
+ prefix, persistent_address,
+ iscsi_session_persistent_port_get(curr),
+ iscsi_session_tpgt_get(curr));
else
- printf("%s\tPersistent Portal: [%s]:%d,%d\n",
- prefix, curr->persistent_address,
- curr->persistent_port, curr->tpgt);
+ printf("%s\tPersistent Portal: [%s]:%" PRIi32
+ ",%" PRIi32 "\n",
+ prefix, persistent_address,
+ iscsi_session_persistent_port_get(curr),
+ iscsi_session_tpgt_get(curr));
} else
printf("\n");
if (flags & SESSION_INFO_IFACE) {
- char *new_prefix;
-
printf("%s\t\t**********\n", prefix);
printf("%s\t\tInterface:\n", prefix);
printf("%s\t\t**********\n", prefix);
new_prefix = calloc(1, 1 + strlen(prefix) +
strlen("\t\t"));
- if (!new_prefix)
+ if (new_prefix == NULL) {
printf("Could not print interface info. "
"Out of Memory.\n");
- else {
+ return;
+ } else {
sprintf(new_prefix, "%s%s", prefix, "\t\t");
- iface_print(&curr->iface, new_prefix);
+ iface_print(iscsi_session_iface_get(curr),
+ new_prefix);
}
free(new_prefix);
}
if (flags & SESSION_INFO_ISCSI_STATE) {
- printf("%s\t\tSID: %d\n", prefix, curr->sid);
- print_iscsi_state(curr->sid, prefix, tmo);
+ printf("%s\t\tSID: %" PRIu32 "\n", prefix, sid);
+ print_iscsi_state((int) sid, prefix, -1 /* tmo */);
+ /* TODO(Gris Ge): It seems in the whole project,
+ * tmo is always -1, correct?
+ */
}
if (flags & SESSION_INFO_ISCSI_TIM) {
@@ -298,27 +362,30 @@ void session_info_print_tree(struct list_head *list, char *prefix,
printf("%s\t\tTimeouts:\n", prefix);
printf("%s\t\t*********\n", prefix);
- printf("%s\t\tRecovery Timeout: %d\n", prefix,
- ((curr->tmo).recovery_tmo));
+ printf("%s\t\tRecovery Timeout: %" PRIi32 "\n", prefix,
+ iscsi_session_recovery_tmo_get(curr));
- if ((curr->tmo).tgt_reset_tmo >= 0)
- printf("%s\t\tTarget Reset Timeout: %d\n",
- prefix,
- ((curr->tmo).tgt_reset_tmo));
+ tgt_reset_tmo = iscsi_session_tgt_reset_tmo_get(curr);
+ lu_reset_tmo = iscsi_session_lu_reset_tmo_get(curr);
+ abort_tmo = iscsi_session_abort_tmo_get(curr);
+
+ if (tgt_reset_tmo >= 0)
+ printf("%s\t\tTarget Reset Timeout: %" PRIi32
+ "\n", prefix, tgt_reset_tmo);
else
printf("%s\t\tTarget Reset Timeout: %s\n",
prefix, UNKNOWN_VALUE);
- if ((curr->tmo).lu_reset_tmo >= 0)
- printf("%s\t\tLUN Reset Timeout: %d\n", prefix,
- ((curr->tmo).lu_reset_tmo));
+ if (lu_reset_tmo >= 0)
+ printf("%s\t\tLUN Reset Timeout: %" PRIi32 "\n",
+ prefix, lu_reset_tmo);
else
printf("%s\t\tLUN Reset Timeout: %s\n", prefix,
UNKNOWN_VALUE);
- if ((curr->tmo).lu_reset_tmo >= 0)
- printf("%s\t\tAbort Timeout: %d\n", prefix,
- ((curr->tmo).abort_tmo));
+ if (abort_tmo >= 0)
+ printf("%s\t\tAbort Timeout: %" PRIi32 "\n",
+ prefix, abort_tmo);
else
printf("%s\t\tAbort Timeout: %s\n", prefix,
UNKNOWN_VALUE);
@@ -328,62 +395,60 @@ void session_info_print_tree(struct list_head *list, char *prefix,
printf("%s\t\t*****\n", prefix);
printf("%s\t\tCHAP:\n", prefix);
printf("%s\t\t*****\n", prefix);
- if (!do_show) {
- strcpy(curr->chap.password, "********");
- strcpy(curr->chap.password_in, "********");
- }
- if (strlen((curr->chap).username))
- printf("%s\t\tusername: %s\n", prefix,
- (curr->chap).username);
- else
- printf("%s\t\tusername: %s\n", prefix,
- UNKNOWN_VALUE);
- if (strlen((curr->chap).password))
+ printf("%s\t\tusername: %s\n", prefix,
+ strlen(iscsi_session_username_get(curr)) ?
+ iscsi_session_username_get(curr) :
+ UNKNOWN_VALUE);
+
+ if (!do_show)
printf("%s\t\tpassword: %s\n", prefix,
- (curr->chap).password);
- else
+ "********");
+ else {
+ pass = iscsi_session_password_get(curr);
printf("%s\t\tpassword: %s\n", prefix,
- UNKNOWN_VALUE);
- if (strlen((curr->chap).username_in))
- printf("%s\t\tusername_in: %s\n", prefix,
- (curr->chap).username_in);
- else
- printf("%s\t\tusername_in: %s\n", prefix,
- UNKNOWN_VALUE);
- if (strlen((curr->chap).password_in))
- printf("%s\t\tpassword_in: %s\n", prefix,
- (curr->chap).password_in);
- else
+ strlen(pass) ? pass : UNKNOWN_VALUE);
+ }
+
+ printf("%s\t\tusername_in: %s\n", prefix,
+ strlen(iscsi_session_username_in_get(curr)) ?
+ iscsi_session_username_in_get(curr) :
+ UNKNOWN_VALUE);
+ if (!do_show)
printf("%s\t\tpassword_in: %s\n", prefix,
- UNKNOWN_VALUE);
+ "********");
+ else {
+ pass = iscsi_session_password_in_get(curr);
+ printf("%s\t\tpassword: %s\n", prefix,
+ strlen(pass) ? pass : UNKNOWN_VALUE);
+ }
}
if (flags & SESSION_INFO_ISCSI_PARAMS)
- print_iscsi_params(curr->sid, prefix);
+ print_iscsi_params((int) sid, prefix);
if (flags & (SESSION_INFO_SCSI_DEVS | SESSION_INFO_HOST_DEVS))
- print_scsi_state(curr->sid, prefix, flags);
+ print_scsi_state((int) sid, prefix, flags);
prev = curr;
}
}
-int session_info_print(int info_level, struct session_info *info, int do_show)
+int session_info_print(int info_level, struct iscsi_session **ses,
+ uint32_t se_count, int do_show)
{
- struct list_head list;
- int num_found = 0, err = 0;
+ int err = 0;
char *version;
unsigned int flags = 0;
+ uint32_t i = 0;
switch (info_level) {
case 0:
case -1:
- if (info) {
- session_info_print_flat(NULL, info);
- num_found = 1;
- } else
- err = iscsi_sysfs_for_each_session(info, &num_found,
- session_info_print_flat, 0);
+ for (i = 0; i < se_count; ++i) {
+ err = session_info_print_flat(ses[i]);
+ if (err != 0)
+ break;
+ }
break;
case 3:
version = iscsi_sysfs_get_iscsi_kernel_version();
@@ -401,31 +466,8 @@ int session_info_print(int info_level, struct session_info *info, int do_show)
| SESSION_INFO_ISCSI_AUTH);
/* fall through */
case 1:
- INIT_LIST_HEAD(&list);
- struct session_link_info link_info;
-
flags |= (SESSION_INFO_ISCSI_STATE | SESSION_INFO_IFACE);
- if (info) {
- INIT_LIST_HEAD(&info->list);
- list_add_tail(&list, &info->list);
- session_info_print_tree(&list, "", flags, do_show,
- info->iscsid_req_tmo);
- num_found = 1;
- break;
- }
-
- memset(&link_info, 0, sizeof(link_info));
- link_info.list = &list;
- link_info.data = NULL;
- link_info.match_fn = NULL;
-
- err = iscsi_sysfs_for_each_session(&link_info, &num_found,
- session_info_create_list, 0);
- if (err || !num_found)
- break;
-
- session_info_print_tree(&list, "", flags, do_show, -1);
- session_info_free_list(&list);
+ session_info_print_tree(ses, se_count, "", flags, do_show);
break;
default:
log_error("Invalid info level %d. Try 0 - 3.", info_level);
@@ -435,9 +477,6 @@ int session_info_print(int info_level, struct session_info *info, int do_show)
if (err) {
log_error("Can not get list of active sessions (%d)", err);
return err;
- } else if (!num_found) {
- log_error("No active sessions.");
- return ISCSI_ERR_NO_OBJS_FOUND;
}
return 0;
}
diff --git a/usr/session_info.h b/usr/session_info.h
index 179b088..cf2e714 100644
--- a/usr/session_info.h
+++ b/usr/session_info.h
@@ -2,6 +2,8 @@
#define SESSION_INFO_H
#include <sys/types.h>
+#include <libopeniscsiusr/libopeniscsiusr.h>
+
#include "sysfs.h"
#include "types.h"
#include "iscsi_proto.h"
@@ -60,9 +62,11 @@ struct session_link_info {
extern int session_info_create_list(void *data, struct session_info *info);
extern void session_info_free_list(struct list_head *list);
-extern int session_info_print(int info_level, struct session_info *match_info,
- int do_show);
-extern void session_info_print_tree(struct list_head *list, char *prefix,
- unsigned int flags, int do_show, int tmo);
+extern int session_info_print(int info_level, struct iscsi_session **ses,
+ uint32_t se_count, int do_show);
+
+extern void session_info_print_tree(struct iscsi_session **ses,
+ uint32_t se_count, char *prefix,
+ unsigned int flags, int do_show);
#endif
diff --git a/utils/fwparam_ibft/Makefile b/utils/fwparam_ibft/Makefile
index 39ea878..1a2b4cf 100644
--- a/utils/fwparam_ibft/Makefile
+++ b/utils/fwparam_ibft/Makefile
@@ -20,15 +20,23 @@
# Doug Maxey <dwm@austin.ibm.com>
# "Prasanna Mumbai" <mumbai.prasanna@gmail.com>
#
+ifeq ($(TOPDIR),)
+ TOPDIR = ../..
+endif
+
SYSDEPS_OBJS = $(sort $(wildcard ../sysdeps/*.o))
-OBJS := fw_entry.o fwparam_sysfs.o $(SYSDEPS_OBJS) ../../usr/iscsi_net_util.o
+OBJS := fw_entry.o fwparam_sysfs.o $(SYSDEPS_OBJS) \
+ $(TOPDIR)/usr/iscsi_net_util.o
OBJS += prom_lex.o prom_parse.tab.o fwparam_ppc.o
CLEANFILES = $(OBJS) *.output *~
CFLAGS ?= -O2 -g
WARNFLAGS ?= -Wall -Wstrict-prototypes -Wno-format-truncation
-CFLAGS += -fPIC $(WARNFLAGS) -I../../include -I../../usr -D_GNU_SOURCE
+CFLAGS += -fPIC $(WARNFLAGS) -I$(TOPDIR)/include -I$(TOPDIR)/usr -D_GNU_SOURCE \
+ -I$(TOPDIR)/libopeniscsiusr
+
+LDFLAGS += -L$(TOPDIR)/libopeniscsiusr -liscsiusr
all: $(OBJS)