]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/commitdiff
NFS: Fix up commit deadlocks
authorTrond Myklebust <trond.myklebust@hammerspace.com>
Mon, 4 Oct 2021 19:37:42 +0000 (15:37 -0400)
committerAndrea Righi <andrea.righi@canonical.com>
Tue, 4 Jan 2022 08:48:33 +0000 (09:48 +0100)
BugLink: https://bugs.launchpad.net/bugs/1951822
[ Upstream commit 133a48abf6ecc535d7eddc6da1c3e4c972445882 ]

If O_DIRECT bumps the commit_info rpcs_out field, then that could lead
to fsync() hangs. The fix is to ensure that O_DIRECT calls
nfs_commit_end().

Fixes: 723c921e7dfc ("sched/wait, fs/nfs: Convert wait_on_atomic_t() usage to the new wait_var_event() API")
Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
fs/nfs/direct.c
fs/nfs/pnfs_nfs.c
fs/nfs/write.c
include/linux/nfs_fs.h

index 2e894fec036b083b8431cf82883a7d06fe9b1e83..3c0335c15a730054b0c09f1d9801765610a1e9b7 100644 (file)
@@ -620,7 +620,7 @@ static void nfs_direct_commit_complete(struct nfs_commit_data *data)
                nfs_unlock_and_release_request(req);
        }
 
-       if (atomic_dec_and_test(&cinfo.mds->rpcs_out))
+       if (nfs_commit_end(cinfo.mds))
                nfs_direct_write_complete(dreq);
 }
 
index 02bd6e83961d9abfdbf286b2a4f0bf57243df43a..316f68f96e573aa8bb3aedc390cfe3a4003b604b 100644 (file)
@@ -468,7 +468,6 @@ pnfs_bucket_alloc_ds_commits(struct list_head *list,
                                goto out_error;
                        data->ds_commit_index = i;
                        list_add_tail(&data->list, list);
-                       atomic_inc(&cinfo->mds->rpcs_out);
                        nreq++;
                }
                mutex_unlock(&NFS_I(cinfo->inode)->commit_mutex);
@@ -520,7 +519,6 @@ pnfs_generic_commit_pagelist(struct inode *inode, struct list_head *mds_pages,
                data->ds_commit_index = -1;
                list_splice_init(mds_pages, &data->pages);
                list_add_tail(&data->list, &list);
-               atomic_inc(&cinfo->mds->rpcs_out);
                nreq++;
        }
 
index 735a05474775227c90feac8d608bb5308bd95aaf..7dce3e735fc533eaf4fd29cc121afae069b79ebd 100644 (file)
@@ -1657,10 +1657,13 @@ static void nfs_commit_begin(struct nfs_mds_commit_info *cinfo)
        atomic_inc(&cinfo->rpcs_out);
 }
 
-static void nfs_commit_end(struct nfs_mds_commit_info *cinfo)
+bool nfs_commit_end(struct nfs_mds_commit_info *cinfo)
 {
-       if (atomic_dec_and_test(&cinfo->rpcs_out))
+       if (atomic_dec_and_test(&cinfo->rpcs_out)) {
                wake_up_var(&cinfo->rpcs_out);
+               return true;
+       }
+       return false;
 }
 
 void nfs_commitdata_release(struct nfs_commit_data *data)
@@ -1760,6 +1763,7 @@ void nfs_init_commit(struct nfs_commit_data *data,
        data->res.fattr   = &data->fattr;
        data->res.verf    = &data->verf;
        nfs_fattr_init(&data->fattr);
+       nfs_commit_begin(cinfo->mds);
 }
 EXPORT_SYMBOL_GPL(nfs_init_commit);
 
@@ -1806,7 +1810,6 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how,
 
        /* Set up the argument struct */
        nfs_init_commit(data, head, NULL, cinfo);
-       atomic_inc(&cinfo->mds->rpcs_out);
        if (NFS_SERVER(inode)->nfs_client->cl_minorversion)
                task_flags = RPC_TASK_MOVEABLE;
        return nfs_initiate_commit(NFS_CLIENT(inode), data, NFS_PROTO(inode),
index b9a8b925db430da699c85366751c1bcc4b8adf3c..4d95cc999d1216a5c25bec7ba3c532fdd40b3bac 100644 (file)
@@ -569,6 +569,7 @@ extern int nfs_wb_page_cancel(struct inode *inode, struct page* page);
 extern int  nfs_commit_inode(struct inode *, int);
 extern struct nfs_commit_data *nfs_commitdata_alloc(bool never_fail);
 extern void nfs_commit_free(struct nfs_commit_data *data);
+bool nfs_commit_end(struct nfs_mds_commit_info *cinfo);
 
 static inline int
 nfs_have_writebacks(struct inode *inode)