aboutsummaryrefslogtreecommitdiffstats
path: root/fs/reiserfs/journal.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/reiserfs/journal.c')
-rw-r--r--fs/reiserfs/journal.c120
1 files changed, 60 insertions, 60 deletions
diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c
index db91754cfb83..4f787462becc 100644
--- a/fs/reiserfs/journal.c
+++ b/fs/reiserfs/journal.c
@@ -1,36 +1,36 @@
1/* 1/*
2** Write ahead logging implementation copyright Chris Mason 2000 2** Write ahead logging implementation copyright Chris Mason 2000
3** 3**
4** The background commits make this code very interelated, and 4** The background commits make this code very interelated, and
5** overly complex. I need to rethink things a bit....The major players: 5** overly complex. I need to rethink things a bit....The major players:
6** 6**
7** journal_begin -- call with the number of blocks you expect to log. 7** journal_begin -- call with the number of blocks you expect to log.
8** If the current transaction is too 8** If the current transaction is too
9** old, it will block until the current transaction is 9** old, it will block until the current transaction is
10** finished, and then start a new one. 10** finished, and then start a new one.
11** Usually, your transaction will get joined in with 11** Usually, your transaction will get joined in with
12** previous ones for speed. 12** previous ones for speed.
13** 13**
14** journal_join -- same as journal_begin, but won't block on the current 14** journal_join -- same as journal_begin, but won't block on the current
15** transaction regardless of age. Don't ever call 15** transaction regardless of age. Don't ever call
16** this. Ever. There are only two places it should be 16** this. Ever. There are only two places it should be
17** called from, and they are both inside this file. 17** called from, and they are both inside this file.
18** 18**
19** journal_mark_dirty -- adds blocks into this transaction. clears any flags 19** journal_mark_dirty -- adds blocks into this transaction. clears any flags
20** that might make them get sent to disk 20** that might make them get sent to disk
21** and then marks them BH_JDirty. Puts the buffer head 21** and then marks them BH_JDirty. Puts the buffer head
22** into the current transaction hash. 22** into the current transaction hash.
23** 23**
24** journal_end -- if the current transaction is batchable, it does nothing 24** journal_end -- if the current transaction is batchable, it does nothing
25** otherwise, it could do an async/synchronous commit, or 25** otherwise, it could do an async/synchronous commit, or
26** a full flush of all log and real blocks in the 26** a full flush of all log and real blocks in the
27** transaction. 27** transaction.
28** 28**
29** flush_old_commits -- if the current transaction is too old, it is ended and 29** flush_old_commits -- if the current transaction is too old, it is ended and
30** commit blocks are sent to disk. Forces commit blocks 30** commit blocks are sent to disk. Forces commit blocks
31** to disk for all backgrounded commits that have been 31** to disk for all backgrounded commits that have been
32** around too long. 32** around too long.
33** -- Note, if you call this as an immediate flush from 33** -- Note, if you call this as an immediate flush from
34** from within kupdate, it will ignore the immediate flag 34** from within kupdate, it will ignore the immediate flag
35*/ 35*/
36 36
@@ -212,7 +212,7 @@ static void allocate_bitmap_nodes(struct super_block *p_s_sb)
212 list_add(&bn->list, &journal->j_bitmap_nodes); 212 list_add(&bn->list, &journal->j_bitmap_nodes);
213 journal->j_free_bitmap_nodes++; 213 journal->j_free_bitmap_nodes++;
214 } else { 214 } else {
215 break; // this is ok, we'll try again when more are needed 215 break; /* this is ok, we'll try again when more are needed */
216 } 216 }
217 } 217 }
218} 218}
@@ -283,7 +283,7 @@ static int free_bitmap_nodes(struct super_block *p_s_sb)
283} 283}
284 284
285/* 285/*
286** get memory for JOURNAL_NUM_BITMAPS worth of bitmaps. 286** get memory for JOURNAL_NUM_BITMAPS worth of bitmaps.
287** jb_array is the array to be filled in. 287** jb_array is the array to be filled in.
288*/ 288*/
289int reiserfs_allocate_list_bitmaps(struct super_block *p_s_sb, 289int reiserfs_allocate_list_bitmaps(struct super_block *p_s_sb,
@@ -315,7 +315,7 @@ int reiserfs_allocate_list_bitmaps(struct super_block *p_s_sb,
315} 315}
316 316
317/* 317/*
318** find an available list bitmap. If you can't find one, flush a commit list 318** find an available list bitmap. If you can't find one, flush a commit list
319** and try again 319** and try again
320*/ 320*/
321static struct reiserfs_list_bitmap *get_list_bitmap(struct super_block *p_s_sb, 321static struct reiserfs_list_bitmap *get_list_bitmap(struct super_block *p_s_sb,
@@ -348,7 +348,7 @@ static struct reiserfs_list_bitmap *get_list_bitmap(struct super_block *p_s_sb,
348 return jb; 348 return jb;
349} 349}
350 350
351/* 351/*
352** allocates a new chunk of X nodes, and links them all together as a list. 352** allocates a new chunk of X nodes, and links them all together as a list.
353** Uses the cnode->next and cnode->prev pointers 353** Uses the cnode->next and cnode->prev pointers
354** returns NULL on failure 354** returns NULL on failure
@@ -376,7 +376,7 @@ static struct reiserfs_journal_cnode *allocate_cnodes(int num_cnodes)
376} 376}
377 377
378/* 378/*
379** pulls a cnode off the free list, or returns NULL on failure 379** pulls a cnode off the free list, or returns NULL on failure
380*/ 380*/
381static struct reiserfs_journal_cnode *get_cnode(struct super_block *p_s_sb) 381static struct reiserfs_journal_cnode *get_cnode(struct super_block *p_s_sb)
382{ 382{
@@ -403,7 +403,7 @@ static struct reiserfs_journal_cnode *get_cnode(struct super_block *p_s_sb)
403} 403}
404 404
405/* 405/*
406** returns a cnode to the free list 406** returns a cnode to the free list
407*/ 407*/
408static void free_cnode(struct super_block *p_s_sb, 408static void free_cnode(struct super_block *p_s_sb,
409 struct reiserfs_journal_cnode *cn) 409 struct reiserfs_journal_cnode *cn)
@@ -1192,8 +1192,8 @@ static int flush_commit_list(struct super_block *s,
1192} 1192}
1193 1193
1194/* 1194/*
1195** flush_journal_list frequently needs to find a newer transaction for a given block. This does that, or 1195** flush_journal_list frequently needs to find a newer transaction for a given block. This does that, or
1196** returns NULL if it can't find anything 1196** returns NULL if it can't find anything
1197*/ 1197*/
1198static struct reiserfs_journal_list *find_newer_jl_for_cn(struct 1198static struct reiserfs_journal_list *find_newer_jl_for_cn(struct
1199 reiserfs_journal_cnode 1199 reiserfs_journal_cnode
@@ -1335,8 +1335,8 @@ static int update_journal_header_block(struct super_block *p_s_sb,
1335 return _update_journal_header_block(p_s_sb, offset, trans_id); 1335 return _update_journal_header_block(p_s_sb, offset, trans_id);
1336} 1336}
1337 1337
1338/* 1338/*
1339** flush any and all journal lists older than you are 1339** flush any and all journal lists older than you are
1340** can only be called from flush_journal_list 1340** can only be called from flush_journal_list
1341*/ 1341*/
1342static int flush_older_journal_lists(struct super_block *p_s_sb, 1342static int flush_older_journal_lists(struct super_block *p_s_sb,
@@ -1382,8 +1382,8 @@ static void del_from_work_list(struct super_block *s,
1382** always set flushall to 1, unless you are calling from inside 1382** always set flushall to 1, unless you are calling from inside
1383** flush_journal_list 1383** flush_journal_list
1384** 1384**
1385** IMPORTANT. This can only be called while there are no journal writers, 1385** IMPORTANT. This can only be called while there are no journal writers,
1386** and the journal is locked. That means it can only be called from 1386** and the journal is locked. That means it can only be called from
1387** do_journal_end, or by journal_release 1387** do_journal_end, or by journal_release
1388*/ 1388*/
1389static int flush_journal_list(struct super_block *s, 1389static int flush_journal_list(struct super_block *s,
@@ -1429,7 +1429,7 @@ static int flush_journal_list(struct super_block *s,
1429 goto flush_older_and_return; 1429 goto flush_older_and_return;
1430 } 1430 }
1431 1431
1432 /* start by putting the commit list on disk. This will also flush 1432 /* start by putting the commit list on disk. This will also flush
1433 ** the commit lists of any olders transactions 1433 ** the commit lists of any olders transactions
1434 */ 1434 */
1435 flush_commit_list(s, jl, 1); 1435 flush_commit_list(s, jl, 1);
@@ -1444,8 +1444,8 @@ static int flush_journal_list(struct super_block *s,
1444 goto flush_older_and_return; 1444 goto flush_older_and_return;
1445 } 1445 }
1446 1446
1447 /* loop through each cnode, see if we need to write it, 1447 /* loop through each cnode, see if we need to write it,
1448 ** or wait on a more recent transaction, or just ignore it 1448 ** or wait on a more recent transaction, or just ignore it
1449 */ 1449 */
1450 if (atomic_read(&(journal->j_wcount)) != 0) { 1450 if (atomic_read(&(journal->j_wcount)) != 0) {
1451 reiserfs_panic(s, "journal-844", "journal list is flushing, " 1451 reiserfs_panic(s, "journal-844", "journal list is flushing, "
@@ -1473,8 +1473,8 @@ static int flush_journal_list(struct super_block *s,
1473 if (!pjl && cn->bh) { 1473 if (!pjl && cn->bh) {
1474 saved_bh = cn->bh; 1474 saved_bh = cn->bh;
1475 1475
1476 /* we do this to make sure nobody releases the buffer while 1476 /* we do this to make sure nobody releases the buffer while
1477 ** we are working with it 1477 ** we are working with it
1478 */ 1478 */
1479 get_bh(saved_bh); 1479 get_bh(saved_bh);
1480 1480
@@ -1497,8 +1497,8 @@ static int flush_journal_list(struct super_block *s,
1497 goto free_cnode; 1497 goto free_cnode;
1498 } 1498 }
1499 1499
1500 /* bh == NULL when the block got to disk on its own, OR, 1500 /* bh == NULL when the block got to disk on its own, OR,
1501 ** the block got freed in a future transaction 1501 ** the block got freed in a future transaction
1502 */ 1502 */
1503 if (saved_bh == NULL) { 1503 if (saved_bh == NULL) {
1504 goto free_cnode; 1504 goto free_cnode;
@@ -1586,7 +1586,7 @@ static int flush_journal_list(struct super_block *s,
1586 __func__); 1586 __func__);
1587 flush_older_and_return: 1587 flush_older_and_return:
1588 1588
1589 /* before we can update the journal header block, we _must_ flush all 1589 /* before we can update the journal header block, we _must_ flush all
1590 ** real blocks from all older transactions to disk. This is because 1590 ** real blocks from all older transactions to disk. This is because
1591 ** once the header block is updated, this transaction will not be 1591 ** once the header block is updated, this transaction will not be
1592 ** replayed after a crash 1592 ** replayed after a crash
@@ -1596,7 +1596,7 @@ static int flush_journal_list(struct super_block *s,
1596 } 1596 }
1597 1597
1598 err = journal->j_errno; 1598 err = journal->j_errno;
1599 /* before we can remove everything from the hash tables for this 1599 /* before we can remove everything from the hash tables for this
1600 ** transaction, we must make sure it can never be replayed 1600 ** transaction, we must make sure it can never be replayed
1601 ** 1601 **
1602 ** since we are only called from do_journal_end, we know for sure there 1602 ** since we are only called from do_journal_end, we know for sure there
@@ -2016,9 +2016,9 @@ static int journal_compare_desc_commit(struct super_block *p_s_sb,
2016 return 0; 2016 return 0;
2017} 2017}
2018 2018
2019/* returns 0 if it did not find a description block 2019/* returns 0 if it did not find a description block
2020** returns -1 if it found a corrupt commit block 2020** returns -1 if it found a corrupt commit block
2021** returns 1 if both desc and commit were valid 2021** returns 1 if both desc and commit were valid
2022*/ 2022*/
2023static int journal_transaction_is_valid(struct super_block *p_s_sb, 2023static int journal_transaction_is_valid(struct super_block *p_s_sb,
2024 struct buffer_head *d_bh, 2024 struct buffer_head *d_bh,
@@ -2380,8 +2380,8 @@ static int journal_read(struct super_block *p_s_sb)
2380 bdevname(journal->j_dev_bd, b)); 2380 bdevname(journal->j_dev_bd, b));
2381 start = get_seconds(); 2381 start = get_seconds();
2382 2382
2383 /* step 1, read in the journal header block. Check the transaction it says 2383 /* step 1, read in the journal header block. Check the transaction it says
2384 ** is the first unflushed, and if that transaction is not valid, 2384 ** is the first unflushed, and if that transaction is not valid,
2385 ** replay is done 2385 ** replay is done
2386 */ 2386 */
2387 journal->j_header_bh = journal_bread(p_s_sb, 2387 journal->j_header_bh = journal_bread(p_s_sb,
@@ -2406,8 +2406,8 @@ static int journal_read(struct super_block *p_s_sb)
2406 le32_to_cpu(jh->j_last_flush_trans_id)); 2406 le32_to_cpu(jh->j_last_flush_trans_id));
2407 valid_journal_header = 1; 2407 valid_journal_header = 1;
2408 2408
2409 /* now, we try to read the first unflushed offset. If it is not valid, 2409 /* now, we try to read the first unflushed offset. If it is not valid,
2410 ** there is nothing more we can do, and it makes no sense to read 2410 ** there is nothing more we can do, and it makes no sense to read
2411 ** through the whole log. 2411 ** through the whole log.
2412 */ 2412 */
2413 d_bh = 2413 d_bh =
@@ -2919,7 +2919,7 @@ int journal_transaction_should_end(struct reiserfs_transaction_handle *th,
2919 return 0; 2919 return 0;
2920} 2920}
2921 2921
2922/* this must be called inside a transaction, and requires the 2922/* this must be called inside a transaction, and requires the
2923** kernel_lock to be held 2923** kernel_lock to be held
2924*/ 2924*/
2925void reiserfs_block_writes(struct reiserfs_transaction_handle *th) 2925void reiserfs_block_writes(struct reiserfs_transaction_handle *th)
@@ -3040,7 +3040,7 @@ static int do_journal_begin_r(struct reiserfs_transaction_handle *th,
3040 now = get_seconds(); 3040 now = get_seconds();
3041 3041
3042 /* if there is no room in the journal OR 3042 /* if there is no room in the journal OR
3043 ** if this transaction is too old, and we weren't called joinable, wait for it to finish before beginning 3043 ** if this transaction is too old, and we weren't called joinable, wait for it to finish before beginning
3044 ** we don't sleep if there aren't other writers 3044 ** we don't sleep if there aren't other writers
3045 */ 3045 */
3046 3046
@@ -3240,7 +3240,7 @@ int journal_begin(struct reiserfs_transaction_handle *th,
3240** 3240**
3241** if it was dirty, cleans and files onto the clean list. I can't let it be dirty again until the 3241** if it was dirty, cleans and files onto the clean list. I can't let it be dirty again until the
3242** transaction is committed. 3242** transaction is committed.
3243** 3243**
3244** if j_len, is bigger than j_len_alloc, it pushes j_len_alloc to 10 + j_len. 3244** if j_len, is bigger than j_len_alloc, it pushes j_len_alloc to 10 + j_len.
3245*/ 3245*/
3246int journal_mark_dirty(struct reiserfs_transaction_handle *th, 3246int journal_mark_dirty(struct reiserfs_transaction_handle *th,
@@ -3290,7 +3290,7 @@ int journal_mark_dirty(struct reiserfs_transaction_handle *th,
3290 atomic_read(&(journal->j_wcount))); 3290 atomic_read(&(journal->j_wcount)));
3291 return 1; 3291 return 1;
3292 } 3292 }
3293 /* this error means I've screwed up, and we've overflowed the transaction. 3293 /* this error means I've screwed up, and we've overflowed the transaction.
3294 ** Nothing can be done here, except make the FS readonly or panic. 3294 ** Nothing can be done here, except make the FS readonly or panic.
3295 */ 3295 */
3296 if (journal->j_len >= journal->j_trans_max) { 3296 if (journal->j_len >= journal->j_trans_max) {
@@ -3380,7 +3380,7 @@ int journal_end(struct reiserfs_transaction_handle *th,
3380 } 3380 }
3381} 3381}
3382 3382
3383/* removes from the current transaction, relsing and descrementing any counters. 3383/* removes from the current transaction, relsing and descrementing any counters.
3384** also files the removed buffer directly onto the clean list 3384** also files the removed buffer directly onto the clean list
3385** 3385**
3386** called by journal_mark_freed when a block has been deleted 3386** called by journal_mark_freed when a block has been deleted
@@ -3478,7 +3478,7 @@ static int can_dirty(struct reiserfs_journal_cnode *cn)
3478} 3478}
3479 3479
3480/* syncs the commit blocks, but does not force the real buffers to disk 3480/* syncs the commit blocks, but does not force the real buffers to disk
3481** will wait until the current transaction is done/committed before returning 3481** will wait until the current transaction is done/committed before returning
3482*/ 3482*/
3483int journal_end_sync(struct reiserfs_transaction_handle *th, 3483int journal_end_sync(struct reiserfs_transaction_handle *th,
3484 struct super_block *p_s_sb, unsigned long nblocks) 3484 struct super_block *p_s_sb, unsigned long nblocks)
@@ -3560,13 +3560,13 @@ int reiserfs_flush_old_commits(struct super_block *p_s_sb)
3560 3560
3561/* 3561/*
3562** returns 0 if do_journal_end should return right away, returns 1 if do_journal_end should finish the commit 3562** returns 0 if do_journal_end should return right away, returns 1 if do_journal_end should finish the commit
3563** 3563**
3564** if the current transaction is too old, but still has writers, this will wait on j_join_wait until all 3564** if the current transaction is too old, but still has writers, this will wait on j_join_wait until all
3565** the writers are done. By the time it wakes up, the transaction it was called has already ended, so it just 3565** the writers are done. By the time it wakes up, the transaction it was called has already ended, so it just
3566** flushes the commit list and returns 0. 3566** flushes the commit list and returns 0.
3567** 3567**
3568** Won't batch when flush or commit_now is set. Also won't batch when others are waiting on j_join_wait. 3568** Won't batch when flush or commit_now is set. Also won't batch when others are waiting on j_join_wait.
3569** 3569**
3570** Note, we can't allow the journal_end to proceed while there are still writers in the log. 3570** Note, we can't allow the journal_end to proceed while there are still writers in the log.
3571*/ 3571*/
3572static int check_journal_end(struct reiserfs_transaction_handle *th, 3572static int check_journal_end(struct reiserfs_transaction_handle *th,
@@ -3594,7 +3594,7 @@ static int check_journal_end(struct reiserfs_transaction_handle *th,
3594 atomic_dec(&(journal->j_wcount)); 3594 atomic_dec(&(journal->j_wcount));
3595 } 3595 }
3596 3596
3597 /* BUG, deal with case where j_len is 0, but people previously freed blocks need to be released 3597 /* BUG, deal with case where j_len is 0, but people previously freed blocks need to be released
3598 ** will be dealt with by next transaction that actually writes something, but should be taken 3598 ** will be dealt with by next transaction that actually writes something, but should be taken
3599 ** care of in this trans 3599 ** care of in this trans
3600 */ 3600 */
@@ -3603,7 +3603,7 @@ static int check_journal_end(struct reiserfs_transaction_handle *th,
3603 /* if wcount > 0, and we are called to with flush or commit_now, 3603 /* if wcount > 0, and we are called to with flush or commit_now,
3604 ** we wait on j_join_wait. We will wake up when the last writer has 3604 ** we wait on j_join_wait. We will wake up when the last writer has
3605 ** finished the transaction, and started it on its way to the disk. 3605 ** finished the transaction, and started it on its way to the disk.
3606 ** Then, we flush the commit or journal list, and just return 0 3606 ** Then, we flush the commit or journal list, and just return 0
3607 ** because the rest of journal end was already done for this transaction. 3607 ** because the rest of journal end was already done for this transaction.
3608 */ 3608 */
3609 if (atomic_read(&(journal->j_wcount)) > 0) { 3609 if (atomic_read(&(journal->j_wcount)) > 0) {
@@ -3674,7 +3674,7 @@ static int check_journal_end(struct reiserfs_transaction_handle *th,
3674/* 3674/*
3675** Does all the work that makes deleting blocks safe. 3675** Does all the work that makes deleting blocks safe.
3676** when deleting a block mark BH_JNew, just remove it from the current transaction, clean it's buffer_head and move on. 3676** when deleting a block mark BH_JNew, just remove it from the current transaction, clean it's buffer_head and move on.
3677** 3677**
3678** otherwise: 3678** otherwise:
3679** set a bit for the block in the journal bitmap. That will prevent it from being allocated for unformatted nodes 3679** set a bit for the block in the journal bitmap. That will prevent it from being allocated for unformatted nodes
3680** before this transaction has finished. 3680** before this transaction has finished.
@@ -3878,7 +3878,7 @@ extern struct tree_balance *cur_tb;
3878** be written to disk while we are altering it. So, we must: 3878** be written to disk while we are altering it. So, we must:
3879** clean it 3879** clean it
3880** wait on it. 3880** wait on it.
3881** 3881**
3882*/ 3882*/
3883int reiserfs_prepare_for_journal(struct super_block *p_s_sb, 3883int reiserfs_prepare_for_journal(struct super_block *p_s_sb,
3884 struct buffer_head *bh, int wait) 3884 struct buffer_head *bh, int wait)
@@ -3920,7 +3920,7 @@ static void flush_old_journal_lists(struct super_block *s)
3920 } 3920 }
3921} 3921}
3922 3922
3923/* 3923/*
3924** long and ugly. If flush, will not return until all commit 3924** long and ugly. If flush, will not return until all commit
3925** blocks and all real buffers in the trans are on disk. 3925** blocks and all real buffers in the trans are on disk.
3926** If no_async, won't return until all commit blocks are on disk. 3926** If no_async, won't return until all commit blocks are on disk.
@@ -3981,7 +3981,7 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
3981 wait_on_commit = 1; 3981 wait_on_commit = 1;
3982 } 3982 }
3983 3983
3984 /* check_journal_end locks the journal, and unlocks if it does not return 1 3984 /* check_journal_end locks the journal, and unlocks if it does not return 1
3985 ** it tells us if we should continue with the journal_end, or just return 3985 ** it tells us if we should continue with the journal_end, or just return
3986 */ 3986 */
3987 if (!check_journal_end(th, p_s_sb, nblocks, flags)) { 3987 if (!check_journal_end(th, p_s_sb, nblocks, flags)) {
@@ -4078,7 +4078,7 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
4078 last_cn->next = jl_cn; 4078 last_cn->next = jl_cn;
4079 } 4079 }
4080 last_cn = jl_cn; 4080 last_cn = jl_cn;
4081 /* make sure the block we are trying to log is not a block 4081 /* make sure the block we are trying to log is not a block
4082 of journal or reserved area */ 4082 of journal or reserved area */
4083 4083
4084 if (is_block_in_log_or_reserved_area 4084 if (is_block_in_log_or_reserved_area
@@ -4225,9 +4225,9 @@ static int do_journal_end(struct reiserfs_transaction_handle *th,
4225 } else if (!(jl->j_state & LIST_COMMIT_PENDING)) 4225 } else if (!(jl->j_state & LIST_COMMIT_PENDING))
4226 queue_delayed_work(commit_wq, &journal->j_work, HZ / 10); 4226 queue_delayed_work(commit_wq, &journal->j_work, HZ / 10);
4227 4227
4228 /* if the next transaction has any chance of wrapping, flush 4228 /* if the next transaction has any chance of wrapping, flush
4229 ** transactions that might get overwritten. If any journal lists are very 4229 ** transactions that might get overwritten. If any journal lists are very
4230 ** old flush them as well. 4230 ** old flush them as well.
4231 */ 4231 */
4232 first_jl: 4232 first_jl:
4233 list_for_each_safe(entry, safe, &journal->j_journal_list) { 4233 list_for_each_safe(entry, safe, &journal->j_journal_list) {