aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/root-tree.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-04-02 11:20:42 -0400
committerDavid Woodhouse <dwmw2@hera.kernel.org>2007-04-02 11:20:42 -0400
commit5caf2a002901f0fde475371c4bf1c553b51884af (patch)
tree1c262f723307fe924ea4e960761354f194f3843e /fs/btrfs/root-tree.c
parent2c90e5d658424bc71b111eb5a972240d5d06fe86 (diff)
Btrfs: dynamic allocation of path struct
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/root-tree.c')
-rw-r--r--fs/btrfs/root-tree.c47
1 files changed, 28 insertions, 19 deletions
diff --git a/fs/btrfs/root-tree.c b/fs/btrfs/root-tree.c
index f37dab87de16..ddc1c13a5352 100644
--- a/fs/btrfs/root-tree.c
+++ b/fs/btrfs/root-tree.c
@@ -6,7 +6,7 @@
6int btrfs_find_last_root(struct btrfs_root *root, u64 objectid, 6int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
7 struct btrfs_root_item *item, struct btrfs_key *key) 7 struct btrfs_root_item *item, struct btrfs_key *key)
8{ 8{
9 struct btrfs_path path; 9 struct btrfs_path *path;
10 struct btrfs_key search_key; 10 struct btrfs_key search_key;
11 struct btrfs_leaf *l; 11 struct btrfs_leaf *l;
12 int ret; 12 int ret;
@@ -16,14 +16,16 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
16 search_key.flags = (u32)-1; 16 search_key.flags = (u32)-1;
17 search_key.offset = (u32)-1; 17 search_key.offset = (u32)-1;
18 18
19 btrfs_init_path(&path); 19 path = btrfs_alloc_path();
20 ret = btrfs_search_slot(NULL, root, &search_key, &path, 0, 0); 20 BUG_ON(!path);
21 btrfs_init_path(path);
22 ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
21 if (ret < 0) 23 if (ret < 0)
22 goto out; 24 goto out;
23 BUG_ON(ret == 0); 25 BUG_ON(ret == 0);
24 l = btrfs_buffer_leaf(path.nodes[0]); 26 l = btrfs_buffer_leaf(path->nodes[0]);
25 BUG_ON(path.slots[0] == 0); 27 BUG_ON(path->slots[0] == 0);
26 slot = path.slots[0] - 1; 28 slot = path->slots[0] - 1;
27 if (btrfs_disk_key_objectid(&l->items[slot].key) != objectid) { 29 if (btrfs_disk_key_objectid(&l->items[slot].key) != objectid) {
28 ret = 1; 30 ret = 1;
29 goto out; 31 goto out;
@@ -31,9 +33,10 @@ int btrfs_find_last_root(struct btrfs_root *root, u64 objectid,
31 memcpy(item, btrfs_item_ptr(l, slot, struct btrfs_root_item), 33 memcpy(item, btrfs_item_ptr(l, slot, struct btrfs_root_item),
32 sizeof(*item)); 34 sizeof(*item));
33 btrfs_disk_key_to_cpu(key, &l->items[slot].key); 35 btrfs_disk_key_to_cpu(key, &l->items[slot].key);
34 btrfs_release_path(root, &path);
35 ret = 0; 36 ret = 0;
36out: 37out:
38 btrfs_release_path(root, path);
39 btrfs_free_path(path);
37 return ret; 40 return ret;
38} 41}
39 42
@@ -41,24 +44,27 @@ int btrfs_update_root(struct btrfs_trans_handle *trans, struct btrfs_root
41 *root, struct btrfs_key *key, struct btrfs_root_item 44 *root, struct btrfs_key *key, struct btrfs_root_item
42 *item) 45 *item)
43{ 46{
44 struct btrfs_path path; 47 struct btrfs_path *path;
45 struct btrfs_leaf *l; 48 struct btrfs_leaf *l;
46 int ret; 49 int ret;
47 int slot; 50 int slot;
48 struct btrfs_root_item *update_item; 51 struct btrfs_root_item *update_item;
49 52
50 btrfs_init_path(&path); 53 path = btrfs_alloc_path();
51 ret = btrfs_search_slot(trans, root, key, &path, 0, 1); 54 BUG_ON(!path);
55 btrfs_init_path(path);
56 ret = btrfs_search_slot(trans, root, key, path, 0, 1);
52 if (ret < 0) 57 if (ret < 0)
53 goto out; 58 goto out;
54 BUG_ON(ret != 0); 59 BUG_ON(ret != 0);
55 l = btrfs_buffer_leaf(path.nodes[0]); 60 l = btrfs_buffer_leaf(path->nodes[0]);
56 slot = path.slots[0]; 61 slot = path->slots[0];
57 update_item = btrfs_item_ptr(l, slot, struct btrfs_root_item); 62 update_item = btrfs_item_ptr(l, slot, struct btrfs_root_item);
58 btrfs_memcpy(root, l, update_item, item, sizeof(*item)); 63 btrfs_memcpy(root, l, update_item, item, sizeof(*item));
59 btrfs_mark_buffer_dirty(path.nodes[0]); 64 btrfs_mark_buffer_dirty(path->nodes[0]);
60out: 65out:
61 btrfs_release_path(root, &path); 66 btrfs_release_path(root, path);
67 btrfs_free_path(path);
62 return ret; 68 return ret;
63} 69}
64 70
@@ -75,16 +81,19 @@ int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root
75int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, 81int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
76 struct btrfs_key *key) 82 struct btrfs_key *key)
77{ 83{
78 struct btrfs_path path; 84 struct btrfs_path *path;
79 int ret; 85 int ret;
80 86
81 btrfs_init_path(&path); 87 path = btrfs_alloc_path();
82 ret = btrfs_search_slot(trans, root, key, &path, -1, 1); 88 BUG_ON(!path);
89 btrfs_init_path(path);
90 ret = btrfs_search_slot(trans, root, key, path, -1, 1);
83 if (ret < 0) 91 if (ret < 0)
84 goto out; 92 goto out;
85 BUG_ON(ret != 0); 93 BUG_ON(ret != 0);
86 ret = btrfs_del_item(trans, root, &path); 94 ret = btrfs_del_item(trans, root, path);
87out: 95out:
88 btrfs_release_path(root, &path); 96 btrfs_release_path(root, path);
97 btrfs_free_path(path);
89 return ret; 98 return ret;
90} 99}