btrfs-progs: Handle errors returned from open_ctree

Signed-off-by: Danny Kukawka <danny.kukawka@bisect.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
Danny Kukawka 2013-01-21 16:57:25 +01:00 committed by David Sterba
parent 0db197d8b2
commit c88c2f52fe
9 changed files with 60 additions and 6 deletions

View File

@ -491,6 +491,11 @@ static int create_metadump(const char *input, FILE *out, int num_threads,
int ret;
root = open_ctree(input, 0, 0);
if (!root) {
fprintf(stderr, "Open ctree failed\n");
exit(1);
}
BUG_ON(root->nodesize != root->leafsize);
ret = metadump_init(&metadump, root, out, num_threads,

View File

@ -84,8 +84,10 @@ int main(int ac, char **av)
root = open_ctree(av[optind], bytenr, 1);
if (root == NULL)
if (!root) {
fprintf(stderr, "Open ctree failed\n");
return 1;
}
/* make the super writing code think we've read the first super */
root->fs_info->super_bytenr = BTRFS_SUPER_INFO_OFFSET;

View File

@ -46,7 +46,7 @@
#define GET_LABEL 3
#define SET_LABEL 4
static void change_label_unmounted(char *dev, char *nLabel)
static int change_label_unmounted(char *dev, char *nLabel)
{
struct btrfs_root *root;
struct btrfs_trans_handle *trans;
@ -123,6 +123,5 @@ int set_label(char *btrfs_dev, char *nLabel)
fprintf(stderr, "FATAL: the filesystem has to be unmounted\n");
return -2;
}
change_label_unmounted(btrfs_dev, nLabel);
return 0;
return change_label_unmounted(btrfs_dev, nLabel);
}

View File

@ -108,6 +108,11 @@ int main(int argc, char *argv[])
root = open_ctree(device, 0, 1);
if (!root) {
fprintf(stderr, "Open ctree failed\n");
return 1;
}
if (seeding_flag) {
ret = update_seeding_flag(root, seeding_value);
if (!ret)

View File

@ -436,6 +436,12 @@ int main(int ac, char **av)
radix_tree_init();
root = open_ctree(av[ac-1], &super, 0);
if (!root) {
fprintf(stderr, "Open ctree failed\n");
return 1;
}
trans = btrfs_start_transaction(root, 1);
dir_oid = btrfs_super_root_dir(&super);
@ -479,6 +485,11 @@ int main(int ac, char **av)
btrfs_header_nritems(&root->node->node.header));
close_ctree(root, &super);
root = open_ctree("dbfile", &super, 0);
if (!root) {
fprintf(stderr, "Open ctree failed\n");
return 1;
}
}
while(count--) {
ret = ops[op](trans, root, &radix);

View File

@ -448,8 +448,11 @@ int main(int argc, char **argv)
root = open_ctree_broken(dev_fd, argv[optind]);
close(dev_fd);
if (!root)
if (!root) {
fprintf(stderr, "Open ctree failed\n");
exit(1);
}
csum_size = btrfs_super_csum_size(&root->fs_info->super_copy);
ret = find_root(root);

3
mkfs.c
View File

@ -1362,7 +1362,8 @@ int main(int ac, char **av)
root = open_ctree(file, 0, O_RDWR);
if (!root) {
fprintf(stderr, "ctree init failed\n");
fprintf(stderr, "Open ctree failed\n");
close(fd);
exit(1);
}
root->fs_info->alloc_start = alloc_start;

View File

@ -52,6 +52,10 @@ int main(int ac, char **av) {
radix_tree_init();
root = open_ctree(av[1], BTRFS_SUPER_INFO_OFFSET, O_RDWR);
if (!root) {
fprintf(stderr, "Open ctree failed\n");
exit(1);
}
trans = btrfs_start_transaction(root, 1);
srand(55);
btrfs_set_key_type(&ins, BTRFS_STRING_ITEM_KEY);
@ -75,6 +79,10 @@ int main(int ac, char **av) {
close_ctree(root);
exit(1);
root = open_ctree(av[1], BTRFS_SUPER_INFO_OFFSET, O_RDWR);
if (!root) {
fprintf(stderr, "Open ctree failed\n");
exit(1);
}
printf("starting search\n");
srand(55);
for (i = 0; i < run_size; i++) {
@ -94,6 +102,10 @@ int main(int ac, char **av) {
close_ctree(root);
root = open_ctree(av[1], BTRFS_SUPER_INFO_OFFSET, O_RDWR);
if (!root) {
fprintf(stderr, "Open ctree failed\n");
exit(1);
}
printf("node %p level %d total ptrs %d free spc %lu\n", root->node,
btrfs_header_level(root->node),
btrfs_header_nritems(root->node),
@ -122,6 +134,10 @@ int main(int ac, char **av) {
close_ctree(root);
root = open_ctree(av[1], BTRFS_SUPER_INFO_OFFSET, O_RDWR);
if (!root) {
fprintf(stderr, "Open ctree failed\n");
exit(1);
}
trans = btrfs_start_transaction(root, 1);
srand(128);
for (i = 0; i < run_size; i++) {
@ -138,6 +154,10 @@ int main(int ac, char **av) {
close_ctree(root);
root = open_ctree(av[1], BTRFS_SUPER_INFO_OFFSET, O_RDWR);
if (!root) {
fprintf(stderr, "Open ctree failed\n");
exit(1);
}
srand(128);
printf("starting search2\n");
for (i = 0; i < run_size; i++) {

View File

@ -356,6 +356,10 @@ int main(int ac, char **av)
struct btrfs_trans_handle *trans;
radix_tree_init();
root = open_ctree("dbfile", &super);
if (!root) {
fprintf(stderr, "Open ctree failed\n");
exit(1);
}
fill_radix(root, &radix);
signal(SIGTERM, sigstopper);
@ -398,6 +402,10 @@ int main(int ac, char **av)
btrfs_header_nritems(&root->node->node.header));
close_ctree(root, &super);
root = open_ctree("dbfile", &super);
if (!root) {
fprintf(stderr, "Open ctree failed\n");
goto out;
}
}
while(count--) {
ret = ops[op](trans, root, &radix);