Browse Source

[scsi] Generalise iscsi_parse_lun() to scsi_parse_lun()

tags/v0.9.8
Michael Brown 14 years ago
parent
commit
d944794680
4 changed files with 48 additions and 48 deletions
  1. 30
    0
      src/drivers/block/scsi.c
  2. 5
    5
      src/include/gpxe/iscsi.h
  3. 12
    6
      src/include/gpxe/scsi.h
  4. 1
    37
      src/net/tcp/iscsi.c

+ 30
- 0
src/drivers/block/scsi.c View File

@@ -19,6 +19,7 @@
19 19
 FILE_LICENCE ( GPL2_OR_LATER );
20 20
 
21 21
 #include <stddef.h>
22
+#include <stdlib.h>
22 23
 #include <string.h>
23 24
 #include <byteswap.h>
24 25
 #include <errno.h>
@@ -334,3 +335,32 @@ int init_scsidev ( struct scsi_device *scsi ) {
334 335
 
335 336
 	return 0;
336 337
 }
338
+
339
+/**
340
+ * Parse SCSI LUN
341
+ *
342
+ * @v lun_string	LUN string representation
343
+ * @v lun		LUN to fill in
344
+ * @ret rc		Return status code
345
+ */
346
+int scsi_parse_lun ( const char *lun_string, struct scsi_lun *lun ) {
347
+	char *p;
348
+	int i;
349
+
350
+	memset ( lun, 0, sizeof ( *lun ) );
351
+	if ( lun_string ) {
352
+		p = ( char * ) lun_string;
353
+		for ( i = 0 ; i < 4 ; i++ ) {
354
+			lun->u16[i] = htons ( strtoul ( p, &p, 16 ) );
355
+			if ( *p == '\0' )
356
+				break;
357
+			if ( *p != '-' )
358
+				return -EINVAL;
359
+			p++;
360
+		}
361
+		if ( *p )
362
+			return -EINVAL;
363
+	}
364
+
365
+	return 0;
366
+}

+ 5
- 5
src/include/gpxe/iscsi.h View File

@@ -249,7 +249,7 @@ struct iscsi_bhs_scsi_command {
249 249
 	/** Segment lengths */
250 250
 	union iscsi_segment_lengths lengths;
251 251
 	/** SCSI Logical Unit Number */
252
-	uint64_t lun;
252
+	struct scsi_lun lun;
253 253
 	/** Initiator Task Tag */
254 254
 	uint32_t itt;
255 255
 	/** Expected data transfer length */
@@ -344,7 +344,7 @@ struct iscsi_bhs_data_in {
344 344
 	/** Segment lengths */
345 345
 	union iscsi_segment_lengths lengths;
346 346
 	/** Logical Unit Number */
347
-	uint64_t lun;
347
+	struct scsi_lun lun;
348 348
 	/** Initiator Task Tag */
349 349
 	uint32_t itt;
350 350
 	/** Target Transfer Tag */
@@ -392,7 +392,7 @@ struct iscsi_bhs_data_out {
392 392
 	/** Segment lengths */
393 393
 	union iscsi_segment_lengths lengths;
394 394
 	/** Logical Unit Number */
395
-	uint64_t lun;
395
+	struct scsi_lun lun;
396 396
 	/** Initiator Task Tag */
397 397
 	uint32_t itt;
398 398
 	/** Target Transfer Tag */
@@ -428,7 +428,7 @@ struct iscsi_bhs_r2t {
428 428
 	/** Segment lengths */
429 429
 	union iscsi_segment_lengths lengths;
430 430
 	/** Logical Unit Number */
431
-	uint64_t lun;
431
+	struct scsi_lun lun;
432 432
 	/** Initiator Task Tag */
433 433
 	uint32_t itt;
434 434
 	/** Target Transfer Tag */
@@ -507,7 +507,7 @@ struct iscsi_session {
507 507
 	/** Target IQN */
508 508
 	char *target_iqn;
509 509
 	/** Logical Unit Number (LUN) */
510
-	uint64_t lun;
510
+	struct scsi_lun lun;
511 511
 	/** Target socket address (recorded only for iBFT) */
512 512
 	struct sockaddr target_sockaddr;
513 513
 

+ 12
- 6
src/include/gpxe/scsi.h View File

@@ -240,16 +240,21 @@ struct scsi_command {
240 240
 	int rc;
241 241
 };
242 242
 
243
+/** A SCSI LUN
244
+ *
245
+ * This is a four-level LUN as specified by SAM-2, in big-endian
246
+ * order.
247
+ */
248
+struct scsi_lun {
249
+	uint16_t u16[4];
250
+}  __attribute__ (( packed ));
251
+
243 252
 /** A SCSI device */
244 253
 struct scsi_device {
245 254
 	/** Block device interface */
246 255
 	struct block_device blockdev;
247
-	/** Logical unit number (LUN)
248
-	 *
249
-	 * This is a four-level LUN as specified by SAM-2, in
250
-	 * big-endian order.
251
-	 */
252
-	uint64_t lun;
256
+	/** Logical unit number (LUN) */
257
+	struct scsi_lun lun;
253 258
 	/**
254 259
 	 * Issue SCSI command
255 260
 	 *
@@ -273,5 +278,6 @@ struct scsi_device {
273 278
 extern int scsi_detached_command ( struct scsi_device *scsi,
274 279
 				   struct scsi_command *command );
275 280
 extern int init_scsidev ( struct scsi_device *scsi );
281
+extern int scsi_parse_lun ( const char *lun_string, struct scsi_lun *lun );
276 282
 
277 283
 #endif /* _GPXE_SCSI_H */

+ 1
- 37
src/net/tcp/iscsi.c View File

@@ -1605,42 +1605,6 @@ enum iscsi_root_path_component {
1605 1605
 	NUM_RP_COMPONENTS
1606 1606
 };
1607 1607
 
1608
-/**
1609
- * Parse iSCSI LUN
1610
- *
1611
- * @v iscsi		iSCSI session
1612
- * @v lun_string	LUN string representation (as per RFC4173)
1613
- * @ret rc		Return status code
1614
- */
1615
-static int iscsi_parse_lun ( struct iscsi_session *iscsi,
1616
-			     const char *lun_string ) {
1617
-	union {
1618
-		uint64_t u64;
1619
-		uint16_t u16[4];
1620
-	} lun;
1621
-	char *p;
1622
-	int i;
1623
-
1624
-	memset ( &lun, 0, sizeof ( lun ) );
1625
-	if ( lun_string ) {
1626
-		p = ( char * ) lun_string;
1627
-		
1628
-		for ( i = 0 ; i < 4 ; i++ ) {
1629
-			lun.u16[i] = htons ( strtoul ( p, &p, 16 ) );
1630
-			if ( *p == '\0' )
1631
-				break;
1632
-			if ( *p != '-' )
1633
-				return -EINVAL;
1634
-			p++;
1635
-		}
1636
-		if ( *p )
1637
-			return -EINVAL;
1638
-	}
1639
-
1640
-	iscsi->lun = lun.u64;
1641
-	return 0;
1642
-}
1643
-
1644 1608
 /**
1645 1609
  * Parse iSCSI root path
1646 1610
  *
@@ -1679,7 +1643,7 @@ static int iscsi_parse_root_path ( struct iscsi_session *iscsi,
1679 1643
 	iscsi->target_port = strtoul ( rp_comp[RP_PORT], NULL, 10 );
1680 1644
 	if ( ! iscsi->target_port )
1681 1645
 		iscsi->target_port = ISCSI_PORT;
1682
-	if ( ( rc = iscsi_parse_lun ( iscsi, rp_comp[RP_LUN] ) ) != 0 ) {
1646
+	if ( ( rc = scsi_parse_lun ( rp_comp[RP_LUN], &iscsi->lun ) ) != 0 ) {
1683 1647
 		DBGC ( iscsi, "iSCSI %p invalid LUN \"%s\"\n",
1684 1648
 		       iscsi, rp_comp[RP_LUN] );
1685 1649
 		return rc;

Loading…
Cancel
Save