Skip to content

Commit

Permalink
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel…
Browse files Browse the repository at this point in the history
…/git/jack/linux-fs-2.6

* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs-2.6:
  ext3: Flush disk caches on fsync when needed
  ext3: Add locking to ext3_do_update_inode
  ext3: Fix possible deadlock between ext3_truncate() and ext3_get_blocks()
  jbd: Annotate transaction start also for journal_restart()
  jbd: Journal block numbers can ever be only 32-bit use unsigned int for them
  ext3: Update MAINTAINERS for ext3 and JBD
  JBD: round commit timer up to avoid uncommitted transaction
  • Loading branch information
torvalds committed Sep 18, 2009
2 parents 714af06 + 56fcad2 commit 2511817
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 60 deletions.
3 changes: 1 addition & 2 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,6 @@ F: fs/ext2/
F: include/linux/ext2*

EXT3 FILE SYSTEM
M: Stephen Tweedie <[email protected]>
M: Andrew Morton <[email protected]>
M: Andreas Dilger <[email protected]>
L: [email protected]
Expand Down Expand Up @@ -2901,8 +2900,8 @@ F: fs/jffs2/
F: include/linux/jffs2.h

JOURNALLING LAYER FOR BLOCK DEVICES (JBD)
M: Stephen Tweedie <[email protected]>
M: Andrew Morton <[email protected]>
M: Jan Kara <[email protected]>
L: [email protected]
S: Maintained
F: fs/jbd*/
Expand Down
12 changes: 11 additions & 1 deletion fs/ext3/fsync.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/

#include <linux/time.h>
#include <linux/blkdev.h>
#include <linux/fs.h>
#include <linux/sched.h>
#include <linux/writeback.h>
Expand Down Expand Up @@ -73,7 +74,7 @@ int ext3_sync_file(struct file * file, struct dentry *dentry, int datasync)
}

if (datasync && !(inode->i_state & I_DIRTY_DATASYNC))
goto out;
goto flush;

/*
* The VFS has written the file data. If the inode is unaltered
Expand All @@ -85,7 +86,16 @@ int ext3_sync_file(struct file * file, struct dentry *dentry, int datasync)
.nr_to_write = 0, /* sys_fsync did this */
};
ret = sync_inode(inode, &wbc);
goto out;
}
flush:
/*
* In case we didn't commit a transaction, we have to flush
* disk caches manually so that data really is on persistent
* storage
*/
if (test_opt(inode->i_sb, BARRIER))
blkdev_issue_flush(inode->i_sb->s_bdev, NULL);
out:
return ret;
}
28 changes: 24 additions & 4 deletions fs/ext3/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,21 @@ static int try_to_extend_transaction(handle_t *handle, struct inode *inode)
* so before we call here everything must be consistently dirtied against
* this transaction.
*/
static int ext3_journal_test_restart(handle_t *handle, struct inode *inode)
static int truncate_restart_transaction(handle_t *handle, struct inode *inode)
{
int ret;

jbd_debug(2, "restarting handle %p\n", handle);
return ext3_journal_restart(handle, blocks_for_truncate(inode));
/*
* Drop truncate_mutex to avoid deadlock with ext3_get_blocks_handle
* At this moment, get_block can be called only for blocks inside
* i_size since page cache has been already dropped and writes are
* blocked by i_mutex. So we can safely drop the truncate_mutex.
*/
mutex_unlock(&EXT3_I(inode)->truncate_mutex);
ret = ext3_journal_restart(handle, blocks_for_truncate(inode));
mutex_lock(&EXT3_I(inode)->truncate_mutex);
return ret;
}

/*
Expand Down Expand Up @@ -2072,7 +2083,7 @@ static void ext3_clear_blocks(handle_t *handle, struct inode *inode,
ext3_journal_dirty_metadata(handle, bh);
}
ext3_mark_inode_dirty(handle, inode);
ext3_journal_test_restart(handle, inode);
truncate_restart_transaction(handle, inode);
if (bh) {
BUFFER_TRACE(bh, "retaking write access");
ext3_journal_get_write_access(handle, bh);
Expand Down Expand Up @@ -2282,7 +2293,7 @@ static void ext3_free_branches(handle_t *handle, struct inode *inode,
return;
if (try_to_extend_transaction(handle, inode)) {
ext3_mark_inode_dirty(handle, inode);
ext3_journal_test_restart(handle, inode);
truncate_restart_transaction(handle, inode);
}

ext3_free_blocks(handle, inode, nr, 1);
Expand Down Expand Up @@ -2892,6 +2903,10 @@ static int ext3_do_update_inode(handle_t *handle,
struct buffer_head *bh = iloc->bh;
int err = 0, rc, block;

again:
/* we can't allow multiple procs in here at once, its a bit racey */
lock_buffer(bh);

/* For fields not not tracking in the in-memory inode,
* initialise them to zero for new inodes. */
if (ei->i_state & EXT3_STATE_NEW)
Expand Down Expand Up @@ -2951,16 +2966,20 @@ static int ext3_do_update_inode(handle_t *handle,
/* If this is the first large file
* created, add a flag to the superblock.
*/
unlock_buffer(bh);
err = ext3_journal_get_write_access(handle,
EXT3_SB(sb)->s_sbh);
if (err)
goto out_brelse;

ext3_update_dynamic_rev(sb);
EXT3_SET_RO_COMPAT_FEATURE(sb,
EXT3_FEATURE_RO_COMPAT_LARGE_FILE);
handle->h_sync = 1;
err = ext3_journal_dirty_metadata(handle,
EXT3_SB(sb)->s_sbh);
/* get our lock and start over */
goto again;
}
}
}
Expand All @@ -2983,6 +3002,7 @@ static int ext3_do_update_inode(handle_t *handle,
raw_inode->i_extra_isize = cpu_to_le16(ei->i_extra_isize);

BUFFER_TRACE(bh, "call ext3_journal_dirty_metadata");
unlock_buffer(bh);
rc = ext3_journal_dirty_metadata(handle, bh);
if (!err)
err = rc;
Expand Down
6 changes: 3 additions & 3 deletions fs/jbd/checkpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ int cleanup_journal_tail(journal_t *journal)
{
transaction_t * transaction;
tid_t first_tid;
unsigned long blocknr, freed;
unsigned int blocknr, freed;

if (is_journal_aborted(journal))
return 1;
Expand Down Expand Up @@ -502,8 +502,8 @@ int cleanup_journal_tail(journal_t *journal)
freed = freed + journal->j_last - journal->j_first;

jbd_debug(1,
"Cleaning journal tail from %d to %d (offset %lu), "
"freeing %lu\n",
"Cleaning journal tail from %d to %d (offset %u), "
"freeing %u\n",
journal->j_tail_sequence, first_tid, blocknr, freed);

journal->j_free += freed;
Expand Down
2 changes: 1 addition & 1 deletion fs/jbd/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ void journal_commit_transaction(journal_t *journal)
int bufs;
int flags;
int err;
unsigned long blocknr;
unsigned int blocknr;
ktime_t start_time;
u64 commit_time;
char *tagp = NULL;
Expand Down
30 changes: 15 additions & 15 deletions fs/jbd/journal.c
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ static void journal_kill_thread(journal_t *journal)
int journal_write_metadata_buffer(transaction_t *transaction,
struct journal_head *jh_in,
struct journal_head **jh_out,
unsigned long blocknr)
unsigned int blocknr)
{
int need_copy_out = 0;
int done_copy_out = 0;
Expand Down Expand Up @@ -567,9 +567,9 @@ int log_wait_commit(journal_t *journal, tid_t tid)
* Log buffer allocation routines:
*/

int journal_next_log_block(journal_t *journal, unsigned long *retp)
int journal_next_log_block(journal_t *journal, unsigned int *retp)
{
unsigned long blocknr;
unsigned int blocknr;

spin_lock(&journal->j_state_lock);
J_ASSERT(journal->j_free > 1);
Expand All @@ -590,11 +590,11 @@ int journal_next_log_block(journal_t *journal, unsigned long *retp)
* this is a no-op. If needed, we can use j_blk_offset - everything is
* ready.
*/
int journal_bmap(journal_t *journal, unsigned long blocknr,
unsigned long *retp)
int journal_bmap(journal_t *journal, unsigned int blocknr,
unsigned int *retp)
{
int err = 0;
unsigned long ret;
unsigned int ret;

if (journal->j_inode) {
ret = bmap(journal->j_inode, blocknr);
Expand All @@ -604,7 +604,7 @@ int journal_bmap(journal_t *journal, unsigned long blocknr,
char b[BDEVNAME_SIZE];

printk(KERN_ALERT "%s: journal block not found "
"at offset %lu on %s\n",
"at offset %u on %s\n",
__func__,
blocknr,
bdevname(journal->j_dev, b));
Expand All @@ -630,7 +630,7 @@ int journal_bmap(journal_t *journal, unsigned long blocknr,
struct journal_head *journal_get_descriptor_buffer(journal_t *journal)
{
struct buffer_head *bh;
unsigned long blocknr;
unsigned int blocknr;
int err;

err = journal_next_log_block(journal, &blocknr);
Expand Down Expand Up @@ -774,7 +774,7 @@ journal_t * journal_init_inode (struct inode *inode)
journal_t *journal = journal_init_common();
int err;
int n;
unsigned long blocknr;
unsigned int blocknr;

if (!journal)
return NULL;
Expand Down Expand Up @@ -846,12 +846,12 @@ static void journal_fail_superblock (journal_t *journal)
static int journal_reset(journal_t *journal)
{
journal_superblock_t *sb = journal->j_superblock;
unsigned long first, last;
unsigned int first, last;

first = be32_to_cpu(sb->s_first);
last = be32_to_cpu(sb->s_maxlen);
if (first + JFS_MIN_JOURNAL_BLOCKS > last + 1) {
printk(KERN_ERR "JBD: Journal too short (blocks %lu-%lu).\n",
printk(KERN_ERR "JBD: Journal too short (blocks %u-%u).\n",
first, last);
journal_fail_superblock(journal);
return -EINVAL;
Expand Down Expand Up @@ -885,7 +885,7 @@ static int journal_reset(journal_t *journal)
**/
int journal_create(journal_t *journal)
{
unsigned long blocknr;
unsigned int blocknr;
struct buffer_head *bh;
journal_superblock_t *sb;
int i, err;
Expand Down Expand Up @@ -969,14 +969,14 @@ void journal_update_superblock(journal_t *journal, int wait)
if (sb->s_start == 0 && journal->j_tail_sequence ==
journal->j_transaction_sequence) {
jbd_debug(1,"JBD: Skipping superblock update on recovered sb "
"(start %ld, seq %d, errno %d)\n",
"(start %u, seq %d, errno %d)\n",
journal->j_tail, journal->j_tail_sequence,
journal->j_errno);
goto out;
}

spin_lock(&journal->j_state_lock);
jbd_debug(1,"JBD: updating superblock (start %ld, seq %d, errno %d)\n",
jbd_debug(1,"JBD: updating superblock (start %u, seq %d, errno %d)\n",
journal->j_tail, journal->j_tail_sequence, journal->j_errno);

sb->s_sequence = cpu_to_be32(journal->j_tail_sequence);
Expand Down Expand Up @@ -1371,7 +1371,7 @@ int journal_flush(journal_t *journal)
{
int err = 0;
transaction_t *transaction = NULL;
unsigned long old_tail;
unsigned int old_tail;

spin_lock(&journal->j_state_lock);

Expand Down
18 changes: 9 additions & 9 deletions fs/jbd/recovery.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static int do_readahead(journal_t *journal, unsigned int start)
{
int err;
unsigned int max, nbufs, next;
unsigned long blocknr;
unsigned int blocknr;
struct buffer_head *bh;

struct buffer_head * bufs[MAXBUF];
Expand Down Expand Up @@ -132,7 +132,7 @@ static int jread(struct buffer_head **bhp, journal_t *journal,
unsigned int offset)
{
int err;
unsigned long blocknr;
unsigned int blocknr;
struct buffer_head *bh;

*bhp = NULL;
Expand Down Expand Up @@ -314,7 +314,7 @@ static int do_one_pass(journal_t *journal,
struct recovery_info *info, enum passtype pass)
{
unsigned int first_commit_ID, next_commit_ID;
unsigned long next_log_block;
unsigned int next_log_block;
int err, success = 0;
journal_superblock_t * sb;
journal_header_t * tmp;
Expand Down Expand Up @@ -367,14 +367,14 @@ static int do_one_pass(journal_t *journal,
if (tid_geq(next_commit_ID, info->end_transaction))
break;

jbd_debug(2, "Scanning for sequence ID %u at %lu/%lu\n",
jbd_debug(2, "Scanning for sequence ID %u at %u/%u\n",
next_commit_ID, next_log_block, journal->j_last);

/* Skip over each chunk of the transaction looking
* either the next descriptor block or the final commit
* record. */

jbd_debug(3, "JBD: checking block %ld\n", next_log_block);
jbd_debug(3, "JBD: checking block %u\n", next_log_block);
err = jread(&bh, journal, next_log_block);
if (err)
goto failed;
Expand Down Expand Up @@ -429,7 +429,7 @@ static int do_one_pass(journal_t *journal,
tagp = &bh->b_data[sizeof(journal_header_t)];
while ((tagp - bh->b_data +sizeof(journal_block_tag_t))
<= journal->j_blocksize) {
unsigned long io_block;
unsigned int io_block;

tag = (journal_block_tag_t *) tagp;
flags = be32_to_cpu(tag->t_flags);
Expand All @@ -443,10 +443,10 @@ static int do_one_pass(journal_t *journal,
success = err;
printk (KERN_ERR
"JBD: IO error %d recovering "
"block %ld in log\n",
"block %u in log\n",
err, io_block);
} else {
unsigned long blocknr;
unsigned int blocknr;

J_ASSERT(obh != NULL);
blocknr = be32_to_cpu(tag->t_blocknr);
Expand Down Expand Up @@ -581,7 +581,7 @@ static int scan_revoke_records(journal_t *journal, struct buffer_head *bh,
max = be32_to_cpu(header->r_count);

while (offset < max) {
unsigned long blocknr;
unsigned int blocknr;
int err;

blocknr = be32_to_cpu(* ((__be32 *) (bh->b_data+offset)));
Expand Down
Loading

0 comments on commit 2511817

Please sign in to comment.