From: pengdonglin <pengdong...@xiaomi.com>

Since commit a8bb74acd8efe ("rcu: Consolidate RCU-sched update-side function 
definitions")
there is no difference between rcu_read_lock(), rcu_read_lock_bh() and
rcu_read_lock_sched() in terms of RCU read section and the relevant grace
period. That means that spin_lock(), which implies rcu_read_lock_sched(),
also implies rcu_read_lock().

There is no need no explicitly start a RCU read section if one has already
been started implicitly by spin_lock().

Simplify the code and remove the inner rcu_read_lock() invocation.

Cc: Trond Myklebust <tron...@kernel.org>
Cc: Anna Schumaker <a...@kernel.org>
Signed-off-by: pengdonglin <pengdong...@xiaomi.com>
Signed-off-by: pengdonglin <dolinux.p...@gmail.com>
---
 fs/nfs/callback_proc.c |  2 --
 fs/nfs/nfs4state.c     |  2 --
 fs/nfs/pnfs.c          | 12 +-----------
 fs/nfs/pnfs_dev.c      |  4 ----
 4 files changed, 1 insertion(+), 19 deletions(-)

diff --git a/fs/nfs/callback_proc.c b/fs/nfs/callback_proc.c
index 8397c43358bd..16144db39335 100644
--- a/fs/nfs/callback_proc.c
+++ b/fs/nfs/callback_proc.c
@@ -721,7 +721,6 @@ __be32 nfs4_callback_offload(void *data, void *dummy,
                return cpu_to_be32(NFS4ERR_DELAY);
 
        spin_lock(&cps->clp->cl_lock);
-       rcu_read_lock();
        list_for_each_entry_rcu(server, &cps->clp->cl_superblocks,
                                client_link) {
                list_for_each_entry(tmp_copy, &server->ss_copies, copies) {
@@ -736,7 +735,6 @@ __be32 nfs4_callback_offload(void *data, void *dummy,
                }
        }
 out:
-       rcu_read_unlock();
        if (!found) {
                memcpy(&copy->stateid, &args->coa_stateid, NFS4_STATEID_SIZE);
                nfs4_copy_cb_args(copy, args);
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index 7612e977e80b..598229fc07ed 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -241,13 +241,11 @@ const struct cred *nfs4_get_renew_cred(struct nfs_client 
*clp)
                goto out;
 
        spin_lock(&clp->cl_lock);
-       rcu_read_lock();
        list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
                cred = nfs4_get_renew_cred_server_locked(server);
                if (cred != NULL)
                        break;
        }
-       rcu_read_unlock();
        spin_unlock(&clp->cl_lock);
 
 out:
diff --git a/fs/nfs/pnfs.c b/fs/nfs/pnfs.c
index a3135b5af7ee..650f86fa144a 100644
--- a/fs/nfs/pnfs.c
+++ b/fs/nfs/pnfs.c
@@ -838,13 +838,12 @@ pnfs_layout_add_bulk_destroy_list(struct inode *inode,
        return ret;
 }
 
-/* Caller must hold rcu_read_lock and clp->cl_lock */
+/* Caller must hold clp->cl_lock (implies rcu_read_lock) */
 static int
 pnfs_layout_bulk_destroy_byserver_locked(struct nfs_client *clp,
                struct nfs_server *server,
                struct list_head *layout_list)
        __must_hold(&clp->cl_lock)
-       __must_hold(RCU)
 {
        struct pnfs_layout_hdr *lo, *next;
        struct inode *inode;
@@ -862,16 +861,13 @@ pnfs_layout_bulk_destroy_byserver_locked(struct 
nfs_client *clp,
                        if (pnfs_layout_add_bulk_destroy_list(inode,
                                                layout_list))
                                continue;
-                       rcu_read_unlock();
                        spin_unlock(&clp->cl_lock);
                        iput(inode);
                } else {
-                       rcu_read_unlock();
                        spin_unlock(&clp->cl_lock);
                }
                nfs_sb_deactive(server->super);
                spin_lock(&clp->cl_lock);
-               rcu_read_lock();
                return -EAGAIN;
        }
        return 0;
@@ -922,7 +918,6 @@ int pnfs_layout_destroy_byfsid(struct nfs_client *clp, 
struct nfs_fsid *fsid,
        LIST_HEAD(layout_list);
 
        spin_lock(&clp->cl_lock);
-       rcu_read_lock();
 restart:
        list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
                if (memcmp(&server->fsid, fsid, sizeof(*fsid)) != 0)
@@ -932,7 +927,6 @@ int pnfs_layout_destroy_byfsid(struct nfs_client *clp, 
struct nfs_fsid *fsid,
                                &layout_list) != 0)
                        goto restart;
        }
-       rcu_read_unlock();
        spin_unlock(&clp->cl_lock);
 
        return pnfs_layout_free_bulk_destroy_list(&layout_list, mode);
@@ -944,14 +938,12 @@ static void 
pnfs_layout_build_destroy_list_byclient(struct nfs_client *clp,
        struct nfs_server *server;
 
        spin_lock(&clp->cl_lock);
-       rcu_read_lock();
 restart:
        list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
                if (pnfs_layout_bulk_destroy_byserver_locked(clp, server,
                                                             list) != 0)
                        goto restart;
        }
-       rcu_read_unlock();
        spin_unlock(&clp->cl_lock);
 }
 
@@ -990,7 +982,6 @@ static void pnfs_layout_build_recover_list_byclient(struct 
nfs_client *clp,
        struct nfs_server *server;
 
        spin_lock(&clp->cl_lock);
-       rcu_read_lock();
 restart:
        list_for_each_entry_rcu(server, &clp->cl_superblocks, client_link) {
                if (!(server->caps & NFS_CAP_REBOOT_LAYOUTRETURN))
@@ -999,7 +990,6 @@ static void pnfs_layout_build_recover_list_byclient(struct 
nfs_client *clp,
                                                             list) != 0)
                        goto restart;
        }
-       rcu_read_unlock();
        spin_unlock(&clp->cl_lock);
 }
 
diff --git a/fs/nfs/pnfs_dev.c b/fs/nfs/pnfs_dev.c
index bf0f2d67e96c..d19752ec1a95 100644
--- a/fs/nfs/pnfs_dev.c
+++ b/fs/nfs/pnfs_dev.c
@@ -231,9 +231,7 @@ nfs4_delete_deviceid(const struct pnfs_layoutdriver_type 
*ld,
        struct nfs4_deviceid_node *d;
 
        spin_lock(&nfs4_deviceid_lock);
-       rcu_read_lock();
        d = _lookup_deviceid(ld, clp, id, nfs4_deviceid_hash(id));
-       rcu_read_unlock();
        if (!d) {
                spin_unlock(&nfs4_deviceid_lock);
                return;
@@ -331,14 +329,12 @@ _deviceid_purge_client(const struct nfs_client *clp, long 
hash)
        HLIST_HEAD(tmp);
 
        spin_lock(&nfs4_deviceid_lock);
-       rcu_read_lock();
        hlist_for_each_entry_rcu(d, &nfs4_deviceid_cache[hash], node)
                if (d->nfs_client == clp && atomic_read(&d->ref)) {
                        hlist_del_init_rcu(&d->node);
                        hlist_add_head(&d->tmpnode, &tmp);
                        clear_bit(NFS_DEVICEID_NOCACHE, &d->flags);
                }
-       rcu_read_unlock();
        spin_unlock(&nfs4_deviceid_lock);
 
        if (hlist_empty(&tmp))
-- 
2.34.1

Reply via email to