Merge tag 'block-6.1-2022-11-18' of git://git.kernel.dk/linux
[platform/kernel/linux-rpi.git] / drivers / md / dm-integrity.c
index e1e7b20..e97e9f9 100644 (file)
@@ -263,6 +263,7 @@ struct dm_integrity_c {
 
        struct completion crypto_backoff;
 
+       bool wrote_to_journal;
        bool journal_uptodate;
        bool just_formatted;
        bool recalculate_flag;
@@ -2375,6 +2376,8 @@ static void integrity_commit(struct work_struct *w)
        if (!commit_sections)
                goto release_flush_bios;
 
+       ic->wrote_to_journal = true;
+
        i = commit_start;
        for (n = 0; n < commit_sections; n++) {
                for (j = 0; j < ic->journal_section_entries; j++) {
@@ -2591,10 +2594,6 @@ static void integrity_writer(struct work_struct *w)
 
        unsigned prev_free_sectors;
 
-       /* the following test is not needed, but it tests the replay code */
-       if (unlikely(dm_post_suspending(ic->ti)) && !ic->meta_dev)
-               return;
-
        spin_lock_irq(&ic->endio_wait.lock);
        write_start = ic->committed_section;
        write_sections = ic->n_committed_sections;
@@ -3101,10 +3100,17 @@ static void dm_integrity_postsuspend(struct dm_target *ti)
        drain_workqueue(ic->commit_wq);
 
        if (ic->mode == 'J') {
-               if (ic->meta_dev)
-                       queue_work(ic->writer_wq, &ic->writer_work);
+               queue_work(ic->writer_wq, &ic->writer_work);
                drain_workqueue(ic->writer_wq);
                dm_integrity_flush_buffers(ic, true);
+               if (ic->wrote_to_journal) {
+                       init_journal(ic, ic->free_section,
+                                    ic->journal_sections - ic->free_section, ic->commit_seq);
+                       if (ic->free_section) {
+                               init_journal(ic, 0, ic->free_section,
+                                            next_commit_seq(ic->commit_seq));
+                       }
+               }
        }
 
        if (ic->mode == 'B') {
@@ -3132,6 +3138,8 @@ static void dm_integrity_resume(struct dm_target *ti)
 
        DEBUG_print("resume\n");
 
+       ic->wrote_to_journal = false;
+
        if (ic->provided_data_sectors != old_provided_data_sectors) {
                if (ic->provided_data_sectors > old_provided_data_sectors &&
                    ic->mode == 'B' &&