diff --git a/iscsi-scst/kernel/config.c b/iscsi-scst/kernel/config.c index b6823706e..e132e3e88 100644 --- a/iscsi-scst/kernel/config.c +++ b/iscsi-scst/kernel/config.c @@ -113,7 +113,7 @@ static __init int iscsi_proc_log_entry_build(struct scst_tgt_template *templ) root = scst_proc_get_tgt_root(templ); if (root) { p = scst_create_proc_entry(root, ISCSI_PROC_VERSION_NAME, - &iscsi_version_proc_data); + &iscsi_version_proc_data); if (p == NULL) { PRINT_ERROR("Not enough memory to register " "target driver %s entry %s in /proc", @@ -126,7 +126,7 @@ static __init int iscsi_proc_log_entry_build(struct scst_tgt_template *templ) /* create the proc file entry for the device */ iscsi_log_proc_data.data = (void *)templ->name; p = scst_create_proc_entry(root, ISCSI_PROC_LOG_ENTRY_NAME, - &iscsi_log_proc_data); + &iscsi_log_proc_data); if (p == NULL) { PRINT_ERROR("Not enough memory to register " "target driver %s entry %s in /proc", @@ -209,7 +209,8 @@ int __init iscsi_procfs_init(void) goto out; for (i = 0; i < ARRAY_SIZE(iscsi_proc_entries); i++) { - ent = create_proc_entry(iscsi_proc_entries[i].name, 0, proc_iscsi_dir); + ent = create_proc_entry(iscsi_proc_entries[i].name, 0, + proc_iscsi_dir); if (ent) ent->proc_fops = iscsi_proc_entries[i].fops; else { @@ -344,7 +345,8 @@ static int del_session(struct iscsi_target *target, void __user *ptr) } /* target_mutex supposed to be locked */ -static int iscsi_param_config(struct iscsi_target *target, void __user *ptr, int set) +static int iscsi_param_config(struct iscsi_target *target, void __user *ptr, + int set) { int err; struct iscsi_param_info info; @@ -545,10 +547,11 @@ void iscsi_dump_iov(struct msghdr *msg) { if (trace_flag & TRACE_D_IOV) { int i; - printk("%p, %zd\n", msg->msg_iov, msg->msg_iovlen); + printk(LOG_FLAG "%p, %zd\n", msg->msg_iov, msg->msg_iovlen); for (i = 0; i < min_t(size_t, msg->msg_iovlen, ISCSI_CONN_IOV_MAX); i++) { - printk("%d: %p,%zd\n", i, msg->msg_iov[i].iov_base, + printk(LOG_FLAG "%d: %p,%zd\n", + i, msg->msg_iov[i].iov_base, msg->msg_iov[i].iov_len); } } @@ -561,26 +564,26 @@ static void iscsi_dump_char(int ch) if (ch < 0) { while ((i % 16) != 0) { - printk(" "); + printk(LOG_FLAG " "); text[i] = ' '; i++; if ((i % 16) == 0) - printk(" | %.16s |\n", text); + printk(LOG_FLAG " | %.16s |\n", text); else if ((i % 4) == 0) - printk(" |"); + printk(LOG_FLAG " |"); } i = 0; return; } text[i] = (ch < 0x20 || (ch >= 0x80 && ch <= 0xa0)) ? ' ' : ch; - printk(" %02x", ch); + printk(LOG_FLAG " %02x", ch); i++; if ((i % 16) == 0) { - printk(" | %.16s |\n", text); + printk(LOG_FLAG " | %.16s |\n", text); i = 0; } else if ((i % 4) == 0) - printk(" |"); + printk(LOG_FLAG " |"); } void iscsi_dump_pdu(struct iscsi_pdu *pdu) @@ -590,18 +593,18 @@ void iscsi_dump_pdu(struct iscsi_pdu *pdu) int i; buf = (void *)&pdu->bhs; - printk("BHS: (%p,%zd)\n", buf, sizeof(pdu->bhs)); + printk(LOG_FLAG "BHS: (%p,%zd)\n", buf, sizeof(pdu->bhs)); for (i = 0; i < sizeof(pdu->bhs); i++) iscsi_dump_char(*buf++); iscsi_dump_char(-1); buf = (void *)pdu->ahs; - printk("AHS: (%p,%d)\n", buf, pdu->ahssize); + printk(LOG_FLAG "AHS: (%p,%d)\n", buf, pdu->ahssize); for (i = 0; i < pdu->ahssize; i++) iscsi_dump_char(*buf++); iscsi_dump_char(-1); - printk("Data: (%d)\n", pdu->datasize); + printk(LOG_FLAG "Data: (%d)\n", pdu->datasize); } } #endif /* CONFIG_SCST_DEBUG */ diff --git a/iscsi-scst/kernel/conn.c b/iscsi-scst/kernel/conn.c index d4fb4073e..03596afd8 100644 --- a/iscsi-scst/kernel/conn.c +++ b/iscsi-scst/kernel/conn.c @@ -251,10 +251,11 @@ static void conn_rsp_timer_fn(unsigned long arg) if (unlikely(time_after_eq(jiffies, wr_cmd->write_timeout))) { if (!conn->closing) { - PRINT_ERROR("Timeout sending data to initiator " - "%s (SID %llx), closing connection", + PRINT_ERROR("Timeout sending data to initiator" + " %s (SID %llx), closing connection", conn->session->initiator_name, - (long long unsigned int)conn->session->sid); + (long long unsigned int) + conn->session->sid); mark_conn_closed(conn); } } else { @@ -349,7 +350,8 @@ int conn_free(struct iscsi_conn *conn) } /* target_mutex supposed to be locked */ -static int iscsi_conn_alloc(struct iscsi_session *session, struct conn_info *info) +static int iscsi_conn_alloc(struct iscsi_session *session, + struct conn_info *info) { struct iscsi_conn *conn; int res = 0; @@ -452,8 +454,8 @@ int conn_del(struct iscsi_session *session, struct conn_info *info) void iscsi_extracheck_is_rd_thread(struct iscsi_conn *conn) { if (unlikely(current != conn->rd_task)) { - printk(KERN_EMERG "conn %p rd_task != current %p (pid %d)\n", conn, - current, current->pid); + printk(KERN_EMERG "conn %p rd_task != current %p (pid %d)\n", + conn, current, current->pid); while (in_softirq()) local_bh_enable(); printk(KERN_EMERG "rd_state %x\n", conn->rd_state); @@ -466,8 +468,8 @@ void iscsi_extracheck_is_rd_thread(struct iscsi_conn *conn) void iscsi_extracheck_is_wr_thread(struct iscsi_conn *conn) { if (unlikely(current != conn->wr_task)) { - printk(KERN_EMERG "conn %p wr_task != current %p (pid %d)\n", conn, - current, current->pid); + printk(KERN_EMERG "conn %p wr_task != current %p (pid %d)\n", + conn, current, current->pid); while (in_softirq()) local_bh_enable(); printk(KERN_EMERG "wr_state %x\n", conn->wr_state); diff --git a/iscsi-scst/kernel/digest.c b/iscsi-scst/kernel/digest.c index ec322d8a9..105151bc4 100644 --- a/iscsi-scst/kernel/digest.c +++ b/iscsi-scst/kernel/digest.c @@ -1,7 +1,8 @@ /* * iSCSI digest handling. * - * Copyright (C) 2004 - 2006 Xiranet Communications GmbH + * Copyright (C) 2004 - 2006 Xiranet Communications GmbH + * * Copyright (C) 2007 - 2008 Vladislav Bolkhovitin * Copyright (C) 2007 - 2008 CMS Distribution Limited * @@ -81,8 +82,9 @@ static u32 evaluate_crc32_from_sg(struct scatterlist *sg, int total, if (pad_bytes) { u32 padding = 0; /* - * Digest includes also padding for aligned pdu length, hopefully - * it is always filled with 0s in pdu (according to crypto/crc32c.c + * Digest includes also padding for aligned pdu length, + * hopefully it is always filled with 0s in pdu (according to + * crypto/crc32c.c */ crc = crc32c(crc, (u8 *)&padding, pad_bytes); } diff --git a/iscsi-scst/kernel/event.c b/iscsi-scst/kernel/event.c index ac99037ed..3bbeded18 100644 --- a/iscsi-scst/kernel/event.c +++ b/iscsi-scst/kernel/event.c @@ -96,7 +96,8 @@ static int notify(void *data, int len, gfp_t gfp_mask) if (!skb) return -ENOMEM; - nlh = __nlmsg_put(skb, iscsid_pid, seq++, NLMSG_DONE, len - sizeof(*nlh), 0); + nlh = __nlmsg_put(skb, iscsid_pid, seq++, NLMSG_DONE, + len - sizeof(*nlh), 0); memcpy(NLMSG_DATA(nlh), data, len); diff --git a/iscsi-scst/kernel/iscsi.c b/iscsi-scst/kernel/iscsi.c index 28d807545..c8d55540c 100644 --- a/iscsi-scst/kernel/iscsi.c +++ b/iscsi-scst/kernel/iscsi.c @@ -126,7 +126,8 @@ static inline void iscsi_fail_waiting_cmnd(struct iscsi_cmnd *cmnd) req_cmnd_release_force(cmnd, ISCSI_FORCE_RELEASE_WRITE); } -struct iscsi_cmnd *cmnd_alloc(struct iscsi_conn *conn, struct iscsi_cmnd *parent) +struct iscsi_cmnd *cmnd_alloc(struct iscsi_conn *conn, + struct iscsi_cmnd *parent) { struct iscsi_cmnd *cmnd; @@ -170,8 +171,8 @@ static void cmnd_free(struct iscsi_cmnd *cmnd) if (unlikely(cmnd->tm_aborted)) { TRACE_MGMT_DBG("Free aborted cmd %p (scst cmd %p, state %d, " - "parent_req %p)", cmnd, cmnd->scst_cmd, cmnd->scst_state, - cmnd->parent_req); + "parent_req %p)", cmnd, cmnd->scst_cmd, + cmnd->scst_state, cmnd->parent_req); } /* Catch users from cmd_list or rsp_cmd_list */ @@ -182,15 +183,16 @@ static void cmnd_free(struct iscsi_cmnd *cmnd) if (unlikely(cmnd->on_write_list || cmnd->on_written_list)) { struct iscsi_scsi_cmd_hdr *req = cmnd_hdr(cmnd); - PRINT_CRIT_ERROR("cmnd %p still on some list?, %x, %x, %x, %x, %x, %x, %x", - cmnd, req->opcode, req->scb[0], req->flags, req->itt, - be32_to_cpu(req->data_length), + PRINT_CRIT_ERROR("cmnd %p still on some list?, %x, %x, %x, " + "%x, %x, %x, %x", cmnd, req->opcode, req->scb[0], + req->flags, req->itt, be32_to_cpu(req->data_length), req->cmd_sn, be32_to_cpu(cmnd->pdu.datasize)); if (unlikely(cmnd->parent_req)) { struct iscsi_scsi_cmd_hdr *preq = cmnd_hdr(cmnd->parent_req); - PRINT_CRIT_ERROR("%p %x %u", preq, preq->opcode, preq->scb[0]); + PRINT_CRIT_ERROR("%p %x %u", preq, preq->opcode, + preq->scb[0]); } sBUG(); } @@ -205,8 +207,8 @@ void cmnd_done(struct iscsi_cmnd *cmnd) if (unlikely(cmnd->tm_aborted)) { TRACE_MGMT_DBG("Done aborted cmd %p (scst cmd %p, state %d, " - "parent_req %p)", cmnd, cmnd->scst_cmd, cmnd->scst_state, - cmnd->parent_req); + "parent_req %p)", cmnd, cmnd->scst_cmd, + cmnd->scst_state, cmnd->parent_req); } EXTRACHECKS_BUG_ON(cmnd->on_rx_digest_list); @@ -255,8 +257,8 @@ void cmnd_done(struct iscsi_cmnd *cmnd) break; } default: - PRINT_CRIT_ERROR("Unexpected cmnd scst state %d", - cmnd->scst_state); + PRINT_CRIT_ERROR("Unexpected cmnd scst state " + "%d", cmnd->scst_state); sBUG(); break; } @@ -336,7 +338,8 @@ void req_cmnd_release_force(struct iscsi_cmnd *req, int flags) } spin_unlock_bh(&conn->write_list_lock); - list_for_each_entry_safe(rsp, t, &cmds_list, write_list_entry) { + list_for_each_entry_safe(rsp, t, &cmds_list, + write_list_entry) { TRACE_MGMT_DBG("Putting write rsp %p", rsp); list_del(&rsp->write_list_entry); cmnd_put(rsp); @@ -345,7 +348,8 @@ void req_cmnd_release_force(struct iscsi_cmnd *req, int flags) again_rsp: spin_lock_bh(&req->rsp_cmd_lock); - list_for_each_entry_reverse(rsp, &req->rsp_cmd_list, rsp_cmd_list_entry) { + list_for_each_entry_reverse(rsp, &req->rsp_cmd_list, + rsp_cmd_list_entry) { bool r; if (rsp->force_cleanup_done) @@ -511,7 +515,8 @@ static void iscsi_cmnds_init_write(struct list_head *send, int flags) * initiator sends cmd with the same ITT => this command will be * erroneously rejected as a duplicate. */ - if ((flags & ISCSI_INIT_WRITE_REMOVE_HASH) && rsp->parent_req->hashed && + if ((flags & ISCSI_INIT_WRITE_REMOVE_HASH) && + rsp->parent_req->hashed && (rsp->parent_req->r2t_length == 0) && (rsp->parent_req->outstanding_r2t == 0)) cmnd_remove_hash(rsp->parent_req); @@ -544,6 +549,8 @@ static void iscsi_cmnds_init_write(struct list_head *send, int flags) if (flags & ISCSI_INIT_WRITE_WAKE) iscsi_make_conn_wr_active(conn); + + return; } static void iscsi_cmnd_init_write(struct iscsi_cmnd *rsp, int flags) @@ -551,8 +558,8 @@ static void iscsi_cmnd_init_write(struct iscsi_cmnd *rsp, int flags) LIST_HEAD(head); if (unlikely(rsp->on_write_list)) { - PRINT_CRIT_ERROR("cmd already on write list (%x %x %x %x %u %u " - "%u %u %u %u %u %d %d", + PRINT_CRIT_ERROR("cmd already on write list (%x %x %x %x %u " + "%u %u %u %u %u %u %d %d", cmnd_itt(rsp), cmnd_ttt(rsp), cmnd_opcode(rsp), cmnd_scsicode(rsp), rsp->r2t_sn, rsp->r2t_length, rsp->is_unsolicited_data, @@ -563,6 +570,7 @@ static void iscsi_cmnd_init_write(struct iscsi_cmnd *rsp, int flags) } list_add(&rsp->write_list_entry, &head); iscsi_cmnds_init_write(&head, flags); + return; } static void iscsi_set_datasize(struct iscsi_cmnd *cmnd, u32 offset, u32 size) @@ -578,6 +586,7 @@ static void iscsi_set_datasize(struct iscsi_cmnd *cmnd, u32 offset, u32 size) while (i--) *p++ = 0; } + return; } static void send_data_rsp(struct iscsi_cmnd *req, u8 status, int send_status) @@ -645,6 +654,7 @@ static void send_data_rsp(struct iscsi_cmnd *req, u8 status, int send_status) list_add_tail(&rsp->write_list_entry, &send); } iscsi_cmnds_init_write(&send, ISCSI_INIT_WRITE_REMOVE_HASH); + return; } static struct iscsi_cmnd *create_status_rsp(struct iscsi_cmnd *req, int status, @@ -813,8 +823,8 @@ static int check_cmd_sn(struct iscsi_cmnd *cmnd) return -ISCSI_REASON_PROTOCOL_ERROR; } -static inline struct iscsi_cmnd *__cmnd_find_hash(struct iscsi_session *session, - u32 itt, u32 ttt) +static inline struct iscsi_cmnd *__cmnd_find_hash( + struct iscsi_session *session, u32 itt, u32 ttt) { struct list_head *head; struct iscsi_cmnd *cmnd; @@ -823,7 +833,8 @@ static inline struct iscsi_cmnd *__cmnd_find_hash(struct iscsi_session *session, list_for_each_entry(cmnd, head, hash_list_entry) { if (cmnd->pdu.bhs.itt == itt) { - if ((ttt != ISCSI_RESERVED_TAG) && (ttt != cmnd->target_task_tag)) + if (ttt != ISCSI_RESERVED_TAG && + ttt != cmnd->target_task_tag) continue; return cmnd; } @@ -925,7 +936,7 @@ static void cmnd_prepare_get_rejected_cmd_data(struct iscsi_cmnd *cmnd) { struct iscsi_conn *conn = cmnd->conn; struct scatterlist *sg = cmnd->sg; - char *addr; + char __user *addr; u32 size; int i; @@ -1061,7 +1072,8 @@ static int cmnd_prepare_recv_pdu(struct iscsi_conn *conn, if (unlikely(++i >= ISCSI_CONN_IOV_MAX)) { PRINT_ERROR("Initiator %s violated negotiated " "parameters by sending too much data (size " - "left %d)", conn->session->initiator_name, size); + "left %d)", conn->session->initiator_name, + size); mark_conn_closed(conn); res = -EINVAL; break; @@ -1211,8 +1223,8 @@ static int noop_out_start(struct iscsi_cmnd *cmnd) } else { err = cmnd_insert_hash(cmnd); if (unlikely(err < 0)) { - PRINT_ERROR("Can't insert in hash: ignore this request %x", - cmnd_itt(cmnd)); + PRINT_ERROR("Can't insert in hash: ignore this " + "request %x", cmnd_itt(cmnd)); goto out; } } @@ -1228,8 +1240,8 @@ static int noop_out_start(struct iscsi_cmnd *cmnd) cmnd->sg = sg = scst_alloc(size, GFP_KERNEL, &cmnd->sg_cnt); if (sg == NULL) { - TRACE(TRACE_OUT_OF_MEM, "Allocating buffer for " - "%d NOP-Out payload failed", size); + TRACE(TRACE_OUT_OF_MEM, "Allocating buffer for" + " %d NOP-Out payload failed", size); err = -ISCSI_REASON_OUT_OF_RESOURCES; goto out; } @@ -1332,7 +1344,8 @@ static int scsi_cmnd_start(struct iscsi_cmnd *req) dir = SCST_DATA_WRITE; else dir = SCST_DATA_NONE; - scst_cmd_set_expected(scst_cmd, dir, be32_to_cpu(req_hdr->data_length)); + scst_cmd_set_expected(scst_cmd, dir, + be32_to_cpu(req_hdr->data_length)); switch (req_hdr->flags & ISCSI_CMD_ATTR_MASK) { case ISCSI_CMD_SIMPLE: @@ -1365,7 +1378,7 @@ static int scsi_cmnd_start(struct iscsi_cmnd *req) req->scst_state = ISCSI_CMD_STATE_RX_CMD; scst_cmd_init_stage1_done(scst_cmd, SCST_CONTEXT_DIRECT, 0); - wait_event(req->scst_waitQ, (req->scst_state != ISCSI_CMD_STATE_RX_CMD)); + wait_event(req->scst_waitQ, req->scst_state != ISCSI_CMD_STATE_RX_CMD); if (unlikely(req->scst_state != ISCSI_CMD_STATE_AFTER_PREPROC)) { TRACE_DBG("req %p is in %x state", req, req->scst_state); @@ -1396,7 +1409,8 @@ static int scsi_cmnd_start(struct iscsi_cmnd *req) if (dir == SCST_DATA_WRITE) { req->is_unsolicited_data = !(req_hdr->flags & ISCSI_CMD_FINAL); - req->r2t_length = be32_to_cpu(req_hdr->data_length) - req->pdu.datasize; + req->r2t_length = be32_to_cpu(req_hdr->data_length) - + req->pdu.datasize; if (req->r2t_length > 0) req->data_waiting = 1; } @@ -1418,7 +1432,8 @@ static int scsi_cmnd_start(struct iscsi_cmnd *req) req->pdu.datasize)) { PRINT_ERROR("Initiator %s violated negotiated paremeters: " "forbidden immediate data sent (ITT %x, op %x)", - session->initiator_name, cmnd_itt(req), req_hdr->scb[0]); + session->initiator_name, cmnd_itt(req), + req_hdr->scb[0]); res = -EINVAL; goto out; } @@ -1427,19 +1442,21 @@ static int scsi_cmnd_start(struct iscsi_cmnd *req) !(req_hdr->flags & ISCSI_CMD_FINAL))) { PRINT_ERROR("Initiator %s violated negotiated paremeters: " "initial R2T is required (ITT %x, op %x)", - session->initiator_name, cmnd_itt(req), req_hdr->scb[0]); + session->initiator_name, cmnd_itt(req), + req_hdr->scb[0]); res = -EINVAL; goto out; } if (req->pdu.datasize) { if (unlikely(dir != SCST_DATA_WRITE)) { - PRINT_ERROR("pdu.datasize(%d) >0, but dir(%x) isn't WRITE", - req->pdu.datasize, dir); + PRINT_ERROR("pdu.datasize(%d) >0, but dir(%x) isn't " + "WRITE", req->pdu.datasize, dir); create_sense_rsp(req, ABORTED_COMMAND, 0xc, 0xc); cmnd_reject_scsi_cmd(req); } else - res = cmnd_prepare_recv_pdu(conn, req, 0, req->pdu.datasize); + res = cmnd_prepare_recv_pdu(conn, req, 0, + req->pdu.datasize); } out: /* Aborted commands will be freed in cmnd_rx_end() */ @@ -1449,7 +1466,8 @@ out: static int data_out_start(struct iscsi_conn *conn, struct iscsi_cmnd *cmnd) { - struct iscsi_data_out_hdr *req_hdr = (struct iscsi_data_out_hdr *)&cmnd->pdu.bhs; + struct iscsi_data_out_hdr *req_hdr = + (struct iscsi_data_out_hdr *)&cmnd->pdu.bhs; struct iscsi_cmnd *orig_req = NULL; u32 offset = be32_to_cpu(req_hdr->buffer_offset); int res = 0; @@ -1513,7 +1531,8 @@ out_reject: static void data_out_end(struct iscsi_cmnd *cmnd) { - struct iscsi_data_out_hdr *req_hdr = (struct iscsi_data_out_hdr *)&cmnd->pdu.bhs; + struct iscsi_data_out_hdr *req_hdr = + (struct iscsi_data_out_hdr *)&cmnd->pdu.bhs; struct iscsi_cmnd *req; sBUG_ON(cmnd == NULL); @@ -1549,7 +1568,8 @@ static void data_out_end(struct iscsi_cmnd *cmnd) if (unlikely(req->is_unsolicited_data)) { PRINT_ERROR("Unexpected unsolicited data " "(r2t_length %u, outstanding_r2t %d)", - req->r2t_length, req->is_unsolicited_data); + req->r2t_length, + req->is_unsolicited_data); mark_conn_closed(req->conn); goto out_put; } @@ -1644,10 +1664,10 @@ static int cmnd_abort(struct iscsi_cmnd *req) if (cmnd->pdu.bhs.opcode & ISCSI_OP_IMMEDIATE) { if (req_hdr->ref_cmd_sn != req_hdr->cmd_sn) { - PRINT_ERROR("ABORT TASK: RefCmdSN(%u) != TM cmd " - "CmdSN(%u) for immediate command %p", - req_hdr->ref_cmd_sn, req_hdr->cmd_sn, - cmnd); + PRINT_ERROR("ABORT TASK: RefCmdSN(%u) != TM " + "cmd CmdSN(%u) for immediate command " + "%p", req_hdr->ref_cmd_sn, + req_hdr->cmd_sn, cmnd); err = ISCSI_RESPONSE_FUNCTION_REJECTED; goto out_put; } @@ -1702,10 +1722,13 @@ static int target_abort(struct iscsi_cmnd *req, int all) mutex_lock(&target->target_mutex); - list_for_each_entry(session, &target->session_list, session_list_entry) { - list_for_each_entry(conn, &session->conn_list, conn_list_entry) { + list_for_each_entry(session, &target->session_list, + session_list_entry) { + list_for_each_entry(conn, &session->conn_list, + conn_list_entry) { spin_lock_bh(&conn->cmd_list_lock); - list_for_each_entry(cmnd, &conn->cmd_list, cmd_list_entry) { + list_for_each_entry(cmnd, &conn->cmd_list, + cmd_list_entry) { if (cmnd == req) continue; if (all) @@ -1771,8 +1794,8 @@ again: spin_unlock_bh(&conn->cmd_list_lock); /* ToDo: this is racy for MC/S */ - TRACE_MGMT_DBG("Restarting data waiting cmd %p", - cmnd); + TRACE_MGMT_DBG("Restarting data waiting cmd " + "%p", cmnd); iscsi_fail_waiting_cmnd(cmnd); cmnd_put(cmnd); @@ -1801,7 +1824,8 @@ static void execute_task_management(struct iscsi_cmnd *req) int rc, status, function = req_hdr->function & ISCSI_FUNCTION_MASK; struct scst_rx_mgmt_params params; - TRACE((function == ISCSI_FUNCTION_ABORT_TASK) ? TRACE_MGMT_MINOR : TRACE_MGMT, + TRACE((function == ISCSI_FUNCTION_ABORT_TASK) ? + TRACE_MGMT_MINOR : TRACE_MGMT, "TM fn %d", function); TRACE_MGMT_DBG("TM req %p, itt %x, rtt %x, sn %u, con %p", req, @@ -2046,7 +2070,8 @@ out_rejected: cmnd->reject_reason); switch (cmnd->reject_reason) { default: - PRINT_ERROR("Unexpected reject reason %d", cmnd->reject_reason); + PRINT_ERROR("Unexpected reject reason %d", + cmnd->reject_reason); /* go through */ case ISCSI_REJECT_SCSI_CMD: req_cmnd_release(cmnd); @@ -2089,7 +2114,8 @@ static void set_cork(struct socket *sock, int on) oldfs = get_fs(); set_fs(get_ds()); - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (void *)&opt, sizeof(opt)); + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, + (void *)&opt, sizeof(opt)); set_fs(oldfs); } @@ -2127,7 +2153,8 @@ void cmnd_tx_start(struct iscsi_cmnd *cmnd) break; case ISCSI_OP_SCSI_DATA_IN: { - struct iscsi_data_in_hdr *rsp = (struct iscsi_data_in_hdr *)&cmnd->pdu.bhs; + struct iscsi_data_in_hdr *rsp = + (struct iscsi_data_in_hdr *)&cmnd->pdu.bhs; u32 offset = cpu_to_be32(rsp->buffer_offset); cmnd_set_sn(cmnd, (rsp->flags & ISCSI_FLG_FINAL) ? 1 : 0); @@ -2201,7 +2228,8 @@ static void iscsi_session_push_cmnd(struct iscsi_cmnd *cmnd) u32 cmd_sn; TRACE_DBG("%p:%x %u,%u", - cmnd, cmnd_opcode(cmnd), cmnd->pdu.bhs.sn, session->exp_cmd_sn); + cmnd, cmnd_opcode(cmnd), cmnd->pdu.bhs.sn, + session->exp_cmd_sn); iscsi_extracheck_is_rd_thread(cmnd->conn); @@ -2242,8 +2270,9 @@ static void iscsi_session_push_cmnd(struct iscsi_cmnd *cmnd) if (list_empty(&session->pending_list)) break; - cmnd = list_entry(session->pending_list.next, struct iscsi_cmnd, - pending_list_entry); + cmnd = list_entry(session->pending_list.next, + struct iscsi_cmnd, + pending_list_entry); if (cmnd->pdu.bhs.sn != cmd_sn) break; @@ -2290,7 +2319,8 @@ static void iscsi_session_push_cmnd(struct iscsi_cmnd *cmnd) spin_unlock(&session->sn_lock); if (unlikely(drop)) { - req_cmnd_release_force(cmnd, ISCSI_FORCE_RELEASE_WRITE); + req_cmnd_release_force(cmnd, + ISCSI_FORCE_RELEASE_WRITE); goto out; } @@ -2306,7 +2336,8 @@ static void iscsi_session_push_cmnd(struct iscsi_cmnd *cmnd) tm_clone->tm_aborted = 1; tm_clone->pdu = cmnd->pdu; - TRACE_MGMT_DBG("TM clone %p created", tm_clone); + TRACE_MGMT_DBG("TM clone %p created", + tm_clone); iscsi_cmnd_exec(cmnd); cmnd = tm_clone; @@ -2315,8 +2346,9 @@ static void iscsi_session_push_cmnd(struct iscsi_cmnd *cmnd) } list_for_each(entry, &session->pending_list) { - struct iscsi_cmnd *tmp = list_entry(entry, struct iscsi_cmnd, - pending_list_entry); + struct iscsi_cmnd *tmp = + list_entry(entry, struct iscsi_cmnd, + pending_list_entry); if (before(cmd_sn, tmp->pdu.bhs.sn)) break; } @@ -2436,7 +2468,8 @@ out: out_rejected: switch (cmnd->reject_reason) { default: - PRINT_ERROR("Unexpected reject reason %d", cmnd->reject_reason); + PRINT_ERROR("Unexpected reject reason %d", + cmnd->reject_reason); /* go through */ case ISCSI_REJECT_CMD: case ISCSI_REJECT_DATA: @@ -2576,7 +2609,8 @@ static int iscsi_xmit_response(struct scst_cmd *scst_cmd) req->scst_state = ISCSI_CMD_STATE_PROCESSED; req_cmnd_release_force(req, ISCSI_FORCE_RELEASE_WRITE); } else - iscsi_set_state_wake_up(req, ISCSI_CMD_STATE_PROCESSED); + iscsi_set_state_wake_up(req, + ISCSI_CMD_STATE_PROCESSED); goto out; } @@ -2609,7 +2643,8 @@ static int iscsi_xmit_response(struct scst_cmd *scst_cmd) req->sg_cnt); if (unlikely((req->bufflen != 0) && !is_send_status)) { - PRINT_CRIT_ERROR("%s", "Sending DATA without STATUS is unsupported"); + PRINT_CRIT_ERROR("%s", "Sending DATA without STATUS is " + "unsupported"); scst_set_cmd_error(scst_cmd, SCST_LOAD_SENSE(scst_sense_hardw_error)); sBUG(); @@ -2631,16 +2666,19 @@ static int iscsi_xmit_response(struct scst_cmd *scst_cmd) if (is_send_status) { rsp = create_status_rsp(req, status, sense, sense_len); - rsp_hdr = (struct iscsi_scsi_rsp_hdr *)&rsp->pdu.bhs; + rsp_hdr = + (struct iscsi_scsi_rsp_hdr *)&rsp->pdu.bhs; resid = cmnd_read_size(req) - req->bufflen; if (resid > 0) { rsp_hdr->flags |= ISCSI_FLG_RESIDUAL_UNDERFLOW; - rsp_hdr->residual_count = cpu_to_be32(resid); + rsp_hdr->residual_count = + cpu_to_be32(resid); } else if (resid < 0) { rsp_hdr->flags |= ISCSI_FLG_RESIDUAL_OVERFLOW; - rsp_hdr->residual_count = cpu_to_be32(-resid); + rsp_hdr->residual_count = + cpu_to_be32(-resid); } iscsi_cmnd_init_write(rsp, ISCSI_INIT_WRITE_REMOVE_HASH); @@ -2810,7 +2848,8 @@ static void iscsi_task_mgmt_fn_done(struct scst_mgmt_cmd *scst_mcmd) { struct iscsi_cmnd *req = (struct iscsi_cmnd *) scst_mgmt_cmd_get_tgt_priv(scst_mcmd); - int status = iscsi_get_mgmt_response(scst_mgmt_cmd_get_status(scst_mcmd)); + int status = + iscsi_get_mgmt_response(scst_mgmt_cmd_get_status(scst_mcmd)); TRACE_MGMT_DBG("req %p, scst_mcmd %p, fn %d, scst status %d", req, scst_mcmd, scst_mgmt_cmd_get_fn(scst_mcmd), @@ -2924,7 +2963,8 @@ static int __init iscsi_init(void) ctr_major = register_chrdev(0, ctr_name, &ctr_fops); if (ctr_major < 0) { - PRINT_ERROR("failed to register the control device %d", ctr_major); + PRINT_ERROR("failed to register the control device %d", + ctr_major); err = ctr_major; goto out_callb; } diff --git a/iscsi-scst/kernel/iscsi.h b/iscsi-scst/kernel/iscsi.h index bbfa594dd..ea004435b 100644 --- a/iscsi-scst/kernel/iscsi.h +++ b/iscsi-scst/kernel/iscsi.h @@ -164,7 +164,10 @@ struct iscsi_conn { struct task_struct *wr_task; #endif - /* All are unprotected, since accessed only from a single write thread */ + /* + * All are unprotected, since accessed only from a single write + * thread. + */ struct iscsi_cmnd *write_cmnd; struct iovec *write_iop; int write_iop_used; @@ -199,7 +202,10 @@ struct iscsi_conn { struct task_struct *rd_task; #endif - /* All are unprotected, since accessed only from a single read thread */ + /* + * All are unprotected, since accessed only from a single read + * thread. + */ struct iscsi_cmnd *read_cmnd; struct msghdr read_msg; u32 read_size; @@ -208,7 +214,7 @@ struct iscsi_conn { struct iscsi_target *target; - struct list_head conn_list_entry; /* list entry in session conn_list */ + struct list_head conn_list_entry; /* list entry in session conn_list */ /* Doesn't need any protection */ u16 cid; @@ -221,14 +227,21 @@ struct iscsi_pdu { unsigned int datasize; }; -typedef void (iscsi_show_info_t)(struct seq_file *seq, struct iscsi_target *target); +typedef void (iscsi_show_info_t)(struct seq_file *seq, + struct iscsi_target *target); /* Command's states */ -#define ISCSI_CMD_STATE_NEW 0 /* New command and SCST processes it */ -#define ISCSI_CMD_STATE_RX_CMD 1 /* SCST processes cmd after scst_rx_cmd() */ -#define ISCSI_CMD_STATE_AFTER_PREPROC 2 /* The command returned from preprocessing_done() */ -#define ISCSI_CMD_STATE_RESTARTED 3 /* scst_restart_cmd() called and SCST processing it */ -#define ISCSI_CMD_STATE_PROCESSED 4 /* SCST done processing */ + +/* New command and SCST processes it */ +#define ISCSI_CMD_STATE_NEW 0 +/* SCST processes cmd after scst_rx_cmd() */ +#define ISCSI_CMD_STATE_RX_CMD 1 +/* The command returned from preprocessing_done() */ +#define ISCSI_CMD_STATE_AFTER_PREPROC 2 +/* scst_restart_cmd() called and SCST processing it */ +#define ISCSI_CMD_STATE_RESTARTED 3 +/* SCST done processing */ +#define ISCSI_CMD_STATE_PROCESSED 4 /* Command's reject reasons */ #define ISCSI_REJECT_SCSI_CMD 1 @@ -263,7 +276,8 @@ struct iscsi_cmnd { unsigned int release_called:1; #endif - volatile unsigned int tm_aborted; /* it's async. with the above flags */ + /* It's async. with the above flags */ + volatile unsigned int tm_aborted; struct list_head hash_list_entry; @@ -393,14 +407,16 @@ extern int session_del(struct iscsi_target *, u64); extern int session_free(struct iscsi_session *session); /* params.c */ -extern int iscsi_param_set(struct iscsi_target *, struct iscsi_param_info *, int); +extern int iscsi_param_set(struct iscsi_target *, struct iscsi_param_info *, + int); /* event.c */ extern int event_send(u32, u64, u32, u32, int); extern int event_init(void); extern void event_exit(void); -#define get_pgcnt(size, offset) ((((size) + ((offset) & ~PAGE_MASK)) + PAGE_SIZE - 1) >> PAGE_SHIFT) +#define get_pgcnt(size, offset) \ + ((((size) + ((offset) & ~PAGE_MASK)) + PAGE_SIZE - 1) >> PAGE_SHIFT) static inline void iscsi_cmnd_get_length(struct iscsi_pdu *pdu) { diff --git a/iscsi-scst/kernel/iscsi_dbg.h b/iscsi-scst/kernel/iscsi_dbg.h index 40bfb006a..b442d9cdf 100644 --- a/iscsi-scst/kernel/iscsi_dbg.h +++ b/iscsi-scst/kernel/iscsi_dbg.h @@ -30,7 +30,8 @@ #define TRACE_D_DATA (TRACE_D_READ | TRACE_D_WRITE) -#define TRACE_ALL_NO_DATA (TRACE_ALL & ~TRACE_D_IOV & ~TRACE_D_DUMP_PDU & ~TRACE_D_DATA) +#define TRACE_ALL_NO_DATA \ + (TRACE_ALL & ~TRACE_D_IOV & ~TRACE_D_DUMP_PDU & ~TRACE_D_DATA) #ifdef CONFIG_SCST_DEBUG #define ISCSI_DEFAULT_LOG_FLAGS (TRACE_FUNCTION | TRACE_LINE | TRACE_PID | \ diff --git a/iscsi-scst/kernel/nthread.c b/iscsi-scst/kernel/nthread.c index 6515479ab..f9408e4b2 100644 --- a/iscsi-scst/kernel/nthread.c +++ b/iscsi-scst/kernel/nthread.c @@ -117,9 +117,11 @@ again: } spin_lock_bh(&cmnd->rsp_cmd_lock); - list_for_each_entry(rsp, &cmnd->rsp_cmd_list, rsp_cmd_list_entry) { - TRACE_CONN_CLOSE_DBG(" rsp %p, ref_cnt %d, net_ref_cnt %d, " - "sg %p", rsp, atomic_read(&rsp->ref_cnt), + list_for_each_entry(rsp, &cmnd->rsp_cmd_list, + rsp_cmd_list_entry) { + TRACE_CONN_CLOSE_DBG(" rsp %p, ref_cnt %d, " + "net_ref_cnt %d, sg %p", + rsp, atomic_read(&rsp->ref_cnt), atomic_read(&rsp->net_ref_cnt), rsp->sg); if ((rsp->sg != cmnd->sg) && (rsp->sg != NULL)) { @@ -129,9 +131,12 @@ again: continue; for (i = 0; i < rsp->sg_cnt; i++) { - struct page *page = sg_page(&rsp->sg[i]); - TRACE_CONN_CLOSE_DBG(" page %p, net_priv %p, " - "_count %d", page, page->net_priv, + struct page *page = + sg_page(&rsp->sg[i]); + TRACE_CONN_CLOSE_DBG( + " page %p, net_priv %p, " + "_count %d", + page, page->net_priv, atomic_read(&page->_count)); if (page->net_priv != NULL) { @@ -178,6 +183,151 @@ static void iscsi_unreg_cmds_done_fn(struct scst_session *scst_sess) return; } +static void free_pending_commands(struct iscsi_conn *conn) +{ + struct iscsi_session *session = conn->session; + struct list_head *pending_list = &session->pending_list; + int req_freed; + struct iscsi_cmnd *cmnd; + + spin_lock(&session->sn_lock); + do { + req_freed = 0; + list_for_each_entry(cmnd, pending_list, pending_list_entry) { + TRACE_CONN_CLOSE_DBG("Pending cmd %p" + "(conn %p, cmd_sn %u, exp_cmd_sn %u)", + cmnd, conn, cmnd->pdu.bhs.sn, + session->exp_cmd_sn); + if ((cmnd->conn == conn) && + (session->exp_cmd_sn == cmnd->pdu.bhs.sn)) { + TRACE_CONN_CLOSE_DBG("Freeing pending cmd %p", + cmnd); + + list_del(&cmnd->pending_list_entry); + cmnd->pending = 0; + + session->exp_cmd_sn++; + + spin_unlock(&session->sn_lock); + + req_cmnd_release_force(cmnd, 0); + + req_freed = 1; + spin_lock(&session->sn_lock); + break; + } + } + } while (req_freed); + spin_unlock(&session->sn_lock); +} + +static void free_orphaned_pending_commands(struct iscsi_conn *conn) +{ + struct iscsi_session *session = conn->session; + struct list_head *pending_list = &session->pending_list; + int req_freed; + struct iscsi_cmnd *cmnd; + + spin_lock(&session->sn_lock); + do { + req_freed = 0; + list_for_each_entry(cmnd, pending_list, pending_list_entry) { + TRACE_CONN_CLOSE_DBG("Pending cmd %p" + "(conn %p, cmd_sn %u, exp_cmd_sn %u)", + cmnd, conn, cmnd->pdu.bhs.sn, + session->exp_cmd_sn); + if (cmnd->conn == conn) { + PRINT_ERROR("Freeing orphaned pending cmd %p", + cmnd); + + list_del(&cmnd->pending_list_entry); + cmnd->pending = 0; + + if (session->exp_cmd_sn == cmnd->pdu.bhs.sn) + session->exp_cmd_sn++; + + spin_unlock(&session->sn_lock); + + req_cmnd_release_force(cmnd, 0); + + req_freed = 1; + spin_lock(&session->sn_lock); + break; + } + } + } while (req_freed); + spin_unlock(&session->sn_lock); +} + +#ifdef CONFIG_SCST_DEBUG +static void trace_conn_close(struct iscsi_conn *conn) +{ + struct iscsi_cmnd *cmnd; +#if defined(CONFIG_TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION) + struct iscsi_cmnd *rsp; +#endif + +#if 0 + if (time_after(jiffies, start_waiting + 10*HZ)) + trace_flag |= TRACE_CONN_OC_DBG; +#endif + + spin_lock_bh(&conn->cmd_list_lock); + list_for_each_entry(cmnd, &conn->cmd_list, + cmd_list_entry) { + TRACE_CONN_CLOSE_DBG( + "cmd %p, scst_state %x, scst_cmd state %d, " + "data_waiting %d, ref_cnt %d, sn %u, " + "parent_req %p, pending %d", + cmnd, cmnd->scst_state, + cmnd->scst_cmd ? cmnd->scst_cmd->state : -1, + cmnd->data_waiting, atomic_read(&cmnd->ref_cnt), + cmnd->pdu.bhs.sn, cmnd->parent_req, cmnd->pending); +#if defined(CONFIG_TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION) + TRACE_CONN_CLOSE_DBG("net_ref_cnt %d, sg %p", + atomic_read(&cmnd->net_ref_cnt), + cmnd->sg); + if (cmnd->sg != NULL) { + int i; + for (i = 0; i < cmnd->sg_cnt; i++) { + struct page *page = sg_page(&cmnd->sg[i]); + TRACE_CONN_CLOSE_DBG("page %p, " + "net_priv %p, _count %d", + page, page->net_priv, + atomic_read(&page->_count)); + } + } + + sBUG_ON(cmnd->parent_req != NULL); + + spin_lock_bh(&cmnd->rsp_cmd_lock); + list_for_each_entry(rsp, &cmnd->rsp_cmd_list, + rsp_cmd_list_entry) { + TRACE_CONN_CLOSE_DBG(" rsp %p, " + "ref_cnt %d, net_ref_cnt %d, sg %p", + rsp, atomic_read(&rsp->ref_cnt), + atomic_read(&rsp->net_ref_cnt), rsp->sg); + if (rsp->sg != cmnd->sg && rsp->sg) { + int i; + for (i = 0; i < rsp->sg_cnt; i++) { + TRACE_CONN_CLOSE_DBG(" page %p, " + "net_priv %p, _count %d", + sg_page(&rsp->sg[i]), + sg_page(&rsp->sg[i])->net_priv, + atomic_read(&sg_page(&rsp->sg[i])-> + _count)); + } + } + } + spin_unlock_bh(&cmnd->rsp_cmd_lock); +#endif /* CONFIG_TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION */ + } + spin_unlock_bh(&conn->cmd_list_lock); +} +#else /* CONFIG_SCST_DEBUG */ +static void trace_conn_close(struct iscsi_conn *conn) {} +#endif /* CONFIG_SCST_DEBUG */ + /* No locks */ static void close_conn(struct iscsi_conn *conn) { @@ -211,7 +361,7 @@ static void close_conn(struct iscsi_conn *conn) /* * We need to call scst_unregister_session() ASAP to make SCST start - * stuck commands recovery. + * recovering stuck commands. * * ToDo: this is incompatible with MC/S */ @@ -230,11 +380,9 @@ static void close_conn(struct iscsi_conn *conn) /* ToDo: not the best way to wait */ while (atomic_read(&conn->conn_ref_cnt) != 0) { - struct iscsi_cmnd *cmnd; - mutex_lock(&target->target_mutex); spin_lock(&session->sn_lock); - if ((session->tm_rsp != NULL) && (session->tm_rsp->conn == conn)) { + if (session->tm_rsp && session->tm_rsp->conn == conn) { struct iscsi_cmnd *tm_rsp = session->tm_rsp; TRACE(TRACE_MGMT_MINOR, "Dropping delayed TM rsp %p", tm_rsp); @@ -251,86 +399,28 @@ static void close_conn(struct iscsi_conn *conn) } if (!list_empty(&session->pending_list)) { - struct list_head *pending_list = &session->pending_list; - int req_freed; - TRACE_CONN_CLOSE_DBG("Disposing pending commands on " - "connection %p (conn_ref_cnt=%d)", conn, + "connection %p (conn_ref_cnt=%d)", + conn, atomic_read(&conn->conn_ref_cnt)); /* - * Such complicated approach currently isn't necessary, - * but it will be necessary for MC/S, if we won't want - * to reestablish the whole session on a connection - * failure. + * Such complicated approach currently isn't really + * necessary, but it will be necessary for MC/S, if we + * won't want to reestablish the whole session on a + * connection failure. */ - spin_lock(&session->sn_lock); - do { - req_freed = 0; - list_for_each_entry(cmnd, pending_list, - pending_list_entry) { - TRACE_CONN_CLOSE_DBG("Pending cmd %p" - "(conn %p, cmd_sn %u, exp_cmd_sn %u)", - cmnd, conn, cmnd->pdu.bhs.sn, - session->exp_cmd_sn); - if ((cmnd->conn == conn) && - (session->exp_cmd_sn == cmnd->pdu.bhs.sn)) { - TRACE_CONN_CLOSE_DBG("Freeing pending cmd %p", - cmnd); + free_pending_commands(conn); - list_del(&cmnd->pending_list_entry); - cmnd->pending = 0; - - session->exp_cmd_sn++; - - spin_unlock(&session->sn_lock); - - req_cmnd_release_force(cmnd, 0); - - req_freed = 1; - spin_lock(&session->sn_lock); - break; - } - } - } while (req_freed); - spin_unlock(&session->sn_lock); - - if (time_after(jiffies, start_waiting + CONN_PENDING_TIMEOUT)) { + if (time_after(jiffies, + start_waiting + CONN_PENDING_TIMEOUT)) { if (!pending_reported) { - TRACE_CONN_CLOSE("%s", "Pending wait time expired"); + TRACE_CONN_CLOSE("%s", + "Pending wait time expired"); pending_reported = 1; } - spin_lock(&session->sn_lock); - do { - req_freed = 0; - list_for_each_entry(cmnd, pending_list, - pending_list_entry) { - TRACE_CONN_CLOSE_DBG("Pending cmd %p" - "(conn %p, cmd_sn %u, exp_cmd_sn %u)", - cmnd, conn, cmnd->pdu.bhs.sn, - session->exp_cmd_sn); - if (cmnd->conn == conn) { - PRINT_ERROR("Freeing orphaned " - "pending cmd %p", cmnd); - - list_del(&cmnd->pending_list_entry); - cmnd->pending = 0; - - if (session->exp_cmd_sn == cmnd->pdu.bhs.sn) - session->exp_cmd_sn++; - - spin_unlock(&session->sn_lock); - - req_cmnd_release_force(cmnd, 0); - - req_freed = 1; - spin_lock(&session->sn_lock); - break; - } - } - } while (req_freed); - spin_unlock(&session->sn_lock); + free_orphaned_pending_commands(conn); } } @@ -340,7 +430,8 @@ static void close_conn(struct iscsi_conn *conn) if (time_after(jiffies, start_waiting + CONN_WAIT_TIMEOUT) && !wait_expired) { TRACE_CONN_CLOSE("Wait time expired (conn %p, " - "sk_state %d)", conn, conn->sock->sk->sk_state); + "sk_state %d)", + conn, conn->sock->sk->sk_state); conn->sock->ops->shutdown(conn->sock, SEND_SHUTDOWN); wait_expired = 1; shut_start_waiting = jiffies; @@ -362,63 +453,12 @@ static void close_conn(struct iscsi_conn *conn) else msleep(1000); - TRACE_CONN_CLOSE_DBG("conn %p, conn_ref_cnt %d left, wr_state %d, " - "exp_cmd_sn %u", conn, atomic_read(&conn->conn_ref_cnt), + TRACE_CONN_CLOSE_DBG("conn %p, conn_ref_cnt %d left, " + "wr_state %d, exp_cmd_sn %u", + conn, atomic_read(&conn->conn_ref_cnt), conn->wr_state, session->exp_cmd_sn); #ifdef CONFIG_SCST_DEBUG - { -#if defined(CONFIG_TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION) - struct iscsi_cmnd *rsp; -#endif - -#if 0 - if (time_after(jiffies, start_waiting + 10*HZ)) - trace_flag |= TRACE_CONN_OC_DBG; -#endif - - spin_lock_bh(&conn->cmd_list_lock); - list_for_each_entry(cmnd, &conn->cmd_list, cmd_list_entry) { - TRACE_CONN_CLOSE_DBG("cmd %p, scst_state %x, scst_cmd " - "state %d, data_waiting %d, ref_cnt %d, sn %u, " - "parent_req %p, pending %d", cmnd, cmnd->scst_state, - (cmnd->scst_cmd != NULL) ? cmnd->scst_cmd->state : -1, - cmnd->data_waiting, atomic_read(&cmnd->ref_cnt), - cmnd->pdu.bhs.sn, cmnd->parent_req, cmnd->pending); -#if defined(CONFIG_TCP_ZERO_COPY_TRANSFER_COMPLETION_NOTIFICATION) - TRACE_CONN_CLOSE_DBG("net_ref_cnt %d, sg %p", - atomic_read(&cmnd->net_ref_cnt), cmnd->sg); - if (cmnd->sg != NULL) { - int i; - for (i = 0; i < cmnd->sg_cnt; i++) { - struct page *page = sg_page(&cmnd->sg[i]); - TRACE_CONN_CLOSE_DBG("page %p, net_priv %p, _count %d", - page, page->net_priv, - atomic_read(&page->_count)); - } - } - - sBUG_ON(cmnd->parent_req != NULL); - - spin_lock_bh(&cmnd->rsp_cmd_lock); - list_for_each_entry(rsp, &cmnd->rsp_cmd_list, rsp_cmd_list_entry) { - TRACE_CONN_CLOSE_DBG(" rsp %p, ref_cnt %d, net_ref_cnt %d, " - "sg %p", rsp, atomic_read(&rsp->ref_cnt), - atomic_read(&rsp->net_ref_cnt), rsp->sg); - if ((rsp->sg != cmnd->sg) && (rsp->sg != NULL)) { - int i; - for (i = 0; i < rsp->sg_cnt; i++) { - TRACE_CONN_CLOSE_DBG(" page %p, net_priv %p, " - "_count %d", sg_page(&rsp->sg[i]), - sg_page(&rsp->sg[i])->net_priv, - atomic_read(&sg_page(&rsp->sg[i])->_count)); - } - } - } - spin_unlock_bh(&cmnd->rsp_cmd_lock); -#endif - } - spin_unlock_bh(&conn->cmd_list_lock); - } + trace_conn_close(conn); #endif iscsi_check_closewait(conn); } @@ -444,7 +484,8 @@ static void close_conn(struct iscsi_conn *conn) msleep(50); } - TRACE_CONN_CLOSE("Notifying user space about closing connection %p", conn); + TRACE_CONN_CLOSE("Notifying user space about closing connection %p", + conn); event_send(target->tid, session->sid, conn->cid, E_CONN_CLOSE, 0); wait_for_completion(&session->unreg_compl); @@ -494,7 +535,8 @@ static void start_close_conn(struct iscsi_conn *conn) return; } -static inline void iscsi_conn_init_read(struct iscsi_conn *conn, void *data, size_t len) +static inline void iscsi_conn_init_read(struct iscsi_conn *conn, void *data, + size_t len) { len = (len + 3) & -4; /* XXX ??? */ conn->read_iov[0].iov_base = data; @@ -504,7 +546,8 @@ static inline void iscsi_conn_init_read(struct iscsi_conn *conn, void *data, siz conn->read_size = (len + 3) & -4; } -static void iscsi_conn_read_ahs(struct iscsi_conn *conn, struct iscsi_cmnd *cmnd) +static void iscsi_conn_read_ahs(struct iscsi_conn *conn, + struct iscsi_cmnd *cmnd) { /* ToDo: __GFP_NOFAIL ?? */ cmnd->pdu.ahs = kmalloc(cmnd->pdu.ahssize, __GFP_NOFAIL|GFP_KERNEL); @@ -548,7 +591,8 @@ static int do_recv(struct iscsi_conn *conn, int state) oldfs = get_fs(); set_fs(get_ds()); - res = sock_recvmsg(conn->sock, &msg, conn->read_size, MSG_DONTWAIT | MSG_NOSIGNAL); + res = sock_recvmsg(conn->sock, &msg, conn->read_size, + MSG_DONTWAIT | MSG_NOSIGNAL); set_fs(oldfs); if (res <= 0) { @@ -556,7 +600,7 @@ static int do_recv(struct iscsi_conn *conn, int state) case -EAGAIN: case -ERESTARTSYS: TRACE_DBG("EAGAIN or ERESTARTSYS (%d) received for " - "conn %p", res, conn); + "conn %p", res, conn); break; default: PRINT_ERROR("sock_recvmsg() failed: %d", res); @@ -575,7 +619,8 @@ static int do_recv(struct iscsi_conn *conn, int state) conn->read_size -= res; if (conn->read_size) { if (res >= first_len) { - int done = 1 + ((res - first_len) >> PAGE_SHIFT); + int done = + 1 + ((res - first_len) >> PAGE_SHIFT); conn->read_msg.msg_iov += done; conn->read_msg.msg_iovlen -= done; } @@ -637,7 +682,8 @@ static int recv(struct iscsi_conn *conn) iscsi_conn_read_ahs(conn, cmnd); conn->read_state = RX_AHS; } else - conn->read_state = hdigest ? RX_INIT_HDIGEST : RX_INIT_DATA; + conn->read_state = + hdigest ? RX_INIT_HDIGEST : RX_INIT_DATA; if (conn->read_state != RX_AHS) break; @@ -700,9 +746,9 @@ static int recv(struct iscsi_conn *conn) cmnd_get(cmnd); } else if (cmnd_opcode(cmnd) != ISCSI_OP_SCSI_DATA_OUT) { /* - * We could get here only for NOP-Out. ISCSI RFC doesn't - * specify how to deal with digest errors in this case. - * Is closing connection correct? + * We could get here only for NOP-Out. ISCSI RFC + * doesn't specify how to deal with digest errors in + * this case. Is closing connection correct? */ TRACE_DBG("cmnd %p, opcode %x: checking NOP RX " "ddigest", cmnd, cmnd_opcode(cmnd)); @@ -770,7 +816,9 @@ static void scst_do_job_rd(void) { TRACE_ENTRY(); - /* We delete/add to tail connections to maintain fairness between them */ + /* + * We delete/add to tail connections to maintain fairness between them. + */ while (!list_empty(&iscsi_rd_list)) { int rc, closed = 0; @@ -929,7 +977,8 @@ static int write_data(struct iscsi_conn *conn) mm_segment_t oldfs; struct file *file; struct socket *sock; - ssize_t (*sock_sendpage)(struct socket *, struct page *, int, size_t, int); + ssize_t (*sock_sendpage)(struct socket *, struct page *, int, size_t, + int); ssize_t (*sendpage)(struct socket *, struct page *, int, size_t, int); struct iscsi_cmnd *write_cmnd = conn->write_cmnd; struct iscsi_cmnd *ref_cmd; @@ -1064,18 +1113,20 @@ static int write_data(struct iscsi_conn *conn) if (sg_page(&sg[idx])->net_priv != NULL) { if (sg_page(&sg[idx])->net_priv != ref_cmd) { /* - * This might happen if user space supplies - * to scst_user the same pages in different - * commands or in case of zero-copy FILEIO, - * when several initiators request the same + * This might happen if user space + * supplies to scst_user the same + * pages in different commands or in + * case of zero-copy FILEIO, when + * several initiators request the same * data simultaneously. */ TRACE_DBG("net_priv isn't NULL and != " - "ref_cmd (write_cmnd %p, ref_cmd %p, " - "sg %p, idx %d, page %p, net_priv %p)", - write_cmnd, ref_cmd, sg, idx, - sg_page(&sg[idx]), - sg_page(&sg[idx])->net_priv); + "ref_cmd (write_cmnd %p, ref_cmd " + "%p, sg %p, idx %d, page %p, " + "net_priv %p)", + write_cmnd, ref_cmd, sg, idx, + sg_page(&sg[idx]), + sg_page(&sg[idx])->net_priv); sendpage = sock_no_sendpage; } } else @@ -1086,14 +1137,14 @@ static int write_data(struct iscsi_conn *conn) sendsize = PAGE_SIZE - offset; if (size <= sendsize) { retry2: - res = sendpage(sock, sg_page(&sg[idx]), offset, size, flags); - TRACE_WRITE("Final %s %#Lx:%u: %d(%lu,%u,%u, cmd %p, page %p)", - (sendpage != sock_no_sendpage) ? "sendpage" : - "sock_no_sendpage", + res = sendpage(sock, sg_page(&sg[idx]), offset, size, + flags); + TRACE_WRITE("Final %s %#Lx:%u: %d(%lu,%u,%u, cmd %p, " + "page %p)", (sendpage != sock_no_sendpage) ? + "sendpage" : "sock_no_sendpage", (long long unsigned int)conn->session->sid, - conn->cid, - res, sg_page(&sg[idx])->index, offset, size, - write_cmnd, sg_page(&sg[idx])); + conn->cid, res, sg_page(&sg[idx])->index, + offset, size, write_cmnd, sg_page(&sg[idx])); if (unlikely(res <= 0)) { if (res == -EINTR) goto retry2; @@ -1195,7 +1246,8 @@ static int exit_tx(struct iscsi_conn *conn, int res) { PRINT_ERROR("Sending data failed: initiator %s, " "write_size %d, write_state %d, res %d", - conn->session->initiator_name, conn->write_size, + conn->session->initiator_name, + conn->write_size, conn->write_state, res); } conn->write_state = TX_END; @@ -1239,7 +1291,9 @@ static void init_tx_hdigest(struct iscsi_cmnd *cmnd) digest_tx_header(cmnd); - sBUG_ON(conn->write_iop_used >= sizeof(conn->write_iov)/sizeof(conn->write_iov[0])); + sBUG_ON(conn->write_iop_used >= + sizeof(conn->write_iov)/sizeof(conn->write_iov[0])); + iop = &conn->write_iop[conn->write_iop_used]; conn->write_iop_used++; iop->iov_base = &(cmnd->hdigest); @@ -1362,7 +1416,9 @@ static void scst_do_job_wr(void) { TRACE_ENTRY(); - /* We delete/add to tail connections to maintain fairness between them */ + /* + * We delete/add to tail connections to maintain fairness between them. + */ while (!list_empty(&iscsi_wr_list)) { int rc; diff --git a/iscsi-scst/kernel/param.c b/iscsi-scst/kernel/param.c index fef754f49..6afdae312 100644 --- a/iscsi-scst/kernel/param.c +++ b/iscsi-scst/kernel/param.c @@ -16,34 +16,34 @@ #include "iscsi.h" #include "digest.h" -#define CHECK_PARAM(info, iparam, word, min, max) \ -do { \ - if (!(info)->partial || ((info)->partial & 1 << key_##word)) \ - if ((iparam)[key_##word] < (min) || \ - (iparam)[key_##word] > (max)) { \ - PRINT_ERROR("%s: %u is out of range (%u %u)", \ - #word, (iparam)[key_##word], (min), (max)); \ - if ((iparam)[key_##word] < (min)) \ - (iparam)[key_##word] = (min); \ - else \ - (iparam)[key_##word] = (max); \ - } \ +#define CHECK_PARAM(info, iparam, word, min, max) \ +do { \ + if (!(info)->partial || ((info)->partial & 1 << key_##word)) \ + if ((iparam)[key_##word] < (min) || \ + (iparam)[key_##word] > (max)) { \ + PRINT_ERROR("%s: %u is out of range (%u %u)", \ + #word, (iparam)[key_##word], (min), (max)); \ + if ((iparam)[key_##word] < (min)) \ + (iparam)[key_##word] = (min); \ + else \ + (iparam)[key_##word] = (max); \ + } \ } while (0) -#define SET_PARAM(param, info, iparam, word) \ -({ \ - int changed = 0; \ - if (!(info)->partial || ((info)->partial & 1 << key_##word)) { \ - if ((param)->word != (iparam)[key_##word]) \ - changed = 1; \ - (param)->word = (iparam)[key_##word]; \ - } \ - changed; \ +#define SET_PARAM(param, info, iparam, word) \ +({ \ + int changed = 0; \ + if (!(info)->partial || ((info)->partial & 1 << key_##word)) { \ + if ((param)->word != (iparam)[key_##word]) \ + changed = 1; \ + (param)->word = (iparam)[key_##word]; \ + } \ + changed; \ }) -#define GET_PARAM(param, info, iparam, word) \ -do { \ - (iparam)[key_##word] = (param)->word; \ +#define GET_PARAM(param, info, iparam, word) \ +do { \ + (iparam)[key_##word] = (param)->word; \ } while (0) static const char *get_bool_name(int val) @@ -68,7 +68,8 @@ static void log_params(struct iscsi_sess_param *param) { PRINT_INFO("Negotiated parameters: InitialR2T %s, ImmediateData %s, " "MaxConnections %d, MaxRecvDataSegmentLength %d, " - "MaxXmitDataSegmentLength %d, ", get_bool_name(param->initial_r2t), + "MaxXmitDataSegmentLength %d, ", + get_bool_name(param->initial_r2t), get_bool_name(param->immediate_data), param->max_connections, param->max_recv_data_length, param->max_xmit_data_length); PRINT_INFO(" MaxBurstLength %d, FirstBurstLength %d, " @@ -77,14 +78,16 @@ static void log_params(struct iscsi_sess_param *param) param->default_wait_time, param->default_retain_time); PRINT_INFO(" MaxOutstandingR2T %d, DataPDUInOrder %s, " "DataSequenceInOrder %s, ErrorRecoveryLevel %d, ", - param->max_outstanding_r2t, get_bool_name(param->data_pdu_inorder), + param->max_outstanding_r2t, + get_bool_name(param->data_pdu_inorder), get_bool_name(param->data_sequence_inorder), param->error_recovery_level); PRINT_INFO(" HeaderDigest %s, DataDigest %s, OFMarker %s, " "IFMarker %s, OFMarkInt %d, IFMarkInt %d", get_digest_name(param->header_digest), get_digest_name(param->data_digest), - get_bool_name(param->ofmarker), get_bool_name(param->ifmarker), + get_bool_name(param->ofmarker), + get_bool_name(param->ifmarker), param->ofmarkint, param->ifmarkint); } @@ -110,7 +113,8 @@ static void sess_param_check(struct iscsi_param_info *info) } /* target_mutex supposed to be locked */ -static void sess_param_set(struct iscsi_sess_param *param, struct iscsi_param_info *info) +static void sess_param_set(struct iscsi_sess_param *param, + struct iscsi_param_info *info) { u32 *iparam = info->session_param; @@ -135,7 +139,8 @@ static void sess_param_set(struct iscsi_sess_param *param, struct iscsi_param_in SET_PARAM(param, info, iparam, ifmarkint); } -static void sess_param_get(struct iscsi_sess_param *param, struct iscsi_param_info *info) +static void sess_param_get(struct iscsi_sess_param *param, + struct iscsi_param_info *info) { u32 *iparam = info->session_param; @@ -165,11 +170,13 @@ static void trgt_param_check(struct iscsi_param_info *info) { u32 *iparam = info->target_param; - CHECK_PARAM(info, iparam, queued_cmnds, MIN_NR_QUEUED_CMNDS, MAX_NR_QUEUED_CMNDS); + CHECK_PARAM(info, iparam, queued_cmnds, MIN_NR_QUEUED_CMNDS, + MAX_NR_QUEUED_CMNDS); } /* target_mutex supposed to be locked */ -static void trgt_param_set(struct iscsi_target *target, struct iscsi_param_info *info) +static void trgt_param_set(struct iscsi_target *target, + struct iscsi_param_info *info) { struct iscsi_trgt_param *param = &target->trgt_param; u32 *iparam = info->target_param; @@ -178,7 +185,8 @@ static void trgt_param_set(struct iscsi_target *target, struct iscsi_param_info } /* target_mutex supposed to be locked */ -static void trgt_param_get(struct iscsi_trgt_param *param, struct iscsi_param_info *info) +static void trgt_param_get(struct iscsi_trgt_param *param, + struct iscsi_param_info *info) { u32 *iparam = info->target_param; @@ -186,7 +194,8 @@ static void trgt_param_get(struct iscsi_trgt_param *param, struct iscsi_param_in } /* target_mutex supposed to be locked */ -static int trgt_param(struct iscsi_target *target, struct iscsi_param_info *info, int set) +static int trgt_param(struct iscsi_target *target, + struct iscsi_param_info *info, int set) { if (set) { struct iscsi_trgt_param *prm; @@ -203,7 +212,8 @@ static int trgt_param(struct iscsi_target *target, struct iscsi_param_info *info } /* target_mutex supposed to be locked */ -static int sess_param(struct iscsi_target *target, struct iscsi_param_info *info, int set) +static int sess_param(struct iscsi_target *target, + struct iscsi_param_info *info, int set) { struct iscsi_session *session = NULL; struct iscsi_sess_param *param; @@ -237,7 +247,8 @@ out: } /* target_mutex supposed to be locked */ -int iscsi_param_set(struct iscsi_target *target, struct iscsi_param_info *info, int set) +int iscsi_param_set(struct iscsi_target *target, struct iscsi_param_info *info, + int set) { int err; diff --git a/iscsi-scst/kernel/session.c b/iscsi-scst/kernel/session.c index a9f6da2f2..d13526c7d 100644 --- a/iscsi-scst/kernel/session.c +++ b/iscsi-scst/kernel/session.c @@ -21,7 +21,8 @@ struct iscsi_session *session_lookup(struct iscsi_target *target, u64 sid) { struct iscsi_session *session; - list_for_each_entry(session, &target->session_list, session_list_entry) { + list_for_each_entry(session, &target->session_list, + session_list_entry) { if ((session->sid == sid) && !session->shutting_down) return session; } @@ -29,7 +30,8 @@ struct iscsi_session *session_lookup(struct iscsi_target *target, u64 sid) } /* target_mutex supposed to be locked */ -static int iscsi_session_alloc(struct iscsi_target *target, struct session_info *info) +static int iscsi_session_alloc(struct iscsi_target *target, + struct session_info *info) { int err, i; struct iscsi_session *session; @@ -173,11 +175,13 @@ int session_del(struct iscsi_target *target, u64 sid) } /* target_mutex supposed to be locked */ -static void iscsi_session_info_show(struct seq_file *seq, struct iscsi_target *target) +static void iscsi_session_info_show(struct seq_file *seq, + struct iscsi_target *target) { struct iscsi_session *session; - list_for_each_entry(session, &target->session_list, session_list_entry) { + list_for_each_entry(session, &target->session_list, + session_list_entry) { seq_printf(seq, "\tsid:%llu initiator:%s shutting down %d\n", (long long unsigned int)session->sid, session->initiator_name, diff --git a/iscsi-scst/kernel/target.c b/iscsi-scst/kernel/target.c index 19f7b8113..dd1648ee5 100644 --- a/iscsi-scst/kernel/target.c +++ b/iscsi-scst/kernel/target.c @@ -215,6 +215,25 @@ out: return err; } +static void target_del_session(struct iscsi_target *target, + struct iscsi_session *session) +{ + TRACE_MGMT_DBG("Cleaning up session %p", session); + if (!list_empty(&session->conn_list)) { + struct iscsi_conn *conn, *tc; + list_for_each_entry_safe(conn, tc, &session->conn_list, + conn_list_entry) { + TRACE_MGMT_DBG("Mark conn %p closing", conn); + __mark_conn_closed(conn, + ISCSI_CONN_ACTIVE_CLOSE|ISCSI_CONN_DELETING); + } + } else { + TRACE_MGMT_DBG("Freeing session %p without connections", + session); + session_del(target, session->sid); + } +} + void target_del_all(void) { struct iscsi_target *target, *t; @@ -230,29 +249,17 @@ void target_del_all(void) if (list_empty(&target_list)) break; - list_for_each_entry_safe(target, t, &target_list, target_list_entry) { + list_for_each_entry_safe(target, t, &target_list, + target_list_entry) { struct iscsi_session *session, *ts; mutex_lock(&target->target_mutex); if (!list_empty(&target->session_list)) { - TRACE_MGMT_DBG("Cleaning up target %p", target); - list_for_each_entry_safe(session, ts, &target->session_list, + TRACE_MGMT_DBG("Cleaning up target %p", + target); + list_for_each_entry_safe(session, ts, + &target->session_list, session_list_entry) { - TRACE_MGMT_DBG("Cleaning up session %p", session); - if (!list_empty(&session->conn_list)) { - struct iscsi_conn *conn, *tc; - list_for_each_entry_safe(conn, tc, - &session->conn_list, - conn_list_entry) { - TRACE_MGMT_DBG("Mark conn %p " - "closing", conn); - __mark_conn_closed(conn, - ISCSI_CONN_ACTIVE_CLOSE|ISCSI_CONN_DELETING); - } - } else { - TRACE_MGMT_DBG("Freeing session %p " - "without connections", session); - session_del(target, session->sid); - } + target_del_session(target, session); } mutex_unlock(&target->target_mutex); } else { diff --git a/scst/include/scst.h b/scst/include/scst.h index 0ef783554..c3b44309c 100644 --- a/scst/include/scst.h +++ b/scst/include/scst.h @@ -2043,7 +2043,8 @@ static inline int scst_cmd_atomic(struct scst_cmd *cmd) { int res = cmd->atomic; #ifdef CONFIG_SCST_EXTRACHECKS - if (unlikely((in_atomic() || in_interrupt()) && !res)) { + if (unlikely((in_atomic() || in_interrupt() || irqs_disabled()) && + !res)) { printk(KERN_ERR "ERROR: atomic context and non-atomic cmd\n"); dump_stack(); cmd->atomic = 1;