From: "J. Bruce Fields" <bfields@redhat.com>
To: linux-nfs@vger.kernel.org
Cc: "J. Bruce Fields" <bfields@redhat.com>
Subject: [PATCH 5/5] nfsd: clean up nfsd_mode_check()
Date: Mon, 15 Aug 2011 18:30:32 -0400 [thread overview]
Message-ID: <1313447432-1537-5-git-send-email-bfields@redhat.com> (raw)
In-Reply-To: <20110815222859.GD32181@fieldses.org>
Add some more comments, simplify logic, do & S_IFMT just once, name
"type" more helpfully.
Signed-off-by: J. Bruce Fields <bfields@redhat.com>
---
fs/nfsd/nfsfh.c | 52 +++++++++++++++++++++++++++++-----------------------
1 files changed, 29 insertions(+), 23 deletions(-)
diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
index dc0f9ff..b4fd50e 100644
--- a/fs/nfsd/nfsfh.c
+++ b/fs/nfsd/nfsfh.c
@@ -59,30 +59,36 @@ static int nfsd_acceptable(void *expv, struct dentry *dentry)
* the write call).
*/
static inline __be32
-nfsd_mode_check(struct svc_rqst *rqstp, umode_t mode, int type)
+nfsd_mode_check(struct svc_rqst *rqstp, umode_t mode, int requested)
{
- if (type > 0 && (mode & S_IFMT) != type) {
- if (rqstp->rq_vers == 4 && (mode & S_IFMT) == S_IFLNK)
- return nfserr_symlink;
- else if (type == S_IFDIR)
- return nfserr_notdir;
- else if ((mode & S_IFMT) == S_IFDIR)
- return nfserr_isdir;
- /*
- * err_symlink is our catch-all error in the v4 case; this
- * looks odd, but:
- * - the comment next to ERR_SYMLINK in file is
- * "should be file/directory"
- * - we happen to know this will cause the linux v4
- * client to do the right thing on attempts to open
- * something other than a regular file:
- */
- else if (rqstp->rq_vers == 4)
- return nfserr_symlink;
- else
- return nfserr_inval;
- }
- return 0;
+ mode &= S_IFMT;
+
+ if (requested == 0) /* the caller doesn't care */
+ return 0;
+ if (mode == requested)
+ return 0;
+ /*
+ * v4 has an error more specific than err_notdir which we should
+ * return in preference to err_notdir:
+ */
+ if (rqstp->rq_vers == 4 && mode == S_IFLNK)
+ return nfserr_symlink;
+ if (requested == S_IFDIR)
+ return nfserr_notdir;
+ if (mode == S_IFDIR)
+ return nfserr_isdir;
+ /*
+ * err_symlink is our catch-all error in the v4 case; this
+ * looks odd, but:
+ * - the comment next to ERR_SYMLINK in file is
+ * "should be file/directory"
+ * - we happen to know this will cause the linux v4
+ * client to do the right thing on attempts to open
+ * something other than a regular file:
+ */
+ if (rqstp->rq_vers == 4)
+ return nfserr_symlink;
+ return nfserr_inval;
}
static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
--
1.7.4.1
next prev parent reply other threads:[~2011-08-15 22:30 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-08-15 15:36 open() of device special files J. Bruce Fields
2011-08-15 16:03 ` Myklebust, Trond
2011-08-15 21:25 ` J. Bruce Fields
2011-08-15 22:23 ` J. Bruce Fields
2011-08-15 22:27 ` J. Bruce Fields
2011-08-16 5:04 ` Myklebust, Trond
2011-08-16 11:03 ` J. Bruce Fields
2011-08-16 5:03 ` Myklebust, Trond
2011-08-16 10:49 ` J. Bruce Fields
2011-08-15 22:28 ` J. Bruce Fields
2011-08-15 22:30 ` [PATCH 1/5] nfsd4: clean up S_IS -> NF4 file type mapping J. Bruce Fields
2011-08-15 22:30 ` [PATCH 2/5] nfsd4: return nfserr_symlink on v4 OPEN of non-regular file J. Bruce Fields
2011-08-15 22:30 ` [PATCH 3/5] nfsd4: fix incorrect comment in nfsd4_set_nfs4_acl J. Bruce Fields
2011-08-15 22:30 ` [PATCH 4/5] nfsd: open-code special directory-hardlink check J. Bruce Fields
2011-08-15 22:30 ` J. Bruce Fields [this message]
2011-08-15 22:48 ` [PATCH 5/5] nfsd: clean up nfsd_mode_check() J. Bruce Fields
2011-08-16 11:32 ` [nfsv4] open() of device special files Steve Dickson
2011-08-17 0:52 ` J. Bruce Fields
2011-08-17 1:40 ` J. Bruce Fields
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=1313447432-1537-5-git-send-email-bfields@redhat.com \
--to=bfields@redhat.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