btrfs-progs: mixed back ref support
Subsystems (2)
PATCH 1/2 btrfs-progs: mixed back ref support
This patch adds mixed back ref support for btrfs programs. The mixed back ref is a new disk format. back compatilibity is still not implemented. To try the new disk format, you need fresh formatted btrfs.
Signed-off-by Yan Zheng <[email protected]>
---
crc32c.h +1 -0
@@ -24,4 +24,5 @@u32 crc32c_le (u32 seed,unsigned char const *data,size_t length);#define crc32c (seed, data, length) crc32c_le(seed, (unsigned char const *)data, length) +#define btrfs_crc32c crc32c#endif
ctree.c +297 -225
775 lines not on this page · raw message
ctree.h +96 -41
199 lines not on this page · raw message
debug-tree.c +3 -1
@@ -39,7 +39,7 @@ static void print_extent_leaf(struct btr {int i;struct btrfs_item *item; -struct btrfs_extent_ref *ref; +// struct btrfs_extent_ref *ref; struct btrfs_key key;static u64 last =0 ;static u64 last_len =0 ;
@@ -55,6 +55,7 @@ static void print_extent_leaf(struct btr last_len = key.offset; last = key.objectid;break ; +#if 0 case BTRFS_EXTENT_REF_KEY : ref = btrfs_item_ptr(l, i, struct btrfs_extent_ref); printf("%llu %llu extent back ref root %llu gen %llu "
@@ -66,6 +67,7 @@ static void print_extent_leaf(struct btr (unsigned long long )btrfs_ref_objectid (l, ref), (unsigned long)btrfs_ref_num_refs(l, ref));break ; +#endif };fflush (stdout); }
disk-io.c +3 -34
@@ -365,46 +365,19 @@ int btrfs_commit_transaction(struct btrf struct btrfs_root *root) {int ret =0 ; -struct btrfs_root *new_root =NULL ;struct btrfs_fs_info *fs_info = root->fs_info;if (root->commit_root == root->node) goto commit_tree; - new_root =malloc (sizeof (*new_root)); -if (!new_root) -return -ENOMEM ; -memcpy (new_root, root,sizeof (*new_root)); - new_root->node = root->commit_root; +free_extent_buffer (root->commit_root); root->commit_root =NULL ; - root->root_key.offset = trans->transid;btrfs_set_root_bytenr (&root->root_item, root->node->start); -btrfs_set_root_generation (&root->root_item, root->root_key.offset); +btrfs_set_root_generation (&root->root_item, trans->transid); root->root_item.level =btrfs_header_level (root->node); - ret =btrfs_insert_root (trans, fs_info->tree_root, - &root->root_key, &root->root_item); -BUG_ON (ret); - -btrfs_set_root_refs (&new_root->root_item,0 ); ret =btrfs_update_root (trans, root->fs_info->tree_root, - &new_root->root_key, &new_root->root_item); -BUG_ON (ret); - - ret =commit_tree_roots (trans, fs_info); -BUG_ON (ret); - ret =__commit_transaction (trans, root); -BUG_ON (ret); -write_ctree_super (trans, root); -btrfs_finish_extent_commit (trans, fs_info->extent_root, - &fs_info->pinned_extents); -btrfs_free_transaction (root, trans); - fs_info->running_transaction =NULL ; - - trans =btrfs_start_transaction (root,1 ); - ret =btrfs_drop_snapshot (trans, new_root); -BUG_ON (ret); - ret =btrfs_del_root (trans, fs_info->tree_root, &new_root->root_key); + &root->root_key, &root->root_item);BUG_ON (ret); commit_tree: ret =commit_tree_roots (trans, fs_info);
@@ -418,10 +391,6 @@ commit_tree:free_extent_buffer (root->commit_root); root->commit_root =NULL ; fs_info->running_transaction =NULL ; -if (new_root) { -free_extent_buffer (new_root->node); -free (new_root); - }return 0 ; }
extent-tree.c +664 -566
1,603 lines not on this page · raw message
kerncompat.h +1 -0
@@ -191,6 +191,7 @@ static inline long IS_ERR(const void *pt*/ #define printk(fmt, args...) fprintf(stderr, fmt, ##args)#define KERN_CRIT "" +#define KERN_ERR ""/* * kmalloc/kfree
Makefile +4 -4
@@ -1,10 +1,11 @@ CC=gcc -AM_CFLAGS = -Wall -fno-strict-aliasing -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 -CFLAGS = -g -Werror -Os +AM_CFLAGS = -Wall -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2 +CFLAGS = -g objects = ctree.o disk-io.o radix-tree.o extent-tree.o print-tree.o \ root-tree.o dir-item.o file-item.o inode-item.o \ inode-map.o crc32c.o rbtree.o extent-cache.o extent_io.o \ volumes.o utils.o + # CHECKFLAGS=-D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise \ -Wuninitialized -Wshadow -Wundef
@@ -15,8 +16,7 @@ prefix ?= /usr/local bindir = $(prefix)/bin LIBS=-luuid -progs = btrfsctl btrfsck mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol \ - btrfstune btrfs-image +progs = btrfsctl mkfs.btrfs btrfs-debug-tree btrfs-show btrfs-vol btrfsck # make C=1 to enable sparse ifdef C
mkfs.c +1 -1
@@ -252,7 +252,7 @@ static int create_data_reloc_tree(struct location.objectid = objectid; location.type =BTRFS_ROOT_ITEM_KEY ; - location.offset = trans->transid; + location.offset =0 ; ret =btrfs_insert_root (trans, root->fs_info->tree_root, &location, &root_item);BUG_ON (ret);
print-tree.c +43 -14
75 lines not on this page · raw message
utils.c +19 -12
@@ -63,8 +63,8 @@ int make_btrfs(int fd, const char *devicstruct extent_buffer *buf;struct btrfs_root_item root_item;struct btrfs_disk_key disk_key; -struct btrfs_extent_ref *extent_ref;struct btrfs_extent_item *extent_item; +struct btrfs_tree_block_info *block_info;struct btrfs_inode_item *inode_item;struct btrfs_chunk *chunk;struct btrfs_dev_item *dev_item;
@@ -212,25 +212,32 @@ int make_btrfs(int fd, const char *devic extent_item =btrfs_item_ptr (buf, nritems, struct btrfs_extent_item);btrfs_set_extent_refs (buf, extent_item,1 ); +btrfs_set_extent_generation (buf, extent_item,1 ); + nritems++; + +/* create tree block info */ + itemoff = itemoff -sizeof (struct btrfs_tree_block_info ); +btrfs_set_disk_key_objectid (&disk_key, blocks[i]); +btrfs_set_disk_key_offset (&disk_key,0 ); +btrfs_set_disk_key_type (&disk_key,BTRFS_TREE_BLOCK_INFO_KEY ); +btrfs_set_item_key (buf, &disk_key, nritems); +btrfs_set_item_offset (buf,btrfs_item_nr (buf, nritems), + itemoff); +btrfs_set_item_size (buf,btrfs_item_nr (buf, nritems), +sizeof (struct btrfs_tree_block_info )); + block_info =btrfs_item_ptr (buf, nritems, + struct btrfs_tree_block_info); nritems++;/* create extent ref */ ref_root = reference_root_table[i]; - itemoff = itemoff -sizeof (struct btrfs_extent_ref );btrfs_set_disk_key_objectid (&disk_key, blocks[i]); -btrfs_set_disk_key_offset (&disk_key, blocks[i]); -btrfs_set_disk_key_type (&disk_key,BTRFS_EXTENT_REF_KEY ); +btrfs_set_disk_key_offset (&disk_key, ref_root); +btrfs_set_disk_key_type (&disk_key,BTRFS_TREE_BLOCK_REF_KEY );btrfs_set_item_key (buf, &disk_key, nritems);btrfs_set_item_offset (buf,btrfs_item_nr (buf, nritems), itemoff); -btrfs_set_item_size (buf,btrfs_item_nr (buf, nritems), -sizeof (struct btrfs_extent_ref )); - extent_ref =btrfs_item_ptr (buf, nritems, - struct btrfs_extent_ref); -btrfs_set_ref_root (buf, extent_ref, ref_root); -btrfs_set_ref_generation (buf, extent_ref,1 ); -btrfs_set_ref_objectid (buf, extent_ref,0 ); -btrfs_set_ref_num_refs (buf, extent_ref,1 ); +btrfs_set_item_size (buf,btrfs_item_nr (buf, nritems),0 ); nritems++; }btrfs_set_header_bytenr (buf, blocks[2 ]);