NFS:remove redundant call to nfs_do_access
authorZhouyi Zhou <zhouzhouyi@gmail.com>
Fri, 6 Mar 2020 03:45:26 +0000 (03:45 +0000)
committerTrond Myklebust <trond.myklebust@hammerspace.com>
Mon, 16 Mar 2020 14:11:59 +0000 (10:11 -0400)
In function nfs_permission:
1. the rcu_read_lock and rcu_read_unlock around nfs_do_access
is unnecessary because the rcu critical data structure is already
protected in subsidiary function nfs_access_get_cached_rcu. No other
data structure needs rcu_read_lock in nfs_do_access.

2. call nfs_do_access once is enough, because:
2-1. when mask has MAY_NOT_BLOCK bit
The second call to nfs_do_access will not happen.

2-2. when mask has no MAY_NOT_BLOCK bit
The second call to nfs_do_access will happen if res == -ECHILD, which
means the first nfs_do_access goes out after statement if (!may_block).
The second call to nfs_do_access will go through this procedure once
again except continue the work after if (!may_block).
But above work can be performed by only one call to nfs_do_access
without mangling the mask flag.

Tested in x86_64
Signed-off-by: Zhouyi Zhou <zhouzhouyi@gmail.com>
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
fs/nfs/dir.c

index f22366f..b3a675d 100644 (file)
@@ -2759,14 +2759,7 @@ force_lookup:
        if (!NFS_PROTO(inode)->access)
                goto out_notsup;
 
-       /* Always try fast lookups first */
-       rcu_read_lock();
-       res = nfs_do_access(inode, cred, mask|MAY_NOT_BLOCK);
-       rcu_read_unlock();
-       if (res == -ECHILD && !(mask & MAY_NOT_BLOCK)) {
-               /* Fast lookup failed, try the slow way */
-               res = nfs_do_access(inode, cred, mask);
-       }
+       res = nfs_do_access(inode, cred, mask);
 out:
        if (!res && (mask & MAY_EXEC))
                res = nfs_execute_ok(inode, mask);