Skip to content

Commit c2661b8

Browse files
committed
Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
Pull ext4 updates from Ted Ts'o: "A large number of cleanups and bug fixes, with some (minor) journal optimizations" [ This got sent to me before -rc1, but was stuck in my spam folder. - Linus ] * tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: (67 commits) ext4: check s_chksum_driver when looking for bg csum presence ext4: move error report out of atomic context in ext4_init_block_bitmap() ext4: Replace open coded mdata csum feature to helper function ext4: delete useless comments about ext4_move_extents ext4: fix reservation overflow in ext4_da_write_begin ext4: add ext4_iget_normal() which is to be used for dir tree lookups ext4: don't orphan or truncate the boot loader inode ext4: grab missed write_count for EXT4_IOC_SWAP_BOOT ext4: optimize block allocation on grow indepth ext4: get rid of code duplication ext4: fix over-defensive complaint after journal abort ext4: fix return value of ext4_do_update_inode ext4: fix mmap data corruption when blocksize < pagesize vfs: fix data corruption when blocksize < pagesize for mmaped data ext4: fold ext4_nojournal_sops into ext4_sops ext4: support freezing ext2 (nojournal) file systems ext4: fold ext4_sync_fs_nojournal() into ext4_sync_fs() ext4: don't check quota format when there are no quota files jbd2: simplify calling convention around __jbd2_journal_clean_checkpoint_list jbd2: avoid pointless scanning of checkpoint lists ...
2 parents f114040 + 813d32f commit c2661b8

33 files changed

+1488
-1883
lines changed

fs/buffer.c

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ init_page_buffers(struct page *page, struct block_device *bdev,
993993
*/
994994
static int
995995
grow_dev_page(struct block_device *bdev, sector_t block,
996-
pgoff_t index, int size, int sizebits)
996+
pgoff_t index, int size, int sizebits, gfp_t gfp)
997997
{
998998
struct inode *inode = bdev->bd_inode;
999999
struct page *page;
@@ -1002,8 +1002,8 @@ grow_dev_page(struct block_device *bdev, sector_t block,
10021002
int ret = 0; /* Will call free_more_memory() */
10031003
gfp_t gfp_mask;
10041004

1005-
gfp_mask = mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS;
1006-
gfp_mask |= __GFP_MOVABLE;
1005+
gfp_mask = (mapping_gfp_mask(inode->i_mapping) & ~__GFP_FS) | gfp;
1006+
10071007
/*
10081008
* XXX: __getblk_slow() can not really deal with failure and
10091009
* will endlessly loop on improvised global reclaim. Prefer
@@ -1060,7 +1060,7 @@ grow_dev_page(struct block_device *bdev, sector_t block,
10601060
* that page was dirty, the buffers are set dirty also.
10611061
*/
10621062
static int
1063-
grow_buffers(struct block_device *bdev, sector_t block, int size)
1063+
grow_buffers(struct block_device *bdev, sector_t block, int size, gfp_t gfp)
10641064
{
10651065
pgoff_t index;
10661066
int sizebits;
@@ -1087,11 +1087,12 @@ grow_buffers(struct block_device *bdev, sector_t block, int size)
10871087
}
10881088

10891089
/* Create a page with the proper size buffers.. */
1090-
return grow_dev_page(bdev, block, index, size, sizebits);
1090+
return grow_dev_page(bdev, block, index, size, sizebits, gfp);
10911091
}
10921092

1093-
static struct buffer_head *
1094-
__getblk_slow(struct block_device *bdev, sector_t block, int size)
1093+
struct buffer_head *
1094+
__getblk_slow(struct block_device *bdev, sector_t block,
1095+
unsigned size, gfp_t gfp)
10951096
{
10961097
/* Size must be multiple of hard sectorsize */
10971098
if (unlikely(size & (bdev_logical_block_size(bdev)-1) ||
@@ -1113,13 +1114,14 @@ __getblk_slow(struct block_device *bdev, sector_t block, int size)
11131114
if (bh)
11141115
return bh;
11151116

1116-
ret = grow_buffers(bdev, block, size);
1117+
ret = grow_buffers(bdev, block, size, gfp);
11171118
if (ret < 0)
11181119
return NULL;
11191120
if (ret == 0)
11201121
free_more_memory();
11211122
}
11221123
}
1124+
EXPORT_SYMBOL(__getblk_slow);
11231125

11241126
/*
11251127
* The relationship between dirty buffers and dirty pages:
@@ -1373,24 +1375,25 @@ __find_get_block(struct block_device *bdev, sector_t block, unsigned size)
13731375
EXPORT_SYMBOL(__find_get_block);
13741376

13751377
/*
1376-
* __getblk will locate (and, if necessary, create) the buffer_head
1378+
* __getblk_gfp() will locate (and, if necessary, create) the buffer_head
13771379
* which corresponds to the passed block_device, block and size. The
13781380
* returned buffer has its reference count incremented.
13791381
*
1380-
* __getblk() will lock up the machine if grow_dev_page's try_to_free_buffers()
1381-
* attempt is failing. FIXME, perhaps?
1382+
* __getblk_gfp() will lock up the machine if grow_dev_page's
1383+
* try_to_free_buffers() attempt is failing. FIXME, perhaps?
13821384
*/
13831385
struct buffer_head *
1384-
__getblk(struct block_device *bdev, sector_t block, unsigned size)
1386+
__getblk_gfp(struct block_device *bdev, sector_t block,
1387+
unsigned size, gfp_t gfp)
13851388
{
13861389
struct buffer_head *bh = __find_get_block(bdev, block, size);
13871390

13881391
might_sleep();
13891392
if (bh == NULL)
1390-
bh = __getblk_slow(bdev, block, size);
1393+
bh = __getblk_slow(bdev, block, size, gfp);
13911394
return bh;
13921395
}
1393-
EXPORT_SYMBOL(__getblk);
1396+
EXPORT_SYMBOL(__getblk_gfp);
13941397

13951398
/*
13961399
* Do async read-ahead on a buffer..
@@ -1406,24 +1409,28 @@ void __breadahead(struct block_device *bdev, sector_t block, unsigned size)
14061409
EXPORT_SYMBOL(__breadahead);
14071410

14081411
/**
1409-
* __bread() - reads a specified block and returns the bh
1412+
* __bread_gfp() - reads a specified block and returns the bh
14101413
* @bdev: the block_device to read from
14111414
* @block: number of block
14121415
* @size: size (in bytes) to read
1413-
*
1416+
* @gfp: page allocation flag
1417+
*
14141418
* Reads a specified block, and returns buffer head that contains it.
1419+
* The page cache can be allocated from non-movable area
1420+
* not to prevent page migration if you set gfp to zero.
14151421
* It returns NULL if the block was unreadable.
14161422
*/
14171423
struct buffer_head *
1418-
__bread(struct block_device *bdev, sector_t block, unsigned size)
1424+
__bread_gfp(struct block_device *bdev, sector_t block,
1425+
unsigned size, gfp_t gfp)
14191426
{
1420-
struct buffer_head *bh = __getblk(bdev, block, size);
1427+
struct buffer_head *bh = __getblk_gfp(bdev, block, size, gfp);
14211428

14221429
if (likely(bh) && !buffer_uptodate(bh))
14231430
bh = __bread_slow(bh);
14241431
return bh;
14251432
}
1426-
EXPORT_SYMBOL(__bread);
1433+
EXPORT_SYMBOL(__bread_gfp);
14271434

14281435
/*
14291436
* invalidate_bh_lrus() is called rarely - but not only at unmount.
@@ -2082,6 +2089,7 @@ int generic_write_end(struct file *file, struct address_space *mapping,
20822089
struct page *page, void *fsdata)
20832090
{
20842091
struct inode *inode = mapping->host;
2092+
loff_t old_size = inode->i_size;
20852093
int i_size_changed = 0;
20862094

20872095
copied = block_write_end(file, mapping, pos, len, copied, page, fsdata);
@@ -2101,6 +2109,8 @@ int generic_write_end(struct file *file, struct address_space *mapping,
21012109
unlock_page(page);
21022110
page_cache_release(page);
21032111

2112+
if (old_size < pos)
2113+
pagecache_isize_extended(inode, old_size, pos);
21042114
/*
21052115
* Don't mark the inode dirty under page lock. First, it unnecessarily
21062116
* makes the holding time of page lock longer. Second, it forces lock

fs/ext4/balloc.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static unsigned int num_clusters_in_group(struct super_block *sb,
176176
}
177177

178178
/* Initializes an uninitialized block bitmap */
179-
static void ext4_init_block_bitmap(struct super_block *sb,
179+
static int ext4_init_block_bitmap(struct super_block *sb,
180180
struct buffer_head *bh,
181181
ext4_group_t block_group,
182182
struct ext4_group_desc *gdp)
@@ -192,7 +192,6 @@ static void ext4_init_block_bitmap(struct super_block *sb,
192192
/* If checksum is bad mark all blocks used to prevent allocation
193193
* essentially implementing a per-group read-only flag. */
194194
if (!ext4_group_desc_csum_verify(sb, block_group, gdp)) {
195-
ext4_error(sb, "Checksum bad for group %u", block_group);
196195
grp = ext4_get_group_info(sb, block_group);
197196
if (!EXT4_MB_GRP_BBITMAP_CORRUPT(grp))
198197
percpu_counter_sub(&sbi->s_freeclusters_counter,
@@ -205,7 +204,7 @@ static void ext4_init_block_bitmap(struct super_block *sb,
205204
count);
206205
}
207206
set_bit(EXT4_GROUP_INFO_IBITMAP_CORRUPT_BIT, &grp->bb_state);
208-
return;
207+
return -EIO;
209208
}
210209
memset(bh->b_data, 0, sb->s_blocksize);
211210

@@ -243,6 +242,7 @@ static void ext4_init_block_bitmap(struct super_block *sb,
243242
sb->s_blocksize * 8, bh->b_data);
244243
ext4_block_bitmap_csum_set(sb, block_group, gdp, bh);
245244
ext4_group_desc_csum_set(sb, block_group, gdp);
245+
return 0;
246246
}
247247

248248
/* Return the number of free blocks in a block group. It is used when
@@ -438,11 +438,15 @@ ext4_read_block_bitmap_nowait(struct super_block *sb, ext4_group_t block_group)
438438
}
439439
ext4_lock_group(sb, block_group);
440440
if (desc->bg_flags & cpu_to_le16(EXT4_BG_BLOCK_UNINIT)) {
441-
ext4_init_block_bitmap(sb, bh, block_group, desc);
441+
int err;
442+
443+
err = ext4_init_block_bitmap(sb, bh, block_group, desc);
442444
set_bitmap_uptodate(bh);
443445
set_buffer_uptodate(bh);
444446
ext4_unlock_group(sb, block_group);
445447
unlock_buffer(bh);
448+
if (err)
449+
ext4_error(sb, "Checksum bad for grp %u", block_group);
446450
return bh;
447451
}
448452
ext4_unlock_group(sb, block_group);
@@ -636,8 +640,7 @@ ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
636640
* Account for the allocated meta blocks. We will never
637641
* fail EDQUOT for metdata, but we do account for it.
638642
*/
639-
if (!(*errp) &&
640-
ext4_test_inode_state(inode, EXT4_STATE_DELALLOC_RESERVED)) {
643+
if (!(*errp) && (flags & EXT4_MB_DELALLOC_RESERVED)) {
641644
spin_lock(&EXT4_I(inode)->i_block_reservation_lock);
642645
spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
643646
dquot_alloc_block_nofail(inode,

fs/ext4/bitmap.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ int ext4_inode_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
2424
__u32 provided, calculated;
2525
struct ext4_sb_info *sbi = EXT4_SB(sb);
2626

27-
if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
28-
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
27+
if (!ext4_has_metadata_csum(sb))
2928
return 1;
3029

3130
provided = le16_to_cpu(gdp->bg_inode_bitmap_csum_lo);
@@ -46,8 +45,7 @@ void ext4_inode_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
4645
__u32 csum;
4746
struct ext4_sb_info *sbi = EXT4_SB(sb);
4847

49-
if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
50-
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
48+
if (!ext4_has_metadata_csum(sb))
5149
return;
5250

5351
csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);
@@ -65,8 +63,7 @@ int ext4_block_bitmap_csum_verify(struct super_block *sb, ext4_group_t group,
6563
struct ext4_sb_info *sbi = EXT4_SB(sb);
6664
int sz = EXT4_CLUSTERS_PER_GROUP(sb) / 8;
6765

68-
if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
69-
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
66+
if (!ext4_has_metadata_csum(sb))
7067
return 1;
7168

7269
provided = le16_to_cpu(gdp->bg_block_bitmap_csum_lo);
@@ -91,8 +88,7 @@ void ext4_block_bitmap_csum_set(struct super_block *sb, ext4_group_t group,
9188
__u32 csum;
9289
struct ext4_sb_info *sbi = EXT4_SB(sb);
9390

94-
if (!EXT4_HAS_RO_COMPAT_FEATURE(sb,
95-
EXT4_FEATURE_RO_COMPAT_METADATA_CSUM))
91+
if (!ext4_has_metadata_csum(sb))
9692
return;
9793

9894
csum = ext4_chksum(sbi, sbi->s_csum_seed, (__u8 *)bh->b_data, sz);

fs/ext4/dir.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,11 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
151151
&file->f_ra, file,
152152
index, 1);
153153
file->f_ra.prev_pos = (loff_t)index << PAGE_CACHE_SHIFT;
154-
bh = ext4_bread(NULL, inode, map.m_lblk, 0, &err);
154+
bh = ext4_bread(NULL, inode, map.m_lblk, 0);
155+
if (IS_ERR(bh))
156+
return PTR_ERR(bh);
155157
}
156158

157-
/*
158-
* We ignore I/O errors on directories so users have a chance
159-
* of recovering data when there's a bad sector
160-
*/
161159
if (!bh) {
162160
if (!dir_has_error) {
163161
EXT4_ERROR_FILE(file, 0,

0 commit comments

Comments
 (0)