Whamcloud - gitweb
b=3119
[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,75 @@
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 +                        created[i] = -1;
66 +                } else {
67 +                        created[i] = 0;
68 +                }
69 +        }
70 +
71 +        if (failed == 0 || create == 0)
72 +                return 0;
73 +
74 +        needed_blocks = ext3_writepage_trans_blocks(inode);
75 +        lock_kernel();
76 +        handle = ext3_journal_start(inode, needed_blocks);
77 +        unlock_kernel();
78 +        if (IS_ERR(handle))
79 +                return PTR_ERR(handle);
80 +
81 +        iblock = page->index * blocks_per_page;
82 +        for (i = 0; i < blocks_per_page; i++, iblock++) {
83 +                struct buffer_head bh;
84 +
85 +                if (blocks[i] != 0)
86 +                        continue;
87 +
88 +                rc = ext3_get_block_handle(handle, inode, iblock, &bh, 1);
89 +                if (rc) {
90 +                        printk(KERN_INFO "ext3_map_inode_page: error %d "
91 +                               "allocating block %ld\n", rc, iblock);
92 +                        goto out;
93 +                }
94 +                if (buffer_new(&bh))
95 +                        unmap_underlying_metadata(&bh);
96 +                blocks[i] = bh.b_blocknr;
97 +                created[i] = 1;
98 +        }
99 +
100 + out:
101 +       lock_kernel();
102 +       ext3_journal_stop(handle, inode);
103 +       unlock_kernel();
104 +        return rc;
105 +}