aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-08-07 16:03:53 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2010-08-07 16:03:53 -0400
commit09dc942c2a767e2d298f1cc9294bc19c7d7208c5 (patch)
treed310c118467c90c264e953bdc320ae08394c662a /fs/ext4
parent90e0c225968f0878e090c7ff3f88323973476cee (diff)
parent6c7a120ac6c62316ab1fc78dfc0a7b13f3bfcbff (diff)
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
* 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: (40 commits) ext4: Adding error check after calling ext4_mb_regular_allocator() ext4: Fix dirtying of journalled buffers in data=journal mode ext4: re-inline ext4_rec_len_(to|from)_disk functions jbd2: Remove t_handle_lock from start_this_handle() jbd2: Change j_state_lock to be a rwlock_t jbd2: Use atomic variables to avoid taking t_handle_lock in jbd2_journal_stop ext4: Add mount options in superblock ext4: force block allocation on quota_off ext4: fix freeze deadlock under IO ext4: drop inode from orphan list if ext4_delete_inode() fails ext4: check to make make sure bd_dev is set before dereferencing it jbd2: Make barrier messages less scary ext4: don't print scary messages for allocation failures post-abort ext4: fix EFBIG edge case when writing to large non-extent file ext4: fix ext4_get_blocks references ext4: Always journal quota file modifications ext4: Fix potential memory leak in ext4_fill_super ext4: Don't error out the fs if the user tries to make a file too big ext4: allocate stripe-multiple IOs on stripe boundaries ext4: move aio completion after unwritten extent conversion ... Fix up conflicts in fs/ext4/inode.c as per Ted. Fix up xfs conflicts as per earlier xfs merge.
Diffstat (limited to 'fs/ext4')
-rw-r--r--fs/ext4/acl.c1
-rw-r--r--fs/ext4/balloc.c6
-rw-r--r--fs/ext4/block_validity.c8
-rw-r--r--fs/ext4/dir.c23
-rw-r--r--fs/ext4/ext4.h152
-rw-r--r--fs/ext4/ext4_jbd2.c71
-rw-r--r--fs/ext4/ext4_jbd2.h56
-rw-r--r--fs/ext4/extents.c18
-rw-r--r--fs/ext4/file.c5
-rw-r--r--fs/ext4/ialloc.c4
-rw-r--r--fs/ext4/inode.c205
-rw-r--r--fs/ext4/mballoc.c153
-rw-r--r--fs/ext4/migrate.c2
-rw-r--r--fs/ext4/move_extent.c10
-rw-r--r--fs/ext4/namei.c40
-rw-r--r--fs/ext4/resize.c8
-rw-r--r--fs/ext4/super.c334
-rw-r--r--fs/ext4/xattr.c3
18 files changed, 658 insertions, 441 deletions
diff --git a/fs/ext4/acl.c b/fs/ext4/acl.c
index feaf498feaa6..5e2ed4504ead 100644
--- a/fs/ext4/acl.c
+++ b/fs/ext4/acl.c
@@ -204,6 +204,7 @@ ext4_set_acl(handle_t *handle, struct inode *inode, int type,
204 return error; 204 return error;
205 else { 205 else {
206 inode->i_mode = mode; 206 inode->i_mode = mode;
207 inode->i_ctime = ext4_current_time(inode);
207 ext4_mark_inode_dirty(handle, inode); 208 ext4_mark_inode_dirty(handle, inode);
208 if (error == 0) 209 if (error == 0)
209 acl = NULL; 210 acl = NULL;
diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
index 95b7594c76f9..bd30799a43ed 100644
--- a/fs/ext4/balloc.c
+++ b/fs/ext4/balloc.c
@@ -377,14 +377,11 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb,
377 ext4_grpblk_t bit; 377 ext4_grpblk_t bit;
378 unsigned int i; 378 unsigned int i;
379 struct ext4_group_desc *desc; 379 struct ext4_group_desc *desc;
380 struct ext4_super_block *es; 380 struct ext4_sb_info *sbi = EXT4_SB(sb);
381 struct ext4_sb_info *sbi;
382 int err = 0, ret, blk_free_count; 381 int err = 0, ret, blk_free_count;
383 ext4_grpblk_t blocks_freed; 382 ext4_grpblk_t blocks_freed;
384 struct ext4_group_info *grp; 383 struct ext4_group_info *grp;
385 384
386 sbi = EXT4_SB(sb);
387 es = sbi->s_es;
388 ext4_debug("Adding block(s) %llu-%llu\n", block, block + count - 1); 385 ext4_debug("Adding block(s) %llu-%llu\n", block, block + count - 1);
389 386
390 ext4_get_group_no_and_offset(sb, block, &block_group, &bit); 387 ext4_get_group_no_and_offset(sb, block, &block_group, &bit);
@@ -477,7 +474,6 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb,
477 ret = ext4_handle_dirty_metadata(handle, NULL, gd_bh); 474 ret = ext4_handle_dirty_metadata(handle, NULL, gd_bh);
478 if (!err) 475 if (!err)
479 err = ret; 476 err = ret;
480 sb->s_dirt = 1;
481 477
482error_return: 478error_return:
483 brelse(bitmap_bh); 479 brelse(bitmap_bh);
diff --git a/fs/ext4/block_validity.c b/fs/ext4/block_validity.c
index 5b6973fbf1bd..3db5084db9bd 100644
--- a/fs/ext4/block_validity.c
+++ b/fs/ext4/block_validity.c
@@ -229,16 +229,20 @@ int ext4_data_block_valid(struct ext4_sb_info *sbi, ext4_fsblk_t start_blk,
229 229
230 if ((start_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) || 230 if ((start_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
231 (start_blk + count < start_blk) || 231 (start_blk + count < start_blk) ||
232 (start_blk + count > ext4_blocks_count(sbi->s_es))) 232 (start_blk + count > ext4_blocks_count(sbi->s_es))) {
233 sbi->s_es->s_last_error_block = cpu_to_le64(start_blk);
233 return 0; 234 return 0;
235 }
234 while (n) { 236 while (n) {
235 entry = rb_entry(n, struct ext4_system_zone, node); 237 entry = rb_entry(n, struct ext4_system_zone, node);
236 if (start_blk + count - 1 < entry->start_blk) 238 if (start_blk + count - 1 < entry->start_blk)
237 n = n->rb_left; 239 n = n->rb_left;
238 else if (start_blk >= (entry->start_blk + entry->count)) 240 else if (start_blk >= (entry->start_blk + entry->count))
239 n = n->rb_right; 241 n = n->rb_right;
240 else 242 else {
243 sbi->s_es->s_last_error_block = cpu_to_le64(start_blk);
241 return 0; 244 return 0;
245 }
242 } 246 }
243 return 1; 247 return 1;
244} 248}
diff --git a/fs/ext4/dir.c b/fs/ext4/dir.c
index ea5e6cb7e2a5..374510f72baa 100644
--- a/fs/ext4/dir.c
+++ b/fs/ext4/dir.c
@@ -61,10 +61,11 @@ static unsigned char get_dtype(struct super_block *sb, int filetype)
61} 61}
62 62
63 63
64int ext4_check_dir_entry(const char *function, struct inode *dir, 64int __ext4_check_dir_entry(const char *function, unsigned int line,
65 struct ext4_dir_entry_2 *de, 65 struct inode *dir,
66 struct buffer_head *bh, 66 struct ext4_dir_entry_2 *de,
67 unsigned int offset) 67 struct buffer_head *bh,
68 unsigned int offset)
68{ 69{
69 const char *error_msg = NULL; 70 const char *error_msg = NULL;
70 const int rlen = ext4_rec_len_from_disk(de->rec_len, 71 const int rlen = ext4_rec_len_from_disk(de->rec_len,
@@ -83,11 +84,10 @@ int ext4_check_dir_entry(const char *function, struct inode *dir,
83 error_msg = "inode out of bounds"; 84 error_msg = "inode out of bounds";
84 85
85 if (error_msg != NULL) 86 if (error_msg != NULL)
86 ext4_error_inode(function, dir, 87 ext4_error_inode(dir, function, line, bh->b_blocknr,
87 "bad entry in directory: %s - block=%llu" 88 "bad entry in directory: %s - "
88 "offset=%u(%u), inode=%u, rec_len=%d, name_len=%d", 89 "offset=%u(%u), inode=%u, rec_len=%d, name_len=%d",
89 error_msg, (unsigned long long) bh->b_blocknr, 90 error_msg, (unsigned) (offset%bh->b_size), offset,
90 (unsigned) (offset%bh->b_size), offset,
91 le32_to_cpu(de->inode), 91 le32_to_cpu(de->inode),
92 rlen, de->name_len); 92 rlen, de->name_len);
93 return error_msg == NULL ? 1 : 0; 93 return error_msg == NULL ? 1 : 0;
@@ -121,7 +121,8 @@ static int ext4_readdir(struct file *filp,
121 * We don't set the inode dirty flag since it's not 121 * We don't set the inode dirty flag since it's not
122 * critical that it get flushed back to the disk. 122 * critical that it get flushed back to the disk.
123 */ 123 */
124 ext4_clear_inode_flag(filp->f_path.dentry->d_inode, EXT4_INODE_INDEX); 124 ext4_clear_inode_flag(filp->f_path.dentry->d_inode,
125 EXT4_INODE_INDEX);
125 } 126 }
126 stored = 0; 127 stored = 0;
127 offset = filp->f_pos & (sb->s_blocksize - 1); 128 offset = filp->f_pos & (sb->s_blocksize - 1);
@@ -193,7 +194,7 @@ revalidate:
193 while (!error && filp->f_pos < inode->i_size 194 while (!error && filp->f_pos < inode->i_size
194 && offset < sb->s_blocksize) { 195 && offset < sb->s_blocksize) {
195 de = (struct ext4_dir_entry_2 *) (bh->b_data + offset); 196 de = (struct ext4_dir_entry_2 *) (bh->b_data + offset);
196 if (!ext4_check_dir_entry("ext4_readdir", inode, de, 197 if (!ext4_check_dir_entry(inode, de,
197 bh, offset)) { 198 bh, offset)) {
198 /* 199 /*
199 * On error, skip the f_pos to the next block 200 * On error, skip the f_pos to the next block
@@ -343,7 +344,7 @@ int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
343 struct dir_private_info *info; 344 struct dir_private_info *info;
344 int len; 345 int len;
345 346
346 info = (struct dir_private_info *) dir_file->private_data; 347 info = dir_file->private_data;
347 p = &info->root.rb_node; 348 p = &info->root.rb_node;
348 349
349 /* Create and allocate the fname structure */ 350 /* Create and allocate the fname structure */
diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
index 19a4de57128a..e03841d9f30b 100644
--- a/fs/ext4/ext4.h
+++ b/fs/ext4/ext4.h
@@ -57,10 +57,13 @@
57#endif 57#endif
58 58
59#define EXT4_ERROR_INODE(inode, fmt, a...) \ 59#define EXT4_ERROR_INODE(inode, fmt, a...) \
60 ext4_error_inode(__func__, (inode), (fmt), ## a) 60 ext4_error_inode((inode), __func__, __LINE__, 0, (fmt), ## a)
61
62#define EXT4_ERROR_INODE_BLOCK(inode, block, fmt, a...) \
63 ext4_error_inode((inode), __func__, __LINE__, (block), (fmt), ## a)
61 64
62#define EXT4_ERROR_FILE(file, fmt, a...) \ 65#define EXT4_ERROR_FILE(file, fmt, a...) \
63 ext4_error_file(__func__, (file), (fmt), ## a) 66 ext4_error_file(__func__, __LINE__, (file), (fmt), ## a)
64 67
65/* data type for block offset of block group */ 68/* data type for block offset of block group */
66typedef int ext4_grpblk_t; 69typedef int ext4_grpblk_t;
@@ -167,13 +170,15 @@ struct mpage_da_data {
167}; 170};
168#define EXT4_IO_UNWRITTEN 0x1 171#define EXT4_IO_UNWRITTEN 0x1
169typedef struct ext4_io_end { 172typedef struct ext4_io_end {
170 struct list_head list; /* per-file finished AIO list */ 173 struct list_head list; /* per-file finished IO list */
171 struct inode *inode; /* file being written to */ 174 struct inode *inode; /* file being written to */
172 unsigned int flag; /* unwritten or not */ 175 unsigned int flag; /* unwritten or not */
173 struct page *page; /* page struct for buffer write */ 176 struct page *page; /* page struct for buffer write */
174 loff_t offset; /* offset in the file */ 177 loff_t offset; /* offset in the file */
175 ssize_t size; /* size of the extent */ 178 ssize_t size; /* size of the extent */
176 struct work_struct work; /* data work queue */ 179 struct work_struct work; /* data work queue */
180 struct kiocb *iocb; /* iocb struct for AIO */
181 int result; /* error value for AIO */
177} ext4_io_end_t; 182} ext4_io_end_t;
178 183
179/* 184/*
@@ -460,7 +465,7 @@ struct ext4_new_group_data {
460}; 465};
461 466
462/* 467/*
463 * Flags used by ext4_get_blocks() 468 * Flags used by ext4_map_blocks()
464 */ 469 */
465 /* Allocate any needed blocks and/or convert an unitialized 470 /* Allocate any needed blocks and/or convert an unitialized
466 extent to be an initialized ext4 */ 471 extent to be an initialized ext4 */
@@ -873,7 +878,6 @@ struct ext4_inode_info {
873#define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */ 878#define EXT4_MOUNT_POSIX_ACL 0x08000 /* POSIX Access Control Lists */
874#define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000 /* No auto delalloc mapping */ 879#define EXT4_MOUNT_NO_AUTO_DA_ALLOC 0x10000 /* No auto delalloc mapping */
875#define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */ 880#define EXT4_MOUNT_BARRIER 0x20000 /* Use block barriers */
876#define EXT4_MOUNT_NOBH 0x40000 /* No bufferheads */
877#define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */ 881#define EXT4_MOUNT_QUOTA 0x80000 /* Some quota option set */
878#define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */ 882#define EXT4_MOUNT_USRQUOTA 0x100000 /* "old" user quota */
879#define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */ 883#define EXT4_MOUNT_GRPQUOTA 0x200000 /* "old" group quota */
@@ -982,7 +986,7 @@ struct ext4_super_block {
982 __le32 s_last_orphan; /* start of list of inodes to delete */ 986 __le32 s_last_orphan; /* start of list of inodes to delete */
983 __le32 s_hash_seed[4]; /* HTREE hash seed */ 987 __le32 s_hash_seed[4]; /* HTREE hash seed */
984 __u8 s_def_hash_version; /* Default hash version to use */ 988 __u8 s_def_hash_version; /* Default hash version to use */
985 __u8 s_reserved_char_pad; 989 __u8 s_jnl_backup_type;
986 __le16 s_desc_size; /* size of group descriptor */ 990 __le16 s_desc_size; /* size of group descriptor */
987/*100*/ __le32 s_default_mount_opts; 991/*100*/ __le32 s_default_mount_opts;
988 __le32 s_first_meta_bg; /* First metablock block group */ 992 __le32 s_first_meta_bg; /* First metablock block group */
@@ -1000,12 +1004,34 @@ struct ext4_super_block {
1000 __le64 s_mmp_block; /* Block for multi-mount protection */ 1004 __le64 s_mmp_block; /* Block for multi-mount protection */
1001 __le32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/ 1005 __le32 s_raid_stripe_width; /* blocks on all data disks (N*stride)*/
1002 __u8 s_log_groups_per_flex; /* FLEX_BG group size */ 1006 __u8 s_log_groups_per_flex; /* FLEX_BG group size */
1003 __u8 s_reserved_char_pad2; 1007 __u8 s_reserved_char_pad;
1004 __le16 s_reserved_pad; 1008 __le16 s_reserved_pad;
1005 __le64 s_kbytes_written; /* nr of lifetime kilobytes written */ 1009 __le64 s_kbytes_written; /* nr of lifetime kilobytes written */
1006 __u32 s_reserved[160]; /* Padding to the end of the block */ 1010 __le32 s_snapshot_inum; /* Inode number of active snapshot */
1011 __le32 s_snapshot_id; /* sequential ID of active snapshot */
1012 __le64 s_snapshot_r_blocks_count; /* reserved blocks for active
1013 snapshot's future use */
1014 __le32 s_snapshot_list; /* inode number of the head of the
1015 on-disk snapshot list */
1016#define EXT4_S_ERR_START offsetof(struct ext4_super_block, s_error_count)
1017 __le32 s_error_count; /* number of fs errors */
1018 __le32 s_first_error_time; /* first time an error happened */
1019 __le32 s_first_error_ino; /* inode involved in first error */
1020 __le64 s_first_error_block; /* block involved of first error */
1021 __u8 s_first_error_func[32]; /* function where the error happened */
1022 __le32 s_first_error_line; /* line number where error happened */
1023 __le32 s_last_error_time; /* most recent time of an error */
1024 __le32 s_last_error_ino; /* inode involved in last error */
1025 __le32 s_last_error_line; /* line number where error happened */
1026 __le64 s_last_error_block; /* block involved of last error */
1027 __u8 s_last_error_func[32]; /* function where the error happened */
1028#define EXT4_S_ERR_END offsetof(struct ext4_super_block, s_mount_opts)
1029 __u8 s_mount_opts[64];
1030 __le32 s_reserved[112]; /* Padding to the end of the block */
1007}; 1031};
1008 1032
1033#define EXT4_S_ERR_LEN (EXT4_S_ERR_END - EXT4_S_ERR_START)
1034
1009#ifdef __KERNEL__ 1035#ifdef __KERNEL__
1010 1036
1011/* 1037/*
@@ -1143,6 +1169,9 @@ struct ext4_sb_info {
1143 1169
1144 /* workqueue for dio unwritten */ 1170 /* workqueue for dio unwritten */
1145 struct workqueue_struct *dio_unwritten_wq; 1171 struct workqueue_struct *dio_unwritten_wq;
1172
1173 /* timer for periodic error stats printing */
1174 struct timer_list s_err_report;
1146}; 1175};
1147 1176
1148static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb) 1177static inline struct ext4_sb_info *EXT4_SB(struct super_block *sb)
@@ -1313,6 +1342,10 @@ EXT4_INODE_BIT_FNS(state, state_flags)
1313#define EXT4_DEFM_JMODE_DATA 0x0020 1342#define EXT4_DEFM_JMODE_DATA 0x0020
1314#define EXT4_DEFM_JMODE_ORDERED 0x0040 1343#define EXT4_DEFM_JMODE_ORDERED 0x0040
1315#define EXT4_DEFM_JMODE_WBACK 0x0060 1344#define EXT4_DEFM_JMODE_WBACK 0x0060
1345#define EXT4_DEFM_NOBARRIER 0x0100
1346#define EXT4_DEFM_BLOCK_VALIDITY 0x0200
1347#define EXT4_DEFM_DISCARD 0x0400
1348#define EXT4_DEFM_NODELALLOC 0x0800
1316 1349
1317/* 1350/*
1318 * Default journal batch times 1351 * Default journal batch times
@@ -1379,6 +1412,43 @@ struct ext4_dir_entry_2 {
1379#define EXT4_MAX_REC_LEN ((1<<16)-1) 1412#define EXT4_MAX_REC_LEN ((1<<16)-1)
1380 1413
1381/* 1414/*
1415 * If we ever get support for fs block sizes > page_size, we'll need
1416 * to remove the #if statements in the next two functions...
1417 */
1418static inline unsigned int
1419ext4_rec_len_from_disk(__le16 dlen, unsigned blocksize)
1420{
1421 unsigned len = le16_to_cpu(dlen);
1422
1423#if (PAGE_CACHE_SIZE >= 65536)
1424 if (len == EXT4_MAX_REC_LEN || len == 0)
1425 return blocksize;
1426 return (len & 65532) | ((len & 3) << 16);
1427#else
1428 return len;
1429#endif
1430}
1431
1432static inline __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize)
1433{
1434 if ((len > blocksize) || (blocksize > (1 << 18)) || (len & 3))
1435 BUG();
1436#if (PAGE_CACHE_SIZE >= 65536)
1437 if (len < 65536)
1438 return cpu_to_le16(len);
1439 if (len == blocksize) {
1440 if (blocksize == 65536)
1441 return cpu_to_le16(EXT4_MAX_REC_LEN);
1442 else
1443 return cpu_to_le16(0);
1444 }
1445 return cpu_to_le16((len & 65532) | ((len >> 16) & 3));
1446#else
1447 return cpu_to_le16(len);
1448#endif
1449}
1450
1451/*
1382 * Hash Tree Directory indexing 1452 * Hash Tree Directory indexing
1383 * (c) Daniel Phillips, 2001 1453 * (c) Daniel Phillips, 2001
1384 */ 1454 */
@@ -1510,9 +1580,11 @@ extern unsigned ext4_init_block_bitmap(struct super_block *sb,
1510 ext4_init_block_bitmap(sb, NULL, group, desc) 1580 ext4_init_block_bitmap(sb, NULL, group, desc)
1511 1581
1512/* dir.c */ 1582/* dir.c */
1513extern int ext4_check_dir_entry(const char *, struct inode *, 1583extern int __ext4_check_dir_entry(const char *, unsigned int, struct inode *,
1514 struct ext4_dir_entry_2 *, 1584 struct ext4_dir_entry_2 *,
1515 struct buffer_head *, unsigned int); 1585 struct buffer_head *, unsigned int);
1586#define ext4_check_dir_entry(dir, de, bh, offset) \
1587 __ext4_check_dir_entry(__func__, __LINE__, (dir), (de), (bh), (offset))
1516extern int ext4_htree_store_dirent(struct file *dir_file, __u32 hash, 1588extern int ext4_htree_store_dirent(struct file *dir_file, __u32 hash,
1517 __u32 minor_hash, 1589 __u32 minor_hash,
1518 struct ext4_dir_entry_2 *dirent); 1590 struct ext4_dir_entry_2 *dirent);
@@ -1601,8 +1673,6 @@ extern long ext4_compat_ioctl(struct file *, unsigned int, unsigned long);
1601extern int ext4_ext_migrate(struct inode *); 1673extern int ext4_ext_migrate(struct inode *);
1602 1674
1603/* namei.c */ 1675/* namei.c */
1604extern unsigned int ext4_rec_len_from_disk(__le16 dlen, unsigned blocksize);
1605extern __le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize);
1606extern int ext4_orphan_add(handle_t *, struct inode *); 1676extern int ext4_orphan_add(handle_t *, struct inode *);
1607extern int ext4_orphan_del(handle_t *, struct inode *); 1677extern int ext4_orphan_del(handle_t *, struct inode *);
1608extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash, 1678extern int ext4_htree_fill_tree(struct file *dir_file, __u32 start_hash,
@@ -1616,25 +1686,38 @@ extern int ext4_group_extend(struct super_block *sb,
1616 ext4_fsblk_t n_blocks_count); 1686 ext4_fsblk_t n_blocks_count);
1617 1687
1618/* super.c */ 1688/* super.c */
1619extern void __ext4_error(struct super_block *, const char *, const char *, ...) 1689extern void __ext4_error(struct super_block *, const char *, unsigned int,
1620 __attribute__ ((format (printf, 3, 4))); 1690 const char *, ...)
1621#define ext4_error(sb, message...) __ext4_error(sb, __func__, ## message) 1691 __attribute__ ((format (printf, 4, 5)));
1622extern void ext4_error_inode(const char *, struct inode *, const char *, ...) 1692#define ext4_error(sb, message...) __ext4_error(sb, __func__, \
1623 __attribute__ ((format (printf, 3, 4))); 1693 __LINE__, ## message)
1624extern void ext4_error_file(const char *, struct file *, const char *, ...) 1694extern void ext4_error_inode(struct inode *, const char *, unsigned int,
1625 __attribute__ ((format (printf, 3, 4))); 1695 ext4_fsblk_t, const char *, ...)
1626extern void __ext4_std_error(struct super_block *, const char *, int); 1696 __attribute__ ((format (printf, 5, 6)));
1627extern void ext4_abort(struct super_block *, const char *, const char *, ...) 1697extern void ext4_error_file(struct file *, const char *, unsigned int,
1628 __attribute__ ((format (printf, 3, 4))); 1698 const char *, ...)
1629extern void __ext4_warning(struct super_block *, const char *, 1699 __attribute__ ((format (printf, 4, 5)));
1700extern void __ext4_std_error(struct super_block *, const char *,
1701 unsigned int, int);
1702extern void __ext4_abort(struct super_block *, const char *, unsigned int,
1703 const char *, ...)
1704 __attribute__ ((format (printf, 4, 5)));
1705#define ext4_abort(sb, message...) __ext4_abort(sb, __func__, \
1706 __LINE__, ## message)
1707extern void __ext4_warning(struct super_block *, const char *, unsigned int,
1630 const char *, ...) 1708 const char *, ...)
1631 __attribute__ ((format (printf, 3, 4))); 1709 __attribute__ ((format (printf, 4, 5)));
1632#define ext4_warning(sb, message...) __ext4_warning(sb, __func__, ## message) 1710#define ext4_warning(sb, message...) __ext4_warning(sb, __func__, \
1711 __LINE__, ## message)
1633extern void ext4_msg(struct super_block *, const char *, const char *, ...) 1712extern void ext4_msg(struct super_block *, const char *, const char *, ...)
1634 __attribute__ ((format (printf, 3, 4))); 1713 __attribute__ ((format (printf, 3, 4)));
1635extern void ext4_grp_locked_error(struct super_block *, ext4_group_t, 1714extern void __ext4_grp_locked_error(const char *, unsigned int, \
1636 const char *, const char *, ...) 1715 struct super_block *, ext4_group_t, \
1637 __attribute__ ((format (printf, 4, 5))); 1716 unsigned long, ext4_fsblk_t, \
1717 const char *, ...)
1718 __attribute__ ((format (printf, 7, 8)));
1719#define ext4_grp_locked_error(sb, grp, message...) \
1720 __ext4_grp_locked_error(__func__, __LINE__, (sb), (grp), ## message)
1638extern void ext4_update_dynamic_rev(struct super_block *sb); 1721extern void ext4_update_dynamic_rev(struct super_block *sb);
1639extern int ext4_update_compat_feature(handle_t *handle, struct super_block *sb, 1722extern int ext4_update_compat_feature(handle_t *handle, struct super_block *sb,
1640 __u32 compat); 1723 __u32 compat);
@@ -1768,7 +1851,7 @@ static inline unsigned int ext4_flex_bg_size(struct ext4_sb_info *sbi)
1768#define ext4_std_error(sb, errno) \ 1851#define ext4_std_error(sb, errno) \
1769do { \ 1852do { \
1770 if ((errno)) \ 1853 if ((errno)) \
1771 __ext4_std_error((sb), __func__, (errno)); \ 1854 __ext4_std_error((sb), __func__, __LINE__, (errno)); \
1772} while (0) 1855} while (0)
1773 1856
1774#ifdef CONFIG_SMP 1857#ifdef CONFIG_SMP
@@ -1860,6 +1943,12 @@ static inline void ext4_unlock_group(struct super_block *sb,
1860 spin_unlock(ext4_group_lock_ptr(sb, group)); 1943 spin_unlock(ext4_group_lock_ptr(sb, group));
1861} 1944}
1862 1945
1946static inline void ext4_mark_super_dirty(struct super_block *sb)
1947{
1948 if (EXT4_SB(sb)->s_journal == NULL)
1949 sb->s_dirt =1;
1950}
1951
1863/* 1952/*
1864 * Inodes and files operations 1953 * Inodes and files operations
1865 */ 1954 */
@@ -1905,9 +1994,6 @@ extern int ext4_convert_unwritten_extents(struct inode *inode, loff_t offset,
1905 ssize_t len); 1994 ssize_t len);
1906extern int ext4_map_blocks(handle_t *handle, struct inode *inode, 1995extern int ext4_map_blocks(handle_t *handle, struct inode *inode,
1907 struct ext4_map_blocks *map, int flags); 1996 struct ext4_map_blocks *map, int flags);
1908extern int ext4_get_blocks(handle_t *handle, struct inode *inode,
1909 sector_t block, unsigned int max_blocks,
1910 struct buffer_head *bh, int flags);
1911extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, 1997extern int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
1912 __u64 start, __u64 len); 1998 __u64 start, __u64 len);
1913/* move_extent.c */ 1999/* move_extent.c */
diff --git a/fs/ext4/ext4_jbd2.c b/fs/ext4/ext4_jbd2.c
index 53d2764d71ca..6e272ef6ba96 100644
--- a/fs/ext4/ext4_jbd2.c
+++ b/fs/ext4/ext4_jbd2.c
@@ -6,29 +6,29 @@
6 6
7#include <trace/events/ext4.h> 7#include <trace/events/ext4.h>
8 8
9int __ext4_journal_get_undo_access(const char *where, handle_t *handle, 9int __ext4_journal_get_undo_access(const char *where, unsigned int line,
10 struct buffer_head *bh) 10 handle_t *handle, struct buffer_head *bh)
11{ 11{
12 int err = 0; 12 int err = 0;
13 13
14 if (ext4_handle_valid(handle)) { 14 if (ext4_handle_valid(handle)) {
15 err = jbd2_journal_get_undo_access(handle, bh); 15 err = jbd2_journal_get_undo_access(handle, bh);
16 if (err) 16 if (err)
17 ext4_journal_abort_handle(where, __func__, bh, 17 ext4_journal_abort_handle(where, line, __func__, bh,
18 handle, err); 18 handle, err);
19 } 19 }
20 return err; 20 return err;
21} 21}
22 22
23int __ext4_journal_get_write_access(const char *where, handle_t *handle, 23int __ext4_journal_get_write_access(const char *where, unsigned int line,
24 struct buffer_head *bh) 24 handle_t *handle, struct buffer_head *bh)
25{ 25{
26 int err = 0; 26 int err = 0;
27 27
28 if (ext4_handle_valid(handle)) { 28 if (ext4_handle_valid(handle)) {
29 err = jbd2_journal_get_write_access(handle, bh); 29 err = jbd2_journal_get_write_access(handle, bh);
30 if (err) 30 if (err)
31 ext4_journal_abort_handle(where, __func__, bh, 31 ext4_journal_abort_handle(where, line, __func__, bh,
32 handle, err); 32 handle, err);
33 } 33 }
34 return err; 34 return err;
@@ -46,9 +46,9 @@ int __ext4_journal_get_write_access(const char *where, handle_t *handle,
46 * If the handle isn't valid we're not journaling, but we still need to 46 * If the handle isn't valid we're not journaling, but we still need to
47 * call into ext4_journal_revoke() to put the buffer head. 47 * call into ext4_journal_revoke() to put the buffer head.
48 */ 48 */
49int __ext4_forget(const char *where, handle_t *handle, int is_metadata, 49int __ext4_forget(const char *where, unsigned int line, handle_t *handle,
50 struct inode *inode, struct buffer_head *bh, 50 int is_metadata, struct inode *inode,
51 ext4_fsblk_t blocknr) 51 struct buffer_head *bh, ext4_fsblk_t blocknr)
52{ 52{
53 int err; 53 int err;
54 54
@@ -79,8 +79,8 @@ int __ext4_forget(const char *where, handle_t *handle, int is_metadata,
79 BUFFER_TRACE(bh, "call jbd2_journal_forget"); 79 BUFFER_TRACE(bh, "call jbd2_journal_forget");
80 err = jbd2_journal_forget(handle, bh); 80 err = jbd2_journal_forget(handle, bh);
81 if (err) 81 if (err)
82 ext4_journal_abort_handle(where, __func__, bh, 82 ext4_journal_abort_handle(where, line, __func__,
83 handle, err); 83 bh, handle, err);
84 return err; 84 return err;
85 } 85 }
86 return 0; 86 return 0;
@@ -92,15 +92,16 @@ int __ext4_forget(const char *where, handle_t *handle, int is_metadata,
92 BUFFER_TRACE(bh, "call jbd2_journal_revoke"); 92 BUFFER_TRACE(bh, "call jbd2_journal_revoke");
93 err = jbd2_journal_revoke(handle, blocknr, bh); 93 err = jbd2_journal_revoke(handle, blocknr, bh);
94 if (err) { 94 if (err) {
95 ext4_journal_abort_handle(where, __func__, bh, handle, err); 95 ext4_journal_abort_handle(where, line, __func__,
96 ext4_abort(inode->i_sb, __func__, 96 bh, handle, err);
97 __ext4_abort(inode->i_sb, where, line,
97 "error %d when attempting revoke", err); 98 "error %d when attempting revoke", err);
98 } 99 }
99 BUFFER_TRACE(bh, "exit"); 100 BUFFER_TRACE(bh, "exit");
100 return err; 101 return err;
101} 102}
102 103
103int __ext4_journal_get_create_access(const char *where, 104int __ext4_journal_get_create_access(const char *where, unsigned int line,
104 handle_t *handle, struct buffer_head *bh) 105 handle_t *handle, struct buffer_head *bh)
105{ 106{
106 int err = 0; 107 int err = 0;
@@ -108,22 +109,23 @@ int __ext4_journal_get_create_access(const char *where,
108 if (ext4_handle_valid(handle)) { 109 if (ext4_handle_valid(handle)) {
109 err = jbd2_journal_get_create_access(handle, bh); 110 err = jbd2_journal_get_create_access(handle, bh);
110 if (err) 111 if (err)
111 ext4_journal_abort_handle(where, __func__, bh, 112 ext4_journal_abort_handle(where, line, __func__,
112 handle, err); 113 bh, handle, err);
113 } 114 }
114 return err; 115 return err;
115} 116}
116 117
117int __ext4_handle_dirty_metadata(const char *where, handle_t *handle, 118int __ext4_handle_dirty_metadata(const char *where, unsigned int line,
118 struct inode *inode, struct buffer_head *bh) 119 handle_t *handle, struct inode *inode,
120 struct buffer_head *bh)
119{ 121{
120 int err = 0; 122 int err = 0;
121 123
122 if (ext4_handle_valid(handle)) { 124 if (ext4_handle_valid(handle)) {
123 err = jbd2_journal_dirty_metadata(handle, bh); 125 err = jbd2_journal_dirty_metadata(handle, bh);
124 if (err) 126 if (err)
125 ext4_journal_abort_handle(where, __func__, bh, 127 ext4_journal_abort_handle(where, line, __func__,
126 handle, err); 128 bh, handle, err);
127 } else { 129 } else {
128 if (inode) 130 if (inode)
129 mark_buffer_dirty_inode(bh, inode); 131 mark_buffer_dirty_inode(bh, inode);
@@ -132,14 +134,33 @@ int __ext4_handle_dirty_metadata(const char *where, handle_t *handle,
132 if (inode && inode_needs_sync(inode)) { 134 if (inode && inode_needs_sync(inode)) {
133 sync_dirty_buffer(bh); 135 sync_dirty_buffer(bh);
134 if (buffer_req(bh) && !buffer_uptodate(bh)) { 136 if (buffer_req(bh) && !buffer_uptodate(bh)) {
135 ext4_error(inode->i_sb, 137 struct ext4_super_block *es;
136 "IO error syncing inode, " 138
137 "inode=%lu, block=%llu", 139 es = EXT4_SB(inode->i_sb)->s_es;
138 inode->i_ino, 140 es->s_last_error_block =
139 (unsigned long long) bh->b_blocknr); 141 cpu_to_le64(bh->b_blocknr);
142 ext4_error_inode(inode, where, line,
143 bh->b_blocknr,
144 "IO error syncing itable block");
140 err = -EIO; 145 err = -EIO;
141 } 146 }
142 } 147 }
143 } 148 }
144 return err; 149 return err;
145} 150}
151
152int __ext4_handle_dirty_super(const char *where, unsigned int line,
153 handle_t *handle, struct super_block *sb)
154{
155 struct buffer_head *bh = EXT4_SB(sb)->s_sbh;
156 int err = 0;
157
158 if (ext4_handle_valid(handle)) {
159 err = jbd2_journal_dirty_metadata(handle, bh);
160 if (err)
161 ext4_journal_abort_handle(where, line, __func__,
162 bh, handle, err);
163 } else
164 sb->s_dirt = 1;
165 return err;
166}
diff --git a/fs/ext4/ext4_jbd2.h b/fs/ext4/ext4_jbd2.h
index dade0c024797..b0bd792c58c5 100644
--- a/fs/ext4/ext4_jbd2.h
+++ b/fs/ext4/ext4_jbd2.h
@@ -122,39 +122,47 @@ int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode);
122/* 122/*
123 * Wrapper functions with which ext4 calls into JBD. 123 * Wrapper functions with which ext4 calls into JBD.
124 */ 124 */
125void ext4_journal_abort_handle(const char *caller, const char *err_fn, 125void ext4_journal_abort_handle(const char *caller, unsigned int line,
126 const char *err_fn,
126 struct buffer_head *bh, handle_t *handle, int err); 127 struct buffer_head *bh, handle_t *handle, int err);
127 128
128int __ext4_journal_get_undo_access(const char *where, handle_t *handle, 129int __ext4_journal_get_undo_access(const char *where, unsigned int line,
129 struct buffer_head *bh); 130 handle_t *handle, struct buffer_head *bh);
130 131
131int __ext4_journal_get_write_access(const char *where, handle_t *handle, 132int __ext4_journal_get_write_access(const char *where, unsigned int line,
132 struct buffer_head *bh); 133 handle_t *handle, struct buffer_head *bh);
133 134
134int __ext4_forget(const char *where, handle_t *handle, int is_metadata, 135int __ext4_forget(const char *where, unsigned int line, handle_t *handle,
135 struct inode *inode, struct buffer_head *bh, 136 int is_metadata, struct inode *inode,
136 ext4_fsblk_t blocknr); 137 struct buffer_head *bh, ext4_fsblk_t blocknr);
137 138
138int __ext4_journal_get_create_access(const char *where, 139int __ext4_journal_get_create_access(const char *where, unsigned int line,
139 handle_t *handle, struct buffer_head *bh); 140 handle_t *handle, struct buffer_head *bh);
140 141
141int __ext4_handle_dirty_metadata(const char *where, handle_t *handle, 142int __ext4_handle_dirty_metadata(const char *where, unsigned int line,
142 struct inode *inode, struct buffer_head *bh); 143 handle_t *handle, struct inode *inode,
144 struct buffer_head *bh);
145
146int __ext4_handle_dirty_super(const char *where, unsigned int line,
147 handle_t *handle, struct super_block *sb);
143 148
144#define ext4_journal_get_undo_access(handle, bh) \ 149#define ext4_journal_get_undo_access(handle, bh) \
145 __ext4_journal_get_undo_access(__func__, (handle), (bh)) 150 __ext4_journal_get_undo_access(__func__, __LINE__, (handle), (bh))
146#define ext4_journal_get_write_access(handle, bh) \ 151#define ext4_journal_get_write_access(handle, bh) \
147 __ext4_journal_get_write_access(__func__, (handle), (bh)) 152 __ext4_journal_get_write_access(__func__, __LINE__, (handle), (bh))
148#define ext4_forget(handle, is_metadata, inode, bh, block_nr) \ 153#define ext4_forget(handle, is_metadata, inode, bh, block_nr) \
149 __ext4_forget(__func__, (handle), (is_metadata), (inode), (bh),\ 154 __ext4_forget(__func__, __LINE__, (handle), (is_metadata), (inode), \
150 (block_nr)) 155 (bh), (block_nr))
151#define ext4_journal_get_create_access(handle, bh) \ 156#define ext4_journal_get_create_access(handle, bh) \
152 __ext4_journal_get_create_access(__func__, (handle), (bh)) 157 __ext4_journal_get_create_access(__func__, __LINE__, (handle), (bh))
153#define ext4_handle_dirty_metadata(handle, inode, bh) \ 158#define ext4_handle_dirty_metadata(handle, inode, bh) \
154 __ext4_handle_dirty_metadata(__func__, (handle), (inode), (bh)) 159 __ext4_handle_dirty_metadata(__func__, __LINE__, (handle), (inode), \
160 (bh))
161#define ext4_handle_dirty_super(handle, sb) \
162 __ext4_handle_dirty_super(__func__, __LINE__, (handle), (sb))
155 163
156handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks); 164handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks);
157int __ext4_journal_stop(const char *where, handle_t *handle); 165int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle);
158 166
159#define EXT4_NOJOURNAL_MAX_REF_COUNT ((unsigned long) 4096) 167#define EXT4_NOJOURNAL_MAX_REF_COUNT ((unsigned long) 4096)
160 168
@@ -207,7 +215,7 @@ static inline handle_t *ext4_journal_start(struct inode *inode, int nblocks)
207} 215}
208 216
209#define ext4_journal_stop(handle) \ 217#define ext4_journal_stop(handle) \
210 __ext4_journal_stop(__func__, (handle)) 218 __ext4_journal_stop(__func__, __LINE__, (handle))
211 219
212static inline handle_t *ext4_journal_current_handle(void) 220static inline handle_t *ext4_journal_current_handle(void)
213{ 221{
@@ -308,17 +316,15 @@ static inline int ext4_should_writeback_data(struct inode *inode)
308 * This function controls whether or not we should try to go down the 316 * This function controls whether or not we should try to go down the
309 * dioread_nolock code paths, which makes it safe to avoid taking 317 * dioread_nolock code paths, which makes it safe to avoid taking
310 * i_mutex for direct I/O reads. This only works for extent-based 318 * i_mutex for direct I/O reads. This only works for extent-based
311 * files, and it doesn't work for nobh or if data journaling is 319 * files, and it doesn't work if data journaling is enabled, since the
312 * enabled, since the dioread_nolock code uses b_private to pass 320 * dioread_nolock code uses b_private to pass information back to the
313 * information back to the I/O completion handler, and this conflicts 321 * I/O completion handler, and this conflicts with the jbd's use of
314 * with the jbd's use of b_private. 322 * b_private.
315 */ 323 */
316static inline int ext4_should_dioread_nolock(struct inode *inode) 324static inline int ext4_should_dioread_nolock(struct inode *inode)
317{ 325{
318 if (!test_opt(inode->i_sb, DIOREAD_NOLOCK)) 326 if (!test_opt(inode->i_sb, DIOREAD_NOLOCK))
319 return 0; 327 return 0;
320 if (test_opt(inode->i_sb, NOBH))
321 return 0;
322 if (!S_ISREG(inode->i_mode)) 328 if (!S_ISREG(inode->i_mode))
323 return 0; 329 return 0;
324 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) 330 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)))
diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c
index bf029c7d5518..06328d3e5717 100644
--- a/fs/ext4/extents.c
+++ b/fs/ext4/extents.c
@@ -401,9 +401,9 @@ static int ext4_valid_extent_entries(struct inode *inode,
401 return 1; 401 return 1;
402} 402}
403 403
404static int __ext4_ext_check(const char *function, struct inode *inode, 404static int __ext4_ext_check(const char *function, unsigned int line,
405 struct ext4_extent_header *eh, 405 struct inode *inode, struct ext4_extent_header *eh,
406 int depth) 406 int depth)
407{ 407{
408 const char *error_msg; 408 const char *error_msg;
409 int max = 0; 409 int max = 0;
@@ -436,7 +436,7 @@ static int __ext4_ext_check(const char *function, struct inode *inode,
436 return 0; 436 return 0;
437 437
438corrupted: 438corrupted:
439 ext4_error_inode(function, inode, 439 ext4_error_inode(inode, function, line, 0,
440 "bad header/extent: %s - magic %x, " 440 "bad header/extent: %s - magic %x, "
441 "entries %u, max %u(%u), depth %u(%u)", 441 "entries %u, max %u(%u), depth %u(%u)",
442 error_msg, le16_to_cpu(eh->eh_magic), 442 error_msg, le16_to_cpu(eh->eh_magic),
@@ -447,7 +447,7 @@ corrupted:
447} 447}
448 448
449#define ext4_ext_check(inode, eh, depth) \ 449#define ext4_ext_check(inode, eh, depth) \
450 __ext4_ext_check(__func__, inode, eh, depth) 450 __ext4_ext_check(__func__, __LINE__, inode, eh, depth)
451 451
452int ext4_ext_check_inode(struct inode *inode) 452int ext4_ext_check_inode(struct inode *inode)
453{ 453{
@@ -1083,7 +1083,6 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode,
1083{ 1083{
1084 struct ext4_ext_path *curp = path; 1084 struct ext4_ext_path *curp = path;
1085 struct ext4_extent_header *neh; 1085 struct ext4_extent_header *neh;
1086 struct ext4_extent_idx *fidx;
1087 struct buffer_head *bh; 1086 struct buffer_head *bh;
1088 ext4_fsblk_t newblock; 1087 ext4_fsblk_t newblock;
1089 int err = 0; 1088 int err = 0;
@@ -1144,10 +1143,10 @@ static int ext4_ext_grow_indepth(handle_t *handle, struct inode *inode,
1144 ext4_idx_store_pblock(curp->p_idx, newblock); 1143 ext4_idx_store_pblock(curp->p_idx, newblock);
1145 1144
1146 neh = ext_inode_hdr(inode); 1145 neh = ext_inode_hdr(inode);
1147 fidx = EXT_FIRST_INDEX(neh);
1148 ext_debug("new root: num %d(%d), lblock %d, ptr %llu\n", 1146 ext_debug("new root: num %d(%d), lblock %d, ptr %llu\n",
1149 le16_to_cpu(neh->eh_entries), le16_to_cpu(neh->eh_max), 1147 le16_to_cpu(neh->eh_entries), le16_to_cpu(neh->eh_max),
1150 le32_to_cpu(fidx->ei_block), idx_pblock(fidx)); 1148 le32_to_cpu(EXT_FIRST_INDEX(neh)->ei_block),
1149 idx_pblock(EXT_FIRST_INDEX(neh)));
1151 1150
1152 neh->eh_depth = cpu_to_le16(path->p_depth + 1); 1151 neh->eh_depth = cpu_to_le16(path->p_depth + 1);
1153 err = ext4_ext_dirty(handle, inode, curp); 1152 err = ext4_ext_dirty(handle, inode, curp);
@@ -2954,7 +2953,6 @@ static int ext4_split_unwritten_extents(handle_t *handle,
2954 struct ext4_extent *ex1 = NULL; 2953 struct ext4_extent *ex1 = NULL;
2955 struct ext4_extent *ex2 = NULL; 2954 struct ext4_extent *ex2 = NULL;
2956 struct ext4_extent *ex3 = NULL; 2955 struct ext4_extent *ex3 = NULL;
2957 struct ext4_extent_header *eh;
2958 ext4_lblk_t ee_block, eof_block; 2956 ext4_lblk_t ee_block, eof_block;
2959 unsigned int allocated, ee_len, depth; 2957 unsigned int allocated, ee_len, depth;
2960 ext4_fsblk_t newblock; 2958 ext4_fsblk_t newblock;
@@ -2971,7 +2969,6 @@ static int ext4_split_unwritten_extents(handle_t *handle,
2971 eof_block = map->m_lblk + map->m_len; 2969 eof_block = map->m_lblk + map->m_len;
2972 2970
2973 depth = ext_depth(inode); 2971 depth = ext_depth(inode);
2974 eh = path[depth].p_hdr;
2975 ex = path[depth].p_ext; 2972 ex = path[depth].p_ext;
2976 ee_block = le32_to_cpu(ex->ee_block); 2973 ee_block = le32_to_cpu(ex->ee_block);
2977 ee_len = ext4_ext_get_actual_len(ex); 2974 ee_len = ext4_ext_get_actual_len(ex);
@@ -3058,7 +3055,6 @@ static int ext4_split_unwritten_extents(handle_t *handle,
3058 err = PTR_ERR(path); 3055 err = PTR_ERR(path);
3059 goto out; 3056 goto out;
3060 } 3057 }
3061 eh = path[depth].p_hdr;
3062 ex = path[depth].p_ext; 3058 ex = path[depth].p_ext;
3063 if (ex2 != &newex) 3059 if (ex2 != &newex)
3064 ex2 = ex; 3060 ex2 = ex;
diff --git a/fs/ext4/file.c b/fs/ext4/file.c
index 5313ae4cda2d..ee92b66d4558 100644
--- a/fs/ext4/file.c
+++ b/fs/ext4/file.c
@@ -70,7 +70,8 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov,
70 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 70 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
71 size_t length = iov_length(iov, nr_segs); 71 size_t length = iov_length(iov, nr_segs);
72 72
73 if (pos > sbi->s_bitmap_maxbytes) 73 if ((pos > sbi->s_bitmap_maxbytes ||
74 (pos == sbi->s_bitmap_maxbytes && length > 0)))
74 return -EFBIG; 75 return -EFBIG;
75 76
76 if (pos + length > sbi->s_bitmap_maxbytes) { 77 if (pos + length > sbi->s_bitmap_maxbytes) {
@@ -123,7 +124,7 @@ static int ext4_file_open(struct inode * inode, struct file * filp)
123 if (!IS_ERR(cp)) { 124 if (!IS_ERR(cp)) {
124 memcpy(sbi->s_es->s_last_mounted, cp, 125 memcpy(sbi->s_es->s_last_mounted, cp,
125 sizeof(sbi->s_es->s_last_mounted)); 126 sizeof(sbi->s_es->s_last_mounted));
126 sb->s_dirt = 1; 127 ext4_mark_super_dirty(sb);
127 } 128 }
128 } 129 }
129 return dquot_file_open(inode, filp); 130 return dquot_file_open(inode, filp);
diff --git a/fs/ext4/ialloc.c b/fs/ext4/ialloc.c
index 25c4b3173fd9..ac377505ed57 100644
--- a/fs/ext4/ialloc.c
+++ b/fs/ext4/ialloc.c
@@ -279,7 +279,7 @@ out:
279 err = ext4_handle_dirty_metadata(handle, NULL, bitmap_bh); 279 err = ext4_handle_dirty_metadata(handle, NULL, bitmap_bh);
280 if (!fatal) 280 if (!fatal)
281 fatal = err; 281 fatal = err;
282 sb->s_dirt = 1; 282 ext4_mark_super_dirty(sb);
283 } else 283 } else
284 ext4_error(sb, "bit already cleared for inode %lu", ino); 284 ext4_error(sb, "bit already cleared for inode %lu", ino);
285 285
@@ -965,7 +965,7 @@ got:
965 percpu_counter_dec(&sbi->s_freeinodes_counter); 965 percpu_counter_dec(&sbi->s_freeinodes_counter);
966 if (S_ISDIR(mode)) 966 if (S_ISDIR(mode))
967 percpu_counter_inc(&sbi->s_dirs_counter); 967 percpu_counter_inc(&sbi->s_dirs_counter);
968 sb->s_dirt = 1; 968 ext4_mark_super_dirty(sb);
969 969
970 if (sbi->s_log_groups_per_flex) { 970 if (sbi->s_log_groups_per_flex) {
971 flex_group = ext4_flex_group(sbi, group); 971 flex_group = ext4_flex_group(sbi, group);
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index 0afc8c1d8cf3..a0ab3754d0d6 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -221,6 +221,7 @@ void ext4_delete_inode(struct inode *inode)
221 "couldn't extend journal (err %d)", err); 221 "couldn't extend journal (err %d)", err);
222 stop_handle: 222 stop_handle:
223 ext4_journal_stop(handle); 223 ext4_journal_stop(handle);
224 ext4_orphan_del(NULL, inode);
224 goto no_delete; 225 goto no_delete;
225 } 226 }
226 } 227 }
@@ -337,9 +338,11 @@ static int ext4_block_to_path(struct inode *inode,
337 return n; 338 return n;
338} 339}
339 340
340static int __ext4_check_blockref(const char *function, struct inode *inode, 341static int __ext4_check_blockref(const char *function, unsigned int line,
342 struct inode *inode,
341 __le32 *p, unsigned int max) 343 __le32 *p, unsigned int max)
342{ 344{
345 struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es;
343 __le32 *bref = p; 346 __le32 *bref = p;
344 unsigned int blk; 347 unsigned int blk;
345 348
@@ -348,8 +351,9 @@ static int __ext4_check_blockref(const char *function, struct inode *inode,
348 if (blk && 351 if (blk &&
349 unlikely(!ext4_data_block_valid(EXT4_SB(inode->i_sb), 352 unlikely(!ext4_data_block_valid(EXT4_SB(inode->i_sb),
350 blk, 1))) { 353 blk, 1))) {
351 ext4_error_inode(function, inode, 354 es->s_last_error_block = cpu_to_le64(blk);
352 "invalid block reference %u", blk); 355 ext4_error_inode(inode, function, line, blk,
356 "invalid block");
353 return -EIO; 357 return -EIO;
354 } 358 }
355 } 359 }
@@ -358,11 +362,13 @@ static int __ext4_check_blockref(const char *function, struct inode *inode,
358 362
359 363
360#define ext4_check_indirect_blockref(inode, bh) \ 364#define ext4_check_indirect_blockref(inode, bh) \
361 __ext4_check_blockref(__func__, inode, (__le32 *)(bh)->b_data, \ 365 __ext4_check_blockref(__func__, __LINE__, inode, \
366 (__le32 *)(bh)->b_data, \
362 EXT4_ADDR_PER_BLOCK((inode)->i_sb)) 367 EXT4_ADDR_PER_BLOCK((inode)->i_sb))
363 368
364#define ext4_check_inode_blockref(inode) \ 369#define ext4_check_inode_blockref(inode) \
365 __ext4_check_blockref(__func__, inode, EXT4_I(inode)->i_data, \ 370 __ext4_check_blockref(__func__, __LINE__, inode, \
371 EXT4_I(inode)->i_data, \
366 EXT4_NDIR_BLOCKS) 372 EXT4_NDIR_BLOCKS)
367 373
368/** 374/**
@@ -1128,20 +1134,24 @@ void ext4_da_update_reserve_space(struct inode *inode,
1128 ext4_discard_preallocations(inode); 1134 ext4_discard_preallocations(inode);
1129} 1135}
1130 1136
1131static int check_block_validity(struct inode *inode, const char *func, 1137static int __check_block_validity(struct inode *inode, const char *func,
1138 unsigned int line,
1132 struct ext4_map_blocks *map) 1139 struct ext4_map_blocks *map)
1133{ 1140{
1134 if (!ext4_data_block_valid(EXT4_SB(inode->i_sb), map->m_pblk, 1141 if (!ext4_data_block_valid(EXT4_SB(inode->i_sb), map->m_pblk,
1135 map->m_len)) { 1142 map->m_len)) {
1136 ext4_error_inode(func, inode, 1143 ext4_error_inode(inode, func, line, map->m_pblk,
1137 "lblock %lu mapped to illegal pblock %llu " 1144 "lblock %lu mapped to illegal pblock "
1138 "(length %d)", (unsigned long) map->m_lblk, 1145 "(length %d)", (unsigned long) map->m_lblk,
1139 map->m_pblk, map->m_len); 1146 map->m_len);
1140 return -EIO; 1147 return -EIO;
1141 } 1148 }
1142 return 0; 1149 return 0;
1143} 1150}
1144 1151
1152#define check_block_validity(inode, map) \
1153 __check_block_validity((inode), __func__, __LINE__, (map))
1154
1145/* 1155/*
1146 * Return the number of contiguous dirty pages in a given inode 1156 * Return the number of contiguous dirty pages in a given inode
1147 * starting at page frame idx. 1157 * starting at page frame idx.
@@ -1244,7 +1254,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
1244 up_read((&EXT4_I(inode)->i_data_sem)); 1254 up_read((&EXT4_I(inode)->i_data_sem));
1245 1255
1246 if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) { 1256 if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) {
1247 int ret = check_block_validity(inode, __func__, map); 1257 int ret = check_block_validity(inode, map);
1248 if (ret != 0) 1258 if (ret != 0)
1249 return ret; 1259 return ret;
1250 } 1260 }
@@ -1324,9 +1334,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
1324 1334
1325 up_write((&EXT4_I(inode)->i_data_sem)); 1335 up_write((&EXT4_I(inode)->i_data_sem));
1326 if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) { 1336 if (retval > 0 && map->m_flags & EXT4_MAP_MAPPED) {
1327 int ret = check_block_validity(inode, 1337 int ret = check_block_validity(inode, map);
1328 "ext4_map_blocks_after_alloc",
1329 map);
1330 if (ret != 0) 1338 if (ret != 0)
1331 return ret; 1339 return ret;
1332 } 1340 }
@@ -1519,9 +1527,25 @@ static int walk_page_buffers(handle_t *handle,
1519static int do_journal_get_write_access(handle_t *handle, 1527static int do_journal_get_write_access(handle_t *handle,
1520 struct buffer_head *bh) 1528 struct buffer_head *bh)
1521{ 1529{
1530 int dirty = buffer_dirty(bh);
1531 int ret;
1532
1522 if (!buffer_mapped(bh) || buffer_freed(bh)) 1533 if (!buffer_mapped(bh) || buffer_freed(bh))
1523 return 0; 1534 return 0;
1524 return ext4_journal_get_write_access(handle, bh); 1535 /*
1536 * __block_prepare_write() could have dirtied some buffers. Clean
1537 * the dirty bit as jbd2_journal_get_write_access() could complain
1538 * otherwise about fs integrity issues. Setting of the dirty bit
1539 * by __block_prepare_write() isn't a real problem here as we clear
1540 * the bit before releasing a page lock and thus writeback cannot
1541 * ever write the buffer.
1542 */
1543 if (dirty)
1544 clear_buffer_dirty(bh);
1545 ret = ext4_journal_get_write_access(handle, bh);
1546 if (!ret && dirty)
1547 ret = ext4_handle_dirty_metadata(handle, NULL, bh);
1548 return ret;
1525} 1549}
1526 1550
1527/* 1551/*
@@ -2194,7 +2218,7 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd)
2194 BUG_ON(!handle); 2218 BUG_ON(!handle);
2195 2219
2196 /* 2220 /*
2197 * Call ext4_get_blocks() to allocate any delayed allocation 2221 * Call ext4_map_blocks() to allocate any delayed allocation
2198 * blocks, or to convert an uninitialized extent to be 2222 * blocks, or to convert an uninitialized extent to be
2199 * initialized (in the case where we have written into 2223 * initialized (in the case where we have written into
2200 * one or more preallocated blocks). 2224 * one or more preallocated blocks).
@@ -2203,7 +2227,7 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd)
2203 * indicate that we are on the delayed allocation path. This 2227 * indicate that we are on the delayed allocation path. This
2204 * affects functions in many different parts of the allocation 2228 * affects functions in many different parts of the allocation
2205 * call path. This flag exists primarily because we don't 2229 * call path. This flag exists primarily because we don't
2206 * want to change *many* call functions, so ext4_get_blocks() 2230 * want to change *many* call functions, so ext4_map_blocks()
2207 * will set the magic i_delalloc_reserved_flag once the 2231 * will set the magic i_delalloc_reserved_flag once the
2208 * inode's allocation semaphore is taken. 2232 * inode's allocation semaphore is taken.
2209 * 2233 *
@@ -2221,6 +2245,8 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd)
2221 2245
2222 blks = ext4_map_blocks(handle, mpd->inode, &map, get_blocks_flags); 2246 blks = ext4_map_blocks(handle, mpd->inode, &map, get_blocks_flags);
2223 if (blks < 0) { 2247 if (blks < 0) {
2248 struct super_block *sb = mpd->inode->i_sb;
2249
2224 err = blks; 2250 err = blks;
2225 /* 2251 /*
2226 * If get block returns with error we simply 2252 * If get block returns with error we simply
@@ -2231,7 +2257,7 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd)
2231 return 0; 2257 return 0;
2232 2258
2233 if (err == -ENOSPC && 2259 if (err == -ENOSPC &&
2234 ext4_count_free_blocks(mpd->inode->i_sb)) { 2260 ext4_count_free_blocks(sb)) {
2235 mpd->retval = err; 2261 mpd->retval = err;
2236 return 0; 2262 return 0;
2237 } 2263 }
@@ -2243,16 +2269,17 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd)
2243 * writepage and writepages will again try to write 2269 * writepage and writepages will again try to write
2244 * the same. 2270 * the same.
2245 */ 2271 */
2246 ext4_msg(mpd->inode->i_sb, KERN_CRIT, 2272 if (!(EXT4_SB(sb)->s_mount_flags & EXT4_MF_FS_ABORTED)) {
2247 "delayed block allocation failed for inode %lu at " 2273 ext4_msg(sb, KERN_CRIT,
2248 "logical offset %llu with max blocks %zd with " 2274 "delayed block allocation failed for inode %lu "
2249 "error %d", mpd->inode->i_ino, 2275 "at logical offset %llu with max blocks %zd "
2250 (unsigned long long) next, 2276 "with error %d", mpd->inode->i_ino,
2251 mpd->b_size >> mpd->inode->i_blkbits, err); 2277 (unsigned long long) next,
2252 printk(KERN_CRIT "This should not happen!! " 2278 mpd->b_size >> mpd->inode->i_blkbits, err);
2253 "Data will be lost\n"); 2279 ext4_msg(sb, KERN_CRIT,
2254 if (err == -ENOSPC) { 2280 "This should not happen!! Data will be lost\n");
2255 ext4_print_free_blocks(mpd->inode); 2281 if (err == -ENOSPC)
2282 ext4_print_free_blocks(mpd->inode);
2256 } 2283 }
2257 /* invalidate all the pages */ 2284 /* invalidate all the pages */
2258 ext4_da_block_invalidatepages(mpd, next, 2285 ext4_da_block_invalidatepages(mpd, next,
@@ -2320,7 +2347,7 @@ static void mpage_add_bh_to_extent(struct mpage_da_data *mpd,
2320 * XXX Don't go larger than mballoc is willing to allocate 2347 * XXX Don't go larger than mballoc is willing to allocate
2321 * This is a stopgap solution. We eventually need to fold 2348 * This is a stopgap solution. We eventually need to fold
2322 * mpage_da_submit_io() into this function and then call 2349 * mpage_da_submit_io() into this function and then call
2323 * ext4_get_blocks() multiple times in a loop 2350 * ext4_map_blocks() multiple times in a loop
2324 */ 2351 */
2325 if (nrblocks >= 8*1024*1024/mpd->inode->i_sb->s_blocksize) 2352 if (nrblocks >= 8*1024*1024/mpd->inode->i_sb->s_blocksize)
2326 goto flush_it; 2353 goto flush_it;
@@ -2553,18 +2580,16 @@ static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock,
2553/* 2580/*
2554 * This function is used as a standard get_block_t calback function 2581 * This function is used as a standard get_block_t calback function
2555 * when there is no desire to allocate any blocks. It is used as a 2582 * when there is no desire to allocate any blocks. It is used as a
2556 * callback function for block_prepare_write(), nobh_writepage(), and 2583 * callback function for block_prepare_write() and block_write_full_page().
2557 * block_write_full_page(). These functions should only try to map a 2584 * These functions should only try to map a single block at a time.
2558 * single block at a time.
2559 * 2585 *
2560 * Since this function doesn't do block allocations even if the caller 2586 * Since this function doesn't do block allocations even if the caller
2561 * requests it by passing in create=1, it is critically important that 2587 * requests it by passing in create=1, it is critically important that
2562 * any caller checks to make sure that any buffer heads are returned 2588 * any caller checks to make sure that any buffer heads are returned
2563 * by this function are either all already mapped or marked for 2589 * by this function are either all already mapped or marked for
2564 * delayed allocation before calling nobh_writepage() or 2590 * delayed allocation before calling block_write_full_page(). Otherwise,
2565 * block_write_full_page(). Otherwise, b_blocknr could be left 2591 * b_blocknr could be left unitialized, and the page write functions will
2566 * unitialized, and the page write functions will be taken by 2592 * be taken by surprise.
2567 * surprise.
2568 */ 2593 */
2569static int noalloc_get_block_write(struct inode *inode, sector_t iblock, 2594static int noalloc_get_block_write(struct inode *inode, sector_t iblock,
2570 struct buffer_head *bh_result, int create) 2595 struct buffer_head *bh_result, int create)
@@ -2749,9 +2774,7 @@ static int ext4_writepage(struct page *page,
2749 return __ext4_journalled_writepage(page, len); 2774 return __ext4_journalled_writepage(page, len);
2750 } 2775 }
2751 2776
2752 if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode)) 2777 if (page_bufs && buffer_uninit(page_bufs)) {
2753 ret = nobh_writepage(page, noalloc_get_block_write, wbc);
2754 else if (page_bufs && buffer_uninit(page_bufs)) {
2755 ext4_set_bh_endio(page_bufs, inode); 2778 ext4_set_bh_endio(page_bufs, inode);
2756 ret = block_write_full_page_endio(page, noalloc_get_block_write, 2779 ret = block_write_full_page_endio(page, noalloc_get_block_write,
2757 wbc, ext4_end_io_buffer_write); 2780 wbc, ext4_end_io_buffer_write);
@@ -3146,13 +3169,10 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping,
3146 int ret, retries = 0; 3169 int ret, retries = 0;
3147 struct page *page; 3170 struct page *page;
3148 pgoff_t index; 3171 pgoff_t index;
3149 unsigned from, to;
3150 struct inode *inode = mapping->host; 3172 struct inode *inode = mapping->host;
3151 handle_t *handle; 3173 handle_t *handle;
3152 3174
3153 index = pos >> PAGE_CACHE_SHIFT; 3175 index = pos >> PAGE_CACHE_SHIFT;
3154 from = pos & (PAGE_CACHE_SIZE - 1);
3155 to = from + len;
3156 3176
3157 if (ext4_nonda_switch(inode->i_sb)) { 3177 if (ext4_nonda_switch(inode->i_sb)) {
3158 *fsdata = (void *)FALL_BACK_TO_NONDELALLOC; 3178 *fsdata = (void *)FALL_BACK_TO_NONDELALLOC;
@@ -3668,6 +3688,8 @@ static int ext4_end_io_nolock(ext4_io_end_t *io)
3668 return ret; 3688 return ret;
3669 } 3689 }
3670 3690
3691 if (io->iocb)
3692 aio_complete(io->iocb, io->result, 0);
3671 /* clear the DIO AIO unwritten flag */ 3693 /* clear the DIO AIO unwritten flag */
3672 io->flag = 0; 3694 io->flag = 0;
3673 return ret; 3695 return ret;
@@ -3767,6 +3789,8 @@ static ext4_io_end_t *ext4_init_io_end (struct inode *inode, gfp_t flags)
3767 io->offset = 0; 3789 io->offset = 0;
3768 io->size = 0; 3790 io->size = 0;
3769 io->page = NULL; 3791 io->page = NULL;
3792 io->iocb = NULL;
3793 io->result = 0;
3770 INIT_WORK(&io->work, ext4_end_io_work); 3794 INIT_WORK(&io->work, ext4_end_io_work);
3771 INIT_LIST_HEAD(&io->list); 3795 INIT_LIST_HEAD(&io->list);
3772 } 3796 }
@@ -3796,12 +3820,18 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
3796 if (io_end->flag != EXT4_IO_UNWRITTEN){ 3820 if (io_end->flag != EXT4_IO_UNWRITTEN){
3797 ext4_free_io_end(io_end); 3821 ext4_free_io_end(io_end);
3798 iocb->private = NULL; 3822 iocb->private = NULL;
3799 goto out; 3823out:
3824 if (is_async)
3825 aio_complete(iocb, ret, 0);
3826 return;
3800 } 3827 }
3801 3828
3802 io_end->offset = offset; 3829 io_end->offset = offset;
3803 io_end->size = size; 3830 io_end->size = size;
3804 io_end->flag = EXT4_IO_UNWRITTEN; 3831 if (is_async) {
3832 io_end->iocb = iocb;
3833 io_end->result = ret;
3834 }
3805 wq = EXT4_SB(io_end->inode->i_sb)->dio_unwritten_wq; 3835 wq = EXT4_SB(io_end->inode->i_sb)->dio_unwritten_wq;
3806 3836
3807 /* queue the work to convert unwritten extents to written */ 3837 /* queue the work to convert unwritten extents to written */
@@ -3813,9 +3843,6 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
3813 list_add_tail(&io_end->list, &ei->i_completed_io_list); 3843 list_add_tail(&io_end->list, &ei->i_completed_io_list);
3814 spin_unlock_irqrestore(&ei->i_completed_io_lock, flags); 3844 spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
3815 iocb->private = NULL; 3845 iocb->private = NULL;
3816out:
3817 if (is_async)
3818 aio_complete(iocb, ret, 0);
3819} 3846}
3820 3847
3821static void ext4_end_io_buffer_write(struct buffer_head *bh, int uptodate) 3848static void ext4_end_io_buffer_write(struct buffer_head *bh, int uptodate)
@@ -3941,7 +3968,7 @@ static ssize_t ext4_ext_direct_IO(int rw, struct kiocb *iocb,
3941 return -ENOMEM; 3968 return -ENOMEM;
3942 /* 3969 /*
3943 * we save the io structure for current async 3970 * we save the io structure for current async
3944 * direct IO, so that later ext4_get_blocks() 3971 * direct IO, so that later ext4_map_blocks()
3945 * could flag the io structure whether there 3972 * could flag the io structure whether there
3946 * is a unwritten extents needs to be converted 3973 * is a unwritten extents needs to be converted
3947 * when IO is completed. 3974 * when IO is completed.
@@ -4132,17 +4159,6 @@ int ext4_block_truncate_page(handle_t *handle,
4132 length = blocksize - (offset & (blocksize - 1)); 4159 length = blocksize - (offset & (blocksize - 1));
4133 iblock = index << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits); 4160 iblock = index << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits);
4134 4161
4135 /*
4136 * For "nobh" option, we can only work if we don't need to
4137 * read-in the page - otherwise we create buffers to do the IO.
4138 */
4139 if (!page_has_buffers(page) && test_opt(inode->i_sb, NOBH) &&
4140 ext4_should_writeback_data(inode) && PageUptodate(page)) {
4141 zero_user(page, offset, length);
4142 set_page_dirty(page);
4143 goto unlock;
4144 }
4145
4146 if (!page_has_buffers(page)) 4162 if (!page_has_buffers(page))
4147 create_empty_buffers(page, blocksize, 0); 4163 create_empty_buffers(page, blocksize, 0);
4148 4164
@@ -4492,9 +4508,8 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode,
4492 * (should be rare). 4508 * (should be rare).
4493 */ 4509 */
4494 if (!bh) { 4510 if (!bh) {
4495 EXT4_ERROR_INODE(inode, 4511 EXT4_ERROR_INODE_BLOCK(inode, nr,
4496 "Read failure block=%llu", 4512 "Read failure");
4497 (unsigned long long) nr);
4498 continue; 4513 continue;
4499 } 4514 }
4500 4515
@@ -4506,27 +4521,6 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode,
4506 depth); 4521 depth);
4507 4522
4508 /* 4523 /*
4509 * We've probably journalled the indirect block several
4510 * times during the truncate. But it's no longer
4511 * needed and we now drop it from the transaction via
4512 * jbd2_journal_revoke().
4513 *
4514 * That's easy if it's exclusively part of this
4515 * transaction. But if it's part of the committing
4516 * transaction then jbd2_journal_forget() will simply
4517 * brelse() it. That means that if the underlying
4518 * block is reallocated in ext4_get_block(),
4519 * unmap_underlying_metadata() will find this block
4520 * and will try to get rid of it. damn, damn.
4521 *
4522 * If this block has already been committed to the
4523 * journal, a revoke record will be written. And
4524 * revoke records must be emitted *before* clearing
4525 * this block's bit in the bitmaps.
4526 */
4527 ext4_forget(handle, 1, inode, bh, bh->b_blocknr);
4528
4529 /*
4530 * Everything below this this pointer has been 4524 * Everything below this this pointer has been
4531 * released. Now let this top-of-subtree go. 4525 * released. Now let this top-of-subtree go.
4532 * 4526 *
@@ -4550,8 +4544,20 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode,
4550 blocks_for_truncate(inode)); 4544 blocks_for_truncate(inode));
4551 } 4545 }
4552 4546
4547 /*
4548 * The forget flag here is critical because if
4549 * we are journaling (and not doing data
4550 * journaling), we have to make sure a revoke
4551 * record is written to prevent the journal
4552 * replay from overwriting the (former)
4553 * indirect block if it gets reallocated as a
4554 * data block. This must happen in the same
4555 * transaction where the data blocks are
4556 * actually freed.
4557 */
4553 ext4_free_blocks(handle, inode, 0, nr, 1, 4558 ext4_free_blocks(handle, inode, 0, nr, 1,
4554 EXT4_FREE_BLOCKS_METADATA); 4559 EXT4_FREE_BLOCKS_METADATA|
4560 EXT4_FREE_BLOCKS_FORGET);
4555 4561
4556 if (parent_bh) { 4562 if (parent_bh) {
4557 /* 4563 /*
@@ -4809,8 +4815,8 @@ static int __ext4_get_inode_loc(struct inode *inode,
4809 4815
4810 bh = sb_getblk(sb, block); 4816 bh = sb_getblk(sb, block);
4811 if (!bh) { 4817 if (!bh) {
4812 EXT4_ERROR_INODE(inode, "unable to read inode block - " 4818 EXT4_ERROR_INODE_BLOCK(inode, block,
4813 "block %llu", block); 4819 "unable to read itable block");
4814 return -EIO; 4820 return -EIO;
4815 } 4821 }
4816 if (!buffer_uptodate(bh)) { 4822 if (!buffer_uptodate(bh)) {
@@ -4908,8 +4914,8 @@ make_io:
4908 submit_bh(READ_META, bh); 4914 submit_bh(READ_META, bh);
4909 wait_on_buffer(bh); 4915 wait_on_buffer(bh);
4910 if (!buffer_uptodate(bh)) { 4916 if (!buffer_uptodate(bh)) {
4911 EXT4_ERROR_INODE(inode, "unable to read inode " 4917 EXT4_ERROR_INODE_BLOCK(inode, block,
4912 "block %llu", block); 4918 "unable to read itable block");
4913 brelse(bh); 4919 brelse(bh);
4914 return -EIO; 4920 return -EIO;
4915 } 4921 }
@@ -4980,7 +4986,7 @@ static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,
4980 /* we are using combined 48 bit field */ 4986 /* we are using combined 48 bit field */
4981 i_blocks = ((u64)le16_to_cpu(raw_inode->i_blocks_high)) << 32 | 4987 i_blocks = ((u64)le16_to_cpu(raw_inode->i_blocks_high)) << 32 |
4982 le32_to_cpu(raw_inode->i_blocks_lo); 4988 le32_to_cpu(raw_inode->i_blocks_lo);
4983 if (ei->i_flags & EXT4_HUGE_FILE_FL) { 4989 if (ext4_test_inode_flag(inode, EXT4_INODE_HUGE_FILE)) {
4984 /* i_blocks represent file system block size */ 4990 /* i_blocks represent file system block size */
4985 return i_blocks << (inode->i_blkbits - 9); 4991 return i_blocks << (inode->i_blkbits - 9);
4986 } else { 4992 } else {
@@ -5076,7 +5082,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
5076 transaction_t *transaction; 5082 transaction_t *transaction;
5077 tid_t tid; 5083 tid_t tid;
5078 5084
5079 spin_lock(&journal->j_state_lock); 5085 read_lock(&journal->j_state_lock);
5080 if (journal->j_running_transaction) 5086 if (journal->j_running_transaction)
5081 transaction = journal->j_running_transaction; 5087 transaction = journal->j_running_transaction;
5082 else 5088 else
@@ -5085,7 +5091,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
5085 tid = transaction->t_tid; 5091 tid = transaction->t_tid;
5086 else 5092 else
5087 tid = journal->j_commit_sequence; 5093 tid = journal->j_commit_sequence;
5088 spin_unlock(&journal->j_state_lock); 5094 read_unlock(&journal->j_state_lock);
5089 ei->i_sync_tid = tid; 5095 ei->i_sync_tid = tid;
5090 ei->i_datasync_tid = tid; 5096 ei->i_datasync_tid = tid;
5091 } 5097 }
@@ -5130,7 +5136,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
5130 ei->i_file_acl); 5136 ei->i_file_acl);
5131 ret = -EIO; 5137 ret = -EIO;
5132 goto bad_inode; 5138 goto bad_inode;
5133 } else if (ei->i_flags & EXT4_EXTENTS_FL) { 5139 } else if (ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS)) {
5134 if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) || 5140 if (S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
5135 (S_ISLNK(inode->i_mode) && 5141 (S_ISLNK(inode->i_mode) &&
5136 !ext4_inode_is_fast_symlink(inode))) 5142 !ext4_inode_is_fast_symlink(inode)))
@@ -5410,9 +5416,8 @@ int ext4_write_inode(struct inode *inode, struct writeback_control *wbc)
5410 if (wbc->sync_mode == WB_SYNC_ALL) 5416 if (wbc->sync_mode == WB_SYNC_ALL)
5411 sync_dirty_buffer(iloc.bh); 5417 sync_dirty_buffer(iloc.bh);
5412 if (buffer_req(iloc.bh) && !buffer_uptodate(iloc.bh)) { 5418 if (buffer_req(iloc.bh) && !buffer_uptodate(iloc.bh)) {
5413 EXT4_ERROR_INODE(inode, 5419 EXT4_ERROR_INODE_BLOCK(inode, iloc.bh->b_blocknr,
5414 "IO error syncing inode (block=%llu)", 5420 "IO error syncing inode");
5415 (unsigned long long) iloc.bh->b_blocknr);
5416 err = -EIO; 5421 err = -EIO;
5417 } 5422 }
5418 brelse(iloc.bh); 5423 brelse(iloc.bh);
@@ -5487,10 +5492,8 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)
5487 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) { 5492 if (!(ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS))) {
5488 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb); 5493 struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
5489 5494
5490 if (attr->ia_size > sbi->s_bitmap_maxbytes) { 5495 if (attr->ia_size > sbi->s_bitmap_maxbytes)
5491 error = -EFBIG; 5496 return -EFBIG;
5492 goto err_out;
5493 }
5494 } 5497 }
5495 } 5498 }
5496 5499
@@ -5692,7 +5695,7 @@ int ext4_writepage_trans_blocks(struct inode *inode)
5692 * Calculate the journal credits for a chunk of data modification. 5695 * Calculate the journal credits for a chunk of data modification.
5693 * 5696 *
5694 * This is called from DIO, fallocate or whoever calling 5697 * This is called from DIO, fallocate or whoever calling
5695 * ext4_get_blocks() to map/allocate a chunk of contiguous disk blocks. 5698 * ext4_map_blocks() to map/allocate a chunk of contiguous disk blocks.
5696 * 5699 *
5697 * journal buffers for data blocks are not included here, as DIO 5700 * journal buffers for data blocks are not included here, as DIO
5698 * and fallocate do no need to journal data buffers. 5701 * and fallocate do no need to journal data buffers.
@@ -5758,7 +5761,6 @@ static int ext4_expand_extra_isize(struct inode *inode,
5758{ 5761{
5759 struct ext4_inode *raw_inode; 5762 struct ext4_inode *raw_inode;
5760 struct ext4_xattr_ibody_header *header; 5763 struct ext4_xattr_ibody_header *header;
5761 struct ext4_xattr_entry *entry;
5762 5764
5763 if (EXT4_I(inode)->i_extra_isize >= new_extra_isize) 5765 if (EXT4_I(inode)->i_extra_isize >= new_extra_isize)
5764 return 0; 5766 return 0;
@@ -5766,7 +5768,6 @@ static int ext4_expand_extra_isize(struct inode *inode,
5766 raw_inode = ext4_raw_inode(&iloc); 5768 raw_inode = ext4_raw_inode(&iloc);
5767 5769
5768 header = IHDR(inode, raw_inode); 5770 header = IHDR(inode, raw_inode);
5769 entry = IFIRST(header);
5770 5771
5771 /* No extended attributes present */ 5772 /* No extended attributes present */
5772 if (!ext4_test_inode_state(inode, EXT4_STATE_XATTR) || 5773 if (!ext4_test_inode_state(inode, EXT4_STATE_XATTR) ||
diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
index 0e83dfd351d5..4b4ad4b7ce57 100644
--- a/fs/ext4/mballoc.c
+++ b/fs/ext4/mballoc.c
@@ -446,10 +446,11 @@ static void mb_free_blocks_double(struct inode *inode, struct ext4_buddy *e4b,
446 blocknr = ext4_group_first_block_no(sb, e4b->bd_group); 446 blocknr = ext4_group_first_block_no(sb, e4b->bd_group);
447 blocknr += first + i; 447 blocknr += first + i;
448 ext4_grp_locked_error(sb, e4b->bd_group, 448 ext4_grp_locked_error(sb, e4b->bd_group,
449 __func__, "double-free of inode" 449 inode ? inode->i_ino : 0,
450 " %lu's block %llu(bit %u in group %u)", 450 blocknr,
451 inode ? inode->i_ino : 0, blocknr, 451 "freeing block already freed "
452 first + i, e4b->bd_group); 452 "(bit %u)",
453 first + i);
453 } 454 }
454 mb_clear_bit(first + i, e4b->bd_info->bb_bitmap); 455 mb_clear_bit(first + i, e4b->bd_info->bb_bitmap);
455 } 456 }
@@ -712,9 +713,9 @@ void ext4_mb_generate_buddy(struct super_block *sb,
712 grp->bb_fragments = fragments; 713 grp->bb_fragments = fragments;
713 714
714 if (free != grp->bb_free) { 715 if (free != grp->bb_free) {
715 ext4_grp_locked_error(sb, group, __func__, 716 ext4_grp_locked_error(sb, group, 0, 0,
716 "EXT4-fs: group %u: %u blocks in bitmap, %u in gd", 717 "%u blocks in bitmap, %u in gd",
717 group, free, grp->bb_free); 718 free, grp->bb_free);
718 /* 719 /*
719 * If we intent to continue, we consider group descritor 720 * If we intent to continue, we consider group descritor
720 * corrupt and update bb_free using bitmap value 721 * corrupt and update bb_free using bitmap value
@@ -1296,10 +1297,10 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b,
1296 blocknr = ext4_group_first_block_no(sb, e4b->bd_group); 1297 blocknr = ext4_group_first_block_no(sb, e4b->bd_group);
1297 blocknr += block; 1298 blocknr += block;
1298 ext4_grp_locked_error(sb, e4b->bd_group, 1299 ext4_grp_locked_error(sb, e4b->bd_group,
1299 __func__, "double-free of inode" 1300 inode ? inode->i_ino : 0,
1300 " %lu's block %llu(bit %u in group %u)", 1301 blocknr,
1301 inode ? inode->i_ino : 0, blocknr, block, 1302 "freeing already freed block "
1302 e4b->bd_group); 1303 "(bit %u)", block);
1303 } 1304 }
1304 mb_clear_bit(block, EXT4_MB_BITMAP(e4b)); 1305 mb_clear_bit(block, EXT4_MB_BITMAP(e4b));
1305 e4b->bd_info->bb_counters[order]++; 1306 e4b->bd_info->bb_counters[order]++;
@@ -1788,8 +1789,8 @@ void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac,
1788 * free blocks even though group info says we 1789 * free blocks even though group info says we
1789 * we have free blocks 1790 * we have free blocks
1790 */ 1791 */
1791 ext4_grp_locked_error(sb, e4b->bd_group, 1792 ext4_grp_locked_error(sb, e4b->bd_group, 0, 0,
1792 __func__, "%d free blocks as per " 1793 "%d free blocks as per "
1793 "group info. But bitmap says 0", 1794 "group info. But bitmap says 0",
1794 free); 1795 free);
1795 break; 1796 break;
@@ -1798,8 +1799,8 @@ void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac,
1798 mb_find_extent(e4b, 0, i, ac->ac_g_ex.fe_len, &ex); 1799 mb_find_extent(e4b, 0, i, ac->ac_g_ex.fe_len, &ex);
1799 BUG_ON(ex.fe_len <= 0); 1800 BUG_ON(ex.fe_len <= 0);
1800 if (free < ex.fe_len) { 1801 if (free < ex.fe_len) {
1801 ext4_grp_locked_error(sb, e4b->bd_group, 1802 ext4_grp_locked_error(sb, e4b->bd_group, 0, 0,
1802 __func__, "%d free blocks as per " 1803 "%d free blocks as per "
1803 "group info. But got %d blocks", 1804 "group info. But got %d blocks",
1804 free, ex.fe_len); 1805 free, ex.fe_len);
1805 /* 1806 /*
@@ -1821,8 +1822,7 @@ void ext4_mb_complex_scan_group(struct ext4_allocation_context *ac,
1821 1822
1822/* 1823/*
1823 * This is a special case for storages like raid5 1824 * This is a special case for storages like raid5
1824 * we try to find stripe-aligned chunks for stripe-size requests 1825 * we try to find stripe-aligned chunks for stripe-size-multiple requests
1825 * XXX should do so at least for multiples of stripe size as well
1826 */ 1826 */
1827static noinline_for_stack 1827static noinline_for_stack
1828void ext4_mb_scan_aligned(struct ext4_allocation_context *ac, 1828void ext4_mb_scan_aligned(struct ext4_allocation_context *ac,
@@ -1999,7 +1999,6 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
1999 ext4_group_t ngroups, group, i; 1999 ext4_group_t ngroups, group, i;
2000 int cr; 2000 int cr;
2001 int err = 0; 2001 int err = 0;
2002 int bsbits;
2003 struct ext4_sb_info *sbi; 2002 struct ext4_sb_info *sbi;
2004 struct super_block *sb; 2003 struct super_block *sb;
2005 struct ext4_buddy e4b; 2004 struct ext4_buddy e4b;
@@ -2041,8 +2040,6 @@ ext4_mb_regular_allocator(struct ext4_allocation_context *ac)
2041 ac->ac_2order = i - 1; 2040 ac->ac_2order = i - 1;
2042 } 2041 }
2043 2042
2044 bsbits = ac->ac_sb->s_blocksize_bits;
2045
2046 /* if stream allocation is enabled, use global goal */ 2043 /* if stream allocation is enabled, use global goal */
2047 if (ac->ac_flags & EXT4_MB_STREAM_ALLOC) { 2044 if (ac->ac_flags & EXT4_MB_STREAM_ALLOC) {
2048 /* TBD: may be hot point */ 2045 /* TBD: may be hot point */
@@ -2094,8 +2091,8 @@ repeat:
2094 ac->ac_groups_scanned++; 2091 ac->ac_groups_scanned++;
2095 if (cr == 0) 2092 if (cr == 0)
2096 ext4_mb_simple_scan_group(ac, &e4b); 2093 ext4_mb_simple_scan_group(ac, &e4b);
2097 else if (cr == 1 && 2094 else if (cr == 1 && sbi->s_stripe &&
2098 ac->ac_g_ex.fe_len == sbi->s_stripe) 2095 !(ac->ac_g_ex.fe_len % sbi->s_stripe))
2099 ext4_mb_scan_aligned(ac, &e4b); 2096 ext4_mb_scan_aligned(ac, &e4b);
2100 else 2097 else
2101 ext4_mb_complex_scan_group(ac, &e4b); 2098 ext4_mb_complex_scan_group(ac, &e4b);
@@ -2221,7 +2218,7 @@ static int ext4_mb_seq_groups_open(struct inode *inode, struct file *file)
2221 2218
2222 rc = seq_open(file, &ext4_mb_seq_groups_ops); 2219 rc = seq_open(file, &ext4_mb_seq_groups_ops);
2223 if (rc == 0) { 2220 if (rc == 0) {
2224 struct seq_file *m = (struct seq_file *)file->private_data; 2221 struct seq_file *m = file->private_data;
2225 m->private = sb; 2222 m->private = sb;
2226 } 2223 }
2227 return rc; 2224 return rc;
@@ -2560,6 +2557,22 @@ int ext4_mb_release(struct super_block *sb)
2560 return 0; 2557 return 0;
2561} 2558}
2562 2559
2560static inline void ext4_issue_discard(struct super_block *sb,
2561 ext4_group_t block_group, ext4_grpblk_t block, int count)
2562{
2563 int ret;
2564 ext4_fsblk_t discard_block;
2565
2566 discard_block = block + ext4_group_first_block_no(sb, block_group);
2567 trace_ext4_discard_blocks(sb,
2568 (unsigned long long) discard_block, count);
2569 ret = sb_issue_discard(sb, discard_block, count);
2570 if (ret == EOPNOTSUPP) {
2571 ext4_warning(sb, "discard not supported, disabling");
2572 clear_opt(EXT4_SB(sb)->s_mount_opt, DISCARD);
2573 }
2574}
2575
2563/* 2576/*
2564 * This function is called by the jbd2 layer once the commit has finished, 2577 * This function is called by the jbd2 layer once the commit has finished,
2565 * so we know we can free the blocks that were released with that commit. 2578 * so we know we can free the blocks that were released with that commit.
@@ -2579,22 +2592,9 @@ static void release_blocks_on_commit(journal_t *journal, transaction_t *txn)
2579 mb_debug(1, "gonna free %u blocks in group %u (0x%p):", 2592 mb_debug(1, "gonna free %u blocks in group %u (0x%p):",
2580 entry->count, entry->group, entry); 2593 entry->count, entry->group, entry);
2581 2594
2582 if (test_opt(sb, DISCARD)) { 2595 if (test_opt(sb, DISCARD))
2583 int ret; 2596 ext4_issue_discard(sb, entry->group,
2584 ext4_fsblk_t discard_block; 2597 entry->start_blk, entry->count);
2585
2586 discard_block = entry->start_blk +
2587 ext4_group_first_block_no(sb, entry->group);
2588 trace_ext4_discard_blocks(sb,
2589 (unsigned long long)discard_block,
2590 entry->count);
2591 ret = sb_issue_discard(sb, discard_block, entry->count);
2592 if (ret == EOPNOTSUPP) {
2593 ext4_warning(sb,
2594 "discard not supported, disabling");
2595 clear_opt(EXT4_SB(sb)->s_mount_opt, DISCARD);
2596 }
2597 }
2598 2598
2599 err = ext4_mb_load_buddy(sb, entry->group, &e4b); 2599 err = ext4_mb_load_buddy(sb, entry->group, &e4b);
2600 /* we expect to find existing buddy because it's pinned */ 2600 /* we expect to find existing buddy because it's pinned */
@@ -2712,7 +2712,6 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
2712 handle_t *handle, unsigned int reserv_blks) 2712 handle_t *handle, unsigned int reserv_blks)
2713{ 2713{
2714 struct buffer_head *bitmap_bh = NULL; 2714 struct buffer_head *bitmap_bh = NULL;
2715 struct ext4_super_block *es;
2716 struct ext4_group_desc *gdp; 2715 struct ext4_group_desc *gdp;
2717 struct buffer_head *gdp_bh; 2716 struct buffer_head *gdp_bh;
2718 struct ext4_sb_info *sbi; 2717 struct ext4_sb_info *sbi;
@@ -2725,8 +2724,6 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
2725 2724
2726 sb = ac->ac_sb; 2725 sb = ac->ac_sb;
2727 sbi = EXT4_SB(sb); 2726 sbi = EXT4_SB(sb);
2728 es = sbi->s_es;
2729
2730 2727
2731 err = -EIO; 2728 err = -EIO;
2732 bitmap_bh = ext4_read_block_bitmap(sb, ac->ac_b_ex.fe_group); 2729 bitmap_bh = ext4_read_block_bitmap(sb, ac->ac_b_ex.fe_group);
@@ -2812,7 +2809,7 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac,
2812 err = ext4_handle_dirty_metadata(handle, NULL, gdp_bh); 2809 err = ext4_handle_dirty_metadata(handle, NULL, gdp_bh);
2813 2810
2814out_err: 2811out_err:
2815 sb->s_dirt = 1; 2812 ext4_mark_super_dirty(sb);
2816 brelse(bitmap_bh); 2813 brelse(bitmap_bh);
2817 return err; 2814 return err;
2818} 2815}
@@ -2850,7 +2847,7 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
2850 int bsbits, max; 2847 int bsbits, max;
2851 ext4_lblk_t end; 2848 ext4_lblk_t end;
2852 loff_t size, orig_size, start_off; 2849 loff_t size, orig_size, start_off;
2853 ext4_lblk_t start, orig_start; 2850 ext4_lblk_t start;
2854 struct ext4_inode_info *ei = EXT4_I(ac->ac_inode); 2851 struct ext4_inode_info *ei = EXT4_I(ac->ac_inode);
2855 struct ext4_prealloc_space *pa; 2852 struct ext4_prealloc_space *pa;
2856 2853
@@ -2881,6 +2878,7 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
2881 size = size << bsbits; 2878 size = size << bsbits;
2882 if (size < i_size_read(ac->ac_inode)) 2879 if (size < i_size_read(ac->ac_inode))
2883 size = i_size_read(ac->ac_inode); 2880 size = i_size_read(ac->ac_inode);
2881 orig_size = size;
2884 2882
2885 /* max size of free chunks */ 2883 /* max size of free chunks */
2886 max = 2 << bsbits; 2884 max = 2 << bsbits;
@@ -2922,8 +2920,8 @@ ext4_mb_normalize_request(struct ext4_allocation_context *ac,
2922 start_off = (loff_t)ac->ac_o_ex.fe_logical << bsbits; 2920 start_off = (loff_t)ac->ac_o_ex.fe_logical << bsbits;
2923 size = ac->ac_o_ex.fe_len << bsbits; 2921 size = ac->ac_o_ex.fe_len << bsbits;
2924 } 2922 }
2925 orig_size = size = size >> bsbits; 2923 size = size >> bsbits;
2926 orig_start = start = start_off >> bsbits; 2924 start = start_off >> bsbits;
2927 2925
2928 /* don't cover already allocated blocks in selected range */ 2926 /* don't cover already allocated blocks in selected range */
2929 if (ar->pleft && start <= ar->lleft) { 2927 if (ar->pleft && start <= ar->lleft) {
@@ -3547,7 +3545,6 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
3547 ext4_group_t group; 3545 ext4_group_t group;
3548 ext4_grpblk_t bit; 3546 ext4_grpblk_t bit;
3549 unsigned long long grp_blk_start; 3547 unsigned long long grp_blk_start;
3550 sector_t start;
3551 int err = 0; 3548 int err = 0;
3552 int free = 0; 3549 int free = 0;
3553 3550
@@ -3567,10 +3564,9 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
3567 if (bit >= end) 3564 if (bit >= end)
3568 break; 3565 break;
3569 next = mb_find_next_bit(bitmap_bh->b_data, end, bit); 3566 next = mb_find_next_bit(bitmap_bh->b_data, end, bit);
3570 start = ext4_group_first_block_no(sb, group) + bit;
3571 mb_debug(1, " free preallocated %u/%u in group %u\n", 3567 mb_debug(1, " free preallocated %u/%u in group %u\n",
3572 (unsigned) start, (unsigned) next - bit, 3568 (unsigned) ext4_group_first_block_no(sb, group) + bit,
3573 (unsigned) group); 3569 (unsigned) next - bit, (unsigned) group);
3574 free += next - bit; 3570 free += next - bit;
3575 3571
3576 if (ac) { 3572 if (ac) {
@@ -3581,7 +3577,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
3581 trace_ext4_mballoc_discard(ac); 3577 trace_ext4_mballoc_discard(ac);
3582 } 3578 }
3583 3579
3584 trace_ext4_mb_release_inode_pa(ac, pa, grp_blk_start + bit, 3580 trace_ext4_mb_release_inode_pa(sb, ac, pa, grp_blk_start + bit,
3585 next - bit); 3581 next - bit);
3586 mb_free_blocks(pa->pa_inode, e4b, bit, next - bit); 3582 mb_free_blocks(pa->pa_inode, e4b, bit, next - bit);
3587 bit = next + 1; 3583 bit = next + 1;
@@ -3591,8 +3587,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
3591 pa, (unsigned long) pa->pa_lstart, 3587 pa, (unsigned long) pa->pa_lstart,
3592 (unsigned long) pa->pa_pstart, 3588 (unsigned long) pa->pa_pstart,
3593 (unsigned long) pa->pa_len); 3589 (unsigned long) pa->pa_len);
3594 ext4_grp_locked_error(sb, group, 3590 ext4_grp_locked_error(sb, group, 0, 0, "free %u, pa_free %u",
3595 __func__, "free %u, pa_free %u",
3596 free, pa->pa_free); 3591 free, pa->pa_free);
3597 /* 3592 /*
3598 * pa is already deleted so we use the value obtained 3593 * pa is already deleted so we use the value obtained
@@ -3613,7 +3608,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
3613 ext4_group_t group; 3608 ext4_group_t group;
3614 ext4_grpblk_t bit; 3609 ext4_grpblk_t bit;
3615 3610
3616 trace_ext4_mb_release_group_pa(ac, pa); 3611 trace_ext4_mb_release_group_pa(sb, ac, pa);
3617 BUG_ON(pa->pa_deleted == 0); 3612 BUG_ON(pa->pa_deleted == 0);
3618 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit); 3613 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
3619 BUG_ON(group != e4b->bd_group && pa->pa_len != 0); 3614 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
@@ -3889,6 +3884,9 @@ static void ext4_mb_show_ac(struct ext4_allocation_context *ac)
3889 struct super_block *sb = ac->ac_sb; 3884 struct super_block *sb = ac->ac_sb;
3890 ext4_group_t ngroups, i; 3885 ext4_group_t ngroups, i;
3891 3886
3887 if (EXT4_SB(sb)->s_mount_flags & EXT4_MF_FS_ABORTED)
3888 return;
3889
3892 printk(KERN_ERR "EXT4-fs: Can't allocate:" 3890 printk(KERN_ERR "EXT4-fs: Can't allocate:"
3893 " Allocation context details:\n"); 3891 " Allocation context details:\n");
3894 printk(KERN_ERR "EXT4-fs: status %d flags %d\n", 3892 printk(KERN_ERR "EXT4-fs: status %d flags %d\n",
@@ -4255,7 +4253,7 @@ static int ext4_mb_discard_preallocations(struct super_block *sb, int needed)
4255 * to usual allocation 4253 * to usual allocation
4256 */ 4254 */
4257ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle, 4255ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
4258 struct ext4_allocation_request *ar, int *errp) 4256 struct ext4_allocation_request *ar, int *errp)
4259{ 4257{
4260 int freed; 4258 int freed;
4261 struct ext4_allocation_context *ac = NULL; 4259 struct ext4_allocation_context *ac = NULL;
@@ -4299,7 +4297,7 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
4299 inquota = ar->len; 4297 inquota = ar->len;
4300 if (ar->len == 0) { 4298 if (ar->len == 0) {
4301 *errp = -EDQUOT; 4299 *errp = -EDQUOT;
4302 goto out3; 4300 goto out;
4303 } 4301 }
4304 } 4302 }
4305 4303
@@ -4307,13 +4305,13 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
4307 if (!ac) { 4305 if (!ac) {
4308 ar->len = 0; 4306 ar->len = 0;
4309 *errp = -ENOMEM; 4307 *errp = -ENOMEM;
4310 goto out1; 4308 goto out;
4311 } 4309 }
4312 4310
4313 *errp = ext4_mb_initialize_context(ac, ar); 4311 *errp = ext4_mb_initialize_context(ac, ar);
4314 if (*errp) { 4312 if (*errp) {
4315 ar->len = 0; 4313 ar->len = 0;
4316 goto out2; 4314 goto out;
4317 } 4315 }
4318 4316
4319 ac->ac_op = EXT4_MB_HISTORY_PREALLOC; 4317 ac->ac_op = EXT4_MB_HISTORY_PREALLOC;
@@ -4322,7 +4320,9 @@ ext4_fsblk_t ext4_mb_new_blocks(handle_t *handle,
4322 ext4_mb_normalize_request(ac, ar); 4320 ext4_mb_normalize_request(ac, ar);
4323repeat: 4321repeat:
4324 /* allocate space in core */ 4322 /* allocate space in core */
4325 ext4_mb_regular_allocator(ac); 4323 *errp = ext4_mb_regular_allocator(ac);
4324 if (*errp)
4325 goto errout;
4326 4326
4327 /* as we've just preallocated more space than 4327 /* as we've just preallocated more space than
4328 * user requested orinally, we store allocated 4328 * user requested orinally, we store allocated
@@ -4333,7 +4333,7 @@ repeat:
4333 } 4333 }
4334 if (likely(ac->ac_status == AC_STATUS_FOUND)) { 4334 if (likely(ac->ac_status == AC_STATUS_FOUND)) {
4335 *errp = ext4_mb_mark_diskspace_used(ac, handle, reserv_blks); 4335 *errp = ext4_mb_mark_diskspace_used(ac, handle, reserv_blks);
4336 if (*errp == -EAGAIN) { 4336 if (*errp == -EAGAIN) {
4337 /* 4337 /*
4338 * drop the reference that we took 4338 * drop the reference that we took
4339 * in ext4_mb_use_best_found 4339 * in ext4_mb_use_best_found
@@ -4344,12 +4344,10 @@ repeat:
4344 ac->ac_b_ex.fe_len = 0; 4344 ac->ac_b_ex.fe_len = 0;
4345 ac->ac_status = AC_STATUS_CONTINUE; 4345 ac->ac_status = AC_STATUS_CONTINUE;
4346 goto repeat; 4346 goto repeat;
4347 } else if (*errp) { 4347 } else if (*errp)
4348 errout:
4348 ext4_discard_allocated_blocks(ac); 4349 ext4_discard_allocated_blocks(ac);
4349 ac->ac_b_ex.fe_len = 0; 4350 else {
4350 ar->len = 0;
4351 ext4_mb_show_ac(ac);
4352 } else {
4353 block = ext4_grp_offs_to_block(sb, &ac->ac_b_ex); 4351 block = ext4_grp_offs_to_block(sb, &ac->ac_b_ex);
4354 ar->len = ac->ac_b_ex.fe_len; 4352 ar->len = ac->ac_b_ex.fe_len;
4355 } 4353 }
@@ -4358,19 +4356,19 @@ repeat:
4358 if (freed) 4356 if (freed)
4359 goto repeat; 4357 goto repeat;
4360 *errp = -ENOSPC; 4358 *errp = -ENOSPC;
4359 }
4360
4361 if (*errp) {
4361 ac->ac_b_ex.fe_len = 0; 4362 ac->ac_b_ex.fe_len = 0;
4362 ar->len = 0; 4363 ar->len = 0;
4363 ext4_mb_show_ac(ac); 4364 ext4_mb_show_ac(ac);
4364 } 4365 }
4365
4366 ext4_mb_release_context(ac); 4366 ext4_mb_release_context(ac);
4367 4367out:
4368out2: 4368 if (ac)
4369 kmem_cache_free(ext4_ac_cachep, ac); 4369 kmem_cache_free(ext4_ac_cachep, ac);
4370out1:
4371 if (inquota && ar->len < inquota) 4370 if (inquota && ar->len < inquota)
4372 dquot_free_block(ar->inode, inquota - ar->len); 4371 dquot_free_block(ar->inode, inquota - ar->len);
4373out3:
4374 if (!ar->len) { 4372 if (!ar->len) {
4375 if (!EXT4_I(ar->inode)->i_delalloc_reserved_flag) 4373 if (!EXT4_I(ar->inode)->i_delalloc_reserved_flag)
4376 /* release all the reserved blocks if non delalloc */ 4374 /* release all the reserved blocks if non delalloc */
@@ -4402,6 +4400,7 @@ static noinline_for_stack int
4402ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b, 4400ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b,
4403 struct ext4_free_data *new_entry) 4401 struct ext4_free_data *new_entry)
4404{ 4402{
4403 ext4_group_t group = e4b->bd_group;
4405 ext4_grpblk_t block; 4404 ext4_grpblk_t block;
4406 struct ext4_free_data *entry; 4405 struct ext4_free_data *entry;
4407 struct ext4_group_info *db = e4b->bd_info; 4406 struct ext4_group_info *db = e4b->bd_info;
@@ -4434,9 +4433,9 @@ ext4_mb_free_metadata(handle_t *handle, struct ext4_buddy *e4b,
4434 else if (block >= (entry->start_blk + entry->count)) 4433 else if (block >= (entry->start_blk + entry->count))
4435 n = &(*n)->rb_right; 4434 n = &(*n)->rb_right;
4436 else { 4435 else {
4437 ext4_grp_locked_error(sb, e4b->bd_group, __func__, 4436 ext4_grp_locked_error(sb, group, 0,
4438 "Double free of blocks %d (%d %d)", 4437 ext4_group_first_block_no(sb, group) + block,
4439 block, entry->start_blk, entry->count); 4438 "Block already on to-be-freed list");
4440 return 0; 4439 return 0;
4441 } 4440 }
4442 } 4441 }
@@ -4494,7 +4493,6 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
4494 struct super_block *sb = inode->i_sb; 4493 struct super_block *sb = inode->i_sb;
4495 struct ext4_allocation_context *ac = NULL; 4494 struct ext4_allocation_context *ac = NULL;
4496 struct ext4_group_desc *gdp; 4495 struct ext4_group_desc *gdp;
4497 struct ext4_super_block *es;
4498 unsigned long freed = 0; 4496 unsigned long freed = 0;
4499 unsigned int overflow; 4497 unsigned int overflow;
4500 ext4_grpblk_t bit; 4498 ext4_grpblk_t bit;
@@ -4513,7 +4511,6 @@ void ext4_free_blocks(handle_t *handle, struct inode *inode,
4513 } 4511 }
4514 4512
4515 sbi = EXT4_SB(sb); 4513 sbi = EXT4_SB(sb);
4516 es = EXT4_SB(sb)->s_es;
4517 if (!(flags & EXT4_FREE_BLOCKS_VALIDATED) && 4514 if (!(flags & EXT4_FREE_BLOCKS_VALIDATED) &&
4518 !ext4_data_block_valid(sbi, block, count)) { 4515 !ext4_data_block_valid(sbi, block, count)) {
4519 ext4_error(sb, "Freeing blocks not in datazone - " 4516 ext4_error(sb, "Freeing blocks not in datazone - "
@@ -4647,6 +4644,8 @@ do_more:
4647 mb_clear_bits(bitmap_bh->b_data, bit, count); 4644 mb_clear_bits(bitmap_bh->b_data, bit, count);
4648 mb_free_blocks(inode, &e4b, bit, count); 4645 mb_free_blocks(inode, &e4b, bit, count);
4649 ext4_mb_return_to_preallocation(inode, &e4b, block, count); 4646 ext4_mb_return_to_preallocation(inode, &e4b, block, count);
4647 if (test_opt(sb, DISCARD))
4648 ext4_issue_discard(sb, block_group, bit, count);
4650 } 4649 }
4651 4650
4652 ret = ext4_free_blks_count(sb, gdp) + count; 4651 ret = ext4_free_blks_count(sb, gdp) + count;
@@ -4680,7 +4679,7 @@ do_more:
4680 put_bh(bitmap_bh); 4679 put_bh(bitmap_bh);
4681 goto do_more; 4680 goto do_more;
4682 } 4681 }
4683 sb->s_dirt = 1; 4682 ext4_mark_super_dirty(sb);
4684error_return: 4683error_return:
4685 if (freed) 4684 if (freed)
4686 dquot_free_block(inode, freed); 4685 dquot_free_block(inode, freed);
diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c
index 6f3a27ec30bf..1765c2c50a9b 100644
--- a/fs/ext4/migrate.c
+++ b/fs/ext4/migrate.c
@@ -376,7 +376,7 @@ static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode,
376 * We have the extent map build with the tmp inode. 376 * We have the extent map build with the tmp inode.
377 * Now copy the i_data across 377 * Now copy the i_data across
378 */ 378 */
379 ei->i_flags |= EXT4_EXTENTS_FL; 379 ext4_test_inode_flag(inode, EXT4_INODE_EXTENTS);
380 memcpy(ei->i_data, tmp_ei->i_data, sizeof(ei->i_data)); 380 memcpy(ei->i_data, tmp_ei->i_data, sizeof(ei->i_data));
381 381
382 /* 382 /*
diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c
index 52abfa12762a..5f1ed9fc913c 100644
--- a/fs/ext4/move_extent.c
+++ b/fs/ext4/move_extent.c
@@ -148,17 +148,17 @@ mext_next_extent(struct inode *inode, struct ext4_ext_path *path,
148 */ 148 */
149static int 149static int
150mext_check_null_inode(struct inode *inode1, struct inode *inode2, 150mext_check_null_inode(struct inode *inode1, struct inode *inode2,
151 const char *function) 151 const char *function, unsigned int line)
152{ 152{
153 int ret = 0; 153 int ret = 0;
154 154
155 if (inode1 == NULL) { 155 if (inode1 == NULL) {
156 __ext4_error(inode2->i_sb, function, 156 __ext4_error(inode2->i_sb, function, line,
157 "Both inodes should not be NULL: " 157 "Both inodes should not be NULL: "
158 "inode1 NULL inode2 %lu", inode2->i_ino); 158 "inode1 NULL inode2 %lu", inode2->i_ino);
159 ret = -EIO; 159 ret = -EIO;
160 } else if (inode2 == NULL) { 160 } else if (inode2 == NULL) {
161 __ext4_error(inode1->i_sb, function, 161 __ext4_error(inode1->i_sb, function, line,
162 "Both inodes should not be NULL: " 162 "Both inodes should not be NULL: "
163 "inode1 %lu inode2 NULL", inode1->i_ino); 163 "inode1 %lu inode2 NULL", inode1->i_ino);
164 ret = -EIO; 164 ret = -EIO;
@@ -1084,7 +1084,7 @@ mext_inode_double_lock(struct inode *inode1, struct inode *inode2)
1084 1084
1085 BUG_ON(inode1 == NULL && inode2 == NULL); 1085 BUG_ON(inode1 == NULL && inode2 == NULL);
1086 1086
1087 ret = mext_check_null_inode(inode1, inode2, __func__); 1087 ret = mext_check_null_inode(inode1, inode2, __func__, __LINE__);
1088 if (ret < 0) 1088 if (ret < 0)
1089 goto out; 1089 goto out;
1090 1090
@@ -1121,7 +1121,7 @@ mext_inode_double_unlock(struct inode *inode1, struct inode *inode2)
1121 1121
1122 BUG_ON(inode1 == NULL && inode2 == NULL); 1122 BUG_ON(inode1 == NULL && inode2 == NULL);
1123 1123
1124 ret = mext_check_null_inode(inode1, inode2, __func__); 1124 ret = mext_check_null_inode(inode1, inode2, __func__, __LINE__);
1125 if (ret < 0) 1125 if (ret < 0)
1126 goto out; 1126 goto out;
1127 1127
diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c
index a43e6617b351..314c0d3b3fa9 100644
--- a/fs/ext4/namei.c
+++ b/fs/ext4/namei.c
@@ -179,30 +179,6 @@ static struct buffer_head * ext4_dx_find_entry(struct inode *dir,
179static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry, 179static int ext4_dx_add_entry(handle_t *handle, struct dentry *dentry,
180 struct inode *inode); 180 struct inode *inode);
181 181
182unsigned int ext4_rec_len_from_disk(__le16 dlen, unsigned blocksize)
183{
184 unsigned len = le16_to_cpu(dlen);
185
186 if (len == EXT4_MAX_REC_LEN || len == 0)
187 return blocksize;
188 return (len & 65532) | ((len & 3) << 16);
189}
190
191__le16 ext4_rec_len_to_disk(unsigned len, unsigned blocksize)
192{
193 if ((len > blocksize) || (blocksize > (1 << 18)) || (len & 3))
194 BUG();
195 if (len < 65536)
196 return cpu_to_le16(len);
197 if (len == blocksize) {
198 if (blocksize == 65536)
199 return cpu_to_le16(EXT4_MAX_REC_LEN);
200 else
201 return cpu_to_le16(0);
202 }
203 return cpu_to_le16((len & 65532) | ((len >> 16) & 3));
204}
205
206/* 182/*
207 * p is at least 6 bytes before the end of page 183 * p is at least 6 bytes before the end of page
208 */ 184 */
@@ -605,7 +581,7 @@ static int htree_dirblock_to_tree(struct file *dir_file,
605 dir->i_sb->s_blocksize - 581 dir->i_sb->s_blocksize -
606 EXT4_DIR_REC_LEN(0)); 582 EXT4_DIR_REC_LEN(0));
607 for (; de < top; de = ext4_next_entry(de, dir->i_sb->s_blocksize)) { 583 for (; de < top; de = ext4_next_entry(de, dir->i_sb->s_blocksize)) {
608 if (!ext4_check_dir_entry("htree_dirblock_to_tree", dir, de, bh, 584 if (!ext4_check_dir_entry(dir, de, bh,
609 (block<<EXT4_BLOCK_SIZE_BITS(dir->i_sb)) 585 (block<<EXT4_BLOCK_SIZE_BITS(dir->i_sb))
610 +((char *)de - bh->b_data))) { 586 +((char *)de - bh->b_data))) {
611 /* On error, skip the f_pos to the next block. */ 587 /* On error, skip the f_pos to the next block. */
@@ -844,8 +820,7 @@ static inline int search_dirblock(struct buffer_head *bh,
844 if ((char *) de + namelen <= dlimit && 820 if ((char *) de + namelen <= dlimit &&
845 ext4_match (namelen, name, de)) { 821 ext4_match (namelen, name, de)) {
846 /* found a match - just to be sure, do a full check */ 822 /* found a match - just to be sure, do a full check */
847 if (!ext4_check_dir_entry("ext4_find_entry", 823 if (!ext4_check_dir_entry(dir, de, bh, offset))
848 dir, de, bh, offset))
849 return -1; 824 return -1;
850 *res_dir = de; 825 *res_dir = de;
851 return 1; 826 return 1;
@@ -1019,7 +994,7 @@ static struct buffer_head * ext4_dx_find_entry(struct inode *dir, const struct q
1019 int off = (block << EXT4_BLOCK_SIZE_BITS(sb)) 994 int off = (block << EXT4_BLOCK_SIZE_BITS(sb))
1020 + ((char *) de - bh->b_data); 995 + ((char *) de - bh->b_data);
1021 996
1022 if (!ext4_check_dir_entry(__func__, dir, de, bh, off)) { 997 if (!ext4_check_dir_entry(dir, de, bh, off)) {
1023 brelse(bh); 998 brelse(bh);
1024 *err = ERR_BAD_DX_DIR; 999 *err = ERR_BAD_DX_DIR;
1025 goto errout; 1000 goto errout;
@@ -1088,7 +1063,6 @@ static struct dentry *ext4_lookup(struct inode *dir, struct dentry *dentry, stru
1088struct dentry *ext4_get_parent(struct dentry *child) 1063struct dentry *ext4_get_parent(struct dentry *child)
1089{ 1064{
1090 __u32 ino; 1065 __u32 ino;
1091 struct inode *inode;
1092 static const struct qstr dotdot = { 1066 static const struct qstr dotdot = {
1093 .name = "..", 1067 .name = "..",
1094 .len = 2, 1068 .len = 2,
@@ -1097,7 +1071,6 @@ struct dentry *ext4_get_parent(struct dentry *child)
1097 struct buffer_head *bh; 1071 struct buffer_head *bh;
1098 1072
1099 bh = ext4_find_entry(child->d_inode, &dotdot, &de); 1073 bh = ext4_find_entry(child->d_inode, &dotdot, &de);
1100 inode = NULL;
1101 if (!bh) 1074 if (!bh)
1102 return ERR_PTR(-ENOENT); 1075 return ERR_PTR(-ENOENT);
1103 ino = le32_to_cpu(de->inode); 1076 ino = le32_to_cpu(de->inode);
@@ -1305,8 +1278,7 @@ static int add_dirent_to_buf(handle_t *handle, struct dentry *dentry,
1305 de = (struct ext4_dir_entry_2 *)bh->b_data; 1278 de = (struct ext4_dir_entry_2 *)bh->b_data;
1306 top = bh->b_data + blocksize - reclen; 1279 top = bh->b_data + blocksize - reclen;
1307 while ((char *) de <= top) { 1280 while ((char *) de <= top) {
1308 if (!ext4_check_dir_entry("ext4_add_entry", dir, de, 1281 if (!ext4_check_dir_entry(dir, de, bh, offset))
1309 bh, offset))
1310 return -EIO; 1282 return -EIO;
1311 if (ext4_match(namelen, name, de)) 1283 if (ext4_match(namelen, name, de))
1312 return -EEXIST; 1284 return -EEXIST;
@@ -1673,7 +1645,7 @@ static int ext4_delete_entry(handle_t *handle,
1673 pde = NULL; 1645 pde = NULL;
1674 de = (struct ext4_dir_entry_2 *) bh->b_data; 1646 de = (struct ext4_dir_entry_2 *) bh->b_data;
1675 while (i < bh->b_size) { 1647 while (i < bh->b_size) {
1676 if (!ext4_check_dir_entry("ext4_delete_entry", dir, de, bh, i)) 1648 if (!ext4_check_dir_entry(dir, de, bh, i))
1677 return -EIO; 1649 return -EIO;
1678 if (de == de_del) { 1650 if (de == de_del) {
1679 BUFFER_TRACE(bh, "get_write_access"); 1651 BUFFER_TRACE(bh, "get_write_access");
@@ -1956,7 +1928,7 @@ static int empty_dir(struct inode *inode)
1956 } 1928 }
1957 de = (struct ext4_dir_entry_2 *) bh->b_data; 1929 de = (struct ext4_dir_entry_2 *) bh->b_data;
1958 } 1930 }
1959 if (!ext4_check_dir_entry("empty_dir", inode, de, bh, offset)) { 1931 if (!ext4_check_dir_entry(inode, de, bh, offset)) {
1960 de = (struct ext4_dir_entry_2 *)(bh->b_data + 1932 de = (struct ext4_dir_entry_2 *)(bh->b_data +
1961 sb->s_blocksize); 1933 sb->s_blocksize);
1962 offset = (offset | (sb->s_blocksize - 1)) + 1; 1934 offset = (offset | (sb->s_blocksize - 1)) + 1;
diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
index 6df797eb9aeb..ca5c8aa00a2f 100644
--- a/fs/ext4/resize.c
+++ b/fs/ext4/resize.c
@@ -921,8 +921,7 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)
921 &sbi->s_flex_groups[flex_group].free_inodes); 921 &sbi->s_flex_groups[flex_group].free_inodes);
922 } 922 }
923 923
924 ext4_handle_dirty_metadata(handle, NULL, sbi->s_sbh); 924 ext4_handle_dirty_super(handle, sb);
925 sb->s_dirt = 1;
926 925
927exit_journal: 926exit_journal:
928 mutex_unlock(&sbi->s_resize_lock); 927 mutex_unlock(&sbi->s_resize_lock);
@@ -953,7 +952,6 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
953 ext4_fsblk_t n_blocks_count) 952 ext4_fsblk_t n_blocks_count)
954{ 953{
955 ext4_fsblk_t o_blocks_count; 954 ext4_fsblk_t o_blocks_count;
956 ext4_group_t o_groups_count;
957 ext4_grpblk_t last; 955 ext4_grpblk_t last;
958 ext4_grpblk_t add; 956 ext4_grpblk_t add;
959 struct buffer_head *bh; 957 struct buffer_head *bh;
@@ -965,7 +963,6 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
965 * yet: we're going to revalidate es->s_blocks_count after 963 * yet: we're going to revalidate es->s_blocks_count after
966 * taking the s_resize_lock below. */ 964 * taking the s_resize_lock below. */
967 o_blocks_count = ext4_blocks_count(es); 965 o_blocks_count = ext4_blocks_count(es);
968 o_groups_count = EXT4_SB(sb)->s_groups_count;
969 966
970 if (test_opt(sb, DEBUG)) 967 if (test_opt(sb, DEBUG))
971 printk(KERN_DEBUG "EXT4-fs: extending last group from %llu uto %llu blocks\n", 968 printk(KERN_DEBUG "EXT4-fs: extending last group from %llu uto %llu blocks\n",
@@ -1045,13 +1042,12 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,
1045 goto exit_put; 1042 goto exit_put;
1046 } 1043 }
1047 ext4_blocks_count_set(es, o_blocks_count + add); 1044 ext4_blocks_count_set(es, o_blocks_count + add);
1048 ext4_handle_dirty_metadata(handle, NULL, EXT4_SB(sb)->s_sbh);
1049 sb->s_dirt = 1;
1050 mutex_unlock(&EXT4_SB(sb)->s_resize_lock); 1045 mutex_unlock(&EXT4_SB(sb)->s_resize_lock);
1051 ext4_debug("freeing blocks %llu through %llu\n", o_blocks_count, 1046 ext4_debug("freeing blocks %llu through %llu\n", o_blocks_count,
1052 o_blocks_count + add); 1047 o_blocks_count + add);
1053 /* We add the blocks to the bitmap and set the group need init bit */ 1048 /* We add the blocks to the bitmap and set the group need init bit */
1054 ext4_add_groupblocks(handle, sb, o_blocks_count, add); 1049 ext4_add_groupblocks(handle, sb, o_blocks_count, add);
1050 ext4_handle_dirty_super(handle, sb);
1055 ext4_debug("freed blocks %llu through %llu\n", o_blocks_count, 1051 ext4_debug("freed blocks %llu through %llu\n", o_blocks_count,
1056 o_blocks_count + add); 1052 o_blocks_count + add);
1057 if ((err = ext4_journal_stop(handle))) 1053 if ((err = ext4_journal_stop(handle)))
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index e72d3235b2fd..8d65575f8c8c 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -241,14 +241,14 @@ handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)
241 if (sb->s_flags & MS_RDONLY) 241 if (sb->s_flags & MS_RDONLY)
242 return ERR_PTR(-EROFS); 242 return ERR_PTR(-EROFS);
243 243
244 vfs_check_frozen(sb, SB_FREEZE_WRITE); 244 vfs_check_frozen(sb, SB_FREEZE_TRANS);
245 /* Special case here: if the journal has aborted behind our 245 /* Special case here: if the journal has aborted behind our
246 * backs (eg. EIO in the commit thread), then we still need to 246 * backs (eg. EIO in the commit thread), then we still need to
247 * take the FS itself readonly cleanly. */ 247 * take the FS itself readonly cleanly. */
248 journal = EXT4_SB(sb)->s_journal; 248 journal = EXT4_SB(sb)->s_journal;
249 if (journal) { 249 if (journal) {
250 if (is_journal_aborted(journal)) { 250 if (is_journal_aborted(journal)) {
251 ext4_abort(sb, __func__, "Detected aborted journal"); 251 ext4_abort(sb, "Detected aborted journal");
252 return ERR_PTR(-EROFS); 252 return ERR_PTR(-EROFS);
253 } 253 }
254 return jbd2_journal_start(journal, nblocks); 254 return jbd2_journal_start(journal, nblocks);
@@ -262,7 +262,7 @@ handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks)
262 * that sync() will call the filesystem's write_super callback if 262 * that sync() will call the filesystem's write_super callback if
263 * appropriate. 263 * appropriate.
264 */ 264 */
265int __ext4_journal_stop(const char *where, handle_t *handle) 265int __ext4_journal_stop(const char *where, unsigned int line, handle_t *handle)
266{ 266{
267 struct super_block *sb; 267 struct super_block *sb;
268 int err; 268 int err;
@@ -279,12 +279,13 @@ int __ext4_journal_stop(const char *where, handle_t *handle)
279 if (!err) 279 if (!err)
280 err = rc; 280 err = rc;
281 if (err) 281 if (err)
282 __ext4_std_error(sb, where, err); 282 __ext4_std_error(sb, where, line, err);
283 return err; 283 return err;
284} 284}
285 285
286void ext4_journal_abort_handle(const char *caller, const char *err_fn, 286void ext4_journal_abort_handle(const char *caller, unsigned int line,
287 struct buffer_head *bh, handle_t *handle, int err) 287 const char *err_fn, struct buffer_head *bh,
288 handle_t *handle, int err)
288{ 289{
289 char nbuf[16]; 290 char nbuf[16];
290 const char *errstr = ext4_decode_error(NULL, err, nbuf); 291 const char *errstr = ext4_decode_error(NULL, err, nbuf);
@@ -300,12 +301,47 @@ void ext4_journal_abort_handle(const char *caller, const char *err_fn,
300 if (is_handle_aborted(handle)) 301 if (is_handle_aborted(handle))
301 return; 302 return;
302 303
303 printk(KERN_ERR "%s: aborting transaction: %s in %s\n", 304 printk(KERN_ERR "%s:%d: aborting transaction: %s in %s\n",
304 caller, errstr, err_fn); 305 caller, line, errstr, err_fn);
305 306
306 jbd2_journal_abort_handle(handle); 307 jbd2_journal_abort_handle(handle);
307} 308}
308 309
310static void __save_error_info(struct super_block *sb, const char *func,
311 unsigned int line)
312{
313 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
314
315 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
316 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
317 es->s_last_error_time = cpu_to_le32(get_seconds());
318 strncpy(es->s_last_error_func, func, sizeof(es->s_last_error_func));
319 es->s_last_error_line = cpu_to_le32(line);
320 if (!es->s_first_error_time) {
321 es->s_first_error_time = es->s_last_error_time;
322 strncpy(es->s_first_error_func, func,
323 sizeof(es->s_first_error_func));
324 es->s_first_error_line = cpu_to_le32(line);
325 es->s_first_error_ino = es->s_last_error_ino;
326 es->s_first_error_block = es->s_last_error_block;
327 }
328 /*
329 * Start the daily error reporting function if it hasn't been
330 * started already
331 */
332 if (!es->s_error_count)
333 mod_timer(&EXT4_SB(sb)->s_err_report, jiffies + 24*60*60*HZ);
334 es->s_error_count = cpu_to_le32(le32_to_cpu(es->s_error_count) + 1);
335}
336
337static void save_error_info(struct super_block *sb, const char *func,
338 unsigned int line)
339{
340 __save_error_info(sb, func, line);
341 ext4_commit_super(sb, 1);
342}
343
344
309/* Deal with the reporting of failure conditions on a filesystem such as 345/* Deal with the reporting of failure conditions on a filesystem such as
310 * inconsistencies detected or read IO failures. 346 * inconsistencies detected or read IO failures.
311 * 347 *
@@ -323,11 +359,6 @@ void ext4_journal_abort_handle(const char *caller, const char *err_fn,
323 359
324static void ext4_handle_error(struct super_block *sb) 360static void ext4_handle_error(struct super_block *sb)
325{ 361{
326 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
327
328 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
329 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
330
331 if (sb->s_flags & MS_RDONLY) 362 if (sb->s_flags & MS_RDONLY)
332 return; 363 return;
333 364
@@ -342,19 +373,19 @@ static void ext4_handle_error(struct super_block *sb)
342 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only"); 373 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
343 sb->s_flags |= MS_RDONLY; 374 sb->s_flags |= MS_RDONLY;
344 } 375 }
345 ext4_commit_super(sb, 1);
346 if (test_opt(sb, ERRORS_PANIC)) 376 if (test_opt(sb, ERRORS_PANIC))
347 panic("EXT4-fs (device %s): panic forced after error\n", 377 panic("EXT4-fs (device %s): panic forced after error\n",
348 sb->s_id); 378 sb->s_id);
349} 379}
350 380
351void __ext4_error(struct super_block *sb, const char *function, 381void __ext4_error(struct super_block *sb, const char *function,
352 const char *fmt, ...) 382 unsigned int line, const char *fmt, ...)
353{ 383{
354 va_list args; 384 va_list args;
355 385
356 va_start(args, fmt); 386 va_start(args, fmt);
357 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); 387 printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: comm %s: ",
388 sb->s_id, function, line, current->comm);
358 vprintk(fmt, args); 389 vprintk(fmt, args);
359 printk("\n"); 390 printk("\n");
360 va_end(args); 391 va_end(args);
@@ -362,14 +393,22 @@ void __ext4_error(struct super_block *sb, const char *function,
362 ext4_handle_error(sb); 393 ext4_handle_error(sb);
363} 394}
364 395
365void ext4_error_inode(const char *function, struct inode *inode, 396void ext4_error_inode(struct inode *inode, const char *function,
397 unsigned int line, ext4_fsblk_t block,
366 const char *fmt, ...) 398 const char *fmt, ...)
367{ 399{
368 va_list args; 400 va_list args;
401 struct ext4_super_block *es = EXT4_SB(inode->i_sb)->s_es;
369 402
403 es->s_last_error_ino = cpu_to_le32(inode->i_ino);
404 es->s_last_error_block = cpu_to_le64(block);
405 save_error_info(inode->i_sb, function, line);
370 va_start(args, fmt); 406 va_start(args, fmt);
371 printk(KERN_CRIT "EXT4-fs error (device %s): %s: inode #%lu: (comm %s) ", 407 printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: inode #%lu: ",
372 inode->i_sb->s_id, function, inode->i_ino, current->comm); 408 inode->i_sb->s_id, function, line, inode->i_ino);
409 if (block)
410 printk("block %llu: ", block);
411 printk("comm %s: ", current->comm);
373 vprintk(fmt, args); 412 vprintk(fmt, args);
374 printk("\n"); 413 printk("\n");
375 va_end(args); 414 va_end(args);
@@ -377,20 +416,26 @@ void ext4_error_inode(const char *function, struct inode *inode,
377 ext4_handle_error(inode->i_sb); 416 ext4_handle_error(inode->i_sb);
378} 417}
379 418
380void ext4_error_file(const char *function, struct file *file, 419void ext4_error_file(struct file *file, const char *function,
381 const char *fmt, ...) 420 unsigned int line, const char *fmt, ...)
382{ 421{
383 va_list args; 422 va_list args;
423 struct ext4_super_block *es;
384 struct inode *inode = file->f_dentry->d_inode; 424 struct inode *inode = file->f_dentry->d_inode;
385 char pathname[80], *path; 425 char pathname[80], *path;
386 426
427 es = EXT4_SB(inode->i_sb)->s_es;
428 es->s_last_error_ino = cpu_to_le32(inode->i_ino);
429 save_error_info(inode->i_sb, function, line);
387 va_start(args, fmt); 430 va_start(args, fmt);
388 path = d_path(&(file->f_path), pathname, sizeof(pathname)); 431 path = d_path(&(file->f_path), pathname, sizeof(pathname));
389 if (!path) 432 if (!path)
390 path = "(unknown)"; 433 path = "(unknown)";
391 printk(KERN_CRIT 434 printk(KERN_CRIT
392 "EXT4-fs error (device %s): %s: inode #%lu (comm %s path %s): ", 435 "EXT4-fs error (device %s): %s:%d: inode #%lu "
393 inode->i_sb->s_id, function, inode->i_ino, current->comm, path); 436 "(comm %s path %s): ",
437 inode->i_sb->s_id, function, line, inode->i_ino,
438 current->comm, path);
394 vprintk(fmt, args); 439 vprintk(fmt, args);
395 printk("\n"); 440 printk("\n");
396 va_end(args); 441 va_end(args);
@@ -435,7 +480,8 @@ static const char *ext4_decode_error(struct super_block *sb, int errno,
435/* __ext4_std_error decodes expected errors from journaling functions 480/* __ext4_std_error decodes expected errors from journaling functions
436 * automatically and invokes the appropriate error response. */ 481 * automatically and invokes the appropriate error response. */
437 482
438void __ext4_std_error(struct super_block *sb, const char *function, int errno) 483void __ext4_std_error(struct super_block *sb, const char *function,
484 unsigned int line, int errno)
439{ 485{
440 char nbuf[16]; 486 char nbuf[16];
441 const char *errstr; 487 const char *errstr;
@@ -448,8 +494,9 @@ void __ext4_std_error(struct super_block *sb, const char *function, int errno)
448 return; 494 return;
449 495
450 errstr = ext4_decode_error(sb, errno, nbuf); 496 errstr = ext4_decode_error(sb, errno, nbuf);
451 printk(KERN_CRIT "EXT4-fs error (device %s) in %s: %s\n", 497 printk(KERN_CRIT "EXT4-fs error (device %s) in %s:%d: %s\n",
452 sb->s_id, function, errstr); 498 sb->s_id, function, line, errstr);
499 save_error_info(sb, function, line);
453 500
454 ext4_handle_error(sb); 501 ext4_handle_error(sb);
455} 502}
@@ -464,29 +511,29 @@ void __ext4_std_error(struct super_block *sb, const char *function, int errno)
464 * case we take the easy way out and panic immediately. 511 * case we take the easy way out and panic immediately.
465 */ 512 */
466 513
467void ext4_abort(struct super_block *sb, const char *function, 514void __ext4_abort(struct super_block *sb, const char *function,
468 const char *fmt, ...) 515 unsigned int line, const char *fmt, ...)
469{ 516{
470 va_list args; 517 va_list args;
471 518
519 save_error_info(sb, function, line);
472 va_start(args, fmt); 520 va_start(args, fmt);
473 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); 521 printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: ", sb->s_id,
522 function, line);
474 vprintk(fmt, args); 523 vprintk(fmt, args);
475 printk("\n"); 524 printk("\n");
476 va_end(args); 525 va_end(args);
477 526
527 if ((sb->s_flags & MS_RDONLY) == 0) {
528 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
529 sb->s_flags |= MS_RDONLY;
530 EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
531 if (EXT4_SB(sb)->s_journal)
532 jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
533 save_error_info(sb, function, line);
534 }
478 if (test_opt(sb, ERRORS_PANIC)) 535 if (test_opt(sb, ERRORS_PANIC))
479 panic("EXT4-fs panic from previous error\n"); 536 panic("EXT4-fs panic from previous error\n");
480
481 if (sb->s_flags & MS_RDONLY)
482 return;
483
484 ext4_msg(sb, KERN_CRIT, "Remounting filesystem read-only");
485 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
486 sb->s_flags |= MS_RDONLY;
487 EXT4_SB(sb)->s_mount_flags |= EXT4_MF_FS_ABORTED;
488 if (EXT4_SB(sb)->s_journal)
489 jbd2_journal_abort(EXT4_SB(sb)->s_journal, -EIO);
490} 537}
491 538
492void ext4_msg (struct super_block * sb, const char *prefix, 539void ext4_msg (struct super_block * sb, const char *prefix,
@@ -502,38 +549,47 @@ void ext4_msg (struct super_block * sb, const char *prefix,
502} 549}
503 550
504void __ext4_warning(struct super_block *sb, const char *function, 551void __ext4_warning(struct super_block *sb, const char *function,
505 const char *fmt, ...) 552 unsigned int line, const char *fmt, ...)
506{ 553{
507 va_list args; 554 va_list args;
508 555
509 va_start(args, fmt); 556 va_start(args, fmt);
510 printk(KERN_WARNING "EXT4-fs warning (device %s): %s: ", 557 printk(KERN_WARNING "EXT4-fs warning (device %s): %s:%d: ",
511 sb->s_id, function); 558 sb->s_id, function, line);
512 vprintk(fmt, args); 559 vprintk(fmt, args);
513 printk("\n"); 560 printk("\n");
514 va_end(args); 561 va_end(args);
515} 562}
516 563
517void ext4_grp_locked_error(struct super_block *sb, ext4_group_t grp, 564void __ext4_grp_locked_error(const char *function, unsigned int line,
518 const char *function, const char *fmt, ...) 565 struct super_block *sb, ext4_group_t grp,
566 unsigned long ino, ext4_fsblk_t block,
567 const char *fmt, ...)
519__releases(bitlock) 568__releases(bitlock)
520__acquires(bitlock) 569__acquires(bitlock)
521{ 570{
522 va_list args; 571 va_list args;
523 struct ext4_super_block *es = EXT4_SB(sb)->s_es; 572 struct ext4_super_block *es = EXT4_SB(sb)->s_es;
524 573
574 es->s_last_error_ino = cpu_to_le32(ino);
575 es->s_last_error_block = cpu_to_le64(block);
576 __save_error_info(sb, function, line);
525 va_start(args, fmt); 577 va_start(args, fmt);
526 printk(KERN_CRIT "EXT4-fs error (device %s): %s: ", sb->s_id, function); 578 printk(KERN_CRIT "EXT4-fs error (device %s): %s:%d: group %u",
579 sb->s_id, function, line, grp);
580 if (ino)
581 printk("inode %lu: ", ino);
582 if (block)
583 printk("block %llu:", (unsigned long long) block);
527 vprintk(fmt, args); 584 vprintk(fmt, args);
528 printk("\n"); 585 printk("\n");
529 va_end(args); 586 va_end(args);
530 587
531 if (test_opt(sb, ERRORS_CONT)) { 588 if (test_opt(sb, ERRORS_CONT)) {
532 EXT4_SB(sb)->s_mount_state |= EXT4_ERROR_FS;
533 es->s_state |= cpu_to_le16(EXT4_ERROR_FS);
534 ext4_commit_super(sb, 0); 589 ext4_commit_super(sb, 0);
535 return; 590 return;
536 } 591 }
592
537 ext4_unlock_group(sb, grp); 593 ext4_unlock_group(sb, grp);
538 ext4_handle_error(sb); 594 ext4_handle_error(sb);
539 /* 595 /*
@@ -660,8 +716,7 @@ static void ext4_put_super(struct super_block *sb)
660 err = jbd2_journal_destroy(sbi->s_journal); 716 err = jbd2_journal_destroy(sbi->s_journal);
661 sbi->s_journal = NULL; 717 sbi->s_journal = NULL;
662 if (err < 0) 718 if (err < 0)
663 ext4_abort(sb, __func__, 719 ext4_abort(sb, "Couldn't clean up the journal");
664 "Couldn't clean up the journal");
665 } 720 }
666 721
667 ext4_release_system_zone(sb); 722 ext4_release_system_zone(sb);
@@ -946,14 +1001,12 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
946 seq_puts(seq, ",journal_async_commit"); 1001 seq_puts(seq, ",journal_async_commit");
947 else if (test_opt(sb, JOURNAL_CHECKSUM)) 1002 else if (test_opt(sb, JOURNAL_CHECKSUM))
948 seq_puts(seq, ",journal_checksum"); 1003 seq_puts(seq, ",journal_checksum");
949 if (test_opt(sb, NOBH))
950 seq_puts(seq, ",nobh");
951 if (test_opt(sb, I_VERSION)) 1004 if (test_opt(sb, I_VERSION))
952 seq_puts(seq, ",i_version"); 1005 seq_puts(seq, ",i_version");
953 if (!test_opt(sb, DELALLOC)) 1006 if (!test_opt(sb, DELALLOC) &&
1007 !(def_mount_opts & EXT4_DEFM_NODELALLOC))
954 seq_puts(seq, ",nodelalloc"); 1008 seq_puts(seq, ",nodelalloc");
955 1009
956
957 if (sbi->s_stripe) 1010 if (sbi->s_stripe)
958 seq_printf(seq, ",stripe=%lu", sbi->s_stripe); 1011 seq_printf(seq, ",stripe=%lu", sbi->s_stripe);
959 /* 1012 /*
@@ -977,7 +1030,7 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
977 if (test_opt(sb, NO_AUTO_DA_ALLOC)) 1030 if (test_opt(sb, NO_AUTO_DA_ALLOC))
978 seq_puts(seq, ",noauto_da_alloc"); 1031 seq_puts(seq, ",noauto_da_alloc");
979 1032
980 if (test_opt(sb, DISCARD)) 1033 if (test_opt(sb, DISCARD) && !(def_mount_opts & EXT4_DEFM_DISCARD))
981 seq_puts(seq, ",discard"); 1034 seq_puts(seq, ",discard");
982 1035
983 if (test_opt(sb, NOLOAD)) 1036 if (test_opt(sb, NOLOAD))
@@ -986,6 +1039,10 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)
986 if (test_opt(sb, DIOREAD_NOLOCK)) 1039 if (test_opt(sb, DIOREAD_NOLOCK))
987 seq_puts(seq, ",dioread_nolock"); 1040 seq_puts(seq, ",dioread_nolock");
988 1041
1042 if (test_opt(sb, BLOCK_VALIDITY) &&
1043 !(def_mount_opts & EXT4_DEFM_BLOCK_VALIDITY))
1044 seq_puts(seq, ",block_validity");
1045
989 ext4_show_quota_options(seq, sb); 1046 ext4_show_quota_options(seq, sb);
990 1047
991 return 0; 1048 return 0;
@@ -1065,6 +1122,7 @@ static int ext4_mark_dquot_dirty(struct dquot *dquot);
1065static int ext4_write_info(struct super_block *sb, int type); 1122static int ext4_write_info(struct super_block *sb, int type);
1066static int ext4_quota_on(struct super_block *sb, int type, int format_id, 1123static int ext4_quota_on(struct super_block *sb, int type, int format_id,
1067 char *path); 1124 char *path);
1125static int ext4_quota_off(struct super_block *sb, int type);
1068static int ext4_quota_on_mount(struct super_block *sb, int type); 1126static int ext4_quota_on_mount(struct super_block *sb, int type);
1069static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data, 1127static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data,
1070 size_t len, loff_t off); 1128 size_t len, loff_t off);
@@ -1086,7 +1144,7 @@ static const struct dquot_operations ext4_quota_operations = {
1086 1144
1087static const struct quotactl_ops ext4_qctl_operations = { 1145static const struct quotactl_ops ext4_qctl_operations = {
1088 .quota_on = ext4_quota_on, 1146 .quota_on = ext4_quota_on,
1089 .quota_off = dquot_quota_off, 1147 .quota_off = ext4_quota_off,
1090 .quota_sync = dquot_quota_sync, 1148 .quota_sync = dquot_quota_sync,
1091 .get_info = dquot_get_dqinfo, 1149 .get_info = dquot_get_dqinfo,
1092 .set_info = dquot_set_dqinfo, 1150 .set_info = dquot_set_dqinfo,
@@ -1624,10 +1682,12 @@ set_qf_format:
1624 *n_blocks_count = option; 1682 *n_blocks_count = option;
1625 break; 1683 break;
1626 case Opt_nobh: 1684 case Opt_nobh:
1627 set_opt(sbi->s_mount_opt, NOBH); 1685 ext4_msg(sb, KERN_WARNING,
1686 "Ignoring deprecated nobh option");
1628 break; 1687 break;
1629 case Opt_bh: 1688 case Opt_bh:
1630 clear_opt(sbi->s_mount_opt, NOBH); 1689 ext4_msg(sb, KERN_WARNING,
1690 "Ignoring deprecated bh option");
1631 break; 1691 break;
1632 case Opt_i_version: 1692 case Opt_i_version:
1633 set_opt(sbi->s_mount_opt, I_VERSION); 1693 set_opt(sbi->s_mount_opt, I_VERSION);
@@ -2249,6 +2309,8 @@ static ssize_t session_write_kbytes_show(struct ext4_attr *a,
2249{ 2309{
2250 struct super_block *sb = sbi->s_buddy_cache->i_sb; 2310 struct super_block *sb = sbi->s_buddy_cache->i_sb;
2251 2311
2312 if (!sb->s_bdev->bd_part)
2313 return snprintf(buf, PAGE_SIZE, "0\n");
2252 return snprintf(buf, PAGE_SIZE, "%lu\n", 2314 return snprintf(buf, PAGE_SIZE, "%lu\n",
2253 (part_stat_read(sb->s_bdev->bd_part, sectors[1]) - 2315 (part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
2254 sbi->s_sectors_written_start) >> 1); 2316 sbi->s_sectors_written_start) >> 1);
@@ -2259,6 +2321,8 @@ static ssize_t lifetime_write_kbytes_show(struct ext4_attr *a,
2259{ 2321{
2260 struct super_block *sb = sbi->s_buddy_cache->i_sb; 2322 struct super_block *sb = sbi->s_buddy_cache->i_sb;
2261 2323
2324 if (!sb->s_bdev->bd_part)
2325 return snprintf(buf, PAGE_SIZE, "0\n");
2262 return snprintf(buf, PAGE_SIZE, "%llu\n", 2326 return snprintf(buf, PAGE_SIZE, "%llu\n",
2263 (unsigned long long)(sbi->s_kbytes_written + 2327 (unsigned long long)(sbi->s_kbytes_written +
2264 ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - 2328 ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
@@ -2431,6 +2495,53 @@ static int ext4_feature_set_ok(struct super_block *sb, int readonly)
2431 return 1; 2495 return 1;
2432} 2496}
2433 2497
2498/*
2499 * This function is called once a day if we have errors logged
2500 * on the file system
2501 */
2502static void print_daily_error_info(unsigned long arg)
2503{
2504 struct super_block *sb = (struct super_block *) arg;
2505 struct ext4_sb_info *sbi;
2506 struct ext4_super_block *es;
2507
2508 sbi = EXT4_SB(sb);
2509 es = sbi->s_es;
2510
2511 if (es->s_error_count)
2512 ext4_msg(sb, KERN_NOTICE, "error count: %u",
2513 le32_to_cpu(es->s_error_count));
2514 if (es->s_first_error_time) {
2515 printk(KERN_NOTICE "EXT4-fs (%s): initial error at %u: %.*s:%d",
2516 sb->s_id, le32_to_cpu(es->s_first_error_time),
2517 (int) sizeof(es->s_first_error_func),
2518 es->s_first_error_func,
2519 le32_to_cpu(es->s_first_error_line));
2520 if (es->s_first_error_ino)
2521 printk(": inode %u",
2522 le32_to_cpu(es->s_first_error_ino));
2523 if (es->s_first_error_block)
2524 printk(": block %llu", (unsigned long long)
2525 le64_to_cpu(es->s_first_error_block));
2526 printk("\n");
2527 }
2528 if (es->s_last_error_time) {
2529 printk(KERN_NOTICE "EXT4-fs (%s): last error at %u: %.*s:%d",
2530 sb->s_id, le32_to_cpu(es->s_last_error_time),
2531 (int) sizeof(es->s_last_error_func),
2532 es->s_last_error_func,
2533 le32_to_cpu(es->s_last_error_line));
2534 if (es->s_last_error_ino)
2535 printk(": inode %u",
2536 le32_to_cpu(es->s_last_error_ino));
2537 if (es->s_last_error_block)
2538 printk(": block %llu", (unsigned long long)
2539 le64_to_cpu(es->s_last_error_block));
2540 printk("\n");
2541 }
2542 mod_timer(&sbi->s_err_report, jiffies + 24*60*60*HZ); /* Once a day */
2543}
2544
2434static int ext4_fill_super(struct super_block *sb, void *data, int silent) 2545static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2435 __releases(kernel_lock) 2546 __releases(kernel_lock)
2436 __acquires(kernel_lock) 2547 __acquires(kernel_lock)
@@ -2448,7 +2559,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2448 struct inode *root; 2559 struct inode *root;
2449 char *cp; 2560 char *cp;
2450 const char *descr; 2561 const char *descr;
2451 int ret = -EINVAL; 2562 int ret = -ENOMEM;
2452 int blocksize; 2563 int blocksize;
2453 unsigned int db_count; 2564 unsigned int db_count;
2454 unsigned int i; 2565 unsigned int i;
@@ -2459,13 +2570,13 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2459 2570
2460 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL); 2571 sbi = kzalloc(sizeof(*sbi), GFP_KERNEL);
2461 if (!sbi) 2572 if (!sbi)
2462 return -ENOMEM; 2573 goto out_free_orig;
2463 2574
2464 sbi->s_blockgroup_lock = 2575 sbi->s_blockgroup_lock =
2465 kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL); 2576 kzalloc(sizeof(struct blockgroup_lock), GFP_KERNEL);
2466 if (!sbi->s_blockgroup_lock) { 2577 if (!sbi->s_blockgroup_lock) {
2467 kfree(sbi); 2578 kfree(sbi);
2468 return -ENOMEM; 2579 goto out_free_orig;
2469 } 2580 }
2470 sb->s_fs_info = sbi; 2581 sb->s_fs_info = sbi;
2471 sbi->s_mount_opt = 0; 2582 sbi->s_mount_opt = 0;
@@ -2473,8 +2584,9 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2473 sbi->s_resgid = EXT4_DEF_RESGID; 2584 sbi->s_resgid = EXT4_DEF_RESGID;
2474 sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS; 2585 sbi->s_inode_readahead_blks = EXT4_DEF_INODE_READAHEAD_BLKS;
2475 sbi->s_sb_block = sb_block; 2586 sbi->s_sb_block = sb_block;
2476 sbi->s_sectors_written_start = part_stat_read(sb->s_bdev->bd_part, 2587 if (sb->s_bdev->bd_part)
2477 sectors[1]); 2588 sbi->s_sectors_written_start =
2589 part_stat_read(sb->s_bdev->bd_part, sectors[1]);
2478 2590
2479 unlock_kernel(); 2591 unlock_kernel();
2480 2592
@@ -2482,6 +2594,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2482 for (cp = sb->s_id; (cp = strchr(cp, '/'));) 2594 for (cp = sb->s_id; (cp = strchr(cp, '/'));)
2483 *cp = '!'; 2595 *cp = '!';
2484 2596
2597 ret = -EINVAL;
2485 blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE); 2598 blocksize = sb_min_blocksize(sb, EXT4_MIN_BLOCK_SIZE);
2486 if (!blocksize) { 2599 if (!blocksize) {
2487 ext4_msg(sb, KERN_ERR, "unable to set blocksize"); 2600 ext4_msg(sb, KERN_ERR, "unable to set blocksize");
@@ -2546,6 +2659,10 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2546 set_opt(sbi->s_mount_opt, ERRORS_CONT); 2659 set_opt(sbi->s_mount_opt, ERRORS_CONT);
2547 else 2660 else
2548 set_opt(sbi->s_mount_opt, ERRORS_RO); 2661 set_opt(sbi->s_mount_opt, ERRORS_RO);
2662 if (def_mount_opts & EXT4_DEFM_BLOCK_VALIDITY)
2663 set_opt(sbi->s_mount_opt, BLOCK_VALIDITY);
2664 if (def_mount_opts & EXT4_DEFM_DISCARD)
2665 set_opt(sbi->s_mount_opt, DISCARD);
2549 2666
2550 sbi->s_resuid = le16_to_cpu(es->s_def_resuid); 2667 sbi->s_resuid = le16_to_cpu(es->s_def_resuid);
2551 sbi->s_resgid = le16_to_cpu(es->s_def_resgid); 2668 sbi->s_resgid = le16_to_cpu(es->s_def_resgid);
@@ -2553,15 +2670,23 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
2553 sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME; 2670 sbi->s_min_batch_time = EXT4_DEF_MIN_BATCH_TIME;
2554 sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME; 2671 sbi->s_max_batch_time = EXT4_DEF_MAX_BATCH_TIME;
2555 2672
2556 set_opt(sbi->s_mount_opt, BARRIER); 2673 if ((def_mount_opts & EXT4_DEFM_NOBARRIER) == 0)
2674 set_opt(sbi->s_mount_opt, BARRIER);
2557 2675
2558 /* 2676 /*
2559 * enable delayed allocation by default 2677 * enable delayed allocation by default
2560 * Use -o nodelalloc to turn it off 2678 * Use -o nodelalloc to turn it off
2561 */ 2679 */
2562 if (!IS_EXT3_SB(sb)) 2680 if (!IS_EXT3_SB(sb) &&
2681 ((def_mount_opts & EXT4_DEFM_NODELALLOC) == 0))
2563 set_opt(sbi->s_mount_opt, DELALLOC); 2682 set_opt(sbi->s_mount_opt, DELALLOC);
2564 2683
2684 if (!parse_options((char *) sbi->s_es->s_mount_opts, sb,
2685 &journal_devnum, &journal_ioprio, NULL, 0)) {
2686 ext4_msg(sb, KERN_WARNING,
2687 "failed to parse options in superblock: %s",
2688 sbi->s_es->s_mount_opts);
2689 }
2565 if (!parse_options((char *) data, sb, &journal_devnum, 2690 if (!parse_options((char *) data, sb, &journal_devnum,
2566 &journal_ioprio, NULL, 0)) 2691 &journal_ioprio, NULL, 0))
2567 goto failed_mount; 2692 goto failed_mount;
@@ -2912,18 +3037,7 @@ no_journal:
2912 ext4_msg(sb, KERN_ERR, "insufficient memory"); 3037 ext4_msg(sb, KERN_ERR, "insufficient memory");
2913 goto failed_mount_wq; 3038 goto failed_mount_wq;
2914 } 3039 }
2915 if (test_opt(sb, NOBH)) { 3040
2916 if (!(test_opt(sb, DATA_FLAGS) == EXT4_MOUNT_WRITEBACK_DATA)) {
2917 ext4_msg(sb, KERN_WARNING, "Ignoring nobh option - "
2918 "its supported only with writeback mode");
2919 clear_opt(sbi->s_mount_opt, NOBH);
2920 }
2921 if (test_opt(sb, DIOREAD_NOLOCK)) {
2922 ext4_msg(sb, KERN_WARNING, "dioread_nolock option is "
2923 "not supported with nobh mode");
2924 goto failed_mount_wq;
2925 }
2926 }
2927 EXT4_SB(sb)->dio_unwritten_wq = create_workqueue("ext4-dio-unwritten"); 3041 EXT4_SB(sb)->dio_unwritten_wq = create_workqueue("ext4-dio-unwritten");
2928 if (!EXT4_SB(sb)->dio_unwritten_wq) { 3042 if (!EXT4_SB(sb)->dio_unwritten_wq) {
2929 printk(KERN_ERR "EXT4-fs: failed to create DIO workqueue\n"); 3043 printk(KERN_ERR "EXT4-fs: failed to create DIO workqueue\n");
@@ -3043,7 +3157,14 @@ no_journal:
3043 descr = "out journal"; 3157 descr = "out journal";
3044 3158
3045 ext4_msg(sb, KERN_INFO, "mounted filesystem with%s. " 3159 ext4_msg(sb, KERN_INFO, "mounted filesystem with%s. "
3046 "Opts: %s", descr, orig_data); 3160 "Opts: %s%s%s", descr, sbi->s_es->s_mount_opts,
3161 *sbi->s_es->s_mount_opts ? "; " : "", orig_data);
3162
3163 init_timer(&sbi->s_err_report);
3164 sbi->s_err_report.function = print_daily_error_info;
3165 sbi->s_err_report.data = (unsigned long) sb;
3166 if (es->s_error_count)
3167 mod_timer(&sbi->s_err_report, jiffies + 300*HZ); /* 5 minutes */
3047 3168
3048 lock_kernel(); 3169 lock_kernel();
3049 kfree(orig_data); 3170 kfree(orig_data);
@@ -3093,6 +3214,7 @@ out_fail:
3093 kfree(sbi->s_blockgroup_lock); 3214 kfree(sbi->s_blockgroup_lock);
3094 kfree(sbi); 3215 kfree(sbi);
3095 lock_kernel(); 3216 lock_kernel();
3217out_free_orig:
3096 kfree(orig_data); 3218 kfree(orig_data);
3097 return ret; 3219 return ret;
3098} 3220}
@@ -3110,7 +3232,7 @@ static void ext4_init_journal_params(struct super_block *sb, journal_t *journal)
3110 journal->j_min_batch_time = sbi->s_min_batch_time; 3232 journal->j_min_batch_time = sbi->s_min_batch_time;
3111 journal->j_max_batch_time = sbi->s_max_batch_time; 3233 journal->j_max_batch_time = sbi->s_max_batch_time;
3112 3234
3113 spin_lock(&journal->j_state_lock); 3235 write_lock(&journal->j_state_lock);
3114 if (test_opt(sb, BARRIER)) 3236 if (test_opt(sb, BARRIER))
3115 journal->j_flags |= JBD2_BARRIER; 3237 journal->j_flags |= JBD2_BARRIER;
3116 else 3238 else
@@ -3119,7 +3241,7 @@ static void ext4_init_journal_params(struct super_block *sb, journal_t *journal)
3119 journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR; 3241 journal->j_flags |= JBD2_ABORT_ON_SYNCDATA_ERR;
3120 else 3242 else
3121 journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR; 3243 journal->j_flags &= ~JBD2_ABORT_ON_SYNCDATA_ERR;
3122 spin_unlock(&journal->j_state_lock); 3244 write_unlock(&journal->j_state_lock);
3123} 3245}
3124 3246
3125static journal_t *ext4_get_journal(struct super_block *sb, 3247static journal_t *ext4_get_journal(struct super_block *sb,
@@ -3327,8 +3449,17 @@ static int ext4_load_journal(struct super_block *sb,
3327 3449
3328 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER)) 3450 if (!EXT4_HAS_INCOMPAT_FEATURE(sb, EXT4_FEATURE_INCOMPAT_RECOVER))
3329 err = jbd2_journal_wipe(journal, !really_read_only); 3451 err = jbd2_journal_wipe(journal, !really_read_only);
3330 if (!err) 3452 if (!err) {
3453 char *save = kmalloc(EXT4_S_ERR_LEN, GFP_KERNEL);
3454 if (save)
3455 memcpy(save, ((char *) es) +
3456 EXT4_S_ERR_START, EXT4_S_ERR_LEN);
3331 err = jbd2_journal_load(journal); 3457 err = jbd2_journal_load(journal);
3458 if (save)
3459 memcpy(((char *) es) + EXT4_S_ERR_START,
3460 save, EXT4_S_ERR_LEN);
3461 kfree(save);
3462 }
3332 3463
3333 if (err) { 3464 if (err) {
3334 ext4_msg(sb, KERN_ERR, "error loading journal"); 3465 ext4_msg(sb, KERN_ERR, "error loading journal");
@@ -3384,10 +3515,14 @@ static int ext4_commit_super(struct super_block *sb, int sync)
3384 */ 3515 */
3385 if (!(sb->s_flags & MS_RDONLY)) 3516 if (!(sb->s_flags & MS_RDONLY))
3386 es->s_wtime = cpu_to_le32(get_seconds()); 3517 es->s_wtime = cpu_to_le32(get_seconds());
3387 es->s_kbytes_written = 3518 if (sb->s_bdev->bd_part)
3388 cpu_to_le64(EXT4_SB(sb)->s_kbytes_written + 3519 es->s_kbytes_written =
3520 cpu_to_le64(EXT4_SB(sb)->s_kbytes_written +
3389 ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) - 3521 ((part_stat_read(sb->s_bdev->bd_part, sectors[1]) -
3390 EXT4_SB(sb)->s_sectors_written_start) >> 1)); 3522 EXT4_SB(sb)->s_sectors_written_start) >> 1));
3523 else
3524 es->s_kbytes_written =
3525 cpu_to_le64(EXT4_SB(sb)->s_kbytes_written);
3391 ext4_free_blocks_count_set(es, percpu_counter_sum_positive( 3526 ext4_free_blocks_count_set(es, percpu_counter_sum_positive(
3392 &EXT4_SB(sb)->s_freeblocks_counter)); 3527 &EXT4_SB(sb)->s_freeblocks_counter));
3393 es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive( 3528 es->s_free_inodes_count = cpu_to_le32(percpu_counter_sum_positive(
@@ -3491,7 +3626,7 @@ int ext4_force_commit(struct super_block *sb)
3491 3626
3492 journal = EXT4_SB(sb)->s_journal; 3627 journal = EXT4_SB(sb)->s_journal;
3493 if (journal) { 3628 if (journal) {
3494 vfs_check_frozen(sb, SB_FREEZE_WRITE); 3629 vfs_check_frozen(sb, SB_FREEZE_TRANS);
3495 ret = ext4_journal_force_commit(journal); 3630 ret = ext4_journal_force_commit(journal);
3496 } 3631 }
3497 3632
@@ -3616,7 +3751,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)
3616 } 3751 }
3617 3752
3618 if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED) 3753 if (sbi->s_mount_flags & EXT4_MF_FS_ABORTED)
3619 ext4_abort(sb, __func__, "Abort forced by user"); 3754 ext4_abort(sb, "Abort forced by user");
3620 3755
3621 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) | 3756 sb->s_flags = (sb->s_flags & ~MS_POSIXACL) |
3622 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0); 3757 (test_opt(sb, POSIX_ACL) ? MS_POSIXACL : 0);
@@ -3981,6 +4116,18 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id,
3981 return err; 4116 return err;
3982} 4117}
3983 4118
4119static int ext4_quota_off(struct super_block *sb, int type)
4120{
4121 /* Force all delayed allocation blocks to be allocated */
4122 if (test_opt(sb, DELALLOC)) {
4123 down_read(&sb->s_umount);
4124 sync_filesystem(sb);
4125 up_read(&sb->s_umount);
4126 }
4127
4128 return dquot_quota_off(sb, type);
4129}
4130
3984/* Read data from quotafile - avoid pagecache and such because we cannot afford 4131/* Read data from quotafile - avoid pagecache and such because we cannot afford
3985 * acquiring the locks... As quota files are never truncated and quota code 4132 * acquiring the locks... As quota files are never truncated and quota code
3986 * itself serializes the operations (and noone else should touch the files) 4133 * itself serializes the operations (and noone else should touch the files)
@@ -4030,7 +4177,6 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
4030 ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb); 4177 ext4_lblk_t blk = off >> EXT4_BLOCK_SIZE_BITS(sb);
4031 int err = 0; 4178 int err = 0;
4032 int offset = off & (sb->s_blocksize - 1); 4179 int offset = off & (sb->s_blocksize - 1);
4033 int journal_quota = EXT4_SB(sb)->s_qf_names[type] != NULL;
4034 struct buffer_head *bh; 4180 struct buffer_head *bh;
4035 handle_t *handle = journal_current_handle(); 4181 handle_t *handle = journal_current_handle();
4036 4182
@@ -4055,24 +4201,16 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type,
4055 bh = ext4_bread(handle, inode, blk, 1, &err); 4201 bh = ext4_bread(handle, inode, blk, 1, &err);
4056 if (!bh) 4202 if (!bh)
4057 goto out; 4203 goto out;
4058 if (journal_quota) { 4204 err = ext4_journal_get_write_access(handle, bh);
4059 err = ext4_journal_get_write_access(handle, bh); 4205 if (err) {
4060 if (err) { 4206 brelse(bh);
4061 brelse(bh); 4207 goto out;
4062 goto out;
4063 }
4064 } 4208 }
4065 lock_buffer(bh); 4209 lock_buffer(bh);
4066 memcpy(bh->b_data+offset, data, len); 4210 memcpy(bh->b_data+offset, data, len);
4067 flush_dcache_page(bh->b_page); 4211 flush_dcache_page(bh->b_page);
4068 unlock_buffer(bh); 4212 unlock_buffer(bh);
4069 if (journal_quota) 4213 err = ext4_handle_dirty_metadata(handle, NULL, bh);
4070 err = ext4_handle_dirty_metadata(handle, NULL, bh);
4071 else {
4072 /* Always do at least ordered writes for quotas */
4073 err = ext4_jbd2_file_inode(handle, inode);
4074 mark_buffer_dirty(bh);
4075 }
4076 brelse(bh); 4214 brelse(bh);
4077out: 4215out:
4078 if (err) { 4216 if (err) {
diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
index 04338009793a..a6f314249574 100644
--- a/fs/ext4/xattr.c
+++ b/fs/ext4/xattr.c
@@ -458,8 +458,7 @@ static void ext4_xattr_update_super_block(handle_t *handle,
458 458
459 if (ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh) == 0) { 459 if (ext4_journal_get_write_access(handle, EXT4_SB(sb)->s_sbh) == 0) {
460 EXT4_SET_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_EXT_ATTR); 460 EXT4_SET_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_EXT_ATTR);
461 sb->s_dirt = 1; 461 ext4_handle_dirty_super(handle, sb);
462 ext4_handle_dirty_metadata(handle, NULL, EXT4_SB(sb)->s_sbh);
463 } 462 }
464} 463}
465 464