From 7fc461d68ef30df5819b889e35e4b0d131ebf6d1 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 22 Sep 2003 11:45:59 +0000 Subject: [PATCH] - few bugs fixed - additional asserts added NOTE: those fixes need to be pushed in the another series --- .../patches/ext3-extents-2.4.18-chaos.patch | 154 +++++++++++++-------- 1 file changed, 99 insertions(+), 55 deletions(-) diff --git a/lustre/kernel_patches/patches/ext3-extents-2.4.18-chaos.patch b/lustre/kernel_patches/patches/ext3-extents-2.4.18-chaos.patch index faafe7b..b7aaa9e 100644 --- a/lustre/kernel_patches/patches/ext3-extents-2.4.18-chaos.patch +++ b/lustre/kernel_patches/patches/ext3-extents-2.4.18-chaos.patch @@ -1,16 +1,16 @@ fs/ext3/Makefile | 3 - fs/ext3/extents.c | 1572 +++++++++++++++++++++++++++++++++++++++++++++ + fs/ext3/extents.c | 1616 +++++++++++++++++++++++++++++++++++++++++++++ fs/ext3/ialloc.c | 4 fs/ext3/inode.c | 30 fs/ext3/super.c | 8 include/linux/ext3_fs.h | 18 include/linux/ext3_fs_i.h | 4 include/linux/ext3_fs_sb.h | 10 - 8 files changed, 1641 insertions(+), 8 deletions(-) + 8 files changed, 1685 insertions(+), 8 deletions(-) --- /dev/null 2003-01-30 13:24:37.000000000 +0300 -+++ linux-2.4.18-chaos-alexey/fs/ext3/extents.c 2003-09-15 10:57:24.000000000 +0400 -@@ -0,0 +1,1572 @@ ++++ linux-2.4.18-chaos-alexey/fs/ext3/extents.c 2003-09-22 15:45:03.000000000 +0400 +@@ -0,0 +1,1616 @@ +/* + * + * linux/fs/ext3/extents.c @@ -292,7 +292,7 @@ + struct ext3_extent_idx *ix; + struct buffer_head *bh; + struct ext3_extent *ex; -+ int depth, i, k, ppos = 0; ++ int depth, i, k, ppos = 0, prev = 0; + + eh = (struct ext3_extent_header *) ei->i_data; + @@ -316,14 +316,19 @@ + ext_debug(inode, "depth %d: num %d, max %d\n", + ppos, eh->e_num, eh->e_max); + ix = EXT_FIRST_INDEX(eh); -+ if (eh->e_num) ++ if (eh->e_num) { ++ EXT_ASSERT(ppos == 0 || ix->e_block == prev); + path[ppos].p_idx = ix; ++ } + EXT_ASSERT(eh->e_num <= eh->e_max); + for (k = 0; k < eh->e_num; k++, ix++) { + ext_debug(inode, "index: %d -> %d\n", + ix->e_block, ix->e_leaf); ++ EXT_ASSERT((k == 0 && prev <= (int)ix->e_block) || ++ (k > 0 && prev < (int)ix->e_block)); + if (block < ix->e_block) + break; ++ prev = ix->e_block; + path[ppos].p_idx = ix; + } + path[ppos].p_block = path[ppos].p_idx->e_leaf; @@ -354,8 +359,12 @@ + path[ppos].p_ext = ex; + EXT_ASSERT(eh->e_num <= eh->e_max); + for (k = 0; k < eh->e_num; k++, ex++) { ++ EXT_ASSERT(ex->e_num < EXT3_BLOCKS_PER_GROUP(inode->i_sb)); ++ EXT_ASSERT((k == 0 && prev <= (int)ex->e_block) || ++ (k > 0 && prev < (int)ex->e_block)); + if (block < ex->e_block) + break; ++ prev = ex->e_block; + path[ppos].p_ext = ex; + } + @@ -466,6 +475,7 @@ + + /* if current leaf will be splitted, then we should use + * border from split point */ ++ + if (path[depth].p_ext != EXT_MAX_EXTENT(path[depth].p_hdr)) { + border = path[depth].p_ext[1].e_block; + ext_debug(inode, "leaf will be splitted." @@ -496,13 +506,15 @@ + memset(ablocks, 0, sizeof(long) * depth); + + /* allocate all needed blocks */ -+ ext_debug(inode, "allocate %d blocks for indexes and leaf\n", -+ depth - at); -+ ablocks[0] = newext->e_start++; -+ newext->e_num--; -+ for (a = 1; a < depth - at; a++) { -+ newblock = ext3_new_block(handle, inode, newext->e_start, -+ 0, 0, &err); ++ ext_debug(inode, "allocate %d blocks for indexes/leaf\n", depth - at); ++ newblock = 0; /* FIXME: something more sophisticated needed here */ ++ for (a = 0; newext->e_num > 0 && a < depth - at; a++) { ++ newblock = ablocks[a] = newext->e_start++; ++ newext->e_num--; ++ } ++ for (; a < depth - at; a++) { ++ newblock = ext3_new_block(handle, inode, ++ newblock + 1, 0, 0, &err); + if (newblock == 0) + goto cleanup; + ablocks[a] = newblock; @@ -599,10 +611,10 @@ + /* copy indexes */ + m = 0; + path[i].p_idx++; -+ EXT_ASSERT(EXT_MAX_INDEX(path[i].p_hdr) == -+ EXT_LAST_INDEX(path[i].p_hdr)); + ext_debug(inode, "cur 0x%p, last 0x%p\n", path[i].p_idx, + EXT_MAX_INDEX(path[i].p_hdr)); ++ EXT_ASSERT(EXT_MAX_INDEX(path[i].p_hdr) == ++ EXT_LAST_INDEX(path[i].p_hdr)); + while (path[i].p_idx <= + EXT_MAX_INDEX(path[i].p_hdr)) { + ext_debug(inode, "%d: move %d:%d in new index\n", @@ -637,7 +649,7 @@ + } + + /* insert new index */ -+ if (!err) ++ if (!err) + err = ext3_ext_insert_index(handle, inode, path + at, + border, newblock); + @@ -682,7 +694,16 @@ + * use already allocated by the called block for new root block + */ + newblock = newext->e_start++; -+ newext->e_num--; ++ if (newext->e_num == 0) { ++ /* ++ * FIXME: if this may happen, then we have to handle ++ * possible error and free allocated block ++ */ ++ printk("grow_indepth with zero blocks\n"); ++ newblock = ext3_new_block(handle, inode, ++ newblock, 0, 0, &err); ++ } else ++ newext->e_num--; + + bh = sb_getblk(inode->i_sb, newblock); + if (!bh) { @@ -743,11 +764,13 @@ + struct ext3_ext_path *path, + struct ext3_extent *newext) +{ -+ int depth = EXT3_I(inode)->i_depth; -+ struct ext3_ext_path *curp; -+ int i = depth, err = 0; + long newblock = newext->e_start; ++ struct ext3_ext_path *curp; ++ int depth, i, err = 0; + ++repeat: ++ i = depth = EXT3_I(inode)->i_depth; ++ + /* walk up to the tree and look for free index entry */ + curp = path + depth; + while (i > 0 && !EXT_HAS_FREE_INDEX(curp)) { @@ -761,31 +784,49 @@ + /* if we found index with free entry, then use that + * entry: create all needed subtree and add new leaf */ + err = ext3_ext_split(handle, inode, path, newext, i); ++ ++ /* refill path */ ++ ext3_ext_drop_refs(inode, path); ++ path = ext3_ext_find_extent(inode, newext->e_block, path); ++ if (IS_ERR(path)) ++ err = PTR_ERR(path); + } else { + /* tree is full, time to grow in depth */ + err = ext3_ext_grow_indepth(handle, inode, path, newext); -+ } + -+ if (!err) { + /* refill path */ + ext3_ext_drop_refs(inode, path); + path = ext3_ext_find_extent(inode, newext->e_block, path); + if (IS_ERR(path)) + err = PTR_ERR(path); -+ ++ + /* -+ * probably we've used some blocks from extent -+ * let's allocate new block for it ++ * only first (depth 0 -> 1) produces free space ++ * in all other cases we have to split growed tree + */ -+ if (newext->e_num == 0 && !err) { -+ newext->e_start = -+ ext3_new_block(handle, inode, newblock, -+ 0, 0, &err); -+ newext->e_num = 1; ++ depth = EXT3_I(inode)->i_depth; ++ if (path[depth].p_hdr->e_num == path[depth].p_hdr->e_max) { ++ /* now we need split */ ++ goto repeat; + } + } + -+ return err; ++ if (err) ++ return err; ++ ++ /* ++ * probably we've used some blocks from extent ++ * let's allocate new block for it ++ */ ++ if (newext->e_num == 0 && !err) { ++ newext->e_start = ++ ext3_new_block(handle, inode, newblock, ++ 0, 0, &err); ++ if (newext->e_start != 0) ++ newext->e_num = 1; ++ } ++ ++ return 0; +} + +/* @@ -882,6 +923,9 @@ + return 0; + } + ++ /* ++ * TODO: we need correction if border is smaller then current one ++ */ + k = depth - 1; + border = path[depth].p_ext->e_block; + if ((err = ext3_ext_get_access(handle, inode, path + k))) @@ -892,8 +936,7 @@ + + while (k--) { + /* change all left-side indexes */ -+ if (path[k].p_idx != EXT_FIRST_INDEX(path[k].p_hdr) -+ && k != 0) ++ if (path[k+1].p_idx != EXT_FIRST_INDEX(path[k+1].p_hdr)) + break; + if ((err = ext3_ext_get_access(handle, inode, path + k))) + break; @@ -986,9 +1029,7 @@ + ext_debug(inode, "first extent in the leaf: %d:%d:%d\n", + newext->e_block, newext->e_start, + newext->e_num); -+ eh->e_num++; + path[depth].p_ext = EXT_FIRST_EXTENT(eh); -+ + } else if (newext->e_block > nearex->e_block) { + EXT_ASSERT(newext->e_block != nearex->e_block); + len = EXT_MAX_EXTENT(eh) - nearex; @@ -1001,7 +1042,6 @@ + ext3_ext_check_boundary(inode, path + depth, nearex + 2, len); + memmove(nearex + 2, nearex + 1, len); + path[depth].p_ext = nearex + 1; -+ eh->e_num++; + } else { + EXT_ASSERT(newext->e_block != nearex->e_block); + len = (EXT_MAX_EXTENT(eh) - nearex) * sizeof(struct ext3_extent); @@ -1010,19 +1050,22 @@ + "move %d from 0x%p to 0x%p\n", + newext->e_block, newext->e_start, newext->e_num, + nearex, len, nearex + 1, nearex + 2); ++ + memmove(nearex + 1, nearex, len); + path[depth].p_ext = nearex; -+ eh->e_num++; -+ -+ /* time to correct all indexes above */ -+ err = ext3_ext_correct_indexes(handle, inode, path); + } + + if (!err) { ++ eh->e_num++; + nearex = path[depth].p_ext; + nearex->e_block = newext->e_block; + nearex->e_start = newext->e_start; + nearex->e_num = newext->e_num; ++ EXT_ASSERT(nearex->e_num < EXT3_BLOCKS_PER_GROUP(inode->i_sb) && ++ nearex->e_num > 0); ++ ++ /* time to correct all indexes above */ ++ err = ext3_ext_correct_indexes(handle, inode, path); + } + + err = ext3_ext_dirty(handle, inode, path + depth); @@ -1054,6 +1097,7 @@ + + /* find extent for this block */ + path = ext3_ext_find_extent(inode, iblock, NULL); ++ EXT_ASSERT(path); + if (IS_ERR(path)) { + err = PTR_ERR(path); + goto out2; @@ -1219,7 +1263,7 @@ + * extent couldn't cross group, so we will modify + * single bitmap block and single group descriptor + */ -+ needed = 2; ++ needed = 3; + + /* + * if this is last extent in a leaf, then we have to @@ -1231,7 +1275,7 @@ + */ + if (!path || (num == path->p_ext->e_num && + path->p_ext == EXT_FIRST_EXTENT(path->p_hdr))) -+ needed += (depth * EXT3_ALLOC_NEEDED) + 1; ++ needed += (depth * (EXT3_ALLOC_NEEDED + 1)) + 1; + + return needed; +} @@ -1583,8 +1627,8 @@ + sbi->s_ext_blocks / sbi->s_ext_extents); +} + ---- linux-2.4.18-chaos/fs/ext3/ialloc.c~ext3-extents-2.4.18-chaos 2003-09-14 17:32:15.000000000 +0400 -+++ linux-2.4.18-chaos-alexey/fs/ext3/ialloc.c 2003-09-15 10:57:24.000000000 +0400 +--- linux-2.4.18-chaos/fs/ext3/ialloc.c~ext3-extents-2.4.18-chaos 2003-09-19 22:07:14.000000000 +0400 ++++ linux-2.4.18-chaos-alexey/fs/ext3/ialloc.c 2003-09-20 00:18:43.000000000 +0400 @@ -573,6 +573,10 @@ repeat: ei->i_prealloc_count = 0; #endif @@ -1596,8 +1640,8 @@ if (ei->i_flags & EXT3_SYNC_FL) inode->i_flags |= S_SYNC; ---- linux-2.4.18-chaos/fs/ext3/inode.c~ext3-extents-2.4.18-chaos 2003-09-14 17:32:16.000000000 +0400 -+++ linux-2.4.18-chaos-alexey/fs/ext3/inode.c 2003-09-15 19:36:17.000000000 +0400 +--- linux-2.4.18-chaos/fs/ext3/inode.c~ext3-extents-2.4.18-chaos 2003-09-19 22:07:14.000000000 +0400 ++++ linux-2.4.18-chaos-alexey/fs/ext3/inode.c 2003-09-22 15:40:30.000000000 +0400 @@ -842,6 +842,15 @@ changed: goto reread; } @@ -1705,8 +1749,8 @@ if (rc) { printk(KERN_INFO "ext3_map_inode_page: error reading " "block %ld\n", iblock); ---- linux-2.4.18-chaos/fs/ext3/Makefile~ext3-extents-2.4.18-chaos 2003-09-14 17:32:15.000000000 +0400 -+++ linux-2.4.18-chaos-alexey/fs/ext3/Makefile 2003-09-15 10:57:24.000000000 +0400 +--- linux-2.4.18-chaos/fs/ext3/Makefile~ext3-extents-2.4.18-chaos 2003-09-19 22:07:14.000000000 +0400 ++++ linux-2.4.18-chaos-alexey/fs/ext3/Makefile 2003-09-20 00:18:43.000000000 +0400 @@ -12,7 +12,8 @@ O_TARGET := ext3.o export-objs := ext3-exports.o @@ -1717,8 +1761,8 @@ obj-m := $(O_TARGET) include $(TOPDIR)/Rules.make ---- linux-2.4.18-chaos/fs/ext3/super.c~ext3-extents-2.4.18-chaos 2003-09-14 17:32:16.000000000 +0400 -+++ linux-2.4.18-chaos-alexey/fs/ext3/super.c 2003-09-15 10:57:24.000000000 +0400 +--- linux-2.4.18-chaos/fs/ext3/super.c~ext3-extents-2.4.18-chaos 2003-09-19 22:07:15.000000000 +0400 ++++ linux-2.4.18-chaos-alexey/fs/ext3/super.c 2003-09-20 00:18:43.000000000 +0400 @@ -619,6 +619,7 @@ void ext3_put_super (struct super_block kdev_t j_dev = sbi->s_journal->j_dev; int i; @@ -1748,8 +1792,8 @@ return sb; ---- linux-2.4.18-chaos/include/linux/ext3_fs.h~ext3-extents-2.4.18-chaos 2003-09-14 17:32:15.000000000 +0400 -+++ linux-2.4.18-chaos-alexey/include/linux/ext3_fs.h 2003-09-15 10:57:24.000000000 +0400 +--- linux-2.4.18-chaos/include/linux/ext3_fs.h~ext3-extents-2.4.18-chaos 2003-09-19 22:07:14.000000000 +0400 ++++ linux-2.4.18-chaos-alexey/include/linux/ext3_fs.h 2003-09-20 00:18:43.000000000 +0400 @@ -183,6 +183,7 @@ struct ext3_group_desc #define EXT3_IMAGIC_FL 0x00002000 /* AFS directory */ #define EXT3_JOURNAL_DATA_FL 0x00004000 /* file data should be journaled */ @@ -1804,7 +1848,7 @@ #endif /* __KERNEL__ */ --- linux-2.4.18-chaos/include/linux/ext3_fs_i.h~ext3-extents-2.4.18-chaos 2001-11-22 22:46:19.000000000 +0300 -+++ linux-2.4.18-chaos-alexey/include/linux/ext3_fs_i.h 2003-09-15 10:57:24.000000000 +0400 ++++ linux-2.4.18-chaos-alexey/include/linux/ext3_fs_i.h 2003-09-20 00:18:43.000000000 +0400 @@ -73,6 +73,10 @@ struct ext3_inode_info { * by other means, so we have truncate_sem. */ @@ -1816,8 +1860,8 @@ }; #endif /* _LINUX_EXT3_FS_I */ ---- linux-2.4.18-chaos/include/linux/ext3_fs_sb.h~ext3-extents-2.4.18-chaos 2003-09-14 17:32:15.000000000 +0400 -+++ linux-2.4.18-chaos-alexey/include/linux/ext3_fs_sb.h 2003-09-15 10:57:24.000000000 +0400 +--- linux-2.4.18-chaos/include/linux/ext3_fs_sb.h~ext3-extents-2.4.18-chaos 2003-09-19 22:07:13.000000000 +0400 ++++ linux-2.4.18-chaos-alexey/include/linux/ext3_fs_sb.h 2003-09-20 00:18:43.000000000 +0400 @@ -84,6 +84,16 @@ struct ext3_sb_info { wait_queue_head_t s_delete_thread_queue; wait_queue_head_t s_delete_waiter_queue; -- 1.8.3.1