Boaz Harrosh wrote:
> Remove the dark ages /* define debug_print */ in code, to use
> a Kconfig option. With a system like Kconfig, in code, commented out,
> configuration options are slavery and hard work.
> (version control, manual edit ... need I say more)
> 
> I've used an "int" config bit-mask so more areas of code can be
> selected with one Koption, but mainly so that allmodconfig will
> not turn it on.
> 
> bit-1 - will turn on prints for libiscsi.
> bit-2 - will turn on prints for libiscsi_tcp & iscsi_tcp.
> 
> More iscsi drivers should use more bits.
> 

I made this a per module compile time option. I also modified the macors 
so they added a sessionX or connectionX:Y prefix.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to open-iscsi@googlegroups.com
To unsubscribe from this group, send email to 
open-iscsi+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/open-iscsi
-~----------~----~----~----~------~----~------~--~---

>From 5e8e4a17f4fedf7eb86c180313b2a841e7cc764d Mon Sep 17 00:00:00 2001
From: Mike Christie <micha...@cs.wisc.edu>
Date: Sun, 8 Feb 2009 01:34:24 -0600

Make debugging a module load option.

---
 drivers/infiniband/ulp/iser/iscsi_iser.c |   10 +-
 drivers/scsi/iscsi_tcp.c                 |   57 +++++++-----
 drivers/scsi/libiscsi.c                  |  156 ++++++++++++++++++------------
 drivers/scsi/libiscsi_tcp.c              |  114 ++++++++++------------
 include/scsi/libiscsi.h                  |   23 +++-
 include/scsi/libiscsi_tcp.h              |   10 ++
 6 files changed, 215 insertions(+), 155 deletions(-)

diff --git a/drivers/infiniband/ulp/iser/iscsi_iser.c 
b/drivers/infiniband/ulp/iser/iscsi_iser.c
index 1287639..4338f54 100644
--- a/drivers/infiniband/ulp/iser/iscsi_iser.c
+++ b/drivers/infiniband/ulp/iser/iscsi_iser.c
@@ -168,7 +168,7 @@ iscsi_iser_mtask_xmit(struct iscsi_conn *conn, struct 
iscsi_task *task)
 {
        int error = 0;
 
-       debug_scsi("task deq [cid %d itt 0x%x]\n", conn->id, task->itt);
+       iser_dbg("task deq [cid %d itt 0x%x]\n", conn->id, task->itt);
 
        error = iser_send_control(conn, task);
 
@@ -195,7 +195,7 @@ iscsi_iser_task_xmit_unsol_data(struct iscsi_conn *conn,
        /* Send data-out PDUs while there's still unsolicited data to send */
        while (iscsi_task_has_unsol_data(task)) {
                iscsi_prep_data_out_pdu(task, r2t, &hdr);
-               debug_scsi("Sending data-out: itt 0x%x, data count %d\n",
+               iser_dbg("Sending data-out: itt 0x%x, data count %d\n",
                           hdr.itt, r2t->data_count);
 
                /* the buffer description has been passed with the command */
@@ -206,7 +206,7 @@ iscsi_iser_task_xmit_unsol_data(struct iscsi_conn *conn,
                        goto iscsi_iser_task_xmit_unsol_data_exit;
                }
                r2t->sent += r2t->data_count;
-               debug_scsi("Need to send %d more as data-out PDUs\n",
+               iser_dbg("Need to send %d more as data-out PDUs\n",
                           r2t->data_length - r2t->sent);
        }
 
@@ -227,12 +227,12 @@ iscsi_iser_task_xmit(struct iscsi_task *task)
        if (task->sc->sc_data_direction == DMA_TO_DEVICE) {
                BUG_ON(scsi_bufflen(task->sc) == 0);
 
-               debug_scsi("cmd [itt %x total %d imm %d unsol_data %d\n",
+               iser_dbg("cmd [itt %x total %d imm %d unsol_data %d\n",
                           task->itt, scsi_bufflen(task->sc),
                           task->imm_count, task->unsol_r2t.data_length);
        }
 
-       debug_scsi("task deq [cid %d itt 0x%x]\n",
+       iser_dbg("task deq [cid %d itt 0x%x]\n",
                   conn->id, task->itt);
 
        /* Send the cmd PDU */
diff --git a/drivers/scsi/iscsi_tcp.c b/drivers/scsi/iscsi_tcp.c
index 5a08ca4..9c2e527 100644
--- a/drivers/scsi/iscsi_tcp.c
+++ b/drivers/scsi/iscsi_tcp.c
@@ -48,13 +48,6 @@ MODULE_AUTHOR("Mike Christie <micha...@cs.wisc.edu>, "
              "Alex Aizman <itn...@yahoo.com>");
 MODULE_DESCRIPTION("iSCSI/TCP data-path");
 MODULE_LICENSE("GPL");
-#undef DEBUG_TCP
-
-#ifdef DEBUG_TCP
-#define debug_tcp(fmt...) printk(KERN_INFO "tcp: " fmt)
-#else
-#define debug_tcp(fmt...)
-#endif
 
 static struct scsi_transport_template *iscsi_sw_tcp_scsi_transport;
 static struct scsi_host_template iscsi_sw_tcp_sht;
@@ -63,6 +56,21 @@ static struct iscsi_transport iscsi_sw_tcp_transport;
 static unsigned int iscsi_max_lun = 512;
 module_param_named(max_lun, iscsi_max_lun, uint, S_IRUGO);
 
+static int iscsi_sw_tcp_dbg;
+module_param_named(debug_iscsi_tcp, iscsi_sw_tcp_dbg, int,
+                  S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(debug_iscsi_tcp, "Turn on debugging for iscsi_tcp module "
+                "Set to 1 to turn on, and zero to turn off. Default is off.");
+
+#define ISCSI_SW_TCP_DBG(_conn, dbg_fmt, arg...)               \
+       do {                                                    \
+               if (iscsi_sw_tcp_dbg)                           \
+                       iscsi_conn_printk(KERN_INFO, _conn,     \
+                                            "%s " dbg_fmt,     \
+                                            __func__, ##arg);  \
+       } while (0);
+
+
 /**
  * iscsi_sw_tcp_recv - TCP receive in sendfile fashion
  * @rd_desc: read descriptor
@@ -77,7 +85,7 @@ static int iscsi_sw_tcp_recv(read_descriptor_t *rd_desc, 
struct sk_buff *skb,
        unsigned int consumed, total_consumed = 0;
        int status;
 
-       debug_tcp("in %d bytes\n", skb->len - offset);
+       ISCSI_SW_TCP_DBG(conn, "in %d bytes\n", skb->len - offset);
 
        do {
                status = 0;
@@ -86,7 +94,8 @@ static int iscsi_sw_tcp_recv(read_descriptor_t *rd_desc, 
struct sk_buff *skb,
                total_consumed += consumed;
        } while (consumed != 0 && status != ISCSI_TCP_SKB_DONE);
 
-       debug_tcp("read %d bytes status %d\n", skb->len - offset, status);
+       ISCSI_SW_TCP_DBG(conn, "read %d bytes status %d\n",
+                        skb->len - offset, status);
        return total_consumed;
 }
 
@@ -131,7 +140,8 @@ static void iscsi_sw_tcp_state_change(struct sock *sk)
        if ((sk->sk_state == TCP_CLOSE_WAIT ||
             sk->sk_state == TCP_CLOSE) &&
            !atomic_read(&sk->sk_rmem_alloc)) {
-               debug_tcp("iscsi_tcp_state_change: TCP_CLOSE|TCP_CLOSE_WAIT\n");
+               ISCSI_SW_TCP_DBG(conn, "iscsi_tcp_state_change: "
+                                "TCP_CLOSE|TCP_CLOSE_WAIT\n");
                iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
        }
 
@@ -155,7 +165,7 @@ static void iscsi_sw_tcp_write_space(struct sock *sk)
        struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
 
        tcp_sw_conn->old_write_space(sk);
-       debug_tcp("iscsi_write_space: cid %d\n", conn->id);
+       ISCSI_SW_TCP_DBG(conn, "iscsi_write_space\n");
        scsi_queue_work(conn->session->host, &conn->xmitwork);
 }
 
@@ -283,7 +293,7 @@ static int iscsi_sw_tcp_xmit(struct iscsi_conn *conn)
                }
        }
 
-       debug_tcp("xmit %d bytes\n", consumed);
+       ISCSI_SW_TCP_DBG(conn, "xmit %d bytes\n", consumed);
 
        conn->txdata_octets += consumed;
        return consumed;
@@ -291,7 +301,7 @@ static int iscsi_sw_tcp_xmit(struct iscsi_conn *conn)
 error:
        /* Transmit error. We could initiate error recovery
         * here. */
-       debug_tcp("Error sending PDU, errno=%d\n", rc);
+       ISCSI_SW_TCP_DBG(conn, "Error sending PDU, errno=%d\n", rc);
        iscsi_conn_failure(conn, rc);
        return -EIO;
 }
@@ -334,9 +344,10 @@ static int iscsi_sw_tcp_send_hdr_done(struct 
iscsi_tcp_conn *tcp_conn,
        struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
 
        tcp_sw_conn->out.segment = tcp_sw_conn->out.data_segment;
-       debug_tcp("Header done. Next segment size %u total_size %u\n",
-                 tcp_sw_conn->out.segment.size,
-                 tcp_sw_conn->out.segment.total_size);
+       ISCSI_SW_TCP_DBG(tcp_conn->iscsi_conn,
+                        "Header done. Next segment size %u total_size %u\n",
+                        tcp_sw_conn->out.segment.size,
+                        tcp_sw_conn->out.segment.total_size);
        return 0;
 }
 
@@ -346,8 +357,8 @@ static void iscsi_sw_tcp_send_hdr_prep(struct iscsi_conn 
*conn, void *hdr,
        struct iscsi_tcp_conn *tcp_conn = conn->dd_data;
        struct iscsi_sw_tcp_conn *tcp_sw_conn = tcp_conn->dd_data;
 
-       debug_tcp("%s(%p%s)\n", __func__, tcp_conn,
-                       conn->hdrdgst_en? ", digest enabled" : "");
+       ISCSI_SW_TCP_DBG(conn, "%s\n", conn->hdrdgst_en ?
+                        "digest enabled" : "digest disabled");
 
        /* Clear the data segment - needs to be filled in by the
         * caller using iscsi_tcp_send_data_prep() */
@@ -389,9 +400,9 @@ iscsi_sw_tcp_send_data_prep(struct iscsi_conn *conn, struct 
scatterlist *sg,
        struct hash_desc *tx_hash = NULL;
        unsigned int hdr_spec_len;
 
-       debug_tcp("%s(%p, offset=%d, datalen=%d%s)\n", __func__,
-                       tcp_conn, offset, len,
-                       conn->datadgst_en? ", digest enabled" : "");
+       ISCSI_SW_TCP_DBG(conn, "offset=%d, datalen=%d %s\n", offset, len,
+                        conn->datadgst_en ?
+                        "digest enabled" : "digest disabled");
 
        /* Make sure the datalen matches what the caller
           said he would send. */
@@ -415,8 +426,8 @@ iscsi_sw_tcp_send_linear_data_prep(struct iscsi_conn *conn, 
void *data,
        struct hash_desc *tx_hash = NULL;
        unsigned int hdr_spec_len;
 
-       debug_tcp("%s(%p, datalen=%d%s)\n", __func__, tcp_conn, len,
-                 conn->datadgst_en? ", digest enabled" : "");
+       ISCSI_SW_TCP_DBG(conn, "datalen=%zd %s\n", len, conn->datadgst_en ?
+                        "digest enabled" : "digest disabled");
 
        /* Make sure the datalen matches what the caller
           said he would send. */
diff --git a/drivers/scsi/libiscsi.c b/drivers/scsi/libiscsi.c
index 809d32d..09e0fa4 100644
--- a/drivers/scsi/libiscsi.c
+++ b/drivers/scsi/libiscsi.c
@@ -38,6 +38,20 @@
 #include <scsi/scsi_transport_iscsi.h>
 #include <scsi/libiscsi.h>
 
+int iscsi_dbg_lib;
+module_param_named(debug_libiscsi, iscsi_dbg_lib, int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(debug_libiscsi, "Turn on debugging for libiscsi module. "
+                "Set to 1 to turn on, and zero to turn off. Default "
+                "is off.");
+
+#define ISCSI_DBG_SESSION(_session, dbg_fmt, arg...)                   \
+       do {                                                            \
+               if (iscsi_dbg_lib)                                      \
+                       iscsi_session_printk(KERN_INFO, _session,       \
+                                            "%s " dbg_fmt,             \
+                                            __func__, ##arg);          \
+       } while (0);
+
 /* Serial Number Arithmetic, 32 bits, less than, RFC1982 */
 #define SNA32_CHECK 2147483648UL
 
@@ -176,10 +190,11 @@ static int iscsi_prep_ecdb_ahs(struct iscsi_task *task)
        ecdb_ahdr->reserved = 0;
        memcpy(ecdb_ahdr->ecdb, cmd->cmnd + ISCSI_CDB_SIZE, rlen);
 
-       debug_scsi("iscsi_prep_ecdb_ahs: varlen_cdb_len %d "
-                  "rlen %d pad_len %d ahs_length %d iscsi_headers_size %u\n",
-                  cmd->cmd_len, rlen, pad_len, ahslength, task->hdr_len);
-
+       ISCSI_DBG_SESSION(task->conn->session,
+                         "iscsi_prep_ecdb_ahs: varlen_cdb_len %d "
+                         "rlen %d pad_len %d ahs_length %d iscsi_headers_size "
+                         "%u\n", cmd->cmd_len, rlen, pad_len, ahslength,
+                         task->hdr_len);
        return 0;
 }
 
@@ -201,10 +216,11 @@ static int iscsi_prep_bidi_ahs(struct iscsi_task *task)
        rlen_ahdr->reserved = 0;
        rlen_ahdr->read_length = cpu_to_be32(scsi_in(sc)->length);
 
-       debug_scsi("bidi-in rlen_ahdr->read_length(%d) "
-                  "rlen_ahdr->ahslength(%d)\n",
-                  be32_to_cpu(rlen_ahdr->read_length),
-                  be16_to_cpu(rlen_ahdr->ahslength));
+       ISCSI_DBG_SESSION(task->conn->session,
+                         "bidi-in rlen_ahdr->read_length(%d) "
+                         "rlen_ahdr->ahslength(%d)\n",
+                         be32_to_cpu(rlen_ahdr->read_length),
+                         be16_to_cpu(rlen_ahdr->ahslength));
        return 0;
 }
 
@@ -335,13 +351,15 @@ static int iscsi_prep_scsi_cmd_pdu(struct iscsi_task 
*task)
        list_move_tail(&task->running, &conn->run_list);
 
        conn->scsicmd_pdus_cnt++;
-       debug_scsi("iscsi prep [%s cid %d sc %p cdb 0x%x itt 0x%x len %d "
-                  "bidi_len %d cmdsn %d win %d]\n", scsi_bidi_cmnd(sc) ?
-                  "bidirectional" : sc->sc_data_direction == DMA_TO_DEVICE ?
-                  "write" : "read", conn->id, sc, sc->cmnd[0], task->itt,
-                  scsi_bufflen(sc),
-                  scsi_bidi_cmnd(sc) ? scsi_in(sc)->length : 0,
-                  session->cmdsn, session->max_cmdsn - session->exp_cmdsn + 1);
+       ISCSI_DBG_SESSION(session, "iscsi prep [%s cid %d sc %p cdb 0x%x "
+                         "itt 0x%x len %d bidi_len %d cmdsn %d win %d]\n",
+                         scsi_bidi_cmnd(sc) ? "bidirectional" :
+                         sc->sc_data_direction == DMA_TO_DEVICE ?
+                         "write" : "read", conn->id, sc, sc->cmnd[0],
+                         task->itt, scsi_bufflen(sc),
+                         scsi_bidi_cmnd(sc) ? scsi_in(sc)->length : 0,
+                         session->cmdsn,
+                         session->max_cmdsn - session->exp_cmdsn + 1);
        return 0;
 }
 
@@ -483,9 +501,9 @@ static int iscsi_prep_mgmt_task(struct iscsi_conn *conn,
 
        task->state = ISCSI_TASK_RUNNING;
        list_move_tail(&task->running, &conn->mgmt_run_list);
-       debug_scsi("mgmtpdu [op 0x%x hdr->itt 0x%x datalen %d]\n",
-                  hdr->opcode & ISCSI_OPCODE_MASK, hdr->itt,
-                  task->data_count);
+       ISCSI_DBG_SESSION(session, "mgmtpdu [op 0x%x hdr->itt 0x%x "
+                         "datalen %d]\n", hdr->opcode & ISCSI_OPCODE_MASK,
+                         hdr->itt, task->data_count);
        return 0;
 }
 
@@ -637,8 +655,9 @@ invalid_datalen:
 
                memcpy(sc->sense_buffer, data + 2,
                       min_t(uint16_t, senselen, SCSI_SENSE_BUFFERSIZE));
-               debug_scsi("copied %d bytes of sense\n",
-                          min_t(uint16_t, senselen, SCSI_SENSE_BUFFERSIZE));
+               ISCSI_DBG_SESSION(session, "copied %d bytes of sense\n",
+                                 min_t(uint16_t, senselen,
+                                 SCSI_SENSE_BUFFERSIZE));
        }
 
        if (rhdr->flags & (ISCSI_FLAG_CMD_BIDI_UNDERFLOW |
@@ -666,8 +685,8 @@ invalid_datalen:
                        sc->result = (DID_BAD_TARGET << 16) | rhdr->cmd_status;
        }
 out:
-       debug_scsi("done [sc %lx res %d itt 0x%x]\n",
-                  (long)sc, sc->result, task->itt);
+       ISCSI_DBG_SESSION(session, "done [sc %p res %d itt 0x%x]\n",
+                         sc, sc->result, task->itt);
        conn->scsirsp_pdus_cnt++;
 
        __iscsi_put_task(task);
@@ -835,8 +854,8 @@ int __iscsi_complete_pdu(struct iscsi_conn *conn, struct 
iscsi_hdr *hdr,
        else
                itt = ~0U;
 
-       debug_scsi("[op 0x%x cid %d itt 0x%x len %d]\n",
-                  opcode, conn->id, itt, datalen);
+       ISCSI_DBG_SESSION(session, "[op 0x%x cid %d itt 0x%x len %d]\n",
+                         opcode, conn->id, itt, datalen);
 
        if (itt == ~0U) {
                iscsi_update_cmdsn(session, (struct iscsi_nopin*)hdr);
@@ -1095,10 +1114,10 @@ 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->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);
+               ISCSI_DBG_SESSION(session, "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;
@@ -1152,7 +1171,7 @@ static int iscsi_data_xmit(struct iscsi_conn *conn)
 
        spin_lock_bh(&conn->session->lock);
        if (unlikely(conn->suspend_tx)) {
-               debug_scsi("conn %d Tx suspended!\n", conn->id);
+               ISCSI_DBG_SESSION(conn->session, "Tx suspended!\n");
                spin_unlock_bh(&conn->session->lock);
                return -ENODATA;
        }
@@ -1398,7 +1417,8 @@ prepd_reject:
        iscsi_complete_command(task);
 reject:
        spin_unlock(&session->lock);
-       debug_scsi("cmd 0x%x rejected (%d)\n", sc->cmnd[0], reason);
+       ISCSI_DBG_SESSION(session, "cmd 0x%x rejected (%d)\n",
+                         sc->cmnd[0], reason);
        spin_lock(host->host_lock);
        return SCSI_MLQUEUE_TARGET_BUSY;
 
@@ -1407,7 +1427,8 @@ prepd_fault:
        iscsi_complete_command(task);
 fault:
        spin_unlock(&session->lock);
-       debug_scsi("iscsi: cmd 0x%x is not queued (%d)\n", sc->cmnd[0], reason);
+       ISCSI_DBG_SESSION(session, "iscsi: cmd 0x%x is not queued (%d)\n",
+                         sc->cmnd[0], reason);
        if (!scsi_bidi_cmnd(sc))
                scsi_set_resid(sc, scsi_bufflen(sc));
        else {
@@ -1457,8 +1478,10 @@ int iscsi_eh_target_reset(struct scsi_cmnd *sc)
        spin_lock_bh(&session->lock);
        if (session->state == ISCSI_STATE_TERMINATE) {
 failed:
-               debug_scsi("failing target reset: session terminated "
-                          "[CID %d age %d]\n", conn->id, session->age);
+               iscsi_session_printk(KERN_INFO, session,
+                                    "failing target reset: Could not log "
+                                    "back into target [age %d]\n",
+                                    session->age);
                spin_unlock_bh(&session->lock);
                mutex_unlock(&session->eh_mutex);
                return FAILED;
@@ -1472,7 +1495,7 @@ failed:
         */
        iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
 
-       debug_scsi("iscsi_eh_target_reset wait for relogin\n");
+       ISCSI_DBG_SESSION(session, "wait for relogin\n");
        wait_event_interruptible(conn->ehwait,
                                 session->state == ISCSI_STATE_TERMINATE ||
                                 session->state == ISCSI_STATE_LOGGED_IN ||
@@ -1501,7 +1524,7 @@ static void iscsi_tmf_timedout(unsigned long data)
        spin_lock(&session->lock);
        if (conn->tmf_state == TMF_QUEUED) {
                conn->tmf_state = TMF_TIMEDOUT;
-               debug_scsi("tmf timedout\n");
+               ISCSI_DBG_SESSION(session, "tmf timedout\n");
                /* unblock eh_abort() */
                wake_up(&conn->ehwait);
        }
@@ -1521,7 +1544,7 @@ static int iscsi_exec_task_mgmt_fn(struct iscsi_conn 
*conn,
                spin_unlock_bh(&session->lock);
                iscsi_conn_failure(conn, ISCSI_ERR_CONN_FAILED);
                spin_lock_bh(&session->lock);
-               debug_scsi("tmf exec failure\n");
+               ISCSI_DBG_SESSION(session, "tmf exec failure\n");
                return -EPERM;
        }
        conn->tmfcmd_pdus_cnt++;
@@ -1529,7 +1552,7 @@ static int iscsi_exec_task_mgmt_fn(struct iscsi_conn 
*conn,
        conn->tmf_timer.function = iscsi_tmf_timedout;
        conn->tmf_timer.data = (unsigned long)conn;
        add_timer(&conn->tmf_timer);
-       debug_scsi("tmf set timeout\n");
+       ISCSI_DBG_SESSION(session, "tmf set timeout\n");
 
        spin_unlock_bh(&session->lock);
        mutex_unlock(&session->eh_mutex);
@@ -1573,16 +1596,18 @@ static void fail_all_commands(struct iscsi_conn *conn, 
unsigned lun,
        /* flush pending */
        list_for_each_entry_safe(task, tmp, &conn->xmitqueue, running) {
                if (lun == task->sc->device->lun || lun == -1) {
-                       debug_scsi("failing pending sc %p itt 0x%x\n",
-                                  task->sc, task->itt);
+                       ISCSI_DBG_SESSION(conn->session,
+                                         "failing pending sc %p itt 0x%x\n",
+                                         task->sc, task->itt);
                        fail_command(conn, task, error << 16);
                }
        }
 
        list_for_each_entry_safe(task, tmp, &conn->requeue, running) {
                if (lun == task->sc->device->lun || lun == -1) {
-                       debug_scsi("failing requeued sc %p itt 0x%x\n",
-                                  task->sc, task->itt);
+                       ISCSI_DBG_SESSION(conn->session,
+                                         "failing requeued sc %p itt 0x%x\n",
+                                         task->sc, task->itt);
                        fail_command(conn, task, error << 16);
                }
        }
@@ -1590,8 +1615,9 @@ static void fail_all_commands(struct iscsi_conn *conn, 
unsigned lun,
        /* fail all other running */
        list_for_each_entry_safe(task, tmp, &conn->run_list, running) {
                if (lun == task->sc->device->lun || lun == -1) {
-                       debug_scsi("failing in progress sc %p itt 0x%x\n",
-                                  task->sc, task->itt);
+                       ISCSI_DBG_SESSION(conn->session,
+                                        "failing in progress sc %p itt 0x%x\n",
+                                        task->sc, task->itt);
                        fail_command(conn, task, error << 16);
                }
        }
@@ -1622,7 +1648,7 @@ static enum blk_eh_timer_return 
iscsi_eh_cmd_timed_out(struct scsi_cmnd *scmd)
        cls_session = starget_to_session(scsi_target(scmd->device));
        session = cls_session->dd_data;
 
-       debug_scsi("scsi cmd %p timedout\n", scmd);
+       ISCSI_DBG_SESSION(session, "scsi cmd %p timedout\n", scmd);
 
        spin_lock(&session->lock);
        if (session->state != ISCSI_STATE_LOGGED_IN) {
@@ -1662,8 +1688,8 @@ static enum blk_eh_timer_return 
iscsi_eh_cmd_timed_out(struct scsi_cmnd *scmd)
                rc = BLK_EH_RESET_TIMER;
 done:
        spin_unlock(&session->lock);
-       debug_scsi("return %s\n", rc == BLK_EH_RESET_TIMER ?
-                                       "timer reset" : "nh");
+       ISCSI_DBG_SESSION(session, "return %s\n", rc == BLK_EH_RESET_TIMER ?
+                         "timer reset" : "nh");
        return rc;
 }
 
@@ -1697,13 +1723,13 @@ static void iscsi_check_transport_timeouts(unsigned 
long data)
 
        if (time_before_eq(last_recv + recv_timeout, jiffies)) {
                /* send a ping to try to provoke some traffic */
-               debug_scsi("Sending nopout as ping on conn %p\n", conn);
+               ISCSI_DBG_CONN(conn, "Sending nopout as ping\n");
                iscsi_send_nopout(conn, NULL);
                next_timeout = conn->last_ping + (conn->ping_timeout * HZ);
        } else
                next_timeout = last_recv + recv_timeout;
 
-       debug_scsi("Setting next tmo %lu\n", next_timeout);
+       ISCSI_DBG_CONN(conn, "Setting next tmo %lu\n", next_timeout);
        mod_timer(&conn->transport_timer, next_timeout);
 done:
        spin_unlock(&session->lock);
@@ -1740,7 +1766,8 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
         * got the command.
         */
        if (!sc->SCp.ptr) {
-               debug_scsi("sc never reached iscsi layer or it completed.\n");
+               ISCSI_DBG_SESSION(session, "sc never reached iscsi layer or "
+                                 "it completed.\n");
                spin_unlock_bh(&session->lock);
                mutex_unlock(&session->eh_mutex);
                return SUCCESS;
@@ -1762,11 +1789,13 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
        age = session->age;
 
        task = (struct iscsi_task *)sc->SCp.ptr;
-       debug_scsi("aborting [sc %p itt 0x%x]\n", sc, task->itt);
+       ISCSI_DBG_SESSION(session, "aborting [sc %p itt 0x%x]\n",
+                         sc, task->itt);
 
        /* task completed before time out */
        if (!task->sc) {
-               debug_scsi("sc completed while abort in progress\n");
+               ISCSI_DBG_SESSION(session, "sc completed while abort in "
+                                 "progress\n");
                goto success;
        }
 
@@ -1815,7 +1844,8 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
                if (!sc->SCp.ptr) {
                        conn->tmf_state = TMF_INITIAL;
                        /* task completed before tmf abort response */
-                       debug_scsi("sc completed while abort in progress\n");
+                       ISCSI_DBG_SESSION(session, "sc completed while abort "
+                                         "in progress\n");
                        goto success;
                }
                /* fall through */
@@ -1827,15 +1857,16 @@ int iscsi_eh_abort(struct scsi_cmnd *sc)
 success:
        spin_unlock_bh(&session->lock);
 success_unlocked:
-       debug_scsi("abort success [sc %lx itt 0x%x]\n", (long)sc, task->itt);
+       ISCSI_DBG_SESSION(session, "abort success [sc %p itt 0x%x]\n",
+                         sc, task->itt);
        mutex_unlock(&session->eh_mutex);
        return SUCCESS;
 
 failed:
        spin_unlock_bh(&session->lock);
 failed_unlocked:
-       debug_scsi("abort failed [sc %p itt 0x%x]\n", sc,
-                   task ? task->itt : 0);
+       ISCSI_DBG_SESSION(session, "abort failed [sc %p itt 0x%x]\n", sc,
+                         task ? task->itt : 0);
        mutex_unlock(&session->eh_mutex);
        return FAILED;
 }
@@ -1862,7 +1893,8 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc)
        cls_session = starget_to_session(scsi_target(sc->device));
        session = cls_session->dd_data;
 
-       debug_scsi("LU Reset [sc %p lun %u]\n", sc, sc->device->lun);
+       ISCSI_DBG_SESSION(session, "LU Reset [sc %p lun %u]\n",
+                         sc, sc->device->lun);
 
        mutex_lock(&session->eh_mutex);
        spin_lock_bh(&session->lock);
@@ -1916,8 +1948,8 @@ int iscsi_eh_device_reset(struct scsi_cmnd *sc)
 unlock:
        spin_unlock_bh(&session->lock);
 done:
-       debug_scsi("iscsi_eh_device_reset %s\n",
-                 rc == SUCCESS ? "SUCCESS" : "FAILED");
+       ISCSI_DBG_SESSION(session, "dev reset result = %s\n",
+                        rc == SUCCESS ? "SUCCESS" : "FAILED");
        mutex_unlock(&session->eh_mutex);
        return rc;
 }
@@ -2467,14 +2499,16 @@ flush_control_queues(struct iscsi_session *session, 
struct iscsi_conn *conn)
 
        /* handle pending */
        list_for_each_entry_safe(task, tmp, &conn->mgmtqueue, running) {
-               debug_scsi("flushing pending mgmt task itt 0x%x\n", task->itt);
+               ISCSI_DBG_SESSION(session, "flushing pending mgmt task "
+                                 "itt 0x%x\n", task->itt);
                /* release ref from prep task */
                __iscsi_put_task(task);
        }
 
        /* handle running */
        list_for_each_entry_safe(task, tmp, &conn->mgmt_run_list, running) {
-               debug_scsi("flushing running mgmt task itt 0x%x\n", task->itt);
+               ISCSI_DBG_SESSION(session, "flushing running mgmt task "
+                                 "itt 0x%x\n", task->itt);
                /* release ref from prep task */
                __iscsi_put_task(task);
        }
@@ -2524,7 +2558,7 @@ static void iscsi_start_session_recovery(struct 
iscsi_session *session,
                conn->datadgst_en = 0;
                if (session->state == ISCSI_STATE_IN_RECOVERY &&
                    old_stop_stage != STOP_CONN_RECOVER) {
-                       debug_scsi("blocking session\n");
+                       ISCSI_DBG_SESSION(session, "blocking session\n");
                        iscsi_block_session(session->cls_session);
                }
        }
diff --git a/drivers/scsi/libiscsi_tcp.c b/drivers/scsi/libiscsi_tcp.c
index e7705d3..b051b22 100644
--- a/drivers/scsi/libiscsi_tcp.c
+++ b/drivers/scsi/libiscsi_tcp.c
@@ -49,13 +49,13 @@ MODULE_AUTHOR("Mike Christie <micha...@cs.wisc.edu>, "
              "Alex Aizman <itn...@yahoo.com>");
 MODULE_DESCRIPTION("iSCSI/TCP data-path");
 MODULE_LICENSE("GPL");
-#undef DEBUG_TCP
 
-#ifdef DEBUG_TCP
-#define debug_tcp(fmt...) printk(KERN_INFO "tcp: " fmt)
-#else
-#define debug_tcp(fmt...)
-#endif
+int iscsi_dbg_libtcp;
+module_param_named(debug_libiscsi_tcp, iscsi_dbg_libtcp, int,
+                  S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(debug_libiscsi_tcp, "Turn on debugging for libiscsi_tcp "
+                "module. Set to 1 to turn on, and zero to turn off. Default "
+                "is off.");
 
 static int iscsi_tcp_hdr_recv_done(struct iscsi_tcp_conn *tcp_conn,
                                   struct iscsi_segment *segment);
@@ -123,18 +123,13 @@ static void iscsi_tcp_segment_map(struct iscsi_segment 
*segment, int recv)
        if (page_count(sg_page(sg)) >= 1 && !recv)
                return;
 
-       debug_tcp("iscsi_tcp_segment_map %s %p\n", recv ? "recv" : "xmit",
-                 segment);
        segment->sg_mapped = kmap_atomic(sg_page(sg), KM_SOFTIRQ0);
        segment->data = segment->sg_mapped + sg->offset + segment->sg_offset;
 }
 
 void iscsi_tcp_segment_unmap(struct iscsi_segment *segment)
 {
-       debug_tcp("iscsi_tcp_segment_unmap %p\n", segment);
-
        if (segment->sg_mapped) {
-               debug_tcp("iscsi_tcp_segment_unmap valid\n");
                kunmap_atomic(segment->sg_mapped, KM_SOFTIRQ0);
                segment->sg_mapped = NULL;
                segment->data = NULL;
@@ -180,8 +175,9 @@ int iscsi_tcp_segment_done(struct iscsi_tcp_conn *tcp_conn,
        struct scatterlist sg;
        unsigned int pad;
 
-       debug_tcp("copied %u %u size %u %s\n", segment->copied, copied,
-                 segment->size, recv ? "recv" : "xmit");
+       ISCSI_DBG_TCP(tcp_conn->iscsi_conn, "copied %u %u size %u %s\n",
+                     segment->copied, copied, segment->size,
+                     recv ? "recv" : "xmit");
        if (segment->hash && copied) {
                /*
                 * If a segment is kmapd we must unmap it before sending
@@ -214,8 +210,8 @@ int iscsi_tcp_segment_done(struct iscsi_tcp_conn *tcp_conn,
        iscsi_tcp_segment_unmap(segment);
 
        /* Do we have more scatterlist entries? */
-       debug_tcp("total copied %u total size %u\n", segment->total_copied,
-                  segment->total_size);
+       ISCSI_DBG_TCP(tcp_conn->iscsi_conn, "total copied %u total size %u\n",
+                     segment->total_copied, segment->total_size);
        if (segment->total_copied < segment->total_size) {
                /* Proceed to the next entry in the scatterlist. */
                iscsi_tcp_segment_init_sg(segment, sg_next(segment->sg),
@@ -229,7 +225,8 @@ int iscsi_tcp_segment_done(struct iscsi_tcp_conn *tcp_conn,
        if (!(tcp_conn->iscsi_conn->session->tt->caps & CAP_PADDING_OFFLOAD)) {
                pad = iscsi_padding(segment->total_copied);
                if (pad != 0) {
-                       debug_tcp("consume %d pad bytes\n", pad);
+                       ISCSI_DBG_TCP(tcp_conn->iscsi_conn,
+                                     "consume %d pad bytes\n", pad);
                        segment->total_size += pad;
                        segment->size = pad;
                        segment->data = segment->padbuf;
@@ -278,13 +275,13 @@ iscsi_tcp_segment_recv(struct iscsi_tcp_conn *tcp_conn,
 
        while (!iscsi_tcp_segment_done(tcp_conn, segment, 1, copy)) {
                if (copied == len) {
-                       debug_tcp("iscsi_tcp_segment_recv copied %d bytes\n",
-                                 len);
+                       ISCSI_DBG_TCP(tcp_conn->iscsi_conn,
+                                     "copied %d bytes\n", len);
                        break;
                }
 
                copy = min(len - copied, segment->size - segment->copied);
-               debug_tcp("iscsi_tcp_segment_recv copying %d\n", copy);
+               ISCSI_DBG_TCP(tcp_conn->iscsi_conn, "copying %d\n", copy);
                memcpy(segment->data + segment->copied, ptr + copied, copy);
                copied += copy;
        }
@@ -311,7 +308,7 @@ iscsi_tcp_dgst_verify(struct iscsi_tcp_conn *tcp_conn,
 
        if (memcmp(segment->recv_digest, segment->digest,
                   segment->digest_len)) {
-               debug_scsi("digest mismatch\n");
+               ISCSI_DBG_TCP(tcp_conn->iscsi_conn, "digest mismatch\n");
                return 0;
        }
 
@@ -355,12 +352,8 @@ iscsi_segment_seek_sg(struct iscsi_segment *segment,
        struct scatterlist *sg;
        unsigned int i;
 
-       debug_scsi("iscsi_segment_seek_sg offset %u size %llu\n",
-                 offset, size);
        __iscsi_segment_init(segment, size, done, hash);
        for_each_sg(sg_list, sg, sg_count, i) {
-               debug_scsi("sg %d, len %u offset %u\n", i, sg->length,
-                          sg->offset);
                if (offset < sg->length) {
                        iscsi_tcp_segment_init_sg(segment, sg, offset);
                        return 0;
@@ -382,8 +375,9 @@ EXPORT_SYMBOL_GPL(iscsi_segment_seek_sg);
  */
 void iscsi_tcp_hdr_recv_prep(struct iscsi_tcp_conn *tcp_conn)
 {
-       debug_tcp("iscsi_tcp_hdr_recv_prep(%p%s)\n", tcp_conn,
-                 tcp_conn->iscsi_conn->hdrdgst_en ? ", digest enabled" : "");
+       ISCSI_DBG_TCP(tcp_conn->iscsi_conn,
+                     "(%s)\n", tcp_conn->iscsi_conn->hdrdgst_en ?
+                     "digest enabled" : "digest disabled");
        iscsi_segment_init_linear(&tcp_conn->in.segment,
                                tcp_conn->in.hdr_buf, sizeof(struct iscsi_hdr),
                                iscsi_tcp_hdr_recv_done, NULL);
@@ -446,7 +440,7 @@ void iscsi_tcp_cleanup_task(struct iscsi_task *task)
        while (__kfifo_get(tcp_task->r2tqueue, (void*)&r2t, sizeof(void*))) {
                __kfifo_put(tcp_task->r2tpool.queue, (void*)&r2t,
                            sizeof(void*));
-               debug_scsi("iscsi_tcp_cleanup_task pending r2t dropped\n");
+               ISCSI_DBG_TCP(task->conn, "pending r2t dropped\n");
        }
 
        r2t = tcp_task->r2t;
@@ -476,8 +470,8 @@ static int iscsi_tcp_data_in(struct iscsi_conn *conn, 
struct iscsi_task *task)
                return 0;
 
        if (tcp_task->exp_datasn != datasn) {
-               debug_tcp("%s: task->exp_datasn(%d) != rhdr->datasn(%d)\n",
-                         __func__, tcp_task->exp_datasn, datasn);
+               ISCSI_DBG_TCP(conn, "task->exp_datasn(%d) != rhdr->datasn(%d)"
+                             "\n", tcp_task->exp_datasn, datasn);
                return ISCSI_ERR_DATASN;
        }
 
@@ -485,9 +479,9 @@ static int iscsi_tcp_data_in(struct iscsi_conn *conn, 
struct iscsi_task *task)
 
        tcp_task->data_offset = be32_to_cpu(rhdr->offset);
        if (tcp_task->data_offset + tcp_conn->in.datalen > total_in_length) {
-               debug_tcp("%s: data_offset(%d) + data_len(%d) > 
total_length_in(%d)\n",
-                         __func__, tcp_task->data_offset,
-                         tcp_conn->in.datalen, total_in_length);
+               ISCSI_DBG_TCP(conn, "data_offset(%d) + data_len(%d) > "
+                             "total_length_in(%d)\n", tcp_task->data_offset,
+                             tcp_conn->in.datalen, total_in_length);
                return ISCSI_ERR_DATA_OFFSET;
        }
 
@@ -518,8 +512,8 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, 
struct iscsi_task *task)
        }
 
        if (tcp_task->exp_datasn != r2tsn){
-               debug_tcp("%s: task->exp_datasn(%d) != rhdr->r2tsn(%d)\n",
-                         __func__, tcp_task->exp_datasn, r2tsn);
+               ISCSI_DBG_TCP(conn, "task->exp_datasn(%d) != rhdr->r2tsn(%d)\n",
+                             tcp_task->exp_datasn, r2tsn);
                return ISCSI_ERR_R2TSN;
        }
 
@@ -552,9 +546,9 @@ static int iscsi_tcp_r2t_rsp(struct iscsi_conn *conn, 
struct iscsi_task *task)
        }
 
        if (r2t->data_length > session->max_burst)
-               debug_scsi("invalid R2T with data len %u and max burst %u."
-                          "Attempting to execute request.\n",
-                           r2t->data_length, session->max_burst);
+               ISCSI_DBG_TCP(conn, "invalid R2T with data len %u and max "
+                             "burst %u. Attempting to execute request.\n",
+                             r2t->data_length, session->max_burst);
 
        r2t->data_offset = be32_to_cpu(rhdr->data_offset);
        if (r2t->data_offset + r2t->data_length > scsi_out(task->sc)->length) {
@@ -641,8 +635,8 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct 
iscsi_hdr *hdr)
        if (rc)
                return rc;
 
-       debug_tcp("opcode 0x%x ahslen %d datalen %d\n",
-                 opcode, ahslen, tcp_conn->in.datalen);
+       ISCSI_DBG_TCP(conn, "opcode 0x%x ahslen %d datalen %d\n",
+                     opcode, ahslen, tcp_conn->in.datalen);
 
        switch(opcode) {
        case ISCSI_OP_SCSI_DATA_IN:
@@ -674,10 +668,10 @@ iscsi_tcp_hdr_dissect(struct iscsi_conn *conn, struct 
iscsi_hdr *hdr)
                            !(conn->session->tt->caps & CAP_DIGEST_OFFLOAD))
                                rx_hash = tcp_conn->rx_hash;
 
-                       debug_tcp("iscsi_tcp_begin_data_in(%p, offset=%d, "
-                                 "datalen=%d)\n", tcp_conn,
-                                 tcp_task->data_offset,
-                                 tcp_conn->in.datalen);
+                       ISCSI_DBG_TCP(conn, "iscsi_tcp_begin_data_in( "
+                                    "offset=%d, datalen=%d)\n",
+                                     tcp_task->data_offset,
+                                     tcp_conn->in.datalen);
                        rc = iscsi_segment_seek_sg(&tcp_conn->in.segment,
                                                   sdb->table.sgl,
                                                   sdb->table.nents,
@@ -854,10 +848,10 @@ int iscsi_tcp_recv_skb(struct iscsi_conn *conn, struct 
sk_buff *skb,
        unsigned int consumed = 0;
        int rc = 0;
 
-       debug_tcp("in %d bytes\n", skb->len - offset);
+       ISCSI_DBG_TCP(conn, "in %d bytes\n", skb->len - offset);
 
        if (unlikely(conn->suspend_rx)) {
-               debug_tcp("conn %d Rx suspended!\n", conn->id);
+               ISCSI_DBG_TCP(conn, "Rx suspended!\n");
                *status = ISCSI_TCP_SUSPENDED;
                return 0;
        }
@@ -874,15 +868,16 @@ int iscsi_tcp_recv_skb(struct iscsi_conn *conn, struct 
sk_buff *skb,
 
                avail = skb_seq_read(consumed, &ptr, &seq);
                if (avail == 0) {
-                       debug_tcp("no more data avail. Consumed %d\n",
-                                 consumed);
+                       ISCSI_DBG_TCP(conn, "no more data avail. Consumed %d\n",
+                                     consumed);
                        *status = ISCSI_TCP_SKB_DONE;
                        skb_abort_seq_read(&seq);
                        goto skb_done;
                }
                BUG_ON(segment->copied >= segment->size);
 
-               debug_tcp("skb %p ptr=%p avail=%u\n", skb, ptr, avail);
+               ISCSI_DBG_TCP(conn, "skb %p ptr=%p avail=%u\n", skb, ptr,
+                             avail);
                rc = iscsi_tcp_segment_recv(tcp_conn, segment, ptr, avail);
                BUG_ON(rc == 0);
                consumed += rc;
@@ -895,11 +890,11 @@ int iscsi_tcp_recv_skb(struct iscsi_conn *conn, struct 
sk_buff *skb,
 
 segment_done:
        *status = ISCSI_TCP_SEGMENT_DONE;
-       debug_tcp("segment done\n");
+       ISCSI_DBG_TCP(conn, "segment done\n");
        rc = segment->done(tcp_conn, segment);
        if (rc != 0) {
                *status = ISCSI_TCP_CONN_ERR;
-               debug_tcp("Error receiving PDU, errno=%d\n", rc);
+               ISCSI_DBG_TCP(conn, "Error receiving PDU, errno=%d\n", rc);
                iscsi_conn_failure(conn, rc);
                return 0;
        }
@@ -929,8 +924,7 @@ int iscsi_tcp_task_init(struct iscsi_task *task)
                 * mgmt tasks do not have a scatterlist since they come
                 * in from the iscsi interface.
                 */
-               debug_scsi("mtask deq [cid %d itt 0x%x]\n", conn->id,
-                          task->itt);
+               ISCSI_DBG_TCP(conn, "mtask deq [itt 0x%x]\n", task->itt);
 
                return conn->session->tt->init_pdu(task, 0, task->data_count);
        }
@@ -939,9 +933,8 @@ int iscsi_tcp_task_init(struct iscsi_task *task)
        tcp_task->exp_datasn = 0;
 
        /* Prepare PDU, optionally w/ immediate data */
-       debug_scsi("task deq [cid %d itt 0x%x imm %d unsol %d]\n",
-                   conn->id, task->itt, task->imm_count,
-                   task->unsol_r2t.data_length);
+       ISCSI_DBG_TCP(conn, "task deq [itt 0x%x imm %d unsol %d]\n",
+                     task->itt, task->imm_count, task->unsol_r2t.data_length);
 
        err = conn->session->tt->init_pdu(task, 0, task->imm_count);
        if (err)
@@ -965,7 +958,8 @@ static struct iscsi_r2t_info *iscsi_tcp_get_curr_r2t(struct 
iscsi_task *task)
                        r2t = tcp_task->r2t;
                        /* Continue with this R2T? */
                        if (r2t->data_length <= r2t->sent) {
-                               debug_scsi("  done with r2t %p\n", r2t);
+                               ISCSI_DBG_TCP(task->conn,
+                                             "  done with r2t %p\n", r2t);
                                __kfifo_put(tcp_task->r2tpool.queue,
                                            (void *)&tcp_task->r2t,
                                            sizeof(void *));
@@ -1019,7 +1013,7 @@ flush:
        r2t = iscsi_tcp_get_curr_r2t(task);
        if (r2t == NULL) {
                /* Waiting for more R2Ts to arrive. */
-               debug_tcp("no R2Ts yet\n");
+               ISCSI_DBG_TCP(conn, "no R2Ts yet\n");
                return 0;
        }
 
@@ -1028,9 +1022,9 @@ flush:
                return rc;
        iscsi_prep_data_out_pdu(task, r2t, (struct iscsi_data *) task->hdr);
 
-       debug_scsi("sol dout %p [dsn %d itt 0x%x doff %d dlen %d]\n",
-                  r2t, r2t->datasn - 1, task->hdr->itt,
-                  r2t->data_offset + r2t->sent, r2t->data_count);
+       ISCSI_DBG_TCP(conn, "sol dout %p [dsn %d itt 0x%x doff %d dlen %d]\n",
+                     r2t, r2t->datasn - 1, task->hdr->itt,
+                     r2t->data_offset + r2t->sent, r2t->data_count);
 
        rc = conn->session->tt->init_pdu(task, r2t->data_offset + r2t->sent,
                                         r2t->data_count);
diff --git a/include/scsi/libiscsi.h b/include/scsi/libiscsi.h
index 7360e19..d2938dc 100644
--- a/include/scsi/libiscsi.h
+++ b/include/scsi/libiscsi.h
@@ -45,12 +45,7 @@ struct iscsi_session;
 struct iscsi_nopin;
 struct device;
 
-/* #define DEBUG_SCSI */
-#ifdef DEBUG_SCSI
-#define debug_scsi(fmt...) printk(KERN_INFO "iscsi: " fmt)
-#else
-#define debug_scsi(fmt...)
-#endif
+extern int iscsi_dbg_lib;
 
 #define ISCSI_DEF_XMIT_CMDS_MAX        128     /* must be power of 2 */
 #define ISCSI_MGMT_CMDS_MAX    15
@@ -371,6 +366,14 @@ extern int iscsi_session_get_param(struct 
iscsi_cls_session *cls_session,
 #define iscsi_session_printk(prefix, _sess, fmt, a...) \
        iscsi_cls_session_printk(prefix, _sess->cls_session, fmt, ##a)
 
+#define ISCSI_DBG_SESSION(_session, dbg_fmt, arg...)                   \
+       do {                                                            \
+               if (iscsi_dbg_lib)                                      \
+                       iscsi_session_printk(KERN_INFO, _session,       \
+                                            "%s " dbg_fmt,             \
+                                            __func__, ##arg);          \
+       } while (0);
+
 /*
  * connection management
  */
@@ -392,6 +395,14 @@ extern void iscsi_suspend_tx(struct iscsi_conn *conn);
        iscsi_cls_conn_printk(prefix, ((struct iscsi_conn *)_c)->cls_conn, \
                              fmt, ##a)
 
+#define ISCSI_DBG_CONN(_conn, dbg_fmt, arg...)                 \
+       do {                                                    \
+               if (iscsi_dbg_lib)                              \
+                       iscsi_conn_printk(KERN_INFO, _conn,     \
+                                            "%s " dbg_fmt,     \
+                                            __func__, ##arg);  \
+       } while (0);
+
 /*
  * pdu and task processing
  */
diff --git a/include/scsi/libiscsi_tcp.h b/include/scsi/libiscsi_tcp.h
index 9e3182e..c11b2e1 100644
--- a/include/scsi/libiscsi_tcp.h
+++ b/include/scsi/libiscsi_tcp.h
@@ -91,6 +91,16 @@ enum {
        ISCSI_TCP_SUSPENDED,            /* conn is suspended */
 };
 
+
+#define ISCSI_DBG_TCP(_conn, dbg_fmt, arg...)                  \
+       do {                                                    \
+               if (iscsi_dbg_libtcp)                           \
+                       iscsi_conn_printk(KERN_INFO, _conn,     \
+                                            "%s " dbg_fmt,     \
+                                            __func__, ##arg);  \
+       } while (0);
+
+
 extern void iscsi_tcp_hdr_recv_prep(struct iscsi_tcp_conn *tcp_conn);
 extern int iscsi_tcp_recv_skb(struct iscsi_conn *conn, struct sk_buff *skb,
                              unsigned int offset, bool offloaded, int *status);
-- 
1.6.0.6

Reply via email to