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(-)
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:
12 + * @block_group: block group of inode
13 + * @offset: relative offset of inode within @block_group
15 + * Check whether any of the inodes in this disk block are in use.
17 + * Caller must be holding superblock lock (group/bitmap read lock in future).
19 +int ext3_itable_block_used(struct super_block *sb, unsigned int block_group,
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;
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))
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;
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++;
57 inode->u.ext3_i.i_state = EXT3_STATE_NEW;
58 - err = ext3_mark_inode_dirty(handle, inode);
60 + err = ext3_get_inode_loc_new(inode, &iloc, 1);
62 + BUFFER_TRACE(iloc->bh, "get_write_access");
63 + err = ext3_journal_get_write_access(handle, iloc.bh);
69 + err = ext3_mark_iloc_dirty(handle, inode, &iloc);
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);
83 - * ext3_get_inode_loc returns with an extra refcount against the
84 - * inode's underlying buffer_head on success.
87 -int ext3_get_inode_loc (struct inode *inode, struct ext3_iloc *iloc)
88 +#define NUM_INODE_PREREAD 16
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.
98 +int ext3_get_inode_loc_new(struct inode *inode, struct ext3_iloc *iloc, int new)
100 - struct buffer_head *bh = 0;
101 + struct buffer_head *bh[NUM_INODE_PREREAD];
103 unsigned long block_group;
104 unsigned long group_desc;
105 @@ -2045,31 +2050,73 @@ int ext3_get_inode_loc (struct inode *in
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];
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");
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);
120 * Figure out the offset within the block group inode table
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));
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);
134 - offset &= (EXT3_BLOCK_SIZE(inode->i_sb) - 1);
135 + (offset * EXT3_INODE_SIZE(inode->i_sb) >> EXT3_BLOCK_SIZE_BITS(inode->i_sb));
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]))
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.
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]);
153 + unsigned long block_end, itable_end;
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;
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]);
171 + ll_rw_block(READ, count, bh);
173 + /* Release all but the block we actually need (bh[0]) */
174 + while (--count > 0)
175 + __brelse(bh[count]);
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,
187 + offset = (offset * EXT3_INODE_SIZE(inode->i_sb)) & (EXT3_BLOCK_SIZE(inode->i_sb) - 1);
190 + iloc->raw_inode = (struct ext3_inode *)(bh[0]->b_data + offset);
191 iloc->block_group = block_group;
194 @@ -2078,6 +2125,11 @@ int ext3_get_inode_loc (struct inode *in
198 +int ext3_get_inode_loc(struct inode *inode, struct ext3_iloc *iloc)
200 + return ext3_get_inode_loc_new(inode, iloc, 0);
203 void ext3_read_inode(struct inode * inode)
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 *);
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);