From 34094537943113467faee98fe67c8a3d3f9a0a8b Mon Sep 17 00:00:00 2001 From: Ryusuke Konishi Date: Sun, 27 Mar 2011 22:50:49 +0900 Subject: nilfs2: fix data loss in mmap page write for hole blocks From the result of a function test of mmap, mmap write to shared pages turned out to be broken for hole blocks. It doesn't write out filled blocks and the data will be lost after umount. This is due to a bug that the target file is not queued for log writer when filling hole blocks. Also, nilfs_page_mkwrite function exits normal code path even after successfully filled hole blocks due to a change of block_page_mkwrite function; just after nilfs was merged into the mainline, block_page_mkwrite() started to return VM_FAULT_LOCKED instead of zero by the patch "mm: close page_mkwrite races" (commit: b827e496c893de0c). The current nilfs_page_mkwrite() is not handling this value properly. This corrects nilfs_page_mkwrite() and will resolve the data loss problem in mmap write. [This should be applied to every kernel since 2.6.30 but a fix is needed for 2.6.37 and prior kernels] Signed-off-by: Ryusuke Konishi Tested-by: Ryusuke Konishi Cc: stable [2.6.38] --- fs/nilfs2/file.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'fs') diff --git a/fs/nilfs2/file.c b/fs/nilfs2/file.c index 93589fccdd97..397e73258631 100644 --- a/fs/nilfs2/file.c +++ b/fs/nilfs2/file.c @@ -72,10 +72,9 @@ static int nilfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) /* * check to see if the page is mapped already (no holes) */ - if (PageMappedToDisk(page)) { - unlock_page(page); + if (PageMappedToDisk(page)) goto mapped; - } + if (page_has_buffers(page)) { struct buffer_head *bh, *head; int fully_mapped = 1; @@ -90,7 +89,6 @@ static int nilfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) if (fully_mapped) { SetPageMappedToDisk(page); - unlock_page(page); goto mapped; } } @@ -105,16 +103,17 @@ static int nilfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) return VM_FAULT_SIGBUS; ret = block_page_mkwrite(vma, vmf, nilfs_get_block); - if (unlikely(ret)) { + if (ret != VM_FAULT_LOCKED) { nilfs_transaction_abort(inode->i_sb); return ret; } + nilfs_set_file_dirty(inode, 1 << (PAGE_SHIFT - inode->i_blkbits)); nilfs_transaction_commit(inode->i_sb); mapped: SetPageChecked(page); wait_on_page_writeback(page); - return 0; + return VM_FAULT_LOCKED; } static const struct vm_operations_struct nilfs_file_vm_ops = { -- cgit v1.2.3 From d611b22f1a5ddd0823e9d6a30bac91219f800e41 Mon Sep 17 00:00:00 2001 From: Ryusuke Konishi Date: Wed, 30 Mar 2011 11:49:20 +0900 Subject: nilfs2: fix oops due to a bad aops initialization Nilfs in 2.6.39-rc1 hit the following oops: BUG: unable to handle kernel NULL pointer dereference at 0000000000000048 IP: [] try_to_release_page+0x2a/0x3d PGD 234cb6067 PUD 234c72067 PMD 0 Oops: 0000 [#1] SMP Process truncate (pid: 10995, threadinfo ffff8802353c2000, task ffff880234cfa000) Stack: ffff8802333c77b8 ffffffff810b64b0 0000000000003802 ffffffffa0052cca 0000000000000000 ffff8802353c3b58 0000000000000000 ffff8802353c3b58 0000000000000001 0000000000000000 ffffea0007b92308 ffffea0007b92308 Call Trace: [] ? invalidate_inode_pages2_range+0x15f/0x273 [] ? nilfs_palloc_get_block+0x2d/0xaf [nilfs2] [] ? bit_waitqueue+0x14/0xa1 [] ? wake_up_bit+0x10/0x20 [] ? nilfs_forget_buffer+0x66/0x7a [nilfs2] [] ? nilfs_btree_concat_left+0x5c/0x77 [nilfs2] [] ? nilfs_btree_delete+0x395/0x3cf [nilfs2] [] ? nilfs_bmap_do_delete+0x6e/0x79 [nilfs2] [] ? nilfs_btree_last_key+0x14b/0x15e [nilfs2] [] ? nilfs_bmap_truncate+0x2f/0x83 [nilfs2] [] ? nilfs_bmap_last_key+0x35/0x62 [nilfs2] [] ? nilfs_truncate_bmap+0x6b/0xc7 [nilfs2] [] ? nilfs_truncate+0x79/0xe4 [nilfs2] [] ? vmtruncate+0x33/0x3b [] ? nilfs_setattr+0x4d/0x8c [nilfs2] [] ? do_page_fault+0x31b/0x356 [] ? notify_change+0x17d/0x262 [] ? do_truncate+0x65/0x80 [] ? sys_ftruncate+0xf1/0xf6 [] ? system_call_fastpath+0x16/0x1b Code: c3 48 83 ec 08 48 8b 17 48 8b 47 18 80 e2 01 75 04 0f 0b eb fe 48 8b 17 80 e6 20 74 05 31 c0 41 59 c3 48 85 c0 74 11 48 8b 40 58 8b 40 48 48 85 c0 74 04 41 58 ff e0 59 e9 b1 b5 05 00 41 54 RIP [] try_to_release_page+0x2a/0x3d RSP CR2: 0000000000000048 This oops was brought in by the change "block: remove per-queue plugging" (commit: 7eaceaccab5f40bb). It initializes mapping->a_ops with a NULL pointer for some pages in nilfs (e.g. btree node pages), but mm code doesn't NULL pointer checks against mapping->a_ops. (the check is done for each callback function) This corrects the aops initialization and fixes the oops. Signed-off-by: Ryusuke Konishi Acked-by: Jens Axboe --- fs/nilfs2/page.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'fs') diff --git a/fs/nilfs2/page.c b/fs/nilfs2/page.c index 4d2a1ee0eb47..9d2dc6b4348e 100644 --- a/fs/nilfs2/page.c +++ b/fs/nilfs2/page.c @@ -495,12 +495,14 @@ unsigned nilfs_page_count_clean_buffers(struct page *page, void nilfs_mapping_init(struct address_space *mapping, struct backing_dev_info *bdi) { + static const struct address_space_operations empty_aops; + mapping->host = NULL; mapping->flags = 0; mapping_set_gfp_mask(mapping, GFP_NOFS); mapping->assoc_mapping = NULL; mapping->backing_dev_info = bdi; - mapping->a_ops = NULL; + mapping->a_ops = &empty_aops; } /* -- cgit v1.2.3 From af71dda0b8e667d03eec21d25f90265eec5efea1 Mon Sep 17 00:00:00 2001 From: Nicolas Kaiser Date: Sat, 19 Mar 2011 16:47:54 +0100 Subject: nilfs2: fix whitespace coding style issues Fixes whitespace coding style issues. Signed-off-by: Nicolas Kaiser Signed-off-by: Ryusuke Konishi --- fs/nilfs2/nilfs.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'fs') diff --git a/fs/nilfs2/nilfs.h b/fs/nilfs2/nilfs.h index 856e8e4e0b74..a8dd344303cb 100644 --- a/fs/nilfs2/nilfs.h +++ b/fs/nilfs2/nilfs.h @@ -114,19 +114,19 @@ enum { * Macros to check inode numbers */ #define NILFS_MDT_INO_BITS \ - ((unsigned int)(1 << NILFS_DAT_INO | 1 << NILFS_CPFILE_INO | \ - 1 << NILFS_SUFILE_INO | 1 << NILFS_IFILE_INO | \ - 1 << NILFS_ATIME_INO | 1 << NILFS_SKETCH_INO)) + ((unsigned int)(1 << NILFS_DAT_INO | 1 << NILFS_CPFILE_INO | \ + 1 << NILFS_SUFILE_INO | 1 << NILFS_IFILE_INO | \ + 1 << NILFS_ATIME_INO | 1 << NILFS_SKETCH_INO)) #define NILFS_SYS_INO_BITS \ - ((unsigned int)(1 << NILFS_ROOT_INO) | NILFS_MDT_INO_BITS) + ((unsigned int)(1 << NILFS_ROOT_INO) | NILFS_MDT_INO_BITS) #define NILFS_FIRST_INO(sb) (((struct the_nilfs *)sb->s_fs_info)->ns_first_ino) #define NILFS_MDT_INODE(sb, ino) \ - ((ino) < NILFS_FIRST_INO(sb) && (NILFS_MDT_INO_BITS & (1 << (ino)))) + ((ino) < NILFS_FIRST_INO(sb) && (NILFS_MDT_INO_BITS & (1 << (ino)))) #define NILFS_VALID_INODE(sb, ino) \ - ((ino) >= NILFS_FIRST_INO(sb) || (NILFS_SYS_INO_BITS & (1 << (ino)))) + ((ino) >= NILFS_FIRST_INO(sb) || (NILFS_SYS_INO_BITS & (1 << (ino)))) /** * struct nilfs_transaction_info: context information for synchronization @@ -285,7 +285,7 @@ extern void nilfs_destroy_inode(struct inode *); extern void nilfs_error(struct super_block *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4))); extern void nilfs_warning(struct super_block *, const char *, const char *, ...) - __attribute__ ((format (printf, 3, 4))); + __attribute__ ((format (printf, 3, 4))); extern struct nilfs_super_block * nilfs_read_super_block(struct super_block *, u64, int, struct buffer_head **); extern int nilfs_store_magic_and_option(struct super_block *, -- cgit v1.2.3