mirror of
https://github.com/torvalds/linux.git
synced 2024-11-24 05:02:12 +00:00
btrfs: unify error handling for ticket flushing
Currently we handle the cleanup of errored out tickets in both the priority flush path and the normal flushing path. This is the same code in both places, so just refactor so we don't duplicate the cleanup work. Signed-off-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
844245b454
commit
374bf9c5cd
@ -878,20 +878,19 @@ static void priority_reclaim_metadata_space(struct btrfs_fs_info *fs_info,
|
||||
} while (flush_state < ARRAY_SIZE(priority_flush_states));
|
||||
}
|
||||
|
||||
static int wait_reserve_ticket(struct btrfs_fs_info *fs_info,
|
||||
static void wait_reserve_ticket(struct btrfs_fs_info *fs_info,
|
||||
struct btrfs_space_info *space_info,
|
||||
struct reserve_ticket *ticket)
|
||||
|
||||
{
|
||||
DEFINE_WAIT(wait);
|
||||
u64 reclaim_bytes = 0;
|
||||
int ret = 0;
|
||||
|
||||
spin_lock(&space_info->lock);
|
||||
while (ticket->bytes > 0 && ticket->error == 0) {
|
||||
ret = prepare_to_wait_event(&ticket->wait, &wait, TASK_KILLABLE);
|
||||
if (ret) {
|
||||
ret = -EINTR;
|
||||
ticket->error = -EINTR;
|
||||
break;
|
||||
}
|
||||
spin_unlock(&space_info->lock);
|
||||
@ -901,18 +900,7 @@ static int wait_reserve_ticket(struct btrfs_fs_info *fs_info,
|
||||
finish_wait(&ticket->wait, &wait);
|
||||
spin_lock(&space_info->lock);
|
||||
}
|
||||
if (!ret)
|
||||
ret = ticket->error;
|
||||
if (!list_empty(&ticket->list))
|
||||
list_del_init(&ticket->list);
|
||||
if (ticket->bytes && ticket->bytes < ticket->orig_bytes)
|
||||
reclaim_bytes = ticket->orig_bytes - ticket->bytes;
|
||||
spin_unlock(&space_info->lock);
|
||||
|
||||
if (reclaim_bytes)
|
||||
btrfs_space_info_add_old_bytes(fs_info, space_info,
|
||||
reclaim_bytes);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1010,15 +998,17 @@ static int __reserve_metadata_bytes(struct btrfs_fs_info *fs_info,
|
||||
return ret;
|
||||
|
||||
if (flush == BTRFS_RESERVE_FLUSH_ALL)
|
||||
return wait_reserve_ticket(fs_info, space_info, &ticket);
|
||||
|
||||
ret = 0;
|
||||
wait_reserve_ticket(fs_info, space_info, &ticket);
|
||||
else
|
||||
priority_reclaim_metadata_space(fs_info, space_info, &ticket);
|
||||
|
||||
spin_lock(&space_info->lock);
|
||||
if (ticket.bytes) {
|
||||
ret = ticket.error;
|
||||
if (ticket.bytes || ticket.error) {
|
||||
if (ticket.bytes < orig_bytes)
|
||||
reclaim_bytes = orig_bytes - ticket.bytes;
|
||||
list_del_init(&ticket.list);
|
||||
if (!ret)
|
||||
ret = -ENOSPC;
|
||||
}
|
||||
spin_unlock(&space_info->lock);
|
||||
|
Loading…
Reference in New Issue
Block a user