Skip to contentSkip to conversation

nfs41: return correct errors on callback replays

PATCH In review [email protected] 2 participants 9 messages Jan 6, 2010 – Jan 12, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover nfs41: return correct errors on callback replays

The first three patches clean up callback processing 0001-nfs41-fix-wrong-error-on-callback-decode-hdr-overflo.patch 0002-nfs41-directly-encode-back-channel-error.patch 0003-nfs41-remove-uneeded-checks-in-callback-processing.patch

These next two implement correct error returns for v4.1 callback replays. Since our back channel has a ca_maxrequestsize_cached = 0, a replay with cachethis set to true results in a NFS4ERR_TOO_BIG_TO_CACHE error. This code is set up to do a real DRC.

A replay with cachethis set to false returns a NFS4ERR_RETRY_UNCACHED_REP error.

0004-nfs41-prepare-for-back-channel-drc.patch 0005-nfs41-back-channel-drc-minimal-implementation.patch

TODO: The callback code currently returns NFS4ERR_RESOURCE on all xdr overflows. This is correct for v4.0, incorrect for v4.1.

Testing:

Modified nfsv4.1 pynfs server tested cb_recall replays with the cb_sequence cachethis set to False and to True.

Connectathon tests pass.

-->Andy

#1 lore raw

PATCH 1/5 nfs41: fix wrong error on callback decode hdr overflow

From: Andy Adamson <[email protected]>

decode_op_hdr returns NFS4ERR_RESOURCE on decode buffer overflow which is correct for v4.0. Will fix the return for v4.1 along with all the other NFS4ERR_RESOURCE overflow errors in a later patch.

---
 fs/nfs/callback_xdr.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
fs/nfs/callback_xdr.c +2 -4
index 8e1a251..e24487d 100644
@@ -605,17 +605,15 @@ static __be32 process_op(uint32_t minorversion, int nop,
 		struct xdr_stream *xdr_out, void *resp)
 {
 	struct callback_op *op = &callback_ops[0];
-	unsigned int op_nr = OP_CB_ILLEGAL;
+	unsigned int op_nr;
 	__be32 status;
 	long maxlen;
 	__be32 res;
 
 	dprintk("%s: start\n", __func__);
 	status = decode_op_hdr(xdr_in, &op_nr);
-	if (unlikely(status)) {
-		status = htonl(NFS4ERR_OP_ILLEGAL);
+	if (unlikely(status))
 		goto out;
-	}
 
 	dprintk("%s: minorversion=%d nop=%d op_nr=%u\n",
 		__func__, minorversion, nop, op_nr);
Signature · 1 line
1.6.5.2
#2 lore raw

PATCH 2/5 nfs41: directly encode back channel error

From: Andy Adamson <[email protected]>

Skip all other processing when error is encountered.

---
 fs/nfs/callback_xdr.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
fs/nfs/callback_xdr.c +6 -3
index e24487d..3637e9a 100644
@@ -613,7 +613,7 @@ static __be32 process_op(uint32_t minorversion, int nop,
 	dprintk("%s: start\n", __func__);
 	status = decode_op_hdr(xdr_in, &op_nr);
 	if (unlikely(status))
-		goto out;
+		goto encode_hdr;
 
 	dprintk("%s: minorversion=%d nop=%d op_nr=%u\n",
 		__func__, minorversion, nop, op_nr);
@@ -622,16 +622,19 @@ static __be32 process_op(uint32_t minorversion, int nop,
 				preprocess_nfs4_op(op_nr, &op);
 	if (status == htonl(NFS4ERR_OP_ILLEGAL))
 		op_nr = OP_CB_ILLEGAL;
-out:
+	if (status)
+		goto encode_hdr;
+
 	maxlen = xdr_out->end - xdr_out->p;
 	if (maxlen > 0 && maxlen < PAGE_SIZE) {
-		if (likely(status == 0 && op->decode_args != NULL))
+		if (likely(op->decode_args != NULL))
 			status = op->decode_args(rqstp, xdr_in, argp);
 		if (likely(status == 0 && op->process_op != NULL))
 			status = op->process_op(argp, resp);
 	} else
 		status = htonl(NFS4ERR_RESOURCE);
 
+encode_hdr:
 	res = encode_op_hdr(xdr_out, op_nr, status);
 	if (status == 0)
 		status = res;
Signature · 1 line
1.6.5.2
#3 lore raw

PATCH 3/5 nfs41: remove uneeded checks in callback processing

From: Andy Adamson <[email protected]>

All callback operations have arguments to decode and require processing. The preprocess_nfs4X_op functions catch unsupported or illegal ops so decode_args and process_op pointers are always non NULL.

---
 fs/nfs/callback_xdr.c |    5 ++---
 1 files changed, 2 insertions(+), 3 deletions(-)
fs/nfs/callback_xdr.c +2 -3
index 3637e9a..c64a174 100644
@@ -627,9 +627,8 @@ static __be32 process_op(uint32_t minorversion, int nop,
 
 	maxlen = xdr_out->end - xdr_out->p;
 	if (maxlen > 0 && maxlen < PAGE_SIZE) {
-		if (likely(op->decode_args != NULL))
-			status = op->decode_args(rqstp, xdr_in, argp);
-		if (likely(status == 0 && op->process_op != NULL))
+		status = op->decode_args(rqstp, xdr_in, argp);
+		if (likely(status == 0))
 			status = op->process_op(argp, resp);
 	} else
 		status = htonl(NFS4ERR_RESOURCE);
Signature · 1 line
1.6.5.2
#4 lore raw

PATCH 4/5 nfs41: prepare for back channel drc

From: Andy Adamson <[email protected]>

Make all cb_sequence arguments available to verify_seqid which will make replay decisions.

---
 fs/nfs/callback_proc.c |   19 +++++++++----------
 1 files changed, 9 insertions(+), 10 deletions(-)
fs/nfs/callback_proc.c +9 -10
index defa9b4..7f92b6d 100644
@@ -153,34 +153,34 @@ int nfs41_validate_delegation_stateid(struct nfs_delegation *delegation, const n
  * a single outstanding callback request at a time.
  */
 static int
-validate_seqid(struct nfs4_slot_table *tbl, u32 slotid, u32 seqid)
+validate_seqid(struct nfs4_slot_table *tbl, struct cb_sequenceargs * args)
 {
 	struct nfs4_slot *slot;
 
 	dprintk("%s enter. slotid %d seqid %d\n",
-		__func__, slotid, seqid);
+		__func__, args->csa_slotid, args->csa_sequenceid);
 
-	if (slotid > NFS41_BC_MAX_CALLBACKS)
+	if (args->csa_slotid > NFS41_BC_MAX_CALLBACKS)
 		return htonl(NFS4ERR_BADSLOT);
 
-	slot = tbl->slots + slotid;
+	slot = tbl->slots + args->csa_slotid;
 	dprintk("%s slot table seqid: %d\n", __func__, slot->seq_nr);
 
 	/* Normal */
-	if (likely(seqid == slot->seq_nr + 1)) {
+	if (likely(args->csa_sequenceid == slot->seq_nr + 1)) {
 		slot->seq_nr++;
 		return htonl(NFS4_OK);
 	}
 
 	/* Replay */
-	if (seqid == slot->seq_nr) {
+	if (args->csa_sequenceid == slot->seq_nr) {
 		dprintk("%s seqid %d is a replay - no DRC available\n",
-			__func__, seqid);
+			__func__, args->csa_sequenceid);
 		return htonl(NFS4_OK);
 	}
 
 	/* Wraparound */
-	if (seqid == 1 && (slot->seq_nr + 1) == 0) {
+	if (args->csa_sequenceid == 1 && (slot->seq_nr + 1) == 0) {
 		slot->seq_nr = 1;
 		return htonl(NFS4_OK);
 	}
@@ -241,8 +241,7 @@ unsigned nfs4_callback_sequence(struct cb_sequenceargs *args,
 	if (clp == NULL)
 		goto out;
 
-	status = validate_seqid(&clp->cl_session->bc_slot_table,
-				args->csa_slotid, args->csa_sequenceid);
+	status = validate_seqid(&clp->cl_session->bc_slot_table, args);
 	if (status)
 		goto out_putclient;
 
Signature · 1 line
1.6.5.2
#5 lore raw

PATCH 5/5 nfs41: back channel drc minimal implementation

From: Andy Adamson <[email protected]>

For now the back channel ca_maxresponsesize_cached is 0 and there is no backchannel DRC. Return NFS4ERR_REP_TOO_BIG_TO_CACHE when a cb_sequence cachethis is true. When it is false, return NFS4ERR_RETRY_UNCACHED_REP as the next operation error.

Remember the replay error accross compound operation processing.

---
 fs/nfs/callback_proc.c |   25 +++++++++++++++++--------
 fs/nfs/callback_xdr.c  |   19 +++++++++++++++----
 2 files changed, 32 insertions(+), 12 deletions(-)
fs/nfs/callback_proc.c +17 -8
index 7f92b6d..3cc2333 100644
@@ -143,9 +143,8 @@ int nfs41_validate_delegation_stateid(struct nfs_delegation *delegation, const n
  * Return success if the sequenceID is one more than what we last saw on
  * this slot, accounting for wraparound.  Increments the slot's sequence.
  *
- * We don't yet implement a duplicate request cache, so at this time
- * we will log replays, and process them as if we had not seen them before,
- * but we don't bump the sequence in the slot.  Not too worried about it,
+ * We don't yet implement a duplicate request cache, instead we set the
+ * back channel ca_maxresponsesize_cached to zero. This is OK for now
  * since we only currently implement idempotent callbacks anyway.
  *
  * We have a single slot backchannel at this time, so we don't bother
@@ -174,9 +173,15 @@ validate_seqid(struct nfs4_slot_table *tbl, struct cb_sequenceargs * args)
 
 	/* Replay */
 	if (args->csa_sequenceid == slot->seq_nr) {
-		dprintk("%s seqid %d is a replay - no DRC available\n",
+		dprintk("%s seqid %d is a replay\n",
 			__func__, args->csa_sequenceid);
-		return htonl(NFS4_OK);
+		/* Signal process_op to set this error on next op */
+		if (args->csa_cachethis == 0)
+			return htonl(NFS4ERR_RETRY_UNCACHED_REP);
+
+		/* The ca_maxresponsesize_cached is 0 with no DRC */
+		else if (args->csa_cachethis == 1)
+			return htonl(NFS4ERR_REP_TOO_BIG_TO_CACHE);
 	}
 
 	/* Wraparound */
@@ -255,9 +260,13 @@ unsigned nfs4_callback_sequence(struct cb_sequenceargs *args,
 out_putclient:
 	nfs_put_client(clp);
 out:
-	dprintk("%s: exit with status = %d\n", __func__, ntohl(status));
-	res->csr_status = status;
-	return res->csr_status;
+	if (status == htonl(NFS4ERR_RETRY_UNCACHED_REP))
+		res->csr_status = 0;
+	else
+		res->csr_status = status;
+	dprintk("%s: exit with status = %d res->csr_status %d\n", __func__,
+		ntohl(status), ntohl(res->csr_status));
+	return status;
 }
 
 unsigned nfs4_callback_recallany(struct cb_recallanyargs *args, void *dummy)
fs/nfs/callback_xdr.c +15 -4
index c64a174..76d082e 100644
@@ -602,7 +602,7 @@ preprocess_nfs4_op(unsigned int op_nr, struct callback_op **op)
 static __be32 process_op(uint32_t minorversion, int nop,
 		struct svc_rqst *rqstp,
 		struct xdr_stream *xdr_in, void *argp,
-		struct xdr_stream *xdr_out, void *resp)
+		struct xdr_stream *xdr_out, void *resp, int* drc_status)
 {
 	struct callback_op *op = &callback_ops[0];
 	unsigned int op_nr;
@@ -625,6 +625,11 @@ static __be32 process_op(uint32_t minorversion, int nop,
 	if (status)
 		goto encode_hdr;
 
+	if (*drc_status) {
+		status = *drc_status;
+		goto encode_hdr;
+	}
+
 	maxlen = xdr_out->end - xdr_out->p;
 	if (maxlen > 0 && maxlen < PAGE_SIZE) {
 		status = op->decode_args(rqstp, xdr_in, argp);
@@ -633,6 +638,12 @@ static __be32 process_op(uint32_t minorversion, int nop,
 	} else
 		status = htonl(NFS4ERR_RESOURCE);
 
+	/* Only set by OP_CB_SEQUENCE processing */
+	if (status == htonl(NFS4ERR_RETRY_UNCACHED_REP)) {
+		*drc_status = status;
+		status = 0;
+	}
+
 encode_hdr:
 	res = encode_op_hdr(xdr_out, op_nr, status);
 	if (status == 0)
@@ -652,7 +663,7 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r
 	struct cb_compound_hdr_res hdr_res = { NULL };
 	struct xdr_stream xdr_in, xdr_out;
 	__be32 *p;
-	__be32 status;
+	__be32 status, drc_status = 0;
 	unsigned int nops = 0;
 
 	dprintk("%s: start\n", __func__);
@@ -672,8 +683,8 @@ static __be32 nfs4_callback_compound(struct svc_rqst *rqstp, void *argp, void *r
 		return rpc_system_err;
 
 	while (status == 0 && nops != hdr_arg.nops) {
-		status = process_op(hdr_arg.minorversion, nops,
-				    rqstp, &xdr_in, argp, &xdr_out, resp);
+		status = process_op(hdr_arg.minorversion, nops, rqstp,
+				    &xdr_in, argp, &xdr_out, resp, &drc_status);
 		nops++;
 	}
 
Signature · 1 line
1.6.5.2
#6 lore raw

Re: [PATCH 2/5] nfs41: directly encode back channel error

In reply to [email protected]
Quoted 34 lines · On Wed, 2010-01-06 at 13:23 -0500, [email protected] wrote:

From: Andy Adamson <[email protected]>

Skip all other processing when error is encountered.

---
 fs/nfs/callback_xdr.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
fs/nfs/callback_xdr.c +5 -3
index e24487d..3637e9a 100644
@@ -613,7 +613,7 @@ static __be32 process_op(uint32_t minorversion, int nop,
 	dprintk("%s: start\n", __func__);
 	status = decode_op_hdr(xdr_in, &op_nr);
 	if (unlikely(status))
-		goto out;
+		goto encode_hdr;
 
 	dprintk("%s: minorversion=%d nop=%d op_nr=%u\n",
 		__func__, minorversion, nop, op_nr);
@@ -622,16 +622,19 @@ static __be32 process_op(uint32_t minorversion, int nop,
 				preprocess_nfs4_op(op_nr, &op);
 	if (status == htonl(NFS4ERR_OP_ILLEGAL))
 		op_nr = OP_CB_ILLEGAL;
-out:
+	if (status)
+		goto encode_hdr;
+
 	maxlen = xdr_out->end - xdr_out->p;
 	if (maxlen > 0 && maxlen < PAGE_SIZE) {
-		if (likely(status == 0 && op->decode_args != NULL))
+		if (likely(op->decode_args != NULL))

fs/nfs/callback_xdr.c static __be32 process_op(uint32_t minorversion, int nop, · line 640

Quoted 10 lines
fs/nfs/callback_xdr.c +1 -0
 			status = op->decode_args(rqstp, xdr_in, argp);
 		if (likely(status == 0 && op->process_op != NULL))
 			status = op->process_op(argp, resp);
 	} else
 		status = htonl(NFS4ERR_RESOURCE);
 
+encode_hdr:
 	res = encode_op_hdr(xdr_out, op_nr, status);
 	if (status == 0)
 		status = res;

Same problem. You have a random value for op_nr...

#7 lore raw

Re: [PATCH 1/5] nfs41: fix wrong error on callback decode hdr overflow

In reply to [email protected]
Quoted 16 lines · On Wed, 2010-01-06 at 13:23 -0500, [email protected] wrote:

From: Andy Adamson <[email protected]>

decode_op_hdr returns NFS4ERR_RESOURCE on decode buffer overflow which is correct for v4.0. Will fix the return for v4.1 along with all the other NFS4ERR_RESOURCE overflow errors in a later patch.

---
 fs/nfs/callback_xdr.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
fs/nfs/callback_xdr.c +0 -0
index 8e1a251..e24487d 100644

fs/nfs/callback_xdr.c static __be32 process_op(uint32_t minorversion, int nop, · line 608

Quoted 5 lines
fs/nfs/callback_xdr.c +1 -1
@@ -605,17 +605,15 @@ static __be32 process_op(uint32_t minorversion, int nop,
 		struct xdr_stream *xdr_out, void *resp)
 {
 	struct callback_op *op = &callback_ops[0];
-	unsigned int op_nr = OP_CB_ILLEGAL;
+	unsigned int op_nr;

This will cause us to return a random op number in the case where the buffer overflows.

Quoted 4 lines
fs/nfs/callback_xdr.c +0 -0
 	__be32 status;
 	long maxlen;
 	__be32 res;
 

fs/nfs/callback_xdr.c static __be32 process_op(uint32_t minorversion, int nop, · line 619

Quoted 10 lines
fs/nfs/callback_xdr.c +1 -3
 	dprintk("%s: start\n", __func__);
 	status = decode_op_hdr(xdr_in, &op_nr);
-	if (unlikely(status)) {
-		status = htonl(NFS4ERR_OP_ILLEGAL);
+	if (unlikely(status))
 		goto out;
-	}
 
 	dprintk("%s: minorversion=%d nop=%d op_nr=%u\n",
 		__func__, minorversion, nop, op_nr);

The correct thing to do would appear to be rather to set NFS4ERR_RESOURCE in the CB_COMPOUND return value, and simply not to return an op here at all.

Trond

#8 lore raw

Re: [PATCH 1/5] nfs41: fix wrong error on callback decode hdr overflow

Quoted 12 lines · Trond Myklebust
Quoted 11 lines · On Wed, 2010-01-06 at 13:23 -0500, [email protected] wrote:

From: Andy Adamson <[email protected]>

decode_op_hdr returns NFS4ERR_RESOURCE on decode buffer overflow which is correct for v4.0. Will fix the return for v4.1 along with all the other NFS4ERR_RESOURCE overflow errors in a later patch.

---
fs/nfs/callback_xdr.c | 6 ++----

1 files changed, 2 insertions(+), 4 deletions(-)
Quoted 14 lines

fs/nfs/callback_xdr.c static __be32 process_op(uint32_t · line 609

Quoted 11 lines
fs/nfs/callback_xdr.c +1 -1
index 8e1a251..e24487d 100644
@@ -605,17 +605,15 @@ static __be32 process_op(uint32_t  
 minorversion, int nop,
 		struct xdr_stream *xdr_out, void *resp)
 {
 	struct callback_op *op = &callback_ops[0];
-	unsigned int op_nr = OP_CB_ILLEGAL;
+	unsigned int op_nr;

This will cause us to return a random op number in the case where the buffer overflows.

yes - good catch.

Quoted 13 lines
Quoted 13 lines
fs/nfs/callback_xdr.c +1 -3
 	__be32 status;
 	long maxlen;
 	__be32 res;
 
 	dprintk("%s: start\n", __func__);
 	status = decode_op_hdr(xdr_in, &op_nr);
-	if (unlikely(status)) {
-		status = htonl(NFS4ERR_OP_ILLEGAL);
+	if (unlikely(status))
 		goto out;
-	}
 
Quoted 6 lines
Quoted 2 lines
fs/nfs/callback_xdr.c +0 -0
 	dprintk("%s: minorversion=%d nop=%d op_nr=%u\n",
		__func__, minorversion, nop, op_nr);

The correct thing to do would appear to be rather to set NFS4ERR_RESOURCE in the CB_COMPOUND return value, and simply not to return an op here at all.

Agreed.

-->Andy

Quoted 2 lines

Trond