Skip to content

Commit 7414705

Browse files
Robert Lovejejb
authored andcommitted
libfc: Add runtime debugging with debug_logging module parameter
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 <[email protected]> Signed-off-by: James Bottomley <[email protected]>
1 parent 650bd12 commit 7414705

7 files changed

Lines changed: 301 additions & 292 deletions

File tree

drivers/scsi/libfc/fc_disc.c

Lines changed: 35 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,6 @@
4545

4646
#define FC_DISC_DELAY 3
4747

48-
static int fc_disc_debug;
49-
50-
#define FC_DEBUG_DISC(fmt...) \
51-
do { \
52-
if (fc_disc_debug) \
53-
FC_DBG(fmt); \
54-
} while (0)
55-
5648
static void fc_disc_gpn_ft_req(struct fc_disc *);
5749
static void fc_disc_gpn_ft_resp(struct fc_seq *, struct fc_frame *, void *);
5850
static int fc_disc_new_target(struct fc_disc *, struct fc_rport *,
@@ -137,8 +129,8 @@ static void fc_disc_rport_callback(struct fc_lport *lport,
137129
struct fc_rport_libfc_priv *rdata = rport->dd_data;
138130
struct fc_disc *disc = &lport->disc;
139131

140-
FC_DEBUG_DISC("Received a %d event for port (%6x)\n", event,
141-
rport->port_id);
132+
FC_DISC_DBG(disc, "Received a %d event for port (%6x)\n", event,
133+
rport->port_id);
142134

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

192184
lport = disc->lport;
193185

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

197188
/* make sure the frame contains an RSCN message */
198189
rp = fc_frame_payload_get(fp, sizeof(*rp));
@@ -225,8 +216,8 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,
225216
*/
226217
switch (fmt) {
227218
case ELS_ADDR_FMT_PORT:
228-
FC_DEBUG_DISC("Port address format for port (%6x)\n",
229-
ntoh24(pp->rscn_fid));
219+
FC_DISC_DBG(disc, "Port address format for port "
220+
"(%6x)\n", ntoh24(pp->rscn_fid));
230221
dp = kzalloc(sizeof(*dp), GFP_KERNEL);
231222
if (!dp) {
232223
redisc = 1;
@@ -243,19 +234,19 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,
243234
case ELS_ADDR_FMT_DOM:
244235
case ELS_ADDR_FMT_FAB:
245236
default:
246-
FC_DEBUG_DISC("Address format is (%d)\n", fmt);
237+
FC_DISC_DBG(disc, "Address format is (%d)\n", fmt);
247238
redisc = 1;
248239
break;
249240
}
250241
}
251242
lport->tt.seq_els_rsp_send(sp, ELS_LS_ACC, NULL);
252243
if (redisc) {
253-
FC_DEBUG_DISC("RSCN received: rediscovering\n");
244+
FC_DISC_DBG(disc, "RSCN received: rediscovering\n");
254245
fc_disc_restart(disc);
255246
} else {
256-
FC_DEBUG_DISC("RSCN received: not rediscovering. "
257-
"redisc %d state %d in_prog %d\n",
258-
redisc, lport->state, disc->pending);
247+
FC_DISC_DBG(disc, "RSCN received: not rediscovering. "
248+
"redisc %d state %d in_prog %d\n",
249+
redisc, lport->state, disc->pending);
259250
list_for_each_entry_safe(dp, next, &disc_ports, peers) {
260251
list_del(&dp->peers);
261252
rport = lport->tt.rport_lookup(lport, dp->ids.port_id);
@@ -270,7 +261,7 @@ static void fc_disc_recv_rscn_req(struct fc_seq *sp, struct fc_frame *fp,
270261
fc_frame_free(fp);
271262
return;
272263
reject:
273-
FC_DEBUG_DISC("Received a bad RSCN frame\n");
264+
FC_DISC_DBG(disc, "Received a bad RSCN frame\n");
274265
rjt_data.fp = NULL;
275266
rjt_data.reason = ELS_RJT_LOGIC;
276267
rjt_data.explan = ELS_EXPL_NONE;
@@ -302,7 +293,8 @@ static void fc_disc_recv_req(struct fc_seq *sp, struct fc_frame *fp,
302293
mutex_unlock(&disc->disc_mutex);
303294
break;
304295
default:
305-
FC_DBG("Received an unsupported request. opcode (%x)\n", op);
296+
FC_DISC_DBG(disc, "Received an unsupported request, "
297+
"the opcode is (%x)\n", op);
306298
break;
307299
}
308300
}
@@ -320,12 +312,10 @@ static void fc_disc_restart(struct fc_disc *disc)
320312
struct fc_rport_libfc_priv *rdata, *next;
321313
struct fc_lport *lport = disc->lport;
322314

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

326317
list_for_each_entry_safe(rdata, next, &disc->rports, peers) {
327318
rport = PRIV_TO_RPORT(rdata);
328-
FC_DEBUG_DISC("list_del(%6x)\n", rport->port_id);
329319
list_del(&rdata->peers);
330320
lport->tt.rport_logoff(rport);
331321
}
@@ -485,8 +475,7 @@ static void fc_disc_done(struct fc_disc *disc)
485475
struct fc_lport *lport = disc->lport;
486476
enum fc_disc_event event;
487477

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

491480
event = disc->event;
492481
disc->event = DISC_EV_NONE;
@@ -510,10 +499,10 @@ static void fc_disc_error(struct fc_disc *disc, struct fc_frame *fp)
510499
{
511500
struct fc_lport *lport = disc->lport;
512501
unsigned long delay = 0;
513-
if (fc_disc_debug)
514-
FC_DBG("Error %ld, retries %d/%d\n",
515-
PTR_ERR(fp), disc->retry_count,
516-
FC_DISC_RETRY_LIMIT);
502+
503+
FC_DISC_DBG(disc, "Error %ld, retries %d/%d\n",
504+
PTR_ERR(fp), disc->retry_count,
505+
FC_DISC_RETRY_LIMIT);
517506

518507
if (!fp || PTR_ERR(fp) == -FC_EX_TIMEOUT) {
519508
/*
@@ -649,9 +638,9 @@ static int fc_disc_gpn_ft_parse(struct fc_disc *disc, void *buf, size_t len)
649638
&disc->rogue_rports);
650639
lport->tt.rport_login(rport);
651640
} else
652-
FC_DBG("Failed to allocate memory for "
653-
"the newly discovered port (%6x)\n",
654-
dp.ids.port_id);
641+
printk(KERN_WARNING "libfc: Failed to allocate "
642+
"memory for the newly discovered port "
643+
"(%6x)\n", dp.ids.port_id);
655644
}
656645

657646
if (np->fp_flags & FC_NS_FID_LAST) {
@@ -671,9 +660,8 @@ static int fc_disc_gpn_ft_parse(struct fc_disc *disc, void *buf, size_t len)
671660
*/
672661
if (error == 0 && len > 0 && len < sizeof(*np)) {
673662
if (np != &disc->partial_buf) {
674-
FC_DEBUG_DISC("Partial buffer remains "
675-
"for discovery by (%6x)\n",
676-
fc_host_port_id(lport->host));
663+
FC_DISC_DBG(disc, "Partial buffer remains "
664+
"for discovery\n");
677665
memcpy(&disc->partial_buf, np, len);
678666
}
679667
disc->buf_len = (unsigned char) len;
@@ -721,8 +709,7 @@ static void fc_disc_gpn_ft_resp(struct fc_seq *sp, struct fc_frame *fp,
721709
int error;
722710

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

727714
if (IS_ERR(fp)) {
728715
fc_disc_error(disc, fp);
@@ -738,30 +725,30 @@ static void fc_disc_gpn_ft_resp(struct fc_seq *sp, struct fc_frame *fp,
738725
disc->seq_count == 0) {
739726
cp = fc_frame_payload_get(fp, sizeof(*cp));
740727
if (!cp) {
741-
FC_DBG("GPN_FT response too short, len %d\n",
742-
fr_len(fp));
728+
FC_DISC_DBG(disc, "GPN_FT response too short, len %d\n",
729+
fr_len(fp));
743730
} else if (ntohs(cp->ct_cmd) == FC_FS_ACC) {
744731

745732
/* Accepted, parse the response. */
746733
buf = cp + 1;
747734
len -= sizeof(*cp);
748735
} else if (ntohs(cp->ct_cmd) == FC_FS_RJT) {
749-
FC_DBG("GPN_FT rejected reason %x exp %x "
750-
"(check zoning)\n", cp->ct_reason,
751-
cp->ct_explan);
736+
FC_DISC_DBG(disc, "GPN_FT rejected reason %x exp %x "
737+
"(check zoning)\n", cp->ct_reason,
738+
cp->ct_explan);
752739
disc->event = DISC_EV_FAILED;
753740
fc_disc_done(disc);
754741
} else {
755-
FC_DBG("GPN_FT unexpected response code %x\n",
756-
ntohs(cp->ct_cmd));
742+
FC_DISC_DBG(disc, "GPN_FT unexpected response code "
743+
"%x\n", ntohs(cp->ct_cmd));
757744
}
758745
} else if (fr_sof(fp) == FC_SOF_N3 &&
759746
seq_cnt == disc->seq_count) {
760747
buf = fh + 1;
761748
} else {
762-
FC_DBG("GPN_FT unexpected frame - out of sequence? "
763-
"seq_cnt %x expected %x sof %x eof %x\n",
764-
seq_cnt, disc->seq_count, fr_sof(fp), fr_eof(fp));
749+
FC_DISC_DBG(disc, "GPN_FT unexpected frame - out of sequence? "
750+
"seq_cnt %x expected %x sof %x eof %x\n",
751+
seq_cnt, disc->seq_count, fr_sof(fp), fr_eof(fp));
765752
}
766753
if (buf) {
767754
error = fc_disc_gpn_ft_parse(disc, buf, len);

drivers/scsi/libfc/fc_exch.c

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,7 @@
3232
#include <scsi/libfc.h>
3333
#include <scsi/fc_encode.h>
3434

35-
/*
36-
* fc_exch_debug can be set in debugger or at compile time to get more logs.
37-
*/
38-
static int fc_exch_debug;
39-
40-
#define FC_DEBUG_EXCH(fmt...) \
41-
do { \
42-
if (fc_exch_debug) \
43-
FC_DBG(fmt); \
44-
} while (0)
45-
46-
static struct kmem_cache *fc_em_cachep; /* cache for exchanges */
35+
static struct kmem_cache *fc_em_cachep; /* cache for exchanges */
4736

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

336-
FC_DEBUG_EXCH("Exchange (%4x) timed out, notifying the upper layer\n",
337-
ep->xid);
325+
FC_EXCH_DBG(ep, "Exchange timed out, notifying the upper layer\n");
326+
338327
if (schedule_delayed_work(&ep->timeout_work,
339328
msecs_to_jiffies(timer_msec)))
340329
fc_exch_hold(ep); /* hold for timer */
@@ -545,7 +534,7 @@ struct fc_exch *fc_exch_alloc(struct fc_exch_mgr *mp,
545534
/* alloc a new xid */
546535
xid = fc_em_alloc_xid(mp, fp);
547536
if (!xid) {
548-
printk(KERN_ERR "fc_em_alloc_xid() failed\n");
537+
printk(KERN_WARNING "libfc: Failed to allocate an exhange\n");
549538
goto err;
550539
}
551540
}
@@ -820,8 +809,8 @@ static struct fc_seq *fc_seq_start_next_locked(struct fc_seq *sp)
820809
struct fc_exch *ep = fc_seq_exch(sp);
821810

822811
sp = fc_seq_alloc(ep, ep->seq_id++);
823-
FC_DEBUG_EXCH("exch %4x f_ctl %6x seq %2x\n",
824-
ep->xid, ep->f_ctl, sp->id);
812+
FC_EXCH_DBG(ep, "f_ctl %6x seq %2x\n",
813+
ep->f_ctl, sp->id);
825814
return sp;
826815
}
827816
/*
@@ -901,7 +890,7 @@ void fc_seq_els_rsp_send(struct fc_seq *sp, enum fc_els_cmd els_cmd,
901890
fc_exch_els_rec(sp, els_data->fp);
902891
break;
903892
default:
904-
FC_DBG("Invalid ELS CMD:%x\n", els_cmd);
893+
FC_EXCH_DBG(fc_seq_exch(sp), "Invalid ELS CMD:%x\n", els_cmd);
905894
}
906895
}
907896
EXPORT_SYMBOL(fc_seq_els_rsp_send);
@@ -1134,7 +1123,7 @@ static void fc_exch_recv_req(struct fc_lport *lp, struct fc_exch_mgr *mp,
11341123
lp->tt.lport_recv(lp, sp, fp);
11351124
fc_exch_release(ep); /* release from lookup */
11361125
} else {
1137-
FC_DEBUG_EXCH("exch/seq lookup failed: reject %x\n", reject);
1126+
FC_EM_DBG(mp, "exch/seq lookup failed: reject %x\n", reject);
11381127
fc_frame_free(fp);
11391128
}
11401129
}
@@ -1242,10 +1231,10 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
12421231
sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
12431232
if (!sp) {
12441233
atomic_inc(&mp->stats.xid_not_found);
1245-
FC_DEBUG_EXCH("seq lookup failed\n");
1234+
FC_EM_DBG(mp, "seq lookup failed\n");
12461235
} else {
12471236
atomic_inc(&mp->stats.non_bls_resp);
1248-
FC_DEBUG_EXCH("non-BLS response to sequence");
1237+
FC_EM_DBG(mp, "non-BLS response to sequence");
12491238
}
12501239
fc_frame_free(fp);
12511240
}
@@ -1266,8 +1255,8 @@ static void fc_exch_abts_resp(struct fc_exch *ep, struct fc_frame *fp)
12661255
int rc = 1, has_rec = 0;
12671256

12681257
fh = fc_frame_header_get(fp);
1269-
FC_DEBUG_EXCH("exch: BLS rctl %x - %s\n",
1270-
fh->fh_r_ctl, fc_exch_rctl_name(fh->fh_r_ctl));
1258+
FC_EXCH_DBG(ep, "exch: BLS rctl %x - %s\n", fh->fh_r_ctl,
1259+
fc_exch_rctl_name(fh->fh_r_ctl));
12711260

12721261
if (cancel_delayed_work_sync(&ep->timeout_work))
12731262
fc_exch_release(ep); /* release from pending timer hold */
@@ -1359,9 +1348,9 @@ static void fc_exch_recv_bls(struct fc_exch_mgr *mp, struct fc_frame *fp)
13591348
case FC_RCTL_ACK_0:
13601349
break;
13611350
default:
1362-
FC_DEBUG_EXCH("BLS rctl %x - %s received",
1363-
fh->fh_r_ctl,
1364-
fc_exch_rctl_name(fh->fh_r_ctl));
1351+
FC_EXCH_DBG(ep, "BLS rctl %x - %s received",
1352+
fh->fh_r_ctl,
1353+
fc_exch_rctl_name(fh->fh_r_ctl));
13651354
break;
13661355
}
13671356
fc_frame_free(fp);
@@ -1599,7 +1588,8 @@ static void fc_exch_rrq_resp(struct fc_seq *sp, struct fc_frame *fp, void *arg)
15991588

16001589
if (err == -FC_EX_CLOSED || err == -FC_EX_TIMEOUT)
16011590
goto cleanup;
1602-
FC_DBG("Cannot process RRQ, because of frame error %d\n", err);
1591+
FC_EXCH_DBG(aborted_ep, "Cannot process RRQ, "
1592+
"frame error %d\n", err);
16031593
return;
16041594
}
16051595

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

16091599
switch (op) {
16101600
case ELS_LS_RJT:
1611-
FC_DBG("LS_RJT for RRQ");
1601+
FC_EXCH_DBG(aborted_ep, "LS_RJT for RRQ");
16121602
/* fall through */
16131603
case ELS_LS_ACC:
16141604
goto cleanup;
16151605
default:
1616-
FC_DBG("unexpected response op %x for RRQ", op);
1606+
FC_EXCH_DBG(aborted_ep, "unexpected response op %x "
1607+
"for RRQ", op);
16171608
return;
16181609
}
16191610

@@ -1740,8 +1731,8 @@ struct fc_exch_mgr *fc_exch_mgr_alloc(struct fc_lport *lp,
17401731
size_t len;
17411732

17421733
if (max_xid <= min_xid || min_xid == 0 || max_xid == FC_XID_UNKNOWN) {
1743-
FC_DBG("Invalid min_xid 0x:%x and max_xid 0x:%x\n",
1744-
min_xid, max_xid);
1734+
FC_LPORT_DBG(lp, "Invalid min_xid 0x:%x and max_xid 0x:%x\n",
1735+
min_xid, max_xid);
17451736
return NULL;
17461737
}
17471738

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

18791870
/* lport lock ? */
18801871
if (!lp || !mp || (lp->state == LPORT_ST_NONE)) {
1881-
FC_DBG("fc_lport or EM is not allocated and configured");
1872+
FC_LPORT_DBG(lp, "Receiving frames for an lport that "
1873+
"has not been initialized correctly\n");
18821874
fc_frame_free(fp);
18831875
return;
18841876
}
@@ -1904,7 +1896,7 @@ void fc_exch_recv(struct fc_lport *lp, struct fc_exch_mgr *mp,
19041896
fc_exch_recv_req(lp, mp, fp);
19051897
break;
19061898
default:
1907-
FC_DBG("dropping invalid frame (eof %x)", fr_eof(fp));
1899+
FC_EM_DBG(mp, "dropping invalid frame (eof %x)", fr_eof(fp));
19081900
fc_frame_free(fp);
19091901
break;
19101902
}

0 commit comments

Comments
 (0)