Skip to content

Commit 31ef83d

Browse files
author
Christoph Hellwig
committed
nfsd: add trace events
For now just a few simple events to trace the layout stateid lifetime, but these already were enough to find several bugs in the Linux client layout stateid handling. Signed-off-by: Christoph Hellwig <[email protected]>
1 parent 18d1aef commit 31ef83d

File tree

5 files changed

+85
-3
lines changed

5 files changed

+85
-3
lines changed

fs/nfsd/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,14 @@
22
# Makefile for the Linux nfs server
33
#
44

5+
ccflags-y += -I$(src) # needed for trace events
6+
57
obj-$(CONFIG_NFSD) += nfsd.o
68

7-
nfsd-y := nfssvc.o nfsctl.o nfsproc.o nfsfh.o vfs.o \
9+
# this one should be compiled first, as the tracing macros can easily blow up
10+
nfsd-y += trace.o
11+
12+
nfsd-y += nfssvc.o nfsctl.o nfsproc.o nfsfh.o vfs.o \
813
export.o auth.o lockd.o nfscache.o nfsxdr.o stats.o
914
nfsd-$(CONFIG_NFSD_FAULT_INJECTION) += fault_inject.o
1015
nfsd-$(CONFIG_NFSD_V2_ACL) += nfs2acl.o

fs/nfsd/nfs4layouts.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include "pnfs.h"
1111
#include "netns.h"
12+
#include "trace.h"
1213

1314
#define NFSDDBG_FACILITY NFSDDBG_PNFS
1415

@@ -125,6 +126,8 @@ nfsd4_free_layout_stateid(struct nfs4_stid *stid)
125126
struct nfs4_client *clp = ls->ls_stid.sc_client;
126127
struct nfs4_file *fp = ls->ls_stid.sc_file;
127128

129+
trace_layoutstate_free(&ls->ls_stid.sc_stateid);
130+
128131
spin_lock(&clp->cl_lock);
129132
list_del_init(&ls->ls_perclnt);
130133
spin_unlock(&clp->cl_lock);
@@ -215,6 +218,7 @@ nfsd4_alloc_layout_stateid(struct nfsd4_compound_state *cstate,
215218
list_add(&ls->ls_perfile, &fp->fi_lo_states);
216219
spin_unlock(&fp->fi_lock);
217220

221+
trace_layoutstate_alloc(&ls->ls_stid.sc_stateid);
218222
return ls;
219223
}
220224

@@ -280,6 +284,8 @@ nfsd4_recall_file_layout(struct nfs4_layout_stateid *ls)
280284
if (list_empty(&ls->ls_layouts))
281285
goto out_unlock;
282286

287+
trace_layout_recall(&ls->ls_stid.sc_stateid);
288+
283289
atomic_inc(&ls->ls_stid.sc_count);
284290
update_stateid(&ls->ls_stid.sc_stateid);
285291
memcpy(&ls->ls_recall_sid, &ls->ls_stid.sc_stateid, sizeof(stateid_t));
@@ -454,8 +460,10 @@ nfsd4_return_file_layouts(struct svc_rqst *rqstp,
454460
nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lrp->lr_sid,
455461
false, lrp->lr_layout_type,
456462
&ls);
457-
if (nfserr)
463+
if (nfserr) {
464+
trace_layout_return_lookup_fail(&lrp->lr_sid);
458465
return nfserr;
466+
}
459467

460468
spin_lock(&ls->ls_lock);
461469
list_for_each_entry_safe(lp, n, &ls->ls_layouts, lo_perstate) {
@@ -472,6 +480,7 @@ nfsd4_return_file_layouts(struct svc_rqst *rqstp,
472480
}
473481
lrp->lrs_present = 1;
474482
} else {
483+
trace_layoutstate_unhash(&ls->ls_stid.sc_stateid);
475484
nfs4_unhash_stid(&ls->ls_stid);
476485
lrp->lrs_present = 0;
477486
}
@@ -570,6 +579,8 @@ nfsd4_cb_layout_fail(struct nfs4_layout_stateid *ls)
570579

571580
rpc_ntop((struct sockaddr *)&clp->cl_addr, addr_str, sizeof(addr_str));
572581

582+
nfsd4_cb_layout_fail(ls);
583+
573584
printk(KERN_WARNING
574585
"nfsd: client %s failed to respond to layout recall. "
575586
" Fencing..\n", addr_str);
@@ -597,6 +608,7 @@ nfsd4_cb_layout_done(struct nfsd4_callback *cb, struct rpc_task *task)
597608
case 0:
598609
return 1;
599610
case -NFS4ERR_NOMATCHING_LAYOUT:
611+
trace_layout_recall_done(&ls->ls_stid.sc_stateid);
600612
task->tk_status = 0;
601613
return 1;
602614
case -NFS4ERR_DELAY:
@@ -624,6 +636,8 @@ nfsd4_cb_layout_release(struct nfsd4_callback *cb)
624636
container_of(cb, struct nfs4_layout_stateid, ls_recall);
625637
LIST_HEAD(reaplist);
626638

639+
trace_layout_recall_release(&ls->ls_stid.sc_stateid);
640+
627641
nfsd4_return_all_layouts(ls, &reaplist);
628642
nfsd4_free_layouts(&reaplist);
629643
nfs4_put_stid(&ls->ls_stid);

fs/nfsd/nfs4proc.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "netns.h"
4545
#include "acl.h"
4646
#include "pnfs.h"
47+
#include "trace.h"
4748

4849
#ifdef CONFIG_NFSD_V4_SECURITY_LABEL
4950
#include <linux/security.h>
@@ -1298,8 +1299,10 @@ nfsd4_layoutget(struct svc_rqst *rqstp,
12981299

12991300
nfserr = nfsd4_preprocess_layout_stateid(rqstp, cstate, &lgp->lg_sid,
13001301
true, lgp->lg_layout_type, &ls);
1301-
if (nfserr)
1302+
if (nfserr) {
1303+
trace_layout_get_lookup_fail(&lgp->lg_sid);
13021304
goto out;
1305+
}
13031306

13041307
nfserr = nfserr_recallconflict;
13051308
if (atomic_read(&ls->ls_stid.sc_file->fi_lo_recalls))
@@ -1359,6 +1362,7 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp,
13591362
false, lcp->lc_layout_type,
13601363
&ls);
13611364
if (nfserr) {
1365+
trace_layout_commit_lookup_fail(&lcp->lc_sid);
13621366
/* fixup error code as per RFC5661 */
13631367
if (nfserr == nfserr_bad_stateid)
13641368
nfserr = nfserr_badlayout;

fs/nfsd/trace.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
2+
#include "state.h"
3+
4+
#define CREATE_TRACE_POINTS
5+
#include "trace.h"

fs/nfsd/trace.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2014 Christoph Hellwig.
3+
*/
4+
#undef TRACE_SYSTEM
5+
#define TRACE_SYSTEM nfsd
6+
7+
#if !defined(_NFSD_TRACE_H) || defined(TRACE_HEADER_MULTI_READ)
8+
#define _NFSD_TRACE_H
9+
10+
#include <linux/tracepoint.h>
11+
12+
DECLARE_EVENT_CLASS(nfsd_stateid_class,
13+
TP_PROTO(stateid_t *stp),
14+
TP_ARGS(stp),
15+
TP_STRUCT__entry(
16+
__field(u32, cl_boot)
17+
__field(u32, cl_id)
18+
__field(u32, si_id)
19+
__field(u32, si_generation)
20+
),
21+
TP_fast_assign(
22+
__entry->cl_boot = stp->si_opaque.so_clid.cl_boot;
23+
__entry->cl_id = stp->si_opaque.so_clid.cl_id;
24+
__entry->si_id = stp->si_opaque.so_id;
25+
__entry->si_generation = stp->si_generation;
26+
),
27+
TP_printk("client %08x:%08x stateid %08x:%08x",
28+
__entry->cl_boot,
29+
__entry->cl_id,
30+
__entry->si_id,
31+
__entry->si_generation)
32+
)
33+
34+
#define DEFINE_STATEID_EVENT(name) \
35+
DEFINE_EVENT(nfsd_stateid_class, name, \
36+
TP_PROTO(stateid_t *stp), \
37+
TP_ARGS(stp))
38+
DEFINE_STATEID_EVENT(layoutstate_alloc);
39+
DEFINE_STATEID_EVENT(layoutstate_unhash);
40+
DEFINE_STATEID_EVENT(layoutstate_free);
41+
DEFINE_STATEID_EVENT(layout_get_lookup_fail);
42+
DEFINE_STATEID_EVENT(layout_commit_lookup_fail);
43+
DEFINE_STATEID_EVENT(layout_return_lookup_fail);
44+
DEFINE_STATEID_EVENT(layout_recall);
45+
DEFINE_STATEID_EVENT(layout_recall_done);
46+
DEFINE_STATEID_EVENT(layout_recall_fail);
47+
DEFINE_STATEID_EVENT(layout_recall_release);
48+
49+
#endif /* _NFSD_TRACE_H */
50+
51+
#undef TRACE_INCLUDE_PATH
52+
#define TRACE_INCLUDE_PATH .
53+
#define TRACE_INCLUDE_FILE trace
54+
#include <trace/define_trace.h>

0 commit comments

Comments
 (0)