Spdk/test/unit/lib/iscsi/common.c

269 lines
4.3 KiB
C
Raw Normal View History

#include "iscsi/task.h"
#include "iscsi/iscsi.h"
#include "iscsi/conn.h"
#include "iscsi/acceptor.h"
#include "spdk/env.h"
#include "spdk/event.h"
#include "spdk/sock.h"
#include "spdk_cunit.h"
#include "spdk_internal/log.h"
#include "scsi/scsi_internal.h"
SPDK_LOG_REGISTER_COMPONENT("iscsi", SPDK_LOG_ISCSI)
TAILQ_HEAD(, spdk_iscsi_pdu) g_write_pdu_list;
struct spdk_iscsi_task *
spdk_iscsi_task_get(struct spdk_iscsi_conn *conn,
struct spdk_iscsi_task *parent,
spdk_scsi_task_cpl cpl_fn)
{
struct spdk_iscsi_task *task;
task = calloc(1, sizeof(*task));
iscsi: Abort queued datain task before submitting abort to SCSI layer By up to the previous patch in the patch series, unexpected behavior due to write tasks in task management commands have been fixed. But unexpected behavior due to read tasks in task management commands have been still observed. Remaining patches in the patch series will fix the unexpected behavior due to read tasks in task management commands. This patch is for ABORT TASK. ABORT TASK is not supported in SCSI layer yet. But the initiator doesn't care about the failure is due to not-supported or failure. It must be avoided that the task management command returns SCSI Good but some tasks are not aborted and return SCSI Good later. On the other hand, it is acceptable that the task management command returns failure but some tasks are partially aborted. Hence this patch adds operation without checking the support status in SCSI layer. iSCSI layer doesn't have pending queue and hence if the target task is read task and is queued in queued_datain_tasks, it must be aborted before submitting ABORT TASK to SCSI layer. Aborting the target task may not complete by an iteration because submitted read tasks are limited. Hence use poller to complete abortion by repetition. Change-Id: I030a8b2f19c2f7c7d2f7b0b2c633579534db631b Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-on: https://review.gerrithub.io/436076 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
2018-12-09 23:12:11 +00:00
if (!task) {
return NULL;
}
task->scsi.iovs = &task->scsi.iov;
return task;
}
void
spdk_scsi_task_put(struct spdk_scsi_task *task)
{
free(task);
}
void
spdk_put_pdu(struct spdk_iscsi_pdu *pdu)
{
if (!pdu) {
return;
}
pdu->ref--;
if (pdu->ref < 0) {
CU_FAIL("negative ref count");
pdu->ref = 0;
}
if (pdu->ref == 0) {
if (pdu->data && !pdu->data_from_mempool) {
free(pdu->data);
}
free(pdu);
}
}
struct spdk_iscsi_pdu *
spdk_get_pdu(void)
{
struct spdk_iscsi_pdu *pdu;
pdu = malloc(sizeof(*pdu));
if (!pdu) {
return NULL;
}
memset(pdu, 0, offsetof(struct spdk_iscsi_pdu, ahs));
pdu->ref = 1;
return pdu;
}
void
spdk_scsi_task_process_null_lun(struct spdk_scsi_task *task)
{
}
iscsi: Abort queued datain task before submitting abort to SCSI layer By up to the previous patch in the patch series, unexpected behavior due to write tasks in task management commands have been fixed. But unexpected behavior due to read tasks in task management commands have been still observed. Remaining patches in the patch series will fix the unexpected behavior due to read tasks in task management commands. This patch is for ABORT TASK. ABORT TASK is not supported in SCSI layer yet. But the initiator doesn't care about the failure is due to not-supported or failure. It must be avoided that the task management command returns SCSI Good but some tasks are not aborted and return SCSI Good later. On the other hand, it is acceptable that the task management command returns failure but some tasks are partially aborted. Hence this patch adds operation without checking the support status in SCSI layer. iSCSI layer doesn't have pending queue and hence if the target task is read task and is queued in queued_datain_tasks, it must be aborted before submitting ABORT TASK to SCSI layer. Aborting the target task may not complete by an iteration because submitted read tasks are limited. Hence use poller to complete abortion by repetition. Change-Id: I030a8b2f19c2f7c7d2f7b0b2c633579534db631b Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-on: https://review.gerrithub.io/436076 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
2018-12-09 23:12:11 +00:00
void
spdk_scsi_task_process_abort(struct spdk_scsi_task *task)
{
}
void
spdk_scsi_dev_queue_task(struct spdk_scsi_dev *dev,
struct spdk_scsi_task *task)
{
}
struct spdk_scsi_port *
spdk_scsi_dev_find_port_by_id(struct spdk_scsi_dev *dev, uint64_t id)
{
return NULL;
}
void
spdk_scsi_dev_queue_mgmt_task(struct spdk_scsi_dev *dev,
struct spdk_scsi_task *task)
{
}
const char *
spdk_scsi_dev_get_name(const struct spdk_scsi_dev *dev)
{
if (dev != NULL) {
return dev->name;
}
return NULL;
}
void
spdk_iscsi_acceptor_start(struct spdk_iscsi_portal *p)
{
}
void
spdk_iscsi_acceptor_stop(struct spdk_iscsi_portal *p)
{
}
struct spdk_sock *
spdk_sock_listen(const char *ip, int port)
{
static int g_sock;
return (struct spdk_sock *)&g_sock;
}
int
spdk_sock_close(struct spdk_sock **sock)
{
*sock = NULL;
return 0;
}
static struct spdk_cpuset *g_app_core_mask;
struct spdk_cpuset *
spdk_app_get_core_mask(void)
{
int i;
if (!g_app_core_mask) {
g_app_core_mask = spdk_cpuset_alloc();
for (i = 0; i < SPDK_CPUSET_SIZE; i++) {
spdk_cpuset_set_cpu(g_app_core_mask, i, true);
}
}
return g_app_core_mask;
}
int
spdk_app_parse_core_mask(const char *mask, struct spdk_cpuset *cpumask)
{
int rc;
if (mask == NULL || cpumask == NULL) {
return -1;
}
rc = spdk_cpuset_parse(cpumask, mask);
if (rc < 0) {
return -1;
}
return 0;
}
uint32_t
spdk_env_get_current_core(void)
{
return 0;
}
struct spdk_event *
spdk_event_allocate(uint32_t core, spdk_event_fn fn, void *arg1, void *arg2)
{
return NULL;
}
struct spdk_scsi_dev *
spdk_scsi_dev_construct(const char *name, const char **bdev_name_list,
int *lun_id_list, int num_luns, uint8_t protocol_id,
void (*hotremove_cb)(const struct spdk_scsi_lun *, void *),
void *hotremove_ctx)
{
return NULL;
}
void
spdk_scsi_dev_destruct(struct spdk_scsi_dev *dev)
{
}
int
spdk_scsi_dev_add_port(struct spdk_scsi_dev *dev, uint64_t id, const char *name)
{
return 0;
}
int
spdk_iscsi_drop_conns(struct spdk_iscsi_conn *conn, const char *conn_match,
int drop_all)
{
return 0;
}
int
spdk_scsi_dev_delete_port(struct spdk_scsi_dev *dev, uint64_t id)
{
return 0;
}
void
spdk_shutdown_iscsi_conns(void)
{
}
void
spdk_iscsi_task_cpl(struct spdk_scsi_task *scsi_task)
{
iscsi: Abort queued datain task before submitting abort to SCSI layer By up to the previous patch in the patch series, unexpected behavior due to write tasks in task management commands have been fixed. But unexpected behavior due to read tasks in task management commands have been still observed. Remaining patches in the patch series will fix the unexpected behavior due to read tasks in task management commands. This patch is for ABORT TASK. ABORT TASK is not supported in SCSI layer yet. But the initiator doesn't care about the failure is due to not-supported or failure. It must be avoided that the task management command returns SCSI Good but some tasks are not aborted and return SCSI Good later. On the other hand, it is acceptable that the task management command returns failure but some tasks are partially aborted. Hence this patch adds operation without checking the support status in SCSI layer. iSCSI layer doesn't have pending queue and hence if the target task is read task and is queued in queued_datain_tasks, it must be aborted before submitting ABORT TASK to SCSI layer. Aborting the target task may not complete by an iteration because submitted read tasks are limited. Hence use poller to complete abortion by repetition. Change-Id: I030a8b2f19c2f7c7d2f7b0b2c633579534db631b Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-on: https://review.gerrithub.io/436076 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
2018-12-09 23:12:11 +00:00
struct spdk_iscsi_task *iscsi_task;
iscsi: Abort queued datain task before submitting abort to SCSI layer By up to the previous patch in the patch series, unexpected behavior due to write tasks in task management commands have been fixed. But unexpected behavior due to read tasks in task management commands have been still observed. Remaining patches in the patch series will fix the unexpected behavior due to read tasks in task management commands. This patch is for ABORT TASK. ABORT TASK is not supported in SCSI layer yet. But the initiator doesn't care about the failure is due to not-supported or failure. It must be avoided that the task management command returns SCSI Good but some tasks are not aborted and return SCSI Good later. On the other hand, it is acceptable that the task management command returns failure but some tasks are partially aborted. Hence this patch adds operation without checking the support status in SCSI layer. iSCSI layer doesn't have pending queue and hence if the target task is read task and is queued in queued_datain_tasks, it must be aborted before submitting ABORT TASK to SCSI layer. Aborting the target task may not complete by an iteration because submitted read tasks are limited. Hence use poller to complete abortion by repetition. Change-Id: I030a8b2f19c2f7c7d2f7b0b2c633579534db631b Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-on: https://review.gerrithub.io/436076 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
2018-12-09 23:12:11 +00:00
if (scsi_task != NULL) {
iscsi_task = spdk_iscsi_task_from_scsi_task(scsi_task);
free(iscsi_task);
}
}
void
spdk_iscsi_task_mgmt_cpl(struct spdk_scsi_task *scsi_task)
{
}
int
spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int bytes,
void *buf)
{
return 0;
}
void
spdk_iscsi_conn_write_pdu(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu)
{
TAILQ_INSERT_TAIL(&g_write_pdu_list, pdu, tailq);
}
void
spdk_iscsi_conn_logout(struct spdk_iscsi_conn *conn)
{
}
void
spdk_scsi_task_set_status(struct spdk_scsi_task *task, int sc, int sk, int asc, int ascq)
{
}
void
spdk_scsi_task_set_data(struct spdk_scsi_task *task, void *data, uint32_t len)
{
SPDK_CU_ASSERT_FATAL(task->iovs != NULL);
task->iovs[0].iov_base = data;
task->iovs[0].iov_len = len;
}