- Fixes two problems on connection closing, leading to crashes and memory corruptions
authorvlnb <vlnb@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Fri, 4 Jan 2008 17:29:58 +0000 (17:29 +0000)
committervlnb <vlnb@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Fri, 4 Jan 2008 17:29:58 +0000 (17:29 +0000)
 - Small logging improvements

git-svn-id: https://scst.svn.sourceforge.net/svnroot/scst/trunk@242 d57e44dd-8a1f-0410-8b47-8ef2f437770f

iscsi-scst/kernel/iscsi.c
iscsi-scst/kernel/nthread.c
scst/src/scst_lib.c

index db9253e..5b90d74 100644 (file)
@@ -261,6 +261,8 @@ void req_cmnd_release_force(struct iscsi_cmnd *req, int flags)
 
        TRACE_DBG("%p", req);
 
+       sBUG_ON(req == conn->read_cmnd);
+
        if (flags & ISCSI_FORCE_RELEASE_WRITE) {
                spin_lock(&conn->write_list_lock);
                list_for_each_entry_safe(rsp, t, &conn->write_list,
@@ -921,7 +923,7 @@ static int cmnd_prepare_recv_pdu(struct iscsi_conn *conn,
                sBUG_ON(sg[idx].page == NULL);
                addr = page_address(sg[idx].page);
                sBUG_ON(addr == NULL);
-               conn->read_iov[i].iov_base =  addr + offset;
+               conn->read_iov[i].iov_base = addr + offset;
                if (offset + size <= PAGE_SIZE) {
                        TRACE_DBG("idx=%d, offset=%u, size=%d, addr=%p",
                                idx, offset, size, addr);
@@ -2478,6 +2480,8 @@ static bool iscsi_is_delay_tm_resp(struct iscsi_cmnd *rsp)
 
        TRACE_ENTRY();
 
+       /* This should be checked for immediate TM commands as well */
+
        switch(function) {
        default:
                if (before(sess->exp_cmd_sn, req_hdr->cmd_sn))
index ccf8d14..4cf37ef 100644 (file)
@@ -134,14 +134,15 @@ static void close_conn(struct iscsi_conn *conn)
        /* We want all our already send operations to complete */
        conn->sock->ops->shutdown(conn->sock, RCV_SHUTDOWN);
 
-       conn_abort(conn);
-
        if (conn->read_state != RX_INIT_BHS) {
-               req_cmnd_release_force(conn->read_cmnd, 0);
+               struct iscsi_cmnd *cmnd = conn->read_cmnd;
                conn->read_cmnd = NULL;
                conn->read_state = RX_INIT_BHS;
+               req_cmnd_release_force(cmnd, 0);
        }
 
+       conn_abort(conn);
+
        /* ToDo: not the best way to wait */
        while(atomic_read(&conn->conn_ref_cnt) != 0) {
                struct iscsi_cmnd *cmnd;
@@ -372,6 +373,8 @@ static int do_recv(struct iscsi_conn *conn, int state)
        struct msghdr msg;
        int res, first_len;
 
+       sBUG_ON(conn->read_cmnd == NULL);
+
        if (unlikely(conn->closing)) {
                res = -EIO;
                goto out;
@@ -559,12 +562,13 @@ static int recv(struct iscsi_conn *conn)
                sBUG();
        }
 
+       conn->read_cmnd = NULL;
+       conn->read_state = RX_INIT_BHS;
+
        cmnd_rx_end(cmnd);
 
        sBUG_ON(conn->read_size != 0);
 
-       conn->read_cmnd = NULL;
-       conn->read_state = RX_INIT_BHS;
        res = 0;
 
 out:
index 9d23c0a..fb7847c 100644 (file)
@@ -2291,17 +2291,27 @@ int scst_obtain_device_parameters(struct scst_device *dev)
 
                        goto out;
                } else {
-                       TRACE(TRACE_MGMT_MINOR, "Internal MODE SENSE to device "
-                               "%d:%d:%d:%d failed: %x", dev->scsi_dev->host->host_no,
-                               dev->scsi_dev->channel, dev->scsi_dev->id,
-                               dev->scsi_dev->lun, res);
-                       TRACE_BUFF_FLAG(TRACE_MGMT_MINOR, "MODE SENSE sense",
-                               sense_buffer, sizeof(sense_buffer));
                        if ((status_byte(res) == CHECK_CONDITION) &&
                            SCST_SENSE_VALID(sense_buffer) &&
                            (sense_buffer[2] == ILLEGAL_REQUEST)) {
+                               TRACE(TRACE_MGMT_MINOR, "Device %d:%d:%d:%d "
+                                       "doesn't support control mode page, using "
+                                       "defaults: TST %x, QUEUE ALG %x, SWP %x, "
+                                       "TAS %x, has_own_order_mgmt %d",
+                                       dev->scsi_dev->host->host_no,
+                                       dev->scsi_dev->channel, dev->scsi_dev->id,
+                                       dev->scsi_dev->lun, dev->tst, dev->queue_alg,
+                                       dev->swp, dev->tas, dev->has_own_order_mgmt);
                                res = 0;
                                goto out;
+                       } else {
+                               TRACE(TRACE_MGMT_MINOR, "Internal MODE SENSE to "
+                                       "device %d:%d:%d:%d failed: %x",
+                                       dev->scsi_dev->host->host_no,
+                                       dev->scsi_dev->channel, dev->scsi_dev->id,
+                                       dev->scsi_dev->lun, res);
+                               TRACE_BUFF_FLAG(TRACE_MGMT_MINOR, "MODE SENSE sense",
+                                       sense_buffer, sizeof(sense_buffer));
                        }
                        scst_check_internal_sense(dev, res, sense_buffer,
                                        sizeof(sense_buffer));