]> err.no Git - linux-2.6/blobdiff - drivers/scsi/libiscsi.c
Merge master.kernel.org:/pub/scm/linux/kernel/git/lethal/sh-2.6.23
[linux-2.6] / drivers / scsi / libiscsi.c
index 1632866f52cc4fc5749aad7e60b24946ff3d06b7..5606d1e62978433e7ca763e917b15e1c8af4c8e6 100644 (file)
@@ -140,7 +140,7 @@ static void iscsi_prep_scsi_cmd_pdu(struct iscsi_cmd_task *ctask)
         hdr->flags = ISCSI_ATTR_SIMPLE;
         int_to_scsilun(sc->device->lun, (struct scsi_lun *)hdr->lun);
         hdr->itt = build_itt(ctask->itt, conn->id, session->age);
-        hdr->data_length = cpu_to_be32(sc->request_bufflen);
+        hdr->data_length = cpu_to_be32(scsi_bufflen(sc));
         hdr->cmdsn = cpu_to_be32(session->cmdsn);
         session->cmdsn++;
         hdr->exp_statsn = cpu_to_be32(conn->exp_statsn);
@@ -172,11 +172,11 @@ static void iscsi_prep_scsi_cmd_pdu(struct iscsi_cmd_task *ctask)
                ctask->unsol_datasn = 0;
 
                if (session->imm_data_en) {
-                       if (sc->request_bufflen >= session->first_burst)
+                       if (scsi_bufflen(sc) >= session->first_burst)
                                ctask->imm_count = min(session->first_burst,
                                                        conn->max_xmit_dlength);
                        else
-                               ctask->imm_count = min(sc->request_bufflen,
+                               ctask->imm_count = min(scsi_bufflen(sc),
                                                        conn->max_xmit_dlength);
                        hton24(ctask->hdr->dlength, ctask->imm_count);
                } else
@@ -184,7 +184,7 @@ static void iscsi_prep_scsi_cmd_pdu(struct iscsi_cmd_task *ctask)
 
                if (!session->initial_r2t_en) {
                        ctask->unsol_count = min((session->first_burst),
-                               (sc->request_bufflen)) - ctask->imm_count;
+                               (scsi_bufflen(sc))) - ctask->imm_count;
                        ctask->unsol_offset = ctask->imm_count;
                }
 
@@ -204,7 +204,7 @@ static void iscsi_prep_scsi_cmd_pdu(struct iscsi_cmd_task *ctask)
         debug_scsi("iscsi prep [%s cid %d sc %p cdb 0x%x itt 0x%x len %d "
                "cmdsn %d win %d]\n",
                 sc->sc_data_direction == DMA_TO_DEVICE ? "write" : "read",
-                conn->id, sc, sc->cmnd[0], ctask->itt, sc->request_bufflen,
+               conn->id, sc, sc->cmnd[0], ctask->itt, scsi_bufflen(sc),
                 session->cmdsn, session->max_cmdsn - session->exp_cmdsn + 1);
 }
 
@@ -297,14 +297,14 @@ invalid_datalen:
        if (rhdr->flags & ISCSI_FLAG_CMD_UNDERFLOW) {
                int res_count = be32_to_cpu(rhdr->residual_count);
 
-               if (res_count > 0 && res_count <= sc->request_bufflen)
-                       sc->resid = res_count;
+               if (res_count > 0 && res_count <= scsi_bufflen(sc))
+                       scsi_set_resid(sc, res_count);
                else
                        sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
        } else if (rhdr->flags & ISCSI_FLAG_CMD_BIDI_UNDERFLOW)
                sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
        else if (rhdr->flags & ISCSI_FLAG_CMD_OVERFLOW)
-               sc->resid = be32_to_cpu(rhdr->residual_count);
+               scsi_set_resid(sc, be32_to_cpu(rhdr->residual_count));
 
 out:
        debug_scsi("done [sc %lx res %d itt 0x%x]\n",
@@ -596,9 +596,16 @@ static void iscsi_prep_mtask(struct iscsi_conn *conn,
        nop->cmdsn = cpu_to_be32(session->cmdsn);
        if (hdr->itt != RESERVED_ITT) {
                hdr->itt = build_itt(mtask->itt, conn->id, session->age);
+               /*
+                * TODO: We always use immediate, so we never hit this.
+                * If we start to send tmfs or nops as non-immediate then
+                * we should start checking the cmdsn numbers for mgmt tasks.
+                */
                if (conn->c_stage == ISCSI_CONN_STARTED &&
-                   !(hdr->opcode & ISCSI_OP_IMMEDIATE))
+                   !(hdr->opcode & ISCSI_OP_IMMEDIATE)) {
+                       session->queued_cmdsn++;
                        session->cmdsn++;
+               }
        }
 
        if (session->tt->init_mgmt_task)
@@ -641,9 +648,11 @@ static int iscsi_check_cmdsn_window_closed(struct iscsi_conn *conn)
        /*
         * Check for iSCSI window and take care of CmdSN wrap-around
         */
-       if (!iscsi_sna_lte(session->cmdsn, session->max_cmdsn)) {
-               debug_scsi("iSCSI CmdSN closed. MaxCmdSN %u CmdSN %u\n",
-                          session->max_cmdsn, session->cmdsn);
+       if (!iscsi_sna_lte(session->queued_cmdsn, session->max_cmdsn)) {
+               debug_scsi("iSCSI CmdSN closed. ExpCmdSn %u MaxCmdSN %u "
+                          "CmdSN %u/%u\n", session->exp_cmdsn,
+                          session->max_cmdsn, session->cmdsn,
+                          session->queued_cmdsn);
                return -ENOSPC;
        }
        return 0;
@@ -722,11 +731,6 @@ check_mgmt:
 
        /* process command queue */
        while (!list_empty(&conn->xmitqueue)) {
-               rc = iscsi_check_cmdsn_window_closed(conn);
-               if (rc) {
-                       spin_unlock_bh(&conn->session->lock);
-                       return rc;
-               }
                /*
                 * iscsi tcp may readd the task to the xmitqueue to send
                 * write data
@@ -834,12 +838,6 @@ int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
                goto fault;
        }
 
-       /*
-        * We check this here and in data xmit, because if we get to the point
-        * that this check is hitting the window then we have enough IO in
-        * flight and enough IO waiting to be transmitted it is better
-        * to let the scsi/block layer queue up.
-        */
        if (iscsi_check_cmdsn_window_closed(conn)) {
                reason = FAILURE_WINDOW_CLOSED;
                goto reject;
@@ -850,6 +848,8 @@ int iscsi_queuecommand(struct scsi_cmnd *sc, void (*done)(struct scsi_cmnd *))
                reason = FAILURE_OOM;
                goto reject;
        }
+       session->queued_cmdsn++;
+
        sc->SCp.phase = session->age;
        sc->SCp.ptr = (char *)ctask;
 
@@ -876,7 +876,7 @@ fault:
        printk(KERN_ERR "iscsi: cmd 0x%x is not queued (%d)\n",
               sc->cmnd[0], reason);
        sc->result = (DID_NO_CONNECT << 16);
-       sc->resid = sc->request_bufflen;
+       scsi_set_resid(sc, scsi_bufflen(sc));
        sc->scsi_done(sc);
        return 0;
 }
@@ -1140,12 +1140,18 @@ static void fail_command(struct iscsi_conn *conn, struct iscsi_cmd_task *ctask,
        if (!sc)
                return;
 
-       if (ctask->state != ISCSI_TASK_PENDING)
+       if (ctask->state == ISCSI_TASK_PENDING)
+               /*
+                * cmd never made it to the xmit thread, so we should not count
+                * the cmd in the sequencing
+                */
+               conn->session->queued_cmdsn--;
+       else
                conn->session->tt->cleanup_cmd_task(conn, ctask);
        iscsi_ctask_mtask_cleanup(ctask);
 
        sc->result = err;
-       sc->resid = sc->request_bufflen;
+       scsi_set_resid(sc, scsi_bufflen(sc));
        if (conn->ctask == ctask)
                conn->ctask = NULL;
        /* release ref from queuecommand */
@@ -1392,7 +1398,7 @@ iscsi_session_setup(struct iscsi_transport *iscsit,
        session->state = ISCSI_STATE_FREE;
        session->mgmtpool_max = ISCSI_MGMT_CMDS_MAX;
        session->cmds_max = cmds_max;
-       session->cmdsn = initial_cmdsn;
+       session->queued_cmdsn = session->cmdsn = initial_cmdsn;
        session->exp_cmdsn = initial_cmdsn + 1;
        session->max_cmdsn = initial_cmdsn + 1;
        session->max_r2t = 1;
@@ -1473,6 +1479,7 @@ void iscsi_session_teardown(struct iscsi_cls_session *cls_session)
        struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
        struct module *owner = cls_session->transport->owner;
 
+       iscsi_unblock_session(cls_session);
        scsi_remove_host(shost);
 
        iscsi_pool_free(&session->mgmtpool, (void**)session->mgmt_cmds);
@@ -1483,6 +1490,7 @@ void iscsi_session_teardown(struct iscsi_cls_session *cls_session)
        kfree(session->username);
        kfree(session->username_in);
        kfree(session->targetname);
+       kfree(session->netdev);
        kfree(session->hwaddress);
        kfree(session->initiatorname);
 
@@ -1614,11 +1622,8 @@ void iscsi_conn_teardown(struct iscsi_cls_conn *cls_conn)
        kfree(conn->persistent_address);
        __kfifo_put(session->mgmtpool.queue, (void*)&conn->login_mtask,
                    sizeof(void*));
-       if (session->leadconn == conn) {
+       if (session->leadconn == conn)
                session->leadconn = NULL;
-               /* no connections exits.. reset sequencing */
-               session->cmdsn = session->max_cmdsn = session->exp_cmdsn = 1;
-       }
        spin_unlock_bh(&session->lock);
 
        kfifo_free(conn->mgmtqueue);
@@ -1648,6 +1653,7 @@ int iscsi_conn_start(struct iscsi_cls_conn *cls_conn)
        spin_lock_bh(&session->lock);
        conn->c_stage = ISCSI_CONN_STARTED;
        session->state = ISCSI_STATE_LOGGED_IN;
+       session->queued_cmdsn = session->cmdsn;
 
        switch(conn->stop_stage) {
        case STOP_CONN_RECOVER:
@@ -2040,6 +2046,12 @@ int iscsi_host_get_param(struct Scsi_Host *shost, enum iscsi_host_param param,
        int len;
 
        switch (param) {
+       case ISCSI_HOST_PARAM_NETDEV_NAME:
+               if (!session->netdev)
+                       len = sprintf(buf, "%s\n", "default");
+               else
+                       len = sprintf(buf, "%s\n", session->netdev);
+               break;
        case ISCSI_HOST_PARAM_HWADDRESS:
                if (!session->hwaddress)
                        len = sprintf(buf, "%s\n", "default");
@@ -2067,6 +2079,10 @@ int iscsi_host_set_param(struct Scsi_Host *shost, enum iscsi_host_param param,
        struct iscsi_session *session = iscsi_hostdata(shost->hostdata);
 
        switch (param) {
+       case ISCSI_HOST_PARAM_NETDEV_NAME:
+               if (!session->netdev)
+                       session->netdev = kstrdup(buf, GFP_KERNEL);
+               break;
        case ISCSI_HOST_PARAM_HWADDRESS:
                if (!session->hwaddress)
                        session->hwaddress = kstrdup(buf, GFP_KERNEL);