Skip to content

Commit

Permalink
btrfs-progs: introduce UASSERT() for purely userspace code
Browse files Browse the repository at this point in the history
While syncing messages.[ch] I had to back out the ASSERT() code in
kerncompat.h, which means we now rely on the kernel code for ASSERT().
In order to maintain some semblance of separation introduce UASSERT()
and use that in all the purely userspace code.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
josefbacik authored and kdave committed May 26, 2023
1 parent c0c5ca1 commit bf0f3db
Show file tree
Hide file tree
Showing 20 changed files with 74 additions and 67 deletions.
4 changes: 2 additions & 2 deletions check/clear-cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,12 @@ int truncate_free_ino_items(struct btrfs_root *root)
fi = btrfs_item_ptr(leaf, path.slots[0],
struct btrfs_file_extent_item);
extent_type = btrfs_file_extent_type(leaf, fi);
ASSERT(extent_type == BTRFS_FILE_EXTENT_REG);
UASSERT(extent_type == BTRFS_FILE_EXTENT_REG);
extent_disk_bytenr = btrfs_file_extent_disk_bytenr(leaf, fi);
extent_num_bytes = btrfs_file_extent_disk_num_bytes (leaf, fi);
extent_offset = found_key.offset -
btrfs_file_extent_offset(leaf, fi);
ASSERT(extent_offset == 0);
UASSERT(extent_offset == 0);
ret = btrfs_free_extent(trans, root, extent_disk_bytenr,
extent_num_bytes, 0, root->objectid,
BTRFS_FREE_INO_OBJECTID, 0);
Expand Down
10 changes: 5 additions & 5 deletions check/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -9680,14 +9680,14 @@ static int build_roots_info_cache(void)
rii->level = (u8)-1;
entry = &rii->cache_extent;
ret = insert_cache_extent(roots_info_cache, entry);
ASSERT(ret == 0);
UASSERT(ret == 0);
} else {
rii = container_of(entry, struct root_item_info,
cache_extent);
}

ASSERT(rii->cache_extent.start == root_id);
ASSERT(rii->cache_extent.size == 1);
UASSERT(rii->cache_extent.start == root_id);
UASSERT(rii->cache_extent.size == 1);

if (level > rii->level || rii->level == (u8)-1) {
rii->level = level;
Expand Down Expand Up @@ -9726,8 +9726,8 @@ static int maybe_repair_root_item(struct btrfs_path *path,
}

rii = container_of(entry, struct root_item_info, cache_extent);
ASSERT(rii->cache_extent.start == root_id);
ASSERT(rii->cache_extent.size == 1);
UASSERT(rii->cache_extent.start == root_id);
UASSERT(rii->cache_extent.size == 1);

if (rii->node_count != 1) {
fprintf(stderr,
Expand Down
12 changes: 6 additions & 6 deletions check/mode-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ int check_prealloc_extent_written(u64 disk_bytenr, u64 num_bytes)

iref = (struct btrfs_extent_inline_ref *)ptr;
type = btrfs_extent_inline_ref_type(path.nodes[0], iref);
ASSERT(type == BTRFS_EXTENT_DATA_REF_KEY ||
type == BTRFS_SHARED_DATA_REF_KEY);
UASSERT(type == BTRFS_EXTENT_DATA_REF_KEY ||
type == BTRFS_SHARED_DATA_REF_KEY);

if (type == BTRFS_EXTENT_DATA_REF_KEY) {
struct btrfs_extent_data_ref *dref;
Expand Down Expand Up @@ -398,7 +398,7 @@ int insert_inode_item(struct btrfs_trans_handle *trans,
btrfs_set_stack_timespec_sec(&ii.mtime, now);

ret = btrfs_insert_inode(trans, root, ino, &ii);
ASSERT(!ret);
UASSERT(!ret);

warning("root %llu inode %llu recreating inode item, this may "
"be incomplete, please check permissions and content after "
Expand Down Expand Up @@ -985,7 +985,7 @@ int repair_imode_common(struct btrfs_root *root, struct btrfs_path *path)
int ret;

btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
ASSERT(key.type == BTRFS_INODE_ITEM_KEY);
UASSERT(key.type == BTRFS_INODE_ITEM_KEY);
if (root->objectid == BTRFS_ROOT_TREE_OBJECTID) {
/* In root tree we only have two possible imode */
if (key.objectid == BTRFS_ROOT_TREE_OBJECTID)
Expand Down Expand Up @@ -1033,7 +1033,7 @@ int check_repair_free_space_inode(struct btrfs_path *path)
int ret = 0;

btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
ASSERT(key.type == BTRFS_INODE_ITEM_KEY && is_fstree(key.objectid));
UASSERT(key.type == BTRFS_INODE_ITEM_KEY && is_fstree(key.objectid));
iitem = btrfs_item_ptr(path->nodes[0], path->slots[0],
struct btrfs_inode_item);
mode = btrfs_inode_mode(path->nodes[0], iitem);
Expand Down Expand Up @@ -1607,7 +1607,7 @@ static int get_num_devs_in_chunk_tree(struct btrfs_fs_info *fs_info)
return ret;

/* We should be the first slot, and chunk tree should not be empty*/
ASSERT(path.slots[0] == 0 && btrfs_header_nritems(path.nodes[0]));
UASSERT(path.slots[0] == 0 && btrfs_header_nritems(path.nodes[0]));

btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]);

Expand Down
20 changes: 10 additions & 10 deletions check/mode-lowmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ static int find_dir_index(struct btrfs_root *root, u64 dirid, u64 location_id,
int slot;
int ret;

ASSERT(index_ret);
UASSERT(index_ret);

/* search from the last index */
key.objectid = dirid;
Expand Down Expand Up @@ -1029,7 +1029,7 @@ static int repair_ternary_lowmem(struct btrfs_root *root, u64 dir_ino, u64 ino,
stage++;

/* stage must be smllarer than 3 */
ASSERT(stage < 3);
UASSERT(stage < 3);

trans = btrfs_start_transaction(root, 1);
if (stage == 2) {
Expand Down Expand Up @@ -1351,7 +1351,7 @@ static int find_inode_ref(struct btrfs_root *root, struct btrfs_key *key,
int slot;
int ret;

ASSERT(index_ret);
UASSERT(index_ret);

btrfs_init_path(&path);
ret = btrfs_search_slot(NULL, root, key, &path, 0, 0);
Expand Down Expand Up @@ -1945,7 +1945,7 @@ static int repair_inline_ram_bytes(struct btrfs_root *root,
recover_ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);

/* This really shouldn't happen, or we have a big problem */
ASSERT(recover_ret == 0);
UASSERT(recover_ret == 0);
return ret;
}

Expand Down Expand Up @@ -2193,7 +2193,7 @@ static int __count_dir_isize(struct btrfs_root *root, u64 ino, int type,
int cur = 0;
int total = 0;

ASSERT(size_ret);
UASSERT(size_ret);
*size_ret = 0;

key.objectid = ino;
Expand Down Expand Up @@ -2247,7 +2247,7 @@ static int count_dir_isize(struct btrfs_root *root, u64 ino, u64 *size)
u64 index_size;
int ret;

ASSERT(size);
UASSERT(size);
ret = __count_dir_isize(root, ino, BTRFS_DIR_ITEM_KEY, &item_size);
if (ret)
goto out;
Expand Down Expand Up @@ -2451,7 +2451,7 @@ static int repair_inode_nlinks_lowmem(struct btrfs_root *root,
btrfs_item_key_to_cpu(path->nodes[0], &old_key, path->slots[0]);

if (name && namelen) {
ASSERT(namelen <= BTRFS_NAME_LEN);
UASSERT(namelen <= BTRFS_NAME_LEN);
memcpy(namebuf, name, namelen);
name_len = namelen;
} else {
Expand Down Expand Up @@ -2550,7 +2550,7 @@ static int repair_inode_gen_lowmem(struct btrfs_root *root,
}
transid = trans->transid;
btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
ASSERT(key.type == BTRFS_INODE_ITEM_KEY);
UASSERT(key.type == BTRFS_INODE_ITEM_KEY);

btrfs_release_path(path);

Expand Down Expand Up @@ -4188,8 +4188,8 @@ static int repair_extent_item_generation(struct btrfs_path *path)
int ret;

btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
ASSERT(key.type == BTRFS_METADATA_ITEM_KEY ||
key.type == BTRFS_EXTENT_ITEM_KEY);
UASSERT(key.type == BTRFS_METADATA_ITEM_KEY ||
key.type == BTRFS_EXTENT_ITEM_KEY);

get_extent_item_generation(key.objectid, &new_gen);
ret = avoid_extents_overwrite();
Expand Down
2 changes: 1 addition & 1 deletion cmds/filesystem-du.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static int add_shared_extent(u64 start, u64 len, struct rb_root *root)
{
struct shared_extent *sh;

ASSERT(len != 0);
UASSERT(len != 0);

sh = calloc(1, sizeof(*sh));
if (!sh)
Expand Down
6 changes: 3 additions & 3 deletions cmds/filesystem-usage.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,15 @@ static void get_raid56_space_info(struct btrfs_ioctl_space_args *sargs,
size = info_ptr->size / (info_ptr->num_stripes - parities_count);

if (info_ptr->type & BTRFS_BLOCK_GROUP_DATA) {
ASSERT(l_data_ratio >= 0);
UASSERT(l_data_ratio >= 0);
*r_data_chunks += size;
*r_data_used += size * l_data_ratio;
} else if (info_ptr->type & BTRFS_BLOCK_GROUP_METADATA) {
ASSERT(l_metadata_ratio >= 0);
UASSERT(l_metadata_ratio >= 0);
*r_metadata_chunks += size;
*r_metadata_used += size * l_metadata_ratio;
} else if (info_ptr->type & BTRFS_BLOCK_GROUP_SYSTEM) {
ASSERT(l_system_ratio >= 0);
UASSERT(l_system_ratio >= 0);
*r_system_chunks += size;
*r_system_used += size * l_system_ratio;
}
Expand Down
22 changes: 11 additions & 11 deletions cmds/qgroup.c
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ static void qgroup_setup_print_column(enum btrfs_qgroup_column_enum column)
{
int i;

ASSERT(0 <= column && column <= BTRFS_QGROUP_ALL);
UASSERT(0 <= column && column <= BTRFS_QGROUP_ALL);

if (column < BTRFS_QGROUP_ALL) {
btrfs_qgroup_columns[column].need_print = 1;
Expand Down Expand Up @@ -332,7 +332,7 @@ static void print_qgroup_column(struct btrfs_qgroup *qgroup,
int unit_mode = btrfs_qgroup_columns[column].unit_mode;
int max_len = btrfs_qgroup_columns[column].max_len;

ASSERT(0 <= column && column < BTRFS_QGROUP_ALL);
UASSERT(0 <= column && column < BTRFS_QGROUP_ALL);

switch (column) {

Expand Down Expand Up @@ -617,9 +617,9 @@ static int qgroup_setup_comparer(struct btrfs_qgroup_comparer_set **comp_set,
struct btrfs_qgroup_comparer_set *set = *comp_set;
int size;

ASSERT(set != NULL);
ASSERT(comparer < BTRFS_QGROUP_COMP_MAX);
ASSERT(set->ncomps <= set->total);
UASSERT(set != NULL);
UASSERT(comparer < BTRFS_QGROUP_COMP_MAX);
UASSERT(set->ncomps <= set->total);

if (set->ncomps == set->total) {
void *tmp;
Expand All @@ -641,7 +641,7 @@ static int qgroup_setup_comparer(struct btrfs_qgroup_comparer_set **comp_set,
*comp_set = set;
}

ASSERT(set->comps[set->ncomps].comp_func == NULL);
UASSERT(set->comps[set->ncomps].comp_func == NULL);

set->comps[set->ncomps].comp_func = all_comp_funcs[comparer];
set->comps[set->ncomps].is_descending = is_descending;
Expand Down Expand Up @@ -1014,9 +1014,9 @@ static int qgroup_setup_filter(struct btrfs_qgroup_filter_set **filter_set,
struct btrfs_qgroup_filter_set *set = *filter_set;
int size;

ASSERT(set != NULL);
ASSERT(filter < BTRFS_QGROUP_FILTER_MAX);
ASSERT(set->nfilters <= set->total);
UASSERT(set != NULL);
UASSERT(filter < BTRFS_QGROUP_FILTER_MAX);
UASSERT(set->nfilters <= set->total);

if (set->nfilters == set->total) {
void *tmp;
Expand All @@ -1038,7 +1038,7 @@ static int qgroup_setup_filter(struct btrfs_qgroup_filter_set **filter_set,
*filter_set = set;
}

ASSERT(set->filters[set->nfilters].filter_func == NULL);
UASSERT(set->filters[set->nfilters].filter_func == NULL);
set->filters[set->nfilters].filter_func = all_filter_funcs[filter];
set->filters[set->nfilters].data = data;
set->nfilters++;
Expand Down Expand Up @@ -1114,7 +1114,7 @@ static void __update_columns_max_len(struct btrfs_qgroup *bq,
int len;
unsigned unit_mode = btrfs_qgroup_columns[column].unit_mode;

ASSERT(0 <= column && column < BTRFS_QGROUP_ALL);
UASSERT(0 <= column && column < BTRFS_QGROUP_ALL);

switch (column) {

Expand Down
4 changes: 2 additions & 2 deletions cmds/replace.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ time2string(char *buf, size_t s, __u64 t)
time_t t_time_t;

t_time_t = (time_t)t;
ASSERT((__u64)t_time_t == t);
UASSERT((__u64)t_time_t == t);
localtime_r(&t_time_t, &t_tm);
strftime(buf, s, "%e.%b %T", &t_tm);
return buf;
Expand All @@ -529,7 +529,7 @@ static char *
progress2string(char *buf, size_t s, int progress_1000)
{
snprintf(buf, s, "%d.%01d%%", progress_1000 / 10, progress_1000 % 10);
ASSERT(s > 0);
UASSERT(s > 0);
buf[s - 1] = '\0';
return buf;
}
Expand Down
6 changes: 3 additions & 3 deletions cmds/rescue-chunk-recover.c
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,7 @@ open_ctree_with_broken_chunk(struct recover_control *rc)
goto out_devices;
}

ASSERT(!memcmp(disk_super->fsid, rc->fs_devices->fsid, BTRFS_FSID_SIZE));
UASSERT(!memcmp(disk_super->fsid, rc->fs_devices->fsid, BTRFS_FSID_SIZE));
fs_info->sectorsize = btrfs_super_sectorsize(disk_super);
fs_info->nodesize = btrfs_super_nodesize(disk_super);
fs_info->stripesize = btrfs_super_stripesize(disk_super);
Expand All @@ -1467,7 +1467,7 @@ open_ctree_with_broken_chunk(struct recover_control *rc)
features = btrfs_super_incompat_flags(disk_super);

if (features & BTRFS_FEATURE_INCOMPAT_METADATA_UUID)
ASSERT(!memcmp(disk_super->metadata_uuid,
UASSERT(!memcmp(disk_super->metadata_uuid,
fs_info->fs_devices->metadata_uuid,
BTRFS_FSID_SIZE));

Expand Down Expand Up @@ -1869,7 +1869,7 @@ static int check_one_csum(int fd, u64 start, u32 len, u32 tree_csum,
int csum_size = 0;
u8 expected_csum[BTRFS_CSUM_SIZE];

ASSERT(0);
UASSERT(0);

data = malloc(len);
if (!data)
Expand Down
4 changes: 2 additions & 2 deletions cmds/rescue.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ static int clear_uuid_tree(struct btrfs_fs_info *fs_info)
ret = btrfs_search_slot(trans, uuid_root, &key, &path, -1, 1);
if (ret < 0)
goto out;
ASSERT(ret > 0);
ASSERT(path.slots[0] == 0);
UASSERT(ret > 0);
UASSERT(path.slots[0] == 0);

nr = btrfs_header_nritems(path.nodes[0]);
if (nr == 0) {
Expand Down
20 changes: 10 additions & 10 deletions cmds/subvolume-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ void btrfs_list_setup_print_column(enum btrfs_list_column_enum column)
{
int i;

ASSERT(0 <= column && column <= BTRFS_LIST_ALL);
UASSERT(0 <= column && column <= BTRFS_LIST_ALL);

if (column < BTRFS_LIST_ALL) {
btrfs_list_columns[column].need_print = 1;
Expand Down Expand Up @@ -367,9 +367,9 @@ static int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,
struct btrfs_list_comparer_set *set = *comp_set;
int size;

ASSERT(set != NULL);
ASSERT(comparer < BTRFS_LIST_COMP_MAX);
ASSERT(set->ncomps <= set->total);
UASSERT(set != NULL);
UASSERT(comparer < BTRFS_LIST_COMP_MAX);
UASSERT(set->ncomps <= set->total);

if (set->ncomps == set->total) {
void *tmp;
Expand All @@ -391,7 +391,7 @@ static int btrfs_list_setup_comparer(struct btrfs_list_comparer_set **comp_set,
*comp_set = set;
}

ASSERT(set->comps[set->ncomps].comp_func == NULL);
UASSERT(set->comps[set->ncomps].comp_func == NULL);

set->comps[set->ncomps].comp_func = all_comp_funcs[comparer];
set->comps[set->ncomps].is_descending = is_descending;
Expand Down Expand Up @@ -1027,9 +1027,9 @@ static void btrfs_list_setup_filter(struct btrfs_list_filter_set **filter_set,
struct btrfs_list_filter_set *set = *filter_set;
int size;

ASSERT(set != NULL);
ASSERT(filter < BTRFS_LIST_FILTER_MAX);
ASSERT(set->nfilters <= set->total);
UASSERT(set != NULL);
UASSERT(filter < BTRFS_LIST_FILTER_MAX);
UASSERT(set->nfilters <= set->total);

if (set->nfilters == set->total) {
void *tmp;
Expand All @@ -1051,7 +1051,7 @@ static void btrfs_list_setup_filter(struct btrfs_list_filter_set **filter_set,
*filter_set = set;
}

ASSERT(set->filters[set->nfilters].filter_func == NULL);
UASSERT(set->filters[set->nfilters].filter_func == NULL);

if (filter == BTRFS_LIST_FILTER_DELETED)
set->only_deleted = 1;
Expand Down Expand Up @@ -1129,7 +1129,7 @@ static void print_subvolume_column(struct root_info *subv,
char tstr[256];
char uuidparse[BTRFS_UUID_UNPARSED_SIZE];

ASSERT(0 <= column && column < BTRFS_LIST_ALL);
UASSERT(0 <= column && column < BTRFS_LIST_ALL);

switch (column) {
case BTRFS_LIST_OBJECTID:
Expand Down
Loading

0 comments on commit bf0f3db

Please sign in to comment.