Skip to contentSkip to conversation

NFSv4.1: sp4_mach_cred cleanup

PATCH In review Weston Andros Adamson 3 participants 6 messages Sep 10, 2013

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

cover NFSv4.1: sp4_mach_cred cleanup

These two patches do some final cleanup of SP4_MACH_CRED:
- actually call put_rpccred() if we get_rpccred(clp->cl_machine_cred)
- advertise to server that we support WRITE and COMMIT

Tested against a linux nfsd hacked to "support" sp4_mach_cred for the client supported ops. Also tested building with v4.1 disabled and v4 disabled.

Trond - it's (obviously) up to you if these get in during this merge window. I think they're pretty straightforward. Also, these patches are independent from eachother, so it's ok to select one but not the other.

Weston Andros Adamson (2):
NFSv4.1: clean up after using machine cred NFSv4.1: sp4_mach_cred: ask for WRITE and COMMIT

 fs/nfs/nfs4_fs.h  | 58 ++++++++++++++++++++++++++++++++++++-------------------
 fs/nfs/nfs4proc.c | 58 +++++++++++++++++++++++++++++++++++++------------------
 fs/nfs/write.c    | 18 +++++++++++------
 3 files changed, 89 insertions(+), 45 deletions(-)
Signature · 1 line
1.7.12.4 (Apple Git-37)
#1 lore raw

PATCH 1/2 NFSv4.1: clean up after using machine cred

Client calls get_rpccred when referencing the machine cred, so it must call put_rpccred after passing cred to rpc layer.

This patch also moves nfs4_sp4_init (formerly nfs4_state_protect) to right before the call to rpc_run_task (and wrappers of rpc_run_task) to minimize error path cleanup code.

---
 fs/nfs/nfs4_fs.h  | 58 ++++++++++++++++++++++++++++++++++++-------------------
 fs/nfs/nfs4proc.c | 52 +++++++++++++++++++++++++++++++++----------------
 fs/nfs/write.c    | 18 +++++++++++------
 3 files changed, 85 insertions(+), 43 deletions(-)
fs/nfs/nfs4_fs.h +38 -20
index f520a11..63e3936 100644
@@ -269,9 +269,10 @@ is_ds_client(struct nfs_client *clp)
 	return clp->cl_exchange_flags & EXCHGID4_FLAG_USE_PNFS_DS;
 }
 
-static inline bool
-_nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
-		    struct rpc_clnt **clntp, struct rpc_message *msg)
+static inline void
+_nfs4_sp4_init(struct nfs_client *clp, unsigned long sp4_mode,
+	       struct rpc_clnt **clntp, struct rpc_message *msg,
+	       bool *did_sp4)
 {
 	struct rpc_cred *newcred = NULL;
 	rpc_authflavor_t flavor;
@@ -290,9 +291,9 @@ _nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
 			flavor != RPC_AUTH_GSS_KRB5P);
 		*clntp = clp->cl_rpcclient;
 
-		return true;
-	}
-	return false;
+		*did_sp4 = true;
+	} else
+		*did_sp4 = false;
 }
 
 /*
@@ -302,25 +303,34 @@ _nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
  * Should be called before rpc_call_sync/rpc_call_async.
  */
 static inline void
-nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_mode,
-		   struct rpc_clnt **clntp, struct rpc_message *msg)
+nfs4_sp4_init(struct nfs_client *clp, unsigned long sp4_mode,
+	      struct rpc_clnt **clntp, struct rpc_message *msg,
+	      bool *did_sp4)
 {
-	_nfs4_state_protect(clp, sp4_mode, clntp, msg);
+	_nfs4_sp4_init(clp, sp4_mode, clntp, msg, did_sp4);
 }
 
 /*
- * Special wrapper to nfs4_state_protect for write.
+ * Special wrapper to nfs4_sp4_init for write.
  * If WRITE can use machine cred but COMMIT cannot, make sure all writes
  * that use machine cred use NFS_FILE_SYNC.
  */
 static inline void
-nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
-			 struct rpc_message *msg, struct nfs_write_data *wdata)
+nfs4_sp4_write_init(struct nfs_client *clp, struct rpc_clnt **clntp,
+		    struct rpc_message *msg, struct nfs_write_data *wdata,
+		    bool *did_sp4)
 {
-	if (_nfs4_state_protect(clp, NFS_SP4_MACH_CRED_WRITE, clntp, msg) &&
-	    !test_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags))
+	_nfs4_sp4_init(clp, NFS_SP4_MACH_CRED_WRITE, clntp, msg, did_sp4);
+	if (*did_sp4 && !test_bit(NFS_SP4_MACH_CRED_COMMIT, &clp->cl_sp4_flags))
 		wdata->args.stable = NFS_FILE_SYNC;
 }
+
+static inline void
+nfs4_sp4_cleanup(struct rpc_message *msg, bool did_sp4)
+{
+	if (did_sp4)
+		put_rpccred(msg->rpc_cred);
+}
 #else /* CONFIG_NFS_v4_1 */
 static inline struct nfs4_session *nfs4_get_session(const struct nfs_server *server)
 {
@@ -340,14 +350,20 @@ is_ds_client(struct nfs_client *clp)
 }
 
 static inline void
-nfs4_state_protect(struct nfs_client *clp, unsigned long sp4_flags,
-		   struct rpc_clnt **clntp, struct rpc_message *msg)
+nfs4_sp4_init(struct nfs_client *clp, unsigned long sp4_flags,
+	      struct rpc_clnt **clntp, struct rpc_message *msg, bool *did_sp4)
+{
+}
+
+static inline void
+nfs4_sp4_write_init(struct nfs_client *clp, struct rpc_clnt **clntp,
+		    struct rpc_message *msg, struct nfs_write_data *wdata,
+		    bool *did_sp4)
 {
 }
 
 static inline void
-nfs4_state_protect_write(struct nfs_client *clp, struct rpc_clnt **clntp,
-			 struct rpc_message *msg, struct nfs_write_data *wdata)
+nfs4_sp4_cleanup(struct rpc_message *msg, bool did_sp4)
 {
 }
 #endif /* CONFIG_NFS_V4_1 */
@@ -485,8 +501,10 @@ static inline bool nfs4_valid_open_stateid(const struct nfs4_state *state)
 
 #define nfs4_close_state(a, b) do { } while (0)
 #define nfs4_close_sync(a, b) do { } while (0)
-#define nfs4_state_protect(a, b, c, d) do { } while (0)
-#define nfs4_state_protect_write(a, b, c, d) do { } while (0)
+/* nfs4_sp4_*_init sets bool "did_sp4" to avoid warning */
+#define nfs4_sp4_init(a, b, c, d, e) (*e = false)
+#define nfs4_sp4_write_init(a, b, c, d, e) (*e = false)
+#define nfs4_sp4_cleanup(a, b) do { } while (0)
 
 #endif /* CONFIG_NFS_V4 */
 #endif /* __LINUX_FS_NFS_NFS4_FS.H */
fs/nfs/nfs4proc.c +35 -17

115 lines not on this page · raw message

fs/nfs/write.c +12 -6
index ac1dc33..da306c0 100644
@@ -1010,6 +1010,7 @@ int nfs_initiate_write(struct rpc_clnt *clnt,
 		.priority = priority,
 	};
 	int ret = 0;
+	bool did_sp4;
 
 	/* Set up the initial task struct.  */
 	NFS_PROTO(inode)->write_setup(data, &msg);
@@ -1022,10 +1023,11 @@ int nfs_initiate_write(struct rpc_clnt *clnt,
 		data->args.count,
 		(unsigned long long)data->args.offset);
 
-	nfs4_state_protect_write(NFS_SERVER(inode)->nfs_client,
-				 &task_setup_data.rpc_client, &msg, data);
-
+	nfs4_sp4_write_init(NFS_SERVER(inode)->nfs_client,
+			    &task_setup_data.rpc_client, &msg, data, &did_sp4);
 	task = rpc_run_task(&task_setup_data);
+	nfs4_sp4_cleanup(&msg, did_sp4);
+
 	if (IS_ERR(task)) {
 		ret = PTR_ERR(task);
 		goto out;
@@ -1486,15 +1488,19 @@ int nfs_initiate_commit(struct rpc_clnt *clnt, struct nfs_commit_data *data,
 		.flags = RPC_TASK_ASYNC | flags,
 		.priority = priority,
 	};
+	bool did_sp4;
+
 	/* Set up the initial task struct.  */
 	NFS_PROTO(data->inode)->commit_setup(data, &msg);
 
 	dprintk("NFS: %5u initiated commit call\n", data->task.tk_pid);
 
-	nfs4_state_protect(NFS_SERVER(data->inode)->nfs_client,
-		NFS_SP4_MACH_CRED_COMMIT, &task_setup_data.rpc_client, &msg);
-
+	nfs4_sp4_init(NFS_SERVER(data->inode)->nfs_client,
+		NFS_SP4_MACH_CRED_COMMIT, &task_setup_data.rpc_client, &msg,
+		&did_sp4);
 	task = rpc_run_task(&task_setup_data);
+	nfs4_sp4_cleanup(&msg, did_sp4);
+
 	if (IS_ERR(task))
 		return PTR_ERR(task);
 	if (how & FLUSH_SYNC)
Signature · 1 line
1.7.12.4 (Apple Git-37)
#2 lore raw

Re: [PATCH 1/2] NFSv4.1: clean up after using machine cred

T24gVHVlLCAyMDEzLTA5LTEwIGF0IDE0OjU1IC0wNDAwLCBXZXN0b24gQW5kcm9zIEFkYW1zb24g d3JvdGU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bmQgTXlrbGVidXN0 DQpMaW51eCBORlMgY2xpZW50IG1haW50YWluZXINCg0KTmV0QXBwDQpUcm9uZC5NeWtsZWJ1c3RA bmV0YXBwLmNvbQ0Kd3d3Lm5ldGFwcC5jb20NCg==

#3 lore raw

Re: [PATCH 1/2] NFSv4.1: clean up after using machine cred

Yes, I thought about this approach, but backed away since we do get/put_rpccred on the cl_machine_cred elsewhere (like nfs4_get_machine_cred_locked).

Shall I submit a new patch that gets rid of get/put_rpccred?

Do we also want to change other uses of cl_machine_cred?

Thanks,
-dros

Quoted 26 lines · Trond
Quoted 7 lines · Weston Andros Adamson

Client calls get_rpccred when referencing the machine cred, so it must call put_rpccred after passing cred to rpc layer.

This patch also moves nfs4_sp4_init (formerly nfs4_state_protect) to right before the call to rpc_run_task (and wrappers of rpc_run_task) to minimize error path cleanup code.

Do we really need this? AFAICS once the clp->cl_machine_cred is set, it isn't freed until the call to nfs_free_client(). In fact, we probably _rely_ on this being the case for SP4_MACH_CRED, since if the machine cred were to change, we'd no longer be able to change our session or lease.

IOW: instead of referencing the cred via get/put_rpccred(), maybe we can just feed the current value of clp->cl_machine_cred into the msg->rpc_cred.

Signature · 6 lines
Trond Myklebust
Linux NFS client maintainer

NetApp
[email protected]
www.netapp.com
#4 lore raw

Re: [PATCH 1/2] NFSv4.1: clean up after using machine cred

T24gVHVlLCAyMDEzLTA5LTEwIGF0IDIxOjA4ICswMDAwLCBBZGFtc29uLCBEcm9zIHdyb3RlOg0K PiBZZXMsIEkgdGhvdWdodCBhYm91dCB0aGlzIGFwcHJvYWNoLCBidXQgYmFja2VkIGF3YXkgc2lu Y2Ugd2UgZG8gZ2V0L3B1dF9ycGNjcmVkIG9uIHRoZSBjbF9tYWNoaW5lX2NyZWQgZWxzZXdoZXJl IChsaWtlIG5mczRfZ2V0X21hY2hpbmVfY3JlZF9sb2NrZWQpLg0KPiANCj4gU2hhbGwgSSBzdWJt aXQgYSBuZXcgcGF0Y2ggdGhhdCBnZXRzIHJpZC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XNuJ3QgZnJlZWQgdW50aWwgdGhlIGNhbGwgdG8gbmZzX2ZyZWVfY2xp ZW50KCkuIEluIGZhY3QsIHdlIHByb2JhYmx5DQo+ID4gX3JlbHlfIG9uIHRoaXMgYmVpbmcgdGhl IGNhc2UgZm9yIFNQNF9NQUNIX0NSRUQsIHNpbmNlIGlmIHRoZSBtYWNoaW5lDQo+ID4gY3JlZCB3 ZXJlIHRvIGNoYW5nZSwgd2UnZCBubyBsb25nZXIgYmUgYWJsZSB0byBjaGFuZ2Ugb3VyIHNlc3Np b24gb3INCj4gPiBsZWFzZS4NCj4gPiANCj4gPiBJT1c6IGluc3RlYWQgb2YgcmVmZXJlbmNpbmcg dGhlIGNyZWQgdmlhIGdldC9wdXRfcnBjY3JlZCgpLCBtYXliZSB3ZSBjYW4NCj4gPiBqdXN0IGZl ZWQgdGhlIGN1cnJlbnQgdmFsdWUgb2YgY2xwLT5jbF9tYWNoaW5lX2NyZWQgaW50byB0aGUNCj4g PiBtc2ctPnJwY19jcmVkLg0KPiA+IA0KPiA+IC0tIA0KPiA+IFRyb25kIE15a2xlYnVzdA0KPiA+ IExpbnV4IE5GUyBjbGllbnQgbWFpbnRhaW5lcg0KPiA+IA0KPiA+IE5ldEFwcA0KPiA+IFRyb25k Lk15a2xlYnVzdEBuZXRhcHAuY29tDQo+ID4gd3d3Lm5ldGFwcC5jb20NCj4gDQoNCi0tIA0KVHJv bmQgTXlrbGVidXN0DQpMaW51eCBORlMgY2xpZW50IG1haW50YWluZXINCg0KTmV0QXBwDQpUcm9u ZC5NeWtsZWJ1c3RAbmV0YXBwLmNvbQ0Kd3d3Lm5ldGFwcC5jb20NCg==

#5 lore raw

PATCH 2/2 NFSv4.1: sp4_mach_cred: ask for WRITE and COMMIT

In reply to Weston Andros Adamson

Request SP4_MACH_CRED WRITE and COMMIT support in spo_must_allow list -- they're already supported by the client.

---
 fs/nfs/nfs4proc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/nfs/nfs4proc.c +4 -2
index ee0d1eb..10feb7b 100644
@@ -6162,11 +6162,13 @@ static const struct nfs41_state_protection nfs4_sp4_mach_cred_request = {
 	},
 	.allow.u.words = {
 		[0] = 1 << (OP_CLOSE) |
-		      1 << (OP_LOCKU),
+		      1 << (OP_LOCKU) |
+		      1 << (OP_COMMIT),
 		[1] = 1 << (OP_SECINFO - 32) |
 		      1 << (OP_SECINFO_NO_NAME - 32) |
 		      1 << (OP_TEST_STATEID - 32) |
-		      1 << (OP_FREE_STATEID - 32)
+		      1 << (OP_FREE_STATEID - 32) |
+		      1 << (OP_WRITE - 32)
 	}
 };
 
Signature · 1 line
1.7.12.4 (Apple Git-37)