X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=btrfstune.c;h=eccedf79a8039641693739dd2d58c1d4c5478748;hb=50417091a076a84ed06ea8d7158b749ece0d0914;hp=15dde908ff97bb37192cb31ca8277df47c313482;hpb=14de259f1f434a1d4d321ebebb28f95f3c9f71d8;p=platform%2Fupstream%2Fbtrfs-progs.git diff --git a/btrfstune.c b/btrfstune.c index 15dde90..eccedf7 100644 --- a/btrfstune.c +++ b/btrfstune.c @@ -32,6 +32,7 @@ #include "transaction.h" #include "utils.h" #include "volumes.h" +#include "help.h" static char *device; static int force = 0; @@ -65,6 +66,7 @@ static int update_seeding_flag(struct btrfs_root *root, int set_flag) } trans = btrfs_start_transaction(root, 1); + BUG_ON(IS_ERR(trans)); btrfs_set_super_flags(disk_super, super_flags); ret = btrfs_commit_transaction(trans, root); @@ -82,6 +84,7 @@ static int set_super_incompat_flags(struct btrfs_root *root, u64 flags) super_flags = btrfs_super_incompat_flags(disk_super); super_flags |= flags; trans = btrfs_start_transaction(root, 1); + BUG_ON(IS_ERR(trans)); btrfs_set_super_incompat_flags(disk_super, super_flags); ret = btrfs_commit_transaction(trans, root); @@ -110,7 +113,7 @@ static int change_header_uuid(struct btrfs_root *root, struct extent_buffer *eb) write_extent_buffer(eb, fs_info->new_chunk_tree_uuid, btrfs_header_chunk_tree_uuid(eb), BTRFS_UUID_SIZE); - ret = write_tree_block(NULL, root, eb); + ret = write_tree_block(NULL, fs_info, eb); return ret; } @@ -118,19 +121,16 @@ static int change_header_uuid(struct btrfs_root *root, struct extent_buffer *eb) static int change_extents_uuid(struct btrfs_fs_info *fs_info) { struct btrfs_root *root = fs_info->extent_root; - struct btrfs_path *path; + struct btrfs_path path; struct btrfs_key key = {0, 0, 0}; int ret = 0; - path = btrfs_alloc_path(); - if (!path) - return -ENOMEM; - + btrfs_init_path(&path); /* * Here we don't use transaction as it will takes a lot of reserve * space, and that will make a near-full btrfs unable to change uuid */ - ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); + ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0); if (ret < 0) goto out; @@ -140,18 +140,18 @@ static int change_extents_uuid(struct btrfs_fs_info *fs_info) u64 flags; u64 bytenr; - btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); + btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]); if (key.type != BTRFS_EXTENT_ITEM_KEY && key.type != BTRFS_METADATA_ITEM_KEY) goto next; - ei = btrfs_item_ptr(path->nodes[0], path->slots[0], + ei = btrfs_item_ptr(path.nodes[0], path.slots[0], struct btrfs_extent_item); - flags = btrfs_extent_flags(path->nodes[0], ei); + flags = btrfs_extent_flags(path.nodes[0], ei); if (!(flags & BTRFS_EXTENT_FLAG_TREE_BLOCK)) goto next; bytenr = key.objectid; - eb = read_tree_block(root, bytenr, root->nodesize, 0); + eb = read_tree_block(fs_info, bytenr, 0); if (IS_ERR(eb)) { error("failed to read tree block: %llu", bytenr); ret = PTR_ERR(eb); @@ -165,7 +165,7 @@ static int change_extents_uuid(struct btrfs_fs_info *fs_info) goto out; } next: - ret = btrfs_next_item(root, path); + ret = btrfs_next_item(root, &path); if (ret < 0) goto out; if (ret > 0) { @@ -175,14 +175,13 @@ next: } out: - btrfs_free_path(path); + btrfs_release_path(&path); return ret; } -static int change_device_uuid(struct btrfs_root *root, struct extent_buffer *eb, +static int change_device_uuid(struct btrfs_fs_info *fs_info, struct extent_buffer *eb, int slot) { - struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_dev_item *di; int ret = 0; @@ -195,7 +194,7 @@ static int change_device_uuid(struct btrfs_root *root, struct extent_buffer *eb, write_extent_buffer(eb, fs_info->new_fsid, (unsigned long)btrfs_device_fsid(di), BTRFS_FSID_SIZE); - ret = write_tree_block(NULL, root, eb); + ret = write_tree_block(NULL, fs_info, eb); return ret; } @@ -203,28 +202,26 @@ static int change_device_uuid(struct btrfs_root *root, struct extent_buffer *eb, static int change_devices_uuid(struct btrfs_fs_info *fs_info) { struct btrfs_root *root = fs_info->chunk_root; - struct btrfs_path *path; + struct btrfs_path path; struct btrfs_key key = {0, 0, 0}; int ret = 0; - path = btrfs_alloc_path(); - if (!path) - return -ENOMEM; + btrfs_init_path(&path); /* No transaction again */ - ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); + ret = btrfs_search_slot(NULL, root, &key, &path, 0, 0); if (ret < 0) goto out; while (1) { - btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); + btrfs_item_key_to_cpu(path.nodes[0], &key, path.slots[0]); if (key.type != BTRFS_DEV_ITEM_KEY || key.objectid != BTRFS_DEV_ITEMS_OBJECTID) goto next; - ret = change_device_uuid(root, path->nodes[0], path->slots[0]); + ret = change_device_uuid(fs_info, path.nodes[0], path.slots[0]); if (ret < 0) goto out; next: - ret = btrfs_next_item(root, path); + ret = btrfs_next_item(root, &path); if (ret < 0) goto out; if (ret > 0) { @@ -233,7 +230,7 @@ next: } } out: - btrfs_free_path(path); + btrfs_release_path(&path); return ret; } @@ -247,7 +244,7 @@ static int change_fsid_prepare(struct btrfs_fs_info *fs_info) btrfs_set_super_flags(fs_info->super_copy, flags); memcpy(fs_info->super_copy->fsid, fs_info->new_fsid, BTRFS_FSID_SIZE); - ret = write_all_supers(tree_root); + ret = write_all_supers(fs_info); if (ret < 0) return ret; @@ -255,7 +252,7 @@ static int change_fsid_prepare(struct btrfs_fs_info *fs_info) write_extent_buffer(tree_root->node, fs_info->new_chunk_tree_uuid, btrfs_header_chunk_tree_uuid(tree_root->node), BTRFS_UUID_SIZE); - return write_tree_block(NULL, tree_root, tree_root->node); + return write_tree_block(NULL, fs_info, tree_root->node); } static int change_fsid_done(struct btrfs_fs_info *fs_info) @@ -265,7 +262,7 @@ static int change_fsid_done(struct btrfs_fs_info *fs_info) flags &= ~BTRFS_SUPER_FLAG_CHANGING_FSID; btrfs_set_super_flags(fs_info->super_copy, flags); - return write_all_supers(fs_info->tree_root); + return write_all_supers(fs_info); } /* @@ -359,7 +356,7 @@ static int change_uuid(struct btrfs_fs_info *fs_info, const char *new_fsid_str) BTRFS_FSID_SIZE); memcpy(fs_info->super_copy->fsid, fs_info->new_fsid, BTRFS_FSID_SIZE); - ret = write_all_supers(fs_info->tree_root); + ret = write_all_supers(fs_info); if (ret < 0) goto out;