From a2592bff3a2225a4554fb31870d813cf485f63ab Mon Sep 17 00:00:00 2001 From: Peter Lieven Date: Wed, 13 Aug 2014 17:55:09 +0200 Subject: [PATCH] test-tool: improve GetLBAStatus.UnmapSingle the test became nearly useless when reverting most of its contents in commit 7d96336. This patch adds some useful stuff back. While we can't check that unmapped blocks are deallocated we still can check that the blocks surrounding the unmapped area don't get dealloaced. Signed-off-by: Peter Lieven --- test-tool/test_get_lba_status_unmap_single.c | 106 ++++++++----------- 1 file changed, 43 insertions(+), 63 deletions(-) diff --git a/test-tool/test_get_lba_status_unmap_single.c b/test-tool/test_get_lba_status_unmap_single.c index b04b068..a41e7d1 100644 --- a/test-tool/test_get_lba_status_unmap_single.c +++ b/test-tool/test_get_lba_status_unmap_single.c @@ -32,10 +32,8 @@ test_get_lba_status_unmap_single(void) int ret; uint64_t i; unsigned char *buf = alloca(257 * block_size); - struct scsi_task *task_ret; struct unmap_list list[1]; - struct scsi_get_lba_status *lbas = NULL; - struct scsi_lba_status_descriptor *lbasd = NULL; + enum scsi_provisioning_type provisioning; CHECK_FOR_DATALOSS; CHECK_FOR_THIN_PROVISIONING; @@ -48,12 +46,14 @@ test_get_lba_status_unmap_single(void) "at offset 0-255"); logging(LOG_VERBOSE, "We have %d logical blocks per physical block", lbppb); - for (i = 0; i + lbppb <= 256; i += lbppb) { - logging(LOG_VERBOSE, "Write the first 257 blocks with a known " - "pattern and thus map the blocks"); - ret = write10(iscsic, tgt_lun, 0, 257 * block_size, - block_size, 0, 0, 0, 0, 0, buf); + logging(LOG_VERBOSE, "Write the first %i blocks with a known " + "pattern and thus map the blocks", 256 + lbppb); + ret = write10(iscsic, tgt_lun, 0, (256 + lbppb) * block_size, + block_size, 0, 0, 0, 0, 0, buf); + CU_ASSERT_EQUAL(ret, 0); + + for (i = 0; i + lbppb <= 256; i += lbppb) { logging(LOG_VERBOSE, "Unmap a single physical block at LBA:%" PRIu64 " (number of logical blocks: %d)", i, lbppb); list[0].lba = i; @@ -63,48 +63,35 @@ test_get_lba_status_unmap_single(void) logging(LOG_VERBOSE, "Read the status of the block at LBA:%" PRIu64, i); - task_ret = get_lba_status_task(iscsic, tgt_lun, i, 24); - if (!task_ret) { - CU_PASS("[SKIPPED] Target does not support " - "GET_LBA_STATUS. Skipping test"); + ret = get_lba_status(iscsic, tgt_lun, i, 24, NULL); + if (ret == -2) { + CU_PASS("[SKIPPED] Target does not support GET_LBA_STATUS. Skipping test"); return; } - - lbas = scsi_datain_unmarshall(task_ret); - if (lbas == NULL) { - logging(LOG_NORMAL, "[FAILED] GET_LBA_STATUS command: " - "failed to unmarschall data."); - CU_FAIL("[FAILED] GET_LBA_STATUS command: " - "failed to unmarschall data."); - scsi_free_scsi_task(task_ret); + if (ret != 0) { + CU_FAIL("[FAILED] GET_LBA_STATUS command failed"); return; } - lbasd = &lbas->descriptors[0]; - - - logging(LOG_VERBOSE, "Verify that the LBA in the first " - "descriptor matches the LBA in the CDB"); - if (lbasd->lba != i) { - logging(LOG_NORMAL, "[FAILED] GET_LBA_STATUS command: " - "LBA offset in first descriptor does not match " - "request (0x%" PRIx64 " != 0x%" PRIx64 ").", - lbasd->lba, i); - CU_FAIL("[FAILED] GET_LBA_STATUS command: " - "LBA offset in first descriptor does not match " - "the LBA in the CDB."); - scsi_free_scsi_task(task_ret); + logging(LOG_VERBOSE, "Read the status of the block at LBA:%" + PRIu64, i + lbppb); + ret = get_lba_status(iscsic, tgt_lun, i + lbppb, 24, &provisioning); + if (ret != 0) { + CU_FAIL("[FAILED] GET_LBA_STATUS command failed"); + return; + } + if (provisioning != SCSI_PROVISIONING_TYPE_MAPPED) { + CU_FAIL("[FAILED] LBA should be mapped but isn't"); return; } - scsi_free_scsi_task(task_ret); } logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test GET_LBA_STATUS for a single range of 1-255 " "blocks at offset 0"); for (i = lbppb; i + lbppb <= 256; i += lbppb) { - logging(LOG_VERBOSE, "Write the first 257 blocks with a known " - "pattern and thus map the blocks"); - ret = write10(iscsic, tgt_lun, 0, 257 * block_size, + logging(LOG_VERBOSE, "Write the first %i blocks with a known " + "pattern and thus map the blocks", (256 + lbppb)); + ret = write10(iscsic, tgt_lun, 0, (256 + lbppb) * block_size, block_size, 0, 0, 0, 0, 0, buf); logging(LOG_VERBOSE, "Unmap %" PRIu64 " blocks at LBA 0", i); @@ -113,33 +100,26 @@ test_get_lba_status_unmap_single(void) ret = unmap(iscsic, tgt_lun, 0, list, 1); CU_ASSERT_EQUAL(ret, 0); - logging(LOG_VERBOSE, "Read the status of the block at LBA 0"); - task_ret = get_lba_status_task(iscsic, tgt_lun, 0, 24); - lbas = scsi_datain_unmarshall(task_ret); - if (lbas == NULL) { - logging(LOG_NORMAL, "[FAILED] GET_LBA_STATUS command: " - "failed to unmarschall data."); - CU_FAIL("[FAILED] GET_LBA_STATUS command: " - "failed to unmarschall data."); - scsi_free_scsi_task(task_ret); - return; - } - lbasd = &lbas->descriptors[0]; - + logging(LOG_VERBOSE, "Read the status of the block at LBA:0"); - logging(LOG_VERBOSE, "Verify that the LBA in the first " - "descriptor matches the LBA in the CDB"); - if (lbasd->lba != 0) { - logging(LOG_NORMAL, "[FAILED] GET_LBA_STATUS command: " - "LBA offset in first descriptor does not match " - "request (0x%" PRIx64 " != 0x%" PRIx64 ").", - lbasd->lba, i); - CU_FAIL("[FAILED] GET_LBA_STATUS command: " - "LBA offset in first descriptor does not match " - "the LBA in the CDB."); - scsi_free_scsi_task(task_ret); + ret = get_lba_status(iscsic, tgt_lun, 0, 24, NULL); + if (ret == -2) { + CU_PASS("[SKIPPED] Target does not support GET_LBA_STATUS. Skipping test"); + return; + } + if (ret != 0) { + CU_FAIL("[FAILED] GET_LBA_STATUS command failed"); + return; + } + logging(LOG_VERBOSE, "Read the status of the block at LBA:%" PRIu64, i + 1); + ret = get_lba_status(iscsic, tgt_lun, i + 1, 24, &provisioning); + if (ret != 0) { + CU_FAIL("[FAILED] GET_LBA_STATUS command failed"); + return; + } + if (provisioning != SCSI_PROVISIONING_TYPE_MAPPED) { + CU_FAIL("[FAILED] LBA should be mapped but isn't"); return; } - scsi_free_scsi_task(task_ret); } }