Selaa lähdekoodia

[scsi] Generalise iscsi_parse_lun() to scsi_parse_lun()

tags/v0.9.8
Michael Brown 15 vuotta sitten
vanhempi
commit
d944794680
4 muutettua tiedostoa jossa 48 lisäystä ja 48 poistoa
  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 Näytä tiedosto

19
 FILE_LICENCE ( GPL2_OR_LATER );
19
 FILE_LICENCE ( GPL2_OR_LATER );
20
 
20
 
21
 #include <stddef.h>
21
 #include <stddef.h>
22
+#include <stdlib.h>
22
 #include <string.h>
23
 #include <string.h>
23
 #include <byteswap.h>
24
 #include <byteswap.h>
24
 #include <errno.h>
25
 #include <errno.h>
334
 
335
 
335
 	return 0;
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 Näytä tiedosto

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

+ 12
- 6
src/include/gpxe/scsi.h Näytä tiedosto

240
 	int rc;
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
 /** A SCSI device */
252
 /** A SCSI device */
244
 struct scsi_device {
253
 struct scsi_device {
245
 	/** Block device interface */
254
 	/** Block device interface */
246
 	struct block_device blockdev;
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
 	 * Issue SCSI command
259
 	 * Issue SCSI command
255
 	 *
260
 	 *
273
 extern int scsi_detached_command ( struct scsi_device *scsi,
278
 extern int scsi_detached_command ( struct scsi_device *scsi,
274
 				   struct scsi_command *command );
279
 				   struct scsi_command *command );
275
 extern int init_scsidev ( struct scsi_device *scsi );
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
 #endif /* _GPXE_SCSI_H */
283
 #endif /* _GPXE_SCSI_H */

+ 1
- 37
src/net/tcp/iscsi.c Näytä tiedosto

1605
 	NUM_RP_COMPONENTS
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
  * Parse iSCSI root path
1609
  * Parse iSCSI root path
1646
  *
1610
  *
1679
 	iscsi->target_port = strtoul ( rp_comp[RP_PORT], NULL, 10 );
1643
 	iscsi->target_port = strtoul ( rp_comp[RP_PORT], NULL, 10 );
1680
 	if ( ! iscsi->target_port )
1644
 	if ( ! iscsi->target_port )
1681
 		iscsi->target_port = ISCSI_PORT;
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
 		DBGC ( iscsi, "iSCSI %p invalid LUN \"%s\"\n",
1647
 		DBGC ( iscsi, "iSCSI %p invalid LUN \"%s\"\n",
1684
 		       iscsi, rp_comp[RP_LUN] );
1648
 		       iscsi, rp_comp[RP_LUN] );
1685
 		return rc;
1649
 		return rc;

Loading…
Peruuta
Tallenna