Skip to content

Commit f8409ab

Browse files
committed
Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
Pull ext4 updates from Ted Ts'o: "Clean ups and miscellaneous bug fixes, in particular for the new collapse_range and zero_range fallocate functions. In addition, improve the scalability of adding and remove inodes from the orphan list" * tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: (25 commits) ext4: handle symlink properly with inline_data ext4: fix wrong assert in ext4_mb_normalize_request() ext4: fix zeroing of page during writeback ext4: remove unused local variable "stored" from ext4_readdir(...) ext4: fix ZERO_RANGE test failure in data journalling ext4: reduce contention on s_orphan_lock ext4: use sbi in ext4_orphan_{add|del}() ext4: use EXT_MAX_BLOCKS in ext4_es_can_be_merged() ext4: add missing BUFFER_TRACE before ext4_journal_get_write_access ext4: remove unnecessary double parentheses ext4: do not destroy ext4_groupinfo_caches if ext4_mb_init() fails ext4: make local functions static ext4: fix block bitmap validation when bigalloc, ^flex_bg ext4: fix block bitmap initialization under sparse_super2 ext4: find the group descriptors on a 1k-block bigalloc,meta_bg filesystem ext4: avoid unneeded lookup when xattr name is invalid ext4: fix data integrity sync in ordered mode ext4: remove obsoleted check ext4: add a new spinlock i_raw_lock to protect the ext4's raw inode ext4: fix locking for O_APPEND writes ...
2 parents b20dcab + bd9db17 commit f8409ab

23 files changed

+515
-440
lines changed

fs/ext4/balloc.c

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ static inline int ext4_block_in_group(struct super_block *sb,
8383
/* Return the number of clusters used for file system metadata; this
8484
* represents the overhead needed by the file system.
8585
*/
86-
unsigned ext4_num_overhead_clusters(struct super_block *sb,
87-
ext4_group_t block_group,
88-
struct ext4_group_desc *gdp)
86+
static unsigned ext4_num_overhead_clusters(struct super_block *sb,
87+
ext4_group_t block_group,
88+
struct ext4_group_desc *gdp)
8989
{
9090
unsigned num_clusters;
9191
int block_cluster = -1, inode_cluster = -1, itbl_cluster = -1, i, c;
@@ -176,9 +176,10 @@ static unsigned int num_clusters_in_group(struct super_block *sb,
176176
}
177177

178178
/* Initializes an uninitialized block bitmap */
179-
void ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,
180-
ext4_group_t block_group,
181-
struct ext4_group_desc *gdp)
179+
static void ext4_init_block_bitmap(struct super_block *sb,
180+
struct buffer_head *bh,
181+
ext4_group_t block_group,
182+
struct ext4_group_desc *gdp)
182183
{
183184
unsigned int bit, bit_max;
184185
struct ext4_sb_info *sbi = EXT4_SB(sb);
@@ -307,6 +308,7 @@ static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb,
307308
ext4_group_t block_group,
308309
struct buffer_head *bh)
309310
{
311+
struct ext4_sb_info *sbi = EXT4_SB(sb);
310312
ext4_grpblk_t offset;
311313
ext4_grpblk_t next_zero_bit;
312314
ext4_fsblk_t blk;
@@ -326,33 +328,34 @@ static ext4_fsblk_t ext4_valid_block_bitmap(struct super_block *sb,
326328
/* check whether block bitmap block number is set */
327329
blk = ext4_block_bitmap(sb, desc);
328330
offset = blk - group_first_block;
329-
if (!ext4_test_bit(offset, bh->b_data))
331+
if (!ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
330332
/* bad block bitmap */
331333
return blk;
332334

333335
/* check whether the inode bitmap block number is set */
334336
blk = ext4_inode_bitmap(sb, desc);
335337
offset = blk - group_first_block;
336-
if (!ext4_test_bit(offset, bh->b_data))
338+
if (!ext4_test_bit(EXT4_B2C(sbi, offset), bh->b_data))
337339
/* bad block bitmap */
338340
return blk;
339341

340342
/* check whether the inode table block number is set */
341343
blk = ext4_inode_table(sb, desc);
342344
offset = blk - group_first_block;
343345
next_zero_bit = ext4_find_next_zero_bit(bh->b_data,
344-
offset + EXT4_SB(sb)->s_itb_per_group,
345-
offset);
346-
if (next_zero_bit < offset + EXT4_SB(sb)->s_itb_per_group)
346+
EXT4_B2C(sbi, offset + EXT4_SB(sb)->s_itb_per_group),
347+
EXT4_B2C(sbi, offset));
348+
if (next_zero_bit <
349+
EXT4_B2C(sbi, offset + EXT4_SB(sb)->s_itb_per_group))
347350
/* bad bitmap for inode tables */
348351
return blk;
349352
return 0;
350353
}
351354

352-
void ext4_validate_block_bitmap(struct super_block *sb,
353-
struct ext4_group_desc *desc,
354-
ext4_group_t block_group,
355-
struct buffer_head *bh)
355+
static void ext4_validate_block_bitmap(struct super_block *sb,
356+
struct ext4_group_desc *desc,
357+
ext4_group_t block_group,
358+
struct buffer_head *bh)
356359
{
357360
ext4_fsblk_t blk;
358361
struct ext4_group_info *grp = ext4_get_group_info(sb, block_group);
@@ -708,16 +711,6 @@ static inline int test_root(ext4_group_t a, int b)
708711
}
709712
}
710713

711-
static int ext4_group_sparse(ext4_group_t group)
712-
{
713-
if (group <= 1)
714-
return 1;
715-
if (!(group & 1))
716-
return 0;
717-
return (test_root(group, 7) || test_root(group, 5) ||
718-
test_root(group, 3));
719-
}
720-
721714
/**
722715
* ext4_bg_has_super - number of blocks used by the superblock in group
723716
* @sb: superblock for filesystem
@@ -728,11 +721,26 @@ static int ext4_group_sparse(ext4_group_t group)
728721
*/
729722
int ext4_bg_has_super(struct super_block *sb, ext4_group_t group)
730723
{
731-
if (EXT4_HAS_RO_COMPAT_FEATURE(sb,
732-
EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
733-
!ext4_group_sparse(group))
724+
struct ext4_super_block *es = EXT4_SB(sb)->s_es;
725+
726+
if (group == 0)
727+
return 1;
728+
if (EXT4_HAS_COMPAT_FEATURE(sb, EXT4_FEATURE_COMPAT_SPARSE_SUPER2)) {
729+
if (group == le32_to_cpu(es->s_backup_bgs[0]) ||
730+
group == le32_to_cpu(es->s_backup_bgs[1]))
731+
return 1;
734732
return 0;
735-
return 1;
733+
}
734+
if ((group <= 1) || !EXT4_HAS_RO_COMPAT_FEATURE(sb,
735+
EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER))
736+
return 1;
737+
if (!(group & 1))
738+
return 0;
739+
if (test_root(group, 3) || (test_root(group, 5)) ||
740+
test_root(group, 7))
741+
return 1;
742+
743+
return 0;
736744
}
737745

738746
static unsigned long ext4_bg_num_gdb_meta(struct super_block *sb,

fs/ext4/dir.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ int __ext4_check_dir_entry(const char *function, unsigned int line,
105105
static int ext4_readdir(struct file *file, struct dir_context *ctx)
106106
{
107107
unsigned int offset;
108-
int i, stored;
108+
int i;
109109
struct ext4_dir_entry_2 *de;
110110
int err;
111111
struct inode *inode = file_inode(file);
@@ -133,7 +133,6 @@ static int ext4_readdir(struct file *file, struct dir_context *ctx)
133133
return ret;
134134
}
135135

136-
stored = 0;
137136
offset = ctx->pos & (sb->s_blocksize - 1);
138137

139138
while (ctx->pos < inode->i_size) {

fs/ext4/ext4.h

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ struct ext4_allocation_request {
158158
#define EXT4_MAP_MAPPED (1 << BH_Mapped)
159159
#define EXT4_MAP_UNWRITTEN (1 << BH_Unwritten)
160160
#define EXT4_MAP_BOUNDARY (1 << BH_Boundary)
161-
#define EXT4_MAP_UNINIT (1 << BH_Uninit)
162161
/* Sometimes (in the bigalloc case, from ext4_da_get_block_prep) the caller of
163162
* ext4_map_blocks wants to know whether or not the underlying cluster has
164163
* already been accounted for. EXT4_MAP_FROM_CLUSTER conveys to the caller that
@@ -169,7 +168,7 @@ struct ext4_allocation_request {
169168
#define EXT4_MAP_FROM_CLUSTER (1 << BH_AllocFromCluster)
170169
#define EXT4_MAP_FLAGS (EXT4_MAP_NEW | EXT4_MAP_MAPPED |\
171170
EXT4_MAP_UNWRITTEN | EXT4_MAP_BOUNDARY |\
172-
EXT4_MAP_UNINIT | EXT4_MAP_FROM_CLUSTER)
171+
EXT4_MAP_FROM_CLUSTER)
173172

174173
struct ext4_map_blocks {
175174
ext4_fsblk_t m_pblk;
@@ -184,7 +183,7 @@ struct ext4_map_blocks {
184183
#define EXT4_IO_END_UNWRITTEN 0x0001
185184

186185
/*
187-
* For converting uninitialized extents on a work queue. 'handle' is used for
186+
* For converting unwritten extents on a work queue. 'handle' is used for
188187
* buffered writeback.
189188
*/
190189
typedef struct ext4_io_end {
@@ -537,26 +536,26 @@ enum {
537536
/*
538537
* Flags used by ext4_map_blocks()
539538
*/
540-
/* Allocate any needed blocks and/or convert an unitialized
539+
/* Allocate any needed blocks and/or convert an unwritten
541540
extent to be an initialized ext4 */
542541
#define EXT4_GET_BLOCKS_CREATE 0x0001
543-
/* Request the creation of an unitialized extent */
544-
#define EXT4_GET_BLOCKS_UNINIT_EXT 0x0002
545-
#define EXT4_GET_BLOCKS_CREATE_UNINIT_EXT (EXT4_GET_BLOCKS_UNINIT_EXT|\
542+
/* Request the creation of an unwritten extent */
543+
#define EXT4_GET_BLOCKS_UNWRIT_EXT 0x0002
544+
#define EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT (EXT4_GET_BLOCKS_UNWRIT_EXT|\
546545
EXT4_GET_BLOCKS_CREATE)
547546
/* Caller is from the delayed allocation writeout path
548547
* finally doing the actual allocation of delayed blocks */
549548
#define EXT4_GET_BLOCKS_DELALLOC_RESERVE 0x0004
550549
/* caller is from the direct IO path, request to creation of an
551-
unitialized extents if not allocated, split the uninitialized
550+
unwritten extents if not allocated, split the unwritten
552551
extent if blocks has been preallocated already*/
553552
#define EXT4_GET_BLOCKS_PRE_IO 0x0008
554553
#define EXT4_GET_BLOCKS_CONVERT 0x0010
555554
#define EXT4_GET_BLOCKS_IO_CREATE_EXT (EXT4_GET_BLOCKS_PRE_IO|\
556-
EXT4_GET_BLOCKS_CREATE_UNINIT_EXT)
555+
EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT)
557556
/* Convert extent to initialized after IO complete */
558557
#define EXT4_GET_BLOCKS_IO_CONVERT_EXT (EXT4_GET_BLOCKS_CONVERT|\
559-
EXT4_GET_BLOCKS_CREATE_UNINIT_EXT)
558+
EXT4_GET_BLOCKS_CREATE_UNWRIT_EXT)
560559
/* Eventual metadata allocation (due to growing extent tree)
561560
* should not fail, so try to use reserved blocks for that.*/
562561
#define EXT4_GET_BLOCKS_METADATA_NOFAIL 0x0020
@@ -876,6 +875,8 @@ struct ext4_inode_info {
876875
struct inode vfs_inode;
877876
struct jbd2_inode *jinode;
878877

878+
spinlock_t i_raw_lock; /* protects updates to the raw inode */
879+
879880
/*
880881
* File creation time. Its function is same as that of
881882
* struct timespec i_{a,c,m}time in the generic inode.
@@ -1159,7 +1160,8 @@ struct ext4_super_block {
11591160
__le32 s_usr_quota_inum; /* inode for tracking user quota */
11601161
__le32 s_grp_quota_inum; /* inode for tracking group quota */
11611162
__le32 s_overhead_clusters; /* overhead blocks/clusters in fs */
1162-
__le32 s_reserved[108]; /* Padding to the end of the block */
1163+
__le32 s_backup_bgs[2]; /* groups with sparse_super2 SBs */
1164+
__le32 s_reserved[106]; /* Padding to the end of the block */
11631165
__le32 s_checksum; /* crc32c(superblock) */
11641166
};
11651167

@@ -1505,6 +1507,7 @@ static inline void ext4_clear_state_flags(struct ext4_inode_info *ei)
15051507
#define EXT4_FEATURE_COMPAT_EXT_ATTR 0x0008
15061508
#define EXT4_FEATURE_COMPAT_RESIZE_INODE 0x0010
15071509
#define EXT4_FEATURE_COMPAT_DIR_INDEX 0x0020
1510+
#define EXT4_FEATURE_COMPAT_SPARSE_SUPER2 0x0200
15081511

15091512
#define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001
15101513
#define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002
@@ -1953,10 +1956,6 @@ extern void ext4_get_group_no_and_offset(struct super_block *sb,
19531956
extern ext4_group_t ext4_get_group_number(struct super_block *sb,
19541957
ext4_fsblk_t block);
19551958

1956-
extern void ext4_validate_block_bitmap(struct super_block *sb,
1957-
struct ext4_group_desc *desc,
1958-
ext4_group_t block_group,
1959-
struct buffer_head *bh);
19601959
extern unsigned int ext4_block_group(struct super_block *sb,
19611960
ext4_fsblk_t blocknr);
19621961
extern ext4_grpblk_t ext4_block_group_offset(struct super_block *sb,
@@ -1985,16 +1984,9 @@ extern int ext4_wait_block_bitmap(struct super_block *sb,
19851984
struct buffer_head *bh);
19861985
extern struct buffer_head *ext4_read_block_bitmap(struct super_block *sb,
19871986
ext4_group_t block_group);
1988-
extern void ext4_init_block_bitmap(struct super_block *sb,
1989-
struct buffer_head *bh,
1990-
ext4_group_t group,
1991-
struct ext4_group_desc *desc);
19921987
extern unsigned ext4_free_clusters_after_init(struct super_block *sb,
19931988
ext4_group_t block_group,
19941989
struct ext4_group_desc *gdp);
1995-
extern unsigned ext4_num_overhead_clusters(struct super_block *sb,
1996-
ext4_group_t block_group,
1997-
struct ext4_group_desc *gdp);
19981990
ext4_fsblk_t ext4_inode_to_goal_block(struct inode *);
19991991

20001992
/* dir.c */
@@ -2137,8 +2129,6 @@ extern int ext4_alloc_da_blocks(struct inode *inode);
21372129
extern void ext4_set_aops(struct inode *inode);
21382130
extern int ext4_writepage_trans_blocks(struct inode *);
21392131
extern int ext4_chunk_trans_blocks(struct inode *, int nrblocks);
2140-
extern int ext4_block_truncate_page(handle_t *handle,
2141-
struct address_space *mapping, loff_t from);
21422132
extern int ext4_zero_partial_blocks(handle_t *handle, struct inode *inode,
21432133
loff_t lstart, loff_t lend);
21442134
extern int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf);
@@ -2198,8 +2188,6 @@ extern int ext4_resize_fs(struct super_block *sb, ext4_fsblk_t n_blocks_count);
21982188

21992189
/* super.c */
22002190
extern int ext4_calculate_overhead(struct super_block *sb);
2201-
extern int ext4_superblock_csum_verify(struct super_block *sb,
2202-
struct ext4_super_block *es);
22032191
extern void ext4_superblock_csum_set(struct super_block *sb);
22042192
extern void *ext4_kvmalloc(size_t size, gfp_t flags);
22052193
extern void *ext4_kvzalloc(size_t size, gfp_t flags);
@@ -2571,19 +2559,11 @@ extern const struct file_operations ext4_dir_operations;
25712559
extern const struct inode_operations ext4_file_inode_operations;
25722560
extern const struct file_operations ext4_file_operations;
25732561
extern loff_t ext4_llseek(struct file *file, loff_t offset, int origin);
2574-
extern void ext4_unwritten_wait(struct inode *inode);
25752562

25762563
/* inline.c */
25772564
extern int ext4_has_inline_data(struct inode *inode);
2578-
extern int ext4_get_inline_size(struct inode *inode);
25792565
extern int ext4_get_max_inline_size(struct inode *inode);
25802566
extern int ext4_find_inline_data_nolock(struct inode *inode);
2581-
extern void ext4_write_inline_data(struct inode *inode,
2582-
struct ext4_iloc *iloc,
2583-
void *buffer, loff_t pos,
2584-
unsigned int len);
2585-
extern int ext4_prepare_inline_data(handle_t *handle, struct inode *inode,
2586-
unsigned int len);
25872567
extern int ext4_init_inline_data(handle_t *handle, struct inode *inode,
25882568
unsigned int len);
25892569
extern int ext4_destroy_inline_data(handle_t *handle, struct inode *inode);
@@ -2771,23 +2751,20 @@ extern void ext4_io_submit(struct ext4_io_submit *io);
27712751
extern int ext4_bio_write_page(struct ext4_io_submit *io,
27722752
struct page *page,
27732753
int len,
2774-
struct writeback_control *wbc);
2754+
struct writeback_control *wbc,
2755+
bool keep_towrite);
27752756

27762757
/* mmp.c */
27772758
extern int ext4_multi_mount_protect(struct super_block *, ext4_fsblk_t);
2778-
extern void ext4_mmp_csum_set(struct super_block *sb, struct mmp_struct *mmp);
2779-
extern int ext4_mmp_csum_verify(struct super_block *sb,
2780-
struct mmp_struct *mmp);
27812759

27822760
/*
27832761
* Note that these flags will never ever appear in a buffer_head's state flag.
27842762
* See EXT4_MAP_... to see where this is used.
27852763
*/
27862764
enum ext4_state_bits {
2787-
BH_Uninit /* blocks are allocated but uninitialized on disk */
2788-
= BH_JBDPrivateStart,
2789-
BH_AllocFromCluster, /* allocated blocks were part of already
2765+
BH_AllocFromCluster /* allocated blocks were part of already
27902766
* allocated cluster. */
2767+
= BH_JBDPrivateStart
27912768
};
27922769

27932770
/*

fs/ext4/ext4_extents.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,21 @@ struct ext4_ext_path {
137137
* EXT_INIT_MAX_LEN is the maximum number of blocks we can have in an
138138
* initialized extent. This is 2^15 and not (2^16 - 1), since we use the
139139
* MSB of ee_len field in the extent datastructure to signify if this
140-
* particular extent is an initialized extent or an uninitialized (i.e.
140+
* particular extent is an initialized extent or an unwritten (i.e.
141141
* preallocated).
142-
* EXT_UNINIT_MAX_LEN is the maximum number of blocks we can have in an
143-
* uninitialized extent.
142+
* EXT_UNWRITTEN_MAX_LEN is the maximum number of blocks we can have in an
143+
* unwritten extent.
144144
* If ee_len is <= 0x8000, it is an initialized extent. Otherwise, it is an
145-
* uninitialized one. In other words, if MSB of ee_len is set, it is an
146-
* uninitialized extent with only one special scenario when ee_len = 0x8000.
147-
* In this case we can not have an uninitialized extent of zero length and
145+
* unwritten one. In other words, if MSB of ee_len is set, it is an
146+
* unwritten extent with only one special scenario when ee_len = 0x8000.
147+
* In this case we can not have an unwritten extent of zero length and
148148
* thus we make it as a special case of initialized extent with 0x8000 length.
149149
* This way we get better extent-to-group alignment for initialized extents.
150150
* Hence, the maximum number of blocks we can have in an *initialized*
151-
* extent is 2^15 (32768) and in an *uninitialized* extent is 2^15-1 (32767).
151+
* extent is 2^15 (32768) and in an *unwritten* extent is 2^15-1 (32767).
152152
*/
153153
#define EXT_INIT_MAX_LEN (1UL << 15)
154-
#define EXT_UNINIT_MAX_LEN (EXT_INIT_MAX_LEN - 1)
154+
#define EXT_UNWRITTEN_MAX_LEN (EXT_INIT_MAX_LEN - 1)
155155

156156

157157
#define EXT_FIRST_EXTENT(__hdr__) \
@@ -187,14 +187,14 @@ static inline unsigned short ext_depth(struct inode *inode)
187187
return le16_to_cpu(ext_inode_hdr(inode)->eh_depth);
188188
}
189189

190-
static inline void ext4_ext_mark_uninitialized(struct ext4_extent *ext)
190+
static inline void ext4_ext_mark_unwritten(struct ext4_extent *ext)
191191
{
192-
/* We can not have an uninitialized extent of zero length! */
192+
/* We can not have an unwritten extent of zero length! */
193193
BUG_ON((le16_to_cpu(ext->ee_len) & ~EXT_INIT_MAX_LEN) == 0);
194194
ext->ee_len |= cpu_to_le16(EXT_INIT_MAX_LEN);
195195
}
196196

197-
static inline int ext4_ext_is_uninitialized(struct ext4_extent *ext)
197+
static inline int ext4_ext_is_unwritten(struct ext4_extent *ext)
198198
{
199199
/* Extent with ee_len of 0x8000 is treated as an initialized extent */
200200
return (le16_to_cpu(ext->ee_len) > EXT_INIT_MAX_LEN);

fs/ext4/ext4_jbd2.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ handle_t *__ext4_journal_start_reserved(handle_t *handle, unsigned int line,
122122
return handle;
123123
}
124124

125-
void ext4_journal_abort_handle(const char *caller, unsigned int line,
126-
const char *err_fn, struct buffer_head *bh,
127-
handle_t *handle, int err)
125+
static void ext4_journal_abort_handle(const char *caller, unsigned int line,
126+
const char *err_fn,
127+
struct buffer_head *bh,
128+
handle_t *handle, int err)
128129
{
129130
char nbuf[16];
130131
const char *errstr = ext4_decode_error(NULL, err, nbuf);

fs/ext4/ext4_jbd2.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,6 @@ int ext4_mark_inode_dirty(handle_t *handle, struct inode *inode);
231231
/*
232232
* Wrapper functions with which ext4 calls into JBD.
233233
*/
234-
void ext4_journal_abort_handle(const char *caller, unsigned int line,
235-
const char *err_fn,
236-
struct buffer_head *bh, handle_t *handle, int err);
237-
238234
int __ext4_journal_get_write_access(const char *where, unsigned int line,
239235
handle_t *handle, struct buffer_head *bh);
240236

0 commit comments

Comments
 (0)