ext4: ignore errors when issuing discards

This is an effective revert of commit a30eec2a8: "ext4: stop issuing
discards if not supported by device".  The problem is that there are
some devices that may return errors in response to a discard request
some times but not others.  (One example would be a hybrid dm device
which concatenates an SSD and an HDD device).

By this logic, I also removed the error checking from ext4's FITRIM
code; so that an error from a discard will not stop the FITRIM from
trying to trim the rest of the file system.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
This commit is contained in:
Theodore Ts'o 2011-04-30 13:47:24 -04:00
parent 39db00f1c4
commit d9f34504e6

View File

@ -2661,7 +2661,7 @@ static void release_blocks_on_commit(journal_t *journal, transaction_t *txn)
struct super_block *sb = journal->j_private; struct super_block *sb = journal->j_private;
struct ext4_buddy e4b; struct ext4_buddy e4b;
struct ext4_group_info *db; struct ext4_group_info *db;
int err, ret, count = 0, count2 = 0; int err, count = 0, count2 = 0;
struct ext4_free_data *entry; struct ext4_free_data *entry;
struct list_head *l, *ltmp; struct list_head *l, *ltmp;
@ -2671,15 +2671,9 @@ static void release_blocks_on_commit(journal_t *journal, transaction_t *txn)
mb_debug(1, "gonna free %u blocks in group %u (0x%p):", mb_debug(1, "gonna free %u blocks in group %u (0x%p):",
entry->count, entry->group, entry); entry->count, entry->group, entry);
if (test_opt(sb, DISCARD)) { if (test_opt(sb, DISCARD))
ret = ext4_issue_discard(sb, entry->group, ext4_issue_discard(sb, entry->group,
entry->start_blk, entry->count); entry->start_blk, entry->count);
if (unlikely(ret == -EOPNOTSUPP)) {
ext4_warning(sb, "discard not supported, "
"disabling");
clear_opt(sb, DISCARD);
}
}
err = ext4_mb_load_buddy(sb, entry->group, &e4b); err = ext4_mb_load_buddy(sb, entry->group, &e4b);
/* we expect to find existing buddy because it's pinned */ /* we expect to find existing buddy because it's pinned */
@ -4717,11 +4711,10 @@ error_return:
* one will allocate those blocks, mark it as used in buddy bitmap. This must * one will allocate those blocks, mark it as used in buddy bitmap. This must
* be called with under the group lock. * be called with under the group lock.
*/ */
static int ext4_trim_extent(struct super_block *sb, int start, int count, static void ext4_trim_extent(struct super_block *sb, int start, int count,
ext4_group_t group, struct ext4_buddy *e4b) ext4_group_t group, struct ext4_buddy *e4b)
{ {
struct ext4_free_extent ex; struct ext4_free_extent ex;
int ret = 0;
assert_spin_locked(ext4_group_lock_ptr(sb, group)); assert_spin_locked(ext4_group_lock_ptr(sb, group));
@ -4735,12 +4728,9 @@ static int ext4_trim_extent(struct super_block *sb, int start, int count,
*/ */
mb_mark_used(e4b, &ex); mb_mark_used(e4b, &ex);
ext4_unlock_group(sb, group); ext4_unlock_group(sb, group);
ext4_issue_discard(sb, group, start, count);
ret = ext4_issue_discard(sb, group, start, count);
ext4_lock_group(sb, group); ext4_lock_group(sb, group);
mb_free_blocks(NULL, e4b, start, ex.fe_len); mb_free_blocks(NULL, e4b, start, ex.fe_len);
return ret;
} }
/** /**
@ -4768,7 +4758,6 @@ ext4_trim_all_free(struct super_block *sb, struct ext4_buddy *e4b,
void *bitmap; void *bitmap;
ext4_grpblk_t next, count = 0; ext4_grpblk_t next, count = 0;
ext4_group_t group; ext4_group_t group;
int ret = 0;
BUG_ON(e4b == NULL); BUG_ON(e4b == NULL);
@ -4785,10 +4774,8 @@ ext4_trim_all_free(struct super_block *sb, struct ext4_buddy *e4b,
next = mb_find_next_bit(bitmap, max, start); next = mb_find_next_bit(bitmap, max, start);
if ((next - start) >= minblocks) { if ((next - start) >= minblocks) {
ret = ext4_trim_extent(sb, start, ext4_trim_extent(sb, start,
next - start, group, e4b); next - start, group, e4b);
if (ret < 0)
break;
count += next - start; count += next - start;
} }
start = next + 1; start = next + 1;
@ -4812,9 +4799,6 @@ ext4_trim_all_free(struct super_block *sb, struct ext4_buddy *e4b,
ext4_debug("trimmed %d blocks in the group %d\n", ext4_debug("trimmed %d blocks in the group %d\n",
count, group); count, group);
if (ret < 0)
count = ret;
return count; return count;
} }