Skip to content

Commit

Permalink
nfsd: Add trace events for all v4 operations
Browse files Browse the repository at this point in the history
Add trace events to all v4 operations. Record client ip for ipv4
clients. Record uid from request credentials.

For READ and WRITE ops, additionally record offset and length request
arguments and device,inode and filename of the affected file.
  • Loading branch information
donald committed Feb 25, 2022
1 parent fd187a4 commit 1a28f2c
Show file tree
Hide file tree
Showing 3 changed files with 283 additions and 0 deletions.
72 changes: 72 additions & 0 deletions fs/nfsd/nfs4proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
struct nfsd_net *nn = net_generic(net, nfsd_net_id);
bool reclaim = false;

trace_nfsd4_open(rqstp);

dprintk("NFSD: nfsd4_open filename %.*s op_openowner %p\n",
(int)open->op_fname.len, open->op_fname.data,
open->op_openowner);
Expand Down Expand Up @@ -496,6 +498,8 @@ static __be32
nfsd4_getfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
union nfsd4_op_u *u)
{
trace_nfsd4_getfh(rqstp);

u->getfh = &cstate->current_fh;
return nfs_ok;
}
Expand All @@ -507,6 +511,8 @@ nfsd4_putfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
struct nfsd4_putfh *putfh = &u->putfh;
__be32 ret;

trace_nfsd4_putfh(rqstp);

fh_put(&cstate->current_fh);
cstate->current_fh.fh_handle.fh_size = putfh->pf_fhlen;
memcpy(&cstate->current_fh.fh_handle.fh_base, putfh->pf_fhval,
Expand All @@ -527,6 +533,8 @@ nfsd4_putrootfh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
{
__be32 status;

trace_nfsd4_putrootfh(rqstp);

fh_put(&cstate->current_fh);
status = exp_pseudoroot(rqstp, &cstate->current_fh);
return status;
Expand All @@ -536,6 +544,8 @@ static __be32
nfsd4_restorefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
union nfsd4_op_u *u)
{
trace_nfsd4_restorefh(rqstp);

if (!cstate->save_fh.fh_dentry)
return nfserr_restorefh;

Expand All @@ -551,6 +561,8 @@ static __be32
nfsd4_savefh(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
union nfsd4_op_u *u)
{
trace_nfsd4_savefh(rqstp);

fh_dup2(&cstate->save_fh, &cstate->current_fh);
if (HAS_CSTATE_FLAG(cstate, CURRENT_STATE_ID_FLAG)) {
memcpy(&cstate->save_stateid, &cstate->current_stateid, sizeof(stateid_t));
Expand All @@ -569,6 +581,8 @@ nfsd4_access(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
struct nfsd4_access *access = &u->access;
u32 access_full;

trace_nfsd4_access(rqstp);

access_full = NFS3_ACCESS_FULL;
if (cstate->minorversion >= 2)
access_full |= NFS4_ACCESS_XALIST | NFS4_ACCESS_XAREAD |
Expand Down Expand Up @@ -597,6 +611,8 @@ nfsd4_commit(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
{
struct nfsd4_commit *commit = &u->commit;

trace_nfsd4_commit(rqstp);

return nfsd_commit(rqstp, &cstate->current_fh, commit->co_offset,
commit->co_count,
(__be32 *)commit->co_verf.data);
Expand All @@ -611,6 +627,8 @@ nfsd4_create(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
__be32 status;
dev_t rdev;

trace_nfsd4_create(rqstp);

fh_init(&resfh, NFS4_FHSIZE);

status = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_NOP);
Expand Down Expand Up @@ -702,6 +720,8 @@ nfsd4_getattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
struct nfsd4_getattr *getattr = &u->getattr;
__be32 status;

trace_nfsd4_getattr(rqstp);

status = fh_verify(rqstp, &cstate->current_fh, 0, NFSD_MAY_NOP);
if (status)
return status;
Expand All @@ -724,6 +744,8 @@ nfsd4_link(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
struct nfsd4_link *link = &u->link;
__be32 status;

trace_nfsd4_link(rqstp);

status = nfsd_link(rqstp, &cstate->current_fh,
link->li_name, link->li_namelen, &cstate->save_fh);
if (!status)
Expand Down Expand Up @@ -752,13 +774,17 @@ static __be32
nfsd4_lookupp(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
union nfsd4_op_u *u)
{
trace_nfsd4_lookupp(rqstp);

return nfsd4_do_lookupp(rqstp, &cstate->current_fh);
}

static __be32
nfsd4_lookup(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
union nfsd4_op_u *u)
{
trace_nfsd4_lookup(rqstp);

return nfsd_lookup(rqstp, &cstate->current_fh,
u->lookup.lo_name, u->lookup.lo_len,
&cstate->current_fh);
Expand All @@ -771,6 +797,8 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
struct nfsd4_read *read = &u->read;
__be32 status;

trace_nfsd4_read(rqstp,cstate,read);

read->rd_nf = NULL;
if (read->rd_offset >= OFFSET_MAX)
return nfserr_inval;
Expand Down Expand Up @@ -822,6 +850,8 @@ nfsd4_readdir(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
u64 cookie = readdir->rd_cookie;
static const nfs4_verifier zeroverf;

trace_nfsd4_readdir(rqstp);

/* no need to check permission - this will be done in nfsd_readdir() */

if (readdir->rd_bmval[1] & NFSD_WRITEONLY_ATTRS_WORD1)
Expand All @@ -844,6 +874,8 @@ static __be32
nfsd4_readlink(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
union nfsd4_op_u *u)
{
trace_nfsd4_readlink(rqstp);

u->readlink.rl_rqstp = rqstp;
u->readlink.rl_fhp = &cstate->current_fh;
return nfs_ok;
Expand All @@ -856,6 +888,8 @@ nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
struct nfsd4_remove *remove = &u->remove;
__be32 status;

trace_nfsd4_remove(rqstp);

if (opens_in_grace(SVC_NET(rqstp)))
return nfserr_grace;
status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
Expand All @@ -874,6 +908,8 @@ nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
struct nfsd4_rename *rename = &u->rename;
__be32 status;

trace_nfsd4_rename(rqstp);

if (opens_in_grace(SVC_NET(rqstp)))
return nfserr_grace;
status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
Expand All @@ -895,6 +931,8 @@ nfsd4_secinfo(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
struct dentry *dentry;
__be32 err;

trace_nfsd4_secinfo(rqstp);

err = fh_verify(rqstp, &cstate->current_fh, S_IFDIR, NFSD_MAY_EXEC);
if (err)
return err;
Expand Down Expand Up @@ -922,6 +960,8 @@ nfsd4_secinfo_no_name(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstat
{
__be32 err;

trace_nfsd4_secinfo_no_name(rqstp);

switch (u->secinfo_no_name.sin_style) {
case NFS4_SECINFO_STYLE4_CURRENT_FH:
break;
Expand Down Expand Up @@ -961,6 +1001,8 @@ nfsd4_setattr(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
__be32 status = nfs_ok;
int err;

trace_nfsd4_setattr(rqstp);

if (setattr->sa_iattr.ia_valid & ATTR_SIZE) {
status = nfs4_preprocess_stateid_op(rqstp, cstate,
&cstate->current_fh, &setattr->sa_stateid,
Expand Down Expand Up @@ -1008,6 +1050,8 @@ nfsd4_write(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
unsigned long cnt;
int nvecs;

trace_nfsd4_write(rqstp,cstate,write);

if (write->wr_offset >= OFFSET_MAX)
return nfserr_inval;

Expand Down Expand Up @@ -1087,6 +1131,8 @@ nfsd4_clone(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
struct nfsd_file *src, *dst;
__be32 status;

trace_nfsd4_clone(rqstp);

status = nfsd4_verify_copy(rqstp, cstate, &clone->cl_src_stateid, &src,
&clone->cl_dst_stateid, &dst);
if (status)
Expand Down Expand Up @@ -1507,6 +1553,8 @@ nfsd4_copy(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
__be32 status;
struct nfsd4_copy *async_copy = NULL;

trace_nfsd4_copy(rqstp);

if (!copy->cp_intra) { /* Inter server SSC */
if (!inter_copy_offload_enable || copy->cp_synchronous) {
status = nfserr_notsupp;
Expand Down Expand Up @@ -1588,6 +1636,8 @@ nfsd4_offload_cancel(struct svc_rqst *rqstp,
struct nfsd4_copy *copy;
struct nfs4_client *clp = cstate->clp;

trace_nfsd4_offload_cancel(rqstp);

copy = find_async_copy(clp, &os->stateid);
if (!copy) {
struct nfsd_net *nn = net_generic(SVC_NET(rqstp), nfsd_net_id);
Expand All @@ -1610,6 +1660,8 @@ nfsd4_copy_notify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
struct nfs4_cpntf_state *cps;
struct nfs4_client *clp = cstate->clp;

trace_nfsd4_copy_notify(rqstp);

status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
&cn->cpn_src_stateid, RD_STATE, NULL,
&stid);
Expand Down Expand Up @@ -1675,6 +1727,8 @@ nfsd4_offload_status(struct svc_rqst *rqstp,
struct nfsd4_copy *copy;
struct nfs4_client *clp = cstate->clp;

trace_nfsd4_offload_status(rqstp);

copy = find_async_copy(clp, &os->stateid);
if (copy) {
os->count = copy->cp_res.wr_bytes_written;
Expand All @@ -1689,13 +1743,17 @@ static __be32
nfsd4_allocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
union nfsd4_op_u *u)
{
trace_nfsd4_allocate(rqstp);

return nfsd4_fallocate(rqstp, cstate, &u->allocate, 0);
}

static __be32
nfsd4_deallocate(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
union nfsd4_op_u *u)
{
trace_nfsd4_deallocate(rqstp);

return nfsd4_fallocate(rqstp, cstate, &u->deallocate,
FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE);
}
Expand All @@ -1709,6 +1767,8 @@ nfsd4_seek(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
__be32 status;
struct nfsd_file *nf;

trace_nfsd4_seek(rqstp);

status = nfs4_preprocess_stateid_op(rqstp, cstate, &cstate->current_fh,
&seek->seek_stateid,
RD_STATE, &nf, NULL);
Expand Down Expand Up @@ -1813,6 +1873,8 @@ nfsd4_nverify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
{
__be32 status;

trace_nfsd4_nverify(rqstp);

status = _nfsd4_verify(rqstp, cstate, &u->verify);
return status == nfserr_not_same ? nfs_ok : status;
}
Expand All @@ -1823,6 +1885,8 @@ nfsd4_verify(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
{
__be32 status;

trace_nfsd4_verify(rqstp);

status = _nfsd4_verify(rqstp, cstate, &u->nverify);
return status == nfserr_same ? nfs_ok : status;
}
Expand Down Expand Up @@ -1856,6 +1920,8 @@ nfsd4_getdeviceinfo(struct svc_rqst *rqstp,
struct svc_export *exp;
__be32 nfserr;

trace_nfsd4_getdeviceinfo(rqstp);

dprintk("%s: layout_type %u dev_id [0x%llx:0x%x] maxcnt %u\n",
__func__,
gdp->gd_layout_type,
Expand Down Expand Up @@ -1909,6 +1975,8 @@ nfsd4_layoutget(struct svc_rqst *rqstp,
__be32 nfserr;
int accmode = NFSD_MAY_READ_IF_EXEC;

trace_nfsd4_layoutget(rqstp);

switch (lgp->lg_seg.iomode) {
case IOMODE_READ:
accmode |= NFSD_MAY_READ;
Expand Down Expand Up @@ -1997,6 +2065,8 @@ nfsd4_layoutcommit(struct svc_rqst *rqstp,
struct nfs4_layout_stateid *ls;
__be32 nfserr;

trace_nfsd4_layoutcommit(rqstp);

nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_WRITE);
if (nfserr)
goto out;
Expand Down Expand Up @@ -2056,6 +2126,8 @@ nfsd4_layoutreturn(struct svc_rqst *rqstp,
struct svc_fh *current_fh = &cstate->current_fh;
__be32 nfserr;

trace_nfsd4_layoutreturn(rqstp);

nfserr = fh_verify(rqstp, current_fh, 0, NFSD_MAY_NOP);
if (nfserr)
goto out;
Expand Down
Loading

0 comments on commit 1a28f2c

Please sign in to comment.