History

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: Lee Duncan <lduncan@suse.com> Reviewed-by: Hannes Reinecke <hare@suse.de> Reviewed-by: Himanshu 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: Bart Van Assche <bvanassche@acm.org> iscsi

Bart Van Assche committed 4 years ago

Commit db22de31 parent 6b66f0912 files · +52 −22Browse files

Unified · Split

12 files
  1. drivers/infiniband/ulp/iser/iscsi_iser.c +1 −0
  2. drivers/scsi/be2iscsi/be_main.c +2 −1
  3. drivers/scsi/bnx2i/bnx2i_iscsi.c +1 −0
  4. drivers/scsi/cxgbi/cxgb3i/cxgb3i.c +1 −0
  5. drivers/scsi/cxgbi/cxgb4i/cxgb4i.c +1 −0
  6. drivers/scsi/iscsi_tcp.c +1 −0
  7. drivers/scsi/libiscsi.c +10 −10
  8. drivers/scsi/qedi/qedi_fw.c +2 −2
  9. drivers/scsi/qedi/qedi_iscsi.c +1 −0
  10. drivers/scsi/qla4xxx/ql4_def.h +13 −3
  11. drivers/scsi/qla4xxx/ql4_os.c +7 −6
  12. include/scsi/libiscsi.h +12 −0
drivers/infiniband/ulp/iser/iscsi_iser.c+1−0
@@ -971,6 +971,7 @@ static struct scsi_host_template iscsi_iser_sht = { · 970 unmodified lines
971971 .proc_name = "iscsi_iser",
972972 .this_id = -1,
973973 .track_queue_depth = 1,
974+ .cmd_size = sizeof(struct iscsi_cmd),
974975 };
975976
976977 static struct iscsi_transport iscsi_iser_transport = {
drivers/scsi/be2iscsi/be_main.c+2−1
@@ -218,7 +218,7 @@ static char const *cqe_desc[] = { · 217 unmodified lines
218218
219219 static int beiscsi_eh_abort(struct scsi_cmnd *sc)
220220 {
221− struct iscsi_task *abrt_task = (struct iscsi_task *)sc->SCp.ptr;
221+ struct iscsi_task *abrt_task = iscsi_cmd(sc)->task;
222222 struct iscsi_cls_session *cls_session;
223223 struct beiscsi_io_task *abrt_io_task;
224224 struct beiscsi_conn *beiscsi_conn;
@@ -403,6 +403,7 @@ static struct scsi_host_template beiscsi_sht = { · 178 unmodified lines
403403 .cmd_per_lun = BEISCSI_CMD_PER_LUN,
404404 .vendor_id = SCSI_NL_VID_TYPE_PCI | BE_VENDOR_ID,
405405 .track_queue_depth = 1,
406+ .cmd_size = sizeof(struct iscsi_cmd),
406407 };
407408
408409 static struct scsi_transport_template *beiscsi_scsi_transport;
drivers/scsi/bnx2i/bnx2i_iscsi.c+1−0
@@ -2268,6 +2268,7 @@ static struct scsi_host_template bnx2i_host_template = { · 2267 unmodified lines
22682268 .sg_tablesize = ISCSI_MAX_BDS_PER_CMD,
22692269 .shost_groups = bnx2i_dev_groups,
22702270 .track_queue_depth = 1,
2271+ .cmd_size = sizeof(struct iscsi_cmd),
22712272 };
22722273
22732274 struct iscsi_transport bnx2i_iscsi_transport = {
drivers/scsi/cxgbi/cxgb3i/cxgb3i.c+1−0
@@ -98,6 +98,7 @@ static struct scsi_host_template cxgb3i_host_template = { · 97 unmodified lines
9898 .dma_boundary = PAGE_SIZE - 1,
9999 .this_id = -1,
100100 .track_queue_depth = 1,
101+ .cmd_size = sizeof(struct iscsi_cmd),
101102 };
102103
103104 static struct iscsi_transport cxgb3i_iscsi_transport = {
drivers/scsi/cxgbi/cxgb4i/cxgb4i.c+1−0
@@ -116,6 +116,7 @@ static struct scsi_host_template cxgb4i_host_template = { · 115 unmodified lines
116116 .dma_boundary = PAGE_SIZE - 1,
117117 .this_id = -1,
118118 .track_queue_depth = 1,
119+ .cmd_size = sizeof(struct iscsi_cmd),
119120 };
120121
121122 static struct iscsi_transport cxgb4i_iscsi_transport = {
drivers/scsi/iscsi_tcp.c+1−0
@@ -1007,6 +1007,7 @@ static struct scsi_host_template iscsi_sw_tcp_sht = { · 1006 unmodified lines
10071007 .proc_name = "iscsi_tcp",
10081008 .this_id = -1,
10091009 .track_queue_depth = 1,
1010+ .cmd_size = sizeof(struct iscsi_cmd),
10101011 };
10111012
10121013 static struct iscsi_transport iscsi_sw_tcp_transport = {
drivers/scsi/libiscsi.c+10−10
@@ -462,7 +462,7 @@ static void iscsi_free_task(struct iscsi_task *task) · 461 unmodified lines
462462
463463 if (sc) {
464464 /* SCSI eh reuses commands to verify us */
465− sc->SCp.ptr = NULL;
465+ iscsi_cmd(sc)->task = NULL;
466466 /*
467467 * queue command may call this to free the task, so
468468 * 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) · 875 unmodified lines
13441344 if (!task || !task->sc)
13451345 return NULL;
13461346
1347− if (task->sc->SCp.phase != conn->session->age) {
1347+ if (iscsi_cmd(task->sc)->age != conn->session->age) {
13481348 iscsi_session_printk(KERN_ERR, conn->session,
13491349 "task's session age %d, expected %d\n",
1350− task->sc->SCp.phase, conn->session->age);
1350+ iscsi_cmd(task->sc)->age, conn->session->age);
13511351 return NULL;
13521352 }
13531353
@@ -1645,8 +1645,8 @@ static inline struct iscsi_task *iscsi_alloc_task(struct iscsi_conn *conn, · 291 unmodified lines
16451645 (void *) &task, sizeof(void *)))
16461646 return NULL;
16471647
1648− sc->SCp.phase = conn->session->age;
1649− sc->SCp.ptr = (char *) task;
1648+ iscsi_cmd(sc)->age = conn->session->age;
1649+ iscsi_cmd(sc)->task = task;
16501650
16511651 refcount_set(&task->refcount, 1);
16521652 task->state = ISCSI_TASK_PENDING;
@@ -1683,7 +1683,7 @@ int iscsi_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *sc) · 30 unmodified lines
16831683 struct iscsi_task *task = NULL;
16841684
16851685 sc->result = 0;
1686− sc->SCp.ptr = NULL;
1686+ iscsi_cmd(sc)->task = NULL;
16871687
16881688 ihost = shost_priv(host);
16891689
@@ -1997,7 +1997,7 @@ enum blk_eh_timer_return iscsi_eh_cmd_timed_out(struct scsi_cmnd *sc) · 307 unmodified lines
19971997
19981998 spin_lock_bh(&session->frwd_lock);
19991999 spin_lock(&session->back_lock);
2000− task = (struct iscsi_task *)sc->SCp.ptr;
2000+ task = iscsi_cmd(sc)->task;
20012001 if (!task) {
20022002 /*
20032003 * Raced with completion. Blk layer has taken ownership
@@ -2260,7 +2260,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc) · 256 unmodified lines
22602260 * if session was ISCSI_STATE_IN_RECOVERY then we may not have
22612261 * got the command.
22622262 */
2263− if (!sc->SCp.ptr) {
2263+ if (!iscsi_cmd(sc)->task) {
22642264 ISCSI_DBG_EH(session, "sc never reached iscsi layer or "
22652265 "it completed.\n");
22662266 spin_unlock_bh(&session->frwd_lock);
@@ -2273,7 +2273,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc) · 6 unmodified lines
22732273 * then let the host reset code handle this
22742274 */
22752275 if (!session->leadconn || session->state != ISCSI_STATE_LOGGED_IN ||
2276− sc->SCp.phase != session->age) {
2276+ iscsi_cmd(sc)->age != session->age) {
22772277 spin_unlock_bh(&session->frwd_lock);
22782278 mutex_unlock(&session->eh_mutex);
22792279 ISCSI_DBG_EH(session, "failing abort due to dropped "
@@ -2282,7 +2282,7 @@ int iscsi_eh_abort(struct scsi_cmnd *sc) · 2 unmodified lines
22822282 }
22832283
22842284 spin_lock(&session->back_lock);
2285− task = (struct iscsi_task *)sc->SCp.ptr;
2285+ task = iscsi_cmd(sc)->task;
22862286 if (!task || !task->sc) {
22872287 /* task completed before time out */
22882288 ISCSI_DBG_EH(session, "sc completed while abort in progress\n");
drivers/scsi/qedi/qedi_fw.c+2−2
@@ -603,9 +603,9 @@ static void qedi_scsi_completion(struct qedi_ctx *qedi, · 602 unmodified lines
603603 goto error;
604604 }
605605
606− if (!sc_cmd->SCp.ptr) {
606+ if (!iscsi_cmd(sc_cmd)->task) {
607607 QEDI_WARN(&qedi->dbg_ctx,
608− "SCp.ptr is NULL, returned in another context.\n");
608+ "NULL task pointer, returned in another context.\n");
609609 goto error;
610610 }
611611
drivers/scsi/qedi/qedi_iscsi.c+1−0
@@ -59,6 +59,7 @@ struct scsi_host_template qedi_host_template = { · 58 unmodified lines
5959 .dma_boundary = QEDI_HW_DMA_BOUNDARY,
6060 .cmd_per_lun = 128,
6161 .shost_groups = qedi_shost_groups,
62+ .cmd_size = sizeof(struct iscsi_cmd),
6263 };
6364
6465 static void qedi_conn_free_login_resources(struct qedi_ctx *qedi,
drivers/scsi/qla4xxx/ql4_def.h+13−3
@@ -216,11 +216,21 @@ · 215 unmodified lines
216216 #define IDC_COMP_TOV 5
217217 #define LINK_UP_COMP_TOV 30
218218
219−#define CMD_SP(Cmnd) ((Cmnd)->SCp.ptr)
219+/*
220+ * Note: the data structure below does not have a struct iscsi_cmd member since
221+ * the qla4xxx driver does not use libiscsi for SCSI I/O.
222+ */
223+struct qla4xxx_cmd_priv {
224+ struct srb *srb;
225+};
226+
227+static inline struct qla4xxx_cmd_priv *qla4xxx_cmd_priv(struct scsi_cmnd *cmd)
228+{
229+ return scsi_cmd_priv(cmd);
230+}
220231
221232 /*
222− * SCSI Request Block structure (srb) that is placed
223− * on cmd->SCp location of every I/O [We have 22 bytes available]
233+ * SCSI Request Block structure (srb) that is associated with each scsi_cmnd.
224234 */
225235 struct srb {
226236 struct list_head list; /* (8) */
drivers/scsi/qla4xxx/ql4_os.c+7−6
@@ -226,6 +226,7 @@ static struct scsi_host_template qla4xxx_driver_template = { · 225 unmodified lines
226226 .name = DRIVER_NAME,
227227 .proc_name = DRIVER_NAME,
228228 .queuecommand = qla4xxx_queuecommand,
229+ .cmd_size = sizeof(struct qla4xxx_cmd_priv),
229230
230231 .eh_abort_handler = qla4xxx_eh_abort,
231232 .eh_device_reset_handler = qla4xxx_eh_device_reset,
@@ -4054,7 +4055,7 @@ static struct srb* qla4xxx_get_new_srb(struct scsi_qla_host *ha, · 3822 unmodified lines
40544055 srb->ddb = ddb_entry;
40554056 srb->cmd = cmd;
40564057 srb->flags = 0;
4057− CMD_SP(cmd) = (void *)srb;
4058+ qla4xxx_cmd_priv(cmd)->srb = srb;
40584059
40594060 return srb;
40604061 }
@@ -4067,7 +4068,7 @@ static void qla4xxx_srb_free_dma(struct scsi_qla_host *ha, struct srb *srb) · 6 unmodified lines
40674068 scsi_dma_unmap(cmd);
40684069 srb->flags &= ~SRB_DMA_VALID;
40694070 }
4070− CMD_SP(cmd) = NULL;
4071+ qla4xxx_cmd_priv(cmd)->srb = NULL;
40714072 }
40724073
40734074 void qla4xxx_srb_compl(struct kref *ref)
@@ -4640,7 +4641,7 @@ static int qla4xxx_cmd_wait(struct scsi_qla_host *ha) · 566 unmodified lines
46404641 * the scsi/block layer is going to prevent
46414642 * the tag from being released.
46424643 */
4643− if (cmd != NULL && CMD_SP(cmd))
4644+ if (cmd != NULL && qla4xxx_cmd_priv(cmd)->srb)
46444645 break;
46454646 }
46464647 spin_unlock_irqrestore(&ha->hardware_lock, flags);
@@ -9079,7 +9080,7 @@ struct srb *qla4xxx_del_from_active_array(struct scsi_qla_host *ha, · 4432 unmodified lines
90799080 if (!cmd)
90809081 return srb;
90819082
9082− srb = (struct srb *)CMD_SP(cmd);
9083+ srb = qla4xxx_cmd_priv(cmd)->srb;
90839084 if (!srb)
90849085 return srb;
90859086
@@ -9121,7 +9122,7 @@ static int qla4xxx_eh_wait_on_command(struct scsi_qla_host *ha, · 35 unmodified lines
91219122
91229123 do {
91239124 /* Checking to see if its returned to OS */
9124− rp = (struct srb *) CMD_SP(cmd);
9125+ rp = qla4xxx_cmd_priv(cmd)->srb;
91259126 if (rp == NULL) {
91269127 done++;
91279128 break;
@@ -9215,7 +9216,7 @@ static int qla4xxx_eh_abort(struct scsi_cmnd *cmd) · 87 unmodified lines
92159216 }
92169217
92179218 spin_lock_irqsave(&ha->hardware_lock, flags);
9218− srb = (struct srb *) CMD_SP(cmd);
9219+ srb = qla4xxx_cmd_priv(cmd)->srb;
92199220 if (!srb) {
92209221 spin_unlock_irqrestore(&ha->hardware_lock, flags);
92219222 ql4_printk(KERN_INFO, ha, "scsi%ld:%d:%llu: Specified command has already completed.\n",
include/scsi/libiscsi.h+12−0
@@ -19,6 +19,7 @@ · 18 unmodified lines
1919 #include <linux/refcount.h>
2020 #include <scsi/iscsi_proto.h>
2121 #include <scsi/iscsi_if.h>
22+#include <scsi/scsi_cmnd.h>
2223 #include <scsi/scsi_transport_iscsi.h>
2324
2425 struct scsi_transport_template;
@@ -152,6 +153,17 @@ static inline bool iscsi_task_is_completed(struct iscsi_task *task) · 127 unmodified lines
152153 task->state == ISCSI_TASK_ABRT_SESS_RECOV;
153154 }
154155
156+/* Private data associated with struct scsi_cmnd. */
157+struct iscsi_cmd {
158+ struct iscsi_task *task;
159+ int age;
160+};
161+
162+static inline struct iscsi_cmd *iscsi_cmd(struct scsi_cmnd *cmd)
163+{
164+ return scsi_cmd_priv(cmd);
165+}
166+
155167 /* Connection's states */
156168 enum {
157169 ISCSI_CONN_INITIAL_STAGE,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t