Commit 4fbf888a authored by Linus Torvalds's avatar Linus Torvalds

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

Pull ext4 changes from Ted Ts'o:
 "Ext4 updates for 3.13.  Mostly bug fixes and cleanups"

* tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4:
  ext4: add prototypes for macro-generated functions
  ext4: return non-zero st_blocks for inline data
  ext4: use prandom_u32() instead of get_random_bytes()
  ext4: remove unreachable code after ext4_can_extents_be_merged()
  ext4: remove unreachable code in ext4_can_extents_be_merged()
  ext4: avoid bh leak in retry path of ext4_expand_extra_isize_ea()
  ext4: don't count free clusters from a corrupt block group
  ext4: fix FITRIM in no journal mode
  ext4: drop set but otherwise unused variable from ext4_add_dirent_to_inline()
  ext4: change ext4_read_inline_dir() to return 0 on success
  ext4: pair trace_ext4_writepages & trace_ext4_writepages_result
  ext4: add ratelimiting to ext4 messages
  ext4: fix performance regression in ext4_writepages
  ext4: fixup kerndoc annotation of mpage_map_and_submit_extent()
  ext4: fix assertion in ext4_add_complete_io()
parents 7e1a1e93 3f61c0cc
...@@ -640,6 +640,7 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb) ...@@ -640,6 +640,7 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
struct ext4_group_desc *gdp; struct ext4_group_desc *gdp;
ext4_group_t i; ext4_group_t i;
ext4_group_t ngroups = ext4_get_groups_count(sb); ext4_group_t ngroups = ext4_get_groups_count(sb);
struct ext4_group_info *grp;
#ifdef EXT4FS_DEBUG #ifdef EXT4FS_DEBUG
struct ext4_super_block *es; struct ext4_super_block *es;
ext4_fsblk_t bitmap_count; ext4_fsblk_t bitmap_count;
...@@ -655,7 +656,11 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb) ...@@ -655,7 +656,11 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
gdp = ext4_get_group_desc(sb, i, NULL); gdp = ext4_get_group_desc(sb, i, NULL);
if (!gdp) if (!gdp)
continue; continue;
desc_count += ext4_free_group_clusters(sb, gdp); grp = NULL;
if (EXT4_SB(sb)->s_group_info)
grp = ext4_get_group_info(sb, i);
if (!grp || !EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
desc_count += ext4_free_group_clusters(sb, gdp);
brelse(bitmap_bh); brelse(bitmap_bh);
bitmap_bh = ext4_read_block_bitmap(sb, i); bitmap_bh = ext4_read_block_bitmap(sb, i);
if (bitmap_bh == NULL) if (bitmap_bh == NULL)
...@@ -679,7 +684,11 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb) ...@@ -679,7 +684,11 @@ ext4_fsblk_t ext4_count_free_clusters(struct super_block *sb)
gdp = ext4_get_group_desc(sb, i, NULL); gdp = ext4_get_group_desc(sb, i, NULL);
if (!gdp) if (!gdp)
continue; continue;
desc_count += ext4_free_group_clusters(sb, gdp); grp = NULL;
if (EXT4_SB(sb)->s_group_info)
grp = ext4_get_group_info(sb, i);
if (!grp || !EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
desc_count += ext4_free_group_clusters(sb, gdp);
} }
return desc_count; return desc_count;
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/blockgroup_lock.h> #include <linux/blockgroup_lock.h>
#include <linux/percpu_counter.h> #include <linux/percpu_counter.h>
#include <linux/ratelimit.h>
#include <crypto/hash.h> #include <crypto/hash.h>
#ifdef __KERNEL__ #ifdef __KERNEL__
#include <linux/compat.h> #include <linux/compat.h>
...@@ -1314,6 +1315,11 @@ struct ext4_sb_info { ...@@ -1314,6 +1315,11 @@ struct ext4_sb_info {
unsigned long s_es_last_sorted; unsigned long s_es_last_sorted;
struct percpu_counter s_extent_cache_cnt; struct percpu_counter s_extent_cache_cnt;
spinlock_t s_es_lru_lock ____cacheline_aligned_in_smp; spinlock_t s_es_lru_lock ____cacheline_aligned_in_smp;
/* Ratelimit ext4 messages. */
struct ratelimit_state s_err_ratelimit_state;
struct ratelimit_state s_warning_ratelimit_state;
struct ratelimit_state s_msg_ratelimit_state;
}; };
static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb) static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb)
...@@ -1396,7 +1402,18 @@ static inline void ext4_clear_inode_##name(struct inode *inode, int bit) \ ...@@ -1396,7 +1402,18 @@ static inline void ext4_clear_inode_##name(struct inode *inode, int bit) \
clear_bit(bit + (offset), &EXT4_I(inode)->i_##field); \ clear_bit(bit + (offset), &EXT4_I(inode)->i_##field); \
} }
/* Add these declarations here only so that these functions can be
* found by name. Otherwise, they are very hard to locate. */
static inline int ext4_test_inode_flag(struct inode *inode, int bit);
static inline void ext4_set_inode_flag(struct inode *inode, int bit);
static inline void ext4_clear_inode_flag(struct inode *inode, int bit);
EXT4_INODE_BIT_FNS(flag, flags, 0) EXT4_INODE_BIT_FNS(flag, flags, 0)
/* Add these declarations here only so that these functions can be
* found by name. Otherwise, they are very hard to locate. */
static inline int ext4_test_inode_state(struct inode *inode, int bit);
static inline void ext4_set_inode_state(struct inode *inode, int bit);
static inline void ext4_clear_inode_state(struct inode *inode, int bit);
#if (BITS_PER_LONG < 64) #if (BITS_PER_LONG < 64)
EXT4_INODE_BIT_FNS(state, state_flags, 0) EXT4_INODE_BIT_FNS(state, state_flags, 0)
......
...@@ -1666,7 +1666,7 @@ int ...@@ -1666,7 +1666,7 @@ int
ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1, ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1,
struct ext4_extent *ex2) struct ext4_extent *ex2)
{ {
unsigned short ext1_ee_len, ext2_ee_len, max_len; unsigned short ext1_ee_len, ext2_ee_len;
/* /*
* Make sure that both extents are initialized. We don't merge * Make sure that both extents are initialized. We don't merge
...@@ -1677,11 +1677,6 @@ ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1, ...@@ -1677,11 +1677,6 @@ ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1,
if (ext4_ext_is_uninitialized(ex1) || ext4_ext_is_uninitialized(ex2)) if (ext4_ext_is_uninitialized(ex1) || ext4_ext_is_uninitialized(ex2))
return 0; return 0;
if (ext4_ext_is_uninitialized(ex1))
max_len = EXT_UNINIT_MAX_LEN;
else
max_len = EXT_INIT_MAX_LEN;
ext1_ee_len = ext4_ext_get_actual_len(ex1); ext1_ee_len = ext4_ext_get_actual_len(ex1);
ext2_ee_len = ext4_ext_get_actual_len(ex2); ext2_ee_len = ext4_ext_get_actual_len(ex2);
...@@ -1694,7 +1689,7 @@ ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1, ...@@ -1694,7 +1689,7 @@ ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1,
* as an RO_COMPAT feature, refuse to merge to extents if * as an RO_COMPAT feature, refuse to merge to extents if
* this can result in the top bit of ee_len being set. * this can result in the top bit of ee_len being set.
*/ */
if (ext1_ee_len + ext2_ee_len > max_len) if (ext1_ee_len + ext2_ee_len > EXT_INIT_MAX_LEN)
return 0; return 0;
#ifdef AGGRESSIVE_TEST #ifdef AGGRESSIVE_TEST
if (ext1_ee_len >= 4) if (ext1_ee_len >= 4)
...@@ -1720,7 +1715,6 @@ static int ext4_ext_try_to_merge_right(struct inode *inode, ...@@ -1720,7 +1715,6 @@ static int ext4_ext_try_to_merge_right(struct inode *inode,
struct ext4_extent_header *eh; struct ext4_extent_header *eh;
unsigned int depth, len; unsigned int depth, len;
int merge_done = 0; int merge_done = 0;
int uninitialized = 0;
depth = ext_depth(inode); depth = ext_depth(inode);
BUG_ON(path[depth].p_hdr == NULL); BUG_ON(path[depth].p_hdr == NULL);
...@@ -1730,12 +1724,8 @@ static int ext4_ext_try_to_merge_right(struct inode *inode, ...@@ -1730,12 +1724,8 @@ static int ext4_ext_try_to_merge_right(struct inode *inode,
if (!ext4_can_extents_be_merged(inode, ex, ex + 1)) if (!ext4_can_extents_be_merged(inode, ex, ex + 1))
break; break;
/* merge with next extent! */ /* merge with next extent! */
if (ext4_ext_is_uninitialized(ex))
uninitialized = 1;
ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex) ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex)
+ ext4_ext_get_actual_len(ex + 1)); + ext4_ext_get_actual_len(ex + 1));
if (uninitialized)
ext4_ext_mark_uninitialized(ex);
if (ex + 1 < EXT_LAST_EXTENT(eh)) { if (ex + 1 < EXT_LAST_EXTENT(eh)) {
len = (EXT_LAST_EXTENT(eh) - ex - 1) len = (EXT_LAST_EXTENT(eh) - ex - 1)
...@@ -1890,7 +1880,6 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode, ...@@ -1890,7 +1880,6 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode,
struct ext4_ext_path *npath = NULL; struct ext4_ext_path *npath = NULL;
int depth, len, err; int depth, len, err;
ext4_lblk_t next; ext4_lblk_t next;
unsigned uninitialized = 0;
int mb_flags = 0; int mb_flags = 0;
if (unlikely(ext4_ext_get_actual_len(newext) == 0)) { if (unlikely(ext4_ext_get_actual_len(newext) == 0)) {
...@@ -1942,18 +1931,8 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode, ...@@ -1942,18 +1931,8 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode,
if (err) if (err)
return err; return err;
/*
* ext4_can_extents_be_merged should have checked
* that either both extents are uninitialized, or
* both aren't. Thus we need to check only one of
* them here.
*/
if (ext4_ext_is_uninitialized(ex))
uninitialized = 1;
ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex) ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex)
+ ext4_ext_get_actual_len(newext)); + ext4_ext_get_actual_len(newext));
if (uninitialized)
ext4_ext_mark_uninitialized(ex);
eh = path[depth].p_hdr; eh = path[depth].p_hdr;
nearex = ex; nearex = ex;
goto merge; goto merge;
...@@ -1976,20 +1955,10 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode, ...@@ -1976,20 +1955,10 @@ int ext4_ext_insert_extent(handle_t *handle, struct inode *inode,
if (err) if (err)
return err; return err;
/*
* ext4_can_extents_be_merged should have checked
* that either both extents are uninitialized, or
* both aren't. Thus we need to check only one of
* them here.
*/
if (ext4_ext_is_uninitialized(ex))
uninitialized = 1;
ex->ee_block = newext->ee_block; ex->ee_block = newext->ee_block;
ext4_ext_store_pblock(ex, ext4_ext_pblock(newext)); ext4_ext_store_pblock(ex, ext4_ext_pblock(newext));
ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex) ex->ee_len = cpu_to_le16(ext4_ext_get_actual_len(ex)
+ ext4_ext_get_actual_len(newext)); + ext4_ext_get_actual_len(newext));
if (uninitialized)
ext4_ext_mark_uninitialized(ex);
eh = path[depth].p_hdr; eh = path[depth].p_hdr;
nearex = ex; nearex = ex;
goto merge; goto merge;
......
...@@ -432,7 +432,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent, ...@@ -432,7 +432,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,
ext4fs_dirhash(qstr->name, qstr->len, &hinfo); ext4fs_dirhash(qstr->name, qstr->len, &hinfo);
grp = hinfo.hash; grp = hinfo.hash;
} else } else
get_random_bytes(&grp, sizeof(grp)); grp = prandom_u32();
parent_group = (unsigned)grp % ngroups; parent_group = (unsigned)grp % ngroups;
for (i = 0; i < ngroups; i++) { for (i = 0; i < ngroups; i++) {
g = (parent_group + i) % ngroups; g = (parent_group + i) % ngroups;
......
...@@ -994,11 +994,9 @@ static int ext4_add_dirent_to_inline(handle_t *handle, ...@@ -994,11 +994,9 @@ static int ext4_add_dirent_to_inline(handle_t *handle,
struct inode *dir = dentry->d_parent->d_inode; struct inode *dir = dentry->d_parent->d_inode;
const char *name = dentry->d_name.name; const char *name = dentry->d_name.name;
int namelen = dentry->d_name.len; int namelen = dentry->d_name.len;
unsigned short reclen;
int err; int err;
struct ext4_dir_entry_2 *de; struct ext4_dir_entry_2 *de;
reclen = EXT4_DIR_REC_LEN(namelen);
err = ext4_find_dest_de(dir, inode, iloc->bh, err = ext4_find_dest_de(dir, inode, iloc->bh,
inline_start, inline_size, inline_start, inline_size,
name, namelen, &de); name, namelen, &de);
...@@ -1442,6 +1440,7 @@ int ext4_read_inline_dir(struct file *file, ...@@ -1442,6 +1440,7 @@ int ext4_read_inline_dir(struct file *file,
if (ret < 0) if (ret < 0)
goto out; goto out;
ret = 0;
sb = inode->i_sb; sb = inode->i_sb;
parent_ino = le32_to_cpu(((struct ext4_dir_entry_2 *)dir_buf)->inode); parent_ino = le32_to_cpu(((struct ext4_dir_entry_2 *)dir_buf)->inode);
offset = ctx->pos; offset = ctx->pos;
......
...@@ -2178,6 +2178,9 @@ static int mpage_map_one_extent(handle_t *handle, struct mpage_da_data *mpd) ...@@ -2178,6 +2178,9 @@ static int mpage_map_one_extent(handle_t *handle, struct mpage_da_data *mpd)
* *
* @handle - handle for journal operations * @handle - handle for journal operations
* @mpd - extent to map * @mpd - extent to map
* @give_up_on_write - we set this to true iff there is a fatal error and there
* is no hope of writing the data. The caller should discard
* dirty pages to avoid infinite loops.
* *
* The function maps extent starting at mpd->lblk of length mpd->len. If it is * The function maps extent starting at mpd->lblk of length mpd->len. If it is
* delayed, blocks are allocated, if it is unwritten, we may need to convert * delayed, blocks are allocated, if it is unwritten, we may need to convert
...@@ -2295,6 +2298,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) ...@@ -2295,6 +2298,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
struct address_space *mapping = mpd->inode->i_mapping; struct address_space *mapping = mpd->inode->i_mapping;
struct pagevec pvec; struct pagevec pvec;
unsigned int nr_pages; unsigned int nr_pages;
long left = mpd->wbc->nr_to_write;
pgoff_t index = mpd->first_page; pgoff_t index = mpd->first_page;
pgoff_t end = mpd->last_page; pgoff_t end = mpd->last_page;
int tag; int tag;
...@@ -2330,6 +2334,17 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) ...@@ -2330,6 +2334,17 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
if (page->index > end) if (page->index > end)
goto out; goto out;
/*
* Accumulated enough dirty pages? This doesn't apply
* to WB_SYNC_ALL mode. For integrity sync we have to
* keep going because someone may be concurrently
* dirtying pages, and we might have synced a lot of
* newly appeared dirty pages, but have not synced all
* of the old dirty pages.
*/
if (mpd->wbc->sync_mode == WB_SYNC_NONE && left <= 0)
goto out;
/* If we can't merge this page, we are done. */ /* If we can't merge this page, we are done. */
if (mpd->map.m_len > 0 && mpd->next_page != page->index) if (mpd->map.m_len > 0 && mpd->next_page != page->index)
goto out; goto out;
...@@ -2364,19 +2379,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) ...@@ -2364,19 +2379,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
if (err <= 0) if (err <= 0)
goto out; goto out;
err = 0; err = 0;
left--;
/*
* Accumulated enough dirty pages? This doesn't apply
* to WB_SYNC_ALL mode. For integrity sync we have to
* keep going because someone may be concurrently
* dirtying pages, and we might have synced a lot of
* newly appeared dirty pages, but have not synced all
* of the old dirty pages.
*/
if (mpd->wbc->sync_mode == WB_SYNC_NONE &&
mpd->next_page - mpd->first_page >=
mpd->wbc->nr_to_write)
goto out;
} }
pagevec_release(&pvec); pagevec_release(&pvec);
cond_resched(); cond_resched();
...@@ -2420,16 +2423,15 @@ static int ext4_writepages(struct address_space *mapping, ...@@ -2420,16 +2423,15 @@ static int ext4_writepages(struct address_space *mapping,
* because that could violate lock ordering on umount * because that could violate lock ordering on umount
*/ */
if (!mapping->nrpages || !mapping_tagged(mapping, PAGECACHE_TAG_DIRTY)) if (!mapping->nrpages || !mapping_tagged(mapping, PAGECACHE_TAG_DIRTY))
return 0; goto out_writepages;
if (ext4_should_journal_data(inode)) { if (ext4_should_journal_data(inode)) {
struct blk_plug plug; struct blk_plug plug;
int ret;
blk_start_plug(&plug); blk_start_plug(&plug);
ret = write_cache_pages(mapping, wbc, __writepage, mapping); ret = write_cache_pages(mapping, wbc, __writepage, mapping);
blk_finish_plug(&plug); blk_finish_plug(&plug);
return ret; goto out_writepages;
} }
/* /*
...@@ -2442,8 +2444,10 @@ static int ext4_writepages(struct address_space *mapping, ...@@ -2442,8 +2444,10 @@ static int ext4_writepages(struct address_space *mapping,
* *never* be called, so if that ever happens, we would want * *never* be called, so if that ever happens, we would want
* the stack trace. * the stack trace.
*/ */
if (unlikely(sbi->s_mount_flags & EXT4_MF_FS_ABORTED)) if (unlikely(sbi->s_mount_flags & EXT4_MF_FS_ABORTED)) {
return -EROFS; ret = -EROFS;
goto out_writepages;
}
if (ext4_should_dioread_nolock(inode)) { if (ext4_should_dioread_nolock(inode)) {
/* /*
...@@ -4689,6 +4693,15 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry, ...@@ -4689,6 +4693,15 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
inode = dentry->d_inode; inode = dentry->d_inode;
generic_fillattr(inode, stat); generic_fillattr(inode, stat);
/*
* If there is inline data in the inode, the inode will normally not
* have data blocks allocated (it may have an external xattr block).
* Report at least one sector for such files, so tools like tar, rsync,
* others doen't incorrectly think the file is completely sparse.
*/
if (unlikely(ext4_has_inline_data(inode)))
stat->blocks += (stat->size + 511) >> 9;
/* /*
* We can't update i_blocks if the block allocation is delayed * We can't update i_blocks if the block allocation is delayed
* otherwise in the case of system crash before the real block * otherwise in the case of system crash before the real block
...@@ -4700,9 +4713,8 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry, ...@@ -4700,9 +4713,8 @@ int ext4_getattr(struct vfsmount *mnt, struct dentry *dentry,
* blocks for this file. * blocks for this file.
*/ */
delalloc_blocks = EXT4_C2B(EXT4_SB(inode->i_sb), delalloc_blocks = EXT4_C2B(EXT4_SB(inode->i_sb),
EXT4_I(inode)->i_reserved_data_blocks); EXT4_I(inode)->i_reserved_data_blocks);
stat->blocks += delalloc_blocks << (inode->i_sb->s_blocksize_bits - 9);
stat->blocks += delalloc_blocks << (inode->i_sb->s_blocksize_bits-9);
return 0; return 0;
} }
......
...@@ -4794,8 +4794,8 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode, ...@@ -4794,8 +4794,8 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
" group:%d block:%d count:%lu failed" " group:%d block:%d count:%lu failed"
" with %d", block_group, bit, count, " with %d", block_group, bit, count,
err); err);
} } else
EXT4_MB_GRP_CLEAR_TRIMMED(e4b.bd_info);
ext4_lock_group(sb, block_group); ext4_lock_group(sb, block_group);
mb_clear_bits(bitmap_bh->b_data, bit, count_clusters); mb_clear_bits(bitmap_bh->b_data, bit, count_clusters);
......
...@@ -259,7 +259,7 @@ static unsigned int mmp_new_seq(void) ...@@ -259,7 +259,7 @@ static unsigned int mmp_new_seq(void)
u32 new_seq; u32 new_seq;
do { do {
get_random_bytes(&new_seq, sizeof(u32)); new_seq = prandom_u32();
} while (new_seq > EXT4_MMP_SEQ_MAX); } while (new_seq > EXT4_MMP_SEQ_MAX);
return new_seq; return new_seq;
......
...@@ -197,14 +197,15 @@ static void dump_completed_IO(struct inode *inode, struct list_head *head) ...@@ -197,14 +197,15 @@ static void dump_completed_IO(struct inode *inode, struct list_head *head)
static void ext4_add_complete_io(ext4_io_end_t *io_end) static void ext4_add_complete_io(ext4_io_end_t *io_end)
{ {
struct ext4_inode_info *ei = EXT4_I(io_end->inode); struct ext4_inode_info *ei = EXT4_I(io_end->inode);
struct ext4_sb_info *sbi = EXT4_SB(io_end->inode->i_sb);
struct workqueue_struct *wq; struct workqueue_struct *wq;
unsigned long flags; unsigned long flags;
/* Only reserved conversions from writeback should enter here */ /* Only reserved conversions from writeback should enter here */
WARN_ON(!(io_end->flag & EXT4_IO_END_UNWRITTEN)); WARN_ON(!(io_end->flag & EXT4_IO_END_UNWRITTEN));
WARN_ON(!io_end->handle); WARN_ON(!io_end->handle && sbi->s_journal);
spin_lock_irqsave(&ei->i_completed_io_lock, flags); spin_lock_irqsave(&ei->i_completed_io_lock, flags);
wq = EXT4_SB(io_end->inode->i_sb)->rsv_conversion_wq; wq = sbi->rsv_conversion_wq;
if (list_empty(&ei->i_rsv_conversion_list)) if (list_empty(&ei->i_rsv_conversion_list))
queue_work(wq, &ei->i_rsv_conversion_work); queue_work(wq, &ei->i_rsv_conversion_work);
list_add_tail(&io_end->list, &ei->i_rsv_conversion_list); list_add_tail(&io_end->list, &ei->i_rsv_conversion_list);
......
...@@ -411,20 +411,26 @@ static void ext4_handle_error(struct super_block *sb) ...@@ -411,20 +411,26 @@ static void ext4_handle_error(struct super_block *sb)
sb->s_id); sb->s_id);
} }
#define ext4_error_ratelimit(sb) \
___ratelimit(&(EXT4_SB(sb)->s_err_ratelimit_state), \
"EXT4-fs error")
void __ext4_error(struct super_block *sb, const char *function, void __ext4_error(struct super_block *sb, const char *function,
unsigned int line, const char *fmt, ...) unsigned int line, const char *fmt, ...)
{ {
struct va_format vaf; struct va_format vaf;
va_list args; va_list args;
va_start(args, fmt); if (ext4_error_ratelimit(sb)) {
vaf.fmt = fmt; va_start(args, fmt);
vaf.va = &args; vaf.fmt = fmt;
printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: comm %s: %pV\n", vaf.va = &args;
sb->s_id, function, line, current->comm, &vaf); printk(KERN_CRIT
va_end(args); "EXT4-fs error (device %s): %s:%d: comm %s: %pV\n",
sb->s_id, function, line, current->comm, &vaf);
va_end(args);
}
save_error_info(sb, function, line); save_error_info(sb, function, line);
ext4_handle_error(sb); ext4_handle_error(sb);
} }
...@@ -438,22 +444,23 @@ void __ext4_error_inode(struct inode *inode, const char *function, ...@@ -438,22 +444,23 @@ void __ext4_error_inode(struct inode *inode, const char *function,
es->s_last_error_ino = cpu_to_le32(inode->i_ino); es->s_last_error_ino = cpu_to_le32(inode->i_ino);
es->s_last_error_block = cpu_to_le64(block); es->s_last_error_block = cpu_to_le64(block);
if (ext4_error_ratelimit(inode->i_sb)) {
va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
if (block)
printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: "
"inode #%lu: block %llu: comm %s: %pV\n",
inode->i_sb->s_id, function, line, inode->i_ino,
block, current->comm, &vaf);
else
printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: "
"inode #%lu: comm %s: %pV\n",
inode->i_sb->s_id, function, line, inode->i_ino,
current->comm, &vaf);
va_end(args);
}
save_error_info(inode->i_sb, function, line); save_error_info(inode->i_sb, function, line);
va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
if (block)
printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: "
"inode #%lu: block %llu: comm %s: %pV\n",
inode->i_sb->s_id, function, line, inode->i_ino,
block, current->comm, &vaf);
else
printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: "
"inode #%lu: comm %s: %pV\n",
inode->i_sb->s_id, function, line, inode->i_ino,
current->comm, &vaf);
va_end(args);
ext4_handle_error(inode->i_sb); ext4_handle_error(inode->i_sb);
} }
...@@ -469,27 +476,28 @@ void __ext4_error_file(struct file *file, const char *function, ...@@ -469,27 +476,28 @@ void __ext4_error_file(struct file *file, const char *function,
es = EXT4_SB(inode->i_sb)->s_es; es = EXT4_SB(inode->i_sb)->s_es;
es->s_last_error_ino = cpu_to_le32(inode->i_ino); es->s_last_error_ino = cpu_to_le32(inode->i_ino);
if (ext4_error_ratelimit(inode->i_sb)) {
path = d_path(&(file->f_path), pathname, sizeof(pathname));
if (IS_ERR(path))
path = "(unknown)";
va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
if (block)
printk(KERN_CRIT
"EXT4-fs error (device %s): %s:%d: inode #%lu: "
"block %llu: comm %s: path %s: %pV\n",
inode->i_sb->s_id, function, line, inode->i_ino,
block, current->comm, path, &vaf);
else
printk(KERN_CRIT
"EXT4-fs error (device %s): %s:%d: inode #%lu: "
"comm %s: path %s: %pV\n",
inode->i_sb->s_id, function, line, inode->i_ino,
current->comm, path, &vaf);
va_end(args);
}
save_error_info(inode->i_sb, function, line); save_error_info(inode->i_sb, function, line);
path = d_path(&(file->f_path), pathname, sizeof(pathname));
if (IS_ERR(path))
path = "(unknown)";
va_start(args, fmt);
vaf.fmt = fmt;
vaf.va = &args;
if (block)
printk(KERN_CRIT
"EXT4-fs error (device %s): %s:%d: inode #%lu: "
"block %llu: comm %s: path %s: %pV\n",
inode->i_sb->s_id, function, line, inode->i_ino,
block, current->comm, path, &vaf);
else
printk(KERN_CRIT
"EXT4-fs error (device %s): %s:%d: inode #%lu: "
"comm %s: path %s: %pV\n",
inode->i_sb->s_id, function, line, inode->i_ino,
current->comm, path, &vaf);
va_end(args);
ext4_handle_error(inode->i_sb); ext4_handle_error(inode->i_sb);
} }
...@@ -543,11 +551,13 @@ void __ext4_std_error(struct super_block *sb, const char *function, ...@@ -543,11 +551,13 @@ void __ext4_std_error(struct super_block *sb, const char *function,
(sb->s_flags & MS_RDONLY)) (sb->s_flags & MS_RDONLY))
return; return;
errstr = ext4_decode_error(sb, errno, nbuf); if (ext4_error_ratelimit(sb)) {
printk(KERN_CRIT "EXT4-fs error (device %s) in %s:%d: %s\n", errstr = ext4_decode_error(sb, errno, nbuf);
sb->s_id, function, line, errstr); printk(KERN_CRIT "EXT4-fs error (device %s) in %s:%d: %s\n",
save_error_info(sb, function, line); sb->s_id, function, line, errstr);
}
save_error_info(sb, function, line);
ext4_handle_error(sb); ext4_handle_error(sb);
} }
...@@ -597,6 +607,9 @@ void __ext4_msg(struct super_block *sb, ...@@ -597,6 +607,9 @@ void __ext4_msg(struct super_block *sb,
struct va_format vaf; struct va_format vaf;
va_list args; va_list args;
if (!___ratelimit(&(EXT4_SB(sb)->s_msg_ratelimit_state), "EXT4-fs"))
return;
va_start(args, fmt); va_start(args, fmt);
vaf.fmt = fmt; vaf.fmt = fmt;
vaf.va = &args; vaf.va = &args;
...@@ -610,6 +623,10 @@ void __ext4_warning(struct super_block *sb, const char *function, ...@@ -610,6 +623,10 @@ void __ext4_warning(struct super_block *sb, const char *function,
struct va_format vaf; struct va_format vaf;
va_list args; va_list args;
if (!___ratelimit(&(EXT4_SB(sb)->s_warning_ratelimit_state),
"EXT4-fs warning"))
return;
va_start(args, fmt); va_start(args, fmt);
vaf.fmt = fmt; vaf.fmt = fmt;
vaf.va = &args; vaf.va = &args;
...@@ -633,18 +650,20 @@ __acquires(bitlock) ...@@ -633,18 +650,20 @@ __acquires(bitlock)
es->s_last_error_block = cpu_to_le64(block); es->s_last_error_block = cpu_to_le64(block);
__save_error_info(sb, function, line); __save_error_info(sb, function, line);
va_start(args, fmt); if (ext4_error_ratelimit(sb)) {
va_start(args, fmt);
vaf.fmt = fmt; vaf.fmt = fmt;
vaf.va = &args; vaf.va = &args;
printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: group %u, ", printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: group %u, ",
sb->s_id, function, line, grp); sb->s_id, function, line, grp);
if (ino) if (ino)
printk(KERN_CONT "inode %lu: ", ino); printk(KERN_CONT "inode %lu: ", ino);
if (block) if (block)
printk(KERN_CONT "block %llu:", (unsigned long long) block); printk(KERN_CONT "block %llu:",
printk(KERN_CONT "%pV\n", &vaf); (unsigned long long) block);
va_end(args); printk(KERN_CONT "%pV\n", &vaf);
va_end(args);
}
if (test_opt(sb, ERRORS_CONT)) { if (test_opt(sb, ERRORS_CONT)) {
ext4_commit_super(sb, 0); ext4_commit_super(sb, 0);
...@@ -2606,6 +2625,12 @@ EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc); ...@@ -2606,6 +2625,12 @@ EXT4_RW_ATTR_SBI_UI(mb_group_prealloc, s_mb_group_prealloc);
EXT4_DEPRECATED_ATTR(max_writeback_mb_bump, 128); EXT4_DEPRECATED_ATTR(max_writeback_mb_bump, 128);
EXT4_RW_ATTR_SBI_UI(extent_max_zeroout_kb, s_extent_max_zeroout_kb); EXT4_RW_ATTR_SBI_UI(extent_max_zeroout_kb, s_extent_max_zeroout_kb);
EXT4_ATTR(trigger_fs_error, 0200, NULL, trigger_test_error); EXT4_ATTR(trigger_fs_error, 0200, NULL, trigger_test_error);
EXT4_RW_ATTR_SBI_UI(err_ratelimit_interval_ms, s_err_ratelimit_state.interval);
EXT4_RW_ATTR_SBI_UI(err_ratelimit_burst, s_err_ratelimit_state.burst);
EXT4_RW_ATTR_SBI_UI(warning_ratelimit_interval_ms, s_warning_ratelimit_state.interval);
EXT4_RW_ATTR_SBI_UI(warning_ratelimit_burst, s_warning_ratelimit_state.burst);
EXT4_RW_ATTR_SBI_UI(msg_ratelimit_interval_ms, s_msg_ratelimit_state.interval);
EXT4_RW_ATTR_SBI_UI(msg_ratelimit_burst, s_msg_ratelimit_state.burst);
static struct attribute *ext4_attrs[] = { static struct attribute *ext4_attrs[] = {
ATTR_LIST(delayed_allocation_blocks), ATTR_LIST(delayed_allocation_blocks),
...@@ -2623,6 +2648,12 @@ static struct attribute *ext4_attrs[] = { ...@@ -2623,6 +2648,12 @@ static struct attribute *ext4_attrs[] = {
ATTR_LIST(max_writeback_mb_bump), ATTR_LIST(max_writeback_mb_bump),
ATTR_LIST(extent_max_zeroout_kb), ATTR_LIST(extent_max_zeroout_kb),
ATTR_LIST(trigger_fs_error), ATTR_LIST(trigger_fs_error),
ATTR_LIST(err_ratelimit_interval_ms),
ATTR_LIST(err_ratelimit_burst),
ATTR_LIST(warning_ratelimit_interval_ms),
ATTR_LIST(warning_ratelimit_burst),
ATTR_LIST(msg_ratelimit_interval_ms),
ATTR_LIST(msg_ratelimit_burst),
NULL, NULL,
}; };
...@@ -3037,7 +3068,6 @@ static struct ext4_li_request *ext4_li_request_new(struct super_block *sb, ...@@ -3037,7 +3068,6 @@ static struct ext4_li_request *ext4_li_request_new(struct super_block *sb,
{ {
struct ext4_sb_info *sbi = EXT4_SB(sb); struct ext4_sb_info *sbi = EXT4_SB(sb);
struct ext4_li_request *elr; struct ext4_li_request *elr;
unsigned long rnd;
elr = kzalloc(sizeof(*elr), GFP_KERNEL); elr = kzalloc(sizeof(*elr), GFP_KERNEL);
if (!elr) if (!elr)
...@@ -3052,10 +3082,8 @@ static struct ext4_li_request *ext4_li_request_new(struct super_block *sb, ...@@ -3052,10 +3082,8 @@ static struct ext4_li_request *ext4_li_request_new(struct super_block *sb,
* spread the inode table initialization requests * spread the inode table initialization requests
* better. * better.
*/ */
get_random_bytes(&rnd, sizeof(rnd)); elr->lr_next_sched = jiffies + (prandom_u32() %
elr->lr_next_sched = jiffies + (unsigned long)rnd % (EXT4_DEF_LI_MAX_START_DELAY * HZ));
(EXT4_DEF_LI_MAX_START_DELAY * HZ);
return elr; return elr;
} }
...@@ -4118,6 +4146,11 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) ...@@ -4118,6 +4146,11 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
if (es->s_error_count) if (es->s_error_count)
mod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */ mod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */
/* Enable message ratelimiting. Default is 10 messages per 5 secs. */
ratelimit_state_init(&sbi->s_err_ratelimit_state, 5 * HZ, 10);
ratelimit_state_init(&sbi->s_warning_ratelimit_state, 5 * HZ, 10);
ratelimit_state_init(&sbi->s_msg_ratelimit_state, 5 * HZ, 10);
kfree(orig_data); kfree(orig_data);
return 0; return 0;
......
...@@ -1352,6 +1352,7 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize, ...@@ -1352,6 +1352,7 @@ int ext4_expand_extra_isize_ea(struct inode *inode, int new_extra_isize,
new_extra_isize = s_min_extra_isize; new_extra_isize = s_min_extra_isize;
kfree(is); is = NULL; kfree(is); is = NULL;
kfree(bs); bs = NULL; kfree(bs); bs = NULL;
brelse(bh);
goto retry; goto retry;
} }
error = -1; error = -1;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment