Btrfs-progs: let btrfs-corrupt-block specify a root

Sometimes we want to corrupt specific keys or delete items on different roots,
so allow btrfs-corrupt-block to take a root objectid so we can corrupt a
specific root.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
master
Josef Bacik 2015-01-13 15:23:01 -05:00
parent 8fa8156a0e
commit 63d66268f4
1 changed files with 25 additions and 3 deletions

View File

@ -109,6 +109,7 @@ static void print_usage(void)
"to corrupt and a root+key for the item)\n");
fprintf(stderr, "\t-D Corrupt a dir item, must specify key and field\n");
fprintf(stderr, "\t-d Delete this item (must specify -K)\n");
fprintf(stderr, "\t-r Operate on this root (only works with -d)\n");
exit(1);
}
@ -1007,6 +1008,7 @@ int main(int ac, char **av)
u64 metadata_block = 0;
u64 inode = 0;
u64 file_extent = (u64)-1;
u64 root_objectid = 0;
char field[FIELD_BUF_LEN];
field[0] = '\0';
@ -1034,11 +1036,12 @@ int main(int ac, char **av)
{ "item", 0, NULL, 'I'},
{ "dir-item", 0, NULL, 'D'},
{ "delete", 0, NULL, 'd'},
{ "root", 0, NULL, 'r'},
{ NULL, 0, NULL, 0 }
};
c = getopt_long(ac, av, "l:c:b:eEkuUi:f:x:m:K:IDd", long_options,
&option_index);
c = getopt_long(ac, av, "l:c:b:eEkuUi:f:x:m:K:IDdr:",
long_options, &option_index);
if (c < 0)
break;
switch(c) {
@ -1098,6 +1101,9 @@ int main(int ac, char **av)
case 'd':
delete = 1;
break;
case 'r':
root_objectid = arg_strtou64(optarg);
break;
default:
print_usage();
}
@ -1206,9 +1212,25 @@ int main(int ac, char **av)
ret = corrupt_btrfs_item(root, &key, field);
}
if (delete) {
struct btrfs_root *target = root;
if (!key.objectid)
print_usage();
ret = delete_item(root, &key);
if (root_objectid) {
struct btrfs_key root_key;
root_key.objectid = root_objectid;
root_key.type = BTRFS_ROOT_ITEM_KEY;
root_key.offset = (u64)-1;
target = btrfs_read_fs_root(root->fs_info, &root_key);
if (IS_ERR(target)) {
fprintf(stderr, "Couldn't find root %llu\n",
(unsigned long long)root_objectid);
print_usage();
}
}
ret = delete_item(target, &key);
goto out_close;
}
if (key.objectid || key.offset || key.type) {