btrfs-progs: check: switch some messages to common helpers

Switch the messages that do not come from the actual image checking,
more like the parameter verification.

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2016-09-08 18:31:10 +02:00
parent a4e59b6776
commit c7a1f66a20
1 changed files with 20 additions and 19 deletions

View File

@ -11281,8 +11281,8 @@ int cmd_check(int argc, char **argv)
case 's': case 's':
num = arg_strtou64(optarg); num = arg_strtou64(optarg);
if (num >= BTRFS_SUPER_MIRROR_MAX) { if (num >= BTRFS_SUPER_MIRROR_MAX) {
fprintf(stderr, error(
"ERROR: super mirror should be less than: %d\n", "super mirror should be less than %d",
BTRFS_SUPER_MIRROR_MAX); BTRFS_SUPER_MIRROR_MAX);
exit(1); exit(1);
} }
@ -11351,7 +11351,7 @@ int cmd_check(int argc, char **argv)
/* This check is the only reason for --readonly to exist */ /* This check is the only reason for --readonly to exist */
if (readonly && repair) { if (readonly && repair) {
fprintf(stderr, "Repair options are not compatible with --readonly\n"); error("repair options are not compatible with --readonly");
exit(1); exit(1);
} }
@ -11359,7 +11359,7 @@ int cmd_check(int argc, char **argv)
* Not supported yet * Not supported yet
*/ */
if (repair && check_mode == CHECK_MODE_LOWMEM) { if (repair && check_mode == CHECK_MODE_LOWMEM) {
error("Low memory mode doesn't support repair yet"); error("low memory mode doesn't support repair yet");
exit(1); exit(1);
} }
@ -11367,10 +11367,10 @@ int cmd_check(int argc, char **argv)
cache_tree_init(&root_cache); cache_tree_init(&root_cache);
if((ret = check_mounted(argv[optind])) < 0) { if((ret = check_mounted(argv[optind])) < 0) {
fprintf(stderr, "Could not check mount status: %s\n", strerror(-ret)); error("could not check mount status: %s", strerror(-ret));
goto err_out; goto err_out;
} else if(ret) { } else if(ret) {
fprintf(stderr, "%s is currently mounted. Aborting.\n", argv[optind]); error("%s is currently mounted, aborting", argv[optind]);
ret = -EBUSY; ret = -EBUSY;
goto err_out; goto err_out;
} }
@ -11382,7 +11382,7 @@ int cmd_check(int argc, char **argv)
info = open_ctree_fs_info(argv[optind], bytenr, tree_root_bytenr, info = open_ctree_fs_info(argv[optind], bytenr, tree_root_bytenr,
chunk_root_bytenr, ctree_flags); chunk_root_bytenr, ctree_flags);
if (!info) { if (!info) {
fprintf(stderr, "Couldn't open file system\n"); error("cannot open file system");
ret = -EIO; ret = -EIO;
goto err_out; goto err_out;
} }
@ -11395,14 +11395,14 @@ int cmd_check(int argc, char **argv)
* will make us fail to load log tree when mounting. * will make us fail to load log tree when mounting.
*/ */
if (repair && btrfs_super_log_root(info->super_copy)) { if (repair && btrfs_super_log_root(info->super_copy)) {
ret = ask_user("repair mode will force to clear out log tree, Are you sure?"); ret = ask_user("repair mode will force to clear out log tree, are you sure?");
if (!ret) { if (!ret) {
ret = 1; ret = 1;
goto close_out; goto close_out;
} }
ret = zero_log_tree(root); ret = zero_log_tree(root);
if (ret) { if (ret) {
fprintf(stderr, "fail to zero log tree\n"); error("failed to zero log tree: %d", ret);
goto close_out; goto close_out;
} }
} }
@ -11427,7 +11427,7 @@ int cmd_check(int argc, char **argv)
if (!extent_buffer_uptodate(info->tree_root->node) || if (!extent_buffer_uptodate(info->tree_root->node) ||
!extent_buffer_uptodate(info->dev_root->node) || !extent_buffer_uptodate(info->dev_root->node) ||
!extent_buffer_uptodate(info->chunk_root->node)) { !extent_buffer_uptodate(info->chunk_root->node)) {
fprintf(stderr, "Critical roots corrupted, unable to fsck the FS\n"); error("critical roots corrupted, unable to check the filesystem");
ret = -EIO; ret = -EIO;
goto close_out; goto close_out;
} }
@ -11437,7 +11437,7 @@ int cmd_check(int argc, char **argv)
trans = btrfs_start_transaction(info->extent_root, 0); trans = btrfs_start_transaction(info->extent_root, 0);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
fprintf(stderr, "Error starting transaction\n"); error("error starting transaction");
ret = PTR_ERR(trans); ret = PTR_ERR(trans);
goto close_out; goto close_out;
} }
@ -11450,10 +11450,11 @@ int cmd_check(int argc, char **argv)
} }
if (init_csum_tree) { if (init_csum_tree) {
fprintf(stderr, "Reinit crc root\n"); printf("Reinitialize checksum tree\n");
ret = btrfs_fsck_reinit_root(trans, info->csum_root, 0); ret = btrfs_fsck_reinit_root(trans, info->csum_root, 0);
if (ret) { if (ret) {
fprintf(stderr, "crc root initialization failed\n"); error("checksum tree initialization failed: %d",
ret);
ret = -EIO; ret = -EIO;
goto close_out; goto close_out;
} }
@ -11461,7 +11462,7 @@ int cmd_check(int argc, char **argv)
ret = fill_csum_tree(trans, info->csum_root, ret = fill_csum_tree(trans, info->csum_root,
init_extent_tree); init_extent_tree);
if (ret) { if (ret) {
fprintf(stderr, "crc refilling failed\n"); error("checksum tree refilling failed: %d", ret);
return -EIO; return -EIO;
} }
} }
@ -11474,24 +11475,24 @@ int cmd_check(int argc, char **argv)
goto close_out; goto close_out;
} }
if (!extent_buffer_uptodate(info->extent_root->node)) { if (!extent_buffer_uptodate(info->extent_root->node)) {
fprintf(stderr, "Critical roots corrupted, unable to fsck the FS\n"); error("critical: extent_root, unable to check the filesystem");
ret = -EIO; ret = -EIO;
goto close_out; goto close_out;
} }
if (!extent_buffer_uptodate(info->csum_root->node)) { if (!extent_buffer_uptodate(info->csum_root->node)) {
fprintf(stderr, "Checksum root corrupted, rerun with --init-csum-tree option\n"); error("critical: csum_root, unable to check the filesystem");
ret = -EIO; ret = -EIO;
goto close_out; goto close_out;
} }
if (!ctx.progress_enabled) if (!ctx.progress_enabled)
fprintf(stderr, "checking extents\n"); printf("checking extents");
if (check_mode == CHECK_MODE_LOWMEM) if (check_mode == CHECK_MODE_LOWMEM)
ret = check_chunks_and_extents_v2(root); ret = check_chunks_and_extents_v2(root);
else else
ret = check_chunks_and_extents(root); ret = check_chunks_and_extents(root);
if (ret) if (ret)
fprintf(stderr, "Errors found in extent allocation tree or chunk allocation\n"); printf("Errors found in extent allocation tree or chunk allocation");
ret = repair_root_items(info); ret = repair_root_items(info);
if (ret < 0) if (ret < 0)
@ -11577,7 +11578,7 @@ int cmd_check(int argc, char **argv)
} }
if (!list_empty(&root->fs_info->recow_ebs)) { if (!list_empty(&root->fs_info->recow_ebs)) {
fprintf(stderr, "Transid errors in file system\n"); error("transid errors in file system");
ret = 1; ret = 1;
} }
out: out: