diff options
author | Chris Mason <chris.mason@oracle.com> | 2007-03-15 12:56:47 -0400 |
---|---|---|
committer | David Woodhouse <dwmw2@hera.kernel.org> | 2007-03-15 12:56:47 -0400 |
commit | 62e2749e03a855d98855f9ce032dbe72d5fad148 (patch) | |
tree | ed12521d1bde4ac7eda7f917b57b3cab1e76539d /fs/btrfs/ctree.c | |
parent | a1516c8921ce2c148b69493e858d95bc79c92f01 (diff) |
Btrfs: Use a chunk of the key flags to record the item type.
Add (untested and simple) directory item code
Fix comp_keys to use the new key ordering
Add btrfs_insert_empty_item
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ctree.c')
-rw-r--r-- | fs/btrfs/ctree.c | 51 |
1 files changed, 34 insertions, 17 deletions
diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c index ece8de7f38ef..7edfbd468042 100644 --- a/fs/btrfs/ctree.c +++ b/fs/btrfs/ctree.c | |||
@@ -107,14 +107,14 @@ static int comp_keys(struct btrfs_disk_key *disk, struct btrfs_key *k2) | |||
107 | return 1; | 107 | return 1; |
108 | if (k1.objectid < k2->objectid) | 108 | if (k1.objectid < k2->objectid) |
109 | return -1; | 109 | return -1; |
110 | if (k1.flags > k2->flags) | ||
111 | return 1; | ||
112 | if (k1.flags < k2->flags) | ||
113 | return -1; | ||
114 | if (k1.offset > k2->offset) | 110 | if (k1.offset > k2->offset) |
115 | return 1; | 111 | return 1; |
116 | if (k1.offset < k2->offset) | 112 | if (k1.offset < k2->offset) |
117 | return -1; | 113 | return -1; |
114 | if (k1.flags > k2->flags) | ||
115 | return 1; | ||
116 | if (k1.flags < k2->flags) | ||
117 | return -1; | ||
118 | return 0; | 118 | return 0; |
119 | } | 119 | } |
120 | 120 | ||
@@ -1122,8 +1122,8 @@ static int split_leaf(struct btrfs_root *root, struct btrfs_path *path, | |||
1122 | * Given a key and some data, insert an item into the tree. | 1122 | * Given a key and some data, insert an item into the tree. |
1123 | * This does all the path init required, making room in the tree if needed. | 1123 | * This does all the path init required, making room in the tree if needed. |
1124 | */ | 1124 | */ |
1125 | int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *cpu_key, | 1125 | int btrfs_insert_empty_item(struct btrfs_root *root, struct btrfs_path *path, |
1126 | void *data, int data_size) | 1126 | struct btrfs_key *cpu_key, u32 data_size) |
1127 | { | 1127 | { |
1128 | int ret = 0; | 1128 | int ret = 0; |
1129 | int slot; | 1129 | int slot; |
@@ -1132,7 +1132,6 @@ int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *cpu_key, | |||
1132 | struct btrfs_buffer *leaf_buf; | 1132 | struct btrfs_buffer *leaf_buf; |
1133 | u32 nritems; | 1133 | u32 nritems; |
1134 | unsigned int data_end; | 1134 | unsigned int data_end; |
1135 | struct btrfs_path path; | ||
1136 | struct btrfs_disk_key disk_key; | 1135 | struct btrfs_disk_key disk_key; |
1137 | 1136 | ||
1138 | btrfs_cpu_key_to_disk(&disk_key, cpu_key); | 1137 | btrfs_cpu_key_to_disk(&disk_key, cpu_key); |
@@ -1140,17 +1139,16 @@ int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *cpu_key, | |||
1140 | /* create a root if there isn't one */ | 1139 | /* create a root if there isn't one */ |
1141 | if (!root->node) | 1140 | if (!root->node) |
1142 | BUG(); | 1141 | BUG(); |
1143 | btrfs_init_path(&path); | 1142 | ret = btrfs_search_slot(root, cpu_key, path, data_size, 1); |
1144 | ret = btrfs_search_slot(root, cpu_key, &path, data_size, 1); | ||
1145 | if (ret == 0) { | 1143 | if (ret == 0) { |
1146 | btrfs_release_path(root, &path); | 1144 | btrfs_release_path(root, path); |
1147 | return -EEXIST; | 1145 | return -EEXIST; |
1148 | } | 1146 | } |
1149 | if (ret < 0) | 1147 | if (ret < 0) |
1150 | goto out; | 1148 | goto out; |
1151 | 1149 | ||
1152 | slot_orig = path.slots[0]; | 1150 | slot_orig = path->slots[0]; |
1153 | leaf_buf = path.nodes[0]; | 1151 | leaf_buf = path->nodes[0]; |
1154 | leaf = &leaf_buf->leaf; | 1152 | leaf = &leaf_buf->leaf; |
1155 | 1153 | ||
1156 | nritems = btrfs_header_nritems(&leaf->header); | 1154 | nritems = btrfs_header_nritems(&leaf->header); |
@@ -1160,7 +1158,7 @@ int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *cpu_key, | |||
1160 | sizeof(struct btrfs_item) + data_size) | 1158 | sizeof(struct btrfs_item) + data_size) |
1161 | BUG(); | 1159 | BUG(); |
1162 | 1160 | ||
1163 | slot = path.slots[0]; | 1161 | slot = path->slots[0]; |
1164 | BUG_ON(slot < 0); | 1162 | BUG_ON(slot < 0); |
1165 | if (slot != nritems) { | 1163 | if (slot != nritems) { |
1166 | int i; | 1164 | int i; |
@@ -1186,23 +1184,42 @@ int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *cpu_key, | |||
1186 | data_end, old_data - data_end); | 1184 | data_end, old_data - data_end); |
1187 | data_end = old_data; | 1185 | data_end = old_data; |
1188 | } | 1186 | } |
1189 | /* copy the new data in */ | 1187 | /* setup the item for the new data */ |
1190 | memcpy(&leaf->items[slot].key, &disk_key, | 1188 | memcpy(&leaf->items[slot].key, &disk_key, |
1191 | sizeof(struct btrfs_disk_key)); | 1189 | sizeof(struct btrfs_disk_key)); |
1192 | btrfs_set_item_offset(leaf->items + slot, data_end - data_size); | 1190 | btrfs_set_item_offset(leaf->items + slot, data_end - data_size); |
1193 | btrfs_set_item_size(leaf->items + slot, data_size); | 1191 | btrfs_set_item_size(leaf->items + slot, data_size); |
1194 | memcpy(btrfs_leaf_data(leaf) + data_end - data_size, data, data_size); | ||
1195 | btrfs_set_header_nritems(&leaf->header, nritems + 1); | 1192 | btrfs_set_header_nritems(&leaf->header, nritems + 1); |
1196 | 1193 | ||
1197 | ret = 0; | 1194 | ret = 0; |
1198 | if (slot == 0) | 1195 | if (slot == 0) |
1199 | ret = fixup_low_keys(root, &path, &disk_key, 1); | 1196 | ret = fixup_low_keys(root, path, &disk_key, 1); |
1200 | 1197 | ||
1201 | BUG_ON(list_empty(&leaf_buf->dirty)); | 1198 | BUG_ON(list_empty(&leaf_buf->dirty)); |
1202 | if (btrfs_leaf_free_space(root, leaf) < 0) | 1199 | if (btrfs_leaf_free_space(root, leaf) < 0) |
1203 | BUG(); | 1200 | BUG(); |
1204 | check_leaf(root, &path, 0); | 1201 | check_leaf(root, path, 0); |
1205 | out: | 1202 | out: |
1203 | return ret; | ||
1204 | } | ||
1205 | |||
1206 | /* | ||
1207 | * Given a key and some data, insert an item into the tree. | ||
1208 | * This does all the path init required, making room in the tree if needed. | ||
1209 | */ | ||
1210 | int btrfs_insert_item(struct btrfs_root *root, struct btrfs_key *cpu_key, | ||
1211 | void *data, u32 data_size) | ||
1212 | { | ||
1213 | int ret = 0; | ||
1214 | struct btrfs_path path; | ||
1215 | u8 *ptr; | ||
1216 | |||
1217 | btrfs_init_path(&path); | ||
1218 | ret = btrfs_insert_empty_item(root, &path, cpu_key, data_size); | ||
1219 | if (!ret) { | ||
1220 | ptr = btrfs_item_ptr(&path.nodes[0]->leaf, path.slots[0], u8); | ||
1221 | memcpy(ptr, data, data_size); | ||
1222 | } | ||
1206 | btrfs_release_path(root, &path); | 1223 | btrfs_release_path(root, &path); |
1207 | return ret; | 1224 | return ret; |
1208 | } | 1225 | } |