[Btrfs-devel][PATCH]Add customized find_free_extent support to btrfs-progs

Yan Zheng yanzheng at 21cn.com
Fri Jan 4 06:52:33 PST 2008


Hello,

This patch adds customized find_free_extent support to btrfs-progs,
the conversion program requires this.

The attachment is the ext3 to btrfs conversion program. it can be
compiled by add following two line to btrfs-progs's Makefile.

convert: $(objects) convert.o utils.o
	gcc $(CFLAGS) -o convert $(objects) convert.o utils.o -luuid -lext2fs
$(LDFLAGS)


Regards
YZ
----
diff -ur a/ctree.h b/ctree.h
--- a/ctree.h	2008-01-04 13:36:25.000000000 +0800
+++ b/ctree.h	2008-01-04 13:28:44.000000000 +0800
@@ -299,6 +299,13 @@
 	u64 pinned;
 };

+struct btrfs_extent_ops {
+       int (*alloc_extent)(struct btrfs_root *root, u64 num_bytes,
+		           u64 hint_byte, struct btrfs_key *ins);
+       int (*free_extent)(struct btrfs_root *root, u64 bytenr,
+		          u64 num_bytes);
+};
+
 struct btrfs_fs_info {
 	u8 fsid[BTRFS_FSID_SIZE];
 	struct btrfs_root *fs_root;
@@ -322,6 +329,9 @@
 	struct mutex fs_mutex;
 	int fp;
 	u64 total_pinned;
+
+	struct btrfs_extent_ops *extent_ops;
+	void *priv_data;
 };

 /*
diff -ur a/disk-io.c b/disk-io.c
--- a/disk-io.c	2008-01-04 14:43:44.000000000 +0800
+++ b/disk-io.c	2008-01-04 13:29:09.000000000 +0800
@@ -396,6 +397,8 @@
 	fs_info->fs_root = root;
 	fs_info->tree_root = tree_root;
 	fs_info->extent_root = extent_root;
+	fs_info->extent_ops = NULL;
+	fs_info->priv_data = NULL;

 	extent_map_tree_init(&fs_info->extent_cache);
 	extent_map_tree_init(&fs_info->free_space_cache);
diff -ur a/extent-tree.c b/extent-tree.c
--- a/extent-tree.c	2008-01-04 13:14:16.000000000 +0800
+++ b/extent-tree.c	2008-01-04 13:08:39.000000000 +0800
@@ -1209,6 +1209,7 @@
 	struct btrfs_path *path;
 	struct btrfs_key key;
 	struct btrfs_fs_info *info = root->fs_info;
+	struct btrfs_extent_ops *ops = info->extent_ops;
 	struct btrfs_root *extent_root = info->extent_root;
 	struct extent_buffer *leaf;
 	int ret;
@@ -1274,9 +1275,12 @@
 					   root_used - num_bytes);

 		ret = btrfs_del_item(trans, extent_root, path);
-		if (ret) {
+		if (ret)
 			return ret;
-		}
+
+		if (ops && ops->free_extent)
+			ops->free_extent(root, bytenr, num_bytes);
+
 		ret = update_block_group(trans, root, bytenr, num_bytes, 0,
 					 mark_free, 0);
 		BUG_ON(ret);
@@ -1626,6 +1630,7 @@
 	u64 new_hint;
 	*/
 	struct btrfs_fs_info *info = root->fs_info;
+	struct btrfs_extent_ops *ops = info->extent_ops;
 	struct btrfs_root *extent_root = info->extent_root;
 	struct btrfs_extent_item extent_item;
 	struct btrfs_path *path;
@@ -1639,10 +1644,14 @@
 	*/

 	WARN_ON(num_bytes < root->sectorsize);
-	ret = find_free_extent(trans, root, num_bytes, empty_size,
-			       search_start, search_end, hint_byte, ins,
-			       trans->alloc_exclude_start,
-			       trans->alloc_exclude_nr, data);
+	if (ops && ops->alloc_extent) {
+		ret = ops->alloc_extent(root, num_bytes, hint_byte, ins);
+	} else {
+		ret = find_free_extent(trans, root, num_bytes, empty_size,
+				        search_start, search_end, hint_byte,
+					ins, trans->alloc_exclude_start,
+					trans->alloc_exclude_nr, data);
+	}
 	BUG_ON(ret);
 	if (ret)
 		return ret;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: convert.c
Type: text/x-csrc
Size: 33986 bytes
Desc: not available
Url : http://oss.oracle.com/pipermail/btrfs-devel/attachments/20080104/ec465c62/convert-0001.bin


More information about the Btrfs-devel mailing list