Skip to content

Commit

Permalink
btrfs-progs: convert strerror to implicit %m
Browse files Browse the repository at this point in the history
Similar to the changes where strerror(errno) was converted, continue
with the remaining cases where the argument was stored in another
variable.

The savings in object size are about 4500 bytes:

 $ size btrfs.old btrfs.new
   text    data     bss     dec     hex filename
 805055   24248   19748  849051   cf49b btrfs.old
 804527   24248   19748  848523   cf28b btrfs.new

Signed-off-by: David Sterba <dsterba@suse.com>
  • Loading branch information
kdave committed Oct 31, 2018
1 parent d59e19c commit e578b59
Show file tree
Hide file tree
Showing 37 changed files with 376 additions and 308 deletions.
12 changes: 6 additions & 6 deletions btrfs-corrupt-block.c
Expand Up @@ -70,19 +70,19 @@ static int debug_corrupt_block(struct extent_buffer *eb,
if (!copy || mirror_num == copy) {
ret = read_extent_from_disk(eb, 0, eb->len);
if (ret < 0) {
error("cannot read eb bytenr %llu: %s",
(unsigned long long)eb->dev_bytenr,
strerror(-ret));
errno = -ret;
error("cannot read eb bytenr %llu: %m",
(unsigned long long)eb->dev_bytenr);
return ret;
}
printf("corrupting %llu copy %d\n", eb->start,
mirror_num);
memset(eb->data, 0, eb->len);
ret = write_extent_to_disk(eb);
if (ret < 0) {
error("cannot write eb bytenr %llu: %s",
(unsigned long long)eb->dev_bytenr,
strerror(-ret));
errno = -ret;
error("cannot write eb bytenr %llu: %m",
(unsigned long long)eb->dev_bytenr);
return ret;
}
fsync(eb->fd);
Expand Down
4 changes: 2 additions & 2 deletions btrfs-find-root.c
Expand Up @@ -204,8 +204,8 @@ int main(int argc, char **argv)
&filter.match_gen, &filter.match_level);
ret = btrfs_find_root_search(fs_info, &filter, &result, &found);
if (ret < 0) {
fprintf(stderr, "Fail to search the tree root: %s\n",
strerror(-ret));
errno = -ret;
fprintf(stderr, "Fail to search the tree root: %m\n");
goto out;
}
if (ret > 0) {
Expand Down
5 changes: 3 additions & 2 deletions btrfs-list.c
Expand Up @@ -515,8 +515,9 @@ static int add_root(struct root_lookup *root_lookup,

ret = root_tree_insert(root_lookup, ri);
if (ret < 0) {
error("failed to insert subvolume %llu to tree: %s",
(unsigned long long)root_id, strerror(-ret));
errno = -ret;
error("failed to insert subvolume %llu to tree: %m",
(unsigned long long)root_id);
exit(1);
}
return 0;
Expand Down
25 changes: 14 additions & 11 deletions btrfs-map-logical.c
Expand Up @@ -113,9 +113,10 @@ static int __print_mapping_info(struct btrfs_fs_info *fs_info, u64 logical,
ret = btrfs_map_block(fs_info, READ, logical + cur_offset,
&cur_len, &multi, mirror_num, NULL);
if (ret) {
errno = -ret;
fprintf(info_file,
"Error: fails to map mirror%d logical %llu: %s\n",
mirror_num, logical, strerror(-ret));
"Error: fails to map mirror%d logical %llu: %m\n",
mirror_num, logical);
return ret;
}
for (i = 0; i < multi->num_stripes; i++) {
Expand Down Expand Up @@ -173,17 +174,18 @@ static int write_extent_content(struct btrfs_fs_info *fs_info, int out_fd,
ret = read_extent_data(fs_info, buffer,
logical + cur_offset, &cur_len, mirror);
if (ret < 0) {
errno = -ret;
fprintf(stderr,
"Failed to read extent at [%llu, %llu]: %s\n",
logical, logical + length, strerror(-ret));
"Failed to read extent at [%llu, %llu]: %m\n",
logical, logical + length);
return ret;
}
ret = write(out_fd, buffer, cur_len);
if (ret < 0 || ret != cur_len) {
if (ret > 0)
ret = -EINTR;
fprintf(stderr, "output file write failed: %s\n",
strerror(-ret));
errno = -ret;
fprintf(stderr, "output file write failed: %m\n");
return ret;
}
cur_offset += cur_len;
Expand Down Expand Up @@ -293,8 +295,9 @@ int main(int argc, char **argv)
/* First find the nearest extent */
ret = map_one_extent(root->fs_info, &cur_logical, &cur_len, 0);
if (ret < 0) {
fprintf(stderr, "Failed to find extent at [%llu,%llu): %s\n",
cur_logical, cur_logical + cur_len, strerror(-ret));
errno = -ret;
fprintf(stderr, "Failed to find extent at [%llu,%llu): %m\n",
cur_logical, cur_logical + cur_len);
goto out_close_fd;
}
/*
Expand All @@ -305,10 +308,10 @@ int main(int argc, char **argv)
if (ret > 0) {
ret = map_one_extent(root->fs_info, &cur_logical, &cur_len, 1);
if (ret < 0) {
errno = -ret;
fprintf(stderr,
"Failed to find extent at [%llu,%llu): %s\n",
cur_logical, cur_logical + cur_len,
strerror(-ret));
"Failed to find extent at [%llu,%llu): %m\n",
cur_logical, cur_logical + cur_len);
goto out_close_fd;
}
if (ret > 0) {
Expand Down
3 changes: 2 additions & 1 deletion btrfs-select-super.c
Expand Up @@ -77,7 +77,8 @@ int main(int argc, char **argv)
radix_tree_init();

if((ret = check_mounted(argv[optind])) < 0) {
error("cannot check mount status: %s", strerror(-ret));
errno = -ret;
error("cannot check mount status: %m");
return ret;
} else if(ret) {
error("%s is currently mounted, aborting", argv[optind]);
Expand Down
4 changes: 2 additions & 2 deletions btrfstune.c
Expand Up @@ -477,8 +477,8 @@ int main(int argc, char *argv[])
ret = check_mounted_where(fd, device, NULL, 0, NULL,
SBREAD_IGNORE_FSID_MISMATCH);
if (ret < 0) {
error("could not check mount status of %s: %s", device,
strerror(-ret));
errno = -ret;
error("could not check mount status of %s: %m", device);
close(fd);
return 1;
} else if (ret) {
Expand Down
61 changes: 34 additions & 27 deletions check/main.c
Expand Up @@ -2291,9 +2291,9 @@ static int repair_inode_nlinks(struct btrfs_trans_handle *trans,

ret = reset_nlink(trans, root, path, rec);
if (ret < 0) {
errno = -ret;
fprintf(stderr,
"Failed to reset nlink for inode %llu: %s\n",
rec->ino, strerror(-ret));
"Failed to reset nlink for inode %llu: %m\n", rec->ino);
goto out;
}

Expand Down Expand Up @@ -3170,8 +3170,8 @@ static int repair_btree(struct btrfs_root *root,
trans = btrfs_start_transaction(root, 1);
if (IS_ERR(trans)) {
ret = PTR_ERR(trans);
fprintf(stderr, "Error starting transaction: %s\n",
strerror(-ret));
errno = -ret;
fprintf(stderr, "Error starting transaction: %m\n");
return ret;
}
btrfs_init_path(&path);
Expand Down Expand Up @@ -3363,8 +3363,8 @@ static int check_fs_root(struct btrfs_root *root,
root->root_key.objectid);
ret = repair_btree(root, &corrupt_blocks);
if (ret < 0)
fprintf(stderr, "Failed to repair btree: %s\n",
strerror(-ret));
errno = -ret;
fprintf(stderr, "Failed to repair btree: %m\n");
if (!ret)
printf("Btree for root %llu is fixed\n",
root->root_key.objectid);
Expand Down Expand Up @@ -5177,18 +5177,20 @@ static int process_extent_item(struct btrfs_root *root,
case BTRFS_TREE_BLOCK_REF_KEY:
ret = add_tree_backref(extent_cache, key.objectid,
0, offset, 0);
if (ret < 0)
if (ret < 0) {
errno = -ret;
error(
"add_tree_backref failed (extent items tree block): %s",
strerror(-ret));
"add_tree_backref failed (extent items tree block): %m");
}
break;
case BTRFS_SHARED_BLOCK_REF_KEY:
ret = add_tree_backref(extent_cache, key.objectid,
offset, 0, 0);
if (ret < 0)
if (ret < 0) {
errno = -ret;
error(
"add_tree_backref failed (extent items shared block): %s",
strerror(-ret));
"add_tree_backref failed (extent items shared block): %m");
}
break;
case BTRFS_EXTENT_DATA_REF_KEY:
dref = (struct btrfs_extent_data_ref *)(&iref->offset);
Expand Down Expand Up @@ -5420,16 +5422,18 @@ static int check_space_cache(struct btrfs_root *root)
if (btrfs_fs_compat_ro(root->fs_info, FREE_SPACE_TREE)) {
ret = exclude_super_stripes(root, cache);
if (ret) {
fprintf(stderr, "could not exclude super stripes: %s\n",
strerror(-ret));
errno = -ret;
fprintf(stderr,
"could not exclude super stripes: %m\n");
error++;
continue;
}
ret = load_free_space_tree(root->fs_info, cache);
free_excluded_extents(root, cache);
if (ret < 0) {
fprintf(stderr, "could not load free space tree: %s\n",
strerror(-ret));
errno = -ret;
fprintf(stderr,
"could not load free space tree: %m\n");
error++;
continue;
}
Expand Down Expand Up @@ -6122,19 +6126,21 @@ static int run_next_block(struct btrfs_root *root,
if (key.type == BTRFS_TREE_BLOCK_REF_KEY) {
ret = add_tree_backref(extent_cache,
key.objectid, 0, key.offset, 0);
if (ret < 0)
if (ret < 0) {
errno = -ret;
error(
"add_tree_backref failed (leaf tree block): %s",
strerror(-ret));
"add_tree_backref failed (leaf tree block): %m");
}
continue;
}
if (key.type == BTRFS_SHARED_BLOCK_REF_KEY) {
ret = add_tree_backref(extent_cache,
key.objectid, key.offset, 0, 0);
if (ret < 0)
if (ret < 0) {
errno = -ret;
error(
"add_tree_backref failed (leaf shared block): %s",
strerror(-ret));
"add_tree_backref failed (leaf shared block): %m");
}
continue;
}
if (key.type == BTRFS_EXTENT_DATA_REF_KEY) {
Expand Down Expand Up @@ -6236,9 +6242,9 @@ static int run_next_block(struct btrfs_root *root,
ret = add_tree_backref(extent_cache, ptr, parent,
owner, 1);
if (ret < 0) {
errno = -ret;
error(
"add_tree_backref failed (non-leaf block): %s",
strerror(-ret));
"add_tree_backref failed (non-leaf block): %m");
continue;
}

Expand Down Expand Up @@ -9678,8 +9684,8 @@ int cmd_check(int argc, char **argv)
ret = check_mounted(argv[optind]);
if (!force) {
if (ret < 0) {
error("could not check mount status: %s",
strerror(-ret));
errno = -ret;
error("could not check mount status: %m");
err |= !!ret;
goto err_out;
} else if (ret) {
Expand Down Expand Up @@ -9856,7 +9862,8 @@ int cmd_check(int argc, char **argv)
task_stop(ctx.info);
if (ret < 0) {
err = !!ret;
error("failed to repair root items: %s", strerror(-ret));
errno = -ret;
error("failed to repair root items: %m");
goto close_out;
}
if (repair) {
Expand Down
8 changes: 5 additions & 3 deletions check/mode-common.c
Expand Up @@ -450,7 +450,8 @@ int link_inode_to_lostfound(struct btrfs_trans_handle *trans,
BTRFS_FIRST_FREE_OBJECTID, &lost_found_ino,
mode);
if (ret < 0) {
error("failed to create '%s' dir: %s", dir_name, strerror(-ret));
errno = -ret;
error("failed to create '%s' dir: %m", dir_name);
goto out;
}
ret = btrfs_add_link(trans, root, ino, lost_found_ino,
Expand All @@ -474,8 +475,9 @@ int link_inode_to_lostfound(struct btrfs_trans_handle *trans,
name_len, filetype, NULL, 1, 0);
}
if (ret < 0) {
error("failed to link the inode %llu to %s dir: %s",
ino, dir_name, strerror(-ret));
errno = -ret;
error("failed to link the inode %llu to %s dir: %m",
ino, dir_name);
goto out;
}

Expand Down

0 comments on commit e578b59

Please sign in to comment.