Skip to content

Commit

Permalink
btrfs: unify error handling for ticket flushing
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Josef Bacik authored and David Sterba committed Sep 9, 2019
1 parent 844245b commit 374bf9c
Showing 1 changed file with 11 additions and 21 deletions.
32 changes: 11 additions & 21 deletions fs/btrfs/space-info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
struct btrfs_space_info *space_info,
struct reserve_ticket *ticket)
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);
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -1010,16 +998,18 @@ 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);
wait_reserve_ticket(fs_info, space_info, &ticket);
else
priority_reclaim_metadata_space(fs_info, space_info, &ticket);

ret = 0;
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);
ret = -ENOSPC;
if (!ret)
ret = -ENOSPC;
}
spin_unlock(&space_info->lock);

Expand Down

0 comments on commit 374bf9c

Please sign in to comment.