Skip to contentSkip to conversation

NFSD: Clean up the test_stateid function

PATCH Superseded [email protected] 2 participants 3 messages Jan 25, 2012 – Jan 26, 2012

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NFSD: Clean up the test_stateid function

From: Bryan Schumaker <[email protected]>

When I initially wrote it, I didn't understand how lists worked so I wrote something that didn't use them. I think making a list of stateids to test is a more straightforward implementation, especially compared to especially compared to decoding stateids while simultaneously encoding a reply to the client.

---
 fs/nfsd/nfs4state.c |    9 ++++++-
 fs/nfsd/nfs4xdr.c   |   70 +++++++++++++++++---------------------------------
 fs/nfsd/xdr4.h      |    9 +++++-
 3 files changed, 39 insertions(+), 49 deletions(-)
fs/nfsd/nfs4state.c +8 -1
index e8c98f0..c59a3f6 100644
@@ -3400,7 +3400,14 @@ __be32
 nfsd4_test_stateid(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 		   struct nfsd4_test_stateid *test_stateid)
 {
-	/* real work is done during encoding */
+	struct nfsd4_test_stateid_id *stateid;
+	struct nfs4_client *cl = cstate->session->se_client;
+
+	nfs4_lock_state();
+	list_for_each_entry(stateid, &test_stateid->ts_stateid_list, ts_id_list)
+		stateid->ts_id_status = nfs4_validate_stateid(cl, &stateid->ts_id_stateid);
+	nfs4_unlock_state();
+
 	return nfs_ok;
 }
 
fs/nfsd/nfs4xdr.c +24 -46

107 lines not on this page · raw message

fs/nfsd/xdr4.h +7 -2
index 2364747..0a667e9 100644
@@ -343,10 +343,15 @@ struct nfsd4_saved_compoundargs {
 	struct page **pagelist;
 };
 
+struct nfsd4_test_stateid_id {
+	__be32			ts_id_status;
+	stateid_t		ts_id_stateid;
+	struct list_head	ts_id_list;
+};
+
 struct nfsd4_test_stateid {
 	__be32		ts_num_ids;
-	struct nfsd4_compoundargs *ts_saved_args;
-	struct nfsd4_saved_compoundargs ts_savedp;
+	struct list_head ts_stateid_list;
 };
 
 struct nfsd4_free_stateid {
Signature · 1 line
1.7.8.4
#1 lore raw
Quoted 7 lines · On Wed, Jan 25, 2012 at 11:48:15AM -0500, [email protected] wrote:

From: Bryan Schumaker <[email protected]>

When I initially wrote it, I didn't understand how lists worked so I wrote something that didn't use them. I think making a list of stateids to test is a more straightforward implementation, especially compared to especially compared to decoding stateids while simultaneously encoding a reply to the client.

Thanks, yes, I'll be much happier with something like this. The only thing I'm worried about:

Quoted 19 lines

static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes) {

fs/nfsd/nfs4xdr.c +2 -5
 	/* We want more bytes than seem to be available.
@@ -1385,31 +1369,36 @@ nfsd4_decode_sequence(struct nfsd4_compoundargs *argp,
 static __be32
 nfsd4_decode_test_stateid(struct nfsd4_compoundargs *argp, struct nfsd4_test_stateid *test_stateid)
 {
-	unsigned int nbytes;
-	stateid_t si;
 	int i;
-	__be32 *p;
-	__be32 status;
+	__be32 *p, status;
+	struct nfsd4_test_stateid_id *stateid;
 
 	READ_BUF(4);
 	test_stateid->ts_num_ids = ntohl(*p++);
 
-	nbytes = test_stateid->ts_num_ids * sizeof(stateid_t);

fs/nfsd/nfs4xdr.c nfsd4_decode_sequence(struct nfsd4_compoundargs *argp, · line 1382

Quoted 10 lines
fs/nfsd/nfs4xdr.c +2 -6
-	if (nbytes > (u32)((char *)argp->end - (char *)argp->p))
-		goto xdr_error;
-
-	test_stateid->ts_saved_args = argp;
-	save_buf(argp, &test_stateid->ts_savedp);
+	INIT_LIST_HEAD(&test_stateid->ts_stateid_list);
 
 	for (i = 0; i < test_stateid->ts_num_ids; i++) {
-		status = nfsd4_decode_stateid(argp, &si);
+		stateid = kmalloc(sizeof(struct nfsd4_test_stateid_id), GFP_KERNEL);

Hm, are you sure this will always get freed in all cases?

Off the top of my head: the compound gets decode in one fell swoop. The we process and encode each op one at a time. So, for example, if we fail later in the decoding, or if processing fails on an earlier op than this one, then we're not going to hit the free in the encoder:

Quoted 3 lines
fs/nfsd/nfs4xdr.c +0 -0
 nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, int nfserr,
 			  struct nfsd4_test_stateid *test_stateid)
 {

...

fs/nfsd/nfs4xdr.c __be32 · line 3392

Quoted 4 lines
fs/nfsd/nfs4xdr.c +4 -0
+	list_for_each_entry_safe(stateid, next, &test_stateid->ts_stateid_list, ts_id_list) {
+		*p++ = htonl(stateid->ts_id_status);
+		list_del(&stateid->ts_id_list);
+		kfree(stateid);

Hence the defer_free/release_compoundargs stuff. If you grep through nfs4xdr.c for defer_free I think you'll see how it works.

--b.

#2 lore raw
Quoted 52 lines · J. Bruce Fields
Quoted 7 lines · On Wed, Jan 25, 2012 at 11:48:15AM -0500, [email protected] wrote:

From: Bryan Schumaker <[email protected]>

When I initially wrote it, I didn't understand how lists worked so I wrote something that didn't use them. I think making a list of stateids to test is a more straightforward implementation, especially compared to especially compared to decoding stateids while simultaneously encoding a reply to the client.

Thanks, yes, I'll be much happier with something like this. The only thing I'm worried about:

Quoted 19 lines

static __be32 *read_buf(struct nfsd4_compoundargs *argp, u32 nbytes) {

fs/nfsd/nfs4xdr.c +2 -5
 	/* We want more bytes than seem to be available.
@@ -1385,31 +1369,36 @@ nfsd4_decode_sequence(struct nfsd4_compoundargs *argp,
 static __be32
 nfsd4_decode_test_stateid(struct nfsd4_compoundargs *argp, struct nfsd4_test_stateid *test_stateid)
 {
-	unsigned int nbytes;
-	stateid_t si;
 	int i;
-	__be32 *p;
-	__be32 status;
+	__be32 *p, status;
+	struct nfsd4_test_stateid_id *stateid;
 
 	READ_BUF(4);
 	test_stateid->ts_num_ids = ntohl(*p++);
 
-	nbytes = test_stateid->ts_num_ids * sizeof(stateid_t);

fs/nfsd/nfs4xdr.c nfsd4_decode_sequence(struct nfsd4_compoundargs *argp, · line 1382

Quoted 10 lines
fs/nfsd/nfs4xdr.c +2 -6
-	if (nbytes > (u32)((char *)argp->end - (char *)argp->p))
-		goto xdr_error;
-
-	test_stateid->ts_saved_args = argp;
-	save_buf(argp, &test_stateid->ts_savedp);
+	INIT_LIST_HEAD(&test_stateid->ts_stateid_list);
 
 	for (i = 0; i < test_stateid->ts_num_ids; i++) {
-		status = nfsd4_decode_stateid(argp, &si);
+		stateid = kmalloc(sizeof(struct nfsd4_test_stateid_id), GFP_KERNEL);

Hm, are you sure this will always get freed in all cases?

Off the top of my head: the compound gets decode in one fell swoop. The we process and encode each op one at a time. So, for example, if we fail later in the decoding, or if processing fails on an earlier op than this one, then we're not going to hit the free in the encoder:

fs/nfsd/nfs4xdr.c __be32 · line 3382

Quoted 3 lines
fs/nfsd/nfs4xdr.c +0 -0
 nfsd4_encode_test_stateid(struct nfsd4_compoundres *resp, int nfserr,
 			  struct nfsd4_test_stateid *test_stateid)
 {
Quoted 8 lines

...

fs/nfsd/nfs4xdr.c __be32 · line 3392

Quoted 4 lines
fs/nfsd/nfs4xdr.c +4 -0
+	list_for_each_entry_safe(stateid, next, &test_stateid->ts_stateid_list, ts_id_list) {
+		*p++ = htonl(stateid->ts_id_status);
+		list_del(&stateid->ts_id_list);
+		kfree(stateid);

Hence the defer_free/release_compoundargs stuff. If you grep through nfs4xdr.c for defer_free I think you'll see how it works.

I'll take a look, thanks! I didn't know about the defer_free option, but using it makes sense here. I'll fix up the patches and send a new version.

- Bryan

Quoted 6 lines

--b.
--
To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html