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