Ext4 patches currently queued for mainline
Subsystems (5)
Theodore Ts'o
maintainercover Ext4 patches currently queued for mainline
These are the patches which I plan to be pushing to Linus as soon as the merge window opens. It doesn't include some patches which are blocked behind Jan Kara's page_mkwrite() patch series to address some problems across multiple filesystems for filesystems where the pagesize is less than blocksize and there are races between mmap() and truncate() --- which currently needs mm review --- and the markers->tracepoint conversion, which is blocked behind tracing patches in Ingo's tree.
- Ted
Alberto Bertogli (1):
jbd2: Fix minor typos in comments in fs/jbd2/journal.c
Andreas Dilger (1):
ext4: super.c whitespace cleanup
Aneesh Kumar K.V (8):
ext4: Properly initialize the buffer_head state
vfs: Add BUG_ON for delayed and unwritten flags in submit_bh()
ext4: Mark the unwritten buffer_head as mapped during write_begin
ext4: hook fiemap operation for directories
vfs: Enable FS_IOC_FIEMAP and FIGETBSZ for all filetypes
ext4: Convert ext4_lock_group to use sb_bgl_lock
ext4: Avoid leaking blocks after a block allocation failure
ext4: truncate the file properly if we fail to copy data from
userspace
Curt Wohlgemuth (1):
ext4: Make the length of the mb_history file tunable
Eric Sandeen (2):
ext4: fix for fiemap last-block test
ext4: Change all super.c messages to print the device
Jan Kara (1):
ext4: Get rid of EXTEND_DISKSIZE flag of ext4_get_blocks_handle()
Linus Torvalds (1):
ext3: avoid unnecessary spinlock in critical POSIX ACL path
Manish Katiyar (3):
ext4: Fix memory leak in ext4_fill_super() in case of a failed mount
ext3: Fix memory leak in ext3_fill_super() in case of a failed mount
ext2: Fix memory leak in ext2_fill_super() in case of a failed mount
Theodore Ts'o (29):
ext4: Fallback to vmalloc if kmalloc can't allocate s_flex_groups
array
ext4: Use is_power_of_2() for clarity
ext4: avoid unnecessary spinlock in critical POSIX ACL path
ext4: Simplify ext4_commit_super()'s function signature
ext4: Fix and simplify s_dirt handling
ext4: Use separate super_operations structure for no_journal
filesystems
ext4: Avoid races caused by on-line resizing and SMP memory
reordering
ext4: Remove outdated comment about lock_super()
ext4: ext4_mark_recovery_complete() doesn't need to use lock_super
ext4: Replace lock/unlock_super() with an explicit lock for the
orphan list
ext4: Replace lock/unlock_super() with an explicit lock for resizing
ext4: Don't avoid using BLOCK_UNINIT block groups in mballoc
ext4: Move the ext4_i.h header file into ext4.h
ext4: Move the ext4_sb.h header file into ext4.h
ext4: Move fs/ext4/namei.h into ext4.h
ext4: Move fs/ext4/group.h into ext4.h
ext4: fix the length returned by fiemap for an unallocated extent
ext4: Simplify function signature for ext4_da_get_block_write()
ext4: Rename ext4_get_blocks_handle() to be ext4_ind_get_blocks()
ext4: Rename ext4_get_blocks_wrap() to be ext4_get_blocks()
ext4: Define a new set of flags for ext4_get_blocks()
ext4: Add documentation to the ext4_*get_block* functions
ext4: Add BUG_ON debugging checks to noalloc_get_block_write()
ext4: Merge ext4_da_get_block_write() into mpage_da_map_blocks()
ext4: Clean up ext4_get_blocks() so it does not depend on
bh_result->b_state
ext4: Add a comprehensive block validity check to ext4_get_blocks()
ext4: down i_data_sem only for read when walking tree for fiemap
ext4: remove unused function __ext4_write_dirty_metadata
ext4: Clean up calls to ext4_get_group_desc()
Toshiyuki Okajima (1):
ext4: fix dx_map_entry to support 256k directory blocks
Vincent Minet (1):
ext4: Fix spinlock assertions on UP systems
fs/buffer.c | 2 + fs/ext2/super.c | 1 + fs/ext3/acl.c | 13 +- fs/ext3/super.c | 1 + fs/ext4/Makefile | 4 +- fs/ext4/acl.c | 15 +- fs/ext4/balloc.c | 28 +- fs/ext4/block_validity.c | 244 ++++++++++++++ fs/ext4/dir.c | 3 +- fs/ext4/ext4.h | 354 ++++++++++++++++++-- fs/ext4/ext4_i.h | 140 -------- fs/ext4/ext4_sb.h | 161 --------- fs/ext4/extents.c | 77 ++--- fs/ext4/group.h | 29 -- fs/ext4/ialloc.c | 73 ++--- fs/ext4/inode.c | 587 ++++++++++++++++++++------------- fs/ext4/mballoc.c | 166 ++++------ fs/ext4/mballoc.h | 1 - fs/ext4/namei.c | 27 +- fs/ext4/namei.h | 8 - fs/ext4/resize.c | 36 +- fs/ext4/super.c | 831 ++++++++++++++++++++++++---------------------- fs/ioctl.c | 14 +- fs/jbd2/journal.c | 8 +- fs/mpage.c | 6 +- 25 files changed, 1591 insertions(+), 1238 deletions(-) create mode 100644 fs/ext4/block_validity.c delete mode 100644 fs/ext4/ext4_i.h delete mode 100644 fs/ext4/ext4_sb.h delete mode 100644 fs/ext4/group.h delete mode 100644 fs/ext4/namei.h
Theodore Ts'o
maintainerPATCH 1/49 ext4: Properly initialize the buffer_head state
From: Aneesh Kumar K.V <[email protected]>
These struct buffer_heads are allocated on the stack (and hence are initialized with stack garbage). They are only used to call a get_blocks() function, so that's mostly OK, but b_state must be initialized to be 0 so we don't have any unexpected BH_* flags set by accident, such as BH_Unwritten or BH_Delay.
--- fs/ext4/extents.c | 1 + fs/ext4/inode.c | 15 ++++++++++++++- fs/mpage.c | 6 ++++-- 3 files changed, 19 insertions(+), 3 deletions(-)
fs/ext4/extents.c +1 -0
@@ -3150,6 +3150,7 @@ retry: ret =PTR_ERR (handle);break ; } + map_bh.b_state =0 ; ret =ext4_get_blocks_wrap (handle, inode, block, max_blocks, &map_bh,EXT4_CREATE_UNINITIALIZED_EXT ,0 ,0 );
fs/ext4/inode.c +14 -1
@@ -2055,7 +2055,20 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd)if ((mpd->b_state & (1 << BH_Mapped)) && !(mpd->b_state & (1 << BH_Delay)))return 0 ; - new.b_state = mpd->b_state; +/* +* We need to make sure the BH_Delay flag is passed down to +* ext4_da_get_block_write(), since it calls +* ext4_get_blocks_wrap() with the EXT4_DELALLOC_RSVED flag. +* This flag causes ext4_get_blocks_wrap() to call +* ext4_da_update_reserve_space() if the passed buffer head +* has the BH_Delay flag set. In the future, once we clean up +* the interfaces to ext4_get_blocks_wrap(), we should pass in +* a separate flag which requests that the delayed allocation +* statistics should be updated, instead of depending on the +* state information getting passed down via the map_bh's +* state bitmasks plus the magic EXT4_DELALLOC_RSVED flag. +*/ + new.b_state = mpd->b_state & (1 << BH_Delay); new.b_blocknr =0 ; new.b_size = mpd->b_size; next = mpd->b_blocknr;
fs/mpage.c +4 -2
@@ -379,7 +379,8 @@ mpage_readpages(struct address_space *mapping, struct list_head *pages,struct buffer_head map_bh;unsigned long first_logical_block =0 ; -clear_buffer_mapped (&map_bh); + map_bh.b_state =0 ; + map_bh.b_size =0 ;for (page_idx =0 ; page_idx < nr_pages; page_idx++) { struct page *page = list_entry(pages->prev, struct page, lru);
@@ -412,7 +413,8 @@ int mpage_readpage(struct page *page, get_block_t get_block)struct buffer_head map_bh;unsigned long first_logical_block =0 ; -clear_buffer_mapped (&map_bh); + map_bh.b_state =0 ; + map_bh.b_size =0 ; bio =do_mpage_readpage (bio, page,1 , &last_block_in_bio, &map_bh, &first_logical_block, get_block);if (bio)
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 2/49 vfs: Add BUG_ON for delayed and unwritten flags in submit_bh()
From: Aneesh Kumar K.V <[email protected]>
The BH_Delay and BH_Unwritten flags should never leak out to submit_bh(). So add some BUG_ON() checks to submit_bh so we can get a stack trace and determine how and why this might have happened.
(Note that only XFS and ext4 use these buffer head flags, and XFS does not use submit_bh(). So this patch should only modify behavior for ext4.)
--- fs/buffer.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
fs/buffer.c +2 -0
@@ -2933,6 +2933,8 @@ int submit_bh(int rw, struct buffer_head * bh)BUG_ON (!buffer_locked (bh));BUG_ON (!buffer_mapped (bh));BUG_ON (!bh->b_end_io); +BUG_ON (buffer_delay (bh)); +BUG_ON (buffer_unwritten (bh));/* * Mask in barrier bit for a write (could be either a WRITE or a
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 3/49 ext4: Mark the unwritten buffer_head as mapped during write_begin
From: Aneesh Kumar K.V <[email protected]>
Setting BH_Unwritten buffer_heads as BH_Mapped avoids multiple (unnecessary) calls to get_block() during the call to the write(2) system call. Setting BH_Unwritten buffer heads as BH_Mapped requires that the writepages() functions can handle BH_Unwritten buffer_heads.
After this commit, things work as follows:
ext4_ext_get_block() returns unmapped, unwritten, buffer head when called with create = 0 for prealloc space. This makes sure we handle the read path and non-delayed allocation case correctly. Even though the buffer head is marked unmapped we have valid b_blocknr and b_bdev values in the buffer_head.
ext4_da_get_block_prep() called for block resrevation will now return mapped, unwritten, new buffer_head for prealloc space. This avoids multiple calls to get_block() for write to same offset. By making such buffers as BH_New, we also assure that sub-block zeroing of buffered writes happens correctly.
--- fs/ext4/extents.c | 4 +- fs/ext4/inode.c | 82 +++++++++++++++++++++++++++++++++------------------- 2 files changed, 54 insertions(+), 32 deletions(-)
fs/ext4/extents.c +2 -2
@@ -2872,6 +2872,8 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,if (create ==EXT4_CREATE_UNINITIALIZED_EXT ) goto out;if (!create) { +if (allocated > max_blocks) + allocated = max_blocks;/* * We have blocks reserved already. We * return allocated blocks so that delalloc
@@ -2879,8 +2881,6 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,* the buffer head will be unmapped so that * a read from the block returns 0s. */ -if (allocated > max_blocks) - allocated = max_blocks;set_buffer_unwritten (bh_result); bh_result->b_bdev = inode->i_sb->s_bdev; bh_result->b_blocknr = newblock;
fs/ext4/inode.c +52 -30
137 lines not on this page · raw message
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 4/49 ext4: Fallback to vmalloc if kmalloc can't allocate s_flex_groups array
For very large filesystems, the s_flex_groups array can get quite big. For example, a filesystem that can be resized up to 16TB will have 8192 flex groups (assuming the default flex_bg size of 16), so the array is 96k, which is *very* marginal for kmalloc(). On the other hand, a 160GB filesystem without the resize_inode feature will only require 960 bytes. So we try to allocate the array first using kmalloc(), and if that fails, we'll try to use vmalloc() instead.
--- fs/ext4/super.c | 22 +++++++++++++++++++--- 1 files changed, 19 insertions(+), 3 deletions(-)
fs/ext4/super.c +19 -3
@@ -20,6 +20,7 @@#include <linux/string.h> #include <linux/fs.h> #include <linux/time.h> +#include <linux/vmalloc.h> #include <linux/jbd2.h> #include <linux/slab.h> #include <linux/init.h>
@@ -586,7 +587,10 @@ static void ext4_put_super(struct super_block *sb)for (i =0 ; i < sbi->s_gdb_count; i++)brelse (sbi->s_group_desc[i]);kfree (sbi->s_group_desc); -kfree (sbi->s_flex_groups); +if (is_vmalloc_addr (sbi->s_flex_groups)) +vfree (sbi->s_flex_groups); +else +kfree (sbi->s_flex_groups);percpu_counter_destroy (&sbi->s_freeblocks_counter);percpu_counter_destroy (&sbi->s_freeinodes_counter);percpu_counter_destroy (&sbi->s_dirs_counter);
@@ -1620,6 +1624,7 @@ static int ext4_fill_flex_info(struct super_block *sb)ext4_group_t flex_group_count;ext4_group_t flex_group;int groups_per_flex =0 ; +size_t size;int i;if (!sbi->s_es->s_log_groups_per_flex) {
@@ -1634,8 +1639,13 @@ static int ext4_fill_flex_info(struct super_block *sb) flex_group_count = ((sbi->s_groups_count + groups_per_flex -1 ) + ((le16_to_cpu (sbi->s_es->s_reserved_gdt_blocks) +1 ) <<EXT4_DESC_PER_BLOCK_BITS (sb))) / groups_per_flex; - sbi->s_flex_groups =kzalloc (flex_group_count * -sizeof (struct flex_groups ),GFP_KERNEL ); + size = flex_group_count *sizeof (struct flex_groups ); + sbi->s_flex_groups =kzalloc (size,GFP_KERNEL ); +if (sbi->s_flex_groups ==NULL ) { + sbi->s_flex_groups =vmalloc (size); +if (sbi->s_flex_groups) +memset (sbi->s_flex_groups,0 , size); + }if (sbi->s_flex_groups ==NULL ) {printk (KERN_ERR "EXT4-fs: not enough memory for " "%u flex groups\n" , flex_group_count);
@@ -2842,6 +2852,12 @@ failed_mount4: sbi->s_journal =NULL ; } failed_mount3: +if (sbi->s_flex_groups) { +if (is_vmalloc_addr (sbi->s_flex_groups)) +vfree (sbi->s_flex_groups); +else +kfree (sbi->s_flex_groups); + }percpu_counter_destroy (&sbi->s_freeblocks_counter);percpu_counter_destroy (&sbi->s_freeinodes_counter);percpu_counter_destroy (&sbi->s_dirs_counter);
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 5/49 ext4: Use is_power_of_2() for clarity
--- fs/ext4/super.c | 5 ++--- 1 files changed, 2 insertions(+), 3 deletions(-)
fs/ext4/super.c +2 -3
@@ -1483,7 +1483,7 @@ set_qf_format:return 0 ;if (option <0 || option > (1 <<30 ))return 0 ; -if (option & (option -1 )) { +if (!is_power_of_2 (option)) {printk (KERN_ERR "EXT4-fs: inode_readahead_blks" " must be a power of 2\n" );return 0 ;
@@ -2101,8 +2101,7 @@ static ssize_t inode_readahead_blks_store(struct ext4_attr *a,if (parse_strtoul (buf,0x40000000 , &t))return -EINVAL ; -/* inode_readahead_blks must be a power of 2 */ -if (t & (t-1 )) +if (!is_power_of_2 (t))return -EINVAL ; sbi->s_inode_readahead_blks = t;
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 6/49 ext3: avoid unnecessary spinlock in critical POSIX ACL path
From: Linus Torvalds <[email protected]>
If a filesystem supports POSIX ACL's, the VFS layer expects the filesystem to do POSIX ACL checks on any files not owned by the caller, and it does this for every single pathname component that it looks up.
That obviously can be pretty expensive if the filesystem isn't careful about it, especially with locking. That's doubly sad, since the common case tends to be that there are no ACL's associated with the files in question.
ext3 already caches the ACL data so that it doesn't have to look it up over and over again, but it does so by taking the inode->i_lock spinlock on every lookup. Which is a noticeable overhead even if it's a private lock, especially on CPU's where the serialization is expensive (eg Intel Netburst aka 'P4').
For the special case of not actually having any ACL's, all that locking is unnecessary. Even if somebody else were to be changing the ACL's on another CPU, we simply don't care - if we've seen a NULL ACL, we might as well use it.
So just load the ACL speculatively without any locking, and if it was NULL, just use it. If it's non-NULL (either because we had a cached entry, or because the cache hasn't been filled in at all), it means that we'll need to get the lock and re-load it properly.
This is noticeable even on Nehalem, which does locking quite well (much better than P4). From lmbench:
Processor, Processes - times in microseconds - smaller is better
--------------------------------------------------------------------
Host OS Mhz null null open slct fork exec sh
call I/O stat clos TCP proc proc proc
--------- ------------- ---- ---- ---- ---- ---- ---- ---- ---- ----
- before:
nehalem.l Linux 2.6.30- 3193 0.04 0.09 0.95 1.45 2.18 69.1 273. 1141 nehalem.l Linux 2.6.30- 3193 0.04 0.09 0.95 1.48 2.28 69.9 253. 1140 nehalem.l Linux 2.6.30- 3193 0.04 0.10 0.95 1.42 2.19 68.6 284. 1141 - after: nehalem.l Linux 2.6.30- 3193 0.04 0.09 0.92 1.44 2.12 68.3 282. 1094 nehalem.l Linux 2.6.30- 3193 0.04 0.09 0.92 1.39 2.20 67.0 308. 1123 nehalem.l Linux 2.6.30- 3193 0.04 0.09 0.92 1.39 2.36 67.4 293. 1148
where you can see what appears to be a roughly 3% improvement in stat and open/close latencies from just the removal of the locking overhead.
Of course, this only matters for files you don't own (the owner never needs to do the ACL checks), but that's the common case for libraries, header files, and executables. As well as for the base components of any absolute pathname, even if you are the owner of the final file.
[ At some point we probably want to move this ACL caching logic entirely
into the VFS layer (and only call down to the filesystem when uncached), but in the meantime this improves ext3 a bit.
A similar fix to btrfs makes a much bigger difference (15x improvement in lmbench) due to broken caching. ]
--- fs/ext3/acl.c | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-)
fs/ext3/acl.c +8 -5
@@ -129,12 +129,15 @@ fail:static inline struct posix_acl *ext3_iget_acl (struct inode *inode,struct posix_acl **i_acl) { -struct posix_acl *acl =EXT3_ACL_NOT_CACHED ; +struct posix_acl *acl =ACCESS_ONCE (*i_acl); -spin_lock (&inode->i_lock); -if (*i_acl !=EXT3_ACL_NOT_CACHED ) - acl =posix_acl_dup (*i_acl); -spin_unlock (&inode->i_lock); +if (acl) { +spin_lock (&inode->i_lock); + acl = *i_acl; +if (acl !=EXT3_ACL_NOT_CACHED ) + acl =posix_acl_dup (acl); +spin_unlock (&inode->i_lock); + }return acl; }
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 7/49 ext4: avoid unnecessary spinlock in critical POSIX ACL path
If a filesystem supports POSIX ACL's, the VFS layer expects the filesystem to do POSIX ACL checks on any files not owned by the caller, and it does this for every single pathname component that it looks up.
That obviously can be pretty expensive if the filesystem isn't careful about it, especially with locking. That's doubly sad, since the common case tends to be that there are no ACL's associated with the files in question.
ext4 already caches the ACL data so that it doesn't have to look it up over and over again, but it does so by taking the inode->i_lock spinlock on every lookup. Which is a noticeable overhead even if it's a private lock, especially on CPU's where the serialization is expensive (eg Intel Netburst aka 'P4').
For the special case of not actually having any ACL's, all that locking is unnecessary. Even if somebody else were to be changing the ACL's on another CPU, we simply don't care - if we've seen a NULL ACL, we might as well use it.
So just load the ACL speculatively without any locking, and if it was NULL, just use it. If it's non-NULL (either because we had a cached entry, or because the cache hasn't been filled in at all), it means that we'll need to get the lock and re-load it properly.
(This commit was ported from a patch originally authored by Linus for ext3.)
--- fs/ext4/acl.c | 15 +++++++++------ 1 files changed, 9 insertions(+), 6 deletions(-)
fs/ext4/acl.c +8 -5
@@ -129,12 +129,15 @@ fail:static inline struct posix_acl *ext4_iget_acl (struct inode *inode,struct posix_acl **i_acl) { -struct posix_acl *acl =EXT4_ACL_NOT_CACHED ; +struct posix_acl *acl =ACCESS_ONCE (*i_acl); -spin_lock (&inode->i_lock); -if (*i_acl !=EXT4_ACL_NOT_CACHED ) - acl =posix_acl_dup (*i_acl); -spin_unlock (&inode->i_lock); +if (acl) { +spin_lock (&inode->i_lock); + acl = *i_acl; +if (acl !=EXT4_ACL_NOT_CACHED ) + acl =posix_acl_dup (acl); +spin_unlock (&inode->i_lock); + }return acl; }
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 8/49 ext4: Simplify ext4_commit_super()'s function signature
The ext4_commit_super() function took both a struct super_block * and a struct ext4_super_block *, but the struct ext4_super_block can be derived from the struct super_block.
--- fs/ext4/super.c | 33 ++++++++++++++++----------------- 1 files changed, 16 insertions(+), 17 deletions(-)
fs/ext4/super.c +16 -17
@@ -54,8 +54,7 @@ static struct kset *ext4_kset;static int ext4_load_journal (struct super_block *,struct ext4_super_block *,unsigned long journal_devnum); -static int ext4_commit_super (struct super_block *sb, -struct ext4_super_block *es,int sync); +static int ext4_commit_super (struct super_block *sb,int sync);static void ext4_mark_recovery_complete (struct super_block *sb,struct ext4_super_block *es); static void ext4_clear_journal_err(struct super_block *sb,
@@ -306,7 +305,7 @@ static void ext4_handle_error(struct super_block *sb)printk (KERN_CRIT "Remounting filesystem read-only\n" ); sb->s_flags |=MS_RDONLY ; } -ext4_commit_super (sb, es,1 ); +ext4_commit_super (sb,1 );if (test_opt (sb,ERRORS_PANIC ))panic ("EXT4-fs (device %s): panic forced after error\n" , sb->s_id);
@@ -448,7 +447,7 @@ __acquires(bitlock)if (test_opt (sb,ERRORS_CONT )) {EXT4_SB (sb)->s_mount_state |=EXT4_ERROR_FS ; es->s_state |=cpu_to_le16 (EXT4_ERROR_FS ); -ext4_commit_super (sb, es,0 ); +ext4_commit_super (sb,0 );return ; }ext4_unlock_group (sb, grp);
@@ -577,7 +576,7 @@ static void ext4_put_super(struct super_block *sb)if (!(sb->s_flags &MS_RDONLY )) {EXT4_CLEAR_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER ); es->s_state =cpu_to_le16 (sbi->s_mount_state); -ext4_commit_super (sb, es,1 ); +ext4_commit_super (sb,1 ); }if (sbi->s_proc) {remove_proc_entry (sb->s_id, ext4_proc_root);
@@ -1596,7 +1595,7 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,if (sbi->s_journal)EXT4_SET_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER ); -ext4_commit_super (sb, es,1 ); +ext4_commit_super (sb,1 );if (test_opt (sb,DEBUG )) printk(KERN_INFO "[EXT4 FS bs=%lu, gc=%u, " "bpg=%lu, ipg=%lu, mo=%04lx]\n",
@@ -2655,7 +2654,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)if (test_opt (sb,ERRORS_PANIC )) {EXT4_SB (sb)->s_mount_state |=EXT4_ERROR_FS ; es->s_state |=cpu_to_le16 (EXT4_ERROR_FS ); -ext4_commit_super (sb, es,1 ); +ext4_commit_super (sb,1 ); goto failed_mount4; } }
@@ -3132,15 +3131,15 @@ static int ext4_load_journal(struct super_block *sb, sb->s_dirt =1 ;/* Make sure we flush the recovery flag to disk. */ -ext4_commit_super (sb, es,1 ); +ext4_commit_super (sb,1 ); }return 0 ; } -static int ext4_commit_super (struct super_block *sb, -struct ext4_super_block *es,int sync) +static int ext4_commit_super (struct super_block *sb,int sync) { +struct ext4_super_block *es =EXT4_SB (sb)->s_es;struct buffer_head *sbh =EXT4_SB (sb)->s_sbh;int error =0 ;
@@ -3212,7 +3211,7 @@ static void ext4_mark_recovery_complete(struct super_block *sb, sb->s_flags & MS_RDONLY) {EXT4_CLEAR_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER ); sb->s_dirt =0 ; -ext4_commit_super (sb, es,1 ); +ext4_commit_super (sb,1 ); }unlock_super (sb);
@@ -3253,7 +3252,7 @@ static void ext4_clear_journal_err(struct super_block *sb,EXT4_SB (sb)->s_mount_state |=EXT4_ERROR_FS ; es->s_state |=cpu_to_le16 (EXT4_ERROR_FS ); -ext4_commit_super (sb, es,1 ); +ext4_commit_super (sb,1 );jbd2_journal_clear_err (journal); }
@@ -3293,7 +3292,7 @@ static void ext4_write_super(struct super_block *sb)BUG (); sb->s_dirt =0 ; }else { -ext4_commit_super (sb,EXT4_SB (sb)->s_es,1 ); +ext4_commit_super (sb,1 ); } }
@@ -3312,7 +3311,7 @@ static int ext4_sync_fs(struct super_block *sb, int wait) target); } }else { -ext4_commit_super (sb,EXT4_SB (sb)->s_es, wait); +ext4_commit_super (sb, wait); }return ret; }
@@ -3345,7 +3344,7 @@ static int ext4_freeze(struct super_block *sb)/* Journal blocked and flushed, clear needs_recovery flag. */ EXT4_CLEAR_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER ); - error =ext4_commit_super (sb,EXT4_SB (sb)->s_es,1 ); + error =ext4_commit_super (sb,1 );if (error) goto out; }
@@ -3365,7 +3364,7 @@ static int ext4_unfreeze(struct super_block *sb)lock_super (sb);/* Reser the needs_recovery flag before the fs is unlocked. */ EXT4_SET_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER ); -ext4_commit_super (sb,EXT4_SB (sb)->s_es,1 ); +ext4_commit_super (sb,1 );unlock_super (sb);jbd2_journal_unlock_updates (EXT4_SB (sb)->s_journal); }
@@ -3520,7 +3519,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) } }if (sbi->s_journal ==NULL ) -ext4_commit_super (sb, es,1 ); +ext4_commit_super (sb,1 );#ifdef CONFIG_QUOTA /* Release old quota file names */
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 9/49 ext4: Fix and simplify s_dirt handling
The s_dirt flag wasn't completely handled correctly, but it didn't really matter when journalling was enabled. It turns out that when ext4 runs without a journal, we don't clear s_dirt in places where we should have, with the result that the high-level write_super() function was writing the superblock when it wasn't necessary.
So we fix this by making ext4_commit_super() clear the s_dirt flag, and removing many of the other places where s_dirt is manipulated. When journalling is enabled, the s_dirt flag might be left set more often, but s_dirt really doesn't matter when journalling is enabled.
--- fs/ext4/super.c | 14 +++----------- 1 files changed, 3 insertions(+), 11 deletions(-)
fs/ext4/super.c +3 -11
@@ -3128,7 +3128,6 @@ static int ext4_load_journal(struct super_block *sb,if (journal_devnum && journal_devnum !=le32_to_cpu (es->s_journal_dev)) { es->s_journal_dev =cpu_to_le32 (journal_devnum); - sb->s_dirt =1 ;/* Make sure we flush the recovery flag to disk. */ ext4_commit_super (sb,1 );
@@ -3168,7 +3167,7 @@ static int ext4_commit_super(struct super_block *sb, int sync) &EXT4_SB(sb)->s_freeblocks_counter)); es->s_free_inodes_count =cpu_to_le32 (percpu_counter_sum_positive ( &EXT4_SB (sb)->s_freeinodes_counter)); - + sb->s_dirt =0 ;BUFFER_TRACE (sbh,"marking dirty" );mark_buffer_dirty (sbh);if (sync) {
@@ -3210,7 +3209,6 @@ static void ext4_mark_recovery_complete(struct super_block *sb,if (EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER ) && sb->s_flags &MS_RDONLY ) {EXT4_CLEAR_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER ); - sb->s_dirt =0 ;ext4_commit_super (sb,1 ); }unlock_super (sb);
@@ -3271,10 +3269,8 @@ int ext4_force_commit(struct super_block *sb)return 0 ; journal =EXT4_SB (sb)->s_journal; -if (journal) { - sb->s_dirt =0 ; +if (journal) ret =ext4_journal_force_commit (journal); - }return ret; }
@@ -3282,15 +3278,13 @@ int ext4_force_commit(struct super_block *sb)/* * Ext4 always journals updates to the superblock itself, so we don't * have to propagate any other updates to the superblock on disk at this -* point. (We can probably nuke this function altogether, and remove -* any mention to sb->s_dirt in all of fs/ext4; eventual cleanup...) +* point if the journalling is enabled. */ static void ext4_write_super (struct super_block *sb) {if (EXT4_SB (sb)->s_journal) {if (mutex_trylock (&sb->s_lock) !=0 )BUG (); - sb->s_dirt =0 ; }else {ext4_commit_super (sb,1 ); }
@@ -3302,7 +3296,6 @@ static int ext4_sync_fs(struct super_block *sb, int wait)tid_t target;trace_mark (ext4_sync_fs,"dev %s wait %d" , sb->s_id, wait); - sb->s_dirt =0 ;if (EXT4_SB (sb)->s_journal) {if (jbd2_journal_start_commit (EXT4_SB (sb)->s_journal, &target)) {
@@ -3324,7 +3317,6 @@ static int ext4_freeze(struct super_block *sb) {int error =0 ;journal_t *journal; - sb->s_dirt =0 ;if (!(sb->s_flags &MS_RDONLY )) { journal =EXT4_SB (sb)->s_journal;
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 10/49 ext4: Use separate super_operations structure for no_journal filesystems
By using a separate super_operations structure for filesystems that have and don't have journals, we can simply ext4_write_super() --- which is only needed when no journal is present --- and ext4_freeze(), ext4_unfreeze(), and ext4_sync_fs(), which are only needed when the journal is present.
--- fs/ext4/super.c | 108 +++++++++++++++++++++++++++++-------------------------- 1 files changed, 57 insertions(+), 51 deletions(-)
fs/ext4/super.c +57 -51
@@ -995,7 +995,6 @@ static const struct super_operations ext4_sops = { .dirty_inode = ext4_dirty_inode, .delete_inode = ext4_delete_inode, .put_super = ext4_put_super, - .write_super = ext4_write_super, .sync_fs = ext4_sync_fs, .freeze_fs = ext4_freeze, .unfreeze_fs = ext4_unfreeze,
@@ -1010,6 +1009,25 @@ static const struct super_operations ext4_sops = { .bdev_try_to_free_page = bdev_try_to_free_page, }; +static const struct super_operations ext4_nojournal_sops = { + .alloc_inode = ext4_alloc_inode, + .destroy_inode = ext4_destroy_inode, + .write_inode = ext4_write_inode, + .dirty_inode = ext4_dirty_inode, + .delete_inode = ext4_delete_inode, + .write_super = ext4_write_super, + .put_super = ext4_put_super, + .statfs = ext4_statfs, + .remount_fs = ext4_remount, + .clear_inode = ext4_clear_inode, + .show_options = ext4_show_options, +#ifdef CONFIG_QUOTA + .quota_read = ext4_quota_read, + .quota_write = ext4_quota_write, +#endif + .bdev_try_to_free_page = bdev_try_to_free_page, +}; +static const struct export_operations ext4_export_ops = { .fh_to_dentry = ext4_fh_to_dentry, .fh_to_parent = ext4_fh_to_parent,
@@ -2615,7 +2633,11 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)/* * set up enough so that it can read an inode */ - sb->s_op = &ext4_sops; +if (!test_opt (sb,NOLOAD ) && +EXT4_HAS_COMPAT_FEATURE (sb,EXT4_FEATURE_COMPAT_HAS_JOURNAL )) + sb->s_op = &ext4_sops; +else + sb->s_op = &ext4_nojournal_sops; sb->s_export_op = &ext4_export_ops; sb->s_xattr = ext4_xattr_handlers;#ifdef CONFIG_QUOTA
@@ -3275,19 +3297,9 @@ int ext4_force_commit(struct super_block *sb)return ret; } -/* -* Ext4 always journals updates to the superblock itself, so we don't -* have to propagate any other updates to the superblock on disk at this -* point if the journalling is enabled. -*/ static void ext4_write_super (struct super_block *sb) { -if (EXT4_SB (sb)->s_journal) { -if (mutex_trylock (&sb->s_lock) !=0 ) -BUG (); - }else { -ext4_commit_super (sb,1 ); - } +ext4_commit_super (sb,1 ); }static int ext4_sync_fs (struct super_block *sb,int wait)
@@ -3296,15 +3308,9 @@ static int ext4_sync_fs(struct super_block *sb, int wait)tid_t target;trace_mark (ext4_sync_fs,"dev %s wait %d" , sb->s_id, wait); -if (EXT4_SB (sb)->s_journal) { -if (jbd2_journal_start_commit (EXT4_SB (sb)->s_journal, - &target)) { -if (wait) -jbd2_log_wait_commit (EXT4_SB (sb)->s_journal, - target); - } - }else { -ext4_commit_super (sb, wait); +if (jbd2_journal_start_commit (EXT4_SB (sb)->s_journal, &target)) { +if (wait) +jbd2_log_wait_commit (EXT4_SB (sb)->s_journal, target); }return ret; }
@@ -3318,32 +3324,31 @@ static int ext4_freeze(struct super_block *sb)int error =0 ;journal_t *journal; -if (!(sb->s_flags &MS_RDONLY )) { - journal =EXT4_SB (sb)->s_journal; +if (sb->s_flags &MS_RDONLY ) +return 0 ; -if (journal) { -/* Now we set up the journal barrier. */ -jbd2_journal_lock_updates (journal); + journal =EXT4_SB (sb)->s_journal; -/* -* We don't want to clear needs_recovery flag when we -* failed to flush the journal. -*/ - error =jbd2_journal_flush (journal); -if (error <0 ) - goto out; - } +/* Now we set up the journal barrier. */ +jbd2_journal_lock_updates (journal); -/* Journal blocked and flushed, clear needs_recovery flag. */ -EXT4_CLEAR_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER ); - error =ext4_commit_super (sb,1 ); -if (error) - goto out; +/* +* Don't clear the needs_recovery flag if we failed to flush +* the journal. +*/ + error =jbd2_journal_flush (journal); +if (error <0 ) { + out: +jbd2_journal_unlock_updates (journal); +return error; } + +/* Journal blocked and flushed, clear needs_recovery flag. */ +EXT4_CLEAR_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER ); + error =ext4_commit_super (sb,1 ); +if (error) + goto out;return 0 ; -out: -jbd2_journal_unlock_updates (journal); -return error; }/*
@@ -3352,14 +3357,15 @@ out:*/ static int ext4_unfreeze (struct super_block *sb) { -if (EXT4_SB (sb)->s_journal && !(sb->s_flags &MS_RDONLY )) { -lock_super (sb); -/* Reser the needs_recovery flag before the fs is unlocked. */ -EXT4_SET_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER ); -ext4_commit_super (sb,1 ); -unlock_super (sb); -jbd2_journal_unlock_updates (EXT4_SB (sb)->s_journal); - } +if (sb->s_flags &MS_RDONLY ) +return 0 ; + +lock_super (sb); +/* Reset the needs_recovery flag before the fs is unlocked. */ +EXT4_SET_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER ); +ext4_commit_super (sb,1 ); +unlock_super (sb); +jbd2_journal_unlock_updates (EXT4_SB (sb)->s_journal);return 0 ; }
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 11/49 ext4: Avoid races caused by on-line resizing and SMP memory reordering
Ext4's on-line resizing adds a new block group and then, only at the last step adjusts s_groups_count. However, it's possible on SMP systems that another CPU could see the updated the s_group_count and not see the newly initialized data structures for the just-added block group. For this reason, it's important to insert a SMP read barrier after reading s_groups_count and before reading any (for example) the new block group descriptors allowed by the increased value of s_groups_count.
Unfortunately, we rather blatently violate this locking protocol documented in fs/ext4/resize.c. Fortunately, (1) on-line resizes happen relatively rarely, and (2) it seems rare that the filesystem code will immediately try to use just-added block group before any memory ordering issues resolve themselves. So apparently problems here are relatively hard to hit, since ext3 has been vulnerable to the same issue for years with no one apparently complaining.
--- fs/ext4/balloc.c | 15 +++++++-------- fs/ext4/ext4.h | 12 ++++++++++++ fs/ext4/ialloc.c | 40 +++++++++++++++++++--------------------- fs/ext4/inode.c | 7 ++++--- fs/ext4/mballoc.c | 45 ++++++++++++++++++++++++--------------------- fs/ext4/super.c | 3 +-- 6 files changed, 67 insertions(+), 55 deletions(-)
fs/ext4/balloc.c +7 -8
@@ -88,6 +88,7 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh, ext4_group_t block_group, struct ext4_group_desc *gdp) { int bit, bit_max; +ext4_group_t ngroups =ext4_get_groups_count (sb);unsigned free_blocks, group_blocks;struct ext4_sb_info *sbi =EXT4_SB (sb);
@@ -123,7 +124,7 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh, bit_max +=ext4_bg_num_gdb (sb, block_group); } -if (block_group == sbi->s_groups_count -1 ) { +if (block_group == ngroups -1 ) {/* * Even though mke2fs always initialize first and last group * if some other tool enabled the EXT4_BG_BLOCK_UNINIT we need
@@ -131,7 +132,7 @@ unsigned ext4_init_block_bitmap(struct super_block *sb, struct buffer_head *bh,*/ group_blocks =ext4_blocks_count (sbi->s_es) -le32_to_cpu (sbi->s_es->s_first_data_block) - - (EXT4_BLOCKS_PER_GROUP (sb) * (sbi->s_groups_count -1 )); + (EXT4_BLOCKS_PER_GROUP (sb) * (ngroups -1 )); }else { group_blocks =EXT4_BLOCKS_PER_GROUP (sb); }
@@ -205,18 +206,18 @@ struct ext4_group_desc * ext4_get_group_desc(struct super_block *sb, {unsigned int group_desc;unsigned int offset; +ext4_group_t ngroups =ext4_get_groups_count (sb);struct ext4_group_desc *desc;struct ext4_sb_info *sbi =EXT4_SB (sb); -if (block_group >= sbi->s_groups_count) { +if (block_group >= ngroups) {ext4_error (sb,"ext4_get_group_desc" ,"block_group >= groups_count - " "block_group = %u, groups_count = %u" , - block_group, sbi->s_groups_count); + block_group, ngroups);return NULL ; } -smp_rmb (); group_desc = block_group >>EXT4_DESC_PER_BLOCK_BITS (sb); offset = block_group & (EXT4_DESC_PER_BLOCK (sb) -1 );
@@ -665,7 +666,7 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)ext4_fsblk_t desc_count;struct ext4_group_desc *gdp;ext4_group_t i; -ext4_group_t ngroups =EXT4_SB (sb)->s_groups_count; +ext4_group_t ngroups =ext4_get_groups_count (sb);#ifdef EXT4FS_DEBUG struct ext4_super_block *es;ext4_fsblk_t bitmap_count;
@@ -677,7 +678,6 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb) bitmap_count =0 ; gdp =NULL ; -smp_rmb ();for (i =0 ; i < ngroups; i++) { gdp =ext4_get_group_desc (sb, i,NULL );if (!gdp)
@@ -700,7 +700,6 @@ ext4_fsblk_t ext4_count_free_blocks(struct super_block *sb)return bitmap_count;#else desc_count =0 ; -smp_rmb ();for (i =0 ; i < ngroups; i++) { gdp =ext4_get_group_desc (sb, i,NULL );if (!gdp)
fs/ext4/ext4.h +12 -0
@@ -1228,6 +1228,18 @@ struct ext4_group_info *ext4_get_group_info(struct super_block *sb,return grp_info[indexv][indexh]; } +/* +* Reading s_groups_count requires using smp_rmb() afterwards. See +* the locking protocol documented in the comments of ext4_group_add() +* in resize.c +*/ +static inline ext4_group_t ext4_get_groups_count (struct super_block *sb) +{ +ext4_group_t ngroups =EXT4_SB (sb)->s_groups_count; + +smp_rmb (); +return ngroups; +}static inline ext4_group_t ext4_flex_group (struct ext4_sb_info *sbi,ext4_group_t block_group)
fs/ext4/ialloc.c +19 -21
@@ -316,7 +316,7 @@ error_return: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; +ext4_group_t ngroups =ext4_get_groups_count (sb);unsigned int freei, avefreei;struct ext4_group_desc *desc, *best_desc =NULL ;ext4_group_t group;
@@ -353,7 +353,7 @@ static int find_group_flex(struct super_block *sb, struct inode *parent,struct flex_groups *flex_group = sbi->s_flex_groups;ext4_group_t parent_group =EXT4_I (parent)->i_block_group;ext4_group_t parent_fbg_group =ext4_flex_group (sbi, parent_group); -ext4_group_t ngroups = sbi->s_groups_count; +ext4_group_t ngroups =ext4_get_groups_count (sb);int flex_size =ext4_flex_bg_size (sbi);ext4_group_t best_flex = parent_fbg_group;int blocks_per_flex = sbi->s_blocks_per_group * flex_size;
@@ -362,7 +362,7 @@ static int find_group_flex(struct super_block *sb, struct inode *parent,ext4_group_t n_fbg_groups;ext4_group_t i; - n_fbg_groups = (sbi->s_groups_count + flex_size -1 ) >> + n_fbg_groups = (ngroups + flex_size -1 ) >> sbi->s_log_groups_per_flex; find_close_to_parent:
@@ -478,20 +478,21 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent, {ext4_group_t parent_group =EXT4_I (parent)->i_block_group;struct ext4_sb_info *sbi =EXT4_SB (sb); -ext4_group_t ngroups = sbi->s_groups_count; +ext4_group_t real_ngroups =ext4_get_groups_count (sb);int inodes_per_group =EXT4_INODES_PER_GROUP (sb);unsigned int freei, avefreei;ext4_fsblk_t freeb, avefreeb;unsigned int ndirs;int max_dirs, min_inodes;ext4_grpblk_t min_blocks; -ext4_group_t i, grp, g; +ext4_group_t i, grp, g, ngroups;struct ext4_group_desc *desc;struct orlov_stats stats;int flex_size =ext4_flex_bg_size (sbi); + ngroups = real_ngroups;if (flex_size >1 ) { - ngroups = (ngroups + flex_size -1 ) >> + ngroups = (real_ngroups + flex_size -1 ) >> sbi->s_log_groups_per_flex; parent_group >>= sbi->s_log_groups_per_flex; }
@@ -543,7 +544,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent,*/ grp *= flex_size;for (i =0 ; i < flex_size; i++) { -if (grp+i >= sbi->s_groups_count) +if (grp+i >= real_ngroups)break ; desc =ext4_get_group_desc (sb, grp+i,NULL );if (desc &&ext4_free_inodes_count (sb, desc)) {
@@ -583,7 +584,7 @@ static int find_group_orlov(struct super_block *sb, struct inode *parent, } fallback: - ngroups = sbi->s_groups_count; + ngroups = real_ngroups; avefreei = freei / ngroups; fallback_retry: parent_group =EXT4_I (parent)->i_block_group;
@@ -613,9 +614,8 @@ static int find_group_other(struct super_block *sb, struct inode *parent, ext4_group_t *group, int mode) {ext4_group_t parent_group =EXT4_I (parent)->i_block_group; -ext4_group_t ngroups =EXT4_SB (sb)->s_groups_count; +ext4_group_t i, last, ngroups =ext4_get_groups_count (sb);struct ext4_group_desc *desc; -ext4_group_t i, last;int flex_size =ext4_flex_bg_size (EXT4_SB (sb));/*
@@ -799,11 +799,10 @@ struct inode *ext4_new_inode(handle_t *handle, struct inode *dir, int mode)struct super_block *sb;struct buffer_head *inode_bitmap_bh =NULL ;struct buffer_head *group_desc_bh; -ext4_group_t group =0 ; +ext4_group_t ngroups, 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 ret2, err =0 ;
@@ -818,15 +817,14 @@ struct inode *ext4_new_inode(handle_t *handle, struct inode *dir, int mode)return ERR_PTR (-EPERM ); sb = dir->i_sb; + ngroups =ext4_get_groups_count (sb);trace_mark (ext4_request_inode,"dev %s dir %lu mode %d" , sb->s_id, dir->i_ino, mode); inode =new_inode (sb);if (!inode)return ERR_PTR (-ENOMEM ); ei =EXT4_I (inode); - sbi =EXT4_SB (sb); - es = sbi->s_es;if (sbi->s_log_groups_per_flex &&test_opt (sb,OLDALLOC )) { ret2 =find_group_flex (sb, dir, &group);
@@ -856,7 +854,7 @@ got_group:if (ret2 ==-1 ) goto out; -for (i =0 ; i < sbi->s_groups_count; i++) { +for (i =0 ; i < ngroups; i++) { err = -EIO ; gdp =ext4_get_group_desc (sb, group, &group_desc_bh);
@@ -917,7 +915,7 @@ repeat_in_this_group:* group descriptor metadata has not yet been updated. * So we just go onto the next blockgroup. */ -if (++group == sbi->s_groups_count) +if (++group == ngroups) group =0 ; } err = -ENOSPC ;
@@ -1158,7 +1156,7 @@ unsigned long ext4_count_free_inodes(struct super_block *sb) {unsigned long desc_count;struct ext4_group_desc *gdp; -ext4_group_t i; +ext4_group_t i, ngroups =ext4_get_groups_count (sb);#ifdef EXT4FS_DEBUG struct ext4_super_block *es;unsigned long bitmap_count, x;
@@ -1168,7 +1166,7 @@ unsigned long ext4_count_free_inodes(struct super_block *sb) desc_count =0 ; bitmap_count =0 ; gdp =NULL ; -for (i =0 ; i <EXT4_SB (sb)->s_groups_count; i++) { +for (i =0 ; i < ngroups; i++) { gdp =ext4_get_group_desc (sb, i,NULL );if (!gdp)continue ;
@@ -1190,7 +1188,7 @@ unsigned long ext4_count_free_inodes(struct super_block *sb)return desc_count;#else desc_count =0 ; -for (i =0 ; i <EXT4_SB (sb)->s_groups_count; i++) { +for (i =0 ; i < ngroups; i++) { gdp =ext4_get_group_desc (sb, i,NULL );if (!gdp)continue ;
@@ -1205,9 +1203,9 @@ unsigned long ext4_count_free_inodes(struct super_block *sb)unsigned long ext4_count_dirs (struct super_block * sb) {unsigned long count =0 ; -ext4_group_t i; +ext4_group_t i, ngroups =ext4_get_groups_count (sb); -for (i =0 ; i <EXT4_SB (sb)->s_groups_count; i++) { +for (i =0 ; i < ngroups; i++) {struct ext4_group_desc *gdp =ext4_get_group_desc (sb, i,NULL );if (!gdp)continue ;
fs/ext4/inode.c +4 -3
@@ -4965,7 +4965,8 @@ static int ext4_index_trans_blocks(struct inode *inode, int nrblocks, int chunk)*/ int ext4_meta_trans_blocks (struct inode *inode,int nrblocks,int chunk) { -int groups, gdpblocks; +ext4_group_t groups, ngroups =ext4_get_groups_count (inode->i_sb); +int gdpblocks;int idxblocks;int ret =0 ;
@@ -4992,8 +4993,8 @@ int ext4_meta_trans_blocks(struct inode *inode, int nrblocks, int chunk) groups += nrblocks; gdpblocks = groups; -if (groups >EXT4_SB (inode->i_sb)->s_groups_count) - groups =EXT4_SB (inode->i_sb)->s_groups_count; +if (groups > ngroups) + groups = ngroups;if (groups >EXT4_SB (inode->i_sb)->s_gdb_count) gdpblocks =EXT4_SB (inode->i_sb)->s_gdb_count;
fs/ext4/mballoc.c +24 -21
185 lines not on this page · raw message
fs/ext4/super.c +1 -2
@@ -3557,9 +3557,8 @@ 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)) { -ext4_group_t ngroups = sbi->s_groups_count, i; +ext4_group_t i, ngroups =ext4_get_groups_count (sb);ext4_fsblk_t overhead =0 ; -smp_rmb ();/* * Compute the overhead (FS structures). This is constant
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 12/49 ext4: Remove outdated comment about lock_super()
ext4_fill_super() is no longer called by read_super(), and it is no longer called with the superblock locked. The unlock_super()/lock_super() is no longer present, so this comment is entirely superfluous.
--- fs/ext4/super.c | 8 -------- 1 files changed, 0 insertions(+), 8 deletions(-)
fs/ext4/super.c +0 -8
@@ -2828,14 +2828,6 @@ no_journal: goto failed_mount4; }; -/* -* akpm: core read_super() calls in here with the superblock locked. -* That deadlocks, because orphan cleanup needs to lock the superblock -* in numerous places. Here we just pop the lock - it's relatively -* harmless, because we are now ready to accept write_super() requests, -* and aviro says that's the only reason for hanging onto the -* superblock lock. -*/ EXT4_SB (sb)->s_mount_state |=EXT4_ORPHAN_FS ;ext4_orphan_cleanup (sb, es);EXT4_SB (sb)->s_mount_state &= ~EXT4_ORPHAN_FS ;
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 13/49 ext4: ext4_mark_recovery_complete() doesn't need to use lock_super
The function ext4_mark_recovery_complete() is called from two call
paths: either (a) while mounting the filesystem, in which case there's no danger of any other CPU calling write_super() until the mount is completed, and (b) while remounting the filesystem read-write, in which case the fs core has already locked the superblock. This also allows us to take out a very vile unlock_super()/lock_super() pair in ext4_remount().
--- fs/ext4/super.c | 11 +---------- 1 files changed, 1 insertions(+), 10 deletions(-)
fs/ext4/super.c +1 -10
@@ -3219,13 +3219,11 @@ static void ext4_mark_recovery_complete(struct super_block *sb,if (jbd2_journal_flush (journal) <0 ) goto out; -lock_super (sb);if (EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER ) && sb->s_flags &MS_RDONLY ) {EXT4_CLEAR_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER );ext4_commit_super (sb,1 ); } -unlock_super (sb); out:jbd2_journal_unlock_updates (journal);
@@ -3436,15 +3434,8 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) (sbi->s_mount_state & EXT4_VALID_FS)) es->s_state =cpu_to_le16 (sbi->s_mount_state); -/* -* We have to unlock super so that we can wait for -* transactions. -*/ -if (sbi->s_journal) { -unlock_super (sb); +if (sbi->s_journal)ext4_mark_recovery_complete (sb, es); -lock_super (sb); - } } else { int ret; if ((ret = EXT4_HAS_RO_COMPAT_FEATURE(sb,
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 14/49 ext4: Replace lock/unlock_super() with an explicit lock for the orphan list
Use a separate lock to protect the orphan list, so we can stop overloading the use of lock_super().
--- fs/ext4/ext4_sb.h | 1 + fs/ext4/namei.c | 20 +++++++++++--------- fs/ext4/super.c | 1 + 3 files changed, 13 insertions(+), 9 deletions(-)
fs/ext4/ext4_sb.h +1 -0
@@ -71,6 +71,7 @@ struct ext4_sb_info {struct inode *s_journal_inode;struct journal_s *s_journal;struct list_head s_orphan; +struct mutex s_orphan_lock;unsigned long s_commit_interval;u32 s_max_batch_time;u32 s_min_batch_time;
fs/ext4/namei.c +11 -9
@@ -1997,7 +1997,7 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)if (!ext4_handle_valid (handle))return 0 ; -lock_super (sb); +mutex_lock (&EXT4_SB (sb)->s_orphan_lock);if (!list_empty (&EXT4_I (inode)->i_orphan)) goto out_unlock;
@@ -2006,9 +2006,13 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)/* @@@ FIXME: Observation from aviro: * I think I can trigger J_ASSERT in ext4_orphan_add(). We block -* here (on lock_super()), so race with ext4_link() which might bump +* here (on s_orphan_lock), so race with ext4_link() which might bump * ->i_nlink. For, say it, character device. Not a regular file, * not a directory, not a symlink and ->i_nlink > 0. +* +* tytso, 4/25/2009: I'm not sure how that could happen; +* shouldn't the fs core protect us from these sort of +* unlink()/link() races? */ J_ASSERT ((S_ISREG (inode->i_mode) ||S_ISDIR (inode->i_mode) ||S_ISLNK (inode->i_mode)) || inode->i_nlink ==0 );
@@ -2045,7 +2049,7 @@ int ext4_orphan_add(handle_t *handle, struct inode *inode)jbd_debug (4 ,"orphan inode %lu will point to %d\n" , inode->i_ino,NEXT_ORPHAN (inode)); out_unlock: -unlock_super (sb); +mutex_unlock (&EXT4_SB (sb)->s_orphan_lock);ext4_std_error (inode->i_sb, err);return err; }
@@ -2066,11 +2070,9 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode)if (!ext4_handle_valid (handle))return 0 ; -lock_super (inode->i_sb); -if (list_empty (&ei->i_orphan)) { -unlock_super (inode->i_sb); -return 0 ; - } +mutex_lock (&EXT4_SB (inode->i_sb)->s_orphan_lock); +if (list_empty (&ei->i_orphan)) + goto out; ino_next =NEXT_ORPHAN (inode); prev = ei->i_orphan.prev;
@@ -2120,7 +2122,7 @@ int ext4_orphan_del(handle_t *handle, struct inode *inode) out_err:ext4_std_error (inode->i_sb, err); out: -unlock_super (inode->i_sb); +mutex_unlock (&EXT4_SB (inode->i_sb)->s_orphan_lock);return err; out_brelse:
fs/ext4/super.c +1 -0
@@ -2645,6 +2645,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) sb->dq_op = &ext4_quota_operations;#endif INIT_LIST_HEAD (&sbi->s_orphan);/* unlinked but open files */ +mutex_init (&sbi->s_orphan_lock); sb->s_root =NULL ;
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 15/49 ext4: Replace lock/unlock_super() with an explicit lock for resizing
Use a separate lock to protect s_groups_count and the other block group descriptors which get changed via an on-line resize operation, so we can stop overloading the use of lock_super().
--- fs/ext4/ext4_sb.h | 1 + fs/ext4/resize.c | 35 ++++++++++++++++++----------------- fs/ext4/super.c | 1 + 3 files changed, 20 insertions(+), 17 deletions(-)
fs/ext4/ext4_sb.h +1 -0
@@ -72,6 +72,7 @@ struct ext4_sb_info {struct journal_s *s_journal;struct list_head s_orphan;struct mutex s_orphan_lock; +struct mutex s_resize_lock;unsigned long s_commit_interval;u32 s_max_batch_time;u32 s_min_batch_time;
fs/ext4/resize.c +18 -17
@@ -193,7 +193,7 @@ static int setup_new_group_blocks(struct super_block *sb,if (IS_ERR (handle))return PTR_ERR (handle); -lock_super (sb); +mutex_lock (&sbi->s_resize_lock);if (input->group != sbi->s_groups_count) { err = -EBUSY ; goto exit_journal;
@@ -302,7 +302,7 @@ exit_bh:brelse (bh); exit_journal: -unlock_super (sb); +mutex_unlock (&sbi->s_resize_lock);if ((err2 =ext4_journal_stop (handle)) && !err) err = err2;
@@ -643,11 +643,12 @@ exit_free:* important part is that the new block and inode counts are in the backup * superblocks, and the location of the new group metadata in the GDT backups. * -* We do not need lock_super() for this, because these blocks are not -* otherwise touched by the filesystem code when it is mounted. We don't -* need to worry about last changing from sbi->s_groups_count, because the -* worst that can happen is that we do not copy the full number of backups -* at this time. The resize which changed s_groups_count will backup again. +* We do not need take the s_resize_lock for this, because these +* blocks are not otherwise touched by the filesystem code when it is +* mounted. We don't need to worry about last changing from +* sbi->s_groups_count, because the worst that can happen is that we +* do not copy the full number of backups at this time. The resize +* which changed s_groups_count will backup again. */ static void update_backups (struct super_block *sb,int blk_off,char *data,int size)
@@ -809,7 +810,7 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input) goto exit_put; } -lock_super (sb); +mutex_lock (&sbi->s_resize_lock);if (input->group != sbi->s_groups_count) {ext4_warning (sb, __func__,"multiple resizers run on filesystem!" );
@@ -840,7 +841,7 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)/* * OK, now we've set up the new group. Time to make it active. * -* Current kernels don't lock all allocations via lock_super(), +* We do not lock all allocations via s_resize_lock * so we have to be safe wrt. concurrent accesses the group * data. So we need to be careful to set all of the relevant * group descriptor data etc. *before* we enable the group.
@@ -900,12 +901,12 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input)* * The precise rules we use are: * -* * Writers of s_groups_count *must* hold lock_super +* * Writers of s_groups_count *must* hold s_resize_lock * AND * * Writers must perform a smp_wmb() after updating all dependent * data and before modifying the groups count * -* * Readers must hold lock_super() over the access +* * Readers must hold s_resize_lock over the access * OR * * Readers must perform an smp_rmb() after reading the groups count * and before reading any dependent data.
@@ -948,7 +949,7 @@ int ext4_group_add(struct super_block *sb, struct ext4_new_group_data *input) sb->s_dirt =1 ; exit_journal: -unlock_super (sb); +mutex_unlock (&sbi->s_resize_lock);if ((err2 =ext4_journal_stop (handle)) && !err) err = err2;if (!err) {
@@ -986,7 +987,7 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es,/* We don't need to worry about locking wrt other resizers just * yet: we're going to revalidate es->s_blocks_count after -* taking lock_super() below. */ +* taking the s_resize_lock below. */ o_blocks_count =ext4_blocks_count (es); o_groups_count =EXT4_SB (sb)->s_groups_count;
@@ -1056,11 +1057,11 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es, goto exit_put; } -lock_super (sb); +mutex_lock (&EXT4_SB (sb)->s_resize_lock);if (o_blocks_count !=ext4_blocks_count (es)) {ext4_warning (sb, __func__,"multiple resizers run on filesystem!" ); -unlock_super (sb); +mutex_unlock (&EXT4_SB (sb)->s_resize_lock);ext4_journal_stop (handle); err = -EBUSY ; goto exit_put;
@@ -1070,14 +1071,14 @@ int ext4_group_extend(struct super_block *sb, struct ext4_super_block *es, EXT4_SB(sb)->s_sbh))) {ext4_warning (sb, __func__,"error %d on journal write access" , err); -unlock_super (sb); +mutex_unlock (&EXT4_SB (sb)->s_resize_lock);ext4_journal_stop (handle); goto exit_put; }ext4_blocks_count_set (es, o_blocks_count + add);ext4_handle_dirty_metadata (handle,NULL ,EXT4_SB (sb)->s_sbh); sb->s_dirt =1 ; -unlock_super (sb); +mutex_unlock (&EXT4_SB (sb)->s_resize_lock);ext4_debug ("freeing blocks %llu through %llu\n" , o_blocks_count, o_blocks_count + add);/* We add the blocks to the bitmap and set the group need init bit */
fs/ext4/super.c +1 -0
@@ -2646,6 +2646,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)#endif INIT_LIST_HEAD (&sbi->s_orphan);/* unlinked but open files */ mutex_init (&sbi->s_orphan_lock); +mutex_init (&sbi->s_resize_lock); sb->s_root =NULL ;
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 16/49 ext4: Don't avoid using BLOCK_UNINIT block groups in mballoc
By avoiding the use of not-yet-used block groups (i.e., block groups with the BLOCK_UNINIT flag), mballoc had a tendency to create large files with large non-contiguous gaps. In addition avoiding the use of new block groups had a tendency to push regular file data into the first block group in a flex_bg group, which slows down the speed of e2fsck pass 2, since it has a tendency to seek much more. For example:
Before Patch After Patch
Time in seconds Time in seconds
Real / User/ Sys MB/s Real / User/ Sys MB/s
Pass 1 8.52 / 2.21 / 0.46 20.43 8.84 / 4.97 / 1.11 19.68 Pass 2 21.16 / 1.02 / 1.86 11.30 6.54 / 1.77 / 1.78 36.39 Pass 3 0.01 / 0.00 / 0.00 139.00 0.01 / 0.01 / 0.00 128.90 Pass 4 0.16 / 0.15 / 0.00 0.00 0.17 / 0.17 / 0.00 0.00 Pass 5 2.52 / 1.99 / 0.09 0.79 2.31 / 1.78 / 0.06 0.86
Total 32.40 / 5.11 / 2.49 12.81 17.99 / 8.75 / 2.98 23.01
This was on a sample 80 gig root filesystem which was approximately 50% full. Note the improved e2fsck pass 2 performance, by over a factor of 3, due to a decreased number of seeks. (The total amount of I/O in pass 2 was unchanged; the layout of the directory blocks was simply much better from e2fsck's's perspective.)
Other changes as a result of this patch on this sample filesystem:
Before Patch After Patch
# of non-contig files 762 779 # of non-contig directories 571 570 # of BLOCK_UNINIT bg's 307 293 # of INODE_UNINIT bg's 503 503
Out of 640 block groups, of which 333 were in use, this patch caused an extra 14 block groups to be utilized. The number of non-contiguous files did go up slightly, but when measured against the 99.9% of the files (603,154) which were contiguously allocated, this is pretty insignificant.
--- fs/ext4/mballoc.c | 9 +-------- 1 files changed, 1 insertions(+), 8 deletions(-)
fs/ext4/mballoc.c +1 -8
@@ -1728,7 +1728,6 @@ static int ext4_mb_good_group(struct ext4_allocation_context *ac,unsigned free, fragments;unsigned i, bits;int flex_size =ext4_flex_bg_size (EXT4_SB (ac->ac_sb)); -struct ext4_group_desc *desc;struct ext4_group_info *grp =ext4_get_group_info (ac->ac_sb, group);BUG_ON (cr <0 || cr >=4 );
@@ -1744,10 +1743,6 @@ static int ext4_mb_good_group(struct ext4_allocation_context *ac,switch (cr) {case 0 :BUG_ON (ac->ac_2order ==0 ); -/* If this group is uninitialized, skip it initially */ - desc =ext4_get_group_desc (ac->ac_sb, group,NULL ); -if (desc->bg_flags &cpu_to_le16 (EXT4_BG_BLOCK_UNINIT )) -return 0 ;/* Avoid using the first bg of a flexgroup for data files */ if ((ac->ac_flags & EXT4_MB_HINT_DATA) &&
@@ -2067,9 +2062,7 @@ repeat: ac->ac_groups_scanned++; desc =ext4_get_group_desc (sb, group,NULL ); -if (cr ==0 || (desc->bg_flags & -cpu_to_le16 (EXT4_BG_BLOCK_UNINIT ) && - ac->ac_2order !=0 )) +if (cr ==0 )ext4_mb_simple_scan_group (ac, &e4b);else if (cr ==1 && ac->ac_g_ex.fe_len == sbi->s_stripe)
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 17/49 ext4: Move the ext4_i.h header file into ext4.h
There is no longer a reason for a separate ext4_i.h header file, so move it into ext4.h just to make life easier for developers to find the relevant data structures and typedefs. Should also speed up compiles slightly, too.
--- fs/ext4/ext4.h | 122 ++++++++++++++++++++++++++++++++++++++++++++++- fs/ext4/ext4_i.h | 140 ------------------------------------------------------ 2 files changed, 121 insertions(+), 141 deletions(-) delete mode 100644 fs/ext4/ext4_i.h
fs/ext4/ext4.h +121 -1
@@ -21,7 +21,10 @@#include <linux/magic.h> #include <linux/jbd2.h> #include <linux/quota.h> -#include "ext4_i.h" +#include <linux/rwsem.h> +#include <linux/rbtree.h> +#include <linux/seqlock.h> +#include <linux/mutex.h> /* * The fourth extended filesystem constants/structures
@@ -46,6 +49,19 @@ #define ext4_debug(f, a...) do {} while (0)#endif +/* data type for block offset of block group */ +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 ; + +/* data type for block group number */ +typedef unsigned int ext4_group_t ; + +/* prefer goal again. length */ #define EXT4_MB_HINT_MERGE 1/* blocks already reserved */
@@ -516,6 +532,110 @@ do { \#endif /* defined(__KERNEL__) || defined(__linux__) */ /* +* storage for cached extent +*/ +struct ext4_ext_cache { +ext4_fsblk_t ec_start; +ext4_lblk_t ec_block; +__u32 ec_len;/* must be 32bit to return holes */ +__u32 ec_type; +}; + +/* +* fourth extended file system inode data in memory +*/ +struct ext4_inode_info { +__le32 i_data[15 ];/* unconverted */ +__u32 i_flags; +ext4_fsblk_t i_file_acl; +__u32 i_dtime; + +/* +* i_block_group is the number of the block group which contains +* this file's inode. Constant across the lifetime of the inode, +* it is ued for making block allocation decisions - we try to +* place a file's data blocks near its inode block, and new inodes +* near to their parent directory's inode. +*/ +ext4_group_t i_block_group; +__u32 i_state;/* Dynamic state flags for ext4 */ + +ext4_lblk_t i_dir_start_lookup; +#ifdef CONFIG_EXT4_FS_XATTR +/* +* Extended attributes can be read independently of the main file +* data. Taking i_mutex even when reading would cause contention +* between readers of EAs and writers of regular file data, so +* instead we synchronize on xattr_sem when reading or changing +* EAs. +*/ +struct rw_semaphore xattr_sem; +#endif +#ifdef CONFIG_EXT4_FS_POSIX_ACL +struct posix_acl *i_acl; +struct posix_acl *i_default_acl; +#endif + +struct list_head i_orphan;/* unlinked but open inodes */ + +/* +* i_disksize keeps track of what the inode size is ON DISK, not +* in memory. During truncate, i_size is set to the new size by +* the VFS prior to calling ext4_truncate(), but the filesystem won't +* set i_disksize to 0 until the truncate is actually under way. +* +* The intent is that i_disksize always represents the blocks which +* are used by this file. This allows recovery to restart truncate +* on orphans if we crash during truncate. We actually write i_disksize +* into the on-disk inode when writing inodes out, instead of i_size. +* +* The only time when i_disksize and i_size may be different is when +* a truncate is in progress. The only things which change i_disksize +* are ext4_get_block (growth) and ext4_truncate (shrinkth). +*/ +loff_t i_disksize; + +/* +* 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 i_data_sem. +*/ +struct rw_semaphore i_data_sem; +struct inode vfs_inode; +struct jbd2_inode jinode; + +struct ext4_ext_cache i_cached_extent; +/* +* File creation time. Its function is same as that of +* struct timespec i_{a,c,m}time in the generic inode. +*/ +struct timespec i_crtime; + +/* mballoc */ +struct list_head i_prealloc_list; +spinlock_t i_prealloc_lock; + +/* ialloc */ +ext4_group_t i_last_alloc_group; + +/* allocation reservation info for delalloc */ +unsigned int i_reserved_data_blocks; +unsigned int i_reserved_meta_blocks; +unsigned int i_allocated_meta_blocks; +unsigned short i_delalloc_reserved_flag; + +/* on-disk additional length */ +__u16 i_extra_isize; + +spinlock_t i_block_reservation_lock; +}; + +/* * File system states */ #define EXT4_VALID_FS 0x0001/* Unmounted cleanly */
fs/ext4/ext4_i.h deleted +0 -140
140 lines not on this page · raw message
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 18/49 ext4: Move the ext4_sb.h header file into ext4.h
There is no longer a reason for a separate ext4_sb.h header file, so move it into ext4.h just to make life easier for developers to find the relevant data structures and typedefs. Should also speed up compiles slightly, too.
--- fs/ext4/ext4.h | 144 +++++++++++++++++++++++++++++++++++++++++++++- fs/ext4/ext4_sb.h | 163 ----------------------------------------------------- 2 files changed, 140 insertions(+), 167 deletions(-) delete mode 100644 fs/ext4/ext4_sb.h
fs/ext4/ext4.h +140 -4
@@ -25,6 +25,10 @@#include <linux/rbtree.h> #include <linux/seqlock.h> #include <linux/mutex.h> +#include <linux/timer.h> +#include <linux/wait.h> +#include <linux/blockgroup_lock.h> +#include <linux/percpu_counter.h> /* * The fourth extended filesystem constants/structures
@@ -195,9 +199,6 @@ struct flex_groups {#define EXT4_BG_BLOCK_UNINIT 0x0002/* Block bitmap not in use */ #define EXT4_BG_INODE_ZEROED 0x0004/* On-disk itable initialized to zero */ -#ifdef __KERNEL__ -#include "ext4_sb.h" -#endif /* * Macro-instructions used to manage group descriptors */
@@ -809,6 +810,136 @@ struct ext4_super_block { };#ifdef __KERNEL__ +/* +* fourth extended-fs super-block data in memory +*/ +struct ext4_sb_info { +unsigned long s_desc_size;/* Size of a group descriptor in bytes */ +unsigned long s_inodes_per_block;/* Number of inodes per block */ +unsigned long s_blocks_per_group;/* Number of blocks in a group */ +unsigned long s_inodes_per_group;/* Number of inodes in a group */ +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 */ +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; +unsigned long s_mount_opt; +ext4_fsblk_t s_sb_block; +uid_t s_resuid; +gid_t s_resgid; +unsigned short s_mount_state; +unsigned short s_pad; +int s_addr_per_block_bits; +int s_desc_per_block_bits; +int s_inode_size; +int s_first_ino; +unsigned int s_inode_readahead_blks; +spinlock_t s_next_gen_lock; +u32 s_next_generation; +u32 s_hash_seed[4 ]; +int s_def_hash_version; +int s_hash_unsigned;/* 3 if hash should be signed, 0 if not */ +struct percpu_counter s_freeblocks_counter; +struct percpu_counter s_freeinodes_counter; +struct percpu_counter s_dirs_counter; +struct percpu_counter s_dirtyblocks_counter; +struct blockgroup_lock *s_blockgroup_lock; +struct proc_dir_entry *s_proc; +struct kobject s_kobj; +struct completion s_kobj_unregister; + +/* Journaling */ +struct inode *s_journal_inode; +struct journal_s *s_journal; +struct list_head s_orphan; +struct mutex s_orphan_lock; +struct mutex s_resize_lock; +unsigned long s_commit_interval; +u32 s_max_batch_time; +u32 s_min_batch_time; +struct block_device *journal_bdev; +#ifdef CONFIG_JBD2_DEBUG +struct timer_list turn_ro_timer;/* For turning read-only (crash simulation) */ +wait_queue_head_t ro_wait_queue;/* For people waiting for the fs to go read-only */ +#endif +#ifdef CONFIG_QUOTA +char *s_qf_names[MAXQUOTAS ];/* Names of quota files with journalled quota */ +int s_jquota_fmt;/* Format of quota to use */ +#endif +unsigned int s_want_extra_isize;/* New inodes should reserve # bytes */ + +#ifdef EXTENTS_STATS +/* ext4 extents stats */ +unsigned long s_ext_min; +unsigned long s_ext_max; +unsigned long s_depth_max; +spinlock_t s_ext_stats_lock; +unsigned long s_ext_blocks; +unsigned long s_ext_extents; +#endif + +/* for buddy allocator */ +struct ext4_group_info ***s_group_info; +struct inode *s_buddy_cache; +long s_blocks_reserved; +spinlock_t s_reserve_lock; +spinlock_t s_md_lock; +tid_t s_last_transaction; +unsigned short *s_mb_offsets; +unsigned int *s_mb_maxs; + +/* tunables */ +unsigned long s_stripe; +unsigned int s_mb_stream_request; +unsigned int s_mb_max_to_scan; +unsigned int s_mb_min_to_scan; +unsigned int s_mb_stats; +unsigned int s_mb_order2_reqs; +unsigned int s_mb_group_prealloc; +/* where last allocation was done - for stream allocation */ +unsigned long s_mb_last_group; +unsigned long s_mb_last_start; + +/* history to debug policy */ +struct ext4_mb_history *s_mb_history; +int s_mb_history_cur; +int s_mb_history_max; +int s_mb_history_num; +spinlock_t s_mb_history_lock; +int s_mb_history_filter; + +/* stats for buddy allocator */ +spinlock_t s_mb_pa_lock; +atomic_t s_bal_reqs;/* number of reqs with len > 1 */ +atomic_t s_bal_success;/* we found long enough chunks */ +atomic_t s_bal_allocated;/* in blocks */ +atomic_t s_bal_ex_scanned;/* total extents scanned */ +atomic_t s_bal_goals;/* goal hits */ +atomic_t s_bal_breaks;/* too long searches */ +atomic_t s_bal_2orders;/* 2^order hits */ +spinlock_t s_bal_lock; +unsigned long s_mb_buddies_generated; +unsigned long long s_mb_generation_time; +atomic_t s_mb_lost_chunks; +atomic_t s_mb_preallocated; +atomic_t s_mb_discarded; + +/* locality groups */ +struct ext4_locality_group *s_locality_groups; + +/* for write statistics */ +unsigned long s_sectors_written_start; +u64 s_kbytes_written; + +unsigned int s_log_groups_per_flex; +struct flex_groups *s_flex_groups; +}; +static inline struct ext4_sb_info *EXT4_SB (struct super_block *sb) {return sb->s_fs_info;
@@ -824,7 +955,6 @@ static inline struct timespec ext4_current_time(struct inode *inode) current_fs_time(inode->i_sb) : CURRENT_TIME_SEC; } -static inline int ext4_valid_inum (struct super_block *sb,unsigned long ino) { return ino == EXT4_ROOT_INO ||
@@ -833,6 +963,12 @@ static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino) (ino >=EXT4_FIRST_INO (sb) && ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count)); } + +static inline spinlock_t * +sb_bgl_lock (struct ext4_sb_info *sbi,unsigned int block_group) +{ +return bgl_lock_ptr (sbi->s_blockgroup_lock, block_group); +}#else /* Assume that user mode programs are passing in an ext4fs superblock, not * a kernel struct super_block. This will allow us to call the feature-test
fs/ext4/ext4_sb.h deleted +0 -163
163 lines not on this page · raw message
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 19/49 ext4: Move fs/ext4/namei.h into ext4.h
The fs/ext4/namei.h header file had only a single function declaration, and should have never been a standalone file. Move it into ext4.h, where should have been from the beginning.
--- fs/ext4/ext4.h | 1 + fs/ext4/namei.c | 1 - fs/ext4/namei.h | 8 -------- fs/ext4/super.c | 1 - 4 files changed, 1 insertions(+), 10 deletions(-) delete mode 100644 fs/ext4/namei.h
fs/ext4/ext4.h +1 -0
@@ -1594,6 +1594,7 @@ extern const struct file_operations ext4_file_operations;/* namei.c */ extern const struct inode_operations ext4_dir_inode_operations;extern const struct inode_operations ext4_special_inode_operations; +extern struct dentry *ext4_get_parent (struct dentry *child);/* symlink.c */ extern const struct inode_operations ext4_symlink_inode_operations;
fs/ext4/namei.c +0 -1
@@ -37,7 +37,6 @@#include "ext4.h" #include "ext4_jbd2.h" -#include "namei.h" #include "xattr.h" #include "acl.h"
fs/ext4/namei.h deleted +0 -8
@@ -1,8 +0,0 @@ -/* linux/fs/ext4/namei.h -* -* Copyright (C) 2005 Simtec Electronics -* Ben Dooks <[email protected]> -* -*/ - -extern struct dentry *ext4_get_parent (struct dentry *child);
fs/ext4/super.c +0 -1
@@ -46,7 +46,6 @@#include "ext4_jbd2.h" #include "xattr.h" #include "acl.h" -#include "namei.h" #include "group.h" struct proc_dir_entry *ext4_proc_root;
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 20/49 ext4: Move fs/ext4/group.h into ext4.h
Move the function prototypes in group.h into ext4.h so they are all defined in one place.
--- fs/ext4/balloc.c | 1 - fs/ext4/ext4.h | 17 +++++++++++++++++ fs/ext4/group.h | 29 ----------------------------- fs/ext4/ialloc.c | 1 - fs/ext4/mballoc.h | 1 - fs/ext4/resize.c | 1 - fs/ext4/super.c | 1 - 7 files changed, 17 insertions(+), 34 deletions(-) delete mode 100644 fs/ext4/group.h
fs/ext4/balloc.c +0 -1
@@ -19,7 +19,6 @@#include <linux/buffer_head.h> #include "ext4.h" #include "ext4_jbd2.h" -#include "group.h" #include "mballoc.h" /*
fs/ext4/ext4.h +17 -0
@@ -1270,6 +1270,14 @@ extern struct ext4_group_desc * ext4_get_group_desc(struct super_block * sb,ext4_group_t block_group, struct buffer_head ** bh);extern int ext4_should_retry_alloc (struct super_block *sb,int *retries); +struct buffer_head *ext4_read_block_bitmap (struct super_block *sb, +ext4_group_t block_group); +extern unsigned ext4_init_block_bitmap (struct super_block *sb, +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)/* dir.c */ extern int ext4_check_dir_entry(const char *, struct inode *,
@@ -1294,6 +1302,11 @@ extern struct inode * ext4_orphan_get(struct super_block *, unsigned long);extern unsigned long ext4_count_free_inodes (struct super_block *);extern unsigned long ext4_count_dirs (struct super_block *);extern void ext4_check_inodes_bitmap (struct super_block *); +extern unsigned ext4_init_inode_bitmap (struct super_block *sb, +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);/* mballoc.c */ extern long ext4_mb_stats;
@@ -1417,6 +1430,10 @@ extern void ext4_used_dirs_set(struct super_block *sb, struct ext4_group_desc *bg, __u32 count);extern void ext4_itable_unused_set (struct super_block *sb,struct ext4_group_desc *bg,__u32 count); +extern __le16 ext4_group_desc_csum (struct ext4_sb_info *sbi,__u32 group, +struct ext4_group_desc *gdp); +extern int ext4_group_desc_csum_verify (struct ext4_sb_info *sbi,__u32 group, +struct ext4_group_desc *gdp);static inline ext4_fsblk_t ext4_blocks_count (struct ext4_super_block *es) {
fs/ext4/group.h deleted +0 -29
@@ -1,29 +0,0 @@ -/* -* linux/fs/ext4/group.h -* -* Copyright (C) 2007 Cluster File Systems, Inc -* -* Author: Andreas Dilger <[email protected]> -*/ - -#ifndef _LINUX_EXT4_GROUP_H -#define _LINUX_EXT4_GROUP_H - -extern __le16 ext4_group_desc_csum (struct ext4_sb_info *sbi,__u32 group, -struct ext4_group_desc *gdp); -extern int ext4_group_desc_csum_verify (struct ext4_sb_info *sbi,__u32 group, -struct ext4_group_desc *gdp); -struct buffer_head *ext4_read_block_bitmap (struct super_block *sb, -ext4_group_t block_group); -extern unsigned ext4_init_block_bitmap (struct super_block *sb, -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, -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 +0 -1
@@ -27,7 +27,6 @@#include "ext4_jbd2.h" #include "xattr.h" #include "acl.h" -#include "group.h" /* * ialloc.c contains the inodes allocation and deallocation routines
fs/ext4/mballoc.h +0 -1
@@ -23,7 +23,6 @@#include <linux/mutex.h> #include "ext4_jbd2.h" #include "ext4.h" -#include "group.h" /* * with AGGRESSIVE_CHECK allocator runs consistency checks over
fs/ext4/resize.c +0 -1
@@ -15,7 +15,6 @@#include <linux/slab.h> #include "ext4_jbd2.h" -#include "group.h" #define outside (b, first, last) ((b) < (first) || (b) >= (last))#define inside (b, first, last) ((b) >= (first) && (b) < (last))
fs/ext4/super.c +0 -1
@@ -46,7 +46,6 @@#include "ext4_jbd2.h" #include "xattr.h" #include "acl.h" -#include "group.h" struct proc_dir_entry *ext4_proc_root;static struct kset *ext4_kset;
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 21/49 ext4: Make the length of the mb_history file tunable
From: Curt Wohlgemuth <[email protected]>
In memory-constrained systems with many partitions, the ~68K for each partition for the mb_history buffer can be excessive.
This patch adds a new mount option, mb_history_length, as well as a way of setting the default via a module parameter (or via a sysfs parameter in /sys/module/ext4/parameter/default_mb_history_length). If the mb_history_length is set to zero, the mb_history facility is disabled entirely.
--- fs/ext4/mballoc.c | 13 +++++++------ fs/ext4/super.c | 18 +++++++++++++++++- 2 files changed, 24 insertions(+), 7 deletions(-)
fs/ext4/mballoc.c +7 -6
@@ -2413,7 +2413,8 @@ static void ext4_mb_history_release(struct super_block *sb)if (sbi->s_proc !=NULL ) {remove_proc_entry ("mb_groups" , sbi->s_proc); -remove_proc_entry ("mb_history" , sbi->s_proc); +if (sbi->s_mb_history_max) +remove_proc_entry ("mb_history" , sbi->s_proc); }kfree (sbi->s_mb_history); }
@@ -2424,17 +2425,17 @@ static void ext4_mb_history_init(struct super_block *sb)int i;if (sbi->s_proc !=NULL ) { -proc_create_data ("mb_history" ,S_IRUGO , sbi->s_proc, - &ext4_mb_seq_history_fops, sb); +if (sbi->s_mb_history_max) +proc_create_data ("mb_history" ,S_IRUGO , sbi->s_proc, + &ext4_mb_seq_history_fops, sb);proc_create_data ("mb_groups" ,S_IRUGO , sbi->s_proc, &ext4_mb_seq_groups_fops, sb); } - sbi->s_mb_history_max =1000 ; sbi->s_mb_history_cur =0 ;spin_lock_init (&sbi->s_mb_history_lock); i = sbi->s_mb_history_max *sizeof (struct ext4_mb_history ); - sbi->s_mb_history =kzalloc (i,GFP_KERNEL ); + sbi->s_mb_history = i ?kzalloc (i,GFP_KERNEL ) :NULL ;/* if we can't allocate history, then we simple won't use it */ }
@@ -2444,7 +2445,7 @@ ext4_mb_store_history(struct ext4_allocation_context *ac)struct ext4_sb_info *sbi =EXT4_SB (ac->ac_sb);struct ext4_mb_history h; -if (unlikely (sbi->s_mb_history ==NULL )) +if (sbi->s_mb_history ==NULL )return ;if (!(ac->ac_op & sbi->s_mb_history_filter))
fs/ext4/super.c +17 -1
@@ -47,6 +47,13 @@#include "xattr.h" #include "acl.h" +static int default_mb_history_length =1000 ; + +module_param_named (default_mb_history_length, default_mb_history_length, + int,0644 ); +MODULE_PARM_DESC (default_mb_history_length, +"Default number of entries saved for mb_history" ); +struct proc_dir_entry *ext4_proc_root;static struct kset *ext4_kset;
@@ -1042,7 +1049,7 @@ enum { Opt_journal_update, Opt_journal_dev, Opt_journal_checksum, Opt_journal_async_commit, Opt_abort, Opt_data_journal, Opt_data_ordered, Opt_data_writeback, - Opt_data_err_abort, Opt_data_err_ignore, + Opt_data_err_abort, Opt_data_err_ignore, Opt_mb_history_length, Opt_usrjquota, Opt_grpjquota, Opt_offusrjquota, Opt_offgrpjquota, Opt_jqfmt_vfsold, Opt_jqfmt_vfsv0, Opt_quota, Opt_noquota, Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err, Opt_resize,
@@ -1088,6 +1095,7 @@ static const match_table_t tokens = { {Opt_data_writeback, "data=writeback"}, {Opt_data_err_abort, "data_err=abort"}, {Opt_data_err_ignore, "data_err=ignore"}, + {Opt_mb_history_length, "mb_history_length=%u"}, {Opt_offusrjquota, "usrjquota="}, {Opt_usrjquota, "usrjquota=%s"}, {Opt_offgrpjquota, "grpjquota="},
@@ -1329,6 +1337,13 @@ static int parse_options(char *options, struct super_block *sb,case Opt_data_err_ignore:clear_opt (sbi->s_mount_opt,DATA_ERR_ABORT );break ; +case Opt_mb_history_length: +if (match_int (&args[0 ], &option)) +return 0 ; +if (option <0 ) +return 0 ; + sbi->s_mb_history_max = option; +break ;#ifdef CONFIG_QUOTA case Opt_usrjquota: qtype =USRQUOTA ;
@@ -2345,6 +2360,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) sbi->s_commit_interval =JBD2_DEFAULT_MAX_COMMIT_AGE *HZ ; sbi->s_min_batch_time =EXT4_DEF_MIN_BATCH_TIME ; sbi->s_max_batch_time =EXT4_DEF_MAX_BATCH_TIME ; + sbi->s_mb_history_max = default_mb_history_length;set_opt (sbi->s_mount_opt,BARRIER );
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 22/49 ext4: hook fiemap operation for directories
From: Aneesh Kumar K.V <[email protected]>
Add fiemap callback for directories
--- fs/ext4/namei.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
fs/ext4/namei.c +1 -0
@@ -2534,6 +2534,7 @@ const struct inode_operations ext4_dir_inode_operations = { .removexattr = generic_removexattr, #endif .permission = ext4_permission, + .fiemap = ext4_fiemap, }; const struct inode_operations ext4_special_inode_operations = {
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 23/49 vfs: Enable FS_IOC_FIEMAP and FIGETBSZ for all filetypes
From: Aneesh Kumar K.V <[email protected]>
The fiemap and get_blk_size ioctls should be enabled even for directories. So move it outisde file_ioctl.
--- fs/ioctl.c | 14 ++++++++++---- 1 files changed, 10 insertions(+), 4 deletions(-)
fs/ioctl.c +10 -4
@@ -414,10 +414,6 @@ static int file_ioctl(struct file *filp, unsigned int cmd,switch (cmd) {case FIBMAP :return ioctl_fibmap (filp, p); -case FS_IOC_FIEMAP : -return ioctl_fiemap (filp, arg); -case FIGETBSZ : -return put_user (inode->i_sb->s_blocksize, p);case FIONREAD :return put_user (i_size_read (inode) - filp->f_pos, p); }
@@ -557,6 +553,16 @@ int do_vfs_ioctl(struct file *filp, unsigned int fd, unsigned int cmd, error =ioctl_fsthaw (filp);break ; +case FS_IOC_FIEMAP : +return ioctl_fiemap (filp, arg); + +case FIGETBSZ : + { +struct inode *inode = filp->f_path.dentry->d_inode; +int __user *p = (int __user *)arg; +return put_user (inode->i_sb->s_blocksize, p); + } +default :if (S_ISREG (filp->f_path.dentry->d_inode->i_mode)) error =file_ioctl (filp, cmd, arg);
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 24/49 ext4: fix for fiemap last-block test
From: Eric Sandeen <[email protected]>
Carl Henrik Lunde reported and debugged this; the test for the last allocated block was comparing bytes to blocks in this test:
if (logical + length - 1 == EXT_MAX_BLOCK || ext4_ext_next_allocated_block(path) == EXT_MAX_BLOCK) flags |= FIEMAP_EXTENT_LAST;
so any extent which ended right at 4G was stopping the extent walk. Just replacing these values with the extent block & length should fix it.
Also give blksize_bits a saner type, and reverse the order of the tests to make the more likely case tested first.
--- fs/ext4/extents.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
fs/ext4/extents.c +3 -3
@@ -3196,7 +3196,7 @@ static int ext4_ext_fiemap_cb(struct inode *inode, struct ext4_ext_path *path, void *data) {struct fiemap_extent_info *fieinfo = data; -unsigned long blksize_bits = inode->i_sb->s_blocksize_bits; +unsigned char blksize_bits = inode->i_sb->s_blocksize_bits;__u64 logical;__u64 physical;__u64 length;
@@ -3243,8 +3243,8 @@ static int ext4_ext_fiemap_cb(struct inode *inode, struct ext4_ext_path *path,* * XXX this might miss a single-block extent at EXT_MAX_BLOCK */ -if (logical + length -1 ==EXT_MAX_BLOCK || -ext4_ext_next_allocated_block (path) ==EXT_MAX_BLOCK ) +if (ext4_ext_next_allocated_block (path) ==EXT_MAX_BLOCK || + newex->ec_block + newex->ec_len -1 ==EXT_MAX_BLOCK ) flags |=FIEMAP_EXTENT_LAST ; error = fiemap_fill_next_extent(fieinfo, logical, physical,
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 25/49 ext4: fix the length returned by fiemap for an unallocated extent
If the file's blocks have not yet been allocated because of delayed allocation, the length of the extent returned by fiemap is incorrect. This commit fixes this bug.
--- fs/ext4/extents.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
fs/ext4/extents.c +8 -1
@@ -3244,8 +3244,15 @@ static int ext4_ext_fiemap_cb(struct inode *inode, struct ext4_ext_path *path,* XXX this might miss a single-block extent at EXT_MAX_BLOCK */ if (ext4_ext_next_allocated_block (path) ==EXT_MAX_BLOCK || - newex->ec_block + newex->ec_len -1 ==EXT_MAX_BLOCK ) + newex->ec_block + newex->ec_len -1 ==EXT_MAX_BLOCK ) { +loff_t size =i_size_read (inode); +loff_t bs =EXT4_BLOCK_SIZE (inode->i_sb); + flags |=FIEMAP_EXTENT_LAST ; +if ((flags &FIEMAP_EXTENT_DELALLOC ) && + logical+length > size) + length = (size - logical + bs -1 ) & ~(bs-1 ); + } error =fiemap_fill_next_extent (fieinfo, logical, physical, length, flags);
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 26/49 ext4: Convert ext4_lock_group to use sb_bgl_lock
From: Aneesh Kumar K.V <[email protected]>
We have sb_bgl_lock() and ext4_group_info.bb_state
bit spinlock to protech group information. The later is only used within mballoc code. Consolidate them to use sb_bgl_lock(). This makes the mballoc.c code much simpler and also avoid confusion with two locks protecting same info.
--- fs/ext4/balloc.c | 12 ++++---- fs/ext4/ext4.h | 26 ++++++----------- fs/ext4/ialloc.c | 29 +++++++++---------- fs/ext4/mballoc.c | 78 ++++++++++++++++++---------------------------------- fs/ext4/super.c | 6 ++-- 5 files changed, 59 insertions(+), 92 deletions(-)
fs/ext4/balloc.c +6 -6
@@ -326,16 +326,16 @@ ext4_read_block_bitmap(struct super_block *sb, ext4_group_t block_group)unlock_buffer (bh);return bh; } -spin_lock (sb_bgl_lock (EXT4_SB (sb), block_group)); +ext4_lock_group (sb, block_group);if (desc->bg_flags &cpu_to_le16 (EXT4_BG_BLOCK_UNINIT )) {ext4_init_block_bitmap (sb, bh, block_group, desc);set_bitmap_uptodate (bh);set_buffer_uptodate (bh); -spin_unlock (sb_bgl_lock (EXT4_SB (sb), block_group)); +ext4_unlock_group (sb, block_group);unlock_buffer (bh);return bh; } -spin_unlock (sb_bgl_lock (EXT4_SB (sb), block_group)); +ext4_unlock_group (sb, block_group);if (buffer_uptodate (bh)) {/* * if not uninit if bh is uptodate,
@@ -451,7 +451,7 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb,down_write (&grp->alloc_sem);for (i =0 , blocks_freed =0 ; i < count; i++) {BUFFER_TRACE (bitmap_bh,"clear bit" ); -if (!ext4_clear_bit_atomic (sb_bgl_lock (sbi, block_group), +if (!ext4_clear_bit_atomic (ext4_group_lock_ptr (sb, block_group), bit + i, bitmap_bh->b_data)) { ext4_error(sb, __func__, "bit already cleared for block %llu",
@@ -461,11 +461,11 @@ void ext4_add_groupblocks(handle_t *handle, struct super_block *sb, blocks_freed++; } } -spin_lock (sb_bgl_lock (sbi, block_group)); +ext4_lock_group (sb, block_group); blk_free_count = blocks_freed +ext4_free_blks_count (sb, desc);ext4_free_blks_set (sb, desc, blk_free_count); desc->bg_checksum =ext4_group_desc_csum (sbi, block_group, desc); -spin_unlock (sb_bgl_lock (sbi, block_group)); +ext4_unlock_group (sb, block_group);percpu_counter_add (&sbi->s_freeblocks_counter, blocks_freed);if (sbi->s_log_groups_per_flex) {
fs/ext4/ext4.h +9 -17
@@ -963,12 +963,6 @@ static inline int ext4_valid_inum(struct super_block *sb, unsigned long ino) (ino >=EXT4_FIRST_INO (sb) && ino <= le32_to_cpu(EXT4_SB(sb)->s_es->s_inodes_count)); } - -static inline spinlock_t * -sb_bgl_lock (struct ext4_sb_info *sbi,unsigned int block_group) -{ -return bgl_lock_ptr (sbi->s_blockgroup_lock, block_group); -}#else /* Assume that user mode programs are passing in an ext4fs superblock, not * a kernel struct super_block. This will allow us to call the feature-test
@@ -1568,33 +1562,31 @@ struct ext4_group_info { };#define EXT4_GROUP_INFO_NEED_INIT_BIT 0 -#define EXT4_GROUP_INFO_LOCKED_BIT 1#define EXT4_MB_GRP_NEED_INIT (grp) \ (test_bit(EXT4_GROUP_INFO_NEED_INIT_BIT, &((grp)->bb_state))) -static inline void ext4_lock_group (struct super_block *sb,ext4_group_t group) +static inline spinlock_t *ext4_group_lock_ptr (struct super_block *sb, +ext4_group_t group) { -struct ext4_group_info *grinfo =ext4_get_group_info (sb, group); +return bgl_lock_ptr (EXT4_SB (sb)->s_blockgroup_lock, group); +} -bit_spin_lock (EXT4_GROUP_INFO_LOCKED_BIT , &(grinfo->bb_state)); +static inline void ext4_lock_group (struct super_block *sb,ext4_group_t group) +{ +spin_lock (ext4_group_lock_ptr (sb, group)); }static inline void ext4_unlock_group (struct super_block *sb,ext4_group_t group) { -struct ext4_group_info *grinfo =ext4_get_group_info (sb, group); - -bit_spin_unlock (EXT4_GROUP_INFO_LOCKED_BIT , &(grinfo->bb_state)); +spin_unlock (ext4_group_lock_ptr (sb, group)); }static inline int ext4_is_group_locked (struct super_block *sb,ext4_group_t group) { -struct ext4_group_info *grinfo =ext4_get_group_info (sb, group); - -return bit_spin_is_locked (EXT4_GROUP_INFO_LOCKED_BIT , - &(grinfo->bb_state)); +return spin_is_locked (ext4_group_lock_ptr (sb, group)); }/*
fs/ext4/ialloc.c +14 -15
@@ -122,16 +122,16 @@ ext4_read_inode_bitmap(struct super_block *sb, ext4_group_t block_group)unlock_buffer (bh);return bh; } -spin_lock (sb_bgl_lock (EXT4_SB (sb), block_group)); +ext4_lock_group (sb, block_group);if (desc->bg_flags &cpu_to_le16 (EXT4_BG_INODE_UNINIT )) {ext4_init_inode_bitmap (sb, bh, block_group, desc);set_bitmap_uptodate (bh);set_buffer_uptodate (bh); -spin_unlock (sb_bgl_lock (EXT4_SB (sb), block_group)); +ext4_unlock_group (sb, block_group);unlock_buffer (bh);return bh; } -spin_unlock (sb_bgl_lock (EXT4_SB (sb), block_group)); +ext4_unlock_group (sb, block_group);if (buffer_uptodate (bh)) {/* * if not uninit if bh is uptodate,
@@ -246,9 +246,8 @@ void ext4_free_inode(handle_t *handle, struct inode *inode) goto error_return;/* Ok, now we can actually update the inode bitmaps.. */ -spin_lock (sb_bgl_lock (sbi, block_group)); - cleared =ext4_clear_bit (bit, bitmap_bh->b_data); -spin_unlock (sb_bgl_lock (sbi, block_group)); + cleared =ext4_clear_bit_atomic (ext4_group_lock_ptr (sb, block_group), + bit, bitmap_bh->b_data);if (!cleared)ext4_error (sb,"ext4_free_inode" ,"bit already cleared for inode %lu" , ino);
@@ -260,7 +259,7 @@ void ext4_free_inode(handle_t *handle, struct inode *inode)if (fatal) goto error_return;if (gdp) { -spin_lock (sb_bgl_lock (sbi, block_group)); +ext4_lock_group (sb, block_group); count =ext4_free_inodes_count (sb, gdp) +1 ;ext4_free_inodes_set (sb, gdp, count);if (is_directory) {
@@ -276,7 +275,7 @@ void ext4_free_inode(handle_t *handle, struct inode *inode) } gdp->bg_checksum =ext4_group_desc_csum (sbi, block_group, gdp); -spin_unlock (sb_bgl_lock (sbi, block_group)); +ext4_unlock_group (sb, block_group);percpu_counter_inc (&sbi->s_freeinodes_counter);if (is_directory)percpu_counter_dec (&sbi->s_dirs_counter);
@@ -707,10 +706,10 @@ static int find_group_other(struct super_block *sb, struct inode *parent,/* * claim the inode from the inode bitmap. If the group -* is uninit we need to take the groups's sb_bgl_lock +* is uninit we need to take the groups's ext4_group_lock * and clear the uninit flag. The inode bitmap update * and group desc uninit flag clear should be done -* after holding sb_bgl_lock so that ext4_read_inode_bitmap +* after holding ext4_group_lock so that ext4_read_inode_bitmap * doesn't race with the ext4_claim_inode */ static int ext4_claim_inode(struct super_block *sb,
@@ -721,7 +720,7 @@ static int ext4_claim_inode(struct super_block *sb,struct ext4_sb_info *sbi =EXT4_SB (sb);struct ext4_group_desc *gdp =ext4_get_group_desc (sb, group,NULL ); -spin_lock (sb_bgl_lock (sbi, group)); +ext4_lock_group (sb, group);if (ext4_set_bit (ino, inode_bitmap_bh->b_data)) {/* not a free inode */ retval =1 ;
@@ -730,7 +729,7 @@ static int ext4_claim_inode(struct super_block *sb, ino++;if ((group ==0 && ino <EXT4_FIRST_INO (sb)) || ino >EXT4_INODES_PER_GROUP (sb)) { -spin_unlock (sb_bgl_lock (sbi, group)); +ext4_unlock_group (sb, group); ext4_error(sb, __func__, "reserved inode or inode > inodes count - " "block_group = %u, inode=%lu", group,
@@ -779,7 +778,7 @@ static int ext4_claim_inode(struct super_block *sb, } gdp->bg_checksum =ext4_group_desc_csum (sbi, group, gdp); err_ret: -spin_unlock (sb_bgl_lock (sbi, group)); +ext4_unlock_group (sb, group);return retval; }
@@ -935,7 +934,7 @@ got: } free =0 ; -spin_lock (sb_bgl_lock (sbi, group)); +ext4_lock_group (sb, group);/* recheck and clear flag under lock if we still need to */ if (gdp->bg_flags &cpu_to_le16 (EXT4_BG_BLOCK_UNINIT )) { free =ext4_free_blocks_after_init (sb, group, gdp);
@@ -944,7 +943,7 @@ got: gdp->bg_checksum =ext4_group_desc_csum (sbi, group, gdp); } -spin_unlock (sb_bgl_lock (sbi, group)); +ext4_unlock_group (sb, group);/* Don't need to dirty bitmap block if we didn't change it */ if (free) {
fs/ext4/mballoc.c +27 -51
205 lines not on this page · raw message
fs/ext4/super.c +3 -3
@@ -1784,18 +1784,18 @@ static int ext4_check_descriptors(struct super_block *sb) "(block %llu)!\n", i, inode_table);return 0 ; } -spin_lock (sb_bgl_lock (sbi, i)); +ext4_lock_group (sb, i);if (!ext4_group_desc_csum_verify (sbi, i, gdp)) {printk (KERN_ERR "EXT4-fs: ext4_check_descriptors: " "Checksum for group %u failed (%u!=%u)\n" , i,le16_to_cpu (ext4_group_desc_csum (sbi, i, gdp)),le16_to_cpu (gdp->bg_checksum));if (!(sb->s_flags &MS_RDONLY )) { -spin_unlock (sb_bgl_lock (sbi, i)); +ext4_unlock_group (sb, i);return 0 ; } } -spin_unlock (sb_bgl_lock (sbi, i)); +ext4_unlock_group (sb, i);if (!flexbg_flag) first_block +=EXT4_BLOCKS_PER_GROUP (sb); }
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 27/49 ext4: Fix spinlock assertions on UP systems
From: Vincent Minet <[email protected]>
On UP systems without DEBUG_SPINLOCK, ext4_is_group_locked always fails which triggers a BUG_ON() call.
This patch fixes it by using assert_spin_locked instead.
--- fs/ext4/ext4.h | 6 ------ fs/ext4/mballoc.c | 10 +++++----- 2 files changed, 5 insertions(+), 11 deletions(-)
fs/ext4/ext4.h +0 -6
@@ -1583,12 +1583,6 @@ static inline void ext4_unlock_group(struct super_block *sb,spin_unlock (ext4_group_lock_ptr (sb, group)); } -static inline int ext4_is_group_locked (struct super_block *sb, -ext4_group_t group) -{ -return spin_is_locked (ext4_group_lock_ptr (sb, group)); -} -/* * Inodes and files operations */
fs/ext4/mballoc.c +5 -5
@@ -436,7 +436,7 @@ static void mb_free_blocks_double(struct inode *inode, struct ext4_buddy *e4b,if (unlikely (e4b->bd_info->bb_bitmap ==NULL ))return ; -BUG_ON (!ext4_is_group_locked (sb, e4b->bd_group)); +assert_spin_locked (ext4_group_lock_ptr (sb, e4b->bd_group));for (i =0 ; i < count; i++) {if (!mb_test_bit (first + i, e4b->bd_info->bb_bitmap)) {ext4_fsblk_t blocknr;
@@ -460,7 +460,7 @@ static void mb_mark_used_double(struct ext4_buddy *e4b, int first, int count)if (unlikely (e4b->bd_info->bb_bitmap ==NULL ))return ; -BUG_ON (!ext4_is_group_locked (e4b->bd_sb, e4b->bd_group)); +assert_spin_locked (ext4_group_lock_ptr (e4b->bd_sb, e4b->bd_group));for (i =0 ; i < count; i++) {BUG_ON (mb_test_bit (first + i, e4b->bd_info->bb_bitmap));mb_set_bit (first + i, e4b->bd_info->bb_bitmap);
@@ -1115,7 +1115,7 @@ static void mb_free_blocks(struct inode *inode, struct ext4_buddy *e4b,struct super_block *sb = e4b->bd_sb;BUG_ON (first + count > (sb->s_blocksize <<3 )); -BUG_ON (!ext4_is_group_locked (sb, e4b->bd_group)); +assert_spin_locked (ext4_group_lock_ptr (sb, e4b->bd_group));mb_check_buddy (e4b);mb_free_blocks_double (inode, e4b, first, count);
@@ -1196,7 +1196,7 @@ static int mb_find_extent(struct ext4_buddy *e4b, int order, int block,int ord;void *buddy; -BUG_ON (!ext4_is_group_locked (e4b->bd_sb, e4b->bd_group)); +assert_spin_locked (ext4_group_lock_ptr (e4b->bd_sb, e4b->bd_group));BUG_ON (ex ==NULL ); buddy =mb_find_buddy (e4b, order, &max);
@@ -1260,7 +1260,7 @@ static int mb_mark_used(struct ext4_buddy *e4b, struct ext4_free_extent *ex)BUG_ON (start + len > (e4b->bd_sb->s_blocksize <<3 ));BUG_ON (e4b->bd_group != ex->fe_group); -BUG_ON (!ext4_is_group_locked (e4b->bd_sb, e4b->bd_group)); +assert_spin_locked (ext4_group_lock_ptr (e4b->bd_sb, e4b->bd_group));mb_check_buddy (e4b);mb_mark_used_double (e4b, start, len);
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 28/49 ext4: Simplify function signature for ext4_da_get_block_write()
The function ext4_da_get_block_write() is called in exactly one write, and the last argument, create, is always 1. Remove it to simplify the code slightly.
--- fs/ext4/inode.c | 6 +++--- 1 files changed, 3 insertions(+), 3 deletions(-)
fs/ext4/inode.c +3 -3
@@ -2000,7 +2000,7 @@ static void ext4_print_free_blocks(struct inode *inode)#define EXT4_DELALLOC_RSVED 1static int ext4_da_get_block_write (struct inode *inode,sector_t iblock, -struct buffer_head *bh_result,int create) +struct buffer_head *bh_result) {int ret;unsigned max_blocks = bh_result->b_size >> inode->i_blkbits;
@@ -2010,7 +2010,7 @@ static int ext4_da_get_block_write(struct inode *inode, sector_t iblock, handle =ext4_journal_current_handle ();BUG_ON (!handle); ret =ext4_get_blocks_wrap (handle, inode, iblock, max_blocks, - bh_result, create,0 ,EXT4_DELALLOC_RSVED ); + bh_result,1 ,0 ,EXT4_DELALLOC_RSVED );if (ret <=0 )return ret;
@@ -2088,7 +2088,7 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd)if (!new.b_size)return 0 ; - err =ext4_da_get_block_write (mpd->inode, next, &new,1 ); + err =ext4_da_get_block_write (mpd->inode, next, &new);if (err) {/* * If get block returns with error we simply
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 29/49 ext4: Rename ext4_get_blocks_handle() to be ext4_ind_get_blocks()
The static function ext4_get_blocks_handle() is badly named. Of *course* it takes a handle. Since its counterpart for extent-based file is ext4_ext_get_blocks(), rename it to be ext4_ind_get_blocks().
--- fs/ext4/inode.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
fs/ext4/inode.c +6 -6
@@ -914,7 +914,7 @@ err_out:* 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) */ -static int ext4_get_blocks_handle (handle_t *handle,struct inode *inode, +static int ext4_ind_get_blocks (handle_t *handle,struct inode *inode,ext4_lblk_t iblock,unsigned int maxblocks,struct buffer_head *bh_result,int create,int extend_disksize)
@@ -1129,7 +1129,7 @@ static void ext4_da_update_reserve_space(struct inode *inode, int used)* mapped. * * If file type is extents based, it will call ext4_ext_get_blocks(), -* Otherwise, call with ext4_get_blocks_handle() to handle indirect mapping +* Otherwise, call with ext4_ind_get_blocks() to handle indirect mapping * based files * * On success, it returns the number of blocks being mapped or allocate.
@@ -1160,8 +1160,8 @@ int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, retval =ext4_ext_get_blocks (handle, inode, block, max_blocks, bh,0 ,0 ); }else { - retval =ext4_get_blocks_handle (handle, - inode, block, max_blocks, bh,0 ,0 ); + retval =ext4_ind_get_blocks (handle, inode, block, max_blocks, + bh,0 ,0 ); }up_read ((&EXT4_I (inode)->i_data_sem));
@@ -1215,7 +1215,7 @@ int ext4_get_blocks_wrap(handle_t *handle, struct inode *inode, sector_t block, retval =ext4_ext_get_blocks (handle, inode, block, max_blocks, bh, create, extend_disksize); }else { - retval =ext4_get_blocks_handle (handle, inode, block, + retval =ext4_ind_get_blocks (handle, inode, block, max_blocks, bh, create, extend_disksize);if (retval >0 &&buffer_new (bh)) {
@@ -1297,7 +1297,7 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, err =ext4_get_blocks_wrap (handle, inode, block,1 , &dummy, create,1 ,0 );/* -* ext4_get_blocks_handle() returns number of blocks +* ext4_get_blocks_wrap() returns number of blocks * mapped. 0 in case of a HOLE. */ if (err >0 ) {
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 30/49 ext4: Rename ext4_get_blocks_wrap() to be ext4_get_blocks()
Another function rename for clarity's sake. The _wrap prefix simply confuses people, and didn't add much people trying to follow the code paths.
--- fs/ext4/dir.c | 3 +-- fs/ext4/ext4.h | 8 ++++---- fs/ext4/extents.c | 6 +++--- fs/ext4/inode.c | 35 +++++++++++++++++------------------ 4 files changed, 25 insertions(+), 27 deletions(-)
fs/ext4/dir.c +1 -2
@@ -131,8 +131,7 @@ static int ext4_readdir(struct file *filp,struct buffer_head *bh =NULL ; map_bh.b_state =0 ; - err =ext4_get_blocks_wrap (NULL , inode, blk,1 , &map_bh, -0 ,0 ,0 ); + err =ext4_get_blocks (NULL , inode, blk,1 , &map_bh,0 ,0 ,0 );if (err >0 ) {pgoff_t index = map_bh.b_blocknr >> (PAGE_CACHE_SHIFT - inode->i_blkbits);
fs/ext4/ext4.h +4 -4
@@ -1617,10 +1617,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); -extern int ext4_get_blocks_wrap (handle_t *handle,struct inode *inode, -sector_t block,unsigned int max_blocks, -struct buffer_head *bh,int create, -int extend_disksize,int flag); +extern int ext4_get_blocks (handle_t *handle,struct inode *inode, +sector_t block,unsigned int max_blocks, +struct buffer_head *bh,int create, +int extend_disksize,int flag);extern int ext4_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,__u64 start,__u64 len);
fs/ext4/extents.c +3 -3
@@ -3151,9 +3151,9 @@ retry:break ; } map_bh.b_state =0 ; - ret =ext4_get_blocks_wrap (handle, inode, block, - max_blocks, &map_bh, -EXT4_CREATE_UNINITIALIZED_EXT ,0 ,0 ); + ret =ext4_get_blocks (handle, inode, block, + max_blocks, &map_bh, +EXT4_CREATE_UNINITIALIZED_EXT ,0 ,0 );if (ret <=0 ) {#ifdef EXT4FS_DEBUG WARN_ON (ret <=0 );
fs/ext4/inode.c +17 -18
@@ -1121,7 +1121,7 @@ static void ext4_da_update_reserve_space(struct inode *inode, int used) }/* -* The ext4_get_blocks_wrap() function try to look up the requested blocks, +* The ext4_get_blocks() function tries to look up the requested blocks, * and returns if the blocks are already mapped. * * Otherwise it takes the write lock of the i_data_sem and allocate blocks
@@ -1142,9 +1142,9 @@ static void ext4_da_update_reserve_space(struct inode *inode, int used)* * It returns the error in case of allocation failure. */ -int ext4_get_blocks_wrap (handle_t *handle,struct inode *inode,sector_t block, -unsigned int max_blocks,struct buffer_head *bh, -int create,int extend_disksize,int flag) +int ext4_get_blocks (handle_t *handle,struct inode *inode,sector_t block, +unsigned int max_blocks,struct buffer_head *bh, +int create,int extend_disksize,int flag) {int retval;
@@ -1268,8 +1268,8 @@ int ext4_get_block(struct inode *inode, sector_t iblock, started =1 ; } - ret =ext4_get_blocks_wrap (handle, inode, iblock, - max_blocks, bh_result, create,0 ,0 ); + ret =ext4_get_blocks (handle, inode, iblock, max_blocks, bh_result, + create,0 ,0 );if (ret >0 ) { bh_result->b_size = (ret << inode->i_blkbits); ret =0 ;
@@ -1294,10 +1294,9 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, dummy.b_state =0 ; dummy.b_blocknr =-1000 ;buffer_trace_init (&dummy.b_history); - err =ext4_get_blocks_wrap (handle, inode, block,1 , - &dummy, create,1 ,0 ); + err =ext4_get_blocks (handle, inode, block,1 , &dummy, create,1 ,0 );/* -* ext4_get_blocks_wrap() returns number of blocks +* ext4_get_blocks() returns number of blocks * mapped. 0 in case of a HOLE. */ if (err >0 ) {
@@ -2009,8 +2008,8 @@ static int ext4_da_get_block_write(struct inode *inode, sector_t iblock, handle =ext4_journal_current_handle ();BUG_ON (!handle); - ret =ext4_get_blocks_wrap (handle, inode, iblock, max_blocks, - bh_result,1 ,0 ,EXT4_DELALLOC_RSVED ); + ret =ext4_get_blocks (handle, inode, iblock, max_blocks, + bh_result,1 ,0 ,EXT4_DELALLOC_RSVED );if (ret <=0 )return ret;
@@ -2067,11 +2066,11 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd)/* * We need to make sure the BH_Delay flag is passed down to * ext4_da_get_block_write(), since it calls -* ext4_get_blocks_wrap() with the EXT4_DELALLOC_RSVED flag. -* This flag causes ext4_get_blocks_wrap() to call +* ext4_get_blocks() with the EXT4_DELALLOC_RSVED flag. +* This flag causes ext4_get_blocks() to call * ext4_da_update_reserve_space() if the passed buffer head * has the BH_Delay flag set. In the future, once we clean up -* the interfaces to ext4_get_blocks_wrap(), we should pass in +* the interfaces to ext4_get_blocks(), we should pass in * a separate flag which requests that the delayed allocation * statistics should be updated, instead of depending on the * state information getting passed down via the map_bh's
@@ -2363,7 +2362,7 @@ static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock,* preallocated blocks are unmapped but should treated * the same as allocated blocks. */ - ret =ext4_get_blocks_wrap (NULL , inode, iblock,1 , bh_result,0 ,0 ,0 ); + ret =ext4_get_blocks (NULL , inode, iblock,1 , bh_result,0 ,0 ,0 );if ((ret ==0 ) && !buffer_delay (bh_result)) {/* the block isn't (pre)allocated yet, let's reserve space */ /*
@@ -2407,8 +2406,8 @@ static int ext4_normal_get_block_write(struct inode *inode, sector_t iblock,* we don't want to do block allocation in writepage * so call get_block_wrap with create = 0 */ - ret =ext4_get_blocks_wrap (NULL , inode, iblock, max_blocks, - bh_result,0 ,0 ,0 ); + ret =ext4_get_blocks (NULL , inode, iblock, max_blocks, + bh_result,0 ,0 ,0 );if (ret >0 ) { bh_result->b_size = (ret << inode->i_blkbits); ret =0 ;
@@ -5034,7 +5033,7 @@ int ext4_writepage_trans_blocks(struct inode *inode)* Calculate the journal credits for a chunk of data modification. * * This is called from DIO, fallocate or whoever calling -* ext4_get_blocks_wrap() to map/allocate a chunk of contigous disk blocks. +* ext4_get_blocks() to map/allocate a chunk of contigous disk blocks. * * journal buffers for data blocks are not included here, as DIO * and fallocate do no need to journal data buffers.
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 31/49 ext4: Define a new set of flags for ext4_get_blocks()
The functions ext4_get_blocks(), ext4_ext_get_blocks(), and ext4_ind_get_blocks() used an ad-hoc set of integer variables used as boolean flags passed in as arguments. Use a single flags parameter and a setandard set of bitfield flags instead. This saves space on the call stack, and it also makes the code a bit more understandable.
--- fs/ext4/dir.c | 2 +- fs/ext4/ext4.h | 22 ++++++++++++++------ fs/ext4/extents.c | 22 ++++++++++---------- fs/ext4/inode.c | 57 +++++++++++++++++++++++++++------------------------- 4 files changed, 57 insertions(+), 46 deletions(-)
fs/ext4/dir.c +1 -1
@@ -131,7 +131,7 @@ static int ext4_readdir(struct file *filp,struct buffer_head *bh =NULL ; map_bh.b_state =0 ; - err =ext4_get_blocks (NULL , inode, blk,1 , &map_bh,0 ,0 ,0 ); + err =ext4_get_blocks (NULL , inode, blk,1 , &map_bh,0 );if (err >0 ) {pgoff_t index = map_bh.b_blocknr >> (PAGE_CACHE_SHIFT - inode->i_blkbits);
fs/ext4/ext4.h +15 -7
@@ -314,10 +314,20 @@ struct ext4_new_group_data { };/* -* Following is used by preallocation code to tell get_blocks() that we -* want uninitialzed extents. +* Flags used by ext4_get_blocks() */ -#define EXT4_CREATE_UNINITIALIZED_EXT 2 +/* Allocate any needed blocks and/or convert an unitialized +extent to be an initialized ext4 */ +#define EXT4_GET_BLOCKS_CREATE 1 +/* Request the creation of an unitialized extent */ +#define EXT4_GET_BLOCKS_UNINIT_EXT 2 +#define EXT4_GET_BLOCKS_CREATE_UNINIT_EXT (EXT4_GET_BLOCKS_UNINIT_EXT|\ + EXT4_GET_BLOCKS_CREATE) +/* Update the ext4_inode_info i_disksize field */ +#define EXT4_GET_BLOCKS_EXTEND_DISKSIZE 4 +/* Caller is from the delayed allocation writeout path, +so the filesystem blocks have already been accounted for */ +#define EXT4_GET_BLOCKS_DELALLOC_RESERVE 8/* * ioctl commands
@@ -1610,8 +1620,7 @@ extern int ext4_ext_index_trans_blocks(struct inode *inode, int nrblocks, int chunk);extern int ext4_ext_get_blocks (handle_t *handle,struct inode *inode,ext4_lblk_t iblock,unsigned int max_blocks, -struct buffer_head *bh_result, -int create,int extend_disksize); +struct buffer_head *bh_result,int flags);extern void ext4_ext_truncate (struct inode *);extern void ext4_ext_init (struct super_block *);extern void ext4_ext_release (struct super_block *);
@@ -1619,8 +1628,7 @@ extern long ext4_fallocate(struct inode *inode, int mode, loff_t offset, loff_t len);extern int ext4_get_blocks (handle_t *handle,struct inode *inode,sector_t block,unsigned int max_blocks, -struct buffer_head *bh,int create, -int extend_disksize,int flag); +struct buffer_head *bh,int flags);extern int ext4_fiemap (struct inode *inode,struct fiemap_extent_info *fieinfo,__u64 start,__u64 len);
fs/ext4/extents.c +11 -11
@@ -2784,7 +2784,7 @@ fix_extent_len:int ext4_ext_get_blocks (handle_t *handle,struct inode *inode,ext4_lblk_t iblock,unsigned int max_blocks,struct buffer_head *bh_result, -int create,int extend_disksize) +int flags) {struct ext4_ext_path *path =NULL ;struct ext4_extent_header *eh;
@@ -2803,7 +2803,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, cache_type =ext4_ext_in_cache (inode, iblock, &newex);if (cache_type) {if (cache_type ==EXT4_EXT_CACHE_GAP ) { -if (!create) { +if ((flags &EXT4_GET_BLOCKS_CREATE ) ==0 ) {/* * block isn't allocated yet and * user doesn't want to allocate it
@@ -2869,9 +2869,9 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, EXT4_EXT_CACHE_EXTENT); goto out; } -if (create ==EXT4_CREATE_UNINITIALIZED_EXT ) +if (flags &EXT4_GET_BLOCKS_UNINIT_EXT ) goto out; -if (!create) { +if ((flags &EXT4_GET_BLOCKS_CREATE ) ==0 ) {if (allocated > max_blocks) allocated = max_blocks;/*
@@ -2903,7 +2903,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,* requested block isn't allocated yet; * we couldn't try to create block if create flag is zero */ -if (!create) { +if ((flags &EXT4_GET_BLOCKS_CREATE ) ==0 ) {/* * put just found gap into cache to speed up * subsequent requests
@@ -2932,10 +2932,10 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,* EXT_UNINIT_MAX_LEN. */ if (max_blocks >EXT_INIT_MAX_LEN && - create !=EXT4_CREATE_UNINITIALIZED_EXT ) + !(flags &EXT4_GET_BLOCKS_UNINIT_EXT )) max_blocks =EXT_INIT_MAX_LEN ;else if (max_blocks >EXT_UNINIT_MAX_LEN && - create ==EXT4_CREATE_UNINITIALIZED_EXT ) + (flags &EXT4_GET_BLOCKS_UNINIT_EXT )) max_blocks =EXT_UNINIT_MAX_LEN ;/* Check if we can really insert (iblock)::(iblock+max_blocks) extent */
@@ -2966,7 +2966,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,/* try to insert new extent into found leaf and return */ ext4_ext_store_pblock (&newex, newblock); newex.ee_len =cpu_to_le16 (ar.len); -if (create ==EXT4_CREATE_UNINITIALIZED_EXT )/* Mark uninitialized */ +if (flags &EXT4_GET_BLOCKS_UNINIT_EXT )/* Mark uninitialized */ ext4_ext_mark_uninitialized (&newex); err =ext4_ext_insert_extent (handle, inode, path, &newex);if (err) {
@@ -2983,7 +2983,7 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, newblock =ext_pblock (&newex); allocated =ext4_ext_get_actual_len (&newex); outnew: -if (extend_disksize) { +if (flags &EXT4_GET_BLOCKS_EXTEND_DISKSIZE ) { disksize = ((loff_t ) iblock + ar.len) << inode->i_blkbits;if (disksize >i_size_read (inode)) disksize =i_size_read (inode);
@@ -2994,7 +2994,7 @@ outnew:set_buffer_new (bh_result);/* Cache only when it is _not_ an uninitialized extent */ -if (create !=EXT4_CREATE_UNINITIALIZED_EXT ) +if ((flags &EXT4_GET_BLOCKS_UNINIT_EXT ) ==0 )ext4_ext_put_in_cache (inode, iblock, allocated, newblock,EXT4_EXT_CACHE_EXTENT ); out:
@@ -3153,7 +3153,7 @@ retry: map_bh.b_state =0 ; ret =ext4_get_blocks (handle, inode, block, max_blocks, &map_bh, -EXT4_CREATE_UNINITIALIZED_EXT ,0 ,0 ); +EXT4_GET_BLOCKS_CREATE_UNINIT_EXT );if (ret <=0 ) {#ifdef EXT4FS_DEBUG WARN_ON (ret <=0 );
fs/ext4/inode.c +30 -27
172 lines not on this page · raw message
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 32/49 ext4: Add documentation to the ext4_*get_block* functions
This adds more documentation to various internal functions in fs/ext4/inode.c, most notably ext4_ind_get_blocks(), ext4_da_get_block_write(), ext4_da_get_block_prep(), ext4_normal_get_block_write().
In addition, the static function ext4_normal_get_block_write() has been renamed noalloc_get_block_write(), since it is used in many places far beyond ext4_normal_writepage().
Plenty of warnings have been added to the noalloc_get_block_write() function, since the way it is used is amazingly fragile.
--- fs/ext4/inode.c | 86 +++++++++++++++++++++++++++++++++++-------------------- 1 files changed, 55 insertions(+), 31 deletions(-)
fs/ext4/inode.c +55 -31
@@ -892,6 +892,10 @@ err_out: }/* +* The ext4_ind_get_blocks() function handles non-extents inodes +* (i.e., using the traditional indirect/double-indirect i_blocks +* scheme) for ext4_get_blocks(). +* * Allocation strategy is simple: if we have to allocate something, we will * have to go the whole way to leaf. So let's do it before attaching anything * to tree, set linkage between the newborn blocks, write them if sync is
@@ -909,10 +913,11 @@ err_out:* return = 0, if plain lookup failed. * return < 0, error case. * -* -* Need to be called with -* 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) +* The ext4_ind_get_blocks() function should be called with +* down_write(&EXT4_I(inode)->i_data_sem) if allocating filesystem +* blocks (i.e., flags has EXT4_GET_BLOCKS_CREATE set) or +* down_read(&EXT4_I(inode)->i_data_sem) if not allocating file system +* blocks. */ static int ext4_ind_get_blocks(handle_t *handle, struct inode *inode, ext4_lblk_t iblock, unsigned int maxblocks,
@@ -1152,8 +1157,8 @@ int ext4_get_blocks(handle_t *handle, struct inode *inode, sector_t block,clear_buffer_unwritten (bh);/* -* Try to see if we can get the block without requesting -* for new file system block. +* Try to see if we can get the block without requesting a new +* file system block. */ down_read ((&EXT4_I (inode)->i_data_sem));if (EXT4_I (inode)->i_flags &EXT4_EXTENTS_FL ) {
@@ -2000,6 +2005,12 @@ static void ext4_print_free_blocks(struct inode *inode)return ; } +/* +* This function is used by mpage_da_map_blocks(). We separate it out +* as a separate function just to make life easier, and because +* mpage_da_map_blocks() used to be a generic function that took a +* get_block_t. +*/ static int ext4_da_get_block_write (struct inode *inode,sector_t iblock,struct buffer_head *bh_result) {
@@ -2031,8 +2042,8 @@ static int ext4_da_get_block_write(struct inode *inode, sector_t iblock,/* * Update on-disk size along with block allocation we don't -* use 'extend_disksize' as size may change within already -* allocated block -bzzz +* use EXT4_GET_BLOCKS_EXTEND_DISKSIZE as size may change +* within already allocated block -bzzz */ disksize = ((loff_t ) iblock + ret) << inode->i_blkbits;if (disksize >i_size_read (inode))
@@ -2338,8 +2349,9 @@ static int __mpage_da_writepage(struct page *page, }/* -* this is a special callback for ->write_begin() only -* it's intention is to return mapped block or reserve space +* This is a special get_blocks_t callback which is used by +* ext4_da_write_begin(). It will either return mapped block or +* reserve space for a single block. * * For delayed buffer_head we have BH_Mapped, BH_New, BH_Delay set. * We also have b_blocknr = -1 and b_bdev initialized properly
@@ -2347,7 +2359,6 @@ static int __mpage_da_writepage(struct page *page,* For unwritten buffer_head we have BH_Mapped, BH_New, BH_Unwritten set. * We also have b_blocknr = physicalblock mapping unwritten extent and b_bdev * initialized properly. -* */ static int ext4_da_get_block_prep (struct inode *inode,sector_t iblock,struct buffer_head *bh_result,int create)
@@ -2400,7 +2411,23 @@ static int ext4_da_get_block_prep(struct inode *inode, sector_t iblock,return ret; } -static int ext4_normal_get_block_write (struct inode *inode,sector_t iblock, +/* +* This function is used as a standard get_block_t calback function +* when there is no desire to allocate any blocks. It is used as a +* callback function for block_prepare_write(), nobh_writepage(), and +* block_write_full_page(). These functions should only try to map a +* single block at a time. +* +* Since this function doesn't do block allocations even if the caller +* requests it by passing in create=1, it is critically important that +* any caller checks to make sure that any buffer heads are returned +* by this function are either all already mapped or marked for +* delayed allocation before calling nobh_writepage() or +* block_write_full_page(). Otherwise, b_blocknr could be left +* unitialized, and the page write functions will be taken by +* surprise. +*/ +static int noalloc_get_block_write (struct inode *inode,sector_t iblock,struct buffer_head *bh_result,int create) {int ret =0 ;
@@ -2419,10 +2446,11 @@ static int ext4_normal_get_block_write(struct inode *inode, sector_t iblock, }/* -* get called vi ext4_da_writepages after taking page lock (have journal handle) -* get called via journal_submit_inode_data_buffers (no journal handle) -* get called via shrink_page_list via pdflush (no journal handle) -* or grab_page_cache when doing write_begin (have journal handle) +* This function can get called via... +* - ext4_da_writepages after taking page lock (have journal handle) +* - journal_submit_inode_data_buffers (no journal handle) +* - shrink_page_list via pdflush (no journal handle) +* - grab_page_cache when doing write_begin (have journal handle) */ static int ext4_da_writepage (struct page *page,struct writeback_control *wbc)
@@ -2473,7 +2501,7 @@ static int ext4_da_writepage(struct page *page,* do block allocation here. */ ret =block_prepare_write (page,0 ,PAGE_CACHE_SIZE , - ext4_normal_get_block_write); + noalloc_get_block_write);if (!ret) { page_bufs =page_buffers (page);/* check whether all are mapped and non delay */
@@ -2498,11 +2526,10 @@ static int ext4_da_writepage(struct page *page, }if (test_opt (inode->i_sb,NOBH ) &&ext4_should_writeback_data (inode)) - ret =nobh_writepage (page, ext4_normal_get_block_write, wbc); + ret =nobh_writepage (page, noalloc_get_block_write, wbc);else - ret =block_write_full_page (page, - ext4_normal_get_block_write, - wbc); + ret =block_write_full_page (page, noalloc_get_block_write, + wbc);return ret; }
@@ -2814,7 +2841,7 @@ retry: *pagep = page; ret =block_write_begin (file, mapping, pos, len, flags, pagep, fsdata, - ext4_da_get_block_prep); + ext4_da_get_block_prep);if (ret <0 ) {unlock_page (page);ext4_journal_stop (handle);
@@ -3122,12 +3149,10 @@ static int __ext4_normal_writepage(struct page *page,struct inode *inode = page->mapping->host;if (test_opt (inode->i_sb,NOBH )) -return nobh_writepage (page, - ext4_normal_get_block_write, wbc); +return nobh_writepage (page, noalloc_get_block_write, wbc);else -return block_write_full_page (page, - ext4_normal_get_block_write, - wbc); +return block_write_full_page (page, noalloc_get_block_write, + wbc); } static int ext4_normal_writepage(struct page *page,
@@ -3179,7 +3204,7 @@ static int __ext4_journalled_writepage(struct page *page,int err; ret =block_prepare_write (page,0 ,PAGE_CACHE_SIZE , - ext4_normal_get_block_write); + noalloc_get_block_write);if (ret !=0 ) goto out_unlock;
@@ -3264,9 +3289,8 @@ static int ext4_journalled_writepage(struct page *page,* really know unless we go poke around in the buffer_heads. * But block_write_full_page will do the right thing. */ -return block_write_full_page (page, - ext4_normal_get_block_write, - wbc); +return block_write_full_page (page, noalloc_get_block_write, + wbc); } no_write:redirty_page_for_writepage (wbc, page);
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 33/49 ext4: Add BUG_ON debugging checks to noalloc_get_block_write()
Enforce that noalloc_get_block_write() is only called to map one block at a time, and that it always is successful in finding a mapping for given an inode's logical block block number if it is called with create == 1.
--- fs/ext4/inode.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-)
fs/ext4/inode.c +3 -0
@@ -2433,11 +2433,14 @@ static int noalloc_get_block_write(struct inode *inode, sector_t iblock,int ret =0 ;unsigned max_blocks = bh_result->b_size >> inode->i_blkbits; +BUG_ON (bh_result->b_size != inode->i_sb->s_blocksize); +/* * we don't want to do block allocation in writepage * so call get_block_wrap with create = 0 */ ret =ext4_get_blocks (NULL , inode, iblock, max_blocks, bh_result,0 ); +BUG_ON (create && ret ==0 );if (ret >0 ) { bh_result->b_size = (ret << inode->i_blkbits); ret =0 ;
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 34/49 ext4: Merge ext4_da_get_block_write() into mpage_da_map_blocks()
The static function ext4_da_get_block_write() was only used by mpage_da_map_blocks(). So to simplify the code, merge that function into mpage_da_map_blocks().
--- fs/ext4/inode.c | 110 +++++++++++++++++++++--------------------------------- 1 files changed, 43 insertions(+), 67 deletions(-)
fs/ext4/inode.c +43 -67
@@ -2006,57 +2006,6 @@ static void ext4_print_free_blocks(struct inode *inode) }/* -* This function is used by mpage_da_map_blocks(). We separate it out -* as a separate function just to make life easier, and because -* mpage_da_map_blocks() used to be a generic function that took a -* get_block_t. -*/ -static int ext4_da_get_block_write (struct inode *inode,sector_t iblock, -struct buffer_head *bh_result) -{ -int ret; -unsigned max_blocks = bh_result->b_size >> inode->i_blkbits; -loff_t disksize =EXT4_I (inode)->i_disksize; -handle_t *handle =NULL ; - - handle =ext4_journal_current_handle (); -BUG_ON (!handle); - ret =ext4_get_blocks (handle, inode, iblock, max_blocks, - bh_result,EXT4_GET_BLOCKS_CREATE | -EXT4_GET_BLOCKS_DELALLOC_RESERVE ); -if (ret <=0 ) -return ret; - - bh_result->b_size = (ret << inode->i_blkbits); - -if (ext4_should_order_data (inode)) { -int retval; - retval =ext4_jbd2_file_inode (handle, inode); -if (retval) -/* -* Failed to add inode for ordered mode. Don't -* update file size -*/ -return retval; - } - -/* -* Update on-disk size along with block allocation we don't -* use EXT4_GET_BLOCKS_EXTEND_DISKSIZE as size may change -* within already allocated block -bzzz -*/ - disksize = ((loff_t ) iblock + ret) << inode->i_blkbits; -if (disksize >i_size_read (inode)) - disksize =i_size_read (inode); -if (disksize >EXT4_I (inode)->i_disksize) { -ext4_update_i_disksize (inode, disksize); - ret =ext4_mark_inode_dirty (handle, inode); -return ret; - } -return 0 ; -} - -/* * mpage_da_map_blocks - go through given space * * @mpd - bh describing space
@@ -2066,9 +2015,12 @@ static int ext4_da_get_block_write(struct inode *inode, sector_t iblock,*/ static int mpage_da_map_blocks (struct mpage_da_data *mpd) { -int err =0 ; +int err, blks;struct buffer_head new; -sector_t next; +sector_t next = mpd->b_blocknr; +unsigned max_blocks = mpd->b_size >> mpd->inode->i_blkbits; +loff_t disksize =EXT4_I (mpd->inode)->i_disksize; +handle_t *handle =NULL ;/* * We consider only non-mapped and non-allocated blocks
@@ -2077,6 +2029,16 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd) !(mpd->b_state & (1 << BH_Delay)) && !(mpd->b_state & (1 << BH_Unwritten)))return 0 ; + +/* +* If we didn't accumulate anything to write simply return +*/ +if (!mpd->b_size) +return 0 ; + + handle =ext4_journal_current_handle (); +BUG_ON (!handle); +/* * We need to make sure the BH_Delay flag is passed down to * ext4_da_get_block_write(), since it calls ext4_get_blocks()
@@ -2092,18 +2054,11 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd)* EXT4_GET_BLOCKS_DELALLOC_RESERVE flag. */ new.b_state = mpd->b_state & (1 << BH_Delay); - new.b_blocknr =0 ; - new.b_size = mpd->b_size; - next = mpd->b_blocknr; -/* -* If we didn't accumulate anything -* to write simply return -*/ -if (!new.b_size) -return 0 ; - - err =ext4_da_get_block_write (mpd->inode, next, &new); -if (err) { + blks =ext4_get_blocks (handle, mpd->inode, next, max_blocks, + &new,EXT4_GET_BLOCKS_CREATE | +EXT4_GET_BLOCKS_DELALLOC_RESERVE ); +if (blks <0 ) { + err = blks;/* * If get block returns with error we simply * return. Later writepage will redirty the page and
@@ -2136,12 +2091,14 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd)if (err == -ENOSPC ) {ext4_print_free_blocks (mpd->inode); } -/* invlaidate all the pages */ +/* invalidate all the pages */ ext4_da_block_invalidatepages (mpd, next, mpd->b_size >> mpd->inode->i_blkbits);return err; } -BUG_ON (new.b_size ==0 ); +BUG_ON (blks ==0 ); + + new.b_size = (blks << mpd->inode->i_blkbits);if (buffer_new (&new))__unmap_underlying_blocks (mpd->inode, &new);
@@ -2154,6 +2111,25 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd) (mpd->b_state & (1 << BH_Unwritten)))mpage_put_bnr_to_bhs (mpd, next, &new); +if (ext4_should_order_data (mpd->inode)) { + err =ext4_jbd2_file_inode (handle, mpd->inode); +if (err) +return err; + } + +/* +* Update on-disk size along with block allocation we don't +* use EXT4_GET_BLOCKS_EXTEND_DISKSIZE as size may change +* within already allocated block -bzzz +*/ + disksize = ((loff_t ) next + blks) << mpd->inode->i_blkbits; +if (disksize >i_size_read (mpd->inode)) + disksize =i_size_read (mpd->inode); +if (disksize >EXT4_I (mpd->inode)->i_disksize) { +ext4_update_i_disksize (mpd->inode, disksize); +return ext4_mark_inode_dirty (handle, mpd->inode); + } +return 0 ; }
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 35/49 ext4: Clean up ext4_get_blocks() so it does not depend on bh_result->b_state
The ext4_get_blocks() function was depending on the value of bh_result->b_state as an input parameter to decide whether or not update the delalloc accounting statistics by calling ext4_da_update_reserve_space(). We now use a separate flag, EXT4_GET_BLOCKS_UPDATE_RESERVE_SPACE, to requests this update, so that all callers of ext4_get_blocks() can clear map_bh.b_state before calling ext4_get_blocks() without worrying about any consistency issues.
--- fs/ext4/ext4.h | 15 +++++++++---- fs/ext4/inode.c | 56 ++++++++++++++++++++++++++++++------------------------ 2 files changed, 41 insertions(+), 30 deletions(-)
fs/ext4/ext4.h +10 -5
@@ -318,16 +318,21 @@ struct ext4_new_group_data {*/ /* Allocate any needed blocks and/or convert an unitialized extent to be an initialized ext4 */ -#define EXT4_GET_BLOCKS_CREATE 1 +#define EXT4_GET_BLOCKS_CREATE 0x0001/* Request the creation of an unitialized extent */ -#define EXT4_GET_BLOCKS_UNINIT_EXT 2 +#define EXT4_GET_BLOCKS_UNINIT_EXT 0x0002#define EXT4_GET_BLOCKS_CREATE_UNINIT_EXT (EXT4_GET_BLOCKS_UNINIT_EXT|\ EXT4_GET_BLOCKS_CREATE)/* Update the ext4_inode_info i_disksize field */ -#define EXT4_GET_BLOCKS_EXTEND_DISKSIZE 4 +#define EXT4_GET_BLOCKS_EXTEND_DISKSIZE 0x0004/* Caller is from the delayed allocation writeout path, -so the filesystem blocks have already been accounted for */ -#define EXT4_GET_BLOCKS_DELALLOC_RESERVE 8 +so set the magic i_delalloc_reserve_flag after taking the +inode allocation semaphore for */ +#define EXT4_GET_BLOCKS_DELALLOC_RESERVE 0x0008 +/* Call ext4_da_update_reserve_space() after successfully +allocating the blocks */ +#define EXT4_GET_BLOCKS_UPDATE_RESERVE_SPACE 0x0010 +/* * ioctl commands
fs/ext4/inode.c +31 -25
77 lines not on this page · raw message
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 36/49 ext4: Add a comprehensive block validity check to ext4_get_blocks()
To catch filesystem bugs or corruption which could lead to the filesystem getting severly damaged, this patch adds a facility for tracking all of the filesystem metadata blocks by contiguous regions in a red-black tree. This allows quick searching of the tree to locate extents which might overlap with filesystem metadata blocks.
This facility is also used by the multi-block allocator to assure that it is not allocating blocks out of the system zone, as well as by the routines used when reading indirect blocks and extents information from disk to make sure their contents are valid.
--- fs/ext4/Makefile | 4 +- fs/ext4/block_validity.c | 244 ++++++++++++++++++++++++++++++++++++++++++++++ fs/ext4/ext4.h | 11 ++ fs/ext4/extents.c | 22 +---- fs/ext4/inode.c | 47 +++++++-- fs/ext4/mballoc.c | 11 +-- fs/ext4/super.c | 32 ++++++- 7 files changed, 332 insertions(+), 39 deletions(-) create mode 100644 fs/ext4/block_validity.c
fs/ext4/Makefile +2 -2
@@ -5,8 +5,8 @@ obj-$(CONFIG_EXT4_FS) += ext4.o ext4-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 mballoc.o + ioctl.o namei.o super.o symlink.o hash.o resize.o extents.o \ + ext4_jbd2.o migrate.o mballoc.o block_validity.o ext4-$(CONFIG_EXT4_FS_XATTR) += xattr.o xattr_user.o xattr_trusted.o ext4-$(CONFIG_EXT4_FS_POSIX_ACL) += acl.o
fs/ext4/block_validity.c new file +244 -0
244 lines not on this page · raw message
fs/ext4/ext4.h +11 -0
@@ -696,6 +696,7 @@ struct ext4_inode_info {#define EXT4_MOUNT_I_VERSION 0x2000000/* i_version support */ #define EXT4_MOUNT_DELALLOC 0x8000000/* Delalloc support */ #define EXT4_MOUNT_DATA_ERR_ABORT 0x10000000/* Abort on file data write */ +#define EXT4_MOUNT_BLOCK_VALIDITY 0x20000000/* Block validity checking */ /* Compatibility, for having both ext2_fs.h and ext4_fs.h included at once */ #ifndef _LINUX_EXT2_FS_H
@@ -887,6 +888,7 @@ struct ext4_sb_info {int s_jquota_fmt;/* Format of quota to use */ #endif unsigned int s_want_extra_isize;/* New inodes should reserve # bytes */ +struct rb_root system_blks;#ifdef EXTENTS_STATS /* ext4 extents stats */
@@ -1618,6 +1620,15 @@ extern struct dentry *ext4_get_parent(struct dentry *child);extern const struct inode_operations ext4_symlink_inode_operations;extern const struct inode_operations ext4_fast_symlink_inode_operations; +/* block_validity */ +extern void ext4_release_system_zone (struct super_block *sb); +extern int ext4_setup_system_zone (struct super_block *sb); +extern int __init init_ext4_system_zone (void ); +extern void exit_ext4_system_zone (void ); +extern int ext4_data_block_valid (struct ext4_sb_info *sbi, +ext4_fsblk_t start_blk, +unsigned int count); +/* extents.c */ extern int ext4_ext_tree_init (handle_t *handle,struct inode *);extern int ext4_ext_writepage_trans_blocks (struct inode *,int );
fs/ext4/extents.c +4 -18
@@ -326,32 +326,18 @@ ext4_ext_max_entries(struct inode *inode, int depth)static int ext4_valid_extent (struct inode *inode,struct ext4_extent *ext) { -ext4_fsblk_t block =ext_pblock (ext), valid_block; +ext4_fsblk_t block =ext_pblock (ext);int len =ext4_ext_get_actual_len (ext); -struct ext4_super_block *es =EXT4_SB (inode->i_sb)->s_es; - valid_block =le32_to_cpu (es->s_first_data_block) + -EXT4_SB (inode->i_sb)->s_gdb_count; -if (unlikely (block <= valid_block || - ((block + len) >ext4_blocks_count (es)))) -return 0 ; -else -return 1 ; +return ext4_data_block_valid (EXT4_SB (inode->i_sb), block, len); }static int ext4_valid_extent_idx (struct inode *inode,struct ext4_extent_idx *ext_idx) { -ext4_fsblk_t block =idx_pblock (ext_idx), valid_block; -struct ext4_super_block *es =EXT4_SB (inode->i_sb)->s_es; +ext4_fsblk_t block =idx_pblock (ext_idx); - valid_block =le32_to_cpu (es->s_first_data_block) + -EXT4_SB (inode->i_sb)->s_gdb_count; -if (unlikely (block <= valid_block || - (block >=ext4_blocks_count (es)))) -return 0 ; -else -return 1 ; +return ext4_data_block_valid (EXT4_SB (inode->i_sb), block,1 ); } static int ext4_valid_extent_entries(struct inode *inode,
fs/ext4/inode.c +38 -9
76 lines not on this page · raw message
fs/ext4/mballoc.c +3 -8
@@ -2961,15 +2961,10 @@ ext4_mb_mark_diskspace_used(struct ext4_allocation_context *ac, +le32_to_cpu (es->s_first_data_block); len = ac->ac_b_ex.fe_len; -if (in_range (ext4_block_bitmap (sb, gdp), block, len) || -in_range (ext4_inode_bitmap (sb, gdp), block, len) || -in_range (block,ext4_inode_table (sb, gdp), -EXT4_SB (sb)->s_itb_per_group) || -in_range (block + len -1 ,ext4_inode_table (sb, gdp), -EXT4_SB (sb)->s_itb_per_group)) { +if (!ext4_data_block_valid (sbi, block, len)) {ext4_error (sb, __func__, -"Allocating block %llu in system zone of %d group\n" , - block, ac->ac_b_ex.fe_group); +"Allocating blocks %llu-%llu which overlap " +"fs metadata\n" , block, block+len);/* File system mounted not to panic on error * Fix the bitmap and repeat the block allocation * We leak some of the blocks here.
fs/ext4/super.c +30 -2
@@ -568,6 +568,7 @@ static void ext4_put_super(struct super_block *sb)struct ext4_super_block *es = sbi->s_es;int i, err; +ext4_release_system_zone (sb);ext4_mb_release (sb);ext4_ext_release (sb);ext4_xattr_put_super (sb);
@@ -1055,6 +1056,7 @@ enum { Opt_ignore, Opt_barrier, Opt_nobarrier, Opt_err, Opt_resize, Opt_usrquota, Opt_grpquota, Opt_i_version, Opt_stripe, Opt_delalloc, Opt_nodelalloc, + Opt_block_validity, Opt_noblock_validity, Opt_inode_readahead_blks, Opt_journal_ioprio };
@@ -1114,6 +1116,8 @@ static const match_table_t tokens = { {Opt_resize, "resize"}, {Opt_delalloc, "delalloc"}, {Opt_nodelalloc, "nodelalloc"}, + {Opt_block_validity, "block_validity"}, + {Opt_noblock_validity, "noblock_validity"}, {Opt_inode_readahead_blks, "inode_readahead_blks=%u"}, {Opt_journal_ioprio, "journal_ioprio=%u"}, {Opt_auto_da_alloc, "auto_da_alloc=%u"},
@@ -1508,6 +1512,12 @@ set_qf_format:case Opt_delalloc:set_opt (sbi->s_mount_opt,DELALLOC );break ; +case Opt_block_validity: +set_opt (sbi->s_mount_opt,BLOCK_VALIDITY ); +break ; +case Opt_noblock_validity: +clear_opt (sbi->s_mount_opt,BLOCK_VALIDITY ); +break ;case Opt_inode_readahead_blks:if (match_int (&args[0 ], &option))return 0 ;
@@ -2826,6 +2836,13 @@ no_journal: }else if (test_opt (sb,DELALLOC ))printk (KERN_INFO "EXT4-fs: delayed allocation enabled\n" ); + err =ext4_setup_system_zone (sb); +if (err) { +printk (KERN_ERR "EXT4-fs: failed to initialize system " +"zone (%d)\n" , err); + goto failed_mount4; + } +ext4_ext_init (sb); err =ext4_mb_init (sb, needs_recovery);if (err) {
@@ -2875,6 +2892,7 @@ cantfind_ext4: failed_mount4:printk (KERN_ERR "EXT4-fs (device %s): mount failed\n" , sb->s_id); +ext4_release_system_zone (sb);if (sbi->s_journal) {jbd2_journal_destroy (sbi->s_journal); sbi->s_journal =NULL ;
@@ -3515,6 +3533,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data) sb->s_flags &= ~MS_RDONLY ; } } +ext4_setup_system_zone (sb);if (sbi->s_journal ==NULL )ext4_commit_super (sb,1 );
@@ -3927,13 +3946,16 @@ static int __init init_ext4_fs(void) {int err; + err =init_ext4_system_zone (); +if (err) +return err; ext4_kset =kset_create_and_add ("ext4" ,NULL , fs_kobj);if (!ext4_kset) -return -ENOMEM ; + goto out4; ext4_proc_root =proc_mkdir ("fs/ext4" ,NULL ); err =init_ext4_mballoc ();if (err) -return err; + goto out3; err =init_ext4_xattr ();if (err)
@@ -3958,6 +3980,11 @@ out1:exit_ext4_xattr (); out2:exit_ext4_mballoc (); +out3: +remove_proc_entry ("fs/ext4" ,NULL ); +kset_unregister (ext4_kset); +out4: +exit_ext4_system_zone ();return err; }
@@ -3972,6 +3999,7 @@ static void __exit exit_ext4_fs(void)exit_ext4_mballoc ();remove_proc_entry ("fs/ext4" ,NULL );kset_unregister (ext4_kset); +exit_ext4_system_zone (); }MODULE_AUTHOR ("Remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theodore Ts'o and others" );
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 37/49 ext4: down i_data_sem only for read when walking tree for fiemap
Not sure why I put this in as down_write originally; all we are doing is walking the tree, nothing will change under us and concurrent reads should be no problem.
--- fs/ext4/extents.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
fs/ext4/extents.c +2 -2
@@ -3312,10 +3312,10 @@ int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,* Walk the extent tree gathering extent information. * ext4_ext_fiemap_cb will push extents back to user. */ -down_write (&EXT4_I (inode)->i_data_sem); +down_read (&EXT4_I (inode)->i_data_sem); error =ext4_ext_walk_space (inode, start_blk, len_blks, ext4_ext_fiemap_cb, fieinfo); -up_write (&EXT4_I (inode)->i_data_sem); +up_read (&EXT4_I (inode)->i_data_sem); }return error;
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 38/49 ext4: Fix memory leak in ext4_fill_super() in case of a failed mount
From: Manish Katiyar <[email protected]>
--- fs/ext4/super.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
fs/ext4/super.c +1 -0
@@ -2924,6 +2924,7 @@ failed_mount:brelse (bh); out_fail: sb->s_fs_info =NULL ; +kfree (sbi->s_blockgroup_lock);kfree (sbi);lock_kernel ();return ret;
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 39/49 ext3: Fix memory leak in ext3_fill_super() in case of a failed mount
From: Manish Katiyar <[email protected]>
--- fs/ext3/super.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
fs/ext3/super.c +1 -0
@@ -2021,6 +2021,7 @@ failed_mount:brelse (bh); out_fail: sb->s_fs_info =NULL ; +kfree (sbi->s_blockgroup_lock);kfree (sbi);lock_kernel ();return ret;
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 40/49 ext2: Fix memory leak in ext2_fill_super() in case of a failed mount
From: Manish Katiyar <[email protected]>
--- fs/ext2/super.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
fs/ext2/super.c +1 -0
@@ -1093,6 +1093,7 @@ failed_mount:brelse (bh); failed_sbi: sb->s_fs_info =NULL ; +kfree (sbi->s_blockgroup_lock);kfree (sbi);return ret; }
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 41/49 ext4: remove unused function __ext4_write_dirty_metadata
The __ext4_write_dirty_metadata() function was introduced by commit 0390131b, "ext4: Allow ext4 to run without a journal", but nothing ever used the function, either then or since. So let's remove it and save a bit of space.
--- fs/ext4/inode.c | 19 ------------------- 1 files changed, 0 insertions(+), 19 deletions(-)
fs/ext4/inode.c +0 -19
@@ -4790,25 +4790,6 @@ int ext4_write_inode(struct inode *inode, int wait)return ext4_force_commit (inode->i_sb); } -int __ext4_write_dirty_metadata (struct inode *inode,struct buffer_head *bh) -{ -int err =0 ; - -mark_buffer_dirty (bh); -if (inode &&inode_needs_sync (inode)) { -sync_dirty_buffer (bh); -if (buffer_req (bh) && !buffer_uptodate (bh)) { -ext4_error (inode->i_sb, __func__, -"IO error syncing inode, " -"inode=%lu, block=%llu" , - inode->i_ino, - (unsigned long long )bh->b_blocknr); - err = -EIO ; - } - } -return err; -} -/* * ext4_setattr() *
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 42/49 ext4: Clean up calls to ext4_get_group_desc()
If the caller isn't planning on modifying the block group descriptors, there's no need to pass in a pointer to a struct buffer_head. Nuking this saves a tiny amount of CPU time and stack space usage.
--- fs/ext4/ialloc.c | 3 +-- fs/ext4/super.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
fs/ext4/ialloc.c +1 -2
@@ -347,7 +347,6 @@ static int find_group_flex(struct super_block *sb, struct inode *parent, {struct ext4_sb_info *sbi =EXT4_SB (sb);struct ext4_group_desc *desc; -struct buffer_head *bh;struct flex_groups *flex_group = sbi->s_flex_groups;ext4_group_t parent_group =EXT4_I (parent)->i_block_group;ext4_group_t parent_fbg_group =ext4_flex_group (sbi, parent_group);
@@ -402,7 +401,7 @@ find_close_to_parent: found_flexbg:for (i = best_flex * flex_size; i < ngroups && i < (best_flex +1 ) * flex_size; i++) { - desc =ext4_get_group_desc (sb, i, &bh); + desc =ext4_get_group_desc (sb, i,NULL );if (ext4_free_inodes_count (sb, desc)) { *best_group = i; goto out;
fs/ext4/super.c +1 -2
@@ -1660,7 +1660,6 @@ static int ext4_fill_flex_info(struct super_block *sb) {struct ext4_sb_info *sbi =EXT4_SB (sb);struct ext4_group_desc *gdp =NULL ; -struct buffer_head *bh;ext4_group_t flex_group_count;ext4_group_t flex_group;int groups_per_flex =0 ;
@@ -1693,7 +1692,7 @@ static int ext4_fill_flex_info(struct super_block *sb) }for (i =0 ; i < sbi->s_groups_count; i++) { - gdp =ext4_get_group_desc (sb, i, &bh); + gdp =ext4_get_group_desc (sb, i,NULL ); flex_group =ext4_flex_group (sbi, i); atomic_set(&sbi->s_flex_groups[flex_group].free_inodes,
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 43/49 jbd2: Fix minor typos in comments in fs/jbd2/journal.c
From: Alberto Bertogli <[email protected]>
--- fs/jbd2/journal.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
fs/jbd2/journal.c +4 -4
@@ -1781,7 +1781,7 @@ int jbd2_journal_wipe(journal_t *journal, int write)* Journal abort has very specific semantics, which we describe * for journal abort. * -* Two internal function, which provide abort to te jbd layer +* Two internal function, which provide abort to the jbd layer * itself are here. */
@@ -1879,7 +1879,7 @@ void jbd2_journal_abort(journal_t *journal, int errno)* int jbd2_journal_errno () - returns the journal's error state. * @journal: journal to examine. * -* This is the errno numbet set with jbd2_journal_abort(), the last +* This is the errno number set with jbd2_journal_abort(), the last * time the journal was mounted - if the journal was stopped * without calling abort this will be 0. *
@@ -1903,7 +1903,7 @@ int jbd2_journal_errno(journal_t *journal)* int jbd2_journal_clear_err () - clears the journal's error state * @journal: journal to act on. * -* An error must be cleared or Acked to take a FS out of readonly +* An error must be cleared or acked to take a FS out of readonly * mode. */ int jbd2_journal_clear_err (journal_t *journal)
@@ -1923,7 +1923,7 @@ int jbd2_journal_clear_err(journal_t *journal)* void jbd2_journal_ack_err() - Ack journal err. * @journal: journal to act on. * -* An error must be cleared or Acked to take a FS out of readonly +* An error must be cleared or acked to take a FS out of readonly * mode. */ void jbd2_journal_ack_err (journal_t *journal)
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 44/49 ext4: super.c whitespace cleanup
From: Andreas Dilger <[email protected]>
Cleanup of whitespace and formatting. Initially driven by confusing indents for the ext4_{block,inode}_bitmap() et. al. helper routines, but figured I'd cleanup some other 80-column wrapping and other indenting problems at the same time.
--- fs/ext4/super.c | 117 ++++++++++++++++++++++++++++-------------------------- 1 files changed, 61 insertions(+), 56 deletions(-)
fs/ext4/super.c +61 -56
@@ -79,7 +79,7 @@ ext4_fsblk_t ext4_block_bitmap(struct super_block *sb, {return le32_to_cpu (bg->bg_block_bitmap_lo) | (EXT4_DESC_SIZE (sb) >=EXT4_MIN_DESC_SIZE_64BIT ? - (ext4_fsblk_t )le32_to_cpu (bg->bg_block_bitmap_hi) <<32 :0 ); + (ext4_fsblk_t )le32_to_cpu (bg->bg_block_bitmap_hi) <<32 :0 ); } ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb,
@@ -87,7 +87,7 @@ ext4_fsblk_t ext4_inode_bitmap(struct super_block *sb, {return le32_to_cpu (bg->bg_inode_bitmap_lo) | (EXT4_DESC_SIZE (sb) >=EXT4_MIN_DESC_SIZE_64BIT ? - (ext4_fsblk_t )le32_to_cpu (bg->bg_inode_bitmap_hi) <<32 :0 ); + (ext4_fsblk_t )le32_to_cpu (bg->bg_inode_bitmap_hi) <<32 :0 ); } ext4_fsblk_t ext4_inode_table(struct super_block *sb,
@@ -95,7 +95,7 @@ ext4_fsblk_t ext4_inode_table(struct super_block *sb, {return le32_to_cpu (bg->bg_inode_table_lo) | (EXT4_DESC_SIZE (sb) >=EXT4_MIN_DESC_SIZE_64BIT ? - (ext4_fsblk_t )le32_to_cpu (bg->bg_inode_table_hi) <<32 :0 ); + (ext4_fsblk_t )le32_to_cpu (bg->bg_inode_table_hi) <<32 :0 ); } __u32 ext4_free_blks_count(struct super_block *sb,
@@ -103,7 +103,7 @@ __u32 ext4_free_blks_count(struct super_block *sb, {return le16_to_cpu (bg->bg_free_blocks_count_lo) | (EXT4_DESC_SIZE (sb) >=EXT4_MIN_DESC_SIZE_64BIT ? - (__u32 )le16_to_cpu (bg->bg_free_blocks_count_hi) <<16 :0 ); + (__u32 )le16_to_cpu (bg->bg_free_blocks_count_hi) <<16 :0 ); } __u32 ext4_free_inodes_count(struct super_block *sb,
@@ -111,7 +111,7 @@ __u32 ext4_free_inodes_count(struct super_block *sb, {return le16_to_cpu (bg->bg_free_inodes_count_lo) | (EXT4_DESC_SIZE (sb) >=EXT4_MIN_DESC_SIZE_64BIT ? - (__u32 )le16_to_cpu (bg->bg_free_inodes_count_hi) <<16 :0 ); + (__u32 )le16_to_cpu (bg->bg_free_inodes_count_hi) <<16 :0 ); } __u32 ext4_used_dirs_count(struct super_block *sb,
@@ -119,7 +119,7 @@ __u32 ext4_used_dirs_count(struct super_block *sb, {return le16_to_cpu (bg->bg_used_dirs_count_lo) | (EXT4_DESC_SIZE (sb) >=EXT4_MIN_DESC_SIZE_64BIT ? - (__u32 )le16_to_cpu (bg->bg_used_dirs_count_hi) <<16 :0 ); + (__u32 )le16_to_cpu (bg->bg_used_dirs_count_hi) <<16 :0 ); } __u32 ext4_itable_unused_count(struct super_block *sb,
@@ -127,7 +127,7 @@ __u32 ext4_itable_unused_count(struct super_block *sb, {return le16_to_cpu (bg->bg_itable_unused_lo) | (EXT4_DESC_SIZE (sb) >=EXT4_MIN_DESC_SIZE_64BIT ? - (__u32 )le16_to_cpu (bg->bg_itable_unused_hi) <<16 :0 ); + (__u32 )le16_to_cpu (bg->bg_itable_unused_hi) <<16 :0 ); } void ext4_block_bitmap_set(struct super_block *sb,
@@ -207,8 +207,7 @@ handle_t *ext4_journal_start_sb(struct super_block *sb, int nblocks) journal =EXT4_SB (sb)->s_journal;if (journal) {if (is_journal_aborted (journal)) { -ext4_abort (sb, __func__, -"Detected aborted journal" ); +ext4_abort (sb, __func__,"Detected aborted journal" );return ERR_PTR (-EROFS ); }return jbd2_journal_start (journal, nblocks);
@@ -436,7 +435,7 @@ void ext4_warning(struct super_block *sb, const char *function, }void ext4_grp_locked_error (struct super_block *sb,ext4_group_t grp, -const char *function,const char *fmt, ...) +const char *function,const char *fmt, ...)__releases (bitlock)__acquires (bitlock) {
@@ -472,7 +471,6 @@ __acquires(bitlock)return ; } -void ext4_update_dynamic_rev (struct super_block *sb) {struct ext4_super_block *es =EXT4_SB (sb)->s_es;
@@ -638,7 +636,6 @@ static void ext4_put_super(struct super_block *sb)lock_kernel ();kfree (sbi->s_blockgroup_lock);kfree (sbi); -return ; }static struct kmem_cache *ext4_inode_cachep;
@@ -653,6 +650,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb) ei =kmem_cache_alloc (ext4_inode_cachep,GFP_NOFS );if (!ei)return NULL ; +#ifdef CONFIG_EXT4_FS_POSIX_ACL ei->i_acl =EXT4_ACL_NOT_CACHED ; ei->i_default_acl =EXT4_ACL_NOT_CACHED ;
@@ -673,6 +671,7 @@ static struct inode *ext4_alloc_inode(struct super_block *sb) ei->i_allocated_meta_blocks =0 ; ei->i_delalloc_reserved_flag =0 ;spin_lock_init (&(ei->i_block_reservation_lock)); +return &ei->vfs_inode; }
@@ -879,12 +878,12 @@ static int ext4_show_options(struct seq_file *seq, struct vfsmount *vfs)seq_puts (seq,",noauto_da_alloc" );ext4_show_quota_options (seq, sb); +return 0 ; } -static struct inode *ext4_nfs_get_inode (struct super_block *sb, -u64 ino,u32 generation) +u64 ino,u32 generation) {struct inode *inode;
@@ -913,14 +912,14 @@ static struct inode *ext4_nfs_get_inode(struct super_block *sb, }static struct dentry *ext4_fh_to_dentry (struct super_block *sb,struct fid *fid, -int fh_len,int fh_type) +int fh_len,int fh_type) {return generic_fh_to_dentry (sb, fid, fh_len, fh_type, ext4_nfs_get_inode); }static struct dentry *ext4_fh_to_parent (struct super_block *sb,struct fid *fid, -int fh_len,int fh_type) +int fh_len,int fh_type) {return generic_fh_to_parent (sb, fid, fh_len, fh_type, ext4_nfs_get_inode);
@@ -932,7 +931,8 @@ static struct dentry *ext4_fh_to_parent(struct super_block *sb, struct fid *fid,* which would prevent try_to_free_buffers() from freeing them, we must use * jbd2 layer's try_to_free_buffers() function to release them. */ -static int bdev_try_to_free_page (struct super_block *sb,struct page *page,gfp_t wait) +static int bdev_try_to_free_page (struct super_block *sb,struct page *page, +gfp_t wait) {journal_t *journal =EXT4_SB (sb)->s_journal;
@@ -1133,8 +1133,9 @@ static ext4_fsblk_t get_sb_block(void **data)if (!options ||strncmp (options,"sb=" ,3 ) !=0 )return 1 ;/* Default location */ + options +=3 ; -/*todo: use simple_strtoll with >32bit ext4 */ +/* TODO: use simple_strtoll with >32bit ext4 */ sb_block =simple_strtoul (options, &options,0 );if (*options && *options !=',' ) { printk(KERN_ERR "EXT4-fs: Invalid sb specification: %s\n",
@@ -1144,6 +1145,7 @@ static ext4_fsblk_t get_sb_block(void **data)if (*options ==',' ) options++; *data = (void *) options; +return sb_block; }
@@ -1626,7 +1628,7 @@ static int ext4_setup_super(struct super_block *sb, struct ext4_super_block *es,printk (KERN_WARNING "EXT4-fs warning: checktime reached, " "running e2fsck is recommended\n" ); -if (!sbi->s_journal) +if (!sbi->s_journal) es->s_state &=cpu_to_le16 (~EXT4_VALID_FS );if (!(__s16 )le16_to_cpu (es->s_max_mnt_count)) es->s_max_mnt_count =cpu_to_le16 (EXT4_DFL_MAX_MNT_COUNT );
@@ -1810,7 +1812,7 @@ static int ext4_check_descriptors(struct super_block *sb) }ext4_free_blocks_count_set (sbi->s_es,ext4_count_free_blocks (sb)); - sbi->s_es->s_free_inodes_count =cpu_to_le32 (ext4_count_free_inodes (sb)); + sbi->s_es->s_free_inodes_count =cpu_to_le32 (ext4_count_free_inodes (sb));return 1 ; }
@@ -1926,6 +1928,7 @@ 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
@@ -1976,19 +1979,19 @@ static loff_t ext4_max_bitmap_size(int bits, int has_huge_files)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, 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 -* total number of 512 bytes blocks of the file +/* This is calculated to be the largest file size for a dense, block +* mapped file such that the file's total number of 512-byte sectors, +* including data and all indirect blocks, does not exceed (2^48 - 1). +* +* __u32 i_blocks_lo and _u16 i_blocks_high represent the total +* number of 512-byte sectors of the file. */ if (!has_huge_files ||sizeof (blkcnt_t) <sizeof (u64)) {/* -* !has_huge_files or CONFIG_LBD is not enabled -* implies the inode i_block represent total blocks in -* 512 bytes 32 == size of vfs inode i_blocks * 8 +* !has_huge_files or CONFIG_LBD not enabled implies that +* the inode i_block field represents total file blocks in +* 2^32 512-byte sectors == size of vfs inode i_blocks * 8 */ upper_limit = (1LL <<32 ) -1 ;
@@ -2030,7 +2033,7 @@ static loff_t ext4_max_bitmap_size(int bits, int has_huge_files) }static ext4_fsblk_t descriptor_loc (struct super_block *sb, -ext4_fsblk_t logical_sb_block,int nr) +ext4_fsblk_t logical_sb_block,int nr) {struct ext4_sb_info *sbi =EXT4_SB (sb);ext4_group_t bg, first_meta_bg;
@@ -2044,6 +2047,7 @@ static ext4_fsblk_t descriptor_loc(struct super_block *sb, bg = sbi->s_desc_per_block * nr;if (ext4_bg_has_super (sb, bg)) has_super =1 ; +return (has_super +ext4_group_first_block_no (sb, bg)); }
@@ -2148,7 +2152,7 @@ static ssize_t inode_readahead_blks_store(struct ext4_attr *a, }static ssize_t sbi_ui_show (struct ext4_attr *a, -struct ext4_sb_info *sbi,char *buf) +struct ext4_sb_info *sbi,char *buf) {unsigned int *ui = (unsigned int *) (((char *) sbi) + a->offset);
@@ -2253,7 +2257,6 @@ static struct kobj_type ext4_ktype = {static int ext4_fill_super (struct super_block *sb,void *data,int silent)__releases (kernel_lock)__acquires (kernel_lock) - {struct buffer_head *bh;struct ext4_super_block *es =NULL ;
@@ -2379,7 +2382,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)*/ set_opt (sbi->s_mount_opt,DELALLOC ); -if (!parse_options ((char *) data, sb, &journal_devnum, &journal_ioprio,NULL ,0 )) goto failed_mount;
@@ -2442,7 +2444,6 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) }if (sb->s_blocksize != blocksize) { -/* Validate the filesystem blocksize */ if (!sb_set_blocksize (sb, blocksize)) { printk(KERN_ERR "EXT4-fs: bad block size %d.\n",
@@ -2489,6 +2490,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)if (sbi->s_inode_size >EXT4_GOOD_OLD_INODE_SIZE ) sb->s_time_gran =1 << (EXT4_EPOCH_BITS -2 ); } + sbi->s_desc_size =le16_to_cpu (es->s_desc_size);if (EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_64BIT )) { if (sbi->s_desc_size < EXT4_MIN_DESC_SIZE_64BIT ||
@@ -2501,10 +2503,12 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) } }else sbi->s_desc_size =EXT4_MIN_DESC_SIZE ; + sbi->s_blocks_per_group =le32_to_cpu (es->s_blocks_per_group); sbi->s_inodes_per_group =le32_to_cpu (es->s_inodes_per_group);if (EXT4_INODE_SIZE (sb) ==0 ||EXT4_INODES_PER_GROUP (sb) ==0 ) goto cantfind_ext4; + sbi->s_inodes_per_block = blocksize /EXT4_INODE_SIZE (sb);if (sbi->s_inodes_per_block ==0 ) goto cantfind_ext4;
@@ -2515,6 +2519,7 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) sbi->s_mount_state =le16_to_cpu (es->s_state); sbi->s_addr_per_block_bits =ilog2 (EXT4_ADDR_PER_BLOCK (sb)); sbi->s_desc_per_block_bits =ilog2 (EXT4_DESC_PER_BLOCK (sb)); +for (i =0 ; i <4 ; i++) sbi->s_hash_seed[i] =le32_to_cpu (es->s_hash_seed[i]); sbi->s_def_hash_version = es->s_def_hash_version;
@@ -2566,12 +2571,12 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) goto failed_mount; } -/* -* It makes no sense for the first data block to be beyond the end -* of the filesystem. -*/ -if (le32_to_cpu (es->s_first_data_block) >=ext4_blocks_count (es)) { -printk (KERN_WARNING "EXT4-fs: bad geometry: first data" +/* +* It makes no sense for the first data block to be beyond the end +* of the filesystem. +*/ +if (le32_to_cpu (es->s_first_data_block) >=ext4_blocks_count (es)) { +printk (KERN_WARNING "EXT4-fs: bad geometry: first data" "block %u is beyond end of filesystem (%llu)\n" ,le32_to_cpu (es->s_first_data_block),ext4_blocks_count (es));
@@ -3082,6 +3087,7 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb,EXT4_SB (sb)->journal_bdev = bdev;ext4_init_journal_params (sb, journal);return journal; + out_journal:jbd2_journal_destroy (journal); out_bdev:
@@ -3116,7 +3122,6 @@ static int ext4_load_journal(struct super_block *sb,* crash? For recovery, we need to check in advance whether we * can get read-write access to the device. */ -if (EXT4_HAS_INCOMPAT_FEATURE (sb,EXT4_FEATURE_INCOMPAT_RECOVER )) {if (sb->s_flags &MS_RDONLY ) { printk(KERN_INFO "EXT4-fs: INFO: recovery "
@@ -3234,7 +3239,6 @@ static int ext4_commit_super(struct super_block *sb, int sync)return error; } -/* * Have we just finished recovery? If so, and if we are mounting (or * remounting) the filesystem readonly, then we will end up with a
@@ -3485,8 +3489,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)/* * Make sure the group descriptor checksums -* are sane. If they aren't, refuse to -* remount r/w. +* are sane. If they aren't, refuse to remount r/w. */ for (g =0 ; g < sbi->s_groups_count; g++) { struct ext4_group_desc *gdp =
@@ -3545,6 +3548,7 @@ static int ext4_remount(struct super_block *sb, int *flags, char *data)kfree (old_opts.s_qf_names[i]);#endif return 0 ; + restore_opts: sb->s_flags = old_sb_flags; sbi->s_mount_opt = old_opts.s_mount_opt;
@@ -3628,11 +3632,12 @@ static int ext4_statfs(struct dentry *dentry, struct kstatfs *buf)le64_to_cpup ((void *)es->s_uuid +sizeof (u64)); buf->f_fsid.val[0 ] = fsid &0xFFFFFFFFUL ; buf->f_fsid.val[1 ] = (fsid >>32 ) &0xFFFFFFFFUL ; +return 0 ; } -/* Helper function for writing quotas on sync - we need to start transaction before quota file -* is locked for write. Otherwise the are possible deadlocks: +/* Helper function for writing quotas on sync - we need to start transaction +* before quota file is locked for write. Otherwise the are possible deadlocks: * Process 1 Process 2 * ext4_create() quota_sync() * jbd2_journal_start() write_dquot()
@@ -3656,7 +3661,7 @@ static int ext4_write_dquot(struct dquot *dquot) inode =dquot_to_inode (dquot); handle =ext4_journal_start (inode, -EXT4_QUOTA_TRANS_BLOCKS (dquot->dq_sb)); +EXT4_QUOTA_TRANS_BLOCKS (dquot->dq_sb));if (IS_ERR (handle))return PTR_ERR (handle); ret =dquot_commit (dquot);
@@ -3672,7 +3677,7 @@ static int ext4_acquire_dquot(struct dquot *dquot)handle_t *handle; handle =ext4_journal_start (dquot_to_inode (dquot), -EXT4_QUOTA_INIT_BLOCKS (dquot->dq_sb)); +EXT4_QUOTA_INIT_BLOCKS (dquot->dq_sb));if (IS_ERR (handle))return PTR_ERR (handle); ret =dquot_acquire (dquot);
@@ -3688,7 +3693,7 @@ static int ext4_release_dquot(struct dquot *dquot)handle_t *handle; handle =ext4_journal_start (dquot_to_inode (dquot), -EXT4_QUOTA_DEL_BLOCKS (dquot->dq_sb)); +EXT4_QUOTA_DEL_BLOCKS (dquot->dq_sb));if (IS_ERR (handle)) {/* Release dquot anyway to avoid endless cycle in dqput() */ dquot_release (dquot);
@@ -3736,7 +3741,7 @@ static int ext4_write_info(struct super_block *sb, int type)static int ext4_quota_on_mount (struct super_block *sb,int type) {return vfs_quota_on_mount (sb,EXT4_SB (sb)->s_qf_names[type], -EXT4_SB (sb)->s_jquota_fmt, type); +EXT4_SB (sb)->s_jquota_fmt, type); }/*
@@ -3907,10 +3912,10 @@ out:#endif -static int ext4_get_sb (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data,struct vfsmount *mnt) +static int ext4_get_sb (struct file_system_type *fs_type,int flags, +const char *dev_name,void *data,struct vfsmount *mnt) { -return get_sb_bdev (fs_type, flags, dev_name, data, ext4_fill_super, mnt); +return get_sb_bdev (fs_type, flags, dev_name, data, ext4_fill_super,mnt); }static struct file_system_type ext4_fs_type = {
@@ -3922,14 +3927,14 @@ static struct file_system_type ext4_fs_type = { };#ifdef CONFIG_EXT4DEV_COMPAT -static int ext4dev_get_sb (struct file_system_type *fs_type, -int flags,const char *dev_name,void *data,struct vfsmount *mnt) +static int ext4dev_get_sb (struct file_system_type *fs_type,int flags, +const char *dev_name,void *data,struct vfsmount *mnt) {printk (KERN_WARNING "EXT4-fs: Update your userspace programs " "to mount using ext4\n" );printk (KERN_WARNING "EXT4-fs: ext4dev backwards compatibility " "will go away by 2.6.31\n" ); -return get_sb_bdev (fs_type, flags, dev_name, data, ext4_fill_super, mnt); +return get_sb_bdev (fs_type, flags, dev_name, data, ext4_fill_super,mnt); } static struct file_system_type ext4dev_fs_type = {
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 45/49 ext4: Get rid of EXTEND_DISKSIZE flag of ext4_get_blocks_handle()
From: Jan Kara <[email protected]>
Get rid of EXTEND_DISKSIZE flag of ext4_get_blocks_handle(). This seems to be a relict from some old days and setting disksize in this function does not make much sense. Currently it was set only by ext4_getblk(). Since the parameter has some effect only if create == 1, it is easy to check by grepping through the sources that the three callers which end up calling ext4_getblk() with create == 1 (ext4_append, ext4_quota_write, ext4_mkdir) do the right thing and set disksize themselves.
--- fs/ext4/ext4.h | 6 ++---- fs/ext4/extents.c | 9 --------- fs/ext4/inode.c | 20 +++----------------- 3 files changed, 5 insertions(+), 30 deletions(-)
fs/ext4/ext4.h +2 -4
@@ -323,15 +323,13 @@ struct ext4_new_group_data {#define EXT4_GET_BLOCKS_UNINIT_EXT 0x0002#define EXT4_GET_BLOCKS_CREATE_UNINIT_EXT (EXT4_GET_BLOCKS_UNINIT_EXT|\ EXT4_GET_BLOCKS_CREATE) -/* Update the ext4_inode_info i_disksize field */ -#define EXT4_GET_BLOCKS_EXTEND_DISKSIZE 0x0004/* Caller is from the delayed allocation writeout path, so set the magic i_delalloc_reserve_flag after taking the inode allocation semaphore for */ -#define EXT4_GET_BLOCKS_DELALLOC_RESERVE 0x0008 +#define EXT4_GET_BLOCKS_DELALLOC_RESERVE 0x0004/* Call ext4_da_update_reserve_space() after successfully allocating the blocks */ -#define EXT4_GET_BLOCKS_UPDATE_RESERVE_SPACE 0x0010 +#define EXT4_GET_BLOCKS_UPDATE_RESERVE_SPACE 0x0008/*
fs/ext4/extents.c +0 -9
@@ -2779,7 +2779,6 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode,int err =0 , depth, ret, cache_type;unsigned int allocated =0 ;struct ext4_allocation_request ar; -loff_t disksize;__clear_bit (BH_New, &bh_result->b_state); ext_debug("blocks %u/%u requested for inode %u\n",
@@ -2969,14 +2968,6 @@ int ext4_ext_get_blocks(handle_t *handle, struct inode *inode, newblock =ext_pblock (&newex); allocated =ext4_ext_get_actual_len (&newex); outnew: -if (flags &EXT4_GET_BLOCKS_EXTEND_DISKSIZE ) { - disksize = ((loff_t ) iblock + ar.len) << inode->i_blkbits; -if (disksize >i_size_read (inode)) - disksize =i_size_read (inode); -if (disksize >EXT4_I (inode)->i_disksize) -EXT4_I (inode)->i_disksize = disksize; - } -set_buffer_new (bh_result);/* Cache only when it is _not_ an uninitialized extent */
fs/ext4/inode.c +3 -17
@@ -1003,19 +1003,7 @@ static int ext4_ind_get_blocks(handle_t *handle, struct inode *inode,if (!err) err =ext4_splice_branch (handle, inode, iblock, partial, indirect_blks, count); -/* -* 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 -*/ -if (!err && (flags &EXT4_GET_BLOCKS_EXTEND_DISKSIZE )) { - disksize = ((loff_t ) iblock + count) << inode->i_blkbits; -if (disksize >i_size_read (inode)) - disksize =i_size_read (inode); -if (disksize > ei->i_disksize) - ei->i_disksize = disksize; - } -if (err) +else goto cleanup;set_buffer_new (bh_result);
@@ -1321,7 +1309,7 @@ struct buffer_head *ext4_getblk(handle_t *handle, struct inode *inode, {struct buffer_head dummy;int fatal =0 , err; -int flags =EXT4_GET_BLOCKS_EXTEND_DISKSIZE ; +int flags =0 ;J_ASSERT (handle !=NULL || create ==0 );
@@ -2153,9 +2141,7 @@ static int mpage_da_map_blocks(struct mpage_da_data *mpd) }/* -* Update on-disk size along with block allocation we don't -* use EXT4_GET_BLOCKS_EXTEND_DISKSIZE as size may change -* within already allocated block -bzzz +* Update on-disk size along with block allocation. */ disksize = ((loff_t ) next + blks) << mpd->inode->i_blkbits;if (disksize >i_size_read (mpd->inode))
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 46/49 ext4: Change all super.c messages to print the device
From: Eric Sandeen <[email protected]>
This patch changes ext4 super.c to include the device name with all warning/error messages, by using a new utility function ext4_msg. It's a rather large patch, but very mechanic. I left debug printks alone.
This is a straightforward port of a patch which Andi Kleen did for ext3.
--- fs/ext4/ext4.h | 2 + fs/ext4/super.c | 462 ++++++++++++++++++++++++++++--------------------------- 2 files changed, 235 insertions(+), 229 deletions(-)
fs/ext4/ext4.h +2 -0
@@ -1401,6 +1401,8 @@ extern void ext4_abort(struct super_block *, const char *, const char *, ...) __attribute__ ((format (printf, 3, 4)));extern void ext4_warning (struct super_block *,const char *,const char *, ...) __attribute__ ((format (printf,3 ,4 ))); +extern void ext4_msg (struct super_block *,const char *,const char *, ...) + __attribute__ ((format (printf,3 ,4 )));extern void ext4_grp_locked_error (struct super_block *,ext4_group_t ,const char *,const char *, ...) __attribute__ ((format (printf,4 ,5 )));
fs/ext4/super.c +233 -229
1,097 lines not on this page · raw message
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 47/49 ext4: Avoid leaking blocks after a block allocation failure
From: Aneesh Kumar K.V <[email protected]>
We should add inode to the orphan list in the same transaction as block allocation. This ensures that if we crash after a failed block allocation and before we do a vmtruncate we don't leak block (ie block marked as used in bitmap but not claimed by the inode).
--- fs/ext4/inode.c | 24 ++++++++++++++++++++++-- 1 files changed, 22 insertions(+), 2 deletions(-)
fs/ext4/inode.c +22 -2
@@ -1462,7 +1462,7 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping, struct page **pagep, void **fsdata) { struct inode *inode = mapping->host; -int ret, needed_blocks =ext4_writepage_trans_blocks (inode); +int ret, needed_blocks;handle_t *handle;int retries =0 ;struct page *page;
@@ -1473,6 +1473,11 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,"dev %s ino %lu pos %llu len %u flags %u" , inode->i_sb->s_id, inode->i_ino, (unsigned long long) pos, len, flags); +/* +* Reserve one block more for addition to orphan list in case +* we allocate blocks but write fails for some reason +*/ + needed_blocks =ext4_writepage_trans_blocks (inode) +1 ; index = pos >>PAGE_CACHE_SHIFT ; from = pos & (PAGE_CACHE_SIZE -1 ); to = from + len;
@@ -1506,15 +1511,30 @@ retry:if (ret) {unlock_page (page); -ext4_journal_stop (handle);page_cache_release (page);/* * block_write_begin may have instantiated a few blocks * outside i_size. Trim these off again. Don't need * i_size_read because we hold i_mutex. +* +* Add inode to orphan list in case we crash before +* truncate finishes */ if (pos + len > inode->i_size) +ext4_orphan_add (handle, inode); + +ext4_journal_stop (handle); +if (pos + len > inode->i_size) {vmtruncate (inode, inode->i_size); +/* +* If vmtruncate failed early the inode might +* still be on the orphan list; we need to +* make sure the inode is removed from the +* orphan list in that case. +*/ +if (inode->i_nlink) +ext4_orphan_del (NULL , inode); + } }if (ret == -ENOSPC &&ext4_should_retry_alloc (inode->i_sb, &retries))
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 48/49 ext4: truncate the file properly if we fail to copy data from userspace
From: Aneesh Kumar K.V <[email protected]>
In generic_perform_write if we fail to copy the user data we don't update the inode->i_size. We should truncate the file in the above case so that we don't have blocks allocated outside inode->i_size. Add the inode to orphan list in the same transaction as block allocation This ensures that if we crash in between the recovery would do the truncate.
--- fs/ext4/inode.c | 128 +++++++++++++++++++++++++++++++++++++++++++----------- 1 files changed, 102 insertions(+), 26 deletions(-)
fs/ext4/inode.c +102 -26
@@ -1552,6 +1552,52 @@ static int write_end_fn(handle_t *handle, struct buffer_head *bh)return ext4_handle_dirty_metadata (handle,NULL , bh); } +static int ext4_generic_write_end (struct file *file, +struct address_space *mapping, +loff_t pos,unsigned len,unsigned copied, +struct page *page,void *fsdata) +{ +int i_size_changed =0 ; +struct inode *inode = mapping->host; +handle_t *handle =ext4_journal_current_handle (); + + copied =block_write_end (file, mapping, pos, len, copied, page, fsdata); + +/* +* No need to use i_size_read() here, the i_size +* cannot change under us because we hold i_mutex. +* +* But it's important to update i_size while still holding page lock: +* page writeout could otherwise come in and zero beyond i_size. +*/ +if (pos + copied > inode->i_size) { +i_size_write (inode, pos + copied); + i_size_changed =1 ; + } + +if (pos + copied >EXT4_I (inode)->i_disksize) { +/* We need to mark inode dirty even if +* new_i_size is less that inode->i_size +* bu greater than i_disksize.(hint delalloc) +*/ +ext4_update_i_disksize (inode, (pos + copied)); + i_size_changed =1 ; + } +unlock_page (page); +page_cache_release (page); + +/* +* Don't mark the inode dirty under page lock. First, it unnecessarily +* makes the holding time of page lock longer. Second, it forces lock +* ordering of page lock and transaction start for journaling +* filesystems. +*/ +if (i_size_changed) +ext4_mark_inode_dirty (handle, inode); + +return copied; +} +/* * We need to pick up the new inode size which generic_commit_write gave us * `file' can be NULL - eg, when called from page_symlink().
@@ -1575,21 +1621,15 @@ static int ext4_ordered_write_end(struct file *file, ret =ext4_jbd2_file_inode (handle, inode);if (ret ==0 ) { -loff_t new_i_size; - - new_i_size = pos + copied; -if (new_i_size >EXT4_I (inode)->i_disksize) { -ext4_update_i_disksize (inode, new_i_size); -/* We need to mark inode dirty even if -* new_i_size is less that inode->i_size -* bu greater than i_disksize.(hint delalloc) -*/ -ext4_mark_inode_dirty (handle, inode); - } - - ret2 =generic_write_end (file, mapping, pos, len, copied, + ret2 =ext4_generic_write_end (file, mapping, pos, len, copied, page, fsdata); copied = ret2; +if (pos + len > inode->i_size) +/* if we have allocated more blocks and copied +* less. We will have blocks allocated outside +* inode->i_size. So truncate them +*/ +ext4_orphan_add (handle, inode);if (ret2 <0 ) ret = ret2; }
@@ -1597,6 +1637,18 @@ static int ext4_ordered_write_end(struct file *file,if (!ret) ret = ret2; +if (pos + len > inode->i_size) { +vmtruncate (inode, inode->i_size); +/* +* If vmtruncate failed early the inode might still be +* on the orphan list; we need to make sure the inode +* is removed from the orphan list in that case. +*/ +if (inode->i_nlink) +ext4_orphan_del (NULL , inode); + } + +return ret ? ret : copied; }
@@ -1608,25 +1660,21 @@ static int ext4_writeback_write_end(struct file *file,handle_t *handle =ext4_journal_current_handle ();struct inode *inode = mapping->host;int ret =0 , ret2; -loff_t new_i_size;trace_mark (ext4_writeback_write_end,"dev %s ino %lu pos %llu len %u copied %u" , inode->i_sb->s_id, inode->i_ino, (unsigned long long ) pos, len, copied); - new_i_size = pos + copied; -if (new_i_size >EXT4_I (inode)->i_disksize) { -ext4_update_i_disksize (inode, new_i_size); -/* We need to mark inode dirty even if -* new_i_size is less that inode->i_size -* bu greater than i_disksize.(hint delalloc) -*/ -ext4_mark_inode_dirty (handle, inode); - } - - ret2 =generic_write_end (file, mapping, pos, len, copied, + ret2 =ext4_generic_write_end (file, mapping, pos, len, copied, page, fsdata); copied = ret2; +if (pos + len > inode->i_size) +/* if we have allocated more blocks and copied +* less. We will have blocks allocated outside +* inode->i_size. So truncate them +*/ +ext4_orphan_add (handle, inode); +if (ret2 <0 ) ret = ret2;
@@ -1634,6 +1682,17 @@ static int ext4_writeback_write_end(struct file *file,if (!ret) ret = ret2; +if (pos + len > inode->i_size) { +vmtruncate (inode, inode->i_size); +/* +* If vmtruncate failed early the inode might still be +* on the orphan list; we need to make sure the inode +* is removed from the orphan list in that case. +*/ +if (inode->i_nlink) +ext4_orphan_del (NULL , inode); + } +return ret ? ret : copied; }
@@ -1678,10 +1737,27 @@ static int ext4_journalled_write_end(struct file *file, }unlock_page (page); +page_cache_release (page); +if (pos + len > inode->i_size) +/* if we have allocated more blocks and copied +* less. We will have blocks allocated outside +* inode->i_size. So truncate them +*/ +ext4_orphan_add (handle, inode); + ret2 =ext4_journal_stop (handle);if (!ret) ret = ret2; -page_cache_release (page); +if (pos + len > inode->i_size) { +vmtruncate (inode, inode->i_size); +/* +* If vmtruncate failed early the inode might still be +* on the orphan list; we need to make sure the inode +* is removed from the orphan list in that case. +*/ +if (inode->i_nlink) +ext4_orphan_del (NULL , inode); + }return ret ? ret : copied; }
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Theodore Ts'o
maintainerPATCH 49/49 ext4: fix dx_map_entry to support 256k directory blocks
From: Toshiyuki Okajima <[email protected]>
The dx_map_entry structure doesn't support over 64KB block size by current usage of its member("offs"). Because "offs" treats an offset of copies of the ext4_dir_entry_2 structure as is. This member size is 16 bits. But real offset for over 64KB(256KB) block size needs 18 bits. However, real offset keeps 4 byte boundary, so lower 2 bits is not used.
Therefore, we do the following to fix this limitation:
For "store":
we divide the real offset by 4 and then store this result to "offs" member.
For "use":
we multiply "offs" member by 4 and then use this result as real offset.
--- fs/ext4/namei.c | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-)
fs/ext4/namei.c +3 -2
@@ -749,7 +749,7 @@ static int dx_make_map(struct ext4_dir_entry_2 *de, unsigned blocksize,ext4fs_dirhash (de->name, de->name_len, &h); map_tail--; map_tail->hash = h.hash; - map_tail->offs = (u16) ((char *) de - base); + map_tail->offs = ((char *) de - base)>>2 ; map_tail->size =le16_to_cpu (de->rec_len); count++;cond_resched ();
@@ -1147,7 +1147,8 @@ dx_move_dirents(char *from, char *to, struct dx_map_entry *map, int count,unsigned rec_len =0 ;while (count--) { -struct ext4_dir_entry_2 *de = (struct ext4_dir_entry_2 *) (from + map->offs); +struct ext4_dir_entry_2 *de = (struct ext4_dir_entry_2 *) + (from + (map->offs<<2 )); rec_len =EXT4_DIR_REC_LEN (de->name_len);memcpy (to, de, rec_len); ((struct ext4_dir_entry_2 *) to)->rec_len =
Signature · 1 line
1.6.3.2.1.gb9f7d.dirty
Re: [PATCH 43/49] jbd2: Fix minor typos in comments in fs/jbd2/journal.c
In reply to Theodore Ts'oQuoted 13 lines · Theodore Ts'o
From: Alberto Bertogli <[email protected]>
Signed-off-by Alberto Bertogli <[email protected]>Signed-off-by Theodore Ts'o <[email protected]>--- fs/jbd2/journal.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)fs/jbd2/journal.c +0
-0
fs/jbd2/journal.c int jbd2_journal_wipe(journal_t *journal, int write) · line 1786
Quoted 7 lines
fs/jbd2/journal.c +1
-1@@ -1781,7 +1781,7 @@ int jbd2_journal_wipe(journal_t *journal, int write)* Journal abort has very specific semantics, which we describe * for journal abort. * -* Two internal function, which provide abort to te jbd layer +* Two internal function, which provide abort to the jbd layer * itself are here. */
There is a second version of the patch (the one you replied to) that has "function*s*" fixed.
Message ID was [email protected]. If you want me to resend it, let me know.
Thanks,
Alberto
Theodore Tso
maintainerRe: [PATCH 43/49] jbd2: Fix minor typos in comments in fs/jbd2/journal.c
Quoted 4 lines · Alberto Bertogli
There is a second version of the patch (the one you replied to) that has "function*s*" fixed.
Thanks for pointing that out; I've edited the patch to change "function" to "functions".
- Ted