-+ ret = ext4_issue_discard(sb, entry->group,
-+ entry->start_blk, entry->count);
-+ if (unlikely(ret == -EOPNOTSUPP)) {
-+ ext4_warning(sb, "discard not supported, "
-+ "disabling");
- clear_opt(EXT4_SB(sb)->s_mount_opt, DISCARD);
- }
- }
-@@ -2620,7 +2629,7 @@ static void release_blocks_on_commit(jou
+- clear_opt(EXT4_SB(sb)->s_mount_opt, DISCARD);
+- }
+- }
++ if (test_opt(sb, DISCARD))
++ ext4_issue_discard(sb, entry->group,
++ entry->start_blk, entry->count);
+
+ err = ext4_mb_load_buddy(sb, entry->group, &e4b);
+ /* we expect to find existing buddy because it's pinned */
+@@ -2611,6 +2613,15 @@ static void release_blocks_on_commit(jou
+ rb_erase(&entry->node, &(db->bb_free_root));
+ mb_free_blocks(NULL, &e4b, entry->start_blk, entry->count);
+
++ /*
++ * Clear the trimmed flag for the group so that the next
++ * ext4_trim_fs can trim it.
++ * If the volume is mounted with -o discard, online discard
++ * is supported and the free blocks will be trimmed online.
++ */
++ if (!test_opt(sb, DISCARD))
++ EXT4_MB_GRP_CLEAR_TRIMMED(db);
++
+ if (!db->bb_free_root.rb_node) {
+ /* No more items in the per group rb tree
+ * balance refcounts from ext4_mb_free_metadata()
+@@ -2620,7 +2631,7 @@ static void release_blocks_on_commit(jou