Browse Source

[iSCSI] Produce meaningful errors on login failure

Return the most appropriate of EACCES, EPERM, ENODEV, ENOTSUP, EIO or
EINVAL depending on the exact error returned by the target, rather than
just always returning EPERM.

Also, ensure that error strings exist for these errors.
tags/v0.9.4
Michael Brown 16 years ago
parent
commit
75965c9c6e
3 changed files with 52 additions and 14 deletions
  1. 10
    7
      src/hci/strerror.c
  2. 8
    4
      src/include/gpxe/iscsi.h
  3. 34
    3
      src/net/tcp/iscsi.c

+ 10
- 7
src/hci/strerror.c View File

@@ -108,15 +108,18 @@ const char * strerror ( int errno ) {
108 108
 /** The most common errors */
109 109
 struct errortab common_errors[] __errortab = {
110 110
 	{ 0, "No error" },
111
-	{ ENOMEM, "Out of memory" },
111
+	{ EACCES, "Permission denied" },
112
+	{ ECANCELED, "Operation cancelled" },
113
+	{ ECONNRESET, "Connection reset" },
112 114
 	{ EINVAL, "Invalid argument" },
113
-	{ ENOSPC, "No space left on device" },
114 115
 	{ EIO, "Input/output error" },
115
-	{ EACCES, "Permission denied" },
116
-	{ ENOENT, "File not found" },
117 116
 	{ ENETUNREACH, "Network unreachable" },
118
-	{ ETIMEDOUT, "Connection timed out" },
119
-	{ EPIPE, "Broken pipe" },
120
-	{ ECANCELED, "Operation cancelled" },
117
+	{ ENODEV, "No such device" },
118
+	{ ENOENT, "File not found" },
121 119
 	{ ENOEXEC, "Not an executable image" },
120
+	{ ENOMEM, "Out of memory" },
121
+	{ ENOSPC, "No space left on device" },
122
+	{ ENOTSUP, "Not supported" },
123
+	{ EPERM, "Operation not permitted" },
124
+	{ ETIMEDOUT, "Connection timed out" },
122 125
 };

+ 8
- 4
src/include/gpxe/iscsi.h View File

@@ -224,10 +224,14 @@ struct iscsi_bhs_login_response {
224 224
 #define ISCSI_OPCODE_LOGIN_RESPONSE 0x23
225 225
 
226 226
 /* Login response status codes */
227
-#define ISCSI_STATUS_SUCCESS		0x00
228
-#define ISCSI_STATUS_REDIRECT		0x01
229
-#define ISCSI_STATUS_INITIATOR_ERROR	0x02
230
-#define ISCSI_STATUS_TARGET_ERROR	0x03
227
+#define ISCSI_STATUS_SUCCESS			0x00
228
+#define ISCSI_STATUS_REDIRECT			0x01
229
+#define ISCSI_STATUS_INITIATOR_ERROR		0x02
230
+#define ISCSI_STATUS_INITIATOR_ERROR_AUTHENTICATION	0x01
231
+#define ISCSI_STATUS_INITIATOR_ERROR_AUTHORISATION	0x02
232
+#define ISCSI_STATUS_INITIATOR_ERROR_NOT_FOUND		0x03
233
+#define ISCSI_STATUS_INITIATOR_ERROR_REMOVED		0x04
234
+#define ISCSI_STATUS_TARGET_ERROR		0x03
231 235
 
232 236
 /**
233 237
  * iSCSI SCSI command basic header segment

+ 34
- 3
src/net/tcp/iscsi.c View File

@@ -830,6 +830,35 @@ static int iscsi_rx_buffered_data ( struct iscsi_session *iscsi,
830 830
 	return 0;
831 831
 }
832 832
 
833
+/**
834
+ * Convert iSCSI response status to return status code
835
+ *
836
+ * @v status_class	iSCSI status class
837
+ * @v status_detail	iSCSI status detail
838
+ * @ret rc		Return status code
839
+ */
840
+static int iscsi_status_to_rc ( unsigned int status_class,
841
+				unsigned int status_detail ) {
842
+	switch ( status_class ) {
843
+	case ISCSI_STATUS_INITIATOR_ERROR :
844
+		switch ( status_detail ) {
845
+		case ISCSI_STATUS_INITIATOR_ERROR_AUTHENTICATION :
846
+			return -EACCES;
847
+		case ISCSI_STATUS_INITIATOR_ERROR_AUTHORISATION :
848
+			return -EPERM;
849
+		case ISCSI_STATUS_INITIATOR_ERROR_NOT_FOUND :
850
+		case ISCSI_STATUS_INITIATOR_ERROR_REMOVED :
851
+			return -ENODEV;
852
+		default :
853
+			return -ENOTSUP;
854
+		}
855
+	case ISCSI_STATUS_TARGET_ERROR :
856
+		return -EIO;
857
+	default :
858
+		return -EINVAL;
859
+	}
860
+}
861
+
833 862
 /**
834 863
  * Receive data segment of an iSCSI login response PDU
835 864
  *
@@ -877,8 +906,10 @@ static int iscsi_rx_login_response ( struct iscsi_session *iscsi,
877 906
 	if ( response->status_class != 0 ) {
878 907
 		DBGC ( iscsi, "iSCSI login failure: class %02x detail %02x\n",
879 908
 		       response->status_class, response->status_detail );
880
-		iscsi->instant_rc = -EPERM;
881
-		return -EPERM;
909
+		rc = iscsi_status_to_rc ( response->status_class,
910
+					  response->status_detail );
911
+		iscsi->instant_rc = rc;
912
+		return rc;
882 913
 	}
883 914
 
884 915
 	/* Handle login transitions */
@@ -1177,7 +1208,7 @@ static int iscsi_rx_data ( struct iscsi_session *iscsi, const void *data,
1177 1208
 			return 0;
1178 1209
 		DBGC ( iscsi, "iSCSI %p unknown opcode %02x\n", iscsi,
1179 1210
 		       response->opcode );
1180
-		return -EOPNOTSUPP;
1211
+		return -ENOTSUP;
1181 1212
 	}
1182 1213
 }
1183 1214
 

Loading…
Cancel
Save