aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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
-rw-r--r--fs/jbd2/checkpoint.c18
-rw-r--r--fs/jbd2/commit.c50
-rw-r--r--fs/jbd2/journal.c121
-rw-r--r--fs/jbd2/recovery.c10
-rw-r--r--fs/jbd2/transaction.c233
-rw-r--r--fs/ocfs2/journal.c4
-rw-r--r--include/linux/jbd2.h16
-rw-r--r--include/trace/events/ext4.h20
26 files changed, 917 insertions, 654 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
diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c
index 076d1cc44f95..1c23a0f4e8a3 100644
--- a/fs/jbd2/checkpoint.c
+++ b/fs/jbd2/checkpoint.c
@@ -118,13 +118,13 @@ static int __try_to_free_cp_buf(struct journal_head *jh)
118void __jbd2_log_wait_for_space(journal_t *journal) 118void __jbd2_log_wait_for_space(journal_t *journal)
119{ 119{
120 int nblocks, space_left; 120 int nblocks, space_left;
121 assert_spin_locked(&journal->j_state_lock); 121 /* assert_spin_locked(&journal->j_state_lock); */
122 122
123 nblocks = jbd_space_needed(journal); 123 nblocks = jbd_space_needed(journal);
124 while (__jbd2_log_space_left(journal) < nblocks) { 124 while (__jbd2_log_space_left(journal) < nblocks) {
125 if (journal->j_flags & JBD2_ABORT) 125 if (journal->j_flags & JBD2_ABORT)
126 return; 126 return;
127 spin_unlock(&journal->j_state_lock); 127 write_unlock(&journal->j_state_lock);
128 mutex_lock(&journal->j_checkpoint_mutex); 128 mutex_lock(&journal->j_checkpoint_mutex);
129 129
130 /* 130 /*
@@ -138,7 +138,7 @@ void __jbd2_log_wait_for_space(journal_t *journal)
138 * filesystem, so abort the journal and leave a stack 138 * filesystem, so abort the journal and leave a stack
139 * trace for forensic evidence. 139 * trace for forensic evidence.
140 */ 140 */
141 spin_lock(&journal->j_state_lock); 141 write_lock(&journal->j_state_lock);
142 spin_lock(&journal->j_list_lock); 142 spin_lock(&journal->j_list_lock);
143 nblocks = jbd_space_needed(journal); 143 nblocks = jbd_space_needed(journal);
144 space_left = __jbd2_log_space_left(journal); 144 space_left = __jbd2_log_space_left(journal);
@@ -149,7 +149,7 @@ void __jbd2_log_wait_for_space(journal_t *journal)
149 if (journal->j_committing_transaction) 149 if (journal->j_committing_transaction)
150 tid = journal->j_committing_transaction->t_tid; 150 tid = journal->j_committing_transaction->t_tid;
151 spin_unlock(&journal->j_list_lock); 151 spin_unlock(&journal->j_list_lock);
152 spin_unlock(&journal->j_state_lock); 152 write_unlock(&journal->j_state_lock);
153 if (chkpt) { 153 if (chkpt) {
154 jbd2_log_do_checkpoint(journal); 154 jbd2_log_do_checkpoint(journal);
155 } else if (jbd2_cleanup_journal_tail(journal) == 0) { 155 } else if (jbd2_cleanup_journal_tail(journal) == 0) {
@@ -167,7 +167,7 @@ void __jbd2_log_wait_for_space(journal_t *journal)
167 WARN_ON(1); 167 WARN_ON(1);
168 jbd2_journal_abort(journal, 0); 168 jbd2_journal_abort(journal, 0);
169 } 169 }
170 spin_lock(&journal->j_state_lock); 170 write_lock(&journal->j_state_lock);
171 } else { 171 } else {
172 spin_unlock(&journal->j_list_lock); 172 spin_unlock(&journal->j_list_lock);
173 } 173 }
@@ -474,7 +474,7 @@ int jbd2_cleanup_journal_tail(journal_t *journal)
474 * next transaction ID we will write, and where it will 474 * next transaction ID we will write, and where it will
475 * start. */ 475 * start. */
476 476
477 spin_lock(&journal->j_state_lock); 477 write_lock(&journal->j_state_lock);
478 spin_lock(&journal->j_list_lock); 478 spin_lock(&journal->j_list_lock);
479 transaction = journal->j_checkpoint_transactions; 479 transaction = journal->j_checkpoint_transactions;
480 if (transaction) { 480 if (transaction) {
@@ -496,7 +496,7 @@ int jbd2_cleanup_journal_tail(journal_t *journal)
496 /* If the oldest pinned transaction is at the tail of the log 496 /* If the oldest pinned transaction is at the tail of the log
497 already then there's not much we can do right now. */ 497 already then there's not much we can do right now. */
498 if (journal->j_tail_sequence == first_tid) { 498 if (journal->j_tail_sequence == first_tid) {
499 spin_unlock(&journal->j_state_lock); 499 write_unlock(&journal->j_state_lock);
500 return 1; 500 return 1;
501 } 501 }
502 502
@@ -516,7 +516,7 @@ int jbd2_cleanup_journal_tail(journal_t *journal)
516 journal->j_free += freed; 516 journal->j_free += freed;
517 journal->j_tail_sequence = first_tid; 517 journal->j_tail_sequence = first_tid;
518 journal->j_tail = blocknr; 518 journal->j_tail = blocknr;
519 spin_unlock(&journal->j_state_lock); 519 write_unlock(&journal->j_state_lock);
520 520
521 /* 521 /*
522 * If there is an external journal, we need to make sure that 522 * If there is an external journal, we need to make sure that
@@ -775,7 +775,7 @@ void __jbd2_journal_drop_transaction(journal_t *journal, transaction_t *transact
775 J_ASSERT(transaction->t_log_list == NULL); 775 J_ASSERT(transaction->t_log_list == NULL);
776 J_ASSERT(transaction->t_checkpoint_list == NULL); 776 J_ASSERT(transaction->t_checkpoint_list == NULL);
777 J_ASSERT(transaction->t_checkpoint_io_list == NULL); 777 J_ASSERT(transaction->t_checkpoint_io_list == NULL);
778 J_ASSERT(transaction->t_updates == 0); 778 J_ASSERT(atomic_read(&transaction->t_updates) == 0);
779 J_ASSERT(journal->j_committing_transaction != transaction); 779 J_ASSERT(journal->j_committing_transaction != transaction);
780 J_ASSERT(journal->j_running_transaction != transaction); 780 J_ASSERT(journal->j_running_transaction != transaction);
781 781
diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
index 75716d3d2be0..f52e5e8049f1 100644
--- a/fs/jbd2/commit.c
+++ b/fs/jbd2/commit.c
@@ -150,11 +150,11 @@ static int journal_submit_commit_record(journal_t *journal,
150 */ 150 */
151 if (ret == -EOPNOTSUPP && barrier_done) { 151 if (ret == -EOPNOTSUPP && barrier_done) {
152 printk(KERN_WARNING 152 printk(KERN_WARNING
153 "JBD: barrier-based sync failed on %s - " 153 "JBD2: Disabling barriers on %s, "
154 "disabling barriers\n", journal->j_devname); 154 "not supported by device\n", journal->j_devname);
155 spin_lock(&journal->j_state_lock); 155 write_lock(&journal->j_state_lock);
156 journal->j_flags &= ~JBD2_BARRIER; 156 journal->j_flags &= ~JBD2_BARRIER;
157 spin_unlock(&journal->j_state_lock); 157 write_unlock(&journal->j_state_lock);
158 158
159 /* And try again, without the barrier */ 159 /* And try again, without the barrier */
160 lock_buffer(bh); 160 lock_buffer(bh);
@@ -180,11 +180,11 @@ retry:
180 wait_on_buffer(bh); 180 wait_on_buffer(bh);
181 if (buffer_eopnotsupp(bh) && (journal->j_flags & JBD2_BARRIER)) { 181 if (buffer_eopnotsupp(bh) && (journal->j_flags & JBD2_BARRIER)) {
182 printk(KERN_WARNING 182 printk(KERN_WARNING
183 "JBD2: wait_on_commit_record: sync failed on %s - " 183 "JBD2: %s: disabling barries on %s - not supported "
184 "disabling barriers\n", journal->j_devname); 184 "by device\n", __func__, journal->j_devname);
185 spin_lock(&journal->j_state_lock); 185 write_lock(&journal->j_state_lock);
186 journal->j_flags &= ~JBD2_BARRIER; 186 journal->j_flags &= ~JBD2_BARRIER;
187 spin_unlock(&journal->j_state_lock); 187 write_unlock(&journal->j_state_lock);
188 188
189 lock_buffer(bh); 189 lock_buffer(bh);
190 clear_buffer_dirty(bh); 190 clear_buffer_dirty(bh);
@@ -400,7 +400,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
400 jbd_debug(1, "JBD: starting commit of transaction %d\n", 400 jbd_debug(1, "JBD: starting commit of transaction %d\n",
401 commit_transaction->t_tid); 401 commit_transaction->t_tid);
402 402
403 spin_lock(&journal->j_state_lock); 403 write_lock(&journal->j_state_lock);
404 commit_transaction->t_state = T_LOCKED; 404 commit_transaction->t_state = T_LOCKED;
405 405
406 /* 406 /*
@@ -417,23 +417,23 @@ void jbd2_journal_commit_transaction(journal_t *journal)
417 stats.run.rs_locked); 417 stats.run.rs_locked);
418 418
419 spin_lock(&commit_transaction->t_handle_lock); 419 spin_lock(&commit_transaction->t_handle_lock);
420 while (commit_transaction->t_updates) { 420 while (atomic_read(&commit_transaction->t_updates)) {
421 DEFINE_WAIT(wait); 421 DEFINE_WAIT(wait);
422 422
423 prepare_to_wait(&journal->j_wait_updates, &wait, 423 prepare_to_wait(&journal->j_wait_updates, &wait,
424 TASK_UNINTERRUPTIBLE); 424 TASK_UNINTERRUPTIBLE);
425 if (commit_transaction->t_updates) { 425 if (atomic_read(&commit_transaction->t_updates)) {
426 spin_unlock(&commit_transaction->t_handle_lock); 426 spin_unlock(&commit_transaction->t_handle_lock);
427 spin_unlock(&journal->j_state_lock); 427 write_unlock(&journal->j_state_lock);
428 schedule(); 428 schedule();
429 spin_lock(&journal->j_state_lock); 429 write_lock(&journal->j_state_lock);
430 spin_lock(&commit_transaction->t_handle_lock); 430 spin_lock(&commit_transaction->t_handle_lock);
431 } 431 }
432 finish_wait(&journal->j_wait_updates, &wait); 432 finish_wait(&journal->j_wait_updates, &wait);
433 } 433 }
434 spin_unlock(&commit_transaction->t_handle_lock); 434 spin_unlock(&commit_transaction->t_handle_lock);
435 435
436 J_ASSERT (commit_transaction->t_outstanding_credits <= 436 J_ASSERT (atomic_read(&commit_transaction->t_outstanding_credits) <=
437 journal->j_max_transaction_buffers); 437 journal->j_max_transaction_buffers);
438 438
439 /* 439 /*
@@ -497,7 +497,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
497 start_time = ktime_get(); 497 start_time = ktime_get();
498 commit_transaction->t_log_start = journal->j_head; 498 commit_transaction->t_log_start = journal->j_head;
499 wake_up(&journal->j_wait_transaction_locked); 499 wake_up(&journal->j_wait_transaction_locked);
500 spin_unlock(&journal->j_state_lock); 500 write_unlock(&journal->j_state_lock);
501 501
502 jbd_debug (3, "JBD: commit phase 2\n"); 502 jbd_debug (3, "JBD: commit phase 2\n");
503 503
@@ -519,19 +519,20 @@ void jbd2_journal_commit_transaction(journal_t *journal)
519 * transaction! Now comes the tricky part: we need to write out 519 * transaction! Now comes the tricky part: we need to write out
520 * metadata. Loop over the transaction's entire buffer list: 520 * metadata. Loop over the transaction's entire buffer list:
521 */ 521 */
522 spin_lock(&journal->j_state_lock); 522 write_lock(&journal->j_state_lock);
523 commit_transaction->t_state = T_COMMIT; 523 commit_transaction->t_state = T_COMMIT;
524 spin_unlock(&journal->j_state_lock); 524 write_unlock(&journal->j_state_lock);
525 525
526 trace_jbd2_commit_logging(journal, commit_transaction); 526 trace_jbd2_commit_logging(journal, commit_transaction);
527 stats.run.rs_logging = jiffies; 527 stats.run.rs_logging = jiffies;
528 stats.run.rs_flushing = jbd2_time_diff(stats.run.rs_flushing, 528 stats.run.rs_flushing = jbd2_time_diff(stats.run.rs_flushing,
529 stats.run.rs_logging); 529 stats.run.rs_logging);
530 stats.run.rs_blocks = commit_transaction->t_outstanding_credits; 530 stats.run.rs_blocks =
531 atomic_read(&commit_transaction->t_outstanding_credits);
531 stats.run.rs_blocks_logged = 0; 532 stats.run.rs_blocks_logged = 0;
532 533
533 J_ASSERT(commit_transaction->t_nr_buffers <= 534 J_ASSERT(commit_transaction->t_nr_buffers <=
534 commit_transaction->t_outstanding_credits); 535 atomic_read(&commit_transaction->t_outstanding_credits));
535 536
536 err = 0; 537 err = 0;
537 descriptor = NULL; 538 descriptor = NULL;
@@ -616,7 +617,7 @@ void jbd2_journal_commit_transaction(journal_t *journal)
616 * the free space in the log, but this counter is changed 617 * the free space in the log, but this counter is changed
617 * by jbd2_journal_next_log_block() also. 618 * by jbd2_journal_next_log_block() also.
618 */ 619 */
619 commit_transaction->t_outstanding_credits--; 620 atomic_dec(&commit_transaction->t_outstanding_credits);
620 621
621 /* Bump b_count to prevent truncate from stumbling over 622 /* Bump b_count to prevent truncate from stumbling over
622 the shadowed buffer! @@@ This can go if we ever get 623 the shadowed buffer! @@@ This can go if we ever get
@@ -977,7 +978,7 @@ restart_loop:
977 * __jbd2_journal_drop_transaction(). Otherwise we could race with 978 * __jbd2_journal_drop_transaction(). Otherwise we could race with
978 * other checkpointing code processing the transaction... 979 * other checkpointing code processing the transaction...
979 */ 980 */
980 spin_lock(&journal->j_state_lock); 981 write_lock(&journal->j_state_lock);
981 spin_lock(&journal->j_list_lock); 982 spin_lock(&journal->j_list_lock);
982 /* 983 /*
983 * Now recheck if some buffers did not get attached to the transaction 984 * Now recheck if some buffers did not get attached to the transaction
@@ -985,7 +986,7 @@ restart_loop:
985 */ 986 */
986 if (commit_transaction->t_forget) { 987 if (commit_transaction->t_forget) {
987 spin_unlock(&journal->j_list_lock); 988 spin_unlock(&journal->j_list_lock);
988 spin_unlock(&journal->j_state_lock); 989 write_unlock(&journal->j_state_lock);
989 goto restart_loop; 990 goto restart_loop;
990 } 991 }
991 992
@@ -1003,7 +1004,8 @@ restart_loop:
1003 * File the transaction statistics 1004 * File the transaction statistics
1004 */ 1005 */
1005 stats.ts_tid = commit_transaction->t_tid; 1006 stats.ts_tid = commit_transaction->t_tid;
1006 stats.run.rs_handle_count = commit_transaction->t_handle_count; 1007 stats.run.rs_handle_count =
1008 atomic_read(&commit_transaction->t_handle_count);
1007 trace_jbd2_run_stats(journal->j_fs_dev->bd_dev, 1009 trace_jbd2_run_stats(journal->j_fs_dev->bd_dev,
1008 commit_transaction->t_tid, &stats.run); 1010 commit_transaction->t_tid, &stats.run);
1009 1011
@@ -1037,7 +1039,7 @@ restart_loop:
1037 journal->j_average_commit_time*3) / 4; 1039 journal->j_average_commit_time*3) / 4;
1038 else 1040 else
1039 journal->j_average_commit_time = commit_time; 1041 journal->j_average_commit_time = commit_time;
1040 spin_unlock(&journal->j_state_lock); 1042 write_unlock(&journal->j_state_lock);
1041 1043
1042 if (commit_transaction->t_checkpoint_list == NULL && 1044 if (commit_transaction->t_checkpoint_list == NULL &&
1043 commit_transaction->t_checkpoint_io_list == NULL) { 1045 commit_transaction->t_checkpoint_io_list == NULL) {
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 036880895bfc..ad5866aaf0f9 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -41,6 +41,7 @@
41#include <linux/hash.h> 41#include <linux/hash.h>
42#include <linux/log2.h> 42#include <linux/log2.h>
43#include <linux/vmalloc.h> 43#include <linux/vmalloc.h>
44#include <linux/backing-dev.h>
44 45
45#define CREATE_TRACE_POINTS 46#define CREATE_TRACE_POINTS
46#include <trace/events/jbd2.h> 47#include <trace/events/jbd2.h>
@@ -48,8 +49,6 @@
48#include <asm/uaccess.h> 49#include <asm/uaccess.h>
49#include <asm/page.h> 50#include <asm/page.h>
50 51
51EXPORT_SYMBOL(jbd2_journal_start);
52EXPORT_SYMBOL(jbd2_journal_restart);
53EXPORT_SYMBOL(jbd2_journal_extend); 52EXPORT_SYMBOL(jbd2_journal_extend);
54EXPORT_SYMBOL(jbd2_journal_stop); 53EXPORT_SYMBOL(jbd2_journal_stop);
55EXPORT_SYMBOL(jbd2_journal_lock_updates); 54EXPORT_SYMBOL(jbd2_journal_lock_updates);
@@ -143,7 +142,7 @@ static int kjournald2(void *arg)
143 /* 142 /*
144 * And now, wait forever for commit wakeup events. 143 * And now, wait forever for commit wakeup events.
145 */ 144 */
146 spin_lock(&journal->j_state_lock); 145 write_lock(&journal->j_state_lock);
147 146
148loop: 147loop:
149 if (journal->j_flags & JBD2_UNMOUNT) 148 if (journal->j_flags & JBD2_UNMOUNT)
@@ -154,10 +153,10 @@ loop:
154 153
155 if (journal->j_commit_sequence != journal->j_commit_request) { 154 if (journal->j_commit_sequence != journal->j_commit_request) {
156 jbd_debug(1, "OK, requests differ\n"); 155 jbd_debug(1, "OK, requests differ\n");
157 spin_unlock(&journal->j_state_lock); 156 write_unlock(&journal->j_state_lock);
158 del_timer_sync(&journal->j_commit_timer); 157 del_timer_sync(&journal->j_commit_timer);
159 jbd2_journal_commit_transaction(journal); 158 jbd2_journal_commit_transaction(journal);
160 spin_lock(&journal->j_state_lock); 159 write_lock(&journal->j_state_lock);
161 goto loop; 160 goto loop;
162 } 161 }
163 162
@@ -169,9 +168,9 @@ loop:
169 * be already stopped. 168 * be already stopped.
170 */ 169 */
171 jbd_debug(1, "Now suspending kjournald2\n"); 170 jbd_debug(1, "Now suspending kjournald2\n");
172 spin_unlock(&journal->j_state_lock); 171 write_unlock(&journal->j_state_lock);
173 refrigerator(); 172 refrigerator();
174 spin_lock(&journal->j_state_lock); 173 write_lock(&journal->j_state_lock);
175 } else { 174 } else {
176 /* 175 /*
177 * We assume on resume that commits are already there, 176 * We assume on resume that commits are already there,
@@ -191,9 +190,9 @@ loop:
191 if (journal->j_flags & JBD2_UNMOUNT) 190 if (journal->j_flags & JBD2_UNMOUNT)
192 should_sleep = 0; 191 should_sleep = 0;
193 if (should_sleep) { 192 if (should_sleep) {
194 spin_unlock(&journal->j_state_lock); 193 write_unlock(&journal->j_state_lock);
195 schedule(); 194 schedule();
196 spin_lock(&journal->j_state_lock); 195 write_lock(&journal->j_state_lock);
197 } 196 }
198 finish_wait(&journal->j_wait_commit, &wait); 197 finish_wait(&journal->j_wait_commit, &wait);
199 } 198 }
@@ -211,7 +210,7 @@ loop:
211 goto loop; 210 goto loop;
212 211
213end_loop: 212end_loop:
214 spin_unlock(&journal->j_state_lock); 213 write_unlock(&journal->j_state_lock);
215 del_timer_sync(&journal->j_commit_timer); 214 del_timer_sync(&journal->j_commit_timer);
216 journal->j_task = NULL; 215 journal->j_task = NULL;
217 wake_up(&journal->j_wait_done_commit); 216 wake_up(&journal->j_wait_done_commit);
@@ -234,16 +233,16 @@ static int jbd2_journal_start_thread(journal_t *journal)
234 233
235static void journal_kill_thread(journal_t *journal) 234static void journal_kill_thread(journal_t *journal)
236{ 235{
237 spin_lock(&journal->j_state_lock); 236 write_lock(&journal->j_state_lock);
238 journal->j_flags |= JBD2_UNMOUNT; 237 journal->j_flags |= JBD2_UNMOUNT;
239 238
240 while (journal->j_task) { 239 while (journal->j_task) {
241 wake_up(&journal->j_wait_commit); 240 wake_up(&journal->j_wait_commit);
242 spin_unlock(&journal->j_state_lock); 241 write_unlock(&journal->j_state_lock);
243 wait_event(journal->j_wait_done_commit, journal->j_task == NULL); 242 wait_event(journal->j_wait_done_commit, journal->j_task == NULL);
244 spin_lock(&journal->j_state_lock); 243 write_lock(&journal->j_state_lock);
245 } 244 }
246 spin_unlock(&journal->j_state_lock); 245 write_unlock(&journal->j_state_lock);
247} 246}
248 247
249/* 248/*
@@ -310,7 +309,17 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
310 */ 309 */
311 J_ASSERT_BH(bh_in, buffer_jbddirty(bh_in)); 310 J_ASSERT_BH(bh_in, buffer_jbddirty(bh_in));
312 311
313 new_bh = alloc_buffer_head(GFP_NOFS|__GFP_NOFAIL); 312retry_alloc:
313 new_bh = alloc_buffer_head(GFP_NOFS);
314 if (!new_bh) {
315 /*
316 * Failure is not an option, but __GFP_NOFAIL is going
317 * away; so we retry ourselves here.
318 */
319 congestion_wait(BLK_RW_ASYNC, HZ/50);
320 goto retry_alloc;
321 }
322
314 /* keep subsequent assertions sane */ 323 /* keep subsequent assertions sane */
315 new_bh->b_state = 0; 324 new_bh->b_state = 0;
316 init_buffer(new_bh, NULL, NULL); 325 init_buffer(new_bh, NULL, NULL);
@@ -442,7 +451,7 @@ int __jbd2_log_space_left(journal_t *journal)
442{ 451{
443 int left = journal->j_free; 452 int left = journal->j_free;
444 453
445 assert_spin_locked(&journal->j_state_lock); 454 /* assert_spin_locked(&journal->j_state_lock); */
446 455
447 /* 456 /*
448 * Be pessimistic here about the number of those free blocks which 457 * Be pessimistic here about the number of those free blocks which
@@ -487,9 +496,9 @@ int jbd2_log_start_commit(journal_t *journal, tid_t tid)
487{ 496{
488 int ret; 497 int ret;
489 498
490 spin_lock(&journal->j_state_lock); 499 write_lock(&journal->j_state_lock);
491 ret = __jbd2_log_start_commit(journal, tid); 500 ret = __jbd2_log_start_commit(journal, tid);
492 spin_unlock(&journal->j_state_lock); 501 write_unlock(&journal->j_state_lock);
493 return ret; 502 return ret;
494} 503}
495 504
@@ -508,7 +517,7 @@ int jbd2_journal_force_commit_nested(journal_t *journal)
508 transaction_t *transaction = NULL; 517 transaction_t *transaction = NULL;
509 tid_t tid; 518 tid_t tid;
510 519
511 spin_lock(&journal->j_state_lock); 520 read_lock(&journal->j_state_lock);
512 if (journal->j_running_transaction && !current->journal_info) { 521 if (journal->j_running_transaction && !current->journal_info) {
513 transaction = journal->j_running_transaction; 522 transaction = journal->j_running_transaction;
514 __jbd2_log_start_commit(journal, transaction->t_tid); 523 __jbd2_log_start_commit(journal, transaction->t_tid);
@@ -516,12 +525,12 @@ int jbd2_journal_force_commit_nested(journal_t *journal)
516 transaction = journal->j_committing_transaction; 525 transaction = journal->j_committing_transaction;
517 526
518 if (!transaction) { 527 if (!transaction) {
519 spin_unlock(&journal->j_state_lock); 528 read_unlock(&journal->j_state_lock);
520 return 0; /* Nothing to retry */ 529 return 0; /* Nothing to retry */
521 } 530 }
522 531
523 tid = transaction->t_tid; 532 tid = transaction->t_tid;
524 spin_unlock(&journal->j_state_lock); 533 read_unlock(&journal->j_state_lock);
525 jbd2_log_wait_commit(journal, tid); 534 jbd2_log_wait_commit(journal, tid);
526 return 1; 535 return 1;
527} 536}
@@ -535,7 +544,7 @@ int jbd2_journal_start_commit(journal_t *journal, tid_t *ptid)
535{ 544{
536 int ret = 0; 545 int ret = 0;
537 546
538 spin_lock(&journal->j_state_lock); 547 write_lock(&journal->j_state_lock);
539 if (journal->j_running_transaction) { 548 if (journal->j_running_transaction) {
540 tid_t tid = journal->j_running_transaction->t_tid; 549 tid_t tid = journal->j_running_transaction->t_tid;
541 550
@@ -554,7 +563,7 @@ int jbd2_journal_start_commit(journal_t *journal, tid_t *ptid)
554 *ptid = journal->j_committing_transaction->t_tid; 563 *ptid = journal->j_committing_transaction->t_tid;
555 ret = 1; 564 ret = 1;
556 } 565 }
557 spin_unlock(&journal->j_state_lock); 566 write_unlock(&journal->j_state_lock);
558 return ret; 567 return ret;
559} 568}
560 569
@@ -566,26 +575,24 @@ int jbd2_log_wait_commit(journal_t *journal, tid_t tid)
566{ 575{
567 int err = 0; 576 int err = 0;
568 577
578 read_lock(&journal->j_state_lock);
569#ifdef CONFIG_JBD2_DEBUG 579#ifdef CONFIG_JBD2_DEBUG
570 spin_lock(&journal->j_state_lock);
571 if (!tid_geq(journal->j_commit_request, tid)) { 580 if (!tid_geq(journal->j_commit_request, tid)) {
572 printk(KERN_EMERG 581 printk(KERN_EMERG
573 "%s: error: j_commit_request=%d, tid=%d\n", 582 "%s: error: j_commit_request=%d, tid=%d\n",
574 __func__, journal->j_commit_request, tid); 583 __func__, journal->j_commit_request, tid);
575 } 584 }
576 spin_unlock(&journal->j_state_lock);
577#endif 585#endif
578 spin_lock(&journal->j_state_lock);
579 while (tid_gt(tid, journal->j_commit_sequence)) { 586 while (tid_gt(tid, journal->j_commit_sequence)) {
580 jbd_debug(1, "JBD: want %d, j_commit_sequence=%d\n", 587 jbd_debug(1, "JBD: want %d, j_commit_sequence=%d\n",
581 tid, journal->j_commit_sequence); 588 tid, journal->j_commit_sequence);
582 wake_up(&journal->j_wait_commit); 589 wake_up(&journal->j_wait_commit);
583 spin_unlock(&journal->j_state_lock); 590 read_unlock(&journal->j_state_lock);
584 wait_event(journal->j_wait_done_commit, 591 wait_event(journal->j_wait_done_commit,
585 !tid_gt(tid, journal->j_commit_sequence)); 592 !tid_gt(tid, journal->j_commit_sequence));
586 spin_lock(&journal->j_state_lock); 593 read_lock(&journal->j_state_lock);
587 } 594 }
588 spin_unlock(&journal->j_state_lock); 595 read_unlock(&journal->j_state_lock);
589 596
590 if (unlikely(is_journal_aborted(journal))) { 597 if (unlikely(is_journal_aborted(journal))) {
591 printk(KERN_EMERG "journal commit I/O error\n"); 598 printk(KERN_EMERG "journal commit I/O error\n");
@@ -602,7 +609,7 @@ int jbd2_journal_next_log_block(journal_t *journal, unsigned long long *retp)
602{ 609{
603 unsigned long blocknr; 610 unsigned long blocknr;
604 611
605 spin_lock(&journal->j_state_lock); 612 write_lock(&journal->j_state_lock);
606 J_ASSERT(journal->j_free > 1); 613 J_ASSERT(journal->j_free > 1);
607 614
608 blocknr = journal->j_head; 615 blocknr = journal->j_head;
@@ -610,7 +617,7 @@ int jbd2_journal_next_log_block(journal_t *journal, unsigned long long *retp)
610 journal->j_free--; 617 journal->j_free--;
611 if (journal->j_head == journal->j_last) 618 if (journal->j_head == journal->j_last)
612 journal->j_head = journal->j_first; 619 journal->j_head = journal->j_first;
613 spin_unlock(&journal->j_state_lock); 620 write_unlock(&journal->j_state_lock);
614 return jbd2_journal_bmap(journal, blocknr, retp); 621 return jbd2_journal_bmap(journal, blocknr, retp);
615} 622}
616 623
@@ -830,7 +837,7 @@ static journal_t * journal_init_common (void)
830 mutex_init(&journal->j_checkpoint_mutex); 837 mutex_init(&journal->j_checkpoint_mutex);
831 spin_lock_init(&journal->j_revoke_lock); 838 spin_lock_init(&journal->j_revoke_lock);
832 spin_lock_init(&journal->j_list_lock); 839 spin_lock_init(&journal->j_list_lock);
833 spin_lock_init(&journal->j_state_lock); 840 rwlock_init(&journal->j_state_lock);
834 841
835 journal->j_commit_interval = (HZ * JBD2_DEFAULT_MAX_COMMIT_AGE); 842 journal->j_commit_interval = (HZ * JBD2_DEFAULT_MAX_COMMIT_AGE);
836 journal->j_min_batch_time = 0; 843 journal->j_min_batch_time = 0;
@@ -1096,14 +1103,14 @@ void jbd2_journal_update_superblock(journal_t *journal, int wait)
1096 set_buffer_uptodate(bh); 1103 set_buffer_uptodate(bh);
1097 } 1104 }
1098 1105
1099 spin_lock(&journal->j_state_lock); 1106 read_lock(&journal->j_state_lock);
1100 jbd_debug(1,"JBD: updating superblock (start %ld, seq %d, errno %d)\n", 1107 jbd_debug(1,"JBD: updating superblock (start %ld, seq %d, errno %d)\n",
1101 journal->j_tail, journal->j_tail_sequence, journal->j_errno); 1108 journal->j_tail, journal->j_tail_sequence, journal->j_errno);
1102 1109
1103 sb->s_sequence = cpu_to_be32(journal->j_tail_sequence); 1110 sb->s_sequence = cpu_to_be32(journal->j_tail_sequence);
1104 sb->s_start = cpu_to_be32(journal->j_tail); 1111 sb->s_start = cpu_to_be32(journal->j_tail);
1105 sb->s_errno = cpu_to_be32(journal->j_errno); 1112 sb->s_errno = cpu_to_be32(journal->j_errno);
1106 spin_unlock(&journal->j_state_lock); 1113 read_unlock(&journal->j_state_lock);
1107 1114
1108 BUFFER_TRACE(bh, "marking dirty"); 1115 BUFFER_TRACE(bh, "marking dirty");
1109 mark_buffer_dirty(bh); 1116 mark_buffer_dirty(bh);
@@ -1124,12 +1131,12 @@ out:
1124 * any future commit will have to be careful to update the 1131 * any future commit will have to be careful to update the
1125 * superblock again to re-record the true start of the log. */ 1132 * superblock again to re-record the true start of the log. */
1126 1133
1127 spin_lock(&journal->j_state_lock); 1134 write_lock(&journal->j_state_lock);
1128 if (sb->s_start) 1135 if (sb->s_start)
1129 journal->j_flags &= ~JBD2_FLUSHED; 1136 journal->j_flags &= ~JBD2_FLUSHED;
1130 else 1137 else
1131 journal->j_flags |= JBD2_FLUSHED; 1138 journal->j_flags |= JBD2_FLUSHED;
1132 spin_unlock(&journal->j_state_lock); 1139 write_unlock(&journal->j_state_lock);
1133} 1140}
1134 1141
1135/* 1142/*
@@ -1391,13 +1398,9 @@ int jbd2_journal_check_used_features (journal_t *journal, unsigned long compat,
1391int jbd2_journal_check_available_features (journal_t *journal, unsigned long compat, 1398int jbd2_journal_check_available_features (journal_t *journal, unsigned long compat,
1392 unsigned long ro, unsigned long incompat) 1399 unsigned long ro, unsigned long incompat)
1393{ 1400{
1394 journal_superblock_t *sb;
1395
1396 if (!compat && !ro && !incompat) 1401 if (!compat && !ro && !incompat)
1397 return 1; 1402 return 1;
1398 1403
1399 sb = journal->j_superblock;
1400
1401 /* We can support any known requested features iff the 1404 /* We can support any known requested features iff the
1402 * superblock is in version 2. Otherwise we fail to support any 1405 * superblock is in version 2. Otherwise we fail to support any
1403 * extended sb features. */ 1406 * extended sb features. */
@@ -1545,7 +1548,7 @@ int jbd2_journal_flush(journal_t *journal)
1545 transaction_t *transaction = NULL; 1548 transaction_t *transaction = NULL;
1546 unsigned long old_tail; 1549 unsigned long old_tail;
1547 1550
1548 spin_lock(&journal->j_state_lock); 1551 write_lock(&journal->j_state_lock);
1549 1552
1550 /* Force everything buffered to the log... */ 1553 /* Force everything buffered to the log... */
1551 if (journal->j_running_transaction) { 1554 if (journal->j_running_transaction) {
@@ -1558,10 +1561,10 @@ int jbd2_journal_flush(journal_t *journal)
1558 if (transaction) { 1561 if (transaction) {
1559 tid_t tid = transaction->t_tid; 1562 tid_t tid = transaction->t_tid;
1560 1563
1561 spin_unlock(&journal->j_state_lock); 1564 write_unlock(&journal->j_state_lock);
1562 jbd2_log_wait_commit(journal, tid); 1565 jbd2_log_wait_commit(journal, tid);
1563 } else { 1566 } else {
1564 spin_unlock(&journal->j_state_lock); 1567 write_unlock(&journal->j_state_lock);
1565 } 1568 }
1566 1569
1567 /* ...and flush everything in the log out to disk. */ 1570 /* ...and flush everything in the log out to disk. */
@@ -1585,12 +1588,12 @@ int jbd2_journal_flush(journal_t *journal)
1585 * the magic code for a fully-recovered superblock. Any future 1588 * the magic code for a fully-recovered superblock. Any future
1586 * commits of data to the journal will restore the current 1589 * commits of data to the journal will restore the current
1587 * s_start value. */ 1590 * s_start value. */
1588 spin_lock(&journal->j_state_lock); 1591 write_lock(&journal->j_state_lock);
1589 old_tail = journal->j_tail; 1592 old_tail = journal->j_tail;
1590 journal->j_tail = 0; 1593 journal->j_tail = 0;
1591 spin_unlock(&journal->j_state_lock); 1594 write_unlock(&journal->j_state_lock);
1592 jbd2_journal_update_superblock(journal, 1); 1595 jbd2_journal_update_superblock(journal, 1);
1593 spin_lock(&journal->j_state_lock); 1596 write_lock(&journal->j_state_lock);
1594 journal->j_tail = old_tail; 1597 journal->j_tail = old_tail;
1595 1598
1596 J_ASSERT(!journal->j_running_transaction); 1599 J_ASSERT(!journal->j_running_transaction);
@@ -1598,7 +1601,7 @@ int jbd2_journal_flush(journal_t *journal)
1598 J_ASSERT(!journal->j_checkpoint_transactions); 1601 J_ASSERT(!journal->j_checkpoint_transactions);
1599 J_ASSERT(journal->j_head == journal->j_tail); 1602 J_ASSERT(journal->j_head == journal->j_tail);
1600 J_ASSERT(journal->j_tail_sequence == journal->j_transaction_sequence); 1603 J_ASSERT(journal->j_tail_sequence == journal->j_transaction_sequence);
1601 spin_unlock(&journal->j_state_lock); 1604 write_unlock(&journal->j_state_lock);
1602 return 0; 1605 return 0;
1603} 1606}
1604 1607
@@ -1617,7 +1620,6 @@ int jbd2_journal_flush(journal_t *journal)
1617 1620
1618int jbd2_journal_wipe(journal_t *journal, int write) 1621int jbd2_journal_wipe(journal_t *journal, int write)
1619{ 1622{
1620 journal_superblock_t *sb;
1621 int err = 0; 1623 int err = 0;
1622 1624
1623 J_ASSERT (!(journal->j_flags & JBD2_LOADED)); 1625 J_ASSERT (!(journal->j_flags & JBD2_LOADED));
@@ -1626,8 +1628,6 @@ int jbd2_journal_wipe(journal_t *journal, int write)
1626 if (err) 1628 if (err)
1627 return err; 1629 return err;
1628 1630
1629 sb = journal->j_superblock;
1630
1631 if (!journal->j_tail) 1631 if (!journal->j_tail)
1632 goto no_recovery; 1632 goto no_recovery;
1633 1633
@@ -1665,12 +1665,12 @@ void __jbd2_journal_abort_hard(journal_t *journal)
1665 printk(KERN_ERR "Aborting journal on device %s.\n", 1665 printk(KERN_ERR "Aborting journal on device %s.\n",
1666 journal->j_devname); 1666 journal->j_devname);
1667 1667
1668 spin_lock(&journal->j_state_lock); 1668 write_lock(&journal->j_state_lock);
1669 journal->j_flags |= JBD2_ABORT; 1669 journal->j_flags |= JBD2_ABORT;
1670 transaction = journal->j_running_transaction; 1670 transaction = journal->j_running_transaction;
1671 if (transaction) 1671 if (transaction)
1672 __jbd2_log_start_commit(journal, transaction->t_tid); 1672 __jbd2_log_start_commit(journal, transaction->t_tid);
1673 spin_unlock(&journal->j_state_lock); 1673 write_unlock(&journal->j_state_lock);
1674} 1674}
1675 1675
1676/* Soft abort: record the abort error status in the journal superblock, 1676/* Soft abort: record the abort error status in the journal superblock,
@@ -1755,12 +1755,12 @@ int jbd2_journal_errno(journal_t *journal)
1755{ 1755{
1756 int err; 1756 int err;
1757 1757
1758 spin_lock(&journal->j_state_lock); 1758 read_lock(&journal->j_state_lock);
1759 if (journal->j_flags & JBD2_ABORT) 1759 if (journal->j_flags & JBD2_ABORT)
1760 err = -EROFS; 1760 err = -EROFS;
1761 else 1761 else
1762 err = journal->j_errno; 1762 err = journal->j_errno;
1763 spin_unlock(&journal->j_state_lock); 1763 read_unlock(&journal->j_state_lock);
1764 return err; 1764 return err;
1765} 1765}
1766 1766
@@ -1775,12 +1775,12 @@ int jbd2_journal_clear_err(journal_t *journal)
1775{ 1775{
1776 int err = 0; 1776 int err = 0;
1777 1777
1778 spin_lock(&journal->j_state_lock); 1778 write_lock(&journal->j_state_lock);
1779 if (journal->j_flags & JBD2_ABORT) 1779 if (journal->j_flags & JBD2_ABORT)
1780 err = -EROFS; 1780 err = -EROFS;
1781 else 1781 else
1782 journal->j_errno = 0; 1782 journal->j_errno = 0;
1783 spin_unlock(&journal->j_state_lock); 1783 write_unlock(&journal->j_state_lock);
1784 return err; 1784 return err;
1785} 1785}
1786 1786
@@ -1793,10 +1793,10 @@ int jbd2_journal_clear_err(journal_t *journal)
1793 */ 1793 */
1794void jbd2_journal_ack_err(journal_t *journal) 1794void jbd2_journal_ack_err(journal_t *journal)
1795{ 1795{
1796 spin_lock(&journal->j_state_lock); 1796 write_lock(&journal->j_state_lock);
1797 if (journal->j_errno) 1797 if (journal->j_errno)
1798 journal->j_flags |= JBD2_ACK_ERR; 1798 journal->j_flags |= JBD2_ACK_ERR;
1799 spin_unlock(&journal->j_state_lock); 1799 write_unlock(&journal->j_state_lock);
1800} 1800}
1801 1801
1802int jbd2_journal_blocks_per_page(struct inode *inode) 1802int jbd2_journal_blocks_per_page(struct inode *inode)
@@ -2201,8 +2201,6 @@ void jbd2_journal_init_jbd_inode(struct jbd2_inode *jinode, struct inode *inode)
2201void jbd2_journal_release_jbd_inode(journal_t *journal, 2201void jbd2_journal_release_jbd_inode(journal_t *journal,
2202 struct jbd2_inode *jinode) 2202 struct jbd2_inode *jinode)
2203{ 2203{
2204 int writeout = 0;
2205
2206 if (!journal) 2204 if (!journal)
2207 return; 2205 return;
2208restart: 2206restart:
@@ -2219,9 +2217,6 @@ restart:
2219 goto restart; 2217 goto restart;
2220 } 2218 }
2221 2219
2222 /* Do we need to wait for data writeback? */
2223 if (journal->j_committing_transaction == jinode->i_transaction)
2224 writeout = 1;
2225 if (jinode->i_transaction) { 2220 if (jinode->i_transaction) {
2226 list_del(&jinode->i_list); 2221 list_del(&jinode->i_list);
2227 jinode->i_transaction = NULL; 2222 jinode->i_transaction = NULL;
diff --git a/fs/jbd2/recovery.c b/fs/jbd2/recovery.c
index 049281b7cb89..2bc4d5f116f1 100644
--- a/fs/jbd2/recovery.c
+++ b/fs/jbd2/recovery.c
@@ -285,12 +285,10 @@ int jbd2_journal_recover(journal_t *journal)
285int jbd2_journal_skip_recovery(journal_t *journal) 285int jbd2_journal_skip_recovery(journal_t *journal)
286{ 286{
287 int err; 287 int err;
288 journal_superblock_t * sb;
289 288
290 struct recovery_info info; 289 struct recovery_info info;
291 290
292 memset (&info, 0, sizeof(info)); 291 memset (&info, 0, sizeof(info));
293 sb = journal->j_superblock;
294 292
295 err = do_one_pass(journal, &info, PASS_SCAN); 293 err = do_one_pass(journal, &info, PASS_SCAN);
296 294
@@ -299,7 +297,8 @@ int jbd2_journal_skip_recovery(journal_t *journal)
299 ++journal->j_transaction_sequence; 297 ++journal->j_transaction_sequence;
300 } else { 298 } else {
301#ifdef CONFIG_JBD2_DEBUG 299#ifdef CONFIG_JBD2_DEBUG
302 int dropped = info.end_transaction - be32_to_cpu(sb->s_sequence); 300 int dropped = info.end_transaction -
301 be32_to_cpu(journal->j_superblock->s_sequence);
303#endif 302#endif
304 jbd_debug(1, 303 jbd_debug(1,
305 "JBD: ignoring %d transaction%s from the journal.\n", 304 "JBD: ignoring %d transaction%s from the journal.\n",
@@ -365,11 +364,6 @@ static int do_one_pass(journal_t *journal,
365 int tag_bytes = journal_tag_bytes(journal); 364 int tag_bytes = journal_tag_bytes(journal);
366 __u32 crc32_sum = ~0; /* Transactional Checksums */ 365 __u32 crc32_sum = ~0; /* Transactional Checksums */
367 366
368 /* Precompute the maximum metadata descriptors in a descriptor block */
369 int MAX_BLOCKS_PER_DESC;
370 MAX_BLOCKS_PER_DESC = ((journal->j_blocksize-sizeof(journal_header_t))
371 / tag_bytes);
372
373 /* 367 /*
374 * First thing is to establish what we expect to find in the log 368 * First thing is to establish what we expect to find in the log
375 * (in terms of transaction IDs), and where (in terms of log 369 * (in terms of transaction IDs), and where (in terms of log
diff --git a/fs/jbd2/transaction.c b/fs/jbd2/transaction.c
index b8e0806681bb..d95cc9d0401d 100644
--- a/fs/jbd2/transaction.c
+++ b/fs/jbd2/transaction.c
@@ -26,6 +26,8 @@
26#include <linux/mm.h> 26#include <linux/mm.h>
27#include <linux/highmem.h> 27#include <linux/highmem.h>
28#include <linux/hrtimer.h> 28#include <linux/hrtimer.h>
29#include <linux/backing-dev.h>
30#include <linux/module.h>
29 31
30static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh); 32static void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh);
31 33
@@ -53,6 +55,9 @@ jbd2_get_transaction(journal_t *journal, transaction_t *transaction)
53 transaction->t_tid = journal->j_transaction_sequence++; 55 transaction->t_tid = journal->j_transaction_sequence++;
54 transaction->t_expires = jiffies + journal->j_commit_interval; 56 transaction->t_expires = jiffies + journal->j_commit_interval;
55 spin_lock_init(&transaction->t_handle_lock); 57 spin_lock_init(&transaction->t_handle_lock);
58 atomic_set(&transaction->t_updates, 0);
59 atomic_set(&transaction->t_outstanding_credits, 0);
60 atomic_set(&transaction->t_handle_count, 0);
56 INIT_LIST_HEAD(&transaction->t_inode_list); 61 INIT_LIST_HEAD(&transaction->t_inode_list);
57 INIT_LIST_HEAD(&transaction->t_private_list); 62 INIT_LIST_HEAD(&transaction->t_private_list);
58 63
@@ -83,65 +88,75 @@ jbd2_get_transaction(journal_t *journal, transaction_t *transaction)
83 * transaction's buffer credits. 88 * transaction's buffer credits.
84 */ 89 */
85 90
86static int start_this_handle(journal_t *journal, handle_t *handle) 91static int start_this_handle(journal_t *journal, handle_t *handle,
92 int gfp_mask)
87{ 93{
88 transaction_t *transaction; 94 transaction_t *transaction;
89 int needed; 95 int needed;
90 int nblocks = handle->h_buffer_credits; 96 int nblocks = handle->h_buffer_credits;
91 transaction_t *new_transaction = NULL; 97 transaction_t *new_transaction = NULL;
92 int ret = 0;
93 unsigned long ts = jiffies; 98 unsigned long ts = jiffies;
94 99
95 if (nblocks > journal->j_max_transaction_buffers) { 100 if (nblocks > journal->j_max_transaction_buffers) {
96 printk(KERN_ERR "JBD: %s wants too many credits (%d > %d)\n", 101 printk(KERN_ERR "JBD: %s wants too many credits (%d > %d)\n",
97 current->comm, nblocks, 102 current->comm, nblocks,
98 journal->j_max_transaction_buffers); 103 journal->j_max_transaction_buffers);
99 ret = -ENOSPC; 104 return -ENOSPC;
100 goto out;
101 } 105 }
102 106
103alloc_transaction: 107alloc_transaction:
104 if (!journal->j_running_transaction) { 108 if (!journal->j_running_transaction) {
105 new_transaction = kzalloc(sizeof(*new_transaction), 109 new_transaction = kzalloc(sizeof(*new_transaction), gfp_mask);
106 GFP_NOFS|__GFP_NOFAIL);
107 if (!new_transaction) { 110 if (!new_transaction) {
108 ret = -ENOMEM; 111 /*
109 goto out; 112 * If __GFP_FS is not present, then we may be
113 * being called from inside the fs writeback
114 * layer, so we MUST NOT fail. Since
115 * __GFP_NOFAIL is going away, we will arrange
116 * to retry the allocation ourselves.
117 */
118 if ((gfp_mask & __GFP_FS) == 0) {
119 congestion_wait(BLK_RW_ASYNC, HZ/50);
120 goto alloc_transaction;
121 }
122 return -ENOMEM;
110 } 123 }
111 } 124 }
112 125
113 jbd_debug(3, "New handle %p going live.\n", handle); 126 jbd_debug(3, "New handle %p going live.\n", handle);
114 127
115repeat:
116
117 /* 128 /*
118 * We need to hold j_state_lock until t_updates has been incremented, 129 * We need to hold j_state_lock until t_updates has been incremented,
119 * for proper journal barrier handling 130 * for proper journal barrier handling
120 */ 131 */
121 spin_lock(&journal->j_state_lock); 132repeat:
122repeat_locked: 133 read_lock(&journal->j_state_lock);
123 if (is_journal_aborted(journal) || 134 if (is_journal_aborted(journal) ||
124 (journal->j_errno != 0 && !(journal->j_flags & JBD2_ACK_ERR))) { 135 (journal->j_errno != 0 && !(journal->j_flags & JBD2_ACK_ERR))) {
125 spin_unlock(&journal->j_state_lock); 136 read_unlock(&journal->j_state_lock);
126 ret = -EROFS; 137 kfree(new_transaction);
127 goto out; 138 return -EROFS;
128 } 139 }
129 140
130 /* Wait on the journal's transaction barrier if necessary */ 141 /* Wait on the journal's transaction barrier if necessary */
131 if (journal->j_barrier_count) { 142 if (journal->j_barrier_count) {
132 spin_unlock(&journal->j_state_lock); 143 read_unlock(&journal->j_state_lock);
133 wait_event(journal->j_wait_transaction_locked, 144 wait_event(journal->j_wait_transaction_locked,
134 journal->j_barrier_count == 0); 145 journal->j_barrier_count == 0);
135 goto repeat; 146 goto repeat;
136 } 147 }
137 148
138 if (!journal->j_running_transaction) { 149 if (!journal->j_running_transaction) {
139 if (!new_transaction) { 150 read_unlock(&journal->j_state_lock);
140 spin_unlock(&journal->j_state_lock); 151 if (!new_transaction)
141 goto alloc_transaction; 152 goto alloc_transaction;
153 write_lock(&journal->j_state_lock);
154 if (!journal->j_running_transaction) {
155 jbd2_get_transaction(journal, new_transaction);
156 new_transaction = NULL;
142 } 157 }
143 jbd2_get_transaction(journal, new_transaction); 158 write_unlock(&journal->j_state_lock);
144 new_transaction = NULL; 159 goto repeat;
145 } 160 }
146 161
147 transaction = journal->j_running_transaction; 162 transaction = journal->j_running_transaction;
@@ -155,7 +170,7 @@ repeat_locked:
155 170
156 prepare_to_wait(&journal->j_wait_transaction_locked, 171 prepare_to_wait(&journal->j_wait_transaction_locked,
157 &wait, TASK_UNINTERRUPTIBLE); 172 &wait, TASK_UNINTERRUPTIBLE);
158 spin_unlock(&journal->j_state_lock); 173 read_unlock(&journal->j_state_lock);
159 schedule(); 174 schedule();
160 finish_wait(&journal->j_wait_transaction_locked, &wait); 175 finish_wait(&journal->j_wait_transaction_locked, &wait);
161 goto repeat; 176 goto repeat;
@@ -166,8 +181,8 @@ repeat_locked:
166 * buffers requested by this operation, we need to stall pending a log 181 * buffers requested by this operation, we need to stall pending a log
167 * checkpoint to free some more log space. 182 * checkpoint to free some more log space.
168 */ 183 */
169 spin_lock(&transaction->t_handle_lock); 184 needed = atomic_add_return(nblocks,
170 needed = transaction->t_outstanding_credits + nblocks; 185 &transaction->t_outstanding_credits);
171 186
172 if (needed > journal->j_max_transaction_buffers) { 187 if (needed > journal->j_max_transaction_buffers) {
173 /* 188 /*
@@ -178,11 +193,11 @@ repeat_locked:
178 DEFINE_WAIT(wait); 193 DEFINE_WAIT(wait);
179 194
180 jbd_debug(2, "Handle %p starting new commit...\n", handle); 195 jbd_debug(2, "Handle %p starting new commit...\n", handle);
181 spin_unlock(&transaction->t_handle_lock); 196 atomic_sub(nblocks, &transaction->t_outstanding_credits);
182 prepare_to_wait(&journal->j_wait_transaction_locked, &wait, 197 prepare_to_wait(&journal->j_wait_transaction_locked, &wait,
183 TASK_UNINTERRUPTIBLE); 198 TASK_UNINTERRUPTIBLE);
184 __jbd2_log_start_commit(journal, transaction->t_tid); 199 __jbd2_log_start_commit(journal, transaction->t_tid);
185 spin_unlock(&journal->j_state_lock); 200 read_unlock(&journal->j_state_lock);
186 schedule(); 201 schedule();
187 finish_wait(&journal->j_wait_transaction_locked, &wait); 202 finish_wait(&journal->j_wait_transaction_locked, &wait);
188 goto repeat; 203 goto repeat;
@@ -215,35 +230,48 @@ repeat_locked:
215 */ 230 */
216 if (__jbd2_log_space_left(journal) < jbd_space_needed(journal)) { 231 if (__jbd2_log_space_left(journal) < jbd_space_needed(journal)) {
217 jbd_debug(2, "Handle %p waiting for checkpoint...\n", handle); 232 jbd_debug(2, "Handle %p waiting for checkpoint...\n", handle);
218 spin_unlock(&transaction->t_handle_lock); 233 atomic_sub(nblocks, &transaction->t_outstanding_credits);
219 __jbd2_log_wait_for_space(journal); 234 read_unlock(&journal->j_state_lock);
220 goto repeat_locked; 235 write_lock(&journal->j_state_lock);
236 if (__jbd2_log_space_left(journal) < jbd_space_needed(journal))
237 __jbd2_log_wait_for_space(journal);
238 write_unlock(&journal->j_state_lock);
239 goto repeat;
221 } 240 }
222 241
223 /* OK, account for the buffers that this operation expects to 242 /* OK, account for the buffers that this operation expects to
224 * use and add the handle to the running transaction. */ 243 * use and add the handle to the running transaction.
225 244 *
226 if (time_after(transaction->t_start, ts)) { 245 * In order for t_max_wait to be reliable, it must be
246 * protected by a lock. But doing so will mean that
247 * start_this_handle() can not be run in parallel on SMP
248 * systems, which limits our scalability. So we only enable
249 * it when debugging is enabled. We may want to use a
250 * separate flag, eventually, so we can enable this
251 * independently of debugging.
252 */
253#ifdef CONFIG_JBD2_DEBUG
254 if (jbd2_journal_enable_debug &&
255 time_after(transaction->t_start, ts)) {
227 ts = jbd2_time_diff(ts, transaction->t_start); 256 ts = jbd2_time_diff(ts, transaction->t_start);
257 spin_lock(&transaction->t_handle_lock);
228 if (ts > transaction->t_max_wait) 258 if (ts > transaction->t_max_wait)
229 transaction->t_max_wait = ts; 259 transaction->t_max_wait = ts;
260 spin_unlock(&transaction->t_handle_lock);
230 } 261 }
231 262#endif
232 handle->h_transaction = transaction; 263 handle->h_transaction = transaction;
233 transaction->t_outstanding_credits += nblocks; 264 atomic_inc(&transaction->t_updates);
234 transaction->t_updates++; 265 atomic_inc(&transaction->t_handle_count);
235 transaction->t_handle_count++;
236 jbd_debug(4, "Handle %p given %d credits (total %d, free %d)\n", 266 jbd_debug(4, "Handle %p given %d credits (total %d, free %d)\n",
237 handle, nblocks, transaction->t_outstanding_credits, 267 handle, nblocks,
268 atomic_read(&transaction->t_outstanding_credits),
238 __jbd2_log_space_left(journal)); 269 __jbd2_log_space_left(journal));
239 spin_unlock(&transaction->t_handle_lock); 270 read_unlock(&journal->j_state_lock);
240 spin_unlock(&journal->j_state_lock);
241 271
242 lock_map_acquire(&handle->h_lockdep_map); 272 lock_map_acquire(&handle->h_lockdep_map);
243out: 273 kfree(new_transaction);
244 if (unlikely(new_transaction)) /* It's usually NULL */ 274 return 0;
245 kfree(new_transaction);
246 return ret;
247} 275}
248 276
249static struct lock_class_key jbd2_handle_key; 277static struct lock_class_key jbd2_handle_key;
@@ -278,7 +306,7 @@ static handle_t *new_handle(int nblocks)
278 * 306 *
279 * Return a pointer to a newly allocated handle, or NULL on failure 307 * Return a pointer to a newly allocated handle, or NULL on failure
280 */ 308 */
281handle_t *jbd2_journal_start(journal_t *journal, int nblocks) 309handle_t *jbd2__journal_start(journal_t *journal, int nblocks, int gfp_mask)
282{ 310{
283 handle_t *handle = journal_current_handle(); 311 handle_t *handle = journal_current_handle();
284 int err; 312 int err;
@@ -298,7 +326,7 @@ handle_t *jbd2_journal_start(journal_t *journal, int nblocks)
298 326
299 current->journal_info = handle; 327 current->journal_info = handle;
300 328
301 err = start_this_handle(journal, handle); 329 err = start_this_handle(journal, handle, gfp_mask);
302 if (err < 0) { 330 if (err < 0) {
303 jbd2_free_handle(handle); 331 jbd2_free_handle(handle);
304 current->journal_info = NULL; 332 current->journal_info = NULL;
@@ -308,6 +336,15 @@ handle_t *jbd2_journal_start(journal_t *journal, int nblocks)
308out: 336out:
309 return handle; 337 return handle;
310} 338}
339EXPORT_SYMBOL(jbd2__journal_start);
340
341
342handle_t *jbd2_journal_start(journal_t *journal, int nblocks)
343{
344 return jbd2__journal_start(journal, nblocks, GFP_NOFS);
345}
346EXPORT_SYMBOL(jbd2_journal_start);
347
311 348
312/** 349/**
313 * int jbd2_journal_extend() - extend buffer credits. 350 * int jbd2_journal_extend() - extend buffer credits.
@@ -342,7 +379,7 @@ int jbd2_journal_extend(handle_t *handle, int nblocks)
342 379
343 result = 1; 380 result = 1;
344 381
345 spin_lock(&journal->j_state_lock); 382 read_lock(&journal->j_state_lock);
346 383
347 /* Don't extend a locked-down transaction! */ 384 /* Don't extend a locked-down transaction! */
348 if (handle->h_transaction->t_state != T_RUNNING) { 385 if (handle->h_transaction->t_state != T_RUNNING) {
@@ -352,7 +389,7 @@ int jbd2_journal_extend(handle_t *handle, int nblocks)
352 } 389 }
353 390
354 spin_lock(&transaction->t_handle_lock); 391 spin_lock(&transaction->t_handle_lock);
355 wanted = transaction->t_outstanding_credits + nblocks; 392 wanted = atomic_read(&transaction->t_outstanding_credits) + nblocks;
356 393
357 if (wanted > journal->j_max_transaction_buffers) { 394 if (wanted > journal->j_max_transaction_buffers) {
358 jbd_debug(3, "denied handle %p %d blocks: " 395 jbd_debug(3, "denied handle %p %d blocks: "
@@ -367,14 +404,14 @@ int jbd2_journal_extend(handle_t *handle, int nblocks)
367 } 404 }
368 405
369 handle->h_buffer_credits += nblocks; 406 handle->h_buffer_credits += nblocks;
370 transaction->t_outstanding_credits += nblocks; 407 atomic_add(nblocks, &transaction->t_outstanding_credits);
371 result = 0; 408 result = 0;
372 409
373 jbd_debug(3, "extended handle %p by %d\n", handle, nblocks); 410 jbd_debug(3, "extended handle %p by %d\n", handle, nblocks);
374unlock: 411unlock:
375 spin_unlock(&transaction->t_handle_lock); 412 spin_unlock(&transaction->t_handle_lock);
376error_out: 413error_out:
377 spin_unlock(&journal->j_state_lock); 414 read_unlock(&journal->j_state_lock);
378out: 415out:
379 return result; 416 return result;
380} 417}
@@ -394,8 +431,7 @@ out:
394 * transaction capabable of guaranteeing the requested number of 431 * transaction capabable of guaranteeing the requested number of
395 * credits. 432 * credits.
396 */ 433 */
397 434int jbd2__journal_restart(handle_t *handle, int nblocks, int gfp_mask)
398int jbd2_journal_restart(handle_t *handle, int nblocks)
399{ 435{
400 transaction_t *transaction = handle->h_transaction; 436 transaction_t *transaction = handle->h_transaction;
401 journal_t *journal = transaction->t_journal; 437 journal_t *journal = transaction->t_journal;
@@ -410,29 +446,35 @@ int jbd2_journal_restart(handle_t *handle, int nblocks)
410 * First unlink the handle from its current transaction, and start the 446 * First unlink the handle from its current transaction, and start the
411 * commit on that. 447 * commit on that.
412 */ 448 */
413 J_ASSERT(transaction->t_updates > 0); 449 J_ASSERT(atomic_read(&transaction->t_updates) > 0);
414 J_ASSERT(journal_current_handle() == handle); 450 J_ASSERT(journal_current_handle() == handle);
415 451
416 spin_lock(&journal->j_state_lock); 452 read_lock(&journal->j_state_lock);
417 spin_lock(&transaction->t_handle_lock); 453 spin_lock(&transaction->t_handle_lock);
418 transaction->t_outstanding_credits -= handle->h_buffer_credits; 454 atomic_sub(handle->h_buffer_credits,
419 transaction->t_updates--; 455 &transaction->t_outstanding_credits);
420 456 if (atomic_dec_and_test(&transaction->t_updates))
421 if (!transaction->t_updates)
422 wake_up(&journal->j_wait_updates); 457 wake_up(&journal->j_wait_updates);
423 spin_unlock(&transaction->t_handle_lock); 458 spin_unlock(&transaction->t_handle_lock);
424 459
425 jbd_debug(2, "restarting handle %p\n", handle); 460 jbd_debug(2, "restarting handle %p\n", handle);
426 __jbd2_log_start_commit(journal, transaction->t_tid); 461 __jbd2_log_start_commit(journal, transaction->t_tid);
427 spin_unlock(&journal->j_state_lock); 462 read_unlock(&journal->j_state_lock);
428 463
429 lock_map_release(&handle->h_lockdep_map); 464 lock_map_release(&handle->h_lockdep_map);
430 handle->h_buffer_credits = nblocks; 465 handle->h_buffer_credits = nblocks;
431 ret = start_this_handle(journal, handle); 466 ret = start_this_handle(journal, handle, gfp_mask);
432 return ret; 467 return ret;
433} 468}
469EXPORT_SYMBOL(jbd2__journal_restart);
434 470
435 471
472int jbd2_journal_restart(handle_t *handle, int nblocks)
473{
474 return jbd2__journal_restart(handle, nblocks, GFP_NOFS);
475}
476EXPORT_SYMBOL(jbd2_journal_restart);
477
436/** 478/**
437 * void jbd2_journal_lock_updates () - establish a transaction barrier. 479 * void jbd2_journal_lock_updates () - establish a transaction barrier.
438 * @journal: Journal to establish a barrier on. 480 * @journal: Journal to establish a barrier on.
@@ -447,7 +489,7 @@ void jbd2_journal_lock_updates(journal_t *journal)
447{ 489{
448 DEFINE_WAIT(wait); 490 DEFINE_WAIT(wait);
449 491
450 spin_lock(&journal->j_state_lock); 492 write_lock(&journal->j_state_lock);
451 ++journal->j_barrier_count; 493 ++journal->j_barrier_count;
452 494
453 /* Wait until there are no running updates */ 495 /* Wait until there are no running updates */
@@ -458,19 +500,19 @@ void jbd2_journal_lock_updates(journal_t *journal)
458 break; 500 break;
459 501
460 spin_lock(&transaction->t_handle_lock); 502 spin_lock(&transaction->t_handle_lock);
461 if (!transaction->t_updates) { 503 if (!atomic_read(&transaction->t_updates)) {
462 spin_unlock(&transaction->t_handle_lock); 504 spin_unlock(&transaction->t_handle_lock);
463 break; 505 break;
464 } 506 }
465 prepare_to_wait(&journal->j_wait_updates, &wait, 507 prepare_to_wait(&journal->j_wait_updates, &wait,
466 TASK_UNINTERRUPTIBLE); 508 TASK_UNINTERRUPTIBLE);
467 spin_unlock(&transaction->t_handle_lock); 509 spin_unlock(&transaction->t_handle_lock);
468 spin_unlock(&journal->j_state_lock); 510 write_unlock(&journal->j_state_lock);
469 schedule(); 511 schedule();
470 finish_wait(&journal->j_wait_updates, &wait); 512 finish_wait(&journal->j_wait_updates, &wait);
471 spin_lock(&journal->j_state_lock); 513 write_lock(&journal->j_state_lock);
472 } 514 }
473 spin_unlock(&journal->j_state_lock); 515 write_unlock(&journal->j_state_lock);
474 516
475 /* 517 /*
476 * We have now established a barrier against other normal updates, but 518 * We have now established a barrier against other normal updates, but
@@ -494,9 +536,9 @@ void jbd2_journal_unlock_updates (journal_t *journal)
494 J_ASSERT(journal->j_barrier_count != 0); 536 J_ASSERT(journal->j_barrier_count != 0);
495 537
496 mutex_unlock(&journal->j_barrier); 538 mutex_unlock(&journal->j_barrier);
497 spin_lock(&journal->j_state_lock); 539 write_lock(&journal->j_state_lock);
498 --journal->j_barrier_count; 540 --journal->j_barrier_count;
499 spin_unlock(&journal->j_state_lock); 541 write_unlock(&journal->j_state_lock);
500 wake_up(&journal->j_wait_transaction_locked); 542 wake_up(&journal->j_wait_transaction_locked);
501} 543}
502 544
@@ -1238,7 +1280,8 @@ int jbd2_journal_stop(handle_t *handle)
1238{ 1280{
1239 transaction_t *transaction = handle->h_transaction; 1281 transaction_t *transaction = handle->h_transaction;
1240 journal_t *journal = transaction->t_journal; 1282 journal_t *journal = transaction->t_journal;
1241 int err; 1283 int err, wait_for_commit = 0;
1284 tid_t tid;
1242 pid_t pid; 1285 pid_t pid;
1243 1286
1244 J_ASSERT(journal_current_handle() == handle); 1287 J_ASSERT(journal_current_handle() == handle);
@@ -1246,7 +1289,7 @@ int jbd2_journal_stop(handle_t *handle)
1246 if (is_handle_aborted(handle)) 1289 if (is_handle_aborted(handle))
1247 err = -EIO; 1290 err = -EIO;
1248 else { 1291 else {
1249 J_ASSERT(transaction->t_updates > 0); 1292 J_ASSERT(atomic_read(&transaction->t_updates) > 0);
1250 err = 0; 1293 err = 0;
1251 } 1294 }
1252 1295
@@ -1291,9 +1334,9 @@ int jbd2_journal_stop(handle_t *handle)
1291 1334
1292 journal->j_last_sync_writer = pid; 1335 journal->j_last_sync_writer = pid;
1293 1336
1294 spin_lock(&journal->j_state_lock); 1337 read_lock(&journal->j_state_lock);
1295 commit_time = journal->j_average_commit_time; 1338 commit_time = journal->j_average_commit_time;
1296 spin_unlock(&journal->j_state_lock); 1339 read_unlock(&journal->j_state_lock);
1297 1340
1298 trans_time = ktime_to_ns(ktime_sub(ktime_get(), 1341 trans_time = ktime_to_ns(ktime_sub(ktime_get(),
1299 transaction->t_start_time)); 1342 transaction->t_start_time));
@@ -1314,14 +1357,8 @@ int jbd2_journal_stop(handle_t *handle)
1314 if (handle->h_sync) 1357 if (handle->h_sync)
1315 transaction->t_synchronous_commit = 1; 1358 transaction->t_synchronous_commit = 1;
1316 current->journal_info = NULL; 1359 current->journal_info = NULL;
1317 spin_lock(&transaction->t_handle_lock); 1360 atomic_sub(handle->h_buffer_credits,
1318 transaction->t_outstanding_credits -= handle->h_buffer_credits; 1361 &transaction->t_outstanding_credits);
1319 transaction->t_updates--;
1320 if (!transaction->t_updates) {
1321 wake_up(&journal->j_wait_updates);
1322 if (journal->j_barrier_count)
1323 wake_up(&journal->j_wait_transaction_locked);
1324 }
1325 1362
1326 /* 1363 /*
1327 * If the handle is marked SYNC, we need to set another commit 1364 * If the handle is marked SYNC, we need to set another commit
@@ -1330,15 +1367,13 @@ int jbd2_journal_stop(handle_t *handle)
1330 * transaction is too old now. 1367 * transaction is too old now.
1331 */ 1368 */
1332 if (handle->h_sync || 1369 if (handle->h_sync ||
1333 transaction->t_outstanding_credits > 1370 (atomic_read(&transaction->t_outstanding_credits) >
1334 journal->j_max_transaction_buffers || 1371 journal->j_max_transaction_buffers) ||
1335 time_after_eq(jiffies, transaction->t_expires)) { 1372 time_after_eq(jiffies, transaction->t_expires)) {
1336 /* Do this even for aborted journals: an abort still 1373 /* Do this even for aborted journals: an abort still
1337 * completes the commit thread, it just doesn't write 1374 * completes the commit thread, it just doesn't write
1338 * anything to disk. */ 1375 * anything to disk. */
1339 tid_t tid = transaction->t_tid;
1340 1376
1341 spin_unlock(&transaction->t_handle_lock);
1342 jbd_debug(2, "transaction too old, requesting commit for " 1377 jbd_debug(2, "transaction too old, requesting commit for "
1343 "handle %p\n", handle); 1378 "handle %p\n", handle);
1344 /* This is non-blocking */ 1379 /* This is non-blocking */
@@ -1349,11 +1384,25 @@ int jbd2_journal_stop(handle_t *handle)
1349 * to wait for the commit to complete. 1384 * to wait for the commit to complete.
1350 */ 1385 */
1351 if (handle->h_sync && !(current->flags & PF_MEMALLOC)) 1386 if (handle->h_sync && !(current->flags & PF_MEMALLOC))
1352 err = jbd2_log_wait_commit(journal, tid); 1387 wait_for_commit = 1;
1353 } else {
1354 spin_unlock(&transaction->t_handle_lock);
1355 } 1388 }
1356 1389
1390 /*
1391 * Once we drop t_updates, if it goes to zero the transaction
1392 * could start commiting on us and eventually disappear. So
1393 * once we do this, we must not dereference transaction
1394 * pointer again.
1395 */
1396 tid = transaction->t_tid;
1397 if (atomic_dec_and_test(&transaction->t_updates)) {
1398 wake_up(&journal->j_wait_updates);
1399 if (journal->j_barrier_count)
1400 wake_up(&journal->j_wait_transaction_locked);
1401 }
1402
1403 if (wait_for_commit)
1404 err = jbd2_log_wait_commit(journal, tid);
1405
1357 lock_map_release(&handle->h_lockdep_map); 1406 lock_map_release(&handle->h_lockdep_map);
1358 1407
1359 jbd2_free_handle(handle); 1408 jbd2_free_handle(handle);
@@ -1719,7 +1768,7 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh)
1719 goto zap_buffer_unlocked; 1768 goto zap_buffer_unlocked;
1720 1769
1721 /* OK, we have data buffer in journaled mode */ 1770 /* OK, we have data buffer in journaled mode */
1722 spin_lock(&journal->j_state_lock); 1771 write_lock(&journal->j_state_lock);
1723 jbd_lock_bh_state(bh); 1772 jbd_lock_bh_state(bh);
1724 spin_lock(&journal->j_list_lock); 1773 spin_lock(&journal->j_list_lock);
1725 1774
@@ -1772,7 +1821,7 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh)
1772 jbd2_journal_put_journal_head(jh); 1821 jbd2_journal_put_journal_head(jh);
1773 spin_unlock(&journal->j_list_lock); 1822 spin_unlock(&journal->j_list_lock);
1774 jbd_unlock_bh_state(bh); 1823 jbd_unlock_bh_state(bh);
1775 spin_unlock(&journal->j_state_lock); 1824 write_unlock(&journal->j_state_lock);
1776 return ret; 1825 return ret;
1777 } else { 1826 } else {
1778 /* There is no currently-running transaction. So the 1827 /* There is no currently-running transaction. So the
@@ -1786,7 +1835,7 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh)
1786 jbd2_journal_put_journal_head(jh); 1835 jbd2_journal_put_journal_head(jh);
1787 spin_unlock(&journal->j_list_lock); 1836 spin_unlock(&journal->j_list_lock);
1788 jbd_unlock_bh_state(bh); 1837 jbd_unlock_bh_state(bh);
1789 spin_unlock(&journal->j_state_lock); 1838 write_unlock(&journal->j_state_lock);
1790 return ret; 1839 return ret;
1791 } else { 1840 } else {
1792 /* The orphan record's transaction has 1841 /* The orphan record's transaction has
@@ -1810,7 +1859,7 @@ static int journal_unmap_buffer(journal_t *journal, struct buffer_head *bh)
1810 jbd2_journal_put_journal_head(jh); 1859 jbd2_journal_put_journal_head(jh);
1811 spin_unlock(&journal->j_list_lock); 1860 spin_unlock(&journal->j_list_lock);
1812 jbd_unlock_bh_state(bh); 1861 jbd_unlock_bh_state(bh);
1813 spin_unlock(&journal->j_state_lock); 1862 write_unlock(&journal->j_state_lock);
1814 return 0; 1863 return 0;
1815 } else { 1864 } else {
1816 /* Good, the buffer belongs to the running transaction. 1865 /* Good, the buffer belongs to the running transaction.
@@ -1829,7 +1878,7 @@ zap_buffer:
1829zap_buffer_no_jh: 1878zap_buffer_no_jh:
1830 spin_unlock(&journal->j_list_lock); 1879 spin_unlock(&journal->j_list_lock);
1831 jbd_unlock_bh_state(bh); 1880 jbd_unlock_bh_state(bh);
1832 spin_unlock(&journal->j_state_lock); 1881 write_unlock(&journal->j_state_lock);
1833zap_buffer_unlocked: 1882zap_buffer_unlocked:
1834 clear_buffer_dirty(bh); 1883 clear_buffer_dirty(bh);
1835 J_ASSERT_BH(bh, !buffer_jbddirty(bh)); 1884 J_ASSERT_BH(bh, !buffer_jbddirty(bh));
@@ -2136,9 +2185,9 @@ int jbd2_journal_begin_ordered_truncate(journal_t *journal,
2136 /* Locks are here just to force reading of recent values, it is 2185 /* Locks are here just to force reading of recent values, it is
2137 * enough that the transaction was not committing before we started 2186 * enough that the transaction was not committing before we started
2138 * a transaction adding the inode to orphan list */ 2187 * a transaction adding the inode to orphan list */
2139 spin_lock(&journal->j_state_lock); 2188 read_lock(&journal->j_state_lock);
2140 commit_trans = journal->j_committing_transaction; 2189 commit_trans = journal->j_committing_transaction;
2141 spin_unlock(&journal->j_state_lock); 2190 read_unlock(&journal->j_state_lock);
2142 spin_lock(&journal->j_list_lock); 2191 spin_lock(&journal->j_list_lock);
2143 inode_trans = jinode->i_transaction; 2192 inode_trans = jinode->i_transaction;
2144 spin_unlock(&journal->j_list_lock); 2193 spin_unlock(&journal->j_list_lock);
diff --git a/fs/ocfs2/journal.c b/fs/ocfs2/journal.c
index 625de9d7088c..9b57c0350ff9 100644
--- a/fs/ocfs2/journal.c
+++ b/fs/ocfs2/journal.c
@@ -760,13 +760,13 @@ void ocfs2_set_journal_params(struct ocfs2_super *osb)
760 if (osb->osb_commit_interval) 760 if (osb->osb_commit_interval)
761 commit_interval = osb->osb_commit_interval; 761 commit_interval = osb->osb_commit_interval;
762 762
763 spin_lock(&journal->j_state_lock); 763 write_lock(&journal->j_state_lock);
764 journal->j_commit_interval = commit_interval; 764 journal->j_commit_interval = commit_interval;
765 if (osb->s_mount_opt & OCFS2_MOUNT_BARRIER) 765 if (osb->s_mount_opt & OCFS2_MOUNT_BARRIER)
766 journal->j_flags |= JBD2_BARRIER; 766 journal->j_flags |= JBD2_BARRIER;
767 else 767 else
768 journal->j_flags &= ~JBD2_BARRIER; 768 journal->j_flags &= ~JBD2_BARRIER;
769 spin_unlock(&journal->j_state_lock); 769 write_unlock(&journal->j_state_lock);
770} 770}
771 771
772int ocfs2_journal_init(struct ocfs2_journal *journal, int *dirty) 772int ocfs2_journal_init(struct ocfs2_journal *journal, int *dirty)
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index adf832dec3f3..0b52924a0cb6 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -601,13 +601,13 @@ struct transaction_s
601 * Number of outstanding updates running on this transaction 601 * Number of outstanding updates running on this transaction
602 * [t_handle_lock] 602 * [t_handle_lock]
603 */ 603 */
604 int t_updates; 604 atomic_t t_updates;
605 605
606 /* 606 /*
607 * Number of buffers reserved for use by all handles in this transaction 607 * Number of buffers reserved for use by all handles in this transaction
608 * handle but not yet modified. [t_handle_lock] 608 * handle but not yet modified. [t_handle_lock]
609 */ 609 */
610 int t_outstanding_credits; 610 atomic_t t_outstanding_credits;
611 611
612 /* 612 /*
613 * Forward and backward links for the circular list of all transactions 613 * Forward and backward links for the circular list of all transactions
@@ -629,7 +629,7 @@ struct transaction_s
629 /* 629 /*
630 * How many handles used this transaction? [t_handle_lock] 630 * How many handles used this transaction? [t_handle_lock]
631 */ 631 */
632 int t_handle_count; 632 atomic_t t_handle_count;
633 633
634 /* 634 /*
635 * This transaction is being forced and some process is 635 * This transaction is being forced and some process is
@@ -764,7 +764,7 @@ struct journal_s
764 /* 764 /*
765 * Protect the various scalars in the journal 765 * Protect the various scalars in the journal
766 */ 766 */
767 spinlock_t j_state_lock; 767 rwlock_t j_state_lock;
768 768
769 /* 769 /*
770 * Number of processes waiting to create a barrier lock [j_state_lock] 770 * Number of processes waiting to create a barrier lock [j_state_lock]
@@ -1082,7 +1082,9 @@ static inline handle_t *journal_current_handle(void)
1082 */ 1082 */
1083 1083
1084extern handle_t *jbd2_journal_start(journal_t *, int nblocks); 1084extern handle_t *jbd2_journal_start(journal_t *, int nblocks);
1085extern int jbd2_journal_restart (handle_t *, int nblocks); 1085extern handle_t *jbd2__journal_start(journal_t *, int nblocks, int gfp_mask);
1086extern int jbd2_journal_restart(handle_t *, int nblocks);
1087extern int jbd2__journal_restart(handle_t *, int nblocks, int gfp_mask);
1086extern int jbd2_journal_extend (handle_t *, int nblocks); 1088extern int jbd2_journal_extend (handle_t *, int nblocks);
1087extern int jbd2_journal_get_write_access(handle_t *, struct buffer_head *); 1089extern int jbd2_journal_get_write_access(handle_t *, struct buffer_head *);
1088extern int jbd2_journal_get_create_access (handle_t *, struct buffer_head *); 1090extern int jbd2_journal_get_create_access (handle_t *, struct buffer_head *);
@@ -1257,8 +1259,8 @@ static inline int jbd_space_needed(journal_t *journal)
1257{ 1259{
1258 int nblocks = journal->j_max_transaction_buffers; 1260 int nblocks = journal->j_max_transaction_buffers;
1259 if (journal->j_committing_transaction) 1261 if (journal->j_committing_transaction)
1260 nblocks += journal->j_committing_transaction-> 1262 nblocks += atomic_read(&journal->j_committing_transaction->
1261 t_outstanding_credits; 1263 t_outstanding_credits);
1262 return nblocks; 1264 return nblocks;
1263} 1265}
1264 1266
diff --git a/include/trace/events/ext4.h b/include/trace/events/ext4.h
index f3865c7b4166..01e9e0076a92 100644
--- a/include/trace/events/ext4.h
+++ b/include/trace/events/ext4.h
@@ -395,11 +395,12 @@ DEFINE_EVENT(ext4__mb_new_pa, ext4_mb_new_group_pa,
395); 395);
396 396
397TRACE_EVENT(ext4_mb_release_inode_pa, 397TRACE_EVENT(ext4_mb_release_inode_pa,
398 TP_PROTO(struct ext4_allocation_context *ac, 398 TP_PROTO(struct super_block *sb,
399 struct ext4_allocation_context *ac,
399 struct ext4_prealloc_space *pa, 400 struct ext4_prealloc_space *pa,
400 unsigned long long block, unsigned int count), 401 unsigned long long block, unsigned int count),
401 402
402 TP_ARGS(ac, pa, block, count), 403 TP_ARGS(sb, ac, pa, block, count),
403 404
404 TP_STRUCT__entry( 405 TP_STRUCT__entry(
405 __field( dev_t, dev ) 406 __field( dev_t, dev )
@@ -410,8 +411,9 @@ TRACE_EVENT(ext4_mb_release_inode_pa,
410 ), 411 ),
411 412
412 TP_fast_assign( 413 TP_fast_assign(
413 __entry->dev = ac->ac_sb->s_dev; 414 __entry->dev = sb->s_dev;
414 __entry->ino = ac->ac_inode->i_ino; 415 __entry->ino = (ac && ac->ac_inode) ?
416 ac->ac_inode->i_ino : 0;
415 __entry->block = block; 417 __entry->block = block;
416 __entry->count = count; 418 __entry->count = count;
417 ), 419 ),
@@ -422,10 +424,11 @@ TRACE_EVENT(ext4_mb_release_inode_pa,
422); 424);
423 425
424TRACE_EVENT(ext4_mb_release_group_pa, 426TRACE_EVENT(ext4_mb_release_group_pa,
425 TP_PROTO(struct ext4_allocation_context *ac, 427 TP_PROTO(struct super_block *sb,
428 struct ext4_allocation_context *ac,
426 struct ext4_prealloc_space *pa), 429 struct ext4_prealloc_space *pa),
427 430
428 TP_ARGS(ac, pa), 431 TP_ARGS(sb, ac, pa),
429 432
430 TP_STRUCT__entry( 433 TP_STRUCT__entry(
431 __field( dev_t, dev ) 434 __field( dev_t, dev )
@@ -436,8 +439,9 @@ TRACE_EVENT(ext4_mb_release_group_pa,
436 ), 439 ),
437 440
438 TP_fast_assign( 441 TP_fast_assign(
439 __entry->dev = ac->ac_sb->s_dev; 442 __entry->dev = sb->s_dev;
440 __entry->ino = ac->ac_inode->i_ino; 443 __entry->ino = (ac && ac->ac_inode) ?
444 ac->ac_inode->i_ino : 0;
441 __entry->pa_pstart = pa->pa_pstart; 445 __entry->pa_pstart = pa->pa_pstart;
442 __entry->pa_len = pa->pa_len; 446 __entry->pa_len = pa->pa_len;
443 ), 447 ),