linux-nfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nadav Shemer <nadav@tonian.com>
To: Trond.Myklebust@netapp.com
Cc: linux-nfs@vger.kernel.org
Subject: [PATCH] NFSv4: fix open(O_RDONLY|O_TRUNC) returning EBADF
Date: Tue,  9 Jul 2013 19:16:45 +0300	[thread overview]
Message-ID: <1373386605-18684-1-git-send-email-nadav@tonian.com> (raw)

Move ATTR_OPEN handling from nfs4_proc_setattr into nfs4_do_setattr

Signed-off-by: Nadav Shemer <nadav@tonian.com>
---
Hello.

I've come across an oddity while testing filesystem coverage
My test creates a non-empty file without write permissions and tries to open it with O_RDONLY|O_TRUNC
It expects EACCES (and gets that for local filesystems and NFSv3) but gets EBADF on NFSv4 (and v4.1)

I found some history on this: In a previous kernel it would just hang due to mishandling the NFS4ERR_OPENMODE exception
http://www.spinics.net/lists/linux-nfs/msg28881.html

A fix for this was introduced (it specifically tests for NFS4ERR_OPENMODE and returns EACCES for the open() case, EBADF otherwise)
http://www.spinics.net/linux/fedora/fedora-kernel/msg03736.html
but another patch was also introduced in the same set which seems to break it (it optimizes away the time modification and removes ATTR_OPEN in nfs4_proc_setattr)
http://www.spinics.net/linux/fedora/fedora-kernel/msg03732.html

By moving the 'Deal with open(O_TRUNC)' bit inside (into nfs4_do_setattr), I got it working again (with no other functional change, as far as I can see)

 fs/nfs/nfs4proc.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 8fbc100..17b9f32 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -2180,6 +2180,10 @@ static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
 		.inode = inode,
 	};
 	int err;
+	int is_o_trunc = sattr->ia_valid & ATTR_OPEN;
+	/* Deal with open(O_TRUNC) */
+	if (sattr->ia_valid & ATTR_OPEN)
+		sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN);
 	do {
 		err = _nfs4_do_setattr(inode, cred, fattr, sattr, state);
 		switch (err) {
@@ -2193,7 +2197,7 @@ static int nfs4_do_setattr(struct inode *inode, struct rpc_cred *cred,
 			}
 			if (state && !(state->state & FMODE_WRITE)) {
 				err = -EBADF;
-				if (sattr->ia_valid & ATTR_OPEN)
+				if (is_o_trunc)
 					err = -EACCES;
 				goto out;
 			}
@@ -2774,10 +2778,6 @@ nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
 
 	nfs_fattr_init(fattr);
 	
-	/* Deal with open(O_TRUNC) */
-	if (sattr->ia_valid & ATTR_OPEN)
-		sattr->ia_valid &= ~(ATTR_MTIME|ATTR_CTIME|ATTR_OPEN);
-
 	/* Optimization: if the end result is no change, don't RPC */
 	if ((sattr->ia_valid & ~(ATTR_FILE)) == 0)
 		return 0;
-- 
1.7.11.7


             reply	other threads:[~2013-07-09 16:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-09 16:16 Nadav Shemer [this message]
2013-07-11 14:49 ` [PATCH] NFSv4: fix open(O_RDONLY|O_TRUNC) returning EBADF Jeff Layton
2013-07-19 14:21   ` Jeff Layton
2013-07-21 14:23     ` Nadav Shemer
2013-07-21 14:21       ` [PATCH V2] nfs: fix open(O_RDONLY|O_TRUNC) in NFS4.0 Nadav Shemer
2013-07-22 10:41         ` Jeff Layton

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1373386605-18684-1-git-send-email-nadav@tonian.com \
    --to=nadav@tonian.com \
    --cc=Trond.Myklebust@netapp.com \
    --cc=linux-nfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).