Add fallocate support v2
PATCH 4/4 Add fallocate support v2
Hello,
This patch updates btrfs-progs for fallocate support.
Regards
Signed-off-by Yan Zheng <[email protected]>
---
fs/btrfs/ctree.h +7 -2
@@ -462,8 +462,9 @@ struct btrfs_root_item {u8 level; } __attribute__ ((__packed__)); -#define BTRFS_FILE_EXTENT_REG 0 -#define BTRFS_FILE_EXTENT_INLINE 1 +#define BTRFS_FILE_EXTENT_INLINE 0 +#define BTRFS_FILE_EXTENT_REG 1 +#define BTRFS_FILE_EXTENT_PREALLOC 2struct btrfs_file_extent_item {/*
@@ -868,6 +869,7 @@ struct btrfs_root {#define BTRFS_INODE_NODATACOW (1 << 1)#define BTRFS_INODE_READONLY (1 << 2)#define BTRFS_INODE_NOCOMPRESS (1 << 3) +#define BTRFS_INODE_PREALLOC (1 << 4)#define btrfs_clear_flag (inode, flag) (BTRFS_I(inode)->flags &= \ ~BTRFS_INODE_##flag)#define btrfs_set_flag (inode, flag) (BTRFS_I(inode)->flags |= \
@@ -1924,6 +1926,9 @@ extern struct file_operations btrfs_fileint btrfs_drop_extents (struct btrfs_trans_handle *trans,struct btrfs_root *root,struct inode *inode,u64 start,u64 end,u64 inline_limit,u64 *hint_block); +int btrfs_mark_extent_written (struct btrfs_trans_handle *trans, +struct btrfs_root *root, +struct inode *inode,u64 start,u64 end);int btrfs_release_file (struct inode *inode,struct file *file);/* tree-defrag.c */
fs/btrfs/extent_io.c +9 -3
@@ -2015,6 +2015,8 @@ printk("2bad mapping end %Lu cur %Lu\n", } bdev = em->bdev; block_start = em->block_start; +if (test_bit (EXTENT_FLAG_PREALLOC , &em->flags)) + block_start =EXTENT_MAP_HOLE ;free_extent_map (em); em =NULL ;
@@ -2769,14 +2771,18 @@ sector_t extent_bmap(struct address_spacstruct inode *inode = mapping->host;u64 start = iblock << inode->i_blkbits;sector_t sector =0 ; +size_t blksize = (1 << inode->i_blkbits);struct extent_map *em; - em =get_extent (inode,NULL ,0 , start, (1 << inode->i_blkbits),0 ); +lock_extent (&BTRFS_I (inode)->io_tree, start, start + blksize -1 , +GFP_NOFS ); + em =get_extent (inode,NULL ,0 , start, blksize,0 ); +unlock_extent (&BTRFS_I (inode)->io_tree, start, start + blksize -1 , +GFP_NOFS );if (!em ||IS_ERR (em))return 0 ; -if (em->block_start ==EXTENT_MAP_INLINE || - em->block_start ==EXTENT_MAP_HOLE ) +if (em->block_start >EXTENT_MAP_LAST_BYTE ) goto out; sector = (em->block_start + start - em->start) >> inode->i_blkbits;
fs/btrfs/extent_map.h +1 -0
@@ -12,6 +12,7 @@#define EXTENT_FLAG_PINNED 0/* this entry not yet on disk, don't free it */ #define EXTENT_FLAG_COMPRESSED 1#define EXTENT_FLAG_VACANCY 2/* no file extent item found */ +#define EXTENT_FLAG_PREALLOC 3/* pre-allocated extent */ struct extent_map {struct rb_node rb_node;
fs/btrfs/extent-tree.c +36 -29
185 lines not on this page · raw message
fs/btrfs/file.c +241 -4
269 lines not on this page · raw message
fs/btrfs/inode.c +253 -72
439 lines not on this page · raw message
fs/btrfs/ioctl.c +2 -1
@@ -724,7 +724,8 @@ long btrfs_ioctl_clone(struct file *file extent =btrfs_item_ptr (leaf, slot, struct btrfs_file_extent_item); found_type =btrfs_file_extent_type (leaf, extent); -if (found_type ==BTRFS_FILE_EXTENT_REG ) { +if (found_type ==BTRFS_FILE_EXTENT_REG || + found_type ==BTRFS_FILE_EXTENT_PREALLOC ) {u64 ds =btrfs_file_extent_disk_bytenr (leaf, extent); u64 dl = btrfs_file_extent_disk_num_bytes(leaf,
fs/btrfs/ordered-data.c +3 -2
@@ -182,7 +182,7 @@ int btrfs_add_ordered_extent(struct inod entry->len = len; entry->disk_len = disk_len; entry->inode = inode; -if (type ==BTRFS_ORDERED_NOCOW || type ==BTRFS_ORDERED_COMPRESSED ) +if (type !=BTRFS_ORDERED_IO_DONE && type !=BTRFS_ORDERED_COMPLETE )set_bit (type, &entry->flags);/* one ref for the tree */
@@ -339,7 +339,8 @@ int btrfs_wait_ordered_extents(struct bt ordered = list_entry(cur, struct btrfs_ordered_extent, root_extent_list);if (nocow_only && - !test_bit (BTRFS_ORDERED_NOCOW , &ordered->flags)) { + !test_bit (BTRFS_ORDERED_NOCOW , &ordered->flags) && + !test_bit (BTRFS_ORDERED_PREALLOC , &ordered->flags)) {list_move (&ordered->root_extent_list, &root->fs_info->ordered_extents);cond_resched_lock (&root->fs_info->ordered_extent_lock);
fs/btrfs/ordered-data.h +3 -1
@@ -68,6 +68,8 @@ struct btrfs_ordered_sum {#define BTRFS_ORDERED_COMPRESSED 3/* writing a compressed extent */ +#define BTRFS_ORDERED_PREALLOC 4/* set when writing to prealloced extent */ +struct btrfs_ordered_extent {/* logical offset in the file */ u64 file_offset;
@@ -132,7 +134,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 type); +u64 start,u64 len,u64 disk_len,int tyep);int btrfs_add_ordered_sum (struct inode *inode,struct btrfs_ordered_extent *entry,struct btrfs_ordered_sum *sum);
fs/btrfs/tree-log.c +9 -4
@@ -442,7 +442,8 @@ insert: fi = (struct btrfs_file_extent_item *)dst_ptr; extent_type =btrfs_file_extent_type (path->nodes[0 ], fi); -if (extent_type ==BTRFS_FILE_EXTENT_REG ) { +if (extent_type ==BTRFS_FILE_EXTENT_REG || + extent_type ==BTRFS_FILE_EXTENT_PREALLOC ) {struct btrfs_key ins; ins.objectid =btrfs_file_extent_disk_bytenr ( path->nodes[0 ], fi);
@@ -538,7 +539,8 @@ static noinline int replay_one_extent(st item = btrfs_item_ptr(eb, slot, struct btrfs_file_extent_item); found_type =btrfs_file_extent_type (eb, item); -if (found_type ==BTRFS_FILE_EXTENT_REG ) +if (found_type ==BTRFS_FILE_EXTENT_REG || + found_type ==BTRFS_FILE_EXTENT_PREALLOC ) extent_end = start +btrfs_file_extent_num_bytes (eb, item);else if (found_type ==BTRFS_FILE_EXTENT_INLINE ) { size =btrfs_file_extent_inline_len (eb, item);
@@ -562,7 +564,9 @@ static noinline int replay_one_extent(st ret =btrfs_lookup_file_extent (trans, root, path, inode->i_ino, start,0 ); -if (ret ==0 && found_type ==BTRFS_FILE_EXTENT_REG ) { +if (ret ==0 && + (found_type ==BTRFS_FILE_EXTENT_REG || + found_type ==BTRFS_FILE_EXTENT_PREALLOC )) {struct btrfs_file_extent_item cmp1;struct btrfs_file_extent_item cmp2;struct btrfs_file_extent_item *existing;
@@ -2522,7 +2526,8 @@ static noinline int copy_items(struct bt struct btrfs_file_extent_item); found_type =btrfs_file_extent_type (src, extent); -if (found_type ==BTRFS_FILE_EXTENT_REG ) { +if (found_type ==BTRFS_FILE_EXTENT_REG || + found_type ==BTRFS_FILE_EXTENT_PREALLOC ) {u64 ds =btrfs_file_extent_disk_bytenr (src, extent); u64 dl = btrfs_file_extent_disk_num_bytes(src,
Quoted 3 lines · Yan Zheng
Hello,
This patch updates btrfs-progs for fallocate support.
Thanks for rediffing these, one question though:
fs/btrfs/ctree.h struct btrfs_root_item { · line 467
Quoted 12 lines
diff -urp
4/fs/btrfs/ctree.h5/fs/btrfs/ctree.hfs/btrfs/ctree.h +3
-2@@ -462,8 +462,9 @@ struct btrfs_root_item {u8 level; } __attribute__ ((__packed__)); -#define BTRFS_FILE_EXTENT_REG 0 -#define BTRFS_FILE_EXTENT_INLINE 1 +#define BTRFS_FILE_EXTENT_INLINE 0 +#define BTRFS_FILE_EXTENT_REG 1 +#define BTRFS_FILE_EXTENT_PREALLOC 2
Why do we swap these around?
-chris