Skip to content

Commit dc522ad

Browse files
committed
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs-2.6
* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jack/linux-fs-2.6: jbd: Fix comment to match the code in journal_start() jbd/jbd2: remove obsolete summarise_journal_usage. jbd: Fix forever sleeping process in do_get_write_access() ext2: fix error msg when mounting fs with too-large blocksize jbd: fix fsync() tid wraparound bug ext3: Fix fs corruption when make_indexed_dir() fails ext3: Fix lock inversion in ext3_symlink()
2 parents df3256f + c2b6773 commit dc522ad

6 files changed

Lines changed: 91 additions & 32 deletions

File tree

‎fs/ext2/super.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,8 @@ static int ext2_fill_super(struct super_block *sb, void *data, int silent)
898898
brelse(bh);
899899

900900
if (!sb_set_blocksize(sb, blocksize)) {
901-
ext2_msg(sb, KERN_ERR, "error: blocksize is too small");
901+
ext2_msg(sb, KERN_ERR,
902+
"error: bad blocksize %d", blocksize);
902903
goto failed_sbi;
903904
}
904905

‎fs/ext3/namei.c‎

Lines changed: 67 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,10 +1416,19 @@ static int make_indexed_dir(handle_t *handle, struct dentry *dentry,
14161416
frame->at = entries;
14171417
frame->bh = bh;
14181418
bh = bh2;
1419+
/*
1420+
* Mark buffers dirty here so that if do_split() fails we write a
1421+
* consistent set of buffers to disk.
1422+
*/
1423+
ext3_journal_dirty_metadata(handle, frame->bh);
1424+
ext3_journal_dirty_metadata(handle, bh);
14191425
de = do_split(handle,dir, &bh, frame, &hinfo, &retval);
1420-
dx_release (frames);
1421-
if (!(de))
1426+
if (!de) {
1427+
ext3_mark_inode_dirty(handle, dir);
1428+
dx_release(frames);
14221429
return retval;
1430+
}
1431+
dx_release(frames);
14231432

14241433
return add_dirent_to_buf(handle, dentry, inode, de, bh);
14251434
}
@@ -2189,17 +2198,34 @@ static int ext3_symlink (struct inode * dir,
21892198
handle_t *handle;
21902199
struct inode * inode;
21912200
int l, err, retries = 0;
2201+
int credits;
21922202

21932203
l = strlen(symname)+1;
21942204
if (l > dir->i_sb->s_blocksize)
21952205
return -ENAMETOOLONG;
21962206

21972207
dquot_initialize(dir);
21982208

2209+
if (l > EXT3_N_BLOCKS * 4) {
2210+
/*
2211+
* For non-fast symlinks, we just allocate inode and put it on
2212+
* orphan list in the first transaction => we need bitmap,
2213+
* group descriptor, sb, inode block, quota blocks.
2214+
*/
2215+
credits = 4 + EXT3_MAXQUOTAS_INIT_BLOCKS(dir->i_sb);
2216+
} else {
2217+
/*
2218+
* Fast symlink. We have to add entry to directory
2219+
* (EXT3_DATA_TRANS_BLOCKS + EXT3_INDEX_EXTRA_TRANS_BLOCKS),
2220+
* allocate new inode (bitmap, group descriptor, inode block,
2221+
* quota blocks, sb is already counted in previous macros).
2222+
*/
2223+
credits = EXT3_DATA_TRANS_BLOCKS(dir->i_sb) +
2224+
EXT3_INDEX_EXTRA_TRANS_BLOCKS + 3 +
2225+
EXT3_MAXQUOTAS_INIT_BLOCKS(dir->i_sb);
2226+
}
21992227
retry:
2200-
handle = ext3_journal_start(dir, EXT3_DATA_TRANS_BLOCKS(dir->i_sb) +
2201-
EXT3_INDEX_EXTRA_TRANS_BLOCKS + 5 +
2202-
EXT3_MAXQUOTAS_INIT_BLOCKS(dir->i_sb));
2228+
handle = ext3_journal_start(dir, credits);
22032229
if (IS_ERR(handle))
22042230
return PTR_ERR(handle);
22052231

@@ -2211,21 +2237,45 @@ static int ext3_symlink (struct inode * dir,
22112237
if (IS_ERR(inode))
22122238
goto out_stop;
22132239

2214-
if (l > sizeof (EXT3_I(inode)->i_data)) {
2240+
if (l > EXT3_N_BLOCKS * 4) {
22152241
inode->i_op = &ext3_symlink_inode_operations;
22162242
ext3_set_aops(inode);
22172243
/*
2218-
* page_symlink() calls into ext3_prepare/commit_write.
2219-
* We have a transaction open. All is sweetness. It also sets
2220-
* i_size in generic_commit_write().
2244+
* We cannot call page_symlink() with transaction started
2245+
* because it calls into ext3_write_begin() which acquires page
2246+
* lock which ranks below transaction start (and it can also
2247+
* wait for journal commit if we are running out of space). So
2248+
* we have to stop transaction now and restart it when symlink
2249+
* contents is written.
2250+
*
2251+
* To keep fs consistent in case of crash, we have to put inode
2252+
* to orphan list in the mean time.
22212253
*/
2254+
drop_nlink(inode);
2255+
err = ext3_orphan_add(handle, inode);
2256+
ext3_journal_stop(handle);
2257+
if (err)
2258+
goto err_drop_inode;
22222259
err = __page_symlink(inode, symname, l, 1);
2260+
if (err)
2261+
goto err_drop_inode;
2262+
/*
2263+
* Now inode is being linked into dir (EXT3_DATA_TRANS_BLOCKS
2264+
* + EXT3_INDEX_EXTRA_TRANS_BLOCKS), inode is also modified
2265+
*/
2266+
handle = ext3_journal_start(dir,
2267+
EXT3_DATA_TRANS_BLOCKS(dir->i_sb) +
2268+
EXT3_INDEX_EXTRA_TRANS_BLOCKS + 1);
2269+
if (IS_ERR(handle)) {
2270+
err = PTR_ERR(handle);
2271+
goto err_drop_inode;
2272+
}
2273+
inc_nlink(inode);
2274+
err = ext3_orphan_del(handle, inode);
22232275
if (err) {
2276+
ext3_journal_stop(handle);
22242277
drop_nlink(inode);
2225-
unlock_new_inode(inode);
2226-
ext3_mark_inode_dirty(handle, inode);
2227-
iput (inode);
2228-
goto out_stop;
2278+
goto err_drop_inode;
22292279
}
22302280
} else {
22312281
inode->i_op = &ext3_fast_symlink_inode_operations;
@@ -2239,6 +2289,10 @@ static int ext3_symlink (struct inode * dir,
22392289
if (err == -ENOSPC && ext3_should_retry_alloc(dir->i_sb, &retries))
22402290
goto retry;
22412291
return err;
2292+
err_drop_inode:
2293+
unlock_new_inode(inode);
2294+
iput(inode);
2295+
return err;
22422296
}
22432297

22442298
static int ext3_link (struct dentry * old_dentry,

‎fs/jbd/commit.c‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -302,12 +302,6 @@ void journal_commit_transaction(journal_t *journal)
302302
* all outstanding updates to complete.
303303
*/
304304

305-
#ifdef COMMIT_STATS
306-
spin_lock(&journal->j_list_lock);
307-
summarise_journal_usage(journal);
308-
spin_unlock(&journal->j_list_lock);
309-
#endif
310-
311305
/* Do we need to erase the effects of a prior journal_flush? */
312306
if (journal->j_flags & JFS_FLUSHED) {
313307
jbd_debug(3, "super block updated\n");
@@ -722,8 +716,13 @@ void journal_commit_transaction(journal_t *journal)
722716
required. */
723717
JBUFFER_TRACE(jh, "file as BJ_Forget");
724718
journal_file_buffer(jh, commit_transaction, BJ_Forget);
725-
/* Wake up any transactions which were waiting for this
726-
IO to complete */
719+
/*
720+
* Wake up any transactions which were waiting for this
721+
* IO to complete. The barrier must be here so that changes
722+
* by journal_file_buffer() take effect before wake_up_bit()
723+
* does the waitqueue check.
724+
*/
725+
smp_mb();
727726
wake_up_bit(&bh->b_state, BH_Unshadow);
728727
JBUFFER_TRACE(jh, "brelse shadowed buffer");
729728
__brelse(bh);

‎fs/jbd/journal.c‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,9 +437,12 @@ int __log_space_left(journal_t *journal)
437437
int __log_start_commit(journal_t *journal, tid_t target)
438438
{
439439
/*
440-
* Are we already doing a recent enough commit?
440+
* The only transaction we can possibly wait upon is the
441+
* currently running transaction (if it exists). Otherwise,
442+
* the target tid must be an old one.
441443
*/
442-
if (!tid_geq(journal->j_commit_request, target)) {
444+
if (journal->j_running_transaction &&
445+
journal->j_running_transaction->t_tid == target) {
443446
/*
444447
* We want a new commit: OK, mark the request and wakeup the
445448
* commit thread. We do _not_ do the commit ourselves.
@@ -451,7 +454,14 @@ int __log_start_commit(journal_t *journal, tid_t target)
451454
journal->j_commit_sequence);
452455
wake_up(&journal->j_wait_commit);
453456
return 1;
454-
}
457+
} else if (!tid_geq(journal->j_commit_request, target))
458+
/* This should never happen, but if it does, preserve
459+
the evidence before kjournald goes into a loop and
460+
increments j_commit_sequence beyond all recognition. */
461+
WARN_ONCE(1, "jbd: bad log_start_commit: %u %u %u %u\n",
462+
journal->j_commit_request, journal->j_commit_sequence,
463+
target, journal->j_running_transaction ?
464+
journal->j_running_transaction->t_tid : 0);
455465
return 0;
456466
}
457467

‎fs/jbd/transaction.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ static handle_t *new_handle(int nblocks)
266266
* This function is visible to journal users (like ext3fs), so is not
267267
* called with the journal already locked.
268268
*
269-
* Return a pointer to a newly allocated handle, or NULL on failure
269+
* Return a pointer to a newly allocated handle, or an ERR_PTR() value
270+
* on failure.
270271
*/
271272
handle_t *journal_start(journal_t *journal, int nblocks)
272273
{

‎fs/jbd2/commit.c‎

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,6 @@ void jbd2_journal_commit_transaction(journal_t *journal)
338338
* all outstanding updates to complete.
339339
*/
340340

341-
#ifdef COMMIT_STATS
342-
spin_lock(&journal->j_list_lock);
343-
summarise_journal_usage(journal);
344-
spin_unlock(&journal->j_list_lock);
345-
#endif
346-
347341
/* Do we need to erase the effects of a prior jbd2_journal_flush? */
348342
if (journal->j_flags & JBD2_FLUSHED) {
349343
jbd_debug(3, "super block updated\n");

0 commit comments

Comments
 (0)