Whamcloud - gitweb
b=3119
[fs/lustre-release.git] / lustre / kernel_patches / patches / ext3-noread-2.4.20.patch
1  fs/ext3/ialloc.c        |   47 ++++++++++++++++++++++-
2  fs/ext3/inode.c         |   96 +++++++++++++++++++++++++++++++++++++-----------
3  include/linux/ext3_fs.h |    2 +
4  3 files changed, 121 insertions(+), 24 deletions(-)
5
6 --- linux-2.4.20/fs/ext3/ialloc.c~ext3-noread-2.4.20    2003-05-16 12:21:39.000000000 +0800
7 +++ linux-2.4.20-root/fs/ext3/ialloc.c  2003-05-16 12:21:46.000000000 +0800
8 @@ -289,6 +289,37 @@ error_return:
9  }
10  
11  /*
12 + * @block_group: block group of inode
13 + * @offset: relative offset of inode within @block_group
14 + *
15 + * Check whether any of the inodes in this disk block are in use.
16 + *
17 + * Caller must be holding superblock lock (group/bitmap read lock in future).
18 + */
19 +int ext3_itable_block_used(struct super_block *sb, unsigned int block_group,
20 +                          int offset)
21 +{
22 +       int bitmap_nr = load_inode_bitmap(sb, block_group);
23 +       int inodes_per_block;
24 +       unsigned long inum, iend;
25 +       struct buffer_head *ibitmap;
26 +
27 +       if (bitmap_nr < 0)
28 +               return 1;
29 +
30 +       inodes_per_block = sb->s_blocksize / EXT3_SB(sb)->s_inode_size;
31 +       inum = offset & ~(inodes_per_block - 1);
32 +       iend = inum + inodes_per_block;
33 +       ibitmap = EXT3_SB(sb)->s_inode_bitmap[bitmap_nr];
34 +       for (; inum < iend; inum++) {
35 +               if (inum != offset && ext3_test_bit(inum, ibitmap->b_data))
36 +                       return 1;
37 +       }
38 +
39 +       return 0;
40 +}
41 +
42 +/*
43   * There are two policies for allocating an inode.  If the new inode is
44   * a directory, then a forward search is made for a block group with both
45   * free space and a low directory-to-inode ratio; if that fails, then of
46 @@ -310,6 +341,7 @@ struct inode * ext3_new_inode (handle_t 
47         struct ext3_group_desc * gdp;
48         struct ext3_group_desc * tmp;
49         struct ext3_super_block * es;
50 +       struct ext3_iloc iloc;
51         int err = 0;
52  
53         /* Cannot create files in a deleted directory */
54 @@ -510,8 +542,19 @@ repeat:
55         inode->i_generation = sb->u.ext3_sb.s_next_generation++;
56  
57         inode->u.ext3_i.i_state = EXT3_STATE_NEW;
58 -       err = ext3_mark_inode_dirty(handle, inode);
59 -       if (err) goto fail;
60 +       err = ext3_get_inode_loc_new(inode, &iloc, 1);
61 +       if (err) goto fail;
62 +       BUFFER_TRACE(iloc->bh, "get_write_access");
63 +       err = ext3_journal_get_write_access(handle, iloc.bh);
64 +       if (err) {
65 +               brelse(iloc.bh);
66 +               iloc.bh = NULL;
67 +               goto fail;
68 +       }
69 +       err = ext3_mark_iloc_dirty(handle, inode, &iloc);
70 +       if (err) goto fail;
71 +
72 +
73         
74         unlock_super (sb);
75         if(DQUOT_ALLOC_INODE(inode)) {
76 --- linux-2.4.20/fs/ext3/inode.c~ext3-noread-2.4.20     2003-05-16 12:21:41.000000000 +0800
77 +++ linux-2.4.20-root/fs/ext3/inode.c   2003-05-16 12:22:15.000000000 +0800
78 @@ -2013,14 +2013,19 @@ out_stop:
79         ext3_journal_stop(handle, inode);
80  }
81  
82 -/* 
83 - * ext3_get_inode_loc returns with an extra refcount against the
84 - * inode's underlying buffer_head on success. 
85 - */
86 -
87 -int ext3_get_inode_loc (struct inode *inode, struct ext3_iloc *iloc)
88 +#define NUM_INODE_PREREAD      16
89 +
90 +/*
91 + * ext3_get_inode_loc returns with an extra refcount against the inode's
92 + * underlying buffer_head on success.  If this is for a new inode allocation
93 + * (new is non-zero) then we may be able to optimize away the read if there
94 + * are no other in-use inodes in this inode table block.  If we need to do
95 + * a read, then read in a whole chunk of blocks to avoid blocking again soon
96 + * if we are doing lots of creates/updates.
97 + */
98 +int ext3_get_inode_loc_new(struct inode *inode, struct ext3_iloc *iloc, int new)
99  {
100 -       struct buffer_head *bh = 0;
101 +       struct buffer_head *bh[NUM_INODE_PREREAD];
102         unsigned long block;
103         unsigned long block_group;
104         unsigned long group_desc;
105 @@ -2045,31 +2050,73 @@ int ext3_get_inode_loc (struct inode *in
106         }
107         group_desc = block_group >> EXT3_DESC_PER_BLOCK_BITS(inode->i_sb);
108         desc = block_group & (EXT3_DESC_PER_BLOCK(inode->i_sb) - 1);
109 -       bh = inode->i_sb->u.ext3_sb.s_group_desc[group_desc];
110 -       if (!bh) {
111 +       if (!(inode->i_sb->u.ext3_sb.s_group_desc[group_desc])) {
112                 ext3_error (inode->i_sb, "ext3_get_inode_loc",
113                             "Descriptor not loaded");
114                 goto bad_inode;
115         }
116  
117 -       gdp = (struct ext3_group_desc *) bh->b_data;
118 +       gdp = (struct ext3_group_desc *)(inode->i_sb->u.ext3_sb.s_group_desc[group_desc]->b_data);
119         /*
120          * Figure out the offset within the block group inode table
121          */
122 -       offset = ((inode->i_ino - 1) % EXT3_INODES_PER_GROUP(inode->i_sb)) *
123 -               EXT3_INODE_SIZE(inode->i_sb);
124 +       offset = ((inode->i_ino - 1) % EXT3_INODES_PER_GROUP(inode->i_sb));
125 +
126         block = le32_to_cpu(gdp[desc].bg_inode_table) +
127 -               (offset >> EXT3_BLOCK_SIZE_BITS(inode->i_sb));
128 -       if (!(bh = sb_bread(inode->i_sb, block))) {
129 -               ext3_error (inode->i_sb, "ext3_get_inode_loc",
130 -                           "unable to read inode block - "
131 -                           "inode=%lu, block=%lu", inode->i_ino, block);
132 -               goto bad_inode;
133 -       }
134 -       offset &= (EXT3_BLOCK_SIZE(inode->i_sb) - 1);
135 +               (offset * EXT3_INODE_SIZE(inode->i_sb) >> EXT3_BLOCK_SIZE_BITS(inode->i_sb));
136  
137 -       iloc->bh = bh;
138 -       iloc->raw_inode = (struct ext3_inode *) (bh->b_data + offset);
139 +       bh[0] = sb_getblk(inode->i_sb, block);
140 +       if (buffer_uptodate(bh[0]))
141 +               goto done;
142 +
143 +       /* If we don't really need to read this block, and it isn't already
144 +        * in memory, then we just zero it out.  Otherwise, we keep the
145 +        * current block contents (deleted inode data) for posterity.
146 +        */
147 +       if (new && !ext3_itable_block_used(inode->i_sb, block_group, offset)) {
148 +               lock_buffer(bh[0]);
149 +               memset(bh[0]->b_data, 0, bh[0]->b_size);
150 +               mark_buffer_uptodate(bh[0], 1);
151 +               unlock_buffer(bh[0]);
152 +       } else {
153 +               unsigned long block_end, itable_end;
154 +               int count = 1;
155 +
156 +               itable_end = le32_to_cpu(gdp[desc].bg_inode_table) +
157 +                               inode->i_sb->u.ext3_sb.s_itb_per_group;
158 +               block_end = block + NUM_INODE_PREREAD;
159 +               if (block_end > itable_end)
160 +                       block_end = itable_end;
161 +
162 +               for (++block; block < block_end; block++) {
163 +                       bh[count] = sb_getblk(inode->i_sb, block);
164 +                       if (count && (buffer_uptodate(bh[count]) ||
165 +                                     buffer_locked(bh[count]))) {
166 +                               __brelse(bh[count]);
167 +                       } else
168 +                               count++;
169 +               }
170 +
171 +               ll_rw_block(READ, count, bh);
172 +
173 +               /* Release all but the block we actually need (bh[0]) */
174 +               while (--count > 0)
175 +                       __brelse(bh[count]);
176 +
177 +               wait_on_buffer(bh[0]);
178 +               if (!buffer_uptodate(bh[0])) {
179 +                       ext3_error(inode->i_sb, __FUNCTION__,
180 +                                  "unable to read inode block - "
181 +                                  "inode=%lu, block=%lu", inode->i_ino,
182 +                                  bh[0]->b_blocknr);
183 +                       goto bad_inode;
184 +               }
185 +       }
186 +done:
187 +       offset = (offset * EXT3_INODE_SIZE(inode->i_sb)) & (EXT3_BLOCK_SIZE(inode->i_sb) - 1);
188 +
189 +       iloc->bh = bh[0];
190 +       iloc->raw_inode = (struct ext3_inode *)(bh[0]->b_data + offset);
191         iloc->block_group = block_group;
192         
193         return 0;
194 @@ -2078,6 +2125,11 @@ int ext3_get_inode_loc (struct inode *in
195         return -EIO;
196  }
197  
198 +int ext3_get_inode_loc(struct inode *inode, struct ext3_iloc *iloc)
199 +{
200 +       return ext3_get_inode_loc_new(inode, iloc, 0);
201 +}
202 +
203  void ext3_read_inode(struct inode * inode)
204  {
205         struct ext3_iloc iloc;
206 --- linux-2.4.20/include/linux/ext3_fs.h~ext3-noread-2.4.20     2003-05-16 12:21:39.000000000 +0800
207 +++ linux-2.4.20-root/include/linux/ext3_fs.h   2003-05-16 12:21:46.000000000 +0800
208 @@ -683,6 +683,8 @@ extern int ext3_forget(handle_t *, int, 
209  extern struct buffer_head * ext3_getblk (handle_t *, struct inode *, long, int, int *);
210  extern struct buffer_head * ext3_bread (handle_t *, struct inode *, int, int, int *);
211  
212 +extern int ext3_itable_block_used(struct super_block *sb, unsigned int, int);
213 +extern int ext3_get_inode_loc_new(struct inode *, struct ext3_iloc *, int);
214  extern int  ext3_get_inode_loc (struct inode *, struct ext3_iloc *);
215  extern void ext3_read_inode (struct inode *);
216  extern void ext3_write_inode (struct inode *, int);
217
218 _