From 32acc8eed29847616f6d99d70b9dac1466e4ec4f Mon Sep 17 00:00:00 2001 From: Nikolay Borisov Date: Mon, 14 May 2018 14:13:31 +0300 Subject: [PATCH] btrfs-progs: corrupt-block: Factor out common "-r" handling code Since more and more of the "corrupt XXX" options are going to support combination with -r option, let's extract the common code needed for this. No functional changes. Signed-off-by: Nikolay Borisov Signed-off-by: David Sterba --- btrfs-corrupt-block.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c index 5aec522f..f4543fa3 100644 --- a/btrfs-corrupt-block.c +++ b/btrfs-corrupt-block.c @@ -1114,7 +1114,7 @@ int main(int argc, char **argv) { struct cache_tree root_cache; struct btrfs_key key; - struct btrfs_root *root; + struct btrfs_root *root, *target_root; char *dev; /* chunk offset can be 0,so change to (u64)-1 */ u64 logical = (u64)-1; @@ -1245,6 +1245,10 @@ int main(int argc, char **argv) fprintf(stderr, "Open ctree failed\n"); exit(1); } + target_root = root; + if (root_objectid) + target_root = open_root(root->fs_info, root_objectid); + if (extent_rec) { struct btrfs_trans_handle *trans; @@ -1342,26 +1346,19 @@ int main(int argc, char **argv) goto out_close; } if (corrupt_item) { - struct btrfs_root *target; if (!key.objectid) print_usage(1); if (!root_objectid) print_usage(1); - target = open_root(root->fs_info, root_objectid); - - ret = corrupt_btrfs_item(target, &key, field); + ret = corrupt_btrfs_item(target_root, &key, field); goto out_close; } if (delete) { - struct btrfs_root *target = root; - if (!key.objectid) print_usage(1); - if (root_objectid) - target = open_root(root->fs_info, root_objectid); - ret = delete_item(target, &key); + ret = delete_item(target_root, &key); goto out_close; } if (should_corrupt_key) {