Whamcloud - gitweb
Branch HEAD
[fs/lustre-release.git] / lustre / kernel_patches / patches / ext3-map_inode_page_2.4.18.patch
1
2
3
4  fs/ext3/ext3-exports.c |    3 ++
5  fs/ext3/inode.c        |   55 +++++++++++++++++++++++++++++++++++++++++++++++++
6  2 files changed, 58 insertions(+)
7
8 Index: linux-2.4.18-p4smp/fs/ext3/ext3-exports.c
9 ===================================================================
10 --- linux-2.4.18-p4smp.orig/fs/ext3/ext3-exports.c      Thu Nov 27 22:18:40 2003
11 +++ linux-2.4.18-p4smp/fs/ext3/ext3-exports.c   Thu Nov 27 22:18:40 2003
12 @@ -9,6 +9,8 @@
13  
14  int ext3_prep_san_write(struct inode *inode, long *blocks,
15                         int nblocks, loff_t newsize);
16 +int ext3_map_inode_page(struct inode *inode, struct page *page,
17 +                        unsigned long *block, int *created, int create);
18  
19  EXPORT_SYMBOL(ext3_force_commit);
20  EXPORT_SYMBOL(ext3_bread);
21 @@ -18,3 +20,4 @@
22  EXPORT_SYMBOL(ext3_xattr_list);
23  EXPORT_SYMBOL(ext3_xattr_set);
24  EXPORT_SYMBOL(ext3_prep_san_write);
25 +EXPORT_SYMBOL(ext3_map_inode_page);
26 Index: linux-2.4.18-p4smp/fs/ext3/inode.c
27 ===================================================================
28 --- linux-2.4.18-p4smp.orig/fs/ext3/inode.c     Thu Nov 27 22:18:40 2003
29 +++ linux-2.4.18-p4smp/fs/ext3/inode.c  Thu Nov 27 22:20:36 2003
30 @@ -3004,3 +3004,80 @@
31                 ret = ret2;
32         return ret;
33  }
34 +
35 +/* copied from fs/buffer.c */
36 +static void unmap_underlying_metadata(struct buffer_head * bh)
37 +{
38 +       struct buffer_head *old_bh;
39 +
40 +       old_bh = get_hash_table(bh->b_dev, bh->b_blocknr, bh->b_size);
41 +       if (old_bh) {
42 +               mark_buffer_clean(old_bh);
43 +               wait_on_buffer(old_bh);
44 +               clear_bit(BH_Req, &old_bh->b_state);
45 +               __brelse(old_bh);
46 +       }
47 +}
48 +
49 +int ext3_map_inode_page(struct inode *inode, struct page *page,
50 +                        unsigned long *blocks, int *created, int create)
51 +{
52 +        unsigned int blocksize, blocks_per_page;
53 +        unsigned long iblock;
54 +        void *handle;
55 +        int i, rc = 0, failed = 0, needed_blocks;
56 +
57 +        blocksize = inode->i_sb->s_blocksize;
58 +        blocks_per_page = PAGE_SIZE >> inode->i_sb->s_blocksize_bits;
59 +        iblock = page->index * blocks_per_page;
60 +
61 +        for (i = 0; i < blocks_per_page; i++, iblock++) {
62 +                blocks[i] = ext3_bmap(inode->i_mapping, iblock);
63 +                if (blocks[i] == 0) {
64 +                        failed++;
65 +                       if (created)
66 +                               created[i] = -1;
67 +               } else if (created) {
68 +                        created[i] = 0;
69 +                }
70 +        }
71 +
72 +        if (failed == 0 || create == 0)
73 +                return 0;
74 +
75 +        needed_blocks = ext3_writepage_trans_blocks(inode);
76 +        lock_kernel();
77 +        handle = ext3_journal_start(inode, needed_blocks);
78 +        unlock_kernel();
79 +        if (IS_ERR(handle))
80 +                return PTR_ERR(handle);
81 +
82 +        iblock = page->index * blocks_per_page;
83 +        for (i = 0; i < blocks_per_page; i++, iblock++) {
84 +                struct buffer_head bh;
85 +
86 +                if (blocks[i] != 0)
87 +                        continue;
88 +
89 +                rc = ext3_get_block_handle(handle, inode, iblock, &bh, 1);
90 +                if (rc) {
91 +                        printk(KERN_INFO "ext3_map_inode_page: error %d "
92 +                               "allocating block %ld\n", rc, iblock);
93 +                        goto out;
94 +                }
95 +               /* Unmap any metadata buffers from the block mapping, to avoid
96 +                * data corruption due to direct-write from Lustre being
97 +                * clobbered by a later flush of the blockdev metadata buffer.*/
98 +                if (buffer_new(&bh))
99 +                        unmap_underlying_metadata(&bh);
100 +                blocks[i] = bh.b_blocknr;
101 +               if (created)
102 +                       created[i] = 1;
103 +        }
104 +
105 + out:
106 +       lock_kernel();
107 +       ext3_journal_stop(handle, inode);
108 +       unlock_kernel();
109 +        return rc;
110 +}