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
 /** The most common errors */
108
 /** The most common errors */
109
 struct errortab common_errors[] __errortab = {
109
 struct errortab common_errors[] __errortab = {
110
 	{ 0, "No error" },
110
 	{ 0, "No error" },
111
-	{ ENOMEM, "Out of memory" },
111
+	{ EACCES, "Permission denied" },
112
+	{ ECANCELED, "Operation cancelled" },
113
+	{ ECONNRESET, "Connection reset" },
112
 	{ EINVAL, "Invalid argument" },
114
 	{ EINVAL, "Invalid argument" },
113
-	{ ENOSPC, "No space left on device" },
114
 	{ EIO, "Input/output error" },
115
 	{ EIO, "Input/output error" },
115
-	{ EACCES, "Permission denied" },
116
-	{ ENOENT, "File not found" },
117
 	{ ENETUNREACH, "Network unreachable" },
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
 	{ ENOEXEC, "Not an executable image" },
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
 #define ISCSI_OPCODE_LOGIN_RESPONSE 0x23
224
 #define ISCSI_OPCODE_LOGIN_RESPONSE 0x23
225
 
225
 
226
 /* Login response status codes */
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
  * iSCSI SCSI command basic header segment
237
  * iSCSI SCSI command basic header segment

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

830
 	return 0;
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
  * Receive data segment of an iSCSI login response PDU
863
  * Receive data segment of an iSCSI login response PDU
835
  *
864
  *
877
 	if ( response->status_class != 0 ) {
906
 	if ( response->status_class != 0 ) {
878
 		DBGC ( iscsi, "iSCSI login failure: class %02x detail %02x\n",
907
 		DBGC ( iscsi, "iSCSI login failure: class %02x detail %02x\n",
879
 		       response->status_class, response->status_detail );
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
 	/* Handle login transitions */
915
 	/* Handle login transitions */
1177
 			return 0;
1208
 			return 0;
1178
 		DBGC ( iscsi, "iSCSI %p unknown opcode %02x\n", iscsi,
1209
 		DBGC ( iscsi, "iSCSI %p unknown opcode %02x\n", iscsi,
1179
 		       response->opcode );
1210
 		       response->opcode );
1180
-		return -EOPNOTSUPP;
1211
+		return -ENOTSUP;
1181
 	}
1212
 	}
1182
 }
1213
 }
1183
 
1214
 

Loading…
Cancel
Save