From 4b44dd300d5bfd500f170bae13f95f589de0b28f Mon Sep 17 00:00:00 2001 From: Tao Ma Date: Fri, 21 Jan 2011 10:52:56 +0800 Subject: ext3: Adjust trim start with first_data_block. As we have make the consense in the e-mail[1], the trim start should be added with first_data_block. So this patch fulfill it and remove the check for start < first_data_block. [1] http://www.spinics.net/lists/linux-ext4/msg22737.html Cc: Jan Kara Cc: Lukas Czerner Signed-off-by: Tao Ma Signed-off-by: Jan Kara --- fs/ext3/balloc.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'fs/ext3') diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c index 045995c8ce5..5b8344fab79 100644 --- a/fs/ext3/balloc.c +++ b/fs/ext3/balloc.c @@ -2090,7 +2090,8 @@ int ext3_trim_fs(struct super_block *sb, struct fstrim_range *range) ext3_fsblk_t max_blks = le32_to_cpu(es->s_blocks_count); int ret = 0; - start = range->start >> sb->s_blocksize_bits; + start = (range->start >> sb->s_blocksize_bits) + + le32_to_cpu(es->s_first_data_block); len = range->len >> sb->s_blocksize_bits; minlen = range->minlen >> sb->s_blocksize_bits; trimmed = 0; @@ -2099,10 +2100,6 @@ int ext3_trim_fs(struct super_block *sb, struct fstrim_range *range) return -EINVAL; if (start >= max_blks) goto out; - if (start < le32_to_cpu(es->s_first_data_block)) { - len -= le32_to_cpu(es->s_first_data_block) - start; - start = le32_to_cpu(es->s_first_data_block); - } if (start + len > max_blks) len = max_blks - start; -- cgit v1.2.3 From bbac751dc85cbf0953a221171a746d69a0b1a85f Mon Sep 17 00:00:00 2001 From: Tao Ma Date: Fri, 21 Jan 2011 22:09:20 +0800 Subject: ext3: speed up group trim with the right free block count. When we trim some free blocks in a group of ext3, we should calculate the free blocks properly and check whether there are enough freed blocks left for us to trim. Current solution will only calculate free spaces if they are large for a trim which is wrong. Let us see a small example: a group has 1.5M free which are 300k, 300k, 300k, 300k, 300k. And minblocks is 1M. With current solution, we have to iterate the whole group since these 300k will never be subtracted from 1.5M. But actually we should exit after we find the first 2 free spaces since the left 3 chunks only sum up to 900K if we subtract the first 600K although they can't be trimed. Cc: Jan Kara Cc: Lukas Czerner Signed-off-by: Tao Ma Signed-off-by: Jan Kara --- fs/ext3/balloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'fs/ext3') diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c index 5b8344fab79..db1906b4e39 100644 --- a/fs/ext3/balloc.c +++ b/fs/ext3/balloc.c @@ -1991,6 +1991,7 @@ ext3_grpblk_t ext3_trim_all_free(struct super_block *sb, unsigned int group, spin_unlock(sb_bgl_lock(sbi, group)); percpu_counter_sub(&sbi->s_freeblocks_counter, next - start); + free_blocks -= next - start; /* Do not issue a TRIM on extents smaller than minblocks */ if ((next - start) < minblocks) goto free_extent; @@ -2040,7 +2041,7 @@ free_extent: cond_resched(); /* No more suitable extents */ - if ((free_blocks - count) < minblocks) + if (free_blocks < minblocks) break; } -- cgit v1.2.3 From ce654b37f87980d95f339080e4c3bdb2370bdf22 Mon Sep 17 00:00:00 2001 From: Amir Goldstein Date: Sat, 26 Feb 2011 22:40:19 +0200 Subject: ext3: skip orphan cleanup on rocompat fs Orphan cleanup is currently executed even if the file system has some number of unknown ROCOMPAT features, which deletes inodes and frees blocks, which could be very bad for some RO_COMPAT features. This patch skips the orphan cleanup if it contains readonly compatible features not known by this ext3 implementation, which would prevent the fs from being mounted (or remounted) readwrite. Signed-off-by: Amir Goldstein Signed-off-by: Jan Kara --- fs/ext3/super.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'fs/ext3') diff --git a/fs/ext3/super.c b/fs/ext3/super.c index 85c8cc8f247..0d62f29f213 100644 --- a/fs/ext3/super.c +++ b/fs/ext3/super.c @@ -1464,6 +1464,13 @@ static void ext3_orphan_cleanup (struct super_block * sb, return; } + /* Check if feature set allows readwrite operations */ + if (EXT3_HAS_RO_COMPAT_FEATURE(sb, ~EXT3_FEATURE_RO_COMPAT_SUPP)) { + ext3_msg(sb, KERN_INFO, "Skipping orphan cleanup due to " + "unknown ROCOMPAT features"); + return; + } + if (EXT3_SB(sb)->s_mount_state & EXT3_ERROR_FS) { if (es->s_last_orphan) jbd_debug(1, "Errors on filesystem, " -- cgit v1.2.3 From 425fa41072b7dce3d88f392b335e561a770aa6c3 Mon Sep 17 00:00:00 2001 From: Tao Ma Date: Thu, 3 Mar 2011 22:58:37 +0800 Subject: ext3: Fix an overflow in ext3_trim_fs. In a bs=4096 volume, if we call FITRIM with the following parameter as fstrim_range(start = 102400, len = 134144000, minlen = 10240), with the following code: if (len >= EXT3_BLOCKS_PER_GROUP(sb)) len -= (EXT3_BLOCKS_PER_GROUP(sb) - first_block); else last_block = first_block + len; So if len < EXT3_BLOCKS_PER_GROUP while first_block + len > EXT3_BLOCKS_PER_GROUP, last_block will be set to an overflow value which exceeds EXT3_BLOCKS_PER_GROUP. This patch fixes it and adjusts len and last_block accordingly. Cc: Lukas Czerner Cc: Jan Kara Signed-off-by: Tao Ma Signed-off-by: Jan Kara --- fs/ext3/balloc.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'fs/ext3') diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c index db1906b4e39..153242187fc 100644 --- a/fs/ext3/balloc.c +++ b/fs/ext3/balloc.c @@ -2127,10 +2127,15 @@ int ext3_trim_fs(struct super_block *sb, struct fstrim_range *range) if (free_blocks < minlen) continue; - if (len >= EXT3_BLOCKS_PER_GROUP(sb)) - len -= (EXT3_BLOCKS_PER_GROUP(sb) - first_block); - else + /* + * For all the groups except the last one, last block will + * always be EXT3_BLOCKS_PER_GROUP(sb), so we only need to + * change it for the last group in which case first_block + + * len < EXT3_BLOCKS_PER_GROUP(sb). + */ + if (first_block + len < EXT3_BLOCKS_PER_GROUP(sb)) last_block = first_block + len; + len -= last_block - first_block; ret = ext3_trim_all_free(sb, group, first_block, last_block, minlen); -- cgit v1.2.3 From d7433142b63d727b5a217c37b1a1468b116a9771 Mon Sep 17 00:00:00 2001 From: Eric Sandeen Date: Fri, 4 Mar 2011 16:04:08 -0600 Subject: ext3: Always set dx_node's fake_dirent explicitly. (crossport of 1f7bebb9e911d870fa8f997ddff838e82b5715ea by Andreas Schlick ) When ext3_dx_add_entry() has to split an index node, it has to ensure that name_len of dx_node's fake_dirent is also zero, because otherwise e2fsck won't recognise it as an intermediate htree node and consider the htree to be corrupted. CC: stable@kernel.org Signed-off-by: Eric Sandeen Signed-off-by: Jan Kara --- fs/ext3/namei.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'fs/ext3') diff --git a/fs/ext3/namei.c b/fs/ext3/namei.c index b27ba71810e..75c968eaf90 100644 --- a/fs/ext3/namei.c +++ b/fs/ext3/namei.c @@ -1540,8 +1540,8 @@ static int ext3_dx_add_entry(handle_t *handle, struct dentry *dentry, goto cleanup; node2 = (struct dx_node *)(bh2->b_data); entries2 = node2->entries; + memset(&node2->fake, 0, sizeof(struct fake_dirent)); node2->fake.rec_len = ext3_rec_len_to_disk(sb->s_blocksize); - node2->fake.inode = 0; BUFFER_TRACE(frame->bh, "get_write_access"); err = ext3_journal_get_write_access(handle, frame->bh); if (err) -- cgit v1.2.3