Add Jan Kara's ext4 data corruption bugs for blocksize < pagesize
[ext4-patch-queue.git] / fold-__wait_cp_io-into-jbd2_log_do_checkpoint
blob7e320cf14b577f2ff05081edc8936d6bb97e1479
1 jbd2: fold __wait_cp_io into jbd2_log_do_checkpoint()
3 __wait_cp_io() is only called by jbd2_log_do_checkpoint().  Fold it in
4 to make it a bit easier to understand.
6 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
7 ---
8  fs/jbd2/checkpoint.c | 87 +++++++++++++++++++++++++++++++--------------------------------------------------------
9  1 file changed, 31 insertions(+), 56 deletions(-)
11 diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c
12 index 993a187..22fcd50 100644
13 --- a/fs/jbd2/checkpoint.c
14 +++ b/fs/jbd2/checkpoint.c
15 @@ -183,58 +183,6 @@ void __jbd2_log_wait_for_space(journal_t *journal)
16         }
17  }
19 -/*
20 - * Clean up transaction's list of buffers submitted for io.
21 - * We wait for any pending IO to complete and remove any clean
22 - * buffers. Note that we take the buffers in the opposite ordering
23 - * from the one in which they were submitted for IO.
24 - *
25 - * Return 0 on success, and return <0 if some buffers have failed
26 - * to be written out.
27 - *
28 - * Called with j_list_lock held.
29 - */
30 -static int __wait_cp_io(journal_t *journal, transaction_t *transaction)
32 -       struct journal_head *jh;
33 -       struct buffer_head *bh;
34 -       tid_t this_tid;
35 -       int released = 0;
36 -       int ret = 0;
38 -       this_tid = transaction->t_tid;
39 -restart:
40 -       /* Did somebody clean up the transaction in the meanwhile? */
41 -       if (journal->j_checkpoint_transactions != transaction ||
42 -                       transaction->t_tid != this_tid)
43 -               return ret;
44 -       while (!released && transaction->t_checkpoint_io_list) {
45 -               jh = transaction->t_checkpoint_io_list;
46 -               bh = jh2bh(jh);
47 -               get_bh(bh);
48 -               if (buffer_locked(bh)) {
49 -                       spin_unlock(&journal->j_list_lock);
50 -                       wait_on_buffer(bh);
51 -                       /* the journal_head may have gone by now */
52 -                       BUFFER_TRACE(bh, "brelse");
53 -                       __brelse(bh);
54 -                       spin_lock(&journal->j_list_lock);
55 -                       goto restart;
56 -               }
57 -               if (unlikely(buffer_write_io_error(bh)))
58 -                       ret = -EIO;
60 -               /*
61 -                * Now in whatever state the buffer currently is, we know that
62 -                * it has been written out and so we can drop it from the list
63 -                */
64 -               released = __jbd2_journal_remove_checkpoint(jh);
65 -               __brelse(bh);
66 -       }
68 -       return ret;
71  static void
72  __flush_batch(journal_t *journal, int *batch_count)
73  {
74 @@ -268,7 +216,7 @@ int jbd2_log_do_checkpoint(journal_t *journal)
75         struct buffer_head      *bh;
76         transaction_t           *transaction;
77         tid_t                   this_tid;
78 -       int                     err, result, batch_count = 0;
79 +       int                     result, batch_count = 0, done = 0;
81         jbd_debug(1, "Start checkpoint\n");
83 @@ -384,9 +332,36 @@ restart:
84          * Now we issued all of the transaction's buffers, let's deal
85          * with the buffers that are out for I/O.
86          */
87 -       err = __wait_cp_io(journal, transaction);
88 -       if (!result)
89 -               result = err;
90 +restart2:
91 +       /* Did somebody clean up the transaction in the meanwhile? */
92 +       if (journal->j_checkpoint_transactions != transaction ||
93 +           transaction->t_tid != this_tid)
94 +               goto out;
96 +       while (!done && transaction->t_checkpoint_io_list) {
97 +               jh = transaction->t_checkpoint_io_list;
98 +               bh = jh2bh(jh);
99 +               get_bh(bh);
100 +               if (buffer_locked(bh)) {
101 +                       spin_unlock(&journal->j_list_lock);
102 +                       wait_on_buffer(bh);
103 +                       /* the journal_head may have gone by now */
104 +                       BUFFER_TRACE(bh, "brelse");
105 +                       __brelse(bh);
106 +                       spin_lock(&journal->j_list_lock);
107 +                       goto restart2;
108 +               }
109 +               if (unlikely(buffer_write_io_error(bh)) && !result)
110 +                       result = -EIO;
112 +               /*
113 +                * Now in whatever state the buffer currently is, we
114 +                * know that it has been written out and so we can
115 +                * drop it from the list
116 +                */
117 +               done = __jbd2_journal_remove_checkpoint(jh);
118 +               __brelse(bh);
119 +       }
120  out:
121         spin_unlock(&journal->j_list_lock);
122         if (result < 0)