NFSv4.1/pnfs: Fix atomicity of commit list updates
authorTrond Myklebust <trond.myklebust@primarydata.com>
Fri, 31 Jul 2015 20:24:30 +0000 (16:24 -0400)
committerTrond Myklebust <trond.myklebust@primarydata.com>
Mon, 10 Aug 2015 23:08:13 +0000 (19:08 -0400)
pnfs_layout_mark_request_commit() needs to ensure that it adds the
request to the commit list atomically with all the other updates
in order to prevent corruption to buckets[ds_commit_idx].wlseg
due to races with pnfs_generic_clear_request_commit().

Fixes: 338d00cfef07d ("pnfs: Refactor the *_layout_mark_request_commit...")
Cc: stable@vger.kernel.org # v4.0+
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
fs/nfs/internal.h
fs/nfs/pnfs_nfs.c
fs/nfs/write.c

index 9b372b8..1dad181 100644 (file)
@@ -490,6 +490,9 @@ void nfs_retry_commit(struct list_head *page_list,
 void nfs_commitdata_release(struct nfs_commit_data *data);
 void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *dst,
                                 struct nfs_commit_info *cinfo);
+void nfs_request_add_commit_list_locked(struct nfs_page *req,
+               struct list_head *dst,
+               struct nfs_commit_info *cinfo);
 void nfs_request_remove_commit_list(struct nfs_page *req,
                                    struct nfs_commit_info *cinfo);
 void nfs_init_cinfo(struct nfs_commit_info *cinfo,
@@ -623,13 +626,15 @@ void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
  * Record the page as unstable and mark its inode as dirty.
  */
 static inline
-void nfs_mark_page_unstable(struct page *page)
+void nfs_mark_page_unstable(struct page *page, struct nfs_commit_info *cinfo)
 {
-       struct inode *inode = page_file_mapping(page)->host;
+       if (!cinfo->dreq) {
+               struct inode *inode = page_file_mapping(page)->host;
 
-       inc_zone_page_state(page, NR_UNSTABLE_NFS);
-       inc_wb_stat(&inode_to_bdi(inode)->wb, WB_RECLAIMABLE);
-        __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
+               inc_zone_page_state(page, NR_UNSTABLE_NFS);
+               inc_wb_stat(&inode_to_bdi(inode)->wb, WB_RECLAIMABLE);
+               __mark_inode_dirty(inode, I_DIRTY_DATASYNC);
+       }
 }
 
 /*
index f37e25b..7a28287 100644 (file)
@@ -863,9 +863,10 @@ pnfs_layout_mark_request_commit(struct nfs_page *req,
        }
        set_bit(PG_COMMIT_TO_DS, &req->wb_flags);
        cinfo->ds->nwritten++;
-       spin_unlock(cinfo->lock);
 
-       nfs_request_add_commit_list(req, list, cinfo);
+       nfs_request_add_commit_list_locked(req, list, cinfo);
+       spin_unlock(cinfo->lock);
+       nfs_mark_page_unstable(req->wb_page, cinfo);
 }
 EXPORT_SYMBOL_GPL(pnfs_layout_mark_request_commit);
 
diff --cc fs/nfs/write.c
Simple merge