Whamcloud - gitweb
87a143594251d262737a87500f4468c8488a7b47
[fs/lustre-release.git] / ldiskfs / kernel_patches / patches / rhel6.3 / ext4-map_inode_page-2.6.18.patch
1 Index: linux-2.6.18.i386/fs/ext4/inode.c
2 ===================================================================
3 --- linux-2.6.18.i386.orig/fs/ext4/inode.c
4 +++ linux-2.6.18.i386/fs/ext4/inode.c
5 @@ -3666,3 +3666,67 @@ out_unlock:
6         unlock_page(page);
7         return ret;
8  }
9 +
10 +int ext4_map_inode_page(struct inode *inode, struct page *page,
11 +                       unsigned long *blocks, int *created, int create)
12 +{
13 +       unsigned int blocksize, blocks_per_page;
14 +       unsigned long iblock;
15 +       struct buffer_head dummy;
16 +       void *handle;
17 +       int i, rc = 0, failed = 0, needed_blocks;
18 +
19 +       blocksize = inode->i_sb->s_blocksize;
20 +       blocks_per_page = PAGE_SIZE >> inode->i_sb->s_blocksize_bits;
21 +       iblock = page->index * blocks_per_page;
22 +
23 +       for (i = 0; i < blocks_per_page; i++, iblock++) {
24 +               blocks[i] = ext4_bmap(inode->i_mapping, iblock);
25 +               if (blocks[i] == 0) {
26 +                       failed++;
27 +                       if (created)
28 +                               created[i] = -1;
29 +               } else if (created) {
30 +                       created[i] = 0;
31 +               }
32 +       }
33 +
34 +       if (failed == 0 || create == 0)
35 +               return 0;
36 +
37 +       needed_blocks = ext4_writepage_trans_blocks(inode);
38 +       handle = ext4_journal_start(inode, needed_blocks);
39 +       if (IS_ERR(handle))
40 +               return PTR_ERR(handle);
41 +
42 +       iblock = page->index * blocks_per_page;
43 +       for (i = 0; i < blocks_per_page; i++, iblock++) {
44 +               if (blocks[i] != 0)
45 +                       continue;
46 +
47 +               rc = ext4_ind_get_blocks(handle, inode, iblock, 1, &dummy,
48 +                                        EXT4_GET_BLOCKS_CREATE);
49 +               if (rc < 0) {
50 +                       printk(KERN_INFO "ext4_map_inode_page: error reading "
51 +                                       "block %ld\n", iblock);
52 +                       goto out;
53 +               } else {
54 +                       if (rc > 1)
55 +                               WARN_ON(1);
56 +                       rc = 0;
57 +               }
58 +               /* Unmap any metadata buffers from the block mapping, to avoid
59 +                * data corruption due to direct-write from Lustre being
60 +                * clobbered by a later flush of the blockdev metadata buffer.*/
61 +               if (buffer_new(&dummy))
62 +                       unmap_underlying_metadata(dummy.b_bdev,
63 +                                       dummy.b_blocknr);
64 +               blocks[i] = dummy.b_blocknr;
65 +               if (created)
66 +                       created[i] = 1;
67 +       }
68 +
69 +out:
70 +       ext4_journal_stop(handle);
71 +       return rc;
72 +}
73 +EXPORT_SYMBOL(ext4_map_inode_page);
74 Index: linux-2.6.18.i386/fs/ext4/super.c
75 ===================================================================
76 --- linux-2.6.18.i386.orig/fs/ext4/super.c
77 +++ linux-2.6.18.i386/fs/ext4/super.c
78 @@ -3498,6 +3498,10 @@ static void __exit exit_ext4_fs(void)
79         __free_page(ext4_zero_page);
80  }
81  
82 +int ext4_map_inode_page(struct inode *inode, struct page *page,
83 +                       unsigned long *blocks, int *created, int create);
84 +EXPORT_SYMBOL(ext4_map_inode_page);
85 +
86  MODULE_AUTHOR("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others");
87  MODULE_DESCRIPTION("Fourth Extended Filesystem with extents");
88  MODULE_LICENSE("GPL");