NFSD: Fix crash in nfsd4_read_release()
Subsystems (2)
Chuck Lever
maintainerPATCH 1/1 NFSD: Fix crash in nfsd4_read_release()
From: Chuck Lever <[email protected]>
When tracing is enabled, the trace_nfsd_read_done trace point crashes during the pynfs read.testNoFh test.
--- fs/nfsd/nfs4proc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
fs/nfsd/nfs4proc.c +4 -3
@@ -988,10 +988,11 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,static void nfsd4_read_release (union nfsd4_op_u *u) { -if (u->read.rd_nf) +if (u->read.rd_nf) { +trace_nfsd_read_done (u->read.rd_rqstp, u->read.rd_fhp, + u->read.rd_offset, u->read.rd_length);nfsd_file_put (u->read.rd_nf); -trace_nfsd_read_done (u->read.rd_rqstp, u->read.rd_fhp, - u->read.rd_offset, u->read.rd_length); + } } static __be32
Signature · 1 line
2.51.0
Quoted 20 lines · Chuck Lever
From: Chuck Lever <[email protected]>
When tracing is enabled, the
trace_nfsd_read_donetrace point crashes during the pynfs read.testNoFh test.Fixes 87c5942e8fae ("nfsd: Add I/O trace points in the NFSv4 read proc")Signed-off-by Chuck Lever <[email protected]>--- fs/nfsd/nfs4proc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)fs/nfsd/nfs4proc.c +0
-1@@ -988,10 +988,11 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,static void nfsd4_read_release (union nfsd4_op_u *u) { -if (u->read.rd_nf)
fs/nfsd/nfs4proc.c nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 998
Quoted 10 lines
fs/nfsd/nfs4proc.c +4
-2+if (u->read.rd_nf) { +trace_nfsd_read_done (u->read.rd_rqstp, u->read.rd_fhp, + u->read.rd_offset, u->read.rd_length);nfsd_file_put (u->read.rd_nf); -trace_nfsd_read_done (u->read.rd_rqstp, u->read.rd_fhp, - u->read.rd_offset, u->read.rd_length); + } } static __be32
Not sending a filehandle is pretty rare so I guess we won't miss the lack of a tracepoint in that case.
Quoted 18 lines · Chuck Lever
From: Chuck Lever <[email protected]>
When tracing is enabled, the
trace_nfsd_read_donetrace point crashes during the pynfs read.testNoFh test.Fixes 87c5942e8fae ("nfsd: Add I/O trace points in the NFSv4 read proc")Signed-off-by Chuck Lever <[email protected]>--- fs/nfsd/nfs4proc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)fs/nfsd/nfs4proc.c +0
-0@@ -988,10 +988,11 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,static void nfsd4_read_release (union nfsd4_op_u *u)
fs/nfsd/nfs4proc.c nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 996
Quoted 10 lines
fs/nfsd/nfs4proc.c +4
-3{ -if (u->read.rd_nf) +if (u->read.rd_nf) { +trace_nfsd_read_done (u->read.rd_rqstp, u->read.rd_fhp, + u->read.rd_offset, u->read.rd_length);nfsd_file_put (u->read.rd_nf); -trace_nfsd_read_done (u->read.rd_rqstp, u->read.rd_fhp, - u->read.rd_offset, u->read.rd_length); + } }
I must say this looks a bit weird. rd_nf isn't used in the trace but if it isn't set, you say the trace crashes...
That is because rd_fhp being NULL (because there is no current_fh) is one thing that results in rd_nf being NULL. Seems a bit indirect. Did you consider
if (u->read.rd_fhp)
trace .....
if (u->read.rd_nf)
nfsd_file_put....??
Or maybe
fs/nfsd/trace.h +1 -1
@@ -444,7 +444,7 @@ DECLARE_EVENT_CLASS(nfsd_io_class, ), TP_fast_assign( __entry->xid = be32_to_cpu(rqstp->rq_xid); - __entry->fh_hash =knfsd_fh_hash (&fhp->fh_handle); + __entry->fh_hash = fhp ?0 :knfsd_fh_hash (&fhp->fh_handle); __entry->offset = offset; __entry->len = len; ),
That would make all IO event trace points robust.
I'm almost tempted to suggest knfsd_fh_hash() be changed to receive a svc_fh and test for NULL, but there are 2 places where there isn't a svc_fh handy.
NeilBrown
Chuck Lever
maintainerQuoted 33 lines · NeilBrown
Quoted 18 lines · Chuck Lever
From: Chuck Lever <[email protected]>
When tracing is enabled, the
trace_nfsd_read_donetrace point crashes during the pynfs read.testNoFh test.Fixes 87c5942e8fae ("nfsd: Add I/O trace points in the NFSv4 read proc")Signed-off-by Chuck Lever <[email protected]>--- fs/nfsd/nfs4proc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)fs/nfsd/nfs4proc.c +0
-0@@ -988,10 +988,11 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,static void nfsd4_read_release (union nfsd4_op_u *u)fs/nfsd/nfs4proc.c nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 996
Quoted 10 lines
fs/nfsd/nfs4proc.c +4
-3{ -if (u->read.rd_nf) +if (u->read.rd_nf) { +trace_nfsd_read_done (u->read.rd_rqstp, u->read.rd_fhp, + u->read.rd_offset, u->read.rd_length);nfsd_file_put (u->read.rd_nf); -trace_nfsd_read_done (u->read.rd_rqstp, u->read.rd_fhp, - u->read.rd_offset, u->read.rd_length); + } }I must say this looks a bit weird.
rd_nfisn't used in the trace but if it isn't set, you say the trace crashes...
Quoted 2 lines
That is because
rd_fhpbeing NULL (because there is nocurrent_fh) is one thing that results inrd_nfbeing NULL. Seems a bit indirect.
When rd_nf is NULL, no file or file handle is present. That's really all there is to it. You can read it as "when rd_nf is NULL, no processing is needed".
The other read trace points are already skipped in this case as well, so there is no need to protect them.
Quoted 7 lines
Did you consider
if (u->read.rd_fhp)trace ..... if (u->read.rd_nf) nfsd_file_put....??
I can't think of a legitimate case where fhp is not NULL but nf is NULL. Or vice versa.
Quoted 21 lines
Or maybe
fs/nfsd/trace.h +1
-1@@ -444,7 +444,7 @@ DECLARE_EVENT_CLASS(nfsd_io_class, ), TP_fast_assign( __entry->xid = be32_to_cpu(rqstp->rq_xid); - __entry->fh_hash =knfsd_fh_hash (&fhp->fh_handle); + __entry->fh_hash = fhp ?0 :knfsd_fh_hash (&fhp->fh_handle); __entry->offset = offset; __entry->len = len; ),That would make all IO event trace points robust.
I'm almost tempted to suggestknfsd_fh_hash()be changed to receive asvc_fhand test for NULL, but there are 2 places where there isn't asvc_fhhandy.NeilBrown
Signature · 1 line
Chuck Lever
Quoted 37 lines · Chuck Lever
Quoted 33 lines · NeilBrown
Quoted 18 lines · Chuck Lever
From: Chuck Lever <[email protected]>
When tracing is enabled, the
trace_nfsd_read_donetrace point crashes during the pynfs read.testNoFh test.Fixes 87c5942e8fae ("nfsd: Add I/O trace points in the NFSv4 read proc")Signed-off-by Chuck Lever <[email protected]>--- fs/nfsd/nfs4proc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)fs/nfsd/nfs4proc.c +0
-0@@ -988,10 +988,11 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,static void nfsd4_read_release (union nfsd4_op_u *u)fs/nfsd/nfs4proc.c nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 996
Quoted 10 lines
fs/nfsd/nfs4proc.c +4
-3{ -if (u->read.rd_nf) +if (u->read.rd_nf) { +trace_nfsd_read_done (u->read.rd_rqstp, u->read.rd_fhp, + u->read.rd_offset, u->read.rd_length);nfsd_file_put (u->read.rd_nf); -trace_nfsd_read_done (u->read.rd_rqstp, u->read.rd_fhp, - u->read.rd_offset, u->read.rd_length); + } }I must say this looks a bit weird.
rd_nfisn't used in the trace but if it isn't set, you say the trace crashes...Quoted 2 lines
That is because
rd_fhpbeing NULL (because there is nocurrent_fh) is one thing that results inrd_nfbeing NULL. Seems a bit indirect.
Quoted 6 lines
When
rd_nfis NULL, no file or file handle is present. That's really all there is to it. You can read it as "whenrd_nfis NULL, no processing is needed".The other read trace points are already skipped in this case as well, so there is no need to protect them.
They are skipped because ALLOWED_WITHOUT_FH is not set so ->op_func isn't called. But ->op_release *is* called. That seems inconsistent. I wonder if we could move the ->op_release call out of nfsd4_encode_operation() and only call it in cases were ->op_func was called.
Something like the following? It isn't as elegant as I would have liked, but I think it is better than hiding the ->op_release cxall in nfsd4_encode_replay().
Thanks,
NeilBrown
fs/nfsd/nfs4proc.c +6 -0
@@ -2837,6 +2837,8 @@ nfsd4_proc_compound(struct svc_rqst *rqstp)trace_nfsd_compound (rqstp, args->tag, args->taglen, args->opcnt);while (!status && resp->opcnt < args->opcnt) { +bool called_func = false; + op = &args->ops[resp->opcnt++];/*
@@ -2886,6 +2888,7 @@ nfsd4_proc_compound(struct svc_rqst *rqstp)if (op->opdesc->op_get_currentstateid) op->opdesc->op_get_currentstateid (cstate, &op->u); op->status = op->opdesc->op_func (rqstp, cstate, &op->u); + called_func = true;trace_nfsd_compound_op_err (rqstp, op->opnum, op->status);/* Only from SEQUENCE */
@@ -2914,6 +2917,9 @@ nfsd4_proc_compound(struct svc_rqst *rqstp)nfsd4_encode_operation (resp, op); status = op->status; } +if (called_func && op->opdesc->op_release) + op->opdesc->op_release (&op->u); +trace_nfsd_compound_status (args->opcnt, resp->opcnt, status,nfsd4_op_name (op->opnum));
fs/nfsd/nfs4xdr.c +3 -6
@@ -5885,10 +5885,10 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)nfsd4_enc encoder;if (xdr_stream_encode_u32 (xdr, op->opnum) !=XDR_UNIT ) - goto release; + goto out; op_status_offset = xdr->buf->len;if (!xdr_reserve_space (xdr,XDR_UNIT )) - goto release; + goto out;if (op->opnum ==OP_ILLEGAL ) goto status;
@@ -5944,10 +5944,7 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) resp->cstate.minorversion);write_bytes_to_xdr_buf (xdr->buf, op_status_offset, &op->status,XDR_UNIT ); -release: -if (opdesc && opdesc->op_release) - opdesc->op_release (&op->u); - +out:/* * Account for pages consumed while encoding this operation. * The xdr_stream primitives don't manage rq_next_page.
Chuck Lever
maintainerQuoted 63 lines · NeilBrown
Quoted 37 lines · Chuck Lever
Quoted 33 lines · NeilBrown
Quoted 18 lines · Chuck Lever
From: Chuck Lever <[email protected]>
When tracing is enabled, the
trace_nfsd_read_donetrace point crashes during the pynfs read.testNoFh test.Fixes 87c5942e8fae ("nfsd: Add I/O trace points in the NFSv4 read proc")Signed-off-by Chuck Lever <[email protected]>--- fs/nfsd/nfs4proc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)fs/nfsd/nfs4proc.c +0
-0@@ -988,10 +988,11 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,static void nfsd4_read_release (union nfsd4_op_u *u)fs/nfsd/nfs4proc.c nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 996
Quoted 10 lines
fs/nfsd/nfs4proc.c +4
-3{ -if (u->read.rd_nf) +if (u->read.rd_nf) { +trace_nfsd_read_done (u->read.rd_rqstp, u->read.rd_fhp, + u->read.rd_offset, u->read.rd_length);nfsd_file_put (u->read.rd_nf); -trace_nfsd_read_done (u->read.rd_rqstp, u->read.rd_fhp, - u->read.rd_offset, u->read.rd_length); + } }I must say this looks a bit weird.
rd_nfisn't used in the trace but if it isn't set, you say the trace crashes...Quoted 2 lines
That is because
rd_fhpbeing NULL (because there is nocurrent_fh) is one thing that results inrd_nfbeing NULL. Seems a bit indirect.Quoted 6 lines
When
rd_nfis NULL, no file or file handle is present. That's really all there is to it. You can read it as "whenrd_nfis NULL, no processing is needed".The other read trace points are already skipped in this case as well, so there is no need to protect them.
They are skipped because
ALLOWED_WITHOUT_FHis not set so ->op_func isn't called. But ->op_release *is* called. That seems inconsistent. I wonder if we could move the ->op_release call out ofnfsd4_encode_operation()and only call it in cases were ->op_func was called.Something like the following? It isn't as elegant as I would have liked, but I think it is better than hiding the ->op_release cxall in
nfsd4_encode_replay().Thanks,
NeilBrownfs/nfsd/nfs4proc.c +0
-0
fs/nfsd/nfs4proc.c nfsd4_proc_compound(struct svc_rqst *rqstp) · line 2841
Quoted 5 lines
fs/nfsd/nfs4proc.c +2
-0@@ -2837,6 +2837,8 @@ nfsd4_proc_compound(struct svc_rqst *rqstp)trace_nfsd_compound (rqstp, args->tag, args->taglen, args->opcnt);while (!status && resp->opcnt < args->opcnt) { +bool called_func = false; +
Or call it "release_needed" ?
This change is not something I'd care to have backported into stable kernels... So maybe keep the modification of nfsd4_read_release for backport, and then subsequently do this change too?
I was reminded of a release-related change that Jeff did recently, maybe commit 15a8b55dbb1b ("nfsd: call op_release, even when op_func returns an error")... might be relevant, might not.
Quoted 52 lines
fs/nfsd/nfs4proc.c +4
-0op = &args->ops[resp->opcnt++];/* @@ -2886,6 +2888,7 @@ nfsd4_proc_compound(struct svc_rqst *rqstp)if (op->opdesc->op_get_currentstateid) op->opdesc->op_get_currentstateid (cstate, &op->u); op->status = op->opdesc->op_func (rqstp, cstate, &op->u); + called_func = true;trace_nfsd_compound_op_err (rqstp, op->opnum, op->status);/* Only from SEQUENCE */ @@ -2914,6 +2917,9 @@ nfsd4_proc_compound(struct svc_rqst *rqstp)nfsd4_encode_operation (resp, op); status = op->status; } +if (called_func && op->opdesc->op_release) + op->opdesc->op_release (&op->u); +trace_nfsd_compound_status (args->opcnt, resp->opcnt, status,nfsd4_op_name (op->opnum));fs/nfsd/nfs4xdr.c +3
-6@@ -5885,10 +5885,10 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op)nfsd4_enc encoder;if (xdr_stream_encode_u32 (xdr, op->opnum) !=XDR_UNIT ) - goto release; + goto out; op_status_offset = xdr->buf->len;if (!xdr_reserve_space (xdr,XDR_UNIT )) - goto release; + goto out;if (op->opnum ==OP_ILLEGAL ) goto status;@@ -5944,10 +5944,7 @@ nfsd4_encode_operation(struct nfsd4_compoundres *resp, struct nfsd4_op *op) resp->cstate.minorversion);write_bytes_to_xdr_buf (xdr->buf, op_status_offset, &op->status,XDR_UNIT ); -release: -if (opdesc && opdesc->op_release) - opdesc->op_release (&op->u); - +out:/* * Account for pages consumed while encoding this operation. * The xdr_stream primitives don't manage rq_next_page.
Signature · 1 line
Chuck Lever
Quoted 65 lines · Chuck Lever
Quoted 64 lines · NeilBrown
Quoted 37 lines · Chuck Lever
Quoted 33 lines · NeilBrown
Quoted 18 lines · Chuck Lever
From: Chuck Lever <[email protected]>
When tracing is enabled, the
trace_nfsd_read_donetrace point crashes during the pynfs read.testNoFh test.Fixes 87c5942e8fae ("nfsd: Add I/O trace points in the NFSv4 read proc")Signed-off-by Chuck Lever <[email protected]>--- fs/nfsd/nfs4proc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)fs/nfsd/nfs4proc.c +0
-0@@ -988,10 +988,11 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,static void nfsd4_read_release (union nfsd4_op_u *u)fs/nfsd/nfs4proc.c nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 996
Quoted 10 lines
fs/nfsd/nfs4proc.c +4
-3{ -if (u->read.rd_nf) +if (u->read.rd_nf) { +trace_nfsd_read_done (u->read.rd_rqstp, u->read.rd_fhp, + u->read.rd_offset, u->read.rd_length);nfsd_file_put (u->read.rd_nf); -trace_nfsd_read_done (u->read.rd_rqstp, u->read.rd_fhp, - u->read.rd_offset, u->read.rd_length); + } }I must say this looks a bit weird.
rd_nfisn't used in the trace but if it isn't set, you say the trace crashes...Quoted 2 lines
That is because
rd_fhpbeing NULL (because there is nocurrent_fh) is one thing that results inrd_nfbeing NULL. Seems a bit indirect.Quoted 6 lines
When
rd_nfis NULL, no file or file handle is present. That's really all there is to it. You can read it as "whenrd_nfis NULL, no processing is needed".The other read trace points are already skipped in this case as well, so there is no need to protect them.
They are skipped because
ALLOWED_WITHOUT_FHis not set so ->op_func isn't called. But ->op_release *is* called. That seems inconsistent. I wonder if we could move the ->op_release call out ofnfsd4_encode_operation()and only call it in cases were ->op_func was called.Something like the following? It isn't as elegant as I would have liked, but I think it is better than hiding the ->op_release cxall in
nfsd4_encode_replay().Thanks,
NeilBrownfs/nfsd/nfs4proc.c +0
-0@@ -2837,6 +2837,8 @@ nfsd4_proc_compound(struct svc_rqst *rqstp)
Quoted 6 lines
fs/nfsd/nfs4proc.c nfsd4_proc_compound(struct svc_rqst *rqstp) · line 2841
Quoted 4 lines
fs/nfsd/nfs4proc.c +2
-0trace_nfsd_compound (rqstp, args->tag, args->taglen, args->opcnt);while (!status && resp->opcnt < args->opcnt) { +bool called_func = false; +Or call it "
release_needed" ?
That might be a bit better - yes.
Quoted 4 lines
This change is not something I'd care to have backported into stable kernels... So maybe keep the modification of
nfsd4_read_releasefor backport, and then subsequently do this change too?
That seems like a sensible safe approach.
Quoted 4 lines
I was reminded of a release-related change that Jeff did recently, maybe commit
15a8b55dbb1b("nfsd: callop_release, even whenop_funcreturns an error")... might be relevant, might not.
Definitely relevant. I think this is the commit to mention in the
Fixes: tag. Prior to this commit nfsd4_read_release wouldn't have been called if there was no filehandle, so the trace point was perfectly safe.
I wonder if this fix by Jeff was the best fix for the problem. An alternative would be to require ->op_func to release any resources before returning an error..... except that wouldn't work for OP_NONTRIVIAL_ERROR_ENCODE functions like OP_LOCK as the ->op_release frees the "deny" info which is needed to encode the reply....
But wait ...nfs4_encode_operation - which currently calls ->op_release - is also called from nfsd4_enc_sequence_replay(). The status is set to an error so ->op_release previously would not have been called, but now it is. Could that mean nfsd4_lock_release() can get called there even tough nfsd4_lock wasn't called. Could that be a problem? It isn't clear to me that is *isn't* a problem, should maybe there is a subtlety that saves it.
I'm beginning to think that we don't want an op_release at all. Anything allocated in ->op_func should either be freed in ->op_func when an error is detected, or in the corresponding nfsd4_enc_ops function after the allocated value is used for encoding.
Looking further...
->op_get_currentstateid is only called immediately before the one time that ->op_func is called. So ->op_func could do that get_currentstateid work.
and ->op_set_currentstateid looks like it could be folded in to ->op_func as well.
Does anyone have any thoughts about that?
Thanks,
NeilBrown
Chuck Lever
maintainerQuoted 9 lines · NeilBrown
Quoted 3 lines · Chuck Lever
I was reminded of a release-related change that Jeff did recently, maybe commit
15a8b55dbb1b("nfsd: callop_release, even whenop_funcreturns an error")... might be relevant, might not.Definitely relevant. I think this is the commit to mention in the
Fixes: tag. Prior to this commitnfsd4_read_releasewouldn't have been called if there was no filehandle, so the trace point was perfectly safe.
I'll replace the Fixes: tag with that one.
Quoted 6 lines
I wonder if this fix by Jeff was the best fix for the problem. An alternative would be to require ->op_func to release any resources before returning an error..... except that wouldn't work for
OP_NONTRIVIAL_ERROR_ENCODEfunctions likeOP_LOCKas the ->op_release frees the "deny" info which is needed to encode the reply....
Quoted 7 lines
But wait ...nfs4_encode_operation - which currently calls ->op_release - is also called from
nfsd4_enc_sequence_replay(). The status is set to an error so ->op_release previously would not have been called, but now it is. Could that meannfsd4_lock_release()can get called there even toughnfsd4_lockwasn't called. Could that be a problem? It isn't clear to me that is *isn't* a problem, should maybe there is a subtlety that saves it.
One approach to getting experimental data would be to hack together a pynfs test for this case. (If it proves useful, please contribute it).
Quoted 5 lines
I'm beginning to think that we don't want an
op_releaseat all. Anything allocated in ->op_func should either be freed in ->op_func when an error is detected, or in the correspondingnfsd4_enc_opsfunction after the allocated value is used for encoding.
Quoted 8 lines
Looking further...
->op_get_currentstateid is only called immediately before the one time that ->op_func is called. So ->op_func could do thatget_currentstateidwork.
and ->op_set_currentstateid looks like it could be folded in to ->op_func as well.Does anyone have any thoughts about that?
Careful review needed, I think. We are getting ready for a week of bake-a-thon next week... that might delay any deep thinking on my part for a few days.
Signature · 1 line
Chuck Lever
Jeff Layton
maintainerQuoted 111 lines · NeilBrown
Quoted 65 lines · Chuck Lever
Quoted 64 lines · NeilBrown
Quoted 37 lines · Chuck Lever
Quoted 33 lines · NeilBrown
Quoted 18 lines · Chuck Lever
From: Chuck Lever <[email protected]>
When tracing is enabled, the
trace_nfsd_read_donetrace point crashes during the pynfs read.testNoFh test.Fixes 87c5942e8fae ("nfsd: Add I/O trace points in the NFSv4 read proc")Signed-off-by Chuck Lever <[email protected]>--- fs/nfsd/nfs4proc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)fs/nfsd/nfs4proc.c +0
-0@@ -988,10 +988,11 @@ nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,static void nfsd4_read_release (union nfsd4_op_u *u)fs/nfsd/nfs4proc.c nfsd4_read(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, · line 996
Quoted 10 lines
fs/nfsd/nfs4proc.c +4
-3{ -if (u->read.rd_nf) +if (u->read.rd_nf) { +trace_nfsd_read_done (u->read.rd_rqstp, u->read.rd_fhp, + u->read.rd_offset, u->read.rd_length);nfsd_file_put (u->read.rd_nf); -trace_nfsd_read_done (u->read.rd_rqstp, u->read.rd_fhp, - u->read.rd_offset, u->read.rd_length); + } }I must say this looks a bit weird.
rd_nfisn't used in the trace but if it isn't set, you say the trace crashes...Quoted 2 lines
That is because
rd_fhpbeing NULL (because there is nocurrent_fh) is one thing that results inrd_nfbeing NULL. Seems a bit indirect.Quoted 6 lines
When
rd_nfis NULL, no file or file handle is present. That's really all there is to it. You can read it as "whenrd_nfis NULL, no processing is needed".The other read trace points are already skipped in this case as well, so there is no need to protect them.
They are skipped because
ALLOWED_WITHOUT_FHis not set so ->op_func isn't called. But ->op_release *is* called. That seems inconsistent. I wonder if we could move the ->op_release call out ofnfsd4_encode_operation()and only call it in cases were ->op_func was called.Something like the following? It isn't as elegant as I would have liked, but I think it is better than hiding the ->op_release cxall in
nfsd4_encode_replay().Thanks,
NeilBrownfs/nfsd/nfs4proc.c +0
-0@@ -2837,6 +2837,8 @@ nfsd4_proc_compound(struct svc_rqst *rqstp)Quoted 6 lines
fs/nfsd/nfs4proc.c nfsd4_proc_compound(struct svc_rqst *rqstp) · line 2841
Quoted 4 lines
fs/nfsd/nfs4proc.c +2
-0trace_nfsd_compound (rqstp, args->tag, args->taglen, args->opcnt);while (!status && resp->opcnt < args->opcnt) { +bool called_func = false; +Or call it "
release_needed" ?That might be a bit better - yes.
Quoted 4 lines
This change is not something I'd care to have backported into stable kernels... So maybe keep the modification of
nfsd4_read_releasefor backport, and then subsequently do this change too?That seems like a sensible safe approach.
Quoted 4 lines
I was reminded of a release-related change that Jeff did recently, maybe commit
15a8b55dbb1b("nfsd: callop_release, even whenop_funcreturns an error")... might be relevant, might not.Definitely relevant. I think this is the commit to mention in the
Fixes: tag. Prior to this commitnfsd4_read_releasewouldn't have been called if there was no filehandle, so the trace point was perfectly safe.I wonder if this fix by Jeff was the best fix for the problem. An alternative would be to require ->op_func to release any resources before returning an error..... except that wouldn't work for
OP_NONTRIVIAL_ERROR_ENCODEfunctions likeOP_LOCKas the ->op_release frees the "deny" info which is needed to encode the reply....But wait ...nfs4_encode_operation - which currently calls ->op_release - is also called from
nfsd4_enc_sequence_replay(). The status is set to an error so ->op_release previously would not have been called, but now it is. Could that meannfsd4_lock_release()can get called there even toughnfsd4_lockwasn't called. Could that be a problem? It isn't clear to me that is *isn't* a problem, should maybe there is a subtlety that saves it.I'm beginning to think that we don't want an
op_releaseat all. Anything allocated in ->op_func should either be freed in ->op_func when an error is detected, or in the correspondingnfsd4_enc_opsfunction after the allocated value is used for encoding.
Quoted 8 lines
Looking further...
->op_get_currentstateid is only called immediately before the one time that ->op_func is called. So ->op_func could do thatget_currentstateidwork.
and ->op_set_currentstateid looks like it could be folded in to ->op_func as well.Does anyone have any thoughts about that?
I think that sounds reasonable. I don't see anything that would preclude that anyway, at least with a cursory look. All of the references that get released in the op_release calls are acquired during op_func, AFAICT.
Signature · 1 line
Jeff Layton <[email protected]>