patch-2.4.22 linux-2.4.22/fs/reiserfs/journal.c
Next file: linux-2.4.22/fs/reiserfs/lbalance.c
Previous file: linux-2.4.22/fs/reiserfs/item_ops.c
Back to the patch index
Back to the overall index
- Lines: 1075
- Date:
2003-08-25 04:44:43.000000000 -0700
- Orig file:
linux-2.4.21/fs/reiserfs/journal.c
- Orig date:
2003-06-13 07:51:37.000000000 -0700
diff -urN linux-2.4.21/fs/reiserfs/journal.c linux-2.4.22/fs/reiserfs/journal.c
@@ -96,7 +96,8 @@
static int can_dirty(struct reiserfs_journal_cnode *cn) ;
static int remove_from_journal_list(struct super_block *s, struct reiserfs_journal_list *jl, struct buffer_head *bh, int remove_freed);
static int journal_join(struct reiserfs_transaction_handle *th, struct super_block *p_s_sb, unsigned long nblocks);
-
+static int release_journal_dev( struct super_block *super,
+ struct reiserfs_journal *journal );
static void init_journal_hash(struct super_block *p_s_sb) {
memset(SB_JOURNAL(p_s_sb)->j_hash_table, 0, JOURNAL_HASH_SIZE * sizeof(struct reiserfs_journal_cnode *)) ;
}
@@ -255,7 +256,7 @@
jb->journal_list = NULL ;
jb->bitmaps = vmalloc( mem ) ;
if (!jb->bitmaps) {
- reiserfs_warning("clm-2000, unable to allocate bitmaps for journal lists\n") ;
+ reiserfs_warning(p_s_sb, "clm-2000, unable to allocate bitmaps for journal lists\n") ;
failed = 1;
break ;
}
@@ -669,7 +670,7 @@
atomic_set(&(jl->j_commit_flushing), 1) ;
- if (jl->j_len > JOURNAL_TRANS_MAX) {
+ if (jl->j_len > SB_JOURNAL_TRANS_MAX(s)) {
reiserfs_panic(s, "journal-512: flush_commit_list: length is %lu, list number %d\n", jl->j_len, jl - SB_JOURNAL_LIST(s)) ;
return 0 ;
}
@@ -683,8 +684,8 @@
retry:
count = 0 ;
for (i = 0 ; atomic_read(&(jl->j_commit_left)) > 1 && i < (jl->j_len + 1) ; i++) { /* everything but commit_bh */
- bn = reiserfs_get_journal_block(s) + (jl->j_start+i) % JOURNAL_BLOCK_COUNT;
- tbh = sb_get_hash_table(s, bn) ;
+ bn = SB_ONDISK_JOURNAL_1st_BLOCK(s) + (jl->j_start+i) % SB_ONDISK_JOURNAL_SIZE(s);
+ tbh = journal_get_hash_table(s, bn) ;
/* kill this sanity check */
if (count > (orig_commit_left + 2)) {
@@ -698,7 +699,7 @@
}
}
if (buffer_dirty(tbh)) {
- printk("journal-569: flush_commit_list, block already dirty!\n") ;
+ reiserfs_warning(s, "journal-569: flush_commit_list, block already dirty!\n") ;
} else {
mark_buffer_dirty(tbh) ;
}
@@ -712,8 +713,8 @@
if (count > 0) {
for (i = 0 ; atomic_read(&(jl->j_commit_left)) > 1 &&
i < (jl->j_len + 1) ; i++) { /* everything but commit_bh */
- bn = reiserfs_get_journal_block(s) + (jl->j_start + i) % JOURNAL_BLOCK_COUNT ;
- tbh = sb_get_hash_table(s, bn) ;
+ bn = SB_ONDISK_JOURNAL_1st_BLOCK(s) + (jl->j_start + i) % SB_ONDISK_JOURNAL_SIZE(s) ;
+ tbh = journal_get_hash_table(s, bn) ;
wait_on_buffer(tbh) ;
if (!buffer_uptodate(tbh)) {
@@ -727,7 +728,7 @@
if (atomic_read(&(jl->j_commit_left)) != 1) { /* just the commit_bh left, flush it without calling getblk for everyone */
if (retry_count < 2) {
- printk("journal-582: flush_commit_list, not all log blocks on disk yet, trying again\n") ;
+ reiserfs_warning(s, "journal-582: flush_commit_list, not all log blocks on disk yet, trying again\n") ;
retry_count++ ;
goto retry;
}
@@ -792,7 +793,7 @@
while(cn) {
if (cn->blocknr != 0) {
if (debug) {
- printk("block %lu, bh is %d, state %ld\n", cn->blocknr, cn->bh ? 1: 0,
+ reiserfs_warning(p_s_sb, "block %lu, bh is %d, state %ld\n", cn->blocknr, cn->bh ? 1: 0,
cn->state) ;
}
fake_bh.b_blocknr = cn->blocknr ;
@@ -833,7 +834,7 @@
ll_rw_block(WRITE, 1, &(SB_JOURNAL(p_s_sb)->j_header_bh)) ;
wait_on_buffer((SB_JOURNAL(p_s_sb)->j_header_bh)) ;
if (!buffer_uptodate(SB_JOURNAL(p_s_sb)->j_header_bh)) {
- printk( "reiserfs: journal-837: IO error during journal replay\n" );
+ reiserfs_warning( p_s_sb, "reiserfs: journal-837: IO error during journal replay\n" );
return -EIO ;
}
}
@@ -872,7 +873,7 @@
static void reiserfs_end_buffer_io_sync(struct buffer_head *bh, int uptodate) {
if (buffer_journaled(bh)) {
- reiserfs_warning("clm-2084: pinned buffer %lu:%s sent to disk\n",
+ reiserfs_warning(NULL, "clm-2084: pinned buffer %lu:%s sent to disk\n",
bh->b_blocknr, kdevname(bh->b_dev)) ;
}
mark_buffer_uptodate(bh, uptodate) ;
@@ -912,7 +913,7 @@
}
if (atomic_read(&SB_JOURNAL(s)->j_wcount) != 0) {
- reiserfs_warning("clm-2048: flush_journal_list called with wcount %d\n",
+ reiserfs_warning(s, "clm-2048: flush_journal_list called with wcount %d\n",
atomic_read(&SB_JOURNAL(s)->j_wcount)) ;
}
/* if someone is getting the commit list, we must wait for them */
@@ -928,7 +929,7 @@
atomic_set(&(jl->j_flushing), 1) ;
count = 0 ;
- if (j_len_saved > JOURNAL_TRANS_MAX) {
+ if (j_len_saved > SB_JOURNAL_TRANS_MAX(s)) {
reiserfs_panic(s, "journal-715: flush_journal_list, length is %lu, list number %d\n", j_len_saved, jl - SB_JOURNAL_LIST(s)) ;
atomic_dec(&(jl->j_flushing)) ;
return 0 ;
@@ -1010,14 +1011,14 @@
** is not marked JDirty_wait
*/
if ((!was_jwait) && !buffer_locked(saved_bh)) {
-printk("journal-813: BAD! buffer %lu %cdirty %cjwait, not in a newer tranasction\n", saved_bh->b_blocknr,
+reiserfs_warning(s, "journal-813: BAD! buffer %lu %cdirty %cjwait, not in a newer tranasction\n", saved_bh->b_blocknr,
was_dirty ? ' ' : '!', was_jwait ? ' ' : '!') ;
}
/* kupdate_one_transaction waits on the buffers it is writing, so we
** should never see locked buffers here
*/
if (buffer_locked(saved_bh)) {
- printk("clm-2083: locked buffer %lu in flush_journal_list\n",
+ reiserfs_warning(s, "clm-2083: locked buffer %lu in flush_journal_list\n",
saved_bh->b_blocknr) ;
wait_on_buffer(saved_bh) ;
if (!buffer_uptodate(saved_bh)) {
@@ -1031,7 +1032,7 @@
submit_logged_buffer(saved_bh) ;
count++ ;
} else {
- printk("clm-2082: Unable to flush buffer %lu in flush_journal_list\n",
+ reiserfs_warning(s, "clm-2082: Unable to flush buffer %lu in flush_journal_list\n",
saved_bh->b_blocknr) ;
}
free_cnode:
@@ -1041,7 +1042,7 @@
/* we incremented this to keep others from taking the buffer head away */
put_bh(saved_bh) ;
if (atomic_read(&(saved_bh->b_count)) < 0) {
- printk("journal-945: saved_bh->b_count < 0") ;
+ reiserfs_warning(s, "journal-945: saved_bh->b_count < 0\n") ;
}
}
}
@@ -1085,7 +1086,7 @@
** being flushed
*/
if (flushall) {
- update_journal_header_block(s, (jl->j_start + jl->j_len + 2) % JOURNAL_BLOCK_COUNT, jl->j_trans_id) ;
+ update_journal_header_block(s, (jl->j_start + jl->j_len + 2) % SB_ONDISK_JOURNAL_SIZE(s), jl->j_trans_id) ;
}
remove_all_from_journal_list(s, jl, 0) ;
jl->j_len = 0 ;
@@ -1189,7 +1190,7 @@
walk_cn = walk_cn->hnext ;
}
if (atomic_read(&saved_bh->b_count) < 1) {
- reiserfs_warning("clm-2081: bad count on %lu\n",
+ reiserfs_warning(s, "clm-2081: bad count on %lu\n",
saved_bh->b_blocknr) ;
}
brelse(saved_bh) ;
@@ -1312,6 +1313,10 @@
if (SB_JOURNAL(p_s_sb)->j_header_bh) {
brelse(SB_JOURNAL(p_s_sb)->j_header_bh) ;
}
+ /* j_header_bh is on the journal dev, make sure not to release the journal
+ * dev until we brelse j_header_bh
+ */
+ release_journal_dev(p_s_sb, SB_JOURNAL(p_s_sb));
vfree(SB_JOURNAL(p_s_sb)) ;
}
@@ -1365,7 +1370,7 @@
struct reiserfs_journal_commit *commit) {
if (le32_to_cpu(commit->j_trans_id) != le32_to_cpu(desc->j_trans_id) ||
le32_to_cpu(commit->j_len) != le32_to_cpu(desc->j_len) ||
- le32_to_cpu(commit->j_len) > JOURNAL_TRANS_MAX ||
+ le32_to_cpu(commit->j_len) > SB_JOURNAL_TRANS_MAX(p_s_sb) ||
le32_to_cpu(commit->j_len) <= 0
) {
return 1 ;
@@ -1401,14 +1406,15 @@
*newest_mount_id) ;
return -1 ;
}
- if ( le32_to_cpu(desc->j_len) > JOURNAL_TRANS_MAX ) {
- reiserfs_warning("journal-2018: Bad transaction length %d encountered, ignoring transaction\n", le32_to_cpu(desc->j_len));
+ if ( le32_to_cpu(desc->j_len) > SB_JOURNAL_TRANS_MAX(p_s_sb) ) {
+ reiserfs_warning(p_s_sb, "journal-2018: Bad transaction length %d encountered, ignoring transaction\n", le32_to_cpu(desc->j_len));
return -1 ;
}
- offset = d_bh->b_blocknr - reiserfs_get_journal_block(p_s_sb) ;
+ offset = d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) ;
/* ok, we have a journal description block, lets see if the transaction was valid */
- c_bh = sb_bread(p_s_sb, reiserfs_get_journal_block(p_s_sb) + ((offset + le32_to_cpu(desc->j_len) + 1) % JOURNAL_BLOCK_COUNT)) ;
+ c_bh = journal_bread(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
+ ((offset + le32_to_cpu(desc->j_len) + 1) % SB_ONDISK_JOURNAL_SIZE(p_s_sb))) ;
if (!c_bh)
return 0 ;
commit = (struct reiserfs_journal_commit *)c_bh->b_data ;
@@ -1416,7 +1422,7 @@
reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE,
"journal_transaction_is_valid, commit offset %ld had bad "
"time %d or length %d\n",
- c_bh->b_blocknr - reiserfs_get_journal_block(p_s_sb),
+ c_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb),
le32_to_cpu(commit->j_trans_id),
le32_to_cpu(commit->j_len));
brelse(c_bh) ;
@@ -1431,7 +1437,7 @@
brelse(c_bh) ;
reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1006: found valid "
"transaction start offset %lu, len %d id %d\n",
- d_bh->b_blocknr - reiserfs_get_journal_block(p_s_sb),
+ d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb),
le32_to_cpu(desc->j_len), le32_to_cpu(desc->j_trans_id)) ;
return 1 ;
} else {
@@ -1463,19 +1469,19 @@
unsigned long trans_offset ;
int i;
- d_bh = sb_bread(p_s_sb, cur_dblock) ;
+ d_bh = journal_bread(p_s_sb, cur_dblock) ;
if (!d_bh)
return 1 ;
desc = (struct reiserfs_journal_desc *)d_bh->b_data ;
- trans_offset = d_bh->b_blocknr - reiserfs_get_journal_block(p_s_sb) ;
+ trans_offset = d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) ;
reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1037: "
"journal_read_transaction, offset %lu, len %d mount_id %d\n",
- d_bh->b_blocknr - reiserfs_get_journal_block(p_s_sb),
+ d_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb),
le32_to_cpu(desc->j_len), le32_to_cpu(desc->j_mount_id)) ;
if (le32_to_cpu(desc->j_trans_id) < oldest_trans_id) {
reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1039: "
"journal_read_trans skipping because %lu is too old\n",
- cur_dblock - reiserfs_get_journal_block(p_s_sb)) ;
+ cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb)) ;
brelse(d_bh) ;
return 1 ;
}
@@ -1487,7 +1493,9 @@
brelse(d_bh) ;
return 1 ;
}
- c_bh = sb_bread(p_s_sb, reiserfs_get_journal_block(p_s_sb) + ((trans_offset + le32_to_cpu(desc->j_len) + 1) % JOURNAL_BLOCK_COUNT)) ;
+ c_bh = journal_bread(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
+ ((trans_offset + le32_to_cpu(desc->j_len) + 1) %
+ SB_ONDISK_JOURNAL_SIZE(p_s_sb))) ;
if (!c_bh) {
brelse(d_bh) ;
return 1 ;
@@ -1496,7 +1504,7 @@
if (journal_compare_desc_commit(p_s_sb, desc, commit)) {
reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal_read_transaction, "
"commit offset %ld had bad time %d or length %d\n",
- c_bh->b_blocknr - reiserfs_get_journal_block(p_s_sb),
+ c_bh->b_blocknr - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb),
le32_to_cpu(commit->j_trans_id), le32_to_cpu(commit->j_len));
brelse(c_bh) ;
brelse(d_bh) ;
@@ -1511,24 +1519,24 @@
brelse(d_bh) ;
reiserfs_kfree(log_blocks, le32_to_cpu(desc->j_len) * sizeof(struct buffer_head *), p_s_sb) ;
reiserfs_kfree(real_blocks, le32_to_cpu(desc->j_len) * sizeof(struct buffer_head *), p_s_sb) ;
- reiserfs_warning("journal-1169: kmalloc failed, unable to mount FS\n") ;
+ reiserfs_warning(p_s_sb, "journal-1169: kmalloc failed, unable to mount FS\n") ;
return -1 ;
}
/* get all the buffer heads */
for(i = 0 ; i < le32_to_cpu(desc->j_len) ; i++) {
- log_blocks[i] = sb_getblk(p_s_sb, reiserfs_get_journal_block(p_s_sb) + (trans_offset + 1 + i) % JOURNAL_BLOCK_COUNT);
+ log_blocks[i] = journal_getblk(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + (trans_offset + 1 + i) % SB_ONDISK_JOURNAL_SIZE(p_s_sb));
if (i < JOURNAL_TRANS_HALF) {
real_blocks[i] = sb_getblk(p_s_sb, le32_to_cpu(desc->j_realblock[i])) ;
} else {
real_blocks[i] = sb_getblk(p_s_sb, le32_to_cpu(commit->j_realblock[i - JOURNAL_TRANS_HALF])) ;
}
if ( real_blocks[i]->b_blocknr > SB_BLOCK_COUNT(p_s_sb) ) {
- reiserfs_warning("journal-1207: REPLAY FAILURE fsck required! Block to replay is outside of filesystem\n");
+ reiserfs_warning(p_s_sb, "journal-1207: REPLAY FAILURE fsck required! Block to replay is outside of filesystem\n");
goto abort_replay;
}
- if (real_blocks[i]->b_blocknr >= reiserfs_get_journal_block(p_s_sb) &&
- real_blocks[i]->b_blocknr < (reiserfs_get_journal_block(p_s_sb)+JOURNAL_BLOCK_COUNT)) {
- reiserfs_warning("journal-1204: REPLAY FAILURE fsck required! Trying to replay onto a log block\n") ;
+ /* make sure we don't try to replay onto log or reserved area */
+ if (is_block_in_log_or_reserved_area(p_s_sb, real_blocks[i]->b_blocknr)) {
+ reiserfs_warning(p_s_sb, "journal-1204: REPLAY FAILURE fsck required! Trying to replay onto a log block\n") ;
abort_replay:
brelse_array(log_blocks, i) ;
brelse_array(real_blocks, i) ;
@@ -1544,7 +1552,7 @@
for (i = 0 ; i < le32_to_cpu(desc->j_len) ; i++) {
wait_on_buffer(log_blocks[i]) ;
if (!buffer_uptodate(log_blocks[i])) {
- reiserfs_warning("journal-1212: REPLAY FAILURE fsck required! buffer write failed\n") ;
+ reiserfs_warning(p_s_sb, "journal-1212: REPLAY FAILURE fsck required! buffer write failed\n") ;
brelse_array(log_blocks + i, le32_to_cpu(desc->j_len) - i) ;
brelse_array(real_blocks, le32_to_cpu(desc->j_len)) ;
brelse(c_bh) ;
@@ -1565,7 +1573,7 @@
for (i = 0 ; i < le32_to_cpu(desc->j_len) ; i++) {
wait_on_buffer(real_blocks[i]) ;
if (!buffer_uptodate(real_blocks[i])) {
- reiserfs_warning("journal-1226: REPLAY FAILURE, fsck required! buffer write failed\n") ;
+ reiserfs_warning(p_s_sb, "journal-1226: REPLAY FAILURE, fsck required! buffer write failed\n") ;
brelse_array(real_blocks + i, le32_to_cpu(desc->j_len) - i) ;
brelse(c_bh) ;
brelse(d_bh) ;
@@ -1575,13 +1583,13 @@
}
brelse(real_blocks[i]) ;
}
- cur_dblock = reiserfs_get_journal_block(p_s_sb) + ((trans_offset + le32_to_cpu(desc->j_len) + 2) % JOURNAL_BLOCK_COUNT) ;
+ cur_dblock = SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + ((trans_offset + le32_to_cpu(desc->j_len) + 2) % SB_ONDISK_JOURNAL_SIZE(p_s_sb)) ;
reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1095: setting journal "
"start to offset %ld\n",
- cur_dblock - reiserfs_get_journal_block(p_s_sb)) ;
+ cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb)) ;
/* init starting values for the first transaction, in case this is the last transaction to be replayed. */
- SB_JOURNAL(p_s_sb)->j_start = cur_dblock - reiserfs_get_journal_block(p_s_sb) ;
+ SB_JOURNAL(p_s_sb)->j_start = cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) ;
SB_JOURNAL(p_s_sb)->j_last_flush_trans_id = trans_id ;
SB_JOURNAL(p_s_sb)->j_trans_id = trans_id + 1;
brelse(c_bh) ;
@@ -1635,6 +1643,13 @@
brelse (bh);
return NULL;
}
+
+static struct buffer_head * journal_breada (struct super_block *p_s_sb, int block)
+{
+ return reiserfs_breada (SB_JOURNAL_DEV(p_s_sb), block, p_s_sb->s_blocksize,
+ SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + SB_ONDISK_JOURNAL_SIZE(p_s_sb));
+}
+
static int journal_read(struct super_block *p_s_sb) {
struct reiserfs_journal_desc *desc ;
unsigned long oldest_trans_id = 0;
@@ -1650,26 +1665,29 @@
int continue_replay = 1 ;
int ret ;
- cur_dblock = reiserfs_get_journal_block(p_s_sb) ;
+ cur_dblock = SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) ;
printk("reiserfs: checking transaction log (device %s) ...\n",
- kdevname(p_s_sb->s_dev)) ;
+ bdevname(SB_JOURNAL_DEV(p_s_sb))) ;
+ printk("for (%s)\n",
+ bdevname(p_s_sb->s_dev)) ;
+
start = CURRENT_TIME ;
/* step 1, read in the journal header block. Check the transaction it says
** is the first unflushed, and if that transaction is not valid,
** replay is done
*/
- SB_JOURNAL(p_s_sb)->j_header_bh = sb_bread(p_s_sb,
- reiserfs_get_journal_block(p_s_sb) +
- JOURNAL_BLOCK_COUNT) ;
+ SB_JOURNAL(p_s_sb)->j_header_bh = journal_bread(p_s_sb,
+ SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
+ SB_ONDISK_JOURNAL_SIZE(p_s_sb)) ;
if (!SB_JOURNAL(p_s_sb)->j_header_bh) {
return 1 ;
}
jh = (struct reiserfs_journal_header *)(SB_JOURNAL(p_s_sb)->j_header_bh->b_data) ;
if (le32_to_cpu(jh->j_first_unflushed_offset) >= 0 &&
- le32_to_cpu(jh->j_first_unflushed_offset) < JOURNAL_BLOCK_COUNT &&
+ le32_to_cpu(jh->j_first_unflushed_offset) < SB_ONDISK_JOURNAL_SIZE(p_s_sb) &&
le32_to_cpu(jh->j_last_flush_trans_id) > 0) {
- oldest_start = reiserfs_get_journal_block(p_s_sb) +
+ oldest_start = SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
le32_to_cpu(jh->j_first_unflushed_offset) ;
oldest_trans_id = le32_to_cpu(jh->j_last_flush_trans_id) + 1;
newest_mount_id = le32_to_cpu(jh->j_mount_id);
@@ -1683,7 +1701,7 @@
** there is nothing more we can do, and it makes no sense to read
** through the whole log.
*/
- d_bh = sb_bread(p_s_sb, reiserfs_get_journal_block(p_s_sb) + le32_to_cpu(jh->j_first_unflushed_offset)) ;
+ d_bh = journal_bread(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + le32_to_cpu(jh->j_first_unflushed_offset)) ;
ret = journal_transaction_is_valid(p_s_sb, d_bh, NULL, NULL) ;
if (!ret) {
continue_replay = 0 ;
@@ -1693,7 +1711,7 @@
}
if (continue_replay && is_read_only(p_s_sb->s_dev)) {
- printk("clm-2076: device is readonly, unable to replay log\n") ;
+ reiserfs_warning(p_s_sb, "clm-2076: device is readonly, unable to replay log\n") ;
return -1 ;
}
if (continue_replay && (p_s_sb->s_flags & MS_RDONLY)) {
@@ -1703,9 +1721,8 @@
/* ok, there are transactions that need to be replayed. start with the first log block, find
** all the valid transactions, and pick out the oldest.
*/
- while(continue_replay && cur_dblock < (reiserfs_get_journal_block(p_s_sb) + JOURNAL_BLOCK_COUNT)) {
- d_bh = reiserfs_breada(p_s_sb->s_dev, cur_dblock, p_s_sb->s_blocksize,
- reiserfs_get_journal_block(p_s_sb) + JOURNAL_BLOCK_COUNT) ;
+ while(continue_replay && cur_dblock < (SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + SB_ONDISK_JOURNAL_SIZE(p_s_sb))) {
+ d_bh = journal_breada(p_s_sb, cur_dblock) ;
ret = journal_transaction_is_valid(p_s_sb, d_bh, &oldest_invalid_trans_id, &newest_mount_id) ;
if (ret == 1) {
desc = (struct reiserfs_journal_desc *)d_bh->b_data ;
@@ -1715,7 +1732,7 @@
newest_mount_id = le32_to_cpu(desc->j_mount_id) ;
reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1179: Setting "
"oldest_start to offset %lu, trans_id %lu\n",
- oldest_start - reiserfs_get_journal_block(p_s_sb),
+ oldest_start - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb),
oldest_trans_id) ;
} else if (oldest_trans_id > le32_to_cpu(desc->j_trans_id)) {
/* one we just read was older */
@@ -1723,7 +1740,7 @@
oldest_start = d_bh->b_blocknr ;
reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1180: Resetting "
"oldest_start to offset %lu, trans_id %lu\n",
- oldest_start - reiserfs_get_journal_block(p_s_sb),
+ oldest_start - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb),
oldest_trans_id) ;
}
if (newest_mount_id < le32_to_cpu(desc->j_mount_id)) {
@@ -1743,7 +1760,7 @@
if (oldest_trans_id) {
reiserfs_debug(p_s_sb, REISERFS_DEBUG_CODE, "journal-1206: Starting replay "
"from offset %lu, trans_id %lu\n",
- cur_dblock - reiserfs_get_journal_block(p_s_sb),
+ cur_dblock - SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb),
oldest_trans_id) ;
}
@@ -1755,7 +1772,7 @@
} else if (ret != 0) {
break ;
}
- cur_dblock = reiserfs_get_journal_block(p_s_sb) + SB_JOURNAL(p_s_sb)->j_start ;
+ cur_dblock = SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + SB_JOURNAL(p_s_sb)->j_start ;
replay_count++ ;
if (cur_dblock == oldest_start)
break;
@@ -1850,7 +1867,7 @@
wake_up(&reiserfs_commit_thread_wait) ;
} else {
#ifdef CONFIG_REISERFS_CHECK
- reiserfs_warning("journal-1540: kmalloc failed, doing sync commit\n") ;
+ reiserfs_warning(p_s_sb, "journal-1540: kmalloc failed, doing sync commit\n") ;
#endif
flush_commit_list(p_s_sb, SB_JOURNAL_LIST(p_s_sb) + jindex, 1) ;
}
@@ -1905,95 +1922,305 @@
}
}
-/*
-** must be called once on fs mount. calls journal_read for you
-*/
-int journal_init(struct super_block *p_s_sb) {
- int num_cnodes = JOURNAL_BLOCK_COUNT * 2 ;
+static int release_journal_dev( struct super_block *super,
+ struct reiserfs_journal *journal )
+{
+ int result;
+
+ result = 0;
+
+ if( journal -> j_dev_bd != NULL && journal->j_dev_bd != super->s_bdev) {
+ result = blkdev_put( journal -> j_dev_bd, BDEV_FS );
+ journal -> j_dev_bd = NULL;
+ }
+ if( journal -> j_dev_file != NULL ) {
+ result = filp_close( journal -> j_dev_file, NULL );
+ journal -> j_dev_file = NULL;
+ }
+ if( result != 0 ) {
+ reiserfs_warning(super, "release_journal_dev: Cannot release journal device: %i", result );
+ }
+ return result;
+}
- if (sizeof(struct reiserfs_journal_commit) != 4096 ||
- sizeof(struct reiserfs_journal_desc) != 4096
- ) {
- printk("journal-1249: commit or desc struct not 4096 %Zd %Zd\n", sizeof(struct reiserfs_journal_commit),
- sizeof(struct reiserfs_journal_desc)) ;
- return 1 ;
- }
- /* sanity check to make sure they don't overflow the journal */
- if (JOURNAL_BLOCK_COUNT > reiserfs_get_journal_orig_size(p_s_sb)) {
- printk("journal-1393: current JOURNAL_BLOCK_COUNT (%d) is too big. This FS was created with a journal size of %lu blocks\n",
- JOURNAL_BLOCK_COUNT, reiserfs_get_journal_orig_size(p_s_sb)) ;
- return 1 ;
- }
- SB_JOURNAL(p_s_sb) = vmalloc(sizeof (struct reiserfs_journal)) ;
+static int journal_init_dev( struct super_block *super,
+ struct reiserfs_journal *journal,
+ const char *jdev_name )
+{
+ int result;
+ kdev_t jdev;
+ int blkdev_mode = FMODE_READ | FMODE_WRITE;
+
+ result = 0;
+
+ journal -> j_dev_bd = NULL;
+ journal -> j_dev_file = NULL;
+ jdev = SB_JOURNAL_DEV( super ) =
+ SB_ONDISK_JOURNAL_DEVICE( super ) ?
+ to_kdev_t(SB_ONDISK_JOURNAL_DEVICE( super )) : super -> s_dev;
+
+ /* there is no "jdev" option */
+
+ if (is_read_only(super->s_dev))
+ blkdev_mode = FMODE_READ;
+
+ if( ( !jdev_name || !jdev_name[ 0 ] ) ) {
+
+ /* don't add an extra reference to the device when
+ * the log is on the same disk as the FS. It makes the
+ * raid code unhappy
+ */
+ if (jdev == super->s_dev) {
+ journal->j_dev_bd = super->s_bdev;
+ return 0;
+ }
+ journal -> j_dev_bd = bdget( kdev_t_to_nr( jdev ) );
+ if( journal -> j_dev_bd ) {
+ result = blkdev_get( journal -> j_dev_bd,
+ blkdev_mode, 0, BDEV_FS );
+ if (result) {
+ bdput(journal->j_dev_bd);
+ journal->j_dev_bd = NULL;
+ }
+ } else {
+ result = -ENOMEM;
+ }
+ if( result != 0 )
+ printk( "journal_init_dev: cannot init journal device\n '%s': %i",
+ kdevname( jdev ), result );
- if (!SB_JOURNAL(p_s_sb)) {
- printk("journal-1256: unable to get memory for journal structure\n") ;
- return 1 ;
- }
- memset(SB_JOURNAL(p_s_sb), 0, sizeof(struct reiserfs_journal)) ;
+ return result;
+ }
- SB_JOURNAL(p_s_sb)->j_list_bitmap_index = 0 ;
- SB_JOURNAL_LIST_INDEX(p_s_sb) = -10000 ; /* make sure flush_old_commits does not try to flush a list while replay is on */
+ /* "jdev" option has been found */
- /* clear out the journal list array */
- memset(SB_JOURNAL_LIST(p_s_sb), 0, sizeof(struct reiserfs_journal_list) * JOURNAL_LIST_COUNT) ;
- journal_list_init(p_s_sb) ;
+ journal -> j_dev_file = filp_open( jdev_name, 0, 0 );
+ if( !IS_ERR( journal -> j_dev_file ) ) {
+ struct inode *jdev_inode;
+
+ jdev_inode = journal -> j_dev_file -> f_dentry -> d_inode;
+ journal -> j_dev_bd = jdev_inode -> i_bdev;
+ if( !S_ISBLK( jdev_inode -> i_mode ) ) {
+ printk( "journal_init_dev: '%s' is not a block device", jdev_name );
+ result = -ENOTBLK;
+ } else if( journal -> j_dev_file -> f_vfsmnt -> mnt_flags & MNT_NODEV) {
+ printk( "journal_init_dev: Cannot use devices on '%s'", jdev_name );
+ result = -EACCES;
+ } else if( jdev_inode -> i_bdev == NULL ) {
+ printk( "journal_init_dev: bdev unintialized for '%s'", jdev_name );
+ result = -ENOMEM;
+ } else if( ( result = blkdev_get( jdev_inode -> i_bdev,
+ blkdev_mode,
+ 0, BDEV_FS ) ) != 0 ) {
+ journal -> j_dev_bd = NULL;
+ printk( "journal_init_dev: Cannot load device '%s': %i", jdev_name,
+ result );
+ } else
+ /* ok */
+ SB_JOURNAL_DEV( super ) =
+ to_kdev_t( jdev_inode -> i_bdev -> bd_dev );
+ } else {
+ result = PTR_ERR( journal -> j_dev_file );
+ journal -> j_dev_file = NULL;
+ printk( "journal_init_dev: Cannot open '%s': %i", jdev_name, result );
+ }
+ if( result != 0 ) {
+ release_journal_dev( super, journal );
+ }
+ printk( "journal_init_dev: journal device: %s", kdevname( SB_JOURNAL_DEV( super ) ) );
+ return result;
+}
+
+/*
+** must be called once on fs mount. calls journal_read for you
+*/
+int journal_init(struct super_block *p_s_sb, const char * j_dev_name,
+ int old_format) {
+ int num_cnodes = SB_ONDISK_JOURNAL_SIZE(p_s_sb) * 2 ;
+ struct buffer_head *bhjh;
+ struct reiserfs_super_block * rs;
+ struct reiserfs_journal_header *jh;
+ struct reiserfs_journal *journal;
+
+ if (sizeof(struct reiserfs_journal_commit) != 4096 ||
+ sizeof(struct reiserfs_journal_desc) != 4096) {
+ reiserfs_warning(p_s_sb, "journal-1249: commit or desc struct not 4096 %Zd %Zd\n",
+ sizeof(struct reiserfs_journal_commit),
+ sizeof(struct reiserfs_journal_desc)) ;
+ return 1 ;
+ }
- memset(SB_JOURNAL(p_s_sb)->j_list_hash_table, 0, JOURNAL_HASH_SIZE * sizeof(struct reiserfs_journal_cnode *)) ;
- memset(journal_writers, 0, sizeof(char *) * 512) ; /* debug code */
+ if ( SB_ONDISK_JOURNAL_SIZE(p_s_sb) < 512 ) {
+ reiserfs_warning(p_s_sb, "Journal size %d is less than 512+1 blocks, which unsupported\n", SB_ONDISK_JOURNAL_SIZE(p_s_sb));
+ return 1 ;
+ }
- INIT_LIST_HEAD(&SB_JOURNAL(p_s_sb)->j_bitmap_nodes) ;
- INIT_LIST_HEAD(&SB_JOURNAL(p_s_sb)->j_dirty_buffers) ;
- reiserfs_allocate_list_bitmaps(p_s_sb, SB_JOURNAL(p_s_sb)->j_list_bitmap,
- SB_BMAP_NR(p_s_sb)) ;
- allocate_bitmap_nodes(p_s_sb) ;
+ journal = SB_JOURNAL(p_s_sb) = vmalloc(sizeof (struct reiserfs_journal)) ;
+ if (!journal) {
+ reiserfs_warning(p_s_sb, "journal-1256: unable to get memory for journal structure\n") ;
+ return 1 ;
+ }
+ memset(journal, 0, sizeof(struct reiserfs_journal)) ;
+ INIT_LIST_HEAD(&SB_JOURNAL(p_s_sb)->j_bitmap_nodes) ;
+ INIT_LIST_HEAD (&SB_JOURNAL(p_s_sb)->j_prealloc_list);
+
+ reiserfs_allocate_list_bitmaps(p_s_sb, SB_JOURNAL(p_s_sb)->j_list_bitmap,
+ SB_BMAP_NR(p_s_sb)) ;
+ allocate_bitmap_nodes(p_s_sb) ;
+
+ /* reserved for journal area support */
+ SB_JOURNAL_1st_RESERVED_BLOCK(p_s_sb) = (old_format ?
+ REISERFS_OLD_DISK_OFFSET_IN_BYTES /
+ p_s_sb->s_blocksize +
+ SB_BMAP_NR(p_s_sb) + 1 :
+ REISERFS_DISK_OFFSET_IN_BYTES /
+ p_s_sb->s_blocksize + 2);
+
+ if( journal_init_dev( p_s_sb, journal, j_dev_name ) != 0 ) {
+ reiserfs_warning(p_s_sb, "journal-1259: unable to initialize jornal device\n");
+ goto free_and_return;
+ }
+
+ rs = SB_DISK_SUPER_BLOCK(p_s_sb);
+
+ /* read journal header */
+ bhjh = journal_bread (p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
+ SB_ONDISK_JOURNAL_SIZE(p_s_sb));
+ if (!bhjh) {
+ reiserfs_warning(p_s_sb, "journal-459: unable to read journal header\n") ;
+ goto free_and_return;
+ }
+ jh = (struct reiserfs_journal_header *)(bhjh->b_data);
+
+ /* make sure that journal matches to the super block */
+ if (is_reiserfs_jr(rs) &&
+ jh->jh_journal.jp_journal_magic != sb_jp_journal_magic(rs)) {
+ char jname[ 32 ];
+ char fname[ 32 ];
+
+ strcpy( jname, kdevname( SB_JOURNAL_DEV(p_s_sb) ) );
+ strcpy( fname, kdevname( p_s_sb->s_dev ) );
+ printk("journal-460: journal header magic %x (device %s) does not "
+ "match magic found in super block %x (device %s)\n",
+ jh->jh_journal.jp_journal_magic, jname,
+ sb_jp_journal_magic(rs), fname);
+ brelse (bhjh);
+ goto free_and_return;
+ }
+
+ SB_JOURNAL_TRANS_MAX(p_s_sb) = le32_to_cpu (jh->jh_journal.jp_journal_trans_max);
+ SB_JOURNAL_MAX_BATCH(p_s_sb) = le32_to_cpu (jh->jh_journal.jp_journal_max_batch);
+ SB_JOURNAL_MAX_COMMIT_AGE(p_s_sb) = le32_to_cpu (jh->jh_journal.jp_journal_max_commit_age);
+ SB_JOURNAL_MAX_TRANS_AGE(p_s_sb) = JOURNAL_MAX_TRANS_AGE;
+
+ if (SB_JOURNAL_TRANS_MAX(p_s_sb)) {
+ /* make sure these parameters are available, assign if they are not */
+ __u32 initial = SB_JOURNAL_TRANS_MAX(p_s_sb);
+ __u32 ratio = 1;
+
+ if (p_s_sb->s_blocksize < 4096)
+ ratio = 4096 / p_s_sb->s_blocksize;
+
+ if (SB_ONDISK_JOURNAL_SIZE(p_s_sb)/SB_JOURNAL_TRANS_MAX(p_s_sb) <
+ JOURNAL_MIN_RATIO)
+ {
+ SB_JOURNAL_TRANS_MAX(p_s_sb) = SB_ONDISK_JOURNAL_SIZE(p_s_sb) /
+ JOURNAL_MIN_RATIO;
+ }
+ if (SB_JOURNAL_TRANS_MAX(p_s_sb) > JOURNAL_TRANS_MAX_DEFAULT / ratio)
+ SB_JOURNAL_TRANS_MAX(p_s_sb) = JOURNAL_TRANS_MAX_DEFAULT / ratio;
+ if (SB_JOURNAL_TRANS_MAX(p_s_sb) < JOURNAL_TRANS_MIN_DEFAULT / ratio)
+ SB_JOURNAL_TRANS_MAX(p_s_sb) = JOURNAL_TRANS_MIN_DEFAULT / ratio;
+
+ if (SB_JOURNAL_TRANS_MAX(p_s_sb) != initial) {
+ printk ("reiserfs warning: wrong transaction max size (%u). "
+ "Changed to %u\n", initial, SB_JOURNAL_TRANS_MAX(p_s_sb));
+ }
+ SB_JOURNAL_MAX_BATCH(p_s_sb) = SB_JOURNAL_TRANS_MAX(p_s_sb) *
+ JOURNAL_MAX_BATCH_DEFAULT /
+ JOURNAL_TRANS_MAX_DEFAULT;
+ }
+
+ if (!SB_JOURNAL_TRANS_MAX(p_s_sb)) {
+ /*we have the file system was created by old version of mkreiserfs
+ so this field contains zero value */
+ SB_JOURNAL_TRANS_MAX(p_s_sb) = JOURNAL_TRANS_MAX_DEFAULT ;
+ SB_JOURNAL_MAX_BATCH(p_s_sb) = JOURNAL_MAX_BATCH_DEFAULT ;
+ SB_JOURNAL_MAX_COMMIT_AGE(p_s_sb) = JOURNAL_MAX_COMMIT_AGE ;
+
+ /* for blocksize >= 4096 - max transaction size is 1024. For
+ block size < 4096 trans max size is decreased proportionally */
+ if (p_s_sb->s_blocksize < 4096) {
+ SB_JOURNAL_TRANS_MAX(p_s_sb) /= (4096 / p_s_sb->s_blocksize) ;
+ SB_JOURNAL_MAX_BATCH(p_s_sb) = SB_JOURNAL_TRANS_MAX(p_s_sb)*9 / 10;
+ }
+ }
- SB_JOURNAL(p_s_sb)->j_start = 0 ;
- SB_JOURNAL(p_s_sb)->j_len = 0 ;
- SB_JOURNAL(p_s_sb)->j_len_alloc = 0 ;
- atomic_set(&(SB_JOURNAL(p_s_sb)->j_wcount), 0) ;
- SB_JOURNAL(p_s_sb)->j_bcount = 0 ;
- SB_JOURNAL(p_s_sb)->j_trans_start_time = 0 ;
- SB_JOURNAL(p_s_sb)->j_last = NULL ;
- SB_JOURNAL(p_s_sb)->j_first = NULL ;
- init_waitqueue_head(&(SB_JOURNAL(p_s_sb)->j_join_wait)) ;
- init_waitqueue_head(&(SB_JOURNAL(p_s_sb)->j_wait)) ;
-
- SB_JOURNAL(p_s_sb)->j_trans_id = 10 ;
- SB_JOURNAL(p_s_sb)->j_mount_id = 10 ;
- SB_JOURNAL(p_s_sb)->j_state = 0 ;
- atomic_set(&(SB_JOURNAL(p_s_sb)->j_jlock), 0) ;
- atomic_set(&(SB_JOURNAL(p_s_sb)->j_wlock), 0) ;
- SB_JOURNAL(p_s_sb)->j_cnode_free_list = allocate_cnodes(num_cnodes) ;
- SB_JOURNAL(p_s_sb)->j_cnode_free_orig = SB_JOURNAL(p_s_sb)->j_cnode_free_list ;
- SB_JOURNAL(p_s_sb)->j_cnode_free = SB_JOURNAL(p_s_sb)->j_cnode_free_list ? num_cnodes : 0 ;
- SB_JOURNAL(p_s_sb)->j_cnode_used = 0 ;
- SB_JOURNAL(p_s_sb)->j_must_wait = 0 ;
- init_journal_hash(p_s_sb) ;
- SB_JOURNAL_LIST(p_s_sb)[0].j_list_bitmap = get_list_bitmap(p_s_sb, SB_JOURNAL_LIST(p_s_sb)) ;
- if (!(SB_JOURNAL_LIST(p_s_sb)[0].j_list_bitmap)) {
- reiserfs_warning("journal-2005, get_list_bitmap failed for journal list 0\n") ;
- return 1 ;
- }
- if (journal_read(p_s_sb) < 0) {
- reiserfs_warning("Replay Failure, unable to mount\n") ;
- free_journal_ram(p_s_sb) ;
- return 1 ;
- }
- SB_JOURNAL_LIST_INDEX(p_s_sb) = 0 ; /* once the read is done, we can set this
- where it belongs */
+ brelse (bhjh);
- INIT_LIST_HEAD (&SB_JOURNAL(p_s_sb)->j_prealloc_list);
+ SB_JOURNAL(p_s_sb)->j_list_bitmap_index = 0 ;
+ SB_JOURNAL_LIST_INDEX(p_s_sb) = -10000 ; /* make sure flush_old_commits does not try to flush a list while replay is on */
- if (reiserfs_dont_log (p_s_sb))
- return 0;
+ /* clear out the journal list array */
+ memset(SB_JOURNAL_LIST(p_s_sb), 0,
+ sizeof(struct reiserfs_journal_list) * JOURNAL_LIST_COUNT) ;
+
+ journal_list_init(p_s_sb) ;
+
+ memset(SB_JOURNAL(p_s_sb)->j_list_hash_table, 0,
+ JOURNAL_HASH_SIZE * sizeof(struct reiserfs_journal_cnode *)) ;
+ memset(journal_writers, 0, sizeof(char *) * 512) ; /* debug code */
+
+ INIT_LIST_HEAD(&(SB_JOURNAL(p_s_sb)->j_dirty_buffers)) ;
+
+ SB_JOURNAL(p_s_sb)->j_start = 0 ;
+ SB_JOURNAL(p_s_sb)->j_len = 0 ;
+ SB_JOURNAL(p_s_sb)->j_len_alloc = 0 ;
+ atomic_set(&(SB_JOURNAL(p_s_sb)->j_wcount), 0) ;
+ SB_JOURNAL(p_s_sb)->j_bcount = 0 ;
+ SB_JOURNAL(p_s_sb)->j_trans_start_time = 0 ;
+ SB_JOURNAL(p_s_sb)->j_last = NULL ;
+ SB_JOURNAL(p_s_sb)->j_first = NULL ;
+ init_waitqueue_head(&(SB_JOURNAL(p_s_sb)->j_join_wait)) ;
+ init_waitqueue_head(&(SB_JOURNAL(p_s_sb)->j_wait)) ;
+
+ SB_JOURNAL(p_s_sb)->j_trans_id = 10 ;
+ SB_JOURNAL(p_s_sb)->j_mount_id = 10 ;
+ SB_JOURNAL(p_s_sb)->j_state = 0 ;
+ atomic_set(&(SB_JOURNAL(p_s_sb)->j_jlock), 0) ;
+ atomic_set(&(SB_JOURNAL(p_s_sb)->j_wlock), 0) ;
+ SB_JOURNAL(p_s_sb)->j_cnode_free_list = allocate_cnodes(num_cnodes) ;
+ SB_JOURNAL(p_s_sb)->j_cnode_free_orig = SB_JOURNAL(p_s_sb)->j_cnode_free_list ;
+ SB_JOURNAL(p_s_sb)->j_cnode_free = SB_JOURNAL(p_s_sb)->j_cnode_free_list ?
+ num_cnodes : 0 ;
+ SB_JOURNAL(p_s_sb)->j_cnode_used = 0 ;
+ SB_JOURNAL(p_s_sb)->j_must_wait = 0 ;
+ init_journal_hash(p_s_sb) ;
+ SB_JOURNAL_LIST(p_s_sb)[0].j_list_bitmap = get_list_bitmap(p_s_sb, SB_JOURNAL_LIST(p_s_sb)) ;
+ if (!(SB_JOURNAL_LIST(p_s_sb)[0].j_list_bitmap)) {
+ reiserfs_warning(p_s_sb, "journal-2005, get_list_bitmap failed for journal list 0\n") ;
+ goto free_and_return;
+ }
+ if (journal_read(p_s_sb) < 0) {
+ reiserfs_warning(p_s_sb, "Replay Failure, unable to mount\n") ;
+ goto free_and_return;
+ }
+ /* once the read is done, we can set this where it belongs */
+ SB_JOURNAL_LIST_INDEX(p_s_sb) = 0 ;
+
+ if (reiserfs_dont_log (p_s_sb))
+ return 0;
+
+ reiserfs_mounted_fs_count++ ;
+ if (reiserfs_mounted_fs_count <= 1) {
+ kernel_thread((void *)(void *)reiserfs_journal_commit_thread, NULL,
+ CLONE_FS | CLONE_FILES | CLONE_VM) ;
+ }
+ return 0 ;
- reiserfs_mounted_fs_count++ ;
- if (reiserfs_mounted_fs_count <= 1) {
- kernel_thread((void *)(void *)reiserfs_journal_commit_thread, NULL,
- CLONE_FS | CLONE_FILES | CLONE_VM) ;
- }
- return 0 ;
+free_and_return:
+ free_journal_ram(p_s_sb);
+ return 1;
}
/*
@@ -2006,10 +2233,10 @@
if (reiserfs_dont_log(th->t_super))
return 0 ;
if ( SB_JOURNAL(th->t_super)->j_must_wait > 0 ||
- (SB_JOURNAL(th->t_super)->j_len_alloc + new_alloc) >= JOURNAL_MAX_BATCH ||
+ (SB_JOURNAL(th->t_super)->j_len_alloc + new_alloc) >= SB_JOURNAL_MAX_BATCH(th->t_super) ||
atomic_read(&(SB_JOURNAL(th->t_super)->j_jlock)) ||
- (now - SB_JOURNAL(th->t_super)->j_trans_start_time) > JOURNAL_MAX_TRANS_AGE ||
- SB_JOURNAL(th->t_super)->j_cnode_free < (JOURNAL_TRANS_MAX * 3)) {
+ (now - SB_JOURNAL(th->t_super)->j_trans_start_time) > SB_JOURNAL_MAX_TRANS_AGE(th->t_super) ||
+ SB_JOURNAL(th->t_super)->j_cnode_free < (SB_JOURNAL_TRANS_MAX(th->t_super) * 3)) {
return 1 ;
}
return 0 ;
@@ -2076,13 +2303,12 @@
** we don't sleep if there aren't other writers
*/
-
if ( (!join && SB_JOURNAL(p_s_sb)->j_must_wait > 0) ||
- ( !join && (SB_JOURNAL(p_s_sb)->j_len_alloc + nblocks + 2) >= JOURNAL_MAX_BATCH) ||
+ ( !join && (SB_JOURNAL(p_s_sb)->j_len_alloc + nblocks + 2) >= SB_JOURNAL_MAX_BATCH(p_s_sb)) ||
(!join && atomic_read(&(SB_JOURNAL(p_s_sb)->j_wcount)) > 0 && SB_JOURNAL(p_s_sb)->j_trans_start_time > 0 &&
- (now - SB_JOURNAL(p_s_sb)->j_trans_start_time) > JOURNAL_MAX_TRANS_AGE) ||
+ (now - SB_JOURNAL(p_s_sb)->j_trans_start_time) > SB_JOURNAL_MAX_TRANS_AGE(p_s_sb)) ||
(!join && atomic_read(&(SB_JOURNAL(p_s_sb)->j_jlock)) ) ||
- (!join && SB_JOURNAL(p_s_sb)->j_cnode_free < (JOURNAL_TRANS_MAX * 3))) {
+ (!join && SB_JOURNAL(p_s_sb)->j_cnode_free < (SB_JOURNAL_TRANS_MAX(p_s_sb) * 3))) {
unlock_journal(p_s_sb) ; /* allow others to finish this transaction */
@@ -2177,7 +2403,7 @@
** could get to disk too early. NOT GOOD.
*/
if (!prepared || buffer_locked(bh)) {
- printk("journal-1777: buffer %lu bad state %cPREPARED %cLOCKED %cDIRTY %cJDIRTY_WAIT\n", bh->b_blocknr, prepared ? ' ' : '!',
+ reiserfs_warning(p_s_sb, "journal-1777: buffer %lu bad state %cPREPARED %cLOCKED %cDIRTY %cJDIRTY_WAIT\n", bh->b_blocknr, prepared ? ' ' : '!',
buffer_locked(bh) ? ' ' : '!',
buffer_dirty(bh) ? ' ' : '!',
buffer_journal_dirty(bh) ? ' ' : '!') ;
@@ -2186,13 +2412,13 @@
count_already_incd = clear_prepared_bits(bh) ;
if (atomic_read(&(SB_JOURNAL(p_s_sb)->j_wcount)) <= 0) {
- printk("journal-1409: journal_mark_dirty returning because j_wcount was %d\n", atomic_read(&(SB_JOURNAL(p_s_sb)->j_wcount))) ;
+ reiserfs_warning(p_s_sb, "journal-1409: journal_mark_dirty returning because j_wcount was %d\n", atomic_read(&(SB_JOURNAL(p_s_sb)->j_wcount))) ;
return 1 ;
}
/* this error means I've screwed up, and we've overflowed the transaction.
** Nothing can be done here, except make the FS readonly or panic.
*/
- if (SB_JOURNAL(p_s_sb)->j_len >= JOURNAL_TRANS_MAX) {
+ if (SB_JOURNAL(p_s_sb)->j_len >= SB_JOURNAL_TRANS_MAX(p_s_sb)) {
reiserfs_panic(th->t_super, "journal-1413: journal_mark_dirty: j_len (%lu) is too big\n", SB_JOURNAL(p_s_sb)->j_len) ;
}
@@ -2310,7 +2536,7 @@
mark_buffer_notjournal_dirty(bh) ;
put_bh(bh) ;
if (atomic_read(&(bh->b_count)) < 0) {
- printk("journal-1752: remove from trans, b_count < 0\n") ;
+ reiserfs_warning(p_s_sb, "journal-1752: remove from trans, b_count < 0\n") ;
}
if (!buffer_locked(bh)) reiserfs_clean_and_file_buffer(bh) ;
ret = 1 ;
@@ -2433,7 +2659,7 @@
/* starting with oldest, loop until we get to the start */
i = (SB_JOURNAL_LIST_INDEX(p_s_sb) + 1) % JOURNAL_LIST_COUNT ;
while(i != start) {
- if (SB_JOURNAL_LIST(p_s_sb)[i].j_len > 0 && ((now - SB_JOURNAL_LIST(p_s_sb)[i].j_timestamp) > JOURNAL_MAX_COMMIT_AGE ||
+ if (SB_JOURNAL_LIST(p_s_sb)[i].j_len > 0 && ((now - SB_JOURNAL_LIST(p_s_sb)[i].j_timestamp) > SB_JOURNAL_MAX_COMMIT_AGE(p_s_sb) ||
immediate)) {
/* we have to check again to be sure the current transaction did not change */
if (i != SB_JOURNAL_LIST_INDEX(p_s_sb)) {
@@ -2449,7 +2675,7 @@
if (!immediate && atomic_read(&(SB_JOURNAL(p_s_sb)->j_wcount)) <= 0 &&
SB_JOURNAL(p_s_sb)->j_trans_start_time > 0 &&
SB_JOURNAL(p_s_sb)->j_len > 0 &&
- (now - SB_JOURNAL(p_s_sb)->j_trans_start_time) > JOURNAL_MAX_TRANS_AGE) {
+ (now - SB_JOURNAL(p_s_sb)->j_trans_start_time) > SB_JOURNAL_MAX_TRANS_AGE(p_s_sb)) {
journal_join(&th, p_s_sb, 1) ;
reiserfs_prepare_for_journal(p_s_sb, SB_BUFFER_WITH_SB(p_s_sb), 1) ;
journal_mark_dirty(&th, p_s_sb, SB_BUFFER_WITH_SB(p_s_sb)) ;
@@ -2541,21 +2767,21 @@
/* deal with old transactions where we are the last writers */
now = CURRENT_TIME ;
- if ((now - SB_JOURNAL(p_s_sb)->j_trans_start_time) > JOURNAL_MAX_TRANS_AGE) {
+ if ((now - SB_JOURNAL(p_s_sb)->j_trans_start_time) > SB_JOURNAL_MAX_TRANS_AGE(p_s_sb)) {
commit_now = 1 ;
SB_JOURNAL(p_s_sb)->j_next_async_flush = 1 ;
}
/* don't batch when someone is waiting on j_join_wait */
/* don't batch when syncing the commit or flushing the whole trans */
if (!(SB_JOURNAL(p_s_sb)->j_must_wait > 0) && !(atomic_read(&(SB_JOURNAL(p_s_sb)->j_jlock))) && !flush && !commit_now &&
- (SB_JOURNAL(p_s_sb)->j_len < JOURNAL_MAX_BATCH) &&
- SB_JOURNAL(p_s_sb)->j_len_alloc < JOURNAL_MAX_BATCH && SB_JOURNAL(p_s_sb)->j_cnode_free > (JOURNAL_TRANS_MAX * 3)) {
+ (SB_JOURNAL(p_s_sb)->j_len < SB_JOURNAL_MAX_BATCH(p_s_sb)) &&
+ SB_JOURNAL(p_s_sb)->j_len_alloc < SB_JOURNAL_MAX_BATCH(p_s_sb) && SB_JOURNAL(p_s_sb)->j_cnode_free > (SB_JOURNAL_TRANS_MAX(p_s_sb) * 3)) {
SB_JOURNAL(p_s_sb)->j_bcount++ ;
unlock_journal(p_s_sb) ;
return 0 ;
}
- if (SB_JOURNAL(p_s_sb)->j_start > JOURNAL_BLOCK_COUNT) {
+ if (SB_JOURNAL(p_s_sb)->j_start > SB_ONDISK_JOURNAL_SIZE(p_s_sb)) {
reiserfs_panic(p_s_sb, "journal-003: journal_end: j_start (%ld) is too high\n", SB_JOURNAL(p_s_sb)->j_start) ;
}
return 1 ;
@@ -2584,7 +2810,7 @@
if (reiserfs_dont_log(th->t_super)) {
bh = sb_get_hash_table(p_s_sb, blocknr) ;
if (bh && buffer_dirty (bh)) {
- printk ("journal_mark_freed(dont_log): dirty buffer on hash list: %lx %ld\n", bh->b_state, blocknr);
+ reiserfs_warning (p_s_sb, "journal_mark_freed(dont_log): dirty buffer on hash list: %lx %ld\n", bh->b_state, blocknr);
BUG ();
}
brelse (bh);
@@ -2625,7 +2851,7 @@
cleaned = 1 ;
put_bh(cn->bh) ;
if (atomic_read(&(cn->bh->b_count)) < 0) {
- printk("journal-2138: cn->bh->b_count < 0\n") ;
+ reiserfs_warning(p_s_sb, "journal-2138: cn->bh->b_count < 0\n") ;
}
}
if (cn->jlist) { /* since we are clearing the bh, we MUST dec nonzerolen */
@@ -2642,7 +2868,7 @@
reiserfs_clean_and_file_buffer(bh) ;
put_bh(bh) ; /* get_hash grabs the buffer */
if (atomic_read(&(bh->b_count)) < 0) {
- printk("journal-2165: bh->b_count < 0\n") ;
+ reiserfs_warning(p_s_sb, "journal-2165: bh->b_count < 0\n") ;
}
}
return 0 ;
@@ -2817,7 +3043,7 @@
rs = SB_DISK_SUPER_BLOCK(p_s_sb) ;
/* setup description block */
- d_bh = sb_getblk(p_s_sb, reiserfs_get_journal_block(p_s_sb) + SB_JOURNAL(p_s_sb)->j_start) ;
+ d_bh = journal_getblk(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) + SB_JOURNAL(p_s_sb)->j_start) ;
mark_buffer_uptodate(d_bh, 1) ;
desc = (struct reiserfs_journal_desc *)(d_bh)->b_data ;
memset(desc, 0, sizeof(struct reiserfs_journal_desc)) ;
@@ -2825,8 +3051,8 @@
desc->j_trans_id = cpu_to_le32(SB_JOURNAL(p_s_sb)->j_trans_id) ;
/* setup commit block. Don't write (keep it clean too) this one until after everyone else is written */
- c_bh = sb_getblk(p_s_sb, reiserfs_get_journal_block(p_s_sb) +
- ((SB_JOURNAL(p_s_sb)->j_start + SB_JOURNAL(p_s_sb)->j_len + 1) % JOURNAL_BLOCK_COUNT)) ;
+ c_bh = journal_getblk(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
+ ((SB_JOURNAL(p_s_sb)->j_start + SB_JOURNAL(p_s_sb)->j_len + 1) % SB_ONDISK_JOURNAL_SIZE(p_s_sb))) ;
commit = (struct reiserfs_journal_commit *)c_bh->b_data ;
memset(commit, 0, sizeof(struct reiserfs_journal_commit)) ;
commit->j_trans_id = cpu_to_le32(SB_JOURNAL(p_s_sb)->j_trans_id) ;
@@ -2869,8 +3095,10 @@
last_cn->next = jl_cn ;
}
last_cn = jl_cn ;
- if (cn->bh->b_blocknr >= reiserfs_get_journal_block(p_s_sb) &&
- cn->bh->b_blocknr < (reiserfs_get_journal_block(p_s_sb) + JOURNAL_BLOCK_COUNT)) {
+ /* make sure the block we are trying to log is not a block
+ of journal or reserved area */
+
+ if (is_block_in_log_or_reserved_area(p_s_sb, cn->bh->b_blocknr)) {
reiserfs_panic(p_s_sb, "journal-2332: Trying to log block %lu, which is a log block\n", cn->bh->b_blocknr) ;
}
jl_cn->blocknr = cn->bh->b_blocknr ;
@@ -2899,7 +3127,7 @@
brelse(d_bh) ;
brelse(c_bh) ;
unlock_journal(p_s_sb) ;
-printk("journal-2020: do_journal_end: BAD desc->j_len is ZERO\n") ;
+reiserfs_warning(p_s_sb, "journal-2020: do_journal_end: BAD desc->j_len is ZERO\n") ;
atomic_set(&(SB_JOURNAL(p_s_sb)->j_jlock), 0) ;
wake_up(&(SB_JOURNAL(p_s_sb)->j_join_wait)) ;
return 0 ;
@@ -2914,14 +3142,14 @@
/* copy all the real blocks into log area. dirty log blocks */
if (test_bit(BH_JDirty, &cn->bh->b_state)) {
struct buffer_head *tmp_bh ;
- tmp_bh = sb_getblk(p_s_sb, reiserfs_get_journal_block(p_s_sb) +
- ((cur_write_start + jindex) % JOURNAL_BLOCK_COUNT)) ;
+ tmp_bh = journal_getblk(p_s_sb, SB_ONDISK_JOURNAL_1st_BLOCK(p_s_sb) +
+ ((cur_write_start + jindex) % SB_ONDISK_JOURNAL_SIZE(p_s_sb))) ;
mark_buffer_uptodate(tmp_bh, 1) ;
memcpy(tmp_bh->b_data, cn->bh->b_data, cn->bh->b_size) ;
jindex++ ;
} else {
/* JDirty cleared sometime during transaction. don't log this one */
- printk("journal-2048: do_journal_end: BAD, buffer in journal hash, but not JDirty!\n") ;
+ reiserfs_warning(p_s_sb, "journal-2048: do_journal_end: BAD, buffer in journal hash, but not JDirty!\n") ;
}
cn = cn->next ;
cur_blocks_left-- ;
@@ -2976,7 +3204,7 @@
/* reset journal values for the next transaction */
old_start = SB_JOURNAL(p_s_sb)->j_start ;
- SB_JOURNAL(p_s_sb)->j_start = (SB_JOURNAL(p_s_sb)->j_start + SB_JOURNAL(p_s_sb)->j_len + 2) % JOURNAL_BLOCK_COUNT;
+ SB_JOURNAL(p_s_sb)->j_start = (SB_JOURNAL(p_s_sb)->j_start + SB_JOURNAL(p_s_sb)->j_len + 2) % SB_ONDISK_JOURNAL_SIZE(p_s_sb);
atomic_set(&(SB_JOURNAL(p_s_sb)->j_wcount), 0) ;
SB_JOURNAL(p_s_sb)->j_bcount = 0 ;
SB_JOURNAL(p_s_sb)->j_last = NULL ;
@@ -2997,12 +3225,12 @@
for (i = 0 ; i < JOURNAL_LIST_COUNT ; i++) {
jindex = i ;
if (SB_JOURNAL_LIST(p_s_sb)[jindex].j_len > 0 && SB_JOURNAL(p_s_sb)->j_start <= SB_JOURNAL_LIST(p_s_sb)[jindex].j_start) {
- if ((SB_JOURNAL(p_s_sb)->j_start + JOURNAL_TRANS_MAX + 1) >= SB_JOURNAL_LIST(p_s_sb)[jindex].j_start) {
+ if ((SB_JOURNAL(p_s_sb)->j_start + SB_JOURNAL_TRANS_MAX(p_s_sb) + 1) >= SB_JOURNAL_LIST(p_s_sb)[jindex].j_start) {
flush_journal_list(p_s_sb, SB_JOURNAL_LIST(p_s_sb) + jindex, 1) ;
}
} else if (SB_JOURNAL_LIST(p_s_sb)[jindex].j_len > 0 &&
- (SB_JOURNAL(p_s_sb)->j_start + JOURNAL_TRANS_MAX + 1) > JOURNAL_BLOCK_COUNT) {
- if (((SB_JOURNAL(p_s_sb)->j_start + JOURNAL_TRANS_MAX + 1) % JOURNAL_BLOCK_COUNT) >=
+ (SB_JOURNAL(p_s_sb)->j_start + SB_JOURNAL_TRANS_MAX(p_s_sb) + 1) > SB_ONDISK_JOURNAL_SIZE(p_s_sb)) {
+ if (((SB_JOURNAL(p_s_sb)->j_start + SB_JOURNAL_TRANS_MAX(p_s_sb) + 1) % SB_ONDISK_JOURNAL_SIZE(p_s_sb)) >=
SB_JOURNAL_LIST(p_s_sb)[jindex].j_start) {
flush_journal_list(p_s_sb, SB_JOURNAL_LIST(p_s_sb) + jindex, 1 ) ;
}
@@ -3010,7 +3238,7 @@
/* this check should always be run, to send old lists to disk */
if (SB_JOURNAL_LIST(p_s_sb)[jindex].j_len > 0 &&
SB_JOURNAL_LIST(p_s_sb)[jindex].j_timestamp <
- (CURRENT_TIME - (JOURNAL_MAX_TRANS_AGE * 4))) {
+ (CURRENT_TIME - (SB_JOURNAL_MAX_TRANS_AGE(p_s_sb) * 4))) {
flush_journal_list(p_s_sb, SB_JOURNAL_LIST(p_s_sb) + jindex, 1 ) ;
}
}
FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)