static int read_one_block_group(struct btrfs_fs_info *info,
struct btrfs_block_group_item_v2 *bgi,
const struct btrfs_key *key,
- int need_clear)
+ bool need_clear)
{
struct btrfs_block_group *cache;
const bool mixed = btrfs_fs_incompat(info, MIXED_GROUPS);
struct btrfs_block_group *cache;
struct btrfs_space_info *space_info;
struct btrfs_key key;
- int need_clear = 0;
+ bool need_clear = false;
u64 cache_gen;
/*
cache_gen = btrfs_super_cache_generation(info->super_copy);
if (btrfs_test_opt(info, SPACE_CACHE) &&
btrfs_super_generation(info->super_copy) != cache_gen)
- need_clear = 1;
+ need_clear = true;
if (btrfs_test_opt(info, CLEAR_CACHE))
- need_clear = 1;
+ need_clear = true;
while (1) {
struct btrfs_block_group_item_v2 bgi;
struct extent_buffer *cow;
int level, ret;
int last_ref = 0;
- int unlock_orig = 0;
+ const bool unlock_orig = (*cow_ret == buf);
u64 parent_start = 0;
u64 reloc_src_root = 0;
- if (*cow_ret == buf)
- unlock_orig = 1;
-
btrfs_assert_tree_write_locked(buf);
WARN_ON(test_bit(BTRFS_ROOT_SHAREABLE, &root->state) &&
}
while (b) {
- int dec = 0;
+ bool dec = false;
int ret2;
level = btrfs_header_level(b);
prev_cmp = ret;
if (ret && slot > 0) {
- dec = 1;
+ dec = true;
slot--;
}
p->slots[level] = slot;
p->locks[level] = BTRFS_READ_LOCK;
while (b) {
- int dec = 0;
+ bool dec = false;
int ret2;
level = btrfs_header_level(b);
}
if (ret && slot > 0) {
- dec = 1;
+ dec = true;
slot--;
}
p->slots[level] = slot;
int wret;
int split;
int num_doubles = 0;
- int tried_avoid_double = 0;
+ bool tried_avoid_double = false;
l = path->nodes[0];
slot = path->slots[0];
push_for_double:
push_for_double_split(trans, root, path, data_size);
- tried_avoid_double = 1;
+ tried_avoid_double = true;
if (btrfs_leaf_free_space(path->nodes[0]) >= data_size)
return 0;
goto again;
const struct btrfs_tree_parent_check *check)
{
struct btrfs_fs_info *fs_info = eb->fs_info;
- int failed = 0;
+ bool failed = false;
int ret;
int num_copies = 0;
int mirror_num = 0;
break;
if (!failed_mirror) {
- failed = 1;
+ failed = true;
failed_mirror = eb->read_mirror;
}
u64 cur_start = *start;
u64 total_bytes = 0;
u64 last = 0;
- int found = 0;
+ bool found = false;
if (WARN_ON(search_end < cur_start))
return 0;
break;
if (!found) {
*start = max(cur_start, state->start);
- found = 1;
+ found = true;
}
last = state->end;
} else if (contig && found) {
struct extent_buffer *leaf;
u32 item_size;
int ret;
- int metadata = 1;
+ bool metadata = true;
if (TRANS_ABORTED(trans))
return 0;
if (!btrfs_fs_incompat(fs_info, SKINNY_METADATA))
- metadata = 0;
+ metadata = false;
path = btrfs_alloc_path();
if (!path)
}
if (ret > 0) {
btrfs_release_path(path);
- metadata = 0;
+ metadata = false;
key.objectid = head->bytenr;
key.type = BTRFS_EXTENT_ITEM_KEY;
int ret;
int is_data;
int extent_slot = 0;
- int found_extent = 0;
+ bool found_extent = false;
int num_to_del = 1;
int refs_to_drop = node->ref_mod;
u32 item_size;
break;
if (key.type == BTRFS_EXTENT_ITEM_KEY &&
key.offset == num_bytes) {
- found_extent = 1;
+ found_extent = true;
break;
}
if (key.type == BTRFS_METADATA_ITEM_KEY &&
key.offset == owner_objectid) {
- found_extent = 1;
+ found_extent = true;
break;
}
bool found;
struct extent_state *cached_state = NULL;
int ret;
- int loops = 0;
+ bool loops = false;
/* Caller should pass a valid @end to indicate the search range end */
ASSERT(orig_end > orig_start);
cached_state = NULL;
if (!loops) {
max_bytes = fs_info->sectorsize;
- loops = 1;
+ loops = true;
goto again;
} else {
return false;
struct btrfs_eb_write_context ctx = { .wbc = wbc };
struct btrfs_fs_info *fs_info = inode_to_fs_info(mapping->host);
int ret = 0;
- int done = 0;
+ bool done = false;
int nr_to_write_done = 0;
struct eb_batch batch;
unsigned int nr_ebs;
unsigned long index;
unsigned long end;
- int scanned = 0;
+ bool scanned = false;
xa_mark_t tag;
eb_batch_init(&batch);
index = (wbc->range_start >> fs_info->nodesize_bits);
end = (wbc->range_end >> fs_info->nodesize_bits);
- scanned = 1;
+ scanned = true;
}
if (wbc->sync_mode == WB_SYNC_ALL)
tag = PAGECACHE_TAG_TOWRITE;
ret = 0;
if (ret) {
- done = 1;
+ done = true;
break;
}
continue;
* We hit the last page and there is more work to be done: wrap
* back to the start of the file
*/
- scanned = 1;
+ scanned = true;
index = 0;
goto retry;
}
struct writeback_control *wbc = bio_ctrl->wbc;
struct inode *inode = mapping->host;
int ret = 0;
- int done = 0;
+ bool done = false;
int nr_to_write_done = 0;
struct folio_batch fbatch;
unsigned int nr_folios;
pgoff_t index;
pgoff_t end; /* Inclusive */
pgoff_t done_index;
- int range_whole = 0;
- int scanned = 0;
+ bool range_whole = false;
+ bool scanned = false;
xa_mark_t tag;
/*
index = wbc->range_start >> PAGE_SHIFT;
end = wbc->range_end >> PAGE_SHIFT;
if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
- range_whole = 1;
- scanned = 1;
+ range_whole = true;
+ scanned = true;
}
/*
ret = extent_writepage(folio, bio_ctrl);
if (ret < 0) {
- done = 1;
+ done = true;
break;
}
* We hit the last page and there is more work to be done: wrap
* back to the start of the file
*/
- scanned = 1;
+ scanned = true;
index = 0;
/*
struct btrfs_folio_state *prealloc = NULL;
u64 lockdep_owner = owner_root;
bool page_contig = true;
- int uptodate = 1;
+ bool uptodate = true;
int ret;
if (check_eb_alignment(fs_info, start))
page_contig = false;
if (!btrfs_meta_folio_test_uptodate(folio, eb))
- uptodate = 0;
+ uptodate = false;
/*
* We can't unlock the pages just yet since the extent buffer
int ret;
int modify_tree = -1;
int update_refs;
- int found = 0;
+ bool found = false;
struct btrfs_path *path = args->path;
args->bytes_found = 0;
goto next_slot;
}
- found = 1;
+ found = true;
search_start = max(key.offset, args->start);
if (recow || !modify_tree) {
modify_tree = -1;
int entries = 0;
int bitmaps = 0;
int ret;
- int must_iput = 0;
+ bool must_iput = false;
int i_size;
if (!i_size_read(inode))
up_write(&block_group->data_rwsem);
BTRFS_I(inode)->generation = 0;
ret = 0;
- must_iput = 1;
+ must_iput = true;
goto out;
}
spin_unlock(&block_group->lock);
{
struct btrfs_free_space *bitmap_info;
struct btrfs_block_group *block_group = ctl->block_group;
- int added = 0;
+ bool added = false;
u64 bytes, offset, bytes_added;
enum btrfs_trim_state trim_state;
int ret;
bitmap_info = tree_search_offset(ctl, offset_to_bitmap(ctl, offset),
1, 0);
if (!bitmap_info) {
- ASSERT(added == 0);
+ ASSERT(!added);
goto new_bitmap;
}
trim_state);
bytes -= bytes_added;
offset += bytes_added;
- added = 0;
+ added = false;
if (!bytes) {
ret = 1;
new_bitmap:
if (info && info->bitmap) {
add_new_bitmap(ctl, info, offset);
- added = 1;
+ added = true;
info = NULL;
goto again;
} else {
u64 bitmap_range, i;
u32 bitmap_size, flags, expected_extent_count;
u32 extent_count = 0;
- int done = 0, nr;
+ bool done = false;
+ int nr;
int ret;
bitmap_size = free_space_bitmap_size(fs_info, block_group->length);
if (found_key.type == BTRFS_FREE_SPACE_INFO_KEY) {
ASSERT(found_key.objectid == block_group->start);
ASSERT(found_key.offset == block_group->length);
- done = 1;
+ done = true;
break;
} else if (found_key.type == BTRFS_FREE_SPACE_EXTENT_KEY) {
u64 first, last;
u32 bitmap_size, flags, expected_extent_count;
unsigned long nrbits, start_bit, end_bit;
u32 extent_count = 0;
- int done = 0, nr;
+ bool done = false;
+ int nr;
int ret;
bitmap_size = free_space_bitmap_size(fs_info, block_group->length);
if (found_key.type == BTRFS_FREE_SPACE_INFO_KEY) {
ASSERT(found_key.objectid == block_group->start);
ASSERT(found_key.offset == block_group->length);
- done = 1;
+ done = true;
break;
} else if (found_key.type == BTRFS_FREE_SPACE_BITMAP_KEY) {
unsigned long ptr;
struct btrfs_key key, found_key;
struct extent_buffer *leaf;
u64 start, end;
- int done = 0, nr;
+ bool done = false;
+ int nr;
int ret;
if (!btrfs_fs_compat_ro(trans->fs_info, FREE_SPACE_TREE))
if (found_key.type == BTRFS_FREE_SPACE_INFO_KEY) {
ASSERT(found_key.objectid == block_group->start);
ASSERT(found_key.offset == block_group->length);
- done = 1;
+ done = true;
nr++;
path->slots[0]--;
break;
if (!inode && root == fs_info->tree_root) {
struct btrfs_root *dead_root;
- int is_dead_root = 0;
+ bool is_dead_root = false;
/*
* This is an orphan in the tree root. Currently these
dead_root = radix_tree_lookup(&fs_info->fs_roots_radix,
(unsigned long)found_key.objectid);
if (dead_root && btrfs_root_refs(&dead_root->root_item) == 0)
- is_dead_root = 1;
+ is_dead_root = true;
spin_unlock(&fs_info->fs_roots_radix_lock);
if (is_dead_root) {
int bucket = rbio_bucket(rbio);
struct btrfs_stripe_hash_table *table;
struct btrfs_stripe_hash *h;
- int freeit = 0;
+ bool freeit = false;
/*
* check the bit again under the hash table lock.
if (test_and_clear_bit(RBIO_CACHE_BIT, &rbio->flags)) {
list_del_init(&rbio->stripe_cache);
table->cache_size -= 1;
- freeit = 1;
+ freeit = true;
/* if the bio list isn't empty, this rbio is
* still involved in an IO. We take it out
{
int bucket;
struct btrfs_stripe_hash *h;
- int keep_cache = 0;
+ bool keep_cache = false;
bucket = rbio_bucket(rbio);
h = rbio->bioc->fs_info->stripe_hash_table->table + bucket;
*/
if (list_empty(&rbio->plug_list) &&
test_bit(RBIO_CACHE_BIT, &rbio->flags)) {
- keep_cache = 1;
+ keep_cache = true;
clear_bit(RBIO_RMW_LOCKED_BIT, &rbio->flags);
BUG_ON(!bio_list_empty(&rbio->bio_list));
goto done;
phys_addr_t p_paddr = INVALID_PADDR;
phys_addr_t q_paddr = INVALID_PADDR;
struct bio_list bio_list;
- int is_replace = 0;
+ bool is_replace = false;
int ret;
bio_list_init(&bio_list);
* need to duplicate the final write to replace target.
*/
if (bioc->replace_nr_stripes && bioc->replace_stripe_src == rbio->scrubp) {
- is_replace = 1;
+ is_replace = true;
bitmap_copy(pbitmap, &rbio->dbitmap, rbio->stripe_nsectors);
}
struct btrfs_root *reloc_root;
struct reloc_control *rc = fs_info->reloc_ctl;
struct btrfs_block_rsv *rsv;
- int clear_rsv = 0;
+ bool clear_rsv = false;
int ret;
if (!rc)
if (!trans->reloc_reserved) {
rsv = trans->block_rsv;
trans->block_rsv = rc->block_rsv;
- clear_rsv = 1;
+ clear_rsv = true;
}
reloc_root = create_reloc_root(trans, root, btrfs_root_id(root));
if (clear_rsv)
u32 nritems;
u32 i;
int ret = 0;
- int first = 1;
+ bool first = true;
if (rc->stage != UPDATE_DATA_PTRS)
return 0;
if (btrfs_root_id(root) != BTRFS_TREE_RELOC_OBJECTID) {
if (first) {
inode = btrfs_find_first_inode(root, key.objectid);
- first = 0;
+ first = false;
} else if (inode && btrfs_ino(inode) < key.objectid) {
btrfs_add_delayed_iput(inode);
inode = btrfs_find_first_inode(root, key.objectid);
u64 new_ptr_gen;
u64 last_snapshot;
u32 blocksize;
- int cow = 0;
+ bool cow = false;
int level;
int ret;
int slot;
if (!cow) {
btrfs_tree_unlock(parent);
free_extent_buffer(parent);
- cow = 1;
+ cow = true;
goto again;
}
int reserve_level;
int level;
int max_level;
- int replaced = 0;
+ bool replaced = false;
int ret = 0;
u32 min_reserved;
btrfs_set_root_last_trans(reloc_root, trans->transid);
trans->block_rsv = rc->block_rsv;
- replaced = 0;
+ replaced = false;
max_level = level;
ret = walk_down_reloc_tree(reloc_root, path, &level);
level = ret;
btrfs_node_key_to_cpu(path->nodes[level], &key,
path->slots[level]);
- replaced = 1;
+ replaced = true;
}
ret = walk_up_reloc_tree(reloc_root, path, &level);
struct btrfs_root *root;
struct btrfs_root *reloc_root;
LIST_HEAD(reloc_roots);
- int found = 0;
+ bool found = false;
int ret = 0;
again:
root = rc->extent_root;
mutex_unlock(&fs_info->reloc_mutex);
while (!list_empty(&reloc_roots)) {
- found = 1;
+ found = true;
reloc_root = list_first_entry(&reloc_roots, struct btrfs_root, root_list);
root = btrfs_get_fs_root(fs_info, reloc_root->root_key.offset,
}
if (found) {
- found = 0;
+ found = false;
goto again;
}
out:
struct btrfs_fs_info *fs_info = root->fs_info;
struct reloc_control *rc;
struct btrfs_backref_node *node;
- int first_cow = 0;
+ bool first_cow = false;
int level;
int ret = 0;
level = btrfs_header_level(buf);
if (btrfs_header_generation(buf) <=
btrfs_root_last_snapshot(&root->root_item))
- first_cow = 1;
+ first_cow = true;
if (btrfs_root_id(root) == BTRFS_TREE_RELOC_OBJECTID && rc->create_reloc_tree) {
WARN_ON(!first_cow && level == 0);
struct btrfs_root_item *item)
{
u32 len;
- int need_reset = 0;
+ bool need_reset = false;
len = btrfs_item_size(eb, slot);
read_extent_buffer(eb, item, btrfs_item_ptr_offset(eb, slot),
min_t(u32, len, sizeof(*item)));
if (len < sizeof(*item))
- need_reset = 1;
+ need_reset = true;
if (!need_reset && btrfs_root_generation(item)
!= btrfs_root_generation_v2(item)) {
if (btrfs_root_generation_v2(item) != 0) {
btrfs_warn(eb->fs_info,
"mismatching generation and generation_v2 found in root item. This root was probably mounted with an older kernel. Resetting all new fields.");
}
- need_reset = 1;
+ need_reset = true;
}
if (need_reset) {
/* Clear all members from generation_v2 onwards. */
struct fs_path *name __free(fs_path_free) = NULL;
u64 parent_inode = 0;
u64 parent_gen = 0;
- int stop = 0;
+ bool stop = false;
const bool is_cur_inode = (ino == sctx->cur_ino && gen == sctx->cur_inode_gen);
if (is_cur_inode && fs_path_len(&sctx->cur_inode_path) > 0) {
wdm = get_waiting_dir_move(sctx, ino);
if (wdm && wdm->orphanized) {
ret = gen_unique_name(sctx, ino, gen, name);
- stop = 1;
+ stop = true;
} else if (wdm) {
ret = get_first_ref(sctx->parent_root, ino,
&parent_inode, &parent_gen, name);
&parent_inode,
&parent_gen, name);
if (ret)
- stop = 1;
+ stop = true;
}
if (ret < 0)
struct rb_node *parent = NULL;
struct pending_dir_move *entry = NULL, *pm;
struct recorded_ref *cur;
- int exists = 0;
+ bool exists = false;
int ret;
pm = kmalloc_obj(*pm);
} else if (parent_ino > entry->parent_ino) {
p = &(*p)->rb_right;
} else {
- exists = 1;
+ exists = true;
break;
}
}
u64 right_uid;
u64 right_gid;
u64 right_fileattr;
- int need_chmod = 0;
- int need_chown = 0;
+ bool need_chmod = false;
+ bool need_chown = false;
bool need_fileattr = false;
- int need_truncate = 1;
+ bool need_truncate = true;
bool pending_move = false;
bool refs_processed = false;
left_fileattr = info.fileattr;
if (!sctx->parent_root || sctx->cur_inode_new) {
- need_chown = 1;
+ need_chown = true;
if (!S_ISLNK(sctx->cur_inode_mode))
- need_chmod = 1;
+ need_chmod = true;
if (sctx->cur_inode_next_write_offset == sctx->cur_inode_size)
- need_truncate = 0;
+ need_truncate = false;
} else {
u64 old_size;
right_fileattr = info.fileattr;
if (left_uid != right_uid || left_gid != right_gid)
- need_chown = 1;
+ need_chown = true;
if (!S_ISLNK(sctx->cur_inode_mode) && left_mode != right_mode)
- need_chmod = 1;
+ need_chmod = true;
if (!S_ISLNK(sctx->cur_inode_mode) && left_fileattr != right_fileattr)
need_fileattr = true;
if ((old_size == sctx->cur_inode_size) ||
(sctx->cur_inode_size > old_size &&
sctx->cur_inode_next_write_offset == sctx->cur_inode_size))
- need_truncate = 0;
+ need_truncate = false;
}
if (S_ISREG(sctx->cur_inode_mode)) {
u64 *clone_sources_tmp = NULL;
int clone_sources_to_rollback = 0;
size_t alloc_size;
- int sort_clone_roots = 0;
+ bool sort_clone_roots = false;
struct btrfs_lru_cache_entry *entry;
struct btrfs_lru_cache_entry *tmp;
sort(sctx->clone_roots, sctx->clone_roots_cnt,
sizeof(*sctx->clone_roots), __clone_root_cmp_sort,
NULL);
- sort_clone_roots = 1;
+ sort_clone_roots = true;
ret = flush_delalloc_roots(sctx);
if (ret)
struct btrfs_block_rsv *block_rsv = &fs_info->global_block_rsv;
int ret;
u64 thresh = 0;
- int mixed = 0;
+ bool mixed = false;
__kernel_fsid_t f_fsid;
list_for_each_entry(found, &fs_info->space_info, list) {
*/
if (!mixed && found->flags & BTRFS_BLOCK_GROUP_METADATA) {
if (found->flags & BTRFS_BLOCK_GROUP_DATA)
- mixed = 1;
+ mixed = true;
else
total_free_meta += found->disk_total -
found->disk_used;
btrfs_create_pending_block_groups(trans);
if (!test_bit(BTRFS_TRANS_DIRTY_BG_RUN, &cur_trans->flags)) {
- int run_it = 0;
+ bool run_it = false;
/* this mutex is also taken before trying to set
* block groups readonly. We need to make sure
mutex_lock(&fs_info->ro_block_group_mutex);
if (!test_and_set_bit(BTRFS_TRANS_DIRTY_BG_RUN,
&cur_trans->flags))
- run_it = 1;
+ run_it = true;
mutex_unlock(&fs_info->ro_block_group_mutex);
if (run_it) {
u32 count_data = 0;
u32 count_meta = 0;
u32 count_sys = 0;
- int chunk_reserved = 0;
+ bool chunk_reserved = false;
struct remap_chunk_info *rci;
unsigned int num_remap_chunks = 0;
LIST_HEAD(remap_chunks);
mutex_unlock(&fs_info->reclaim_bgs_lock);
goto error;
} else if (ret == 1) {
- chunk_reserved = 1;
+ chunk_reserved = true;
}
}
{
u64 meta_target, data_target;
u64 allowed;
- int mixed = 0;
+ bool mixed = false;
int ret;
u64 num_devices;
unsigned seq;
allowed = btrfs_super_incompat_flags(fs_info->super_copy);
if (allowed & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS)
- mixed = 1;
+ mixed = true;
/*
* In case of mixed groups both data and meta should be picked,
{
struct btrfs_dev_replace *dev_replace = &fs_info->dev_replace;
struct btrfs_device *device;
- int dev_replace_is_ongoing = 0;
+ bool dev_replace_is_ongoing = false;
unsigned int nofs_flag;
struct blk_zone zone;
int ret;