History

Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4

Pull ext4 bug fixes from Ted Ts'o: "Various bug fixes for ext4. Perhaps the most serious bug fixed is one which could cause file system corruptions when performing file punch operations." * tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: ext4: avoid hang when mounting non-journal filesystems with orphan list ext4: lock i_mutex when truncating orphan inodes ext4: do not try to write superblock on ro remount w/o journal ext4: include journal blocks in df overhead calcs ext4: remove unaligned AIO warning printk ext4: fix an incorrect comment about i_mutex ext4: fix deadlock in journal_unmap_buffer() ext4: split off ext4_journalled_invalidatepage() jbd2: fix assertion failure in jbd2_journal_flush() ext4: check dioread_nolock on remount ext4: fix extent tree corruption caused by hole punch

Linus Torvalds committed 13 years ago

Commit 5439ca62 parents a7a88b2 0e9a9a19 files · +152 −58Browse files

Unified · Split

9 files
  1. fs/ext4/extents.c +18 −4
  2. fs/ext4/file.c +0 −8
  3. fs/ext4/fsync.c +0 −2
  4. fs/ext4/inode.c +84 −15
  5. fs/ext4/namei.c +2 −1
  6. fs/ext4/super.c +18 −12
  7. fs/jbd2/transaction.c +16 −14
  8. include/linux/jbd2.h +1 −1
  9. include/trace/events/ext4.h +13 −1
fs/ext4/extents.c+18−4
@@ -2226,13 +2226,14 @@ errout: · 2225 unmodified lines
22262226 * removes index from the index block.
22272227 */
22282228 static int ext4_ext_rm_idx(handle_t *handle, struct inode *inode,
2229− struct ext4_ext_path *path)
2229+ struct ext4_ext_path *path, int depth)
22302230 {
22312231 int err;
22322232 ext4_fsblk_t leaf;
22332233
22342234 /* free index block */
2235− path--;
2235+ depth--;
2236+ path = path + depth;
22362237 leaf = ext4_idx_pblock(path->p_idx);
22372238 if (unlikely(path->p_hdr->eh_entries == 0)) {
22382239 EXT4_ERROR_INODE(inode, "path->p_hdr->eh_entries == 0");
@@ -2257,6 +2258,19 @@ static int ext4_ext_rm_idx(handle_t *handle, struct inode *inode, · 18 unmodified lines
22572258
22582259 ext4_free_blocks(handle, inode, NULL, leaf, 1,
22592260 EXT4_FREE_BLOCKS_METADATA | EXT4_FREE_BLOCKS_FORGET);
2261+
2262+ while (--depth >= 0) {
2263+ if (path->p_idx != EXT_FIRST_INDEX(path->p_hdr))
2264+ break;
2265+ path--;
2266+ err = ext4_ext_get_access(handle, inode, path);
2267+ if (err)
2268+ break;
2269+ path->p_idx->ei_block = (path+1)->p_idx->ei_block;
2270+ err = ext4_ext_dirty(handle, inode, path);
2271+ if (err)
2272+ break;
2273+ }
22602274 return err;
22612275 }
22622276
@@ -2599,7 +2613,7 @@ ext4_ext_rm_leaf(handle_t *handle, struct inode *inode, · 336 unmodified lines
25992613 /* if this leaf is free, then we should
26002614 * remove it from index block above */
26012615 if (err == 0 && eh->eh_entries == 0 && path[depth].p_bh != NULL)
2602− err = ext4_ext_rm_idx(handle, inode, path + depth);
2616+ err = ext4_ext_rm_idx(handle, inode, path, depth);
26032617
26042618 out:
26052619 return err;
@@ -2802,7 +2816,7 @@ again: · 196 unmodified lines
28022816 /* index is empty, remove it;
28032817 * handle must be already prepared by the
28042818 * truncatei_leaf() */
2805− err = ext4_ext_rm_idx(handle, inode, path + i);
2819+ err = ext4_ext_rm_idx(handle, inode, path, i);
28062820 }
28072821 /* root level has p_bh == NULL, brelse() eats this */
28082822 brelse(path[i].p_bh);
fs/ext4/file.c+0−8
@@ -108,14 +108,6 @@ ext4_file_dio_write(struct kiocb *iocb, const struct iovec *iov, · 107 unmodified lines
108108
109109 /* Unaligned direct AIO must be serialized; see comment above */
110110 if (unaligned_aio) {
111− static unsigned long unaligned_warn_time;
112−
113− /* Warn about this once per day */
114− if (printk_timed_ratelimit(&unaligned_warn_time, 60*60*24*HZ))
115− ext4_msg(inode->i_sb, KERN_WARNING,
116− "Unaligned AIO/DIO on inode %ld by %s; "
117− "performance will be poor.",
118− inode->i_ino, current->comm);
119111 mutex_lock(ext4_aio_mutex(inode));
120112 ext4_unwritten_wait(inode);
121113 }
fs/ext4/fsync.c+0−2
@@ -109,8 +109,6 @@ static int __sync_inode(struct inode *inode, int datasync) · 108 unmodified lines
109109 *
110110 * What we do is just kick off a commit and wait on it. This will snapshot the
111111 * inode to disk.
112− *
113− * i_mutex lock is held when entering and exiting this function
114112 */
115113
116114 int ext4_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
fs/ext4/inode.c+84−15
@@ -2880,8 +2880,6 @@ static void ext4_invalidatepage_free_endio(struct page *page, unsigned long offs · 2879 unmodified lines
28802880
28812881 static void ext4_invalidatepage(struct page *page, unsigned long offset)
28822882 {
2883− journal_t *journal = EXT4_JOURNAL(page->mapping->host);
2884−
28852883 trace_ext4_invalidatepage(page, offset);
28862884
28872885 /*
@@ -2889,16 +2887,34 @@ static void ext4_invalidatepage(struct page *page, unsigned long offset) · 1 unmodified line
28892887 */
28902888 if (ext4_should_dioread_nolock(page->mapping->host))
28912889 ext4_invalidatepage_free_endio(page, offset);
2890+
2891+ /* No journalling happens on data buffers when this function is used */
2892+ WARN_ON(page_has_buffers(page) && buffer_jbd(page_buffers(page)));
2893+
2894+ block_invalidatepage(page, offset);
2895+}
2896+
2897+static int __ext4_journalled_invalidatepage(struct page *page,
2898+ unsigned long offset)
2899+{
2900+ journal_t *journal = EXT4_JOURNAL(page->mapping->host);
2901+
2902+ trace_ext4_journalled_invalidatepage(page, offset);
2903+
28922904 /*
28932905 * If it's a full truncate we just forget about the pending dirtying
28942906 */
28952907 if (offset == 0)
28962908 ClearPageChecked(page);
28972909
2898− if (journal)
2899− jbd2_journal_invalidatepage(journal, page, offset);
2900− else
2901− block_invalidatepage(page, offset);
2910+ return jbd2_journal_invalidatepage(journal, page, offset);
2911+}
2912+
2913+/* Wrapper for aops... */
2914+static void ext4_journalled_invalidatepage(struct page *page,
2915+ unsigned long offset)
2916+{
2917+ WARN_ON(__ext4_journalled_invalidatepage(page, offset) < 0);
29022918 }
29032919
29042920 static int ext4_releasepage(struct page *page, gfp_t wait)
@@ -3264,7 +3280,7 @@ static const struct address_space_operations ext4_journalled_aops = { · 359 unmodified lines
32643280 .write_end = ext4_journalled_write_end,
32653281 .set_page_dirty = ext4_journalled_set_page_dirty,
32663282 .bmap = ext4_bmap,
3267− .invalidatepage = ext4_invalidatepage,
3283+ .invalidatepage = ext4_journalled_invalidatepage,
32683284 .releasepage = ext4_releasepage,
32693285 .direct_IO = ext4_direct_IO,
32703286 .is_partially_uptodate = block_is_partially_uptodate,
@@ -4304,6 +4320,47 @@ int ext4_write_inode(struct inode *inode, struct writeback_control *wbc) · 1033 unmodified lines
43044320 return err;
43054321 }
43064322
4323+/*
4324+ * In data=journal mode ext4_journalled_invalidatepage() may fail to invalidate
4325+ * buffers that are attached to a page stradding i_size and are undergoing
4326+ * commit. In that case we have to wait for commit to finish and try again.
4327+ */
4328+static void ext4_wait_for_tail_page_commit(struct inode *inode)
4329+{
4330+ struct page *page;
4331+ unsigned offset;
4332+ journal_t *journal = EXT4_SB(inode->i_sb)->s_journal;
4333+ tid_t commit_tid = 0;
4334+ int ret;
4335+
4336+ offset = inode->i_size & (PAGE_CACHE_SIZE - 1);
4337+ /*
4338+ * All buffers in the last page remain valid? Then there's nothing to
4339+ * do. We do the check mainly to optimize the common PAGE_CACHE_SIZE ==
4340+ * blocksize case
4341+ */
4342+ if (offset > PAGE_CACHE_SIZE - (1 << inode->i_blkbits))
4343+ return;
4344+ while (1) {
4345+ page = find_lock_page(inode->i_mapping,
4346+ inode->i_size >> PAGE_CACHE_SHIFT);
4347+ if (!page)
4348+ return;
4349+ ret = __ext4_journalled_invalidatepage(page, offset);
4350+ unlock_page(page);
4351+ page_cache_release(page);
4352+ if (ret != -EBUSY)
4353+ return;
4354+ commit_tid = 0;
4355+ read_lock(&journal->j_state_lock);
4356+ if (journal->j_committing_transaction)
4357+ commit_tid = journal->j_committing_transaction->t_tid;
4358+ read_unlock(&journal->j_state_lock);
4359+ if (commit_tid)
4360+ jbd2_log_wait_commit(journal, commit_tid);
4361+ }
4362+}
4363+
43074364 /*
43084365 * ext4_setattr()
43094366 *
@@ -4417,16 +4474,28 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr) · 107 unmodified lines
44174474 }
44184475
44194476 if (attr->ia_valid & ATTR_SIZE) {
4420− if (attr->ia_size != i_size_read(inode)) {
4421− truncate_setsize(inode, attr->ia_size);
4422− /* Inode size will be reduced, wait for dio in flight.
4423− * Temporarily disable dioread_nolock to prevent
4424− * livelock. */
4477+ if (attr->ia_size != inode->i_size) {
4478+ loff_t oldsize = inode->i_size;
4479+
4480+ i_size_write(inode, attr->ia_size);
4481+ /*
4482+ * Blocks are going to be removed from the inode. Wait
4483+ * for dio in flight. Temporarily disable
4484+ * dioread_nolock to prevent livelock.
4485+ */
44254486 if (orphan) {
4426− ext4_inode_block_unlocked_dio(inode);
4427− inode_dio_wait(inode);
4428− ext4_inode_resume_unlocked_dio(inode);
4487+ if (!ext4_should_journal_data(inode)) {
4488+ ext4_inode_block_unlocked_dio(inode);
4489+ inode_dio_wait(inode);
4490+ ext4_inode_resume_unlocked_dio(inode);
4491+ } else
4492+ ext4_wait_for_tail_page_commit(inode);
44294493 }
4494+ /*
4495+ * Truncate pagecache after we've waited for commit
4496+ * in data=journal mode to make pages freeable.
4497+ */
4498+ truncate_pagecache(inode, oldsize, inode->i_size);
44304499 }
44314500 ext4_truncate(inode);
44324501 }
fs/ext4/namei.c+2−1
@@ -2648,7 +2648,8 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode) · 2647 unmodified lines
26482648 struct ext4_iloc iloc;
26492649 int err = 0;
26502650
2651− if (!EXT4_SB(inode->i_sb)->s_journal)
2651+ if ((!EXT4_SB(inode->i_sb)->s_journal) &&
2652+ !(EXT4_SB(inode->i_sb)->s_mount_state & EXT4_ORPHAN_FS))
26522653 return 0;
26532654
26542655 mutex_lock(&EXT4_SB(inode->i_sb)->s_orphan_lock);
fs/ext4/super.c+18−12
@@ -1645,9 +1645,7 @@ static int parse_options(char *options, struct super_block *sb, · 1644 unmodified lines
16451645 unsigned int *journal_ioprio,
16461646 int is_remount)
16471647 {
1648−#ifdef CONFIG_QUOTA
16491648 struct ext4_sb_info *sbi = EXT4_SB(sb);
1650−#endif
16511649 char *p;
16521650 substring_t args[MAX_OPT_ARGS];
16531651 int token;
@@ -1696,6 +1694,16 @@ static int parse_options(char *options, struct super_block *sb, · 42 unmodified lines
16961694 }
16971695 }
16981696 #endif
1697+ if (test_opt(sb, DIOREAD_NOLOCK)) {
1698+ int blocksize =
1699+ BLOCK_SIZE << le32_to_cpu(sbi->s_es->s_log_block_size);
1700+
1701+ if (blocksize < PAGE_CACHE_SIZE) {
1702+ ext4_msg(sb, KERN_ERR, "can't mount with "
1703+ "dioread_nolock if block size != PAGE_SIZE");
1704+ return 0;
1705+ }
1706+ }
16991707 return 1;
17001708 }
17011709
@@ -2212,7 +2220,9 @@ static void ext4_orphan_cleanup(struct super_block *sb, · 510 unmodified lines
22122220 __func__, inode->i_ino, inode->i_size);
22132221 jbd_debug(2, "truncating inode %lu to %lld bytes\n",
22142222 inode->i_ino, inode->i_size);
2223+ mutex_lock(&inode->i_mutex);
22152224 ext4_truncate(inode);
2225+ mutex_unlock(&inode->i_mutex);
22162226 nr_truncates++;
22172227 } else {
22182228 ext4_msg(sb, KERN_DEBUG,
@@ -3223,6 +3233,10 @@ int ext4_calculate_overhead(struct super_block *sb) · 1004 unmodified lines
32233233 memset(buf, 0, PAGE_SIZE);
32243234 cond_resched();
32253235 }
3236+ /* Add the journal blocks as well */
3237+ if (sbi->s_journal)
3238+ overhead += EXT4_B2C(sbi, sbi->s_journal->j_maxlen);
3239+
32263240 sbi->s_overhead = overhead;
32273241 smp_wmb();
32283242 free_page((unsigned long) buf);
@@ -3436,15 +3450,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) · 207 unmodified lines
34363450 clear_opt(sb, DELALLOC);
34373451 }
34383452
3439− blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size);
3440− if (test_opt(sb, DIOREAD_NOLOCK)) {
3441− if (blocksize < PAGE_SIZE) {
3442− ext4_msg(sb, KERN_ERR, "can't mount with "
3443− "dioread_nolock if block size != PAGE_SIZE");
3444− goto failed_mount;
3445− }
3446− }
3447−
34483453 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
34493454 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
34503455
@@ -3486,6 +3491,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) · 35 unmodified lines
34863491 if (!ext4_feature_set_ok(sb, (sb->s_flags & MS_RDONLY)))
34873492 goto failed_mount;
34883493
3494+ blocksize = BLOCK_SIZE << le32_to_cpu(es->s_log_block_size);
34893495 if (blocksize < EXT4_MIN_BLOCK_SIZE ||
34903496 blocksize > EXT4_MAX_BLOCK_SIZE) {
34913497 ext4_msg(sb, KERN_ERR,
@@ -4725,7 +4731,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) · 1233 unmodified lines
47254731 }
47264732
47274733 ext4_setup_system_zone(sb);
4728− if (sbi->s_journal == NULL)
4734+ if (sbi->s_journal == NULL && !(old_sb_flags & MS_RDONLY))
47294735 ext4_commit_super(sb, 1);
47304736
47314737 #ifdef CONFIG_QUOTA
fs/jbd2/transaction.c+16−14
@@ -209,7 +209,8 @@ repeat: · 208 unmodified lines
209209 if (!new_transaction)
210210 goto alloc_transaction;
211211 write_lock(&journal->j_state_lock);
212− if (!journal->j_running_transaction) {
212+ if (!journal->j_running_transaction &&
213+ !journal->j_barrier_count) {
213214 jbd2_get_transaction(journal, new_transaction);
214215 new_transaction = NULL;
215216 }
@@ -1839,7 +1840,6 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh, · 1623 unmodified lines
18391840
18401841 BUFFER_TRACE(bh, "entry");
18411842
1842−retry:
18431843 /*
18441844 * It is safe to proceed here without the j_list_lock because the
18451845 * buffers cannot be stolen by try_to_free_buffers as long as we are
@@ -1934,14 +1934,11 @@ retry: · 88 unmodified lines
19341934 * for commit and try again.
19351935 */
19361936 if (partial_page) {
1937− tid_t tid = journal->j_committing_transaction->t_tid;
1938−
19391937 jbd2_journal_put_journal_head(jh);
19401938 spin_unlock(&journal->j_list_lock);
19411939 jbd_unlock_bh_state(bh);
19421940 write_unlock(&journal->j_state_lock);
1943− jbd2_log_wait_commit(journal, tid);
1944− goto retry;
1941+ return -EBUSY;
19451942 }
19461943 /*
19471944 * OK, buffer won't be reachable after truncate. We just set
@@ -2002,21 +1999,23 @@ zap_buffer_unlocked: · 54 unmodified lines
20021999 * @page: page to flush
20032000 * @offset: length of page to invalidate.
20042001 *
2005− * Reap page buffers containing data after offset in page.
2006− *
2002+ * Reap page buffers containing data after offset in page. Can return -EBUSY
2003+ * if buffers are part of the committing transaction and the page is straddling
2004+ * i_size. Caller then has to wait for current commit and try again.
20072005 */
2008−void jbd2_journal_invalidatepage(journal_t *journal,
2009− struct page *page,
2010− unsigned long offset)
2006+int jbd2_journal_invalidatepage(journal_t *journal,
2007+ struct page *page,
2008+ unsigned long offset)
20112009 {
20122010 struct buffer_head *head, *bh, *next;
20132011 unsigned int curr_off = 0;
20142012 int may_free = 1;
2013+ int ret = 0;
20152014
20162015 if (!PageLocked(page))
20172016 BUG();
20182017 if (!page_has_buffers(page))
2019− return;
2018+ return 0;
20202019
20212020 /* We will potentially be playing with lists other than just the
20222021 * data lists (especially for journaled data mode), so be
@@ -2030,9 +2029,11 @@ void jbd2_journal_invalidatepage(journal_t *journal, · 7 unmodified lines
20302029 if (offset <= curr_off) {
20312030 /* This block is wholly outside the truncation point */
20322031 lock_buffer(bh);
2033− may_free &= journal_unmap_buffer(journal, bh,
2034− offset > 0);
2032+ ret = journal_unmap_buffer(journal, bh, offset > 0);
20352033 unlock_buffer(bh);
2034+ if (ret < 0)
2035+ return ret;
2036+ may_free &= ret;
20362037 }
20372038 curr_off = next_off;
20382039 bh = next;
@@ -2043,6 +2044,7 @@ void jbd2_journal_invalidatepage(journal_t *journal, · 4 unmodified lines
20432044 if (may_free && try_to_free_buffers(page))
20442045 J_ASSERT(!page_has_buffers(page));
20452046 }
2047+ return 0;
20462048 }
20472049
20482050 /*
include/linux/jbd2.h+1−1
@@ -1098,7 +1098,7 @@ void jbd2_journal_set_triggers(struct buffer_head *, · 1097 unmodified lines
10981098 extern int jbd2_journal_dirty_metadata (handle_t *, struct buffer_head *);
10991099 extern int jbd2_journal_forget (handle_t *, struct buffer_head *);
11001100 extern void journal_sync_buffer (struct buffer_head *);
1101−extern void jbd2_journal_invalidatepage(journal_t *,
1101+extern int jbd2_journal_invalidatepage(journal_t *,
11021102 struct page *, unsigned long);
11031103 extern int jbd2_journal_try_to_free_buffers(journal_t *, struct page *, gfp_t);
11041104 extern int jbd2_journal_stop(handle_t *);
include/trace/events/ext4.h+13−1
@@ -451,7 +451,7 @@ DEFINE_EVENT(ext4__page_op, ext4_releasepage, · 450 unmodified lines
451451 TP_ARGS(page)
452452 );
453453
454−TRACE_EVENT(ext4_invalidatepage,
454+DECLARE_EVENT_CLASS(ext4_invalidatepage_op,
455455 TP_PROTO(struct page *page, unsigned long offset),
456456
457457 TP_ARGS(page, offset),
@@ -477,6 +477,18 @@ TRACE_EVENT(ext4_invalidatepage, · 19 unmodified lines
477477 (unsigned long) __entry->index, __entry->offset)
478478 );
479479
480+DEFINE_EVENT(ext4_invalidatepage_op, ext4_invalidatepage,
481+ TP_PROTO(struct page *page, unsigned long offset),
482+
483+ TP_ARGS(page, offset)
484+);
485+
486+DEFINE_EVENT(ext4_invalidatepage_op, ext4_journalled_invalidatepage,
487+ TP_PROTO(struct page *page, unsigned long offset),
488+
489+ TP_ARGS(page, offset)
490+);
491+
480492 TRACE_EVENT(ext4_discard_blocks,
481493 TP_PROTO(struct super_block *sb, unsigned long long blk,
482494 unsigned long long count),