Skip to content

Commit b668d34

Browse files
josefbacikkdave
authored andcommitted
btrfs: do not infinite loop in data reclaim if we aborted
Error injection stressing uncovered a busy loop in our data reclaim loop. There are two cases here, one where we loop creating block groups until space_info->full is set, or in the main loop we will skip erroring out any tickets if space_info->full == 0. Unfortunately if we aborted the transaction then we will never allocate chunks or reclaim any space and thus never get ->full, and you'll see stack traces like this: watchdog: BUG: soft lockup - CPU#0 stuck for 26s! [kworker/u4:4:139] CPU: 0 PID: 139 Comm: kworker/u4:4 Tainted: G W 5.13.0-rc1+ torvalds#328 Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.13.0-2.fc32 04/01/2014 Workqueue: events_unbound btrfs_async_reclaim_data_space RIP: 0010:btrfs_join_transaction+0x12/0x20 RSP: 0018:ffffb2b780b77de0 EFLAGS: 00000246 RAX: ffffb2b781863d58 RBX: 0000000000000000 RCX: 0000000000000000 RDX: 0000000000000801 RSI: ffff987952b57400 RDI: ffff987940aa3000 RBP: ffff987954d55000 R08: 0000000000000001 R09: ffff98795539e8f0 R10: 000000000000000f R11: 000000000000000f R12: ffffffffffffffff R13: ffff987952b574c8 R14: ffff987952b57400 R15: 0000000000000008 FS: 0000000000000000(0000) GS:ffff9879bbc00000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 00007f0703da4000 CR3: 0000000113398004 CR4: 0000000000370ef0 Call Trace: flush_space+0x4a8/0x660 btrfs_async_reclaim_data_space+0x55/0x130 process_one_work+0x1e9/0x380 worker_thread+0x53/0x3e0 ? process_one_work+0x380/0x380 kthread+0x118/0x140 ? __kthread_bind_mask+0x60/0x60 ret_from_fork+0x1f/0x30 Fix this by checking to see if we have a btrfs fs error in either of the reclaim loops, and if so fail the tickets and bail. In addition to this, fix maybe_fail_all_tickets() to not try to grant tickets if we've aborted, simply fail everything. Reviewed-by: Nikolay Borisov <[email protected]> Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent d5e55b3 commit b668d34

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

fs/btrfs/space-info.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,7 @@ static bool maybe_fail_all_tickets(struct btrfs_fs_info *fs_info,
885885
{
886886
struct reserve_ticket *ticket;
887887
u64 tickets_id = space_info->tickets_id;
888+
const bool aborted = BTRFS_FS_ERROR(fs_info);
888889

889890
trace_btrfs_fail_all_tickets(fs_info, space_info);
890891

@@ -898,16 +899,19 @@ static bool maybe_fail_all_tickets(struct btrfs_fs_info *fs_info,
898899
ticket = list_first_entry(&space_info->tickets,
899900
struct reserve_ticket, list);
900901

901-
if (ticket->steal &&
902+
if (!aborted && ticket->steal &&
902903
steal_from_global_rsv(fs_info, space_info, ticket))
903904
return true;
904905

905-
if (btrfs_test_opt(fs_info, ENOSPC_DEBUG))
906+
if (!aborted && btrfs_test_opt(fs_info, ENOSPC_DEBUG))
906907
btrfs_info(fs_info, "failing ticket with %llu bytes",
907908
ticket->bytes);
908909

909910
remove_ticket(space_info, ticket);
910-
ticket->error = -ENOSPC;
911+
if (aborted)
912+
ticket->error = -EIO;
913+
else
914+
ticket->error = -ENOSPC;
911915
wake_up(&ticket->wait);
912916

913917
/*
@@ -916,7 +920,8 @@ static bool maybe_fail_all_tickets(struct btrfs_fs_info *fs_info,
916920
* here to see if we can make progress with the next ticket in
917921
* the list.
918922
*/
919-
btrfs_try_granting_tickets(fs_info, space_info);
923+
if (!aborted)
924+
btrfs_try_granting_tickets(fs_info, space_info);
920925
}
921926
return (tickets_id != space_info->tickets_id);
922927
}
@@ -1172,6 +1177,10 @@ static void btrfs_async_reclaim_data_space(struct work_struct *work)
11721177
spin_unlock(&space_info->lock);
11731178
return;
11741179
}
1180+
1181+
/* Something happened, fail everything and bail. */
1182+
if (BTRFS_FS_ERROR(fs_info))
1183+
goto aborted_fs;
11751184
last_tickets_id = space_info->tickets_id;
11761185
spin_unlock(&space_info->lock);
11771186
}
@@ -1202,9 +1211,20 @@ static void btrfs_async_reclaim_data_space(struct work_struct *work)
12021211
} else {
12031212
flush_state = 0;
12041213
}
1214+
1215+
/* Something happened, fail everything and bail. */
1216+
if (BTRFS_FS_ERROR(fs_info))
1217+
goto aborted_fs;
1218+
12051219
}
12061220
spin_unlock(&space_info->lock);
12071221
}
1222+
return;
1223+
1224+
aborted_fs:
1225+
maybe_fail_all_tickets(fs_info, space_info);
1226+
space_info->flush = 0;
1227+
spin_unlock(&space_info->lock);
12081228
}
12091229

12101230
void btrfs_init_async_reclaim_work(struct btrfs_fs_info *fs_info)

0 commit comments

Comments
 (0)