[Btrfs-devel][PATCH]Add inode flags support

Yan Zheng
Mon, 07 Jan 2008 02:04:31 -0000

Hello,

This patch adds NODATASUM & NODATACOW inode flags support.

Regards
YZ
----
diff -r 0cb34a2c27ae btrfs_inode.h
--- a/btrfs_inode.h	Fri Jan 04 09:34:54 2008 -0500
+++ b/btrfs_inode.h	Mon Jan 07 17:58:14 2008 +0800
@@ -33,6 +33,7 @@ struct btrfs_inode {
 	 * transid of the trans_handle that last modified this inode
 	 */
 	u64 last_trans;
+	u32 flags;
 };
 static inline struct btrfs_inode *BTRFS_I(struct inode *inode)
 {
diff -r 0cb34a2c27ae ctree.h
--- a/ctree.h	Fri Jan 04 09:34:54 2008 -0500
+++ b/ctree.h	Mon Jan 07 17:58:14 2008 +0800
@@ -447,6 +447,18 @@ struct btrfs_root {
 #define btrfs_set_opt(o, opt)		((o) |= BTRFS_MOUNT_##opt)
 #define btrfs_test_opt(root, opt)	((root)->fs_info->mount_opt & \
 					 BTRFS_MOUNT_##opt)
+/*
+ * Inode flags
+ */
+#define BTRFS_INODE_NODATASUM 		0x1
+#define BTRFS_INODE_NODATACOW 		0x2
+
+#define btrfs_clear_flag(inode, flag)	(BTRFS_I(inode)->flags &= \
+					 ~BTRFS_INODE_##flag)
+#define btrfs_set_flag(inode, flag)	(BTRFS_I(inode)->flags |= \
+					 BTRFS_INODE_##flag)
+#define btrfs_test_flag(inode, flag)	(BTRFS_I(inode)->flags & \
+					 BTRFS_INODE_##flag)

 /* some macros to generate set/get funcs for the struct fields.  This
  * assumes there is a lefoo_to_cpu for every type, so lets make a simple
diff -r 0cb34a2c27ae inode.c
--- a/inode.c	Fri Jan 04 09:34:54 2008 -0500
+++ b/inode.c	Mon Jan 07 17:58:14 2008 +0800
@@ -233,7 +233,8 @@ static int run_delalloc_range(struct ino
 	int ret;

 	mutex_lock(&root->fs_info->fs_mutex);
-	if (btrfs_test_opt(root, NODATACOW))
+	if (btrfs_test_opt(root, NODATACOW) ||
+	    btrfs_test_flag(inode, NODATACOW))
 		ret = run_delalloc_nocow(inode, start, end);
 	else
 		ret = cow_file_range(inode, start, end);
@@ -262,7 +263,8 @@ int btrfs_writepage_io_hook(struct page
 	u64 page_start = (u64)page->index << PAGE_CACHE_SHIFT;
 	size_t offset = start - page_start;

-	if (btrfs_test_opt(root, NODATASUM))
+	if (btrfs_test_opt(root, NODATASUM) ||
+	    btrfs_test_flag(inode, NODATASUM))
 		return 0;

 	mutex_lock(&root->fs_info->fs_mutex);
@@ -288,7 +290,8 @@ int btrfs_readpage_io_hook(struct page *
 	struct btrfs_path *path = NULL;
 	u32 csum;

-	if (btrfs_test_opt(root, NODATASUM))
+	if (btrfs_test_opt(root, NODATASUM) ||
+	    btrfs_test_flag(inode, NODATASUM))
 		return 0;

 	mutex_lock(&root->fs_info->fs_mutex);
@@ -324,7 +327,8 @@ int btrfs_readpage_end_io_hook(struct pa
 	u32 csum = ~(u32)0;
 	unsigned long flags;

-	if (btrfs_test_opt(root, NODATASUM))
+	if (btrfs_test_opt(root, NODATASUM) ||
+	    btrfs_test_flag(inode, NODATASUM))
 		return 0;

 	ret = get_state_private(em_tree, start, &private);
@@ -403,6 +407,7 @@ void btrfs_read_locked_inode(struct inod
 	alloc_group_block = btrfs_inode_block_group(leaf, inode_item);
 	BTRFS_I(inode)->block_group = btrfs_lookup_block_group(root->fs_info,
 						       alloc_group_block);
+	BTRFS_I(inode)->flags = btrfs_inode_flags(leaf, inode_item);

 	if (!BTRFS_I(inode)->block_group) {
 		BTRFS_I(inode)->block_group = btrfs_find_block_group(root,
@@ -472,6 +477,7 @@ static void fill_inode_item(struct exten
 	btrfs_set_inode_nblocks(leaf, item, inode->i_blocks);
 	btrfs_set_inode_generation(leaf, item, inode->i_generation);
 	btrfs_set_inode_rdev(leaf, item, inode->i_rdev);
+	btrfs_set_inode_flags(leaf, item, BTRFS_I(inode)->flags);
 	btrfs_set_inode_block_group(leaf, item,
 				    BTRFS_I(inode)->block_group->key.objectid);
 }
@@ -1428,6 +1434,7 @@ static struct inode *btrfs_new_inode(str
 		owner = 1;
 	group = btrfs_find_block_group(root, group, 0, 0, owner);
 	BTRFS_I(inode)->block_group = group;
+	BTRFS_I(inode)->flags = 0;

 	ret = btrfs_insert_empty_inode(trans, root, path, objectid);
 	if (ret)