Skip to content

Commit e6a67e7

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. Signed-off-by: Josef Bacik <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 69edf17 commit e6a67e7

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

fs/btrfs/space-info.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -870,6 +870,7 @@ static bool maybe_fail_all_tickets(struct btrfs_fs_info *fs_info,
870870
{
871871
struct reserve_ticket *ticket;
872872
u64 tickets_id = space_info->tickets_id;
873+
const bool aborted = btrfs_has_fs_error(fs_info);
873874

874875
trace_btrfs_fail_all_tickets(fs_info, space_info);
875876

@@ -883,7 +884,7 @@ static bool maybe_fail_all_tickets(struct btrfs_fs_info *fs_info,
883884
ticket = list_first_entry(&space_info->tickets,
884885
struct reserve_ticket, list);
885886

886-
if (ticket->steal &&
887+
if (!aborted && ticket->steal &&
887888
steal_from_global_rsv(fs_info, space_info, ticket))
888889
return true;
889890

@@ -892,7 +893,10 @@ static bool maybe_fail_all_tickets(struct btrfs_fs_info *fs_info,
892893
ticket->bytes);
893894

894895
remove_ticket(space_info, ticket);
895-
ticket->error = -ENOSPC;
896+
if (aborted)
897+
ticket->error = -EIO;
898+
else
899+
ticket->error = -ENOSPC;
896900
wake_up(&ticket->wait);
897901

898902
/*
@@ -901,7 +905,8 @@ static bool maybe_fail_all_tickets(struct btrfs_fs_info *fs_info,
901905
* here to see if we can make progress with the next ticket in
902906
* the list.
903907
*/
904-
btrfs_try_granting_tickets(fs_info, space_info);
908+
if (!aborted)
909+
btrfs_try_granting_tickets(fs_info, space_info);
905910
}
906911
return (tickets_id != space_info->tickets_id);
907912
}
@@ -1157,6 +1162,10 @@ static void btrfs_async_reclaim_data_space(struct work_struct *work)
11571162
spin_unlock(&space_info->lock);
11581163
return;
11591164
}
1165+
1166+
/* Something happened, fail everything and bail. */
1167+
if (btrfs_has_fs_error(fs_info))
1168+
goto aborted_fs;
11601169
last_tickets_id = space_info->tickets_id;
11611170
spin_unlock(&space_info->lock);
11621171
}
@@ -1187,9 +1196,19 @@ static void btrfs_async_reclaim_data_space(struct work_struct *work)
11871196
} else {
11881197
flush_state = 0;
11891198
}
1199+
1200+
/* Something happened, fail everything and bail. */
1201+
if (btrfs_has_fs_error(fs_info))
1202+
goto aborted_fs;
1203+
11901204
}
11911205
spin_unlock(&space_info->lock);
11921206
}
1207+
return;
1208+
aborted_fs:
1209+
maybe_fail_all_tickets(fs_info, space_info);
1210+
space_info->flush = 0;
1211+
spin_unlock(&space_info->lock);
11931212
}
11941213

11951214
void btrfs_init_async_reclaim_work(struct btrfs_fs_info *fs_info)

0 commit comments

Comments
 (0)