summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolay Borisov <nborisov@suse.com>2018-05-14 14:13:26 +0300
committerDavid Sterba <dsterba@suse.com>2018-06-07 16:37:39 +0200
commit12087e6d75279d0e912764728d2540e8709978fe (patch)
tree7096be2189c981ab59154cad99de866450693022
parentbb9b8bcfd9b8957c82c19c626e68cc95f417963f (diff)
btrfs-progs: corrupt-block: Factor out specific-root code
Some options operate on a specific root so let's extract the code which deals with this. No functional change. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
-rw-r--r--btrfs-corrupt-block.c37
1 files changed, 23 insertions, 14 deletions
diff --git a/btrfs-corrupt-block.c b/btrfs-corrupt-block.c
index fc06204b..6c587504 100644
--- a/btrfs-corrupt-block.c
+++ b/btrfs-corrupt-block.c
@@ -1080,6 +1080,26 @@ out:
return ret;
}
+
+static struct btrfs_root *open_root(struct btrfs_fs_info *fs_info,
+ u64 root_objectid)
+{
+
+ struct btrfs_key root_key;
+ struct btrfs_root *root;
+
+ root_key.objectid = root_objectid;
+ root_key.type = BTRFS_ROOT_ITEM_KEY;
+ root_key.offset = (u64)-1;
+
+ root = btrfs_read_fs_root(fs_info, &root_key);
+ if (IS_ERR(root)) {
+ fprintf(stderr, "couldn't find root %llu\n", root_objectid);
+ print_usage(1);
+ }
+
+ return root;
+}
int main(int argc, char **argv)
{
struct cache_tree root_cache;
@@ -1326,20 +1346,9 @@ int main(int argc, char **argv)
if (!key.objectid)
print_usage(1);
- 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(1);
- }
- }
+ if (root_objectid)
+ target = open_root(root->fs_info, root_objectid);
+
ret = delete_item(target, &key);
goto out_close;
}