All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] NFSv4: Servers should only check SETATTR stateid open mode on size change
@ 2013-04-29 15:15 Trond Myklebust
  2013-04-29 15:15 ` [PATCH 2/2] NFSv4: Warn once about servers that incorrectly apply open mode to setattr Trond Myklebust
  2013-04-29 18:15 ` [PATCH 1/2] NFSv4: Servers should only check SETATTR stateid open mode on size change Myklebust, Trond
  0 siblings, 2 replies; 11+ messages in thread
From: Trond Myklebust @ 2013-04-29 15:15 UTC (permalink / raw)
  To: linux-nfs

The NFSv4 and NFSv4.1 specs are both clear that the server should only check
stateid open mode if a SETATTR specifies the size attribute. If the
open mode is not one that allows writing, then it returns NFS4ERR_OPENMODE.

In the case where the SETATTR is not changing the size, the client will
still pass it the delegation stateid to ensure that the server does not
recall that delegation. In that case, the server should _ignore_ the
delegation open mode, and simply apply standard permission checks.

Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
---
 fs/nfs/nfs4proc.c | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 3bc847c..982b452 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -2142,20 +2142,25 @@ static int _nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
 		.rpc_cred	= cred,
         };
 	unsigned long timestamp = jiffies;
+	fmode_t fmode;
+	bool truncate;
 	int status;
 
 	nfs_fattr_init(fattr);
 
-	if (state != NULL && nfs4_valid_open_stateid(state)) {
+	/* Servers should only apply open mode checks for file size changes */
+	truncate = (sattr->ia_valid & ATTR_SIZE) ? true : false;
+	fmode = truncate ? FMODE_WRITE : FMODE_READ;
+
+	if (nfs4_copy_delegation_stateid(&arg.stateid, inode, fmode)) {
+		/* Use that stateid */
+	} else if (truncate && state != NULL && nfs4_valid_open_stateid(state)) {
 		struct nfs_lockowner lockowner = {
 			.l_owner = current->files,
 			.l_pid = current->tgid,
 		};
 		nfs4_select_rw_stateid(&arg.stateid, state, FMODE_WRITE,
 				&lockowner);
-	} else if (nfs4_copy_delegation_stateid(&arg.stateid, inode,
-				FMODE_WRITE)) {
-		/* Use that stateid */
 	} else
 		nfs4_stateid_copy(&arg.stateid, &zero_stateid);
 
-- 
1.8.1.4


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-04-29 19:16 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-29 15:15 [PATCH 1/2] NFSv4: Servers should only check SETATTR stateid open mode on size change Trond Myklebust
2013-04-29 15:15 ` [PATCH 2/2] NFSv4: Warn once about servers that incorrectly apply open mode to setattr Trond Myklebust
2013-04-29 18:15 ` [PATCH 1/2] NFSv4: Servers should only check SETATTR stateid open mode on size change Myklebust, Trond
2013-04-29 18:21   ` J. Bruce Fields
2013-04-29 18:27     ` Myklebust, Trond
2013-04-29 18:29       ` J. Bruce Fields
2013-04-29 18:33         ` Myklebust, Trond
2013-04-29 18:41           ` J. Bruce Fields
2013-04-29 19:09             ` Myklebust, Trond
2013-04-29 19:16               ` J. Bruce Fields
2013-04-29 18:28     ` J. Bruce Fields

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.