Skip to content

Commit

Permalink
iscsi tools: fix iscsiadm exit codes
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Mike Christie committed Feb 1, 2011
1 parent 39d4ceb commit 2c839a2
Show file tree
Hide file tree
Showing 23 changed files with 680 additions and 451 deletions.
130 changes: 130 additions & 0 deletions doc/iscsiadm.8
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions etc/initd/initd.suse
Expand Up @@ -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
Expand All @@ -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
Expand Down
16 changes: 14 additions & 2 deletions usr/iscsi_err.h → include/iscsi_err.h
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
2 changes: 1 addition & 1 deletion usr/Makefile
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion usr/discovery.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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;
}

Expand Down
10 changes: 7 additions & 3 deletions usr/host.c
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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;
}

0 comments on commit 2c839a2

Please sign in to comment.