diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-03-13 09:49:06 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@hera.kernel.org> | 2007-03-13 09:49:06 -0400 |
commit | cf27e1eec063fa68a89c57ae0a83f93aa38851d6 (patch) | |
tree | 230f1f887d5dad72501ed0826cf3d6e9a9d0f6fc /fs | |
parent | 1d4f8a0c1eca5586134b56a4114a7cd5e85e3560 (diff) |
Btrfs: struct extent_item endian
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/btrfs/ctree.h | 24 | ||||
-rw-r--r-- | fs/btrfs/extent-tree.c | 22 | ||||
-rw-r--r-- | fs/btrfs/mkfs.c | 8 |
3 files changed, 39 insertions, 15 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h index a8454c401cee..90cc2c9bd79e 100644 --- a/fs/btrfs/ctree.h +++ b/fs/btrfs/ctree.h | |||
@@ -136,8 +136,8 @@ struct node { | |||
136 | * owner of the block and the number of references | 136 | * owner of the block and the number of references |
137 | */ | 137 | */ |
138 | struct extent_item { | 138 | struct extent_item { |
139 | u32 refs; | 139 | __le32 refs; |
140 | u64 owner; | 140 | __le64 owner; |
141 | } __attribute__ ((__packed__)); | 141 | } __attribute__ ((__packed__)); |
142 | 142 | ||
143 | /* | 143 | /* |
@@ -153,6 +153,26 @@ struct ctree_path { | |||
153 | int slots[MAX_LEVEL]; | 153 | int slots[MAX_LEVEL]; |
154 | }; | 154 | }; |
155 | 155 | ||
156 | static inline u64 btrfs_extent_owner(struct extent_item *ei) | ||
157 | { | ||
158 | return le64_to_cpu(ei->owner); | ||
159 | } | ||
160 | |||
161 | static inline void btrfs_set_extent_owner(struct extent_item *ei, u64 val) | ||
162 | { | ||
163 | ei->owner = cpu_to_le64(val); | ||
164 | } | ||
165 | |||
166 | static inline u32 btrfs_extent_refs(struct extent_item *ei) | ||
167 | { | ||
168 | return le32_to_cpu(ei->refs); | ||
169 | } | ||
170 | |||
171 | static inline void btrfs_set_extent_refs(struct extent_item *ei, u32 val) | ||
172 | { | ||
173 | ei->refs = cpu_to_le32(val); | ||
174 | } | ||
175 | |||
156 | static inline u64 btrfs_node_blockptr(struct node *n, int nr) | 176 | static inline u64 btrfs_node_blockptr(struct node *n, int nr) |
157 | { | 177 | { |
158 | return le64_to_cpu(n->blockptrs[nr]); | 178 | return le64_to_cpu(n->blockptrs[nr]); |
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index e511f48eb48e..1676a6595cce 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c | |||
@@ -29,6 +29,7 @@ static int inc_block_ref(struct ctree_root *root, u64 blocknr) | |||
29 | struct leaf *l; | 29 | struct leaf *l; |
30 | struct extent_item *item; | 30 | struct extent_item *item; |
31 | struct btrfs_key ins; | 31 | struct btrfs_key ins; |
32 | u32 refs; | ||
32 | 33 | ||
33 | find_free_extent(root->extent_root, 0, 0, (u64)-1, &ins); | 34 | find_free_extent(root->extent_root, 0, 0, (u64)-1, &ins); |
34 | init_path(&path); | 35 | init_path(&path); |
@@ -42,7 +43,8 @@ static int inc_block_ref(struct ctree_root *root, u64 blocknr) | |||
42 | l = &path.nodes[0]->leaf; | 43 | l = &path.nodes[0]->leaf; |
43 | item = (struct extent_item *)(l->data + btrfs_item_offset(l->items + | 44 | item = (struct extent_item *)(l->data + btrfs_item_offset(l->items + |
44 | path.slots[0])); | 45 | path.slots[0])); |
45 | item->refs++; | 46 | refs = btrfs_extent_refs(item); |
47 | btrfs_set_extent_refs(item, refs + 1); | ||
46 | 48 | ||
47 | BUG_ON(list_empty(&path.nodes[0]->dirty)); | 49 | BUG_ON(list_empty(&path.nodes[0]->dirty)); |
48 | release_path(root->extent_root, &path); | 50 | release_path(root->extent_root, &path); |
@@ -69,7 +71,7 @@ static int lookup_block_ref(struct ctree_root *root, u64 blocknr, u32 *refs) | |||
69 | item = (struct extent_item *)(l->data + | 71 | item = (struct extent_item *)(l->data + |
70 | btrfs_item_offset(l->items + | 72 | btrfs_item_offset(l->items + |
71 | path.slots[0])); | 73 | path.slots[0])); |
72 | *refs = item->refs; | 74 | *refs = btrfs_extent_refs(item); |
73 | release_path(root->extent_root, &path); | 75 | release_path(root->extent_root, &path); |
74 | return 0; | 76 | return 0; |
75 | } | 77 | } |
@@ -120,9 +122,9 @@ static int finish_current_insert(struct ctree_root *extent_root) | |||
120 | int i; | 122 | int i; |
121 | int ret; | 123 | int ret; |
122 | 124 | ||
123 | extent_item.refs = 1; | 125 | btrfs_set_extent_refs(&extent_item, 1); |
124 | extent_item.owner = | 126 | btrfs_set_extent_owner(&extent_item, |
125 | btrfs_header_parentid(&extent_root->node->node.header); | 127 | btrfs_header_parentid(&extent_root->node->node.header)); |
126 | ins.offset = 1; | 128 | ins.offset = 1; |
127 | ins.flags = 0; | 129 | ins.flags = 0; |
128 | 130 | ||
@@ -148,6 +150,7 @@ int __free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks) | |||
148 | struct btrfs_item *item; | 150 | struct btrfs_item *item; |
149 | struct extent_item *ei; | 151 | struct extent_item *ei; |
150 | struct btrfs_key ins; | 152 | struct btrfs_key ins; |
153 | u32 refs; | ||
151 | 154 | ||
152 | key.objectid = blocknr; | 155 | key.objectid = blocknr; |
153 | key.flags = 0; | 156 | key.flags = 0; |
@@ -166,8 +169,9 @@ int __free_extent(struct ctree_root *root, u64 blocknr, u64 num_blocks) | |||
166 | ei = (struct extent_item *)(path.nodes[0]->leaf.data + | 169 | ei = (struct extent_item *)(path.nodes[0]->leaf.data + |
167 | btrfs_item_offset(item)); | 170 | btrfs_item_offset(item)); |
168 | BUG_ON(ei->refs == 0); | 171 | BUG_ON(ei->refs == 0); |
169 | ei->refs--; | 172 | refs = btrfs_extent_refs(ei) - 1; |
170 | if (ei->refs == 0) { | 173 | btrfs_set_extent_refs(ei, refs); |
174 | if (refs == 0) { | ||
171 | if (root == extent_root) { | 175 | if (root == extent_root) { |
172 | int err; | 176 | int err; |
173 | radix_tree_preload(GFP_KERNEL); | 177 | radix_tree_preload(GFP_KERNEL); |
@@ -368,8 +372,8 @@ int alloc_extent(struct ctree_root *root, u64 num_blocks, u64 search_start, | |||
368 | struct ctree_root *extent_root = root->extent_root; | 372 | struct ctree_root *extent_root = root->extent_root; |
369 | struct extent_item extent_item; | 373 | struct extent_item extent_item; |
370 | 374 | ||
371 | extent_item.refs = 1; | 375 | btrfs_set_extent_refs(&extent_item, 1); |
372 | extent_item.owner = owner; | 376 | btrfs_set_extent_owner(&extent_item, owner); |
373 | 377 | ||
374 | if (root == extent_root) { | 378 | if (root == extent_root) { |
375 | BUG_ON(extent_root->current_insert.offset == 0); | 379 | BUG_ON(extent_root->current_insert.offset == 0); |
diff --git a/fs/btrfs/mkfs.c b/fs/btrfs/mkfs.c index 0f77babcd306..e0d3bc1d0259 100644 --- a/fs/btrfs/mkfs.c +++ b/fs/btrfs/mkfs.c | |||
@@ -51,8 +51,8 @@ int mkfs(int fd) | |||
51 | btrfs_set_item_offset(&item, | 51 | btrfs_set_item_offset(&item, |
52 | LEAF_DATA_SIZE - sizeof(struct extent_item)); | 52 | LEAF_DATA_SIZE - sizeof(struct extent_item)); |
53 | btrfs_set_item_size(&item, sizeof(struct extent_item)); | 53 | btrfs_set_item_size(&item, sizeof(struct extent_item)); |
54 | extent_item.refs = 1; | 54 | btrfs_set_extent_refs(&extent_item, 1); |
55 | extent_item.owner = 0; | 55 | btrfs_set_extent_owner(&extent_item, 0); |
56 | memcpy(empty_leaf.items, &item, sizeof(item)); | 56 | memcpy(empty_leaf.items, &item, sizeof(item)); |
57 | memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item, | 57 | memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item, |
58 | btrfs_item_size(&item)); | 58 | btrfs_item_size(&item)); |
@@ -62,7 +62,7 @@ int mkfs(int fd) | |||
62 | btrfs_set_key_offset(&item.key, 1); | 62 | btrfs_set_key_offset(&item.key, 1); |
63 | btrfs_set_item_offset(&item, | 63 | btrfs_set_item_offset(&item, |
64 | LEAF_DATA_SIZE - sizeof(struct extent_item) * 2); | 64 | LEAF_DATA_SIZE - sizeof(struct extent_item) * 2); |
65 | extent_item.owner = 1; | 65 | btrfs_set_extent_owner(&extent_item, 1); |
66 | memcpy(empty_leaf.items + 1, &item, sizeof(item)); | 66 | memcpy(empty_leaf.items + 1, &item, sizeof(item)); |
67 | memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item, | 67 | memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item, |
68 | btrfs_item_size(&item)); | 68 | btrfs_item_size(&item)); |
@@ -72,7 +72,7 @@ int mkfs(int fd) | |||
72 | btrfs_set_key_offset(&item.key, 1); | 72 | btrfs_set_key_offset(&item.key, 1); |
73 | btrfs_set_item_offset(&item, | 73 | btrfs_set_item_offset(&item, |
74 | LEAF_DATA_SIZE - sizeof(struct extent_item) * 3); | 74 | LEAF_DATA_SIZE - sizeof(struct extent_item) * 3); |
75 | extent_item.owner = 2; | 75 | btrfs_set_extent_owner(&extent_item, 2); |
76 | memcpy(empty_leaf.items + 2, &item, sizeof(item)); | 76 | memcpy(empty_leaf.items + 2, &item, sizeof(item)); |
77 | memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item, | 77 | memcpy(empty_leaf.data + btrfs_item_offset(&item), &extent_item, |
78 | btrfs_item_size(&item)); | 78 | btrfs_item_size(&item)); |