iscsi: clean up iSCSI/SCSI task conversions

Add a helper function to find the iSCSI task given its nested SCSI task
structure, and use it to remove all casting between spdk_scsi_task and
spdk_iscsi_task.

Change-Id: Idc7c6d0a3b4d53041916d25a1bdecedfb56b94f9
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Daniel Verkamp 2017-05-15 16:33:10 -07:00
parent b347d551e8
commit 133dc1e6ae
2 changed files with 10 additions and 4 deletions

View File

@ -42,7 +42,7 @@
static void
spdk_iscsi_task_free(struct spdk_scsi_task *scsi_task)
{
struct spdk_iscsi_task *task = (struct spdk_iscsi_task *)scsi_task;
struct spdk_iscsi_task *task = spdk_iscsi_task_from_scsi_task(scsi_task);
spdk_iscsi_task_disassociate_pdu(task);
rte_mempool_put(g_spdk_iscsi.task_pool, (void *)task);
@ -66,9 +66,9 @@ spdk_iscsi_task_get(struct spdk_iscsi_conn *conn, struct spdk_iscsi_task *parent
task->conn = conn;
assert(conn->pending_task_cnt < UINT32_MAX);
conn->pending_task_cnt++;
spdk_scsi_task_construct((struct spdk_scsi_task *)task,
spdk_scsi_task_construct(&task->scsi,
spdk_iscsi_task_free,
(struct spdk_scsi_task *)parent);
parent ? &parent->scsi : NULL);
if (parent) {
task->tag = parent->tag;
}

View File

@ -157,6 +157,12 @@ 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);
static inline struct spdk_iscsi_task *
spdk_iscsi_task_from_scsi_task(struct spdk_scsi_task *task)
{
return (struct spdk_iscsi_task *)((uintptr_t)task - offsetof(struct spdk_iscsi_task, scsi));
}
static inline struct spdk_iscsi_task *
spdk_iscsi_task_get_primary(struct spdk_iscsi_task *task)
{
@ -165,7 +171,7 @@ spdk_iscsi_task_get_primary(struct spdk_iscsi_task *task)
scsi_task = &task->scsi;
scsi_primary_task = spdk_scsi_task_get_primary(scsi_task);
return (struct spdk_iscsi_task *)scsi_primary_task;
return spdk_iscsi_task_from_scsi_task(scsi_primary_task);
}
#endif /* SPDK_ISCSI_TASK_H */