diff --git a/lib/iscsi-command.c b/lib/iscsi-command.c index 07d747e..9591b11 100644 --- a/lib/iscsi-command.c +++ b/lib/iscsi-command.c @@ -1539,7 +1539,6 @@ iscsi_writesame10_task(struct iscsi_context *iscsi, int lun, uint32_t lba, scsi_free_scsi_task(task); return NULL; } - return task; } diff --git a/test-tool/test_writesame10_beyond_eol.c b/test-tool/test_writesame10_beyond_eol.c index 02a794c..f53fc29 100644 --- a/test-tool/test_writesame10_beyond_eol.c +++ b/test-tool/test_writesame10_beyond_eol.c @@ -16,6 +16,7 @@ */ #include +#include #include @@ -28,6 +29,7 @@ void test_writesame10_beyond_eol(void) { int i, ret; + unsigned char *buf = alloca(block_size); CHECK_FOR_DATALOSS; CHECK_FOR_SBC; @@ -39,13 +41,11 @@ test_writesame10_beyond_eol(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test WRITESAME10 1-256 blocks one block beyond the end"); + memset(buf, 0, block_size); for (i = 1; i <= 256; i++) { - unsigned char *buf = malloc(block_size); - ret = writesame10_lbaoutofrange(iscsic, tgt_lun, num_blocks - i + 1, block_size, i, 0, 0, 0, 0, buf); - free(buf); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support WRITESAME10. Skipping test"); return; @@ -56,36 +56,27 @@ test_writesame10_beyond_eol(void) logging(LOG_VERBOSE, "Test WRITESAME10 1-256 blocks at LBA==2^31"); for (i = 1; i <= 256; i++) { - unsigned char *buf = malloc(block_size); - ret = writesame10_lbaoutofrange(iscsic, tgt_lun, 0x80000000, block_size, i, 0, 0, 0, 0, buf); - free(buf); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "Test WRITESAME10 1-256 blocks at LBA==-1"); for (i = 1; i <= 256; i++) { - unsigned char *buf = malloc(block_size); - ret = writesame10_lbaoutofrange(iscsic, tgt_lun, -1, block_size, i, 0, 0, 0, 0, buf); - free(buf); CU_ASSERT_EQUAL(ret, 0); } logging(LOG_VERBOSE, "Test WRITESAME10 2-256 blocks all but one block beyond the end"); for (i = 2; i <= 256; i++) { - unsigned char *buf = malloc(block_size); - ret = writesame10_lbaoutofrange(iscsic, tgt_lun, num_blocks - 1, block_size, i, 0, 0, 0, 0, buf); - free(buf); CU_ASSERT_EQUAL(ret, 0); } } diff --git a/test-tool/test_writesame10_simple.c b/test-tool/test_writesame10_simple.c index 264b00a..e14f7ee 100644 --- a/test-tool/test_writesame10_simple.c +++ b/test-tool/test_writesame10_simple.c @@ -17,6 +17,7 @@ */ #include +#include #include @@ -30,6 +31,7 @@ void test_writesame10_simple(void) { int i, ret; + unsigned char *buf = alloca(block_size); CHECK_FOR_DATALOSS; CHECK_FOR_SBC; @@ -37,13 +39,11 @@ test_writesame10_simple(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test WRITESAME10 of 1-256 blocks at the start of the LUN"); + memset(buf, 0, block_size); for (i = 1; i <= 256; i++) { - unsigned char *buf = malloc(block_size); - ret = writesame10(iscsic, tgt_lun, 0, block_size, i, 0, 0, 0, 0, buf); - free(buf); if (ret == -2) { CU_PASS("[SKIPPED] Target does not support WRITESAME10. Skipping test"); return; @@ -53,12 +53,9 @@ test_writesame10_simple(void) logging(LOG_VERBOSE, "Test WRITESAME10 of 1-256 blocks at the end of the LUN"); for (i = 1; i <= 256; i++) { - unsigned char *buf = malloc(block_size ); - ret = writesame10(iscsic, tgt_lun, num_blocks - i, block_size, i, 0, 0, 0, 0, buf); - free(buf); CU_ASSERT_EQUAL(ret, 0); } diff --git a/test-tool/test_writesame10_unmap.c b/test-tool/test_writesame10_unmap.c index 398642b..58439e0 100644 --- a/test-tool/test_writesame10_unmap.c +++ b/test-tool/test_writesame10_unmap.c @@ -31,7 +31,7 @@ test_writesame10_unmap(void) { int i, ret; unsigned int j; - unsigned char *buf = malloc(block_size * 256); + unsigned char *buf = alloca(256 * block_size); CHECK_FOR_DATALOSS; CHECK_FOR_THIN_PROVISIONING; @@ -43,16 +43,17 @@ test_writesame10_unmap(void) "the LUN"); for (i = 1; i <= 256; i++) { logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); - memset(buf, 0xff, block_size * i); + memset(buf, 0xff, i * block_size); ret = write10(iscsic, tgt_lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0, buf); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME10", i); + memset(buf, 0, block_size); ret = writesame10(iscsic, tgt_lun, 0, block_size, i, - 0, 1, 0, 0, NULL); + 0, 1, 0, 0, buf); CU_ASSERT_EQUAL(ret, 0); if (rc16->lbprz) { @@ -80,13 +81,14 @@ test_writesame10_unmap(void) "the LUN"); for (i = 1; i <= 256; i++) { logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); - memset(buf, 0xff, block_size * i); + memset(buf, 0xff, i * block_size); ret = write10(iscsic, tgt_lun, num_blocks - i, i * block_size, block_size, 0, 0, 0, 0, 0, buf); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME10", i); + memset(buf, 0, block_size); ret = writesame10(iscsic, tgt_lun, num_blocks - i, block_size, i, 0, 1, 0, 0, buf); @@ -116,22 +118,23 @@ test_writesame10_unmap(void) "invalid"); ret = writesame10_invalidfieldincdb(iscsic, tgt_lun, 0, block_size, 1, - 1, 0, 0, 0, NULL); + 1, 0, 0, 0, buf); CU_ASSERT_EQUAL(ret, 0); if (inq_lbp->anc_sup) { logging(LOG_VERBOSE, "Test WRITESAME10 ANCHOR==1 + UNMAP==0"); + memset(buf, 0, block_size); ret = writesame10(iscsic, tgt_lun, 0, block_size, 1, - 1, 1, 0, 0, NULL); + 1, 1, 0, 0, buf); } else { logging(LOG_VERBOSE, "Test WRITESAME10 ANCHOR==1 + UNMAP==0 no " "ANC_SUP so expecting to fail"); ret = writesame10_invalidfieldincdb(iscsic, tgt_lun, 0, block_size, 1, - 1, 1, 0, 0, NULL); + 1, 1, 0, 0, buf); } CU_ASSERT_EQUAL(ret, 0); @@ -141,7 +144,6 @@ test_writesame10_unmap(void) "BlockLimits VPD is missing."); CU_FAIL("[FAILED] WRITESAME10 works but " "BlockLimits VPD is missing."); - free(buf); return; } @@ -153,16 +155,17 @@ test_writesame10_unmap(void) "lengths"); logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); - memset(buf, 0xff, block_size * i); + memset(buf, 0xff, i * block_size); ret = write10(iscsic, tgt_lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0, buf); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME10", i); + memset(buf, 0, block_size); ret = writesame10(iscsic, tgt_lun, 0, block_size, i, - 0, 1, 0, 0, NULL); + 0, 1, 0, 0, buf); CU_ASSERT_EQUAL(ret, 0); if (rc16->lbprz) { @@ -191,8 +194,7 @@ test_writesame10_unmap(void) logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME10", i); ret = writesame10_invalidfieldincdb(iscsic, tgt_lun, 0, block_size, i, - 0, 1, 0, 0, NULL); + 0, 1, 0, 0, buf); CU_ASSERT_EQUAL(ret, 0); } - free(buf); } diff --git a/test-tool/test_writesame10_unmap_vpd.c b/test-tool/test_writesame10_unmap_vpd.c index ea408d4..b8e272d 100644 --- a/test-tool/test_writesame10_unmap_vpd.c +++ b/test-tool/test_writesame10_unmap_vpd.c @@ -16,6 +16,7 @@ */ #include +#include #include @@ -29,6 +30,7 @@ void test_writesame10_unmap_vpd(void) { int ret; + unsigned char *buf = alloca(block_size); logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test WRITESAME10 UNMAP availability is " @@ -39,9 +41,10 @@ test_writesame10_unmap_vpd(void) logging(LOG_VERBOSE, "Check if WRITESAME10 can be used for UNMAP."); logging(LOG_VERBOSE, "Unmap 1 block using WRITESAME10"); + memset(buf, 0, block_size); ret = writesame10(iscsic, tgt_lun, 0, block_size, 1, - 0, 1, 0, 0, NULL); + 0, 1, 0, 0, buf); if (ret != 0) { logging(LOG_VERBOSE, "WRITESAME10 UNMAP is not available. " diff --git a/test-tool/test_writesame10_wrprotect.c b/test-tool/test_writesame10_wrprotect.c index 7cd560d..d5bc21d 100644 --- a/test-tool/test_writesame10_wrprotect.c +++ b/test-tool/test_writesame10_wrprotect.c @@ -41,6 +41,7 @@ test_writesame10_wrprotect(void) CHECK_FOR_DATALOSS; CHECK_FOR_SBC; + memset(buf, 0, block_size); if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) { diff --git a/test-tool/test_writesame16_beyond_eol.c b/test-tool/test_writesame16_beyond_eol.c index 468a146..1bf2380 100644 --- a/test-tool/test_writesame16_beyond_eol.c +++ b/test-tool/test_writesame16_beyond_eol.c @@ -29,14 +29,14 @@ void test_writesame16_beyond_eol(void) { int i, ret; - unsigned char *buf = alloca(256 * block_size); - + unsigned char *buf = alloca(block_size); CHECK_FOR_DATALOSS; CHECK_FOR_SBC; logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test WRITESAME16 1-256 blocks one block beyond the end"); + memset(buf, 0, block_size); for (i = 1; i <= 256; i++) { ret = writesame16_lbaoutofrange(iscsic, tgt_lun, num_blocks - i + 1, block_size, i, diff --git a/test-tool/test_writesame16_simple.c b/test-tool/test_writesame16_simple.c index 719eb0d..09ff0ff 100644 --- a/test-tool/test_writesame16_simple.c +++ b/test-tool/test_writesame16_simple.c @@ -31,7 +31,6 @@ test_writesame16_simple(void) { int i, ret; unsigned char *buf = alloca(block_size); - CHECK_FOR_DATALOSS; CHECK_FOR_SBC; @@ -39,6 +38,7 @@ test_writesame16_simple(void) logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test WRITESAME16 of 1-256 blocks at the start of the LUN"); + memset(buf, 0, block_size); for (i = 1; i <= 256; i++) { ret = writesame16(iscsic, tgt_lun, 0, block_size, i, diff --git a/test-tool/test_writesame16_unmap.c b/test-tool/test_writesame16_unmap.c index 12aa6a4..6a69423 100644 --- a/test-tool/test_writesame16_unmap.c +++ b/test-tool/test_writesame16_unmap.c @@ -30,8 +30,7 @@ test_writesame16_unmap(void) { int i, ret; unsigned int j; - unsigned char *buf = malloc(block_size * 65536); - + unsigned char *buf = malloc(65536 * block_size); CHECK_FOR_DATALOSS; CHECK_FOR_THIN_PROVISIONING; @@ -42,19 +41,19 @@ test_writesame16_unmap(void) logging(LOG_VERBOSE, "Test WRITESAME16 of 1-256 blocks at the start of the LUN"); for (i = 1; i <= 256; i++) { logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); - memset(buf, 0xff, block_size * i); + memset(buf, 0xff, i * block_size); ret = write16(iscsic, tgt_lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0, buf); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i); + memset(buf, 0, block_size); ret = writesame16(iscsic, tgt_lun, 0, block_size, i, - 0, 1, 0, 0, NULL); + 0, 1, 0, 0, buf); if (ret == -2) { logging(LOG_NORMAL, "[SKIPPED] WRITESAME16 is not implemented."); CU_PASS("[SKIPPED] Target does not support WRITESAME16. Skipping test"); - free(buf); return; } CU_ASSERT_EQUAL(ret, 0); @@ -82,13 +81,14 @@ test_writesame16_unmap(void) logging(LOG_VERBOSE, "Test WRITESAME16 of 1-256 blocks at the end of the LUN"); for (i = 1; i <= 256; i++) { logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); - memset(buf, 0xff, block_size * i); + memset(buf, 0xff, i * block_size); ret = write16(iscsic, tgt_lun, num_blocks - i, i * block_size, block_size, 0, 0, 0, 0, 0, buf); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i); + memset(buf, 0, block_size); ret = writesame16(iscsic, tgt_lun, num_blocks - i, block_size, i, 0, 1, 0, 0, buf); @@ -116,21 +116,22 @@ test_writesame16_unmap(void) logging(LOG_VERBOSE, "Verify that WRITESAME16 ANCHOR==1 + UNMAP==0 is invalid"); ret = writesame16_invalidfieldincdb(iscsic, tgt_lun, 0, block_size, 1, - 1, 0, 0, 0, NULL); + 1, 0, 0, 0, buf); CU_ASSERT_EQUAL(ret, 0); if (inq_lbp->anc_sup) { logging(LOG_VERBOSE, "Test WRITESAME16 ANCHOR==1 + UNMAP==0"); + memset(buf, 0, block_size); ret = writesame16(iscsic, tgt_lun, 0, block_size, 1, - 1, 1, 0, 0, NULL); + 1, 1, 0, 0, buf); } else { logging(LOG_VERBOSE, "Test WRITESAME16 ANCHOR==1 + UNMAP==0 no ANC_SUP so expecting to fail"); ret = writesame16_invalidfieldincdb(iscsic, tgt_lun, 0, block_size, 1, - 1, 1, 0, 0, NULL); + 1, 1, 0, 0, buf); } CU_ASSERT_EQUAL(ret, 0); @@ -141,7 +142,6 @@ test_writesame16_unmap(void) "BlockLimits VPD is missing."); CU_FAIL("[FAILED] WRITESAME16 works but " "BlockLimits VPD is missing."); - free(buf); return; } @@ -153,16 +153,17 @@ test_writesame16_unmap(void) "lengths"); logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); - memset(buf, 0xff, block_size * i); + memset(buf, 0xff, i * block_size); ret = write16(iscsic, tgt_lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0, buf); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i); + memset(buf, 0, block_size); ret = writesame16(iscsic, tgt_lun, 0, block_size, i, - 0, 1, 0, 0, NULL); + 0, 1, 0, 0, buf); CU_ASSERT_EQUAL(ret, 0); if (rc16->lbprz) { @@ -191,12 +192,11 @@ test_writesame16_unmap(void) logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i); ret = writesame16_invalidfieldincdb(iscsic, tgt_lun, 0, block_size, i, - 0, 1, 0, 0, NULL); + 0, 1, 0, 0, buf); CU_ASSERT_EQUAL(ret, 0); } - i = 65536; if (inq_bl->max_ws_len == 0 || inq_bl->max_ws_len >= 256) { logging(LOG_VERBOSE, "Block Limits VPD page reports MAX_WS_LEN " @@ -205,16 +205,17 @@ test_writesame16_unmap(void) "lengths"); logging(LOG_VERBOSE, "Write %d blocks of 0xFF", i); - memset(buf, 0xff, block_size * i); + memset(buf, 0xff, i * block_size); ret = write16(iscsic, tgt_lun, 0, i * block_size, block_size, 0, 0, 0, 0, 0, buf); CU_ASSERT_EQUAL(ret, 0); logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i); + memset(buf, 0, block_size); ret = writesame16(iscsic, tgt_lun, 0, block_size, i, - 0, 1, 0, 0, NULL); + 0, 1, 0, 0, buf); CU_ASSERT_EQUAL(ret, 0); if (rc16->lbprz) { @@ -243,9 +244,8 @@ test_writesame16_unmap(void) logging(LOG_VERBOSE, "Unmap %d blocks using WRITESAME16", i); ret = writesame16_invalidfieldincdb(iscsic, tgt_lun, 0, block_size, i, - 0, 1, 0, 0, NULL); + 0, 1, 0, 0, buf); CU_ASSERT_EQUAL(ret, 0); } - free(buf); } diff --git a/test-tool/test_writesame16_unmap_vpd.c b/test-tool/test_writesame16_unmap_vpd.c index 4d9e805..782606e 100644 --- a/test-tool/test_writesame16_unmap_vpd.c +++ b/test-tool/test_writesame16_unmap_vpd.c @@ -16,6 +16,7 @@ */ #include +#include #include @@ -29,6 +30,7 @@ void test_writesame16_unmap_vpd(void) { int ret; + unsigned char *buf = alloca(block_size); logging(LOG_VERBOSE, LOG_BLANK_LINE); logging(LOG_VERBOSE, "Test WRITESAME16 UNMAP availability is " @@ -40,9 +42,10 @@ test_writesame16_unmap_vpd(void) logging(LOG_VERBOSE, "Check if WRITESAME16 can be used for UNMAP."); logging(LOG_VERBOSE, "Unmap 1 block using WRITESAME16"); + memset(buf, 0, block_size); ret = writesame16(iscsic, tgt_lun, 0, block_size, 1, - 0, 1, 0, 0, NULL); + 0, 1, 0, 0, buf); if (ret != 0) { logging(LOG_VERBOSE, "WRITESAME16 UNMAP is not available. " diff --git a/test-tool/test_writesame16_wrprotect.c b/test-tool/test_writesame16_wrprotect.c index a36a28b..1e30584 100644 --- a/test-tool/test_writesame16_wrprotect.c +++ b/test-tool/test_writesame16_wrprotect.c @@ -41,6 +41,7 @@ test_writesame16_wrprotect(void) CHECK_FOR_DATALOSS; CHECK_FOR_SBC; + memset(buf, 0, block_size); if (!inq->protect || (rc16 != NULL && !rc16->prot_en)) { logging(LOG_VERBOSE, "Device does not support/use protection information. All commands should fail."); for (i = 1; i < 8; i++) {