minor cleanup in preparation for porting the NetBSD iSCSI target to Solaris 9.

This commit is contained in:
agc 2006-03-26 23:34:06 +00:00
parent fbe98ede0f
commit 6e1f35f92e
6 changed files with 64 additions and 80 deletions

View File

@ -5,16 +5,6 @@
#include <sys/types.h>
#define ISCSI_HTON16(a) htons(a)
#define ISCSI_HTON32(a) htonl(a)
#define ISCSI_HTON64(a) htonq(a)
#define ISCSI_NTOH16(a) ntohs(a)
#define ISCSI_NTOH32(a) ntohl(a)
#define ISCSI_NTOH64(a) ntohq(a)
uint64_t htonq(uint64_t);
uint64_t ntohq(uint64_t);
#ifndef HAVE_STRLCPY
size_t strlcpy(char *, const char *, size_t);
#endif

View File

@ -78,11 +78,11 @@ typedef struct iscsi_parameter_item_t {
} iscsi_parameter_value_t;
/* this struct defines the credentials a user has */
typedef struct cred_t {
typedef struct iscsi_cred_t {
char *user; /* user's name */
char *auth_type; /* preferred authentication type */
char *shared_secret; /* the shared secret which will be used */
} cred_t;
} iscsi_cred_t;
/*
* Structure for storing negotiated parameters that are frequently accessed
@ -92,7 +92,7 @@ typedef struct iscsi_sess_param_t {
uint32_t max_burst_length;
uint32_t first_burst_length;
uint32_t max_data_seg_length;
cred_t cred;
iscsi_cred_t cred;
uint8_t initial_r2t;
uint8_t immediate_data;
uint8_t header_digest;
@ -125,7 +125,7 @@ int param_list_add(iscsi_parameter_t ** , int , const char *, const
int param_list_print(iscsi_parameter_t * );
int param_list_destroy(iscsi_parameter_t * );
int param_text_add(iscsi_parameter_t *, const char *, const char *, char *, int *, int, int );
int param_text_parse(iscsi_parameter_t *, cred_t *, char *, int , char *, int *, int, int);
int param_text_parse(iscsi_parameter_t *, iscsi_cred_t *, char *, int , char *, int *, int, int);
int param_text_print(char *, uint32_t );
int param_num_vals(iscsi_parameter_t * , char *);
int param_val_reset(iscsi_parameter_t * , const char *);

View File

@ -159,32 +159,12 @@ void iscsi_print_buffer(const char *, const size_t);
#define __BIG_ENDIAN _BIG_ENDIAN
#define __LITTLE_ENDIAN _LITTLE_ENDIAN
/*
#if __BYTE_ORDER == __BIG_ENDIAN
# define ISCSI_NTOHLL(x) (x)
# define ISCSI_HTONLL(x) (x)
# define ISCSI_NTOHL(x) (x)
# define ISCSI_HTONL(x) (x)
# define ISCSI_NTOHS(x) (x)
# define ISCSI_HTONS(x) (x)
#else
# define ISCSI_NTOHLL(x) bswap_64(x)
# define ISCSI_HTONLL(x) bswap_64(x)
# define ISCSI_NTOHL(x) bswap_32(x)
# define ISCSI_HTONL(x) bswap_32(x)
# define ISCSI_NTOHS(x) bswap_16(x)
# define ISCSI_HTONS(x) bswap_16(x)
#endif
#else
*/
# define ISCSI_NTOHLL(x) BE64TOH(x)
# define ISCSI_HTONLL(x) HTOBE64(x)
# define ISCSI_NTOHL(a) ntohl(a)
# define ISCSI_HTONL(a) htonl(a)
# define ISCSI_NTOHS(a) ntohs(a)
# define ISCSI_HTONS(a) htons(a)
/*
#endif .* !linux */
#define ISCSI_NTOHLL(x) BE64TOH(x)
#define ISCSI_HTONLL(x) HTOBE64(x)
#define ISCSI_NTOHL(a) ntohl(a)
#define ISCSI_HTONL(a) htonl(a)
#define ISCSI_NTOHS(a) ntohs(a)
#define ISCSI_HTONS(a) htons(a)
#define ISCSI_GETPID getpid()

17
dist/iscsi/src/disk.c vendored
View File

@ -1,4 +1,4 @@
/* $NetBSD: disk.c,v 1.10 2006/03/23 00:01:48 agc Exp $ */
/* $NetBSD: disk.c,v 1.11 2006/03/26 23:34:06 agc Exp $ */
/*
* Copyright © 2006 Alistair Crooks. All rights reserved.
@ -924,10 +924,17 @@ device_command(target_session_t * sess, target_cmd_t * cmd)
case INQUIRY_DEVICE_IDENTIFICATION_VPD:
data[0] = DISK_PERIPHERAL_DEVICE;
data[1] = INQUIRY_DEVICE_IDENTIFICATION_VPD;
data[3] = cdb[4] - 7;
data[4] = (INQUIRY_DEVICE_ISCSI_PROTOCOL << 4) | INQUIRY_DEVICE_CODESET_UTF8;
data[5] = (INQUIRY_DEVICE_ASSOCIATION_TARGET_DEVICE << 4) | INQUIRY_DEVICE_IDENTIFIER_SCSI_NAME;
data[7] = snprintf((char *)&data[8], (unsigned) cdb[4] - 8, "%s", sess->globals->targetname);
len = data[3] = cdb[4] - 7;
cp = &data[4];
cp[0] = (INQUIRY_DEVICE_ISCSI_PROTOCOL << 4) | INQUIRY_DEVICE_CODESET_UTF8;
cp[1] = (INQUIRY_DEVICE_ASSOCIATION_TARGET_DEVICE << 4) | INQUIRY_DEVICE_IDENTIFIER_SCSI_NAME;
len = (uint8_t) snprintf((char *)&cp[4], (int)len, "%s", sess->globals->targetname) + 4;
cp[3] = len;
cp += len;
cp[0] = (INQUIRY_DEVICE_ISCSI_PROTOCOL << 4) | INQUIRY_DEVICE_CODESET_UTF8;
cp[1] = (INQUIRY_DEVICE_ASSOCIATION_TARGET_PORT << 4) | INQUIRY_DEVICE_IDENTIFIER_SCSI_NAME;
len = (uint8_t) snprintf((char *)&cp[4], (int)len, "%s,t,0x%x", sess->globals->targetname, lun) + 4;
cp[3] = len;
done = 1;
break;
case INQUIRY_SUPPORTED_VPD_PAGES:

View File

@ -390,7 +390,7 @@ driver_atoi(const char *s)
/* find the credentials for `user' and put them in `cred' */
static int
find_credentials(cred_t *cred, char *user, const char *auth)
find_credentials(iscsi_cred_t *cred, char *user, const char *auth)
{
conffile_t conf;
const char *authtype;
@ -426,7 +426,7 @@ find_credentials(cred_t *cred, char *user, const char *auth)
#if 0
/* free any storage allocated in `cred' */
static void
free_cred(cred_t *cred)
free_cred(iscsi_cred_t *cred)
{
if (cred) {
if (cred->user) {
@ -450,7 +450,7 @@ free_cred(cred_t *cred)
static int
param_parse_security(iscsi_parameter_t * head,
iscsi_parameter_t * param_in,
cred_t *cred,
iscsi_cred_t *cred,
char *text_out, int *text_len_out, int textsize)
{
@ -658,7 +658,7 @@ param_parse_security(iscsi_parameter_t * head,
int
param_text_parse(iscsi_parameter_t * head,
cred_t *cred,
iscsi_cred_t *cred,
char *text_in, int text_len_in,
char *text_out, int *text_len_out,
int textsize,

69
dist/iscsi/src/util.c vendored
View File

@ -530,7 +530,7 @@ iscsi_sock_bind(iscsi_socket_t sock, int port)
(void) memset(&laddr, 0x0, sizeof(laddr));
laddr.sin_family = AF_INET;
laddr.sin_addr.s_addr = INADDR_ANY;
laddr.sin_port = ISCSI_HTON16(port);
laddr.sin_port = ISCSI_HTONS(port);
if ((rc = bind(sock, (struct sockaddr *) (void *) &laddr, sizeof(laddr))) < 0) {
iscsi_trace_error("bind() failed: rc %i errno %i\n", rc, errno);
return -1;
@ -1096,21 +1096,24 @@ cdb2lba(uint32_t *lba, uint16_t *len, uint8_t *cdb)
/* Some platforms (like strongarm) aligns on */
/* word boundaries. So HTONL and NTOHL won't */
/* work here. */
#if (BYTE_ORDER == BIG_ENDIAN)
((uint8_t *) (void *) lba)[0] = cdb[2];
((uint8_t *) (void *) lba)[1] = cdb[3];
((uint8_t *) (void *) lba)[2] = cdb[4];
((uint8_t *) (void *) lba)[3] = cdb[5];
((uint8_t *) (void *) len)[0] = cdb[7];
((uint8_t *) (void *) len)[1] = cdb[8];
#else
((uint8_t *) (void *) lba)[0] = cdb[5];
((uint8_t *) (void *) lba)[1] = cdb[4];
((uint8_t *) (void *) lba)[2] = cdb[3];
((uint8_t *) (void *) lba)[3] = cdb[2];
((uint8_t *) (void *) len)[0] = cdb[8];
((uint8_t *) (void *) len)[1] = cdb[7];
#endif
int indian = 1;
if (*(char *) &indian) {
/* little endian */
((uint8_t *) (void *) lba)[0] = cdb[5];
((uint8_t *) (void *) lba)[1] = cdb[4];
((uint8_t *) (void *) lba)[2] = cdb[3];
((uint8_t *) (void *) lba)[3] = cdb[2];
((uint8_t *) (void *) len)[0] = cdb[8];
((uint8_t *) (void *) len)[1] = cdb[7];
} else {
((uint8_t *) (void *) lba)[0] = cdb[2];
((uint8_t *) (void *) lba)[1] = cdb[3];
((uint8_t *) (void *) lba)[2] = cdb[4];
((uint8_t *) (void *) lba)[3] = cdb[5];
((uint8_t *) (void *) len)[0] = cdb[7];
((uint8_t *) (void *) len)[1] = cdb[8];
}
}
void
@ -1119,19 +1122,23 @@ lba2cdb(uint8_t *cdb, uint32_t *lba, uint16_t *len)
/* Some platforms (like strongarm) aligns on */
/* word boundaries. So HTONL and NTOHL won't */
/* work here. */
#if (BYTE_ORDER == BIG_ENDIAN)
cdb[2] = ((uint8_t *) lba)[2];
cdb[3] = ((uint8_t *) lba)[3];
cdb[4] = ((uint8_t *) lba)[0];
cdb[5] = ((uint8_t *) lba)[1];
cdb[7] = ((uint8_t *) len)[0];
cdb[8] = ((uint8_t *) len)[1];
#else
cdb[2] = ((uint8_t *) lba)[3];
cdb[3] = ((uint8_t *) lba)[2];
cdb[4] = ((uint8_t *) lba)[1];
cdb[5] = ((uint8_t *) lba)[0];
cdb[7] = ((uint8_t *) len)[1];
cdb[8] = ((uint8_t *) len)[0];
#endif
int indian = 1;
if (*(char *) &indian) {
/* little endian */
cdb[2] = ((uint8_t *) lba)[3];
cdb[3] = ((uint8_t *) lba)[2];
cdb[4] = ((uint8_t *) lba)[1];
cdb[5] = ((uint8_t *) lba)[0];
cdb[7] = ((uint8_t *) len)[1];
cdb[8] = ((uint8_t *) len)[0];
} else {
/* big endian */
cdb[2] = ((uint8_t *) lba)[2];
cdb[3] = ((uint8_t *) lba)[3];
cdb[4] = ((uint8_t *) lba)[0];
cdb[5] = ((uint8_t *) lba)[1];
cdb[7] = ((uint8_t *) len)[0];
cdb[8] = ((uint8_t *) len)[1];
}
}