Merge pull request #195 from ddiss/abort_nocancel
Remove local cancellation from ABORT TASK path and add simple test
This commit is contained in:
@@ -82,6 +82,11 @@ EXTERN int iscsi_service(struct iscsi_context *iscsi, int revents);
|
||||
* How many commands are in flight.
|
||||
*/
|
||||
EXTERN int iscsi_queue_length(struct iscsi_context *iscsi);
|
||||
/*
|
||||
* How many commands are queued for dispatch.
|
||||
*/
|
||||
EXTERN int iscsi_out_queue_length(struct iscsi_context *iscsi);
|
||||
|
||||
|
||||
/************************************************************
|
||||
* Timeout Handling.
|
||||
@@ -595,6 +600,17 @@ enum iscsi_task_mgmt_funcs {
|
||||
ISCSI_TM_TASK_REASSIGN = 0x08
|
||||
};
|
||||
|
||||
enum iscsi_task_mgmt_response {
|
||||
ISCSI_TMR_FUNC_COMPLETE = 0x0,
|
||||
ISCSI_TMR_TASK_DOES_NOT_EXIST = 0x1,
|
||||
ISCSI_TMR_LUN_DOES_NOT_EXIST = 0x2,
|
||||
ISCSI_TMR_TASK_STILL_ALLEGIANT = 0x3,
|
||||
ISCSI_TMR_TASK_ALLEGIANCE_REASS_NOT_SUPPORTED = 0x4,
|
||||
ISCSI_TMR_TMF_NOT_SUPPORTED = 0x5,
|
||||
ISCSI_TMR_FUNC_AUTH_FAILED = 0x6,
|
||||
ISCSI_TMR_FUNC_REJECTED = 0xFF
|
||||
};
|
||||
|
||||
/*
|
||||
* Asynchronous call for task management
|
||||
*
|
||||
|
||||
@@ -46,6 +46,7 @@ iscsi_prefetch16_task
|
||||
iscsi_preventallow_sync
|
||||
iscsi_preventallow_task
|
||||
iscsi_queue_length
|
||||
iscsi_out_queue_length
|
||||
iscsi_queue_pdu
|
||||
iscsi_read10_sync
|
||||
iscsi_read10_task
|
||||
|
||||
@@ -44,6 +44,7 @@ iscsi_prefetch16_task
|
||||
iscsi_preventallow_sync
|
||||
iscsi_preventallow_task
|
||||
iscsi_queue_length
|
||||
iscsi_out_queue_length
|
||||
iscsi_queue_pdu
|
||||
iscsi_read10_sync
|
||||
iscsi_read10_task
|
||||
|
||||
13
lib/socket.c
13
lib/socket.c
@@ -439,6 +439,19 @@ iscsi_queue_length(struct iscsi_context *iscsi)
|
||||
return i;
|
||||
}
|
||||
|
||||
int
|
||||
iscsi_out_queue_length(struct iscsi_context *iscsi)
|
||||
{
|
||||
int i = 0;
|
||||
struct iscsi_pdu *pdu;
|
||||
|
||||
for (pdu = iscsi->outqueue; pdu; pdu = pdu->next) {
|
||||
i++;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
ssize_t
|
||||
iscsi_iovector_readv_writev(struct iscsi_context *iscsi, struct scsi_iovector *iovector, uint32_t pos, ssize_t count, int do_write)
|
||||
{
|
||||
|
||||
@@ -276,8 +276,6 @@ int
|
||||
iscsi_task_mgmt_abort_task_sync(struct iscsi_context *iscsi,
|
||||
struct scsi_task *task)
|
||||
{
|
||||
iscsi_scsi_cancel_task(iscsi, task);
|
||||
|
||||
return iscsi_task_mgmt_sync(iscsi, task->lun,
|
||||
ISCSI_TM_ABORT_TASK,
|
||||
task->itt, task->cmdsn);
|
||||
|
||||
@@ -101,14 +101,11 @@ iscsi_process_task_mgmt_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
iscsi_task_mgmt_abort_task_async(struct iscsi_context *iscsi,
|
||||
struct scsi_task *task,
|
||||
iscsi_command_cb cb, void *private_data)
|
||||
{
|
||||
iscsi_scsi_cancel_task(iscsi, task);
|
||||
|
||||
return iscsi_task_mgmt_async(iscsi,
|
||||
task->lun, ISCSI_TM_ABORT_TASK,
|
||||
task->itt, task->cmdsn,
|
||||
|
||||
@@ -224,7 +224,8 @@ iscsi_test_cu_SOURCES = iscsi-test-cu.c \
|
||||
test_multipathio_compareandwrite.c \
|
||||
test_multipathio_async_caw.c \
|
||||
test_async_read.c \
|
||||
test_async_write.c
|
||||
test_async_write.c \
|
||||
test_async_abort_simple.c
|
||||
|
||||
endif
|
||||
|
||||
|
||||
@@ -3028,3 +3028,22 @@ test_iscsi_tur_until_good(struct scsi_device *iscsi_sd, int *num_uas)
|
||||
|
||||
return -ETIMEDOUT;
|
||||
}
|
||||
|
||||
uint64_t
|
||||
test_get_clock_sec(void)
|
||||
{
|
||||
uint64_t secs;
|
||||
int res;
|
||||
|
||||
#ifdef HAVE_CLOCK_GETTIME
|
||||
struct timespec ts;
|
||||
res = clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
secs = ts.tv_sec;
|
||||
#else
|
||||
struct timeval tv;
|
||||
res = gettimeofday(&tv, NULL);
|
||||
secs = tv.tv_sec;
|
||||
#endif
|
||||
assert(res == 0);
|
||||
return secs;
|
||||
}
|
||||
|
||||
@@ -859,4 +859,7 @@ int receive_copy_results(struct scsi_task **task, struct scsi_device *sdev,
|
||||
void **datap, int status, enum scsi_sense_key key,
|
||||
int *ascq, int num_ascq);
|
||||
int test_iscsi_tur_until_good(struct scsi_device *iscsi_sd, int *num_uas);
|
||||
|
||||
uint64_t test_get_clock_sec(void);
|
||||
|
||||
#endif /* _ISCSI_SUPPORT_H_ */
|
||||
|
||||
@@ -559,6 +559,11 @@ static CU_TestInfo tests_iscsi_residuals[] = {
|
||||
CU_TEST_INFO_NULL
|
||||
};
|
||||
|
||||
static CU_TestInfo tests_iscsi_tmf[] = {
|
||||
{ "AbortTaskSimpleAsync", test_async_abort_simple },
|
||||
CU_TEST_INFO_NULL
|
||||
};
|
||||
|
||||
/* iSCSI protocol tests */
|
||||
static libiscsi_suite_info iscsi_suites[] = {
|
||||
{ "iSCSIcmdsn", NON_PGR_FUNCS,
|
||||
@@ -567,6 +572,8 @@ static libiscsi_suite_info iscsi_suites[] = {
|
||||
tests_iscsi_datasn },
|
||||
{ "iSCSIResiduals", NON_PGR_FUNCS,
|
||||
tests_iscsi_residuals },
|
||||
{ "iSCSITMF", NON_PGR_FUNCS,
|
||||
tests_iscsi_tmf },
|
||||
{ NULL, NULL, NULL, NULL, NULL, NULL }
|
||||
};
|
||||
|
||||
@@ -621,6 +628,7 @@ static libiscsi_suite_info all_suites[] = {
|
||||
{ "iSCSIcmdsn", NON_PGR_FUNCS, tests_iscsi_cmdsn },
|
||||
{ "iSCSIdatasn", NON_PGR_FUNCS, tests_iscsi_datasn },
|
||||
{ "iSCSIResiduals", NON_PGR_FUNCS, tests_iscsi_residuals },
|
||||
{ "iSCSITMF", NON_PGR_FUNCS, tests_iscsi_tmf },
|
||||
{ "MultipathIO", NON_PGR_FUNCS, tests_multipathio },
|
||||
{ NULL, NULL, NULL, NULL, NULL, NULL },
|
||||
};
|
||||
|
||||
@@ -311,4 +311,6 @@ void test_multipathio_reset(void);
|
||||
void test_multipathio_compareandwrite(void);
|
||||
void test_mpio_async_caw(void);
|
||||
|
||||
void test_async_abort_simple(void);
|
||||
|
||||
#endif /* _ISCSI_TEST_CU_H_ */
|
||||
|
||||
202
test-tool/test_async_abort_simple.c
Normal file
202
test-tool/test_async_abort_simple.c
Normal file
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
Copyright (C) SUSE LINUX GmbH 2016
|
||||
|
||||
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
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <signal.h>
|
||||
#include <poll.h>
|
||||
|
||||
#include <CUnit/CUnit.h>
|
||||
|
||||
#include "iscsi.h"
|
||||
#include "scsi-lowlevel.h"
|
||||
#include "iscsi-support.h"
|
||||
#include "iscsi-test-cu.h"
|
||||
|
||||
struct tests_async_abort_state {
|
||||
struct scsi_task *wtask;
|
||||
uint32_t wr_cancelled;
|
||||
uint32_t wr_good;
|
||||
uint32_t abort_ok;
|
||||
uint32_t abort_bad_itt;
|
||||
};
|
||||
|
||||
static void
|
||||
test_async_write_cb(struct iscsi_context *iscsi __attribute__((unused)),
|
||||
int status, void *command_data,
|
||||
void *private_data)
|
||||
{
|
||||
struct scsi_task *wtask = command_data;
|
||||
struct tests_async_abort_state *state = private_data;
|
||||
|
||||
if (status == SCSI_STATUS_GOOD) {
|
||||
state->wr_good++;
|
||||
logging(LOG_VERBOSE, "WRITE10 successful: (CmdSN=0x%x, "
|
||||
"ITT=0x%x)", wtask->cmdsn, wtask->itt);
|
||||
} else if (status == SCSI_STATUS_CANCELLED) {
|
||||
state->wr_cancelled++;
|
||||
logging(LOG_VERBOSE, "WRITE10 cancelled: (CmdSN=0x%x, "
|
||||
"ITT=0x%x)", wtask->cmdsn, wtask->itt);
|
||||
} else {
|
||||
CU_ASSERT_NOT_EQUAL(status, SCSI_STATUS_CHECK_CONDITION);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_async_abort_cb(struct iscsi_context *iscsi __attribute__((unused)),
|
||||
int status, void *command_data,
|
||||
void *private_data)
|
||||
{
|
||||
uint32_t tmf_response = *(uint32_t *)command_data;
|
||||
struct tests_async_abort_state *state = private_data;
|
||||
|
||||
logging(LOG_VERBOSE, "ABORT TASK: TMF response %d for"
|
||||
" RefCmdSN=0x%x, RefITT=0x%x",
|
||||
tmf_response, state->wtask->cmdsn, state->wtask->itt);
|
||||
if (tmf_response == ISCSI_TMR_FUNC_COMPLETE) {
|
||||
state->abort_ok++;
|
||||
logging(LOG_VERBOSE, "ABORT TASK completed");
|
||||
} else if (tmf_response == ISCSI_TMR_TASK_DOES_NOT_EXIST) {
|
||||
/* expected if the write has already been handled by the tgt */
|
||||
state->abort_bad_itt++;
|
||||
logging(LOG_VERBOSE, "ABORT TASK bad ITT");
|
||||
} else {
|
||||
logging(LOG_NORMAL, "ABORT TASK: unexpected TMF response %d for"
|
||||
" RefCmdSN=0x%x, RefITT=0x%x",
|
||||
tmf_response, state->wtask->cmdsn, state->wtask->itt);
|
||||
CU_ASSERT_FATAL((tmf_response != ISCSI_TMR_FUNC_COMPLETE)
|
||||
&& (tmf_response != ISCSI_TMR_TASK_DOES_NOT_EXIST));
|
||||
}
|
||||
CU_ASSERT_NOT_EQUAL(status, SCSI_STATUS_CHECK_CONDITION);
|
||||
}
|
||||
|
||||
void
|
||||
test_async_abort_simple(void)
|
||||
{
|
||||
int ret;
|
||||
struct tests_async_abort_state state = { 0 };
|
||||
int blocksize = 512;
|
||||
int blocks_per_io = 8;
|
||||
unsigned char buf[blocksize * blocks_per_io];
|
||||
uint64_t timeout_sec;
|
||||
|
||||
CHECK_FOR_DATALOSS;
|
||||
CHECK_FOR_SBC;
|
||||
if (sd->iscsi_ctx == NULL) {
|
||||
CU_PASS("[SKIPPED] Non-iSCSI");
|
||||
return;
|
||||
}
|
||||
|
||||
if (maximum_transfer_length
|
||||
&& (maximum_transfer_length < (int)(blocks_per_io))) {
|
||||
CU_PASS("[SKIPPED] device too small for async_abort test");
|
||||
return;
|
||||
}
|
||||
|
||||
memset(buf, 0, blocksize * blocks_per_io);
|
||||
|
||||
/* queue and dispatch write before the abort */
|
||||
state.wtask = scsi_cdb_write10(0, blocks_per_io * blocksize,
|
||||
blocksize, 0, 0, 0, 0, 0);
|
||||
CU_ASSERT_PTR_NOT_NULL_FATAL(state.wtask);
|
||||
|
||||
ret = scsi_task_add_data_out_buffer(state.wtask,
|
||||
blocks_per_io * blocksize,
|
||||
buf);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
ret = iscsi_scsi_command_async(sd->iscsi_ctx, sd->iscsi_lun,
|
||||
state.wtask, test_async_write_cb, NULL,
|
||||
&state);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "WRITE10 queued: (CmdSN=0x%x, ITT=0x%x)",
|
||||
state.wtask->cmdsn, state.wtask->itt);
|
||||
|
||||
CU_ASSERT_EQUAL(iscsi_out_queue_length(sd->iscsi_ctx), 1);
|
||||
|
||||
logging(LOG_VERBOSE, "dispatching out queue...");
|
||||
while ((uint32_t)iscsi_out_queue_length(sd->iscsi_ctx) > 0) {
|
||||
struct pollfd pfd;
|
||||
|
||||
pfd.fd = iscsi_get_fd(sd->iscsi_ctx);
|
||||
pfd.events = POLLOUT; /* only send */
|
||||
|
||||
ret = poll(&pfd, 1, 1000);
|
||||
CU_ASSERT_NOT_EQUAL(ret, -1);
|
||||
|
||||
ret = iscsi_service(sd->iscsi_ctx, pfd.revents);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
}
|
||||
logging(LOG_VERBOSE, "dispatched");
|
||||
|
||||
/*
|
||||
* queue abort - shouldn't cancel the dispatched task. TMF req should
|
||||
* be sent to the target.
|
||||
*/
|
||||
ret = iscsi_task_mgmt_async(sd->iscsi_ctx,
|
||||
state.wtask->lun, ISCSI_TM_ABORT_TASK,
|
||||
state.wtask->itt, state.wtask->cmdsn,
|
||||
test_async_abort_cb, &state);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
logging(LOG_VERBOSE, "ABORT queued: (RefCmdSN=0x%x, "
|
||||
"RefITT=0x%x)", state.wtask->cmdsn, state.wtask->itt);
|
||||
|
||||
/*
|
||||
* wait for all responses, timeout in 5 seconds. Expected responses:
|
||||
* + WRITE:good, ABORT:bad_itt - write completed before abort
|
||||
* + WRITE:no-response, ABORT:ok - write aborted
|
||||
*/
|
||||
logging(LOG_VERBOSE, "dispatching abort and handling responses...");
|
||||
timeout_sec = test_get_clock_sec() + 5;
|
||||
while (test_get_clock_sec() <= timeout_sec) {
|
||||
struct pollfd pfd;
|
||||
|
||||
pfd.fd = iscsi_get_fd(sd->iscsi_ctx);
|
||||
pfd.events = iscsi_which_events(sd->iscsi_ctx);
|
||||
|
||||
ret = poll(&pfd, 1, 1000);
|
||||
CU_ASSERT_NOT_EQUAL(ret, -1);
|
||||
|
||||
ret = iscsi_service(sd->iscsi_ctx, pfd.revents);
|
||||
CU_ASSERT_EQUAL(ret, 0);
|
||||
|
||||
if (((state.wr_good == 1) && (state.abort_bad_itt == 1))
|
||||
|| (state.abort_ok == 1)) {
|
||||
logging(LOG_VERBOSE, "received all expected responses");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
logging(LOG_VERBOSE, "%d IOs completed, %d aborts successful, "
|
||||
"%d aborts unsuccessful",
|
||||
state.wr_good, state.abort_ok, state.abort_bad_itt);
|
||||
|
||||
if (state.abort_ok == 1) {
|
||||
CU_ASSERT_EQUAL(state.wr_good, 0);
|
||||
CU_ASSERT_EQUAL(state.wr_cancelled, 0);
|
||||
CU_ASSERT_EQUAL(state.abort_bad_itt, 0);
|
||||
} else if (state.abort_bad_itt == 1) {
|
||||
CU_ASSERT_EQUAL(state.wr_good, 1);
|
||||
CU_ASSERT_EQUAL(state.wr_cancelled, 0);
|
||||
CU_ASSERT_EQUAL(state.abort_ok, 0);
|
||||
} else {
|
||||
CU_FAIL("unexpected WRITE/ABORT state");
|
||||
}
|
||||
|
||||
scsi_free_scsi_task(state.wtask);
|
||||
}
|
||||
Reference in New Issue
Block a user