btrfs-progs: convert strerror to implicit %m

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>
master
David Sterba 2018-10-25 14:10:54 +02:00
parent d59e19ca07
commit e578b59bf6
37 changed files with 376 additions and 308 deletions

View File

@ -70,9 +70,9 @@ static int debug_corrupt_block(struct extent_buffer *eb,
if (!copy || mirror_num == copy) { if (!copy || mirror_num == copy) {
ret = read_extent_from_disk(eb, 0, eb->len); ret = read_extent_from_disk(eb, 0, eb->len);
if (ret < 0) { if (ret < 0) {
error("cannot read eb bytenr %llu: %s", errno = -ret;
(unsigned long long)eb->dev_bytenr, error("cannot read eb bytenr %llu: %m",
strerror(-ret)); (unsigned long long)eb->dev_bytenr);
return ret; return ret;
} }
printf("corrupting %llu copy %d\n", eb->start, printf("corrupting %llu copy %d\n", eb->start,
@ -80,9 +80,9 @@ static int debug_corrupt_block(struct extent_buffer *eb,
memset(eb->data, 0, eb->len); memset(eb->data, 0, eb->len);
ret = write_extent_to_disk(eb); ret = write_extent_to_disk(eb);
if (ret < 0) { if (ret < 0) {
error("cannot write eb bytenr %llu: %s", errno = -ret;
(unsigned long long)eb->dev_bytenr, error("cannot write eb bytenr %llu: %m",
strerror(-ret)); (unsigned long long)eb->dev_bytenr);
return ret; return ret;
} }
fsync(eb->fd); fsync(eb->fd);

View File

@ -204,8 +204,8 @@ int main(int argc, char **argv)
&filter.match_gen, &filter.match_level); &filter.match_gen, &filter.match_level);
ret = btrfs_find_root_search(fs_info, &filter, &result, &found); ret = btrfs_find_root_search(fs_info, &filter, &result, &found);
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "Fail to search the tree root: %s\n", errno = -ret;
strerror(-ret)); fprintf(stderr, "Fail to search the tree root: %m\n");
goto out; goto out;
} }
if (ret > 0) { if (ret > 0) {

View File

@ -515,8 +515,9 @@ static int add_root(struct root_lookup *root_lookup,
ret = root_tree_insert(root_lookup, ri); ret = root_tree_insert(root_lookup, ri);
if (ret < 0) { if (ret < 0) {
error("failed to insert subvolume %llu to tree: %s", errno = -ret;
(unsigned long long)root_id, strerror(-ret)); error("failed to insert subvolume %llu to tree: %m",
(unsigned long long)root_id);
exit(1); exit(1);
} }
return 0; return 0;

View File

@ -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, ret = btrfs_map_block(fs_info, READ, logical + cur_offset,
&cur_len, &multi, mirror_num, NULL); &cur_len, &multi, mirror_num, NULL);
if (ret) { if (ret) {
errno = -ret;
fprintf(info_file, fprintf(info_file,
"Error: fails to map mirror%d logical %llu: %s\n", "Error: fails to map mirror%d logical %llu: %m\n",
mirror_num, logical, strerror(-ret)); mirror_num, logical);
return ret; return ret;
} }
for (i = 0; i < multi->num_stripes; i++) { for (i = 0; i < multi->num_stripes; i++) {
@ -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, ret = read_extent_data(fs_info, buffer,
logical + cur_offset, &cur_len, mirror); logical + cur_offset, &cur_len, mirror);
if (ret < 0) { if (ret < 0) {
errno = -ret;
fprintf(stderr, fprintf(stderr,
"Failed to read extent at [%llu, %llu]: %s\n", "Failed to read extent at [%llu, %llu]: %m\n",
logical, logical + length, strerror(-ret)); logical, logical + length);
return ret; return ret;
} }
ret = write(out_fd, buffer, cur_len); ret = write(out_fd, buffer, cur_len);
if (ret < 0 || ret != cur_len) { if (ret < 0 || ret != cur_len) {
if (ret > 0) if (ret > 0)
ret = -EINTR; ret = -EINTR;
fprintf(stderr, "output file write failed: %s\n", errno = -ret;
strerror(-ret)); fprintf(stderr, "output file write failed: %m\n");
return ret; return ret;
} }
cur_offset += cur_len; cur_offset += cur_len;
@ -293,8 +295,9 @@ int main(int argc, char **argv)
/* First find the nearest extent */ /* First find the nearest extent */
ret = map_one_extent(root->fs_info, &cur_logical, &cur_len, 0); ret = map_one_extent(root->fs_info, &cur_logical, &cur_len, 0);
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "Failed to find extent at [%llu,%llu): %s\n", errno = -ret;
cur_logical, cur_logical + cur_len, strerror(-ret)); fprintf(stderr, "Failed to find extent at [%llu,%llu): %m\n",
cur_logical, cur_logical + cur_len);
goto out_close_fd; goto out_close_fd;
} }
/* /*
@ -305,10 +308,10 @@ int main(int argc, char **argv)
if (ret > 0) { if (ret > 0) {
ret = map_one_extent(root->fs_info, &cur_logical, &cur_len, 1); ret = map_one_extent(root->fs_info, &cur_logical, &cur_len, 1);
if (ret < 0) { if (ret < 0) {
errno = -ret;
fprintf(stderr, fprintf(stderr,
"Failed to find extent at [%llu,%llu): %s\n", "Failed to find extent at [%llu,%llu): %m\n",
cur_logical, cur_logical + cur_len, cur_logical, cur_logical + cur_len);
strerror(-ret));
goto out_close_fd; goto out_close_fd;
} }
if (ret > 0) { if (ret > 0) {

View File

@ -77,7 +77,8 @@ int main(int argc, char **argv)
radix_tree_init(); radix_tree_init();
if((ret = check_mounted(argv[optind])) < 0) { 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; return ret;
} else if(ret) { } else if(ret) {
error("%s is currently mounted, aborting", argv[optind]); error("%s is currently mounted, aborting", argv[optind]);

View File

@ -477,8 +477,8 @@ int main(int argc, char *argv[])
ret = check_mounted_where(fd, device, NULL, 0, NULL, ret = check_mounted_where(fd, device, NULL, 0, NULL,
SBREAD_IGNORE_FSID_MISMATCH); SBREAD_IGNORE_FSID_MISMATCH);
if (ret < 0) { if (ret < 0) {
error("could not check mount status of %s: %s", device, errno = -ret;
strerror(-ret)); error("could not check mount status of %s: %m", device);
close(fd); close(fd);
return 1; return 1;
} else if (ret) { } else if (ret) {

View File

@ -2291,9 +2291,9 @@ static int repair_inode_nlinks(struct btrfs_trans_handle *trans,
ret = reset_nlink(trans, root, path, rec); ret = reset_nlink(trans, root, path, rec);
if (ret < 0) { if (ret < 0) {
errno = -ret;
fprintf(stderr, fprintf(stderr,
"Failed to reset nlink for inode %llu: %s\n", "Failed to reset nlink for inode %llu: %m\n", rec->ino);
rec->ino, strerror(-ret));
goto out; goto out;
} }
@ -3170,8 +3170,8 @@ static int repair_btree(struct btrfs_root *root,
trans = btrfs_start_transaction(root, 1); trans = btrfs_start_transaction(root, 1);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
ret = PTR_ERR(trans); ret = PTR_ERR(trans);
fprintf(stderr, "Error starting transaction: %s\n", errno = -ret;
strerror(-ret)); fprintf(stderr, "Error starting transaction: %m\n");
return ret; return ret;
} }
btrfs_init_path(&path); btrfs_init_path(&path);
@ -3363,8 +3363,8 @@ skip_walking:
root->root_key.objectid); root->root_key.objectid);
ret = repair_btree(root, &corrupt_blocks); ret = repair_btree(root, &corrupt_blocks);
if (ret < 0) if (ret < 0)
fprintf(stderr, "Failed to repair btree: %s\n", errno = -ret;
strerror(-ret)); fprintf(stderr, "Failed to repair btree: %m\n");
if (!ret) if (!ret)
printf("Btree for root %llu is fixed\n", printf("Btree for root %llu is fixed\n",
root->root_key.objectid); root->root_key.objectid);
@ -5177,18 +5177,20 @@ static int process_extent_item(struct btrfs_root *root,
case BTRFS_TREE_BLOCK_REF_KEY: case BTRFS_TREE_BLOCK_REF_KEY:
ret = add_tree_backref(extent_cache, key.objectid, ret = add_tree_backref(extent_cache, key.objectid,
0, offset, 0); 0, offset, 0);
if (ret < 0) if (ret < 0) {
errno = -ret;
error( error(
"add_tree_backref failed (extent items tree block): %s", "add_tree_backref failed (extent items tree block): %m");
strerror(-ret)); }
break; break;
case BTRFS_SHARED_BLOCK_REF_KEY: case BTRFS_SHARED_BLOCK_REF_KEY:
ret = add_tree_backref(extent_cache, key.objectid, ret = add_tree_backref(extent_cache, key.objectid,
offset, 0, 0); offset, 0, 0);
if (ret < 0) if (ret < 0) {
errno = -ret;
error( error(
"add_tree_backref failed (extent items shared block): %s", "add_tree_backref failed (extent items shared block): %m");
strerror(-ret)); }
break; break;
case BTRFS_EXTENT_DATA_REF_KEY: case BTRFS_EXTENT_DATA_REF_KEY:
dref = (struct btrfs_extent_data_ref *)(&iref->offset); dref = (struct btrfs_extent_data_ref *)(&iref->offset);
@ -5420,16 +5422,18 @@ static int check_space_cache(struct btrfs_root *root)
if (btrfs_fs_compat_ro(root->fs_info, FREE_SPACE_TREE)) { if (btrfs_fs_compat_ro(root->fs_info, FREE_SPACE_TREE)) {
ret = exclude_super_stripes(root, cache); ret = exclude_super_stripes(root, cache);
if (ret) { if (ret) {
fprintf(stderr, "could not exclude super stripes: %s\n", errno = -ret;
strerror(-ret)); fprintf(stderr,
"could not exclude super stripes: %m\n");
error++; error++;
continue; continue;
} }
ret = load_free_space_tree(root->fs_info, cache); ret = load_free_space_tree(root->fs_info, cache);
free_excluded_extents(root, cache); free_excluded_extents(root, cache);
if (ret < 0) { if (ret < 0) {
fprintf(stderr, "could not load free space tree: %s\n", errno = -ret;
strerror(-ret)); fprintf(stderr,
"could not load free space tree: %m\n");
error++; error++;
continue; continue;
} }
@ -6122,19 +6126,21 @@ static int run_next_block(struct btrfs_root *root,
if (key.type == BTRFS_TREE_BLOCK_REF_KEY) { if (key.type == BTRFS_TREE_BLOCK_REF_KEY) {
ret = add_tree_backref(extent_cache, ret = add_tree_backref(extent_cache,
key.objectid, 0, key.offset, 0); key.objectid, 0, key.offset, 0);
if (ret < 0) if (ret < 0) {
errno = -ret;
error( error(
"add_tree_backref failed (leaf tree block): %s", "add_tree_backref failed (leaf tree block): %m");
strerror(-ret)); }
continue; continue;
} }
if (key.type == BTRFS_SHARED_BLOCK_REF_KEY) { if (key.type == BTRFS_SHARED_BLOCK_REF_KEY) {
ret = add_tree_backref(extent_cache, ret = add_tree_backref(extent_cache,
key.objectid, key.offset, 0, 0); key.objectid, key.offset, 0, 0);
if (ret < 0) if (ret < 0) {
errno = -ret;
error( error(
"add_tree_backref failed (leaf shared block): %s", "add_tree_backref failed (leaf shared block): %m");
strerror(-ret)); }
continue; continue;
} }
if (key.type == BTRFS_EXTENT_DATA_REF_KEY) { if (key.type == BTRFS_EXTENT_DATA_REF_KEY) {
@ -6236,9 +6242,9 @@ static int run_next_block(struct btrfs_root *root,
ret = add_tree_backref(extent_cache, ptr, parent, ret = add_tree_backref(extent_cache, ptr, parent,
owner, 1); owner, 1);
if (ret < 0) { if (ret < 0) {
errno = -ret;
error( error(
"add_tree_backref failed (non-leaf block): %s", "add_tree_backref failed (non-leaf block): %m");
strerror(-ret));
continue; continue;
} }
@ -9678,8 +9684,8 @@ int cmd_check(int argc, char **argv)
ret = check_mounted(argv[optind]); ret = check_mounted(argv[optind]);
if (!force) { if (!force) {
if (ret < 0) { if (ret < 0) {
error("could not check mount status: %s", errno = -ret;
strerror(-ret)); error("could not check mount status: %m");
err |= !!ret; err |= !!ret;
goto err_out; goto err_out;
} else if (ret) { } else if (ret) {
@ -9856,7 +9862,8 @@ int cmd_check(int argc, char **argv)
task_stop(ctx.info); task_stop(ctx.info);
if (ret < 0) { if (ret < 0) {
err = !!ret; err = !!ret;
error("failed to repair root items: %s", strerror(-ret)); errno = -ret;
error("failed to repair root items: %m");
goto close_out; goto close_out;
} }
if (repair) { if (repair) {

View File

@ -450,7 +450,8 @@ int link_inode_to_lostfound(struct btrfs_trans_handle *trans,
BTRFS_FIRST_FREE_OBJECTID, &lost_found_ino, BTRFS_FIRST_FREE_OBJECTID, &lost_found_ino,
mode); mode);
if (ret < 0) { 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; goto out;
} }
ret = btrfs_add_link(trans, root, ino, lost_found_ino, ret = btrfs_add_link(trans, root, ino, lost_found_ino,
@ -474,8 +475,9 @@ int link_inode_to_lostfound(struct btrfs_trans_handle *trans,
name_len, filetype, NULL, 1, 0); name_len, filetype, NULL, 1, 0);
} }
if (ret < 0) { if (ret < 0) {
error("failed to link the inode %llu to %s dir: %s", errno = -ret;
ino, dir_name, strerror(-ret)); error("failed to link the inode %llu to %s dir: %m",
ino, dir_name);
goto out; goto out;
} }

View File

@ -284,7 +284,8 @@ static int modify_block_groups_cache(struct btrfs_fs_info *fs_info, u64 flags,
btrfs_init_path(&path); btrfs_init_path(&path);
ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0); ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0);
if (ret < 0) { if (ret < 0) {
error("fail to search block groups due to %s", strerror(-ret)); errno = -ret;
error("fail to search block groups due to %m");
goto out; goto out;
} }
@ -341,19 +342,22 @@ static int create_chunk_and_block_group(struct btrfs_fs_info *fs_info,
trans = btrfs_start_transaction(root, 1); trans = btrfs_start_transaction(root, 1);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
ret = PTR_ERR(trans); ret = PTR_ERR(trans);
error("error starting transaction %s", strerror(-ret)); errno = -ret;
error("error starting transaction %m");
return ret; return ret;
} }
ret = btrfs_alloc_chunk(trans, fs_info, start, nbytes, flags); ret = btrfs_alloc_chunk(trans, fs_info, start, nbytes, flags);
if (ret) { if (ret) {
error("fail to allocate new chunk %s", strerror(-ret)); errno = -ret;
error("fail to allocate new chunk %m");
goto out; goto out;
} }
ret = btrfs_make_block_group(trans, fs_info, 0, flags, *start, ret = btrfs_make_block_group(trans, fs_info, 0, flags, *start,
*nbytes); *nbytes);
if (ret) { if (ret) {
error("fail to make block group for chunk %llu %llu %s", errno = -ret;
*start, *nbytes, strerror(-ret)); error("fail to make block group for chunk %llu %llu %m",
*start, *nbytes);
goto out; goto out;
} }
out: out:
@ -521,8 +525,10 @@ static int avoid_extents_overwrite(struct btrfs_fs_info *fs_info)
"Try to exclude all metadata blcoks and extents, it may be slow\n"); "Try to exclude all metadata blcoks and extents, it may be slow\n");
ret = exclude_metadata_blocks(fs_info); ret = exclude_metadata_blocks(fs_info);
out: out:
if (ret) if (ret) {
error("failed to avoid extents overwrite %s", strerror(-ret)); errno = -ret;
error("failed to avoid extents overwrite %m");
}
return ret; return ret;
} }
@ -552,7 +558,8 @@ static int repair_block_accounting(struct btrfs_fs_info *fs_info)
trans = btrfs_start_transaction(root, 1); trans = btrfs_start_transaction(root, 1);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
ret = PTR_ERR(trans); ret = PTR_ERR(trans);
error("fail to start transaction %s", strerror(-ret)); errno = -ret;
error("fail to start transaction: %m");
return ret; return ret;
} }
@ -629,7 +636,8 @@ static int repair_tree_block_ref(struct btrfs_root *root,
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
ret = PTR_ERR(trans); ret = PTR_ERR(trans);
trans = NULL; trans = NULL;
error("fail to start transaction %s", strerror(-ret)); errno = -ret;
error("fail to start transaction: %m");
goto out; goto out;
} }
/* insert an extent item */ /* insert an extent item */
@ -701,9 +709,10 @@ out:
btrfs_commit_transaction(trans, extent_root); btrfs_commit_transaction(trans, extent_root);
btrfs_release_path(&path); btrfs_release_path(&path);
if (ret) { if (ret) {
errno = -ret;
error( error(
"failed to repair tree block ref start %llu root %llu due to %s", "failed to repair tree block ref start %llu root %llu due to %m",
bytenr, root->objectid, strerror(-ret)); bytenr, root->objectid);
} else { } else {
printf("Added one tree block ref start %llu %s %llu\n", printf("Added one tree block ref start %llu %s %llu\n",
bytenr, parent ? "parent" : "root", bytenr, parent ? "parent" : "root",
@ -3006,7 +3015,8 @@ static int repair_extent_data_item(struct btrfs_root *root,
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
ret = PTR_ERR(trans); ret = PTR_ERR(trans);
trans = NULL; trans = NULL;
error("fail to start transaction %s", strerror(-ret)); errno = -ret;
error("fail to start transaction: %m");
goto out; goto out;
} }
/* insert an extent item */ /* insert an extent item */
@ -3820,7 +3830,8 @@ static int repair_extent_item(struct btrfs_root *root, struct btrfs_path *path,
trans = btrfs_start_transaction(extent_root, 1); trans = btrfs_start_transaction(extent_root, 1);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
ret = PTR_ERR(trans); ret = PTR_ERR(trans);
error("fail to start transaction %s", strerror(-ret)); errno = -ret;
error("fail to start transaction: %m");
/* nothing happened */ /* nothing happened */
ret = 0; ret = 0;
goto out; goto out;
@ -4281,7 +4292,8 @@ static int repair_chunk_item(struct btrfs_root *chunk_root,
trans = btrfs_start_transaction(extent_root, 1); trans = btrfs_start_transaction(extent_root, 1);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
ret = PTR_ERR(trans); ret = PTR_ERR(trans);
error("fail to start transaction %s", strerror(-ret)); errno = -ret;
error("fail to start transaction: %m");
return ret; return ret;
} }
@ -4316,7 +4328,8 @@ static int delete_extent_tree_item(struct btrfs_root *root,
trans = btrfs_start_transaction(root, 1); trans = btrfs_start_transaction(root, 1);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
ret = PTR_ERR(trans); ret = PTR_ERR(trans);
error("fail to start transaction %s", strerror(-ret)); errno = -ret;
error("fail to start transaction: %m");
goto out; goto out;
} }
btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);

View File

@ -442,8 +442,8 @@ static int cmd_device_stats(int argc, char **argv)
ret = get_fs_info(dev_path, &fi_args, &di_args); ret = get_fs_info(dev_path, &fi_args, &di_args);
if (ret) { if (ret) {
error("getting device info for %s failed: %s", dev_path, errno = -ret;
strerror(-ret)); error("getting device info for %s failed: %m", dev_path);
err = 1; err = 1;
goto out; goto out;
} }

View File

@ -406,9 +406,10 @@ static int du_walk_dir(struct du_dir_ctxt *ctxt, struct rb_root *shared_extents)
ret = 0; ret = 0;
continue; continue;
} else if (ret) { } else if (ret) {
errno = -ret;
fprintf(stderr, fprintf(stderr,
"failed to walk dir/file: %s :%s\n", "failed to walk dir/file: %s : %m\n",
entry->d_name, strerror(-ret)); entry->d_name);
break; break;
} }
@ -601,8 +602,8 @@ int cmd_filesystem_du(int argc, char **argv)
for (i = optind; i < argc; i++) { for (i = optind; i < argc; i++) {
ret = du_add_file(argv[i], AT_FDCWD, NULL, NULL, NULL, 1); ret = du_add_file(argv[i], AT_FDCWD, NULL, NULL, NULL, 1);
if (ret) { if (ret) {
error("cannot check space of '%s': %s", argv[i], errno = -ret;
strerror(-ret)); error("cannot check space of '%s': %m", argv[i]);
err = 1; err = 1;
} }

View File

@ -145,7 +145,8 @@ static int cmd_filesystem_df(int argc, char **argv)
print_df(sargs, unit_mode); print_df(sargs, unit_mode);
free(sargs); free(sargs);
} else { } else {
error("get_df failed %s", strerror(-ret)); errno = -ret;
error("get_df failed: %m");
} }
close_file_or_dir(fd, dirstream); close_file_or_dir(fd, dirstream);
@ -1054,8 +1055,8 @@ static int cmd_filesystem_defrag(int argc, char **argv)
break; break;
} }
if (ret) { if (ret) {
error("defrag failed on %s: %s", argv[i], errno = defrag_err;
strerror(defrag_err)); error("defrag failed on %s: %m", argv[i]);
goto next; goto next;
} }
} }

View File

@ -313,12 +313,13 @@ int cmd_inspect_dump_tree(int argc, char **argv)
ret = check_arg_type(argv[optind]); ret = check_arg_type(argv[optind]);
if (ret != BTRFS_ARG_BLKDEV && ret != BTRFS_ARG_REG) { if (ret != BTRFS_ARG_BLKDEV && ret != BTRFS_ARG_REG) {
if (ret < 0) if (ret < 0) {
error("invalid argument %s: %s", argv[optind], errno = -ret;
strerror(-ret)); error("invalid argument %s: %m", argv[optind]);
else } else {
error("not a block device or regular file: %s", error("not a block device or regular file: %s",
argv[optind]); argv[optind]);
}
goto out; goto out;
} }
@ -432,9 +433,9 @@ again:
key.type = BTRFS_ROOT_ITEM_KEY; key.type = BTRFS_ROOT_ITEM_KEY;
ret = btrfs_search_slot(NULL, tree_root_scan, &key, &path, 0, 0); ret = btrfs_search_slot(NULL, tree_root_scan, &key, &path, 0, 0);
if (ret < 0) { if (ret < 0) {
error("cannot read ROOT_ITEM from tree %llu: %s", errno = -ret;
(unsigned long long)tree_root_scan->root_key.objectid, error("cannot read ROOT_ITEM from tree %llu: %m",
strerror(-ret)); (unsigned long long)tree_root_scan->root_key.objectid);
goto close_root; goto close_root;
} }
while (1) { while (1) {

View File

@ -454,8 +454,8 @@ int cmd_inspect_tree_stats(int argc, char **argv)
ret = check_mounted(argv[optind]); ret = check_mounted(argv[optind]);
if (ret < 0) { if (ret < 0) {
warning("unable to check mount status of: %s", errno = -ret;
strerror(-ret)); warning("unable to check mount status of: %m");
} else if (ret) { } else if (ret) {
warning("%s already mounted, results may be inaccurate", warning("%s already mounted, results may be inaccurate",
argv[optind]); argv[optind]);

View File

@ -330,7 +330,8 @@ static int cmd_inspect_rootid(int argc, char **argv)
ret = lookup_path_rootid(fd, &rootid); ret = lookup_path_rootid(fd, &rootid);
if (ret) { if (ret) {
error("failed to lookup root id: %s", strerror(-ret)); errno = -ret;
error("failed to lookup root id: %m");
goto out; goto out;
} }
@ -565,7 +566,8 @@ static int print_min_dev_size(int fd, u64 devid)
ret = add_dev_extent(&holes, last_pos, ret = add_dev_extent(&holes, last_pos,
btrfs_search_header_offset(sh) - 1, 1); btrfs_search_header_offset(sh) - 1, 1);
if (ret) { if (ret) {
error("add device extent: %s", strerror(-ret)); errno = -ret;
error("add device extent: %m");
ret = 1; ret = 1;
goto out; goto out;
} }

View File

@ -91,7 +91,8 @@ static int check_is_root(const char *object)
ret = get_fsid(object, fsid, 0); ret = get_fsid(object, fsid, 0);
if (ret < 0) { if (ret < 0) {
error("get_fsid for %s failed: %s", object, strerror(-ret)); errno = -ret;
error("get_fsid for %s failed: %m", object);
goto out; goto out;
} }
@ -103,7 +104,8 @@ static int check_is_root(const char *object)
ret = 1; ret = 1;
goto out; goto out;
} else if (ret < 0) { } else if (ret < 0) {
error("get_fsid for %s failed: %s", tmp, strerror(-ret)); errno = -ret;
error("get_fsid for %s failed: %m", tmp);
goto out; goto out;
} }
@ -317,8 +319,8 @@ static void parse_args(int argc, char **argv,
if (!*types) { if (!*types) {
ret = autodetect_object_types(*object, types); ret = autodetect_object_types(*object, types);
if (ret < 0) { if (ret < 0) {
error("failed to detect object type: %s", errno = -ret;
strerror(-ret)); error("failed to detect object type: %m");
usage(usage_str); usage(usage_str);
} }
if (!*types) { if (!*types) {

View File

@ -386,8 +386,8 @@ static int cmd_qgroup_show(int argc, char **argv)
if (filter_flag) { if (filter_flag) {
ret = lookup_path_rootid(fd, &qgroupid); ret = lookup_path_rootid(fd, &qgroupid);
if (ret < 0) { if (ret < 0) {
error("cannot resolve rootid for %s: %s", errno = -ret;
path, strerror(-ret)); error("cannot resolve rootid for %s: %m", path);
close_file_or_dir(fd, dirstream); close_file_or_dir(fd, dirstream);
goto out; goto out;
} }

View File

@ -103,8 +103,7 @@ static int finish_subvol(struct btrfs_receive *rctx)
O_RDONLY | O_NOATIME); O_RDONLY | O_NOATIME);
if (subvol_fd < 0) { if (subvol_fd < 0) {
ret = -errno; ret = -errno;
error("cannot open %s: %s", error("cannot open %s: %m", rctx->cur_subvol_path);
rctx->cur_subvol_path, strerror(-ret));
goto out; goto out;
} }
@ -121,8 +120,7 @@ static int finish_subvol(struct btrfs_receive *rctx)
ret = ioctl(subvol_fd, BTRFS_IOC_SET_RECEIVED_SUBVOL, &rs_args); ret = ioctl(subvol_fd, BTRFS_IOC_SET_RECEIVED_SUBVOL, &rs_args);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("ioctl BTRFS_IOC_SET_RECEIVED_SUBVOL failed: %s", error("ioctl BTRFS_IOC_SET_RECEIVED_SUBVOL failed: %m");
strerror(-ret));
goto out; goto out;
} }
rctx->cur_subvol.rtransid = rs_args.rtransid; rctx->cur_subvol.rtransid = rs_args.rtransid;
@ -130,8 +128,7 @@ static int finish_subvol(struct btrfs_receive *rctx)
ret = ioctl(subvol_fd, BTRFS_IOC_SUBVOL_GETFLAGS, &flags); ret = ioctl(subvol_fd, BTRFS_IOC_SUBVOL_GETFLAGS, &flags);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("ioctl BTRFS_IOC_SUBVOL_GETFLAGS failed: %s", error("ioctl BTRFS_IOC_SUBVOL_GETFLAGS failed: %m");
strerror(-ret));
goto out; goto out;
} }
@ -140,8 +137,7 @@ static int finish_subvol(struct btrfs_receive *rctx)
ret = ioctl(subvol_fd, BTRFS_IOC_SUBVOL_SETFLAGS, &flags); ret = ioctl(subvol_fd, BTRFS_IOC_SUBVOL_SETFLAGS, &flags);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("failed to make subvolume read only: %s", error("failed to make subvolume read only: %m");
strerror(-ret));
goto out; goto out;
} }
@ -215,7 +211,7 @@ static int process_subvol(const char *path, const u8 *uuid, u64 ctransid,
ret = ioctl(rctx->dest_dir_fd, BTRFS_IOC_SUBVOL_CREATE, &args_v1); ret = ioctl(rctx->dest_dir_fd, BTRFS_IOC_SUBVOL_CREATE, &args_v1);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("creating subvolume %s failed: %s", path, strerror(-ret)); error("creating subvolume %s failed: %m", path);
goto out; goto out;
} }
@ -360,8 +356,7 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
if (args_v2.fd < 0) { if (args_v2.fd < 0) {
ret = -errno; ret = -errno;
if (errno != ENOENT) if (errno != ENOENT)
error("cannot open %s: %s", error("cannot open %s: %m", parent_subvol->path);
parent_subvol->path, strerror(-ret));
else else
fprintf(stderr, fprintf(stderr,
"It seems that you have changed your default " "It seems that you have changed your default "
@ -375,8 +370,8 @@ static int process_snapshot(const char *path, const u8 *uuid, u64 ctransid,
close(args_v2.fd); close(args_v2.fd);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("creating snapshot %s -> %s failed: %s", error("creating snapshot %s -> %s failed: %m",
parent_subvol->path, path, strerror(-ret)); parent_subvol->path, path);
goto out; goto out;
} }
@ -406,7 +401,7 @@ static int process_mkfile(const char *path, void *user)
ret = creat(full_path, 0600); ret = creat(full_path, 0600);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("mkfile %s failed: %s", path, strerror(-ret)); error("mkfile %s failed: %m", path);
goto out; goto out;
} }
close(ret); close(ret);
@ -434,7 +429,7 @@ static int process_mkdir(const char *path, void *user)
ret = mkdir(full_path, 0700); ret = mkdir(full_path, 0700);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("mkdir %s failed: %s", path, strerror(-ret)); error("mkdir %s failed: %m", path);
} }
out: out:
@ -460,7 +455,7 @@ static int process_mknod(const char *path, u64 mode, u64 dev, void *user)
ret = mknod(full_path, mode & S_IFMT, dev); ret = mknod(full_path, mode & S_IFMT, dev);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("mknod %s failed: %s", path, strerror(-ret)); error("mknod %s failed: %m", path);
} }
out: out:
@ -485,7 +480,7 @@ static int process_mkfifo(const char *path, void *user)
ret = mkfifo(full_path, 0600); ret = mkfifo(full_path, 0600);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("mkfifo %s failed: %s", path, strerror(-ret)); error("mkfifo %s failed: %m", path);
} }
out: out:
@ -510,7 +505,7 @@ static int process_mksock(const char *path, void *user)
ret = mknod(full_path, 0600 | S_IFSOCK, 0); ret = mknod(full_path, 0600 | S_IFSOCK, 0);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("mknod %s failed: %s", path, strerror(-ret)); error("mknod %s failed: %m", path);
} }
out: out:
@ -535,8 +530,7 @@ static int process_symlink(const char *path, const char *lnk, void *user)
ret = symlink(lnk, full_path); ret = symlink(lnk, full_path);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("symlink %s -> %s failed: %s", path, error("symlink %s -> %s failed: %m", path, lnk);
lnk, strerror(-ret));
} }
out: out:
@ -568,8 +562,7 @@ static int process_rename(const char *from, const char *to, void *user)
ret = rename(full_from, full_to); ret = rename(full_from, full_to);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("rename %s -> %s failed: %s", from, error("rename %s -> %s failed: %m", from, to);
to, strerror(-ret));
} }
out: out:
@ -601,7 +594,7 @@ static int process_link(const char *path, const char *lnk, void *user)
ret = link(full_link_path, full_path); ret = link(full_link_path, full_path);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("link %s -> %s failed: %s", path, lnk, strerror(-ret)); error("link %s -> %s failed: %m", path, lnk);
} }
out: out:
@ -627,7 +620,7 @@ static int process_unlink(const char *path, void *user)
ret = unlink(full_path); ret = unlink(full_path);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("unlink %s failed. %s", path, strerror(-ret)); error("unlink %s failed: %m", path);
} }
out: out:
@ -652,7 +645,7 @@ static int process_rmdir(const char *path, void *user)
ret = rmdir(full_path); ret = rmdir(full_path);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("rmdir %s failed: %s", path, strerror(-ret)); error("rmdir %s failed: %m", path);
} }
out: out:
@ -673,7 +666,7 @@ static int open_inode_for_write(struct btrfs_receive *rctx, const char *path)
rctx->write_fd = open(path, O_RDWR); rctx->write_fd = open(path, O_RDWR);
if (rctx->write_fd < 0) { if (rctx->write_fd < 0) {
ret = -errno; ret = -errno;
error("cannot open %s: %s", path, strerror(-ret)); error("cannot open %s: %m", path);
goto out; goto out;
} }
strncpy_null(rctx->write_path, path); strncpy_null(rctx->write_path, path);
@ -716,8 +709,7 @@ static int process_write(const char *path, const void *data, u64 offset,
offset + pos); offset + pos);
if (w < 0) { if (w < 0) {
ret = -errno; ret = -errno;
error("writing to %s failed: %s", error("writing to %s failed: %m", path);
path, strerror(-ret));
goto out; goto out;
} }
pos += w; pos += w;
@ -812,7 +804,7 @@ static int process_clone(const char *path, u64 offset, u64 len,
clone_fd = openat(rctx->mnt_fd, full_clone_path, O_RDONLY | O_NOATIME); clone_fd = openat(rctx->mnt_fd, full_clone_path, O_RDONLY | O_NOATIME);
if (clone_fd < 0) { if (clone_fd < 0) {
ret = -errno; ret = -errno;
error("cannot open %s: %s", full_clone_path, strerror(-ret)); error("cannot open %s: %m", full_clone_path);
goto out; goto out;
} }
@ -823,8 +815,7 @@ static int process_clone(const char *path, u64 offset, u64 len,
ret = ioctl(rctx->write_fd, BTRFS_IOC_CLONE_RANGE, &clone_args); ret = ioctl(rctx->write_fd, BTRFS_IOC_CLONE_RANGE, &clone_args);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("failed to clone extents to %s\n%s", error("failed to clone extents to %s: %m", path);
path, strerror(-ret));
goto out; goto out;
} }
@ -878,8 +869,8 @@ static int process_set_xattr(const char *path, const char *name,
ret = lsetxattr(full_path, name, data, len, 0); ret = lsetxattr(full_path, name, data, len, 0);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("lsetxattr %s %s=%.*s failed: %s", error("lsetxattr %s %s=%.*s failed: %m",
path, name, len, (char*)data, strerror(-ret)); path, name, len, (char*)data);
goto out; goto out;
} }
@ -907,8 +898,7 @@ static int process_remove_xattr(const char *path, const char *name, void *user)
ret = lremovexattr(full_path, name); ret = lremovexattr(full_path, name);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("lremovexattr %s %s failed: %s", error("lremovexattr %s %s failed: %m", path, name);
path, name, strerror(-ret));
goto out; goto out;
} }
@ -934,7 +924,7 @@ static int process_truncate(const char *path, u64 size, void *user)
ret = truncate(full_path, size); ret = truncate(full_path, size);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("truncate %s failed: %s", path, strerror(-ret)); error("truncate %s failed: %m", path);
goto out; goto out;
} }
@ -960,7 +950,7 @@ static int process_chmod(const char *path, u64 mode, void *user)
ret = chmod(full_path, mode); ret = chmod(full_path, mode);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("chmod %s failed: %s", path, strerror(-ret)); error("chmod %s failed: %m", path);
goto out; goto out;
} }
@ -987,7 +977,7 @@ static int process_chown(const char *path, u64 uid, u64 gid, void *user)
ret = lchown(full_path, uid, gid); ret = lchown(full_path, uid, gid);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("chown %s failed: %s", path, strerror(-ret)); error("chown %s failed: %m", path);
goto out; goto out;
} }
@ -1002,8 +992,7 @@ static int process_chown(const char *path, u64 uid, u64 gid, void *user)
rctx->cached_capabilities_len = 0; rctx->cached_capabilities_len = 0;
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("restoring capabilities %s: %s", error("restoring capabilities %s: %m", path);
path, strerror(-ret));
goto out; goto out;
} }
} }
@ -1035,8 +1024,7 @@ static int process_utimes(const char *path, struct timespec *at,
ret = utimensat(AT_FDCWD, full_path, tv, AT_SYMLINK_NOFOLLOW); ret = utimensat(AT_FDCWD, full_path, tv, AT_SYMLINK_NOFOLLOW);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("utimes %s failed: %s", error("utimes %s failed: %m", path);
path, strerror(-ret));
goto out; goto out;
} }
@ -1096,14 +1084,14 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
dest_dir_full_path = realpath(tomnt, NULL); dest_dir_full_path = realpath(tomnt, NULL);
if (!dest_dir_full_path) { if (!dest_dir_full_path) {
ret = -errno; ret = -errno;
error("realpath(%s) failed: %s", tomnt, strerror(-ret)); error("realpath(%s) failed: %m", tomnt);
goto out; goto out;
} }
rctx->dest_dir_fd = open(dest_dir_full_path, O_RDONLY | O_NOATIME); rctx->dest_dir_fd = open(dest_dir_full_path, O_RDONLY | O_NOATIME);
if (rctx->dest_dir_fd < 0) { if (rctx->dest_dir_fd < 0) {
ret = -errno; ret = -errno;
error("cannot open destination directory %s: %s", error("cannot open destination directory %s: %m",
dest_dir_full_path, strerror(-ret)); dest_dir_full_path);
goto out; goto out;
} }
@ -1112,8 +1100,9 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
} else { } else {
ret = find_mount_root(dest_dir_full_path, &rctx->root_path); ret = find_mount_root(dest_dir_full_path, &rctx->root_path);
if (ret < 0) { if (ret < 0) {
error("failed to determine mount point for %s: %s", errno = -ret;
dest_dir_full_path, strerror(-ret)); error("failed to determine mount point for %s: %m",
dest_dir_full_path);
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
@ -1127,7 +1116,7 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
rctx->mnt_fd = open(rctx->root_path, O_RDONLY | O_NOATIME); rctx->mnt_fd = open(rctx->root_path, O_RDONLY | O_NOATIME);
if (rctx->mnt_fd < 0) { if (rctx->mnt_fd < 0) {
ret = -errno; ret = -errno;
error("cannot open %s: %s", rctx->root_path, strerror(-ret)); error("cannot open %s: %m", rctx->root_path);
goto out; goto out;
} }
@ -1158,14 +1147,12 @@ static int do_receive(struct btrfs_receive *rctx, const char *tomnt,
if (rctx->dest_dir_chroot) { if (rctx->dest_dir_chroot) {
if (chroot(dest_dir_full_path)) { if (chroot(dest_dir_full_path)) {
ret = -errno; ret = -errno;
error("failed to chroot to %s: %s", error("failed to chroot to %s: %m", dest_dir_full_path);
dest_dir_full_path, strerror(-ret));
goto out; goto out;
} }
if (chdir("/")) { if (chdir("/")) {
ret = -errno; ret = -errno;
error("failed to chdir to / after chroot: %s", error("failed to chdir to / after chroot: %m");
strerror(-ret));
goto out; goto out;
} }
fprintf(stderr, "Chroot to %s\n", dest_dir_full_path); fprintf(stderr, "Chroot to %s\n", dest_dir_full_path);
@ -1345,9 +1332,10 @@ int cmd_receive(int argc, char **argv)
dump_args.full_subvol_path[1] = '\0'; dump_args.full_subvol_path[1] = '\0';
ret = btrfs_read_and_process_send_stream(receive_fd, ret = btrfs_read_and_process_send_stream(receive_fd,
&btrfs_print_send_ops, &dump_args, 0, 0); &btrfs_print_send_ops, &dump_args, 0, 0);
if (ret < 0) if (ret < 0) {
error("failed to dump the send stream: %s", errno = -ret;
strerror(-ret)); error("failed to dump the send stream: %m");
}
} else { } else {
ret = do_receive(&rctx, tomnt, realmnt, receive_fd, max_errors); ret = do_receive(&rctx, tomnt, realmnt, receive_fd, max_errors);
} }

View File

@ -208,7 +208,8 @@ static int cmd_replace_start(int argc, char **argv)
ret = get_fs_info(path, &fi_args, &di_args); ret = get_fs_info(path, &fi_args, &di_args);
if (ret) { if (ret) {
error("failed to get device info: %s", strerror(-ret)); errno = -ret;
error("failed to get device info: %m");
free(di_args); free(di_args);
goto leave_with_error; goto leave_with_error;
} }

View File

@ -77,7 +77,8 @@ static int cmd_rescue_chunk_recover(int argc, char *argv[])
ret = check_mounted(file); ret = check_mounted(file);
if (ret < 0) { if (ret < 0) {
error("could not check mount status: %s", strerror(-ret)); errno = -ret;
error("could not check mount status: %m");
return 1; return 1;
} else if (ret) { } else if (ret) {
error("the device is busy"); error("the device is busy");
@ -142,7 +143,8 @@ static int cmd_rescue_super_recover(int argc, char **argv)
dname = argv[optind]; dname = argv[optind];
ret = check_mounted(dname); ret = check_mounted(dname);
if (ret < 0) { if (ret < 0) {
error("could not check mount status: %s", strerror(-ret)); errno = -ret;
error("could not check mount status: %m");
return 1; return 1;
} else if (ret) { } else if (ret) {
error("the device is busy"); error("the device is busy");
@ -175,7 +177,8 @@ static int cmd_rescue_zero_log(int argc, char **argv)
devname = argv[optind]; devname = argv[optind];
ret = check_mounted(devname); ret = check_mounted(devname);
if (ret < 0) { if (ret < 0) {
error("could not check mount status: %s", strerror(-ret)); errno = -ret;
error("could not check mount status: %m");
goto out; goto out;
} else if (ret) { } else if (ret) {
error("%s is currently mounted", devname); error("%s is currently mounted", devname);
@ -226,7 +229,8 @@ static int cmd_rescue_fix_device_size(int argc, char **argv)
devname = argv[optind]; devname = argv[optind];
ret = check_mounted(devname); ret = check_mounted(devname);
if (ret < 0) { if (ret < 0) {
error("could not check mount status: %s", strerror(-ret)); errno = -ret;
error("could not check mount status: %m");
goto out; goto out;
} else if (ret) { } else if (ret) {
error("%s is currently mounted", devname); error("%s is currently mounted", devname);

View File

@ -1542,8 +1542,8 @@ int cmd_restore(int argc, char **argv)
} }
if ((ret = check_mounted(argv[optind])) < 0) { if ((ret = check_mounted(argv[optind])) < 0) {
fprintf(stderr, "Could not check mount status: %s\n", errno = -ret;
strerror(-ret)); fprintf(stderr, "Could not check mount status: %m\n");
return 1; return 1;
} else if (ret) { } else if (ret) {
fprintf(stderr, "%s is currently mounted. Aborting.\n", argv[optind]); fprintf(stderr, "%s is currently mounted. Aborting.\n", argv[optind]);
@ -1591,8 +1591,9 @@ int cmd_restore(int argc, char **argv)
key.offset = (u64)-1; key.offset = (u64)-1;
root = btrfs_read_fs_root(orig_root->fs_info, &key); root = btrfs_read_fs_root(orig_root->fs_info, &key);
if (IS_ERR(root)) { if (IS_ERR(root)) {
fprintf(stderr, "fail to read root %llu: %s\n", errno = -PTR_ERR(root);
root_objectid, strerror(-PTR_ERR(root))); fprintf(stderr, "fail to read root %llu: %m\n",
root_objectid);
root = orig_root; root = orig_root;
ret = 1; ret = 1;
goto out; goto out;

View File

@ -1206,9 +1206,9 @@ static int scrub_start(int argc, char **argv, int resume)
ret = get_fs_info(path, &fi_args, &di_args); ret = get_fs_info(path, &fi_args, &di_args);
if (ret) { if (ret) {
errno = -ret;
error_on(!do_quiet, error_on(!do_quiet,
"getting dev info for scrub failed: %s", "getting dev info for scrub failed: %m");
strerror(-ret));
err = 1; err = 1;
goto out; goto out;
} }
@ -1221,13 +1221,14 @@ static int scrub_start(int argc, char **argv, int resume)
uuid_unparse(fi_args.fsid, fsid); uuid_unparse(fi_args.fsid, fsid);
fdres = scrub_open_file_r(SCRUB_DATA_FILE, fsid); fdres = scrub_open_file_r(SCRUB_DATA_FILE, fsid);
if (fdres < 0 && fdres != -ENOENT) { if (fdres < 0 && fdres != -ENOENT) {
warning_on(!do_quiet, "failed to open status file: %s", errno = -fdres;
strerror(-fdres)); warning_on(!do_quiet, "failed to open status file: %m");
} else if (fdres >= 0) { } else if (fdres >= 0) {
past_scrubs = scrub_read_file(fdres, !do_quiet); past_scrubs = scrub_read_file(fdres, !do_quiet);
if (IS_ERR(past_scrubs)) if (IS_ERR(past_scrubs)) {
warning_on(!do_quiet, "failed to read status file: %s", errno = -PTR_ERR(past_scrubs);
strerror(-PTR_ERR(past_scrubs))); warning_on(!do_quiet, "failed to read status file: %m");
}
close(fdres); close(fdres);
} }
@ -1273,8 +1274,8 @@ static int scrub_start(int argc, char **argv, int resume)
devid = di_args[i].devid; devid = di_args[i].devid;
ret = pthread_mutex_init(&sp[i].progress_mutex, NULL); ret = pthread_mutex_init(&sp[i].progress_mutex, NULL);
if (ret) { if (ret) {
error_on(!do_quiet, "pthread_mutex_init failed: %s", errno = ret;
strerror(ret)); error_on(!do_quiet, "pthread_mutex_init failed: %m");
err = 1; err = 1;
goto out; goto out;
} }
@ -1359,9 +1360,9 @@ static int scrub_start(int argc, char **argv, int resume)
ret = scrub_write_progress(&spc_write_mutex, fsid, sp, ret = scrub_write_progress(&spc_write_mutex, fsid, sp,
fi_args.num_devices); fi_args.num_devices);
if (ret) { if (ret) {
errno = -ret;
warning_on(!do_quiet, warning_on(!do_quiet,
"failed to write the progress status file: %s. Status recording disabled", "failed to write the progress status file: %m. Status recording disabled");
strerror(-ret));
do_record = 0; do_record = 0;
} }
} }
@ -1418,9 +1419,12 @@ static int scrub_start(int argc, char **argv, int resume)
ret = pthread_create(&t_devs[i], NULL, ret = pthread_create(&t_devs[i], NULL,
scrub_one_dev, &sp[i]); scrub_one_dev, &sp[i]);
if (ret) { if (ret) {
if (do_print) if (do_print) {
error("creating scrub_one_dev[%llu] thread failed: %s", errno = ret;
devid, strerror(ret)); error(
"creating scrub_one_dev[%llu] thread failed: %m",
devid);
}
err = 1; err = 1;
goto out; goto out;
} }
@ -1434,9 +1438,10 @@ static int scrub_start(int argc, char **argv, int resume)
spc.fi = &fi_args; spc.fi = &fi_args;
ret = pthread_create(&t_prog, NULL, scrub_progress_cycle, &spc); ret = pthread_create(&t_prog, NULL, scrub_progress_cycle, &spc);
if (ret) { if (ret) {
if (do_print) if (do_print) {
error("creating progress thread failed: %s", errno = ret;
strerror(ret)); error("creating progress thread failed: %m");
}
err = 1; err = 1;
goto out; goto out;
} }
@ -1448,9 +1453,12 @@ static int scrub_start(int argc, char **argv, int resume)
devid = di_args[i].devid; devid = di_args[i].devid;
ret = pthread_join(t_devs[i], NULL); ret = pthread_join(t_devs[i], NULL);
if (ret) { if (ret) {
if (do_print) if (do_print) {
error("pthread_join failed for scrub_one_dev[%llu]: %s", errno = ret;
devid, strerror(ret)); error(
"pthread_join failed for scrub_one_dev[%llu]: %m",
devid);
}
++err; ++err;
continue; continue;
} }
@ -1465,11 +1473,13 @@ static int scrub_start(int argc, char **argv, int resume)
++err; ++err;
break; break;
default: default:
if (do_print) if (do_print) {
error("scrubbing %s failed for device id %lld: ret=%d, errno=%d (%s)", errno = sp[i].ioctl_errno;
path, devid, error(
sp[i].ret, sp[i].ioctl_errno, "scrubbing %s failed for device id %lld: ret=%d, errno=%d (%m)",
strerror(sp[i].ioctl_errno)); path, devid, sp[i].ret,
sp[i].ioctl_errno);
}
++err; ++err;
continue; continue;
} }
@ -1511,21 +1521,23 @@ static int scrub_start(int argc, char **argv, int resume)
/* check for errors from the handling of the progress thread */ /* check for errors from the handling of the progress thread */
if (do_print && ret) { if (do_print && ret) {
error("progress thread handling failed: %s", errno = ret;
strerror(ret)); error("progress thread handling failed: %m");
} }
/* check for errors returned from the progress thread itself */ /* check for errors returned from the progress thread itself */
if (do_print && terr && terr != PTHREAD_CANCELED) if (do_print && terr && terr != PTHREAD_CANCELED) {
error("recording progress failed: %s", errno = -PTR_ERR(terr);
strerror(-PTR_ERR(terr))); error("recording progress failed: %m");
}
if (do_record) { if (do_record) {
ret = scrub_write_progress(&spc_write_mutex, fsid, sp, ret = scrub_write_progress(&spc_write_mutex, fsid, sp,
fi_args.num_devices); fi_args.num_devices);
if (ret && do_print) if (ret && do_print) {
error("failed to record the result: %s", errno = -ret;
strerror(-ret)); error("failed to record the result: %m");
}
} }
scrub_handle_sigint_child(-1); scrub_handle_sigint_child(-1);
@ -1701,8 +1713,8 @@ static int cmd_scrub_status(int argc, char **argv)
ret = get_fs_info(path, &fi_args, &di_args); ret = get_fs_info(path, &fi_args, &di_args);
if (ret) { if (ret) {
error("getting dev info for scrub failed: %s", errno = -ret;
strerror(-ret)); error("getting dev info for scrub failed: %m");
err = 1; err = 1;
goto out; goto out;
} }
@ -1729,8 +1741,8 @@ static int cmd_scrub_status(int argc, char **argv)
close(fdres); close(fdres);
fdres = scrub_open_file_r(SCRUB_DATA_FILE, fsid); fdres = scrub_open_file_r(SCRUB_DATA_FILE, fsid);
if (fdres < 0 && fdres != -ENOENT) { if (fdres < 0 && fdres != -ENOENT) {
warning("failed to open status file: %s", errno = -fdres;
strerror(-fdres)); warning("failed to open status file: %m");
err = 1; err = 1;
goto out; goto out;
} }
@ -1738,9 +1750,10 @@ static int cmd_scrub_status(int argc, char **argv)
if (fdres >= 0) { if (fdres >= 0) {
past_scrubs = scrub_read_file(fdres, 1); past_scrubs = scrub_read_file(fdres, 1);
if (IS_ERR(past_scrubs)) if (IS_ERR(past_scrubs)) {
warning("failed to read status: %s", errno = -PTR_ERR(past_scrubs);
strerror(-PTR_ERR(past_scrubs))); warning("failed to read status: %m");
}
} }
in_progress = is_scrub_running_in_kernel(fdmnt, di_args, fi_args.num_devices); in_progress = is_scrub_running_in_kernel(fdmnt, di_args, fi_args.num_devices);

View File

@ -281,8 +281,7 @@ static void *read_sent_data(void *arg)
NULL, SEND_BUFFER_SIZE, SPLICE_F_MORE); NULL, SEND_BUFFER_SIZE, SPLICE_F_MORE);
if (sbytes < 0) { if (sbytes < 0) {
ret = -errno; ret = -errno;
error("failed to read stream from kernel: %s", error("failed to read stream from kernel: %m");
strerror(-ret));
goto out; goto out;
} }
if (!sbytes) { if (!sbytes) {
@ -312,14 +311,14 @@ static int do_send(struct btrfs_send *send, u64 parent_root_id,
subvol_fd = openat(send->mnt_fd, subvol, O_RDONLY | O_NOATIME); subvol_fd = openat(send->mnt_fd, subvol, O_RDONLY | O_NOATIME);
if (subvol_fd < 0) { if (subvol_fd < 0) {
ret = -errno; ret = -errno;
error("cannot open %s: %s", subvol, strerror(-ret)); error("cannot open %s: %m", subvol);
goto out; goto out;
} }
ret = pipe(pipefd); ret = pipe(pipefd);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("pipe failed: %s", strerror(-ret)); error("pipe failed: %m");
goto out; goto out;
} }
@ -331,7 +330,8 @@ static int do_send(struct btrfs_send *send, u64 parent_root_id,
ret = pthread_create(&t_read, NULL, read_sent_data, send); ret = pthread_create(&t_read, NULL, read_sent_data, send);
if (ret) { if (ret) {
ret = -ret; ret = -ret;
error("thread setup failed: %s", strerror(-ret)); errno = -ret;
error("thread setup failed: %m");
goto out; goto out;
} }
@ -346,7 +346,7 @@ static int do_send(struct btrfs_send *send, u64 parent_root_id,
ret = ioctl(subvol_fd, BTRFS_IOC_SEND, &io_send); ret = ioctl(subvol_fd, BTRFS_IOC_SEND, &io_send);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("send ioctl failed with %d: %s", ret, strerror(-ret)); error("send ioctl failed with %d: %m", ret);
if (ret == -EINVAL && (!is_first_subvol || !is_last_subvol)) if (ret == -EINVAL && (!is_first_subvol || !is_last_subvol))
fprintf(stderr, fprintf(stderr,
"Try upgrading your kernel or don't use -e.\n"); "Try upgrading your kernel or don't use -e.\n");
@ -364,7 +364,8 @@ static int do_send(struct btrfs_send *send, u64 parent_root_id,
ret = pthread_join(t_read, &t_err); ret = pthread_join(t_read, &t_err);
if (ret) { if (ret) {
ret = -ret; ret = -ret;
error("pthread_join failed: %s", strerror(-ret)); errno = -ret;
error("pthread_join failed: %m");
goto out; goto out;
} }
if (t_err) { if (t_err) {
@ -395,8 +396,8 @@ static int init_root_path(struct btrfs_send *sctx, const char *subvol)
ret = find_mount_root(subvol, &sctx->root_path); ret = find_mount_root(subvol, &sctx->root_path);
if (ret < 0) { if (ret < 0) {
error("failed to determine mount point for %s: %s", errno = -ret;
subvol, strerror(-ret)); error("failed to determine mount point for %s: %m", subvol);
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
@ -409,14 +410,14 @@ static int init_root_path(struct btrfs_send *sctx, const char *subvol)
sctx->mnt_fd = open(sctx->root_path, O_RDONLY | O_NOATIME); sctx->mnt_fd = open(sctx->root_path, O_RDONLY | O_NOATIME);
if (sctx->mnt_fd < 0) { if (sctx->mnt_fd < 0) {
ret = -errno; ret = -errno;
error("cannot open '%s': %s", sctx->root_path, strerror(-ret)); error("cannot open '%s': %m", sctx->root_path);
goto out; goto out;
} }
ret = subvol_uuid_search_init(sctx->mnt_fd, &sctx->sus); ret = subvol_uuid_search_init(sctx->mnt_fd, &sctx->sus);
if (ret < 0) { if (ret < 0) {
error("failed to initialize subvol search: %s", errno = -ret;
strerror(-ret)); error("failed to initialize subvol search: %m");
goto out; goto out;
} }
@ -434,15 +435,14 @@ static int is_subvol_ro(struct btrfs_send *sctx, const char *subvol)
fd = openat(sctx->mnt_fd, subvol, O_RDONLY | O_NOATIME); fd = openat(sctx->mnt_fd, subvol, O_RDONLY | O_NOATIME);
if (fd < 0) { if (fd < 0) {
ret = -errno; ret = -errno;
error("cannot open %s: %s", subvol, strerror(-ret)); error("cannot open %s: %m", subvol);
goto out; goto out;
} }
ret = ioctl(fd, BTRFS_IOC_SUBVOL_GETFLAGS, &flags); ret = ioctl(fd, BTRFS_IOC_SUBVOL_GETFLAGS, &flags);
if (ret < 0) { if (ret < 0) {
ret = -errno; ret = -errno;
error("failed to get flags for subvolume %s: %s", error("failed to get flags for subvolume %s: %m", subvol);
subvol, strerror(-ret));
goto out; goto out;
} }
@ -535,7 +535,7 @@ int cmd_send(int argc, char **argv)
subvol = realpath(optarg, NULL); subvol = realpath(optarg, NULL);
if (!subvol) { if (!subvol) {
ret = -errno; ret = -errno;
error("realpath %s failed: %s\n", optarg, strerror(-ret)); error("realpath %s failed: %m\n", optarg);
goto out; goto out;
} }
@ -554,7 +554,8 @@ int cmd_send(int argc, char **argv)
ret = add_clone_source(&send, root_id); ret = add_clone_source(&send, root_id);
if (ret < 0) { if (ret < 0) {
error("cannot add clone source: %s", strerror(-ret)); errno = -ret;
error("cannot add clone source: %m");
goto out; goto out;
} }
free(subvol); free(subvol);
@ -578,7 +579,7 @@ int cmd_send(int argc, char **argv)
snapshot_parent = realpath(optarg, NULL); snapshot_parent = realpath(optarg, NULL);
if (!snapshot_parent) { if (!snapshot_parent) {
ret = -errno; ret = -errno;
error("realpath %s failed: %s", optarg, strerror(-ret)); error("realpath %s failed: %m", optarg);
goto out; goto out;
} }
@ -629,7 +630,7 @@ int cmd_send(int argc, char **argv)
send.dump_fd = tmpfd; send.dump_fd = tmpfd;
if (send.dump_fd == -1) { if (send.dump_fd == -1) {
ret = -errno; ret = -errno;
error("cannot create '%s': %s", outname, strerror(-ret)); error("cannot create '%s': %m", outname);
goto out; goto out;
} }
} }
@ -664,7 +665,8 @@ int cmd_send(int argc, char **argv)
ret = add_clone_source(&send, parent_root_id); ret = add_clone_source(&send, parent_root_id);
if (ret < 0) { if (ret < 0) {
error("cannot add clone source: %s", strerror(-ret)); errno = -ret;
error("cannot add clone source: %m");
goto out; goto out;
} }
} }
@ -680,8 +682,8 @@ int cmd_send(int argc, char **argv)
ret = find_mount_root(subvol, &mount_root); ret = find_mount_root(subvol, &mount_root);
if (ret < 0) { if (ret < 0) {
error("find_mount_root failed on %s: %s", subvol, errno = -ret;
strerror(-ret)); error("find_mount_root failed on %s: %m", subvol);
goto out; goto out;
} }
if (ret > 0) { if (ret > 0) {
@ -724,7 +726,7 @@ int cmd_send(int argc, char **argv)
subvol = realpath(subvol, NULL); subvol = realpath(subvol, NULL);
if (!subvol) { if (!subvol) {
ret = -errno; ret = -errno;
error("realpath %s failed: %s", argv[i], strerror(-ret)); error("realpath %s failed: %m", argv[i]);
goto out; goto out;
} }
@ -759,7 +761,8 @@ int cmd_send(int argc, char **argv)
/* done with this subvol, so add it to the clone sources */ /* done with this subvol, so add it to the clone sources */
ret = add_clone_source(&send, root_id); ret = add_clone_source(&send, root_id);
if (ret < 0) { if (ret < 0) {
error("cannot add clone source: %s", strerror(-ret)); errno = -ret;
error("cannot add clone source: %m");
goto out; goto out;
} }
free_send_info(&send); free_send_info(&send);

View File

@ -136,7 +136,8 @@ static int cmd_subvol_create(int argc, char **argv)
retval = 1; /* failure */ retval = 1; /* failure */
res = test_isdir(dst); res = test_isdir(dst);
if (res < 0 && res != -ENOENT) { if (res < 0 && res != -ENOENT) {
error("cannot access %s: %s", dst, strerror(-res)); errno = -res;
error("cannot access %s: %m", dst);
goto out; goto out;
} }
if (res >= 0) { if (res >= 0) {
@ -337,8 +338,8 @@ again:
} else if (commit_mode == COMMIT_AFTER) { } else if (commit_mode == COMMIT_AFTER) {
res = get_fsid(dname, fsid, 0); res = get_fsid(dname, fsid, 0);
if (res < 0) { if (res < 0) {
error("unable to get fsid for '%s': %s", errno = -res;
path, strerror(-res)); error("unable to get fsid for '%s': %m", path);
error( error(
"delete succeeded but commit may not be done in the end"); "delete succeeded but commit may not be done in the end");
ret = 1; ret = 1;
@ -690,7 +691,8 @@ static int cmd_subvol_snapshot(int argc, char **argv)
res = test_isdir(dst); res = test_isdir(dst);
if (res < 0 && res != -ENOENT) { if (res < 0 && res != -ENOENT) {
error("cannot access %s: %s", dst, strerror(-res)); errno = -res;
error("cannot access %s: %m", dst);
goto out; goto out;
} }
if (res == 0) { if (res == 0) {

View File

@ -318,10 +318,12 @@ static int create_image_file_range(struct btrfs_trans_handle *trans,
if (datacsum) { if (datacsum) {
ret = csum_disk_extent(trans, root, bytenr, len); ret = csum_disk_extent(trans, root, bytenr, len);
if (ret < 0) if (ret < 0) {
errno = -ret;
error( error(
"failed to calculate csum for bytenr %llu len %llu: %s", "failed to calculate csum for bytenr %llu len %llu: %m",
bytenr, len, strerror(-ret)); bytenr, len);
}
} }
*ret_len = len; *ret_len = len;
return ret; return ret;
@ -771,27 +773,31 @@ static int create_image(struct btrfs_root *root,
ret = btrfs_find_free_objectid(trans, root, BTRFS_FIRST_FREE_OBJECTID, ret = btrfs_find_free_objectid(trans, root, BTRFS_FIRST_FREE_OBJECTID,
&ino); &ino);
if (ret < 0) { if (ret < 0) {
error("failed to find free objectid for root %llu: %s", errno = -ret;
root->root_key.objectid, strerror(-ret)); error("failed to find free objectid for root %llu: %m",
root->root_key.objectid);
goto out; goto out;
} }
ret = btrfs_new_inode(trans, root, ino, 0400 | S_IFREG); ret = btrfs_new_inode(trans, root, ino, 0400 | S_IFREG);
if (ret < 0) { if (ret < 0) {
error("failed to create new inode for root %llu: %s", errno = -ret;
root->root_key.objectid, strerror(-ret)); error("failed to create new inode for root %llu: %m",
root->root_key.objectid);
goto out; goto out;
} }
ret = btrfs_change_inode_flags(trans, root, ino, flags); ret = btrfs_change_inode_flags(trans, root, ino, flags);
if (ret < 0) { if (ret < 0) {
error("failed to change inode flag for ino %llu root %llu: %s", errno = -ret;
ino, root->root_key.objectid, strerror(-ret)); error("failed to change inode flag for ino %llu root %llu: %m",
ino, root->root_key.objectid);
goto out; goto out;
} }
ret = btrfs_add_link(trans, root, ino, BTRFS_FIRST_FREE_OBJECTID, name, ret = btrfs_add_link(trans, root, ino, BTRFS_FIRST_FREE_OBJECTID, name,
strlen(name), BTRFS_FT_REG_FILE, NULL, 1, 0); strlen(name), BTRFS_FT_REG_FILE, NULL, 1, 0);
if (ret < 0) { if (ret < 0) {
error("failed to link ino %llu to '/%s' in root %llu: %s", errno = -ret;
ino, name, root->root_key.objectid, strerror(-ret)); error("failed to link ino %llu to '/%s' in root %llu: %m",
ino, name, root->root_key.objectid);
goto out; goto out;
} }
@ -1158,7 +1164,8 @@ static int do_convert(const char *devname, u32 convert_flags, u32 nodesize,
ret = make_convert_btrfs(fd, &mkfs_cfg, &cctx); ret = make_convert_btrfs(fd, &mkfs_cfg, &cctx);
if (ret) { if (ret) {
error("unable to create initial ctree: %s", strerror(-ret)); errno = -ret;
error("unable to create initial ctree: %m");
goto fail; goto fail;
} }
@ -1376,8 +1383,8 @@ static int check_convert_image(struct btrfs_root *image_root, u64 ino,
* So we only need to check if ret < 0 * So we only need to check if ret < 0
*/ */
if (ret < 0) { if (ret < 0) {
error("failed to iterate file extents at offset 0: %s", errno = -ret;
strerror(-ret)); error("failed to iterate file extents at offset 0: %m");
btrfs_release_path(&path); btrfs_release_path(&path);
return ret; return ret;
} }
@ -1581,8 +1588,8 @@ static int do_rollback(const char *devname)
ret = -ENOENT; ret = -ENOENT;
goto close_fs; goto close_fs;
} else if (ret < 0) { } else if (ret < 0) {
error("failed to find source fs image subvolume: %s", errno = -ret;
strerror(-ret)); error("failed to find source fs image subvolume: %m");
goto close_fs; goto close_fs;
} }
@ -1593,8 +1600,8 @@ static int do_rollback(const char *devname)
image_root = btrfs_read_fs_root(fs_info, &key); image_root = btrfs_read_fs_root(fs_info, &key);
if (IS_ERR(image_root)) { if (IS_ERR(image_root)) {
ret = PTR_ERR(image_root); ret = PTR_ERR(image_root);
error("failed to open convert image subvolume: %s", errno = -ret;
strerror(-ret)); error("failed to open convert image subvolume: %m");
goto close_fs; goto close_fs;
} }
@ -1609,8 +1616,8 @@ static int do_rollback(const char *devname)
ret = PTR_ERR(dir); ret = PTR_ERR(dir);
else else
ret = -ENOENT; ret = -ENOENT;
error("failed to locate file %s: %s", image_name, errno = -ret;
strerror(-ret)); error("failed to locate file %s: %m", image_name);
goto close_fs; goto close_fs;
} }
btrfs_dir_item_key_to_cpu(path.nodes[0], dir, &key); btrfs_dir_item_key_to_cpu(path.nodes[0], dir, &key);
@ -1623,7 +1630,8 @@ static int do_rollback(const char *devname)
if (ret < 0) { if (ret < 0) {
btrfs_release_path(&path); btrfs_release_path(&path);
error("unable to find inode %llu: %s", ino, strerror(-ret)); errno = -ret;
error("unable to find inode %llu: %m", ino);
goto close_fs; goto close_fs;
} }
inode_item = btrfs_item_ptr(path.nodes[0], path.slots[0], inode_item = btrfs_item_ptr(path.nodes[0], path.slots[0],
@ -1665,8 +1673,9 @@ close_fs:
ret = -errno; ret = -errno;
else else
ret = -EIO; ret = -EIO;
error("failed to recover range [%llu, %llu): %s", errno = -ret;
range->start, real_size, strerror(-ret)); error("failed to recover range [%llu, %llu): %m",
range->start, real_size);
goto free_mem; goto free_mem;
} }
ret = 0; ret = 0;
@ -1828,7 +1837,8 @@ int main(int argc, char *argv[])
file = argv[optind]; file = argv[optind];
ret = check_mounted(file); ret = check_mounted(file);
if (ret < 0) { if (ret < 0) {
error("could not check mount status: %s", strerror(-ret)); errno = -ret;
error("could not check mount status: %m");
return 1; return 1;
} else if (ret) { } else if (ret) {
error("%s is mounted", file); error("%s is mounted", file);

View File

@ -162,8 +162,8 @@ static int ext2_read_used_space(struct btrfs_convert_context *cctx)
} }
ret = __ext2_add_one_block(fs, block_bitmap, i, used_tree); ret = __ext2_add_one_block(fs, block_bitmap, i, used_tree);
if (ret < 0) { if (ret < 0) {
error("fail to build used space tree, %s", errno = -ret;
strerror(-ret)); error("fail to build used space tree, %m");
break; break;
} }
blk_itr += EXT2_CLUSTERS_PER_GROUP(fs->super); blk_itr += EXT2_CLUSTERS_PER_GROUP(fs->super);

View File

@ -493,10 +493,10 @@ static int reiserfs_copy_dirent(reiserfs_filsys_t fs,
ret = reiserfs_copy_meta(fs, root, dirent_data->convert_flags, ret = reiserfs_copy_meta(fs, root, dirent_data->convert_flags,
deh_dirid, deh_objectid, &type); deh_dirid, deh_objectid, &type);
if (ret) { if (ret) {
errno = -ret;
error( error(
"an error occured while converting \"%.*s\", reiserfs key [%u %u]: %s", "an error occured while converting \"%.*s\", reiserfs key [%u %u]: %m",
(int)len, name, deh_dirid, deh_objectid, (int)len, name, deh_dirid, deh_objectid);
strerror(-ret));
return ret; return ret;
} }
trans = btrfs_start_transaction(root, 1); trans = btrfs_start_transaction(root, 1);

View File

@ -499,7 +499,8 @@ static int write_buffers(struct metadump_struct *md, u64 *next)
} }
if (err) { if (err) {
error("one of the threads failed: %s", strerror(-err)); errno = -err;
error("one of the threads failed: %m");
goto out; goto out;
} }
@ -690,10 +691,12 @@ static int flush_pending(struct metadump_struct *md, int done)
} }
if (md->num_items >= ITEMS_PER_CLUSTER || done) { if (md->num_items >= ITEMS_PER_CLUSTER || done) {
ret = write_buffers(md, &start); ret = write_buffers(md, &start);
if (ret) if (ret) {
error("unable to write buffers: %s", strerror(-ret)); errno = -ret;
else error("unable to write buffers: %m");
} else {
meta_cluster_init(md, start); meta_cluster_init(md, start);
}
} }
pthread_mutex_unlock(&md->mutex); pthread_mutex_unlock(&md->mutex);
return ret; return ret;
@ -2377,10 +2380,12 @@ static int update_disk_super_on_device(struct btrfs_fs_info *info,
ret = pwrite64(fp, buf, BTRFS_SUPER_INFO_SIZE, BTRFS_SUPER_INFO_OFFSET); ret = pwrite64(fp, buf, BTRFS_SUPER_INFO_SIZE, BTRFS_SUPER_INFO_OFFSET);
if (ret != BTRFS_SUPER_INFO_SIZE) { if (ret != BTRFS_SUPER_INFO_SIZE) {
if (ret < 0) if (ret < 0) {
error("cannot write superblock: %s", strerror(ret)); errno = ret;
else error("cannot write superblock: %m");
} else {
error("cannot write superblock"); error("cannot write superblock");
}
ret = -EIO; ret = -EIO;
goto out; goto out;
} }
@ -2535,8 +2540,8 @@ int main(int argc, char *argv[])
if (create) { if (create) {
ret = check_mounted(source); ret = check_mounted(source);
if (ret < 0) { if (ret < 0) {
warning("unable to check mount status of: %s", errno = -ret;
strerror(-ret)); warning("unable to check mount status of: %m");
} else if (ret) { } else if (ret) {
warning("%s already mounted, results may be inaccurate", warning("%s already mounted, results may be inaccurate",
source); source);

View File

@ -714,7 +714,8 @@ int test_dev_for_mkfs(const char *file, int force_overwrite)
ret = is_swap_device(file); ret = is_swap_device(file);
if (ret < 0) { if (ret < 0) {
error("checking status of %s: %s", file, strerror(-ret)); errno = -ret;
error("checking status of %s: %m", file);
return 1; return 1;
} }
if (ret == 1) { if (ret == 1) {
@ -760,8 +761,8 @@ int test_status_for_mkfs(const char *file, bool force_overwrite)
} }
ret = check_mounted(file); ret = check_mounted(file);
if (ret < 0) { if (ret < 0) {
error("cannot check mount status of %s: %s", file, errno = -ret;
strerror(-ret)); error("cannot check mount status of %s: %m", file);
return 1; return 1;
} }
if (ret == 1) { if (ret == 1) {

View File

@ -1094,7 +1094,8 @@ int main(int argc, char **argv)
ret = make_btrfs(fd, &mkfs_cfg); ret = make_btrfs(fd, &mkfs_cfg);
if (ret) { if (ret) {
error("error during mkfs: %s", strerror(-ret)); errno = -ret;
error("error during mkfs: %m");
goto error; goto error;
} }

View File

@ -261,8 +261,9 @@ static int add_xattr_item(struct btrfs_trans_handle *trans,
cur_name_len, cur_value, cur_name_len, cur_value,
ret, objectid); ret, objectid);
if (ret) { if (ret) {
error("inserting a xattr item failed for %s: %s", errno = -ret;
file_name, strerror(-ret)); error("inserting a xattr item failed for %s: %m",
file_name);
} }
cur_name = strtok(next_location, &delimiter); cur_name = strtok(next_location, &delimiter);
@ -858,8 +859,8 @@ static int set_device_size(struct btrfs_fs_info *fs_info,
trans = btrfs_start_transaction(chunk_root, 1); trans = btrfs_start_transaction(chunk_root, 1);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
ret = PTR_ERR(trans); ret = PTR_ERR(trans);
error("failed to start transaction: %d (%s)", ret, errno = -ret;
strerror(-ret)); error("failed to start transaction: %d (%m)", ret);
return ret; return ret;
} }
key.objectid = BTRFS_DEV_ITEMS_OBJECTID; key.objectid = BTRFS_DEV_ITEMS_OBJECTID;
@ -887,9 +888,10 @@ static int set_device_size(struct btrfs_fs_info *fs_info,
* super->dev_item * super->dev_item
*/ */
ret = btrfs_commit_transaction(trans, chunk_root); ret = btrfs_commit_transaction(trans, chunk_root);
if (ret < 0) if (ret < 0) {
error("failed to commit current transaction: %d (%s)", errno = -ret;
ret, strerror(-ret)); error("failed to commit current transaction: %d (%m)", ret);
}
btrfs_release_path(&path); btrfs_release_path(&path);
return ret; return ret;
@ -924,8 +926,8 @@ int btrfs_mkfs_shrink_fs(struct btrfs_fs_info *fs_info, u64 *new_size_ret,
ret = get_device_extent_end(fs_info, 1, &new_size); ret = get_device_extent_end(fs_info, 1, &new_size);
if (ret < 0) { if (ret < 0) {
error("failed to get minimal device size: %d (%s)", errno = -ret;
ret, strerror(-ret)); error("failed to get minimal device size: %d (%m)", ret);
return ret; return ret;
} }

View File

@ -110,7 +110,7 @@ static int prop_compression(enum prop_object_type type,
fd = open_file_or_dir3(object, &dirstream, open_flags); fd = open_file_or_dir3(object, &dirstream, open_flags);
if (fd == -1) { if (fd == -1) {
ret = -errno; ret = -errno;
error("failed to open %s: %s", object, strerror(-ret)); error("failed to open %s: %m", object);
goto out; goto out;
} }
@ -133,8 +133,8 @@ static int prop_compression(enum prop_object_type type,
if (sret < 0) { if (sret < 0) {
ret = -errno; ret = -errno;
if (ret != -ENOATTR) if (ret != -ENOATTR)
error("failed to %s compression for %s: %s", error("failed to %s compression for %s: %m",
value ? "set" : "get", object, strerror(-ret)); value ? "set" : "get", object);
else else
ret = 0; ret = 0;
goto out; goto out;
@ -150,8 +150,7 @@ static int prop_compression(enum prop_object_type type,
sret = fgetxattr(fd, xattr_name, buf, len); sret = fgetxattr(fd, xattr_name, buf, len);
if (sret < 0) { if (sret < 0) {
ret = -errno; ret = -errno;
error("failed to get compression for %s: %s", error("failed to get compression for %s: %m", object);
object, strerror(-ret));
goto out; goto out;
} }
fprintf(stdout, "compression=%.*s\n", (int)len, buf); fprintf(stdout, "compression=%.*s\n", (int)len, buf);

View File

@ -610,8 +610,9 @@ static struct btrfs_qgroup *get_or_add_qgroup(
ret = qgroup_tree_insert(qgroup_lookup, bq); ret = qgroup_tree_insert(qgroup_lookup, bq);
if (ret) { if (ret) {
error("failed to insert %llu into tree: %s", errno = -ret;
(unsigned long long)bq->qgroupid, strerror(-ret)); error("failed to insert %llu into tree: %m",
(unsigned long long)bq->qgroupid);
free(bq); free(bq);
return ERR_PTR(ret); return ERR_PTR(ret);
} }

View File

@ -61,8 +61,7 @@ static int read_buf(struct btrfs_send_stream *sctx, char *buf, size_t len)
rbytes = read(sctx->fd, buf + pos, len - pos); rbytes = read(sctx->fd, buf + pos, len - pos);
if (rbytes < 0) { if (rbytes < 0) {
ret = -errno; ret = -errno;
error("read from stream failed: %s", error("read from stream failed: %m");
strerror(-ret));
goto out; goto out;
} }
if (rbytes == 0) { if (rbytes == 0) {

View File

@ -40,8 +40,7 @@ static int btrfs_get_root_id_by_sub_path(int mnt_fd, const char *sub_path,
subvol_fd = openat(mnt_fd, sub_path, O_RDONLY); subvol_fd = openat(mnt_fd, sub_path, O_RDONLY);
if (subvol_fd < 0) { if (subvol_fd < 0) {
ret = -errno; ret = -errno;
fprintf(stderr, "ERROR: open %s failed. %s\n", sub_path, fprintf(stderr, "ERROR: open %s failed: %m\n", sub_path);
strerror(-ret));
return ret; return ret;
} }

18
utils.c
View File

@ -357,7 +357,8 @@ int btrfs_prepare_device(int fd, const char *file, u64 *block_count_ret,
ZERO_DEV_BYTES, block_count); ZERO_DEV_BYTES, block_count);
if (ret < 0) { if (ret < 0) {
error("failed to zero device '%s': %s", file, strerror(-ret)); errno = -ret;
error("failed to zero device '%s': %m", file);
return 1; return 1;
} }
@ -530,7 +531,8 @@ int get_btrfs_mount(const char *dev, char *mp, size_t mp_size)
error("not a block device: %s", dev); error("not a block device: %s", dev);
ret = -EINVAL; ret = -EINVAL;
} else { } else {
error("cannot check %s: %s", dev, strerror(-ret)); errno = -ret;
error("cannot check %s: %m", dev);
} }
goto out; goto out;
} }
@ -1492,8 +1494,10 @@ path:
if (fd < 0) if (fd < 0)
goto err; goto err;
ret = lookup_path_rootid(fd, &id); ret = lookup_path_rootid(fd, &id);
if (ret) if (ret) {
error("failed to lookup root id: %s", strerror(-ret)); errno = -ret;
error("failed to lookup root id: %m");
}
close(fd); close(fd);
if (ret < 0) if (ret < 0)
goto err; goto err;
@ -1782,8 +1786,7 @@ int get_fsid(const char *path, u8 *fsid, int silent)
if (fd < 0) { if (fd < 0) {
ret = -errno; ret = -errno;
if (!silent) if (!silent)
error("failed to open %s: %s", path, error("failed to open %s: %m", path);
strerror(-ret));
goto out; goto out;
} }
@ -2000,7 +2003,8 @@ int btrfs_scan_devices(void)
&num_devices, BTRFS_SUPER_INFO_OFFSET, &num_devices, BTRFS_SUPER_INFO_OFFSET,
SBREAD_DEFAULT); SBREAD_DEFAULT);
if (ret) { if (ret) {
error("cannot scan %s: %s", path, strerror(-ret)); errno = -ret;
error("cannot scan %s: %m", path);
close (fd); close (fd);
continue; continue;
} }

View File

@ -1926,8 +1926,9 @@ static int read_one_chunk(struct btrfs_fs_info *fs_info, struct btrfs_key *key,
} }
ret = insert_cache_extent(&map_tree->cache_tree, &map->ce); ret = insert_cache_extent(&map_tree->cache_tree, &map->ce);
if (ret < 0) { if (ret < 0) {
error("failed to add chunk map start=%llu len=%llu: %d (%s)", errno = -ret;
map->ce.start, map->ce.size, ret, strerror(-ret)); error("failed to add chunk map start=%llu len=%llu: %d (%m)",
map->ce.start, map->ce.size, ret);
} }
return ret; return ret;
@ -2448,8 +2449,8 @@ int btrfs_fix_device_size(struct btrfs_fs_info *fs_info,
trans = btrfs_start_transaction(chunk_root, 1); trans = btrfs_start_transaction(chunk_root, 1);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
ret = PTR_ERR(trans); ret = PTR_ERR(trans);
error("error starting transaction: %d (%s)", errno = -ret;
ret, strerror(-ret)); error("error starting transaction: %d (%m)", ret);
return ret; return ret;
} }
@ -2461,8 +2462,8 @@ int btrfs_fix_device_size(struct btrfs_fs_info *fs_info,
goto err; goto err;
} }
if (ret < 0) { if (ret < 0) {
error("failed to search chunk root: %d (%s)", errno = -ret;
ret, strerror(-ret)); error("failed to search chunk root: %d (%m)", ret);
goto err; goto err;
} }
di = btrfs_item_ptr(path.nodes[0], path.slots[0], struct btrfs_dev_item); di = btrfs_item_ptr(path.nodes[0], path.slots[0], struct btrfs_dev_item);
@ -2470,8 +2471,8 @@ int btrfs_fix_device_size(struct btrfs_fs_info *fs_info,
btrfs_mark_buffer_dirty(path.nodes[0]); btrfs_mark_buffer_dirty(path.nodes[0]);
ret = btrfs_commit_transaction(trans, chunk_root); ret = btrfs_commit_transaction(trans, chunk_root);
if (ret < 0) { if (ret < 0) {
error("failed to commit current transaction: %d (%s)", errno = -ret;
ret, strerror(-ret)); error("failed to commit current transaction: %d (%m)", ret);
btrfs_release_path(&path); btrfs_release_path(&path);
return ret; return ret;
} }
@ -2524,14 +2525,14 @@ int btrfs_fix_super_size(struct btrfs_fs_info *fs_info)
trans = btrfs_start_transaction(fs_info->tree_root, 1); trans = btrfs_start_transaction(fs_info->tree_root, 1);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
ret = PTR_ERR(trans); ret = PTR_ERR(trans);
error("error starting transaction: %d (%s)", errno = -ret;
ret, strerror(-ret)); error("error starting transaction: %d (%m)", ret);
return ret; return ret;
} }
ret = btrfs_commit_transaction(trans, fs_info->tree_root); ret = btrfs_commit_transaction(trans, fs_info->tree_root);
if (ret < 0) { if (ret < 0) {
error("failed to commit current transaction: %d (%s)", errno = -ret;
ret, strerror(-ret)); error("failed to commit current transaction: %d (%m)", ret);
return ret; return ret;
} }
printf("Fixed super total bytes, old size: %llu new size: %llu\n", printf("Fixed super total bytes, old size: %llu new size: %llu\n",