int ret;
        struct btrfs_device *dev;
        unsigned int nofs_flag;
+       bool need_commit = false;
 
        if (btrfs_fs_closing(fs_info))
                return -EAGAIN;
         */
        nofs_flag = memalloc_nofs_save();
        if (!is_dev_replace) {
+               u64 old_super_errors;
+
+               spin_lock(&sctx->stat_lock);
+               old_super_errors = sctx->stat.super_errors;
+               spin_unlock(&sctx->stat_lock);
+
                btrfs_info(fs_info, "scrub: started on devid %llu", devid);
                /*
                 * by holding device list mutex, we can
                mutex_lock(&fs_info->fs_devices->device_list_mutex);
                ret = scrub_supers(sctx, dev);
                mutex_unlock(&fs_info->fs_devices->device_list_mutex);
+
+               spin_lock(&sctx->stat_lock);
+               /*
+                * Super block errors found, but we can not commit transaction
+                * at current context, since btrfs_commit_transaction() needs
+                * to pause the current running scrub (hold by ourselves).
+                */
+               if (sctx->stat.super_errors > old_super_errors && !sctx->readonly)
+                       need_commit = true;
+               spin_unlock(&sctx->stat_lock);
        }
 
        if (!ret)
        scrub_workers_put(fs_info);
        scrub_put_ctx(sctx);
 
+       /*
+        * We found some super block errors before, now try to force a
+        * transaction commit, as scrub has finished.
+        */
+       if (need_commit) {
+               struct btrfs_trans_handle *trans;
+
+               trans = btrfs_start_transaction(fs_info->tree_root, 0);
+               if (IS_ERR(trans)) {
+                       ret = PTR_ERR(trans);
+                       btrfs_err(fs_info,
+       "scrub: failed to start transaction to fix super block errors: %d", ret);
+                       return ret;
+               }
+               ret = btrfs_commit_transaction(trans);
+               if (ret < 0)
+                       btrfs_err(fs_info,
+       "scrub: failed to commit transaction to fix super block errors: %d", ret);
+       }
        return ret;
 out:
        scrub_workers_put(fs_info);