Btrfs stable patches for 4.5.x
Subsystems (2)
Hi,
please queue the following patches to 4.5 stable. There are fixes for user visible bugs, improved error handling and stability fixes, all picked from current 4.7 changes.
The patches do not apply cleanly on top of 4.5.6 so I'll send them as reply to this mail, now with the stable changelog notices in place.
I have tested the patches on top of 4.5. Some patches may apply to older stable branches but haven't been tested nor reviewed them in that respect.
Subjects:
btrfs: bugfix: handle FS_IOC32_{GETFLAGS,SETFLAGS,GETVERSION} in btrfs_ioctl
Btrfs: do not create empty block group if we have allocated data
btrfs: allow balancing to dup with multi-device
btrfs: fix mixed block count of available space
btrfs: avoid overflowing f_bfree
btrfs: fix lock dep warning, move scratch dev out of device_list_mutex and uuid_mutex
btrfs: add read-only check to sysfs handler of features
btrfs: add check to sysfs handler of label
Btrfs: fix divide error upon chunk's stripe_len
Btrfs: remove BUG_ON()'s in btrfs_map_block
btrfs: fix lock dep warning move scratch super outside of chunk_mutex
btrfs: add write protection to SET_FEATURES ioctl
btrfs: fix int32 overflow in shrink_delalloc().
Btrfs: fix fspath error deallocation
btrfs: fix memory leak during RAID 5/6 device replacement
btrfs: pass the right error code to the btrfs_std_error
Btrfs: fix for incorrect directory entries after fsync log replay
Btrfs: fix empty symlink after creating symlink and fsync parent dir
Btrfs: fix unexpected return value of fiemap
btrfs: scrub: Set bbio to NULL before calling btrfs_map_block
btrfs: make state preallocation more speculative in __set_extent_bit
Commits:
4c63c2454eff996c5e27991221106eb511f7db38
cf25ce518e8ef9d59b292e51193bed2b023a32da
88be159c905a2b4f6d59afa352bef410afb6af02
ae02d1bd070767e109f4a6f1bb1f466e9698a355
41b34accb265e3a20211a7a8ef3625678f1c6ec7
779bf3fefa835cb52a07457c8acac6f2f66f2493
ee6111386a1b304f8bf589d36810d53e3b27ee20
66ac9fe7bacf9fa76c472efc7a7aaa590c7bce6a
3d8da67817606380fdadfa483d4dba5c3a5446c6
e042d1ec4417981dfe9331e47b76f17929bc2ffe
48b3b9d401ec86899a52003b37331190a35a81a6
7ab19625a911f7568ec85302e3aa7a64186006c8
8eb0dfdbda3f56bf7d248ed87fcc383df114ecbb
72928f2476d08c79f132b4f44a17c9a011dd98e3
4673272f43ae790ab9ec04e38a7542f82bb8f020
ad8403df054c9b5dc3175a26c6179571b9cafa4e
657ed1aa4898c8304500e0d13f240d5a67e8be5f
3f9749f6e9edcf8ec569fb542efc3be35e06e84a
2d324f59f343967a03eeb2690f0ff178304d0687
f1fee6534dcfbf468a159789aa202db2bce8c200
059f791c6bbaba72dc3c1bd6e2657aacc8552849David Sterba
maintainerPATCH 1/21 btrfs: bugfix: handle FS_IOC32_{GETFLAGS,SETFLAGS,GETVERSION} in btrfs_ioctl
From: Luke Dashjr <[email protected]>
commit 4c63c2454eff996c5e27991221106eb511f7db38 upstream.
32-bit ioctl uses these rather than the regular FS_IOC_* versions. They can be handled in btrfs using the same code. Without this, 32-bit {ch,ls}attr fail.
--- fs/btrfs/ctree.h | 1 + fs/btrfs/file.c | 2 +- fs/btrfs/inode.c | 2 +- fs/btrfs/ioctl.c | 21 +++++++++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-)
fs/btrfs/ctree.h +1 -0
@@ -4089,6 +4089,7 @@ void btrfs_test_inode_set_ops(struct inode *inode);/* ioctl.c */ long btrfs_ioctl (struct file *file,unsigned int cmd,unsigned long arg); +long btrfs_compat_ioctl (struct file *file,unsigned int cmd,unsigned long arg);void btrfs_update_iflags (struct inode *inode);void btrfs_inherit_iflags (struct inode *inode,struct inode *dir);int btrfs_is_empty_uuid (u8 *uuid);
fs/btrfs/file.c +1 -1
@@ -2931,7 +2931,7 @@ const struct file_operations btrfs_file_operations = { .fallocate = btrfs_fallocate, .unlocked_ioctl = btrfs_ioctl, #ifdef CONFIG_COMPAT - .compat_ioctl = btrfs_ioctl, + .compat_ioctl = btrfs_compat_ioctl, #endif .copy_file_range = btrfs_copy_file_range, .clone_file_range = btrfs_clone_file_range,
fs/btrfs/inode.c +1 -1
@@ -10088,7 +10088,7 @@ static const struct file_operations btrfs_dir_file_operations = { .iterate = btrfs_real_readdir, .unlocked_ioctl = btrfs_ioctl, #ifdef CONFIG_COMPAT - .compat_ioctl = btrfs_ioctl, + .compat_ioctl = btrfs_compat_ioctl, #endif .release = btrfs_release_file, .fsync = btrfs_sync_file,
fs/btrfs/ioctl.c +21 -0
@@ -5555,3 +5555,24 @@ long btrfs_ioctl(struct file *file, unsigned intreturn -ENOTTY ; } + +#ifdef CONFIG_COMPAT +long btrfs_compat_ioctl (struct file *file,unsigned int cmd,unsigned long arg) +{ +switch (cmd) { +case FS_IOC32_GETFLAGS : + cmd =FS_IOC_GETFLAGS ; +break ; +case FS_IOC32_SETFLAGS : + cmd =FS_IOC_SETFLAGS ; +break ; +case FS_IOC32_GETVERSION : + cmd =FS_IOC_GETVERSION ; +break ; +default : +return -ENOIOCTLCMD ; + } + +return btrfs_ioctl (file, cmd, (unsigned long )compat_ptr (arg)); +} +#endif
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 2/21 Btrfs: do not create empty block group if we have allocated data
In reply to David SterbaFrom: Liu Bo <[email protected]>
commit cf25ce518e8ef9d59b292e51193bed2b023a32da upstream.
Now we force to create empty block group to keep data profile alive, however, in the below example, we eventually get an empty block group while we're trying to get more space for other types (metadata/system),
- Before,
block group "A": size=2G, used=1.2G
block group "B": size=2G, used=512M
- After "btrfs balance start -dusage=50 mount_point", block group "A": size=2G, used=(1.2+0.5)G block group "C": size=2G, used=0
Since there is no data in block group C, it won't be deleted automatically and we have to get the unused 2G until the next mount.
Balance itself just moves data and doesn't remove data, so it's safe to not create such a empty block group if we already have data
allocated in other block groups.
--- fs/btrfs/volumes.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
fs/btrfs/volumes.c +8 -1
@@ -3401,6 +3401,7 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info)u32 count_meta =0 ;u32 count_sys =0 ;int chunk_reserved =0 ; +u64 bytes_used =0 ;/* step one make some room on all the devices */ devices = &fs_info->fs_devices->devices;
@@ -3539,7 +3540,13 @@ static int __btrfs_balance(struct btrfs_fs_info *fs_info) goto loop; } -if ((chunk_type &BTRFS_BLOCK_GROUP_DATA ) && !chunk_reserved) { +ASSERT (fs_info->data_sinfo); +spin_lock (&fs_info->data_sinfo->lock); + bytes_used = fs_info->data_sinfo->bytes_used; +spin_unlock (&fs_info->data_sinfo->lock); + +if ((chunk_type &BTRFS_BLOCK_GROUP_DATA ) && + !chunk_reserved && !bytes_used) { trans =btrfs_start_transaction (chunk_root,0 );if (IS_ERR (trans)) {mutex_unlock (&fs_info->delete_unused_bgs_mutex);
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 3/21 btrfs: allow balancing to dup with multi-device
In reply to David SterbaFrom: "Austin S. Hemmelgarn" <[email protected]>
commit 88be159c905a2b4f6d59afa352bef410afb6af02 upstream.
Currently, we don't allow the user to try and rebalance to a dup profile on a multi-device filesystem. In most cases, this is a perfectly sensible restriction as raid1 uses the same amount of space and provides better protection.
However, when reshaping a multi-device filesystem down to a single device filesystem, this requires the user to convert metadata and system chunks to single profile before deleting devices, and then convert again to dup, which leaves a period of time where metadata integrity is reduced.
This patch removes the single-device-only restriction from converting to dup profile to remove this potential data integrity reduction.
--- fs/btrfs/volumes.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
fs/btrfs/volumes.c +2 -4
@@ -3699,10 +3699,8 @@ int btrfs_balance(struct btrfs_balance_control *bctl, num_devices--; }btrfs_dev_replace_unlock (&fs_info->dev_replace); - allowed =BTRFS_AVAIL_ALLOC_BIT_SINGLE ; -if (num_devices ==1 ) - allowed |=BTRFS_BLOCK_GROUP_DUP ; -else if (num_devices >1 ) + allowed =BTRFS_AVAIL_ALLOC_BIT_SINGLE |BTRFS_BLOCK_GROUP_DUP ; +if (num_devices >1 ) allowed |= (BTRFS_BLOCK_GROUP_RAID0 |BTRFS_BLOCK_GROUP_RAID1 );if (num_devices >2 ) allowed |=BTRFS_BLOCK_GROUP_RAID5 ;
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 4/21 btrfs: fix mixed block count of available space
In reply to David SterbaFrom: Luis de Bethencourt <[email protected]>
commit ae02d1bd070767e109f4a6f1bb1f466e9698a355 upstream.
Metadata for mixed block is already accounted in total data and should not be counted as part of the free metadata space.
--- fs/btrfs/super.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
fs/btrfs/super.c +13 -3
@@ -2024,6 +2024,7 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv;int ret;u64 thresh =0 ; +int mixed =0 ;/* * holding chunk_muext to avoid allocating new chunks, holding
@@ -2049,8 +2050,17 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) } } } -if (found->flags &BTRFS_BLOCK_GROUP_METADATA ) - total_free_meta += found->disk_total - found->disk_used; + +/* +* Metadata in mixed block goup profiles are accounted in data +*/ +if (!mixed && found->flags &BTRFS_BLOCK_GROUP_METADATA ) { +if (found->flags &BTRFS_BLOCK_GROUP_DATA ) + mixed =1 ; +else + total_free_meta += found->disk_total - + found->disk_used; + } total_used += found->disk_used; }
@@ -2088,7 +2098,7 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)*/ thresh =4 *1024 *1024 ; -if (total_free_meta - thresh < block_rsv->size) +if (!mixed && total_free_meta - thresh < block_rsv->size) buf->f_bavail =0 ; buf->f_type =BTRFS_SUPER_MAGIC ;
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 5/21 btrfs: avoid overflowing f_bfree
In reply to David SterbaFrom: Luis de Bethencourt <[email protected]>
commit 41b34accb265e3a20211a7a8ef3625678f1c6ec7 upstream.
Since mixed block groups accounting isn't byte-accurate and f_bree is an unsigned integer, it could overflow. Avoid this.
--- fs/btrfs/super.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/btrfs/super.c +5 -1
@@ -2073,7 +2073,11 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf)/* Account global block reserve as used, it's in logical size already */ spin_lock (&block_rsv->lock); - buf->f_bfree -= block_rsv->size >> bits; +/* Mixed block groups accounting is not byte-accurate, avoid overflow */ +if (buf->f_bfree >= block_rsv->size >> bits) + buf->f_bfree -= block_rsv->size >> bits; +else + buf->f_bfree =0 ;spin_unlock (&block_rsv->lock); buf->f_bavail =div_u64 (total_free_data, factor);
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 6/21 btrfs: fix lock dep warning, move scratch dev out of device_list_mutex and uuid_mutex
In reply to David SterbaFrom: Anand Jain <[email protected]>
commit 779bf3fefa835cb52a07457c8acac6f2f66f2493 upstream.
When the replace target fails, the target device will be taken out of fs device list, scratch + update_dev_time and freed. However we could do the scratch + update_dev_time and free part after the device has been taken out of device list, so that we don't have to hold the device_list_mutex and uuid_mutex locks.
Reported issue:
[ 5375.718845] ======================================================
[ 5375.718846] [ INFO: possible circular locking dependency detected ]
[ 5375.718849] 4.4.5-scst31x-debug-11+ #40 Not tainted
[ 5375.718849] -------------------------------------------------------
[ 5375.718851] btrfs-health/4662 is trying to acquire lock:
[ 5375.718861] (sb_writers){.+.+.+}, at: [<ffffffff812214f7>] __sb_start_write+0xb7/0xf0
[ 5375.718862]
[ 5375.718862] but task is already holding lock:
[ 5375.718907] (&fs_devs->device_list_mutex){+.+.+.}, at: [<ffffffffa028263c>] btrfs_destroy_dev_replace_tgtdev+0x3c/0x150 [btrfs]
[ 5375.718907]
[ 5375.718907] which lock already depends on the new lock.
[ 5375.718907]
[ 5375.718908]
[ 5375.718908] the existing dependency chain (in reverse order) is:
[ 5375.718911]
[ 5375.718911] -> #3 (&fs_devs->device_list_mutex){+.+.+.}:
[ 5375.718917] [<ffffffff810da4be>] lock_acquire+0xce/0x1e0
[ 5375.718921] [<ffffffff81633949>] mutex_lock_nested+0x69/0x3c0
[ 5375.718940] [<ffffffffa0219bf6>] btrfs_show_devname+0x36/0x210 [btrfs]
[ 5375.718945] [<ffffffff81267079>] show_vfsmnt+0x49/0x150
[ 5375.718948] [<ffffffff81240b07>] m_show+0x17/0x20
[ 5375.718951] [<ffffffff81246868>] seq_read+0x2d8/0x3b0
[ 5375.718955] [<ffffffff8121df28>] __vfs_read+0x28/0xd0
[ 5375.718959] [<ffffffff8121e806>] vfs_read+0x86/0x130
[ 5375.718962] [<ffffffff8121f4c9>] SyS_read+0x49/0xa0
[ 5375.718966] [<ffffffff81637976>] entry_SYSCALL_64_fastpath+0x16/0x7a
[ 5375.718968]
[ 5375.718968] -> #2 (namespace_sem){+++++.}:
[ 5375.718971] [<ffffffff810da4be>] lock_acquire+0xce/0x1e0
[ 5375.718974] [<ffffffff81635199>] down_write+0x49/0x80
[ 5375.718977] [<ffffffff81243593>] lock_mount+0x43/0x1c0
[ 5375.718979] [<ffffffff81243c13>] do_add_mount+0x23/0xd0
[ 5375.718982] [<ffffffff81244afb>] do_mount+0x27b/0xe30
[ 5375.718985] [<ffffffff812459dc>] SyS_mount+0x8c/0xd0
[ 5375.718988] [<ffffffff81637976>] entry_SYSCALL_64_fastpath+0x16/0x7a
[ 5375.718991]
[ 5375.718991] -> #1 (&sb->s_type->i_mutex_key#5){+.+.+.}:
[ 5375.718994] [<ffffffff810da4be>] lock_acquire+0xce/0x1e0
[ 5375.718996] [<ffffffff81633949>] mutex_lock_nested+0x69/0x3c0
[ 5375.719001] [<ffffffff8122d608>] path_openat+0x468/0x1360
[ 5375.719004] [<ffffffff8122f86e>] do_filp_open+0x7e/0xe0
[ 5375.719007] [<ffffffff8121da7b>] do_sys_open+0x12b/0x210
[ 5375.719010] [<ffffffff8121db7e>] SyS_open+0x1e/0x20
[ 5375.719013] [<ffffffff81637976>] entry_SYSCALL_64_fastpath+0x16/0x7a
[ 5375.719015]
[ 5375.719015] -> #0 (sb_writers){.+.+.+}:
[ 5375.719018] [<ffffffff810d97ca>] __lock_acquire+0x17ba/0x1ae0
[ 5375.719021] [<ffffffff810da4be>] lock_acquire+0xce/0x1e0
[ 5375.719026] [<ffffffff810d3bef>] percpu_down_read+0x4f/0xa0
[ 5375.719028] [<ffffffff812214f7>] __sb_start_write+0xb7/0xf0
[ 5375.719031] [<ffffffff81242eb4>] mnt_want_write+0x24/0x50
[ 5375.719035] [<ffffffff8122ded2>] path_openat+0xd32/0x1360
[ 5375.719037] [<ffffffff8122f86e>] do_filp_open+0x7e/0xe0
[ 5375.719040] [<ffffffff8121d8a4>] file_open_name+0xe4/0x130
[ 5375.719043] [<ffffffff8121d923>] filp_open+0x33/0x60
[ 5375.719073] [<ffffffffa02776a6>] update_dev_time+0x16/0x40 [btrfs]
[ 5375.719099] [<ffffffffa02825be>] btrfs_scratch_superblocks+0x4e/0x90 [btrfs]
[ 5375.719123] [<ffffffffa0282665>] btrfs_destroy_dev_replace_tgtdev+0x65/0x150 [btrfs]
[ 5375.719150] [<ffffffffa02c6c80>] btrfs_dev_replace_finishing+0x6b0/0x990 [btrfs]
[ 5375.719175] [<ffffffffa02c729e>] btrfs_dev_replace_start+0x33e/0x540 [btrfs]
[ 5375.719199] [<ffffffffa02c7f58>] btrfs_auto_replace_start+0xf8/0x140 [btrfs]
[ 5375.719222] [<ffffffffa02464e6>] health_kthread+0x246/0x490 [btrfs]
[ 5375.719225] [<ffffffff810a70df>] kthread+0xef/0x110
[ 5375.719229] [<ffffffff81637d2f>] ret_from_fork+0x3f/0x70
[ 5375.719230]
[ 5375.719230] other info that might help us debug this:
[ 5375.719230]
[ 5375.719233] Chain exists of:
[ 5375.719233] sb_writers --> namespace_sem --> &fs_devs->device_list_mutex
[ 5375.719233]
[ 5375.719234] Possible unsafe locking scenario:
[ 5375.719234]
[ 5375.719234] CPU0 CPU1
[ 5375.719235] ---- ----
[ 5375.719236] lock(&fs_devs->device_list_mutex);
[ 5375.719238] lock(namespace_sem);
[ 5375.719239] lock(&fs_devs->device_list_mutex);
[ 5375.719241] lock(sb_writers);
[ 5375.719241]
[ 5375.719241] *** DEADLOCK ***
[ 5375.719241]
[ 5375.719243] 4 locks held by btrfs-health/4662:
[ 5375.719266] #0: (&fs_info->health_mutex){+.+.+.}, at: [<ffffffffa0246303>] health_kthread+0x63/0x490 [btrfs]
[ 5375.719293] #1: (&fs_info->dev_replace.lock_finishing_cancel_unmount){+.+.+.}, at: [<ffffffffa02c6611>] btrfs_dev_replace_finishing+0x41/0x990 [btrfs]
[ 5375.719319] #2: (uuid_mutex){+.+.+.}, at: [<ffffffffa0282620>] btrfs_destroy_dev_replace_tgtdev+0x20/0x150 [btrfs]
[ 5375.719343] #3: (&fs_devs->device_list_mutex){+.+.+.}, at: [<ffffffffa028263c>] btrfs_destroy_dev_replace_tgtdev+0x3c/0x150 [btrfs]
[ 5375.719343]
[ 5375.719343] stack backtrace:
[ 5375.719347] CPU: 2 PID: 4662 Comm: btrfs-health Not tainted 4.4.5-scst31x-debug-11+ #40
[ 5375.719348] Hardware name: Supermicro SYS-6018R-WTRT/X10DRW-iT, BIOS 1.0c 01/07/2015
[ 5375.719352] 0000000000000000 ffff880856f73880 ffffffff813529e3 ffffffff826182a0
[ 5375.719354] ffffffff8260c090 ffff880856f738c0 ffffffff810d667c ffff880856f73930
[ 5375.719357] ffff880861f32b40 ffff880861f32b68 0000000000000003 0000000000000004
[ 5375.719357] Call Trace:
[ 5375.719363] [<ffffffff813529e3>] dump_stack+0x85/0xc2
[ 5375.719366] [<ffffffff810d667c>] print_circular_bug+0x1ec/0x260
[ 5375.719369] [<ffffffff810d97ca>] __lock_acquire+0x17ba/0x1ae0
[ 5375.719373] [<ffffffff810f606d>] ? debug_lockdep_rcu_enabled+0x1d/0x20
[ 5375.719376] [<ffffffff810da4be>] lock_acquire+0xce/0x1e0
[ 5375.719378] [<ffffffff812214f7>] ? __sb_start_write+0xb7/0xf0
[ 5375.719383] [<ffffffff810d3bef>] percpu_down_read+0x4f/0xa0
[ 5375.719385] [<ffffffff812214f7>] ? __sb_start_write+0xb7/0xf0
[ 5375.719387] [<ffffffff812214f7>] __sb_start_write+0xb7/0xf0
[ 5375.719389] [<ffffffff81242eb4>] mnt_want_write+0x24/0x50
[ 5375.719393] [<ffffffff8122ded2>] path_openat+0xd32/0x1360
[ 5375.719415] [<ffffffffa02462a0>] ? btrfs_congested_fn+0x180/0x180 [btrfs]
[ 5375.719418] [<ffffffff810f606d>] ? debug_lockdep_rcu_enabled+0x1d/0x20
[ 5375.719420] [<ffffffff8122f86e>] do_filp_open+0x7e/0xe0
[ 5375.719423] [<ffffffff810f615d>] ? rcu_read_lock_sched_held+0x6d/0x80
[ 5375.719426] [<ffffffff81201a9b>] ? kmem_cache_alloc+0x26b/0x5d0
[ 5375.719430] [<ffffffff8122e7d4>] ? getname_kernel+0x34/0x120
[ 5375.719433] [<ffffffff8121d8a4>] file_open_name+0xe4/0x130
[ 5375.719436] [<ffffffff8121d923>] filp_open+0x33/0x60
[ 5375.719462] [<ffffffffa02776a6>] update_dev_time+0x16/0x40 [btrfs]
[ 5375.719485] [<ffffffffa02825be>] btrfs_scratch_superblocks+0x4e/0x90 [btrfs]
[ 5375.719506] [<ffffffffa0282665>] btrfs_destroy_dev_replace_tgtdev+0x65/0x150 [btrfs]
[ 5375.719530] [<ffffffffa02c6c80>] btrfs_dev_replace_finishing+0x6b0/0x990 [btrfs]
[ 5375.719554] [<ffffffffa02c6b23>] ? btrfs_dev_replace_finishing+0x553/0x990 [btrfs]
[ 5375.719576] [<ffffffffa02c729e>] btrfs_dev_replace_start+0x33e/0x540 [btrfs]
[ 5375.719598] [<ffffffffa02c7f58>] btrfs_auto_replace_start+0xf8/0x140 [btrfs]
[ 5375.719621] [<ffffffffa02464e6>] health_kthread+0x246/0x490 [btrfs]
[ 5375.719641] [<ffffffffa02463d8>] ? health_kthread+0x138/0x490 [btrfs]
[ 5375.719661] [<ffffffffa02462a0>] ? btrfs_congested_fn+0x180/0x180 [btrfs]
[ 5375.719663] [<ffffffff810a70df>] kthread+0xef/0x110
[ 5375.719666] [<ffffffff810a6ff0>] ? kthread_create_on_node+0x200/0x200
[ 5375.719669] [<ffffffff81637d2f>] ret_from_fork+0x3f/0x70
[ 5375.719672] [<ffffffff810a6ff0>] ? kthread_create_on_node+0x200/0x200
[ 5375.719697] ------------[ cut here ]--------------- fs/btrfs/volumes.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-)
fs/btrfs/volumes.c +12 -5
@@ -2023,10 +2023,9 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,btrfs_sysfs_rm_device_link (fs_info->fs_devices, tgtdev); -if (tgtdev->bdev) { -btrfs_scratch_superblocks (tgtdev->bdev, tgtdev->name->str); +if (tgtdev->bdev) fs_info->fs_devices->open_devices--; - } + fs_info->fs_devices->num_devices--; next_device = list_entry(fs_info->fs_devices->devices.next,
@@ -2037,10 +2036,18 @@ void btrfs_destroy_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, fs_info->fs_devices->latest_bdev = next_device->bdev;list_del_rcu (&tgtdev->dev_list); -call_rcu (&tgtdev->rcu, free_device); -mutex_unlock (&fs_info->fs_devices->device_list_mutex);mutex_unlock (&uuid_mutex); + +/* +* The update_dev_time() with in btrfs_scratch_superblocks() +* may lead to a call to btrfs_show_devname() which will try +* to hold device_list_mutex. And here this device +* is already out of device list, so we don't have to hold +* the device_list_mutex lock. +*/ +btrfs_scratch_superblocks (tgtdev->bdev, tgtdev->name->str); +call_rcu (&tgtdev->rcu, free_device); } static int btrfs_find_device_by_path(struct btrfs_root *root, char *device_path,
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 7/21 btrfs: add read-only check to sysfs handler of features
In reply to David SterbaFrom: David Sterba <[email protected]>
commit ee6111386a1b304f8bf589d36810d53e3b27ee20 upstream.
We don't want to trigger the change on a read-only filesystem, similar to what the label handler does.
--- fs/btrfs/sysfs.c | 3 +++ 1 file changed, 3 insertions(+)
fs/btrfs/sysfs.c +3 -0
@@ -120,6 +120,9 @@ static ssize_t btrfs_feature_attr_store(struct kobject *kobj,if (!fs_info)return -EPERM ; +if (fs_info->sb->s_flags &MS_RDONLY ) +return -EROFS ; + ret =kstrtoul (skip_spaces (buf),0 , &val);if (ret)return ret;
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 8/21 btrfs: add check to sysfs handler of label
In reply to David Sterbacommit 66ac9fe7bacf9fa76c472efc7a7aaa590c7bce6a upstream.
Add a sanity check for the fs_info as we will dereference it, similar to what the 'store features' handler does.
--- fs/btrfs/sysfs.c | 3 +++ 1 file changed, 3 insertions(+)
fs/btrfs/sysfs.c +3 -0
@@ -377,6 +377,9 @@ static ssize_t btrfs_label_store(struct kobject *kobj,struct btrfs_fs_info *fs_info =to_fs_info (kobj);size_t p_len; +if (!fs_info) +return -EPERM ; +if (fs_info->sb->s_flags &MS_RDONLY )return -EROFS ;
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 9/21 Btrfs: fix divide error upon chunk's stripe_len
In reply to David SterbaFrom: Liu Bo <[email protected]>
commit 3d8da67817606380fdadfa483d4dba5c3a5446c6 upstream.
The struct 'map_lookup' uses type int for @stripe_len, while btrfs_chunk_stripe_len() can return a u64 value, and it may end up with @stripe_len being undefined value and it can lead to 'divide error' in
__btrfs_map_block().
This changes 'map_lookup' to use type u64 for stripe_len, also right now we only use BTRFS_STRIPE_LEN for stripe_len, so this adds a valid checker for BTRFS_STRIPE_LEN.
--- fs/btrfs/scrub.c | 2 +- fs/btrfs/volumes.c | 2 +- fs/btrfs/volumes.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/scrub.c +1 -1
@@ -2858,7 +2858,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx,int extent_mirror_num;int stop_loop =0 ; - nsectors = map->stripe_len / root->sectorsize; + nsectors =div_u64 (map->stripe_len, root->sectorsize); bitmap_len =scrub_calc_parity_bitmap_len (nsectors); sparity =kzalloc (sizeof (struct scrub_parity ) +2 * bitmap_len,GFP_NOFS );
fs/btrfs/volumes.c +1 -1
@@ -6249,7 +6249,7 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key, "invalid chunk length %llu", length);return -EIO ; } -if (!is_power_of_2 (stripe_len)) { +if (!is_power_of_2 (stripe_len) || stripe_len !=BTRFS_STRIPE_LEN ) {btrfs_err (root->fs_info,"invalid chunk stripe length: %llu" , stripe_len);return -EIO ;
fs/btrfs/volumes.h +1 -1
@@ -347,7 +347,7 @@ struct map_lookup {u64 type;int io_align;int io_width; -int stripe_len; +u64 stripe_len;int sector_size;int num_stripes;int sub_stripes;
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 10/21 Btrfs: remove BUG_ON()'s in btrfs_map_block
In reply to David SterbaFrom: Josef Bacik <[email protected]>
commit e042d1ec4417981dfe9331e47b76f17929bc2ffe upstream.
btrfs_map_block can go horribly wrong in the face of fs corruption, lets agree to not be assholes and panic at any possible chance things are all fucked up.
--- fs/btrfs/volumes.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-)
fs/btrfs/volumes.c +16 -2
@@ -5289,7 +5289,15 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, stripe_nr =div64_u64 (stripe_nr, stripe_len); stripe_offset = stripe_nr * stripe_len; -BUG_ON (offset < stripe_offset); +if (offset < stripe_offset) { +btrfs_crit (fs_info,"stripe math has gone wrong, " +"stripe_offset=%llu, offset=%llu, start=%llu, " +"logical=%llu, stripe_len=%llu" , + stripe_offset, offset, em->start, logical, + stripe_len); +free_extent_map (em); +return -EINVAL ; + }/* stripe_offset is the offset of this block in its stripe*/ stripe_offset = offset - stripe_offset;
@@ -5528,7 +5536,13 @@ static int __btrfs_map_block(struct btrfs_fs_info *fs_info, int rw, &stripe_index); mirror_num = stripe_index +1 ; } -BUG_ON (stripe_index >= map->num_stripes); +if (stripe_index >= map->num_stripes) { +btrfs_crit (fs_info,"stripe index math went horribly wrong, " +"got stripe_index=%u, num_stripes=%u" , + stripe_index, map->num_stripes); + ret = -EINVAL ; + goto out; + } num_alloc_stripes = num_stripes;if (dev_replace_is_ongoing) {
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 11/21 btrfs: fix lock dep warning move scratch super outside of chunk_mutex
In reply to David SterbaFrom: Anand Jain <[email protected]>
commit 48b3b9d401ec86899a52003b37331190a35a81a6 upstream.
Move scratch super outside of the chunk lock to avoid below lockdep warning. The better place to scratch super is in the function btrfs_rm_dev_replace_free_srcdev() just before free_device, which is outside of the chunk lock as well.
To reproduce:
(fresh boot)
mkfs.btrfs -f -draid5 -mraid5 /dev/sdc /dev/sdd /dev/sde mount /dev/sdc /btrfs
dd if=/dev/zero of=/btrfs/tf1 bs=4096 count=100 (get devmgt from https://github.com/asj/devmgt.git)
devmgt detach /dev/sde
dd if=/dev/zero of=/btrfs/tf1 bs=4096 count=100 sync
btrfs replace start -Brf 3 /dev/sdf /btrfs <-- devmgt attach host7
======================================================
[ INFO: possible circular locking dependency detected ] 4.6.0-rc2asj+ #1 Not tainted
---------------------------------------------------
btrfs/2174 is trying to acquire lock:
(sb_writers){.+.+.+}, at:
[<ffffffff812449b4>] __sb_start_write+0xb4/0xf0
but task is already holding lock:
(&fs_info->chunk_mutex){+.+.+.}, at:
[<ffffffffa05c5f55>] btrfs_dev_replace_finishing+0x145/0x980 [btrfs]
which lock already depends on the new lock.
Chain exists of: sb_writers --> &fs_devs->device_list_mutex --> &fs_info->chunk_mutex Possible unsafe locking scenario: CPU0 CPU1 ---- ---- lock(&fs_info->chunk_mutex); lock(&fs_devs->device_list_mutex); lock(&fs_info->chunk_mutex);
lock(sb_writers);
*** DEADLOCK ***
-> #0 (sb_writers){.+.+.+}:
[<ffffffff810e6415>] __lock_acquire+0x1bc5/0x1ee0 [<ffffffff810e707e>] lock_acquire+0xbe/0x210 [<ffffffff810df49a>] percpu_down_read+0x4a/0xa0 [<ffffffff812449b4>] __sb_start_write+0xb4/0xf0 [<ffffffff81265534>] mnt_want_write+0x24/0x50 [<ffffffff812508a2>] path_openat+0x952/0x1190 [<ffffffff81252451>] do_filp_open+0x91/0x100 [<ffffffff8123f5cc>] file_open_name+0xfc/0x140 [<ffffffff8123f643>] filp_open+0x33/0x60 [<ffffffffa0572bb6>] update_dev_time+0x16/0x40 [btrfs] [<ffffffffa057f60d>] btrfs_scratch_superblocks+0x5d/0xb0 [btrfs] [<ffffffffa057f70e>] btrfs_rm_dev_replace_remove_srcdev+0xae/0xd0 [btrfs] [<ffffffffa05c62c5>] btrfs_dev_replace_finishing+0x4b5/0x980 [btrfs] [<ffffffffa05c6ae8>] btrfs_dev_replace_start+0x358/0x530 [btrfs]
--- fs/btrfs/volumes.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
fs/btrfs/volumes.c +5 -4
@@ -1971,11 +1971,8 @@ void btrfs_rm_dev_replace_remove_srcdev(struct btrfs_fs_info *fs_info,if (srcdev->missing) fs_devices->missing_devices--; -if (srcdev->writeable) { +if (srcdev->writeable) fs_devices->rw_devices--; -/* zero out the old super if it is writable */ -btrfs_scratch_superblocks (srcdev->bdev, srcdev->name->str); - }if (srcdev->bdev) fs_devices->open_devices--;
@@ -1986,6 +1983,10 @@ void btrfs_rm_dev_replace_free_srcdev(struct btrfs_fs_info *fs_info, {struct btrfs_fs_devices *fs_devices = srcdev->fs_devices; +if (srcdev->writeable) { +/* zero out the old super if it is writable */ +btrfs_scratch_superblocks (srcdev->bdev, srcdev->name->str); + }call_rcu (&srcdev->rcu, free_device);/*
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 12/21 btrfs: add write protection to SET_FEATURES ioctl
In reply to David SterbaFrom: David Sterba <[email protected]>
commit 7ab19625a911f7568ec85302e3aa7a64186006c8 upstream.
Perform the want_write check if we get far enough to do any writes.
--- fs/btrfs/ioctl.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
fs/btrfs/ioctl.c +13 -3
@@ -5397,9 +5397,15 @@ static int btrfs_ioctl_set_features(struct file *file, void __user *arg)if (ret)return ret; + ret =mnt_want_write_file (file); +if (ret) +return ret; + trans =btrfs_start_transaction (root,0 ); -if (IS_ERR (trans)) -return PTR_ERR (trans); +if (IS_ERR (trans)) { + ret =PTR_ERR (trans); + goto out_drop_write; + }spin_lock (&root->fs_info->super_lock); newflags =btrfs_super_compat_flags (super_block);
@@ -5418,7 +5424,11 @@ static int btrfs_ioctl_set_features(struct file *file, void __user *arg)btrfs_set_super_incompat_flags (super_block, newflags);spin_unlock (&root->fs_info->super_lock); -return btrfs_commit_transaction (trans, root); + ret =btrfs_commit_transaction (trans, root); +out_drop_write: +mnt_drop_write_file (file); + +return ret; } long btrfs_ioctl(struct file *file, unsigned int
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 13/21 btrfs: fix int32 overflow in shrink_delalloc().
In reply to David SterbaFrom: Adam Borowski <[email protected]>
commit 8eb0dfdbda3f56bf7d248ed87fcc383df114ecbb upstream.
UBSAN: Undefined behaviour in fs/btrfs/extent-tree.c:4623:21
signed integer overflow:
10808 * 262144 cannot be represented in type 'int [8]'
If 8192<=items<16384, we request a writeback of an insane number of pages which is benign (everything will be written). But if items>=16384, the space reservation won't be enough.
--- fs/btrfs/extent-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/extent-tree.c +1 -1
@@ -4620,7 +4620,7 @@ static void shrink_delalloc(struct btrfs_root *root, u64 to_reclaim, u64 orig,/* Calc the number of the pages we need flush for space reservation */ items =calc_reclaim_items_nr (root, to_reclaim); - to_reclaim = items *EXTENT_SIZE_PER_ITEM ; + to_reclaim = (u64 )items *EXTENT_SIZE_PER_ITEM ; trans = (struct btrfs_trans_handle *)current->journal_info; block_rsv = &root->fs_info->delalloc_block_rsv;
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 14/21 Btrfs: fix fspath error deallocation
In reply to David SterbaFrom: Vincent Stehlé <[email protected]>
commit 72928f2476d08c79f132b4f44a17c9a011dd98e3 upstream.
Make sure to deallocate fspath with vfree() in case of error in init_ipath().
fspath is allocated with vmalloc() in init_data_container() since commit 425d17a290c0 ("Btrfs: use larger limit for translation of logical to inode").
--- fs/btrfs/backref.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/backref.c +1 -1
@@ -1995,7 +1995,7 @@ struct inode_fs_paths *init_ipath(s32 total_bytes, struct btrfs_root *fs_root, ifp =kmalloc (sizeof (*ifp),GFP_NOFS );if (!ifp) { -kfree (fspath); +vfree (fspath);return ERR_PTR (-ENOMEM ); }
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 15/21 btrfs: fix memory leak during RAID 5/6 device replacement
In reply to David SterbaFrom: Scott Talbert <[email protected]>
commit 4673272f43ae790ab9ec04e38a7542f82bb8f020 upstream.
A 'struct bio' is allocated in scrub_missing_raid56_pages(), but it was never freed anywhere.
--- fs/btrfs/scrub.c | 2 ++ 1 file changed, 2 insertions(+)
fs/btrfs/scrub.c +2 -0
@@ -2125,6 +2125,8 @@ static void scrub_missing_raid56_end_io(struct bio *bio)if (bio->bi_error) sblock->no_io_error_seen =0 ; +bio_put (bio); +btrfs_queue_work (fs_info->scrub_workers, &sblock->work); }
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 16/21 btrfs: pass the right error code to the btrfs_std_error
In reply to David SterbaFrom: Anand Jain <[email protected]>
commit ad8403df054c9b5dc3175a26c6179571b9cafa4e upstream.
Also drop the newline from the message.
--- fs/btrfs/ioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
fs/btrfs/ioctl.c +2 -2
@@ -4849,8 +4849,8 @@ static long btrfs_ioctl_qgroup_assign(struct file *file, void __user *arg)/* update qgroup status and info */ err =btrfs_run_qgroups (trans, root->fs_info);if (err <0 ) -btrfs_std_error (root->fs_info, ret, -"failed to update qgroup status and info\n" ); +btrfs_std_error (root->fs_info, err, +"failed to update qgroup status and info" ); err =btrfs_end_transaction (trans, root);if (err && !ret) ret = err;
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 17/21 Btrfs: fix for incorrect directory entries after fsync log replay
In reply to David SterbaFrom: Filipe Manana <[email protected]>
commit 657ed1aa4898c8304500e0d13f240d5a67e8be5f upstream.
If we move a directory to a new parent and later log that parent and don't explicitly log the old parent, when we replay the log we can end up with entries for the moved directory in both the old and new parent directories. Besides being ilegal to have directories with multiple hard links in linux, it also resulted in the leaving the inode item with a link count of 1. A similar issue also happens if we move a regular file - after the log tree is replayed the file has a link in both the old and new parent directories, when it should be only at the new directory.
Sample reproducer:
$ mkfs.btrfs -f /dev/sdc $ mount /dev/sdc /mnt $ mkdir /mnt/x $ mkdir /mnt/y $ touch /mnt/x/foo $ mkdir /mnt/y/z $ sync $ ln /mnt/x/foo /mnt/x/bar $ mv /mnt/y/z /mnt/x/z < power fail > $ mount /dev/sdc /mnt $ ls -1Ri /mnt /mnt: 257 x 258 y
/mnt/x:
259 bar
259 foo
260 z
/mnt/x/z:
/mnt/y:
260 z
/mnt/y/z:
$ umount /dev/sdc
$ btrfs check /dev/sdc
Checking filesystem on /dev/sdc
UUID: a67e2c4a-a4b4-4fdc-b015-9d9af1e344be
checking extents
checking free space cache
checking fs roots
root 5 inode 260 errors 2000, link count wrong
unresolved ref dir 257 index 4 namelen 1 name z filetype 2 errors 0
unresolved ref dir 258 index 2 namelen 1 name z filetype 2 errors 0
(...)Attempting to remove the directory becomes impossible:
$ mount /dev/sdc /mnt $ rmdir /mnt/y/z $ ls -lh /mnt/y ls: cannot access /mnt/y/z: No such file or directory total 0 d????????? ? ? ? ? ? z $ rmdir /mnt/x/z rmdir: failed to remove ‘/mnt/x/z’: Stale file handle $ ls -lh /mnt/x ls: cannot access /mnt/x/z: Stale file handle total 0 -rw-r--r-- 2 root root 0 Apr 6 18:06 bar -rw-r--r-- 2 root root 0 Apr 6 18:06 foo d????????? ? ? ? ? ? z
So make sure that on rename we set the last_unlink_trans value for our inode, even if it's a directory, to the value of the current transaction's ID and that if the new parent directory is logged that we fallback to a transaction commit.
A test case for fstests is being submitted as well.
--- fs/btrfs/tree-log.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
fs/btrfs/tree-log.c +8 -5
@@ -5277,11 +5277,16 @@ static int btrfs_log_all_parents(struct btrfs_trans_handle *trans,if (IS_ERR (dir_inode))continue ; +if (ctx) + ctx->log_new_dentries = false; ret =btrfs_log_inode (trans, root, dir_inode,LOG_INODE_ALL ,0 ,LLONG_MAX , ctx);if (!ret &&btrfs_must_commit_transaction (trans, dir_inode)) ret =1 ; +if (!ret && ctx && ctx->log_new_dentries) + ret =log_new_dir_dentries (trans, root, + dir_inode, ctx);iput (dir_inode);if (ret) goto out;
@@ -5651,11 +5656,9 @@ void btrfs_record_unlink_dir(struct btrfs_trans_handle *trans,* into the file. When the file is logged we check it and * don't log the parents if the file is fully on disk. */ -if (S_ISREG (inode->i_mode)) { -mutex_lock (&BTRFS_I (inode)->log_mutex); -BTRFS_I (inode)->last_unlink_trans = trans->transid; -mutex_unlock (&BTRFS_I (inode)->log_mutex); - } +mutex_lock (&BTRFS_I (inode)->log_mutex); +BTRFS_I (inode)->last_unlink_trans = trans->transid; +mutex_unlock (&BTRFS_I (inode)->log_mutex);/* * if this directory was already logged any new
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 18/21 Btrfs: fix empty symlink after creating symlink and fsync parent dir
In reply to David SterbaFrom: Filipe Manana <[email protected]>
commit 3f9749f6e9edcf8ec569fb542efc3be35e06e84a upstream.
If we create a symlink, fsync its parent directory, crash/power fail and mount the filesystem, we end up with an empty symlink, which not only is useless it's also not allowed in linux (the man page symlink(2) is well explicit about that). So we just need to make sure to fully log an inode if it's a symlink, to ensure its inline extent gets logged, ensuring the same behaviour as ext3, ext4, xfs, reiserfs, f2fs, nilfs2, etc.
Example reproducer:
$ mkfs.btrfs -f /dev/sdb $ mount /dev/sdb /mnt $ mkdir /mnt/testdir $ sync $ ln -s /mnt/foo /mnt/testdir/bar $ xfs_io -c fsync /mnt/testdir <power fail> $ mount /dev/sdb /mnt $ readlink /mnt/testdir/bar <empty string>
A test case for fstests follows soon.
--- fs/btrfs/tree-log.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
fs/btrfs/tree-log.c +1 -1
@@ -5157,7 +5157,7 @@ static int log_new_dir_dentries(struct btrfs_trans_handle *trans, } ctx->log_new_dentries = false; -if (type ==BTRFS_FT_DIR ) +if (type ==BTRFS_FT_DIR || type ==BTRFS_FT_SYMLINK ) log_mode =LOG_INODE_ALL ;btrfs_release_path (path); ret = btrfs_log_inode(trans, root, di_inode,
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 20/21 btrfs: scrub: Set bbio to NULL before calling btrfs_map_block
In reply to David SterbaFrom: Zhao Lei <[email protected]>
commit f1fee6534dcfbf468a159789aa202db2bce8c200 upstream.
We usually call btrfs_put_bbio() when btrfs_map_block() failed, btrfs_put_bbio() works right whether bbio is a valid value, or NULL.
But there is a exception, in some case, btrfs_map_block() will return fail without touching *bbio(keeping its original value), and if bbio was not initialized yet, invalid memory accessing will happened.
Above case is in scrub_missing_raid56_pages(), and similar case in scrub_raid56_parity().
--- fs/btrfs/scrub.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
fs/btrfs/scrub.c +2 -1
@@ -2179,7 +2179,7 @@ static void scrub_missing_raid56_pages(struct scrub_block *sblock)struct btrfs_fs_info *fs_info = sctx->dev_root->fs_info;u64 length = sblock->page_count *PAGE_SIZE ;u64 logical = sblock->pagev[0 ]->logical; -struct btrfs_bio *bbio; +struct btrfs_bio *bbio =NULL ;struct bio *bio;struct btrfs_raid_bio *rbio;int ret;
@@ -2980,6 +2980,7 @@ static noinline_for_stack int scrub_raid56_parity(struct scrub_ctx *sctx, extent_len); mapped_length = extent_len; + bbio =NULL ; ret =btrfs_map_block (fs_info,READ , extent_logical, &mapped_length, &bbio,0 );if (!ret) {
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 19/21 Btrfs: fix unexpected return value of fiemap
In reply to David SterbaFrom: Liu Bo <[email protected]>
commit 2d324f59f343967a03eeb2690f0ff178304d0687 upstream.
btrfs's fiemap is supposed to return 0 on success and return < 0 on error. however, ret becomes 1 after looking up the last file extent:
btrfs_lookup_file_extent ->
btrfs_search_slot(..., ins_len=0, cow=0)
and if the offset is beyond EOF, we'll get 'path' pointed to the place of potentail insertion, and ret == 1.
This may confuse applications using ioctl(FIEL_IOC_FIEMAP).
--- fs/btrfs/extent_io.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
fs/btrfs/extent_io.c +5 -1
@@ -4385,8 +4385,12 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,if (ret <0 ) {btrfs_free_path (path);return ret; + }else { +WARN_ON (!ret); +if (ret ==1 ) + ret =0 ; } -WARN_ON (!ret); + path->slots[0 ]--;btrfs_item_key_to_cpu (path->nodes[0 ], &found_key, path->slots[0 ]); found_type = found_key.type;
Signature · 1 line
2.7.1
David Sterba
maintainerPATCH 21/21 btrfs: make state preallocation more speculative in __set_extent_bit
In reply to David Sterbacommit 059f791c6bbaba72dc3c1bd6e2657aacc8552849 upstream.
Similar to __clear_extent_bit, do not fail if the state preallocation fails as we might not need it. One less BUG_ON.
--- fs/btrfs/extent_io.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
fs/btrfs/extent_io.c +7 -1
@@ -875,8 +875,14 @@ __set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, bits |=EXTENT_FIRST_DELALLOC ; again:if (!prealloc &&gfpflags_allow_blocking (mask)) { +/* +* Don't care for allocation failure here because we might end +* up not needing the pre-allocated extent state at all, which +* is the case if we only have in the tree extent states that +* cover our input range and don't cover too any other range. +* If we end up needing a new extent state we allocate it later. +*/ prealloc =alloc_extent_state (mask); -BUG_ON (!prealloc); }spin_lock (&tree->lock);
Signature · 1 line
2.7.1
Greg KH
maintainerQuoted 11 lines · David Sterba
Hi,
please queue the following patches to 4.5 stable. There are fixes for user visible bugs, improved error handling and stability fixes, all picked from current 4.7 changes.
The patches do not apply cleanly on top of 4.5.6 so I'll send them as reply to this mail, now with the stable changelog notices in place.
I have tested the patches on top of 4.5. Some patches may apply to older stable branches but haven't been tested nor reviewed them in that respect.
Thanks for these, all now applied, just in time for the last 4.5-stable kernel to be released :)
greg k-h