Skip to content

Commit

Permalink
jbd2: simplify code flow in do_get_write_access()
Browse files Browse the repository at this point in the history
needs_copy is set only in one place in do_get_write_access(), just move
the frozen buffer copying into that place and factor it out to a
separate function to make do_get_write_access() slightly more readable.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
  • Loading branch information
Jan Kara authored and Theodore Ts'o committed Jun 8, 2015
1 parent b4ab9e2 commit ee57aba
Showing 1 changed file with 25 additions and 24 deletions.
49 changes: 25 additions & 24 deletions fs/jbd2/transaction.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,30 @@ static void warn_dirty_buffer(struct buffer_head *bh)
bdevname(bh->b_bdev, b), (unsigned long long)bh->b_blocknr);
}

/* Call t_frozen trigger and copy buffer data into jh->b_frozen_data. */
static void jbd2_freeze_jh_data(struct journal_head *jh)
{
struct page *page;
int offset;
char *source;
struct buffer_head *bh = jh2bh(jh);

J_EXPECT_JH(jh, buffer_uptodate(bh), "Possible IO failure.\n");
page = bh->b_page;
offset = offset_in_page(bh->b_data);
source = kmap_atomic(page);
/* Fire data frozen trigger just before we copy the data */
jbd2_buffer_frozen_trigger(jh, source + offset, jh->b_triggers);
memcpy(jh->b_frozen_data, source + offset, bh->b_size);
kunmap_atomic(source);

/*
* Now that the frozen data is saved off, we need to store any matching
* triggers.
*/
jh->b_frozen_triggers = jh->b_triggers;
}

/*
* If the buffer is already part of the current transaction, then there
* is nothing we need to do. If it is already part of a prior
Expand All @@ -774,7 +798,6 @@ do_get_write_access(handle_t *handle, struct journal_head *jh,
journal_t *journal;
int error;
char *frozen_buffer = NULL;
int need_copy = 0;
unsigned long start_lock, time_lock;

if (is_handle_aborted(handle))
Expand Down Expand Up @@ -931,7 +954,7 @@ do_get_write_access(handle_t *handle, struct journal_head *jh,
}
jh->b_frozen_data = frozen_buffer;
frozen_buffer = NULL;
need_copy = 1;
jbd2_freeze_jh_data(jh);
}
jh->b_next_transaction = transaction;
}
Expand All @@ -952,28 +975,6 @@ do_get_write_access(handle_t *handle, struct journal_head *jh,
}

done:
if (need_copy) {
struct page *page;
int offset;
char *source;

J_EXPECT_JH(jh, buffer_uptodate(jh2bh(jh)),
"Possible IO failure.\n");
page = jh2bh(jh)->b_page;
offset = offset_in_page(jh2bh(jh)->b_data);
source = kmap_atomic(page);
/* Fire data frozen trigger just before we copy the data */
jbd2_buffer_frozen_trigger(jh, source + offset,
jh->b_triggers);
memcpy(jh->b_frozen_data, source+offset, jh2bh(jh)->b_size);
kunmap_atomic(source);

/*
* Now that the frozen data is saved off, we need to store
* any matching triggers.
*/
jh->b_frozen_triggers = jh->b_triggers;
}
jbd_unlock_bh_state(bh);

/*
Expand Down

0 comments on commit ee57aba

Please sign in to comment.