summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Christie <michaelc@cs.wisc.edu>2011-01-30 22:49:56 -0600
committerMike Christie <michaelc@cs.wisc.edu>2011-01-31 21:52:18 -0600
commit2c839a208413b88878ac56f138b5423bba893785 (patch)
tree4aa9cebd177375b6a85b9331ff0d0dfa4a777fb9
parent39d4ceb04f051c208ae7509d268a3871ffa194c5 (diff)
downloadopen-iscsi-2c839a208413b88878ac56f138b5423bba893785.tar.gz
iscsi tools: fix iscsiadm exit codes
iscsiadm/iscsistart return a mix of type of returns codes. Sometimes -1 and sometimes a EXYZ type of error code. This patch has them return a ISCSI_ERR value. See iscsiadm man page EXIT STATUS section for error code definitions.
-rw-r--r--doc/iscsiadm.8130
-rw-r--r--etc/initd/initd.suse4
-rw-r--r--include/iscsi_err.h (renamed from usr/iscsi_err.h)16
-rw-r--r--usr/Makefile2
-rw-r--r--usr/discovery.c3
-rw-r--r--usr/host.c10
-rw-r--r--usr/idbm.c220
-rw-r--r--usr/idbm.h3
-rw-r--r--usr/iface.c40
-rw-r--r--usr/initiator.c1
-rw-r--r--usr/io.c12
-rw-r--r--usr/iscsi_err.c69
-rw-r--r--usr/iscsi_sysfs.c65
-rw-r--r--usr/iscsiadm.c385
-rw-r--r--usr/iscsid.c23
-rw-r--r--usr/iscsid_req.c28
-rw-r--r--usr/iscsid_req.h1
-rw-r--r--usr/iscsistart.c31
-rw-r--r--usr/session_info.c9
-rw-r--r--usr/session_mgmt.c41
-rw-r--r--utils/fwparam_ibft/fw_entry.c8
-rw-r--r--utils/fwparam_ibft/fwparam_ppc.c21
-rw-r--r--utils/fwparam_ibft/fwparam_sysfs.c9
23 files changed, 680 insertions, 451 deletions
diff --git a/doc/iscsiadm.8 b/doc/iscsiadm.8
index 7ff3d57..3020a90 100644
--- a/doc/iscsiadm.8
+++ b/doc/iscsiadm.8
@@ -294,6 +294,136 @@ or
SendTargets (st)
discovery type. An SLP implementation is under development.
+.SH EXIT STATUS
+
+On success 0 is returned. On error one of the return codes below will
+be returned.
+
+Commands that operation on multiple objects (sessions, records, etc),
+iscsiadm/iscsistart will return the first error that is encountered.
+iscsiadm/iscsistart will attempt to execute the operation on the objects it
+can. If no objects are found ISCSI_ERR_NO_OBJS_FOUND is returned.
+
+
+.TP
+.B
+0
+ISCSI_SUCCESS - command executed successfully.
+
+.TP
+.B
+1
+ISCSI_ERR - generic error code.
+
+.TP
+.B
+2
+ISCSI_ERR_SESS_NOT_FOUND - session could not be found.
+
+.TP
+.B
+3
+ISCSI_ERR_NOMEM - could not allocate resource for operation.
+.TP
+.B
+4
+ISCSI_ERR_TRANS - connect problem caused operation to fail.
+
+.TP
+.B
+5
+ISCSI_ERR_LOGIN - generic iSCSI login failure.
+
+.TP
+.B
+6
+ISCSI_ERR_IDBM - error accessing/managing iSCSI DB.
+
+.TP
+.B
+7
+ISCSI_ERR_INVAL - invalid argument.
+
+.TP
+.B
+8
+ISCSI_ERR_TRANS_TIMEOUT - connection timer exired while trying to connect.
+
+.TP
+.B
+9
+ISCSI_ERR_INTERNAL - generic internal iscsid/kernel failure.
+
+.TP
+.B
+10
+ISCSI_ERR_LOGOUT - iSCSI logout failed.
+
+.TP
+.B
+11
+ISCSI_ERR_PDU_TIMEOUT - iSCSI PDU timedout.
+
+.TP
+.B
+12
+ISCSI_ERR_TRANS_NOT_FOUND - iSCSI transport module not loaded in kernel or iscsid.
+
+.TP
+.B
+13
+ISCSI_ERR_ACCESS - did not have proper OS permissions to access iscsid or execute iscsiadm command.
+
+.TP
+.B
+14
+ISCSI_ERR_TRANS_CAPS - transport module did not support operation.
+
+.TP
+.B
+15
+ISCSI_ERR_SESS_EXISTS - session is logged in.
+
+.TP
+.B
+16
+ISCSI_ERR_INVALID_MGMT_REQ - invalid IPC MGMT request.
+
+.TP
+.B
+17
+ISCSI_ERR_ISNS_UNAVAILABLE - iSNS service is not supported.
+
+.TP
+.B
+18
+ISCSI_ERR_ISCSID_COMM_ERR - a read/write to iscsid failed.
+
+.TP
+.B
+19
+ISCSI_ERR_FATAL_LOGIN - fatal iSCSI login error.
+
+.TP
+.B
+20
+ISCSI_ERR_ISCSID_NOTCONN - could ont connect to iscsid.
+
+.TP
+.B
+21
+ISCSI_ERR_NO_OBJS_FOUND - no records/targets/sessions/portals found to execute operation on.
+
+.TP
+.B
+22
+ISCSI_ERR_SYSFS_LOOKUP - could not lookup object in sysfs.
+
+.TP
+.B
+23
+ISCSI_ERR_HOST_NOT_FOUND - could not lookup host.
+
.SH EXAMPLES
.nf
diff --git a/etc/initd/initd.suse b/etc/initd/initd.suse
index 2184bb5..cc0baa9 100644
--- a/etc/initd/initd.suse
+++ b/etc/initd/initd.suse
@@ -30,7 +30,7 @@ iscsi_login_all_nodes()
{
echo -n "Setting up iSCSI targets: "
$ISCSIADM -m node --loginall=automatic 2> /dev/null
- if [ $? == 19 ] ; then
+ if [ $? == 21 ] ; then
rc_failed 6
fi
rc_status -v
@@ -41,7 +41,7 @@ iscsi_logout_all_nodes()
echo -n "Closing all iSCSI connections: "
# Logout from all sessions marked automatic
if ! $ISCSIADM -m node --logoutall=automatic 2> /dev/null; then
- if [ $? == 19 ] ; then
+ if [ $? == 21 ] ; then
RETVAL=6
else
RETVAL=1
diff --git a/usr/iscsi_err.h b/include/iscsi_err.h
index 72663b5..c54edee 100644
--- a/usr/iscsi_err.h
+++ b/include/iscsi_err.h
@@ -8,7 +8,7 @@ enum {
ISCSI_SUCCESS = 0,
/* Generic error */
ISCSI_ERR = 1,
- /* session/record could not be found */
+ /* session could not be found */
ISCSI_ERR_SESS_NOT_FOUND = 2,
/* Could not allocate resource for operation */
ISCSI_ERR_NOMEM = 3,
@@ -34,7 +34,7 @@ enum {
ISCSI_ERR_ACCESS = 13,
/* Transport module did not support operation */
ISCSI_ERR_TRANS_CAPS = 14,
- /* Session is already logged in */
+ /* Session is logged in */
ISCSI_ERR_SESS_EXISTS = 15,
/* Invalid IPC MGMT request */
ISCSI_ERR_INVALID_MGMT_REQ = 16,
@@ -46,6 +46,18 @@ enum {
ISCSI_ERR_FATAL_LOGIN = 19,
/* Could ont connect to iscsid */
ISCSI_ERR_ISCSID_NOTCONN = 20,
+ /* No records/targets/sessions/portals found to execute operation on */
+ ISCSI_ERR_NO_OBJS_FOUND = 21,
+ /* Could not lookup object in sysfs */
+ ISCSI_ERR_SYSFS_LOOKUP = 22,
+ /* Could not lookup host */
+ ISCSI_ERR_HOST_NOT_FOUND = 23,
+
+ /* Always last. Indicates end of error code space */
+ ISCSI_MAX_ERR_VAL,
} iscsi_err;
+extern void iscsi_err_print_msg(int err);
+extern char *iscsi_err_to_str(int err);
+
#endif
diff --git a/usr/Makefile b/usr/Makefile
index 7d0d9fe..4d5ab50 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -40,7 +40,7 @@ SYSDEPS_SRCS = $(wildcard ../utils/sysdeps/*.o)
ISCSI_LIB_SRCS = iscsi_util.o io.o auth.o iscsi_timer.o login.o log.o md5.o \
sha1.o iface.o idbm.o sysfs.o host.o session_info.o iscsi_sysfs.o \
iscsi_net_util.o iscsid_req.o transport.o cxgbi.o be2iscsi.o \
- initiator_common.o $(IPC_OBJ) $(SYSDEPS_SRCS)
+ initiator_common.o iscsi_err.o $(IPC_OBJ) $(SYSDEPS_SRCS)
# core initiator files
INITIATOR_SRCS = initiator.o scsi.o actor.o event_poll.o mgmt_ipc.o
diff --git a/usr/discovery.c b/usr/discovery.c
index 566ef6e..63792ec 100644
--- a/usr/discovery.c
+++ b/usr/discovery.c
@@ -48,6 +48,7 @@
#include "iscsi_ipc.h"
#include "iface.h"
#include "iscsi_timer.h"
+#include "iscsi_err.h"
/* libisns includes */
#include "isns.h"
#include "paths.h"
@@ -451,7 +452,7 @@ int discovery_offload_sendtargets(int host_no, int do_login,
if (rc) {
log_error("Could not offload sendtargets to %s.\n",
drec->address);
- iscsid_handle_error(rc);
+ iscsi_err_print_msg(rc);
return EIO;
}
diff --git a/usr/host.c b/usr/host.c
index 4ce837c..ec983b0 100644
--- a/usr/host.c
+++ b/usr/host.c
@@ -33,6 +33,7 @@
#include "transport.h"
#include "initiator.h"
#include "iface.h"
+#include "iscsi_err.h"
static int match_host_to_session(void *data, struct session_info *info)
{
@@ -200,13 +201,16 @@ int host_info_print(int info_level, uint32_t host_no)
break;
default:
log_error("Invalid info level %d. Try 0 - 4.", info_level);
- return EINVAL;
+ return ISCSI_ERR_INVAL;
}
if (err) {
- log_error("Can not get list of iSCSI hosts (%d)", err);
+ log_error("Can not get list of iSCSI hosts: %s",
+ iscsi_err_to_str(err));
return err;
- } else if (!num_found)
+ } else if (!num_found) {
log_error("No iSCSI hosts.");
+ return ISCSI_ERR_NO_OBJS_FOUND;
+ }
return 0;
}
diff --git a/usr/idbm.c b/usr/idbm.c
index cd93e9f..331d684 100644
--- a/usr/idbm.c
+++ b/usr/idbm.c
@@ -40,6 +40,7 @@
#include "iface.h"
#include "sysdeps.h"
#include "fw_context.h"
+#include "iscsi_err.h"
#define IDBM_HIDE 0 /* Hide parameter when print. */
#define IDBM_SHOW 1 /* Show parameter when print. */
@@ -543,7 +544,7 @@ setup_passwd_len:
}
}
- return 1;
+ return ISCSI_ERR_INVAL;
updated:
strlcpy((char*)info[i].value, value, VALUE_MAXVAL);
@@ -584,12 +585,12 @@ int idbm_verify_param(recinfo_t *info, char *name)
else {
log_error("Cannot modify %s. It is used to look up "
"the record and cannot be changed.", name);
- return EINVAL;
+ return ISCSI_ERR_INVAL;
}
}
log_error("Cannot modify %s. Invalid param name.", name);
- return EINVAL;
+ return ISCSI_ERR_INVAL;
}
void idbm_recinfo_config(recinfo_t *info, FILE *f)
@@ -655,7 +656,7 @@ void idbm_recinfo_config(recinfo_t *info, FILE *f)
}
*(value+i) = 0;
- (void)idbm_rec_update_param(info, name, value, line_number);
+ idbm_rec_update_param(info, name, value, line_number);
} while (line);
}
@@ -809,19 +810,19 @@ get_params_from_disc_link(char *link, char **target, char **tpgt,
(*target) = link;
*address = strchr(*target, ',');
if (!(*address))
- return EINVAL;
+ return ISCSI_ERR_INVAL;
*(*address)++ = '\0';
*port = strchr(*address, ',');
if (!(*port))
- return EINVAL;
+ return ISCSI_ERR_INVAL;
*(*port)++ = '\0';
*tpgt = strchr(*port, ',');
if (!(*tpgt))
- return EINVAL;
+ return ISCSI_ERR_INVAL;
*(*tpgt)++ = '\0';
*ifaceid = strchr(*tpgt, ',');
if (!(*ifaceid))
- return EINVAL;
+ return ISCSI_ERR_INVAL;
*(*ifaceid)++ = '\0';
return 0;
}
@@ -837,8 +838,9 @@ int idbm_lock(void)
if (access(LOCK_DIR, F_OK) != 0) {
if (mkdir(LOCK_DIR, 0660) != 0) {
- log_error("Could not open %s. Exiting\n", LOCK_DIR);
- return errno;
+ log_error("Could not open %s: %s\n", LOCK_DIR,
+ strerror(errno));
+ return ISCSI_ERR_IDBM;
}
}
@@ -855,7 +857,7 @@ int idbm_lock(void)
log_error("Maybe you are not root?");
log_error("Could not lock discovery DB: %s: %s",
LOCK_WRITE_FILE, strerror(errno));
- return errno;
+ return ISCSI_ERR_IDBM;
} else if (i == 0)
log_debug(2, "Waiting for discovery DB lock");
@@ -908,7 +910,7 @@ static int __idbm_rec_read(node_rec_t *out_rec, char *conf)
info = idbm_recinfo_alloc(MAX_KEYS);
if (!info)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
rc = idbm_lock();
if (rc)
@@ -916,8 +918,9 @@ static int __idbm_rec_read(node_rec_t *out_rec, char *conf)
f = fopen(conf, "r");
if (!f) {
- log_debug(5, "Could not open %s err %d\n", conf, errno);
- rc = errno;
+ log_debug(5, "Could not open %s err %s\n", conf,
+ strerror(errno));
+ rc = ISCSI_ERR_IDBM;
goto unlock;
}
@@ -944,7 +947,7 @@ idbm_rec_read(node_rec_t *out_rec, char *targetname, int tpgt,
portal = calloc(1, PATH_MAX);
if (!portal)
- return ENOMEM;
+ return ISCSI_ERR_IDBM;
/* try old style portal as config */
snprintf(portal, PATH_MAX, "%s/%s/%s,%d", NODE_CONFIG_DIR,
@@ -957,14 +960,14 @@ idbm_rec_read(node_rec_t *out_rec, char *targetname, int tpgt,
targetname, ip, port, tpgt, iface->name);
log_debug(5, "rec read looking for config file %s.", portal);
if (!strlen(iface->name)) {
- rc = EINVAL;
+ rc = ISCSI_ERR_INVAL;
goto free_portal;
}
if (stat(portal, &statb)) {
- log_debug(5, "Could not stat %s err %d.", portal, errno);
+ log_debug(5, "Could not stat %s: %s.", portal, strerror(errno));
free(portal);
- return errno;
+ return ISCSI_ERR_IDBM;
}
read:
@@ -1106,17 +1109,12 @@ static int __idbm_print_all_by_drec(void *data, struct discovery_rec *drec)
if (info_level >= 1) {
printf("DiscoveryAddress: %s,%d\n",
drec->address, drec->port);
- rc = idbm_print_discovered(drec, info_level);
- if (rc)
- return 0;
- else
- return ENODEV;
- } else {
+ idbm_print_discovered(drec, info_level);
+ } else
printf("%s:%d via %s\n", drec->address, drec->port,
drec->type == DISCOVERY_TYPE_ISNS ?
"isns" : "sendtargets");
- return 0;
- }
+ return 0;
}
static int idbm_print_all_st(int info_level)
@@ -1196,11 +1194,23 @@ int idbm_print_all_discovery(int info_level)
return found;
}
-/*
- * This iterates over the ifaces in use in the nodes dir.
- * It does not iterate over the ifaces setup in /etc/iscsi/ifaces.
+/**
+ * idbm_for_each_iface - iterate over bound iface recs
+ * @found: nr of recs found so far
+ * @data: data pointer passed to fn
+ * @fn: iterator function ran over each bound iface rec
+ * @targetname: rec's target name
+ * @tpgt: rec's portal group tag
+ * @ip: rec's ip address
+ * @port: rec's port
+ *
+ * This will run fn over all recs with the {targetname,tpgt,ip,port}
+ * id. It does not iterate over the ifaces setup in /etc/iscsi/ifaces.
+ *
+ * fn should return -1 if it skipped the rec, a ISCSI_ERR error code if
+ * the operation failed or 0 if fn was run successfully.
*/
-int idbm_for_each_iface(int *found, void *data,
+static int idbm_for_each_iface(int *found, void *data,
idbm_iface_op_fn *fn,
char *targetname, int tpgt, char *ip, int port)
{
@@ -1213,7 +1223,7 @@ int idbm_for_each_iface(int *found, void *data,
portal = calloc(1, PATH_MAX);
if (!portal)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
if (tpgt >= 0)
goto read_iface;
@@ -1223,7 +1233,7 @@ int idbm_for_each_iface(int *found, void *data,
ip, port);
if (stat(portal, &statb)) {
log_error("iface iter could not stat %s.", portal);
- rc = ENODEV;
+ rc = ISCSI_ERR_IDBM;
goto free_portal;
}
@@ -1245,11 +1255,13 @@ read_iface:
iface_dirfd = opendir(portal);
if (!iface_dirfd) {
log_error("iface iter could not read dir %s.", portal);
- rc = errno;
+ rc = ISCSI_ERR_IDBM;
goto free_portal;
}
while ((iface_dent = readdir(iface_dirfd))) {
+ int curr_rc;
+
if (!strcmp(iface_dent->d_name, ".") ||
!strcmp(iface_dent->d_name, ".."))
continue;
@@ -1261,14 +1273,12 @@ read_iface:
if (__idbm_rec_read(&rec, portal))
continue;
+ curr_rc = fn(data, &rec);
/* less than zero means it was not a match */
- rc = fn(data, &rec);
- if (rc > 0)
- break;
- else if (rc == 0)
+ if (curr_rc > 0 && !rc)
+ rc = curr_rc;
+ else if (curr_rc == 0)
(*found)++;
- else
- rc = 0;
}
closedir(iface_dirfd);
@@ -1291,17 +1301,18 @@ int idbm_for_each_portal(int *found, void *data, idbm_portal_op_fn *fn,
portal = calloc(1, PATH_MAX);
if (!portal)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
snprintf(portal, PATH_MAX, "%s/%s", NODE_CONFIG_DIR, targetname);
portal_dirfd = opendir(portal);
if (!portal_dirfd) {
- rc = errno;
+ rc = ISCSI_ERR_IDBM;
goto done;
}
while ((portal_dent = readdir(portal_dirfd))) {
char *tmp_port, *tmp_tpgt;
+ int curr_rc;
if (!strcmp(portal_dent->d_name, ".") ||
!strcmp(portal_dent->d_name, ".."))
@@ -1316,11 +1327,12 @@ int idbm_for_each_portal(int *found, void *data, idbm_portal_op_fn *fn,
if (tmp_tpgt)
*tmp_tpgt++ = '\0';
- rc = fn(found, data, targetname,
+ curr_rc = fn(found, data, targetname,
tmp_tpgt ? atoi(tmp_tpgt) : -1,
portal_dent->d_name, atoi(tmp_port));
- if (rc)
- break;
+ /* less than zero means it was not a match */
+ if (curr_rc > 0 && !rc)
+ rc = curr_rc;
}
closedir(portal_dirfd);
done:
@@ -1342,14 +1354,17 @@ int idbm_for_each_node(int *found, void *data, idbm_node_op_fn *fn)
return 0;
while ((node_dent = readdir(node_dirfd))) {
+ int curr_rc;
+
if (!strcmp(node_dent->d_name, ".") ||
!strcmp(node_dent->d_name, ".."))
continue;
log_debug(5, "searching %s\n", node_dent->d_name);
- rc = fn(found, data, node_dent->d_name);
- if (rc)
- break;
+ curr_rc = fn(found, data, node_dent->d_name);
+ /* less than zero means it was not a match */
+ if (curr_rc > 0 && !rc)
+ rc = curr_rc;
}
closedir(node_dirfd);
@@ -1404,17 +1419,17 @@ idbm_discovery_read(discovery_rec_t *out_rec, int drec_type,
FILE *f;
if (drec_type > 1)
- return EINVAL;
+ return ISCSI_ERR_INVAL;
memset(out_rec, 0, sizeof(discovery_rec_t));
info = idbm_recinfo_alloc(MAX_KEYS);
if (!info)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
portal = malloc(PATH_MAX);
if (!portal) {
- rc = ENOMEM;
+ rc = ISCSI_ERR_NOMEM;
goto free_info;
}
@@ -1430,8 +1445,9 @@ idbm_discovery_read(discovery_rec_t *out_rec, int drec_type,
f = idbm_open_rec_r(portal,
disc_type_to_config_vals[drec_type].config_name);
if (!f) {
- log_debug(1, "Could not open %s err %d\n", portal, errno);
- rc = errno;
+ log_debug(1, "Could not open %s: %s\n", portal,
+ strerror(errno));
+ rc = ISCSI_ERR_IDBM;
goto unlock;
}
@@ -1502,14 +1518,15 @@ static int idbm_rec_write(node_rec_t *rec)
portal = malloc(PATH_MAX);
if (!portal) {
log_error("Could not alloc portal\n");
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
}
snprintf(portal, PATH_MAX, "%s", NODE_CONFIG_DIR);
if (access(portal, F_OK) != 0) {
if (mkdir(portal, 0660) != 0) {
- log_error("Could not make %s\n", portal);
- rc = errno;
+ log_error("Could not make %s: %s\n", portal,
+ strerror(errno));
+ rc = ISCSI_ERR_IDBM;
goto free_portal;
}
}
@@ -1517,8 +1534,9 @@ static int idbm_rec_write(node_rec_t *rec)
snprintf(portal, PATH_MAX, "%s/%s", NODE_CONFIG_DIR, rec->name);
if (access(portal, F_OK) != 0) {
if (mkdir(portal, 0660) != 0) {
- log_error("Could not make %s\n", portal);
- rc = errno;
+ log_error("Could not make %s: %s\n", portal,
+ strerror(errno));
+ rc = ISCSI_ERR_IDBM;
goto free_portal;
}
}
@@ -1559,13 +1577,13 @@ static int idbm_rec_write(node_rec_t *rec)
* Old style portal as a file, but with tpgt. Let's update it.
*/
if (unlink(portal)) {
- log_error("Could not convert %s. err %d\n", portal,
- errno);
- rc = errno;
+ log_error("Could not convert %s: %s\n", portal,
+ strerror(errno));
+ rc = ISCSI_ERR_IDBM;
goto unlock;
}
} else {
- rc = EINVAL;
+ rc = ISCSI_ERR_INVAL;
goto unlock;
}
@@ -1574,9 +1592,9 @@ mkdir_portal:
rec->name, rec->conn[0].address, rec->conn[0].port, rec->tpgt);
if (stat(portal, &statb)) {
if (mkdir(portal, 0660) != 0) {
- log_error("Could not make dir %s err %d\n",
- portal, errno);
- rc = errno;
+ log_error("Could not make dir %s: %s\n",
+ portal, strerror(errno));
+ rc = ISCSI_ERR_IDBM;
goto unlock;
}
}
@@ -1587,8 +1605,8 @@ mkdir_portal:
open_conf:
f = fopen(portal, "w");
if (!f) {
- log_error("Could not open %s err %d\n", portal, errno);
- rc = errno;
+ log_error("Could not open %s: %sd\n", portal, strerror(errno));
+ rc = ISCSI_ERR_IDBM;
goto unlock;
}
@@ -1609,12 +1627,12 @@ idbm_discovery_write(discovery_rec_t *rec)
int rc = 0;
if (rec->type > 1)
- return EINVAL;
+ return ISCSI_ERR_INVAL;
portal = malloc(PATH_MAX);
if (!portal) {
log_error("Could not alloc portal\n");
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
}
rc = idbm_lock();
@@ -1625,8 +1643,9 @@ idbm_discovery_write(discovery_rec_t *rec)
disc_type_to_config_vals[rec->type].config_root);
if (access(portal, F_OK) != 0) {
if (mkdir(portal, 0660) != 0) {
- log_error("Could not make %s\n", portal);
- rc = errno;
+ log_error("Could not make %s: %s\n", portal,
+ strerror(errno));
+ rc = ISCSI_ERR_IDBM;
goto unlock;
}
}
@@ -1638,8 +1657,8 @@ idbm_discovery_write(discovery_rec_t *rec)
f = idbm_open_rec_w(portal,
disc_type_to_config_vals[rec->type].config_name);
if (!f) {
- log_error("Could not open %s err %d\n", portal, errno);
- rc = errno;
+ log_error("Could not open %s: %s\n", portal, strerror(errno));
+ rc = ISCSI_ERR_IDBM;
goto unlock;
}
@@ -1683,9 +1702,9 @@ static int setup_disc_to_node_link(char *disc_portal, node_rec_t *rec)
case DISCOVERY_TYPE_FW:
if (access(FW_CONFIG_DIR, F_OK) != 0) {
if (mkdir(FW_CONFIG_DIR, 0660) != 0) {
- log_error("Could not make %s\n",
- FW_CONFIG_DIR);
- rc = errno;
+ log_error("Could not make %s: %s",
+ FW_CONFIG_DIR, strerror(errno));
+ rc = ISCSI_ERR_IDBM;
}
}
@@ -1697,9 +1716,9 @@ static int setup_disc_to_node_link(char *disc_portal, node_rec_t *rec)
case DISCOVERY_TYPE_STATIC:
if (access(STATIC_CONFIG_DIR, F_OK) != 0) {
if (mkdir(STATIC_CONFIG_DIR, 0660) != 0) {
- log_error("Could not make %s\n",
- STATIC_CONFIG_DIR);
- rc = errno;
+ log_error("Could not make %s; %s",
+ STATIC_CONFIG_DIR, strerror(errno));
+ rc = ISCSI_ERR_IDBM;
}
}
@@ -1711,9 +1730,9 @@ static int setup_disc_to_node_link(char *disc_portal, node_rec_t *rec)
case DISCOVERY_TYPE_ISNS:
if (access(ISNS_CONFIG_DIR, F_OK) != 0) {
if (mkdir(ISNS_CONFIG_DIR, 0660) != 0) {
- log_error("Could not make %s\n",
- ISNS_CONFIG_DIR);
- rc = errno;
+ log_error("Could not make %s: %s",
+ ISNS_CONFIG_DIR, strerror(errno));
+ rc = ISCSI_ERR_IDBM;
}
}
@@ -1760,7 +1779,7 @@ static int setup_disc_to_node_link(char *disc_portal, node_rec_t *rec)
break;
case DISCOVERY_TYPE_SLP:
default:
- rc = EINVAL;
+ rc = ISCSI_ERR_INVAL;
}
return rc;
@@ -1801,7 +1820,7 @@ int idbm_add_node(node_rec_t *newrec, discovery_rec_t *drec, int overwrite)
node_portal = calloc(2, PATH_MAX);
if (!node_portal)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
disc_portal = node_portal + PATH_MAX;
snprintf(node_portal, PATH_MAX, "%s/%s/%s,%d,%d", NODE_CONFIG_DIR,
@@ -1823,9 +1842,10 @@ int idbm_add_node(node_rec_t *newrec, discovery_rec_t *drec, int overwrite)
log_debug(7, "link from %s to %s exists", node_portal,
disc_portal);
else {
- rc = errno;
+ rc = ISCSI_ERR_IDBM;
log_error("Could not make link from disc source %s to "
- "node %s", disc_portal, node_portal);
+ "node %s: %s", disc_portal, node_portal,
+ strerror(errno));
}
}
idbm_unlock();
@@ -1843,7 +1863,7 @@ static int idbm_bind_iface_to_nodes(idbm_disc_nodes_fn *disc_node_fn,
INIT_LIST_HEAD(&new_recs);
if (disc_node_fn(data, iface, &new_recs))
- return ENODEV;
+ return ISCSI_ERR;
list_for_each_entry_safe(rec, tmp, &new_recs, list) {
list_del_init(&rec->list);
@@ -1988,7 +2008,7 @@ int idbm_delete_discovery(discovery_rec_t *drec)
portal = calloc(1, PATH_MAX);
if (!portal)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
snprintf(portal, PATH_MAX, "%s/%s,%d",
disc_type_to_config_vals[drec->type].config_root,
@@ -2045,7 +2065,7 @@ static int idbm_remove_disc_to_node_link(node_rec_t *rec,
tmprec = malloc(sizeof(*tmprec));
if (!tmprec)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
memset(portal, 0, PATH_MAX);
snprintf(portal, PATH_MAX, "%s/%s/%s,%d,%d/%s", NODE_CONFIG_DIR,
@@ -2073,9 +2093,9 @@ static int idbm_remove_disc_to_node_link(node_rec_t *rec,
if (!stat(portal, &statb)) {
if (unlink(portal)) {
- log_error("Could not remove link %s err %d\n",
- portal, errno);
- rc = errno;
+ log_error("Could not remove link %s: %s\n",
+ portal, strerror(errno));
+ rc = ISCSI_ERR_IDBM;
} else
log_debug(7, "rmd %s", portal);
} else
@@ -2101,7 +2121,7 @@ int idbm_delete_node(node_rec_t *rec)
portal = calloc(1, PATH_MAX);
if (!portal)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
rc = idbm_remove_disc_to_node_link(rec, portal);
if (rc)
@@ -2128,15 +2148,15 @@ int idbm_delete_node(node_rec_t *rec)
if (!stat(portal, &statb))
goto rm_conf;
- log_error("Could not stat %s to delete node err %d\n",
- portal, errno);
- rc = errno;
+ log_error("Could not stat %s to delete node: %s\n",
+ portal, strerror(errno));
+ rc = ISCSI_ERR_IDBM;
goto unlock;
rm_conf:
if (unlink(portal)) {
- log_error("Could not remove %s err %d\n", portal, errno);
- rc = errno;
+ log_error("Could not remove %s: %s\n", portal, strerror(errno));
+ rc = ISCSI_ERR_IDBM;
goto unlock;
}
@@ -2206,7 +2226,7 @@ int idbm_node_set_param(void *data, node_rec_t *rec)
info = idbm_recinfo_alloc(MAX_KEYS);
if (!info)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
idbm_recinfo_node(rec, info);
@@ -2235,7 +2255,7 @@ int idbm_discovery_set_param(void *data, discovery_rec_t *rec)
info = idbm_recinfo_alloc(MAX_KEYS);
if (!info)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
idbm_recinfo_discovery((discovery_rec_t *)rec, info);
@@ -2270,7 +2290,7 @@ int idbm_init(idbm_get_config_file_fn *fn)
db = malloc(sizeof(idbm_t));
if (!db) {
log_error("out of memory on idbm allocation");
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
}
memset(db, 0, sizeof(idbm_t));
db->get_config_file = fn;
diff --git a/usr/idbm.h b/usr/idbm.h
index 4f8f8be..1bcad58 100644
--- a/usr/idbm.h
+++ b/usr/idbm.h
@@ -93,9 +93,6 @@ struct rec_op_data {
node_rec_t *match_rec;
idbm_iface_op_fn *fn;
};
-extern int idbm_for_each_iface(int *found, void *data,
- idbm_iface_op_fn *fn,
- char *targetname, int tpgt, char *ip, int port);
extern int idbm_for_each_portal(int *found, void *data,
idbm_portal_op_fn *fn, char *targetname);
extern int idbm_for_each_node(int *found, void *data,
diff --git a/usr/iface.c b/usr/iface.c
index 80615ca..8a1683b 100644
--- a/usr/iface.c
+++ b/usr/iface.c
@@ -39,6 +39,7 @@
#include "host.h"
#include "fw_context.h"
#include "sysdeps.h"
+#include "iscsi_err.h"
/*
* Default ifaces for use with transports that do not bind to hardware
@@ -101,13 +102,13 @@ struct iface_rec *iface_alloc(char *ifname, int *err)
struct iface_rec *iface;
if (!strlen(ifname) || strlen(ifname) + 1 > ISCSI_MAX_IFACE_LEN) {
- *err = EINVAL;
+ *err = ISCSI_ERR_INVAL;
return NULL;
}
iface = calloc(1, sizeof(*iface));
if (!iface) {
- *err = ENOMEM;
+ *err = ISCSI_ERR_NOMEM;
return NULL;
}
@@ -125,11 +126,11 @@ static int __iface_conf_read(struct iface_rec *iface)
iface_conf = calloc(1, PATH_MAX);
if (!iface_conf)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
info = idbm_recinfo_alloc(MAX_KEYS);
if (!info) {
- rc = ENOMEM;
+ rc = ISCSI_ERR_NOMEM;
goto free_conf;
}
@@ -147,7 +148,7 @@ static int __iface_conf_read(struct iface_rec *iface)
iface_setup_defaults(iface);
rc = 0;
} else
- rc = errno;
+ rc = ISCSI_ERR_IDBM;
goto free_info;
}
@@ -213,12 +214,12 @@ int iface_conf_delete(struct iface_rec *iface)
if (def_iface) {
log_error("iface %s is a special interface and "
"cannot be deleted.\n", iface->name);
- return EINVAL;
+ return ISCSI_ERR_INVAL;
}
iface_conf = calloc(1, PATH_MAX);
if (!iface_conf)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
sprintf(iface_conf, "%s/%s", IFACE_CONFIG_DIR, iface->name);
rc = idbm_lock();
@@ -226,7 +227,7 @@ int iface_conf_delete(struct iface_rec *iface)
goto free_conf;
if (unlink(iface_conf))
- rc = errno;
+ rc = ISCSI_ERR_IDBM;
idbm_unlock();
free_conf:
@@ -246,17 +247,17 @@ int iface_conf_write(struct iface_rec *iface)
log_error("iface %s is a special interface and "
"is not stored in %s.\n", iface->name,
IFACE_CONFIG_DIR);
- return EINVAL;
+ return ISCSI_ERR_INVAL;
}
iface_conf = calloc(1, PATH_MAX);
if (!iface_conf)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
sprintf(iface_conf, "%s/%s", IFACE_CONFIG_DIR, iface->name);
f = fopen(iface_conf, "w");
if (!f) {
- rc = errno;
+ rc = ISCSI_ERR_IDBM;
goto free_conf;
}
@@ -285,12 +286,12 @@ int iface_conf_update(struct db_set_param *param,
if (def_iface) {
log_error("iface %s is a special interface and "
"cannot be modified.\n", iface->name);
- return EINVAL;
+ return ISCSI_ERR_INVAL;
}
info = idbm_recinfo_alloc(MAX_KEYS);
if (!info)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
idbm_recinfo_iface(iface, info);
rc = idbm_verify_param(info, param->name);
@@ -298,10 +299,8 @@ int iface_conf_update(struct db_set_param *param,
goto free_info;
rc = idbm_rec_update_param(info, param->name, param->value, 0);
- if (rc) {
- rc = EIO;
+ if (rc)
goto free_info;
- }
rc = iface_conf_write(iface);
free_info:
@@ -418,7 +417,7 @@ int iface_get_by_net_binding(struct iface_rec *pattern,
__iface_get_by_net_binding);
if (rc == 1)
return 0;
- return ENODEV;
+ return ISCSI_ERR_NO_OBJS_FOUND;
}
static int __iface_setup_host_bindings(void *data, struct host_info *hinfo)
@@ -438,7 +437,8 @@ static int __iface_setup_host_bindings(void *data, struct host_info *hinfo)
return 0;
}
- if (iface_get_by_net_binding(&hinfo->iface, &iface) == ENODEV) {
+ if (iface_get_by_net_binding(&hinfo->iface, &iface) ==
+ ISCSI_ERR_NO_OBJS_FOUND) {
/* Must be a new port */
if (!strlen(hinfo->iface.hwaddress)) {
log_error("Invalid offload iSCSI host %u. Missing "
@@ -704,7 +704,7 @@ int iface_for_each_iface(void *data, int skip_def, int *nr_found,
iface_dent->d_name);
iface = iface_alloc(iface_dent->d_name, &err);
if (!iface || err) {
- if (err == EINVAL)
+ if (err == ISCSI_ERR_INVAL)
log_error("Invalid iface name %s. Must be "
"from 1 to %d characters.",
iface_dent->d_name,
@@ -756,7 +756,7 @@ static int iface_link(void *data, struct iface_rec *iface)
iface_copy = calloc(1, sizeof(*iface_copy));
if (!iface_copy)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
memcpy(iface_copy, iface, sizeof(*iface_copy));
INIT_LIST_HEAD(&iface_copy->list);
diff --git a/usr/initiator.c b/usr/initiator.c
index 70a2c8e..927bdba 100644
--- a/usr/initiator.c
+++ b/usr/initiator.c
@@ -1758,7 +1758,6 @@ iscsi_sync_session(node_rec_t *rec, queue_task_t *qtask, uint32_t sid)
session->hostno = iscsi_sysfs_get_host_no_from_sid(sid, &err);
if (err) {
log_error("Could not get hostno for session %d\n", sid);
- err = ISCSI_ERR_INTERNAL;
goto destroy_session;
}
diff --git a/usr/io.c b/usr/io.c
index 24a09d6..cf21088 100644
--- a/usr/io.c
+++ b/usr/io.c
@@ -401,7 +401,6 @@ iscsi_io_connect(iscsi_conn_t *conn)
int rc, ret;
struct sigaction action;
struct sigaction old;
- char serv[NI_MAXSERV];
/* set a timeout, since the socket calls may take a long time to
* timeout on their own
@@ -420,22 +419,21 @@ iscsi_io_connect(iscsi_conn_t *conn)
*/
rc = iscsi_io_tcp_connect(conn, 0);
if (timedout) {
+ log_error("connect to %s timed out", conn->host);
+
log_debug(1, "socket %d connect timed out", conn->socket_fd);
ret = 0;
goto done;
} else if (rc < 0) {
- getnameinfo((struct sockaddr *) &conn->saddr,
- sizeof(conn->saddr),
- conn->host, sizeof(conn->host), serv, sizeof(serv),
- NI_NUMERICHOST|NI_NUMERICSERV);
- log_error("cannot make connection to %s:%s (%d)",
- conn->host, serv, errno);
+ log_error("cannot make connection to %s: %s",
+ conn->host, strerror(errno));
close(conn->socket_fd);
ret = 0;
goto done;
} else if (log_level > 0) {
struct sockaddr_storage ss;
char lserv[NI_MAXSERV];
+ char serv[NI_MAXSERV];
socklen_t salen = sizeof(ss);
if (getsockname(conn->socket_fd, (struct sockaddr *) &ss,
diff --git a/usr/iscsi_err.c b/usr/iscsi_err.c
new file mode 100644
index 0000000..c922b6d
--- /dev/null
+++ b/usr/iscsi_err.c
@@ -0,0 +1,69 @@
+/*
+ * iSCSI error helpers
+ *
+ * Copyright (C) 2011 Mike Christie
+ * Copyright (C) 2011 Red Hat, Inc. All rights reserved.
+ * maintained by open-iscsi@googlegroups.com
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * See the file COPYING included with this distribution for more details.
+ */
+#include "stdlib.h"
+#include "iscsi_err.h"
+#include "log.h"
+
+static char *iscsi_err_msgs[] = {
+ /* 0 */ "",
+ /* 1 */ "unknown error",
+ /* 2 */ "session not found",
+ /* 3 */ "no available memory",
+ /* 4 */ "encountered connection failure",
+ /* 5 */ "encountered iSCSI login failure",
+ /* 6 */ "encountered iSCSI database failure",
+ /* 7 */ "invalid parameter",
+ /* 8 */ "connection timed out",
+ /* 9 */ "internal error",
+ /* 10 */ "encountered iSCSI logout failure",
+ /* 11 */ "iSCSI PDU timed out",
+ /* 12 */ "iSCSI driver not found. Please make sure it is loaded, and retry the operation",
+ /* 13 */ "daemon access denied",
+ /* 14 */ "iSCSI driver does not support requested capability.",
+ /* 15 */ "session exists",
+ /* 16 */ "Unknown request",
+ /* 17 */ "iSNS service not supported",
+ /* 18 */ "could not communicate to iscsid",
+ /* 19 */ "encountered non-retryable iSCSI login failure",
+ /* 20 */ "could not connect to iscsid",
+ /* 21 */ "no objects found",
+ /* 23 */ "sysfs lookup failure",
+ /* 23 */ "host not found",
+};
+
+char *iscsi_err_to_str(int err)
+{
+ if (err >= ISCSI_MAX_ERR_VAL || err < 0) {
+ log_error("invalid error code %d", err);
+ return NULL;
+ }
+
+ return iscsi_err_msgs[err];
+}
+
+void iscsi_err_print_msg(int err)
+{
+ if (err >= ISCSI_MAX_ERR_VAL || err < 0) {
+ log_error("invalid error code %d", err);
+ return;
+ }
+ log_error("initiator reported error (%d - %s)", err,
+ iscsi_err_msgs[err]);
+}
diff --git a/usr/iscsi_sysfs.c b/usr/iscsi_sysfs.c
index a9c78c6..7f66861 100644
--- a/usr/iscsi_sysfs.c
+++ b/usr/iscsi_sysfs.c
@@ -36,6 +36,7 @@
#include "iface.h"
#include "session_info.h"
#include "host.h"
+#include "iscsi_err.h"
/*
* TODO: remove the _DIR defines and search for subsys dirs like
@@ -242,7 +243,7 @@ uint32_t iscsi_sysfs_get_host_no_from_sid(uint32_t sid, int *err)
ISCSI_SESSION_SUBSYS, id)) {
log_error("Could not lookup devpath for %s. Possible sysfs "
"incompatibility.\n", id);
- *err = EIO;
+ *err = ISCSI_ERR_SYSFS_LOOKUP;
return 0;
}
@@ -250,7 +251,7 @@ uint32_t iscsi_sysfs_get_host_no_from_sid(uint32_t sid, int *err)
if (!session_dev) {
log_error("Could not get dev for %s. Possible sysfs "
"incompatibility.\n", id);
- *err = EIO;
+ *err = ISCSI_ERR_SYSFS_LOOKUP;
return 0;
}
@@ -275,7 +276,7 @@ uint32_t iscsi_sysfs_get_host_no_from_sid(uint32_t sid, int *err)
if (!host_dev) {
log_error("Could not get host dev for %s. Possible "
"sysfs incompatibility.\n", id);
- *err = EIO;
+ *err = ISCSI_ERR_SYSFS_LOOKUP;
return 0;
}
}
@@ -305,7 +306,7 @@ static uint32_t get_host_no_from_netdev(char *netdev, int *rc)
info = calloc(1, sizeof(*info));
if (!info) {
- *rc = ENOMEM;
+ *rc = ISCSI_ERR_NOMEM;
return -1;
}
strcpy(info->iface.netdev, netdev);
@@ -315,7 +316,7 @@ static uint32_t get_host_no_from_netdev(char *netdev, int *rc)
if (local_rc == 1)
host_no = info->host_no;
else
- *rc = ENODEV;
+ *rc = ISCSI_ERR_HOST_NOT_FOUND;
free(info);
return host_no;
}
@@ -341,7 +342,7 @@ static uint32_t get_host_no_from_hwaddress(char *address, int *rc)
info = calloc(1, sizeof(*info));
if (!info) {
- *rc = ENOMEM;
+ *rc = ISCSI_ERR_NOMEM;
return -1;
}
strcpy(info->iface.hwaddress, address);
@@ -351,7 +352,7 @@ static uint32_t get_host_no_from_hwaddress(char *address, int *rc)
if (local_rc == 1)
host_no = info->host_no;
else
- *rc = ENODEV;
+ *rc = ISCSI_ERR_HOST_NOT_FOUND;
free(info);
return host_no;
}
@@ -378,7 +379,7 @@ static uint32_t get_host_no_from_ipaddress(char *address, int *rc)
info = calloc(1, sizeof(*info));
if (!info) {
- *rc = ENOMEM;
+ *rc = ISCSI_ERR_NOMEM;
return -1;
}
strcpy(info->iface.ipaddress, address);
@@ -388,7 +389,7 @@ static uint32_t get_host_no_from_ipaddress(char *address, int *rc)
if (local_rc == 1)
host_no = info->host_no;
else
- *rc = ENODEV;
+ *rc = ISCSI_ERR_HOST_NOT_FOUND;
free(info);
return host_no;
}
@@ -408,7 +409,7 @@ uint32_t iscsi_sysfs_get_host_no_from_hwinfo(struct iface_rec *iface, int *rc)
strcasecmp(iface->ipaddress, DEFAULT_IPADDRESS))
host_no = get_host_no_from_ipaddress(iface->ipaddress, &tmp_rc);
else
- tmp_rc = EINVAL;
+ tmp_rc = ISCSI_ERR_INVAL;
*rc = tmp_rc;
return host_no;
@@ -527,7 +528,10 @@ static int iscsi_sysfs_read_iface(struct iface_rec *iface, int host_no,
iface_str(iface));
}
}
- return ret;
+ if (ret)
+ return ISCSI_ERR_SYSFS_LOOKUP;
+ else
+ return 0;
}
int iscsi_sysfs_get_hostinfo_by_host_no(struct host_info *hinfo)
@@ -544,7 +548,7 @@ int iscsi_sysfs_for_each_host(void *data, int *nr_found,
info = malloc(sizeof(*info));
if (!info)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
n = scandir(ISCSI_HOST_DIR, &namelist, trans_filter,
alphasort);
@@ -635,7 +639,7 @@ int iscsi_sysfs_get_sid_from_path(char *session)
if (!dev) {
log_error("Could not get dev for %s. Possible sysfs "
"incompatibility.\n", devpath);
- exit(1);
+ return -1;
}
if (!strncmp(dev->kernel, "session", 7))
@@ -649,8 +653,7 @@ int iscsi_sysfs_get_sid_from_path(char *session)
}
log_error("Unable to find sid in path %s", session);
- exit(1);
- return 0;
+ return -1;
}
int iscsi_sysfs_get_sessioninfo_by_id(struct session_info *info, char *session)
@@ -661,21 +664,21 @@ int iscsi_sysfs_get_sessioninfo_by_id(struct session_info *info, char *session)
if (sscanf(session, "session%d", &info->sid) != 1) {
log_error("invalid session '%s'", session);
- return EINVAL;
+ return ISCSI_ERR_INVAL;
}
ret = sysfs_get_str(session, ISCSI_SESSION_SUBSYS, "targetname",
info->targetname, sizeof(info->targetname));
if (ret) {
log_error("could not read session targetname: %d", ret);
- return ret;
+ return ISCSI_ERR_SYSFS_LOOKUP;
}
ret = sysfs_get_int(session, ISCSI_SESSION_SUBSYS, "tpgt",
&info->tpgt);
if (ret) {
- log_error("could not read session tpgt: %u", ret);
- return ret;
+ log_error("could not read session tpgt: %d", ret);
+ return ISCSI_ERR_SYSFS_LOOKUP;
}
snprintf(id, sizeof(id), ISCSI_CONN_ID, info->sid);
@@ -731,8 +734,8 @@ int iscsi_sysfs_get_sessioninfo_by_id(struct session_info *info, char *session)
ret = 0;
host_no = iscsi_sysfs_get_host_no_from_sid(info->sid, &ret);
if (ret) {
- log_error("could not get host_no for session%d err %d.",
- info->sid, ret);
+ log_error("could not get host_no for session%d: %s.",
+ info->sid, iscsi_err_to_str(ret));
return ret;
}
@@ -759,7 +762,7 @@ int iscsi_sysfs_for_each_session(void *data, int *nr_found,
info = calloc(1, sizeof(*info));
if (!info)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
n = scandir(ISCSI_SESSION_DIR, &namelist, trans_filter,
alphasort);
@@ -801,8 +804,10 @@ int iscsi_sysfs_get_session_state(char *state, int sid)
char id[NAME_SIZE];
snprintf(id, sizeof(id), ISCSI_SESSION_ID, sid);
- return sysfs_get_str(id, ISCSI_SESSION_SUBSYS, "state", state,
- SCSI_MAX_STATE_VALUE);
+ if (sysfs_get_str(id, ISCSI_SESSION_SUBSYS, "state", state,
+ SCSI_MAX_STATE_VALUE))
+ return ISCSI_ERR_SYSFS_LOOKUP;
+ return 0;
}
int iscsi_sysfs_get_host_state(char *state, int host_no)
@@ -810,8 +815,10 @@ int iscsi_sysfs_get_host_state(char *state, int host_no)
char id[NAME_SIZE];
snprintf(id, sizeof(id), ISCSI_HOST_ID, host_no);
- return sysfs_get_str(id, SCSI_HOST_SUBSYS, "state", state,
- SCSI_MAX_STATE_VALUE);
+ if (sysfs_get_str(id, SCSI_HOST_SUBSYS, "state", state,
+ SCSI_MAX_STATE_VALUE))
+ return ISCSI_ERR_SYSFS_LOOKUP;
+ return 0;
}
int iscsi_sysfs_get_device_state(char *state, int host_no, int target, int lun)
@@ -822,7 +829,7 @@ int iscsi_sysfs_get_device_state(char *state, int host_no, int target, int lun)
if (sysfs_get_str(id, SCSI_SUBSYS, "state", state,
SCSI_MAX_STATE_VALUE)) {
log_debug(3, "Could not read attr state for %s\n", id);
- return EIO;
+ return ISCSI_ERR_SYSFS_LOOKUP;
}
return 0;
@@ -923,7 +930,7 @@ static uint32_t get_target_no_from_sid(uint32_t sid, int *err)
uint32_t host, bus, target = 0;
size_t sysfs_len;
- *err = ENODEV;
+ *err = ISCSI_ERR_SESS_NOT_FOUND;
snprintf(id, sizeof(id), "session%u", sid);
if (!sysfs_lookup_devpath_by_subsys_id(devpath, sizeof(devpath),
@@ -1066,7 +1073,7 @@ int iscsi_sysfs_for_each_device(void *data, int host_no, uint32_t sid,
ISCSI_SESSION_SUBSYS, id)) {
log_debug(3, "Could not lookup devpath for %s %s\n",
ISCSI_SESSION_SUBSYS, id);
- return EIO;
+ return ISCSI_ERR_SYSFS_LOOKUP;
}
snprintf(path_full, sizeof(path_full), "%s%s/device/target%d:0:%d",
diff --git a/usr/iscsiadm.c b/usr/iscsiadm.c
index e9d0e7c..db52520 100644
--- a/usr/iscsiadm.c
+++ b/usr/iscsiadm.c
@@ -48,6 +48,7 @@
#include "session_mgmt.h"
#include "iscsid_req.h"
#include "isns-proto.h"
+#include "iscsi_err.h"
static char program_name[] = "iscsiadm";
static char config_file[TARGET_NAME_MAXLEN];
@@ -119,7 +120,7 @@ iscsiadm -m fw [ -l ]\n\
iscsiadm -m host [ -P printlevel ] [ -H hostno ]\n\
iscsiadm -k priority\n");
}
- exit(status == 0 ? 0 : -1);
+ exit(status);
}
static int
@@ -212,7 +213,7 @@ static void kill_iscsid(int priority)
req.command = MGMT_IPC_IMMEDIATE_STOP;
rc = iscsid_exec_req(&req, &rsp, 0);
if (rc) {
- iscsid_handle_error(rc);
+ iscsi_err_print_msg(rc);
log_error("Could not stop iscsid. Trying sending iscsid "
"SIGTERM or SIGKILL signals manually\n");
}
@@ -251,12 +252,12 @@ static int print_ifaces(struct iface_rec *iface, int info_level)
break;
default:
log_error("Invalid info level %d. Try 0 - 1.", info_level);
- return EINVAL;
+ return ISCSI_ERR_INVAL;
}
if (!num_found) {
log_error("No interfaces found.");
- err = ENODEV;
+ err = ISCSI_ERR_NO_OBJS_FOUND;
}
return err;
}
@@ -296,11 +297,11 @@ for_each_session(struct node_rec *rec, iscsi_sysfs_session_op_fn *fn)
err = iscsi_sysfs_for_each_session(rec, &num_found, fn);
if (err)
- log_error("Could not execute operation on all sessions. Err "
- "%d.", err);
+ log_error("Could not execute operation on all sessions: %s",
+ iscsi_err_to_str(err));
else if (!num_found) {
- log_error("No portal found.");
- err = ENODEV;
+ log_error("No session found.");
+ err = ISCSI_ERR_NO_OBJS_FOUND;
}
return err;
@@ -313,7 +314,7 @@ static int link_recs(void *data, struct node_rec *rec)
rec_copy = calloc(1, sizeof(*rec_copy));
if (!rec_copy)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
memcpy(rec_copy, rec, sizeof(*rec_copy));
INIT_LIST_HEAD(&rec_copy->list);
list_add_tail(&rec_copy->list, list);
@@ -326,7 +327,6 @@ __logout_by_startup(void *data, struct list_head *list,
{
char *mode = data;
node_rec_t rec;
- int rc = 0;
memset(&rec, 0, sizeof(node_rec_t));
if (idbm_rec_read(&rec, info->targetname, info->tpgt,
@@ -352,28 +352,33 @@ __logout_by_startup(void *data, struct list_head *list,
if (rec.startup == ISCSI_STARTUP_ONBOOT)
return -1;
- if (!match_startup_mode(&rec, mode))
- rc = iscsi_logout_portal(info, list);
- return rc;
+ if (match_startup_mode(&rec, mode))
+ return -1;
+
+ return iscsi_logout_portal(info, list);
}
static int
logout_by_startup(char *mode)
{
int nr_found;
+ int rc;
if (!mode || !(!strcmp(mode, "automatic") || !strcmp(mode, "all") ||
!strcmp(mode,"manual"))) {
log_error("Invalid logoutall option %s.", mode);
- usage(0);
- return EINVAL;
+ usage(ISCSI_ERR_INVAL);
+ return ISCSI_ERR_INVAL;
}
- return iscsi_logout_portals(mode, &nr_found, 1, __logout_by_startup);
+ rc = iscsi_logout_portals(mode, &nr_found, 1, __logout_by_startup);
+ if (rc == ISCSI_ERR_NO_OBJS_FOUND)
+ log_error("No matching sessions found");
+ return rc;
}
/*
- * TODO: merged this and logout into the common for_each_rec by making
+ * TODO: merged this and logout into the common for_each_matched_rec by making
* the matching more generic
*/
static int
@@ -390,36 +395,45 @@ __login_by_startup(void *data, struct list_head *list, struct node_rec *rec)
if (match_startup_mode(rec, mode))
return -1;
- iscsi_login_portal(NULL, list, rec);
- return 0;
+ return iscsi_login_portal(NULL, list, rec);
}
static int
login_by_startup(char *mode)
{
- int nr_found = 0, rc, err;
+ int nr_found = 0, err, rc;
struct list_head rec_list;
if (!mode || !(!strcmp(mode, "automatic") || !strcmp(mode, "all") ||
!strcmp(mode,"manual"))) {
log_error("Invalid loginall option %s.", mode);
- usage(0);
- return EINVAL;
+ usage(ISCSI_ERR_INVAL);
+ return ISCSI_ERR_INVAL;
}
INIT_LIST_HEAD(&rec_list);
- rc = idbm_for_each_rec(&nr_found, &rec_list, link_recs);
+ err = idbm_for_each_rec(&nr_found, &rec_list, link_recs);
+ if (err && !list_empty(&rec_list))
+ /* log msg and try to log into what we found */
+ log_error("Could not read all records: %s",
+ iscsi_err_to_str(err));
+ else if (err && list_empty(&rec_list)) {
+ log_error("Could not read node DB: %s.",
+ iscsi_err_to_str(err));
+ return err;
+ } else if (list_empty(&rec_list)) {
+ log_error("No records found");
+ return ISCSI_ERR_NO_OBJS_FOUND;
+ }
+ rc = err;
+
err = iscsi_login_portals(mode, &nr_found, 1, &rec_list,
__login_by_startup);
+ if (err)
+ log_error("Could not log into all portals");
+
if (err && !rc)
rc = err;
-
- if (rc)
- log_error("Could not log into all portals. Err %d.", rc);
- else if (!nr_found) {
- log_error("No records found!");
- rc = ENODEV;
- }
return rc;
}
@@ -454,7 +468,7 @@ static int iscsi_logout_matched_portal(void *data, struct list_head *list,
return iscsi_logout_portal(info, list);
}
-static int iface_fn(void *data, node_rec_t *rec)
+static int rec_match_fn(void *data, node_rec_t *rec)
{
struct rec_op_data *op_data = data;
@@ -465,8 +479,8 @@ static int iface_fn(void *data, node_rec_t *rec)
return op_data->fn(op_data->data, rec);
}
-static int __for_each_rec(int verbose, struct node_rec *rec,
- void *data, idbm_iface_op_fn *fn)
+static int __for_each_matched_rec(int verbose, struct node_rec *rec,
+ void *data, idbm_iface_op_fn *fn)
{
struct rec_op_data op_data;
int nr_found = 0, rc;
@@ -476,39 +490,51 @@ static int __for_each_rec(int verbose, struct node_rec *rec,
op_data.match_rec = rec;
op_data.fn = fn;
- rc = idbm_for_each_rec(&nr_found, &op_data, iface_fn);
+ rc = idbm_for_each_rec(&nr_found, &op_data, rec_match_fn);
if (rc) {
if (verbose)
log_error("Could not execute operation on all "
- "records. Err %d.", rc);
+ "records: %s", iscsi_err_to_str(rc));
} else if (!nr_found) {
if (verbose)
- log_error("no records found!");
- rc = ENODEV;
+ log_error("No records found");
+ rc = ISCSI_ERR_NO_OBJS_FOUND;
}
return rc;
}
-static int for_each_rec(struct node_rec *rec, void *data,
- idbm_iface_op_fn *fn)
+static int for_each_matched_rec(struct node_rec *rec, void *data,
+ idbm_iface_op_fn *fn)
{
- return __for_each_rec(1, rec, data, fn);
+ return __for_each_matched_rec(1, rec, data, fn);
}
static int login_portals(struct node_rec *pattern_rec)
{
struct list_head rec_list;
- int err, ret, nr_found;
+ int nr_found, rc, err;
INIT_LIST_HEAD(&rec_list);
- ret = for_each_rec(pattern_rec, &rec_list, link_recs);
+ err = for_each_matched_rec(pattern_rec, &rec_list, link_recs);
+ if (err == ISCSI_ERR_NO_OBJS_FOUND)
+ return err;
+ else if (err && list_empty(&rec_list))
+ return err;
+
+ rc = err;
+ /* if there is an err but some recs then try to login to what we have */
+
err = iscsi_login_portals(NULL, &nr_found, 1, &rec_list,
iscsi_login_portal);
- if (err && !ret)
- ret = err;
- return ret;
+ if (err)
+ log_error("Could not log into all portals");
+
+ if (err && !rc)
+ rc = err;
+
+ return rc;
}
static int print_nodes(int info_level, struct node_rec *rec)
@@ -519,17 +545,16 @@ static int print_nodes(int info_level, struct node_rec *rec)
switch (info_level) {
case 0:
case -1:
- if (for_each_rec(rec, NULL, idbm_print_node_flat))
- rc = -1;
+ rc = for_each_matched_rec(rec, NULL, idbm_print_node_flat);
break;
case 1:
memset(&tmp_rec, 0, sizeof(node_rec_t));
- if (for_each_rec(rec, &tmp_rec, idbm_print_node_and_iface_tree))
- rc = -1;
+ rc = for_each_matched_rec(rec, &tmp_rec,
+ idbm_print_node_and_iface_tree);
break;
default:
log_error("Invalid info level %d. Try 0 or 1.", info_level);
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
}
return rc;
@@ -596,7 +621,7 @@ session_stats(void *data, struct session_info *info)
rc = iscsid_exec_req(&req, &rsp, 1);
if (rc)
- return EIO;
+ return rc;
printf("Stats for session [sid: %d, target: %s, portal: "
"%s,%d]\n",
@@ -675,14 +700,14 @@ static int add_static_rec(int *found, char *targetname, int tpgt,
rec = calloc(1, sizeof(*rec));
if (!rec) {
log_error("Could not allocate memory for node addition");
- rc = ENOMEM;
+ rc = ISCSI_ERR_NOMEM;
goto done;
}
drec = calloc(1, sizeof(*drec));
if (!drec) {
log_error("Could not allocate memory for node addition");
- rc = ENOMEM;
+ rc = ISCSI_ERR_NOMEM;
goto free_rec;
}
drec->type = DISCOVERY_TYPE_STATIC;
@@ -725,10 +750,10 @@ static int add_static_portal(int *found, void *data,
if (strlen(rec->conn[0].address) &&
strcmp(rec->conn[0].address, ip))
- return 0;
+ return -1;
if (rec->conn[0].port != -1 && rec->conn[0].port != port)
- return 0;
+ return -1;
return add_static_rec(found, targetname, tpgt, ip, port,
&rec->iface);
@@ -743,7 +768,7 @@ static int add_static_node(int *found, void *data,
goto search;
if (strcmp(rec->name, targetname))
- return 0;
+ return -1;
if (!strlen(rec->conn[0].address))
goto search;
@@ -761,11 +786,8 @@ static int add_static_recs(struct node_rec *rec)
int rc, nr_found = 0;
rc = idbm_for_each_node(&nr_found, rec, add_static_node);
- if (rc) {
- log_error("Error while adding records. DB may be in an "
- "inconsistent state. Err %d", rc);
- return rc;
- }
+ if (rc)
+ goto done;
/* success */
if (nr_found > 0)
return 0;
@@ -775,13 +797,12 @@ static int add_static_recs(struct node_rec *rec)
rc = add_static_rec(&nr_found, rec->name, rec->tpgt,
rec->conn[0].address, rec->conn[0].port,
&rec->iface);
- if (rc)
- goto done;
- return 0;
+ if (!rc)
+ return 0;
}
done:
- printf("No records added.\n");
- return ENODEV;
+ log_error("Error while adding record: %s", iscsi_err_to_str(rc));
+ return rc;
}
/*
@@ -809,7 +830,7 @@ static int delete_node(void *data, struct node_rec *rec)
"using it. Logout session then rerun command to "
"remove record.", rec->iface.name, rec->name,
rec->conn[0].address, rec->conn[0].port);
- return EINVAL;
+ return ISCSI_ERR_SESS_EXISTS;
}
return idbm_delete_node(rec);
@@ -832,18 +853,17 @@ static int delete_stale_rec(void *data, struct node_rec *rec)
* if we are not from the same discovery source
* ignore it
*/
- return 0;
+ return -1;
if (__iscsi_match_session(rec,
new_rec->name,
new_rec->conn[0].address,
new_rec->conn[0].port,
&new_rec->iface))
- return 0;
+ return -1;
}
/* if there is a error we can continue on */
- delete_node(NULL, rec);
- return 0;
+ return delete_node(NULL, rec);
}
static int
@@ -996,7 +1016,7 @@ do_sendtargets(discovery_rec_t *drec, struct list_head *ifaces,
}
if (list_empty(ifaces))
- return ENODEV;
+ return ISCSI_ERR_NO_OBJS_FOUND;
sw_st:
return do_software_sendtargets(drec, ifaces, info_level, do_login,
@@ -1081,7 +1101,7 @@ static int exec_iface_op(int op, int do_show, int info_level,
rec = idbm_create_rec(NULL, -1, NULL, -1, iface, 0);
if (rec && iscsi_check_for_running_session(rec)) {
- rc = EBUSY;
+ rc = ISCSI_ERR_SESS_EXISTS;
goto new_fail;
}
@@ -1098,18 +1118,18 @@ new_fail:
if (!iface) {
log_error("Could not delete interface. No interface "
"passed in.");
- return EINVAL;
+ return ISCSI_ERR_INVAL;
}
rec = idbm_create_rec(NULL, -1, NULL, -1, iface, 1);
if (!rec) {
- rc = EINVAL;
+ rc = ISCSI_ERR_INVAL;
goto delete_fail;
}
/* logout and delete records using it first */
- rc = __for_each_rec(0, rec, NULL, delete_node);
- if (rc && rc != ENODEV)
+ rc = __for_each_matched_rec(0, rec, NULL, delete_node);
+ if (rc && rc != ISCSI_ERR_NO_OBJS_FOUND)
goto delete_fail;
rc = iface_conf_delete(iface);
@@ -1119,20 +1139,19 @@ new_fail:
printf("%s unbound and deleted.\n", iface->name);
break;
delete_fail:
- log_error("Could not delete iface %s. A session is "
- "is using it or it could not be found.",
- iface->name);
+ log_error("Could not delete iface %s: %s", iface->name,
+ iscsi_err_to_str(rc));
break;
case OP_UPDATE:
if (!iface || !name || !value) {
log_error("Update requires name, value, and iface.");
- rc = EINVAL;
+ rc = ISCSI_ERR_INVAL;
break;
}
rec = idbm_create_rec(NULL, -1, NULL, -1, iface, 1);
if (!rec) {
- rc = EINVAL;
+ rc = ISCSI_ERR_INVAL;
goto update_fail;
}
@@ -1146,7 +1165,7 @@ delete_fail:
log_error("Can not update "
"iface.iscsi_ifacename. Delete it, "
"and then create a new one.");
- rc = EINVAL;
+ rc = ISCSI_ERR_INVAL;
break;
}
@@ -1156,7 +1175,7 @@ delete_fail:
"from hwaddress to net_ifacename. ");
log_error("You must delete the interface and "
"create a new one");
- rc = EINVAL;
+ rc = ISCSI_ERR_INVAL;
break;
}
@@ -1166,7 +1185,7 @@ delete_fail:
"from net_ifacename to hwaddress. ");
log_error("You must delete the interface and "
"create a new one");
- rc = EINVAL;
+ rc = ISCSI_ERR_INVAL;
break;
}
set_param.name = name;
@@ -1177,8 +1196,9 @@ delete_fail:
if (rc)
goto update_fail;
- rc = __for_each_rec(0, rec, &set_param, idbm_node_set_param);
- if (rc == ENODEV)
+ rc = __for_each_matched_rec(0, rec, &set_param,
+ idbm_node_set_param);
+ if (rc == ISCSI_ERR_NO_OBJS_FOUND)
rc = 0;
else if (rc)
goto update_fail;
@@ -1186,16 +1206,15 @@ delete_fail:
printf("%s updated.\n", iface->name);
break;
update_fail:
- log_error("Could not update iface %s. A session is "
- "is using it or it could not be found.",
- iface->name);
+ log_error("Could not update iface %s: %s",
+ iface->name, iscsi_err_to_str(rc));
break;
default:
if (!iface || (iface && info_level > 0)) {
if (op == OP_NOOP || op == OP_SHOW)
rc = print_ifaces(iface, info_level);
else
- rc = EINVAL;
+ rc = ISCSI_ERR_INVAL;
} else {
rc = iface_conf_read(iface);
if (!rc)
@@ -1226,33 +1245,29 @@ static int exec_node_op(int op, int do_login, int do_logout,
rec->name, rec->conn[0].address, rec->conn[0].port);
if (op == OP_NEW) {
- if (add_static_recs(rec))
- rc = -1;
+ rc = add_static_recs(rec);
goto out;
}
if (do_rescan) {
- if (for_each_session(rec, rescan_portal))
- rc = -1;
+ rc = for_each_session(rec, rescan_portal);
goto out;
}
if (do_stats) {
- if (for_each_session(rec, session_stats))
- rc = -1;
+ rc = for_each_session(rec, session_stats);
goto out;
}
if (do_login && do_logout) {
- log_error("either login or logout at the time allowed!");
- rc = -1;
+ log_error("Invalid parameters. Both login and logout passed in");
+ rc = ISCSI_ERR_INVAL;
goto out;
}
if ((do_login || do_logout) && op > OP_NOOP) {
- log_error("either operation or login/logout "
- "at the time allowed!");
- rc = -1;
+ log_error("Invalid parameters. Login/logout and op passed in");
+ rc = ISCSI_ERR_INVAL;
goto out;
}
@@ -1264,30 +1279,29 @@ static int exec_node_op(int op, int do_login, int do_logout,
}
if (do_login) {
- if (login_portals(rec))
- rc = -1;
+ rc = login_portals(rec);
goto out;
}
if (do_logout) {
int nr_found;
- if (iscsi_logout_portals(rec, &nr_found, 1,
- iscsi_logout_matched_portal))
- rc = -1;
+ rc = iscsi_logout_portals(rec, &nr_found, 1,
+ iscsi_logout_matched_portal);
+ if (rc == ISCSI_ERR_NO_OBJS_FOUND)
+ log_error("No matching sessions found");
goto out;
}
if (op == OP_NOOP || (!do_login && !do_logout && op == OP_SHOW)) {
- if (for_each_rec(rec, &do_show, idbm_print_node_info))
- rc = -1;
+ rc = for_each_matched_rec(rec, &do_show, idbm_print_node_info);
goto out;
}
if (op == OP_UPDATE) {
if (!name || !value) {
log_error("update requires name and value");
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto out;
}
@@ -1296,7 +1310,7 @@ static int exec_node_op(int op, int do_login, int do_logout,
strcmp(name, "iface.transport_name")) {
log_error("Cannot modify %s. Use iface mode to update "
"this value.", name);
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto out;
}
@@ -1316,7 +1330,7 @@ static int exec_node_op(int op, int do_login, int do_logout,
"transport name while a session "
"is using it. Log out the session "
"then update record.");
- rc = -1;
+ rc = ISCSI_ERR_SESS_EXISTS;
goto out;
}
}
@@ -1324,16 +1338,14 @@ static int exec_node_op(int op, int do_login, int do_logout,
set_param.name = name;
set_param.value = value;
- if (for_each_rec(rec, &set_param, idbm_node_set_param))
- rc = -1;
+ rc = for_each_matched_rec(rec, &set_param, idbm_node_set_param);
goto out;
} else if (op == OP_DELETE) {
- if (for_each_rec(rec, NULL, delete_node))
- rc = -1;
+ rc = for_each_matched_rec(rec, NULL, delete_node);
goto out;
} else {
log_error("operation is not supported.");
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto out;
}
out:
@@ -1455,7 +1467,7 @@ static int exec_fw_op(discovery_rec_t *drec, struct list_head *ifaces,
if (!rec) {
log_error("Could not convert firmware info to "
"node record.\n");
- rc = ENOMEM;
+ rc = ISCSI_ERR_NOMEM;
break;
}
@@ -1505,9 +1517,9 @@ static void setup_drec_defaults(int type, char *ip, int port,
* and will read and add a drec, and perform discovery if needed.
*
* returns:
- * -1 - error
+ * Greater than 0 - error
* 0 - op/discovery completed
- * 1 - exec db op
+ * -1 - exec db op
*/
static int exec_discover(int disc_type, char *ip, int port,
struct list_head *ifaces, int info_level,
@@ -1518,15 +1530,16 @@ static int exec_discover(int disc_type, char *ip, int port,
if (ip == NULL) {
log_error("Please specify portal as <ipaddr>[:<ipport>]");
- return -1;
+ return ISCSI_ERR_INVAL;
}
if (op & OP_NEW && !do_discover) {
setup_drec_defaults(disc_type, ip, port, drec);
- if (idbm_add_discovery(drec)) {
+ rc = idbm_add_discovery(drec);
+ if (rc) {
log_error("Could not add new discovery record.");
- return -1;
+ return rc;
} else {
printf("New discovery record for [%s,%d] added.\n", ip,
port);
@@ -1539,7 +1552,7 @@ static int exec_discover(int disc_type, char *ip, int port,
if (!do_discover) {
log_error("Discovery record [%s,%d] not found.",
ip, port);
- return -1;
+ return rc;
}
/* Just add default rec for user */
@@ -1551,11 +1564,11 @@ static int exec_discover(int disc_type, char *ip, int port,
if (rc) {
log_error("Could not add new discovery "
"record.");
- return -1;
+ return rc;
}
}
} else if (!do_discover)
- return 1;
+ return -1;
rc = 0;
switch (disc_type) {
@@ -1575,9 +1588,7 @@ static int exec_discover(int disc_type, char *ip, int port,
break;
}
- if (rc)
- return -1;
- return 0;
+ return rc;
}
static int exec_disc2_op(int disc_type, char *ip, int port,
@@ -1599,12 +1610,12 @@ static int exec_disc2_op(int disc_type, char *ip, int port,
rc = exec_discover(disc_type, ip, port, ifaces, info_level,
do_login, do_discover, op, &drec);
- if (rc == 1)
+ if (rc < 0)
goto do_db_op;
goto done;
case DISCOVERY_TYPE_SLP:
log_error("SLP discovery is not fully implemented yet.");
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto done;
case DISCOVERY_TYPE_ISNS:
if (port < 0)
@@ -1612,29 +1623,30 @@ static int exec_disc2_op(int disc_type, char *ip, int port,
rc = exec_discover(disc_type, ip, port, ifaces, info_level,
do_login, do_discover, op, &drec);
- if (rc == 1)
+ if (rc < 0)
goto do_db_op;
goto done;
case DISCOVERY_TYPE_FW:
if (!do_discover) {
log_error("Invalid command. Possibly missing "
"--discover argument.");
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto done;
}
drec.type = DISCOVERY_TYPE_FW;
- if (exec_fw_op(&drec, ifaces, info_level, do_login, op))
- rc = -1;
+ rc = exec_fw_op(&drec, ifaces, info_level, do_login, op);
goto done;
default:
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
if (!ip) {
if (op == OP_NOOP || op == OP_SHOW) {
if (idbm_print_all_discovery(info_level))
/* successfully found some recs */
rc = 0;
+ else
+ rc = ISCSI_ERR_NO_OBJS_FOUND;
} else
log_error("Invalid operation. Operation not "
"supported.");
@@ -1652,29 +1664,27 @@ do_db_op:
if (op == OP_NOOP || op == OP_SHOW) {
if (!idbm_print_discovery_info(&drec, do_show)) {
- log_error("No records found!");
- rc = -1;
+ log_error("No records found");
+ rc = ISCSI_ERR_NO_OBJS_FOUND;
}
} else if (op == OP_DELETE) {
- if (idbm_delete_discovery(&drec)) {
+ rc = idbm_delete_discovery(&drec);
+ if (rc)
log_error("Unable to delete record!");
- rc = -1;
- }
} else if (op == OP_UPDATE) {
struct db_set_param set_param;
if (!name || !value) {
log_error("Update requires name and value.");
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto done;
}
set_param.name = name;
set_param.value = value;
- if (idbm_discovery_set_param(&set_param, &drec))
- rc = -1;
+ rc = idbm_discovery_set_param(&set_param, &drec);
} else {
log_error("Operation is not supported.");
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto done;
}
done:
@@ -1701,7 +1711,7 @@ static int exec_disc_op(int disc_type, char *ip, int port,
if (ip == NULL) {
log_error("Please specify portal as "
"<ipaddr>[:<ipport>]");
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto done;
}
@@ -1709,21 +1719,20 @@ static int exec_disc_op(int disc_type, char *ip, int port,
strlcpy(drec.address, ip, sizeof(drec.address));
drec.port = port;
- if (do_sendtargets(&drec, ifaces, info_level,
- do_login, op, 1)) {
- rc = -1;
+ rc = do_sendtargets(&drec, ifaces, info_level,
+ do_login, op, 1);
+ if (rc)
goto done;
- }
break;
case DISCOVERY_TYPE_SLP:
log_error("SLP discovery is not fully implemented yet.");
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
break;
case DISCOVERY_TYPE_ISNS:
if (!ip) {
log_error("Please specify portal as "
"<ipaddr>:[<ipport>]");
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto done;
}
@@ -1733,15 +1742,13 @@ static int exec_disc_op(int disc_type, char *ip, int port,
else
drec.port = port;
- if (do_isns(&drec, ifaces, info_level, do_login, op)) {
- rc = -1;
+ rc = do_isns(&drec, ifaces, info_level, do_login, op);
+ if (rc)
goto done;
- }
break;
case DISCOVERY_TYPE_FW:
drec.type = DISCOVERY_TYPE_FW;
- if (exec_fw_op(&drec, ifaces, info_level, do_login, op))
- rc = -1;
+ rc = exec_fw_op(&drec, ifaces, info_level, do_login, op);
break;
default:
if (ip) {
@@ -1761,42 +1768,41 @@ static int exec_disc_op(int disc_type, char *ip, int port,
ip, port)) {
log_error("Discovery record [%s,%d] "
"not found!", ip, port);
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto done;
}
if ((do_discover || do_login) &&
drec.type == DISCOVERY_TYPE_SENDTARGETS) {
- do_sendtargets(&drec, ifaces, info_level,
- do_login, op, 0);
+ rc = do_sendtargets(&drec, ifaces, info_level,
+ do_login, op, 0);
} else if (op == OP_NOOP || op == OP_SHOW) {
if (!idbm_print_discovery_info(&drec,
do_show)) {
- log_error("No records found!");
- rc = -1;
+ log_error("No records found");
+ rc = ISCSI_ERR_NO_OBJS_FOUND;
}
} else if (op == OP_DELETE) {
- if (idbm_delete_discovery(&drec)) {
+ rc = idbm_delete_discovery(&drec);
+ if (rc)
log_error("Unable to delete record!");
- rc = -1;
- }
} else if (op == OP_UPDATE || op == OP_NEW) {
log_error("Operations new and update for "
"discovery mode is not supported. "
"Use discoverydb mode.");
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto done;
} else {
log_error("Invalid operation.");
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto done;
}
} else if (op == OP_NOOP || op == OP_SHOW) {
if (!idbm_print_all_discovery(info_level))
- rc = -1;
+ rc = ISCSI_ERR_NO_OBJS_FOUND;
goto done;
} else {
log_error("Invalid operation.");
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto done;
}
/* fall through */
@@ -1849,7 +1855,7 @@ main(int argc, char **argv)
log_error("Invalid killiscsid priority %d "
"Priority must be greater than or "
"equal to zero.", killiscsid);
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto free_ifaces;
}
break;
@@ -1861,7 +1867,7 @@ main(int argc, char **argv)
if (op == OP_NOOP) {
log_error("can not recognize operation: '%s'",
optarg);
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto free_ifaces;
}
break;
@@ -1877,7 +1883,7 @@ main(int argc, char **argv)
if (errno) {
log_error("invalid host no %s. %s.",
optarg, strerror(errno));
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto free_ifaces;
}
break;
@@ -1886,7 +1892,7 @@ main(int argc, char **argv)
if (sid < 0) {
log_error("invalid sid '%s'",
optarg);
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto free_ifaces;
}
break;
@@ -1933,15 +1939,14 @@ main(int argc, char **argv)
break;
case 'I':
iface = iface_alloc(optarg, &rc);
- if (rc == EINVAL) {
+ if (rc == ISCSI_ERR_INVAL) {
printf("Invalid iface name %s. Must be from "
"1 to %d characters.\n",
optarg, ISCSI_MAX_IFACE_LEN - 1);
- rc = -1;
goto free_ifaces;
} else if (!iface || rc) {
printf("Could not add iface %s.", optarg);
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto free_ifaces;
}
@@ -1959,7 +1964,7 @@ main(int argc, char **argv)
if (optopt) {
log_error("unrecognized character '%c'", optopt);
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto free_ifaces;
}
@@ -1969,13 +1974,13 @@ main(int argc, char **argv)
}
if (mode < 0)
- usage(0);
+ usage(ISCSI_ERR_INVAL);
if (mode == MODE_FW) {
if ((rc = verify_mode_params(argc, argv, "ml", 0))) {
log_error("fw mode: option '-%c' is not "
"allowed/supported", rc);
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto free_ifaces;
}
@@ -1986,7 +1991,7 @@ main(int argc, char **argv)
increase_max_files();
if (idbm_init(get_config_file)) {
log_warning("exiting due to idbm configuration error");
- rc = -1;
+ rc = ISCSI_ERR_IDBM;
goto free_ifaces;
}
@@ -1995,7 +2000,7 @@ main(int argc, char **argv)
if ((rc = verify_mode_params(argc, argv, "HdmP", 0))) {
log_error("host mode: option '-%c' is not "
"allowed/supported", rc);
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto out;
}
@@ -2007,7 +2012,7 @@ main(int argc, char **argv)
if ((rc = verify_mode_params(argc, argv, "IdnvmPo", 0))) {
log_error("iface mode: option '-%c' is not "
"allowed/supported", rc);
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto out;
}
@@ -2026,7 +2031,7 @@ main(int argc, char **argv)
if ((rc = verify_mode_params(argc, argv, "DSIPdmntplov", 0))) {
log_error("discovery mode: option '-%c' is not "
"allowed/supported", rc);
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto out;
}
@@ -2038,7 +2043,7 @@ main(int argc, char **argv)
if ((rc = verify_mode_params(argc, argv, "DSIPdmntplov", 0))) {
log_error("discovery mode: option '-%c' is not "
"allowed/supported", rc);
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto out;
}
@@ -2051,7 +2056,7 @@ main(int argc, char **argv)
0))) {
log_error("node mode: option '-%c' is not "
"allowed/supported", rc);
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto out;
}
@@ -2081,7 +2086,7 @@ main(int argc, char **argv)
rec = idbm_create_rec(targetname, tpgt, ip, port, iface, 1);
if (!rec) {
- rc = -1;
+ rc = ISCSI_ERR_NOMEM;
goto out;
}
@@ -2094,7 +2099,7 @@ main(int argc, char **argv)
"PiRdrmusonuSv", 1))) {
log_error("session mode: option '-%c' is not "
"allowed or supported", rc);
- rc = -1;
+ rc = ISCSI_ERR_INVAL;
goto out;
}
if (sid >= 0) {
@@ -2106,7 +2111,7 @@ main(int argc, char **argv)
info = calloc(1, sizeof(*info));
if (!info) {
- rc = ENOMEM;
+ rc = ISCSI_ERR_NOMEM;
goto out;
}
@@ -2128,8 +2133,6 @@ 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);
- if (rc)
- rc = -1;
goto free_info;
}
@@ -2139,7 +2142,7 @@ main(int argc, char **argv)
info->persistent_port,
&info->iface, 1);
if (!rec) {
- rc = -1;
+ rc = ISCSI_ERR_NOMEM;
goto free_info;
}
diff --git a/usr/iscsid.c b/usr/iscsid.c
index cae7e28..a60d6fa 100644
--- a/usr/iscsid.c
+++ b/usr/iscsid.c
@@ -95,7 +95,7 @@ Open-iSCSI initiator daemon.\n\
-v, --version display version and exit\n\
");
}
- exit(status == 0 ? 0 : -1);
+ exit(status);
}
static void
@@ -211,7 +211,8 @@ static int sync_session(void *data, struct session_info *info)
host_no = iscsi_sysfs_get_host_no_from_sid(info->sid, &err);
if (err) {
log_error("Could not get host no from sid %u. Can not "
- "sync session. Error %d", info->sid, err);
+ "sync session: %s", info->sid,
+ iscsi_err_to_str(err));
return 0;
}
iscsi_sysfs_scan_host(host_no, 0);
@@ -387,17 +388,17 @@ int main(int argc, char *argv[])
log_pid = log_init(program_name, DEFAULT_AREA_SIZE,
daemonize ? log_do_log_daemon : log_do_log_std, NULL);
if (log_pid < 0)
- exit(1);
+ exit(ISCSI_ERR);
sysfs_init();
if (idbm_init(iscsid_get_config_file)) {
log_close(log_pid);
- exit(1);
+ exit(ISCSI_ERR);
}
if (iscsi_sysfs_check_class_version()) {
log_close(log_pid);
- exit(1);
+ exit(ISCSI_ERR);
}
umask(0177);
@@ -409,7 +410,7 @@ int main(int argc, char *argv[])
if ((mgmt_ipc_fd = mgmt_ipc_listen()) < 0) {
log_close(log_pid);
- exit(1);
+ exit(ISCSI_ERR);
}
if (daemonize) {
@@ -420,13 +421,13 @@ int main(int argc, char *argv[])
if (fd < 0) {
log_error("Unable to create pid file");
log_close(log_pid);
- exit(1);
+ exit(ISCSI_ERR);
}
pid = fork();
if (pid < 0) {
log_error("Starting daemon failed");
log_close(log_pid);
- exit(1);
+ exit(ISCSI_ERR);
} else if (pid) {
log_error("iSCSI daemon with pid=%d started!", pid);
exit(0);
@@ -434,14 +435,14 @@ int main(int argc, char *argv[])
if ((control_fd = ipc->ctldev_open()) < 0) {
log_close(log_pid);
- exit(1);
+ exit(ISCSI_ERR);
}
chdir("/");
if (lockf(fd, F_TLOCK, 0) < 0) {
log_error("Unable to lock pid file");
log_close(log_pid);
- exit(1);
+ exit(ISCSI_ERR);
}
ftruncate(fd, 0);
sprintf(buf, "%d\n", getpid());
@@ -509,7 +510,7 @@ int main(int argc, char *argv[])
if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
log_error("failed to mlockall, exiting...");
log_close(log_pid);
- exit(1);
+ exit(ISCSI_ERR);
}
actor_init();
diff --git a/usr/iscsid_req.c b/usr/iscsid_req.c
index 657cd55..a49b667 100644
--- a/usr/iscsid_req.c
+++ b/usr/iscsid_req.c
@@ -190,31 +190,3 @@ int iscsid_req_by_sid(iscsiadm_cmd_e cmd, int sid)
return err;
return iscsid_req_wait(cmd, fd);
}
-
-void iscsid_handle_error(int err)
-{
- static char *err_msgs[] = {
- /* 0 */ "",
- /* 1 */ "unknown error",
- /* 2 */ "not found",
- /* 3 */ "no available memory",
- /* 4 */ "encountered connection failure",
- /* 5 */ "encountered iSCSI login failure",
- /* 6 */ "encountered iSCSI database failure",
- /* 7 */ "invalid parameter",
- /* 8 */ "connection timed out",
- /* 9 */ "internal error",
- /* 10 */ "encountered iSCSI logout failure",
- /* 11 */ "iSCSI PDU timed out",
- /* 12 */ "iSCSI driver not found. Please make sure it is loaded, and retry the operation",
- /* 13 */ "daemon access denied",
- /* 14 */ "iSCSI driver does not support requested capability.",
- /* 15 */ "already exists",
- /* 16 */ "Unknown request",
- /* 17 */ "encountered iSNS failure",
- /* 18 */ "could not communicate to iscsid",
- /* 19 */ "encountered non-retryable iSCSI login failure",
- /* 20 */ "could not connect to iscsid",
- };
- log_error("initiator reported error (%d - %s)", err, err_msgs[err]);
-}
diff --git a/usr/iscsid_req.h b/usr/iscsid_req.h
index 3bba2f4..68f5256 100644
--- a/usr/iscsid_req.h
+++ b/usr/iscsid_req.h
@@ -27,7 +27,6 @@ struct node_rec;
extern int iscsid_exec_req(struct iscsiadm_req *req, struct iscsiadm_rsp *rsp,
int iscsid_start);
-extern void iscsid_handle_error(int err);
extern int iscsid_req_wait(int cmd, int fd);
extern int iscsid_req_by_rec_async(int cmd, struct node_rec *rec, int *fd);
extern int iscsid_req_by_rec(int cmd, struct node_rec *rec);
diff --git a/usr/iscsistart.c b/usr/iscsistart.c
index a6752e9..6046ac6 100644
--- a/usr/iscsistart.c
+++ b/usr/iscsistart.c
@@ -107,7 +107,7 @@ Open-iSCSI initiator.\n\
-v, --version display version and exit\n\
");
}
- exit(status == 0 ? 0 : -1);
+ exit(status);
}
static int stop_event_loop(void)
@@ -120,7 +120,7 @@ static int stop_event_loop(void)
req.command = MGMT_IPC_IMMEDIATE_STOP;
rc = iscsid_exec_req(&req, &rsp, 0);
if (rc) {
- iscsid_handle_error(rc);
+ iscsi_err_print_msg(rc);
log_error("Could not stop event_loop\n");
}
return rc;
@@ -159,7 +159,7 @@ retry:
sleep(1);
goto retry;
} else if (rc)
- iscsid_handle_error(rc);
+ iscsi_err_print_msg(rc);
return rc;
}
@@ -228,7 +228,7 @@ do { \
if (strlen(str) > max_len) { \
printf("%s: invalid %s %s. Max %s length is %d.\n", \
program_name, param, str, param, max_len); \
- exit(1); \
+ exit(ISCSI_ERR_INVAL); \
} \
} while (0);
@@ -260,7 +260,7 @@ int main(int argc, char *argv[])
sysfs_init();
if (iscsi_sysfs_check_class_version())
- exit(1);
+ exit(ISCSI_ERR_SYSFS_LOOKUP);
while ((ch = getopt_long(argc, argv, "i:t:g:a:p:d:u:w:U:W:bNfvh",
long_options, &longindex)) >= 0) {
@@ -316,25 +316,24 @@ int main(int argc, char *argv[])
ret = fw_get_entry(&boot_context);
if (ret) {
printf("Could not get boot entry.\n");
- exit(1);
+ exit(ret);
}
initiatorname = boot_context.initiatorname;
ret = fw_get_targets(&targets);
if (ret || list_empty(&targets)) {
printf("Could not setup fw entries.\n");
- exit(1);
+ exit(ret);
}
break;
case 'N':
- ret = fw_setup_nics();
- exit(ret);
+ exit(fw_setup_nics());
case 'f':
ret = fw_get_targets(&targets);
if (ret || list_empty(&targets)) {
printf("Could not get list of targets from "
"firmware.\n");
- exit(1);
+ exit(ret);
}
list_for_each_entry(context, &targets, list)
@@ -350,18 +349,18 @@ int main(int argc, char *argv[])
usage(0);
break;
default:
- usage(1);
+ usage(ISCSI_ERR_INVAL);
break;
}
}
if (list_empty(&targets) && check_params(initiatorname))
- exit(1);
+ exit(ISCSI_ERR_INVAL);
pid = fork();
if (pid < 0) {
log_error("iscsiboot fork failed");
- exit(1);
+ exit(ISCSI_ERR_NOMEM);
} else if (pid) {
int status, rc, rc2;
@@ -376,7 +375,7 @@ int main(int argc, char *argv[])
waitpid(pid, &status, WUNTRACED);
if (rc || rc2)
- exit(-1);
+ exit(ISCSI_ERR);
log_debug(1, "iscsi parent done");
exit(0);
@@ -385,12 +384,12 @@ int main(int argc, char *argv[])
mgmt_ipc_fd = mgmt_ipc_listen();
if (mgmt_ipc_fd < 0) {
log_error("Could not setup mgmt ipc\n");
- exit(-1);
+ exit(ISCSI_ERR_NOMEM);
}
control_fd = ipc->ctldev_open();
if (control_fd < 0)
- exit(-1);
+ exit(ISCSI_ERR_NOMEM);
memset(&daemon_config, 0, sizeof (daemon_config));
daemon_config.initiator_name = initiatorname;
diff --git a/usr/session_info.c b/usr/session_info.c
index cecd8e8..cded5e3 100644
--- a/usr/session_info.c
+++ b/usr/session_info.c
@@ -13,6 +13,7 @@
#include "initiator.h"
#include "iface.h"
#include "iscsid_req.h"
+#include "iscsi_err.h"
int session_info_create_list(void *data, struct session_info *info)
{
@@ -25,7 +26,7 @@ int session_info_create_list(void *data, struct session_info *info)
new = calloc(1, sizeof(*new));
if (!new)
- return ENOMEM;
+ return ISCSI_ERR_NOMEM;
memcpy(new, info, sizeof(*new));
INIT_LIST_HEAD(&new->list);
@@ -346,13 +347,15 @@ int session_info_print(int info_level, struct session_info *info)
break;
default:
log_error("Invalid info level %d. Try 0 - 3.", info_level);
- return EINVAL;
+ return ISCSI_ERR_INVAL;
}
if (err) {
log_error("Can not get list of active sessions (%d)", err);
return err;
- } else if (!num_found)
+ } else if (!num_found) {
log_error("No active sessions.");
+ return ISCSI_ERR_NO_OBJS_FOUND;
+ }
return 0;
}
diff --git a/usr/session_mgmt.c b/usr/session_mgmt.c
index d7c4579..0bfa205 100644
--- a/usr/session_mgmt.c
+++ b/usr/session_mgmt.c
@@ -41,7 +41,7 @@ static void log_login_msg(struct node_rec *rec, int rc)
"portal: %s,%d].", rec->iface.name,
rec->name, rec->conn[0].address,
rec->conn[0].port);
- iscsid_handle_error(rc);
+ iscsi_err_print_msg(rc);
} else
log_info("Login to [iface: %s, target: %s, portal: "
"%s,%d] successful.", rec->iface.name,
@@ -83,6 +83,8 @@ static int iscsid_login_reqs_wait(struct list_head *list)
rec = curr->data;
err = iscsid_req_wait(MGMT_IPC_SESSION_LOGIN, curr->fd);
+ if (err && !ret)
+ ret = err;
log_login_msg(rec, err);
list_del(&curr->list);
free(curr);
@@ -124,11 +126,7 @@ int iscsi_login_portal(void *data, struct list_head *list, struct node_rec *rec)
log_login_msg(rec, rc);
if (async_req)
free(async_req);
- /* we raced with another app or instance of iscsiadm */
- if (rc == ISCSI_ERR_SESS_EXISTS)
- return 0;
-
- return ENOTCONN;
+ return rc;
}
if (async_req) {
@@ -192,7 +190,6 @@ int iscsi_login_portals(void *data, int *nr_found, int wait,
if (!err)
(*nr_found)++;
}
-
if (wait) {
err = iscsid_login_reqs_wait(&login_list);
if (err && !ret)
@@ -214,7 +211,7 @@ static void log_logout_msg(struct session_info *info, int rc)
"portal: %s,%d].", info->sid,
info->targetname,
info->persistent_address, info->port);
- iscsid_handle_error(rc);
+ iscsi_err_print_msg(rc);
} else
log_info("Logout of [sid: %d, target: %s, "
"portal: %s,%d] successful.",
@@ -278,11 +275,7 @@ int iscsi_logout_portal(struct session_info *info, struct list_head *list)
log_logout_msg(info, rc);
if (async_req)
free(async_req);
-
- if (rc == ISCSI_ERR_SESS_NOT_FOUND)
- return 0;
-
- return EIO;
+ return rc;
}
if (async_req) {
@@ -326,10 +319,17 @@ int iscsi_logout_portals(void *data, int *nr_found, int wait,
err = iscsi_sysfs_for_each_session(&link_info, nr_found,
session_info_create_list);
- if (err || !*nr_found)
+ if (err && !list_empty(&session_list))
+ log_error("Could not read in all sessions: %s",
+ iscsi_err_to_str(err));
+ else if (err && list_empty(&session_list)) {
+ log_error("Could not read session info.");
return err;
-
+ } else if (list_empty(&session_list))
+ return ISCSI_ERR_NO_OBJS_FOUND;
+ ret = err;
*nr_found = 0;
+
list_for_each_entry(curr_info, &session_list, list) {
err = logout_fn(data, &logout_list, curr_info);
if (err > 0 && !ret)
@@ -338,13 +338,22 @@ int iscsi_logout_portals(void *data, int *nr_found, int wait,
(*nr_found)++;
}
+ if (!*nr_found) {
+ ret = ISCSI_ERR_NO_OBJS_FOUND;
+ goto free_list;
+ }
+
if (wait) {
err = iscsid_logout_reqs_wait(&logout_list);
- if (err)
+ if (err && !ret)
ret = err;
} else
iscsid_reqs_close(&logout_list);
+ if (ret)
+ log_error("Could not logout of all requested sessions");
+
+free_list:
session_info_free_list(&session_list);
return ret;
}
diff --git a/utils/fwparam_ibft/fw_entry.c b/utils/fwparam_ibft/fw_entry.c
index bbdb6d2..9010339 100644
--- a/utils/fwparam_ibft/fw_entry.c
+++ b/utils/fwparam_ibft/fw_entry.c
@@ -34,6 +34,7 @@
#include "fwparam.h"
#include "idbm_fields.h"
#include "iscsi_net_util.h"
+#include "iscsi_err.h"
/**
* fw_setup_nics - setup nics (ethXs) based on ibft net info
@@ -56,7 +57,7 @@ int fw_setup_nics(void)
ret = fw_get_targets(&targets);
if (ret || list_empty(&targets)) {
printf("Could not setup fw entries.\n");
- return ENODEV;
+ return ISCSI_ERR_NO_OBJS_FOUND;
}
/*
@@ -85,7 +86,10 @@ int fw_setup_nics(void)
}
fw_free_targets(&targets);
- return ret;
+ if (ret)
+ return ISCSI_ERR;
+ else
+ return 0;
}
/**
diff --git a/utils/fwparam_ibft/fwparam_ppc.c b/utils/fwparam_ibft/fwparam_ppc.c
index 7dc337a..391faa2 100644
--- a/utils/fwparam_ibft/fwparam_ppc.c
+++ b/utils/fwparam_ibft/fwparam_ppc.c
@@ -30,6 +30,7 @@
#include "iscsi_obp.h"
#include "prom_parse.h"
#include "sysdeps.h"
+#include "iscsi_err.h"
void* yy_scan_string(const char *str);
int yyparse(struct ofw_dev *ofwdev);
@@ -449,7 +450,7 @@ int fwparam_ppc_boot_info(struct boot_context *context)
devtree = find_devtree(filename);
if (!devtree)
- return EINVAL;
+ return ISCSI_ERR_INVAL;
/*
* Always search the device-tree to find the capable nic devices.
@@ -459,7 +460,7 @@ int fwparam_ppc_boot_info(struct boot_context *context)
goto free_devtree;
if (find_file(filename) < 1)
- error = ENODEV;
+ error = ISCSI_ERR_NO_OBJS_FOUND;
else {
if (debug)
printf("%s:\n%s\n\n", filename, bootpath_val);
@@ -469,12 +470,12 @@ int fwparam_ppc_boot_info(struct boot_context *context)
*/
if (!strstr(bootpath_val, "iscsi")) {
- error = EINVAL;
+ error = ISCSI_ERR_INVAL;
goto free_devtree;
}
ofwdevs[0] = calloc(1, sizeof(struct ofw_dev));
if (!ofwdevs[0]) {
- error = ENOMEM;
+ error = ISCSI_ERR_NOMEM;
goto free_devtree;
}
@@ -484,7 +485,7 @@ int fwparam_ppc_boot_info(struct boot_context *context)
if (!error) {
context = calloc(1, sizeof(*context));
if (!context)
- error = ENOMEM;
+ error = ISCSI_ERR_NOMEM;
else
fill_context(context, ofwdevs[0]);
}
@@ -524,7 +525,7 @@ int fwparam_ppc_get_targets(struct list_head *list)
devtree = find_devtree(filename);
if (!devtree)
- return EINVAL;
+ return ISCSI_ERR_INVAL;
/*
* Always search the device-tree to find the capable nic devices.
@@ -534,7 +535,7 @@ int fwparam_ppc_get_targets(struct list_head *list)
goto free_devtree;
if (find_file(filename) < 1)
- error = ENODEV;
+ error = ISCSI_ERR_NO_OBJS_FOUND;
else {
if (debug)
printf("%s:\n%s\n\n", filename, bootpath_val);
@@ -544,12 +545,12 @@ int fwparam_ppc_get_targets(struct list_head *list)
*/
if (!strstr(bootpath_val, "iscsi")) {
- error = EINVAL;
+ error = ISCSI_ERR_INVAL;
goto free_devtree;
}
ofwdevs[0] = calloc(1, sizeof(struct ofw_dev));
if (!ofwdevs[0]) {
- error = ENOMEM;
+ error = ISCSI_ERR_NOMEM;
goto free_devtree;
}
@@ -559,7 +560,7 @@ int fwparam_ppc_get_targets(struct list_head *list)
if (!error) {
context = calloc(1, sizeof(*context));
if (!context)
- error = ENOMEM;
+ error = ISCSI_ERR_NOMEM;
else {
fill_context(context, ofwdevs[0]);
list_add_tail(&context->list, list);
diff --git a/utils/fwparam_ibft/fwparam_sysfs.c b/utils/fwparam_ibft/fwparam_sysfs.c
index 35a6309..b5568c5 100644
--- a/utils/fwparam_ibft/fwparam_sysfs.c
+++ b/utils/fwparam_ibft/fwparam_sysfs.c
@@ -36,6 +36,7 @@
#include "fwparam.h"
#include "sysdeps.h"
#include "iscsi_net_util.h"
+#include "iscsi_err.h"
#define ISCSI_BOOT_MAX 255
#define IBFT_SYSFS_ROOT "/sys/firmware/ibft/"
@@ -351,7 +352,7 @@ int fwparam_sysfs_boot_info(struct boot_context *context)
*/
dirfd = opendir(ISCSI_LLD_ROOT);
if (!dirfd)
- return errno;
+ return ISCSI_ERR_SYSFS_LOOKUP;
while ((dent = readdir(dirfd))) {
char lld_root[FILENAMESZ];
@@ -369,7 +370,7 @@ int fwparam_sysfs_boot_info(struct boot_context *context)
if (!get_boot_info(context, lld_root, dent->d_name))
goto done;
}
- rc = ENODEV;
+ rc = ISCSI_ERR_NO_OBJS_FOUND;
done:
closedir(dirfd);
return rc;
@@ -465,7 +466,7 @@ int fwparam_sysfs_get_targets(struct list_head *list)
*/
dirfd = opendir(ISCSI_LLD_ROOT);
if (!dirfd) {
- rc = errno;
+ rc = ISCSI_ERR_SYSFS_LOOKUP;
goto done;
}
@@ -486,7 +487,7 @@ int fwparam_sysfs_get_targets(struct list_head *list)
closedir(dirfd);
done:
if (!rc && list_empty(list))
- rc = ENODEV;
+ rc = ISCSI_ERR_NO_OBJS_FOUND;
if (rc)
fw_free_targets(list);
return rc;