aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2007-08-10 17:45:10 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2007-10-09 17:18:34 -0400
commitaf22f94ae02ab9dd4fd7fe628c8434a59cc293be (patch)
treee3794a90fc0720c33266dfa682e264a4041e7a14
parentcd3758e37ddea66fccca7d93c4b601e8a2e51926 (diff)
NFSv4: Simplify _nfs4_do_access()
Currently, _nfs4_do_access() is just a copy of nfs_do_access() with added conversion of the open flags into an access mask. This patch merges the duplicate functionality. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
-rw-r--r--fs/nfs/dir.c22
-rw-r--r--fs/nfs/nfs4proc.c35
-rw-r--r--include/linux/nfs_fs.h5
3 files changed, 24 insertions, 38 deletions
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index b332c527d95d..2b5e611352c5 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -1815,7 +1815,7 @@ static struct nfs_access_entry *nfs_access_search_rbtree(struct inode *inode, st
1815 return NULL; 1815 return NULL;
1816} 1816}
1817 1817
1818int nfs_access_get_cached(struct inode *inode, struct rpc_cred *cred, struct nfs_access_entry *res) 1818static int nfs_access_get_cached(struct inode *inode, struct rpc_cred *cred, struct nfs_access_entry *res)
1819{ 1819{
1820 struct nfs_inode *nfsi = NFS_I(inode); 1820 struct nfs_inode *nfsi = NFS_I(inode);
1821 struct nfs_access_entry *cache; 1821 struct nfs_access_entry *cache;
@@ -1882,7 +1882,7 @@ found:
1882 nfs_access_free_entry(entry); 1882 nfs_access_free_entry(entry);
1883} 1883}
1884 1884
1885void nfs_access_add_cache(struct inode *inode, struct nfs_access_entry *set) 1885static void nfs_access_add_cache(struct inode *inode, struct nfs_access_entry *set)
1886{ 1886{
1887 struct nfs_access_entry *cache = kmalloc(sizeof(*cache), GFP_KERNEL); 1887 struct nfs_access_entry *cache = kmalloc(sizeof(*cache), GFP_KERNEL);
1888 if (cache == NULL) 1888 if (cache == NULL)
@@ -1930,6 +1930,24 @@ out:
1930 return -EACCES; 1930 return -EACCES;
1931} 1931}
1932 1932
1933static int nfs_open_permission_mask(int openflags)
1934{
1935 int mask = 0;
1936
1937 if (openflags & FMODE_READ)
1938 mask |= MAY_READ;
1939 if (openflags & FMODE_WRITE)
1940 mask |= MAY_WRITE;
1941 if (openflags & FMODE_EXEC)
1942 mask |= MAY_EXEC;
1943 return mask;
1944}
1945
1946int nfs_may_open(struct inode *inode, struct rpc_cred *cred, int openflags)
1947{
1948 return nfs_do_access(inode, cred, nfs_open_permission_mask(openflags));
1949}
1950
1933int nfs_permission(struct inode *inode, int mask, struct nameidata *nd) 1951int nfs_permission(struct inode *inode, int mask, struct nameidata *nd)
1934{ 1952{
1935 struct rpc_cred *cred; 1953 struct rpc_cred *cred;
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 2919271a983a..5aa0dd1e1bdf 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -65,7 +65,6 @@ static int nfs4_async_handle_error(struct rpc_task *, const struct nfs_server *)
65static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry); 65static int _nfs4_proc_access(struct inode *inode, struct nfs_access_entry *entry);
66static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception); 66static int nfs4_handle_exception(const struct nfs_server *server, int errorcode, struct nfs4_exception *exception);
67static int nfs4_wait_clnt_recover(struct rpc_clnt *clnt, struct nfs_client *clp); 67static int nfs4_wait_clnt_recover(struct rpc_clnt *clnt, struct nfs_client *clp);
68static int _nfs4_do_access(struct inode *inode, struct rpc_cred *cred, int openflags);
69static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr); 68static int _nfs4_proc_lookup(struct inode *dir, const struct qstr *name, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
70static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr); 69static int _nfs4_proc_getattr(struct nfs_server *server, struct nfs_fh *fhandle, struct nfs_fattr *fattr);
71 70
@@ -454,7 +453,7 @@ static struct nfs4_state *nfs4_try_open_cached(struct nfs4_opendata *opendata)
454 memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data)); 453 memcpy(stateid.data, delegation->stateid.data, sizeof(stateid.data));
455 rcu_read_unlock(); 454 rcu_read_unlock();
456 lock_kernel(); 455 lock_kernel();
457 ret = _nfs4_do_access(state->inode, state->owner->so_cred, open_mode); 456 ret = nfs_may_open(state->inode, state->owner->so_cred, open_mode);
458 unlock_kernel(); 457 unlock_kernel();
459 if (ret != 0) 458 if (ret != 0)
460 goto out; 459 goto out;
@@ -948,36 +947,6 @@ static int _nfs4_proc_open(struct nfs4_opendata *data)
948 return 0; 947 return 0;
949} 948}
950 949
951static int _nfs4_do_access(struct inode *inode, struct rpc_cred *cred, int openflags)
952{
953 struct nfs_access_entry cache;
954 int mask = 0;
955 int status;
956
957 if (openflags & FMODE_READ)
958 mask |= MAY_READ;
959 if (openflags & FMODE_WRITE)
960 mask |= MAY_WRITE;
961 if (openflags & FMODE_EXEC)
962 mask |= MAY_EXEC;
963 status = nfs_access_get_cached(inode, cred, &cache);
964 if (status == 0)
965 goto out;
966
967 /* Be clever: ask server to check for all possible rights */
968 cache.mask = MAY_EXEC | MAY_WRITE | MAY_READ;
969 cache.cred = cred;
970 cache.jiffies = jiffies;
971 status = _nfs4_proc_access(inode, &cache);
972 if (status != 0)
973 return status;
974 nfs_access_add_cache(inode, &cache);
975out:
976 if ((cache.mask & mask) == mask)
977 return 0;
978 return -EACCES;
979}
980
981static int nfs4_recover_expired_lease(struct nfs_server *server) 950static int nfs4_recover_expired_lease(struct nfs_server *server)
982{ 951{
983 struct nfs_client *clp = server->nfs_client; 952 struct nfs_client *clp = server->nfs_client;
@@ -1381,7 +1350,7 @@ static int nfs4_intent_set_file(struct nameidata *nd, struct path *path, struct
1381 1350
1382 /* If the open_intent is for execute, we have an extra check to make */ 1351 /* If the open_intent is for execute, we have an extra check to make */
1383 if (nd->intent.open.flags & FMODE_EXEC) { 1352 if (nd->intent.open.flags & FMODE_EXEC) {
1384 ret = _nfs4_do_access(state->inode, 1353 ret = nfs_may_open(state->inode,
1385 state->owner->so_cred, 1354 state->owner->so_cred,
1386 nd->intent.open.flags); 1355 nd->intent.open.flags);
1387 if (ret < 0) 1356 if (ret < 0)
diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h
index 5c200fd8c652..5b42fef0baf0 100644
--- a/include/linux/nfs_fs.h
+++ b/include/linux/nfs_fs.h
@@ -292,9 +292,6 @@ extern int nfs_refresh_inode(struct inode *, struct nfs_fattr *);
292extern int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr); 292extern int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr);
293extern int nfs_getattr(struct vfsmount *, struct dentry *, struct kstat *); 293extern int nfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
294extern int nfs_permission(struct inode *, int, struct nameidata *); 294extern int nfs_permission(struct inode *, int, struct nameidata *);
295extern int nfs_access_get_cached(struct inode *, struct rpc_cred *, struct nfs_access_entry *);
296extern void nfs_access_add_cache(struct inode *, struct nfs_access_entry *);
297extern void nfs_access_zap_cache(struct inode *inode);
298extern int nfs_open(struct inode *, struct file *); 295extern int nfs_open(struct inode *, struct file *);
299extern int nfs_release(struct inode *, struct file *); 296extern int nfs_release(struct inode *, struct file *);
300extern int nfs_attribute_timeout(struct inode *inode); 297extern int nfs_attribute_timeout(struct inode *inode);
@@ -382,6 +379,8 @@ extern const struct file_operations nfs_dir_operations;
382extern struct dentry_operations nfs_dentry_operations; 379extern struct dentry_operations nfs_dentry_operations;
383 380
384extern int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fh, struct nfs_fattr *fattr); 381extern int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fh, struct nfs_fattr *fattr);
382extern int nfs_may_open(struct inode *inode, struct rpc_cred *cred, int openflags);
383extern void nfs_access_zap_cache(struct inode *inode);
385 384
386/* 385/*
387 * linux/fs/nfs/symlink.c 386 * linux/fs/nfs/symlink.c