aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2007-12-11 09:25:06 -0500
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:03:58 -0400
commit74493f7a59bfd4d1c7029c74ab2cd0e400612c6b (patch)
treeb5fc75b08d2edcf8218c814ea02ab6c548e73652 /fs/btrfs/extent-tree.c
parent17636e03f42a1a42fed3834859de4702bd655fd1 (diff)
Btrfs: Implement generation numbers in block pointers
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c60
1 files changed, 58 insertions, 2 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 8ab4954f6ad0..0f1ebdd4e925 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -17,6 +17,7 @@
17 */ 17 */
18 18
19#include <linux/sched.h> 19#include <linux/sched.h>
20#include "hash.h"
20#include "ctree.h" 21#include "ctree.h"
21#include "disk-io.h" 22#include "disk-io.h"
22#include "print-tree.h" 23#include "print-tree.h"
@@ -352,9 +353,63 @@ found:
352 return found_group; 353 return found_group;
353} 354}
354 355
356static u64 hash_extent_ref(u64 root_objectid, u64 root_generation,
357 u64 owner, u64 owner_offset)
358{
359 u32 high_crc = ~(u32)0;
360 u32 low_crc = ~(u32)0;
361 __le64 lenum;
362
363 lenum = cpu_to_le64(root_objectid);
364 high_crc = crc32c(high_crc, &lenum, sizeof(lenum));
365 lenum = cpu_to_le64(root_generation);
366 high_crc = crc32c(high_crc, &lenum, sizeof(lenum));
367
368 lenum = cpu_to_le64(owner);
369 low_crc = crc32c(low_crc, &lenum, sizeof(lenum));
370
371 lenum = cpu_to_le64(owner_offset);
372 low_crc = crc32c(low_crc, &lenum, sizeof(lenum));
373
374 return ((u64)high_crc << 32) | (u64)low_crc;
375}
376
377int insert_extent_ref(struct btrfs_trans_handle *trans,
378 struct btrfs_root *root,
379 struct btrfs_path *path,
380 u64 bytenr,
381 u64 root_objectid, u64 root_generation,
382 u64 owner, u64 owner_offset)
383{
384 u64 hash;
385 struct btrfs_key key;
386 struct btrfs_extent_ref ref;
387 struct extent_buffer *l;
388 struct btrfs_extent_item *item;
389 int ret;
390
391 btrfs_set_stack_ref_root(&ref, root_objectid);
392 btrfs_set_stack_ref_generation(&ref, root_generation);
393 btrfs_set_stack_ref_objectid(&ref, owner);
394 btrfs_set_stack_ref_offset(&ref, owner_offset);
395
396 ret = btrfs_name_hash(&ref, sizeof(ref), &hash);
397 key.offset = hash;
398 key.objectid = bytenr;
399 key.type = BTRFS_EXTENT_REF_KEY;
400
401 ret = btrfs_insert_empty_item(trans, root, path, &key, sizeof(ref));
402 while (ret == -EEXIST) {
403
404 }
405
406}
407
355int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, 408int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
356 struct btrfs_root *root, 409 struct btrfs_root *root,
357 u64 bytenr, u64 num_bytes) 410 u64 bytenr, u64 num_bytes,
411 u64 root_objectid, u64 root_generation,
412 u64 owner, u64 owner_offset)
358{ 413{
359 struct btrfs_path *path; 414 struct btrfs_path *path;
360 int ret; 415 int ret;
@@ -386,9 +441,10 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
386 btrfs_mark_buffer_dirty(path->nodes[0]); 441 btrfs_mark_buffer_dirty(path->nodes[0]);
387 442
388 btrfs_release_path(root->fs_info->extent_root, path); 443 btrfs_release_path(root->fs_info->extent_root, path);
389 btrfs_free_path(path);
390 finish_current_insert(trans, root->fs_info->extent_root); 444 finish_current_insert(trans, root->fs_info->extent_root);
391 del_pending_extents(trans, root->fs_info->extent_root); 445 del_pending_extents(trans, root->fs_info->extent_root);
446
447 btrfs_free_path(path);
392 return 0; 448 return 0;
393} 449}
394 450