diff --git a/include/spdk/scsi.h b/include/spdk/scsi.h index 8f6e81cd0..4d6fa948c 100644 --- a/include/spdk/scsi.h +++ b/include/spdk/scsi.h @@ -72,11 +72,6 @@ enum spdk_scsi_task_func { SPDK_SCSI_TASK_FUNC_LUN_RESET, }; -enum spdk_scsi_task_type { - SPDK_SCSI_TASK_TYPE_CMD = 0, - SPDK_SCSI_TASK_TYPE_MANAGE, -}; - /* * SAM does not define the value for these service responses. Each transport * (i.e. SAS, FC, iSCSI) will map these value to transport-specific codes, @@ -91,8 +86,11 @@ enum spdk_scsi_task_mgmt_resp { SPDK_SCSI_TASK_MGMT_RESP_REJECT_FUNC_NOT_SUPPORTED }; +struct spdk_scsi_task; +typedef void (*spdk_scsi_task_cpl)(struct spdk_scsi_task *task); +typedef void (*spdk_scsi_task_free)(struct spdk_scsi_task *task); + struct spdk_scsi_task { - uint8_t type; uint8_t status; uint8_t function; /* task mgmt function */ uint8_t response; /* task mgmt response */ @@ -100,7 +98,9 @@ struct spdk_scsi_task { struct spdk_io_channel *ch; struct spdk_scsi_port *target_port; struct spdk_scsi_port *initiator_port; - struct spdk_event *cb_event; + + spdk_scsi_task_cpl cpl_fn; + spdk_scsi_task_free free_fn; uint32_t ref; uint32_t transfer_len; @@ -116,8 +116,6 @@ struct spdk_scsi_task { uint64_t offset; struct spdk_scsi_task *parent; - void (*free_fn)(struct spdk_scsi_task *); - uint8_t *cdb; /** @@ -208,7 +206,8 @@ const char *spdk_scsi_port_get_name(const struct spdk_scsi_port *port); void spdk_scsi_task_construct(struct spdk_scsi_task *task, - void (*free_fn)(struct spdk_scsi_task *task), + spdk_scsi_task_cpl cpl_fn, + spdk_scsi_task_free free_fn, struct spdk_scsi_task *parent); void spdk_scsi_task_put(struct spdk_scsi_task *task); diff --git a/lib/iscsi/conn.c b/lib/iscsi/conn.c index f309460f6..0cc17c4c6 100644 --- a/lib/iscsi/conn.c +++ b/lib/iscsi/conn.c @@ -847,13 +847,12 @@ spdk_iscsi_conn_read_data(struct spdk_iscsi_conn *conn, int bytes, } void -process_task_mgmt_completion(void *arg1, void *arg2) +spdk_iscsi_task_mgmt_cpl(struct spdk_scsi_task *scsi_task) { - struct spdk_iscsi_conn *conn = arg1; - struct spdk_iscsi_task *task = arg2; + struct spdk_iscsi_task *task = spdk_iscsi_task_from_scsi_task(scsi_task); - conn->last_activity_tsc = spdk_get_ticks(); - spdk_iscsi_task_mgmt_response(conn, task); + task->conn->last_activity_tsc = spdk_get_ticks(); + spdk_iscsi_task_mgmt_response(task->conn, task); spdk_iscsi_task_put(task); } @@ -909,11 +908,12 @@ process_read_task_completion(struct spdk_iscsi_conn *conn, process_completed_read_subtask_list(conn, primary); } -void process_task_completion(void *arg1, void *arg2) +void +spdk_iscsi_task_cpl(struct spdk_scsi_task *scsi_task) { - struct spdk_iscsi_conn *conn = arg1; - struct spdk_iscsi_task *task = arg2; struct spdk_iscsi_task *primary; + struct spdk_iscsi_task *task = spdk_iscsi_task_from_scsi_task(scsi_task); + struct spdk_iscsi_conn *conn = task->conn; assert(task != NULL); spdk_trace_record(TRACE_ISCSI_TASK_DONE, conn->id, 0, (uintptr_t)task, 0); diff --git a/lib/iscsi/iscsi.c b/lib/iscsi/iscsi.c index 9c082c174..998b2d920 100644 --- a/lib/iscsi/iscsi.c +++ b/lib/iscsi/iscsi.c @@ -2830,8 +2830,6 @@ spdk_iscsi_compare_pdu_bhs_within_existed_r2t_tasks(struct spdk_iscsi_conn *conn static void spdk_iscsi_queue_task(struct spdk_iscsi_conn *conn, struct spdk_iscsi_task *task) { - task->scsi.cb_event = spdk_event_allocate(spdk_env_get_current_core(), process_task_completion, - conn, task); spdk_trace_record(TRACE_ISCSI_TASK_QUEUE, conn->id, task->scsi.length, (uintptr_t)task, (uintptr_t)task->pdu); spdk_scsi_dev_queue_task(conn->dev, &task->scsi); @@ -2841,8 +2839,6 @@ static void spdk_iscsi_queue_mgmt_task(struct spdk_iscsi_conn *conn, struct spdk_iscsi_task *task, enum spdk_scsi_task_func func) { - task->scsi.cb_event = spdk_event_allocate(spdk_env_get_current_core(), process_task_mgmt_completion, - conn, task); spdk_scsi_dev_queue_mgmt_task(conn->dev, &task->scsi, func); } @@ -2866,7 +2862,7 @@ int spdk_iscsi_conn_handle_queued_tasks(struct spdk_iscsi_conn *conn) uint32_t remaining_size = 0; remaining_size = task->scsi.transfer_len - task->current_datain_offset; - subtask = spdk_iscsi_task_get(conn, task); + subtask = spdk_iscsi_task_get(conn, task, spdk_iscsi_task_cpl); assert(subtask != NULL); subtask->scsi.offset = task->current_datain_offset; subtask->scsi.length = DMIN32(SPDK_BDEV_LARGE_BUF_MAX_SIZE, remaining_size); @@ -2937,7 +2933,7 @@ spdk_iscsi_op_scsi(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu) SPDK_TRACEDUMP(SPDK_TRACE_DEBUG, "CDB", cdb, 16); - task = spdk_iscsi_task_get(conn, NULL); + task = spdk_iscsi_task_get(conn, NULL, spdk_iscsi_task_cpl); if (!task) { SPDK_ERRLOG("Unable to acquire task\n"); return SPDK_ISCSI_CONNECTION_FATAL; @@ -2963,7 +2959,7 @@ spdk_iscsi_op_scsi(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu) if (task->scsi.lun == NULL) { spdk_scsi_task_process_null_lun(&task->scsi); - process_task_completion(conn, task); + spdk_iscsi_task_cpl(&task->scsi); return 0; } @@ -3253,7 +3249,7 @@ spdk_iscsi_op_task(struct spdk_iscsi_conn *conn, struct spdk_iscsi_pdu *pdu) lun_i = spdk_islun2lun(lun); dev = conn->dev; - task = spdk_iscsi_task_get(conn, NULL); + task = spdk_iscsi_task_get(conn, NULL, spdk_iscsi_task_mgmt_cpl); if (!task) { SPDK_ERRLOG("Unable to acquire task\n"); return SPDK_ISCSI_CONNECTION_FATAL; @@ -4089,7 +4085,7 @@ static int spdk_iscsi_op_data(struct spdk_iscsi_conn *conn, task->current_r2t_length = 0; } - subtask = spdk_iscsi_task_get(conn, task); + subtask = spdk_iscsi_task_get(conn, task, spdk_iscsi_task_cpl); if (subtask == NULL) { SPDK_ERRLOG("Unable to acquire subtask\n"); return SPDK_ISCSI_CONNECTION_FATAL; diff --git a/lib/iscsi/iscsi.h b/lib/iscsi/iscsi.h index 2308b22f0..fe7af26f8 100644 --- a/lib/iscsi/iscsi.h +++ b/lib/iscsi/iscsi.h @@ -357,8 +357,8 @@ int spdk_iscsi_negotiate_params(struct spdk_iscsi_conn *conn, int alloc_len, int data_len); int spdk_iscsi_copy_param2var(struct spdk_iscsi_conn *conn); -void process_task_completion(void *arg1, void *arg2); -void process_task_mgmt_completion(void *arg1, void *arg2); +void spdk_iscsi_task_cpl(struct spdk_scsi_task *scsi_task); +void spdk_iscsi_task_mgmt_cpl(struct spdk_scsi_task *scsi_task); /* Memory management */ void spdk_put_pdu(struct spdk_iscsi_pdu *pdu); diff --git a/lib/iscsi/task.c b/lib/iscsi/task.c index f8359ef28..a7948f401 100644 --- a/lib/iscsi/task.c +++ b/lib/iscsi/task.c @@ -51,7 +51,8 @@ spdk_iscsi_task_free(struct spdk_scsi_task *scsi_task) } struct spdk_iscsi_task * -spdk_iscsi_task_get(struct spdk_iscsi_conn *conn, struct spdk_iscsi_task *parent) +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; int rc; @@ -67,6 +68,7 @@ spdk_iscsi_task_get(struct spdk_iscsi_conn *conn, struct spdk_iscsi_task *parent assert(conn->pending_task_cnt < UINT32_MAX); conn->pending_task_cnt++; spdk_scsi_task_construct(&task->scsi, + cpl_fn, spdk_iscsi_task_free, parent ? &parent->scsi : NULL); if (parent) { diff --git a/lib/iscsi/task.h b/lib/iscsi/task.h index 568bb293b..5439b3e98 100644 --- a/lib/iscsi/task.h +++ b/lib/iscsi/task.h @@ -155,7 +155,8 @@ spdk_iscsi_task_get_cmdsn(struct spdk_iscsi_task *task) } struct spdk_iscsi_task *spdk_iscsi_task_get(struct spdk_iscsi_conn *conn, - struct spdk_iscsi_task *parent); + struct spdk_iscsi_task *parent, + spdk_scsi_task_cpl cpl_fn); static inline struct spdk_iscsi_task * spdk_iscsi_task_from_scsi_task(struct spdk_scsi_task *task) diff --git a/lib/iscsi/tgt_node.c b/lib/iscsi/tgt_node.c index 1b3a3bc49..158fa9943 100644 --- a/lib/iscsi/tgt_node.c +++ b/lib/iscsi/tgt_node.c @@ -1059,7 +1059,7 @@ spdk_iscsi_tgt_node_cleanup_luns(struct spdk_iscsi_conn *conn, continue; /* we create a fake management task per LUN to cleanup */ - task = spdk_iscsi_task_get(conn, NULL); + task = spdk_iscsi_task_get(conn, NULL, spdk_iscsi_task_mgmt_cpl); if (!task) { SPDK_ERRLOG("Unable to acquire task\n"); return -1; @@ -1069,8 +1069,6 @@ spdk_iscsi_tgt_node_cleanup_luns(struct spdk_iscsi_conn *conn, task->scsi.initiator_port = conn->initiator_port; task->scsi.lun = lun; - task->scsi.cb_event = spdk_event_allocate(spdk_env_get_current_core(), - process_task_mgmt_completion, conn, task); spdk_scsi_dev_queue_mgmt_task(target->dev, &task->scsi, SPDK_SCSI_TASK_FUNC_LUN_RESET); } diff --git a/lib/scsi/dev.c b/lib/scsi/dev.c index ac6d7718a..e932d13d2 100644 --- a/lib/scsi/dev.c +++ b/lib/scsi/dev.c @@ -208,7 +208,6 @@ spdk_scsi_dev_queue_mgmt_task(struct spdk_scsi_dev *dev, { assert(task != NULL); - task->type = SPDK_SCSI_TASK_TYPE_MANAGE; task->function = func; spdk_scsi_lun_task_mgmt_execute(task, func); } @@ -219,7 +218,6 @@ spdk_scsi_dev_queue_task(struct spdk_scsi_dev *dev, { assert(task != NULL); - task->type = SPDK_SCSI_TASK_TYPE_CMD; if (spdk_scsi_lun_append_task(task->lun, task) == 0) { /* ready to execute, disk is valid for LUN access */ spdk_scsi_lun_execute_tasks(task->lun); diff --git a/lib/scsi/lun.c b/lib/scsi/lun.c index 006cb21bb..43fbf6557 100644 --- a/lib/scsi/lun.c +++ b/lib/scsi/lun.c @@ -46,7 +46,7 @@ spdk_scsi_lun_complete_task(struct spdk_scsi_lun *lun, struct spdk_scsi_task *ta TAILQ_REMOVE(&lun->tasks, task, scsi_link); spdk_trace_record(TRACE_SCSI_TASK_DONE, lun->dev->id, 0, (uintptr_t)task, 0); } - spdk_event_call(task->cb_event); + task->cpl_fn(task); } void @@ -56,7 +56,7 @@ spdk_scsi_lun_complete_mgmt_task(struct spdk_scsi_lun *lun, struct spdk_scsi_tas task->status == SPDK_SCSI_STATUS_GOOD) { spdk_scsi_lun_clear_all(task->lun); } - spdk_event_call(task->cb_event); + task->cpl_fn(task); } void diff --git a/lib/scsi/task.c b/lib/scsi/task.c index 2a02ac1f9..bde28a974 100644 --- a/lib/scsi/task.c +++ b/lib/scsi/task.c @@ -66,10 +66,15 @@ spdk_scsi_task_put(struct spdk_scsi_task *task) void spdk_scsi_task_construct(struct spdk_scsi_task *task, - void (*free_fn)(struct spdk_scsi_task *task), + spdk_scsi_task_cpl cpl_fn, + spdk_scsi_task_free free_fn, struct spdk_scsi_task *parent) { + assert(task != NULL); + assert(cpl_fn != NULL); assert(free_fn != NULL); + + task->cpl_fn = cpl_fn; task->free_fn = free_fn; task->ref++; diff --git a/lib/vhost/task.c b/lib/vhost/task.c index 59695283f..5add31df7 100644 --- a/lib/vhost/task.c +++ b/lib/vhost/task.c @@ -43,11 +43,6 @@ #include "spdk/vhost.h" #include "task.h" -#undef container_of -#define container_of(ptr, type, member) ({ \ - typeof(((type *)0)->member) *__mptr = (ptr); \ - (type *)((char *)__mptr - offsetof(type, member)); }) - static struct rte_mempool *g_task_pool; void @@ -66,7 +61,7 @@ spdk_vhost_task_free_cb(struct spdk_scsi_task *scsi_task) } struct spdk_vhost_task * -spdk_vhost_task_get(struct spdk_vhost_scsi_dev *vdev) +spdk_vhost_task_get(struct spdk_vhost_scsi_dev *vdev, spdk_scsi_task_cpl cpl_fn) { struct spdk_vhost_task *task; int rc; @@ -80,7 +75,10 @@ spdk_vhost_task_get(struct spdk_vhost_scsi_dev *vdev) memset(task, 0, sizeof(*task)); task->svdev = vdev; spdk_vhost_dev_task_ref((struct spdk_vhost_dev *) task->svdev); - spdk_scsi_task_construct(&task->scsi, spdk_vhost_task_free_cb, NULL); + spdk_scsi_task_construct(&task->scsi, + cpl_fn, + spdk_vhost_task_free_cb, + NULL); return task; } diff --git a/lib/vhost/task.h b/lib/vhost/task.h index 4126ae99d..e38918792 100644 --- a/lib/vhost/task.h +++ b/lib/vhost/task.h @@ -36,6 +36,11 @@ #include "spdk/scsi.h" +#undef container_of +#define container_of(ptr, type, member) ({ \ + typeof(((type *)0)->member) *__mptr = (ptr); \ + (type *)((char *)__mptr - offsetof(type, member)); }) + /* Allocated iovec buffer len */ #define VHOST_SCSI_IOVS_LEN 128 @@ -59,9 +64,13 @@ struct spdk_vhost_task { }; void spdk_vhost_task_put(struct spdk_vhost_task *task); -struct spdk_vhost_task *spdk_vhost_task_get(struct spdk_vhost_scsi_dev *vdev); +struct spdk_vhost_task *spdk_vhost_task_get(struct spdk_vhost_scsi_dev *vdev, + spdk_scsi_task_cpl cpl_fn); void spdk_vhost_dev_task_ref(struct spdk_vhost_dev *vdev); void spdk_vhost_dev_task_unref(struct spdk_vhost_dev *vdev); +void spdk_vhost_task_cpl(struct spdk_scsi_task *scsi_task); +void spdk_vhost_task_mgmt_cpl(struct spdk_scsi_task *scsi_task); + #endif /* SPDK_VHOST_TASK_H */ diff --git a/lib/vhost/vhost_scsi.c b/lib/vhost/vhost_scsi.c index 9d5a29091..4f8d3522a 100644 --- a/lib/vhost/vhost_scsi.c +++ b/lib/vhost/vhost_scsi.c @@ -106,18 +106,18 @@ submit_completion(struct spdk_vhost_task *task) spdk_vhost_task_put(task); } -static void -process_mgmt_task_completion(void *arg1, void *arg2) +void +spdk_vhost_task_mgmt_cpl(struct spdk_scsi_task *scsi_task) { - struct spdk_vhost_task *task = arg1; + struct spdk_vhost_task *task = container_of(scsi_task, struct spdk_vhost_task, scsi); submit_completion(task); } -static void -process_task_completion(void *arg1, void *arg2) +void +spdk_vhost_task_cpl(struct spdk_scsi_task *scsi_task) { - struct spdk_vhost_task *task = arg1; + struct spdk_vhost_task *task = container_of(scsi_task, struct spdk_vhost_task, scsi); /* The SCSI task has completed. Do final processing and then post notification to the virtqueue's "used" ring. @@ -137,14 +137,11 @@ static void task_submit(struct spdk_vhost_task *task) { /* The task is ready to be submitted. First create the callback event that - will be invoked when the SCSI command is completed. See process_task_completion() + will be invoked when the SCSI command is completed. See spdk_vhost_task_cpl() for what SPDK vhost-scsi does when the task is completed. */ task->resp->response = VIRTIO_SCSI_S_OK; - task->scsi.cb_event = spdk_event_allocate(rte_lcore_id(), - process_task_completion, - task, NULL); spdk_scsi_dev_queue_task(task->scsi_dev, &task->scsi); } @@ -152,9 +149,6 @@ static void mgmt_task_submit(struct spdk_vhost_task *task, enum spdk_scsi_task_func func) { task->tmf_resp->response = VIRTIO_SCSI_S_OK; - task->scsi.cb_event = spdk_event_allocate(rte_lcore_id(), - process_mgmt_task_completion, - task, NULL); spdk_scsi_dev_queue_mgmt_task(task->scsi_dev, &task->scsi, func); } @@ -208,7 +202,7 @@ process_ctrl_request(struct spdk_vhost_scsi_dev *svdev, struct rte_vhost_vring * SPDK_TRACEDUMP(SPDK_TRACE_VHOST_SCSI_QUEUE, "Request desriptor", (uint8_t *)ctrl_req, desc->len); - task = spdk_vhost_task_get(svdev); + task = spdk_vhost_task_get(svdev, spdk_vhost_task_mgmt_cpl); task->vq = controlq; task->svdev = svdev; task->req_idx = req_idx; @@ -429,7 +423,7 @@ process_requestq(struct spdk_vhost_scsi_dev *svdev, struct rte_vhost_vring *vq) assert(reqs_cnt <= 32); for (i = 0; i < reqs_cnt; i++) { - task = spdk_vhost_task_get(svdev); + task = spdk_vhost_task_get(svdev, spdk_vhost_task_cpl); SPDK_TRACELOG(SPDK_TRACE_VHOST_SCSI, "====== Starting processing request idx %"PRIu16"======\n", reqs[i]); @@ -442,7 +436,7 @@ process_requestq(struct spdk_vhost_scsi_dev *svdev, struct rte_vhost_vring *vq) SPDK_TRACELOG(SPDK_TRACE_VHOST_SCSI, "====== Task %p req_idx %d submitted ======\n", task, task->req_idx); } else if (result > 0) { - process_task_completion(task, NULL); + spdk_vhost_task_cpl(&task->scsi); SPDK_TRACELOG(SPDK_TRACE_VHOST_SCSI, "====== Task %p req_idx %d finished early ======\n", task, task->req_idx); } else { diff --git a/test/lib/iscsi/common.c b/test/lib/iscsi/common.c index e7a0fd4b5..cff533998 100644 --- a/test/lib/iscsi/common.c +++ b/test/lib/iscsi/common.c @@ -12,7 +12,9 @@ SPDK_LOG_REGISTER_TRACE_FLAG("iscsi", SPDK_TRACE_ISCSI) struct spdk_iscsi_task * -spdk_iscsi_task_get(struct spdk_iscsi_conn *conn, struct spdk_iscsi_task *parent) +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; @@ -130,13 +132,15 @@ spdk_shutdown_iscsi_conns(void) } void -process_task_completion(void *arg1, void *arg2) +spdk_iscsi_task_cpl(struct spdk_scsi_task *scsi_task) { + } void -process_task_mgmt_completion(void *arg1, void *arg2) +spdk_iscsi_task_mgmt_cpl(struct spdk_scsi_task *scsi_task) { + } int diff --git a/test/unit/lib/scsi/lun.c/lun_ut.c b/test/unit/lib/scsi/lun.c/lun_ut.c index 4e5e9a476..8600028a6 100644 --- a/test/unit/lib/scsi/lun.c/lun_ut.c +++ b/test/unit/lib/scsi/lun.c/lun_ut.c @@ -75,6 +75,11 @@ void spdk_trace_record(uint16_t tpoint_id, uint16_t poller_id, uint32_t size, { } +static void +spdk_lun_ut_cpl_task(struct spdk_scsi_task *task) +{ +} + static void spdk_lun_ut_free_task(struct spdk_scsi_task *task) { @@ -93,7 +98,9 @@ spdk_get_task(uint32_t *owner_task_ctr) return NULL; } - spdk_scsi_task_construct(task, spdk_lun_ut_free_task, NULL); + spdk_scsi_task_construct(task, spdk_lun_ut_cpl_task, + spdk_lun_ut_free_task, + NULL); g_task_count++; return task;