ext4 merge plans for 2.6.25
Subsystems (9)
Theodore Ts'o
maintainerThe following patches have been in the -mm tree for a while, and I plan to push them to Linus when the 2.6.25 merge window opens. With this patch series, it is expected that ext4 format should be settling down. We still have delayed allocation and online defrag which aren't quite ready to merge, but those shouldn't affect the on-disk format.
I don't expect any other on-disk format changes to show up after this point, but I've been wrong before.... any such changes would have to have a Really Good Reason, though. (No, Abhishek Rai's changes wouldn't count as an on-disk change, since they change layout choices, but not anything that e2fsck would actually care about. We may try merging those into ext4 and see how they play out in the -mm tree; we'll see.)
- Ted
P.S. Yes, the currently released e2fsprogs won't support all of these format changes yet; again ext4, shouldn't be deployed to production systems yet, although we do salute those who are willing to be guinea pigs and play with this code! Never fear, I'll be working to get e2fsprogs caught up Real Soon Now.
Adrian Bunk (1):
ext4/super.c: fix #ifdef's (CONFIG_EXT4_* -> CONFIG_EXT4DEV_*)
Alex Tomas (2):
ext4: Add new functions for searching extent tree
ext4: Add multi block allocator for ext4
Aneesh Kumar K.V (23):
ext4: Introduce ext4_lblk_t
ext4: Introduce ext4_update_*_feature
ext4: Fix sparse warnings.
ext4: Rename i_file_acl to i_file_acl_lo
ext4: Rename i_dir_acl to i_size_high
ext4: Add support for 48 bit inode i_blocks.
ext4: Support large files
ext2: Fix the max file size for ext2 file system.
ext3: Fix the max file size for ext3 file system.
ext4: Return after ext4_error in case of failures
ext4: Change the default behaviour on error
Add buffer head related helper functions
ext4: add block bitmap validation
ext4: Check for the correct error return from
ext4: Make ext4_get_blocks_wrap take the truncate_mutex early.
ext4: Convert truncate_mutex to read write semaphore.
ext4: Take read lock during overwrite case.
ext4: Add EXT4_IOC_MIGRATE ioctl
ext4: Fix ext4_show_options to show the correct mount options.
ext4: Add ext4_find_next_bit()
ext4: Enable the multiblock allocator by default
ext4: Check for return value from sb_set_blocksize
ext4: Use the ext4_ext_actual_len() helper function
Avantika Mathur (2):
ext4: add ext4_group_t, and change all group variables to this type.
ext4: fixes block group number being set to a negative value
Chris Snook (1):
jbd2: Remove printk from J_ASSERT to preserve registers during BUG
Coly Li (1):
ext4: sync up block group descriptor with e2fsprogs.
Dmitry Monakhov (1):
ext4: fix uniniatilized extent splitting error
Eric Sandeen (6):
ext4 extents: remove unneeded casts
ext4: different maxbytes functions for bitmap & extent files
ext4: export iov_shorten from kernel for ext4's use
ext4: store maxbytes for bitmapped files and return EFBIG as appropriate
ext4: fix oops on corrupted ext4 mount
ext4: fix up EXT4FS_DEBUG builds
Girish Shilamkar (1):
ext4: Add the journal checksum feature
Jan Kara (2):
ext4: Avoid rec_len overflow with 64KB block size
jbd2: Fix assertion failure in fs/jbd2/checkpoint.c
Jean Noel Cordenner (2):
vfs: Add 64 bit i_version support
ext4: Add inode version support in ext4
Johann Lombardi (1):
jbd2: jbd2 stats through procfs
Mariusz Kozlowski (1):
ext4: remove unused code from ext4_find_entry()
Mingming Cao (4):
jbd2: add lockdep support
jbd2: Mark jbd2 slabs as SLAB_TEMPORARY
jbd2: Use round-jiffies() function for the "5 second" ext4/jbd2 wakeup
jbd2: sparse pointer use of zero as null
Takashi Sato (1):
ext4: Support large blocksize up to PAGESIZE
Theodore Ts'o
maintainerPATCH 39/49 ext4: Add ext4_find_next_bit()
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
This function is used by the ext4 multi block allocator patches.
Also add generic_find_next_le_bit
--- include/asm-arm/bitops.h | 2 + include/asm-generic/bitops/ext2-non-atomic.h | 2 + include/asm-generic/bitops/le.h | 4 ++ include/asm-m68k/bitops.h | 2 + include/asm-m68knommu/bitops.h | 2 + include/asm-powerpc/bitops.h | 4 ++ include/asm-s390/bitops.h | 2 + include/linux/ext4_fs.h | 1 + lib/find_next_bit.c | 43 ++++++++++++++++++++++++++ 9 files changed, 62 insertions(+), 0 deletions(-)
include/asm-arm/bitops.h +2 -0
@@ -310,6 +310,8 @@ static inline int constant_fls(int x) _find_first_zero_bit_le(p,sz)#define ext2_find_next_zero_bit (p,sz,off) \ _find_next_zero_bit_le(p,sz,off) +#define ext2_find_next_bit (p, sz, off) \ + _find_next_bit_le(p, sz, off)/* * Minix is defined to use little-endian byte ordering.
include/asm-generic/bitops/ext2-non-atomic.h +2 -0
@@ -14,5 +14,7 @@ generic_find_first_zero_le_bit((unsigned long *)(addr), (size))#define ext2_find_next_zero_bit (addr, size, off) \ generic_find_next_zero_le_bit((unsigned long *)(addr), (size), (off)) +#define ext2_find_next_bit (addr, size, off) \ + generic_find_next_le_bit((unsigned long *)(addr), (size), (off))#endif /* _ASM_GENERIC_BITOPS_EXT2_NON_ATOMIC_H_ */
include/asm-generic/bitops/le.h +4 -0
@@ -20,6 +20,8 @@#define generic___test_and_clear_le_bit (nr, addr) __test_and_clear_bit(nr, addr)#define generic_find_next_zero_le_bit (addr, size, offset) find_next_zero_bit(addr, size, offset) +#define generic_find_next_le_bit (addr, size, offset) \ + find_next_bit(addr, size, offset)#elif defined(__BIG_ENDIAN)
@@ -42,6 +44,8 @@extern unsigned long generic_find_next_zero_le_bit (const unsigned long *addr,unsigned long size,unsigned long offset); +extern unsigned long generic_find_next_le_bit (const unsigned long *addr, +unsigned long size,unsigned long offset);#else #error "Please fix <asm/byteorder.h>"
include/asm-m68k/bitops.h +2 -0
@@ -410,6 +410,8 @@ static inline int ext2_find_next_zero_bit(const void *vaddr, unsigned size, res =ext2_find_first_zero_bit (p, size -32 * (p - addr)); return (p - addr) * 32 + res; } +#define ext2_find_next_bit (addr, size, off) \ + generic_find_next_le_bit((unsigned long *)(addr), (size), (off))#endif /* __KERNEL__ */
include/asm-m68knommu/bitops.h +2 -0
@@ -294,6 +294,8 @@ found_middle: return result + ffz(__swab32(tmp)); } +#define ext2_find_next_bit (addr, size, off) \ + generic_find_next_le_bit((unsigned long *)(addr), (size), (off))#include <asm-generic/bitops/minix.h> #endif /* __KERNEL__ */
include/asm-powerpc/bitops.h +4 -0
@@ -359,6 +359,8 @@ static __inline__ int test_le_bit(unsigned long nr,unsigned long generic_find_next_zero_le_bit (const unsigned long *addr,unsigned long size,unsigned long offset); +unsigned long generic_find_next_le_bit (const unsigned long *addr, +unsigned long size,unsigned long offset);/* Bitmap functions for the ext2 filesystem */ #define ext2_set_bit (nr,addr) \
@@ -378,6 +380,8 @@ unsigned long generic_find_next_zero_le_bit(const unsigned long *addr,#define ext2_find_next_zero_bit (addr, size, off) \ generic_find_next_zero_le_bit((unsigned long*)addr, size, off) +#define ext2_find_next_bit (addr, size, off) \ + generic_find_next_le_bit((unsigned long *)addr, size, off)/* Bitmap functions for the minix filesystem. */ #define minix_test_and_set_bit (nr,addr) \
include/asm-s390/bitops.h +2 -0
@@ -772,6 +772,8 @@ static inline int sched_find_first_bit(unsigned long *b) test_and_clear_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr)#define ext2_test_bit (nr, addr) \ test_bit((nr)^(__BITOPS_WORDSIZE - 8), (unsigned long *)addr) +#define ext2_find_next_bit (addr, size, off) \ + generic_find_next_le_bit((unsigned long *)(addr), (size), (off))#ifndef __s390x__
include/linux/ext4_fs.h +1 -0
@@ -493,6 +493,7 @@ do { \#define ext4_test_bit ext2_test_bit#define ext4_find_first_zero_bit ext2_find_first_zero_bit#define ext4_find_next_zero_bit ext2_find_next_zero_bit +#define ext4_find_next_bit ext2_find_next_bit/* * Maximal mount counts between two filesystem checks
lib/find_next_bit.c +43 -0
47 lines not on this page · raw message
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 15/49 ext4: store maxbytes for bitmapped files and return EFBIG as appropriate
In reply to Theodore Ts'oFrom: Eric Sandeen <[email protected]>
Calculate & store the max offset for bitmapped files, and catch too-large seeks, truncates, and writes in ext4, shortening or rejecting as appropriate.
--- fs/ext4/file.c | 19 ++++++++++++++++++- fs/ext4/inode.c | 16 +++++++++++++++- fs/ext4/super.c | 1 + include/linux/ext4_fs_sb.h | 1 + 4 files changed, 35 insertions(+), 2 deletions(-)
fs/ext4/file.c +18 -1
@@ -56,8 +56,25 @@ ext4_file_write(struct kiocb *iocb, const struct iovec *iov,ssize_t ret;int err; - ret =generic_file_aio_write (iocb, iov, nr_segs, pos); +/* +* If we have encountered a bitmap-format file, the size limit +* is smaller than s_maxbytes, which is for extent-mapped files. +*/ + +if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) { +struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb); +size_t length =iov_length (iov, nr_segs); +if (pos > sbi->s_bitmap_maxbytes) +return -EFBIG ; + +if (pos + length > sbi->s_bitmap_maxbytes) { + nr_segs =iov_shorten ((struct iovec *)iov, nr_segs, + sbi->s_bitmap_maxbytes - pos); + } + } + + ret =generic_file_aio_write (iocb, iov, nr_segs, pos);/* * Skip flushing if there was an error, or if nothing was written. */
fs/ext4/inode.c +15 -1
@@ -314,7 +314,10 @@ static int ext4_block_to_path(struct inode *inode, offsets[n++] = i_block & (ptrs -1 ); final = ptrs; }else { -ext4_warning (inode->i_sb,"ext4_block_to_path" ,"block > big" ); +ext4_warning (inode->i_sb,"ext4_block_to_path" , +"block %u > max" , + i_block + direct_blocks + + indirect_blocks + double_blocks); }if (boundary) *boundary = final -1 - (i_block & (ptrs -1 ));
@@ -3092,6 +3095,17 @@ int ext4_setattr(struct dentry *dentry, struct iattr *attr)ext4_journal_stop (handle); } +if (attr->ia_valid &ATTR_SIZE ) { +if (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL )) { +struct ext4_sb_info *sbi =EXT4_SB (inode->i_sb); + +if (attr->ia_size > sbi->s_bitmap_maxbytes) { + error = -EFBIG ; + goto err_out; + } + } + } +if (S_ISREG (inode->i_mode) && attr->ia_valid &ATTR_SIZE && attr->ia_size < inode->i_size) {handle_t *handle;
fs/ext4/super.c +1 -0
@@ -1922,6 +1922,7 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) } } + sbi->s_bitmap_maxbytes =ext4_max_bitmap_size (sb->s_blocksize_bits); sb->s_maxbytes =ext4_max_size (sb->s_blocksize_bits);if (le32_to_cpu (es->s_rev_level) ==EXT4_GOOD_OLD_REV ) {
include/linux/ext4_fs_sb.h +1 -0
@@ -38,6 +38,7 @@ struct ext4_sb_info {ext4_group_t s_groups_count;/* Number of groups in the fs */ unsigned long s_overhead_last;/* Last calculated overhead */ unsigned long s_blocks_last;/* Last seen block count */ +loff_t s_bitmap_maxbytes;/* max bytes for bitmap files */ struct buffer_head * s_sbh;/* Buffer containing the super block */ struct ext4_super_block * s_es;/* Pointer to the super block in the buffer */ struct buffer_head ** s_group_desc;
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 40/49 ext4: Add new functions for searching extent tree
In reply to Theodore Ts'oFrom: Alex Tomas <[email protected]>
Add the functions ext4_ext_search_left() and ext4_ext_search_right(), which are used by mballoc during ext4_ext_get_blocks to decided whether to merge extent information.
--- fs/ext4/extents.c | 142 +++++++++++++++++++++++++++++++++++++++ include/linux/ext4_fs_extents.h | 4 + 2 files changed, 146 insertions(+), 0 deletions(-)
fs/ext4/extents.c +142 -0
@@ -1017,6 +1017,148 @@ out: }/* +* search the closest allocated block to the left for *logical +* and returns it at @logical + it's physical address at @phys +* if *logical is the smallest allocated block, the function +* returns 0 at @phys +* return value contains 0 (success) or error code +*/ +int +ext4_ext_search_left (struct inode *inode,struct ext4_ext_path *path, +ext4_lblk_t *logical,ext4_fsblk_t *phys) +{ +struct ext4_extent_idx *ix; +struct ext4_extent *ex; +int depth; + +BUG_ON (path ==NULL ); + depth = path->p_depth; + *phys =0 ; + +if (depth ==0 && path->p_ext ==NULL ) +return 0 ; + +/* usually extent in the path covers blocks smaller +* then *logical, but it can be that extent is the +* first one in the file */ + + ex = path[depth].p_ext; +if (*logical <le32_to_cpu (ex->ee_block)) { +BUG_ON (EXT_FIRST_EXTENT (path[depth].p_hdr) != ex); +while (--depth >=0 ) { + ix = path[depth].p_idx; +BUG_ON (ix !=EXT_FIRST_INDEX (path[depth].p_hdr)); + } +return 0 ; + } + +BUG_ON (*logical <le32_to_cpu (ex->ee_block) +le16_to_cpu (ex->ee_len)); + + *logical =le32_to_cpu (ex->ee_block) +le16_to_cpu (ex->ee_len) -1 ; + *phys =ext_pblock (ex) +le16_to_cpu (ex->ee_len) -1 ; +return 0 ; +} + +/* +* search the closest allocated block to the right for *logical +* and returns it at @logical + it's physical address at @phys +* if *logical is the smallest allocated block, the function +* returns 0 at @phys +* return value contains 0 (success) or error code +*/ +int +ext4_ext_search_right (struct inode *inode,struct ext4_ext_path *path, +ext4_lblk_t *logical,ext4_fsblk_t *phys) +{ +struct buffer_head *bh =NULL ; +struct ext4_extent_header *eh; +struct ext4_extent_idx *ix; +struct ext4_extent *ex; +ext4_fsblk_t block; +int depth; + +BUG_ON (path ==NULL ); + depth = path->p_depth; + *phys =0 ; + +if (depth ==0 && path->p_ext ==NULL ) +return 0 ; + +/* usually extent in the path covers blocks smaller +* then *logical, but it can be that extent is the +* first one in the file */ + + ex = path[depth].p_ext; +if (*logical <le32_to_cpu (ex->ee_block)) { +BUG_ON (EXT_FIRST_EXTENT (path[depth].p_hdr) != ex); +while (--depth >=0 ) { + ix = path[depth].p_idx; +BUG_ON (ix !=EXT_FIRST_INDEX (path[depth].p_hdr)); + } + *logical =le32_to_cpu (ex->ee_block); + *phys =ext_pblock (ex); +return 0 ; + } + +BUG_ON (*logical <le32_to_cpu (ex->ee_block) +le16_to_cpu (ex->ee_len)); + +if (ex !=EXT_LAST_EXTENT (path[depth].p_hdr)) { +/* next allocated block in this leaf */ + ex++; + *logical =le32_to_cpu (ex->ee_block); + *phys =ext_pblock (ex); +return 0 ; + } + +/* go up and search for index to the right */ +while (--depth >=0 ) { + ix = path[depth].p_idx; +if (ix !=EXT_LAST_INDEX (path[depth].p_hdr)) +break ; + } + +if (depth <0 ) { +/* we've gone up to the root and +* found no index to the right */ +return 0 ; + } + +/* we've found index to the right, let's +* follow it and find the closest allocated +* block to the right */ + ix++; + block =idx_pblock (ix); +while (++depth < path->p_depth) { + bh =sb_bread (inode->i_sb, block); +if (bh ==NULL ) +return -EIO ; + eh =ext_block_hdr (bh); +if (ext4_ext_check_header (inode, eh, depth)) { +brelse (bh); +return -EIO ; + } + ix =EXT_FIRST_INDEX (eh); + block =idx_pblock (ix); +brelse (bh); + } + + bh =sb_bread (inode->i_sb, block); +if (bh ==NULL ) +return -EIO ; + eh =ext_block_hdr (bh); +if (ext4_ext_check_header (inode, eh, path->p_depth - depth)) { +brelse (bh); +return -EIO ; + } + ex =EXT_FIRST_EXTENT (eh); + *logical =le32_to_cpu (ex->ee_block); + *phys =ext_pblock (ex); +brelse (bh); +return 0 ; + +} + +/* * ext4_ext_next_allocated_block: * returns allocated block in subsequent extent or EXT_MAX_BLOCK. * NOTE: it considers block number from index entry as
include/linux/ext4_fs_extents.h +4 -0
@@ -221,5 +221,9 @@ extern unsigned int ext4_ext_check_overlap(struct inode *, struct ext4_extent *,extern int ext4_ext_insert_extent (handle_t *,struct inode *,struct ext4_ext_path *,struct ext4_extent *);extern struct ext4_ext_path *ext4_ext_find_extent (struct inode *,ext4_lblk_t ,struct ext4_ext_path *); +extern int ext4_ext_search_left (struct inode *,struct ext4_ext_path *, +ext4_lblk_t *,ext4_fsblk_t *); +extern int ext4_ext_search_right (struct inode *,struct ext4_ext_path *, +ext4_lblk_t *,ext4_fsblk_t *);#endif /* _LINUX_EXT4_EXTENTS */
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 1/49 ext4: Support large blocksize up to PAGESIZE
In reply to Theodore Ts'oFrom: Takashi Sato <[email protected]>
This patch set supports large block size(>4k, <=64k) in ext4, just enlarging the block size limit. But it is NOT possible to have 64kB blocksize on ext4 without some changes to the directory handling code. The reason is that an empty 64kB directory block would have a rec_len == (__u16)2^16 == 0, and this would cause an error to be hit in the filesystem. The proposed solution is treat 64k rec_len with a an impossible value like rec_len = 0xffff to handle this.
The Patch-set consists of the following 2 patches.
[1/2] ext4: enlarge blocksize
- Allow blocksize up to pagesize
[2/2] ext4: fix rec_len overflow
- prevent rec_len from overflow with 64KB blocksize
Now on 64k page ppc64 box runs with this patch set we could create a 64k block size ext4dev, and able to handle empty directory block.
--- fs/ext4/super.c | 5 +++++ include/linux/ext4_fs.h | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-)
fs/ext4/super.c +5 -0
@@ -1624,6 +1624,11 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) goto out_fail; } +if (!sb_set_blocksize (sb, blocksize)) { +printk (KERN_ERR "EXT4-fs: bad blocksize %d.\n" , blocksize); + goto out_fail; + } +/* * The ext4 superblock will not be buffer aligned for other than 1kB * block sizes. We need to calculate the offset from buffer start.
include/linux/ext4_fs.h +2 -2
@@ -73,8 +73,8 @@* Macro-instructions used to manage several block sizes */ #define EXT4_MIN_BLOCK_SIZE 1024 -#define EXT4_MAX_BLOCK_SIZE 4096 -#define EXT4_MIN_BLOCK_LOG_SIZE 10 +#define EXT4_MAX_BLOCK_SIZE 65536 +#define EXT4_MIN_BLOCK_LOG_SIZE 10#ifdef __KERNEL__# define EXT4_BLOCK_SIZE (s) ((s)->s_blocksize)#else
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 44/49 ext4: fix uniniatilized extent splitting error
In reply to Theodore Ts'oFrom: Dmitry Monakhov <[email protected]>
Fix bug reported by Dmitry Monakhov caused by lost error code
Testcase:
blksize = 0x1000;
fd = open(argv[1], O_RDWR|O_CREAT, 0700);
unsigned long long sz = 0x10000000UL;
/* allocating big blocks chunk */
syscall(__NR_fallocate, fd, 0, 0UL, sz)
/* grab all other available filesystem space */
tfd = open("tmp", O_RDWR|O_CREAT|O_DIRECT, 0700);
while( write(tfd, buf, 4096) > 0); /* loop untill ENOSPC */
fsync(fd); /* just in case */
while (pos < sz) {
/* each seek+ write operation result in splits uninitialized extent
in three extents. Splitting may result in new extent allocation
which probably will fail because of ENOSPC*/
lseek(fd, blksize*2 -1, SEEK_CUR);
if ((ret = write(fd, 'a', 1)) != 1)
exit(1);
pos += blksize * 2;
}--- fs/ext4/extents.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
fs/ext4/extents.c +3 -2
@@ -2373,9 +2373,10 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, ret =ext4_ext_convert_to_initialized (handle, inode, path, iblock, max_blocks); -if (ret <=0 ) +if (ret <=0 ) { + err = ret; goto out2; -else + }else allocated = ret; goto outnew; }
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 48/49 jbd2: Use round-jiffies() function for the "5 second" ext4/jbd2 wakeup
In reply to Theodore Ts'oFrom: Mingming Cao <[email protected]>
While "every 5 seconds" doesn't sound as a problem, there can be many of these (and these timers do add up over all the kernel). The "5 second" wakeup isn't really timing sensitive; in addition even with rounding it'll still happen every 5 seconds (with the exception of the very first time, which is likely to be rounded up to somewhere closer to 6 seconds)
(Ported from similar JBD patch made by Arjan van de Ven to fs/jbd/transaction.c)
--- fs/jbd2/transaction.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
fs/jbd2/transaction.c +1 -1
@@ -54,7 +54,7 @@ jbd2_get_transaction(journal_t *journal, transaction_t *transaction)spin_lock_init (&transaction->t_handle_lock);/* Set up the commit timer for the new transaction. */ - journal->j_commit_timer.expires = transaction->t_expires; + journal->j_commit_timer.expires =round_jiffies (transaction->t_expires);add_timer (&journal->j_commit_timer);J_ASSERT (journal->j_running_transaction ==NULL );
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 20/49 ext4/super.c: fix #ifdef's (CONFIG_EXT4_* -> CONFIG_EXT4DEV_*)
In reply to Theodore Ts'oFrom: Adrian Bunk <[email protected]>
Based on a report by Robert P. J. Day.
--- fs/ext4/super.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
fs/ext4/super.c +2 -2
@@ -706,7 +706,7 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)seq_puts (seq,",debug" );if (test_opt (sb,OLDALLOC ))seq_puts (seq,",oldalloc" ); -#ifdef CONFIG_EXT4_FS_XATTR +#ifdef CONFIG_EXT4DEV_FS_XATTR if (test_opt (sb,XATTR_USER ))seq_puts (seq,",user_xattr" ); if (!test_opt(sb, XATTR_USER) &&
@@ -714,7 +714,7 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs) seq_puts(seq, ",nouser_xattr"); }#endif -#ifdef CONFIG_EXT4_FS_POSIX_ACL +#ifdef CONFIG_EXT4DEV_FS_POSIX_ACL if (test_opt (sb,POSIX_ACL ))seq_puts (seq,",acl" );if (!test_opt (sb,POSIX_ACL ) && (def_mount_opts &EXT4_DEFM_ACL ))
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 41/49 ext4: Add multi block allocator for ext4
In reply to Theodore Ts'oFrom: Alex Tomas <[email protected]>
--- fs/ext4/Makefile | 2 +- fs/ext4/balloc.c | 67 +- fs/ext4/extents.c | 45 +- fs/ext4/inode.c | 15 +- fs/ext4/mballoc.c | 4551 ++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/migrate.c | 10 +- fs/ext4/super.c | 61 +- fs/ext4/xattr.c | 4 +- include/linux/ext4_fs.h | 76 +- include/linux/ext4_fs_i.h | 4 + include/linux/ext4_fs_sb.h | 52 + 11 files changed, 4850 insertions(+), 37 deletions(-) create mode 100644 fs/ext4/mballoc.c
fs/ext4/Makefile +1 -1
@@ -6,7 +6,7 @@ obj-$(CONFIG_EXT4DEV_FS) += ext4dev.o ext4dev-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \ ioctl.o namei.o super.o symlink.o hash.o resize.o extents.o \ - ext4_jbd2.o migrate.o + ext4_jbd2.o migrate.o mballoc.o ext4dev-$(CONFIG_EXT4DEV_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o ext4dev-$(CONFIG_EXT4DEV_FS_POSIX_ACL) += acl.o
fs/ext4/balloc.c +56 -11
108 lines not on this page · raw message
fs/ext4/extents.c +36 -9
112 lines not on this page · raw message
fs/ext4/inode.c +8 -7
@@ -551,7 +551,7 @@ static int ext4_alloc_blocks(handle_t *handle, struct inode *inode,return ret; failed_out:for (i =0 ; i <index; i++) -ext4_free_blocks (handle, inode, new_blocks[i],1 ); +ext4_free_blocks (handle, inode, new_blocks[i],1 ,0 );return ret; }
@@ -650,9 +650,9 @@ failed:ext4_journal_forget (handle, branch[i].bh); }for (i =0 ; i <indirect_blks; i++) -ext4_free_blocks (handle, inode, new_blocks[i],1 ); +ext4_free_blocks (handle, inode, new_blocks[i],1 ,0 ); -ext4_free_blocks (handle, inode, new_blocks[i], num); +ext4_free_blocks (handle, inode, new_blocks[i], num,0 );return err; }
@@ -749,9 +749,10 @@ err_out:for (i =1 ; i <= num; i++) {BUFFER_TRACE (where[i].bh,"call jbd2_journal_forget" );ext4_journal_forget (handle, where[i].bh); -ext4_free_blocks (handle,inode,le32_to_cpu (where[i-1 ].key),1 ); +ext4_free_blocks (handle, inode, +le32_to_cpu (where[i-1 ].key),1 ,0 ); } -ext4_free_blocks (handle, inode,le32_to_cpu (where[num].key), blks); +ext4_free_blocks (handle, inode,le32_to_cpu (where[num].key), blks,0 );return err; }
@@ -2051,7 +2052,7 @@ static void ext4_clear_blocks(handle_t *handle, struct inode *inode, } } -ext4_free_blocks (handle, inode, block_to_free, count); +ext4_free_blocks (handle, inode, block_to_free, count,0 ); }/**
@@ -2224,7 +2225,7 @@ static void ext4_free_branches(handle_t *handle, struct inode *inode,ext4_journal_test_restart (handle, inode); } -ext4_free_blocks (handle, inode, nr,1 ); +ext4_free_blocks (handle, inode, nr,1 ,1 );if (parent_bh) {/*
fs/ext4/mballoc.c new file +4551 -0
2,725 lines not on this page · raw message
fs/ext4/super.c +60 -1
61 lines not on this page · raw message
include/linux/ext4_fs.h +75 -1
76 lines not on this page · raw message
include/linux/ext4_fs_sb.h +52 -0
52 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Part of the diff is not shown here. View the raw message.
Theodore Ts'o
maintainerPATCH 47/49 jbd2: Mark jbd2 slabs as SLAB_TEMPORARY
In reply to Theodore Ts'oFrom: Mingming Cao <[email protected]>
This patch marks slab allocations by jbd2 as short-lived in support of Mel Gorman's "Group short-lived and reclaimable kernel allocations" patch. (Ported from similar changes made to fs/jbd/journal.c and fs/jbd/revoke.c in Mel's patch.)
--- fs/jbd2/journal.c | 4 ++-- fs/jbd2/revoke.c | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-)
fs/jbd2/journal.c +2 -2
@@ -1975,7 +1975,7 @@ static int journal_init_jbd2_journal_head_cache(void) jbd2_journal_head_cache =kmem_cache_create ("jbd2_journal_head" ,sizeof (struct journal_head ),0 ,/* offset */ -0 ,/* flags */ +SLAB_TEMPORARY ,/* flags */ NULL );/* ctor */ retval =0 ;if (jbd2_journal_head_cache ==0 ) {
@@ -2271,7 +2271,7 @@ static int __init journal_init_handle_cache(void) jbd2_handle_cache =kmem_cache_create ("jbd2_journal_handle" ,sizeof (handle_t),0 ,/* offset */ -0 ,/* flags */ +SLAB_TEMPORARY ,/* flags */ NULL );/* ctor */ if (jbd2_handle_cache ==NULL ) {printk (KERN_EMERG "JBD: failed to create handle cache\n" );
fs/jbd2/revoke.c +4 -2
@@ -171,13 +171,15 @@ int __init jbd2_journal_init_revoke_caches(void) { jbd2_revoke_record_cache =kmem_cache_create ("jbd2_revoke_record" ,sizeof (struct jbd2_revoke_record_s ), -0 ,SLAB_HWCACHE_ALIGN ,NULL ); +0 , +SLAB_HWCACHE_ALIGN |SLAB_TEMPORARY , +NULL );if (jbd2_revoke_record_cache ==0 )return -ENOMEM ; jbd2_revoke_table_cache =kmem_cache_create ("jbd2_revoke_table" ,sizeof (struct jbd2_revoke_table_s ), -0 ,0 ,NULL ); +0 ,SLAB_TEMPORARY ,NULL );if (jbd2_revoke_table_cache ==0 ) {kmem_cache_destroy (jbd2_revoke_record_cache); jbd2_revoke_record_cache =NULL ;
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 25/49 jbd2: Remove printk from J_ASSERT to preserve registers during BUG
In reply to Theodore Ts'oFrom: Chris Snook <[email protected]>
--- include/linux/jbd2.h | 16 +--------------- 1 files changed, 1 insertions(+), 15 deletions(-)
include/linux/jbd2.h +1 -15
@@ -256,17 +256,7 @@ typedef struct journal_superblock_s#include <linux/fs.h> #include <linux/sched.h> -#define JBD2_ASSERTIONS -#ifdef JBD2_ASSERTIONS -#define J_ASSERT (assert) \ -do { \ - if (!(assert)) { \ - printk (KERN_EMERG \ - "Assertion failure in %s() at %s:%d: \"%s\"\n", \ - __FUNCTION__, __FILE__, __LINE__, # assert); \ - BUG(); \ - } \ -} while (0) +#define J_ASSERT (assert) BUG_ON(!(assert))#if defined(CONFIG_BUFFER_DEBUG )void buffer_assertion_failure (struct buffer_head *bh);
@@ -282,10 +272,6 @@ void buffer_assertion_failure(struct buffer_head *bh);#define J_ASSERT_JH (jh, expr) J_ASSERT(expr)#endif -#else -#define J_ASSERT (assert) do { } while (0) -#endif /* JBD2_ASSERTIONS */ -#if defined(JBD2_PARANOID_IOFAIL ) #define J_EXPECT(expr, why...) J_ASSERT(expr) #define J_EXPECT_BH(bh, expr, why...) J_ASSERT_BH(bh, expr)
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 26/49 jbd2: Fix assertion failure in fs/jbd2/checkpoint.c
From: Jan Kara <[email protected]>
Before we start committing a transaction, we call __journal_clean_checkpoint_list() to cleanup transaction's written-back buffers.
If this call happens to remove all of them (and there were already some buffers), __journal_remove_checkpoint() will decide to free the transaction because it isn't (yet) a committing transaction and soon we fail some assertion - the transaction really isn't ready to be freed :).
We change the check in __journal_remove_checkpoint() to free only a transaction in T_FINISHED state. The locking there is subtle though (as everywhere in JBD ;(). We use j_list_lock to protect the check and a subsequent call to __journal_drop_transaction() and do the same in the end of journal_commit_transaction() which is the only place where a transaction can get to T_FINISHED state.
Probably I'm too paranoid here and such locking is not really necessary - checkpoint lists are processed only from log_do_checkpoint() where a transaction must be already committed to be processed or from __journal_clean_checkpoint_list() where kjournald itself calls it and thus transaction cannot change state either. Better be safe if something changes in future...
--- fs/jbd2/checkpoint.c | 12 ++++++------ fs/jbd2/commit.c | 8 ++++---- include/linux/jbd2.h | 2 ++ 3 files changed, 12 insertions(+), 10 deletions(-)
fs/jbd2/checkpoint.c +6 -6
@@ -602,15 +602,15 @@ int __jbd2_journal_remove_checkpoint(struct journal_head *jh)/* * There is one special case to worry about: if we have just pulled the -* buffer off a committing transaction's forget list, then even if the -* checkpoint list is empty, the transaction obviously cannot be -* dropped! +* buffer off a running or committing transaction's checkpoing list, +* then even if the checkpoint list is empty, the transaction obviously +* cannot be dropped! * -* The locking here around j_committing_transaction is a bit sleazy. +* The locking here around t_state is a bit sleazy. * See the comment at the end of jbd2_journal_commit_transaction(). */ -if (transaction == journal->j_committing_transaction) { -JBUFFER_TRACE (jh,"belongs to committing transaction" ); +if (transaction->t_state !=T_FINISHED ) { +JBUFFER_TRACE (jh,"belongs to running/committing transaction" ); goto out; }
fs/jbd2/commit.c +4 -4
@@ -867,10 +867,10 @@ restart_loop: }spin_unlock (&journal->j_list_lock);/* -* This is a bit sleazy. We borrow j_list_lock to protect -* journal->j_committing_transaction in __jbd2_journal_remove_checkpoint. -* Really, __jbd2_journal_remove_checkpoint should be using j_state_lock but -* it's a bit hassle to hold that across __jbd2_journal_remove_checkpoint +* This is a bit sleazy. We use j_list_lock to protect transition +* of a transaction into T_FINISHED state and calling +* __jbd2_journal_drop_transaction(). Otherwise we could race with +* other checkpointing code processing the transaction... */ spin_lock (&journal->j_state_lock);spin_lock (&journal->j_list_lock);
include/linux/jbd2.h +2 -0
@@ -442,6 +442,8 @@ struct transaction_s/* * Transaction's current state * [no locking - only kjournald2 alters this] +* [j_list_lock] guards transition of a transaction into T_FINISHED +* state and subsequent call of __jbd2_journal_drop_transaction() * FIXME: needs barriers * KLUDGE: [use j_state_lock] */
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 4/49 ext4 extents: remove unneeded casts
In reply to Theodore Ts'oFrom: Eric Sandeen <[email protected]>
There are many casts in extents.c which are not needed, as the variables are already the type of the cast, or are being promoted for no particular reason in printk's.
--- fs/ext4/extents.c | 49 ++++++++++++++++++++++--------------------------- 1 files changed, 22 insertions(+), 27 deletions(-)
fs/ext4/extents.c +22 -27
@@ -374,7 +374,7 @@ ext4_ext_binsearch_idx(struct inode *inode,struct ext4_extent_idx *r, *l, *m; -ext_debug ("binsearch for %lu(idx): " , (unsigned long )block); +ext_debug ("binsearch for %u(idx): " , block); l =EXT_FIRST_INDEX (eh) +1 ; r =EXT_LAST_INDEX (eh);
@@ -440,7 +440,7 @@ ext4_ext_binsearch(struct inode *inode,return ; } -ext_debug ("binsearch for %lu: " , (unsigned long )block); +ext_debug ("binsearch for %u: " , block); l =EXT_FIRST_EXTENT (eh) +1 ; r =EXT_LAST_EXTENT (eh);
@@ -766,7 +766,7 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode,while (k--) { oldblock = newblock; newblock = ablocks[--a]; - bh =sb_getblk (inode->i_sb, (ext4_fsblk_t )newblock); + bh =sb_getblk (inode->i_sb, newblock);if (!bh) { err = -EIO ; goto cleanup;
@@ -786,9 +786,8 @@ static int ext4_ext_split(handle_t *handle, struct inode *inode, fidx->ei_block = border;ext4_idx_store_pblock (fidx, oldblock); -ext_debug ("int.index at %d (block %llu): %lu -> %llu\n" , i, - newblock, (unsigned long )le32_to_cpu (border), - oldblock); +ext_debug ("int.index at %d (block %llu): %u -> %llu\n" , + i, newblock,le32_to_cpu (border), oldblock);/* copy indexes */ m =0 ; path[i].p_idx++;
@@ -1476,10 +1475,10 @@ ext4_ext_put_gap_in_cache(struct inode *inode, struct ext4_ext_path *path, }else if (block <le32_to_cpu (ex->ee_block)) { lblock = block; len =le32_to_cpu (ex->ee_block) - block; -ext_debug ("cache gap(before): %lu [%lu:%lu]" , - (unsigned long ) block, - (unsigned long )le32_to_cpu (ex->ee_block), - (unsigned long )ext4_ext_get_actual_len (ex)); +ext_debug ("cache gap(before): %u [%u:%u]" , + block, +le32_to_cpu (ex->ee_block), +ext4_ext_get_actual_len (ex)); }else if (block >=le32_to_cpu (ex->ee_block) +ext4_ext_get_actual_len (ex)) {ext4_lblk_t next;
@@ -1487,10 +1486,10 @@ ext4_ext_put_gap_in_cache(struct inode *inode, struct ext4_ext_path *path, +ext4_ext_get_actual_len (ex); next =ext4_ext_next_allocated_block (path); -ext_debug ("cache gap(after): [%lu:%lu] %lu" , - (unsigned long )le32_to_cpu (ex->ee_block), - (unsigned long )ext4_ext_get_actual_len (ex), - (unsigned long ) block); +ext_debug ("cache gap(after): [%u:%u] %u" , +le32_to_cpu (ex->ee_block), +ext4_ext_get_actual_len (ex), + block);BUG_ON (next == lblock); len = next - lblock; }else {
@@ -1498,7 +1497,7 @@ ext4_ext_put_gap_in_cache(struct inode *inode, struct ext4_ext_path *path,BUG (); } -ext_debug (" -> %lu:%lu\n" , (unsigned long ) lblock, len); +ext_debug (" -> %u:%lu\n" , lblock, len);ext4_ext_put_in_cache (inode, lblock, len,0 ,EXT4_EXT_CACHE_GAP ); }
@@ -1520,11 +1519,9 @@ ext4_ext_in_cache(struct inode *inode, ext4_lblk_t block, ex->ee_block =cpu_to_le32 (cex->ec_block);ext4_ext_store_pblock (ex, cex->ec_start); ex->ee_len =cpu_to_le16 (cex->ec_len); -ext_debug ("%lu cached by %lu:%lu:%llu\n" , - (unsigned long ) block, - (unsigned long ) cex->ec_block, - (unsigned long ) cex->ec_len, - cex->ec_start); +ext_debug ("%u cached by %u:%u:%llu\n" , + block, + cex->ec_block, cex->ec_len, cex->ec_start);return cex->ec_type; }
@@ -2145,9 +2142,8 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,unsigned long allocated =0 ;__clear_bit (BH_New, &bh_result->b_state); -ext_debug ("blocks %lu/%lu requested for inode %u\n" , - (unsigned long ) iblock, max_blocks, - (unsigned ) inode->i_ino); +ext_debug ("blocks %u/%lu requested for inode %u\n" , + iblock, max_blocks, inode->i_ino);mutex_lock (&EXT4_I (inode)->truncate_mutex);/* check in cache */
@@ -2210,7 +2206,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, newblock = iblock - ee_block + ee_start;/* number of remaining blocks in the extent */ allocated = ee_len - (iblock - ee_block); -ext_debug ("%d fit into %lu:%d -> %llu\n" , (int ) iblock, +ext_debug ("%u fit into %lu:%d -> %llu\n" , iblock, ee_block, ee_len, newblock);/* Do not put uninitialized extent in the cache */
@@ -2470,9 +2466,8 @@ retry:if (!ret) {ext4_error (inode->i_sb,"ext4_fallocate" ,"ext4_ext_get_blocks returned 0! inode#%lu" -", block=%lu, max_blocks=%lu" , - inode->i_ino, (unsigned long )block, - (unsigned long )max_blocks); +", block=%u, max_blocks=%lu" , + inode->i_ino, block, max_blocks); ret = -EIO ;ext4_mark_inode_dirty (handle, inode); ret2 =ext4_journal_stop (handle);
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 9/49 ext4: Rename i_file_acl to i_file_acl_lo
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
Rename i_file_acl to i_file_acl_lo. This helps
in finding bugs where we use i_file_acl instead
of the combined i_file_acl_lo and i_file_acl_high
--- fs/ext4/inode.c | 4 ++-- include/linux/ext4_fs.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
fs/ext4/inode.c +2 -2
@@ -2718,7 +2718,7 @@ void ext4_read_inode(struct inode * inode) } inode->i_blocks =le32_to_cpu (raw_inode->i_blocks); ei->i_flags =le32_to_cpu (raw_inode->i_flags); - ei->i_file_acl =le32_to_cpu (raw_inode->i_file_acl); + ei->i_file_acl =le32_to_cpu (raw_inode->i_file_acl_lo);if (EXT4_SB (inode->i_sb)->s_es->s_creator_os !=cpu_to_le32 (EXT4_OS_HURD )) ei->i_file_acl |=
@@ -2866,7 +2866,7 @@ static int ext4_do_update_inode(handle_t *handle, cpu_to_le32(EXT4_OS_HURD)) raw_inode->i_file_acl_high =cpu_to_le16 (ei->i_file_acl >>32 ); - raw_inode->i_file_acl =cpu_to_le32 (ei->i_file_acl); + raw_inode->i_file_acl_lo =cpu_to_le32 (ei->i_file_acl);if (!S_ISREG (inode->i_mode)) { raw_inode->i_dir_acl =cpu_to_le32 (ei->i_dir_acl); }else {
include/linux/ext4_fs.h +1 -1
@@ -297,7 +297,7 @@ struct ext4_inode { } osd1;/* OS dependent 1 */ __le32 i_block[EXT4_N_BLOCKS ];/* Pointers to blocks */ __le32 i_generation;/* File version (for NFS) */ -__le32 i_file_acl;/* File ACL */ +__le32 i_file_acl_lo;/* File ACL */ __le32 i_dir_acl;/* Directory ACL */ __le32 i_obso_faddr;/* Obsoleted fragment address */ union {
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 28/49 ext4: remove unused code from ext4_find_entry()
In reply to Theodore Ts'oFrom: Mariusz Kozlowski <[email protected]>
The unused code found in ext3_find_entry() is also present (and still unused) in the ext4_find_entry() code. This patch removes it.
--- fs/ext4/namei.c | 4 ---- 1 files changed, 0 insertions(+), 4 deletions(-)
fs/ext4/namei.c +0 -4
@@ -861,14 +861,10 @@ static struct buffer_head * ext4_find_entry (struct dentry *dentry,int i, err;struct inode *dir = dentry->d_parent->d_inode;int namelen; -const u8 *name; -unsigned blocksize; *res_dir =NULL ; sb = dir->i_sb; - blocksize = sb->s_blocksize; namelen = dentry->d_name.len; - name = dentry->d_name.name;if (namelen >EXT4_NAME_LEN )return NULL ;if (is_dx (dir)) {
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 45/49 ext4: Use the ext4_ext_actual_len() helper function
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
ext4 uses the high bit of the extent length to encode whether the extent is intialized or not. The helper function ext4_ext_get_actual_len should be used to get the actual length of the extent.
This addresses the kernel bug documented here:
http://bugzilla.kernel.org/show_bug.cgi?id=9732
kernel BUG at fs/ext4/extents.c:1056!
....
Call Trace: [<ffffffff88366073>] :ext4dev:ext4_ext_get_blocks+0x5ba/0x8c1 [<ffffffff81053c91>] lock_release_holdtime+0x27/0x49 [<ffffffff812748f6>] _spin_unlock+0x17/0x20 [<ffffffff883400a6>] :jbd2:start_this_handle+0x4e0/0x4fe [<ffffffff88366564>] :ext4dev:ext4_fallocate+0x175/0x39a [<ffffffff81053c91>] lock_release_holdtime+0x27/0x49 [<ffffffff81056480>] __lock_acquire+0x4e7/0xc4d [<ffffffff81053c91>] lock_release_holdtime+0x27/0x49 [<ffffffff810a8de7>] sys_fallocate+0xe4/0x10d [<ffffffff8100c043>] tracesys+0xd5/0xda
--- fs/ext4/extents.c | 24 +++++++++++++----------- 1 files changed, 13 insertions(+), 11 deletions(-)
fs/ext4/extents.c +13 -11
@@ -1029,7 +1029,7 @@ ext4_ext_search_left(struct inode *inode, struct ext4_ext_path *path, {struct ext4_extent_idx *ix;struct ext4_extent *ex; -int depth; +int depth, ee_len;BUG_ON (path ==NULL ); depth = path->p_depth;
@@ -1043,6 +1043,7 @@ ext4_ext_search_left(struct inode *inode, struct ext4_ext_path *path,* first one in the file */ ex = path[depth].p_ext; + ee_len =ext4_ext_get_actual_len (ex);if (*logical <le32_to_cpu (ex->ee_block)) {BUG_ON (EXT_FIRST_EXTENT (path[depth].p_hdr) != ex);while (--depth >=0 ) {
@@ -1052,10 +1053,10 @@ ext4_ext_search_left(struct inode *inode, struct ext4_ext_path *path,return 0 ; } -BUG_ON (*logical <le32_to_cpu (ex->ee_block) +le16_to_cpu (ex->ee_len)); +BUG_ON (*logical < (le32_to_cpu (ex->ee_block) + ee_len)); - *logical =le32_to_cpu (ex->ee_block) +le16_to_cpu (ex->ee_len) -1 ; - *phys =ext_pblock (ex) +le16_to_cpu (ex->ee_len) -1 ; + *logical =le32_to_cpu (ex->ee_block) + ee_len -1 ; + *phys =ext_pblock (ex) + ee_len -1 ;return 0 ; }
@@ -1075,7 +1076,7 @@ ext4_ext_search_right(struct inode *inode, struct ext4_ext_path *path,struct ext4_extent_idx *ix;struct ext4_extent *ex;ext4_fsblk_t block; -int depth; +int depth, ee_len;BUG_ON (path ==NULL ); depth = path->p_depth;
@@ -1089,6 +1090,7 @@ ext4_ext_search_right(struct inode *inode, struct ext4_ext_path *path,* first one in the file */ ex = path[depth].p_ext; + ee_len =ext4_ext_get_actual_len (ex);if (*logical <le32_to_cpu (ex->ee_block)) {BUG_ON (EXT_FIRST_EXTENT (path[depth].p_hdr) != ex);while (--depth >=0 ) {
@@ -1100,7 +1102,7 @@ ext4_ext_search_right(struct inode *inode, struct ext4_ext_path *path,return 0 ; } -BUG_ON (*logical <le32_to_cpu (ex->ee_block) +le16_to_cpu (ex->ee_len)); +BUG_ON (*logical < (le32_to_cpu (ex->ee_block) + ee_len));if (ex !=EXT_LAST_EXTENT (path[depth].p_hdr)) {/* next allocated block in this leaf */
@@ -1316,7 +1318,7 @@ ext4_can_extents_be_merged(struct inode *inode, struct ext4_extent *ex1,if (ext1_ee_len + ext2_ee_len > max_len)return 0 ;#ifdef AGGRESSIVE_TEST -if (le16_to_cpu (ex1->ee_len) >=4 ) +if (ext1_ee_len >=4 )return 0 ;#endif
@@ -2313,7 +2315,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, -le32_to_cpu (newex.ee_block) +ext_pblock (&newex);/* number of remaining blocks in the extent */ - allocated =le16_to_cpu (newex.ee_len) - + allocated =ext4_ext_get_actual_len (&newex) - (iblock -le32_to_cpu (newex.ee_block)); goto out; }else {
@@ -2429,7 +2431,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, newex.ee_len =cpu_to_le16 (max_blocks); err =ext4_ext_check_overlap (inode, &newex, path);if (err) - allocated =le16_to_cpu (newex.ee_len); + allocated =ext4_ext_get_actual_len (&newex);else allocated = max_blocks;
@@ -2461,7 +2463,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,* but otherwise we'd need to call it every free() */ ext4_mb_discard_inode_preallocations (inode);ext4_free_blocks (handle, inode,ext_pblock (&newex), -le16_to_cpu (newex.ee_len),0 ); +ext4_ext_get_actual_len (&newex),0 ); goto out2; }
@@ -2470,7 +2472,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,/* previous routine could use block we allocated */ newblock =ext_pblock (&newex); - allocated =le16_to_cpu (newex.ee_len); + allocated =ext4_ext_get_actual_len (&newex); outnew:__set_bit (BH_New, &bh_result->b_state);
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 42/49 ext4: Enable the multiblock allocator by default
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
Enable the multiblock allocator by default.
Fix ext4_show_options() so if it is not enabled, the nomballoc option included in /proc/mounts.
--- fs/ext4/super.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
fs/ext4/super.c +7 -0
@@ -736,6 +736,8 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)seq_puts (seq,",nobh" );if (!test_opt (sb,EXTENTS ))seq_puts (seq,",noextents" ); +if (!test_opt (sb,MBALLOC )) +seq_puts (seq,",nomballoc" );if (test_opt (sb,I_VERSION ))seq_puts (seq,",i_version" );
@@ -1902,6 +1904,11 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)* User -o noextents to turn it off */ set_opt (sbi->s_mount_opt,EXTENTS ); +/* +* turn on mballoc feature by default in ext4 filesystem +* User -o nomballoc to turn it off +*/ +set_opt (sbi->s_mount_opt,MBALLOC );if (!parse_options ((char *) data, sb, &journal_inum, &journal_devnum,NULL ,0 ))
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 27/49 ext4: Check for the correct error return from
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
ext4_ext_get_blocks returns negative values on error. We should check for <= 0
--- fs/ext4/extents.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
fs/ext4/extents.c +5 -5
@@ -2462,12 +2462,12 @@ retry: ret =ext4_ext_get_blocks (handle, inode, block, max_blocks, &map_bh,EXT4_CREATE_UNINITIALIZED_EXT ,0 ); -WARN_ON (!ret); -if (!ret) { +WARN_ON (ret <=0 ); +if (ret <=0 ) {ext4_error (inode->i_sb,"ext4_fallocate" , -"ext4_ext_get_blocks returned 0! inode#%lu" -", block=%u, max_blocks=%lu" , - inode->i_ino, block, max_blocks); +"ext4_ext_get_blocks returned error: " +"inode#%lu, block=%u, max_blocks=%lu" , + inode->i_ino, block, max_blocks); ret = -EIO ;ext4_mark_inode_dirty (handle, inode); ret2 =ext4_journal_stop (handle);
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 19/49 ext4: Return after ext4_error in case of failures
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
This fix some instances where we were continuing after calling ext4_error. ext4_error call panic only if errors=panic mount option is set. So we need to make sure we return correctly after ext4_error call
Reported by: Adrian Bunk <[email protected]>
--- fs/ext4/balloc.c | 8 ++++++-- 1 files changed, 6 insertions(+), 2 deletions(-)
fs/ext4/balloc.c +6 -2
@@ -587,11 +587,13 @@ do_more: in_range(ext4_inode_bitmap(sb, desc), block, count) || in_range(block, ext4_inode_table(sb, desc), sbi->s_itb_per_group) || in_range(block + count - 1, ext4_inode_table(sb, desc), - sbi->s_itb_per_group)) + sbi->s_itb_per_group)) {ext4_error (sb,"ext4_free_blocks" ,"Freeing blocks in system zones - " "Block = %llu, count = %lu" , block, count); + goto error_return; + }/* * We are about to start releasing blocks in the bitmap,
@@ -1690,11 +1692,13 @@ allocated: in_range(ret_block, ext4_inode_table(sb, gdp), EXT4_SB(sb)->s_itb_per_group) || in_range(ret_block + num - 1, ext4_inode_table(sb, gdp), - EXT4_SB(sb)->s_itb_per_group)) + EXT4_SB(sb)->s_itb_per_group)) {ext4_error (sb,"ext4_new_block" ,"Allocating block in system zone - " "blocks from %llu, length %lu" , ret_block, num); + goto out; + } performed_allocation =1 ;
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 16/49 ext2: Fix the max file size for ext2 file system.
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
The max file size for ext2 file system is now calculated with hardcoded 4K block size. The patch fixes it to be calculated with the right block size.
--- fs/ext2/super.c | 32 ++++++++++++++++++++++++++++---- 1 files changed, 28 insertions(+), 4 deletions(-)
fs/ext2/super.c +28 -4
@@ -680,11 +680,31 @@ static int ext2_check_descriptors (struct super_block * sb)static loff_t ext2_max_size (int bits) {loff_t res =EXT2_NDIR_BLOCKS ; -/* This constant is calculated to be the largest file size for a -* dense, 4k-blocksize file such that the total number of +int meta_blocks; +loff_t upper_limit; + +/* This is calculated to be the largest file size for a +* dense, file such that the total number of * sectors in the file, including data and all indirect blocks, -* does not exceed 2^32. */ -const loff_t upper_limit =0x1ff7fffd000LL ; +* does not exceed 2^32 -1 +* __u32 i_blocks representing the total number of +* 512 bytes blocks of the file +*/ + upper_limit = (1LL <<32 ) -1 ; + +/* total blocks in file system block size */ + upper_limit >>= (bits -9 ); + + +/* indirect blocks */ + meta_blocks =1 ; +/* double indirect blocks */ + meta_blocks +=1 + (1LL << (bits-2 )); +/* tripple indirect blocks */ + meta_blocks +=1 + (1LL << (bits-2 )) + (1LL << (2 *(bits-2 ))); + + upper_limit -= meta_blocks; + upper_limit <<= bits; res +=1LL << (bits-2 ); res +=1LL << (2 *(bits-2 ));
@@ -692,6 +712,10 @@ static loff_t ext2_max_size(int bits) res <<= bits;if (res > upper_limit) res = upper_limit; + +if (res >MAX_LFS_FILESIZE ) + res =MAX_LFS_FILESIZE ; +return res; }
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 17/49 ext3: Fix the max file size for ext3 file system.
From: Aneesh Kumar K.V <[email protected]>
The max file size for ext3 file system is now calculated with hardcoded 4K block size. The patch fixes it to be calculated with the right block size.
--- fs/ext3/super.c | 32 ++++++++++++++++++++++++++++---- 1 files changed, 28 insertions(+), 4 deletions(-)
fs/ext3/super.c +28 -4
@@ -1436,11 +1436,31 @@ static void ext3_orphan_cleanup (struct super_block * sb,static loff_t ext3_max_size (int bits) {loff_t res =EXT3_NDIR_BLOCKS ; -/* This constant is calculated to be the largest file size for a -* dense, 4k-blocksize file such that the total number of +int meta_blocks; +loff_t upper_limit; + +/* This is calculated to be the largest file size for a +* dense, file such that the total number of * sectors in the file, including data and all indirect blocks, -* does not exceed 2^32. */ -const loff_t upper_limit =0x1ff7fffd000LL ; +* does not exceed 2^32 -1 +* __u32 i_blocks representing the total number of +* 512 bytes blocks of the file +*/ + upper_limit = (1LL <<32 ) -1 ; + +/* total blocks in file system block size */ + upper_limit >>= (bits -9 ); + + +/* indirect blocks */ + meta_blocks =1 ; +/* double indirect blocks */ + meta_blocks +=1 + (1LL << (bits-2 )); +/* tripple indirect blocks */ + meta_blocks +=1 + (1LL << (bits-2 )) + (1LL << (2 *(bits-2 ))); + + upper_limit -= meta_blocks; + upper_limit <<= bits; res +=1LL << (bits-2 ); res +=1LL << (2 *(bits-2 ));
@@ -1448,6 +1468,10 @@ static loff_t ext3_max_size(int bits) res <<= bits;if (res > upper_limit) res = upper_limit; + +if (res >MAX_LFS_FILESIZE ) + res =MAX_LFS_FILESIZE ; +return res; }
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 23/49 Add buffer head related helper functions
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
Add buffer head related helper function bh_uptodate_or_lock and bh_submit_read which can be used by file system
--- fs/buffer.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/linux/buffer_head.h | 2 ++ 2 files changed, 43 insertions(+), 0 deletions(-)
fs/buffer.c +41 -0
@@ -3213,6 +3213,47 @@ static int buffer_cpu_notify(struct notifier_block *self,return NOTIFY_OK ; } +/** +* bh_uptodate_or_lock: Test whether the buffer is uptodate +* @bh: struct buffer_head +* +* Return true if the buffer is up-to-date and false, +* with the buffer locked, if not. +*/ +int bh_uptodate_or_lock (struct buffer_head *bh) +{ +if (!buffer_uptodate (bh)) { +lock_buffer (bh); +if (!buffer_uptodate (bh)) +return 0 ; +unlock_buffer (bh); + } +return 1 ; +} +EXPORT_SYMBOL (bh_uptodate_or_lock); +/** +* bh_submit_read: Submit a locked buffer for reading +* @bh: struct buffer_head +* +* Returns a negative error +*/ +int bh_submit_read (struct buffer_head *bh) +{ +if (!buffer_locked (bh)) +lock_buffer (bh); + +if (buffer_uptodate (bh)) +return 0 ; + +get_bh (bh); + bh->b_end_io = end_buffer_read_sync; +submit_bh (READ , bh); +wait_on_buffer (bh); +if (buffer_uptodate (bh)) +return 0 ; +return -EIO ; +} +EXPORT_SYMBOL (bh_submit_read);void __init buffer_init (void ) {int nrpages;
include/linux/buffer_head.h +2 -0
@@ -192,6 +192,8 @@ int sync_dirty_buffer(struct buffer_head *bh);int submit_bh (int ,struct buffer_head *);void write_boundary_block (struct block_device *bdev,sector_t bblock,unsigned blocksize); +int bh_uptodate_or_lock (struct buffer_head *bh); +int bh_submit_read (struct buffer_head *bh);extern int buffer_heads_over_limit;
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 31/49 ext4: Take read lock during overwrite case.
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
When we are overwriting a file and not actually allocating new file system blocks we need to take only the read lock on i_data_sem.
--- fs/ext4/inode.c | 32 ++++++++++++++++++++++++-------- 1 files changed, 24 insertions(+), 8 deletions(-)
fs/ext4/inode.c +24 -8
@@ -901,11 +901,31 @@ int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, int create, int extend_disksize) { int retval; -if (create) { -down_write ((&EXT4_I (inode)->i_data_sem)); +/* +* Try to see if we can get the block without requesting +* for new file system block. +*/ +down_read ((&EXT4_I (inode)->i_data_sem)); +if (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) { + retval =ext4_ext_get_blocks (handle, inode, block, max_blocks, + bh,0 ,0 ); }else { -down_read ((&EXT4_I (inode)->i_data_sem)); + retval =ext4_get_blocks_handle (handle, + inode, block, max_blocks, bh,0 ,0 ); } +up_read ((&EXT4_I (inode)->i_data_sem)); +if (!create || (retval >0 )) +return retval; + +/* +* We need to allocate new blocks which will result +* in i_data update +*/ +down_write ((&EXT4_I (inode)->i_data_sem)); +/* +* We need to check for EXT4 here because migrate +* could have changed the inode type in between +*/ if (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) { retval =ext4_ext_get_blocks (handle, inode, block, max_blocks, bh, create, extend_disksize);
@@ -913,11 +933,7 @@ int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, retval =ext4_get_blocks_handle (handle, inode, block, max_blocks, bh, create, extend_disksize); } -if (create) { -up_write ((&EXT4_I (inode)->i_data_sem)); - }else { -up_read ((&EXT4_I (inode)->i_data_sem)); - } +up_write ((&EXT4_I (inode)->i_data_sem));return retval; } static int ext4_get_block(struct inode *inode, sector_t iblock,
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 14/49 ext4: export iov_shorten from kernel for ext4's use
In reply to Theodore Ts'oFrom: Eric Sandeen <[email protected]>
Export iov_shorten() from kernel so that ext4 can
truncate too-large writes to bitmapped files.
--- fs/read_write.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
fs/read_write.c +1 -0
@@ -450,6 +450,7 @@ unsigned long iov_shorten(struct iovec *iov, unsigned long nr_segs, size_t to) }return seg; } +EXPORT_SYMBOL (iov_shorten);ssize_t do_sync_readv_writev (struct file *filp,const struct iovec *iov,unsigned long nr_segs,size_t len,loff_t *ppos,iov_fn_t fn)
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 21/49 ext4: fix oops on corrupted ext4 mount
In reply to Theodore Ts'oFrom: Eric Sandeen <[email protected]>
When mounting an ext4 filesystem with corrupted s_first_data_block, things can go very wrong and oops.
Because blocks_count in ext4_fill_super is a u64, and we must use do_div, the calculation of db_count is done differently than on ext4. If first_data_block is corrupted such that it is larger than ext4_blocks_count, for example, then the intermediate blocks_count value may go negative, but sign-extend to a very large value:
blocks_count = (ext4_blocks_count(es) -
le32_to_cpu(es->s_first_data_block) +
EXT4_BLOCKS_PER_GROUP(sb) - 1);This is then assigned to s_groups_count which is an unsigned long:
sbi->s_groups_count = blocks_count;
This may result in a value of 0xFFFFFFFF which is then used to compute db_count:
db_count = (sbi->s_groups_count + EXT4_DESC_PER_BLOCK(sb) - 1) /
EXT4_DESC_PER_BLOCK(sb);and in this case db_count will wind up as 0 because the addition overflows 32 bits. This in turn causes the kmalloc for group_desc to be of 0 size:
sbi->s_group_desc = kmalloc(db_count * sizeof (struct buffer_head *),
GFP_KERNEL);and eventually in ext4_check_descriptors, dereferencing sbi->s_group_desc[desc_block] will result in a NULL pointer dereference.
The simplest test seems to be to sanity check s_first_data_block, EXT4_BLOCKS_PER_GROUP, and ext4_blocks_count values to be sure their combination won't result in a bad intermediate value for blocks_count. We could just check for db_count == 0, but catching it at the root cause seems like it provides more info.
--- fs/ext4/super.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
fs/ext4/super.c +11 -0
@@ -1997,6 +1997,17 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)if (EXT4_BLOCKS_PER_GROUP (sb) ==0 ) goto cantfind_ext4; + +/* ensure blocks_count calculation below doesn't sign-extend */ +if (ext4_blocks_count (es) +EXT4_BLOCKS_PER_GROUP (sb) < +le32_to_cpu (es->s_first_data_block) +1 ) { +printk (KERN_WARNING "EXT4-fs: bad geometry: block count %llu, " +"first data block %u, blocks per group %lu\n" , +ext4_blocks_count (es), +le32_to_cpu (es->s_first_data_block), +EXT4_BLOCKS_PER_GROUP (sb)); + goto failed_mount; + } blocks_count = (ext4_blocks_count (es) -le32_to_cpu (es->s_first_data_block) +EXT4_BLOCKS_PER_GROUP (sb) -1 );
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 7/49 ext4: Introduce ext4_update_*_feature
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
Introduce ext4_update_*_feature and use them instead of opencoding.
--- fs/ext4/ialloc.c | 11 +++----- fs/ext4/super.c | 60 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/ext4_fs.h | 6 ++++ 3 files changed, 70 insertions(+), 7 deletions(-)
fs/ext4/ialloc.c +4 -7
@@ -748,13 +748,10 @@ got:if (test_opt (sb,EXTENTS )) {EXT4_I (inode)->i_flags |=EXT4_EXTENTS_FL ;ext4_ext_tree_init (handle, inode); -if (!EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_EXTENTS )) { - err =ext4_journal_get_write_access (handle,EXT4_SB (sb)->s_sbh); -if (err) goto fail; -EXT4_SET_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_EXTENTS ); -BUFFER_TRACE (EXT4_SB (sb)->s_sbh,"call ext4_journal_dirty_metadata" ); - err =ext4_journal_dirty_metadata (handle,EXT4_SB (sb)->s_sbh); - } + err =ext4_update_incompat_feature (handle, sb, +EXT4_FEATURE_INCOMPAT_EXTENTS ); +if (err) + goto fail; }ext4_debug ("allocating inode %lu\n" , inode->i_ino);
fs/ext4/super.c +60 -0
66 lines not on this page · raw message
include/linux/ext4_fs.h +6 -0
@@ -989,6 +989,12 @@ extern void ext4_abort (struct super_block *, const char *, const char *, ...)extern void ext4_warning (struct super_block *,const char *,const char *, ...) __attribute__ ((format (printf,3 ,4 )));extern void ext4_update_dynamic_rev (struct super_block *sb); +extern int ext4_update_compat_feature (handle_t *handle,struct super_block *sb, +__u32 compat); +extern int ext4_update_rocompat_feature (handle_t *handle, +struct super_block *sb,__u32 rocompat); +extern int ext4_update_incompat_feature (handle_t *handle, +struct super_block *sb,__u32 incompat);extern ext4_fsblk_t ext4_block_bitmap (struct super_block *sb,struct ext4_group_desc *bg); extern ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 8/49 ext4: Fix sparse warnings.
From: Aneesh Kumar K.V <[email protected]>
Fix sparse warnings related to static functions
and local variables.
--- fs/ext4/extents.c | 6 +++--- fs/ext4/inode.c | 18 +++++++++++------- fs/ext4/super.c | 3 +++ include/linux/ext4_fs.h | 2 ++ 4 files changed, 19 insertions(+), 10 deletions(-)
fs/ext4/extents.c +3 -3
@@ -1088,7 +1088,7 @@ static ext4_lblk_t ext4_ext_next_leaf_block(struct inode *inode,* then we have to correct all indexes above. * TODO: do we need to correct tree in all cases? */ -int ext4_ext_correct_indexes (handle_t *handle,struct inode *inode, +static int ext4_ext_correct_indexes (handle_t *handle,struct inode *inode,struct ext4_ext_path *path) {struct ext4_extent_header *eh;
@@ -1535,7 +1535,7 @@ ext4_ext_in_cache(struct inode *inode, ext4_lblk_t block,* It's used in truncate case only, thus all requests are for * last index in the block only. */ -int ext4_ext_rm_idx (handle_t *handle,struct inode *inode, +static int ext4_ext_rm_idx (handle_t *handle,struct inode *inode,struct ext4_ext_path *path) {struct buffer_head *bh;
@@ -1806,7 +1806,7 @@ ext4_ext_more_to_rm(struct ext4_ext_path *path)return 1 ; } -int ext4_ext_remove_space (struct inode *inode,ext4_lblk_t start) +static int ext4_ext_remove_space (struct inode *inode,ext4_lblk_t start) {struct super_block *sb = inode->i_sb;int depth =ext_depth (inode);
fs/ext4/inode.c +11 -7
@@ -2052,11 +2052,11 @@ static void ext4_clear_blocks(handle_t *handle, struct inode *inode,for (p = first; p < last; p++) {u32 nr =le32_to_cpu (*p);if (nr) { -struct buffer_head *bh; +struct buffer_head *tbh; *p =0 ; - bh =sb_find_get_block (inode->i_sb, nr); -ext4_forget (handle,0 , inode, bh, nr); + tbh =sb_find_get_block (inode->i_sb, nr); +ext4_forget (handle,0 , inode, tbh, nr); } }
@@ -2324,8 +2324,10 @@ void ext4_truncate(struct inode *inode)return ; } -if (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) -return ext4_ext_truncate (inode, page); +if (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) { +ext4_ext_truncate (inode, page); +return ; + } handle =start_transaction (inode);if (IS_ERR (handle)) {
@@ -3163,8 +3165,10 @@ ext4_reserve_inode_write(handle_t *handle, struct inode *inode,* Expand an inode by new_extra_isize bytes. * Returns 0 on success or negative error number on failure. */ -int ext4_expand_extra_isize (struct inode *inode,unsigned int new_extra_isize, -struct ext4_iloc iloc,handle_t *handle) +static int ext4_expand_extra_isize (struct inode *inode, +unsigned int new_extra_isize, +struct ext4_iloc iloc, +handle_t *handle) {struct ext4_inode *raw_inode;struct ext4_xattr_ibody_header *header;
fs/ext4/super.c +3 -0
@@ -1644,6 +1644,9 @@ static ext4_fsblk_t descriptor_loc(struct super_block *sb,static int ext4_fill_super (struct super_block *sb,void *data,int silent) +__releases (kernel_sem) +__acquires (kernel_sem) + {struct buffer_head * bh;struct ext4_super_block *es =NULL ;
include/linux/ext4_fs.h +2 -0
@@ -893,6 +893,8 @@ extern ext4_fsblk_t ext4_new_block (handle_t *handle, struct inode *inode, ext4_fsblk_t goal, int *errp);extern ext4_fsblk_t ext4_new_blocks (handle_t *handle,struct inode *inode,ext4_fsblk_t goal,unsigned long *count,int *errp); +extern ext4_fsblk_t ext4_new_blocks_old (handle_t *handle,struct inode *inode, +ext4_fsblk_t goal,unsigned long *count,int *errp);extern void ext4_free_blocks (handle_t *handle,struct inode *inode,ext4_fsblk_t block,unsigned long count); extern void ext4_free_blocks_sb (handle_t *handle, struct super_block *sb,
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 12/49 ext4: Support large files
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
This patch converts ext4_inode i_blocks to represent total blocks occupied by the inode in file system block size. Earlier the variable used to represent this in 512 byte block size. This actually limited the total size of the file.
The feature is enabled transparently when we write an inode whose i_blocks cannot be represnted as 512 byte units in a 48 bit variable.
inode flag EXT4_HUGE_FILE_FL
--- fs/ext4/inode.c | 32 +++++++++++++++++++++++++------- fs/ext4/super.c | 9 ++++++--- include/linux/ext4_fs.h | 3 ++- 3 files changed, 33 insertions(+), 11 deletions(-)
fs/ext4/inode.c +25 -7
@@ -2671,14 +2671,20 @@ static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode, struct ext4_inode_info *ei) {blkcnt_t i_blocks ; -struct super_block *sb = ei->vfs_inode.i_sb; +struct inode *inode = &(ei->vfs_inode); +struct super_block *sb = inode->i_sb;if (EXT4_HAS_RO_COMPAT_FEATURE (sb,EXT4_FEATURE_RO_COMPAT_HUGE_FILE )) {/* we are using combined 48 bit field */ i_blocks = ((u64 )le16_to_cpu (raw_inode->i_blocks_high)) <<32 |le32_to_cpu (raw_inode->i_blocks_lo); -return i_blocks; +if (ei->i_flags &EXT4_HUGE_FILE_FL ) { +/* i_blocks represent file system block size */ +return i_blocks << (inode->i_blkbits -9 ); + }else { +return i_blocks; + } }else {return le32_to_cpu (raw_inode->i_blocks_lo); }
@@ -2829,8 +2835,9 @@ static int ext4_inode_blocks_set(handle_t *handle,* i_blocks can be represnted in a 32 bit variable * as multiple of 512 bytes */ - raw_inode->i_blocks_lo =cpu_to_le32 ((u32 )i_blocks); + raw_inode->i_blocks_lo =cpu_to_le32 (i_blocks); raw_inode->i_blocks_high =0 ; + ei->i_flags &= ~EXT4_HUGE_FILE_FL ; }else if (i_blocks <=0xffffffffffffULL ) {/* * i_blocks can be represented in a 48 bit variable
@@ -2841,12 +2848,23 @@ static int ext4_inode_blocks_set(handle_t *handle,if (err) goto err_out;/* i_block is stored in the split 48 bit fields */ - raw_inode->i_blocks_lo =cpu_to_le32 ((u32 )i_blocks); + raw_inode->i_blocks_lo =cpu_to_le32 (i_blocks); raw_inode->i_blocks_high =cpu_to_le16 (i_blocks >>32 ); + ei->i_flags &= ~EXT4_HUGE_FILE_FL ; }else { -ext4_error (sb, __FUNCTION__, -"Wrong inode i_blocks count %llu\n" , - (unsigned long long )inode->i_blocks); +/* +* i_blocks should be represented in a 48 bit variable +* as multiple of file system block size +*/ + err =ext4_update_rocompat_feature (handle, sb, +EXT4_FEATURE_RO_COMPAT_HUGE_FILE ); +if (err) + goto err_out; + ei->i_flags |=EXT4_HUGE_FILE_FL ; +/* i_block is stored in file system block size */ + i_blocks = i_blocks >> (inode->i_blkbits -9 ); + raw_inode->i_blocks_lo =cpu_to_le32 (i_blocks); + raw_inode->i_blocks_high =cpu_to_le16 (i_blocks >>32 ); } err_out:return err;
fs/ext4/super.c +6 -3
@@ -1631,11 +1631,14 @@ static loff_t ext4_max_size(int bits) upper_limit >>= (bits -9 ); }else { -/* We use 48 bit ext4_inode i_blocks */ +/* +* We use 48 bit ext4_inode i_blocks +* With EXT4_HUGE_FILE_FL set the i_blocks +* represent total number of blocks in +* file system block size +*/ upper_limit = (1LL <<48 ) -1 ; -/* total blocks in file system block size */ - upper_limit >>= (bits -9 ); }/* indirect blocks */
include/linux/ext4_fs.h +2 -1
@@ -178,8 +178,9 @@ struct ext4_group_desc#define EXT4_NOTAIL_FL 0x00008000/* file tail should not be merged */ #define EXT4_DIRSYNC_FL 0x00010000/* dirsync behaviour (directories only) */ #define EXT4_TOPDIR_FL 0x00020000/* Top of directory hierarchies*/ -#define EXT4_RESERVED_FL 0x80000000/* reserved for ext4 lib */ +#define EXT4_HUGE_FILE_FL 0x00040000/* Set to each huge file */ #define EXT4_EXTENTS_FL 0x00080000/* Inode uses extents */ +#define EXT4_RESERVED_FL 0x80000000/* reserved for ext4 lib */ #define EXT4_FL_USER_VISIBLE 0x000BDFFF/* User visible flags */ #define EXT4_FL_USER_MODIFIABLE 0x000380FF/* User modifiable flags */
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 37/49 ext4: Fix ext4_show_options to show the correct mount options.
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
We need to look at the default value and make sure the mount options are not set via default value before showing them via ext4_show_options
--- fs/ext4/super.c | 26 +++++++++++++++----------- 1 files changed, 15 insertions(+), 11 deletions(-)
fs/ext4/super.c +15 -11
@@ -665,18 +665,20 @@ static inline void ext4_show_quota_options(struct seq_file *seq, struct super_bl*/ static int ext4_show_options (struct seq_file *seq,struct vfsmount *vfs) { +int def_errors; +unsigned long def_mount_opts;struct super_block *sb = vfs->mnt_sb;struct ext4_sb_info *sbi =EXT4_SB (sb);struct ext4_super_block *es = sbi->s_es; -unsigned long def_mount_opts; def_mount_opts =le32_to_cpu (es->s_default_mount_opts); + def_errors =le16_to_cpu (es->s_errors);if (sbi->s_sb_block !=1 )seq_printf (seq,",sb=%llu" , sbi->s_sb_block);if (test_opt (sb,MINIX_DF ))seq_puts (seq,",minixdf" ); -if (test_opt (sb,GRPID )) +if (test_opt (sb,GRPID ) && !(def_mount_opts &EXT4_DEFM_BSDGROUPS ))seq_puts (seq,",grpid" );if (!test_opt (sb,GRPID ) && (def_mount_opts &EXT4_DEFM_BSDGROUPS ))seq_puts (seq,",nogrpid" );
@@ -689,25 +691,24 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)seq_printf (seq,",resgid=%u" , sbi->s_resgid); }if (test_opt (sb,ERRORS_RO )) { -int def_errors =le16_to_cpu (es->s_errors); -if (def_errors ==EXT4_ERRORS_PANIC || def_errors ==EXT4_ERRORS_CONTINUE ) {seq_puts (seq,",errors=remount-ro" ); } } -if (test_opt (sb,ERRORS_CONT )) +if (test_opt (sb,ERRORS_CONT ) && def_errors !=EXT4_ERRORS_CONTINUE )seq_puts (seq,",errors=continue" ); -if (test_opt (sb,ERRORS_PANIC )) +if (test_opt (sb,ERRORS_PANIC ) && def_errors !=EXT4_ERRORS_PANIC )seq_puts (seq,",errors=panic" ); -if (test_opt (sb,NO_UID32 )) +if (test_opt (sb,NO_UID32 ) && !(def_mount_opts &EXT4_DEFM_UID16 ))seq_puts (seq,",nouid32" ); -if (test_opt (sb,DEBUG )) +if (test_opt (sb,DEBUG ) && !(def_mount_opts &EXT4_DEFM_DEBUG ))seq_puts (seq,",debug" );if (test_opt (sb,OLDALLOC ))seq_puts (seq,",oldalloc" );#ifdef CONFIG_EXT4DEV_FS_XATTR -if (test_opt (sb,XATTR_USER )) +if (test_opt (sb,XATTR_USER ) && + !(def_mount_opts &EXT4_DEFM_XATTR_USER ))seq_puts (seq,",user_xattr" );if (!test_opt (sb,XATTR_USER ) && (def_mount_opts &EXT4_DEFM_XATTR_USER )) {
@@ -715,7 +716,7 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs) }#endif #ifdef CONFIG_EXT4DEV_FS_POSIX_ACL -if (test_opt (sb,POSIX_ACL )) +if (test_opt (sb,POSIX_ACL ) && !(def_mount_opts &EXT4_DEFM_ACL ))seq_puts (seq,",acl" );if (!test_opt (sb,POSIX_ACL ) && (def_mount_opts &EXT4_DEFM_ACL ))seq_puts (seq,",noacl" );
@@ -735,6 +736,10 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)if (test_opt (sb,I_VERSION ))seq_puts (seq,",i_version" ); +/* +* journal mode get enabled in different ways +* So just print the value even if we didn't specify it +*/ if (test_opt (sb,DATA_FLAGS ) ==EXT4_MOUNT_JOURNAL_DATA )seq_puts (seq,",data=journal" );else if (test_opt (sb,DATA_FLAGS ) ==EXT4_MOUNT_ORDERED_DATA )
@@ -743,7 +748,6 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)seq_puts (seq,",data=writeback" );ext4_show_quota_options (seq, sb); -return 0 ; }
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 24/49 ext4: add block bitmap validation
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
When a new block bitmap is read from disk in read_block_bitmap() there are a few bits that should ALWAYS be set. In particular, the blocks given corresponding to block bitmap, inode bitmap and inode tables. Validate the block bitmap against these blocks.
--- fs/ext4/balloc.c | 99 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 81 insertions(+), 18 deletions(-)
fs/ext4/balloc.c +81 -18
@@ -189,13 +189,65 @@ struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,return desc; } +static int ext4_valid_block_bitmap (struct super_block *sb, +struct ext4_group_desc *desc, +unsigned int block_group, +struct buffer_head *bh) +{ +ext4_grpblk_t offset; +ext4_grpblk_t next_zero_bit; +ext4_fsblk_t bitmap_blk; +ext4_fsblk_t group_first_block; + +if (EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_FLEX_BG )) { +/* with FLEX_BG, the inode/block bitmaps and itable +* blocks may not be in the group at all +* so the bitmap validation will be skipped for those groups +* or it has to also read the block group where the bitmaps +* are located to verify they are set. +*/ +return 1 ; + } + group_first_block =ext4_group_first_block_no (sb, block_group); + +/* check whether block bitmap block number is set */ + bitmap_blk =ext4_block_bitmap (sb, desc); + offset = bitmap_blk - group_first_block; +if (!ext4_test_bit (offset, bh->b_data)) +/* bad block bitmap */ + goto err_out; + +/* check whether the inode bitmap block number is set */ + bitmap_blk =ext4_inode_bitmap (sb, desc); + offset = bitmap_blk - group_first_block; +if (!ext4_test_bit (offset, bh->b_data)) +/* bad block bitmap */ + goto err_out; + +/* check whether the inode table block number is set */ + bitmap_blk =ext4_inode_table (sb, desc); + offset = bitmap_blk - group_first_block; + next_zero_bit =ext4_find_next_zero_bit (bh->b_data, + offset +EXT4_SB (sb)->s_itb_per_group, + offset); +if (next_zero_bit >= offset +EXT4_SB (sb)->s_itb_per_group) +/* good bitmap for inode tables */ +return 1 ; + +err_out: +ext4_error (sb, __FUNCTION__, +"Invalid block bitmap - " +"block_group = %d, block = %llu" , + block_group, bitmap_blk); +return 0 ; +}/** * read_block_bitmap() * @sb: super block * @block_group: given block group * -* Read the bitmap for a given block_group, reading into the specified -* slot in the superblock's bitmap cache. +* Read the bitmap for a given block_group,and validate the +* bits for block/inode/inode tables are set in the bitmaps * * Return buffer_head on success or NULL in case of failure. */
@@ -210,25 +262,36 @@ read_block_bitmap(struct super_block *sb, ext4_group_t block_group)if (!desc)return NULL ; bitmap_blk =ext4_block_bitmap (sb, desc); + bh =sb_getblk (sb, bitmap_blk); +if (unlikely (!bh)) { +ext4_error (sb, __FUNCTION__, +"Cannot read block bitmap - " +"block_group = %d, block_bitmap = %llu" , + (int )block_group, (unsigned long long )bitmap_blk); +return NULL ; + } +if (bh_uptodate_or_lock (bh)) +return bh; +if (desc->bg_flags &cpu_to_le16 (EXT4_BG_BLOCK_UNINIT )) { - bh =sb_getblk (sb, bitmap_blk); -if (!buffer_uptodate (bh)) { -lock_buffer (bh); -if (!buffer_uptodate (bh)) { -ext4_init_block_bitmap (sb, bh, block_group, - desc); -set_buffer_uptodate (bh); - } -unlock_buffer (bh); - } - }else { - bh =sb_bread (sb, bitmap_blk); +ext4_init_block_bitmap (sb, bh, block_group, desc); +set_buffer_uptodate (bh); +unlock_buffer (bh); +return bh; } -if (!bh) -ext4_error (sb, __FUNCTION__, +if (bh_submit_read (bh) <0 ) { +brelse (bh); +ext4_error (sb, __FUNCTION__,"Cannot read block bitmap - " -"block_group = %lu, block_bitmap = %llu" , - block_group, bitmap_blk); +"block_group = %d, block_bitmap = %llu" , + (int )block_group, (unsigned long long )bitmap_blk); +return NULL ; + } +if (!ext4_valid_block_bitmap (sb, desc, block_group, bh)) { +brelse (bh); +return NULL ; + } +return bh; }/*
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 46/49 jbd2: add lockdep support
In reply to Theodore Ts'oFrom: Mingming Cao <[email protected]>
Ported from similar patch for the jbd layer.
--- fs/jbd2/transaction.c | 11 +++++++++++ include/linux/jbd2.h | 4 ++++ 2 files changed, 15 insertions(+), 0 deletions(-)
fs/jbd2/transaction.c +11 -0
@@ -241,6 +241,8 @@ out:return ret; } +static struct lock_class_key jbd2_handle_key; +/* Allocate a new handle. This should probably be in a slab... */ static handle_t *new_handle (int nblocks) {
@@ -251,6 +253,9 @@ static handle_t *new_handle(int nblocks) handle->h_buffer_credits = nblocks; handle->h_ref =1 ; +lockdep_init_map (&handle->h_lockdep_map,"jbd2_handle" , + &jbd2_handle_key,0 ); +return handle; }
@@ -293,7 +298,11 @@ handle_t *jbd2_journal_start(journal_t *journal, int nblocks)jbd2_free_handle (handle); current->journal_info =NULL ; handle =ERR_PTR (err); + goto out; } + +lock_acquire (&handle->h_lockdep_map,0 ,0 ,0 ,2 , _THIS_IP_); +out:return handle; }
@@ -1419,6 +1428,8 @@ int jbd2_journal_stop(handle_t *handle)spin_unlock (&journal->j_state_lock); } +lock_release (&handle->h_lockdep_map,1 , _THIS_IP_); +jbd2_free_handle (handle);return err; }
include/linux/jbd2.h +4 -0
@@ -418,6 +418,10 @@ struct handle_s unsigned int h_sync: 1; /* sync-on-close */ unsigned int h_jdata: 1; /* force data journaling */ unsigned int h_aborted: 1; /* fatal error on handle */ + +#ifdef CONFIG_DEBUG_LOCK_ALLOC +struct lockdep_map h_lockdep_map; +#endif };
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 10/49 ext4: Rename i_dir_acl to i_size_high
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
Rename ext4_inode.i_dir_acl to i_size_high
drop ext4_inode_info.i_dir_acl as it is not used
Rename ext4_inode.i_size to ext4_inode.i_size_lo
Add helper function for accessing the ext4_inode combined i_size.
--- fs/ext4/ialloc.c | 1 - fs/ext4/inode.c | 55 ++++++++++++++++++--------------------------- include/linux/ext4_fs.h | 15 +++++++++-- include/linux/ext4_fs_i.h | 1 - 4 files changed, 34 insertions(+), 38 deletions(-)
fs/ext4/ialloc.c +0 -1
@@ -709,7 +709,6 @@ got:if (!S_ISDIR (mode)) ei->i_flags &= ~EXT4_DIRSYNC_FL ; ei->i_file_acl =0 ; - ei->i_dir_acl =0 ; ei->i_dtime =0 ; ei->i_block_alloc_info =NULL ; ei->i_block_group = group;
fs/ext4/inode.c +22 -33
83 lines not on this page · raw message
include/linux/ext4_fs.h +12 -3
@@ -275,7 +275,7 @@ struct ext4_mount_options {struct ext4_inode {__le16 i_mode;/* File mode */ __le16 i_uid;/* Low 16 bits of Owner Uid */ -__le32 i_size;/* Size in bytes */ +__le32 i_size_lo;/* Size in bytes */ __le32 i_atime;/* Access time */ __le32 i_ctime;/* Inode Change time */ __le32 i_mtime;/* Modification time */
@@ -298,7 +298,7 @@ struct ext4_inode {__le32 i_block[EXT4_N_BLOCKS ];/* Pointers to blocks */ __le32 i_generation;/* File version (for NFS) */ __le32 i_file_acl_lo;/* File ACL */ -__le32 i_dir_acl;/* Directory ACL */ +__le32 i_size_high;__le32 i_obso_faddr;/* Obsoleted fragment address */ union { struct {
@@ -330,7 +330,6 @@ struct ext4_inode {__le32 i_crtime_extra;/* extra FileCreationtime (nsec << 2 | epoch) */ }; -#define i_size_high i_dir_acl#define EXT4_EPOCH_BITS 2#define EXT4_EPOCH_MASK ((1 << EXT4_EPOCH_BITS) - 1)
@@ -1049,7 +1048,17 @@ static inline void ext4_r_blocks_count_set(struct ext4_super_block *es, es->s_r_blocks_count_hi =cpu_to_le32 (blk >>32 ); } +static inline loff_t ext4_isize (struct ext4_inode *raw_inode) +{ +return ((loff_t )le32_to_cpu (raw_inode->i_size_high) <<32 ) | +le32_to_cpu (raw_inode->i_size_lo); +} +static inline void ext4_isize_set (struct ext4_inode *raw_inode,loff_t i_size) +{ + raw_inode->i_size_lo =cpu_to_le32 (i_size); + raw_inode->i_size_high =cpu_to_le32 (i_size >>32 ); +}#define ext4_std_error (sb, errno) \ do { \
include/linux/ext4_fs_i.h +0 -1
@@ -85,7 +85,6 @@ struct ext4_inode_info {__le32 i_data[15 ];/* unconverted */ __u32 i_flags;ext4_fsblk_t i_file_acl; -__u32 i_dir_acl;__u32 i_dtime;/*
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 29/49 ext4: Make ext4_get_blocks_wrap take the truncate_mutex early.
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
When doing a migrate from ext3 to ext4 inode we need to make sure the test for inode type and walking inode data happens inside lock. To make this happen move truncate_mutex early before checking the i_flags.
This actually should enable us to remove the verify_chain().
--- fs/ext4/extents.c | 9 ++++-- fs/ext4/inode.c | 69 +++++----------------------------------------- include/linux/ext4_fs.h | 2 + 3 files changed, 16 insertions(+), 64 deletions(-)
fs/ext4/extents.c +6 -3
@@ -2129,6 +2129,10 @@ out:return err ? err : allocated; } +/* +* Need to be called with +* mutex_lock(&EXT4_I(inode)->truncate_mutex); +*/ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, ext4_lblk_t iblock, unsigned long max_blocks, struct buffer_head *bh_result,
@@ -2144,7 +2148,6 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,__clear_bit (BH_New, &bh_result->b_state);ext_debug ("blocks %u/%lu requested for inode %u\n" , iblock, max_blocks, inode->i_ino); -mutex_lock (&EXT4_I (inode)->truncate_mutex);/* check in cache */ goal =ext4_ext_in_cache (inode, iblock, &newex);
@@ -2318,8 +2321,6 @@ out2:ext4_ext_drop_refs (path);kfree (path); } -mutex_unlock (&EXT4_I (inode)->truncate_mutex); -return err ? err : allocated; }
@@ -2449,6 +2450,7 @@ long ext4_fallocate(struct inode *inode, int mode, loff_t offset, loff_t len)* modify 1 super block, 1 block bitmap and 1 group descriptor. */ credits =EXT4_DATA_TRANS_BLOCKS (inode->i_sb) +3 ; + mutex_lock(&EXT4_I(inode)->truncate_mutex) retry:while (ret >=0 && ret < max_blocks) { block = block + ret;
@@ -2505,6 +2507,7 @@ retry:if (ret == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries)) goto retry; +mutex_unlock (&EXT4_I (inode)->truncate_mutex)/* * Time to update the file size. * Update only when preallocation was requested beyond the file size.
fs/ext4/inode.c +8 -61
125 lines not on this page · raw message
include/linux/ext4_fs.h +2 -0
@@ -1113,6 +1113,7 @@ ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, int create, int extend_disksize) { int retval; +mutex_lock (&EXT4_I (inode)->truncate_mutex); if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) { retval = ext4_ext_get_blocks(handle, inode, (ext4_lblk_t)block, max_blocks,
@@ -1122,6 +1123,7 @@ ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, (ext4_lblk_t )block, max_blocks, bh, create, extend_disksize); } +mutex_unlock (&EXT4_I (inode)->truncate_mutex);return retval; }
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 11/49 ext4: Add support for 48 bit inode i_blocks.
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
Use the __le16 l_i_reserved1 field of the linux2 struct of ext4_inode to represet the higher 16 bits for i_blocks. With this change max_file size becomes (2**48 -1 )* 512 bytes.
We add a RO_COMPAT feature to the super block to indicate that inode have i_blocks represented as a split 48 bits. Super block with this feature set cannot be mounted read write on a kernel with CONFIG_LSF disabled.
Super block flag EXT4_FEATURE_RO_COMPAT_HUGE_FILE
--- fs/ext4/inode.c | 58 ++++++++++++++++++++++++++++++++++++++++++- fs/ext4/super.c | 62 ++++++++++++++++++++++++++++++++++++++++++---- include/linux/ext4_fs.h | 10 +++++-- 3 files changed, 119 insertions(+), 11 deletions(-)
fs/ext4/inode.c +56 -2
@@ -2667,6 +2667,22 @@ void ext4_get_inode_flags(struct ext4_inode_info *ei)if (flags &S_DIRSYNC ) ei->i_flags |=EXT4_DIRSYNC_FL ; } +static blkcnt_t ext4_inode_blocks (struct ext4_inode *raw_inode, +struct ext4_inode_info *ei) +{ +blkcnt_t i_blocks ; +struct super_block *sb = ei->vfs_inode.i_sb; + +if (EXT4_HAS_RO_COMPAT_FEATURE (sb, +EXT4_FEATURE_RO_COMPAT_HUGE_FILE )) { +/* we are using combined 48 bit field */ + i_blocks = ((u64 )le16_to_cpu (raw_inode->i_blocks_high)) <<32 | +le32_to_cpu (raw_inode->i_blocks_lo); +return i_blocks; + }else { +return le32_to_cpu (raw_inode->i_blocks_lo); + } +}void ext4_read_inode (struct inode * inode) {
@@ -2715,8 +2731,8 @@ void ext4_read_inode(struct inode * inode)* recovery code: that's fine, we're about to complete * the process of deleting those. */ } - inode->i_blocks =le32_to_cpu (raw_inode->i_blocks); ei->i_flags =le32_to_cpu (raw_inode->i_flags); + inode->i_blocks =ext4_inode_blocks (raw_inode, ei); ei->i_file_acl =le32_to_cpu (raw_inode->i_file_acl_lo);if (EXT4_SB (inode->i_sb)->s_es->s_creator_os !=cpu_to_le32 (EXT4_OS_HURD )) {
@@ -2799,6 +2815,43 @@ bad_inode:return ; } +static int ext4_inode_blocks_set (handle_t *handle, +struct ext4_inode *raw_inode, +struct ext4_inode_info *ei) +{ +struct inode *inode = &(ei->vfs_inode); +u64 i_blocks = inode->i_blocks; +struct super_block *sb = inode->i_sb; +int err =0 ; + +if (i_blocks <= ~0U ) { +/* +* i_blocks can be represnted in a 32 bit variable +* as multiple of 512 bytes +*/ + raw_inode->i_blocks_lo =cpu_to_le32 ((u32 )i_blocks); + raw_inode->i_blocks_high =0 ; + }else if (i_blocks <=0xffffffffffffULL ) { +/* +* i_blocks can be represented in a 48 bit variable +* as multiple of 512 bytes +*/ + err =ext4_update_rocompat_feature (handle, sb, +EXT4_FEATURE_RO_COMPAT_HUGE_FILE ); +if (err) + goto err_out; +/* i_block is stored in the split 48 bit fields */ + raw_inode->i_blocks_lo =cpu_to_le32 ((u32 )i_blocks); + raw_inode->i_blocks_high =cpu_to_le16 (i_blocks >>32 ); + }else { +ext4_error (sb, __FUNCTION__, +"Wrong inode i_blocks count %llu\n" , + (unsigned long long )inode->i_blocks); + } +err_out: +return err; +} +/* * Post the struct inode info into an on-disk inode location in the * buffer-cache. This gobbles the caller's reference to the
@@ -2853,7 +2906,8 @@ static int ext4_do_update_inode(handle_t *handle,EXT4_INODE_SET_XTIME (i_atime, inode, raw_inode);EXT4_EINODE_SET_XTIME (i_crtime, ei, raw_inode); - raw_inode->i_blocks =cpu_to_le32 (inode->i_blocks); +if (ext4_inode_blocks_set (handle, raw_inode, ei)) + goto out_brelse; raw_inode->i_dtime =cpu_to_le32 (ei->i_dtime); raw_inode->i_flags =cpu_to_le32 (ei->i_flags); if (EXT4_SB(inode->i_sb)->s_es->s_creator_os !=
fs/ext4/super.c +56 -6
85 lines not on this page · raw message
include/linux/ext4_fs.h +7 -3
@@ -282,7 +282,7 @@ struct ext4_inode {__le32 i_dtime;/* Deletion Time */ __le16 i_gid;/* Low 16 bits of Group Id */ __le16 i_links_count;/* Links count */ -__le32 i_blocks;/* Blocks count */ +__le32 i_blocks_lo;/* Blocks count */ __le32 i_flags;/* File flags */ union { struct {
@@ -302,7 +302,7 @@ struct ext4_inode {__le32 i_obso_faddr;/* Obsoleted fragment address */ union {struct { -__le16 l_i_reserved1;/* Obsoleted fragment number/size which are removed in ext4 */ +__le16 l_i_blocks_high;/* were l_i_reserved1 */ __le16 l_i_file_acl_high;__le16 l_i_uid_high;/* these 2 fields */ __le16 l_i_gid_high;/* were reserved2[0] */
@@ -404,6 +404,7 @@ do { \#if defined(__KERNEL__) || defined(__linux__)#define i_reserved1 osd1.linux1.l_i_reserved1#define i_file_acl_high osd2.linux2.l_i_file_acl_high +#define i_blocks_high osd2.linux2.l_i_blocks_high#define i_uid_low i_uid#define i_gid_low i_gid#define i_uid_high osd2.linux2.l_i_uid_high
@@ -670,6 +671,7 @@ static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)#define EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER 0x0001#define EXT4_FEATURE_RO_COMPAT_LARGE_FILE 0x0002#define EXT4_FEATURE_RO_COMPAT_BTREE_DIR 0x0004 +#define EXT4_FEATURE_RO_COMPAT_HUGE_FILE 0x0008#define EXT4_FEATURE_RO_COMPAT_GDT_CSUM 0x0010#define EXT4_FEATURE_RO_COMPAT_DIR_NLINK 0x0020#define EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE 0x0040
@@ -681,6 +683,7 @@ static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)#define EXT4_FEATURE_INCOMPAT_META_BG 0x0010#define EXT4_FEATURE_INCOMPAT_EXTENTS 0x0040/* extents support */ #define EXT4_FEATURE_INCOMPAT_64BIT 0x0080 +#define EXT4_FEATURE_INCOMPAT_MMP 0x0100#define EXT4_FEATURE_INCOMPAT_FLEX_BG 0x0200#define EXT4_FEATURE_COMPAT_SUPP EXT2_FEATURE_COMPAT_EXT_ATTR
@@ -695,7 +698,8 @@ static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino)EXT4_FEATURE_RO_COMPAT_GDT_CSUM | \EXT4_FEATURE_RO_COMPAT_DIR_NLINK | \EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE | \ - EXT4_FEATURE_RO_COMPAT_BTREE_DIR) +EXT4_FEATURE_RO_COMPAT_BTREE_DIR |\ + EXT4_FEATURE_RO_COMPAT_HUGE_FILE)/* * Default values for user and/or group using reserved blocks
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 30/49 ext4: Convert truncate_mutex to read write semaphore.
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
We are currently taking the truncate_mutex for every read. This would have performance impact on large CPU configuration. Convert the lock to read write semaphore and take read lock when we are trying to read the file.
--- fs/ext4/balloc.c | 2 +- fs/ext4/extents.c | 13 +++++++------ fs/ext4/file.c | 4 ++-- fs/ext4/inode.c | 39 ++++++++++++++++++++++++++++++++------- fs/ext4/ioctl.c | 4 ++-- fs/ext4/super.c | 2 +- include/linux/ext4_fs.h | 25 ++++--------------------- include/linux/ext4_fs_i.h | 6 +++--- 8 files changed, 52 insertions(+), 43 deletions(-)
fs/ext4/balloc.c +1 -1
@@ -526,7 +526,7 @@ static inline int rsv_is_empty(struct ext4_reserve_window *rsv)* when setting the reservation window size through ioctl before the file * is open for write (needs block allocation). * -* Needs truncate_mutex protection prior to call this function. +* Needs down_write(i_data_sem) protection prior to call this function. */ void ext4_init_block_alloc_info (struct inode *inode) {
fs/ext4/extents.c +7 -6
@@ -1565,7 +1565,7 @@ static int ext4_ext_rm_idx(handle_t *handle, struct inode *inode,* This routine returns max. credits that the extent tree can consume. * It should be OK for low-performance paths like ->writepage() * To allow many writing processes to fit into a single transaction, -* the caller should calculate credits under truncate_mutex and +* the caller should calculate credits under i_data_sem and * pass the actual path. */ int ext4_ext_calc_credits_for_insert(struct inode *inode,
@@ -2131,7 +2131,8 @@ out:/* * Need to be called with -* mutex_lock(&EXT4_I(inode)->truncate_mutex); +* down_read(&EXT4_I(inode)->i_data_sem) if not allocating file system block +* (ie, create is zero). Otherwise down_write(&EXT4_I(inode)->i_data_sem) */ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, ext4_lblk_t iblock,
@@ -2350,7 +2351,7 @@ void ext4_ext_truncate(struct inode * inode, struct page *page)if (page)ext4_block_truncate_page (handle, page, mapping, inode->i_size); -mutex_lock (&EXT4_I (inode)->truncate_mutex); +down_write (&EXT4_I (inode)->i_data_sem);ext4_ext_invalidate_cache (inode);/*
@@ -2386,7 +2387,7 @@ out_stop:if (inode->i_nlink)ext4_orphan_del (handle, inode); -mutex_unlock (&EXT4_I (inode)->truncate_mutex); +up_write (&EXT4_I (inode)->i_data_sem);ext4_journal_stop (handle); }
@@ -2450,7 +2451,7 @@ long ext4_fallocate(struct inode *inode, int mode, loff_t offset, loff_t len)* modify 1 super block, 1 block bitmap and 1 group descriptor. */ credits =EXT4_DATA_TRANS_BLOCKS (inode->i_sb) +3 ; - mutex_lock(&EXT4_I(inode)->truncate_mutex) +down_write ((&EXT4_I (inode)->i_data_sem)); retry:while (ret >=0 && ret < max_blocks) { block = block + ret;
@@ -2507,7 +2508,7 @@ retry:if (ret == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries)) goto retry; -mutex_unlock (&EXT4_I (inode)->truncate_mutex) +up_write ((&EXT4_I (inode)->i_data_sem));/* * Time to update the file size. * Update only when preallocation was requested beyond the file size.
fs/ext4/file.c +2 -2
@@ -37,9 +37,9 @@ static int ext4_release_file (struct inode * inode, struct file * filp)if ((filp->f_mode &FMODE_WRITE ) && (atomic_read (&inode->i_writecount) ==1 )) { -mutex_lock (&EXT4_I (inode)->truncate_mutex); +down_write (&EXT4_I (inode)->i_data_sem);ext4_discard_reservation (inode); -mutex_unlock (&EXT4_I (inode)->truncate_mutex); +up_write (&EXT4_I (inode)->i_data_sem); }if (is_dx (inode) && filp->private_data)ext4_htree_free_dir_info (filp->private_data);
fs/ext4/inode.c +32 -7
@@ -308,7 +308,7 @@ static int ext4_block_to_path(struct inode *inode, final = ptrs; }else {ext4_warning (inode->i_sb,"ext4_block_to_path" , -"block %u > max" , +"block %lu > max" , i_block + direct_blocks + indirect_blocks + double_blocks); }
@@ -345,7 +345,7 @@ static int ext4_block_to_path(struct inode *inode,* the whole chain, all way to the data (returns %NULL, *err == 0). * * Need to be called with -* mutex_lock(&EXT4_I(inode)->truncate_mutex) +* down_read(&EXT4_I(inode)->i_data_sem) */ static Indirect *ext4_get_branch(struct inode *inode, int depth, ext4_lblk_t *offsets,
@@ -777,7 +777,8 @@ err_out:* * * Need to be called with -* mutex_lock(&EXT4_I(inode)->truncate_mutex) +* down_read(&EXT4_I(inode)->i_data_sem) if not allocating file system block +* (ie, create is zero). Otherwise down_write(&EXT4_I(inode)->i_data_sem) */ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode, ext4_lblk_t iblock, unsigned long maxblocks,
@@ -865,7 +866,7 @@ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode, err =ext4_splice_branch (handle, inode, iblock, partial, indirect_blks, count);/* -* i_disksize growing is protected by truncate_mutex. Don't forget to +* i_disksize growing is protected by i_data_sem. Don't forget to * protect it if you're about to implement concurrent * ext4_get_block() -bzzz */
@@ -895,6 +896,30 @@ out:#define DIO_CREDITS (EXT4_RESERVE_TRANS_BLOCKS + 32) +int ext4_get_blocks_wrap (handle_t *handle,struct inode *inode,sector_t block, +unsigned long max_blocks,struct buffer_head *bh, +int create,int extend_disksize) +{ +int retval; +if (create) { +down_write ((&EXT4_I (inode)->i_data_sem)); + }else { +down_read ((&EXT4_I (inode)->i_data_sem)); + } +if (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) { + retval =ext4_ext_get_blocks (handle, inode, block, max_blocks, + bh, create, extend_disksize); + }else { + retval =ext4_get_blocks_handle (handle, inode, block, + max_blocks, bh, create, extend_disksize); + } +if (create) { +up_write ((&EXT4_I (inode)->i_data_sem)); + }else { +up_read ((&EXT4_I (inode)->i_data_sem)); + } +return retval; +}static int ext4_get_block (struct inode *inode,sector_t iblock,struct buffer_head *bh_result,int create) {
@@ -1399,7 +1424,7 @@ static int jbd2_journal_dirty_data_fn(handle_t *handle, struct buffer_head *bh)* ext4_file_write() -> generic_file_write() -> __alloc_pages() -> ... * * Same applies to ext4_get_block(). We will deadlock on various things like -* lock_journal and i_truncate_mutex. +* lock_journal and i_data_sem * * Setting PF_MEMALLOC here doesn't work - too many internal memory * allocations fail.
@@ -2325,7 +2350,7 @@ void ext4_truncate(struct inode *inode)* From here we block out all ext4_get_block() callers who want to * modify the block allocation tree. */ -mutex_lock (&ei->truncate_mutex); +down_write (&ei->i_data_sem);if (n ==1 ) {/* direct blocks */ ext4_free_data(handle, inode, NULL, i_data+offsets[0],
@@ -2389,7 +2414,7 @@ do_indirects:ext4_discard_reservation (inode); -mutex_unlock (&ei->truncate_mutex); +up_write (&ei->i_data_sem); inode->i_mtime = inode->i_ctime =ext4_current_time (inode);ext4_mark_inode_dirty (handle, inode);
fs/ext4/ioctl.c +2 -2
@@ -199,7 +199,7 @@ flags_err:* need to allocate reservation structure for this inode * before set the window size */ -mutex_lock (&ei->truncate_mutex); +down_write (&ei->i_data_sem);if (!ei->i_block_alloc_info)ext4_init_block_alloc_info (inode);
@@ -207,7 +207,7 @@ flags_err:struct ext4_reserve_window_node *rsv = &ei->i_block_alloc_info->rsv_window_node; rsv->rsv_goal_size = rsv_window_size; } -mutex_unlock (&ei->truncate_mutex); +up_write (&ei->i_data_sem);return 0 ; }case EXT4_IOC_GROUP_EXTEND : {
fs/ext4/super.c +1 -1
@@ -593,7 +593,7 @@ static void init_once(struct kmem_cache *cachep, void *foo)#ifdef CONFIG_EXT4DEV_FS_XATTR init_rwsem (&ei->xattr_sem);#endif -mutex_init (&ei->truncate_mutex); +init_rwsem (&ei->i_data_sem);inode_init_once (&ei->vfs_inode); }
include/linux/ext4_fs.h +4 -21
@@ -1107,27 +1107,10 @@ extern void ext4_ext_init(struct super_block *);extern void ext4_ext_release (struct super_block *);extern long ext4_fallocate (struct inode *inode,int mode,loff_t offset,loff_t len); -static inline int -ext4_get_blocks_wrap (handle_t *handle,struct inode *inode,sector_t block, -unsigned long max_blocks,struct buffer_head *bh, -int create,int extend_disksize) -{ -int retval; -mutex_lock (&EXT4_I (inode)->truncate_mutex); -if (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) { - retval =ext4_ext_get_blocks (handle, inode, - (ext4_lblk_t )block, max_blocks, - bh, create, extend_disksize); - }else { - retval =ext4_get_blocks_handle (handle, inode, - (ext4_lblk_t )block, max_blocks, - bh, create, extend_disksize); - } -mutex_unlock (&EXT4_I (inode)->truncate_mutex); -return retval; -} - - +extern int ext4_get_blocks_wrap (handle_t *handle,struct inode *inode, +sector_t block,unsigned long max_blocks, +struct buffer_head *bh,int create, +int extend_disksize);#endif /* __KERNEL__ */ #endif /* _LINUX_EXT4_FS_H */
include/linux/ext4_fs_i.h +3 -3
@@ -139,16 +139,16 @@ struct ext4_inode_info {__u16 i_extra_isize;/* -* truncate_mutex is for serialising ext4_truncate() against +* i_data_sem is for serialising ext4_truncate() against * ext4_getblock(). In the 2.4 ext2 design, great chunks of inode's * data tree are chopped off during truncate. We can't do that in * ext4 because whenever we perform intermediate commits during * truncate, the inode and all the metadata blocks *must* be in a * consistent state which allows truncation of the orphans to restart * during recovery. Hence we must fix the get_block-vs-truncate race -* by other means, so we have truncate_mutex. +* by other means, so we have i_data_sem. */ -struct mutex truncate_mutex; +struct rw_semaphore i_data_sem;struct inode vfs_inode;unsigned long i_ext_generation;
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 36/49 ext4: Add EXT4_IOC_MIGRATE ioctl
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
The below patch add ioctl for migrating ext3 indirect block mapped inode to ext4 extent mapped inode.
--- fs/ext4/Makefile | 2 +- fs/ext4/ioctl.c | 3 + fs/ext4/migrate.c | 634 +++++++++++++++++++++++++++++++++++++++++++++++ include/linux/ext4_fs.h | 4 + 4 files changed, 642 insertions(+), 1 deletions(-) create mode 100644 fs/ext4/migrate.c
fs/ext4/Makefile +1 -1
@@ -6,7 +6,7 @@ obj-$(CONFIG_EXT4DEV_FS) += ext4dev.o ext4dev-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \ ioctl.o namei.o super.o symlink.o hash.o resize.o extents.o \ - ext4_jbd2.o + ext4_jbd2.o migrate.o ext4dev-$(CONFIG_EXT4DEV_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o ext4dev-$(CONFIG_EXT4DEV_FS_POSIX_ACL) += acl.o
fs/ext4/ioctl.c +3 -0
@@ -254,6 +254,9 @@ flags_err:return err; } +case EXT4_IOC_MIGRATE : +return ext4_ext_migrate (inode, filp, cmd, arg); +default :return -ENOTTY ; }
fs/ext4/migrate.c new file +634 -0
634 lines not on this page · raw message
include/linux/ext4_fs.h +4 -0
@@ -243,6 +243,7 @@ struct ext4_new_group_data {#endif #define EXT4_IOC_GETRSVSZ _IOR('f', 5, long)#define EXT4_IOC_SETRSVSZ _IOW('f', 6, long) +#define EXT4_IOC_MIGRATE _IO('f', 7)/* * ioctl commands in 32 bit emulation
@@ -983,6 +984,9 @@ extern int ext4_ioctl (struct inode *, struct file *, unsigned int, unsigned long);extern long ext4_compat_ioctl (struct file *,unsigned int ,unsigned long ); +/* migrate.c */ +extern int ext4_ext_migrate (struct inode *,struct file *,unsigned int , +unsigned long );/* namei.c */ extern int ext4_orphan_add (handle_t *,struct inode *);extern int ext4_orphan_del (handle_t *,struct inode *);
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 13/49 ext4: different maxbytes functions for bitmap & extent files
In reply to Theodore Ts'oFrom: Eric Sandeen <[email protected]>
use 2 different maxbytes functions for bitmapped & extent-based files.
--- fs/ext4/super.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 42 insertions(+), 3 deletions(-)
fs/ext4/super.c +42 -3
@@ -1600,19 +1600,58 @@ static void ext4_orphan_cleanup (struct super_block * sb,#endif sb->s_flags = s_flags;/* Restore MS_RDONLY status */ } +/* +* Maximal extent format file size. +* Resulting logical blkno at s_maxbytes must fit in our on-disk +* extent format containers, within a sector_t, and within i_blocks +* in the vfs. ext4 inode has 48 bits of i_block in fsblock units, +* so that won't be a limiting factor. +* +* Note, this does *not* consider any metadata overhead for vfs i_blocks. +*/ +static loff_t ext4_max_size (int blkbits) +{ +loff_t res; +loff_t upper_limit =MAX_LFS_FILESIZE ; + +/* small i_blocks in vfs inode? */ +if (sizeof (blkcnt_t) <sizeof (u64)) { +/* +* CONFIG_LSF is not enabled implies the inode +* i_block represent total blocks in 512 bytes +* 32 == size of vfs inode i_blocks * 8 +*/ + upper_limit = (1LL <<32 ) -1 ; + +/* total blocks in file system block size */ + upper_limit >>= (blkbits -9 ); + upper_limit <<= blkbits; + } + +/* 32-bit extent-start container, ee_block */ + res =1LL <<32 ; + res <<= blkbits; + res -=1 ; + +/* Sanity check against vm- & vfs- imposed limits */ +if (res > upper_limit) + res = upper_limit; + +return res; +}/* -* Maximal file size. There is a direct, and {,double-,triple-}indirect +* Maximal bitmap file size. There is a direct, and {,double-,triple-}indirect * block limit, and also a limit of (2^48 - 1) 512-byte sectors in i_blocks. * We need to be 1 filesystem block less than the 2^48 sector limit. */ -static loff_t ext4_max_size (int bits) +static loff_t ext4_max_bitmap_size (int bits) {loff_t res =EXT4_NDIR_BLOCKS ;int meta_blocks;loff_t upper_limit;/* This is calculated to be the largest file size for a -* dense, file such that the total number of +* dense, bitmapped file such that the total number of * sectors in the file, including data and all indirect blocks, * does not exceed 2^48 -1 * __u32 i_blocks_lo and _u16 i_blocks_high representing the
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 5/49 ext4: add ext4_group_t, and change all group variables to this type.
In reply to Theodore Ts'oFrom: Avantika Mathur <[email protected]>
In many places variables for block group are of type int, which limits the maximum number of block groups to 2^31. Each block group can have up to 2^15 blocks, with a 4K block size, and the max filesystem size is limited to 2^31 * (2^15 * 2^12) = 2^58 -- or 256 PB
This patch introduces a new type ext4_group_t, of type unsigned long, to represent block group numbers in ext4.
All occurrences of block group variables are converted to type ext4_group_t.
--- fs/ext4/balloc.c | 69 +++++++++++++++++++++----------------------- fs/ext4/group.h | 8 +++-- fs/ext4/ialloc.c | 46 +++++++++++++++-------------- fs/ext4/inode.c | 5 ++- fs/ext4/resize.c | 12 ++++---- fs/ext4/super.c | 20 ++++++------- include/linux/ext4_fs.h | 11 ++++--- include/linux/ext4_fs_i.h | 5 ++- include/linux/ext4_fs_sb.h | 2 +- 9 files changed, 91 insertions(+), 87 deletions(-)
fs/ext4/balloc.c +33 -36
@@ -29,7 +29,7 @@* Calculate the block group number and offset, given a block number */ void ext4_get_group_no_and_offset (struct super_block *sb,ext4_fsblk_t blocknr, -unsigned long *blockgrpp,ext4_grpblk_t *offsetp) +ext4_group_t *blockgrpp,ext4_grpblk_t *offsetp) {struct ext4_super_block *es =EXT4_SB (sb)->s_es;ext4_grpblk_t offset;
@@ -46,7 +46,7 @@ void ext4_get_group_no_and_offset(struct super_block *sb, ext4_fsblk_t blocknr,/* Initializes an uninitialized block bitmap if given, and returns the * number of blocks free in the group. */ unsigned ext4_init_block_bitmap (struct super_block *sb,struct buffer_head *bh, -int block_group,struct ext4_group_desc *gdp) +ext4_group_t block_group,struct ext4_group_desc *gdp) {unsigned long start;int bit, bit_max;
@@ -60,7 +60,7 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,* essentially implementing a per-group read-only flag. */ if (!ext4_group_desc_csum_verify (sbi, block_group, gdp)) {ext4_error (sb, __FUNCTION__, -"Checksum bad for group %u\n" , block_group); +"Checksum bad for group %lu\n" , block_group); gdp->bg_free_blocks_count =0 ; gdp->bg_free_inodes_count =0 ; gdp->bg_itable_unused =0 ;
@@ -153,7 +153,7 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,* group descriptor */ struct ext4_group_desc *ext4_get_group_desc (struct super_block * sb, -unsigned int block_group, +ext4_group_t block_group,struct buffer_head ** bh) {unsigned long group_desc;
@@ -164,7 +164,7 @@ struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,if (block_group >= sbi->s_groups_count) {ext4_error (sb,"ext4_get_group_desc" ,"block_group >= groups_count - " -"block_group = %d, groups_count = %lu" , +"block_group = %lu, groups_count = %lu" , block_group, sbi->s_groups_count);return NULL ;
@@ -176,7 +176,7 @@ struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,if (!sbi->s_group_desc[group_desc]) {ext4_error (sb,"ext4_get_group_desc" ,"Group descriptor not loaded - " -"block_group = %d, group_desc = %lu, desc = %lu" , +"block_group = %lu, group_desc = %lu, desc = %lu" , block_group, group_desc, offset);return NULL ; }
@@ -200,7 +200,7 @@ struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,* Return buffer_head on success or NULL in case of failure. */ struct buffer_head * -read_block_bitmap (struct super_block *sb,unsigned int block_group) +read_block_bitmap (struct super_block *sb,ext4_group_t block_group) {struct ext4_group_desc * desc;struct buffer_head * bh =NULL ;
@@ -227,7 +227,7 @@ read_block_bitmap(struct super_block *sb, unsigned int block_group)if (!bh)ext4_error (sb, __FUNCTION__,"Cannot read block bitmap - " -"block_group = %d, block_bitmap = %llu" , +"block_group = %lu, block_bitmap = %llu" , block_group, bitmap_blk);return bh; }
@@ -320,7 +320,7 @@ restart:*/ static int goal_in_my_reservation (struct ext4_reserve_window *rsv,ext4_grpblk_t grp_goal, -unsigned int group,struct super_block * sb) +ext4_group_t group,struct super_block *sb) {ext4_fsblk_t group_first_block, group_last_block;
@@ -540,7 +540,7 @@ void ext4_free_blocks_sb(handle_t *handle, struct super_block *sb, {struct buffer_head *bitmap_bh =NULL ;struct buffer_head *gd_bh; -unsigned long block_group; +ext4_group_t block_group;ext4_grpblk_t bit;unsigned long i;unsigned long overflow;
@@ -920,9 +920,10 @@ claim_block(spinlock_t *lock, ext4_grpblk_t block, struct buffer_head *bh)* ext4_journal_release_buffer(), else we'll run out of credits. */ static ext4_grpblk_t -ext4_try_to_allocate (struct super_block *sb,handle_t *handle,int group, -struct buffer_head *bitmap_bh,ext4_grpblk_t grp_goal, -unsigned long *count,struct ext4_reserve_window *my_rsv) +ext4_try_to_allocate (struct super_block *sb,handle_t *handle, +ext4_group_t group,struct buffer_head *bitmap_bh, +ext4_grpblk_t grp_goal,unsigned long *count, +struct ext4_reserve_window *my_rsv) {ext4_fsblk_t group_first_block;ext4_grpblk_t start, end;
@@ -1156,7 +1157,7 @@ static int find_next_reservable_window(*/ static int alloc_new_reservation (struct ext4_reserve_window_node *my_rsv,ext4_grpblk_t grp_goal,struct super_block *sb, -unsigned int group,struct buffer_head *bitmap_bh) +ext4_group_t group,struct buffer_head *bitmap_bh) {struct ext4_reserve_window_node *search_head;ext4_fsblk_t group_first_block, group_end_block, start_block;
@@ -1354,7 +1355,7 @@ static void try_to_extend_reservation(struct ext4_reserve_window_node *my_rsv,*/ static ext4_grpblk_t ext4_try_to_allocate_with_rsv (struct super_block *sb,handle_t *handle, -unsigned int group,struct buffer_head *bitmap_bh, +ext4_group_t group,struct buffer_head *bitmap_bh,ext4_grpblk_t grp_goal,struct ext4_reserve_window_node * my_rsv,unsigned long *count,int *errp)
@@ -1528,12 +1529,12 @@ ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode, {struct buffer_head *bitmap_bh =NULL ;struct buffer_head *gdp_bh; -unsigned long group_no; -int goal_group; +ext4_group_t group_no; +ext4_group_t goal_group;ext4_grpblk_t grp_target_blk;/* blockgroup relative goal block */ ext4_grpblk_t grp_alloc_blk;/* blockgroup-relative allocated block*/ ext4_fsblk_t ret_block;/* filesyetem-wide allocated block */ -int bgi;/* blockgroup iteration index */ +ext4_group_t bgi;/* blockgroup iteration index */ int fatal =0 , err;int performed_allocation =0 ;ext4_grpblk_t free_blocks;/* number of free blocks in a group */
@@ -1544,10 +1545,7 @@ ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode,struct ext4_reserve_window_node *my_rsv =NULL ;struct ext4_block_alloc_info *block_i;unsigned short windowsz =0 ; -#ifdef EXT4FS_DEBUG -static int goal_hits, goal_attempts; -#endif -unsigned long ngroups; +ext4_group_t ngroups;unsigned long num = *count; *errp = -ENOSPC ;
@@ -1743,9 +1741,6 @@ allocated:* list of some description. We don't know in advance whether * the caller wants to use it as metadata or data. */ -ext4_debug ("allocating block %lu. Goal hits %d of %d.\n" , - ret_block, goal_hits, goal_attempts); -spin_lock (sb_bgl_lock (sbi, group_no));if (gdp->bg_flags &cpu_to_le16 (EXT4_BG_BLOCK_UNINIT )) gdp->bg_flags &=cpu_to_le16 (~EXT4_BG_BLOCK_UNINIT );
@@ -1804,8 +1799,8 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb) {ext4_fsblk_t desc_count;struct ext4_group_desc *gdp; -int i; -unsigned long ngroups =EXT4_SB (sb)->s_groups_count; +ext4_group_t i; +ext4_group_t ngroups =EXT4_SB (sb)->s_groups_count;#ifdef EXT4FS_DEBUG struct ext4_super_block *es;ext4_fsblk_t bitmap_count;
@@ -1829,7 +1824,7 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)continue ; x =ext4_count_free (bitmap_bh, sb->s_blocksize); -printk ("group %d: stored = %d, counted = %lu\n" , +printk (KERN_DEBUG "group %lu: stored = %d, counted = %lu\n" , i,le16_to_cpu (gdp->bg_free_blocks_count), x); bitmap_count += x; }
@@ -1853,7 +1848,7 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)#endif } -static inline int test_root (int a,int b) +static inline int test_root (ext4_group_t a,int b) {int num = b;
@@ -1862,7 +1857,7 @@ static inline int test_root(int a, int b)return num == a; } -static int ext4_group_sparse (int group) +static int ext4_group_sparse (ext4_group_t group) {if (group <=1 )return 1 ;
@@ -1880,7 +1875,7 @@ static int ext4_group_sparse(int group)* Return the number of blocks used by the superblock (primary or backup) * in this group. Currently this will be only 0 or 1. */ -int ext4_bg_has_super (struct super_block *sb,int group) +int ext4_bg_has_super (struct super_block *sb,ext4_group_t group) { if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
@@ -1889,18 +1884,20 @@ int ext4_bg_has_super(struct super_block *sb, int group)return 1 ; } -static unsigned long ext4_bg_num_gdb_meta (struct super_block *sb,int group) +static unsigned long ext4_bg_num_gdb_meta (struct super_block *sb, +ext4_group_t group) {unsigned long metagroup = group /EXT4_DESC_PER_BLOCK (sb); -unsigned long first = metagroup *EXT4_DESC_PER_BLOCK (sb); -unsigned long last = first +EXT4_DESC_PER_BLOCK (sb) -1 ; +ext4_group_t first = metagroup *EXT4_DESC_PER_BLOCK (sb); +ext4_group_t last = first +EXT4_DESC_PER_BLOCK (sb) -1 ;if (group == first || group == first +1 || group == last)return 1 ;return 0 ; } -static unsigned long ext4_bg_num_gdb_nometa (struct super_block *sb,int group) +static unsigned long ext4_bg_num_gdb_nometa (struct super_block *sb, +ext4_group_t group) { if (EXT4_HAS_RO_COMPAT_FEATURE(sb, EXT4_FEATURE_RO_COMPAT_SPARSE_SUPER) &&
@@ -1918,7 +1915,7 @@ static unsigned long ext4_bg_num_gdb_nometa(struct super_block *sb, int group)* (primary or backup) in this group. In the future there may be a * different number of descriptor blocks in each group. */ -unsigned long ext4_bg_num_gdb (struct super_block *sb,int group) +unsigned long ext4_bg_num_gdb (struct super_block *sb,ext4_group_t group) {unsigned long first_meta_bg =le32_to_cpu (EXT4_SB (sb)->s_es->s_first_meta_bg);
fs/ext4/group.h +5 -3
@@ -14,14 +14,16 @@ extern __le16 ext4_group_desc_csum(struct ext4_sb_info *sbi, __u32 group,extern int ext4_group_desc_csum_verify (struct ext4_sb_info *sbi,__u32 group,struct ext4_group_desc *gdp);struct buffer_head *read_block_bitmap (struct super_block *sb, -unsigned int block_group); +ext4_group_t block_group);extern unsigned ext4_init_block_bitmap (struct super_block *sb, -struct buffer_head *bh,int group, +struct buffer_head *bh, +ext4_group_t group,struct ext4_group_desc *desc);#define ext4_free_blocks_after_init (sb, group, desc) \ ext4_init_block_bitmap(sb, NULL, group, desc)extern unsigned ext4_init_inode_bitmap (struct super_block *sb, -struct buffer_head *bh,int group, +struct buffer_head *bh, +ext4_group_t group,struct ext4_group_desc *desc);extern void mark_bitmap_end (int start_bit,int end_bit,char *bitmap);#endif /* _LINUX_EXT4_GROUP_H */
fs/ext4/ialloc.c +24 -22
138 lines not on this page · raw message
fs/ext4/inode.c +3 -2
@@ -2464,7 +2464,8 @@ out_stop:static ext4_fsblk_t ext4_get_inode_block (struct super_block *sb,unsigned long ino,struct ext4_iloc *iloc) { -unsigned long desc, group_desc, block_group; +unsigned long desc, group_desc; +ext4_group_t block_group;unsigned long offset;ext4_fsblk_t block;struct buffer_head *bh;
@@ -2551,7 +2552,7 @@ static int __ext4_get_inode_loc(struct inode *inode,struct ext4_group_desc *desc;int inodes_per_buffer;int inode_offset, i; -int block_group; +ext4_group_t block_group;int start; block_group = (inode->i_ino - 1) /
fs/ext4/resize.c +6 -6
@@ -28,7 +28,7 @@ static int verify_group_input(struct super_block *sb,struct ext4_super_block *es = sbi->s_es;ext4_fsblk_t start =ext4_blocks_count (es);ext4_fsblk_t end = start + input->blocks_count; -unsigned group = input->group; +ext4_group_t group = input->group;ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group; unsigned overhead = ext4_bg_has_super(sb, group) ? (1 + ext4_bg_num_gdb(sb, group) +
@@ -357,7 +357,7 @@ static int verify_reserved_gdb(struct super_block *sb, struct buffer_head *primary) {const ext4_fsblk_t blk = primary->b_blocknr; -const unsigned long end =EXT4_SB (sb)->s_groups_count; +const ext4_group_t end =EXT4_SB (sb)->s_groups_count;unsigned three =1 ;unsigned five =5 ;unsigned seven =7 ;
@@ -656,12 +656,12 @@ static void update_backups(struct super_block *sb, int blk_off, char *data, int size) { struct ext4_sb_info *sbi = EXT4_SB(sb); -const unsigned long last = sbi->s_groups_count; +const ext4_group_t last = sbi->s_groups_count;const int bpg =EXT4_BLOCKS_PER_GROUP (sb);unsigned three =1 ;unsigned five =5 ;unsigned seven =7 ; -unsigned group; +ext4_group_t group;int rest = sb->s_blocksize - size;handle_t *handle;int err =0 , err2;
@@ -716,7 +716,7 @@ static void update_backups(struct super_block *sb, exit_err:if (err) {ext4_warning (sb, __FUNCTION__, -"can't update backup for group %d (err %d), " +"can't update backup for group %lu (err %d), " "forcing fsck on next reboot" , group, err); sbi->s_mount_state &= ~EXT4_VALID_FS ; sbi->s_es->s_state &=cpu_to_le16 (~EXT4_VALID_FS );
@@ -952,7 +952,7 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es, ext4_fsblk_t n_blocks_count) {ext4_fsblk_t o_blocks_count; -unsigned long o_groups_count; +ext4_group_t o_groups_count;ext4_grpblk_t last;ext4_grpblk_t add;struct buffer_head * bh;
fs/ext4/super.c +9 -11
@@ -1364,7 +1364,7 @@ static int ext4_check_descriptors (struct super_block * sb)struct ext4_group_desc * gdp =NULL ;int desc_block =0 ;int flexbg_flag =0 ; -int i; +ext4_group_t i;if (EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_FLEX_BG )) flexbg_flag =1 ;
@@ -1386,7 +1386,7 @@ static int ext4_check_descriptors (struct super_block * sb)if (block_bitmap < first_block || block_bitmap > last_block) {ext4_error (sb,"ext4_check_descriptors" , -"Block bitmap for group %d" +"Block bitmap for group %lu" " not in group (block %llu)!" , i, block_bitmap);return 0 ;
@@ -1395,7 +1395,7 @@ static int ext4_check_descriptors (struct super_block * sb)if (inode_bitmap < first_block || inode_bitmap > last_block) {ext4_error (sb,"ext4_check_descriptors" , -"Inode bitmap for group %d" +"Inode bitmap for group %lu" " not in group (block %llu)!" , i, inode_bitmap);return 0 ;
@@ -1405,17 +1405,16 @@ static int ext4_check_descriptors (struct super_block * sb) inode_table + sbi->s_itb_per_group - 1 > last_block) {ext4_error (sb,"ext4_check_descriptors" , -"Inode table for group %d" +"Inode table for group %lu" " not in group (block %llu)!" , i, inode_table);return 0 ; }if (!ext4_group_desc_csum_verify (sbi, i, gdp)) {ext4_error (sb, __FUNCTION__, -"Checksum for group %d failed (%u!=%u)\n" , i, -le16_to_cpu (ext4_group_desc_csum (sbi, i, - gdp)), -le16_to_cpu (gdp->bg_checksum)); +"Checksum for group %lu failed (%u!=%u)\n" , + i,le16_to_cpu (ext4_group_desc_csum (sbi, i, + gdp)),le16_to_cpu (gdp->bg_checksum));return 0 ; }if (!flexbg_flag)
@@ -1429,7 +1428,6 @@ static int ext4_check_descriptors (struct super_block * sb)return 1 ; } -/* ext4_orphan_cleanup() walks a singly-linked list of inodes (starting at * the superblock) which were deleted from all directories, but held open by * a process at the time of a crash. We walk the list and try to delete these
@@ -1570,7 +1568,7 @@ static ext4_fsblk_t descriptor_loc(struct super_block *sb, ext4_fsblk_t logical_sb_block, int nr) {struct ext4_sb_info *sbi =EXT4_SB (sb); -unsigned long bg, first_meta_bg; +ext4_group_t bg, first_meta_bg;int has_super =0 ; first_meta_bg =le32_to_cpu (sbi->s_es->s_first_meta_bg);
@@ -2678,7 +2676,7 @@ static int ext4_statfs (struct dentry * dentry, struct kstatfs * buf)if (test_opt (sb,MINIX_DF )) { sbi->s_overhead_last =0 ; }else if (sbi->s_blocks_last !=ext4_blocks_count (es)) { -unsigned long ngroups = sbi->s_groups_count, i; +ext4_group_t ngroups = sbi->s_groups_count, i;ext4_fsblk_t overhead =0 ;smp_rmb ();
include/linux/ext4_fs.h +6 -5
@@ -830,7 +830,7 @@ struct ext4_iloc {struct buffer_head *bh;unsigned long offset; -unsigned long block_group; +ext4_group_t block_group; };static inline struct ext4_inode *ext4_raw_inode (struct ext4_iloc *iloc)
@@ -855,7 +855,7 @@ struct dir_private_info {/* calculate the first block number of the group */ static inline ext4_fsblk_t -ext4_group_first_block_no (struct super_block *sb,unsigned long group_no) +ext4_group_first_block_no (struct super_block *sb,ext4_group_t group_no) {return group_no * (ext4_fsblk_t )EXT4_BLOCKS_PER_GROUP (sb) +le32_to_cpu (EXT4_SB (sb)->s_es->s_first_data_block);
@@ -886,8 +886,9 @@ extern unsigned int ext4_block_group(struct super_block *sb, ext4_fsblk_t blocknr);extern ext4_grpblk_t ext4_block_group_offset (struct super_block *sb,ext4_fsblk_t blocknr); -extern int ext4_bg_has_super (struct super_block *sb,int group); -extern unsigned long ext4_bg_num_gdb (struct super_block *sb,int group); +extern int ext4_bg_has_super (struct super_block *sb,ext4_group_t group); +extern unsigned long ext4_bg_num_gdb (struct super_block *sb, +ext4_group_t group);extern ext4_fsblk_t ext4_new_block (handle_t *handle,struct inode *inode,ext4_fsblk_t goal,int *errp); extern ext4_fsblk_t ext4_new_blocks (handle_t *handle, struct inode *inode,
@@ -900,7 +901,7 @@ extern void ext4_free_blocks_sb (handle_t *handle, struct super_block *sb,extern ext4_fsblk_t ext4_count_free_blocks (struct super_block *);extern void ext4_check_blocks_bitmap (struct super_block *);extern struct ext4_group_desc *ext4_get_group_desc (struct super_block * sb, -unsigned int block_group, +ext4_group_t block_group,struct buffer_head ** bh);extern int ext4_should_retry_alloc (struct super_block *sb,int *retries);extern void ext4_init_block_alloc_info (struct inode *);
include/linux/ext4_fs_i.h +4 -1
@@ -30,6 +30,9 @@ typedef unsigned long long ext4_fsblk_t;/* data type for file logical block number */ typedef __u32 ext4_lblk_t ; +/* data type for block group number */ +typedef unsigned long ext4_group_t ; +struct ext4_reserve_window {ext4_fsblk_t _rsv_start;/* First byte reserved */ ext4_fsblk_t _rsv_end;/* Last byte reserved or 0 */
@@ -92,7 +95,7 @@ struct ext4_inode_info {* place a file's data blocks near its inode block, and new inodes * near to their parent directory's inode. */ -__u32 i_block_group; +ext4_group_t i_block_group;__u32 i_state;/* Dynamic state flags for ext4 */ /* block reservation info */
include/linux/ext4_fs_sb.h +1 -1
@@ -35,7 +35,7 @@ struct ext4_sb_info {unsigned long s_itb_per_group;/* Number of inode table blocks per group */ unsigned long s_gdb_count;/* Number of group descriptor blocks */ unsigned long s_desc_per_block;/* Number of group descriptors per block */ -unsigned long s_groups_count;/* Number of groups in the fs */ +ext4_group_t s_groups_count;/* Number of groups in the fs */ unsigned long s_overhead_last;/* Last calculated overhead */ unsigned long s_blocks_last;/* Last seen block count */ struct buffer_head * s_sbh;/* Buffer containing the super block */
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 22/49 ext4: Change the default behaviour on error
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
ext4 file system was by default ignoring errors and continuing. This is not a good default as continuing on error could lead to file system corruption. Change the default to mark the file system readonly. Debian and ubuntu already does this as the default in their fstab.
--- fs/ext4/super.c | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-)
fs/ext4/super.c +8 -8
@@ -688,16 +688,16 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs) le16_to_cpu(es->s_def_resgid) != EXT4_DEF_RESGID) {seq_printf (seq,",resgid=%u" , sbi->s_resgid); } -if (test_opt (sb,ERRORS_CONT )) { +if (test_opt (sb,ERRORS_RO )) {int def_errors =le16_to_cpu (es->s_errors);if (def_errors ==EXT4_ERRORS_PANIC || - def_errors ==EXT4_ERRORS_RO ) { -seq_puts (seq,",errors=continue" ); + def_errors ==EXT4_ERRORS_CONTINUE ) { +seq_puts (seq,",errors=remount-ro" ); } } -if (test_opt (sb,ERRORS_RO )) -seq_puts (seq,",errors=remount-ro" ); +if (test_opt (sb,ERRORS_CONT )) +seq_puts (seq,",errors=continue" );if (test_opt (sb,ERRORS_PANIC ))seq_puts (seq,",errors=panic" );if (test_opt (sb,NO_UID32 ))
@@ -1819,10 +1819,10 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)if (le16_to_cpu (sbi->s_es->s_errors) ==EXT4_ERRORS_PANIC )set_opt (sbi->s_mount_opt,ERRORS_PANIC ); -else if (le16_to_cpu (sbi->s_es->s_errors) ==EXT4_ERRORS_RO ) -set_opt (sbi->s_mount_opt,ERRORS_RO ); -else +else if (le16_to_cpu (sbi->s_es->s_errors) ==EXT4_ERRORS_CONTINUE )set_opt (sbi->s_mount_opt,ERRORS_CONT ); +else +set_opt (sbi->s_mount_opt,ERRORS_RO ); sbi->s_resuid =le16_to_cpu (es->s_def_resuid); sbi->s_resgid =le16_to_cpu (es->s_def_resgid);
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 43/49 ext4: Check for return value from sb_set_blocksize
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
sb_set_blocksize validates whether the specfied block size can be used by the file system. Make sure we fail mounting the file system if the blocksize specfied cannot be used.
--- fs/ext4/super.c | 15 +++++---------- 1 files changed, 5 insertions(+), 10 deletions(-)
fs/ext4/super.c +5 -10
@@ -1809,7 +1809,6 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent)unsigned long def_mount_opts;struct inode *root;int blocksize; -int hblock;int db_count;int i;int needs_recovery;
@@ -1966,20 +1965,16 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) goto failed_mount; } - hblock =bdev_hardsect_size (sb->s_bdev);if (sb->s_blocksize != blocksize) { -/* -* Make sure the blocksize for the filesystem is larger -* than the hardware sectorsize for the machine. -*/ -if (blocksize < hblock) { -printk (KERN_ERR "EXT4-fs: blocksize %d too small for " -"device blocksize %d.\n" , blocksize, hblock); + +/* Validate the filesystem blocksize */ +if (!sb_set_blocksize (sb, blocksize)) { +printk (KERN_ERR "EXT4-fs: bad block size %d.\n" , + blocksize); goto failed_mount; }brelse (bh); -sb_set_blocksize (sb, blocksize); logical_sb_block = sb_block *EXT4_MIN_BLOCK_SIZE ; offset =do_div (logical_sb_block, blocksize); bh =sb_bread (sb, logical_sb_block);
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 2/49 ext4: Avoid rec_len overflow with 64KB block size
In reply to Theodore Ts'oFrom: Jan Kara <[email protected]>
With 64KB blocksize, a directory entry can have size 64KB which does not fit into 16 bits we have for entry lenght. So we store 0xffff instead and convert value when read from / written to disk. The patch also converts some places to use ext4_next_entry() when we are changing them anyway.
--- fs/ext4/dir.c | 12 ++++---- fs/ext4/namei.c | 77 ++++++++++++++++++++++------------------------ include/linux/ext4_fs.h | 20 ++++++++++++ 3 files changed, 63 insertions(+), 46 deletions(-)
fs/ext4/dir.c +6 -6
@@ -67,7 +67,7 @@ int ext4_check_dir_entry (const char * function, struct inode * dir, unsigned long offset) {const char * error_msg =NULL ; -const int rlen =le16_to_cpu (de->rec_len); +const int rlen =ext4_rec_len_from_disk (de->rec_len);if (rlen <EXT4_DIR_REC_LEN (1 )) error_msg ="rec_len is smaller than minimal" ;
@@ -172,10 +172,10 @@ revalidate:* least that it is non-zero. A * failure will be detected in the * dirent test below. */ -if (le16_to_cpu (de->rec_len) < -EXT4_DIR_REC_LEN (1 )) +if (ext4_rec_len_from_disk (de->rec_len) + <EXT4_DIR_REC_LEN (1 ))break ; - i +=le16_to_cpu (de->rec_len); + i +=ext4_rec_len_from_disk (de->rec_len); } offset = i; filp->f_pos = (filp->f_pos & ~(sb->s_blocksize -1 ))
@@ -197,7 +197,7 @@ revalidate: ret = stored; goto out; } - offset +=le16_to_cpu (de->rec_len); + offset +=ext4_rec_len_from_disk (de->rec_len);if (le32_to_cpu (de->inode)) {/* We might block in the next section * if the data destination is
@@ -219,7 +219,7 @@ revalidate: goto revalidate; stored ++; } - filp->f_pos +=le16_to_cpu (de->rec_len); + filp->f_pos +=ext4_rec_len_from_disk (de->rec_len); } offset =0 ;brelse (bh);
fs/ext4/namei.c +37 -40
208 lines not on this page · raw message
include/linux/ext4_fs.h +20 -0
@@ -767,6 +767,26 @@ struct ext4_dir_entry_2 {#define EXT4_DIR_ROUND (EXT4_DIR_PAD - 1)#define EXT4_DIR_REC_LEN (name_len) (((name_len) + 8 + EXT4_DIR_ROUND) & \ ~EXT4_DIR_ROUND) +#define EXT4_MAX_REC_LEN ((1<<16)-1) + +static inline unsigned ext4_rec_len_from_disk (__le16 dlen) +{ +unsigned len =le16_to_cpu (dlen); + +if (len ==EXT4_MAX_REC_LEN ) +return 1 <<16 ; +return len; +} + +static inline __le16 ext4_rec_len_to_disk (unsigned len) +{ +if (len == (1 <<16 )) +return cpu_to_le16 (EXT4_MAX_REC_LEN ); +else if (len > (1 <<16 )) +BUG (); +return cpu_to_le16 (len); +} +/* * Hash Tree Directory indexing * (c) Daniel Phillips, 2001
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 18/49 ext4: sync up block group descriptor with e2fsprogs.
In reply to Theodore Ts'oFrom: Coly Li <[email protected]>
This patch extends bg_itable_unused of ext4 group descriptor from 16bit into 32bit. In order to add bg_itable_unused_hi into struct ext4_group_desc, some extra fields which are already introduced into e2fsprogs are also added in for consistency.
--- include/linux/ext4_fs.h | 5 +++++ 1 files changed, 5 insertions(+), 0 deletions(-)
include/linux/ext4_fs.h +5 -0
@@ -118,6 +118,11 @@ struct ext4_group_desc__le32 bg_block_bitmap_hi;/* Blocks bitmap block MSB */ __le32 bg_inode_bitmap_hi;/* Inodes bitmap block MSB */ __le32 bg_inode_table_hi;/* Inodes table block MSB */ +__le16 bg_free_blocks_count_hi;/* Free blocks count MSB */ +__le16 bg_free_inodes_count_hi;/* Free inodes count MSB */ +__le16 bg_used_dirs_count_hi;/* Directories count MSB */ +__le16 bg_itable_unused_hi;/* Unused inodes count MSB */ +__u32 bg_reserved2[3 ]; };#define EXT4_BG_INODE_UNINIT 0x0001/* Inode table/bitmap not in use */
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 33/49 ext4: Add the journal checksum feature
In reply to Theodore Ts'oFrom: Girish Shilamkar <[email protected]>
The journal checksum feature adds two new flags i.e JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT and JBD2_FEATURE_COMPAT_CHECKSUM.
JBD2_FEATURE_CHECKSUM flag indicates that the commit block contains the checksum for the blocks described by the descriptor blocks. Due to checksums, writing of the commit record no longer needs to be synchronous. Now commit record can be sent to disk without waiting for descriptor blocks to be written to disk. This behavior is controlled using JBD2_FEATURE_ASYNC_COMMIT flag. Older kernels/e2fsck should not be able to recover the journal with _ASYNC_COMMIT hence it is made incompat.
The commit header has been extended to hold the checksum along with the type of the checksum.
For recovery in pass scan checksums are verified to ensure the sanity and completeness(in case of _ASYNC_COMMIT) of every transaction.
--- Documentation/filesystems/ext4.txt | 10 ++ fs/Kconfig | 1 + fs/ext4/super.c | 25 +++++ fs/jbd2/commit.c | 196 +++++++++++++++++++++++++++--------- fs/jbd2/journal.c | 28 +++++ fs/jbd2/recovery.c | 149 ++++++++++++++++++++++++++-- include/linux/ext4_fs.h | 3 +- include/linux/jbd2.h | 36 ++++++- 8 files changed, 388 insertions(+), 60 deletions(-)
Documentation/filesystems/ext4.txt +10 -0
@@ -89,6 +89,16 @@ When mounting an ext4 filesystem, the following option are accepted: extents ext4 will use extents to address file data. The file system will no longer be mountable by ext3. +journal_checksum Enable checksumming of the journal transactions. + This will allow the recovery code in e2fsck and the + kernel to detect corruption in the kernel. It is a + compatible change and will be ignored by older kernels. + +journal_async_commit Commit block can be written to disk without waiting + for descriptor blocks. If enabled older kernels cannot + mount the device. This will enable 'journal_checksum' + internally. + journal=update Update the ext4 file system's journal to the current format.
fs/Kconfig +1 -0
@@ -236,6 +236,7 @@ config JBD_DEBUG config JBD2 tristate + select CRC32 help This is a generic journaling layer for block devices that support both 32-bit and 64-bit block numbers. It is currently used by
fs/ext4/super.c +25 -0
@@ -869,6 +869,7 @@ enum { Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl, Opt_reservation, Opt_noreservation, Opt_noload, Opt_nobh, Opt_bh, Opt_commit, Opt_journal_update, Opt_journal_inum, Opt_journal_dev, + Opt_journal_checksum, Opt_journal_async_commit, Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback, Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
@@ -908,6 +909,8 @@ static match_table_t tokens = { {Opt_journal_update, "journal=update"}, {Opt_journal_inum, "journal=%u"}, {Opt_journal_dev, "journal_dev=%u"}, + {Opt_journal_checksum, "journal_checksum"}, + {Opt_journal_async_commit, "journal_async_commit"}, {Opt_abort, "abort"}, {Opt_data_journal, "data=journal"}, {Opt_data_ordered, "data=ordered"},
@@ -1095,6 +1098,13 @@ static int parse_options (char *options, struct super_block *sb,return 0 ; *journal_devnum = option;break ; +case Opt_journal_checksum: +set_opt (sbi->s_mount_opt,JOURNAL_CHECKSUM ); +break ; +case Opt_journal_async_commit: +set_opt (sbi->s_mount_opt,JOURNAL_ASYNC_COMMIT ); +set_opt (sbi->s_mount_opt,JOURNAL_CHECKSUM ); +break ;case Opt_noload:set_opt (sbi->s_mount_opt,NOLOAD );break ;
@@ -2114,6 +2124,21 @@ static int ext4_fill_super (struct super_block *sb, void *data, int silent) goto failed_mount4; } +if (test_opt (sb,JOURNAL_ASYNC_COMMIT )) { +jbd2_journal_set_features (sbi->s_journal, +JBD2_FEATURE_COMPAT_CHECKSUM ,0 , +JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT ); + }else if (test_opt (sb,JOURNAL_CHECKSUM )) { +jbd2_journal_set_features (sbi->s_journal, +JBD2_FEATURE_COMPAT_CHECKSUM ,0 ,0 ); +jbd2_journal_clear_features (sbi->s_journal,0 ,0 , +JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT ); + }else { +jbd2_journal_clear_features (sbi->s_journal, +JBD2_FEATURE_COMPAT_CHECKSUM ,0 , +JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT ); + } +/* We have now updated the journal if required, so we can * validate the data journaling mode. */ switch (test_opt (sb,DATA_FLAGS )) {
fs/jbd2/commit.c +148 -48
278 lines not on this page · raw message
fs/jbd2/journal.c +28 -0
@@ -1578,6 +1578,34 @@ int jbd2_journal_set_features (journal_t *journal, unsigned long compat,return 1 ; } +/* +* jbd2_journal_clear_features () - Clear a given journal feature in the +* superblock +* @journal: Journal to act on. +* @compat: bitmask of compatible features +* @ro: bitmask of features that force read-only mount +* @incompat: bitmask of incompatible features +* +* Clear a given journal feature as present on the +* superblock. Returns true if the requested features could be reset. +*/ +int jbd2_journal_clear_features (journal_t *journal,unsigned long compat, +unsigned long ro,unsigned long incompat) +{ +journal_superblock_t *sb; + +jbd_debug (1 ,"Clear features 0x%lx/0x%lx/0x%lx\n" , + compat, ro, incompat); + + sb = journal->j_superblock; + + sb->s_feature_compat &= ~cpu_to_be32 (compat); + sb->s_feature_ro_compat &= ~cpu_to_be32 (ro); + sb->s_feature_incompat &= ~cpu_to_be32 (incompat); + +return 1 ; +} +EXPORT_SYMBOL (jbd2_journal_clear_features);/** * int jbd2_journal_update_format () - Update on-disk journal structure.
fs/jbd2/recovery.c +142 -7
187 lines not on this page · raw message
include/linux/ext4_fs.h +2 -1
@@ -467,7 +467,8 @@ do { \#define EXT4_MOUNT_USRQUOTA 0x100000/* "old" user quota */ #define EXT4_MOUNT_GRPQUOTA 0x200000/* "old" group quota */ #define EXT4_MOUNT_EXTENTS 0x400000/* Extents support */ - +#define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000/* Journal checksums */ +#define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000/* Journal Async Commit */ /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */ #ifndef _LINUX_EXT2_FS_H#define clear_opt (o, opt) o &= ~EXT4_MOUNT_##opt
include/linux/jbd2.h +32 -4
@@ -149,6 +149,28 @@ typedef struct journal_header_s__be32 h_sequence; } journal_header_t; +/* +* Checksum types. +*/ +#define JBD2_CRC32_CHKSUM 1 +#define JBD2_MD5_CHKSUM 2 +#define JBD2_SHA1_CHKSUM 3 + +#define JBD2_CRC32_CHKSUM_SIZE 4 + +#define JBD2_CHECKSUM_BYTES (32 / sizeof(u32)) +/* +* Commit block header for storing transactional checksums: +*/ +struct commit_header { +__be32 h_magic; +__be32 h_blocktype; +__be32 h_sequence; +unsigned char h_chksum_type; +unsigned char h_chksum_size; +unsigned char h_padding[2 ]; +__be32 h_chksum[JBD2_CHECKSUM_BYTES ]; +};/* * The block tag: used to describe a single buffer in the journal.
@@ -242,14 +264,18 @@ typedef struct journal_superblock_s ((j)->j_format_version >=2 && \ ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask)))) -#define JBD2_FEATURE_INCOMPAT_REVOKE 0x00000001 -#define JBD2_FEATURE_INCOMPAT_64BIT 0x00000002 +#define JBD2_FEATURE_COMPAT_CHECKSUM 0x00000001 + +#define JBD2_FEATURE_INCOMPAT_REVOKE 0x00000001 +#define JBD2_FEATURE_INCOMPAT_64BIT 0x00000002 +#define JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004/* Features known to this kernel version: */ -#define JBD2_KNOWN_COMPAT_FEATURES 0 +#define JBD2_KNOWN_COMPAT_FEATURES JBD2_FEATURE_COMPAT_CHECKSUM#define JBD2_KNOWN_ROCOMPAT_FEATURES 0#define JBD2_KNOWN_INCOMPAT_FEATURES (JBD2_FEATURE_INCOMPAT_REVOKE | \ - JBD2_FEATURE_INCOMPAT_64BIT) + JBD2_FEATURE_INCOMPAT_64BIT | \ + JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)#ifdef __KERNEL__
@@ -997,6 +1023,8 @@ extern int jbd2_journal_check_available_features (journal_t *, unsigned long, unsigned long, unsigned long);extern int jbd2_journal_set_features (journal_t *,unsigned long ,unsigned long ,unsigned long ); +extern int jbd2_journal_clear_features + (journal_t *,unsigned long ,unsigned long ,unsigned long );extern int jbd2_journal_create (journal_t *);extern int jbd2_journal_load (journal_t *journal);extern void jbd2_journal_destroy (journal_t *);
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 38/49 ext4: fix up EXT4FS_DEBUG builds
In reply to Theodore Ts'oFrom: Eric Sandeen <[email protected]>
Builds with EXT4FS_DEBUG defined (to enable ext4_debug()) fail without these changes. Clean up some format warnings too.
--- fs/ext4/balloc.c | 6 +++--- fs/ext4/ialloc.c | 2 +- fs/ext4/resize.c | 16 ++++++++-------- 3 files changed, 12 insertions(+), 12 deletions(-)
fs/ext4/balloc.c +3 -3
@@ -1630,7 +1630,7 @@ ext4_fsblk_t ext4_new_blocks(handle_t *handle, struct inode *inode, sbi =EXT4_SB (sb); es =EXT4_SB (sb)->s_es; -ext4_debug ("goal=%lu.\n" , goal); +ext4_debug ("goal=%llu.\n" , goal);/* * Allocate a block from reservation only when * filesystem is mounted with reservation(default,-o reservation), and
@@ -1740,7 +1740,7 @@ retry_alloc: allocated: -ext4_debug ("using block group %d(%d)\n" , +ext4_debug ("using block group %lu(%d)\n" , group_no, gdp->bg_free_blocks_count);BUFFER_TRACE (gdp_bh,"get_write_access" );
@@ -1898,7 +1898,7 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)brelse (bitmap_bh);printk ("ext4_count_free_blocks: stored = %llu" ", computed = %llu, %llu\n" , -EXT4_FREE_BLOCKS_COUNT (es), +ext4_free_blocks_count (es), desc_count, bitmap_count);return bitmap_count;#else
fs/ext4/ialloc.c +1 -1
@@ -857,7 +857,7 @@ unsigned long ext4_count_free_inodes (struct super_block * sb)continue ; x =ext4_count_free (bitmap_bh,EXT4_INODES_PER_GROUP (sb) /8 ); -printk ("group %d: stored = %d, counted = %lu\n" , +printk (KERN_DEBUG "group %lu: stored = %d, counted = %lu\n" , i,le16_to_cpu (gdp->bg_free_inodes_count), x); bitmap_count += x; }
fs/ext4/resize.c +8 -8
@@ -206,7 +206,7 @@ static int setup_new_group_blocks(struct super_block *sb, }if (ext4_bg_has_super (sb, input->group)) { -ext4_debug ("mark backup superblock %#04lx (+0)\n" , start); +ext4_debug ("mark backup superblock %#04llx (+0)\n" , start);ext4_set_bit (0 , bh->b_data); }
@@ -215,7 +215,7 @@ static int setup_new_group_blocks(struct super_block *sb, i < gdblocks; i++, block++, bit++) {struct buffer_head *gdb; -ext4_debug ("update backup group %#04lx (+%d)\n" , block, bit); +ext4_debug ("update backup group %#04llx (+%d)\n" , block, bit);if ((err =extend_or_restart_transaction (handle,1 , bh))) goto exit_bh;
@@ -243,7 +243,7 @@ static int setup_new_group_blocks(struct super_block *sb, i < reserved_gdb; i++, block++, bit++) {struct buffer_head *gdb; -ext4_debug ("clear reserved block %#04lx (+%d)\n" , block, bit); +ext4_debug ("clear reserved block %#04llx (+%d)\n" , block, bit);if ((err =extend_or_restart_transaction (handle,1 , bh))) goto exit_bh;
@@ -256,10 +256,10 @@ static int setup_new_group_blocks(struct super_block *sb,ext4_set_bit (bit, bh->b_data);brelse (gdb); } -ext4_debug ("mark block bitmap %#04x (+%ld)\n" , input->block_bitmap, +ext4_debug ("mark block bitmap %#04llx (+%llu)\n" , input->block_bitmap, input->block_bitmap - start);ext4_set_bit (input->block_bitmap - start, bh->b_data); -ext4_debug ("mark inode bitmap %#04x (+%ld)\n" , input->inode_bitmap, +ext4_debug ("mark inode bitmap %#04llx (+%llu)\n" , input->inode_bitmap, input->inode_bitmap - start);ext4_set_bit (input->inode_bitmap - start, bh->b_data);
@@ -268,7 +268,7 @@ static int setup_new_group_blocks(struct super_block *sb, i < sbi->s_itb_per_group; i++, bit++, block++) {struct buffer_head *it; -ext4_debug ("clear inode block %#04lx (+%d)\n" , block, bit); +ext4_debug ("clear inode block %#04llx (+%d)\n" , block, bit);if ((err =extend_or_restart_transaction (handle,1 , bh))) goto exit_bh;
@@ -291,7 +291,7 @@ static int setup_new_group_blocks(struct super_block *sb,brelse (bh);/* Mark unused entries in inode bitmap used */ -ext4_debug ("clear inode bitmap %#04x (+%ld)\n" , +ext4_debug ("clear inode bitmap %#04llx (+%llu)\n" , input->inode_bitmap, input->inode_bitmap - start);if (IS_ERR (bh =bclean (handle, sb, input->inode_bitmap))) { err =PTR_ERR (bh);
@@ -1054,7 +1054,7 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,ext4_journal_dirty_metadata (handle,EXT4_SB (sb)->s_sbh); sb->s_dirt =1 ;unlock_super (sb); -ext4_debug ("freeing blocks %lu through %llu\n" , o_blocks_count, +ext4_debug ("freeing blocks %llu through %llu\n" , o_blocks_count, o_blocks_count + add);ext4_free_blocks_sb (handle, sb, o_blocks_count, add, &freed_blocks); ext4_debug("freed blocks %llu through %llu\n", o_blocks_count,
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 34/49 vfs: Add 64 bit i_version support
In reply to Theodore Ts'oFrom: Jean Noel Cordenner <[email protected]>
The i_version field of the inode is changed to be a 64-bit counter that is set on every inode creation and that is incremented every time the inode data is modified (similarly to the "ctime" time-stamp). The aim is to fulfill a NFSv4 requirement for rfc3530.
This first part concerns the vfs, it converts the 32-bit i_version in the generic inode to a 64-bit, a flag is added in the super block in order to check if the feature is enabled and the i_version is incremented in the vfs.
--- fs/afs/dir.c | 9 +++++---- fs/afs/inode.c | 3 ++- fs/inode.c | 22 ++++++++++++++++++++++ include/linux/fs.h | 5 ++++- 4 files changed, 33 insertions(+), 6 deletions(-)
fs/afs/dir.c +5 -4
@@ -546,11 +546,11 @@ static struct dentry *afs_lookup(struct inode *dir, struct dentry *dentry, dentry->d_op = &afs_fs_dentry_operations;d_add (dentry, inode); -_leave (" = 0 { vn=%u u=%u } -> { ino=%lu v=%lu }" , +_leave (" = 0 { vn=%u u=%u } -> { ino=%lu v=%llu }" , fid.vnode, fid.unique, dentry->d_inode->i_ino, - dentry->d_inode->i_version); + (unsigned long long )dentry->d_inode->i_version);return NULL ; }
@@ -630,9 +630,10 @@ static int afs_d_revalidate(struct dentry *dentry, struct nameidata *nd)* been deleted and replaced, and the original vnode ID has * been reused */ if (fid.unique != vnode->fid.unique) { -_debug ("%s: file deleted (uq %u -> %u I:%lu)" , +_debug ("%s: file deleted (uq %u -> %u I:%llu)" , dentry->d_name.name, fid.unique, - vnode->fid.unique, dentry->d_inode->i_version); + vnode->fid.unique, + (unsigned long long )dentry->d_inode->i_version);spin_lock (&vnode->lock);set_bit (AFS_VNODE_DELETED , &vnode->flags);spin_unlock (&vnode->lock);
fs/afs/inode.c +2 -1
@@ -301,7 +301,8 @@ int afs_getattr(struct vfsmount *mnt, struct dentry *dentry, inode = dentry->d_inode; -_enter ("{ ino=%lu v=%lu }" , inode->i_ino, inode->i_version); +_enter ("{ ino=%lu v=%llu }" , inode->i_ino, + (unsigned long long )inode->i_version);generic_fillattr (inode, stat);return 0 ;
fs/inode.c +22 -0
@@ -1243,6 +1243,23 @@ void touch_atime(struct vfsmount *mnt, struct dentry *dentry)EXPORT_SYMBOL (touch_atime);/** +* inode_inc_iversion - increments i_version +* @inode: inode that need to be updated +* +* Every time the inode is modified, the i_version field +* will be incremented. +* The filesystem has to be mounted with i_version flag +* +*/ + +void inode_inc_iversion (struct inode *inode) +{ +spin_lock (&inode->i_lock); + inode->i_version++; +spin_unlock (&inode->i_lock); +} + +/** * file_update_time - update mtime and ctime time * @file: file accessed *
@@ -1276,6 +1293,11 @@ void file_update_time(struct file *file) sync_it =1 ; } +if (IS_I_VERSION (inode)) { +inode_inc_iversion (inode); + sync_it =1 ; + } +if (sync_it)mark_inode_dirty_sync (inode); }
include/linux/fs.h +4 -1
@@ -124,6 +124,7 @@ extern int dir_notify_enable;#define MS_SHARED (1<<20)/* change to shared */ #define MS_RELATIME (1<<21)/* Update atime relative to mtime/ctime. */ #define MS_KERNMOUNT (1<<22)/* this is a kern_mount call */ +#define MS_I_VERSION (1<<23)/* Update inode I_version field */ #define MS_ACTIVE (1<<30)#define MS_NOUSER (1<<31)
@@ -173,6 +174,7 @@ extern int dir_notify_enable; ((inode)->i_flags & (S_SYNC|S_DIRSYNC)))#define IS_MANDLOCK (inode) __IS_FLG(inode, MS_MANDLOCK)#define IS_NOATIME (inode) __IS_FLG(inode, MS_RDONLY|MS_NOATIME) +#define IS_I_VERSION (inode) __IS_FLG(inode, MS_I_VERSION)#define IS_NOQUOTA (inode) ((inode)->i_flags & S_NOQUOTA)#define IS_APPEND (inode) ((inode)->i_flags & S_APPEND)
@@ -599,7 +601,7 @@ struct inode {uid_t i_uid;gid_t i_gid;dev_t i_rdev; -unsigned long i_version; +u64 i_version;loff_t i_size;#ifdef __NEED_I_SIZE_ORDEREDseqcount_t i_size_seqcount;
@@ -1394,6 +1396,7 @@ static inline void inode_dec_link_count(struct inode *inode)mark_inode_dirty (inode); } +extern void inode_inc_iversion (struct inode *inode);extern void touch_atime (struct vfsmount *mnt,struct dentry *dentry);static inline void file_accessed (struct file *file) {
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 3/49 ext4: Introduce ext4_lblk_t
In reply to Theodore Ts'oFrom: Aneesh Kumar K.V <[email protected]>
This patch adds a new data type ext4_lblk_t to represent the logical file blocks.
This is the preparatory patch to support large files in ext4 The follow up patch with convert the ext4_inode i_blocks to represent the number of blocks in file system block size. This changes makes it possible to have a block number 2**32 -1 which will result in overflow if the block number is represented by signed long. This patch convert all the block number to type ext4_lblk_t which is typedef to __u32
Also remove dead code ext4_ext_walk_space
--- fs/ext4/dir.c | 2 +- fs/ext4/extents.c | 218 ++++++++++++--------------------------- fs/ext4/inode.c | 34 ++++--- fs/ext4/namei.c | 54 ++++++----- fs/ext4/super.c | 4 +- include/linux/ext4_fs.h | 29 ++++-- include/linux/ext4_fs_extents.h | 19 +--- include/linux/ext4_fs_i.h | 9 +- 8 files changed, 143 insertions(+), 226 deletions(-)
fs/ext4/dir.c +1 -1
@@ -124,7 +124,7 @@ static int ext4_readdir(struct file * filp, offset = filp->f_pos & (sb->s_blocksize -1 );while (!error && !stored && filp->f_pos < inode->i_size) { -unsigned long blk = filp->f_pos >>EXT4_BLOCK_SIZE_BITS (sb); +ext4_lblk_t blk = filp->f_pos >>EXT4_BLOCK_SIZE_BITS (sb);struct buffer_head map_bh;struct buffer_head *bh =NULL ;
fs/ext4/extents.c +64 -154
432 lines not on this page · raw message
fs/ext4/inode.c +19 -15
@@ -105,7 +105,7 @@ int ext4_forget(handle_t *handle, int is_metadata, struct inode *inode,*/ static unsigned long blocks_for_truncate (struct inode *inode) { -unsigned long needed; +ext4_lblk_t needed; needed = inode->i_blocks >> (inode->i_sb->s_blocksize_bits -9 );
@@ -282,7 +282,8 @@ static int verify_chain(Indirect *from, Indirect *to)*/ static int ext4_block_to_path (struct inode *inode, -long i_block,int offsets[4 ],int *boundary) +ext4_lblk_t i_block, +ext4_lblk_t offsets[4 ],int *boundary) {int ptrs =EXT4_ADDR_PER_BLOCK (inode->i_sb);int ptrs_bits =EXT4_ADDR_PER_BLOCK_BITS (inode->i_sb);
@@ -349,7 +350,8 @@ static int ext4_block_to_path(struct inode *inode,* or when it reads all @depth-1 indirect blocks successfully and finds * the whole chain, all way to the data (returns %NULL, *err == 0). */ -static Indirect *ext4_get_branch (struct inode *inode,int depth,int *offsets, +static Indirect *ext4_get_branch (struct inode *inode,int depth, +ext4_lblk_t *offsets,Indirect chain[4 ],int *err) {struct super_block *sb = inode->i_sb;
@@ -445,7 +447,7 @@ static ext4_fsblk_t ext4_find_near(struct inode *inode, Indirect *ind)* stores it in *@goal and returns zero. */ -static ext4_fsblk_t ext4_find_goal (struct inode *inode,long block, +static ext4_fsblk_t ext4_find_goal (struct inode *inode,ext4_lblk_t block,Indirect chain[4 ],Indirect *partial) {struct ext4_block_alloc_info *block_i;
@@ -590,7 +592,7 @@ failed_out:*/ static int ext4_alloc_branch (handle_t *handle,struct inode *inode,int indirect_blks,int *blks,ext4_fsblk_t goal, -int *offsets,Indirect *branch) +ext4_lblk_t *offsets,Indirect *branch) {int blocksize = inode->i_sb->s_blocksize;int i, n =0 ;
@@ -680,7 +682,7 @@ failed:* chain to new block and return 0. */ static int ext4_splice_branch (handle_t *handle,struct inode *inode, -long block,Indirect *where,int num,int blks) +ext4_lblk_t block,Indirect *where,int num,int blks) {int i;int err =0 ;
@@ -784,12 +786,12 @@ err_out:* return < 0, error case. */ int ext4_get_blocks_handle (handle_t *handle,struct inode *inode, -sector_t iblock,unsigned long maxblocks, +ext4_lblk_t iblock,unsigned long maxblocks,struct buffer_head *bh_result,int create,int extend_disksize) {int err = -EIO ; -int offsets[4 ]; +ext4_lblk_t offsets[4 ];Indirect chain[4 ];Indirect *partial;ext4_fsblk_t goal;
@@ -803,7 +805,8 @@ int ext4_get_blocks_handle(handle_t *handle, struct inode *inode,J_ASSERT (!(EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ));J_ASSERT (handle !=NULL || create ==0 ); - depth =ext4_block_to_path (inode,iblock,offsets,&blocks_to_boundary); + depth =ext4_block_to_path (inode, iblock, offsets, + &blocks_to_boundary);if (depth ==0 ) goto out;
@@ -996,7 +999,7 @@ get_block:* `handle' can be NULL if create is zero */ struct buffer_head *ext4_getblk (handle_t *handle,struct inode *inode, -long block,int create,int *errp) +ext4_lblk_t block,int create,int *errp) {struct buffer_head dummy;int fatal =0 , err;
@@ -1063,7 +1066,7 @@ err: }struct buffer_head *ext4_bread (handle_t *handle,struct inode *inode, -int block,int create,int *err) +ext4_lblk_t block,int create,int *err) {struct buffer_head * bh;
@@ -1828,7 +1831,8 @@ int ext4_block_truncate_page(handle_t *handle, struct page *page, {ext4_fsblk_t index = from >>PAGE_CACHE_SHIFT ;unsigned offset = from & (PAGE_CACHE_SIZE -1 ); -unsigned blocksize, iblock, length, pos; +unsigned blocksize, length, pos; +ext4_lblk_t iblock;struct inode *inode = mapping->host;struct buffer_head *bh;int err =0 ;
@@ -1964,7 +1968,7 @@ static inline int all_zeroes(__le32 *p, __le32 *q)* (no partially truncated stuff there). */ static Indirect *ext4_find_shared (struct inode *inode,int depth, -int offsets[4 ],Indirect chain[4 ],__le32 *top) +ext4_lblk_t offsets[4 ],Indirect chain[4 ],__le32 *top) {Indirect *partial, *p;int k, err;
@@ -2289,12 +2293,12 @@ void ext4_truncate(struct inode *inode)__le32 *i_data = ei->i_data;int addr_per_block =EXT4_ADDR_PER_BLOCK (inode->i_sb);struct address_space *mapping = inode->i_mapping; -int offsets[4 ]; +ext4_lblk_t offsets[4 ];Indirect chain[4 ];Indirect *partial;__le32 nr =0 ;int n; -long last_block; +ext4_lblk_t last_block;unsigned blocksize = inode->i_sb->s_blocksize;struct page *page;
fs/ext4/namei.c +30 -24
172 lines not on this page · raw message
fs/ext4/super.c +2 -2
@@ -2914,7 +2914,7 @@ static ssize_t ext4_quota_read(struct super_block *sb, int type, char *data, size_t len, loff_t off) {struct inode *inode =sb_dqopt (sb)->files[type]; -sector_t blk = off >>EXT4_BLOCK_SIZE_BITS (sb); +ext4_lblk_t blk = off >>EXT4_BLOCK_SIZE_BITS (sb);int err =0 ;int offset = off & (sb->s_blocksize -1 );int tocopy;
@@ -2952,7 +2952,7 @@ static ssize_t ext4_quota_write(struct super_block *sb, int type, const char *data, size_t len, loff_t off) { struct inode *inode = sb_dqopt(sb)->files[type]; -sector_t blk = off >>EXT4_BLOCK_SIZE_BITS (sb); +ext4_lblk_t blk = off >>EXT4_BLOCK_SIZE_BITS (sb);int err =0 ;int offset = off & (sb->s_blocksize -1 );int tocopy;
include/linux/ext4_fs.h +19 -10
@@ -935,11 +935,14 @@ extern unsigned long ext4_count_free (struct buffer_head *, unsigned);/* inode.c */ int ext4_forget (handle_t *handle,int is_metadata,struct inode *inode,struct buffer_head *bh,ext4_fsblk_t blocknr); -struct buffer_head *ext4_getblk (handle_t *,struct inode *,long ,int ,int *); -struct buffer_head *ext4_bread (handle_t *,struct inode *,int ,int ,int *); +struct buffer_head *ext4_getblk (handle_t *,struct inode *, +ext4_lblk_t ,int ,int *); +struct buffer_head *ext4_bread (handle_t *,struct inode *, +ext4_lblk_t ,int ,int *);int ext4_get_blocks_handle (handle_t *handle,struct inode *inode, -sector_t iblock,unsigned long maxblocks,struct buffer_head *bh_result, -int create,int extend_disksize); +ext4_lblk_t iblock,unsigned long maxblocks, +struct buffer_head *bh_result, +int create,int extend_disksize);extern void ext4_read_inode (struct inode *);extern int ext4_write_inode (struct inode *,int );
@@ -1068,7 +1071,7 @@ extern const struct inode_operations ext4_fast_symlink_inode_operations;extern int ext4_ext_tree_init (handle_t *handle,struct inode *);extern int ext4_ext_writepage_trans_blocks (struct inode *,int );extern int ext4_ext_get_blocks (handle_t *handle,struct inode *inode, -ext4_fsblk_t iblock, +ext4_lblk_t iblock,unsigned long max_blocks,struct buffer_head *bh_result,int create,int extend_disksize);extern void ext4_ext_truncate (struct inode *,struct page *);
@@ -1081,11 +1084,17 @@ ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, unsigned long max_blocks, struct buffer_head *bh, int create, int extend_disksize) { - if (EXT4_I(inode)->i_flags & EXT4_EXTENTS_FL) - return ext4_ext_get_blocks(handle, inode, block, max_blocks, - bh, create, extend_disksize); -return ext4_get_blocks_handle (handle, inode, block, max_blocks, bh, - create, extend_disksize); + int retval; +if (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) { + retval =ext4_ext_get_blocks (handle, inode, + (ext4_lblk_t )block, max_blocks, + bh, create, extend_disksize); + }else { + retval =ext4_get_blocks_handle (handle, inode, + (ext4_lblk_t )block, max_blocks, + bh, create, extend_disksize); + } +return retval; }
include/linux/ext4_fs_extents.h +2 -17
@@ -124,20 +124,6 @@ struct ext4_ext_path {#define EXT4_EXT_CACHE_GAP 1#define EXT4_EXT_CACHE_EXTENT 2 -/* -* to be called by ext4_ext_walk_space() -* negative retcode - error -* positive retcode - signal for ext4_ext_walk_space(), see below -* callback must return valid extent (passed or newly created) -*/ -typedef int (*ext_prepare_callback )(struct inode *,struct ext4_ext_path *, -struct ext4_ext_cache *, -void *); - -#define EXT_CONTINUE 0 -#define EXT_BREAK 1 -#define EXT_REPEAT 2 -#define EXT_MAX_BLOCK 0xffffffff
@@ -233,8 +219,7 @@ extern int ext4_ext_try_to_merge(struct inode *inode, struct ext4_extent *);extern unsigned int ext4_ext_check_overlap (struct inode *,struct ext4_extent *,struct ext4_ext_path *);extern int ext4_ext_insert_extent (handle_t *,struct inode *,struct ext4_ext_path *,struct ext4_extent *); -extern int ext4_ext_walk_space (struct inode *,unsigned long ,unsigned long ,ext_prepare_callback ,void *); -extern struct ext4_ext_path *ext4_ext_find_extent (struct inode *,int ,struct ext4_ext_path *); - +extern struct ext4_ext_path *ext4_ext_find_extent (struct inode *,ext4_lblk_t , +struct ext4_ext_path *);#endif /* _LINUX_EXT4_EXTENTS */
include/linux/ext4_fs_i.h +6 -3
@@ -27,6 +27,9 @@ typedef int ext4_grpblk_t;/* data type for filesystem-wide blocks number */ typedef unsigned long long ext4_fsblk_t ; +/* data type for file logical block number */ +typedef __u32 ext4_lblk_t ; +struct ext4_reserve_window {ext4_fsblk_t _rsv_start;/* First byte reserved */ ext4_fsblk_t _rsv_end;/* Last byte reserved or 0 */
@@ -48,7 +51,7 @@ struct ext4_block_alloc_info {* most-recently-allocated block in this file. * We use this for detecting linearly ascending allocation requests. */ -__u32 last_alloc_logical_block; +ext4_lblk_t last_alloc_logical_block;/* * Was i_next_alloc_goal in ext4_inode_info * is the *physical* companion to i_next_alloc_block.
@@ -67,7 +70,7 @@ struct ext4_block_alloc_info {*/ struct ext4_ext_cache {ext4_fsblk_t ec_start; -__u32 ec_block; +ext4_lblk_t ec_block;__u32 ec_len;/* must be 32bit to return holes */ __u32 ec_type; };
@@ -95,7 +98,7 @@ struct ext4_inode_info {/* block reservation info */ struct ext4_block_alloc_info *i_block_alloc_info; -__u32 i_dir_start_lookup; +ext4_lblk_t i_dir_start_lookup;#ifdef CONFIG_EXT4DEV_FS_XATTR /* * Extended attributes can be read independently of the main file
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 35/49 ext4: Add inode version support in ext4
In reply to Theodore Ts'oFrom: Jean Noel Cordenner <[email protected]>
This patch adds 64-bit inode version support to ext4. The lower 32 bits are stored in the osd1.linux1.l_i_version field while the high 32 bits are stored in the i_version_hi field newly created in the ext4_inode. This field is incremented in case the ext4_inode is large enough. A i_version mount option has been added to enable the feature.
--- fs/ext4/inode.c | 18 +++++++++++++++++- fs/ext4/super.c | 10 ++++++++-- fs/inode.c | 17 ----------------- include/linux/ext4_fs.h | 6 +++++- include/linux/fs.h | 16 +++++++++++++++- 5 files changed, 45 insertions(+), 22 deletions(-)
fs/ext4/inode.c +17 -1
@@ -2780,6 +2780,13 @@ void ext4_read_inode(struct inode * inode)EXT4_INODE_GET_XTIME (i_atime, inode, raw_inode);EXT4_EINODE_GET_XTIME (i_crtime, ei, raw_inode); + inode->i_version =le32_to_cpu (raw_inode->i_disk_version); +if (EXT4_INODE_SIZE (inode->i_sb) >EXT4_GOOD_OLD_INODE_SIZE ) { +if (EXT4_FITS_IN_INODE (raw_inode, ei, i_version_hi)) + inode->i_version |= + (__u64)(le32_to_cpu (raw_inode->i_version_hi)) <<32 ; + } +if (S_ISREG (inode->i_mode)) { inode->i_op = &ext4_file_inode_operations; inode->i_fop = &ext4_file_operations;
@@ -2962,8 +2969,14 @@ static int ext4_do_update_inode(handle_t *handle, }else for (block =0 ; block <EXT4_N_BLOCKS ; block++) raw_inode->i_block[block] = ei->i_data[block]; -if (ei->i_extra_isize) + raw_inode->i_disk_version =cpu_to_le32 (inode->i_version); +if (ei->i_extra_isize) { +if (EXT4_FITS_IN_INODE (raw_inode, ei, i_version_hi)) + raw_inode->i_version_hi = +cpu_to_le32 (inode->i_version >>32 ); raw_inode->i_extra_isize =cpu_to_le16 (ei->i_extra_isize); + } +BUFFER_TRACE (bh,"call ext4_journal_dirty_metadata" ); rc =ext4_journal_dirty_metadata (handle, bh);
@@ -3190,6 +3203,9 @@ int ext4_mark_iloc_dirty(handle_t *handle, {int err =0 ; +if (test_opt (inode->i_sb,I_VERSION )) +inode_inc_iversion (inode); +/* the do_update_inode consumes one bh->b_count */ get_bh (iloc->bh);
fs/ext4/super.c +8 -2
@@ -732,6 +732,8 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)seq_puts (seq,",nobh" );if (!test_opt (sb,EXTENTS ))seq_puts (seq,",noextents" ); +if (test_opt (sb,I_VERSION )) +seq_puts (seq,",i_version" );if (test_opt (sb,DATA_FLAGS ) ==EXT4_MOUNT_JOURNAL_DATA )seq_puts (seq,",data=journal" );
@@ -874,7 +876,7 @@ enum { Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota, Opt_ignore, Opt_barrier, Opt_err, Opt_resize, Opt_usrquota, - Opt_grpquota, Opt_extents, Opt_noextents, + Opt_grpquota, Opt_extents, Opt_noextents, Opt_i_version, }; static match_table_t tokens = {
@@ -928,6 +930,7 @@ static match_table_t tokens = { {Opt_barrier, "barrier=%u"}, {Opt_extents, "extents"}, {Opt_noextents, "noextents"}, + {Opt_i_version, "i_version"}, {Opt_err, NULL}, {Opt_resize, "resize"}, };
@@ -1273,6 +1276,10 @@ clear_qf_name:case Opt_noextents:clear_opt (sbi->s_mount_opt,EXTENTS );break ; +case Opt_i_version: +set_opt (sbi->s_mount_opt,I_VERSION ); + sb->s_flags |=MS_I_VERSION ; +break ;default :printk (KERN_ERR "EXT4-fs: Unrecognized mount option \"%s\" "
@@ -3197,7 +3204,6 @@ out:i_size_write (inode, off+len-towrite);EXT4_I (inode)->i_disksize = inode->i_size; } - inode->i_version++; inode->i_mtime = inode->i_ctime =CURRENT_TIME ;ext4_mark_inode_dirty (handle, inode);mutex_unlock (&inode->i_mutex);
fs/inode.c +0 -17
@@ -1243,23 +1243,6 @@ void touch_atime(struct vfsmount *mnt, struct dentry *dentry)EXPORT_SYMBOL (touch_atime);/** -* inode_inc_iversion - increments i_version -* @inode: inode that need to be updated -* -* Every time the inode is modified, the i_version field -* will be incremented. -* The filesystem has to be mounted with i_version flag -* -*/ - -void inode_inc_iversion (struct inode *inode) -{ -spin_lock (&inode->i_lock); - inode->i_version++; -spin_unlock (&inode->i_lock); -} - -/** * file_update_time - update mtime and ctime time * @file: file accessed *
include/linux/ext4_fs.h +5 -1
@@ -292,7 +292,7 @@ struct ext4_inode {__le32 i_flags;/* File flags */ union {struct { -__u32 l_i_reserved1; +__le32 l_i_version; } linux1;struct {__u32 h_i_translator;
@@ -334,6 +334,7 @@ struct ext4_inode {__le32 i_atime_extra;/* extra Access time (nsec << 2 | epoch) */ __le32 i_crtime;/* File Creation time */ __le32 i_crtime_extra;/* extra FileCreationtime (nsec << 2 | epoch) */ +__le32 i_version_hi;/* high 32 bits for 64-bit version */ };
@@ -407,6 +408,8 @@ do { \ raw_inode->xtime ## _extra); \ } while (0) +#define i_disk_version osd1.linux1.l_i_version +#if defined(__KERNEL__) || defined(__linux__)#define i_reserved1 osd1.linux1.l_i_reserved1#define i_file_acl_high osd2.linux2.l_i_file_acl_high
@@ -469,6 +472,7 @@ do { \#define EXT4_MOUNT_EXTENTS 0x400000/* Extents support */ #define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000/* Journal checksums */ #define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000/* Journal Async Commit */ +#define EXT4_MOUNT_I_VERSION 0x2000000/* i_version support */ /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */ #ifndef _LINUX_EXT2_FS_H#define clear_opt (o, opt) o &= ~EXT4_MOUNT_##opt
include/linux/fs.h +15 -1
@@ -1396,7 +1396,21 @@ static inline void inode_dec_link_count(struct inode *inode)mark_inode_dirty (inode); } -extern void inode_inc_iversion (struct inode *inode); +/** +* inode_inc_iversion - increments i_version +* @inode: inode that need to be updated +* +* Every time the inode is modified, the i_version field will be incremented. +* The filesystem has to be mounted with i_version flag +*/ + +static inline void inode_inc_iversion (struct inode *inode) +{ +spin_lock (&inode->i_lock); + inode->i_version++; +spin_unlock (&inode->i_lock); +} +extern void touch_atime (struct vfsmount *mnt,struct dentry *dentry);static inline void file_accessed (struct file *file) {
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 32/49 jbd2: jbd2 stats through procfs
In reply to Theodore Ts'oFrom: Johann Lombardi <[email protected]>
The patch below updates the jbd stats patch to 2.6.20/jbd2. The initial patch was posted by Alex Tomas in December 2005
(http://marc.info/?l=linux-ext4&m=113538565128617&w=2).
It provides statistics via procfs such as transaction lifetime and size.
Sometimes, investigating performance problems, i find useful to have stats from jbd about transaction's lifetime, size, etc. here is a patch for review and inclusion probably.
for example, stats after creation of 3M files in htree directory:
[root@bob ~]# cat /proc/fs/jbd/sda/history
R/C tid wait run lock flush log hndls block inlog ctime write drop close R 261 8260 2720 0 0 750 9892 8170 8187 C 259 750 0 4885 1 R 262 20 2200 10 0 770 9836 8170 8187 R 263 30 2200 10 0 3070 9812 8170 8187 R 264 0 5000 10 0 1340 0 0 0 C 261 8240 3212 4957 0 R 265 8260 1470 0 0 4640 9854 8170 8187 R 266 0 5000 10 0 1460 0 0 0 C 262 8210 2989 4868 0 R 267 8230 1490 10 0 4440 9875 8171 8188 R 268 0 5000 10 0 1260 0 0 0 C 263 7710 2937 4908 0 R 269 7730 1470 10 0 3330 9841 8170 8187 R 270 0 5000 10 0 830 0 0 0 C 265 8140 3234 4898 0 C 267 720 0 4849 1 R 271 8630 2740 20 0 740 9819 8170 8187 C 269 800 0 4214 1 R 272 40 2170 10 0 830 9716 8170 8187 R 273 40 2280 0 0 3530 9799 8170 8187 R 274 0 5000 10 0 990 0 0 0
where,
R - line for transaction's life from T_RUNNING to T_FINISHED C - line for transaction's checkpointing tid - transaction's id wait - for how long we were waiting for new transaction to start
(the longest period journal_start() took in this transaction)
run - real transaction's lifetime (from T_RUNNING to T_LOCKED
lock - how long we were waiting for all handles to close
(time the transaction was in T_LOCKED)
flush - how long it took to flush all data (data=ordered)
log - how long it took to write the transaction to the log
hndls - how many handles got to the transaction
block - how many blocks got to the transaction
inlog - how many blocks are written to the log (block + descriptors) ctime - how long it took to checkpoint the transaction
write - how many blocks have been written during checkpointing drop - how many blocks have been dropped during checkpointing close - how many running transactions have been closed to checkpoint this one
all times are in msec.
[root@bob ~]# cat /proc/fs/jbd/sda/info
280 transaction, each upto 8192 blocks
average:
1633ms waiting for transaction
3616ms running transaction
5ms transaction was being locked
1ms flushing data (in ordered mode)
1799ms logging transaction
11781 handles per transaction
5629 blocks per transaction
5641 logged blocks per transaction
--- fs/jbd2/checkpoint.c | 10 +- fs/jbd2/commit.c | 49 +++++++ fs/jbd2/journal.c | 338 +++++++++++++++++++++++++++++++++++++++++++++++++ fs/jbd2/transaction.c | 9 ++ include/linux/jbd2.h | 77 +++++++++++ 5 files changed, 481 insertions(+), 2 deletions(-)
fs/jbd2/checkpoint.c +8 -2
@@ -232,7 +232,8 @@ __flush_batch(journal_t *journal, struct buffer_head **bhs, int *batch_count)* Called under jbd_lock_bh_state(jh2bh(jh)), and drops it */ static int __process_buffer (journal_t *journal,struct journal_head *jh, -struct buffer_head **bhs,int *batch_count) +struct buffer_head **bhs,int *batch_count, +transaction_t *transaction) {struct buffer_head *bh =jh2bh (jh);int ret =0 ;
@@ -250,6 +251,7 @@ static int __process_buffer(journal_t *journal, struct journal_head *jh,transaction_t *t = jh->b_transaction;tid_t tid = t->t_tid; + transaction->t_chp_stats.cs_forced_to_close++;spin_unlock (&journal->j_list_lock);jbd_unlock_bh_state (bh);jbd2_log_start_commit (journal, tid);
@@ -279,6 +281,7 @@ static int __process_buffer(journal_t *journal, struct journal_head *jh, bhs[*batch_count] = bh;__buffer_relink_io (jh);jbd_unlock_bh_state (bh); + transaction->t_chp_stats.cs_written++; (*batch_count)++;if (*batch_count ==NR_BATCH ) {spin_unlock (&journal->j_list_lock);
@@ -322,6 +325,8 @@ int jbd2_log_do_checkpoint(journal_t *journal)if (!journal->j_checkpoint_transactions) goto out; transaction = journal->j_checkpoint_transactions; +if (transaction->t_chp_stats.cs_chp_time ==0 ) + transaction->t_chp_stats.cs_chp_time = jiffies; this_tid = transaction->t_tid; restart:/*
@@ -346,7 +351,8 @@ restart: retry =1 ;break ; } - retry =__process_buffer (journal, jh, bhs,&batch_count); + retry =__process_buffer (journal, jh, bhs, &batch_count, + transaction);if (!retry &&lock_need_resched (&journal->j_list_lock)){spin_unlock (&journal->j_list_lock); retry =1 ;
fs/jbd2/commit.c +49 -0
97 lines not on this page · raw message
fs/jbd2/journal.c +338 -0
392 lines not on this page · raw message
fs/jbd2/transaction.c +9 -0
@@ -59,6 +59,8 @@ jbd2_get_transaction(journal_t *journal, transaction_t *transaction)J_ASSERT (journal->j_running_transaction ==NULL ); journal->j_running_transaction = transaction; + transaction->t_max_wait =0 ; + transaction->t_start = jiffies;return transaction; }
@@ -85,6 +87,7 @@ static int start_this_handle(journal_t *journal, handle_t *handle)int nblocks = handle->h_buffer_credits;transaction_t *new_transaction =NULL ;int ret =0 ; +unsigned long ts = jiffies;if (nblocks > journal->j_max_transaction_buffers) { printk(KERN_ERR "JBD: %s wants too many credits (%d > %d)\n",
@@ -217,6 +220,12 @@ repeat_locked:/* OK, account for the buffers that this operation expects to * use and add the handle to the running transaction. */ +if (time_after (transaction->t_start, ts)) { + ts =jbd2_time_diff (ts, transaction->t_start); +if (ts > transaction->t_max_wait) + transaction->t_max_wait = ts; + } + handle->h_transaction = transaction; transaction->t_outstanding_credits += nblocks; transaction->t_updates++;
include/linux/jbd2.h +77 -0
107 lines not on this page · raw message
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 6/49 ext4: fixes block group number being set to a negative value
In reply to Theodore Ts'oFrom: Avantika Mathur <[email protected]>
This patch fixes various places where the group number is set to a negative value.
--- fs/ext4/ialloc.c | 101 ++++++++++++++++++++++++++++------------------------- 1 files changed, 53 insertions(+), 48 deletions(-)
fs/ext4/ialloc.c +53 -48
@@ -260,12 +260,14 @@ error_return:* For other inodes, search forward from the parent directory\'s block * group to find a free inode. */ -static ext4_group_t find_group_dir (struct super_block *sb,struct inode *parent) +static int find_group_dir (struct super_block *sb,struct inode *parent, +ext4_group_t *best_group) {ext4_group_t ngroups =EXT4_SB (sb)->s_groups_count;unsigned int freei, avefreei;struct ext4_group_desc *desc, *best_desc =NULL ; -ext4_group_t group, best_group =-1 ; +ext4_group_t group; +int ret =-1 ; freei =percpu_counter_read_positive (&EXT4_SB (sb)->s_freeinodes_counter); avefreei = freei / ngroups;
@@ -279,11 +281,12 @@ static ext4_group_t find_group_dir(struct super_block *sb, struct inode *parent)if (!best_desc || (le16_to_cpu (desc->bg_free_blocks_count) >le16_to_cpu (best_desc->bg_free_blocks_count))) { - best_group = group; + *best_group = group; best_desc = desc; + ret =0 ; } } -return best_group; +return ret; }/*
@@ -314,8 +317,8 @@ static ext4_group_t find_group_dir(struct super_block *sb, struct inode *parent)#define INODE_COST 64#define BLOCK_COST 256 -static ext4_group_t find_group_orlov (struct super_block *sb, -struct inode *parent) +static int find_group_orlov (struct super_block *sb,struct inode *parent, +ext4_group_t *group) {ext4_group_t parent_group =EXT4_I (parent)->i_block_group;struct ext4_sb_info *sbi =EXT4_SB (sb);
@@ -328,7 +331,7 @@ static ext4_group_t find_group_orlov(struct super_block *sb,unsigned int ndirs;int max_debt, max_dirs, min_inodes;ext4_grpblk_t min_blocks; -ext4_group_t group =-1 , i; +ext4_group_t i;struct ext4_group_desc *desc; freei =percpu_counter_read_positive (&sbi->s_freeinodes_counter);
@@ -341,13 +344,14 @@ static ext4_group_t find_group_orlov(struct super_block *sb,if ((parent == sb->s_root->d_inode) || (EXT4_I (parent)->i_flags &EXT4_TOPDIR_FL )) {int best_ndir = inodes_per_group; -ext4_group_t best_group =-1 ; +ext4_group_t grp; +int ret =-1 ; -get_random_bytes (&group,sizeof (group)); - parent_group = (unsigned )group % ngroups; +get_random_bytes (&grp,sizeof (grp)); + parent_group = (unsigned )grp % ngroups;for (i =0 ; i < ngroups; i++) { - group = (parent_group + i) % ngroups; - desc =ext4_get_group_desc (sb, group,NULL ); + grp = (parent_group + i) % ngroups; + desc =ext4_get_group_desc (sb, grp,NULL );if (!desc || !desc->bg_free_inodes_count)continue ;if (le16_to_cpu (desc->bg_used_dirs_count) >= best_ndir)
@@ -356,11 +360,12 @@ static ext4_group_t find_group_orlov(struct super_block *sb,continue ;if (le16_to_cpu (desc->bg_free_blocks_count) < avefreeb)continue ; - best_group = group; + *group = grp; + ret =0 ; best_ndir =le16_to_cpu (desc->bg_used_dirs_count); } -if (best_group >=0 ) -return best_group; +if (ret ==0 ) +return ret; goto fallback; }
@@ -381,8 +386,8 @@ static ext4_group_t find_group_orlov(struct super_block *sb, max_debt =1 ;for (i =0 ; i < ngroups; i++) { - group = (parent_group + i) % ngroups; - desc =ext4_get_group_desc (sb, group,NULL ); + *group = (parent_group + i) % ngroups; + desc =ext4_get_group_desc (sb, *group,NULL );if (!desc || !desc->bg_free_inodes_count)continue ;if (le16_to_cpu (desc->bg_used_dirs_count) >= max_dirs)
@@ -391,17 +396,16 @@ static ext4_group_t find_group_orlov(struct super_block *sb,continue ;if (le16_to_cpu (desc->bg_free_blocks_count) < min_blocks)continue ; -return group; +return 0 ; } fallback:for (i =0 ; i < ngroups; i++) { - group = (parent_group + i) % ngroups; - desc =ext4_get_group_desc (sb, group,NULL ); -if (!desc || !desc->bg_free_inodes_count) -continue ; -if (le16_to_cpu (desc->bg_free_inodes_count) >= avefreei) -return group; + *group = (parent_group + i) % ngroups; + desc =ext4_get_group_desc (sb, *group,NULL ); +if (desc && desc->bg_free_inodes_count && +le16_to_cpu (desc->bg_free_inodes_count) >= avefreei) +return 0 ; }if (avefreei) {
@@ -416,22 +420,22 @@ fallback:return -1 ; } -static ext4_group_t find_group_other (struct super_block *sb, -struct inode *parent) +static int find_group_other (struct super_block *sb,struct inode *parent, +ext4_group_t *group) {ext4_group_t parent_group =EXT4_I (parent)->i_block_group;ext4_group_t ngroups =EXT4_SB (sb)->s_groups_count;struct ext4_group_desc *desc; -ext4_group_t group, i; +ext4_group_t i;/* * Try to place the inode in its parent directory */ - group = parent_group; - desc =ext4_get_group_desc (sb, group,NULL ); + *group = parent_group; + desc =ext4_get_group_desc (sb, *group,NULL );if (desc &&le16_to_cpu (desc->bg_free_inodes_count) &&le16_to_cpu (desc->bg_free_blocks_count)) -return group; +return 0 ;/* * We're going to place this inode in a different blockgroup from its
@@ -442,33 +446,33 @@ static ext4_group_t find_group_other(struct super_block *sb,* * So add our directory's i_ino into the starting point for the hash. */ - group = (group + parent->i_ino) % ngroups; + *group = (*group + parent->i_ino) % ngroups;/* * Use a quadratic hash to find a group with a free inode and some free * blocks. */ for (i =1 ; i < ngroups; i <<=1 ) { - group += i; -if (group >= ngroups) - group -= ngroups; - desc =ext4_get_group_desc (sb, group,NULL ); + *group += i; +if (*group >= ngroups) + *group -= ngroups; + desc =ext4_get_group_desc (sb, *group,NULL );if (desc &&le16_to_cpu (desc->bg_free_inodes_count) &&le16_to_cpu (desc->bg_free_blocks_count)) -return group; +return 0 ; }/* * That failed: try linear search for a free inode, even if that group * has no free blocks. */ - group = parent_group; + *group = parent_group;for (i =0 ; i < ngroups; i++) { -if (++group >= ngroups) - group =0 ; - desc =ext4_get_group_desc (sb, group,NULL ); +if (++*group >= ngroups) + *group =0 ; + desc =ext4_get_group_desc (sb, *group,NULL );if (desc &&le16_to_cpu (desc->bg_free_inodes_count)) -return group; +return 0 ; }return -1 ;
@@ -489,16 +493,17 @@ struct inode *ext4_new_inode(handle_t *handle, struct inode * dir, int mode)struct super_block *sb;struct buffer_head *bitmap_bh =NULL ;struct buffer_head *bh2; -ext4_group_t group; +ext4_group_t group =0 ;unsigned long ino =0 ;struct inode * inode;struct ext4_group_desc * gdp =NULL ;struct ext4_super_block * es;struct ext4_inode_info *ei;struct ext4_sb_info *sbi; -int err =0 ; +int ret2, err =0 ;struct inode *ret; -int i, free =0 ; +ext4_group_t i; +int free =0 ;/* Cannot create files in a deleted directory */ if (!dir || !dir->i_nlink)
@@ -514,14 +519,14 @@ struct inode *ext4_new_inode(handle_t *handle, struct inode * dir, int mode) es = sbi->s_es;if (S_ISDIR (mode)) {if (test_opt (sb,OLDALLOC )) - group =find_group_dir (sb, dir); + ret2 =find_group_dir (sb, dir, &group);else - group =find_group_orlov (sb, dir); + ret2 =find_group_orlov (sb, dir, &group); }else - group =find_group_other (sb, dir); + ret2 =find_group_other (sb, dir, &group); err = -ENOSPC ; -if (group ==-1 ) +if (ret2 ==-1 ) goto out;for (i =0 ; i < sbi->s_groups_count; i++) {
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
Theodore Ts'o
maintainerPATCH 49/49 jbd2: sparse pointer use of zero as null
In reply to Theodore Ts'oFrom: Mingming Cao <[email protected]>
Get rid of sparse related warnings from places that use integer as NULL pointer. (Ported from upstream ext3/jbd changes.)
--- fs/jbd2/transaction.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
fs/jbd2/transaction.c +6 -6
@@ -1182,7 +1182,7 @@ int jbd2_journal_dirty_metadata(handle_t *handle, struct buffer_head *bh) }/* That test should have eliminated the following case: */ -J_ASSERT_JH (jh, jh->b_frozen_data ==0 ); +J_ASSERT_JH (jh, jh->b_frozen_data ==NULL );JBUFFER_TRACE (jh,"file as BJ_Metadata" );spin_lock (&journal->j_list_lock);
@@ -1532,7 +1532,7 @@ void __jbd2_journal_temp_unlink_buffer(struct journal_head *jh)J_ASSERT_JH (jh, jh->b_jlist < BJ_Types);if (jh->b_jlist != BJ_None) -J_ASSERT_JH (jh, transaction !=0 ); +J_ASSERT_JH (jh, transaction !=NULL );switch (jh->b_jlist) {case BJ_None:
@@ -1601,11 +1601,11 @@ __journal_try_to_free_buffer(journal_t *journal, struct buffer_head *bh)if (buffer_locked (bh) ||buffer_dirty (bh)) goto out; -if (jh->b_next_transaction !=0 ) +if (jh->b_next_transaction !=NULL ) goto out;spin_lock (&journal->j_list_lock); -if (jh->b_transaction !=0 && jh->b_cp_transaction ==0 ) { +if (jh->b_transaction !=NULL && jh->b_cp_transaction ==NULL ) {if (jh->b_jlist == BJ_SyncData || jh->b_jlist == BJ_Locked) {/* A written-back ordered data buffer */ JBUFFER_TRACE (jh,"release data" );
@@ -1613,7 +1613,7 @@ __journal_try_to_free_buffer(journal_t *journal, struct buffer_head *bh)jbd2_journal_remove_journal_head (bh);__brelse (bh); } - }else if (jh->b_cp_transaction !=0 && jh->b_transaction ==0 ) { + }else if (jh->b_cp_transaction !=NULL && jh->b_transaction ==NULL ) {/* written-back checkpointed metadata buffer */ if (jh->b_jlist == BJ_None) {JBUFFER_TRACE (jh,"remove from checkpoint list" );
@@ -1973,7 +1973,7 @@ void __jbd2_journal_file_buffer(struct journal_head *jh,J_ASSERT_JH (jh, jh->b_jlist < BJ_Types);J_ASSERT_JH (jh, jh->b_transaction == transaction || - jh->b_transaction ==0 ); + jh->b_transaction ==NULL );if (jh->b_transaction && jh->b_jlist == jlist)return ;
Signature · 1 line
1.5.4.rc3.31.g1271-dirty
The log is pretty messy, any chance you could reshuffle the gazillions of fixup patches into the few feature patches to give a proper readable history in git?
Andrew Morton
maintainerRe: [PATCH 30/49] ext4: Convert truncate_mutex to read write semaphore.
In reply to Theodore Ts'oQuoted 13 lines · On Mon, 21 Jan 2008 22:02:09 -0500 "Theodore Ts'o" <[email protected]> wrote:
fs/ext4/inode.c +12
-0+int ext4_get_blocks_wrap (handle_t *handle,struct inode *inode,sector_t block, +unsigned long max_blocks,struct buffer_head *bh, +int create,int extend_disksize) +{ +int retval; +if (create) { +down_write ((&EXT4_I (inode)->i_data_sem)); + }else { +down_read ((&EXT4_I (inode)->i_data_sem)); + } +if (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) { + retval = ext4_ext_get_blocks(handle, inode, block, max_blocks,
fs/ext4/inode.c out: · line 920
Quoted 10 lines
fs/ext4/inode.c +10
-0+ bh, create, extend_disksize); + }else { + retval =ext4_get_blocks_handle (handle, inode, block, + max_blocks, bh, create, extend_disksize); + } +if (create) { +up_write ((&EXT4_I (inode)->i_data_sem)); + }else { +up_read ((&EXT4_I (inode)->i_data_sem)); + }
This function has many unneeded braces. checkpatch used to detect this but it seems to have broken.
fs/ext4/inode.c out: · line 924
Quoted 4 lines
fs/ext4/inode.c +2
-0+return retval; +}static int ext4_get_block (struct inode *inode,sector_t iblock,struct buffer_head *bh_result,int create)
Mising newline.
Andrew Morton
maintainerRe: [PATCH 33/49] ext4: Add the journal checksum feature
In reply to Theodore Ts'oQuoted 17 lines · On Mon, 21 Jan 2008 22:02:12 -0500 "Theodore Ts'o" <[email protected]> wrote:
From: Girish Shilamkar <[email protected]>
The journal checksum feature adds two new flags i.e
JBD2_FEATURE_INCOMPAT_ASYNC_COMMITandJBD2_FEATURE_COMPAT_CHECKSUM.
JBD2_FEATURE_CHECKSUMflag indicates that the commit block contains the checksum for the blocks described by the descriptor blocks. Due to checksums, writing of the commit record no longer needs to be synchronous. Now commit record can be sent to disk without waiting for descriptor blocks to be written to disk. This behavior is controlled usingJBD2_FEATURE_ASYNC_COMMITflag. Older kernels/e2fsck should not be able to recover the journal with_ASYNC_COMMIThence it is made incompat.
The commit header has been extended to hold the checksum along with the type of the checksum.
Quoted 6 lines
For recovery in pass scan checksums are verified to ensure the sanity and
completeness(in case of _ASYNC_COMMIT)of every transaction....
+static inline
__u32jbd2_checksum_data(__u32 crc32_sum, struct buffer_head *bh)
unneeded inlining.
fs/jbd2/commit.c write_out_data: · line 365
Quoted 12 lines
fs/jbd2/commit.c +12
-0+{ +struct page *page = bh->b_page; +char *addr; +__u32 checksum; + + addr =kmap_atomic (page,KM_USER0 ); + checksum =crc32_be (crc32_sum, + (void *)(addr +offset_in_page (bh->b_data)), bh->b_size); +kunmap_atomic (addr,KM_USER0 ); + +return checksum; +}
Can this buffer actually be in highmem?
Quoted 2 lines
static inline void write_tag_block(int
tag_bytes,journal_block_tag_t*tag,
unsigned long long block)
More unnecessary inlining.
Quoted 18 lines
fs/jbd2/journal.c +18
-0+/* +* jbd2_journal_clear_features () - Clear a given journal feature in the +* superblock +* @journal: Journal to act on. +* @compat: bitmask of compatible features +* @ro: bitmask of features that force read-only mount +* @incompat: bitmask of incompatible features +* +* Clear a given journal feature as present on the +* superblock. Returns true if the requested features could be reset. +*/ +int jbd2_journal_clear_features (journal_t *journal,unsigned long compat, +unsigned long ro,unsigned long incompat) +{ +journal_superblock_t *sb; + +jbd_debug (1 ,"Clear features 0x%lx/0x%lx/0x%lx\n" , + compat, ro, incompat);
fs/jbd2/journal.c int jbd2_journal_set_features (journal_t *journal, unsigned long compat, · line 1608
Quoted 10 lines
fs/jbd2/journal.c +10
-0+ + sb = journal->j_superblock; + + sb->s_feature_compat &= ~cpu_to_be32 (compat); + sb->s_feature_ro_compat &= ~cpu_to_be32 (ro); + sb->s_feature_incompat &= ~cpu_to_be32 (incompat); + +return 1 ; +} +EXPORT_SYMBOL (jbd2_journal_clear_features);
Kernel usually returns 0 on success. So we can return a useful errno on failure.
Quoted 7 lines
fs/jbd2/recovery.c +7
-0+/* +* calc_chksums calculates the checksums for the blocks described in the +* descriptor block. +*/ +static int calc_chksums (journal_t *journal,struct buffer_head *bh, +unsigned long *next_log_block,__u32 *crc32_sum) +{
fs/jbd2/recovery.c static inline unsigned long long read_tag_block(int tag_bytes, journal_block_tag · line 336
Quoted 10 lines
fs/jbd2/recovery.c +10
-0+int i, num_blks, err; +unsigned io_block; +struct buffer_head *obh; + + num_blks =count_tags (journal, bh); +/* Calculate checksum of the descriptor block. */ + *crc32_sum =crc32_be (*crc32_sum, (void *)bh->b_data, bh->b_size); + +for (i =0 ; i < num_blks; i++) { + io_block = (*next_log_block)++;
unsigned <- unsigned long.
Are all the types appropriate in here?
Quoted 32 lines
fs/jbd2/recovery.c +16
-2+wrap (journal, *next_log_block); + err =jread (&obh, journal, io_block); +if (err) { +printk (KERN_ERR "JBD: IO error %d recovering block " +"%u in log\n" , err, io_block); +return 1 ; + }else { + *crc32_sum =crc32_be (*crc32_sum, (void *)obh->b_data, + obh->b_size); + } + } +return 0 ; +} +static int do_one_pass (journal_t *journal,struct recovery_info *info,enum passtype pass) {@@ -328,6 +360,7 @@ static int do_one_pass(journal_t *journal,unsigned int sequence;int blocktype;int tag_bytes =journal_tag_bytes (journal); +__u32 crc32_sum = ~0 ;/* Transactional Checksums */ /* Precompute the maximum metadata descriptors in a descriptor block */ int MAX_BLOCKS_PER_DESC ;@@ -419,9 +452,23 @@ static int do_one_pass(journal_t *journal,switch (blocktype) {case JBD2_DESCRIPTOR_BLOCK :/* If it is a valid descriptor block, replay it -* in pass REPLAY; otherwise, just skip over the -* blocks it describes. */ +* in pass REPLAY; if journal_checksums enabled, then
fs/jbd2/recovery.c static int do_one_pass(journal_t *journal, · line 465
Quoted 10 lines
fs/jbd2/recovery.c +9
-0+* calculate checksums in PASS_SCAN, otherwise, +* just skip over the blocks it describes. */ if (pass !=PASS_REPLAY ) { +if (pass ==PASS_SCAN && +JBD2_HAS_COMPAT_FEATURE (journal, +JBD2_FEATURE_COMPAT_CHECKSUM ) && + !info->end_transaction) { +if (calc_chksums (journal, bh, + &next_log_block, + &crc32_sum)) {
put_bh()
fs/jbd2/recovery.c static int do_one_pass(journal_t *journal, · line 470
Quoted 5 lines
fs/jbd2/recovery.c +5
-0+brelse (bh); +break ; + } +brelse (bh); +continue ;
put_bh()
fs/jbd2/recovery.c static int do_one_pass(journal_t *journal, · line 565
Quoted 8 lines
fs/jbd2/recovery.c +2
-0+ } next_log_block +=count_tags (journal, bh);wrap (journal, next_log_block);brelse (bh);@@ -516,9 +563,96 @@ static int do_one_pass(journal_t *journal,continue ; +brelse (bh);
etc
Andrew Morton
maintainerRe: [PATCH 23/49] Add buffer head related helper functions
In reply to Theodore Ts'ofs/buffer.c static int buffer_cpu_notify(struct notifier_block *self, · line 3234
Quoted 4 lines · On Mon, 21 Jan 2008 22:02:02 -0500 "Theodore Ts'o" <[email protected]> wrote:
fs/buffer.c +3
-0+} +EXPORT_SYMBOL (bh_uptodate_or_lock); +/**
Missing newline.
fs/buffer.c static int buffer_cpu_notify(struct notifier_block *self, · line 3246
Quoted 12 lines
+ *
bh_submit_read: Submit a locked buffer for reading
+ * @bh: structbuffer_head
+ *
+ * Returns a negative error
+ */fs/buffer.c +7
-0+int bh_submit_read (struct buffer_head *bh) +{ +if (!buffer_locked (bh)) +lock_buffer (bh); + +if (buffer_uptodate (bh)) +return 0 ;
Here it can lock the buffer then return zero
fs/buffer.c static int buffer_cpu_notify(struct notifier_block *self, · line 3253
Quoted 6 lines
fs/buffer.c +6
-0+get_bh (bh); + bh->b_end_io = end_buffer_read_sync; +submit_bh (READ , bh); +wait_on_buffer (bh); +if (buffer_uptodate (bh)) +return 0 ;
Here it will unlock the buffer and return zero.
This function is unusable when passed an unlocked buffer.
The return value should (always) be documented.
fs/buffer.c static int buffer_cpu_notify(struct notifier_block *self, · line 3257
Quoted 4 lines
fs/buffer.c +3
-0+return -EIO ; +} +EXPORT_SYMBOL (bh_submit_read);void __init buffer_init (void )
Missing newline.
Andrew Morton
maintainerRe: [PATCH 24/49] ext4: add block bitmap validation
In reply to Theodore Ts'oQuoted 5 lines · On Mon, 21 Jan 2008 22:02:03 -0500 "Theodore Ts'o" <[email protected]> wrote:
fs/ext4/balloc.c +3
-0+if (bh_submit_read (bh) <0 ) { +brelse (bh); +ext4_error (sb, __FUNCTION__, "Cannot read block bitmap - "
fs/ext4/balloc.c read_block_bitmap(struct super_block *sb, ext4_group_t block_group) · line 293
Quoted 10 lines
fs/ext4/balloc.c +8
-2-"block_group = %lu, block_bitmap = %llu" , - block_group, bitmap_blk); +"block_group = %d, block_bitmap = %llu" , + (int)block_group, (unsigned long long)bitmap_blk); +return NULL ; + } +if (!ext4_valid_block_bitmap (sb, desc, block_group, bh)) { +brelse (bh); +return NULL ; + }
brelse() should only be used when the bh might be NULL - put_bh() can be used here.
Please review all ext4/jbd2 code for this trivial speedup.
Andrew Morton
maintainerRe: [PATCH 41/49] ext4: Add multi block allocator for ext4
In reply to Theodore Ts'oQuoted 16 lines · On Mon, 21 Jan 2008 22:02:20 -0500 "Theodore Ts'o" <[email protected]> wrote:
From: Alex Tomas <[email protected]>
Signed-off-by Alex Tomas <[email protected]>Signed-off-by Andreas Dilger <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>Signed-off-by Eric Sandeen <[email protected]>Signed-off-by "Theodore Ts'o" <[email protected]>...
fs/ext4/mballoc.c new file +5
-0+#if BITS_PER_LONG ==64 +#define mb_correct_addr_and_bit (bit, addr) \ +{ \ + bit += ((unsigned long) addr & 7UL) << 3; \ + addr = (void *) ((unsigned long) addr & ~7UL); \
fs/ext4/mballoc.c line 640
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+} +#elif BITS_PER_LONG == 32 +#define mb_correct_addr_and_bit (bit, addr) \ +{ \ + bit += ((unsigned long) addr & 3UL) << 3; \ + addr = (void *) ((unsigned long) addr & ~3UL); \ +} +#else +#error "how many bits you are?!" +#endif
Why do these exist?
fs/ext4/mballoc.c line 646
Quoted 5 lines
fs/ext4/mballoc.c new file +5
-0+static inline int mb_test_bit (int bit,void *addr) +{ +mb_correct_addr_and_bit (bit, addr); +return ext4_test_bit (bit, addr); +}
ext2_test_bit() already handles bitnum > wordsize.
If mb_correct_addr_and_bit() is actually needed then some suitable comment would help.
Quoted 15 lines
fs/ext4/mballoc.c new file +15
-0+static inline void mb_set_bit (int bit,void *addr) +{ +mb_correct_addr_and_bit (bit, addr); +ext4_set_bit (bit, addr); +} + +static inline void mb_set_bit_atomic (spinlock_t *lock,int bit,void *addr) +{ +mb_correct_addr_and_bit (bit, addr); +ext4_set_bit_atomic (lock, bit, addr); +} + +static inline void mb_clear_bit (int bit,void *addr) +{ +mb_correct_addr_and_bit (bit, addr);
fs/ext4/mballoc.c line 672
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+ext4_clear_bit (bit, addr); +} + +static inline void mb_clear_bit_atomic (spinlock_t *lock,int bit,void *addr) +{ +mb_correct_addr_and_bit (bit, addr); +ext4_clear_bit_atomic (lock, bit, addr); +} + +static inline void *mb_find_buddy (struct ext4_buddy *e4b,int order,int *max)
uninlining this will save about eighty squigabytes of text.
Please review all of ext4/jbd2 with a view to removig unnecessary and wrong inlings.
Quoted 21 lines
fs/ext4/mballoc.c new file +21
-0+{ +char *bb; + +/* FIXME!! is this needed */ +BUG_ON (EXT4_MB_BITMAP (e4b) ==EXT4_MB_BUDDY (e4b)); +BUG_ON (max ==NULL ); + +if (order > e4b->bd_blkbits +1 ) { + *max =0 ; +return NULL ; + } + +/* at order 0 we see each particular block */ + *max =1 << (e4b->bd_blkbits +3 ); +if (order ==0 ) +return EXT4_MB_BITMAP (e4b); + + bb =EXT4_MB_BUDDY (e4b) +EXT4_SB (e4b->bd_sb)->s_mb_offsets[order]; + *max =EXT4_SB (e4b->bd_sb)->s_mb_maxs[order]; + +return bb;
fs/ext4/mballoc.c line 758
Quoted 10 lines
fs/ext4/mballoc.c new file +7
-0+} + +#else +#define mb_free_blocks_double (a, b, c, d) +#define mb_mark_used_double (a, b, c) +#define mb_cmp_bitmaps (a, b) +#endif
Please use the do{}while(0) thing. Or, better, proper C functions which have typechecking (unless this will cause undefined-var compile errors, which happens sometimes)
Quoted 9 lines
fs/ext4/mballoc.c new file +9
-0+/* find most significant bit */ +static int fmsb (unsigned short word) +{ +int order; + +if (word >255 ) { + order =7 ; + word >>=8 ; + }else {
fs/ext4/mballoc.c line 898
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+ order =-1 ; + } + +do { + order++; + word >>=1 ; + }while (word !=0 ); + +return order; +}
Did we just reinvent fls()?
Quoted 4 lines
fs/ext4/mballoc.c new file +4
-0+/* FIXME!! need more doc */ +static void ext4_mb_mark_free_simple (struct super_block *sb, +void *buddy,unsigned first,int len, +struct ext4_group_info *grp)
fs/ext4/mballoc.c line 913
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+{ +struct ext4_sb_info *sbi =EXT4_SB (sb); +unsigned short min; +unsigned short max; +unsigned short chunk; +unsigned short border; + +BUG_ON (len >=EXT4_BLOCKS_PER_GROUP (sb)); + + border =2 << sb->s_blocksize_bits;
Won't this explode with >= 32k blocksize?
Quoted 50 lines
fs/ext4/mballoc.c new file +47
-0+while (len >0 ) { +/* find how many blocks can be covered since this position */ + max =ffs (first | border) -1 ; + +/* find how many blocks of power 2 we need to mark */ + min =fmsb (len); + +if (max < min) + min = max; + chunk =1 << min; + +/* mark multiblock chunks only */ + grp->bb_counters[min]++; +if (min >0 ) +mb_clear_bit (first >> min, + buddy + sbi->s_mb_offsets[min]); + + len -= chunk; + first += chunk; + } +} + +static int ext4_mb_init_cache (struct page *page,char *incore) +{ +int blocksize; +int blocks_per_page; +int groups_per_page; +int err =0 ; +int i; +ext4_group_t first_group; +int first_block; +struct super_block *sb; +struct buffer_head *bhs; +struct buffer_head **bh; +struct inode *inode; +char *data; +char *bitmap; + +mb_debug ("init page %lu\n" , page->index); + + inode = page->mapping->host; + sb = inode->i_sb; + blocksize =1 << inode->i_blkbits; + blocks_per_page =PAGE_CACHE_SIZE / blocksize; + + groups_per_page = blocks_per_page >>1 ; +if (groups_per_page ==0 )
fs/ext4/mballoc.c line 1035
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+ groups_per_page =1 ; + +/* allocate buffer_heads to read bitmaps */ +if (groups_per_page >1 ) { + err = -ENOMEM ; + i =sizeof (struct buffer_head *) * groups_per_page; + bh =kmalloc (i,GFP_NOFS ); +if (bh ==NULL ) + goto out; +memset (bh,0 , i);
kzalloc()
Quoted 20 lines
fs/ext4/mballoc.c new file +20
-0+ }else + bh = &bhs; + + first_group = page->index * blocks_per_page /2 ; + +/* read all groups the page covers into the cache */ +for (i =0 ; i < groups_per_page; i++) { +struct ext4_group_desc *desc; + +if (first_group + i >=EXT4_SB (sb)->s_groups_count) +break ; + + err = -EIO ; + desc =ext4_get_group_desc (sb, first_group + i,NULL ); +if (desc ==NULL ) + goto out; + + err = -ENOMEM ; + bh[i] =sb_getblk (sb,ext4_block_bitmap (sb, desc)); +if (bh[i] ==NULL )
fs/ext4/mballoc.c line 1065
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+ goto out; + +if (buffer_uptodate (bh[i])) +continue ; + +lock_buffer (bh[i]); +if (buffer_uptodate (bh[i])) { +unlock_buffer (bh[i]); +continue ; + }
Didn't we just add a helper in fs/buffer.c to do this?
Quoted 70 lines
fs/ext4/mballoc.c new file +70
-0+if (desc->bg_flags &cpu_to_le16 (EXT4_BG_BLOCK_UNINIT )) { +ext4_init_block_bitmap (sb, bh[i], + first_group + i, desc); +set_buffer_uptodate (bh[i]); +unlock_buffer (bh[i]); +continue ; + } +get_bh (bh[i]); + bh[i]->b_end_io = end_buffer_read_sync; +submit_bh (READ , bh[i]); +mb_debug ("read bitmap for group %lu\n" , first_group + i); + } + +/* wait for I/O completion */ +for (i =0 ; i < groups_per_page && bh[i]; i++) +wait_on_buffer (bh[i]); + + err = -EIO ; +for (i =0 ; i < groups_per_page && bh[i]; i++) +if (!buffer_uptodate (bh[i])) + goto out; + + first_block = page->index * blocks_per_page; +for (i =0 ; i < blocks_per_page; i++) { +int group; +struct ext4_group_info *grinfo; + + group = (first_block + i) >>1 ; +if (group >=EXT4_SB (sb)->s_groups_count) +break ; + +/* +* data carry information regarding this +* particular group in the format specified +* above +* +*/ + data =page_address (page) + (i * blocksize); + bitmap = bh[group - first_group]->b_data; + +/* +* We place the buddy block and bitmap block +* close together +*/ +if ((first_block + i) &1 ) { +/* this is block of buddy */ +BUG_ON (incore ==NULL ); +mb_debug ("put buddy for group %u in page %lu/%x\n" , + group, page->index, i * blocksize); +memset (data,0xff , blocksize); + grinfo =ext4_get_group_info (sb, group); + grinfo->bb_fragments =0 ; +memset (grinfo->bb_counters,0 , +sizeof (unsigned short )*(sb->s_blocksize_bits+2 )); +/* +* incore got set to the group block bitmap below +*/ +ext4_mb_generate_buddy (sb, data, incore, group); + incore =NULL ; + }else { +/* this is block of bitmap */ +BUG_ON (incore !=NULL ); +mb_debug ("put bitmap for group %u in page %lu/%x\n" , + group, page->index, i * blocksize); + +/* see comments in ext4_mb_put_pa() */ +ext4_lock_group (sb, group); +memcpy (data, bitmap, blocksize); + +/* mark all preallocated blks used in in-core bitmap */
fs/ext4/mballoc.c line 1146
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+ext4_mb_generate_from_pa (sb, data, group); +ext4_unlock_group (sb, group); + +/* set incore so that the buddy information can be +* generated using this +*/ + incore = data; + } + } +SetPageUptodate (page);
Is the page locked here?
fs/ext4/mballoc.c line 1151
Quoted 4 lines
fs/ext4/mballoc.c new file +4
-0+out: +if (bh) { +for (i =0 ; i < groups_per_page && bh[i]; i++) +brelse (bh[i]);
put_bh()
Quoted 7 lines
fs/ext4/mballoc.c new file +6
-0+if (bh != &bhs) +kfree (bh); + } +return err; +} +
fs/ext4/mballoc.c line 1305
Quoted 10 lines
fs/ext4/mballoc.c new file +8
-0+static void mb_set_bits (spinlock_t *lock,void *bm,int cur,int len) +{ +__u32 *addr; + + len = cur + len; +while (cur < len) { +if ((cur &31 ) ==0 && (len - cur) >=32 ) { +/* fast path: clear whole word at once */
s/clear/set/
Quoted 26 lines
fs/ext4/mballoc.c new file +23
-0+ addr = bm + (cur >>3 ); + *addr =0xffffffff ; + cur +=32 ; +continue ; + } +mb_set_bit_atomic (lock, cur, bm); + cur++; + } +} + +static void ext4_mb_use_best_found (struct ext4_allocation_context *ac, +struct ext4_buddy *e4b) +{ +struct ext4_sb_info *sbi =EXT4_SB (ac->ac_sb); +int ret; + +BUG_ON (ac->ac_b_ex.fe_group != e4b->bd_group); +BUG_ON (ac->ac_status ==AC_STATUS_FOUND ); + + ac->ac_b_ex.fe_len =min (ac->ac_b_ex.fe_len, ac->ac_g_ex.fe_len); + ac->ac_b_ex.fe_logical = ac->ac_g_ex.fe_logical; + ret =mb_mark_used (e4b, &ac->ac_b_ex); +
fs/ext4/mballoc.c line 1560
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+/* preallocation can change ac_b_ex, thus we store actually +* allocated blocks for history */ + ac->ac_f_ex = ac->ac_b_ex; + + ac->ac_status =AC_STATUS_FOUND ; + ac->ac_tail = ret &0xffff ; + ac->ac_buddy = ret >>16 ; + +/* XXXXXXX: SUCH A HORRIBLE **CK */ +/*FIXME!! Why ? */
?
Quoted 41 lines
(quoted diff) +38
-0+ ac->ac_bitmap_page = e4b->bd_bitmap_page; + get_page(ac->ac_bitmap_page); + ac->ac_buddy_page = e4b->bd_buddy_page; + get_page(ac->ac_buddy_page); + + /* store last allocated for subsequent stream allocation */ + if ((ac->ac_flags & EXT4_MB_HINT_DATA)) { + spin_lock(&sbi->s_md_lock); + sbi->s_mb_last_group = ac->ac_f_ex.fe_group; + sbi->s_mb_last_start = ac->ac_f_ex.fe_start; + spin_unlock(&sbi->s_md_lock); + } +} +static void ext4_mb_generate_from_pa(struct super_block *sb, void *bitmap, + ext4_group_t group) +{ + struct ext4_group_info *grp = ext4_get_group_info(sb, group); + struct ext4_prealloc_space *pa; + struct list_head *cur; + ext4_group_t groupnr; + ext4_grpblk_t start; + int preallocated = 0; + int count = 0; + int len; + + /* all form of preallocation discards first load group, + * so the only competing code is preallocation use. + * we don't need any locking here + * notice we do NOT ignore preallocations with pa_deleted + * otherwise we could leave used blocks available for + * allocation in buddy when concurrent ext4_mb_put_pa() + * is dropping preallocation + */ + list_for_each_rcu(cur, &grp->bb_prealloc_list) { + pa = list_entry(cur, struct ext4_prealloc_space, pa_group_list); + spin_lock(&pa->pa_lock); + ext4_get_group_no_and_offset(sb, pa->pa_pstart, + &groupnr, &start);
Review
Quoted 10 lines
(quoted diff) +10
-0+ len = pa->pa_len; + spin_unlock(&pa->pa_lock); + if (unlikely(len == 0)) + continue; + BUG_ON(groupnr != group); + mb_set_bits(sb_bgl_lock(EXT4_SB(sb), group), + bitmap, start, len); + preallocated += len; + count++; + }
Seems to be missing rcu_read_lock()
fs/ext4/mballoc.c line 3489
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+mb_debug ("prellocated %u for group %lu\n" , preallocated, group); +} + +static void ext4_mb_pa_callback (struct rcu_head *head) +{ +struct ext4_prealloc_space *pa; + pa = container_of(head, struct ext4_prealloc_space, u.pa_rcu); +kmem_cache_free (ext4_pspace_cachep, pa); +} +#define mb_call_rcu (__pa) call_rcu(&(__pa)->u.pa_rcu, ext4_mb_pa_callback)
Is there any reason why this had to be implemented as a macro?
Quoted 6 lines
...
fs/ext4/mballoc.c new file +3
-0+static int ext4_mb_new_inode_pa (struct ext4_allocation_context *ac) +{ +struct super_block *sb = ac->ac_sb;
fs/ext4/mballoc.c line 3556
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+struct ext4_prealloc_space *pa; +struct ext4_group_info *grp; +struct ext4_inode_info *ei; + +/* preallocate only when found space is larger then requested */ +BUG_ON (ac->ac_o_ex.fe_len >= ac->ac_b_ex.fe_len); +BUG_ON (ac->ac_status !=AC_STATUS_FOUND ); +BUG_ON (!S_ISREG (ac->ac_inode->i_mode)); + + pa =kmem_cache_alloc (ext4_pspace_cachep,GFP_NOFS );
Do all the GFP_NOFS's in this code really need to be GFP_NOFS?
Quoted 57 lines
fs/ext4/mballoc.c new file +57
-0+if (pa ==NULL ) +return -ENOMEM ; + +if (ac->ac_b_ex.fe_len < ac->ac_g_ex.fe_len) { +int winl; +int wins; +int win; +int offs; + +/* we can't allocate as much as normalizer wants. +* so, found space must get proper lstart +* to cover original request */ +BUG_ON (ac->ac_g_ex.fe_logical > ac->ac_o_ex.fe_logical); +BUG_ON (ac->ac_g_ex.fe_len < ac->ac_o_ex.fe_len); + +/* we're limited by original request in that +* logical block must be covered any way +* winl is window we can move our chunk within */ + winl = ac->ac_o_ex.fe_logical - ac->ac_g_ex.fe_logical; + +/* also, we should cover whole original request */ + wins = ac->ac_b_ex.fe_len - ac->ac_o_ex.fe_len; + +/* the smallest one defines real window */ + win =min (winl, wins); + + offs = ac->ac_o_ex.fe_logical % ac->ac_b_ex.fe_len; +if (offs && offs < win) + win = offs; + + ac->ac_b_ex.fe_logical = ac->ac_o_ex.fe_logical - win; +BUG_ON (ac->ac_o_ex.fe_logical < ac->ac_b_ex.fe_logical); +BUG_ON (ac->ac_o_ex.fe_len > ac->ac_b_ex.fe_len); + } + +/* preallocation can change ac_b_ex, thus we store actually +* allocated blocks for history */ + ac->ac_f_ex = ac->ac_b_ex; + + pa->pa_lstart = ac->ac_b_ex.fe_logical; + pa->pa_pstart =ext4_grp_offs_to_block (sb, &ac->ac_b_ex); + pa->pa_len = ac->ac_b_ex.fe_len; + pa->pa_free = pa->pa_len; +atomic_set (&pa->pa_count,1 ); +spin_lock_init (&pa->pa_lock); + pa->pa_deleted =0 ; + pa->pa_linear =0 ; + +mb_debug ("new inode pa %p: %llu/%u for %u\n" , pa, + pa->pa_pstart, pa->pa_len, pa->pa_lstart); + +ext4_mb_use_inode_pa (ac, pa); +atomic_add (pa->pa_free, &EXT4_SB (sb)->s_mb_preallocated); + + ei =EXT4_I (ac->ac_inode); + grp =ext4_get_group_info (sb, ac->ac_b_ex.fe_group); +
fs/ext4/mballoc.c line 3623
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+ pa->pa_obj_lock = &ei->i_prealloc_lock; + pa->pa_inode = ac->ac_inode; + +ext4_lock_group (sb, ac->ac_b_ex.fe_group); +list_add_rcu (&pa->pa_group_list, &grp->bb_prealloc_list); +ext4_unlock_group (sb, ac->ac_b_ex.fe_group); + +spin_lock (pa->pa_obj_lock); +list_add_rcu (&pa->pa_inode_list, &ei->i_prealloc_list); +spin_unlock (pa->pa_obj_lock);
hm. Strange to see list_add_rcu() inside spinlock like this.
Quoted 55 lines
fs/ext4/mballoc.c new file +52
-0+return 0 ; +} + +static int ext4_mb_discard_group_preallocations (struct super_block *sb, +ext4_group_t group,int needed) +{ +struct ext4_group_info *grp =ext4_get_group_info (sb, group); +struct buffer_head *bitmap_bh =NULL ; +struct ext4_prealloc_space *pa, *tmp; +struct list_head list; +struct ext4_buddy e4b; +int err; +int busy =0 ; +int free =0 ; + +mb_debug ("discard preallocation for group %lu\n" , group); + +if (list_empty (&grp->bb_prealloc_list)) +return 0 ; + + bitmap_bh =read_block_bitmap (sb, group); +if (bitmap_bh ==NULL ) { +/* error handling here */ +ext4_mb_release_desc (&e4b); +BUG_ON (bitmap_bh ==NULL ); + } + + err =ext4_mb_load_buddy (sb, group, &e4b); +BUG_ON (err !=0 );/* error handling here */ + +if (needed ==0 ) + needed =EXT4_BLOCKS_PER_GROUP (sb) +1 ; + + grp =ext4_get_group_info (sb, group); +INIT_LIST_HEAD (&list); + +repeat: +ext4_lock_group (sb, group); +list_for_each_entry_safe (pa, tmp, + &grp->bb_prealloc_list, pa_group_list) { +spin_lock (&pa->pa_lock); +if (atomic_read (&pa->pa_count)) { +spin_unlock (&pa->pa_lock); + busy =1 ; +continue ; + } +if (pa->pa_deleted) { +spin_unlock (&pa->pa_lock); +continue ; + } + +/* seems this one can be freed ... */
fs/ext4/mballoc.c line 3858
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+ pa->pa_deleted =1 ; + +/* we can trust pa_free ... */ + free += pa->pa_free; + +spin_unlock (&pa->pa_lock); + +list_del_rcu (&pa->pa_group_list); +list_add (&pa->u.pa_tmp_list, &list); + }
Strange to see rcu operations outside rcu_read_lock().
fs/ext4/mballoc.c line 3868
Quoted 9 lines
fs/ext4/mballoc.c new file +9
-0+/* if we still need more blocks and some PAs were used, try again */ +if (free < needed && busy) { + busy =0 ; +ext4_unlock_group (sb, group); +/* +* Yield the CPU here so that we don't get soft lockup +* in non preempt case. +*/ +yield ();
argh, no, yield() is basically unusable. schedule_timeout(1) is preferable.
Please test this code whe there are lots of cpu-intensive tasks running.
Quoted 20 lines
fs/ext4/mballoc.c new file +20
-0+ goto repeat; + } + +/* found anything to free? */ +if (list_empty (&list)) { +BUG_ON (free !=0 ); + goto out; + } + +/* now free all selected PAs */ +list_for_each_entry_safe (pa, tmp, &list, u.pa_tmp_list) { + +/* remove from object (inode or locality group) */ +spin_lock (pa->pa_obj_lock); +list_del_rcu (&pa->pa_inode_list); +spin_unlock (pa->pa_obj_lock); + +if (pa->pa_linear) +ext4_mb_release_group_pa (&e4b, pa); +else
fs/ext4/mballoc.c line 3898
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+ext4_mb_release_inode_pa (&e4b, bitmap_bh, pa); + +list_del (&pa->u.pa_tmp_list); +mb_call_rcu (pa); + } + +out: +ext4_unlock_group (sb, group); +ext4_mb_release_desc (&e4b); +brelse (bitmap_bh);
put_bh()
Quoted 37 lines
fs/ext4/mballoc.c new file +37
-0+return free; +} + +/* +* releases all non-used preallocated blocks for given inode +* +* It's important to discard preallocations under i_data_sem +* We don't want another block to be served from the prealloc +* space when we are discarding the inode prealloc space. +* +* FIXME!! Make sure it is valid at all the call sites +*/ +void ext4_mb_discard_inode_preallocations (struct inode *inode) +{ +struct ext4_inode_info *ei =EXT4_I (inode); +struct super_block *sb = inode->i_sb; +struct buffer_head *bitmap_bh =NULL ; +struct ext4_prealloc_space *pa, *tmp; +ext4_group_t group =0 ; +struct list_head list; +struct ext4_buddy e4b; +int err; + +if (!test_opt (sb,MBALLOC ) || !S_ISREG (inode->i_mode)) { +/*BUG_ON(!list_empty(&ei->i_prealloc_list));*/ +return ; + } + +mb_debug ("discard preallocation for inode %lu\n" , inode->i_ino); + +INIT_LIST_HEAD (&list); + +repeat: +/* first, collect all pa's in the inode */ +spin_lock (&ei->i_prealloc_lock); +while (!list_empty (&ei->i_prealloc_list)) { + pa = list_entry(ei->i_prealloc_list.next,
fs/ext4/mballoc.c line 3945
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+ struct ext4_prealloc_space, pa_inode_list); +BUG_ON (pa->pa_obj_lock != &ei->i_prealloc_lock); +spin_lock (&pa->pa_lock); +if (atomic_read (&pa->pa_count)) { +/* this shouldn't happen often - nobody should +* use preallocation while we're discarding it */ +spin_unlock (&pa->pa_lock); +spin_unlock (&ei->i_prealloc_lock); +printk (KERN_ERR "uh-oh! used pa while discarding\n" ); +dump_stack ();
WARN_ON(1) would be more conventional.
Review
Quoted 2 lines
(quoted diff) +2
-0+ current->state = TASK_UNINTERRUPTIBLE; + schedule_timeout(HZ);
schedule_timeout_uninterruptible()
Quoted 19 lines
fs/ext4/mballoc.c new file +19
-0+ goto repeat; + + } +if (pa->pa_deleted ==0 ) { + pa->pa_deleted =1 ; +spin_unlock (&pa->pa_lock); +list_del_rcu (&pa->pa_inode_list); +list_add (&pa->u.pa_tmp_list, &list); +continue ; + } + +/* someone is deleting pa right now */ +spin_unlock (&pa->pa_lock); +spin_unlock (&ei->i_prealloc_lock); + +/* we have to wait here because pa_deleted +* doesn't mean pa is already unlinked from +* the list. as we might be called from +* ->clear_inode() the inode will get freed
fs/ext4/mballoc.c line 3976
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+* and concurrent thread which is unlinking +* pa from inode's list may access already +* freed memory, bad-bad-bad */ + +/* XXX: if this happens too often, we can +* add a flag to force wait only in case +* of ->clear_inode(), but not in case of +* regular truncate */ + current->state =TASK_UNINTERRUPTIBLE ; +schedule_timeout (HZ );
ditto
Quoted 20 lines
fs/ext4/mballoc.c new file +20
-0+ goto repeat; + } +spin_unlock (&ei->i_prealloc_lock); + +list_for_each_entry_safe (pa, tmp, &list, u.pa_tmp_list) { +BUG_ON (pa->pa_linear !=0 ); +ext4_get_group_no_and_offset (sb, pa->pa_pstart, &group,NULL ); + + err =ext4_mb_load_buddy (sb, group, &e4b); +BUG_ON (err !=0 );/* error handling here */ + + bitmap_bh =read_block_bitmap (sb, group); +if (bitmap_bh ==NULL ) { +/* error handling here */ +ext4_mb_release_desc (&e4b); +BUG_ON (bitmap_bh ==NULL ); + } + +ext4_lock_group (sb, group); +list_del_rcu (&pa->pa_group_list);
fs/ext4/mballoc.c line 4006
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+ext4_mb_release_inode_pa (&e4b, bitmap_bh, pa); +ext4_unlock_group (sb, group); + +ext4_mb_release_desc (&e4b); +brelse (bitmap_bh); + +list_del (&pa->u.pa_tmp_list); +mb_call_rcu (pa); + } +}
Would be nice to ask Paul to review all the rcu usage in here. It looks odd.
fs/ext4/mballoc.c line 4074
Quoted 6 lines
...
fs/ext4/mballoc.c new file +3
-0+#else +#define ext4_mb_show_ac (x) +#endif
static inlined C functions are preferred (+1e6 dittoes)
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+/* +* We use locality group preallocation for small size file. The size of the +* file is determined by the current size or the resulting size after +* allocation which ever is larger +* +* One can tune this size via /proc/fs/ext4/<partition>/stream_req +*/ +static void ext4_mb_group_or_file (struct ext4_allocation_context *ac) +{ +struct ext4_sb_info *sbi =EXT4_SB (ac->ac_sb);
fs/ext4/mballoc.c line 4095
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+int bsbits = ac->ac_sb->s_blocksize_bits; +loff_t size, isize; + +if (!(ac->ac_flags &EXT4_MB_HINT_DATA )) +return ; + + size = ac->ac_o_ex.fe_logical + ac->ac_o_ex.fe_len; + isize =i_size_read (ac->ac_inode) >> bsbits; +if (size < isize) + size = isize;
min()?
fs/ext4/mballoc.c line 4106
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+/* don't use group allocation for large files */ +if (size >= sbi->s_mb_stream_request) +return ; + +if (unlikely (ac->ac_flags &EXT4_MB_HINT_GOAL_ONLY )) +return ; + +BUG_ON (ac->ac_lg !=NULL ); + ac->ac_lg = &sbi->s_locality_groups[get_cpu ()]; +put_cpu ();
Strange-looking code. I'd be interested in a description of the per-cou design here.
fs/ext4/mballoc.c line 4112
Quoted 5 lines
fs/ext4/mballoc.c new file +5
-0+/* we're going to use group allocation */ + ac->ac_flags |=EXT4_MB_HINT_GROUP_ALLOC ; + +/* serialize all allocations in the group */ +down (&ac->ac_lg->lg_sem);
This should be a mutex, shouldn't it?
Quoted 18 lines
fs/ext4/mballoc.c new file +15
-0+} + +static int ext4_mb_free_metadata (handle_t *handle,struct ext4_buddy *e4b, +ext4_group_t group,ext4_grpblk_t block,int count) +{ +struct ext4_group_info *db = e4b->bd_info; +struct super_block *sb = e4b->bd_sb; +struct ext4_sb_info *sbi =EXT4_SB (sb); +struct ext4_free_metadata *md; +int i; + +BUG_ON (e4b->bd_bitmap_page ==NULL ); +BUG_ON (e4b->bd_buddy_page ==NULL ); + +ext4_lock_group (sb, group);
fs/ext4/mballoc.c line 4361
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+for (i =0 ; i < count; i++) { + md = db->bb_md_cur; +if (md && db->bb_tid != handle->h_transaction->t_tid) { + db->bb_md_cur =NULL ; + md =NULL ; + } + +if (md ==NULL ) { +ext4_unlock_group (sb, group); + md =kmalloc (sizeof (*md),GFP_KERNEL );
Why was this one not GFP_NOFS?
fs/ext4/mballoc.c line 4363
Quoted 2 lines
fs/ext4/mballoc.c new file +2
-0+if (md ==NULL ) +return -ENOMEM ;
Did we just leak some memory?
Quoted 42 lines
fs/ext4/mballoc.c new file +39
-0+ md->num =0 ; + md->group = group; + +ext4_lock_group (sb, group); +if (db->bb_md_cur ==NULL ) { +spin_lock (&sbi->s_md_lock); +list_add (&md->list, &sbi->s_active_transaction); +spin_unlock (&sbi->s_md_lock); +/* protect buddy cache from being freed, +* otherwise we'll refresh it from +* on-disk bitmap and lose not-yet-available +* blocks */ +page_cache_get (e4b->bd_buddy_page); +page_cache_get (e4b->bd_bitmap_page); + db->bb_md_cur = md; + db->bb_tid = handle->h_transaction->t_tid; +mb_debug ("new md 0x%p for group %lu\n" , + md, md->group); + }else { +kfree (md); + md = db->bb_md_cur; + } + } + +BUG_ON (md->num >=EXT4_BB_MAX_BLOCKS ); + md->blocks[md->num] = block + i; + md->num++; +if (md->num ==EXT4_BB_MAX_BLOCKS ) { +/* no more space, put full container on a sb's list */ + db->bb_md_cur =NULL ; + } + } +ext4_unlock_group (sb, group); +return 0 ; +} + +case Opt_mballoc: +set_opt (sbi->s_mount_opt,MBALLOC ); +break ;
fs/ext4/mballoc.c
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+case Opt_nomballoc: +clear_opt (sbi->s_mount_opt,MBALLOC ); +break ; +case Opt_stripe: +if (match_int (&args[0 ], &option)) +return 0 ; +if (option <0 ) +return 0 ; + sbi->s_stripe = option; +break ;
These appear to be undocumented.
Quoted 21 lines
fs/ext4/super.c +14
-0default :printk (KERN_ERR "EXT4-fs: Unrecognized mount option \"%s\" "@@ -1742,6 +1762,33 @@ static ext4_fsblk_t descriptor_loc(struct super_block *sb,return (has_super +ext4_group_first_block_no (sb, bg)); } +/** +* ext4_get_stripe_size: Get the stripe size. +* @sbi: In memory super block info +* +* If we have specified it via mount option, then +* use the mount option value. If the value specified at mount time is +* greater than the blocks per group use the super block value. +* If the super block value is greater than blocks per group return 0. +* Allocator needs it be less than blocks per group. +* +*/ +static unsigned long ext4_get_stripe_size (struct ext4_sb_info *sbi) +{ +unsigned long stride =le16_to_cpu (sbi->s_es->s_raid_stride);
fs/ext4/super.c static ext4_fsblk_t descriptor_loc(struct super_block *sb, · line 1788
Quoted 10 lines
fs/ext4/super.c +10
-0+unsigned long stripe_width = +le32_to_cpu (sbi->s_es->s_raid_stripe_width); + +if (sbi->s_stripe && sbi->s_stripe <= sbi->s_blocks_per_group) { +return sbi->s_stripe; + }else if (stripe_width <= sbi->s_blocks_per_group) { +return stripe_width; + }else if (stride <= sbi->s_blocks_per_group) { +return stride; + }
unneeded braces.
Quoted 6 lines
include/linux/ext4_fs.h +3
-0+return 0 ; +} +static inline
include/linux/ext4_fs.h static inline void ext4_isize_set(struct ext4_inode *raw_inode, loff_t i_size) · line 1154
Quoted 10 lines
include/linux/ext4_fs.h +10
-0+struct ext4_group_info *ext4_get_group_info (struct super_block *sb, +ext4_group_t group) +{ +struct ext4_group_info ***grp_info; +long indexv, indexh; + grp_info =EXT4_SB (sb)->s_group_info; + indexv = group >> (EXT4_DESC_PER_BLOCK_BITS (sb)); + indexh = group & ((EXT4_DESC_PER_BLOCK (sb)) -1 ); +return grp_info[indexv][indexh]; +}
This should be uninlined.
Gosh what a lot of code. Is it faster?
Andrew Morton
maintainerRe: [PATCH 36/49] ext4: Add EXT4_IOC_MIGRATE ioctl
In reply to Theodore Ts'oQuoted 3 lines · On Mon, 21 Jan 2008 22:02:15 -0500 "Theodore Ts'o" <[email protected]> wrote:
The below patch add ioctl for migrating ext3 indirect block mapped inode to ext4 extent mapped inode.
This patch adds lots of weird and inexplicable single- and double-newlines in inappropriate places. However it frequently forgets to add newlines between end-of-locals and start-of-code, which is usual practice.
+struct list_blocks_struct {
+ ext4_lblk_t first_block, last_block;
+ ext4_fsblk_t first_pblock, last_pblock;
+};
This structure would benefit from some code comments.
Re: [PATCH 33/49] ext4: Add the journal checksum feature
In reply to Andrew MortonQuoted 6 lines · Andrew Morton
Quoted 6 lines
fs/jbd2/commit.c +6
-0+{ +struct page *page = bh->b_page; +char *addr; +__u32 checksum; + + addr =kmap_atomic (page,KM_USER0 );
Quoted 8 lines
fs/jbd2/commit.c write_out_data: · line 365
Quoted 6 lines
fs/jbd2/commit.c +6
-0+ checksum =crc32_be (crc32_sum, + (void *)(addr +offset_in_page (bh->b_data)), bh->b_size); +kunmap_atomic (addr,KM_USER0 ); + +return checksum; +}Can this buffer actually be in highmem?
Yes, this was found during system testing. While ext3/4 will only allocate buffer heads in lowmem, the jbd/jbd2 code can allocate buffers in highmem. I was surprised about this also.
Please see the thread in ext4-devel:
[PATCH][RFC]JBD2: Fix journal checksum kernel oops on NUMA
Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.
Re: [PATCH 41/49] ext4: Add multi block allocator for ext4
In reply to Andrew MortonQuoted 7 lines · Andrew Morton
fs/ext4/mballoc.c line 637
Quoted 5 lines
fs/ext4/mballoc.c new file +5
-0+#define mb_correct_addr_and_bit (bit, addr) \ +{ \ + bit += ((unsigned long) addr & 3UL) << 3; \ + addr = (void *) ((unsigned long) addr & ~3UL); \ +}Why do these exist?
They seem to be a holdover from when mballoc stored the buddy bitmaps on disk. That no longer happens (to avoid bitmap vs. buddy consistency problems), so I suspect they can be removed.
I can't comment on many of the other issues because Alex wrote most of the code.
Quoted 1 line
Gosh what a lot of code. Is it faster?
Yes, and also importantly it uses a lot less CPU to do a given amount of allocation, which is critical in our environments where there is very high disk bandwidth on a single node and CPU becomes the limiting factor of the IO speed. This of course also helps any write-intensive environment where the CPU is doing something "useful".
Some older test results include:
https://ols2006.108.redhat.com/2007/Reprints/mathur-Reprint.pdf (Section 7)
In the linux-ext4 thread "compilebench numbers for ext4":
http://www.mail-archive.com/[email protected]/msg03834.html
http://oss.oracle.com/~mason/compilebench/ext4/ext-create-compare.png
http://oss.oracle.com/~mason/compilebench/ext4/ext-compile-compare.png
http://oss.oracle.com/~mason/compilebench/ext4/ext-read-compare.png
http://oss.oracle.com/~mason/compilebench/ext4/ext-rm-compare.png
note the ext-read-compare.png graph shows lower read performance, but a couple of bugs in mballoc were since fixed to have ext4 allocate more contiguous extents.
In the old linux-ext4 thread "[RFC] delayed allocation testing on node zefir"
http://www.mail-archive.com/[email protected]/msg00587.html
: dd2048rw
: REAL UTIME STIME READ WRITTEN DETAILS
EXT3 : 58.46 23 1491 2572 2097292 17 extents
EXT4 : 44.56 19 1018 12 2097244 19 extents
REISERFS: 56.80 26 1370 2952 2097336 457 extents
JFS : 45.77 22 984 0 2097216 1 extents
XFS : 50.97 20 1394 0 2100825 7 extents
: kernuntar
: REAL UTIME STIME READ WRITTEN DETAILS
EXT3 : 56.99 5037 651 68 252016
EXT4 : 55.03 5034 553 36 249884
REISERFS: 52.55 4996 854 64 238068
JFS : 70.15 5057 630 496 288116
XFS : 72.84 5052 953 132 316798
: kernstat
: REAL UTIME STIME READ WRITTEN DETAILS
EXT3 : 2.83 8 15 5892 0
EXT4 : 0.51 9 10 5892 0
REISERFS: 0.81 7 49 2696 0
JFS : 6.19 11 49 12552 0
XFS : 2.09 9 61 6504 0
: kerncat
: REAL UTIME STIME READ WRITTEN DETAILS
EXT3 : 9.48 25 213 241624 0
EXT4 : 6.29 27 197 238560 0
REISERFS: 14.69 33 230 234744 0
JFS : 23.51 23 231 244596 0
XFS : 18.24 36 254 238548 0
: kernrm
: REAL UTIME STIME READ WRITTEN DETAILS
EXT3 : 4.82 4 108 9628 4672
EXT4 : 1.61 5 110 6536 4632
REISERFS: 3.15 8 276 2768 236
JFS : 33.90 7 168 14400 33048
XFS : 20.03 8 296 6632 86160
Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.
Re: [PATCH 23/49] Add buffer head related helper functions
In reply to Andrew MortonQuoted 31 lines · Andrew Morton
Review
Quoted 4 lines · On Mon, 21 Jan 2008 22:02:02 -0500 "Theodore Ts'o" <[email protected]> wrote:
(quoted diff) +3
-0+} +EXPORT_SYMBOL(bh_uptodate_or_lock); +/**Missing newline.
Review
Quoted 12 lines
+ *
bh_submit_read: Submit a locked buffer for reading
+ * @bh: structbuffer_head
+ *
+ * Returns a negative error
+ */(quoted diff) +7
-0+int bh_submit_read(struct buffer_head *bh) +{ + if (!buffer_locked(bh)) + lock_buffer(bh); + + if (buffer_uptodate(bh)) + return 0;Here it can lock the buffer then return zero
Review
Quoted 6 lines
(quoted diff) +6
-0+ get_bh(bh); + bh->b_end_io = end_buffer_read_sync; + submit_bh(READ, bh); + wait_on_buffer(bh); + if (buffer_uptodate(bh)) + return 0;Here it will unlock the buffer and return zero.
Quoted 2 lines
This function is unusable when passed an unlocked buffer.
Updated patch below.
commit 70d4ca32604e0935a8b9a49c5ac8b9c64c810693
Author: Aneesh Kumar K.V <[email protected]> Date: Thu Jan 24 10:50:24 2008 +0530
Add buffer head related helper functions
Add buffer head related helper function bh_uptodate_or_lock and bh_submit_read which can be used by file system
fs/buffer.c +47 -0
@@ -3213,6 +3213,53 @@ static int buffer_cpu_notify(struct notifier_block *self,return NOTIFY_OK ; } +/** +* bh_uptodate_or_lock: Test whether the buffer is uptodate +* @bh: struct buffer_head +* +* Return true if the buffer is up-to-date and false, +* with the buffer locked, if not. +*/ +int bh_uptodate_or_lock (struct buffer_head *bh) +{ +if (!buffer_uptodate (bh)) { +lock_buffer (bh); +if (!buffer_uptodate (bh)) +return 0 ; +unlock_buffer (bh); + } +return 1 ; +} +EXPORT_SYMBOL (bh_uptodate_or_lock); + +/** +* bh_submit_read: Submit a locked buffer for reading +* @bh: struct buffer_head +* +* Returns zero on success and -EIO on error.If the input +* buffer is not locked returns -EINVAL +* +*/ +int bh_submit_read (struct buffer_head *bh) +{ +if (!buffer_locked (bh)) +return -EINVAL ; + +if (buffer_uptodate (bh)) { +unlock_buffer (bh); +return 0 ; + } + +get_bh (bh); + bh->b_end_io = end_buffer_read_sync; +submit_bh (READ , bh); +wait_on_buffer (bh); +if (buffer_uptodate (bh)) +return 0 ; +return -EIO ; +} +EXPORT_SYMBOL (bh_submit_read); +void __init buffer_init (void ) {int nrpages;
include/linux/buffer_head.h +2 -0
@@ -192,6 +192,8 @@ int sync_dirty_buffer(struct buffer_head *bh);int submit_bh (int ,struct buffer_head *);void write_boundary_block (struct block_device *bdev,sector_t bblock,unsigned blocksize); +int bh_uptodate_or_lock (struct buffer_head *bh); +int bh_submit_read (struct buffer_head *bh);extern int buffer_heads_over_limit;
Re: [PATCH 30/49] ext4: Convert truncate_mutex to read write semaphore.
In reply to Andrew MortonQuoted 18 lines · Andrew Morton
Quoted 18 lines · On Mon, 21 Jan 2008 22:02:09 -0500 "Theodore Ts'o" <[email protected]> wrote:
fs/ext4/inode.c +17
-0+int ext4_get_blocks_wrap (handle_t *handle,struct inode *inode,sector_t block, +unsigned long max_blocks,struct buffer_head *bh, +int create,int extend_disksize) +{ +int retval; +if (create) { +down_write ((&EXT4_I (inode)->i_data_sem)); + }else { +down_read ((&EXT4_I (inode)->i_data_sem)); + } +if (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) { + retval =ext4_ext_get_blocks (handle, inode, block, max_blocks, + bh, create, extend_disksize); + }else { + retval =ext4_get_blocks_handle (handle, inode, block, + max_blocks, bh, create, extend_disksize); + }
Quoted 8 lines
fs/ext4/inode.c out: · line 920
Quoted 5 lines
fs/ext4/inode.c +5
-0+if (create) { +up_write ((&EXT4_I (inode)->i_data_sem)); + }else { +up_read ((&EXT4_I (inode)->i_data_sem)); + }This function has many unneeded braces. checkpatch used to detect this but it seems to have broken.
The follow up patch "ext4: Take read lock during overwrite case" removes those single line if statement.
Quoted 7 lines
fs/ext4/inode.c out: · line 924
Quoted 5 lines
fs/ext4/inode.c +2
-0+return retval; +}static int ext4_get_block (struct inode *inode,sector_t iblock,struct buffer_head *bh_result,int create)Mising newline.
Fixed.
-aneesh
Re: [PATCH 36/49] ext4: Add EXT4_IOC_MIGRATE ioctl
In reply to Andrew MortonQuoted 10 lines · Andrew Morton
Quoted 3 lines · On Mon, 21 Jan 2008 22:02:15 -0500 "Theodore Ts'o" <[email protected]> wrote:
The below patch add ioctl for migrating ext3 indirect block mapped inode to ext4 extent mapped inode.
This patch adds lots of weird and inexplicable single- and double-newlines in inappropriate places. However it frequently forgets to add newlines between end-of-locals and start-of-code, which is usual practice.
Review
Quoted 4 lines
(quoted diff) +4
-0+struct list_blocks_struct { + ext4_lblk_t first_block, last_block; + ext4_fsblk_t first_pblock, last_pblock; +};
Updated patch
commit c4786b67cdc5b24d2548a69b62774fb54f8f1575
Author: Aneesh Kumar K.V <[email protected]> Date: Tue Jan 22 09:28:55 2008 +0530
ext4: Add EXT4_IOC_MIGRATE ioctl
The below patch add ioctl for migrating ext3 indirect block mapped inode to ext4 extent mapped inode.
fs/ext4/Makefile +1 -1
@@ -6,7 +6,7 @@ obj-$(CONFIG_EXT4DEV_FS) += ext4dev.o ext4dev-y := balloc.o bitmap.o dir.o file.o fsync.o ialloc.o inode.o \ ioctl.o namei.o super.o symlink.o hash.o resize.o extents.o \ - ext4_jbd2.o + ext4_jbd2.o migrate.o ext4dev-$(CONFIG_EXT4DEV_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o ext4dev-$(CONFIG_EXT4DEV_FS_POSIX_ACL) += acl.o
fs/ext4/extents.c +1 -1
@@ -75,7 +75,7 @@ static ext4_fsblk_t idx_pblock(struct ext4_extent_idx *ix)* stores a large physical block number into an extent struct, * breaking it into parts */ -static void ext4_ext_store_pblock (struct ext4_extent *ex,ext4_fsblk_t pb) +void ext4_ext_store_pblock (struct ext4_extent *ex,ext4_fsblk_t pb) { ex->ee_start_lo =cpu_to_le32 ((unsigned long ) (pb &0xffffffff )); ex->ee_start_hi =cpu_to_le16 ((unsigned long ) ((pb >>31 ) >>1 ) &0xffff );
fs/ext4/ioctl.c +3 -0
@@ -254,6 +254,9 @@ flags_err:return err; } +case EXT4_IOC_MIGRATE : +return ext4_ext_migrate (inode, filp, cmd, arg); +default :return -ENOTTY ; }
fs/ext4/migrate.c new file +588 -0
588 lines not on this page · raw message
include/linux/ext4_fs.h +4 -0
@@ -243,6 +243,7 @@ struct ext4_new_group_data {#endif #define EXT4_IOC_GETRSVSZ _IOR('f', 5, long)#define EXT4_IOC_SETRSVSZ _IOW('f', 6, long) +#define EXT4_IOC_MIGRATE _IO('f', 7)/* * ioctl commands in 32 bit emulation
@@ -983,6 +984,9 @@ extern int ext4_ioctl (struct inode *, struct file *, unsigned int, unsigned long);extern long ext4_compat_ioctl (struct file *,unsigned int ,unsigned long ); +/* migrate.c */ +extern int ext4_ext_migrate (struct inode *,struct file *,unsigned int , +unsigned long );/* namei.c */ extern int ext4_orphan_add (handle_t *,struct inode *);extern int ext4_orphan_del (handle_t *,struct inode *);
include/linux/ext4_fs_extents.h +1 -0
@@ -212,6 +212,7 @@ static inline int ext4_ext_get_actual_len(struct ext4_extent *ext) (le16_to_cpu(ext->ee_len) - EXT_INIT_MAX_LEN)); } +extern void ext4_ext_store_pblock (struct ext4_extent *,ext4_fsblk_t );extern int ext4_extent_tree_init (handle_t *,struct inode *);extern int ext4_ext_calc_credits_for_insert (struct inode *,struct ext4_ext_path *); extern int ext4_ext_try_to_merge(struct inode *inode,
Re: [PATCH 41/49] ext4: Add multi block allocator for ext4
In reply to Andrew MortonQuoted 20 lines · Andrew Morton
Quoted 20 lines · On Mon, 21 Jan 2008 22:02:20 -0500 "Theodore Ts'o" <[email protected]> wrote:
From: Alex Tomas <[email protected]>
Signed-off-by Alex Tomas <[email protected]>Signed-off-by Andreas Dilger <[email protected]>Signed-off-by Aneesh Kumar K.V <[email protected]>Signed-off-by Eric Sandeen <[email protected]>Signed-off-by "Theodore Ts'o" <[email protected]>...
fs/ext4/mballoc.c new file +9
-0+#if BITS_PER_LONG ==64 +#define mb_correct_addr_and_bit (bit, addr) \ +{ \ + bit += ((unsigned long) addr & 7UL) << 3; \ + addr = (void *) ((unsigned long) addr & ~7UL); \ +} +#elif BITS_PER_LONG ==32 +#define mb_correct_addr_and_bit (bit, addr) \ +{ \
Quoted 8 lines
fs/ext4/mballoc.c line 640
Quoted 6 lines
fs/ext4/mballoc.c new file +6
-0+ bit += ((unsigned long ) addr &3UL ) <<3 ; \ + addr = (void *) ((unsigned long) addr & ~3UL); \ +} +#else +#error "how many bits you are?!" +#endif Why do these exist?
Initial version on mballoc supported on x86 32 this was there to give compile warning on 64 bit platform. I guess we can remove that now. Or may be we can keep it as such because it is harmless.
Quoted 11 lines
fs/ext4/mballoc.c line 646
Quoted 6 lines
fs/ext4/mballoc.c new file +5
-0+static inline int mb_test_bit (int bit,void *addr) +{ +mb_correct_addr_and_bit (bit, addr); +return ext4_test_bit (bit, addr); +}
ext2_test_bit()already handles bitnum > wordsize.If
mb_correct_addr_and_bit()is actually needed then some suitable comment would help.
ext4_test_bit on powerpc needs the addr to be 8 byte aligned. Othewise it fails
Quoted 20 lines
Quoted 20 lines
fs/ext4/mballoc.c new file +19
-0+static inline void mb_set_bit (int bit,void *addr) +{ +mb_correct_addr_and_bit (bit, addr); +ext4_set_bit (bit, addr); +} + +static inline void mb_set_bit_atomic (spinlock_t *lock,int bit,void *addr) +{ +mb_correct_addr_and_bit (bit, addr); +ext4_set_bit_atomic (lock, bit, addr); +} + +static inline void mb_clear_bit (int bit,void *addr) +{ +mb_correct_addr_and_bit (bit, addr); +ext4_clear_bit (bit, addr); +} + +static inline void mb_clear_bit_atomic (spinlock_t *lock,int bit,void *addr)
Quoted 8 lines
fs/ext4/mballoc.c line 672
Quoted 6 lines
fs/ext4/mballoc.c new file +6
-0+{ +mb_correct_addr_and_bit (bit, addr); +ext4_clear_bit_atomic (lock, bit, addr); +} + +static inline void *mb_find_buddy (struct ext4_buddy *e4b,int order,int *max)uninlining this will save about eighty squigabytes of text.
Fixed
Quoted 30 lines
Please review all of ext4/jbd2 with a view to removig unnecessary and wrong inlings.
Quoted 26 lines
fs/ext4/mballoc.c new file +23
-0+{ +char *bb; + +/* FIXME!! is this needed */ +BUG_ON (EXT4_MB_BITMAP (e4b) ==EXT4_MB_BUDDY (e4b)); +BUG_ON (max ==NULL ); + +if (order > e4b->bd_blkbits +1 ) { + *max =0 ; +return NULL ; + } + +/* at order 0 we see each particular block */ + *max =1 << (e4b->bd_blkbits +3 ); +if (order ==0 ) +return EXT4_MB_BITMAP (e4b); + + bb =EXT4_MB_BUDDY (e4b) +EXT4_SB (e4b->bd_sb)->s_mb_offsets[order]; + *max =EXT4_SB (e4b->bd_sb)->s_mb_maxs[order]; + +return bb; +} +
Quoted 9 lines
fs/ext4/mballoc.c line 758
Quoted 5 lines
fs/ext4/mballoc.c new file +5
-0+#else +#define mb_free_blocks_double (a, b, c, d) +#define mb_mark_used_double (a, b, c) +#define mb_cmp_bitmaps (a, b) +#endif Please use the do{}while(0) thing. Or, better, proper C functions which have typechecking (unless this will cause undefined-var compile errors, which happens sometimes)
makde static inline void.
Quoted 14 lines
Quoted 14 lines
fs/ext4/mballoc.c new file +13
-0+/* find most significant bit */ +static int fmsb (unsigned short word) +{ +int order; + +if (word >255 ) { + order =7 ; + word >>=8 ; + }else { + order =-1 ; + } + + do {
Quoted 8 lines
fs/ext4/mballoc.c line 898
Quoted 6 lines
fs/ext4/mballoc.c new file +6
-0+ order++; + word >>=1 ; + }while (word !=0 ); + +return order; +}Did we just reinvent
fls()?
replaced by fls.
Quoted 72 lines
Quoted 5 lines
fs/ext4/mballoc.c new file +4
-0+/* FIXME!! need more doc */ +static void ext4_mb_mark_free_simple (struct super_block *sb, +void *buddy,unsigned first,int len, +struct ext4_group_info *grp)fs/ext4/mballoc.c line 913
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+{ +struct ext4_sb_info *sbi =EXT4_SB (sb); +unsigned short min; +unsigned short max; +unsigned short chunk; +unsigned short border; + +BUG_ON (len >=EXT4_BLOCKS_PER_GROUP (sb)); + + border =2 << sb->s_blocksize_bits;Won't this explode with >= 32k blocksize?
Quoted 54 lines
fs/ext4/mballoc.c new file +51
-0+while (len >0 ) { +/* find how many blocks can be covered since this position */ + max =ffs (first | border) -1 ; + +/* find how many blocks of power 2 we need to mark */ + min =fmsb (len); + +if (max < min) + min = max; + chunk =1 << min; + +/* mark multiblock chunks only */ + grp->bb_counters[min]++; +if (min >0 ) +mb_clear_bit (first >> min, + buddy + sbi->s_mb_offsets[min]); + + len -= chunk; + first += chunk; + } +} + +static int ext4_mb_init_cache (struct page *page,char *incore) +{ +int blocksize; +int blocks_per_page; +int groups_per_page; +int err =0 ; +int i; +ext4_group_t first_group; +int first_block; +struct super_block *sb; +struct buffer_head *bhs; +struct buffer_head **bh; +struct inode *inode; +char *data; +char *bitmap; + +mb_debug ("init page %lu\n" , page->index); + + inode = page->mapping->host; + sb = inode->i_sb; + blocksize =1 << inode->i_blkbits; + blocks_per_page =PAGE_CACHE_SIZE / blocksize; + + groups_per_page = blocks_per_page >>1 ; +if (groups_per_page ==0 ) + groups_per_page =1 ; + +/* allocate buffer_heads to read bitmaps */ +if (groups_per_page >1 ) {
Quoted 8 lines
fs/ext4/mballoc.c line 1035
Quoted 6 lines
fs/ext4/mballoc.c new file +6
-0+ err = -ENOMEM ; + i =sizeof (struct buffer_head *) * groups_per_page; + bh =kmalloc (i,GFP_NOFS ); +if (bh ==NULL ) + goto out; +memset (bh,0 , i);
kzalloc()
Fixed
Quoted 25 lines
Quoted 25 lines
fs/ext4/mballoc.c new file +24
-0+ }else + bh = &bhs; + + first_group = page->index * blocks_per_page /2 ; + +/* read all groups the page covers into the cache */ +for (i =0 ; i < groups_per_page; i++) { +struct ext4_group_desc *desc; + +if (first_group + i >=EXT4_SB (sb)->s_groups_count) +break ; + + err = -EIO ; + desc =ext4_get_group_desc (sb, first_group + i,NULL ); +if (desc ==NULL ) + goto out; + + err = -ENOMEM ; + bh[i] =sb_getblk (sb,ext4_block_bitmap (sb, desc)); +if (bh[i] ==NULL ) + goto out; + +if (buffer_uptodate (bh[i])) +continue ;
Quoted 9 lines
fs/ext4/mballoc.c line 1065
Quoted 6 lines
fs/ext4/mballoc.c new file +6
-0+ +lock_buffer (bh[i]); +if (buffer_uptodate (bh[i])) { +unlock_buffer (bh[i]); +continue ; + }Didn't we just add a helper in
fs/buffer.cto do this?
Fixed
Quoted 9 lines
Quoted 9 lines
fs/ext4/mballoc.c new file +9
-0+if (desc->bg_flags &cpu_to_le16 (EXT4_BG_BLOCK_UNINIT )) { +ext4_init_block_bitmap (sb, bh[i], + first_group + i, desc); +set_buffer_uptodate (bh[i]); +unlock_buffer (bh[i]); +continue ; + } +get_bh (bh[i]); + bh[i]->b_end_io = end_buffer_read_sync;
[... snip... ]
Quoted 10 lines
fs/ext4/mballoc.c line 1146
Quoted 8 lines
fs/ext4/mballoc.c new file +8
-0+ +/* set incore so that the buddy information can be +* generated using this +*/ + incore = data; + } + } +SetPageUptodate (page);Is the page locked here?
The page is locked via find_or_create_page
Quoted 17 lines
fs/ext4/mballoc.c line 1151
Quoted 5 lines
fs/ext4/mballoc.c new file +4
-0+out: +if (bh) { +for (i =0 ; i < groups_per_page && bh[i]; i++) +brelse (bh[i]);
put_bh()Quoted 9 lines
fs/ext4/mballoc.c new file +6
-0+if (bh != &bhs) +kfree (bh); + } +return err; +} +
Quoted 10 lines
fs/ext4/mballoc.c line 1305
Quoted 8 lines
fs/ext4/mballoc.c new file +8
-0+static void mb_set_bits (spinlock_t *lock,void *bm,int cur,int len) +{ +__u32 *addr; + + len = cur + len; +while (cur < len) { +if ((cur &31 ) ==0 && (len - cur) >=32 ) { +/* fast path: clear whole word at once */ s/clear/set/
Fixed
Quoted 43 lines
Quoted 43 lines
fs/ext4/mballoc.c new file +39
-0+ addr = bm + (cur >>3 ); + *addr =0xffffffff ; + cur +=32 ; +continue ; + } +mb_set_bit_atomic (lock, cur, bm); + cur++; + } +} + +static void ext4_mb_generate_from_pa (struct super_block *sb,void *bitmap, +ext4_group_t group) +{ +struct ext4_group_info *grp =ext4_get_group_info (sb, group); +struct ext4_prealloc_space *pa; +struct list_head *cur; +ext4_group_t groupnr; +ext4_grpblk_t start; +int preallocated =0 ; +int count =0 ; +int len; + +/* all form of preallocation discards first load group, +* so the only competing code is preallocation use. +* we don't need any locking here +* notice we do NOT ignore preallocations with pa_deleted +* otherwise we could leave used blocks available for +* allocation in buddy when concurrent ext4_mb_put_pa() +* is dropping preallocation +*/ +list_for_each_rcu (cur, &grp->bb_prealloc_list) { + pa = list_entry(cur, struct ext4_prealloc_space, pa_group_list); +spin_lock (&pa->pa_lock); +ext4_get_group_no_and_offset (sb, pa->pa_pstart, + &groupnr, &start); + len = pa->pa_len; +spin_unlock (&pa->pa_lock); +if (unlikely (len ==0 )) +continue ;
Quoted 9 lines
fs/ext4/mballoc.c line 3479
Quoted 6 lines
fs/ext4/mballoc.c new file +6
-0+BUG_ON (groupnr != group); +mb_set_bits (sb_bgl_lock (EXT4_SB (sb), group), + bitmap, start, len); + preallocated += len; + count++; + }Seems to be missing
rcu_read_lock()
bb_prealloc_list is actually modified under ext4_group_lock. So it is not actually rcu. I this we should be using list_for_each there. The rcu managed list are i_prealloc_list and lg_prealloc_list
Quoted 4 lines
Quoted 4 lines
fs/ext4/mballoc.c new file +4
-0+mb_debug ("prellocated %u for group %lu\n" , preallocated, group); +} + +static void ext4_mb_pa_callback (struct rcu_head *head)
Quoted 8 lines
fs/ext4/mballoc.c line 3489
Quoted 6 lines
fs/ext4/mballoc.c new file +6
-0+{ +struct ext4_prealloc_space *pa; + pa = container_of(head, struct ext4_prealloc_space, u.pa_rcu); +kmem_cache_free (ext4_pspace_cachep, pa); +} +#define mb_call_rcu (__pa) call_rcu(&(__pa)->u.pa_rcu, ext4_mb_pa_callback)Is there any reason why this had to be implemented as a macro?
Fixed
Quoted 23 lines
Quoted 7 lines
...
fs/ext4/mballoc.c new file +3
-0+static int ext4_mb_new_inode_pa (struct ext4_allocation_context *ac) +{ +struct super_block *sb = ac->ac_sb;fs/ext4/mballoc.c line 3556
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+struct ext4_prealloc_space *pa; +struct ext4_group_info *grp; +struct ext4_inode_info *ei; + +/* preallocate only when found space is larger then requested */ +BUG_ON (ac->ac_o_ex.fe_len >= ac->ac_b_ex.fe_len); +BUG_ON (ac->ac_status !=AC_STATUS_FOUND ); +BUG_ON (!S_ISREG (ac->ac_inode->i_mode)); + + pa =kmem_cache_alloc (ext4_pspace_cachep,GFP_NOFS );Do all the GFP_NOFS's in this code really need to be
GFP_NOFS?Quoted 3 lines
fs/ext4/mballoc.c new file +3
-0+if (pa ==NULL ) +return -ENOMEM ; +ext4_lock_group (sb, ac->ac_b_ex.fe_group);
....
Quoted 8 lines
fs/ext4/mballoc.c line 3623
Quoted 6 lines
fs/ext4/mballoc.c new file +6
-0+list_add_rcu (&pa->pa_group_list, &grp->bb_prealloc_list); +ext4_unlock_group (sb, ac->ac_b_ex.fe_group); + +spin_lock (pa->pa_obj_lock); +list_add_rcu (&pa->pa_inode_list, &ei->i_prealloc_list); +spin_unlock (pa->pa_obj_lock);hm. Strange to see
list_add_rcu()inside spinlock like this.
Few lines above we havepa->pa_obj_lock = &ei->i_prealloc_lock;
So the spin_lock is there to prevent mutiple cpu's adding to the prealloc list together.
Quoted 19 lines
Quoted 19 lines
fs/ext4/mballoc.c new file +15
-0+return 0 ; +} + +static int ext4_mb_discard_group_preallocations (struct super_block *sb, +ext4_group_t group,int needed) +{ +struct ext4_group_info *grp =ext4_get_group_info (sb, group); +struct buffer_head *bitmap_bh =NULL ; +struct ext4_prealloc_space *pa, *tmp; +struct list_head list; +struct ext4_buddy e4b; +int err; +int busy =0 ; +int free =0 ; +/* seems this one can be freed ... */
....
Quoted 4 lines
Quoted 4 lines
fs/ext4/mballoc.c new file +4
-0+ pa->pa_deleted =1 ; + +/* we can trust pa_free ... */ + free += pa->pa_free;
Quoted 8 lines
fs/ext4/mballoc.c line 3858
Quoted 6 lines
fs/ext4/mballoc.c new file +6
-0+ +spin_unlock (&pa->pa_lock); + +list_del_rcu (&pa->pa_group_list); +list_add (&pa->u.pa_tmp_list, &list); + }Strange to see rcu operations outside
rcu_read_lock().
That need not be actually list_del_rcu. As i stated above that is holding the bb_prealloc_list. It is updated under ext4_group_lock
Quoted 12 lines
fs/ext4/mballoc.c line 3868
Quoted 10 lines
fs/ext4/mballoc.c new file +9
-0+/* if we still need more blocks and some PAs were used, try again */ +if (free < needed && busy) { + busy =0 ; +ext4_unlock_group (sb, group); +/* +* Yield the CPU here so that we don't get soft lockup +* in non preempt case. +*/ +yield ();argh, no,
yield()is basically unusable.schedule_timeout(1)is preferable.
I actually schedule_timeout(HZ); This was actually a bug fix a soft lockup happening when we were running non preemptible kernel. Well we just want to make sure the high priority watchdog thread gets a chance to run. And if there are no high priority threads we ourself would like to run. My understanding was yield is the right choice there.
Quoted 15 lines
Please test this code whe there are lots of cpu-intensive tasks running.
Quoted 12 lines
fs/ext4/mballoc.c new file +12
-0+ goto repeat; + } + +/* found anything to free? */ +if (list_empty (&list)) { +BUG_ON (free !=0 ); + goto out; + } + +/* now free all selected PAs */ +if (atomic_read (&pa->pa_count)) { +/* this shouldn't happen often - nobody should
.....
Quoted 7 lines
fs/ext4/mballoc.c line 3945
Quoted 5 lines
fs/ext4/mballoc.c new file +5
-0+* use preallocation while we're discarding it */ +spin_unlock (&pa->pa_lock); +spin_unlock (&ei->i_prealloc_lock); +printk (KERN_ERR "uh-oh! used pa while discarding\n" ); +dump_stack ();
WARN_ON(1)would be more conventional.
Fixed
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ current->state = TASK_UNINTERRUPTIBLE; + schedule_timeout(HZ);
schedule_timeout_uninterruptible()
Fixed
Quoted 23 lines
Quoted 23 lines
fs/ext4/mballoc.c new file +23
-0+ goto repeat; + + } +if (pa->pa_deleted ==0 ) { + pa->pa_deleted =1 ; +spin_unlock (&pa->pa_lock); +list_del_rcu (&pa->pa_inode_list); +list_add (&pa->u.pa_tmp_list, &list); +continue ; + } + +/* someone is deleting pa right now */ +spin_unlock (&pa->pa_lock); +spin_unlock (&ei->i_prealloc_lock); + +/* we have to wait here because pa_deleted +* doesn't mean pa is already unlinked from +* the list. as we might be called from +* ->clear_inode() the inode will get freed +* and concurrent thread which is unlinking +* pa from inode's list may access already +* freed memory, bad-bad-bad */ +
Quoted 9 lines
fs/ext4/mballoc.c line 3976
Quoted 6 lines
fs/ext4/mballoc.c new file +6
-0+/* XXX: if this happens too often, we can +* add a flag to force wait only in case +* of ->clear_inode(), but not in case of +* regular truncate */ + current->state =TASK_UNINTERRUPTIBLE ; +schedule_timeout (HZ );ditto
Fixed
Quoted 24 lines
Quoted 24 lines
fs/ext4/mballoc.c new file +24
-0+ goto repeat; + } +spin_unlock (&ei->i_prealloc_lock); + +list_for_each_entry_safe (pa, tmp, &list, u.pa_tmp_list) { +BUG_ON (pa->pa_linear !=0 ); +ext4_get_group_no_and_offset (sb, pa->pa_pstart, &group,NULL ); + + err =ext4_mb_load_buddy (sb, group, &e4b); +BUG_ON (err !=0 );/* error handling here */ + + bitmap_bh =read_block_bitmap (sb, group); +if (bitmap_bh ==NULL ) { +/* error handling here */ +ext4_mb_release_desc (&e4b); +BUG_ON (bitmap_bh ==NULL ); + } + +ext4_lock_group (sb, group); +list_del_rcu (&pa->pa_group_list); +ext4_mb_release_inode_pa (&e4b, bitmap_bh, pa); +ext4_unlock_group (sb, group); + +ext4_mb_release_desc (&e4b);
Quoted 9 lines
fs/ext4/mballoc.c line 4006
Quoted 6 lines
fs/ext4/mballoc.c new file +6
-0+brelse (bitmap_bh); + +list_del (&pa->u.pa_tmp_list); +mb_call_rcu (pa); + } +}Would be nice to ask Paul to review all the rcu usage in here. It looks odd.
Will add Paul to the CC
Quoted 8 lines
fs/ext4/mballoc.c line 4074
Quoted 6 lines
...
fs/ext4/mballoc.c new file +3
-0+#else +#define ext4_mb_show_ac (x) +#endif static inlined C functions are preferred (+1e6 dittoes)
Fixed
Quoted 15 lines
Quoted 15 lines
fs/ext4/mballoc.c new file +14
-0+/* +* We use locality group preallocation for small size file. The size of the +* file is determined by the current size or the resulting size after +* allocation which ever is larger +* +* One can tune this size via /proc/fs/ext4/<partition>/stream_req +*/ +static void ext4_mb_group_or_file (struct ext4_allocation_context *ac) +{ +struct ext4_sb_info *sbi =EXT4_SB (ac->ac_sb); +int bsbits = ac->ac_sb->s_blocksize_bits; +loff_t size, isize; + +if (!(ac->ac_flags &EXT4_MB_HINT_DATA ))
Quoted 9 lines
fs/ext4/mballoc.c line 4095
Quoted 6 lines
fs/ext4/mballoc.c new file +6
-0+return ; + + size = ac->ac_o_ex.fe_logical + ac->ac_o_ex.fe_len; + isize =i_size_read (ac->ac_inode) >> bsbits; +if (size < isize) + size = isize;
min()?
updated as size = max(size, isize);
Quoted 5 lines
Quoted 5 lines
fs/ext4/mballoc.c new file +5
-0+/* don't use group allocation for large files */ +if (size >= sbi->s_mb_stream_request) +return ; + +if (unlikely (ac->ac_flags &EXT4_MB_HINT_GOAL_ONLY ))
Quoted 8 lines
fs/ext4/mballoc.c line 4106
Quoted 5 lines
fs/ext4/mballoc.c new file +5
-0+return ; + +BUG_ON (ac->ac_lg !=NULL ); + ac->ac_lg = &sbi->s_locality_groups[get_cpu ()]; +put_cpu ();Strange-looking code. I'd be interested in a description of the per-cou design here.
I added the below doc
/*
* locality group prealloc space are per cpu. The reason for
* having per cpu locality group is to reduce the contention
* between block request from multiple CPUs.
*/
Quoted 9 lines
fs/ext4/mballoc.c line 4112
Quoted 6 lines
fs/ext4/mballoc.c new file +5
-0+/* we're going to use group allocation */ + ac->ac_flags |=EXT4_MB_HINT_GROUP_ALLOC ; + +/* serialize all allocations in the group */ +down (&ac->ac_lg->lg_sem);This should be a mutex, shouldn't it?
converted to mutex
Quoted 31 lines
Quoted 18 lines
fs/ext4/mballoc.c new file +15
-0+} + +static int ext4_mb_free_metadata (handle_t *handle,struct ext4_buddy *e4b, +ext4_group_t group,ext4_grpblk_t block,int count) +{ +struct ext4_group_info *db = e4b->bd_info; +struct super_block *sb = e4b->bd_sb; +struct ext4_sb_info *sbi =EXT4_SB (sb); +struct ext4_free_metadata *md; +int i; + +BUG_ON (e4b->bd_bitmap_page ==NULL ); +BUG_ON (e4b->bd_buddy_page ==NULL ); + +ext4_lock_group (sb, group);fs/ext4/mballoc.c line 4361
Quoted 10 lines
fs/ext4/mballoc.c new file +10
-0+for (i =0 ; i < count; i++) { + md = db->bb_md_cur; +if (md && db->bb_tid != handle->h_transaction->t_tid) { + db->bb_md_cur =NULL ; + md =NULL ; + } + +if (md ==NULL ) { +ext4_unlock_group (sb, group); + md =kmalloc (sizeof (*md),GFP_KERNEL );Why was this one not
GFP_NOFS?
Quoted 5 lines
fs/ext4/mballoc.c line 4363
Quoted 2 lines
fs/ext4/mballoc.c new file +2
-0+if (md ==NULL ) +return -ENOMEM ;Did we just leak some memory?
No the data is allocated to carry information regarding the free blocks.
Quoted 39 lines
Quoted 39 lines
fs/ext4/mballoc.c new file +36
-0+ md->num =0 ; + md->group = group; + +ext4_lock_group (sb, group); +if (db->bb_md_cur ==NULL ) { +spin_lock (&sbi->s_md_lock); +list_add (&md->list, &sbi->s_active_transaction); +spin_unlock (&sbi->s_md_lock); +/* protect buddy cache from being freed, +* otherwise we'll refresh it from +* on-disk bitmap and lose not-yet-available +* blocks */ +page_cache_get (e4b->bd_buddy_page); +page_cache_get (e4b->bd_bitmap_page); + db->bb_md_cur = md; + db->bb_tid = handle->h_transaction->t_tid; +mb_debug ("new md 0x%p for group %lu\n" , + md, md->group); + }else { +kfree (md); + md = db->bb_md_cur; + } + } + +BUG_ON (md->num >=EXT4_BB_MAX_BLOCKS ); + md->blocks[md->num] = block + i; + md->num++; +if (md->num ==EXT4_BB_MAX_BLOCKS ) { +/* no more space, put full container on a sb's list */ + db->bb_md_cur =NULL ; + } + } +ext4_unlock_group (sb, group); +return 0 ; +} +
Quoted 15 lines
fs/ext4/super.c clear_qf_name: · line 1306
Quoted 13 lines
fs/ext4/super.c +13
-0+case Opt_mballoc: +set_opt (sbi->s_mount_opt,MBALLOC ); +break ; +case Opt_nomballoc: +clear_opt (sbi->s_mount_opt,MBALLOC ); +break ; +case Opt_stripe: +if (match_int (&args[0 ], &option)) +return 0 ; +if (option <0 ) +return 0 ; + sbi->s_stripe = option; +break ;These appear to be undocumented.
Updated
Quoted 26 lines
Quoted 26 lines
fs/ext4/super.c +18
-0default :printk (KERN_ERR "EXT4-fs: Unrecognized mount option \"%s\" "@@ -1742,6 +1762,33 @@ static ext4_fsblk_t descriptor_loc(struct super_block *sb,return (has_super +ext4_group_first_block_no (sb, bg)); } +/** +* ext4_get_stripe_size: Get the stripe size. +* @sbi: In memory super block info +* +* If we have specified it via mount option, then +* use the mount option value. If the value specified at mount time is +* greater than the blocks per group use the super block value. +* If the super block value is greater than blocks per group return 0. +* Allocator needs it be less than blocks per group. +* +*/ +static unsigned long ext4_get_stripe_size (struct ext4_sb_info *sbi) +{ +unsigned long stride =le16_to_cpu (sbi->s_es->s_raid_stride); +unsigned long stripe_width = +le32_to_cpu (sbi->s_es->s_raid_stripe_width); + +if (sbi->s_stripe && sbi->s_stripe <= sbi->s_blocks_per_group) {
Quoted 8 lines
fs/ext4/super.c static ext4_fsblk_t descriptor_loc(struct super_block *sb, · line 1788
Quoted 6 lines
fs/ext4/super.c +6
-0+return sbi->s_stripe; + }else if (stripe_width <= sbi->s_blocks_per_group) { +return stripe_width; + }else if (stride <= sbi->s_blocks_per_group) { +return stride; + }unneeded braces.
I was thinking it is ok these days. checkpatch didn't warn and i had multiple else if. I could remove those else if
Quoted 22 lines
Quoted 7 lines
include/linux/ext4_fs.h +3
-0+return 0 ; +} +static inlineinclude/linux/ext4_fs.h static inline void ext4_isize_set(struct ext4_inode *raw_inode, loff_t i_size) · line 1154
Quoted 10 lines
include/linux/ext4_fs.h +10
-0+struct ext4_group_info *ext4_get_group_info (struct super_block *sb, +ext4_group_t group) +{ +struct ext4_group_info ***grp_info; +long indexv, indexh; + grp_info =EXT4_SB (sb)->s_group_info; + indexv = group >> (EXT4_DESC_PER_BLOCK_BITS (sb)); + indexh = group & ((EXT4_DESC_PER_BLOCK (sb)) -1 ); +return grp_info[indexv][indexh]; +}This should be uninlined.
Quoted 1 line
Gosh what a lot of code. Is it faster?
Performance numbers with compile bench http://ext4.wiki.kernel.org/index.php/Performance_results
Andrew Morton
maintainerRe: [PATCH 23/49] Add buffer head related helper functions
In reply to Aneesh Kumar K.Vfs/buffer.c static int buffer_cpu_notify(struct notifier_block *self, · line 3246
Quoted 9 lines · On Thu, 24 Jan 2008 10:52:27 +0530 "Aneesh Kumar K.V"…
+ * Returns zero on success and
-EIOon error.If the input
+ * buffer is not locked returns-EINVAL
+ *
+ */fs/buffer.c +4
-0+int bh_submit_read (struct buffer_head *bh) +{ +if (!buffer_locked (bh)) +return -EINVAL ;
Is this case just catching a programming bug?
If so, a plain old BUG_ON would be better.
Re: [PATCH 41/49] ext4: Add multi block allocator for ext4
In reply to Aneesh Kumar K.Vupdated patch. Waiting for the test results.
I am only attaching the diff. Mballoc patch is really large.
-aneesh
Documentation/filesystems/ext4.txt +6 -0
@@ -89,6 +89,8 @@ When mounting an ext4 filesystem, the following option are accepted: extents ext4 will use extents to address file data. The file system will no longer be mountable by ext3. +noextents ext4 will not use extents for new files created. + journal_checksum Enable checksumming of the journal transactions. This will allow the recovery code in e2fsck and the kernel to detect corruption in the kernel. It is a
@@ -206,6 +208,10 @@ nobh (a) cache disk block mapping information "nobh" option tries to avoid associating buffer heads (supported only for "writeback" mode). +mballoc (*) Use the mutliblock allocator for block allocation +nomballoc disabled multiblock allocator for block allocation. +stripe=n filesystem blocks per stripe for a RAID configuration. + Data Mode ---------
Documentation/filesystems/proc.txt +39 -0
@@ -857,6 +857,45 @@ CPUs. The "procs_blocked" line gives the number of processes currently blocked, waiting for I/O to complete. +1.9 Ext4 file system parameters +------------------------------ +Ext4 file system have one directory per partition under /proc/fs/ext4/ +# ls /proc/fs/ext4/hdc/ +group_prealloc max_to_scan mb_groups mb_history min_to_scan order2_req +stats stream_req + +mb_groups: +This file gives the details of mutiblock allocator buddy cache of free blocks + +mb_history: +Multiblock allocation history. + +stats: +This file indicate whether the multiblock allocator should start collecting +statistics. The statistics are shown during unmount + +group_prealloc: +The multiblock allocator normalize the block allocation request to +group_prealloc filesystem blocks if we don't have strip value set. +The stripe value can be specified at mount time or during mke2fs. + +max_to_scan: +How long multiblock allocator can look for a best extent (in found extents) + +min_to_scan: +How long multiblock allocator must look for a best extent + +order2_req: +Multiblock allocator use 2^N search using buddies only for requests greater +than or equal to order2_req. The request size is specfied in file system +blocks. A value of 2 indicate only if the requests are greater than or equal +to 4 blocks. + +stream_req: +Files smaller than stream_req are served by the stream allocator, whose +purpose is to pack requests as close each to other as possible to +produce smooth I/O traffic. Avalue of 16 indicate that file smaller than 16 +filesystem block size will use group based preallocation. ------------------------------------------------------------------------------ Summary
fs/ext4/mballoc.c +59 -60
321 lines not on this page · raw message
fs/ext4/super.c +5 -4
@@ -1779,13 +1779,14 @@ static unsigned long ext4_get_stripe_size(struct ext4_sb_info *sbi)unsigned long stripe_width =le32_to_cpu (sbi->s_es->s_raid_stripe_width); -if (sbi->s_stripe && sbi->s_stripe <= sbi->s_blocks_per_group) { +if (sbi->s_stripe && sbi->s_stripe <= sbi->s_blocks_per_group)return sbi->s_stripe; - }else if (stripe_width <= sbi->s_blocks_per_group) { + +if (stripe_width <= sbi->s_blocks_per_group)return stripe_width; - }else if (stride <= sbi->s_blocks_per_group) { + +if (stride <= sbi->s_blocks_per_group)return stride; - }return 0 ; }
Re: [PATCH 30/49] ext4: Convert truncate_mutex to read write semaphore.
In reply to Andrew MortonQuoted 18 lines · Andrew Morton
Quoted 18 lines · On Mon, 21 Jan 2008 22:02:09 -0500 "Theodore Ts'o" <[email protected]> wrote:
fs/ext4/inode.c +17
-0+int ext4_get_blocks_wrap (handle_t *handle,struct inode *inode,sector_t block, +unsigned long max_blocks,struct buffer_head *bh, +int create,int extend_disksize) +{ +int retval; +if (create) { +down_write ((&EXT4_I (inode)->i_data_sem)); + }else { +down_read ((&EXT4_I (inode)->i_data_sem)); + } +if (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) { + retval =ext4_ext_get_blocks (handle, inode, block, max_blocks, + bh, create, extend_disksize); + }else { + retval =ext4_get_blocks_handle (handle, inode, block, + max_blocks, bh, create, extend_disksize); + }
Quoted 8 lines
fs/ext4/inode.c out: · line 920
Quoted 5 lines
fs/ext4/inode.c +5
-0+if (create) { +up_write ((&EXT4_I (inode)->i_data_sem)); + }else { +up_read ((&EXT4_I (inode)->i_data_sem)); + }This function has many unneeded braces. checkpatch used to detect this but it seems to have broken.
This is a side effect of this rule:
This does not apply if one branch of a conditional statement is a single statement. Use braces in both branches.
Basically each arm is being considered in isolation, each arm is seen as having a "sibling" arm with braces so it is permitted to have braces. Bugger.
I guess I'll try and see if I can detect this.
Quoted 6 lines
fs/ext4/inode.c out: · line 924
Quoted 4 lines
fs/ext4/inode.c +2
-0+return retval; +}static int ext4_get_block (struct inode *inode,sector_t iblock,struct buffer_head *bh_result,int create)Mising newline.
We could check for those ... will look to add in the next release.
-apw
Re: [PATCH 41/49] ext4: Add multi block allocator for ext4
In reply to Aneesh Kumar K.VQuoted 24 lines · Aneesh Kumar K.V
Quoted 15 lines
Quoted 15 lines
fs/ext4/mballoc.c new file +13
-0+/* find most significant bit */ +static int fmsb (unsigned short word) +{ +int order; + +if (word >255 ) { + order =7 ; + word >>=8 ; + }else { + order =-1 ; + } + + do {Quoted 8 lines
fs/ext4/mballoc.c line 898
Quoted 6 lines
fs/ext4/mballoc.c new file +6
-0+ order++; + word >>=1 ; + }while (word !=0 ); + +return order; +}Did we just reinvent
fls()?
Quoted 3 lines
replaced by fls.
Quoted 1 line
That should be fls() - 1;
The full patch is at
http://www.radian.org/~kvaneesh/ext4/jan-24-2008/mballoc-core.patch
The patch is too big to inline.
-aneesh
Re: [PATCH 33/49] ext4: Add the journal checksum feature
In reply to Andrew MortonQuoted 160 lines · Andrew Morton
Quoted 17 lines · On Mon, 21 Jan 2008 22:02:12 -0500 "Theodore Ts'o" <[email protected]> wrote:
From: Girish Shilamkar <[email protected]>
The journal checksum feature adds two new flags i.e
JBD2_FEATURE_INCOMPAT_ASYNC_COMMITandJBD2_FEATURE_COMPAT_CHECKSUM.
JBD2_FEATURE_CHECKSUMflag indicates that the commit block contains the checksum for the blocks described by the descriptor blocks. Due to checksums, writing of the commit record no longer needs to be synchronous. Now commit record can be sent to disk without waiting for descriptor blocks to be written to disk. This behavior is controlled usingJBD2_FEATURE_ASYNC_COMMITflag. Older kernels/e2fsck should not be able to recover the journal with_ASYNC_COMMIThence it is made incompat.
The commit header has been extended to hold the checksum along with the type of the checksum.Quoted 6 lines
For recovery in pass scan checksums are verified to ensure the sanity and
completeness(in case of _ASYNC_COMMIT)of every transaction....
+static inline
__u32jbd2_checksum_data(__u32 crc32_sum, struct buffer_head *bh)unneeded inlining.
Review
Quoted 12 lines
(quoted diff) +12
-0+{ + struct page *page = bh->b_page; + char *addr; + __u32 checksum; + + addr = kmap_atomic(page, KM_USER0); + checksum = crc32_be(crc32_sum, + (void *)(addr + offset_in_page(bh->b_data)), bh->b_size); + kunmap_atomic(addr, KM_USER0); + + return checksum; +}Can this buffer actually be in highmem?
Quoted 2 lines
static inline void write_tag_block(int
tag_bytes,journal_block_tag_t*tag,
unsigned long long block)More unnecessary inlining.
Quoted 18 lines
(quoted diff) +18
-0+/* + * jbd2_journal_clear_features () - Clear a given journal feature in the + * superblock + * @journal: Journal to act on. + * @compat: bitmask of compatible features + * @ro: bitmask of features that force read-only mount + * @incompat: bitmask of incompatible features + * + * Clear a given journal feature as present on the + * superblock. Returns true if the requested features could be reset. + */ +int jbd2_journal_clear_features(journal_t *journal, unsigned long compat, + unsigned long ro, unsigned long incompat) +{ + journal_superblock_t *sb; + + jbd_debug(1, "Clear features 0x%lx/0x%lx/0x%lx\n", + compat, ro, incompat);Review
Quoted 10 lines
(quoted diff) +10
-0+ + sb = journal->j_superblock; + + sb->s_feature_compat &= ~cpu_to_be32(compat); + sb->s_feature_ro_compat &= ~cpu_to_be32(ro); + sb->s_feature_incompat &= ~cpu_to_be32(incompat); + + return 1; +} +EXPORT_SYMBOL(jbd2_journal_clear_features);Kernel usually returns 0 on success. So we can return a useful errno on failure.
Quoted 7 lines
(quoted diff) +7
-0+/* + * calc_chksums calculates the checksums for the blocks described in the + * descriptor block. + */ +static int calc_chksums(journal_t *journal, struct buffer_head *bh, + unsigned long *next_log_block, __u32 *crc32_sum) +{Review
Quoted 10 lines
(quoted diff) +10
-0+ int i, num_blks, err; + unsigned io_block; + struct buffer_head *obh; + + num_blks = count_tags(journal, bh); + /* Calculate checksum of the descriptor block. */ + *crc32_sum = crc32_be(*crc32_sum, (void *)bh->b_data, bh->b_size); + + for (i = 0; i < num_blks; i++) { + io_block = (*next_log_block)++;unsigned <- unsigned long.
Are all the types appropriate in here?
Quoted 32 lines
(quoted diff) +16
-2+ wrap(journal, *next_log_block); + err = jread(&obh, journal, io_block); + if (err) { + printk(KERN_ERR "JBD: IO error %d recovering block " + "%u in log\n", err, io_block); + return 1; + } else { + *crc32_sum = crc32_be(*crc32_sum, (void *)obh->b_data, + obh->b_size); + } + } + return 0; +} + static int do_one_pass(journal_t *journal, struct recovery_info *info, enum passtype pass) {@@ -328,6 +360,7 @@ static int do_one_pass(journal_t *journal, unsigned int sequence; int blocktype; int tag_bytes = journal_tag_bytes(journal); + __u32 crc32_sum = ~0; /* Transactional Checksums */ /* Precompute the maximum metadata descriptors in a descriptor block */ int MAX_BLOCKS_PER_DESC;@@ -419,9 +452,23 @@ static int do_one_pass(journal_t *journal, switch(blocktype) { case JBD2_DESCRIPTOR_BLOCK: /* If it is a valid descriptor block, replay it - * in pass REPLAY; otherwise, just skip over the - * blocks it describes. */ + * in pass REPLAY; if journal_checksums enabled, thenReview static int do_one_pass(journal_t *journal, · line 465
Quoted 10 lines
(quoted diff) +9
-0+ * calculate checksums in PASS_SCAN, otherwise, + * just skip over the blocks it describes. */ if (pass != PASS_REPLAY) { + if (pass == PASS_SCAN && + JBD2_HAS_COMPAT_FEATURE(journal, + JBD2_FEATURE_COMPAT_CHECKSUM) && + !info->end_transaction) { + if (calc_chksums(journal, bh, + &next_log_block, + &crc32_sum)) {
put_bh()Review static int do_one_pass(journal_t *journal, · line 470
Quoted 5 lines
(quoted diff) +5
-0+ brelse(bh); + break; + } + brelse(bh); + continue;
put_bh()Quoted 7 lines
(quoted diff) +1
-0+ } next_log_block += count_tags(journal, bh); wrap(journal, next_log_block); brelse(bh);@@ -516,9 +563,96 @@ static int do_one_pass(journal_t *journal, continue;
Quoted 4 lines
Review static int do_one_pass(journal_t *journal, · line 565
Quoted 1 line
(quoted diff) +1
-0+ brelse(bh);etc
Thanks, Updated patch below:
ext4: Add the journal checksum feature
From: Girish Shilamkar <[email protected]>
The journal checksum feature adds two new flags i.e JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT and JBD2_FEATURE_COMPAT_CHECKSUM.
JBD2_FEATURE_CHECKSUM flag indicates that the commit block contains the checksum for the blocks described by the descriptor blocks. Due to checksums, writing of the commit record no longer needs to be synchronous. Now commit record can be sent to disk without waiting for descriptor blocks to be written to disk. This behavior is controlled using JBD2_FEATURE_ASYNC_COMMIT flag. Older kernels/e2fsck should not be able to recover the journal with _ASYNC_COMMIT hence it is made incompat.
The commit header has been extended to hold the checksum along with the type of the checksum.
For recovery in pass scan checksums are verified to ensure the sanity and completeness(in case of _ASYNC_COMMIT) of every transaction.
---
Documentation/filesystems/ext4.txt | 10 + fs/Kconfig | 1 fs/ext4/super.c | 25 ++++ fs/jbd2/commit.c | 198 +++++++++++++++++++++++++++---------- fs/jbd2/journal.c | 26 ++++ fs/jbd2/recovery.c | 151 ++++++++++++++++++++++++++-- include/linux/ext4_fs.h | 3 include/linux/jbd2.h | 36 +++++- 8 files changed, 388 insertions(+), 62 deletions(-)
Documentation/filesystems/ext4.txt +10 -0
@@ -89,6 +89,16 @@ When mounting an ext4 filesystem, the fo extents ext4 will use extents to address file data. The file system will no longer be mountable by ext3. +journal_checksum Enable checksumming of the journal transactions. + This will allow the recovery code in e2fsck and the + kernel to detect corruption in the kernel. It is a + compatible change and will be ignored by older kernels. + +journal_async_commit Commit block can be written to disk without waiting + for descriptor blocks. If enabled older kernels cannot + mount the device. This will enable 'journal_checksum' + internally. + journal=update Update the ext4 file system's journal to the current format.
fs/Kconfig +1 -0
@@ -236,6 +236,7 @@ config JBD_DEBUG config JBD2 tristate + select CRC32 help This is a generic journaling layer for block devices that support both 32-bit and 64-bit block numbers. It is currently used by
fs/ext4/super.c +25 -0
@@ -869,6 +869,7 @@ enum { Opt_user_xattr, Opt_nouser_xattr, Opt_acl, Opt_noacl, Opt_reservation, Opt_noreservation, Opt_noload, Opt_nobh, Opt_bh, Opt_commit, Opt_journal_update, Opt_journal_inum, Opt_journal_dev, + Opt_journal_checksum, Opt_journal_async_commit, Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback, Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota,
@@ -908,6 +909,8 @@ static match_table_t tokens = { {Opt_journal_update, "journal=update"}, {Opt_journal_inum, "journal=%u"}, {Opt_journal_dev, "journal_dev=%u"}, + {Opt_journal_checksum, "journal_checksum"}, + {Opt_journal_async_commit, "journal_async_commit"}, {Opt_abort, "abort"}, {Opt_data_journal, "data=journal"}, {Opt_data_ordered, "data=ordered"},
@@ -1095,6 +1098,13 @@ static int parse_options (char *options,return 0 ; *journal_devnum = option;break ; +case Opt_journal_checksum: +set_opt (sbi->s_mount_opt,JOURNAL_CHECKSUM ); +break ; +case Opt_journal_async_commit: +set_opt (sbi->s_mount_opt,JOURNAL_ASYNC_COMMIT ); +set_opt (sbi->s_mount_opt,JOURNAL_CHECKSUM ); +break ;case Opt_noload:set_opt (sbi->s_mount_opt,NOLOAD );break ;
@@ -2114,6 +2124,21 @@ static int ext4_fill_super (struct super goto failed_mount4; } +if (test_opt (sb,JOURNAL_ASYNC_COMMIT )) { +jbd2_journal_set_features (sbi->s_journal, +JBD2_FEATURE_COMPAT_CHECKSUM ,0 , +JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT ); + }else if (test_opt (sb,JOURNAL_CHECKSUM )) { +jbd2_journal_set_features (sbi->s_journal, +JBD2_FEATURE_COMPAT_CHECKSUM ,0 ,0 ); +jbd2_journal_clear_features (sbi->s_journal,0 ,0 , +JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT ); + }else { +jbd2_journal_clear_features (sbi->s_journal, +JBD2_FEATURE_COMPAT_CHECKSUM ,0 , +JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT ); + } +/* We have now updated the journal if required, so we can * validate the data journaling mode. */ switch (test_opt (sb,DATA_FLAGS )) {
fs/jbd2/commit.c +149 -49
280 lines not on this page · raw message
fs/jbd2/journal.c +26 -0
@@ -1578,6 +1578,32 @@ int jbd2_journal_set_features (journal_treturn 1 ; } +/* +* jbd2_journal_clear_features () - Clear a given journal feature in the +* superblock +* @journal: Journal to act on. +* @compat: bitmask of compatible features +* @ro: bitmask of features that force read-only mount +* @incompat: bitmask of incompatible features +* +* Clear a given journal feature as present on the +* superblock. +*/ +int jbd2_journal_clear_features (journal_t *journal,unsigned long compat, +unsigned long ro,unsigned long incompat) +{ +journal_superblock_t *sb; + +jbd_debug (1 ,"Clear features 0x%lx/0x%lx/0x%lx\n" , + compat, ro, incompat); + + sb = journal->j_superblock; + + sb->s_feature_compat &= ~cpu_to_be32 (compat); + sb->s_feature_ro_compat &= ~cpu_to_be32 (ro); + sb->s_feature_incompat &= ~cpu_to_be32 (incompat); +} +EXPORT_SYMBOL (jbd2_journal_clear_features);/** * int jbd2_journal_update_format () - Update on-disk journal structure.
fs/jbd2/recovery.c +143 -8
191 lines not on this page · raw message
include/linux/ext4_fs.h +2 -1
@@ -467,7 +467,8 @@ do { \#define EXT4_MOUNT_USRQUOTA 0x100000/* "old" user quota */ #define EXT4_MOUNT_GRPQUOTA 0x200000/* "old" group quota */ #define EXT4_MOUNT_EXTENTS 0x400000/* Extents support */ - +#define EXT4_MOUNT_JOURNAL_CHECKSUM 0x800000/* Journal checksums */ +#define EXT4_MOUNT_JOURNAL_ASYNC_COMMIT 0x1000000/* Journal Async Commit */ /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */ #ifndef _LINUX_EXT2_FS_H#define clear_opt (o, opt) o &= ~EXT4_MOUNT_##opt
include/linux/jbd2.h +32 -4
@@ -149,6 +149,28 @@ typedef struct journal_header_s__be32 h_sequence; } journal_header_t; +/* +* Checksum types. +*/ +#define JBD2_CRC32_CHKSUM 1 +#define JBD2_MD5_CHKSUM 2 +#define JBD2_SHA1_CHKSUM 3 + +#define JBD2_CRC32_CHKSUM_SIZE 4 + +#define JBD2_CHECKSUM_BYTES (32 / sizeof(u32)) +/* +* Commit block header for storing transactional checksums: +*/ +struct commit_header { +__be32 h_magic; +__be32 h_blocktype; +__be32 h_sequence; +unsigned char h_chksum_type; +unsigned char h_chksum_size; +unsigned char h_padding[2 ]; +__be32 h_chksum[JBD2_CHECKSUM_BYTES ]; +};/* * The block tag: used to describe a single buffer in the journal.
@@ -242,14 +264,18 @@ typedef struct journal_superblock_s ((j)->j_format_version >=2 && \ ((j)->j_superblock->s_feature_incompat & cpu_to_be32((mask)))) -#define JBD2_FEATURE_INCOMPAT_REVOKE 0x00000001 -#define JBD2_FEATURE_INCOMPAT_64BIT 0x00000002 +#define JBD2_FEATURE_COMPAT_CHECKSUM 0x00000001 + +#define JBD2_FEATURE_INCOMPAT_REVOKE 0x00000001 +#define JBD2_FEATURE_INCOMPAT_64BIT 0x00000002 +#define JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT 0x00000004/* Features known to this kernel version: */ -#define JBD2_KNOWN_COMPAT_FEATURES 0 +#define JBD2_KNOWN_COMPAT_FEATURES JBD2_FEATURE_COMPAT_CHECKSUM#define JBD2_KNOWN_ROCOMPAT_FEATURES 0#define JBD2_KNOWN_INCOMPAT_FEATURES (JBD2_FEATURE_INCOMPAT_REVOKE | \ - JBD2_FEATURE_INCOMPAT_64BIT) + JBD2_FEATURE_INCOMPAT_64BIT | \ + JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT)#ifdef __KERNEL__
@@ -997,6 +1023,8 @@ extern int jbd2_journal_check_availab (journal_t *, unsigned long, unsigned long, unsigned long);extern int jbd2_journal_set_features (journal_t *,unsigned long ,unsigned long ,unsigned long ); +extern int jbd2_journal_clear_features + (journal_t *,unsigned long ,unsigned long ,unsigned long );extern int jbd2_journal_create (journal_t *);extern int jbd2_journal_load (journal_t *journal);extern void jbd2_journal_destroy (journal_t *);
Quoted 5 lines
-
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Theodore Tso
maintainerRe: [PATCH 36/49] ext4: Add EXT4_IOC_MIGRATE ioctl
In reply to Aneesh Kumar K.VQuoted 17 lines · Aneesh Kumar K.V
fs/ext4/migrate.c new file +17
-0+static int free_ext_idx (handle_t *handle,struct inode *inode, +struct ext4_extent_idx *ix) +{ +int i, retval =0 ; +ext4_fsblk_t block; +struct buffer_head *bh; +struct ext4_extent_header *eh; + + block =idx_pblock (ix); + bh =sb_bread (inode->i_sb, block); +if (!bh) +return -EIO ; + + eh = (struct ext4_extent_header *)bh->b_data; +if (eh->eh_depth ==0 ) { +brelse (bh); +ext4_free_blocks (handle, inode, block,1 );
fs/ext4/migrate.c line 388
Quoted 10 lines
fs/ext4/migrate.c new file +10
-0+ }else { + ix =EXT_FIRST_INDEX (eh); +for (i =0 ; i <le16_to_cpu (eh->eh_entries); i++, ix++) { + retval =free_ext_idx (handle, inode, ix); +if (retval) +return retval; + } + } +return retval; +}
Aneesh, looks like if eh->eh_depth is != 0, bh gets leaked. This is how I plan to fix it up:
+static int free_ext_idx(handle_t *handle, struct inode *inode,
+ struct ext4_extent_idx *ix)
+{
+ int i, retval = 0;
+ ext4_fsblk_t block;
+ struct buffer_head *bh;
+ struct ext4_extent_header *eh;
+
+ block = idx_pblock(ix);
+ bh = sb_bread(inode->i_sb, block);
+ if (!bh)
+ return -EIO;
+
+ eh = (struct ext4_extent_header *)bh->b_data;
+ if (eh->eh_depth == 0)
+ ext4_free_blocks(handle, inode, block, 1);
+ else {
+ ix = EXT_FIRST_INDEX(eh);
+ for (i = 0; i < le16_to_cpu(eh->eh_entries); i++, ix++) {
+ retval = free_ext_idx(handle, inode, ix);
+ if (retval)
+ break;
+ }
+ }
+ put_bh(bh);
+ return retval;
+}
- Ted
Re: [PATCH 36/49] ext4: Add EXT4_IOC_MIGRATE ioctl
Quoted 47 lines · Theodore Tso
Quoted 17 lines · Aneesh Kumar K.V
fs/ext4/migrate.c new file +17
-0+static int free_ext_idx (handle_t *handle,struct inode *inode, +struct ext4_extent_idx *ix) +{ +int i, retval =0 ; +ext4_fsblk_t block; +struct buffer_head *bh; +struct ext4_extent_header *eh; + + block =idx_pblock (ix); + bh =sb_bread (inode->i_sb, block); +if (!bh) +return -EIO ; + + eh = (struct ext4_extent_header *)bh->b_data; +if (eh->eh_depth ==0 ) { +brelse (bh); +ext4_free_blocks (handle, inode, block,1 );fs/ext4/migrate.c line 388
Quoted 10 lines
fs/ext4/migrate.c new file +10
-0+ }else { + ix =EXT_FIRST_INDEX (eh); +for (i =0 ; i <le16_to_cpu (eh->eh_entries); i++, ix++) { + retval =free_ext_idx (handle, inode, ix); +if (retval) +return retval; + } + } +return retval; +}Aneesh, looks like if
eh->eh_depthis != 0, bh gets leaked. This is how I plan to fix it up:fs/ext4/migrate.c new file +15
-0+static int free_ext_idx (handle_t *handle,struct inode *inode, +struct ext4_extent_idx *ix) +{ +int i, retval =0 ; +ext4_fsblk_t block; +struct buffer_head *bh; +struct ext4_extent_header *eh; + + block =idx_pblock (ix); + bh =sb_bread (inode->i_sb, block); +if (!bh) +return -EIO ; + + eh = (struct ext4_extent_header *)bh->b_data; +if (eh->eh_depth ==0 )
fs/ext4/migrate.c
Quoted 10 lines
fs/ext4/migrate.c new file +10
-0+ext4_free_blocks (handle, inode, block,1 ); + else { + ix =EXT_FIRST_INDEX (eh); +for (i =0 ; i <le16_to_cpu (eh->eh_entries); i++, ix++) { + retval =free_ext_idx (handle, inode, ix); +if (retval) +break ; + } + } +put_bh (bh);
We need to mark the index block as free.
via ext4_free_blocks(handle, inode, block, 1);
I remember making this change. May be it was related to dind/tind blocks.
-aneesh
Theodore Tso
maintainerRe: [PATCH 24/49] ext4: add block bitmap validation
In reply to Andrew MortonQuoted 4 lines · Andrew Morton
brelse()should only be used when the bh might be NULL -put_bh()can be used here.Please review all ext4/jbd2 code for this trivial speedup.
I've reviewed all of the pending patches in the stable queue for this speedup, and applied them where necessary; it was useful, since I detected a buffer head leak in one of the patches while I was at it.
The ext4/jbd2 code as a whole still needs to be reviewed for this speedup, but I don't want to fix this in the initial stable push, lest I break something by accident. I'll put it in the "TO DO" queue.
Regards,
- Ted
Re: [PATCH 41/49] ext4: Add multi block allocator for ext4
In reply to Theodore Ts'oThe latest version of the mballoc patch in the ext4dev git patch queue has a potential uninitialized use: CC [M] fs/ext4/mballoc.o
fs/ext4/mballoc.c: In function ‘ext4_mb_free_blocks’:fs/ext4/mballoc.c:4408: warning: ‘bitmap_bh’ may be used uninitialized in this function
There are 2 gotos which will call put_bh on a NULL bitmap_bh.
fs/ext4/mballoc.c +3 -2
@@ -4405,7 +4405,7 @@ void ext4_mb_free_blocks(handle_t *handl unsigned long block, unsigned long count, int metadata, unsigned long *freed) { - struct buffer_head *bitmap_bh; + struct buffer_head *bitmap_bh = NULL;struct super_block *sb = inode->i_sb;struct ext4_allocation_context ac;struct ext4_group_desc *gdp;
@@ -4546,7 +4546,8 @@ do_more: } sb->s_dirt =1 ; error_return: -put_bh (bitmap_bh); +if (bitmap_bh) +put_bh (bitmap_bh);ext4_std_error (sb, err);return ; }
Re: [PATCH 33/49] ext4: Add the journal checksum feature
In reply to Mingming CaoHi,
Quoted 31 lines · Mingming Cao
fs/jbd2/commit.c +12
-9-static int journal_write_commit_record (journal_t *journal, -transaction_t *commit_transaction) +static int journal_submit_commit_record (journal_t *journal, +transaction_t *commit_transaction, +struct buffer_head **cbh, +__u32 crc32_sum) {struct journal_head *descriptor; +struct commit_header *tmp;struct buffer_head *bh; -int i, ret; +int ret;int barrier_done =0 ;if (is_journal_aborted (journal))@@ -117,21 +122,33 @@ static int journal_write_commit_record(j bh =jh2bh (descriptor); -/* AKPM: buglet - add `i' to tmp! */ -for (i =0 ; i < bh->b_size; i +=512 ) { -journal_header_t *tmp = (journal_header_t *)bh->b_data; - tmp->h_magic =cpu_to_be32 (JBD2_MAGIC_NUMBER ); - tmp->h_blocktype =cpu_to_be32 (JBD2_COMMIT_BLOCK ); - tmp->h_sequence =cpu_to_be32 (commit_transaction->t_tid); + tmp = (struct commit_header *)bh->b_data; + tmp->h_magic =cpu_to_be32 (JBD2_MAGIC_NUMBER ); + tmp->h_blocktype =cpu_to_be32 (JBD2_COMMIT_BLOCK ); + tmp->h_sequence =cpu_to_be32 (commit_transaction->t_tid); + + if (JBD2_HAS_COMPAT_FEATURE(journal,
fs/jbd2/commit.c static int journal_write_commit_record(j · line 139
Quoted 10 lines
fs/jbd2/commit.c +7
-1+ JBD2_FEATURE_COMPAT_CHECKSUM)) { + tmp->h_chksum_type =JBD2_CRC32_CHKSUM ; + tmp->h_chksum_size =JBD2_CRC32_CHKSUM_SIZE ; + tmp->h_chksum[0 ] =cpu_to_be32 (crc32_sum); } -JBUFFER_TRACE (descriptor,"write commit block" ); +JBUFFER_TRACE (descriptor,"submit commit block" ); +lock_buffer (bh); +
get_bh() is missing here.
bh refcount is decremented in journal_wait_on_commit_record(), but it is not incremented in journal_submit_commit_record().
Thanks to Johann Lombardi for pointing this out.
Comments.
Quoted 40 lines
fs/jbd2/commit.c +23
-5set_buffer_dirty (bh); -if (journal->j_flags &JBD2_BARRIER ) { +set_buffer_uptodate (bh); + bh->b_end_io = journal_end_buffer_io_sync; + +if (journal->j_flags &JBD2_BARRIER && + !JBD2_HAS_COMPAT_FEATURE (journal, +JBD2_FEATURE_INCOMPAT_ASYNC_COMMIT )) {set_buffer_ordered (bh); barrier_done =1 ; } - ret =sync_dirty_buffer (bh); + ret =submit_bh (WRITE , bh); +/* is it possible for another commit to fail at roughly * the same time as this one? If so, we don't want to * trust the barrier flag in the super, but instead want @@ -152,14 +169,72 @@ static int journal_write_commit_record(jclear_buffer_ordered (bh);set_buffer_uptodate (bh);set_buffer_dirty (bh); - ret =sync_dirty_buffer (bh); + ret =submit_bh (WRITE , bh); } -put_bh (bh);/* One for getblk() */ -jbd2_journal_put_journal_head (descriptor); + *cbh = bh; +return ret; +} + +/* +* This function along with journal_submit_commit_record +* allows to write the commit record asynchronously. +*/ +static int journal_wait_on_commit_record (struct buffer_head *bh) +{ +int ret =0 ; + +clear_buffer_dirty (bh); +wait_on_buffer (bh);
fs/jbd2/commit.c static int journal_write_commit_record(j · line 196
Quoted 10 lines
fs/jbd2/commit.c +6
-1+ +if (unlikely (!buffer_uptodate (bh))) + ret = -EIO ; +put_bh (bh);/* One for getblk() */ +jbd2_journal_put_journal_head (bh2jh (bh)); -return (ret == -EIO ); +return ret; }
-Girish