Filipe Manana
d4b450cd4b
Btrfs: fix race between transaction commit and empty block group removal
...
Committing a transaction can race with automatic removal of empty block
groups (cleaner kthread), leading to a BUG_ON() in the transaction
commit code while running btrfs_finish_extent_commit(). The following
sequence diagram shows how it can happen:
CPU 1 CPU 2
btrfs_commit_transaction()
fs_info->running_transaction = NULL
btrfs_finish_extent_commit()
find_first_extent_bit()
-> found range for block group X
in fs_info->freed_extents[]
btrfs_delete_unused_bgs()
-> found block group X
Removed block group X's range
from fs_info->freed_extents[]
btrfs_remove_chunk()
btrfs_remove_block_group(bg X)
unpin_extent_range(bg X range)
btrfs_lookup_block_group(bg X)
-> returns NULL
-> BUG_ON()
The trace that results from the BUG_ON() is:
[48665.187808] ------------[ cut here ]------------
[48665.188032] kernel BUG at fs/btrfs/extent-tree.c:5675!
[48665.188032] invalid opcode: 0000 [#1 ] SMP DEBUG_PAGEALLOC
[48665.188032] Modules linked in: dm_flakey dm_mod crc32c_generic btrfs xor raid6_pq nfsd auth_rpcgss oid_registry nfs_acl nfs lockd grace fscache sunrpc loop parport_pc evdev microcode
[48665.197388] CPU: 2 PID: 31211 Comm: kworker/u32:16 Tainted: G W 3.19.0-rc5-btrfs-next-4+ #1
[48665.197388] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.7.5-0-ge51488c-20140602_164612-nilsson.home.kraxel.org 04/01/2014
[48665.197388] Workqueue: events_unbound btrfs_async_reclaim_metadata_space [btrfs]
[48665.197388] task: ffff880222011810 ti: ffff8801b56a4000 task.ti: ffff8801b56a4000
[48665.197388] RIP: 0010:[<ffffffffa0350d05>] [<ffffffffa0350d05>] unpin_extent_range+0x6a/0x1ba [btrfs]
[48665.197388] RSP: 0018:ffff8801b56a7b88 EFLAGS: 00010246
[48665.197388] RAX: 0000000000000000 RBX: ffff8802143a6000 RCX: ffff8802220120c8
[48665.197388] RDX: 0000000000000001 RSI: 0000000000000001 RDI: ffff8800a3c140b0
[48665.197388] RBP: ffff8801b56a7bd8 R08: 0000000000000003 R09: 0000000000000000
[48665.197388] R10: 0000000000000000 R11: 000000000000bbac R12: 0000000012e8e000
[48665.197388] R13: ffff8800a3c14000 R14: 0000000000000000 R15: 0000000000000000
[48665.197388] FS: 0000000000000000(0000) GS:ffff88023ec40000(0000) knlGS:0000000000000000
[48665.197388] CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b
[48665.197388] CR2: 00007f065e42f270 CR3: 0000000206f70000 CR4: 00000000000006e0
[48665.197388] Stack:
[48665.197388] ffff8801b56a7bd8 0000000012ea0000 01ff8800a3c14138 0000000012e9ffff
[48665.197388] ffff880141df3dd8 ffff8802143a6000 ffff8800a3c14138 ffff880141df3df0
[48665.197388] ffff880141df3dd8 0000000000000000 ffff8801b56a7c08 ffffffffa0354227
[48665.197388] Call Trace:
[48665.197388] [<ffffffffa0354227>] btrfs_finish_extent_commit+0xb0/0xd9 [btrfs]
[48665.197388] [<ffffffffa0366b4b>] btrfs_commit_transaction+0x791/0x92c [btrfs]
[48665.197388] [<ffffffffa0352432>] flush_space+0x43d/0x452 [btrfs]
[48665.197388] [<ffffffff814295c3>] ? _raw_spin_unlock+0x28/0x33
[48665.197388] [<ffffffffa035255f>] btrfs_async_reclaim_metadata_space+0x118/0x164 [btrfs]
[48665.197388] [<ffffffff81059917>] ? process_one_work+0x14b/0x3ab
[48665.197388] [<ffffffff810599ac>] process_one_work+0x1e0/0x3ab
[48665.197388] [<ffffffff81079fa9>] ? trace_hardirqs_off+0xd/0xf
[48665.197388] [<ffffffff8105a55b>] worker_thread+0x210/0x2d0
[48665.197388] [<ffffffff8105a34b>] ? rescuer_thread+0x2c3/0x2c3
[48665.197388] [<ffffffff8105e5c0>] kthread+0xef/0xf7
[48665.197388] [<ffffffff81429682>] ? _raw_spin_unlock_irq+0x2d/0x39
[48665.197388] [<ffffffff8105e4d1>] ? __kthread_parkme+0xad/0xad
[48665.197388] [<ffffffff81429dec>] ret_from_fork+0x7c/0xb0
[48665.197388] [<ffffffff8105e4d1>] ? __kthread_parkme+0xad/0xad
[48665.197388] Code: 85 f6 74 14 49 8b 06 49 03 46 09 49 39 c4 72 1d 4c 89 f7 e8 83 ec ff ff 4c 89 e6 4c 89 ef e8 1e f1 ff ff 48 85 c0 49 89 c6 75 02 <0f> 0b 49 8b 1e 49 03 5e 09 48 8b
[48665.197388] RIP [<ffffffffa0350d05>] unpin_extent_range+0x6a/0x1ba [btrfs]
[48665.197388] RSP <ffff8801b56a7b88>
[48665.272246] ---[ end trace b9c6ab9957521376 ]---
Fix this by ensuring that unpining the block group's range in
btrfs_finish_extent_commit() is done in a synchronized fashion
with removing the block group's range from freed_extents[]
in btrfs_delete_unused_bgs()
This race got introduced with the change:
Btrfs: remove empty block groups automatically
commit 47ab2a6c689913db23ccae38349714edf8365e0a
Signed-off-by: Filipe Manana <fdmanana@suse.com>
Signed-off-by: Chris Mason <clm@fb.com>
2015-02-02 19:24:48 -08:00
..
2014-11-19 13:01:20 -05:00
2014-08-08 15:57:24 -07:00
2014-12-13 12:42:52 -08:00
2014-12-11 14:27:06 -08:00
2014-11-19 13:01:20 -05:00
2014-12-13 12:42:51 -08:00
2014-08-08 15:57:24 -07:00
2015-02-02 19:24:48 -08:00
2014-11-19 13:01:20 -05:00
2015-01-08 20:36:56 +03:00
2014-12-22 14:16:21 -06:00
2014-12-11 16:28:12 -05:00
2014-11-19 13:01:20 -05:00
2014-08-08 15:57:25 -07:00
2014-12-14 16:10:09 -08:00
2014-12-10 16:10:49 -08:00
2014-12-19 18:15:12 -08:00
2014-12-10 16:10:49 -08:00
2014-08-08 15:57:18 -07:00
2014-10-19 20:22:32 +03:00
2014-11-03 15:20:29 -05:00
2014-11-10 10:06:10 +01:00
2014-11-10 10:06:10 +01:00
2015-01-06 14:05:40 -08:00
2014-12-08 14:19:09 -08:00
2014-12-13 12:42:51 -08:00
2014-10-13 17:52:21 +01:00
2015-01-06 10:45:35 +01:00
2014-12-10 16:10:49 -08:00
2014-12-10 17:41:16 -08:00
2014-12-18 19:08:10 -08:00
2014-08-07 14:40:09 -04:00
2014-08-08 15:57:22 -07:00
2014-10-31 17:48:54 -04:00
2014-12-13 12:42:45 -08:00
2014-12-19 11:29:24 +01:00
2014-11-18 10:15:29 +01:00
2014-12-12 09:28:03 -08:00
2014-11-28 18:23:44 -08:00
2014-12-10 16:10:49 -08:00
2015-01-09 15:51:08 -08:00
2015-01-05 19:40:53 -08:00
2014-08-06 18:01:12 -07:00
2014-08-08 15:57:20 -07:00
2014-12-10 18:34:42 -08:00
2015-01-05 19:40:54 -08:00
2014-09-17 16:33:11 -04:00
2015-01-07 13:38:21 -05:00
2014-12-10 17:41:16 -08:00
2015-01-09 11:18:12 +01:00
2014-11-19 13:01:20 -05:00
2015-01-08 15:10:51 -08:00
2014-10-14 02:18:22 +02:00
2014-12-08 20:39:29 -05:00
2014-12-19 13:26:08 -08:00
2014-12-14 16:10:09 -08:00
2014-08-08 15:57:26 -07:00
2014-11-10 10:06:18 +01:00
2014-08-08 15:57:18 -07:00
2014-12-16 15:46:01 -08:00
2014-08-08 15:57:25 -07:00
2014-11-27 18:48:44 +00:00
2014-11-07 10:54:38 -08:00
2014-11-07 12:32:22 +02:00
2014-12-21 22:42:37 +01:00
2014-10-14 02:18:20 +02:00
2014-12-12 09:48:17 -08:00
2014-12-13 17:50:20 -05:00
2014-08-07 14:40:09 -04:00
2014-11-19 13:01:20 -05:00
2014-10-09 02:39:00 -04:00
2014-12-11 17:56:37 -08:00
2014-12-13 12:42:51 -08:00
2014-12-17 08:27:14 -05:00
2014-12-13 12:42:51 -08:00
2014-11-17 10:35:17 +00:00
2014-10-21 13:55:11 -06:00
2014-12-10 17:41:04 -08:00
2014-07-11 13:53:04 +03:00
2014-10-31 17:48:54 -04:00
2014-10-14 02:18:21 +02:00
2014-12-08 20:39:29 -05:00
2014-09-26 21:16:51 -04:00
2014-12-13 12:42:48 -08:00
2014-11-05 14:13:23 -05:00
2014-11-05 14:13:23 -05:00
2014-12-13 12:42:51 -08:00
2015-01-08 15:10:52 -08:00
2014-10-13 11:28:42 +02:00
2014-12-10 17:41:10 -08:00
2014-08-07 14:40:09 -04:00
2014-11-04 10:42:23 -07:00
2014-12-16 15:53:03 -08:00
2014-12-10 21:30:20 -05:00
2014-12-16 15:25:31 -08:00
2014-10-24 00:14:38 +02:00
2014-11-24 07:45:02 +01:00
2014-11-03 15:20:29 -05:00
2015-01-13 07:00:55 -05:00
2014-12-10 21:31:59 -05:00
2014-06-25 22:08:29 -04:00
2014-12-04 14:31:00 -05:00
2014-10-09 22:25:53 -04:00
2014-12-16 15:53:03 -08:00
2014-12-18 11:22:02 -08:00
2014-12-10 21:30:20 -05:00
2014-12-16 15:25:31 -08:00
2014-12-02 10:46:50 -06:00
2014-12-17 08:27:15 -05:00
2014-12-14 20:36:37 -08:00
2014-10-31 17:48:54 -04:00
2014-12-13 12:42:49 -08:00
2014-11-05 14:13:23 -05:00
2014-10-24 00:14:35 +02:00
2014-08-26 09:35:56 +02:00
2014-11-10 10:06:18 +01:00
2014-11-19 13:01:25 -05:00
2014-11-05 14:13:23 -05:00
2014-11-19 13:01:26 -05:00