Skip to content

Commit 4515c30

Browse files
committed
Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
* 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: (47 commits) ext4: Fix potential fiemap deadlock (mmap_sem vs. i_data_sem) ext4: Do not override ext2 or ext3 if built they are built as modules jbd2: Export jbd2_log_start_commit to fix ext4 build ext4: Fix insufficient checks in EXT4_IOC_MOVE_EXT ext4: Wait for proper transaction commit on fsync ext4: fix incorrect block reservation on quota transfer. ext4: quota macros cleanup ext4: ext4_get_reserved_space() must return bytes instead of blocks ext4: remove blocks from inode prealloc list on failure ext4: wait for log to commit when umounting ext4: Avoid data / filesystem corruption when write fails to copy data ext4: Use ext4 file system driver for ext2/ext3 file system mounts ext4: Return the PTR_ERR of the correct pointer in setup_new_group_blocks() jbd2: Add ENOMEM checking in and for jbd2_journal_write_metadata_buffer() ext4: remove unused parameter wbc from __ext4_journalled_writepage() ext4: remove encountered_congestion trace ext4: move_extent_per_page() cleanup ext4: initialize moved_len before calling ext4_move_extents() ext4: Fix double-free of blocks with EXT4_IOC_MOVE_EXT ext4: use ext4_data_block_valid() in ext4_free_blocks() ...
2 parents a5eba3f + fab3a54 commit 4515c30

21 files changed

Lines changed: 677 additions & 514 deletions

File tree

‎Documentation/filesystems/ext4.txt‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,8 @@ journal_dev=devnum When the external journal device's major/minor numbers
153153
identified through its new major/minor numbers encoded
154154
in devnum.
155155

156-
noload Don't load the journal on mounting. Note that
157-
if the filesystem was not unmounted cleanly,
156+
norecovery Don't load the journal on mounting. Note that
157+
noload if the filesystem was not unmounted cleanly,
158158
skipping the journal replay will lead to the
159159
filesystem containing inconsistencies that can
160160
lead to any number of problems.
@@ -353,6 +353,12 @@ noauto_da_alloc replacing existing files via patterns such as
353353
system crashes before the delayed allocation
354354
blocks are forced to disk.
355355

356+
discard Controls whether ext4 should issue discard/TRIM
357+
nodiscard(*) commands to the underlying block device when
358+
blocks are freed. This is useful for SSD devices
359+
and sparse/thinly-provisioned LUNs, but it is off
360+
by default until sufficient testing has been done.
361+
356362
Data Mode
357363
=========
358364
There are 3 different data modes:

‎fs/ext4/Kconfig‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ config EXT4_FS
2626

2727
If unsure, say N.
2828

29+
config EXT4_USE_FOR_EXT23
30+
bool "Use ext4 for ext2/ext3 file systems"
31+
depends on EXT3_FS=n || EXT2_FS=n
32+
default y
33+
help
34+
Allow the ext4 file system driver code to be used for ext2 or
35+
ext3 file system mounts. This allows users to reduce their
36+
compiled kernel size by using one file system driver for
37+
ext2, ext3, and ext4 file systems.
38+
2939
config EXT4_FS_XATTR
3040
bool "Ext4 extended attributes"
3141
depends on EXT4_FS

‎fs/ext4/balloc.c‎

Lines changed: 7 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -498,44 +498,6 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb,
498498
return;
499499
}
500500

501-
/**
502-
* ext4_free_blocks() -- Free given blocks and update quota
503-
* @handle: handle for this transaction
504-
* @inode: inode
505-
* @block: start physical block to free
506-
* @count: number of blocks to count
507-
* @metadata: Are these metadata blocks
508-
*/
509-
void ext4_free_blocks(handle_t *handle, struct inode *inode,
510-
ext4_fsblk_t block, unsigned long count,
511-
int metadata)
512-
{
513-
struct super_block *sb;
514-
unsigned long dquot_freed_blocks;
515-
516-
/* this isn't the right place to decide whether block is metadata
517-
* inode.c/extents.c knows better, but for safety ... */
518-
if (S_ISDIR(inode->i_mode) || S_ISLNK(inode->i_mode))
519-
metadata = 1;
520-
521-
/* We need to make sure we don't reuse
522-
* block released untill the transaction commit.
523-
* writeback mode have weak data consistency so
524-
* don't force data as metadata when freeing block
525-
* for writeback mode.
526-
*/
527-
if (metadata == 0 && !ext4_should_writeback_data(inode))
528-
metadata = 1;
529-
530-
sb = inode->i_sb;
531-
532-
ext4_mb_free_blocks(handle, inode, block, count,
533-
metadata, &dquot_freed_blocks);
534-
if (dquot_freed_blocks)
535-
vfs_dq_free_block(inode, dquot_freed_blocks);
536-
return;
537-
}
538-
539501
/**
540502
* ext4_has_free_blocks()
541503
* @sbi: in-core super block structure.
@@ -761,7 +723,13 @@ static unsigned long ext4_bg_num_gdb_meta(struct super_block *sb,
761723
static unsigned long ext4_bg_num_gdb_nometa(struct super_block *sb,
762724
ext4_group_t group)
763725
{
764-
return ext4_bg_has_super(sb, group) ? EXT4_SB(sb)->s_gdb_count : 0;
726+
if (!ext4_bg_has_super(sb, group))
727+
return 0;
728+
729+
if (EXT4_HAS_INCOMPAT_FEATURE(sb,EXT4_FEATURE_INCOMPAT_META_BG))
730+
return le32_to_cpu(EXT4_SB(sb)->s_es->s_first_meta_bg);
731+
else
732+
return EXT4_SB(sb)->s_gdb_count;
765733
}
766734

767735
/**

‎fs/ext4/block_validity.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ int ext4_setup_system_zone(struct super_block *sb)
160160
if (ext4_bg_has_super(sb, i) &&
161161
((i < 5) || ((i % flex_size) == 0)))
162162
add_system_zone(sbi, ext4_group_first_block_no(sb, i),
163-
sbi->s_gdb_count + 1);
163+
ext4_bg_num_gdb(sb, i) + 1);
164164
gdp = ext4_get_group_desc(sb, i, NULL);
165165
ret = add_system_zone(sbi, ext4_block_bitmap(sb, gdp), 1);
166166
if (ret)
@@ -228,6 +228,7 @@ int ext4_data_block_valid(struct ext4_sb_info *sbi, ext4_fsblk_t start_blk,
228228
struct rb_node *n = sbi->system_blks.rb_node;
229229

230230
if ((start_blk <= le32_to_cpu(sbi->s_es->s_first_data_block)) ||
231+
(start_blk + count < start_blk) ||
231232
(start_blk + count > ext4_blocks_count(sbi->s_es)))
232233
return 0;
233234
while (n) {

‎fs/ext4/ext4.h‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,12 @@ struct ext4_new_group_data {
375375
#define EXT4_GET_BLOCKS_DIO_CONVERT_EXT (EXT4_GET_BLOCKS_CONVERT|\
376376
EXT4_GET_BLOCKS_DIO_CREATE_EXT)
377377

378+
/*
379+
* Flags used by ext4_free_blocks
380+
*/
381+
#define EXT4_FREE_BLOCKS_METADATA 0x0001
382+
#define EXT4_FREE_BLOCKS_FORGET 0x0002
383+
378384
/*
379385
* ioctl commands
380386
*/
@@ -703,6 +709,13 @@ struct ext4_inode_info {
703709
struct list_head i_aio_dio_complete_list;
704710
/* current io_end structure for async DIO write*/
705711
ext4_io_end_t *cur_aio_dio;
712+
713+
/*
714+
* Transactions that contain inode's metadata needed to complete
715+
* fsync and fdatasync, respectively.
716+
*/
717+
tid_t i_sync_tid;
718+
tid_t i_datasync_tid;
706719
};
707720

708721
/*
@@ -750,6 +763,7 @@ struct ext4_inode_info {
750763
#define EXT4_MOUNT_DELALLOC 0x8000000 /* Delalloc support */
751764
#define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000 /* Abort on file data write */
752765
#define EXT4_MOUNT_BLOCK_VALIDITY 0x20000000 /* Block validity checking */
766+
#define EXT4_MOUNT_DISCARD 0x40000000 /* Issue DISCARD requests */
753767

754768
#define clear_opt(o, opt) o &= ~EXT4_MOUNT_##opt
755769
#define set_opt(o, opt) o |= EXT4_MOUNT_##opt
@@ -1324,8 +1338,6 @@ extern ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
13241338
ext4_fsblk_t goal, unsigned long *count, int *errp);
13251339
extern int ext4_claim_free_blocks(struct ext4_sb_info *sbi, s64 nblocks);
13261340
extern int ext4_has_free_blocks(struct ext4_sb_info *sbi, s64 nblocks);
1327-
extern void ext4_free_blocks(handle_t *handle, struct inode *inode,
1328-
ext4_fsblk_t block, unsigned long count, int metadata);
13291341
extern void ext4_add_groupblocks(handle_t *handle, struct super_block *sb,
13301342
ext4_fsblk_t block, unsigned long count);
13311343
extern ext4_fsblk_t ext4_count_free_blocks(struct super_block *);
@@ -1384,16 +1396,15 @@ extern int ext4_mb_reserve_blocks(struct super_block *, int);
13841396
extern void ext4_discard_preallocations(struct inode *);
13851397
extern int __init init_ext4_mballoc(void);
13861398
extern void exit_ext4_mballoc(void);
1387-
extern void ext4_mb_free_blocks(handle_t *, struct inode *,
1388-
ext4_fsblk_t, unsigned long, int, unsigned long *);
1399+
extern void ext4_free_blocks(handle_t *handle, struct inode *inode,
1400+
struct buffer_head *bh, ext4_fsblk_t block,
1401+
unsigned long count, int flags);
13891402
extern int ext4_mb_add_groupinfo(struct super_block *sb,
13901403
ext4_group_t i, struct ext4_group_desc *desc);
13911404
extern int ext4_mb_get_buddy_cache_lock(struct super_block *, ext4_group_t);
13921405
extern void ext4_mb_put_buddy_cache_lock(struct super_block *,
13931406
ext4_group_t, int);
13941407
/* inode.c */
1395-
int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode,
1396-
struct buffer_head *bh, ext4_fsblk_t blocknr);
13971408
struct buffer_head *ext4_getblk(handle_t *, struct inode *,
13981409
ext4_lblk_t, int, int *);
13991410
struct buffer_head *ext4_bread(handle_t *, struct inode *,

‎fs/ext4/ext4_jbd2.c‎

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
#include "ext4_jbd2.h"
66

7+
#include <trace/events/ext4.h>
8+
79
int __ext4_journal_get_undo_access(const char *where, handle_t *handle,
810
struct buffer_head *bh)
911
{
@@ -32,35 +34,69 @@ int __ext4_journal_get_write_access(const char *where, handle_t *handle,
3234
return err;
3335
}
3436

35-
int __ext4_journal_forget(const char *where, handle_t *handle,
36-
struct buffer_head *bh)
37+
/*
38+
* The ext4 forget function must perform a revoke if we are freeing data
39+
* which has been journaled. Metadata (eg. indirect blocks) must be
40+
* revoked in all cases.
41+
*
42+
* "bh" may be NULL: a metadata block may have been freed from memory
43+
* but there may still be a record of it in the journal, and that record
44+
* still needs to be revoked.
45+
*
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.
48+
*/
49+
int __ext4_forget(const char *where, handle_t *handle, int is_metadata,
50+
struct inode *inode, struct buffer_head *bh,
51+
ext4_fsblk_t blocknr)
3752
{
38-
int err = 0;
53+
int err;
3954

40-
if (ext4_handle_valid(handle)) {
41-
err = jbd2_journal_forget(handle, bh);
42-
if (err)
43-
ext4_journal_abort_handle(where, __func__, bh,
44-
handle, err);
45-
}
46-
else
55+
might_sleep();
56+
57+
trace_ext4_forget(inode, is_metadata, blocknr);
58+
BUFFER_TRACE(bh, "enter");
59+
60+
jbd_debug(4, "forgetting bh %p: is_metadata = %d, mode %o, "
61+
"data mode %x\n",
62+
bh, is_metadata, inode->i_mode,
63+
test_opt(inode->i_sb, DATA_FLAGS));
64+
65+
/* In the no journal case, we can just do a bforget and return */
66+
if (!ext4_handle_valid(handle)) {
4767
bforget(bh);
48-
return err;
49-
}
68+
return 0;
69+
}
5070

51-
int __ext4_journal_revoke(const char *where, handle_t *handle,
52-
ext4_fsblk_t blocknr, struct buffer_head *bh)
53-
{
54-
int err = 0;
71+
/* Never use the revoke function if we are doing full data
72+
* journaling: there is no need to, and a V1 superblock won't
73+
* support it. Otherwise, only skip the revoke on un-journaled
74+
* data blocks. */
5575

56-
if (ext4_handle_valid(handle)) {
57-
err = jbd2_journal_revoke(handle, blocknr, bh);
58-
if (err)
59-
ext4_journal_abort_handle(where, __func__, bh,
60-
handle, err);
76+
if (test_opt(inode->i_sb, DATA_FLAGS) == EXT4_MOUNT_JOURNAL_DATA ||
77+
(!is_metadata && !ext4_should_journal_data(inode))) {
78+
if (bh) {
79+
BUFFER_TRACE(bh, "call jbd2_journal_forget");
80+
err = jbd2_journal_forget(handle, bh);
81+
if (err)
82+
ext4_journal_abort_handle(where, __func__, bh,
83+
handle, err);
84+
return err;
85+
}
86+
return 0;
6187
}
62-
else
63-
bforget(bh);
88+
89+
/*
90+
* data!=journal && (is_metadata || should_journal_data(inode))
91+
*/
92+
BUFFER_TRACE(bh, "call jbd2_journal_revoke");
93+
err = jbd2_journal_revoke(handle, blocknr, bh);
94+
if (err) {
95+
ext4_journal_abort_handle(where, __func__, bh, handle, err);
96+
ext4_abort(inode->i_sb, __func__,
97+
"error %d when attempting revoke", err);
98+
}
99+
BUFFER_TRACE(bh, "exit");
64100
return err;
65101
}
66102

‎fs/ext4/ext4_jbd2.h‎

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,15 @@
4949

5050
#define EXT4_DATA_TRANS_BLOCKS(sb) (EXT4_SINGLEDATA_TRANS_BLOCKS(sb) + \
5151
EXT4_XATTR_TRANS_BLOCKS - 2 + \
52-
2*EXT4_QUOTA_TRANS_BLOCKS(sb))
52+
EXT4_MAXQUOTAS_TRANS_BLOCKS(sb))
5353

5454
/*
5555
* Define the number of metadata blocks we need to account to modify data.
5656
*
5757
* This include super block, inode block, quota blocks and xattr blocks
5858
*/
5959
#define EXT4_META_TRANS_BLOCKS(sb) (EXT4_XATTR_TRANS_BLOCKS + \
60-
2*EXT4_QUOTA_TRANS_BLOCKS(sb))
60+
EXT4_MAXQUOTAS_TRANS_BLOCKS(sb))
6161

6262
/* Delete operations potentially hit one directory's namespace plus an
6363
* entire inode, plus arbitrary amounts of bitmap/indirection data. Be
@@ -92,13 +92,17 @@
9292
* but inode, sb and group updates are done only once */
9393
#define EXT4_QUOTA_INIT_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_INIT_ALLOC*\
9494
(EXT4_SINGLEDATA_TRANS_BLOCKS(sb)-3)+3+DQUOT_INIT_REWRITE) : 0)
95+
9596
#define EXT4_QUOTA_DEL_BLOCKS(sb) (test_opt(sb, QUOTA) ? (DQUOT_DEL_ALLOC*\
9697
(EXT4_SINGLEDATA_TRANS_BLOCKS(sb)-3)+3+DQUOT_DEL_REWRITE) : 0)
9798
#else
9899
#define EXT4_QUOTA_TRANS_BLOCKS(sb) 0
99100
#define EXT4_QUOTA_INIT_BLOCKS(sb) 0
100101
#define EXT4_QUOTA_DEL_BLOCKS(sb) 0
101102
#endif
103+
#define EXT4_MAXQUOTAS_TRANS_BLOCKS(sb) (MAXQUOTAS*EXT4_QUOTA_TRANS_BLOCKS(sb))
104+
#define EXT4_MAXQUOTAS_INIT_BLOCKS(sb) (MAXQUOTAS*EXT4_QUOTA_INIT_BLOCKS(sb))
105+
#define EXT4_MAXQUOTAS_DEL_BLOCKS(sb) (MAXQUOTAS*EXT4_QUOTA_DEL_BLOCKS(sb))
102106

103107
int
104108
ext4_mark_iloc_dirty(handle_t *handle,
@@ -116,12 +120,8 @@ int ext4_reserve_inode_write(handle_t *handle, struct inode *inode,
116120
int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode);
117121

118122
/*
119-
* Wrapper functions with which ext4 calls into JBD. The intent here is
120-
* to allow these to be turned into appropriate stubs so ext4 can control
121-
* ext2 filesystems, so ext2+ext4 systems only nee one fs. This work hasn't
122-
* been done yet.
123+
* Wrapper functions with which ext4 calls into JBD.
123124
*/
124-
125125
void ext4_journal_abort_handle(const char *caller, const char *err_fn,
126126
struct buffer_head *bh, handle_t *handle, int err);
127127

@@ -131,13 +131,9 @@ int __ext4_journal_get_undo_access(const char *where, handle_t *handle,
131131
int __ext4_journal_get_write_access(const char *where, handle_t *handle,
132132
struct buffer_head *bh);
133133

134-
/* When called with an invalid handle, this will still do a put on the BH */
135-
int __ext4_journal_forget(const char *where, handle_t *handle,
136-
struct buffer_head *bh);
137-
138-
/* When called with an invalid handle, this will still do a put on the BH */
139-
int __ext4_journal_revoke(const char *where, handle_t *handle,
140-
ext4_fsblk_t blocknr, struct buffer_head *bh);
134+
int __ext4_forget(const char *where, handle_t *handle, int is_metadata,
135+
struct inode *inode, struct buffer_head *bh,
136+
ext4_fsblk_t blocknr);
141137

142138
int __ext4_journal_get_create_access(const char *where,
143139
handle_t *handle, struct buffer_head *bh);
@@ -149,12 +145,11 @@ int __ext4_handle_dirty_metadata(const char *where, handle_t *handle,
149145
__ext4_journal_get_undo_access(__func__, (handle), (bh))
150146
#define ext4_journal_get_write_access(handle, bh) \
151147
__ext4_journal_get_write_access(__func__, (handle), (bh))
152-
#define ext4_journal_revoke(handle, blocknr, bh) \
153-
__ext4_journal_revoke(__func__, (handle), (blocknr), (bh))
148+
#define ext4_forget(handle, is_metadata, inode, bh, block_nr) \
149+
__ext4_forget(__func__, (handle), (is_metadata), (inode), (bh),\
150+
(block_nr))
154151
#define ext4_journal_get_create_access(handle, bh) \
155152
__ext4_journal_get_create_access(__func__, (handle), (bh))
156-
#define ext4_journal_forget(handle, bh) \
157-
__ext4_journal_forget(__func__, (handle), (bh))
158153
#define ext4_handle_dirty_metadata(handle, inode, bh) \
159154
__ext4_handle_dirty_metadata(__func__, (handle), (inode), (bh))
160155

@@ -254,6 +249,19 @@ static inline int ext4_jbd2_file_inode(handle_t *handle, struct inode *inode)
254249
return 0;
255250
}
256251

252+
static inline void ext4_update_inode_fsync_trans(handle_t *handle,
253+
struct inode *inode,
254+
int datasync)
255+
{
256+
struct ext4_inode_info *ei = EXT4_I(inode);
257+
258+
if (ext4_handle_valid(handle)) {
259+
ei->i_sync_tid = handle->h_transaction->t_tid;
260+
if (datasync)
261+
ei->i_datasync_tid = handle->h_transaction->t_tid;
262+
}
263+
}
264+
257265
/* super.c */
258266
int ext4_force_commit(struct super_block *sb);
259267

0 commit comments

Comments
 (0)