Skip to content

Commit c0420ad

Browse files
Coly LiMark Fasheh
authored andcommitted
[PATCH] ocfs2: fix oops in mmap_truncate testing
This patch fixes a mmap_truncate bug which was found by ocfs2 test suite. In an ocfs2 cluster more than 1 node, run program mmap_truncate, which races mmap writes and truncates from multiple processes. While the test is running, a stat from another node forces writeout, causing an oops in ocfs2_get_block() because it sees a buffer to write which isn't allocated. This patch fixed the bug by clear dirty and uptodate bits in buffer, leave the buffer unmapped and return. Fix is suggested by Mark Fasheh, and I code up the patch. Signed-off-by: Coly Li <coyli@suse.de> Signed-off-by: Mark Fasheh <mfasheh@suse.com>
1 parent e752065 commit c0420ad

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

fs/ocfs2/aops.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,17 @@ static int ocfs2_get_block(struct inode *inode, sector_t iblock,
174174
* need to use BH_New is when we're extending i_size on a file
175175
* system which doesn't support holes, in which case BH_New
176176
* allows block_prepare_write() to zero.
177+
*
178+
* If we see this on a sparse file system, then a truncate has
179+
* raced us and removed the cluster. In this case, we clear
180+
* the buffers dirty and uptodate bits and let the buffer code
181+
* ignore it as a hole.
177182
*/
178-
mlog_bug_on_msg(create && p_blkno == 0 && ocfs2_sparse_alloc(osb),
179-
"ino %lu, iblock %llu\n", inode->i_ino,
180-
(unsigned long long)iblock);
183+
if (create && p_blkno == 0 && ocfs2_sparse_alloc(osb)) {
184+
clear_buffer_dirty(bh_result);
185+
clear_buffer_uptodate(bh_result);
186+
goto bail;
187+
}
181188

182189
/* Treat the unwritten extent as a hole for zeroing purposes. */
183190
if (p_blkno && !(ext_flags & OCFS2_EXT_UNWRITTEN))

0 commit comments

Comments
 (0)