add patch more-simplifications-in-do_get_write_access
[ext4-patch-queue.git] / simplify-code-flow-in-do_get_write_access
blobb3fc81cfca90d8317200a93a9a87a99eaaa7fa4e
1 jbd2: simplify code flow in do_get_write_access()
3 From: Jan Kara <jack@suse.cz>
5 needs_copy is set only in one place in do_get_write_access(), just move
6 the frozen buffer copying into that place and factor it out to a
7 separate function to make do_get_write_access() slightly more readable.
9 Signed-off-by: Jan Kara <jack@suse.cz>
10 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
11 ---
12  fs/jbd2/transaction.c | 49 +++++++++++++++++++++++++------------------------
13  1 file changed, 25 insertions(+), 24 deletions(-)
15 diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
16 index 5f09370c90a8..2b75f0f109be 100644
17 --- a/fs/jbd2/transaction.c
18 +++ b/fs/jbd2/transaction.c
19 @@ -763,6 +763,30 @@ static void warn_dirty_buffer(struct buffer_head *bh)
20                bdevname(bh->b_bdev, b), (unsigned long long)bh->b_blocknr);
21  }
23 +/* Call t_frozen trigger and copy buffer data into jh->b_frozen_data. */
24 +static void jbd2_freeze_jh_data(struct journal_head *jh)
26 +       struct page *page;
27 +       int offset;
28 +       char *source;
29 +       struct buffer_head *bh = jh2bh(jh);
31 +       J_EXPECT_JH(jh, buffer_uptodate(bh), "Possible IO failure.\n");
32 +       page = bh->b_page;
33 +       offset = offset_in_page(bh->b_data);
34 +       source = kmap_atomic(page);
35 +       /* Fire data frozen trigger just before we copy the data */
36 +       jbd2_buffer_frozen_trigger(jh, source + offset, jh->b_triggers);
37 +       memcpy(jh->b_frozen_data, source + offset, bh->b_size);
38 +       kunmap_atomic(source);
40 +       /*
41 +        * Now that the frozen data is saved off, we need to store any matching
42 +        * triggers.
43 +        */
44 +       jh->b_frozen_triggers = jh->b_triggers;
47  /*
48   * If the buffer is already part of the current transaction, then there
49   * is nothing we need to do.  If it is already part of a prior
50 @@ -782,7 +806,6 @@ do_get_write_access(handle_t *handle, struct journal_head *jh,
51         journal_t *journal;
52         int error;
53         char *frozen_buffer = NULL;
54 -       int need_copy = 0;
55         unsigned long start_lock, time_lock;
57         WARN_ON(!transaction);
58 @@ -940,7 +963,7 @@ repeat:
59                         }
60                         jh->b_frozen_data = frozen_buffer;
61                         frozen_buffer = NULL;
62 -                       need_copy = 1;
63 +                       jbd2_freeze_jh_data(jh);
64                 }
65                 jh->b_next_transaction = transaction;
66         }
67 @@ -961,28 +984,6 @@ repeat:
68         }
70  done:
71 -       if (need_copy) {
72 -               struct page *page;
73 -               int offset;
74 -               char *source;
76 -               J_EXPECT_JH(jh, buffer_uptodate(jh2bh(jh)),
77 -                           "Possible IO failure.\n");
78 -               page = jh2bh(jh)->b_page;
79 -               offset = offset_in_page(jh2bh(jh)->b_data);
80 -               source = kmap_atomic(page);
81 -               /* Fire data frozen trigger just before we copy the data */
82 -               jbd2_buffer_frozen_trigger(jh, source + offset,
83 -                                          jh->b_triggers);
84 -               memcpy(jh->b_frozen_data, source+offset, jh2bh(jh)->b_size);
85 -               kunmap_atomic(source);
87 -               /*
88 -                * Now that the frozen data is saved off, we need to store
89 -                * any matching triggers.
90 -                */
91 -               jh->b_frozen_triggers = jh->b_triggers;
92 -       }
93         jbd_unlock_bh_state(bh);
95         /*
96 -- 
97 2.1.4