On 09/08/2011 07:23 AM, Ankit Jain wrote:
> On Thu, Sep 8, 2011 at 2:26 PM, Aastha Mehta <aasth...@gmail.com> wrote:
>> Sorry, please ignore the previous patch. There was some minor error in that.
>> Re-attaching the patch here.
> 
> +#include<stdio.h>
> +#include<stdlib.h>
> +#include<string.h>
> +#include "iscsi_if.h"
> +#include"kern_error_table.h"
> +#define NUM_ERRORS 22
> 
> You can probably clean up the includes, and the #define.
> 
> +       log_warning("error %d: %s ", error, err_desc);
> Maybe do:
>        log_warning("error %d: %s ", error, err_code_to_string(error);
> 
> +       switch(code % ISCSI_ERR_BASE){
> +               case 0:  return "ISCSI_OK: operation successful";
> +               case 1:  return "ISCSI_ERR_DATASN: Received invalid
> data sequence
> number from target";
> 
> Since you are returning the error strings here directly, you don't need
> "code % ISCSI_ERR_BASE" and can use ISCSI_ERR_* enum values
> in the case statements directly. That would be clearer than using just
> numbers.
> 
> +               default: return "Invalid error code. Is there a new error code
> added which is not handled?";
> 
> "Invalid" or "Unknown" ? This is probably nitpicking :/
> 

I think these are all good suggestions. Thanks for the review. I merged
them into the almost final patch attached.

Aastha, is ok to add the GPL2 headers on the files you are adding like
is done in the other files? Many distros requires that all files have
some sort of header like that.

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-iscsi@googlegroups.com.
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.

>From aef7832ce520634d1f68564fc0e1fd45df4c8c30 Mon Sep 17 00:00:00 2001
From: Mike Christie <mchri...@redhat.com>
Date: Mon, 3 Oct 2011 20:11:49 -0500
Subject: [PATCH] iscsid: print more descriptive error value for iscsi kernel 
errors

---
 usr/Makefile         |    2 +-
 usr/initiator.c      |    6 +++-
 usr/kern_err_table.c |   65 ++++++++++++++++++++++++++++++++++++++++++++++++++
 usr/kern_err_table.h |    5 ++++
 4 files changed, 75 insertions(+), 3 deletions(-)
 create mode 100644 usr/kern_err_table.c
 create mode 100644 usr/kern_err_table.h

diff --git a/usr/Makefile b/usr/Makefile
index 3ee0cb4..bc7af2c 100644
--- a/usr/Makefile
+++ b/usr/Makefile
@@ -44,7 +44,7 @@ ISCSI_LIB_SRCS = iscsi_util.o io.o auth.o iscsi_timer.o 
login.o log.o md5.o \
        iscsi_net_util.o iscsid_req.o transport.o cxgbi.o be2iscsi.o \
        initiator_common.o iscsi_err.o $(IPC_OBJ)  $(SYSDEPS_SRCS) $(DCB_OBJ)
 # core initiator files
-INITIATOR_SRCS = initiator.o scsi.o actor.o event_poll.o mgmt_ipc.o
+INITIATOR_SRCS = initiator.o scsi.o actor.o event_poll.o mgmt_ipc.o 
kern_err_table.o
 
 # fw boot files
 FW_BOOT_SRCS = $(wildcard ../utils/fwparam_ibft/*.o)
diff --git a/usr/initiator.c b/usr/initiator.c
index 6c06318..663c3ee 100644
--- a/usr/initiator.c
+++ b/usr/initiator.c
@@ -47,6 +47,7 @@
 #include "iface.h"
 #include "sysdeps.h"
 #include "iscsi_err.h"
+#include "kern_err_table.h"
 
 #define ISCSI_CONN_ERR_REOPEN_DELAY    3
 #define ISCSI_INTERNAL_ERR_REOPEN_DELAY        5
@@ -847,9 +848,10 @@ static void session_conn_error(void *data)
        iscsi_conn_t *conn = ev_context->conn;
        iscsi_session_t *session = conn->session;
 
-       log_warning("Kernel reported iSCSI connection %d:%d error (%d) "
+       log_warning("Kernel reported iSCSI connection %d:%d error (%d - %s) "
                    "state (%d)", session->id, conn->id, error,
-                   conn->state);
+                   kern_err_code_to_string(error), conn->state);
+
        iscsi_ev_context_put(ev_context);
 
        switch (error) {
diff --git a/usr/kern_err_table.c b/usr/kern_err_table.c
new file mode 100644
index 0000000..ddb3c84
--- /dev/null
+++ b/usr/kern_err_table.c
@@ -0,0 +1,65 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include "iscsi_if.h"
+
+#include "kern_err_table.h"
+
+const char *kern_err_code_to_string(int err)
+{
+       switch (err){
+       case ISCSI_OK:
+               return "ISCSI_OK: operation successful";
+       case ISCSI_ERR_DATASN:
+               return "ISCSI_ERR_DATASN: Received invalid data sequence "
+                       "number from target";
+       case ISCSI_ERR_DATA_OFFSET:
+               return "ISCSI_ERR_DATA_OFFSET: Seeking offset beyond the size "
+                       "of the iSCSI segment";
+       case ISCSI_ERR_MAX_CMDSN:
+               return "ISCSI_ERR_MAX_CMDSN: Received invalid command sequence "
+                       "number from target";
+       case ISCSI_ERR_EXP_CMDSN:
+               return "ISCSI_ERR_EXP_CMDSN: Received invalid expected command 
"                        "sequence number from target";
+       case ISCSI_ERR_BAD_OPCODE:
+               return "ISCSI_ERR_BAD_OPCODE: Received an invalid iSCSI opcode";
+       case ISCSI_ERR_DATALEN:
+               return "ISCSI_ERR_DATALEN: Invalid data length value";
+       case ISCSI_ERR_AHSLEN:
+               return "ISCSI_ERR_AHSLEN: Received an invalid AHS length";
+       case ISCSI_ERR_PROTO:
+               return "ISCSI_ERR_PROTO: iSCSI protocol violation";
+       case ISCSI_ERR_LUN:
+               return "ISCSI_ERR_LUN: LUN mismatch";
+       case ISCSI_ERR_BAD_ITT:
+               return "ISCSI_ERR_BAD_ITT: Received invalid initiator task tag 
"                        "from target";
+       case ISCSI_ERR_CONN_FAILED:
+               return "ISCSI_ERR_CONN_FAILED: iSCSI connection failed";
+       case ISCSI_ERR_R2TSN:
+               return "ISCSI_ERR_R2TSN: Received invalid R2T (Ready to "
+                       "Transfer) data sequence number from target";
+       case ISCSI_ERR_SESSION_FAILED:
+               return "ISCSI_ERR_SESSION_FAILED: iSCSI session failed";
+       case ISCSI_ERR_HDR_DGST:
+               return "ISCSI_ERR_HDR_DGST: Header digest mismatch";
+       case ISCSI_ERR_DATA_DGST:
+               return "ISCSI_ERR_DATA_DGST: Data digest mismatch";
+       case ISCSI_ERR_PARAM_NOT_FOUND:
+               return "ISCSI_ERR_PARAM_NOT_FOUND: Parameter not found";
+       case ISCSI_ERR_NO_SCSI_CMD:
+               return "ISCSI_ERR_NO_SCSI_CMD: Could not look up SCSI command";
+       case ISCSI_ERR_INVALID_HOST:
+               return "ISCSI_ERR_INVALID_HOST: iSCSI host is in an invalid "
+                       "state";
+       case ISCSI_ERR_XMIT_FAILED:
+               return "ISCSI_ERR_XMIT_FAILED: Transmission of iSCSI packet "
+                       "failed";
+       case ISCSI_ERR_TCP_CONN_CLOSE:
+               return "ISCSI_ERR_TCP_CONN_CLOSE: TCP connection closed";
+       case ISCSI_ERR_SCSI_EH_SESSION_RST:
+               return "ISCSI_ERR_SCSI_EH_SESSION_RST: Session was dropped as "
+                       "a result of SCSI error recovery";
+       default:
+               return "Invalid or unknown error code";
+       }
+}
diff --git a/usr/kern_err_table.h b/usr/kern_err_table.h
new file mode 100644
index 0000000..08914fe
--- /dev/null
+++ b/usr/kern_err_table.h
@@ -0,0 +1,5 @@
+#ifndef __KERN_ERR_TABLE_H__
+#define __KERN_ERR_TABLE_H__
+
+extern const char *kern_err_code_to_string(int);
+#endif
-- 
1.7.2.3

Reply via email to