Commit db22de3e authored by Bart Van Assche's avatar Bart Van Assche Committed by Martin K. Petersen

scsi: iscsi: Stop using the SCSI pointer

Instead of storing the iSCSI task pointer and the session age in the SCSI
pointer, use command-private variables. This patch prepares for removal of
the SCSI pointer from struct scsi_cmnd.

The list of iSCSI drivers has been obtained as follows:
$ git grep -lw iscsi_host_alloc
drivers/infiniband/ulp/iser/iscsi_iser.c
drivers/scsi/be2iscsi/be_main.c
drivers/scsi/bnx2i/bnx2i_iscsi.c
drivers/scsi/cxgbi/libcxgbi.c
drivers/scsi/iscsi_tcp.c
drivers/scsi/libiscsi.c
drivers/scsi/qedi/qedi_main.c
drivers/scsi/qla4xxx/ql4_os.c
include/scsi/libiscsi.h

Note: it is not clear to me how the qla4xxx driver can work without this
patch since it uses the scsi_cmnd::SCp.ptr member for two different
purposes:
- The qla4xxx driver uses this member to store a struct srb pointer.
- libiscsi uses this member to store a struct iscsi_task pointer.
Reviewed-by: default avatarLee Duncan <lduncan@suse.com>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Reviewed-by: default avatarHimanshu Madhani <himanshu.madhani@oracle.com>
Cc: Chris Leech <cleech@redhat.com>
Cc: Sagi Grimberg <sagi@grimberg.me>
Cc: Nilesh Javali <njavali@marvell.com>
Cc: Manish Rangankar <mrangankar@marvell.com>
Cc: Karen Xie <kxie@chelsio.com>
Cc: Ketan Mukadam <ketan.mukadam@broadcom.com>
Signed-off-by: default avatarBart Van Assche <bvanassche@acm.org>

iscsi

Link: https://lore.kernel.org/r/20220218195117.25689-26-bvanassche@acm.orgSigned-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 6b66f09c
...@@ -971,6 +971,7 @@ static struct scsi_host_template iscsi_iser_sht = { ...@@ -971,6 +971,7 @@ static struct scsi_host_template iscsi_iser_sht = {
.proc_name = "iscsi_iser", .proc_name = "iscsi_iser",
.this_id = -1, .this_id = -1,
.track_queue_depth = 1, .track_queue_depth = 1,
.cmd_size = sizeof(struct iscsi_cmd),
}; };
static struct iscsi_transport iscsi_iser_transport = { static struct iscsi_transport iscsi_iser_transport = {
......
...@@ -218,7 +218,7 @@ static char const *cqe_desc[] = { ...@@ -218,7 +218,7 @@ static char const *cqe_desc[] = {
static int beiscsi_eh_abort(struct scsi_cmnd *sc) static int beiscsi_eh_abort(struct scsi_cmnd *sc)
{ {
struct iscsi_task *abrt_task = (struct iscsi_task *)sc->SCp.ptr; struct iscsi_task *abrt_task = iscsi_cmd(sc)->task;
struct iscsi_cls_session *cls_session; struct iscsi_cls_session *cls_session;
struct beiscsi_io_task *abrt_io_task; struct beiscsi_io_task *abrt_io_task;
struct beiscsi_conn *beiscsi_conn; struct beiscsi_conn *beiscsi_conn;
...@@ -403,6 +403,7 @@ static struct scsi_host_template beiscsi_sht = { ...@@ -403,6 +403,7 @@ static struct scsi_host_template beiscsi_sht = {
.cmd_per_lun = BEISCSI_CMD_PER_LUN, .cmd_per_lun = BEISCSI_CMD_PER_LUN,
.vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID, .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID,
.track_queue_depth = 1, .track_queue_depth = 1,
.cmd_size = sizeof(struct iscsi_cmd),
}; };
static struct scsi_transport_template *beiscsi_scsi_transport; static struct scsi_transport_template *beiscsi_scsi_transport;
......
...@@ -2268,6 +2268,7 @@ static struct scsi_host_template bnx2i_host_template = { ...@@ -2268,6 +2268,7 @@ static struct scsi_host_template bnx2i_host_template = {
.sg_tablesize = ISCSI_MAX_BDS_PER_CMD, .sg_tablesize = ISCSI_MAX_BDS_PER_CMD,
.shost_groups = bnx2i_dev_groups, .shost_groups = bnx2i_dev_groups,
.track_queue_depth = 1, .track_queue_depth = 1,
.cmd_size = sizeof(struct iscsi_cmd),
}; };
struct iscsi_transport bnx2i_iscsi_transport = { struct iscsi_transport bnx2i_iscsi_transport = {
......
...@@ -98,6 +98,7 @@ static struct scsi_host_template cxgb3i_host_template = { ...@@ -98,6 +98,7 @@ static struct scsi_host_template cxgb3i_host_template = {
.dma_boundary = PAGE_SIZE - 1, .dma_boundary = PAGE_SIZE - 1,
.this_id = -1, .this_id = -1,
.track_queue_depth = 1, .track_queue_depth = 1,
.cmd_size = sizeof(struct iscsi_cmd),
}; };
static struct iscsi_transport cxgb3i_iscsi_transport = { static struct iscsi_transport cxgb3i_iscsi_transport = {
......
...@@ -116,6 +116,7 @@ static struct scsi_host_template cxgb4i_host_template = { ...@@ -116,6 +116,7 @@ static struct scsi_host_template cxgb4i_host_template = {
.dma_boundary = PAGE_SIZE - 1, .dma_boundary = PAGE_SIZE - 1,
.this_id = -1, .this_id = -1,
.track_queue_depth = 1, .track_queue_depth = 1,
.cmd_size = sizeof(struct iscsi_cmd),
}; };
static struct iscsi_transport cxgb4i_iscsi_transport = { static struct iscsi_transport cxgb4i_iscsi_transport = {
......
...@@ -1007,6 +1007,7 @@ static struct scsi_host_template iscsi_sw_tcp_sht = { ...@@ -1007,6 +1007,7 @@ static struct scsi_host_template iscsi_sw_tcp_sht = {
.proc_name = "iscsi_tcp", .proc_name = "iscsi_tcp",
.this_id = -1, .this_id = -1,
.track_queue_depth = 1, .track_queue_depth = 1,
.cmd_size = sizeof(struct iscsi_cmd),
}; };
static struct iscsi_transport iscsi_sw_tcp_transport = { static struct iscsi_transport iscsi_sw_tcp_transport = {
......
...@@ -462,7 +462,7 @@ static void iscsi_free_task(struct iscsi_task *task) ...@@ -462,7 +462,7 @@ static void iscsi_free_task(struct iscsi_task *task)
if (sc) { if (sc) {
/* SCSI eh reuses commands to verify us */ /* SCSI eh reuses commands to verify us */
sc->SCp.ptr = NULL; iscsi_cmd(sc)->task = NULL;
/* /*
* queue command may call this to free the task, so * queue command may call this to free the task, so
* it will decide how to return sc to scsi-ml. * it will decide how to return sc to scsi-ml.
...@@ -1344,10 +1344,10 @@ struct iscsi_task *iscsi_itt_to_ctask(struct iscsi_conn *conn, itt_t itt) ...@@ -1344,10 +1344,10 @@ struct iscsi_task *iscsi_itt_to_ctask(struct iscsi_conn *conn, itt_t itt)
if (!task || !task->sc) if (!task || !task->sc)
return NULL; return NULL;
if (task->sc->SCp.phase != conn->session->age) { if (iscsi_cmd(task->sc)->age != conn->session->age) {
iscsi_session_printk(KERN_ERR, conn->session, iscsi_session_printk(KERN_ERR, conn->session,
"task's session age %d, expected %d\n", "task's session age %d, expected %d\n",
task->sc->SCp.phase, conn->session->age); iscsi_cmd(task->sc)->age, conn->session->age);
return NULL; return NULL;
} }
...@@ -1645,8 +1645,8 @@ static inline struct iscsi_task *iscsi_alloc_task(struct iscsi_conn *conn, ...@@ -1645,8 +1645,8 @@ static inline struct iscsi_task *iscsi_alloc_task(struct iscsi_conn *conn,
(void *) &task, sizeof(void *))) (void *) &task, sizeof(void *)))
return NULL; return NULL;
sc->SCp.phase = conn->session->age; iscsi_cmd(sc)->age = conn->session->age;
sc->SCp.ptr = (char *) task; iscsi_cmd(sc)->task = task;
refcount_set(&task->refcount, 1); refcount_set(&task->refcount, 1);
task->state = ISCSI_TASK_PENDING; task->state = ISCSI_TASK_PENDING;
...@@ -1683,7 +1683,7 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) ...@@ -1683,7 +1683,7 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc)
struct iscsi_task *task = NULL; struct iscsi_task *task = NULL;
sc->result = 0; sc->result = 0;
sc->SCp.ptr = NULL; iscsi_cmd(sc)->task = NULL;
ihost = shost_priv(host); ihost = shost_priv(host);
...@@ -1997,7 +1997,7 @@ enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc) ...@@ -1997,7 +1997,7 @@ enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc)
spin_lock_bh(&session->frwd_lock); spin_lock_bh(&session->frwd_lock);
spin_lock(&session->back_lock); spin_lock(&session->back_lock);
task = (struct iscsi_task *)sc->SCp.ptr; task = iscsi_cmd(sc)->task;
if (!task) { if (!task) {
/* /*
* Raced with completion. Blk layer has taken ownership * Raced with completion. Blk layer has taken ownership
...@@ -2260,7 +2260,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc) ...@@ -2260,7 +2260,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
* if session was ISCSI_STATE_IN_RECOVERY then we may not have * if session was ISCSI_STATE_IN_RECOVERY then we may not have
* got the command. * got the command.
*/ */
if (!sc->SCp.ptr) { if (!iscsi_cmd(sc)->task) {
ISCSI_DBG_EH(session, "sc never reached iscsi layer or " ISCSI_DBG_EH(session, "sc never reached iscsi layer or "
"it completed.\n"); "it completed.\n");
spin_unlock_bh(&session->frwd_lock); spin_unlock_bh(&session->frwd_lock);
...@@ -2273,7 +2273,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc) ...@@ -2273,7 +2273,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
* then let the host reset code handle this * then let the host reset code handle this
*/ */
if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN || if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN ||
sc->SCp.phase != session->age) { iscsi_cmd(sc)->age != session->age) {
spin_unlock_bh(&session->frwd_lock); spin_unlock_bh(&session->frwd_lock);
mutex_unlock(&session->eh_mutex); mutex_unlock(&session->eh_mutex);
ISCSI_DBG_EH(session, "failing abort due to dropped " ISCSI_DBG_EH(session, "failing abort due to dropped "
...@@ -2282,7 +2282,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc) ...@@ -2282,7 +2282,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
} }
spin_lock(&session->back_lock); spin_lock(&session->back_lock);
task = (struct iscsi_task *)sc->SCp.ptr; task = iscsi_cmd(sc)->task;
if (!task || !task->sc) { if (!task || !task->sc) {
/* task completed before time out */ /* task completed before time out */
ISCSI_DBG_EH(session, "sc completed while abort in progress\n"); ISCSI_DBG_EH(session, "sc completed while abort in progress\n");
......
...@@ -603,9 +603,9 @@ static void qedi_scsi_completion(struct qedi_ctx *qedi, ...@@ -603,9 +603,9 @@ static void qedi_scsi_completion(struct qedi_ctx *qedi,
goto error; goto error;
} }
if (!sc_cmd->SCp.ptr) { if (!iscsi_cmd(sc_cmd)->task) {
QEDI_WARN(&qedi->dbg_ctx, QEDI_WARN(&qedi->dbg_ctx,
"SCp.ptr is NULL, returned in another context.\n"); "NULL task pointer, returned in another context.\n");
goto error; goto error;
} }
......
...@@ -59,6 +59,7 @@ struct scsi_host_template qedi_host_template = { ...@@ -59,6 +59,7 @@ struct scsi_host_template qedi_host_template = {
.dma_boundary = QEDI_HW_DMA_BOUNDARY, .dma_boundary = QEDI_HW_DMA_BOUNDARY,
.cmd_per_lun = 128, .cmd_per_lun = 128,
.shost_groups = qedi_shost_groups, .shost_groups = qedi_shost_groups,
.cmd_size = sizeof(struct iscsi_cmd),
}; };
static void qedi_conn_free_login_resources(struct qedi_ctx *qedi, static void qedi_conn_free_login_resources(struct qedi_ctx *qedi,
......
...@@ -216,11 +216,21 @@ ...@@ -216,11 +216,21 @@
#define IDC_COMP_TOV 5 #define IDC_COMP_TOV 5
#define LINK_UP_COMP_TOV 30 #define LINK_UP_COMP_TOV 30
#define CMD_SP(Cmnd) ((Cmnd)->SCp.ptr) /*
* Note: the data structure below does not have a struct iscsi_cmd member since
* the qla4xxx driver does not use libiscsi for SCSI I/O.
*/
struct qla4xxx_cmd_priv {
struct srb *srb;
};
static inline struct qla4xxx_cmd_priv *qla4xxx_cmd_priv(struct scsi_cmnd *cmd)
{
return scsi_cmd_priv(cmd);
}
/* /*
* SCSI Request Block structure (srb) that is placed * SCSI Request Block structure (srb) that is associated with each scsi_cmnd.
* on cmd->SCp location of every I/O [We have 22 bytes available]
*/ */
struct srb { struct srb {
struct list_head list; /* (8) */ struct list_head list; /* (8) */
......
...@@ -226,6 +226,7 @@ static struct scsi_host_template qla4xxx_driver_template = { ...@@ -226,6 +226,7 @@ static struct scsi_host_template qla4xxx_driver_template = {
.name = DRIVER_NAME, .name = DRIVER_NAME,
.proc_name = DRIVER_NAME, .proc_name = DRIVER_NAME,
.queuecommand = qla4xxx_queuecommand, .queuecommand = qla4xxx_queuecommand,
.cmd_size = sizeof(struct qla4xxx_cmd_priv),
.eh_abort_handler = qla4xxx_eh_abort, .eh_abort_handler = qla4xxx_eh_abort,
.eh_device_reset_handler = qla4xxx_eh_device_reset, .eh_device_reset_handler = qla4xxx_eh_device_reset,
...@@ -4054,7 +4055,7 @@ static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha, ...@@ -4054,7 +4055,7 @@ static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha,
srb->ddb = ddb_entry; srb->ddb = ddb_entry;
srb->cmd = cmd; srb->cmd = cmd;
srb->flags = 0; srb->flags = 0;
CMD_SP(cmd) = (void *)srb; qla4xxx_cmd_priv(cmd)->srb = srb;
return srb; return srb;
} }
...@@ -4067,7 +4068,7 @@ static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb) ...@@ -4067,7 +4068,7 @@ static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb)
scsi_dma_unmap(cmd); scsi_dma_unmap(cmd);
srb->flags &= ~SRB_DMA_VALID; srb->flags &= ~SRB_DMA_VALID;
} }
CMD_SP(cmd) = NULL; qla4xxx_cmd_priv(cmd)->srb = NULL;
} }
void qla4xxx_srb_compl(struct kref *ref) void qla4xxx_srb_compl(struct kref *ref)
...@@ -4640,7 +4641,7 @@ static int qla4xxx_cmd_wait(struct scsi_qla_host *ha) ...@@ -4640,7 +4641,7 @@ static int qla4xxx_cmd_wait(struct scsi_qla_host *ha)
* the scsi/block layer is going to prevent * the scsi/block layer is going to prevent
* the tag from being released. * the tag from being released.
*/ */
if (cmd != NULL && CMD_SP(cmd)) if (cmd != NULL && qla4xxx_cmd_priv(cmd)->srb)
break; break;
} }
spin_unlock_irqrestore(&ha->hardware_lock, flags); spin_unlock_irqrestore(&ha->hardware_lock, flags);
...@@ -9079,7 +9080,7 @@ struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha, ...@@ -9079,7 +9080,7 @@ struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha,
if (!cmd) if (!cmd)
return srb; return srb;
srb = (struct srb *)CMD_SP(cmd); srb = qla4xxx_cmd_priv(cmd)->srb;
if (!srb) if (!srb)
return srb; return srb;
...@@ -9121,7 +9122,7 @@ static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha, ...@@ -9121,7 +9122,7 @@ static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha,
do { do {
/* Checking to see if its returned to OS */ /* Checking to see if its returned to OS */
rp = (struct srb *) CMD_SP(cmd); rp = qla4xxx_cmd_priv(cmd)->srb;
if (rp == NULL) { if (rp == NULL) {
done++; done++;
break; break;
...@@ -9215,7 +9216,7 @@ static int qla4xxx_eh_abort(struct scsi_cmnd *cmd) ...@@ -9215,7 +9216,7 @@ static int qla4xxx_eh_abort(struct scsi_cmnd *cmd)
} }
spin_lock_irqsave(&ha->hardware_lock, flags); spin_lock_irqsave(&ha->hardware_lock, flags);
srb = (struct srb *) CMD_SP(cmd); srb = qla4xxx_cmd_priv(cmd)->srb;
if (!srb) { if (!srb) {
spin_unlock_irqrestore(&ha->hardware_lock, flags); spin_unlock_irqrestore(&ha->hardware_lock, flags);
ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n", ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/refcount.h> #include <linux/refcount.h>
#include <scsi/iscsi_proto.h> #include <scsi/iscsi_proto.h>
#include <scsi/iscsi_if.h> #include <scsi/iscsi_if.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_transport_iscsi.h> #include <scsi/scsi_transport_iscsi.h>
struct scsi_transport_template; struct scsi_transport_template;
...@@ -152,6 +153,17 @@ static inline bool iscsi_task_is_completed(struct iscsi_task *task) ...@@ -152,6 +153,17 @@ static inline bool iscsi_task_is_completed(struct iscsi_task *task)
task->state == ISCSI_TASK_ABRT_SESS_RECOV; task->state == ISCSI_TASK_ABRT_SESS_RECOV;
} }
/* Private data associated with struct scsi_cmnd. */
struct iscsi_cmd {
struct iscsi_task *task;
int age;
};
static inline struct iscsi_cmd *iscsi_cmd(struct scsi_cmnd *cmd)
{
return scsi_cmd_priv(cmd);
}
/* Connection's states */ /* Connection's states */
enum { enum {
ISCSI_CONN_INITIAL_STAGE, ISCSI_CONN_INITIAL_STAGE,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment