Merge pull request #71 from bonzini/aliasing-more

use scsi_get/set_uint16/32/64 in tests
This commit is contained in:
Ronnie Sahlberg
2013-08-03 06:52:43 -07:00
12 changed files with 32 additions and 21 deletions

View File

@@ -204,6 +204,9 @@ scsi_devqualifier_to_str
scsi_devtype_to_str scsi_devtype_to_str
scsi_free_scsi_task scsi_free_scsi_task
scsi_get_task_private_ptr scsi_get_task_private_ptr
scsi_get_uint16
scsi_get_uint32
scsi_get_uint64
scsi_inquiry_pagecode_to_str scsi_inquiry_pagecode_to_str
scsi_modesense_dataout_marshall scsi_modesense_dataout_marshall
scsi_modesense_get_page scsi_modesense_get_page
@@ -212,6 +215,9 @@ scsi_reportluns_cdb
scsi_sense_ascq_str scsi_sense_ascq_str
scsi_sense_key_str scsi_sense_key_str
scsi_set_task_private_ptr scsi_set_task_private_ptr
scsi_set_uint16
scsi_set_uint32
scsi_set_uint64
scsi_task_add_data_in_buffer scsi_task_add_data_in_buffer
scsi_task_add_data_out_buffer scsi_task_add_data_out_buffer
scsi_task_set_iov_in scsi_task_set_iov_in

View File

@@ -202,6 +202,9 @@ scsi_devqualifier_to_str
scsi_devtype_to_str scsi_devtype_to_str
scsi_free_scsi_task scsi_free_scsi_task
scsi_get_task_private_ptr scsi_get_task_private_ptr
scsi_get_uint16
scsi_get_uint32
scsi_get_uint64
scsi_inquiry_pagecode_to_str scsi_inquiry_pagecode_to_str
scsi_modesense_dataout_marshall scsi_modesense_dataout_marshall
scsi_modesense_get_page scsi_modesense_get_page
@@ -211,6 +214,9 @@ scsi_sense_ascq_str
scsi_pr_type_str scsi_pr_type_str
scsi_sense_key_str scsi_sense_key_str
scsi_set_task_private_ptr scsi_set_task_private_ptr
scsi_set_uint16
scsi_set_uint32
scsi_set_uint64
scsi_task_add_data_in_buffer scsi_task_add_data_in_buffer
scsi_task_add_data_out_buffer scsi_task_add_data_out_buffer
scsi_task_set_iov_in scsi_task_set_iov_in

View File

@@ -29,11 +29,11 @@ static int my_iscsi_queue_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu
switch (change_cmdsn) { switch (change_cmdsn) {
case 1: case 1:
/* change the cmdsn so it becomes too big */ /* change the cmdsn so it becomes too big */
*(uint32_t *)&pdu->outdata.data[24] = htonl(iscsi->maxcmdsn + 1); scsi_set_uint32(&pdu->outdata.data[24], iscsi->maxcmdsn + 1);
break; break;
case 2: case 2:
/* change the cmdsn so it becomes too small */ /* change the cmdsn so it becomes too small */
*(uint32_t *)&pdu->outdata.data[24] = 0; scsi_set_uint32(&pdu->outdata.data[24], 0);
break; break;
} }

View File

@@ -34,20 +34,20 @@ static int my_iscsi_queue_pdu(struct iscsi_context *iscsi _U_, struct iscsi_pdu
switch (clamp_datasn) { switch (clamp_datasn) {
case 1: case 1:
/* change datasn to 0 */ /* change datasn to 0 */
*(uint32_t *)&pdu->outdata.data[36] = 0; scsi_set_uint32(&pdu->outdata.data[36], 0);
break; break;
case 2: case 2:
/* change datasn to 27 */ /* change datasn to 27 */
*(uint32_t *)&pdu->outdata.data[36] = htonl(27); scsi_set_uint32(&pdu->outdata.data[36], 27);
break; break;
case 3: case 3:
/* change datasn to -1 */ /* change datasn to -1 */
*(uint32_t *)&pdu->outdata.data[36] = htonl(-1); scsi_set_uint32(&pdu->outdata.data[36], -1);
break; break;
case 4: case 4:
/* change datasn from (0,1) to (1,0) */ /* change datasn from (0,1) to (1,0) */
datasn = ntohl(*(uint32_t *)&pdu->outdata.data[36]); datasn = scsi_get_uint32(&pdu->outdata.data[36]);
*(uint32_t *)&pdu->outdata.data[36] = htonl(1 - datasn); scsi_set_uint32(&pdu->outdata.data[36], 1 - datasn);
break; break;
} }
return 0; return 0;

View File

@@ -31,15 +31,15 @@ static int my_iscsi_queue_pdu(struct iscsi_context *iscsi _U_, struct iscsi_pdu
if (pdu->outdata.data[0] != ISCSI_PDU_DATA_OUT) { if (pdu->outdata.data[0] != ISCSI_PDU_DATA_OUT) {
return 0; return 0;
} }
buffer_offset = ntohl(*(uint32_t *)&pdu->outdata.data[40]); buffer_offset = scsi_get_uint32(&pdu->outdata.data[40]);
switch (change_bufferoffset) { switch (change_bufferoffset) {
case 1: case 1:
/* Add 1M to the buffer offset */ /* Add 1M to the buffer offset */
*(uint32_t *)&pdu->outdata.data[40] = htonl(buffer_offset + 1024*1024); scsi_set_uint32(&pdu->outdata.data[40], buffer_offset + 1024*1024);
break; break;
case 2: case 2:
/* Add -'block_size' to the buffer offset */ /* Add -'block_size' to the buffer offset */
*(uint32_t *)&pdu->outdata.data[40] = htonl(buffer_offset - block_size); scsi_set_uint32(&pdu->outdata.data[40], buffer_offset - block_size);
break; break;
} }
return 0; return 0;

View File

@@ -74,8 +74,7 @@ my_iscsi_pdu_add_data(struct iscsi_context *iscsi, struct iscsi_pdu *pdu,
} }
/* update data segment length */ /* update data segment length */
*(uint32_t *)&pdu->outdata.data[4] = htonl(pdu->outdata.size scsi_set_uint32(&pdu->outdata.data[4], pdu->outdata.size - ISCSI_HEADER_SIZE);
- ISCSI_HEADER_SIZE);
return 0; return 0;
} }
@@ -83,13 +82,13 @@ my_iscsi_pdu_add_data(struct iscsi_context *iscsi, struct iscsi_pdu *pdu,
static void static void
my_iscsi_pdu_set_itt(struct iscsi_pdu *pdu, uint32_t itt) my_iscsi_pdu_set_itt(struct iscsi_pdu *pdu, uint32_t itt)
{ {
*(uint32_t *)&pdu->outdata.data[16] = htonl(itt); scsi_set_uint32(&pdu->outdata.data[16], itt);
} }
static void static void
my_iscsi_pdu_set_expstatsn(struct iscsi_pdu *pdu, uint32_t expstatsnsn) my_iscsi_pdu_set_expstatsn(struct iscsi_pdu *pdu, uint32_t expstatsnsn)
{ {
*(uint32_t *)&pdu->outdata.data[28] = htonl(expstatsnsn); scsi_set_uint32(&pdu->outdata.data[28], expstatsnsn);
} }
static void static void

View File

@@ -37,7 +37,7 @@ static int my_queue_immediate_data(struct iscsi_context *iscsi _U_, struct iscsi
pdu_was_valid = 0; pdu_was_valid = 0;
return 0; return 0;
} }
if ( (*(uint32_t *)&pdu->outdata.data[4] & 0x00ffffff) != htonl(block_size)) { if ( (scsi_get_uint32(&pdu->outdata.data[4]) & 0x00ffffff) != block_size) {
printf("SCSI-Command PDU did not have one block of immediate data.\n"); printf("SCSI-Command PDU did not have one block of immediate data.\n");
pdu_was_valid = 0; pdu_was_valid = 0;
return 0; return 0;

View File

@@ -37,7 +37,7 @@ static int my_queue_immediate_data(struct iscsi_context *iscsi _U_, struct iscsi
pdu_was_valid = 0; pdu_was_valid = 0;
return 0; return 0;
} }
if ( *(uint32_t *)&pdu->outdata.data[4] & 0x00ffffff ) { if ( scsi_get_uint32(&pdu->outdata.data[4]) & 0x00ffffff ) {
printf("SCSI-Command PDU had non-zero datasegmentsize.\n"); printf("SCSI-Command PDU had non-zero datasegmentsize.\n");
pdu_was_valid = 0; pdu_was_valid = 0;
return 0; return 0;
@@ -50,7 +50,7 @@ static int my_queue_immediate_data(struct iscsi_context *iscsi _U_, struct iscsi
pdu_was_valid = 0; pdu_was_valid = 0;
return 0; return 0;
} }
if ( (*(uint32_t *)&pdu->outdata.data[4] & 0x00ffffff) != htonl(block_size)) { if ( (scsi_get_uint32(&pdu->outdata.data[4]) & 0x00ffffff) != block_size) {
printf("The DATA-OUT PDU did not carry a full block.\n"); printf("The DATA-OUT PDU did not carry a full block.\n");
pdu_was_valid = 0; pdu_was_valid = 0;
return 0; return 0;

View File

@@ -90,7 +90,7 @@ int T1100_persistent_reserve_in_read_keys_simple(const char *initiator, const ch
/* Verify that ADDITIONAL_LENGTH matches DATA-IN size */ /* Verify that ADDITIONAL_LENGTH matches DATA-IN size */
printf("Verify that ADDITIONAL_LENGTH matches DATA-IN size ... "); printf("Verify that ADDITIONAL_LENGTH matches DATA-IN size ... ");
al = ntohl(*(uint32_t *)&task->datain.data[4]); al = scsi_get_uint32(&task->datain.data[4]);
if (al != task->datain.size - 8) { if (al != task->datain.size - 8) {
printf("[FAILED]\n"); printf("[FAILED]\n");
printf("ADDITIONAL_LENGTH was %d bytes but %d was expected.\n", printf("ADDITIONAL_LENGTH was %d bytes but %d was expected.\n",

View File

@@ -31,7 +31,7 @@ static int my_iscsi_queue_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu
switch (change_cmdsn) { switch (change_cmdsn) {
case 1: case 1:
/* change the cmdsn so it becomes too big */ /* change the cmdsn so it becomes too big */
*(uint32_t *)&pdu->outdata.data[24] = htonl(iscsi->maxcmdsn + 1); scsi_set_uint32(&pdu->outdata.data[24], iscsi->maxcmdsn + 1);
/* fudge the cmdsn value back to where it should be if this /* fudge the cmdsn value back to where it should be if this
* pdu is ignored. * pdu is ignored.
*/ */

View File

@@ -31,7 +31,7 @@ static int my_iscsi_queue_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu
switch (change_cmdsn) { switch (change_cmdsn) {
case 1: case 1:
/* change the cmdsn so it becomes too big */ /* change the cmdsn so it becomes too big */
*(uint32_t *)&pdu->outdata.data[24] = htonl(iscsi->expcmdsn + 1); scsi_set_uint32(&pdu->outdata.data[24], iscsi->expcmdsn + 1);
/* fudge the cmdsn value back to where it should be if this /* fudge the cmdsn value back to where it should be if this
* pdu is ignored. * pdu is ignored.
*/ */

View File

@@ -52,7 +52,7 @@ test_prin_read_keys_simple(void)
} }
logging(LOG_VERBOSE, "Test ADDITIONAL_LENGTH matches DATA_IN size."); logging(LOG_VERBOSE, "Test ADDITIONAL_LENGTH matches DATA_IN size.");
al = ntohl(*(uint32_t *)&task->datain.data[4]); al = scsi_get_uint32(&task->datain.data[4]);
if (al != task->datain.size - 8) { if (al != task->datain.size - 8) {
logging(LOG_NORMAL, logging(LOG_NORMAL,
"[FAILED] ADDITIONAL_LENGTH was %d bytes but %d was expected.", "[FAILED] ADDITIONAL_LENGTH was %d bytes but %d was expected.",