TESTS: update unmap to new api

Signed-off-by: Ronnie Sahlberg <sahlberg@localhost>
This commit is contained in:
Ronnie Sahlberg
2014-09-17 17:33:14 -07:00
committed by Ronnie Sahlberg
parent 832d88797a
commit 398f03205d
10 changed files with 72 additions and 117 deletions
+1
View File
@@ -210,6 +210,7 @@ scsi_get_uint16
scsi_get_uint32 scsi_get_uint32
scsi_get_uint64 scsi_get_uint64
scsi_inquiry_pagecode_to_str scsi_inquiry_pagecode_to_str
scsi_malloc
scsi_modesense_dataout_marshall scsi_modesense_dataout_marshall
scsi_modesense_get_page scsi_modesense_get_page
scsi_protocol_identifier_to_str scsi_protocol_identifier_to_str
+1
View File
@@ -208,6 +208,7 @@ scsi_get_uint16
scsi_get_uint32 scsi_get_uint32
scsi_get_uint64 scsi_get_uint64
scsi_inquiry_pagecode_to_str scsi_inquiry_pagecode_to_str
scsi_malloc
scsi_modesense_dataout_marshall scsi_modesense_dataout_marshall
scsi_modesense_get_page scsi_modesense_get_page
scsi_protocol_identifier_to_str scsi_protocol_identifier_to_str
+42 -99
View File
@@ -1840,120 +1840,63 @@ reserve6_conflict(struct iscsi_context *iscsi, int lun)
} }
int int
unmap(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len) unmap(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len, int status, enum scsi_sense_key key, int *ascq, int num_ascq)
{ {
struct scsi_task *task; struct scsi_task *task;
struct scsi_iovec *iov;
unsigned char *data;
int xferlen;
int i;
int ret;
logging(LOG_VERBOSE, "Send UNMAP list_len:%d anchor:%d", list_len, anchor); logging(LOG_VERBOSE, "Send UNMAP (Expecting %s) list_len:%d anchor:%d",
task = iscsi_unmap_sync(iscsi, lun, anchor, 0, list, list_len); scsi_status_str(status),
if (task == NULL) { list_len, anchor);
logging(LOG_NORMAL, "[FAILED] Failed to send UNMAP command: %s",
iscsi_get_error(iscsi)); if (!data_loss) {
printf("--dataloss flag is not set in. Skipping unmap\n");
return -1; return -1;
} }
if (task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST xferlen = 8 + list_len * 16;
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
logging(LOG_NORMAL, "[SKIPPED] UNMAP is not implemented on target"); task = scsi_cdb_unmap(anchor, 0, xferlen);
scsi_free_scsi_task(task); assert(task != NULL);
return -2;
} data = scsi_malloc(task, xferlen);
if (task->status != SCSI_STATUS_GOOD) { if (data == NULL) {
logging(LOG_NORMAL, "[FAILED] UNMAP command: failed with sense. %s", iscsi_get_error(iscsi)); logging(LOG_NORMAL, "Out-of-memory: Failed to create "
"unmap parameters.");
scsi_free_scsi_task(task); scsi_free_scsi_task(task);
return -1; return -1;
} }
scsi_free_scsi_task(task); scsi_set_uint16(&data[0], xferlen - 2);
logging(LOG_VERBOSE, "[OK] UNMAP returned SUCCESS."); scsi_set_uint16(&data[2], xferlen - 8);
return 0; for (i = 0; i < list_len; i++) {
} scsi_set_uint32(&data[8 + 16 * i], list[i].lba >> 32);
scsi_set_uint32(&data[8 + 16 * i + 4], list[i].lba & 0xffffffff);
int scsi_set_uint32(&data[8 + 16 * i + 8], list[i].num);
unmap_writeprotected(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len)
{
struct scsi_task *task;
logging(LOG_VERBOSE, "Send UNMAP (Expecting WRITE_PROTECTED) "
"list_len:%d anchor:%d", list_len, anchor);
task = iscsi_unmap_sync(iscsi, lun, anchor, 0, list, list_len);
if (task == NULL) {
logging(LOG_NORMAL, "[FAILED] Failed to send UNMAP command: %s",
iscsi_get_error(iscsi));
return -1;
} }
if (task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST iov = scsi_malloc(task, sizeof(struct scsi_iovec));
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) { if (iov == NULL) {
logging(LOG_NORMAL, "[SKIPPED] UNMAP is not implemented on target"); logging(LOG_NORMAL, "Out-of-memory: Failed to create "
scsi_free_scsi_task(task); "iov array.");
return -2;
}
if (task->status == SCSI_STATUS_GOOD) {
logging(LOG_NORMAL, "[FAILED] UNMAP successful but should "
"have failed with DATA_PROTECTION/WRITE_PROTECTED");
scsi_free_scsi_task(task); scsi_free_scsi_task(task);
return -1; return -1;
} }
if (task->status != SCSI_STATUS_CHECK_CONDITION iov->iov_base = data;
|| task->sense.key != SCSI_SENSE_DATA_PROTECTION iov->iov_len = xferlen;
|| task->sense.ascq != SCSI_SENSE_ASCQ_WRITE_PROTECTED) { scsi_task_set_iov_out(task, iov, 1);
logging(LOG_NORMAL, "[FAILED] UNMAP failed with wrong sense. "
"Should have failed with DATA_PRTOTECTION/" task = iscsi_scsi_command_sync(iscsi, lun, task, NULL);
"WRITE_PROTECTED. Sense:%s\n",
iscsi_get_error(iscsi)); ret = check_result("UNMAP", iscsi, task, status, key, ascq, num_ascq);
if (task) {
scsi_free_scsi_task(task); scsi_free_scsi_task(task);
return -1;
} }
return ret;
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] UNMAP returned DATA_PROTECTION/WRITE_PROTECTED.");
return 0;
}
int
unmap_nomedium(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len)
{
struct scsi_task *task;
logging(LOG_VERBOSE, "Send UNMAP (Expecting MEDIUM_NOT_PRESENT) "
"list_len:%d anchor:%d", list_len, anchor);
task = iscsi_unmap_sync(iscsi, lun, anchor, 0, list, list_len);
if (task == NULL) {
logging(LOG_NORMAL, "[FAILED] Failed to send UNMAP command: %s",
iscsi_get_error(iscsi));
return -1;
}
if (task->status == SCSI_STATUS_CHECK_CONDITION
&& task->sense.key == SCSI_SENSE_ILLEGAL_REQUEST
&& task->sense.ascq == SCSI_SENSE_ASCQ_INVALID_OPERATION_CODE) {
logging(LOG_NORMAL, "[SKIPPED] UNMAP is not implemented on target");
scsi_free_scsi_task(task);
return -2;
}
if (task->status == SCSI_STATUS_GOOD) {
logging(LOG_NORMAL, "[FAILED] UNMAP successful but should "
"have failed with NOT_READY/MEDIUM_NOT_PRESENT*");
scsi_free_scsi_task(task);
return -1;
}
if (task->status != SCSI_STATUS_CHECK_CONDITION
|| task->sense.key != SCSI_SENSE_NOT_READY
|| (task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_OPEN
&& task->sense.ascq != SCSI_SENSE_ASCQ_MEDIUM_NOT_PRESENT_TRAY_CLOSED)) {
logging(LOG_NORMAL, "[FAILED] UNMAP Should have failed "
"with NOT_READY/MEDIUM_NOT_PRESENT* But failed "
"with %s", iscsi_get_error(iscsi));
scsi_free_scsi_task(task);
return -1;
}
scsi_free_scsi_task(task);
logging(LOG_VERBOSE, "[OK] UNMAP returned MEDIUM_NOT_PRESENT.");
return 0;
} }
int int
+2 -3
View File
@@ -2,6 +2,7 @@
iscsi-test tool support iscsi-test tool support
Copyright (C) 2012 by Lee Duncan <leeman.duncan@gmail.com> Copyright (C) 2012 by Lee Duncan <leeman.duncan@gmail.com>
Copyright (C) 2014 by Ronnie sahlberg <ronniesahlberg@gmail.com>
This program is free software; you can redistribute it and/or modify This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -280,9 +281,7 @@ int synchronizecache16(struct iscsi_context *iscsi, int lun, uint64_t lba, int n
int testunitready_clear_ua(struct iscsi_context *iscsi, int lun); int testunitready_clear_ua(struct iscsi_context *iscsi, int lun);
int testunitready(struct iscsi_context *iscsi, int lun, int status, enum scsi_sense_key key, int *ascq, int num_ascq); int testunitready(struct iscsi_context *iscsi, int lun, int status, enum scsi_sense_key key, int *ascq, int num_ascq);
int mode_sense(struct iscsi_context *iscsi, int lun); int mode_sense(struct iscsi_context *iscsi, int lun);
int unmap(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len); int unmap(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len, int status, enum scsi_sense_key key, int *ascq, int num_ascq);
int unmap_writeprotected(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len);
int unmap_nomedium(struct iscsi_context *iscsi, int lun, int anchor, struct unmap_list *list, int list_len);
int verify10(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq); int verify10(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq);
int verify12(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq); int verify12(struct iscsi_context *iscsi, int lun, uint32_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq);
int verify16(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq); int verify16(struct iscsi_context *iscsi, int lun, uint64_t lba, uint32_t datalen, int blocksize, int vprotect, int dpo, int bytchk, unsigned char *data, int status, enum scsi_sense_key key, int *ascq, int num_ascq);
+4 -2
View File
@@ -60,7 +60,8 @@ test_get_lba_status_unmap_single(void)
PRIu64 " (number of logical blocks: %d)", i, lbppb); PRIu64 " (number of logical blocks: %d)", i, lbppb);
list[0].lba = i; list[0].lba = i;
list[0].num = lbppb; list[0].num = lbppb;
ret = unmap(iscsic, tgt_lun, 0, list, 1); ret = unmap(iscsic, tgt_lun, 0, list, 1,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0); CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Read the status of the block at LBA:%" logging(LOG_VERBOSE, "Read the status of the block at LBA:%"
@@ -122,7 +123,8 @@ test_get_lba_status_unmap_single(void)
logging(LOG_VERBOSE, "Unmap %" PRIu64 " blocks at LBA 0", i); logging(LOG_VERBOSE, "Unmap %" PRIu64 " blocks at LBA 0", i);
list[0].lba = 0; list[0].lba = 0;
list[0].num = i; list[0].num = i;
ret = unmap(iscsic, tgt_lun, 0, list, 1); ret = unmap(iscsic, tgt_lun, 0, list, 1,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0); CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Read the status of the block at LBA:0"); logging(LOG_VERBOSE, "Read the status of the block at LBA:0");
+2 -1
View File
@@ -266,7 +266,8 @@ test_nomedia_sbc(void)
logging(LOG_VERBOSE, "Test UNMAP when medium is ejected."); logging(LOG_VERBOSE, "Test UNMAP when medium is ejected.");
list[0].lba = 0; list[0].lba = 0;
list[0].num = lbppb; list[0].num = lbppb;
ret = unmap_nomedium(iscsic, tgt_lun, 0, list, 1); ret = unmap(iscsic, tgt_lun, 0, list, 1,
EXPECT_NO_MEDIUM);
if (ret == -2) { if (ret == -2) {
logging(LOG_NORMAL, "[SKIPPED] target does not support " logging(LOG_NORMAL, "[SKIPPED] target does not support "
"UNMAP"); "UNMAP");
+4 -2
View File
@@ -97,7 +97,8 @@ test_readonly_sbc(void)
logging(LOG_VERBOSE, "Test UNMAP of one physical block fails with WRITE_PROTECTED"); logging(LOG_VERBOSE, "Test UNMAP of one physical block fails with WRITE_PROTECTED");
list[0].lba = 0; list[0].lba = 0;
list[0].num = lbppb; list[0].num = lbppb;
ret = unmap_writeprotected(iscsic, tgt_lun, 0, list, 1); ret = unmap(iscsic, tgt_lun, 0, list, 1,
EXPECT_WRITE_PROTECTED);
if (ret == -2) { if (ret == -2) {
logging(LOG_VERBOSE, "UNMAP not supported on target. Skipped."); logging(LOG_VERBOSE, "UNMAP not supported on target. Skipped.");
} }
@@ -106,7 +107,8 @@ test_readonly_sbc(void)
logging(LOG_VERBOSE, "Test UNMAP of one logical block fails with WRITE_PROTECTED"); logging(LOG_VERBOSE, "Test UNMAP of one logical block fails with WRITE_PROTECTED");
list[0].lba = 0; list[0].lba = 0;
list[0].num = 1; list[0].num = 1;
ret = unmap_writeprotected(iscsic, tgt_lun, 0, list, 1); ret = unmap(iscsic, tgt_lun, 0, list, 1,
EXPECT_WRITE_PROTECTED);
if (ret == -2) { if (ret == -2) {
logging(LOG_VERBOSE, "UNMAP not supported on target. Skipped."); logging(LOG_VERBOSE, "UNMAP not supported on target. Skipped.");
} }
+10 -6
View File
@@ -1,4 +1,3 @@
/* /*
Copyright (C) 2013 Ronnie Sahlberg <ronniesahlberg@gmail.com> Copyright (C) 2013 Ronnie Sahlberg <ronniesahlberg@gmail.com>
@@ -41,7 +40,8 @@ test_unmap_0blocks(void)
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
list[0].lba = i; list[0].lba = i;
list[0].num = 0; list[0].num = 0;
ret = unmap(iscsic, tgt_lun, 0, list, 1); ret = unmap(iscsic, tgt_lun, 0, list, 1,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0); CU_ASSERT_EQUAL(ret, 0);
} }
@@ -49,14 +49,16 @@ test_unmap_0blocks(void)
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
list[i].lba = i; list[i].lba = i;
list[i].num = 0; list[i].num = 0;
ret = unmap(iscsic, tgt_lun, 0, list, i); ret = unmap(iscsic, tgt_lun, 0, list, i,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0); CU_ASSERT_EQUAL(ret, 0);
} }
logging(LOG_VERBOSE, "Test UNMAP of 0 blocks at end-of-LUN"); logging(LOG_VERBOSE, "Test UNMAP of 0 blocks at end-of-LUN");
list[0].lba = num_blocks; list[0].lba = num_blocks;
list[0].num = 0; list[0].num = 0;
ret = unmap(iscsic, tgt_lun, 0, list, 1); ret = unmap(iscsic, tgt_lun, 0, list, 1,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0); CU_ASSERT_EQUAL(ret, 0);
@@ -65,12 +67,14 @@ test_unmap_0blocks(void)
list[i].lba = i/2; list[i].lba = i/2;
list[i].num = 0; list[i].num = 0;
} }
ret = unmap(iscsic, tgt_lun, 0, list, 256); ret = unmap(iscsic, tgt_lun, 0, list, 256,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0); CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Test UNMAP without any descriptors."); logging(LOG_VERBOSE, "Test UNMAP without any descriptors.");
ret = unmap(iscsic, tgt_lun, 0, list, 0); ret = unmap(iscsic, tgt_lun, 0, list, 0,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0); CU_ASSERT_EQUAL(ret, 0);
} }
+4 -2
View File
@@ -64,7 +64,8 @@ test_unmap_simple(void)
logging(LOG_VERBOSE, "UNMAP blocks 0-%d", i); logging(LOG_VERBOSE, "UNMAP blocks 0-%d", i);
list[0].lba = 0; list[0].lba = 0;
list[0].num = i; list[0].num = i;
ret = unmap(iscsic, tgt_lun, 0, list, 1); ret = unmap(iscsic, tgt_lun, 0, list, 1,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0); CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Read blocks 0-%d", i); logging(LOG_VERBOSE, "Read blocks 0-%d", i);
@@ -98,7 +99,8 @@ test_unmap_simple(void)
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
list[i].lba = i; list[i].lba = i;
list[i].num = 1; list[i].num = 1;
ret = unmap(iscsic, tgt_lun, 0, list, i + 1); ret = unmap(iscsic, tgt_lun, 0, list, i + 1,
EXPECT_STATUS_GOOD);
CU_ASSERT_EQUAL(ret, 0); CU_ASSERT_EQUAL(ret, 0);
logging(LOG_VERBOSE, "Read blocks 0-%d", i); logging(LOG_VERBOSE, "Read blocks 0-%d", i);
+2 -2
View File
@@ -40,8 +40,8 @@ test_unmap_vpd(void)
logging(LOG_VERBOSE, "Check if UNMAP is available."); logging(LOG_VERBOSE, "Check if UNMAP is available.");
list[0].lba = 0; list[0].lba = 0;
list[0].num = 0; list[0].num = 0;
ret = unmap(iscsic, tgt_lun, 0, list, 1); ret = unmap(iscsic, tgt_lun, 0, list, 1,
EXPECT_STATUS_GOOD);
if (ret != 0) { if (ret != 0) {
logging(LOG_VERBOSE, "UNMAP is not available. Verify that VPD " logging(LOG_VERBOSE, "UNMAP is not available. Verify that VPD "
"settings reflect this."); "settings reflect this.");