mirror of https://github.com/ipxe/ipxe.git
[scsi] Generalise iscsi_parse_lun() to scsi_parse_lun()
parent
976f12c501
commit
d944794680
|
@ -19,6 +19,7 @@
|
||||||
FILE_LICENCE ( GPL2_OR_LATER );
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <byteswap.h>
|
#include <byteswap.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
@ -334,3 +335,32 @@ int init_scsidev ( struct scsi_device *scsi ) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse SCSI LUN
|
||||||
|
*
|
||||||
|
* @v lun_string LUN string representation
|
||||||
|
* @v lun LUN to fill in
|
||||||
|
* @ret rc Return status code
|
||||||
|
*/
|
||||||
|
int scsi_parse_lun ( const char *lun_string, struct scsi_lun *lun ) {
|
||||||
|
char *p;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
memset ( lun, 0, sizeof ( *lun ) );
|
||||||
|
if ( lun_string ) {
|
||||||
|
p = ( char * ) lun_string;
|
||||||
|
for ( i = 0 ; i < 4 ; i++ ) {
|
||||||
|
lun->u16[i] = htons ( strtoul ( p, &p, 16 ) );
|
||||||
|
if ( *p == '\0' )
|
||||||
|
break;
|
||||||
|
if ( *p != '-' )
|
||||||
|
return -EINVAL;
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
if ( *p )
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
@ -249,7 +249,7 @@ struct iscsi_bhs_scsi_command {
|
||||||
/** Segment lengths */
|
/** Segment lengths */
|
||||||
union iscsi_segment_lengths lengths;
|
union iscsi_segment_lengths lengths;
|
||||||
/** SCSI Logical Unit Number */
|
/** SCSI Logical Unit Number */
|
||||||
uint64_t lun;
|
struct scsi_lun lun;
|
||||||
/** Initiator Task Tag */
|
/** Initiator Task Tag */
|
||||||
uint32_t itt;
|
uint32_t itt;
|
||||||
/** Expected data transfer length */
|
/** Expected data transfer length */
|
||||||
|
@ -344,7 +344,7 @@ struct iscsi_bhs_data_in {
|
||||||
/** Segment lengths */
|
/** Segment lengths */
|
||||||
union iscsi_segment_lengths lengths;
|
union iscsi_segment_lengths lengths;
|
||||||
/** Logical Unit Number */
|
/** Logical Unit Number */
|
||||||
uint64_t lun;
|
struct scsi_lun lun;
|
||||||
/** Initiator Task Tag */
|
/** Initiator Task Tag */
|
||||||
uint32_t itt;
|
uint32_t itt;
|
||||||
/** Target Transfer Tag */
|
/** Target Transfer Tag */
|
||||||
|
@ -392,7 +392,7 @@ struct iscsi_bhs_data_out {
|
||||||
/** Segment lengths */
|
/** Segment lengths */
|
||||||
union iscsi_segment_lengths lengths;
|
union iscsi_segment_lengths lengths;
|
||||||
/** Logical Unit Number */
|
/** Logical Unit Number */
|
||||||
uint64_t lun;
|
struct scsi_lun lun;
|
||||||
/** Initiator Task Tag */
|
/** Initiator Task Tag */
|
||||||
uint32_t itt;
|
uint32_t itt;
|
||||||
/** Target Transfer Tag */
|
/** Target Transfer Tag */
|
||||||
|
@ -428,7 +428,7 @@ struct iscsi_bhs_r2t {
|
||||||
/** Segment lengths */
|
/** Segment lengths */
|
||||||
union iscsi_segment_lengths lengths;
|
union iscsi_segment_lengths lengths;
|
||||||
/** Logical Unit Number */
|
/** Logical Unit Number */
|
||||||
uint64_t lun;
|
struct scsi_lun lun;
|
||||||
/** Initiator Task Tag */
|
/** Initiator Task Tag */
|
||||||
uint32_t itt;
|
uint32_t itt;
|
||||||
/** Target Transfer Tag */
|
/** Target Transfer Tag */
|
||||||
|
@ -507,7 +507,7 @@ struct iscsi_session {
|
||||||
/** Target IQN */
|
/** Target IQN */
|
||||||
char *target_iqn;
|
char *target_iqn;
|
||||||
/** Logical Unit Number (LUN) */
|
/** Logical Unit Number (LUN) */
|
||||||
uint64_t lun;
|
struct scsi_lun lun;
|
||||||
/** Target socket address (recorded only for iBFT) */
|
/** Target socket address (recorded only for iBFT) */
|
||||||
struct sockaddr target_sockaddr;
|
struct sockaddr target_sockaddr;
|
||||||
|
|
||||||
|
|
|
@ -240,16 +240,21 @@ struct scsi_command {
|
||||||
int rc;
|
int rc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** A SCSI LUN
|
||||||
|
*
|
||||||
|
* This is a four-level LUN as specified by SAM-2, in big-endian
|
||||||
|
* order.
|
||||||
|
*/
|
||||||
|
struct scsi_lun {
|
||||||
|
uint16_t u16[4];
|
||||||
|
} __attribute__ (( packed ));
|
||||||
|
|
||||||
/** A SCSI device */
|
/** A SCSI device */
|
||||||
struct scsi_device {
|
struct scsi_device {
|
||||||
/** Block device interface */
|
/** Block device interface */
|
||||||
struct block_device blockdev;
|
struct block_device blockdev;
|
||||||
/** Logical unit number (LUN)
|
/** Logical unit number (LUN) */
|
||||||
*
|
struct scsi_lun lun;
|
||||||
* This is a four-level LUN as specified by SAM-2, in
|
|
||||||
* big-endian order.
|
|
||||||
*/
|
|
||||||
uint64_t lun;
|
|
||||||
/**
|
/**
|
||||||
* Issue SCSI command
|
* Issue SCSI command
|
||||||
*
|
*
|
||||||
|
@ -273,5 +278,6 @@ struct scsi_device {
|
||||||
extern int scsi_detached_command ( struct scsi_device *scsi,
|
extern int scsi_detached_command ( struct scsi_device *scsi,
|
||||||
struct scsi_command *command );
|
struct scsi_command *command );
|
||||||
extern int init_scsidev ( struct scsi_device *scsi );
|
extern int init_scsidev ( struct scsi_device *scsi );
|
||||||
|
extern int scsi_parse_lun ( const char *lun_string, struct scsi_lun *lun );
|
||||||
|
|
||||||
#endif /* _GPXE_SCSI_H */
|
#endif /* _GPXE_SCSI_H */
|
||||||
|
|
|
@ -1605,42 +1605,6 @@ enum iscsi_root_path_component {
|
||||||
NUM_RP_COMPONENTS
|
NUM_RP_COMPONENTS
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Parse iSCSI LUN
|
|
||||||
*
|
|
||||||
* @v iscsi iSCSI session
|
|
||||||
* @v lun_string LUN string representation (as per RFC4173)
|
|
||||||
* @ret rc Return status code
|
|
||||||
*/
|
|
||||||
static int iscsi_parse_lun ( struct iscsi_session *iscsi,
|
|
||||||
const char *lun_string ) {
|
|
||||||
union {
|
|
||||||
uint64_t u64;
|
|
||||||
uint16_t u16[4];
|
|
||||||
} lun;
|
|
||||||
char *p;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
memset ( &lun, 0, sizeof ( lun ) );
|
|
||||||
if ( lun_string ) {
|
|
||||||
p = ( char * ) lun_string;
|
|
||||||
|
|
||||||
for ( i = 0 ; i < 4 ; i++ ) {
|
|
||||||
lun.u16[i] = htons ( strtoul ( p, &p, 16 ) );
|
|
||||||
if ( *p == '\0' )
|
|
||||||
break;
|
|
||||||
if ( *p != '-' )
|
|
||||||
return -EINVAL;
|
|
||||||
p++;
|
|
||||||
}
|
|
||||||
if ( *p )
|
|
||||||
return -EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
iscsi->lun = lun.u64;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse iSCSI root path
|
* Parse iSCSI root path
|
||||||
*
|
*
|
||||||
|
@ -1679,7 +1643,7 @@ static int iscsi_parse_root_path ( struct iscsi_session *iscsi,
|
||||||
iscsi->target_port = strtoul ( rp_comp[RP_PORT], NULL, 10 );
|
iscsi->target_port = strtoul ( rp_comp[RP_PORT], NULL, 10 );
|
||||||
if ( ! iscsi->target_port )
|
if ( ! iscsi->target_port )
|
||||||
iscsi->target_port = ISCSI_PORT;
|
iscsi->target_port = ISCSI_PORT;
|
||||||
if ( ( rc = iscsi_parse_lun ( iscsi, rp_comp[RP_LUN] ) ) != 0 ) {
|
if ( ( rc = scsi_parse_lun ( rp_comp[RP_LUN], &iscsi->lun ) ) != 0 ) {
|
||||||
DBGC ( iscsi, "iSCSI %p invalid LUN \"%s\"\n",
|
DBGC ( iscsi, "iSCSI %p invalid LUN \"%s\"\n",
|
||||||
iscsi, rp_comp[RP_LUN] );
|
iscsi, rp_comp[RP_LUN] );
|
||||||
return rc;
|
return rc;
|
||||||
|
|
Loading…
Reference in New Issue