diff --git a/dist/iscsi/include/util.h b/dist/iscsi/include/util.h index a0cc006177f5..99fa0bbcd8c1 100644 --- a/dist/iscsi/include/util.h +++ b/dist/iscsi/include/util.h @@ -196,11 +196,7 @@ typedef int socklen_t; * Sleeping */ -#ifdef __KERNEL__ -#define ISCSI_SLEEP(N) {uint32_t future = jiffies+N*HZ; while (jiffiesthread.pthread = current; - -#if LINUX_VERSION_CODE >= LinuxVersionCode(2,4,0) -#define REPARENT_TO_INIT() reparent_to_init() -#define ISCSI_THREAD_START(NAME) \ - lock_kernel(); \ - daemonize(); \ - REPARENT_TO_INIT(); \ - unlock_kernel(); \ - sprintf(current->comm, "%s", NAME); -#else -#define REPARENT_TO_INIT -#define ISCSI_THREAD_START(NAME) \ - sprintf(current->comm, "%s", NAME); -#endif -#else #define ISCSI_SET_THREAD(ME) /* for user pthread id set by pthread_create * in iscsi_thread_create */ #define ISCSI_THREAD_START(NAME) -#endif /* * Worker Thread @@ -481,12 +441,7 @@ typedef struct { /* * Spin Lock */ - -#ifdef __KERNEL__ -#define ISCSI_SPIN schedule() -#else #define ISCSI_SPIN -#endif /* * Pre/Post condition checking diff --git a/dist/iscsi/src/disk.c b/dist/iscsi/src/disk.c index 99cc29973294..76d66e7f1098 100644 --- a/dist/iscsi/src/disk.c +++ b/dist/iscsi/src/disk.c @@ -1,4 +1,4 @@ -/* $NetBSD: disk.c,v 1.7 2006/03/20 20:45:07 agc Exp $ */ +/* $NetBSD: disk.c,v 1.8 2006/03/21 21:03:14 agc Exp $ */ /* * Copyright © 2006 Alistair Crooks. All rights reserved. @@ -934,25 +934,7 @@ device_command(target_session_t * sess, target_cmd_t * cmd) case WRITE_10: - /* 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 + cdb2lba(&lba, &len, cdb); iscsi_trace(TRACE_SCSI_CMD, "WRITE_10(lba %u, len %u blocks)\n", lba, len); if (disk_write(sess, args, lun, lba, (unsigned) len) != 0) { @@ -964,26 +946,7 @@ device_command(target_session_t * sess, target_cmd_t * cmd) case READ_10: - /* 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 + cdb2lba(&lba, &len, cdb); iscsi_trace(TRACE_SCSI_CMD, "READ_10(lba %u, len %u blocks)\n", lba, len); if (disk_read(sess, args, lba, len, lun) != 0) { diff --git a/dist/iscsi/src/tests.c b/dist/iscsi/src/tests.c index 08e6395064d6..d1b4dea79eec 100644 --- a/dist/iscsi/src/tests.c +++ b/dist/iscsi/src/tests.c @@ -248,26 +248,7 @@ write_read_test(uint64_t target, uint32_t lun, int type) if (type == 10) { cdb[0] = WRITE_10; cdb[1] = lun << 5; - - /* Strongarm aligns on word boundaries. */ - /* So HTONL and NTOHL won't work here. */ - -#if (BYTE_ORDER == BIG_ENDIAN) - cdb[2] = ((uint8_t *) &i)[2]; - cdb[3] = ((uint8_t *) &i)[3]; - cdb[4] = ((uint8_t *) &i)[0]; - cdb[5] = ((uint8_t *) &i)[1]; - cdb[7] = ((uint8_t *) &len)[0]; - cdb[8] = ((uint8_t *) &len)[1]; -#else - cdb[2] = ((uint8_t *) &i)[3]; - cdb[3] = ((uint8_t *) &i)[2]; - cdb[4] = ((uint8_t *) &i)[1]; - cdb[5] = ((uint8_t *) &i)[0]; - cdb[7] = ((uint8_t *) &len)[1]; - cdb[8] = ((uint8_t *) &len)[0]; -#endif - + lba2cdb(cdb, &i, &len); } else { *((uint32_t *) (cdb + 0)) = ISCSI_HTONL(i); cdb[0] = WRITE_6; @@ -302,26 +283,7 @@ write_read_test(uint64_t target, uint32_t lun, int type) if (type == 10) { cdb[0] = READ_10; cdb[1] = lun << 5; - - /* Strongarm aligns on word boundaries. */ - /* So HTONL and NTOHL won't work here. */ - -#if (BYTE_ORDER == BIG_ENDIAN) - cdb[2] = ((uint8_t *) &i)[2]; - cdb[3] = ((uint8_t *) &i)[3]; - cdb[4] = ((uint8_t *) &i)[0]; - cdb[5] = ((uint8_t *) &i)[1]; - cdb[7] = ((uint8_t *) &len)[0]; - cdb[8] = ((uint8_t *) &len)[1]; -#else - cdb[2] = ((uint8_t *) &i)[3]; - cdb[3] = ((uint8_t *) &i)[2]; - cdb[4] = ((uint8_t *) &i)[1]; - cdb[5] = ((uint8_t *) &i)[0]; - cdb[7] = ((uint8_t *) &len)[1]; - cdb[8] = ((uint8_t *) &len)[0]; -#endif - + lba2cdb(cdb, &i, &len); } else { *((uint32_t *) (cdb + 0)) = ISCSI_HTONL(i); cdb[0] = READ_6; @@ -710,50 +672,14 @@ latency_test(uint64_t target, uint32_t lun, uint8_t op, uint32_t iters) trans_len = block_len; cdb[0] = READ_10; cdb[1] = lun << 5; - - /* 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 + lba2cdb(cdb, &lba, &len); break; case WRITE_10: output = 1; trans_len = block_len; cdb[0] = WRITE_10; cdb[1] = lun << 5; - - /* 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 + lba2cdb(cdb, &lba, &len); break; default: iscsi_trace_error("op 0x%x not implemented\n", op); @@ -892,25 +818,7 @@ scatter_gather_test(uint64_t target, uint32_t lun, uint8_t op) sg[i].iov_base = buff[i]; sg[i].iov_len = block_len; } - - /* 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 + lba2cdb(cdb, &lba, &len); gettimeofday(&t_start, 0); diff --git a/dist/iscsi/src/util.c b/dist/iscsi/src/util.c index 08e5782f3027..7c9e69846e92 100644 --- a/dist/iscsi/src/util.c +++ b/dist/iscsi/src/util.c @@ -1088,3 +1088,50 @@ GenRandomData(uint8_t *data, uint32_t length) *data++ = n; } } + + +void +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 +} + +void +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 +}