Skip to content

Commit

Permalink
libfc: Add runtime debugging with debug_logging module parameter
Browse files Browse the repository at this point in the history
This patch adds the /sys/module/libfc/parameters/debug_logging
file to sysfs as a module parameter. It accepts an integer
bitmask for logging. Currently it supports:

   bit
LSB 0 = general libfc debugging
    1 = lport debugging
    2 = disc debugging
    3 = rport debugging
    4 = fcp debugging
    5 = EM debugging
    6 = exch/seq debugging
    7 = scsi logging (mostly error handling)

the other bits are not used at this time.

The patch converts all of the libfc source files to use
these new macros and removes the old FC_DBG macro.

Signed-off-by: Robert Love <robert.w.love@intel.com>
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
  • Loading branch information
Robert Love authored and James Bottomley committed Jun 21, 2009
1 parent 650bd12 commit 7414705
Show file tree
Hide file tree
Showing 7 changed files with 301 additions and 292 deletions.
83 changes: 35 additions & 48 deletions drivers/scsi/libfc/fc_disc.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@

#define FC_DISC_DELAY 3

static int fc_disc_debug;

#define FC_DEBUG_DISC(fmt...) \
do { \
if (fc_disc_debug) \
FC_DBG(fmt); \
} while (0)

static void fc_disc_gpn_ft_req(struct fc_disc *);
static void fc_disc_gpn_ft_resp(struct fc_seq *, struct fc_frame *, void *);
static int fc_disc_new_target(struct fc_disc *, struct fc_rport *,
Expand Down Expand Up @@ -137,8 +129,8 @@ static void fc_disc_rport_callback(struct fc_lport *lport,
struct fc_rport_libfc_priv *rdata = rport->dd_data;
struct fc_disc *disc = &lport->disc;

FC_DEBUG_DISC("Received a %d event for port (%6x)\n", event,
rport->port_id);
FC_DISC_DBG(disc, "Received a %d event for port (%6x)\n", event,
rport->port_id);

switch (event) {
case RPORT_EV_CREATED:
Expand Down Expand Up @@ -191,8 +183,7 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,

lport = disc->lport;

FC_DEBUG_DISC("Received an RSCN event on port (%6x)\n",
fc_host_port_id(lport->host));
FC_DISC_DBG(disc, "Received an RSCN event\n");

/* make sure the frame contains an RSCN message */
rp = fc_frame_payload_get(fp, sizeof(*rp));
Expand Down Expand Up @@ -225,8 +216,8 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,
*/
switch (fmt) {
case ELS_ADDR_FMT_PORT:
FC_DEBUG_DISC("Port address format for port (%6x)\n",
ntoh24(pp->rscn_fid));
FC_DISC_DBG(disc, "Port address format for port "
"(%6x)\n", ntoh24(pp->rscn_fid));
dp = kzalloc(sizeof(*dp), GFP_KERNEL);
if (!dp) {
redisc = 1;
Expand All @@ -243,19 +234,19 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,
case ELS_ADDR_FMT_DOM:
case ELS_ADDR_FMT_FAB:
default:
FC_DEBUG_DISC("Address format is (%d)\n", fmt);
FC_DISC_DBG(disc, "Address format is (%d)\n", fmt);
redisc = 1;
break;
}
}
lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL);
if (redisc) {
FC_DEBUG_DISC("RSCN received: rediscovering\n");
FC_DISC_DBG(disc, "RSCN received: rediscovering\n");
fc_disc_restart(disc);
} else {
FC_DEBUG_DISC("RSCN received: not rediscovering. "
"redisc %d state %d in_prog %d\n",
redisc, lport->state, disc->pending);
FC_DISC_DBG(disc, "RSCN received: not rediscovering. "
"redisc %d state %d in_prog %d\n",
redisc, lport->state, disc->pending);
list_for_each_entry_safe(dp, next, &disc_ports, peers) {
list_del(&dp->peers);
rport = lport->tt.rport_lookup(lport, dp->ids.port_id);
Expand All @@ -270,7 +261,7 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,
fc_frame_free(fp);
return;
reject:
FC_DEBUG_DISC("Received a bad RSCN frame\n");
FC_DISC_DBG(disc, "Received a bad RSCN frame\n");
rjt_data.fp = NULL;
rjt_data.reason = ELS_RJT_LOGIC;
rjt_data.explan = ELS_EXPL_NONE;
Expand Down Expand Up @@ -302,7 +293,8 @@ static void fc_disc_recv_req(struct fc_seq *sp, struct fc_frame *fp,
mutex_unlock(&disc->disc_mutex);
break;
default:
FC_DBG("Received an unsupported request. opcode (%x)\n", op);
FC_DISC_DBG(disc, "Received an unsupported request, "
"the opcode is (%x)\n", op);
break;
}
}
Expand All @@ -320,12 +312,10 @@ static void fc_disc_restart(struct fc_disc *disc)
struct fc_rport_libfc_priv *rdata, *next;
struct fc_lport *lport = disc->lport;

FC_DEBUG_DISC("Restarting discovery for port (%6x)\n",
fc_host_port_id(lport->host));
FC_DISC_DBG(disc, "Restarting discovery\n");

list_for_each_entry_safe(rdata, next, &disc->rports, peers) {
rport = PRIV_TO_RPORT(rdata);
FC_DEBUG_DISC("list_del(%6x)\n", rport->port_id);
list_del(&rdata->peers);
lport->tt.rport_logoff(rport);
}
Expand Down Expand Up @@ -485,8 +475,7 @@ static void fc_disc_done(struct fc_disc *disc)
struct fc_lport *lport = disc->lport;
enum fc_disc_event event;

FC_DEBUG_DISC("Discovery complete for port (%6x)\n",
fc_host_port_id(lport->host));
FC_DISC_DBG(disc, "Discovery complete\n");

event = disc->event;
disc->event = DISC_EV_NONE;
Expand All @@ -510,10 +499,10 @@ static void fc_disc_error(struct fc_disc *disc, struct fc_frame *fp)
{
struct fc_lport *lport = disc->lport;
unsigned long delay = 0;
if (fc_disc_debug)
FC_DBG("Error %ld, retries %d/%d\n",
PTR_ERR(fp), disc->retry_count,
FC_DISC_RETRY_LIMIT);

FC_DISC_DBG(disc, "Error %ld, retries %d/%d\n",
PTR_ERR(fp), disc->retry_count,
FC_DISC_RETRY_LIMIT);

if (!fp || PTR_ERR(fp) == -FC_EX_TIMEOUT) {
/*
Expand Down Expand Up @@ -649,9 +638,9 @@ static int fc_disc_gpn_ft_parse(struct fc_disc *disc, void *buf, size_t len)
&disc->rogue_rports);
lport->tt.rport_login(rport);
} else
FC_DBG("Failed to allocate memory for "
"the newly discovered port (%6x)\n",
dp.ids.port_id);
printk(KERN_WARNING "libfc: Failed to allocate "
"memory for the newly discovered port "
"(%6x)\n", dp.ids.port_id);
}

if (np->fp_flags & FC_NS_FID_LAST) {
Expand All @@ -671,9 +660,8 @@ static int fc_disc_gpn_ft_parse(struct fc_disc *disc, void *buf, size_t len)
*/
if (error == 0 && len > 0 && len < sizeof(*np)) {
if (np != &disc->partial_buf) {
FC_DEBUG_DISC("Partial buffer remains "
"for discovery by (%6x)\n",
fc_host_port_id(lport->host));
FC_DISC_DBG(disc, "Partial buffer remains "
"for discovery\n");
memcpy(&disc->partial_buf, np, len);
}
disc->buf_len = (unsigned char) len;
Expand Down Expand Up @@ -721,8 +709,7 @@ static void fc_disc_gpn_ft_resp(struct fc_seq *sp, struct fc_frame *fp,
int error;

mutex_lock(&disc->disc_mutex);
FC_DEBUG_DISC("Received a GPN_FT response on port (%6x)\n",
fc_host_port_id(disc->lport->host));
FC_DISC_DBG(disc, "Received a GPN_FT response\n");

if (IS_ERR(fp)) {
fc_disc_error(disc, fp);
Expand All @@ -738,30 +725,30 @@ static void fc_disc_gpn_ft_resp(struct fc_seq *sp, struct fc_frame *fp,
disc->seq_count == 0) {
cp = fc_frame_payload_get(fp, sizeof(*cp));
if (!cp) {
FC_DBG("GPN_FT response too short, len %d\n",
fr_len(fp));
FC_DISC_DBG(disc, "GPN_FT response too short, len %d\n",
fr_len(fp));
} else if (ntohs(cp->ct_cmd) == FC_FS_ACC) {

/* Accepted, parse the response. */
buf = cp + 1;
len -= sizeof(*cp);
} else if (ntohs(cp->ct_cmd) == FC_FS_RJT) {
FC_DBG("GPN_FT rejected reason %x exp %x "
"(check zoning)\n", cp->ct_reason,
cp->ct_explan);
FC_DISC_DBG(disc, "GPN_FT rejected reason %x exp %x "
"(check zoning)\n", cp->ct_reason,
cp->ct_explan);
disc->event = DISC_EV_FAILED;
fc_disc_done(disc);
} else {
FC_DBG("GPN_FT unexpected response code %x\n",
ntohs(cp->ct_cmd));
FC_DISC_DBG(disc, "GPN_FT unexpected response code "
"%x\n", ntohs(cp->ct_cmd));
}
} else if (fr_sof(fp) == FC_SOF_N3 &&
seq_cnt == disc->seq_count) {
buf = fh + 1;
} else {
FC_DBG("GPN_FT unexpected frame - out of sequence? "
"seq_cnt %x expected %x sof %x eof %x\n",
seq_cnt, disc->seq_count, fr_sof(fp), fr_eof(fp));
FC_DISC_DBG(disc, "GPN_FT unexpected frame - out of sequence? "
"seq_cnt %x expected %x sof %x eof %x\n",
seq_cnt, disc->seq_count, fr_sof(fp), fr_eof(fp));
}
if (buf) {
error = fc_disc_gpn_ft_parse(disc, buf, len);
Expand Down
58 changes: 25 additions & 33 deletions drivers/scsi/libfc/fc_exch.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,7 @@
#include <scsi/libfc.h>
#include <scsi/fc_encode.h>

/*
* fc_exch_debug can be set in debugger or at compile time to get more logs.
*/
static int fc_exch_debug;

#define FC_DEBUG_EXCH(fmt...) \
do { \
if (fc_exch_debug) \
FC_DBG(fmt); \
} while (0)

static struct kmem_cache *fc_em_cachep; /* cache for exchanges */
static struct kmem_cache *fc_em_cachep; /* cache for exchanges */

/*
* Structure and function definitions for managing Fibre Channel Exchanges
Expand Down Expand Up @@ -333,8 +322,8 @@ static inline void fc_exch_timer_set_locked(struct fc_exch *ep,
if (ep->state & (FC_EX_RST_CLEANUP | FC_EX_DONE))
return;

FC_DEBUG_EXCH("Exchange (%4x) timed out, notifying the upper layer\n",
ep->xid);
FC_EXCH_DBG(ep, "Exchange timed out, notifying the upper layer\n");

if (schedule_delayed_work(&ep->timeout_work,
msecs_to_jiffies(timer_msec)))
fc_exch_hold(ep); /* hold for timer */
Expand Down Expand Up @@ -545,7 +534,7 @@ struct fc_exch *fc_exch_alloc(struct fc_exch_mgr *mp,
/* alloc a new xid */
xid = fc_em_alloc_xid(mp, fp);
if (!xid) {
printk(KERN_ERR "fc_em_alloc_xid() failed\n");
printk(KERN_WARNING "libfc: Failed to allocate an exhange\n");
goto err;
}
}
Expand Down Expand Up @@ -820,8 +809,8 @@ static struct fc_seq *fc_seq_start_next_locked(struct fc_seq *sp)
struct fc_exch *ep = fc_seq_exch(sp);

sp = fc_seq_alloc(ep, ep->seq_id++);
FC_DEBUG_EXCH("exch %4x f_ctl %6x seq %2x\n",
ep->xid, ep->f_ctl, sp->id);
FC_EXCH_DBG(ep, "f_ctl %6x seq %2x\n",
ep->f_ctl, sp->id);
return sp;
}
/*
Expand Down Expand Up @@ -901,7 +890,7 @@ void fc_seq_els_rsp_send(struct fc_seq *sp, enum fc_els_cmd els_cmd,
fc_exch_els_rec(sp, els_data->fp);
break;
default:
FC_DBG("Invalid ELS CMD:%x\n", els_cmd);
FC_EXCH_DBG(fc_seq_exch(sp), "Invalid ELS CMD:%x\n", els_cmd);
}
}
EXPORT_SYMBOL(fc_seq_els_rsp_send);
Expand Down Expand Up @@ -1134,7 +1123,7 @@ static void fc_exch_recv_req(struct fc_lport *lp, struct fc_exch_mgr *mp,
lp->tt.lport_recv(lp, sp, fp);
fc_exch_release(ep); /* release from lookup */
} else {
FC_DEBUG_EXCH("exch/seq lookup failed: reject %x\n", reject);
FC_EM_DBG(mp, "exch/seq lookup failed: reject %x\n", reject);
fc_frame_free(fp);
}
}
Expand Down Expand Up @@ -1242,10 +1231,10 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
if (!sp) {
atomic_inc(&mp->stats.xid_not_found);
FC_DEBUG_EXCH("seq lookup failed\n");
FC_EM_DBG(mp, "seq lookup failed\n");
} else {
atomic_inc(&mp->stats.non_bls_resp);
FC_DEBUG_EXCH("non-BLS response to sequence");
FC_EM_DBG(mp, "non-BLS response to sequence");
}
fc_frame_free(fp);
}
Expand All @@ -1266,8 +1255,8 @@ static void fc_exch_abts_resp(struct fc_exch *ep, struct fc_frame *fp)
int rc = 1, has_rec = 0;

fh = fc_frame_header_get(fp);
FC_DEBUG_EXCH("exch: BLS rctl %x - %s\n",
fh->fh_r_ctl, fc_exch_rctl_name(fh->fh_r_ctl));
FC_EXCH_DBG(ep, "exch: BLS rctl %x - %s\n", fh->fh_r_ctl,
fc_exch_rctl_name(fh->fh_r_ctl));

if (cancel_delayed_work_sync(&ep->timeout_work))
fc_exch_release(ep); /* release from pending timer hold */
Expand Down Expand Up @@ -1359,9 +1348,9 @@ static void fc_exch_recv_bls(struct fc_exch_mgr *mp, struct fc_frame *fp)
case FC_RCTL_ACK_0:
break;
default:
FC_DEBUG_EXCH("BLS rctl %x - %s received",
fh->fh_r_ctl,
fc_exch_rctl_name(fh->fh_r_ctl));
FC_EXCH_DBG(ep, "BLS rctl %x - %s received",
fh->fh_r_ctl,
fc_exch_rctl_name(fh->fh_r_ctl));
break;
}
fc_frame_free(fp);
Expand Down Expand Up @@ -1599,7 +1588,8 @@ static void fc_exch_rrq_resp(struct fc_seq *sp, struct fc_frame *fp, void *arg)

if (err == -FC_EX_CLOSED || err == -FC_EX_TIMEOUT)
goto cleanup;
FC_DBG("Cannot process RRQ, because of frame error %d\n", err);
FC_EXCH_DBG(aborted_ep, "Cannot process RRQ, "
"frame error %d\n", err);
return;
}

Expand All @@ -1608,12 +1598,13 @@ static void fc_exch_rrq_resp(struct fc_seq *sp, struct fc_frame *fp, void *arg)

switch (op) {
case ELS_LS_RJT:
FC_DBG("LS_RJT for RRQ");
FC_EXCH_DBG(aborted_ep, "LS_RJT for RRQ");
/* fall through */
case ELS_LS_ACC:
goto cleanup;
default:
FC_DBG("unexpected response op %x for RRQ", op);
FC_EXCH_DBG(aborted_ep, "unexpected response op %x "
"for RRQ", op);
return;
}

Expand Down Expand Up @@ -1740,8 +1731,8 @@ struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp,
size_t len;

if (max_xid <= min_xid || min_xid == 0 || max_xid == FC_XID_UNKNOWN) {
FC_DBG("Invalid min_xid 0x:%x and max_xid 0x:%x\n",
min_xid, max_xid);
FC_LPORT_DBG(lp, "Invalid min_xid 0x:%x and max_xid 0x:%x\n",
min_xid, max_xid);
return NULL;
}

Expand Down Expand Up @@ -1878,7 +1869,8 @@ void fc_exch_recv(struct fc_lport *lp, struct fc_exch_mgr *mp,

/* lport lock ? */
if (!lp || !mp || (lp->state == LPORT_ST_NONE)) {
FC_DBG("fc_lport or EM is not allocated and configured");
FC_LPORT_DBG(lp, "Receiving frames for an lport that "
"has not been initialized correctly\n");
fc_frame_free(fp);
return;
}
Expand All @@ -1904,7 +1896,7 @@ void fc_exch_recv(struct fc_lport *lp, struct fc_exch_mgr *mp,
fc_exch_recv_req(lp, mp, fp);
break;
default:
FC_DBG("dropping invalid frame (eof %x)", fr_eof(fp));
FC_EM_DBG(mp, "dropping invalid frame (eof %x)", fr_eof(fp));
fc_frame_free(fp);
break;
}
Expand Down
Loading

0 comments on commit 7414705

Please sign in to comment.