Skip to content

Commit e4ce30f

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: (40 commits) ext4: Make fsync sync new parent directories in no-journal mode ext4: Drop whitespace at end of lines ext4: Fix compat EXT4_IOC_ADD_GROUP ext4: Conditionally define compat ioctl numbers tracing: Convert more ext4 events to DEFINE_EVENT ext4: Add new tracepoints to track mballoc's buddy bitmap loads ext4: Add a missing trace hook ext4: restart ext4_ext_remove_space() after transaction restart ext4: Clear the EXT4_EOFBLOCKS_FL flag only when warranted ext4: Avoid crashing on NULL ptr dereference on a filesystem error ext4: Use bitops to read/modify i_flags in struct ext4_inode_info ext4: Convert calls of ext4_error() to EXT4_ERROR_INODE() ext4: Convert callers of ext4_get_blocks() to use ext4_map_blocks() ext4: Add new abstraction ext4_map_blocks() underneath ext4_get_blocks() ext4: Use our own write_cache_pages() ext4: Show journal_checksum option ext4: Fix for ext4_mb_collect_stats() ext4: check for a good block group before loading buddy pages ext4: Prevent creation of files larger than RLIMIT_FSIZE using fallocate ext4: Remove extraneous newlines in ext4_msg() calls ... Fixed up trivial conflict in fs/ext4/fsync.c
2 parents b899ebe + 14ece10 commit e4ce30f

23 files changed

Lines changed: 1136 additions & 834 deletions

‎fs/ext4/balloc.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -591,14 +591,15 @@ ext4_fsblk_t ext4_new_meta_blocks(handle_t *handle, struct inode *inode,
591591
ret = ext4_mb_new_blocks(handle, &ar, errp);
592592
if (count)
593593
*count = ar.len;
594-
595594
/*
596-
* Account for the allocated meta blocks
595+
* Account for the allocated meta blocks. We will never
596+
* fail EDQUOT for metdata, but we do account for it.
597597
*/
598598
if (!(*errp) && EXT4_I(inode)->i_delalloc_reserved_flag) {
599599
spin_lock(&EXT4_I(inode)->i_block_reservation_lock);
600600
EXT4_I(inode)->i_allocated_meta_blocks += ar.len;
601601
spin_unlock(&EXT4_I(inode)->i_block_reservation_lock);
602+
dquot_alloc_block_nofail(inode, ar.len);
602603
}
603604
return ret;
604605
}

‎fs/ext4/block_validity.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@ static int add_system_zone(struct ext4_sb_info *sbi,
7272
else if (start_blk >= (entry->start_blk + entry->count))
7373
n = &(*n)->rb_right;
7474
else {
75-
if (start_blk + count > (entry->start_blk +
75+
if (start_blk + count > (entry->start_blk +
7676
entry->count))
77-
entry->count = (start_blk + count -
77+
entry->count = (start_blk + count -
7878
entry->start_blk);
7979
new_node = *n;
8080
new_entry = rb_entry(new_node, struct ext4_system_zone,

‎fs/ext4/dir.c‎

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,10 @@ int ext4_check_dir_entry(const char *function, struct inode *dir,
8383
error_msg = "inode out of bounds";
8484

8585
if (error_msg != NULL)
86-
__ext4_error(dir->i_sb, function,
87-
"bad entry in directory #%lu: %s - block=%llu"
86+
ext4_error_inode(function, dir,
87+
"bad entry in directory: %s - block=%llu"
8888
"offset=%u(%u), inode=%u, rec_len=%d, name_len=%d",
89-
dir->i_ino, error_msg,
90-
(unsigned long long) bh->b_blocknr,
89+
error_msg, (unsigned long long) bh->b_blocknr,
9190
(unsigned) (offset%bh->b_size), offset,
9291
le32_to_cpu(de->inode),
9392
rlen, de->name_len);
@@ -111,7 +110,7 @@ static int ext4_readdir(struct file *filp,
111110

112111
if (EXT4_HAS_COMPAT_FEATURE(inode->i_sb,
113112
EXT4_FEATURE_COMPAT_DIR_INDEX) &&
114-
((EXT4_I(inode)->i_flags & EXT4_INDEX_FL) ||
113+
((ext4_test_inode_flag(inode, EXT4_INODE_INDEX)) ||
115114
((inode->i_size >> sb->s_blocksize_bits) == 1))) {
116115
err = ext4_dx_readdir(filp, dirent, filldir);
117116
if (err != ERR_BAD_DX_DIR) {
@@ -122,28 +121,28 @@ static int ext4_readdir(struct file *filp,
122121
* We don't set the inode dirty flag since it's not
123122
* critical that it get flushed back to the disk.
124123
*/
125-
EXT4_I(filp->f_path.dentry->d_inode)->i_flags &= ~EXT4_INDEX_FL;
124+
ext4_clear_inode_flag(filp->f_path.dentry->d_inode, EXT4_INODE_INDEX);
126125
}
127126
stored = 0;
128127
offset = filp->f_pos & (sb->s_blocksize - 1);
129128

130129
while (!error && !stored && filp->f_pos < inode->i_size) {
131-
ext4_lblk_t blk = filp->f_pos >> EXT4_BLOCK_SIZE_BITS(sb);
132-
struct buffer_head map_bh;
130+
struct ext4_map_blocks map;
133131
struct buffer_head *bh = NULL;
134132

135-
map_bh.b_state = 0;
136-
err = ext4_get_blocks(NULL, inode, blk, 1, &map_bh, 0);
133+
map.m_lblk = filp->f_pos >> EXT4_BLOCK_SIZE_BITS(sb);
134+
map.m_len = 1;
135+
err = ext4_map_blocks(NULL, inode, &map, 0);
137136
if (err > 0) {
138-
pgoff_t index = map_bh.b_blocknr >>
137+
pgoff_t index = map.m_pblk >>
139138
(PAGE_CACHE_SHIFT - inode->i_blkbits);
140139
if (!ra_has_index(&filp->f_ra, index))
141140
page_cache_sync_readahead(
142141
sb->s_bdev->bd_inode->i_mapping,
143142
&filp->f_ra, filp,
144143
index, 1);
145144
filp->f_ra.prev_pos = (loff_t)index << PAGE_CACHE_SHIFT;
146-
bh = ext4_bread(NULL, inode, blk, 0, &err);
145+
bh = ext4_bread(NULL, inode, map.m_lblk, 0, &err);
147146
}
148147

149148
/*
@@ -152,9 +151,8 @@ static int ext4_readdir(struct file *filp,
152151
*/
153152
if (!bh) {
154153
if (!dir_has_error) {
155-
ext4_error(sb, "directory #%lu "
154+
EXT4_ERROR_INODE(inode, "directory "
156155
"contains a hole at offset %Lu",
157-
inode->i_ino,
158156
(unsigned long long) filp->f_pos);
159157
dir_has_error = 1;
160158
}

‎fs/ext4/ext4.h‎

Lines changed: 145 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
#include <linux/wait.h>
3030
#include <linux/blockgroup_lock.h>
3131
#include <linux/percpu_counter.h>
32+
#ifdef __KERNEL__
33+
#include <linux/compat.h>
34+
#endif
3235

3336
/*
3437
* The fourth extended filesystem constants/structures
@@ -54,10 +57,10 @@
5457
#endif
5558

5659
#define EXT4_ERROR_INODE(inode, fmt, a...) \
57-
ext4_error_inode(__func__, (inode), (fmt), ## a);
60+
ext4_error_inode(__func__, (inode), (fmt), ## a)
5861

5962
#define EXT4_ERROR_FILE(file, fmt, a...) \
60-
ext4_error_file(__func__, (file), (fmt), ## a);
63+
ext4_error_file(__func__, (file), (fmt), ## a)
6164

6265
/* data type for block offset of block group */
6366
typedef int ext4_grpblk_t;
@@ -72,7 +75,7 @@ typedef __u32 ext4_lblk_t;
7275
typedef unsigned int ext4_group_t;
7376

7477
/*
75-
* Flags used in mballoc's allocation_context flags field.
78+
* Flags used in mballoc's allocation_context flags field.
7679
*
7780
* Also used to show what's going on for debugging purposes when the
7881
* flag field is exported via the traceport interface
@@ -125,6 +128,29 @@ struct ext4_allocation_request {
125128
unsigned int flags;
126129
};
127130

131+
/*
132+
* Logical to physical block mapping, used by ext4_map_blocks()
133+
*
134+
* This structure is used to pass requests into ext4_map_blocks() as
135+
* well as to store the information returned by ext4_map_blocks(). It
136+
* takes less room on the stack than a struct buffer_head.
137+
*/
138+
#define EXT4_MAP_NEW (1 << BH_New)
139+
#define EXT4_MAP_MAPPED (1 << BH_Mapped)
140+
#define EXT4_MAP_UNWRITTEN (1 << BH_Unwritten)
141+
#define EXT4_MAP_BOUNDARY (1 << BH_Boundary)
142+
#define EXT4_MAP_UNINIT (1 << BH_Uninit)
143+
#define EXT4_MAP_FLAGS (EXT4_MAP_NEW | EXT4_MAP_MAPPED |\
144+
EXT4_MAP_UNWRITTEN | EXT4_MAP_BOUNDARY |\
145+
EXT4_MAP_UNINIT)
146+
147+
struct ext4_map_blocks {
148+
ext4_fsblk_t m_pblk;
149+
ext4_lblk_t m_lblk;
150+
unsigned int m_len;
151+
unsigned int m_flags;
152+
};
153+
128154
/*
129155
* For delayed allocation tracking
130156
*/
@@ -321,6 +347,83 @@ static inline __u32 ext4_mask_flags(umode_t mode, __u32 flags)
321347
return flags & EXT4_OTHER_FLMASK;
322348
}
323349

350+
/*
351+
* Inode flags used for atomic set/get
352+
*/
353+
enum {
354+
EXT4_INODE_SECRM = 0, /* Secure deletion */
355+
EXT4_INODE_UNRM = 1, /* Undelete */
356+
EXT4_INODE_COMPR = 2, /* Compress file */
357+
EXT4_INODE_SYNC = 3, /* Synchronous updates */
358+
EXT4_INODE_IMMUTABLE = 4, /* Immutable file */
359+
EXT4_INODE_APPEND = 5, /* writes to file may only append */
360+
EXT4_INODE_NODUMP = 6, /* do not dump file */
361+
EXT4_INODE_NOATIME = 7, /* do not update atime */
362+
/* Reserved for compression usage... */
363+
EXT4_INODE_DIRTY = 8,
364+
EXT4_INODE_COMPRBLK = 9, /* One or more compressed clusters */
365+
EXT4_INODE_NOCOMPR = 10, /* Don't compress */
366+
EXT4_INODE_ECOMPR = 11, /* Compression error */
367+
/* End compression flags --- maybe not all used */
368+
EXT4_INODE_INDEX = 12, /* hash-indexed directory */
369+
EXT4_INODE_IMAGIC = 13, /* AFS directory */
370+
EXT4_INODE_JOURNAL_DATA = 14, /* file data should be journaled */
371+
EXT4_INODE_NOTAIL = 15, /* file tail should not be merged */
372+
EXT4_INODE_DIRSYNC = 16, /* dirsync behaviour (directories only) */
373+
EXT4_INODE_TOPDIR = 17, /* Top of directory hierarchies*/
374+
EXT4_INODE_HUGE_FILE = 18, /* Set to each huge file */
375+
EXT4_INODE_EXTENTS = 19, /* Inode uses extents */
376+
EXT4_INODE_EA_INODE = 21, /* Inode used for large EA */
377+
EXT4_INODE_EOFBLOCKS = 22, /* Blocks allocated beyond EOF */
378+
EXT4_INODE_RESERVED = 31, /* reserved for ext4 lib */
379+
};
380+
381+
#define TEST_FLAG_VALUE(FLAG) (EXT4_##FLAG##_FL == (1 << EXT4_INODE_##FLAG))
382+
#define CHECK_FLAG_VALUE(FLAG) if (!TEST_FLAG_VALUE(FLAG)) { \
383+
printk(KERN_EMERG "EXT4 flag fail: " #FLAG ": %d %d\n", \
384+
EXT4_##FLAG##_FL, EXT4_INODE_##FLAG); BUG_ON(1); }
385+
386+
/*
387+
* Since it's pretty easy to mix up bit numbers and hex values, and we
388+
* can't do a compile-time test for ENUM values, we use a run-time
389+
* test to make sure that EXT4_XXX_FL is consistent with respect to
390+
* EXT4_INODE_XXX. If all is well the printk and BUG_ON will all drop
391+
* out so it won't cost any extra space in the compiled kernel image.
392+
* But it's important that these values are the same, since we are
393+
* using EXT4_INODE_XXX to test for the flag values, but EXT4_XX_FL
394+
* must be consistent with the values of FS_XXX_FL defined in
395+
* include/linux/fs.h and the on-disk values found in ext2, ext3, and
396+
* ext4 filesystems, and of course the values defined in e2fsprogs.
397+
*
398+
* It's not paranoia if the Murphy's Law really *is* out to get you. :-)
399+
*/
400+
static inline void ext4_check_flag_values(void)
401+
{
402+
CHECK_FLAG_VALUE(SECRM);
403+
CHECK_FLAG_VALUE(UNRM);
404+
CHECK_FLAG_VALUE(COMPR);
405+
CHECK_FLAG_VALUE(SYNC);
406+
CHECK_FLAG_VALUE(IMMUTABLE);
407+
CHECK_FLAG_VALUE(APPEND);
408+
CHECK_FLAG_VALUE(NODUMP);
409+
CHECK_FLAG_VALUE(NOATIME);
410+
CHECK_FLAG_VALUE(DIRTY);
411+
CHECK_FLAG_VALUE(COMPRBLK);
412+
CHECK_FLAG_VALUE(NOCOMPR);
413+
CHECK_FLAG_VALUE(ECOMPR);
414+
CHECK_FLAG_VALUE(INDEX);
415+
CHECK_FLAG_VALUE(IMAGIC);
416+
CHECK_FLAG_VALUE(JOURNAL_DATA);
417+
CHECK_FLAG_VALUE(NOTAIL);
418+
CHECK_FLAG_VALUE(DIRSYNC);
419+
CHECK_FLAG_VALUE(TOPDIR);
420+
CHECK_FLAG_VALUE(HUGE_FILE);
421+
CHECK_FLAG_VALUE(EXTENTS);
422+
CHECK_FLAG_VALUE(EA_INODE);
423+
CHECK_FLAG_VALUE(EOFBLOCKS);
424+
CHECK_FLAG_VALUE(RESERVED);
425+
}
426+
324427
/* Used to pass group descriptor data when online resize is done */
325428
struct ext4_new_group_input {
326429
__u32 group; /* Group number for this data */
@@ -332,6 +435,18 @@ struct ext4_new_group_input {
332435
__u16 unused;
333436
};
334437

438+
#if defined(__KERNEL__) && defined(CONFIG_COMPAT)
439+
struct compat_ext4_new_group_input {
440+
u32 group;
441+
compat_u64 block_bitmap;
442+
compat_u64 inode_bitmap;
443+
compat_u64 inode_table;
444+
u32 blocks_count;
445+
u16 reserved_blocks;
446+
u16 unused;
447+
};
448+
#endif
449+
335450
/* The struct ext4_new_group_input in kernel space, with free_blocks_count */
336451
struct ext4_new_group_data {
337452
__u32 group;
@@ -355,7 +470,7 @@ struct ext4_new_group_data {
355470
#define EXT4_GET_BLOCKS_CREATE_UNINIT_EXT (EXT4_GET_BLOCKS_UNINIT_EXT|\
356471
EXT4_GET_BLOCKS_CREATE)
357472
/* Caller is from the delayed allocation writeout path,
358-
so set the magic i_delalloc_reserve_flag after taking the
473+
so set the magic i_delalloc_reserve_flag after taking the
359474
inode allocation semaphore for */
360475
#define EXT4_GET_BLOCKS_DELALLOC_RESERVE 0x0004
361476
/* caller is from the direct IO path, request to creation of an
@@ -398,6 +513,7 @@ struct ext4_new_group_data {
398513
#define EXT4_IOC_ALLOC_DA_BLKS _IO('f', 12)
399514
#define EXT4_IOC_MOVE_EXT _IOWR('f', 15, struct move_extent)
400515

516+
#if defined(__KERNEL__) && defined(CONFIG_COMPAT)
401517
/*
402518
* ioctl commands in 32 bit emulation
403519
*/
@@ -408,11 +524,13 @@ struct ext4_new_group_data {
408524
#define EXT4_IOC32_GETRSVSZ _IOR('f', 5, int)
409525
#define EXT4_IOC32_SETRSVSZ _IOW('f', 6, int)
410526
#define EXT4_IOC32_GROUP_EXTEND _IOW('f', 7, unsigned int)
527+
#define EXT4_IOC32_GROUP_ADD _IOW('f', 8, struct compat_ext4_new_group_input)
411528
#ifdef CONFIG_JBD2_DEBUG
412529
#define EXT4_IOC32_WAIT_FOR_READONLY _IOR('f', 99, int)
413530
#endif
414531
#define EXT4_IOC32_GETVERSION_OLD FS_IOC32_GETVERSION
415532
#define EXT4_IOC32_SETVERSION_OLD FS_IOC32_SETVERSION
533+
#endif
416534

417535

418536
/*
@@ -616,9 +734,8 @@ struct ext4_ext_cache {
616734
*/
617735
struct ext4_inode_info {
618736
__le32 i_data[15]; /* unconverted */
619-
__u32 i_flags;
620-
ext4_fsblk_t i_file_acl;
621737
__u32 i_dtime;
738+
ext4_fsblk_t i_file_acl;
622739

623740
/*
624741
* i_block_group is the number of the block group which contains
@@ -629,6 +746,7 @@ struct ext4_inode_info {
629746
*/
630747
ext4_group_t i_block_group;
631748
unsigned long i_state_flags; /* Dynamic state flags */
749+
unsigned long i_flags;
632750

633751
ext4_lblk_t i_dir_start_lookup;
634752
#ifdef CONFIG_EXT4_FS_XATTR
@@ -1062,22 +1180,25 @@ enum {
10621180
EXT4_STATE_DA_ALLOC_CLOSE, /* Alloc DA blks on close */
10631181
EXT4_STATE_EXT_MIGRATE, /* Inode is migrating */
10641182
EXT4_STATE_DIO_UNWRITTEN, /* need convert on dio done*/
1183+
EXT4_STATE_NEWENTRY, /* File just added to dir */
10651184
};
10661185

1067-
static inline int ext4_test_inode_state(struct inode *inode, int bit)
1068-
{
1069-
return test_bit(bit, &EXT4_I(inode)->i_state_flags);
1070-
}
1071-
1072-
static inline void ext4_set_inode_state(struct inode *inode, int bit)
1073-
{
1074-
set_bit(bit, &EXT4_I(inode)->i_state_flags);
1186+
#define EXT4_INODE_BIT_FNS(name, field) \
1187+
static inline int ext4_test_inode_##name(struct inode *inode, int bit) \
1188+
{ \
1189+
return test_bit(bit, &EXT4_I(inode)->i_##field); \
1190+
} \
1191+
static inline void ext4_set_inode_##name(struct inode *inode, int bit) \
1192+
{ \
1193+
set_bit(bit, &EXT4_I(inode)->i_##field); \
1194+
} \
1195+
static inline void ext4_clear_inode_##name(struct inode *inode, int bit) \
1196+
{ \
1197+
clear_bit(bit, &EXT4_I(inode)->i_##field); \
10751198
}
10761199

1077-
static inline void ext4_clear_inode_state(struct inode *inode, int bit)
1078-
{
1079-
clear_bit(bit, &EXT4_I(inode)->i_state_flags);
1080-
}
1200+
EXT4_INODE_BIT_FNS(flag, flags)
1201+
EXT4_INODE_BIT_FNS(state, state_flags)
10811202
#else
10821203
/* Assume that user mode programs are passing in an ext4fs superblock, not
10831204
* a kernel struct super_block. This will allow us to call the feature-test
@@ -1264,7 +1385,7 @@ struct ext4_dir_entry_2 {
12641385

12651386
#define is_dx(dir) (EXT4_HAS_COMPAT_FEATURE(dir->i_sb, \
12661387
EXT4_FEATURE_COMPAT_DIR_INDEX) && \
1267-
(EXT4_I(dir)->i_flags & EXT4_INDEX_FL))
1388+
ext4_test_inode_flag((dir), EXT4_INODE_INDEX))
12681389
#define EXT4_DIR_LINK_MAX(dir) (!is_dx(dir) && (dir)->i_nlink >= EXT4_LINK_MAX)
12691390
#define EXT4_DIR_LINK_EMPTY(dir) ((dir)->i_nlink == 2 || (dir)->i_nlink == 1)
12701391

@@ -1678,6 +1799,7 @@ struct ext4_group_info {
16781799
ext4_grpblk_t bb_first_free; /* first free block */
16791800
ext4_grpblk_t bb_free; /* total free blocks */
16801801
ext4_grpblk_t bb_fragments; /* nr of freespace fragments */
1802+
ext4_grpblk_t bb_largest_free_order;/* order of largest frag in BG */
16811803
struct list_head bb_prealloc_list;
16821804
#ifdef DOUBLE_CHECK
16831805
void *bb_bitmap;
@@ -1772,16 +1894,17 @@ extern int ext4_ext_tree_init(handle_t *handle, struct inode *);
17721894
extern int ext4_ext_writepage_trans_blocks(struct inode *, int);
17731895
extern int ext4_ext_index_trans_blocks(struct inode *inode, int nrblocks,
17741896
int chunk);
1775-
extern int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,
1776-
ext4_lblk_t iblock, unsigned int max_blocks,
1777-
struct buffer_head *bh_result, int flags);
1897+
extern int ext4_ext_map_blocks(handle_t *handle, struct inode *inode,
1898+
struct ext4_map_blocks *map, int flags);
17781899
extern void ext4_ext_truncate(struct inode *);
17791900
extern void ext4_ext_init(struct super_block *);
17801901
extern void ext4_ext_release(struct super_block *);
17811902
extern long ext4_fallocate(struct inode *inode, int mode, loff_t offset,
17821903
loff_t len);
17831904
extern int ext4_convert_unwritten_extents(struct inode *inode, loff_t offset,
17841905
ssize_t len);
1906+
extern int ext4_map_blocks(handle_t *handle, struct inode *inode,
1907+
struct ext4_map_blocks *map, int flags);
17851908
extern int ext4_get_blocks(handle_t *handle, struct inode *inode,
17861909
sector_t block, unsigned int max_blocks,
17871910
struct buffer_head *bh, int flags);

0 commit comments

Comments
 (0)