update nodatacow code v2
PATCH 3/4 update nodatacow code v2
Hello,
This patch simplifies the nodatacow checker. If all references were created after the latest snapshot, then we can avoid COW safely. This patch also updates run_delalloc_nocow to do more fine-grained checking.
Regards
Signed-off-by Yan Zheng <[email protected]>
---
fs/btrfs/ctree.h +5 -3
@@ -454,6 +454,7 @@ struct btrfs_root_item {__le64 bytenr;__le64 byte_limit;__le64 bytes_used; +__le64 last_snapshot;__le32 flags;__le32 refs;struct btrfs_disk_key drop_progress;
@@ -1413,6 +1414,8 @@ BTRFS_SETGET_STACK_FUNCS(root_refs, stru BTRFS_SETGET_STACK_FUNCS(root_flags, struct btrfs_root_item, flags, 32); BTRFS_SETGET_STACK_FUNCS(root_used, struct btrfs_root_item, bytes_used, 64); BTRFS_SETGET_STACK_FUNCS(root_limit, struct btrfs_root_item, byte_limit, 64); +BTRFS_SETGET_STACK_FUNCS(root_last_snapshot, struct btrfs_root_item, + last_snapshot,64 );/* struct btrfs_super_block */ BTRFS_SETGET_STACK_FUNCS(super_bytenr, struct btrfs_super_block, bytenr, 64);
@@ -1564,9 +1567,8 @@ int btrfs_update_pinned_extents(struct b u64 bytenr, u64 num, int pin);int btrfs_drop_leaf_ref (struct btrfs_trans_handle *trans,struct btrfs_root *root,struct extent_buffer *leaf); -int btrfs_cross_ref_exists (struct btrfs_trans_handle *trans, -struct btrfs_root *root, -struct btrfs_key *key,u64 bytenr); +int btrfs_cross_ref_exist (struct btrfs_trans_handle *trans, +struct btrfs_root *root,u64 bytenr);int btrfs_extent_post_op (struct btrfs_trans_handle *trans,struct btrfs_root *root);int btrfs_copy_pinned (struct btrfs_root *root,struct extent_io_tree *copy);
fs/btrfs/extent-tree.c +18 -113
170 lines not on this page · raw message
fs/btrfs/inode.c +125 -90
255 lines not on this page · raw message
fs/btrfs/ioctl.c +1 -0
@@ -112,6 +112,7 @@ static noinline int create_subvol(structbtrfs_set_root_level (&root_item,0 );btrfs_set_root_refs (&root_item,1 );btrfs_set_root_used (&root_item,0 ); +btrfs_set_root_last_snapshot (&root_item,0 );memset (&root_item.drop_progress,0 ,sizeof (root_item.drop_progress)); root_item.drop_level =0 ;
fs/btrfs/ordered-data.c +3 -6
@@ -165,8 +165,7 @@ static inline struct rb_node *tree_searc* inserted. */ int btrfs_add_ordered_extent (struct inode *inode,u64 file_offset, -u64 start,u64 len,u64 disk_len,int nocow, -int compressed) +u64 start,u64 len,u64 disk_len,int type) {struct btrfs_ordered_inode_tree *tree;struct rb_node *node;
@@ -183,10 +182,8 @@ int btrfs_add_ordered_extent(struct inod entry->len = len; entry->disk_len = disk_len; entry->inode = inode; -if (nocow) -set_bit (BTRFS_ORDERED_NOCOW , &entry->flags); -if (compressed) -set_bit (BTRFS_ORDERED_COMPRESSED , &entry->flags); +if (type ==BTRFS_ORDERED_NOCOW || type ==BTRFS_ORDERED_COMPRESSED ) +set_bit (type, &entry->flags);/* one ref for the tree */ atomic_set (&entry->refs,1 );
fs/btrfs/ordered-data.h +1 -2
@@ -132,8 +132,7 @@ int btrfs_remove_ordered_extent(struct iint btrfs_dec_test_ordered_pending (struct inode *inode,u64 file_offset,u64 io_size);int btrfs_add_ordered_extent (struct inode *inode,u64 file_offset, -u64 start,u64 len,u64 disk_len,int nocow, -int compressed); +u64 start,u64 len,u64 disk_len,int type);int btrfs_add_ordered_sum (struct inode *inode,struct btrfs_ordered_extent *entry,struct btrfs_ordered_sum *sum);
fs/btrfs/transaction.c +2 -0
@@ -751,6 +751,8 @@ static noinline int create_pending_snapsif (ret) goto fail; +btrfs_record_root_in_trans (root); +btrfs_set_root_last_snapshot (&root->root_item, trans->transid);memcpy (new_root_item, &root->root_item,sizeof (*new_root_item)); key.objectid = objectid;