Commit a09f23c3 authored by Anand Jain's avatar Anand Jain Committed by David Sterba

btrfs: rename and switch to bool btrfs_chunk_readonly

btrfs_chunk_readonly() checks if the given chunk is writeable. It
returns 1 for readonly, and 0 for writeable. So the return argument type
bool shall suffice instead of the current type int.

Also, rename btrfs_chunk_readonly() to btrfs_chunk_writeable() as we
check if the bg is writeable, and helps to keep the logic at the parent
function simpler to understand.
Signed-off-by: default avatarAnand Jain <anand.jain@oracle.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 44bee215
...@@ -2062,15 +2062,18 @@ static int read_one_block_group(struct btrfs_fs_info *info, ...@@ -2062,15 +2062,18 @@ static int read_one_block_group(struct btrfs_fs_info *info,
link_block_group(cache); link_block_group(cache);
set_avail_alloc_bits(info, cache->flags); set_avail_alloc_bits(info, cache->flags);
if (btrfs_chunk_readonly(info, cache->start)) { if (btrfs_chunk_writeable(info, cache->start)) {
if (cache->used == 0) {
ASSERT(list_empty(&cache->bg_list));
if (btrfs_test_opt(info, DISCARD_ASYNC))
btrfs_discard_queue_work(&info->discard_ctl, cache);
else
btrfs_mark_bg_unused(cache);
}
} else {
inc_block_group_ro(cache, 1); inc_block_group_ro(cache, 1);
} else if (cache->used == 0) {
ASSERT(list_empty(&cache->bg_list));
if (btrfs_test_opt(info, DISCARD_ASYNC))
btrfs_discard_queue_work(&info->discard_ctl, cache);
else
btrfs_mark_bg_unused(cache);
} }
return 0; return 0;
error: error:
btrfs_put_block_group(cache); btrfs_put_block_group(cache);
......
...@@ -5597,17 +5597,17 @@ static inline int btrfs_chunk_max_errors(struct map_lookup *map) ...@@ -5597,17 +5597,17 @@ static inline int btrfs_chunk_max_errors(struct map_lookup *map)
return btrfs_raid_array[index].tolerated_failures; return btrfs_raid_array[index].tolerated_failures;
} }
int btrfs_chunk_readonly(struct btrfs_fs_info *fs_info, u64 chunk_offset) bool btrfs_chunk_writeable(struct btrfs_fs_info *fs_info, u64 chunk_offset)
{ {
struct extent_map *em; struct extent_map *em;
struct map_lookup *map; struct map_lookup *map;
int readonly = 0;
int miss_ndevs = 0; int miss_ndevs = 0;
int i; int i;
bool ret = true;
em = btrfs_get_chunk_map(fs_info, chunk_offset, 1); em = btrfs_get_chunk_map(fs_info, chunk_offset, 1);
if (IS_ERR(em)) if (IS_ERR(em))
return 1; return false;
map = em->map_lookup; map = em->map_lookup;
for (i = 0; i < map->num_stripes; i++) { for (i = 0; i < map->num_stripes; i++) {
...@@ -5618,21 +5618,20 @@ int btrfs_chunk_readonly(struct btrfs_fs_info *fs_info, u64 chunk_offset) ...@@ -5618,21 +5618,20 @@ int btrfs_chunk_readonly(struct btrfs_fs_info *fs_info, u64 chunk_offset)
} }
if (!test_bit(BTRFS_DEV_STATE_WRITEABLE, if (!test_bit(BTRFS_DEV_STATE_WRITEABLE,
&map->stripes[i].dev->dev_state)) { &map->stripes[i].dev->dev_state)) {
readonly = 1; ret = false;
goto end; goto end;
} }
} }
/* /*
* If the number of missing devices is larger than max errors, * If the number of missing devices is larger than max errors, we can
* we can not write the data into that chunk successfully, so * not write the data into that chunk successfully.
* set it readonly.
*/ */
if (miss_ndevs > btrfs_chunk_max_errors(map)) if (miss_ndevs > btrfs_chunk_max_errors(map))
readonly = 1; ret = false;
end: end:
free_extent_map(em); free_extent_map(em);
return readonly; return ret;
} }
void btrfs_mapping_tree_free(struct extent_map_tree *tree) void btrfs_mapping_tree_free(struct extent_map_tree *tree)
......
...@@ -493,7 +493,7 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset); ...@@ -493,7 +493,7 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset);
int btrfs_cancel_balance(struct btrfs_fs_info *fs_info); int btrfs_cancel_balance(struct btrfs_fs_info *fs_info);
int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info); int btrfs_create_uuid_tree(struct btrfs_fs_info *fs_info);
int btrfs_uuid_scan_kthread(void *data); int btrfs_uuid_scan_kthread(void *data);
int btrfs_chunk_readonly(struct btrfs_fs_info *fs_info, u64 chunk_offset); bool btrfs_chunk_writeable(struct btrfs_fs_info *fs_info, u64 chunk_offset);
int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes, int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
u64 *start, u64 *max_avail); u64 *start, u64 *max_avail);
void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index); void btrfs_dev_stat_inc_and_print(struct btrfs_device *dev, int index);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment