37 #include <linux/time.h>
41 #include <linux/kernel.h>
42 #include <linux/errno.h>
43 #include <linux/fcntl.h>
44 #include <linux/stat.h>
45 #include <linux/string.h>
52 #include <linux/slab.h>
56 #define JOURNAL_LIST_ENTRY(h) (list_entry((h), struct reiserfs_journal_list, \
58 #define JOURNAL_WORK_ENTRY(h) (list_entry((h), struct reiserfs_journal_list, \
64 static int reiserfs_mounted_fs_count;
68 #define JOURNAL_TRANS_HALF 1018
75 #define BLOCK_FREED_HOLDER 3
77 #define BLOCK_NEEDS_FLUSH 4
78 #define BLOCK_DIRTIED 5
81 #define LIST_TOUCHED 1
83 #define LIST_COMMIT_PENDING 4
100 static int release_journal_dev(
struct super_block *super,
116 unsigned long nblocks,
int join);
130 static int reiserfs_clean_and_file_buffer(
struct buffer_head *bh)
133 clear_buffer_dirty(bh);
134 clear_buffer_journal_test(bh);
155 INIT_LIST_HEAD(&bn->
list);
175 bn = allocate_bitmap_node(sb);
182 static inline void free_bitmap_node(
struct super_block *sb,
196 static void allocate_bitmap_nodes(
struct super_block *sb)
202 bn = allocate_bitmap_node(sb);
212 static int set_bit_in_list_bitmap(
struct super_block *sb,
216 unsigned int bmap_nr = block / (sb->
s_blocksize << 3);
217 unsigned int bit_nr = block % (sb->
s_blocksize << 3);
220 jb->
bitmaps[bmap_nr] = get_bitmap_node(sb);
226 static void cleanup_bitmap_list(
struct super_block *sb,
233 for (i = 0; i < reiserfs_bmap_count(sb); i++) {
235 free_bitmap_node(sb, jb->
bitmaps[i]);
244 static int free_list_bitmaps(
struct super_block *sb,
252 cleanup_bitmap_list(sb, jb);
259 static int free_bitmap_nodes(
struct super_block *sb)
283 unsigned int bmap_nr)
296 "allocate bitmaps for journal lists");
302 free_list_bitmaps(sb, jb_array);
325 flush_commit_list(sb,
351 if (num_cnodes <= 0) {
359 head[0].
next = head + 1;
361 head[
i].
prev = head + (i - 1);
362 head[
i].
next = head + (i + 1);
416 static void clear_prepared_bits(
struct buffer_head *bh)
418 clear_buffer_journal_prepared(bh);
419 clear_buffer_journal_restore_dirty(bh);
460 unsigned int bmap_nr,
int bit_nr,
int search_all,
482 (
unsigned long *)jb->
bitmaps[bmap_nr]->
504 if ((cn = get_journal_hash_dev(sb, journal->
j_hash_table, bl))) {
531 static inline void lock_journal(
struct super_block *sb)
535 reiserfs_mutex_lock_safe(&
SB_JOURNAL(sb)->j_mutex, sb);
539 static inline void unlock_journal(
struct super_block *sb)
549 static inline void put_journal_list(
struct super_block *
s,
565 static void cleanup_freed_for_journal_list(
struct super_block *sb,
571 cleanup_bitmap_list(sb, jb);
577 static int journal_list_still_alive(
struct super_block *s,
584 if (!list_empty(entry)) {
603 static void release_buffer_page(
struct buffer_head *bh)
606 if (!page->
mapping && trylock_page(page)) {
618 static void reiserfs_end_buffer_io_sync(
struct buffer_head *bh,
int uptodate)
622 if (buffer_journaled(bh)) {
624 "pinned buffer %lu:%s sent to disk",
625 bh->b_blocknr,
bdevname(bh->b_bdev, b));
628 set_buffer_uptodate(bh);
630 clear_buffer_uptodate(bh);
633 release_buffer_page(bh);
636 static void reiserfs_end_ordered_io(
struct buffer_head *bh,
int uptodate)
639 set_buffer_uptodate(bh);
641 clear_buffer_uptodate(bh);
646 static void submit_logged_buffer(
struct buffer_head *bh)
649 bh->b_end_io = reiserfs_end_buffer_io_sync;
650 clear_buffer_journal_new(bh);
651 clear_buffer_dirty(bh);
652 if (!test_clear_buffer_journal_test(bh))
654 if (!buffer_uptodate(bh))
659 static void submit_ordered_buffer(
struct buffer_head *bh)
662 bh->b_end_io = reiserfs_end_ordered_io;
663 clear_buffer_dirty(bh);
664 if (!buffer_uptodate(bh))
669 #define CHUNK_SIZE 32
678 for (i = 0; i < chunk->
nr; i++) {
679 submit_logged_buffer(chunk->
bh[i]);
687 for (i = 0; i < chunk->
nr; i++) {
688 submit_ordered_buffer(chunk->
bh[i]);
693 static int add_to_chunk(
struct buffer_chunk *chunk,
struct buffer_head *bh,
698 chunk->
bh[chunk->
nr++] = bh;
734 bh->b_private =
NULL;
736 list_del_init(&jh->
list);
745 static inline int __add_jh(
struct reiserfs_journal *j,
struct buffer_head *bh,
752 if (!bh->b_private) {
757 list_del_init(&jh->
list);
789 #define JH_ENTRY(l) list_entry((l), struct reiserfs_jh, list)
790 static int write_ordered_buffers(
spinlock_t * lock,
795 struct buffer_head *bh;
800 INIT_LIST_HEAD(&tmp);
804 while (!list_empty(list)) {
808 if (!trylock_buffer(bh)) {
809 if (!buffer_dirty(bh)) {
810 list_move(&jh->
list, &tmp);
815 write_ordered_chunk(&chunk);
825 if (!buffer_uptodate(bh) && buffer_dirty(bh)) {
826 clear_buffer_dirty(bh);
829 if (buffer_dirty(bh)) {
830 list_move(&jh->
list, &tmp);
831 add_to_chunk(&chunk, bh, lock, write_ordered_chunk);
842 write_ordered_chunk(&chunk);
845 while (!list_empty(&tmp)) {
851 if (buffer_locked(bh)) {
856 if (!buffer_uptodate(bh)) {
867 if (buffer_dirty(bh) &&
unlikely(bh->b_page->mapping ==
NULL)) {
879 static int flush_older_commits(
struct super_block *s,
887 unsigned int other_trans_id;
888 unsigned int first_trans_id;
903 entry = other_jl->
j_list.prev;
907 if (first_jl == jl) {
913 entry = &first_jl->
j_list;
918 if (other_trans_id < trans_id) {
920 flush_commit_list(s, other_jl, 0);
923 if (!journal_list_still_alive(s, trans_id))
930 if (!journal_list_still_alive
931 (s, other_trans_id)) {
945 static int reiserfs_async_progress_wait(
struct super_block *s)
965 static int flush_commit_list(
struct super_block *s,
970 struct buffer_head *tbh =
NULL;
988 get_journal_list(jl);
990 if (flush_older_commits(s, jl) == 1) {
999 if (!journal_list_still_alive(s, trans_id)) {
1024 if (ret < 0 && retval == 0)
1037 write_len = jl->
j_len + 1;
1038 if (write_len < 256)
1040 for (i = 0 ; i < write_len ; i++) {
1045 if (buffer_dirty(tbh)) {
1055 for (i = 0; i < (jl->
j_len + 1); i++) {
1061 wait_on_buffer(tbh);
1067 if (buffer_dirty(tbh)) {
1072 if (
unlikely(!buffer_uptodate(tbh))) {
1073 #ifdef CONFIG_REISERFS_CHECK
1075 "buffer write failed");
1106 #ifdef CONFIG_REISERFS_CHECK
1120 cleanup_freed_for_journal_list(s, jl);
1122 retval = retval ? retval : journal->
j_errno;
1126 dirty_one_transaction(s, jl);
1134 put_journal_list(s, jl);
1178 static void remove_journal_hash(
struct super_block *,
1188 static void remove_all_from_journal_list(
struct super_block *sb,
1203 "block %u, bh is %d, state %ld",
1213 free_cnode(sb, last);
1225 static int _update_journal_header_block(
struct super_block *sb,
1227 unsigned int trans_id)
1241 #ifdef CONFIG_REISERFS_CHECK
1243 "buffer write failed");
1267 "IO error during journal replay");
1274 static int update_journal_header_block(
struct super_block *sb,
1275 unsigned long offset,
1276 unsigned int trans_id)
1278 return _update_journal_header_block(sb, offset, trans_id);
1285 static int flush_older_journal_lists(
struct super_block *sb,
1305 flush_journal_list(sb, other_jl, 0);
1313 static void del_from_work_list(
struct super_block *s,
1332 static int flush_journal_list(
struct super_block *s,
1340 struct buffer_head *saved_bh;
1341 unsigned long j_len_saved = jl->
j_len;
1345 BUG_ON(j_len_saved <= 0);
1370 goto flush_older_and_return;
1376 flush_commit_list(s, jl, 1);
1385 goto flush_older_and_return;
1409 pjl = find_newer_jl_for_cn(cn);
1414 if (!pjl && cn->
bh) {
1422 if (buffer_journal_dirty(saved_bh)) {
1426 }
else if (can_dirty(cn)) {
1437 flush_commit_list(s, pjl, 1);
1444 if (saved_bh ==
NULL) {
1452 if ((!was_jwait) && !buffer_locked(saved_bh)) {
1454 "BAD! buffer %llu %cdirty %cjwait, "
1455 "not in a newer tranasction",
1456 (
unsigned long long)saved_bh->
1457 b_blocknr, was_dirty ?
' ' :
'!',
1458 was_jwait ?
' ' :
'!');
1464 lock_buffer(saved_bh);
1466 if (buffer_dirty(saved_bh))
1467 submit_logged_buffer(saved_bh);
1473 "Unable to flush buffer %llu in %s",
1474 (
unsigned long long)saved_bh->
1475 b_blocknr, __func__);
1485 "saved_bh->b_count < 0");
1499 wait_on_buffer(cn->
bh);
1507 #ifdef CONFIG_REISERFS_CHECK
1509 "buffer write failed");
1516 BUG_ON(!test_clear_buffer_journal_dirty
1522 release_buffer_page(cn->
bh);
1530 "Write error while pushing transaction to disk in %s",
1532 flush_older_and_return:
1540 flush_older_journal_lists(s, jl);
1552 if (!err && flushall) {
1554 update_journal_header_block(s,
1560 "Write error while updating journal header in %s",
1563 remove_all_from_journal_list(s, jl, 0);
1564 list_del_init(&jl->
j_list);
1566 del_from_work_list(s, jl);
1585 put_journal_list(s, jl);
1591 static int test_transaction(
struct super_block *s,
1607 if (cn->
bh && !newer_jl_done(cn))
1616 static int write_one_transaction(
struct super_block *s,
1624 del_from_work_list(s, jl);
1637 if (cn->
bh && can_dirty(cn) && buffer_dirty(cn->
bh)) {
1638 struct buffer_head *tmp_bh;
1645 lock_buffer(tmp_bh);
1646 if (cn->
bh && can_dirty(cn) && buffer_dirty(tmp_bh)) {
1647 if (!buffer_journal_dirty(tmp_bh) ||
1648 buffer_journal_prepared(tmp_bh))
1650 add_to_chunk(chunk, tmp_bh,
NULL, write_chunk);
1666 static int dirty_one_transaction(
struct super_block *s,
1680 pjl = find_newer_jl_for_cn(cn);
1682 && buffer_journal_dirty(cn->
bh)) {
1688 clear_buffer_journal_new(cn->
bh);
1689 if (buffer_journal_prepared(cn->
bh)) {
1690 set_buffer_journal_restore_dirty(cn->
bh);
1692 set_buffer_journal_test(cn->
bh);
1701 static int kupdate_transactions(
struct super_block *s,
1704 unsigned int *next_trans_id,
1705 int num_blocks,
int num_trans)
1709 int transactions_flushed = 0;
1717 if (!journal_list_still_alive(s, orig_trans_id)) {
1724 while ((num_trans && transactions_flushed < num_trans) ||
1725 (!num_trans && written < num_blocks)) {
1730 del_from_work_list(s, jl);
1733 ret = write_one_transaction(s, jl, &chunk);
1737 transactions_flushed++;
1752 write_chunk(&chunk);
1769 static int flush_used_journal_lists(
struct super_block *s,
1772 unsigned long len = 0;
1773 unsigned long cur_len;
1782 flush_jl = tjl = jl;
1788 for (i = 0; i < 256 && len <
limit; i++) {
1807 if (flush_jl != jl) {
1808 ret = kupdate_transactions(s, jl, &tjl, &trans_id, len, i);
1810 flush_journal_list(s, flush_jl, 1);
1821 unsigned long block,
int remove_freed)
1832 if (cur->
blocknr == block && cur->
sb == sb
1855 static void free_journal_ram(
struct super_block *sb)
1863 free_bitmap_nodes(sb);
1870 release_journal_dev(sb, journal);
1893 if (!journal_join(&myth, sb, 1)) {
1899 do_journal_end(&myth, sb, 1,
FLUSH_ALL);
1906 memset(&myth, 0,
sizeof(myth));
1913 do_journal_end(&myth, sb, 1,
FLUSH_ALL);
1917 reiserfs_mounted_fs_count--;
1930 if (!reiserfs_mounted_fs_count) {
1935 free_journal_ram(sb);
1948 return do_journal_release(th, sb, 0);
1957 return do_journal_release(th, sb, 1);
1961 static int journal_compare_desc_commit(
struct super_block *sb,
1978 static int journal_transaction_is_valid(
struct super_block *sb,
1979 struct buffer_head *d_bh,
1980 unsigned int *oldest_invalid_trans_id,
1981 unsigned long *newest_mount_id)
1985 struct buffer_head *c_bh;
1994 if (oldest_invalid_trans_id && *oldest_invalid_trans_id
1997 "journal-986: transaction "
1998 "is valid returning because trans_id %d is greater than "
1999 "oldest_invalid %lu",
2001 *oldest_invalid_trans_id);
2007 "journal-1087: transaction "
2008 "is valid returning because mount_id %d is less than "
2009 "newest_mount_id %lu",
2016 "Bad transaction length %d "
2017 "encountered, ignoring transaction",
2032 if (journal_compare_desc_commit(sb, desc, commit)) {
2034 "journal_transaction_is_valid, commit offset %ld had bad "
2035 "time %d or length %d",
2041 if (oldest_invalid_trans_id) {
2042 *oldest_invalid_trans_id =
2046 "transaction_is_valid setting oldest invalid trans_id "
2054 "journal-1006: found valid "
2055 "transaction start offset %llu, len %d id %d",
2066 static void brelse_array(
struct buffer_head **
heads,
int num)
2069 for (i = 0; i < num; i++) {
2079 static int journal_read_transaction(
struct super_block *sb,
2080 unsigned long cur_dblock,
2081 unsigned long oldest_start,
2082 unsigned int oldest_trans_id,
2083 unsigned long newest_mount_id)
2088 unsigned int trans_id = 0;
2089 struct buffer_head *c_bh;
2090 struct buffer_head *d_bh;
2091 struct buffer_head **log_blocks =
NULL;
2092 struct buffer_head **real_blocks =
NULL;
2093 unsigned int trans_offset;
2103 "journal_read_transaction, offset %llu, len %d mount_id %d",
2108 "journal_read_trans skipping because %lu is too old",
2116 "journal_read_trans skipping because %d is != "
2130 if (journal_compare_desc_commit(sb, desc, commit)) {
2132 "journal_read_transaction, "
2133 "commit offset %llu had bad time %d or length %d",
2145 "device is readonly, unable to replay log");
2154 sizeof(
struct buffer_head *),
GFP_NOFS);
2156 sizeof(
struct buffer_head *),
GFP_NOFS);
2157 if (!log_blocks || !real_blocks) {
2163 "kmalloc failed, unable to mount FS");
2174 if (i < trans_half) {
2186 "REPLAY FAILURE fsck required! "
2187 "Block to replay is outside of "
2193 (sb, real_blocks[i]->b_blocknr)) {
2195 "REPLAY FAILURE fsck required! "
2196 "Trying to replay onto a log block");
2198 brelse_array(log_blocks, i);
2199 brelse_array(real_blocks, i);
2212 wait_on_buffer(log_blocks[i]);
2215 if (!buffer_uptodate(log_blocks[i])) {
2217 "REPLAY FAILURE fsck required! "
2218 "buffer write failed");
2219 brelse_array(log_blocks + i,
2228 memcpy(real_blocks[i]->b_data, log_blocks[i]->b_data,
2229 real_blocks[i]->b_size);
2230 set_buffer_uptodate(real_blocks[i]);
2231 brelse(log_blocks[i]);
2235 set_buffer_dirty(real_blocks[i]);
2239 wait_on_buffer(real_blocks[i]);
2240 if (!buffer_uptodate(real_blocks[i])) {
2242 "REPLAY FAILURE, fsck required! "
2243 "buffer write failed");
2244 brelse_array(real_blocks + i,
2252 brelse(real_blocks[i]);
2259 "journal-1095: setting journal " "start to offset %ld",
2286 struct buffer_head *bhlist[
BUFNR];
2287 unsigned int blocks =
BUFNR;
2288 struct buffer_head *bh;
2291 bh =
__getblk(dev, block, bufsize);
2292 if (buffer_uptodate(bh))
2295 if (block +
BUFNR > max_block) {
2296 blocks = max_block -
block;
2300 for (i = 1; i < blocks; i++) {
2301 bh =
__getblk(dev, block + i, bufsize);
2302 if (buffer_uptodate(bh)) {
2309 for (i = 1; i <
j; i++)
2313 if (buffer_uptodate(bh))
2332 unsigned int oldest_trans_id = 0;
2333 unsigned int oldest_invalid_trans_id = 0;
2335 unsigned long oldest_start = 0;
2336 unsigned long cur_dblock = 0;
2337 unsigned long newest_mount_id = 9;
2338 struct buffer_head *d_bh;
2340 int valid_journal_header = 0;
2341 int replay_count = 0;
2342 int continue_replay = 1;
2371 "journal-1153: found in "
2372 "header: first_unflushed_offset %d, last_flushed_trans_id "
2375 valid_journal_header = 1;
2385 ret = journal_transaction_is_valid(sb, d_bh,
NULL,
NULL);
2387 continue_replay = 0;
2390 goto start_log_replay;
2396 while (continue_replay
2403 reiserfs_breada(journal->
j_dev_bd, cur_dblock,
2408 journal_transaction_is_valid(sb, d_bh,
2409 &oldest_invalid_trans_id,
2413 if (oldest_start == 0) {
2415 oldest_start = d_bh->b_blocknr;
2418 "journal-1179: Setting "
2419 "oldest_start to offset %llu, trans_id %lu",
2422 (sb), oldest_trans_id);
2426 oldest_start = d_bh->b_blocknr;
2428 "journal-1180: Resetting "
2429 "oldest_start to offset %lu, trans_id %lu",
2432 (sb), oldest_trans_id);
2437 "journal-1299: Setting "
2438 "newest_mount_id to %d",
2449 cur_dblock = oldest_start;
2450 if (oldest_trans_id) {
2452 "journal-1206: Starting replay "
2453 "from offset %llu, trans_id %lu",
2459 while (continue_replay && oldest_trans_id > 0) {
2461 journal_read_transaction(sb, cur_dblock, oldest_start,
2462 oldest_trans_id, newest_mount_id);
2465 }
else if (ret != 0) {
2471 if (cur_dblock == oldest_start)
2475 if (oldest_trans_id == 0) {
2477 "journal-1225: No valid " "transactions found");
2483 if (valid_journal_header && replay_count == 0) {
2497 "newest_mount_id to %lu", journal->
j_mount_id);
2499 if (replay_count > 0) {
2501 "replayed %d transactions in %lu seconds\n",
2505 _update_journal_header_block(sb, journal->
j_start,
2520 INIT_LIST_HEAD(&jl->
j_list);
2526 get_journal_list(jl);
2530 static void journal_list_init(
struct super_block *sb)
2532 SB_JOURNAL(sb)->j_current_jl = alloc_journal_list(sb);
2535 static int release_journal_dev(
struct super_block *super,
2549 "Cannot release journal device: %i", result);
2556 const char *jdev_name)
2573 if ((!jdev_name || !jdev_name[0])) {
2574 if (jdev == super->
s_dev)
2580 result = PTR_ERR(journal->
j_dev_bd);
2583 "cannot init journal device '%s': %i",
2586 }
else if (jdev != super->
s_dev)
2595 result = PTR_ERR(journal->
j_dev_bd);
2598 "journal_init_dev: Cannot open '%s': %i",
2605 "journal_init_dev: journal device: %s\n",
2622 #define REISERFS_STANDARD_BLKSIZE (4096)
2624 static int check_advise_trans_params(
struct super_block *sb,
2639 "bad transaction max size (%u). "
2646 "bad transaction max batch (%u). "
2671 int old_format,
unsigned int commit_max_age)
2674 struct buffer_head *bhjh;
2685 "unable to get memory for journal structure");
2694 reiserfs_bmap_count(sb)))
2695 goto free_and_return;
2697 allocate_bitmap_nodes(sb);
2703 reiserfs_bmap_count(sb) +
2714 "journal does not fit for area addressed "
2715 "by first of bitmap blocks. It starts at "
2716 "%u and its size is %u. Block size %ld",
2720 goto free_and_return;
2725 "unable to initialize jornal device");
2726 goto free_and_return;
2737 "unable to read journal header");
2738 goto free_and_return;
2747 "journal header magic %x (device %s) does "
2748 "not match to magic found in super block %x",
2753 goto free_and_return;
2762 if (check_advise_trans_params(sb, journal) != 0)
2763 goto free_and_return;
2766 if (commit_max_age != 0) {
2772 "journal first block %u, max trans len %u, max batch %u, "
2773 "max commit age %u, max trans age %u\n",
2784 journal_list_init(sb);
2817 "allocation failed (%ld bytes). Journal is "
2818 "too large for available memory. Usually "
2819 "this is due to a journal that is too large.",
2821 goto free_and_return;
2824 init_journal_hash(sb);
2837 "get_list_bitmap failed for journal list 0");
2838 goto free_and_return;
2846 ret = journal_read(sb);
2850 "Replay Failure, unable to mount");
2851 goto free_and_return;
2854 reiserfs_mounted_fs_count++;
2855 if (reiserfs_mounted_fs_count <= 1)
2862 free_journal_ram(sb);
2922 static void queue_log_writer(
struct super_block *s)
2932 init_waitqueue_entry(&wait,
current);
2944 static void wake_queued_writers(
struct super_block *s)
2951 static void let_transaction_grow(
struct super_block *sb,
unsigned int trans_id)
2963 queue_log_writer(sb);
2984 unsigned int old_trans_id;
2987 int sched_count = 0;
3035 if (!join && (journal->
j_len_alloc + nblocks + 2) >=
3037 ((journal->
j_len + nblocks + 2) * 100) <
3041 queue_log_writer(sb);
3049 while (journal->
j_trans_id == old_trans_id &&
3051 queue_log_writer(sb);
3055 retval = journal_join(&myth, sb, 1);
3061 retval = do_journal_end(&myth, sb, 1, 0);
3063 retval = do_journal_end(&myth, sb, 1,
COMMIT_NOW);
3082 INIT_LIST_HEAD(&th->
t_list);
3086 memset(th, 0,
sizeof(*th));
3105 if (reiserfs_transaction_running(s)) {
3150 return do_journal_begin_r(th, sb, nblocks,
JBEGIN_JOIN);
3163 return do_journal_begin_r(th, sb, nblocks,
JBEGIN_ABORT);
3178 memcpy(th, cur_th,
sizeof(*th));
3181 "BAD: refcount <= 1, but "
3182 "journal_info != 0");
3190 "nesting info a different FS");
3197 ret = do_journal_begin_r(th, sb, nblocks,
JBEGIN_REG);
3225 int count_already_incd = 0;
3232 "handle trans id %ld != current trans id %ld",
3236 prepared = test_clear_buffer_journal_prepared(bh);
3237 clear_buffer_journal_restore_dirty(bh);
3239 if (buffer_journaled(bh)) {
3248 if (!prepared || buffer_dirty(bh)) {
3250 "buffer %llu bad state "
3251 "%cPREPARED %cLOCKED %cDIRTY %cJDIRTY_WAIT",
3252 (
unsigned long long)bh->b_blocknr,
3253 prepared ?
' ' :
'!',
3254 buffer_locked(bh) ?
' ' :
'!',
3255 buffer_dirty(bh) ?
' ' :
'!',
3256 buffer_journal_dirty(bh) ?
' ' :
'!');
3261 "returning because j_wcount was %d",
3270 "j_len (%lu) is too big",
3274 if (buffer_journal_dirty(bh)) {
3275 count_already_incd = 1;
3277 clear_buffer_journal_dirty(bh);
3284 set_buffer_journaled(bh);
3305 if (!count_already_incd) {
3313 journal->
j_last->next = cn;
3351 return do_journal_end(th, sb, nblocks, 0);
3362 static int remove_from_transaction(
struct super_block *sb,
3365 struct buffer_head *bh;
3370 cn = get_journal_hash_dev(sb, journal->
j_hash_table, blocknr);
3371 if (!cn || !cn->
bh) {
3384 if (cn == journal->
j_last) {
3390 clear_buffer_journaled(bh);
3392 if (!already_cleaned) {
3393 clear_buffer_journal_dirty(bh);
3394 clear_buffer_dirty(bh);
3395 clear_buffer_journal_test(bh);
3430 while (cur && can_dirty) {
3441 while (cur && can_dirty) {
3463 if (journal->
j_len == 0) {
3487 flush_commit_list(sb, jl, 1);
3514 journal->
j_len > 0 &&
3516 if (!journal_join(&th, sb, 1)) {
3550 int wait_on_commit = flags &
WAIT;
3558 "handle trans id %ld != current trans id %ld",
3580 if (flush || commit_now) {
3596 queue_log_writer(sb);
3609 && journal_list_still_alive(sb, trans_id)
3610 && wait_on_commit) {
3611 flush_commit_list(sb, jl, 1);
3638 "j_start (%ld) is too high",
3663 struct buffer_head *bh =
NULL;
3668 cn = get_journal_hash_dev(sb, journal->
j_hash_table, blocknr);
3674 if (bh && buffer_journal_new(bh)) {
3675 clear_buffer_journal_new(bh);
3676 clear_prepared_bits(bh);
3677 reiserfs_clean_and_file_buffer(bh);
3678 cleaned = remove_from_transaction(sb, blocknr, cleaned);
3684 "journal_list_bitmap is NULL");
3686 set_bit_in_list_bitmap(sb, blocknr, jb);
3691 clear_prepared_bits(bh);
3692 reiserfs_clean_and_file_buffer(bh);
3694 cleaned = remove_from_transaction(sb, blocknr, cleaned);
3700 if (sb == cn->
sb && blocknr == cn->
blocknr) {
3707 clear_buffer_journal_dirty(cn->
3709 clear_buffer_dirty(cn->
bh);
3710 clear_buffer_journal_test(cn->
3715 (&(cn->
bh->b_count)) < 0) {
3718 "cn->bh->b_count < 0");
3734 release_buffer_page(bh);
3742 REISERFS_I(inode)->i_trans_id = journal->
j_trans_id;
3749 static int __commit_trans_jl(
struct inode *
inode,
unsigned long id,
3761 let_transaction_grow(sb,
id);
3763 goto flush_commit_only;
3776 goto flush_commit_only;
3789 if (journal_list_still_alive(inode->
i_sb,
id)) {
3797 flush_commit_list(sb, jl, 1);
3808 unsigned int id = REISERFS_I(inode)->i_trans_id;
3816 id = REISERFS_I(inode)->i_trans_id;
3820 return __commit_trans_jl(inode,
id, jl);
3824 struct buffer_head *bh)
3831 if (test_clear_buffer_journal_restore_dirty(bh) &&
3832 buffer_journal_dirty(bh)) {
3834 cn = get_journal_hash_dev(sb,
3837 if (cn && can_dirty(cn)) {
3838 set_buffer_journal_test(bh);
3842 clear_buffer_journal_prepared(bh);
3854 struct buffer_head *bh,
int wait)
3858 if (!trylock_buffer(bh)) {
3863 set_buffer_journal_prepared(bh);
3864 if (test_clear_buffer_dirty(bh) && buffer_journal_dirty(bh)) {
3865 clear_buffer_journal_test(bh);
3866 set_buffer_journal_restore_dirty(bh);
3872 static void flush_old_journal_lists(
struct super_block *s)
3885 test_transaction(s, jl)) {
3886 flush_used_journal_lists(s, jl);
3912 struct buffer_head *c_bh;
3913 struct buffer_head *d_bh;
3914 int cur_write_start = 0;
3921 unsigned long jindex;
3922 unsigned int commit_trans_id;
3931 flags |= FLUSH_ALL | COMMIT_NOW |
WAIT;
3933 wait_on_commit = flags &
WAIT;
3937 if (journal->
j_len == 0) {
3949 flags |= COMMIT_NOW |
WAIT;
3956 if (!check_journal_end(th, sb, nblocks, flags)) {
3958 wake_queued_writers(sb);
3959 reiserfs_async_progress_wait(sb);
3975 #ifdef REISERFS_PREALLOCATE
3991 set_buffer_uptodate(d_bh);
3993 memset(d_bh->b_data, 0, d_bh->b_size);
4002 memset(c_bh->b_data, 0, c_bh->b_size);
4004 set_buffer_uptodate(c_bh);
4034 for (i = 0, cn = journal->
j_first; cn; cn = cn->
next, i++) {
4035 if (buffer_journaled(cn->
bh)) {
4039 "get_cnode returned NULL");
4044 jl_cn->
prev = last_cn;
4047 last_cn->
next = jl_cn;
4054 (sb, cn->
bh->b_blocknr)) {
4056 "Trying to log block %lu, "
4057 "which is a log block",
4066 if (i < trans_half) {
4092 cur_write_start = journal->
j_start;
4096 clear_buffer_journal_new(cn->
bh);
4098 if (buffer_journaled(cn->
bh)) {
4099 struct buffer_head *tmp_bh;
4108 set_buffer_uptodate(tmp_bh);
4109 page = cn->
bh->b_page;
4117 set_buffer_journal_dirty(cn->
bh);
4118 clear_buffer_journaled(cn->
bh);
4122 "BAD, buffer in journal hash, "
4165 init_journal_hash(sb);
4194 flush_commit_list(sb, jl, 1);
4195 flush_journal_list(sb, jl, 1);
4209 flush_used_journal_lists(sb, temp_jl);
4211 }
else if ((journal->
j_start +
4220 }
else if ((journal->
j_start +
4226 flush_used_journal_lists(sb, temp_jl);
4237 flush_old_journal_lists(sb);
4244 "could not get a list bitmap");
4253 if (!flush && wait_on_commit &&
4254 journal_list_still_alive(sb, commit_trans_id)) {
4255 flush_commit_list(sb, jl, 1);
4260 memset(th, 0,
sizeof(*th));
4282 #ifdef CONFIG_REISERFS_CHECK