Commit 9f2e3a53 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'for-5.2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux

Pull btrfs updates from David Sterba:
 "This time the majority of changes are cleanups, though there's still a
  number of changes of user interest.

  User visible changes:

   - better read time and write checks to catch errors early and before
     writing data to disk (to catch potential memory corruption on data
     that get checksummed)

   - qgroups + metadata relocation: last speed up patch int the series
     to address the slowness, there should be no overhead comparing
     balance with and without qgroups

   - FIEMAP ioctl does not start a transaction unnecessarily, this can
     result in a speed up and less blocking due to IO

   - LOGICAL_INO (v1, v2) does not start transaction unnecessarily, this
     can speed up the mentioned ioctl and scrub as well

   - fsync on files with many (but not too many) hardlinks is faster,
     finer decision if the links should be fsynced individually or
     completely

   - send tries harder to find ranges to clone

   - trim/discard will skip unallocated chunks that haven't been touched
     since the last mount

  Fixes:

   - send flushes delayed allocation before start, otherwise it could
     miss some changes in case of a very recent rw->ro switch of a
     subvolume

   - fix fallocate with qgroups that could lead to space accounting
     underflow, reported as a warning

   - trim/discard ioctl honours the requested range

   - starting send and dedupe on a subvolume at the same time will let
     only one of them succeed, this is to prevent changes that send
     could miss due to dedupe; both operations are restartable

  Core changes:

   - more tree-checker validations, errors reported by fuzzing tools:
      - device item
      - inode item
      - block group profiles

   - tracepoints for extent buffer locking

   - async cow preallocates memory to avoid errors happening too deep in
     the call chain

   - metadata reservations for delalloc reworked to better adapt in
     many-writers/low-space scenarios

   - improved space flushing logic for intense DIO vs buffered workloads

   - lots of cleanups
      - removed unused struct members
      - redundant argument removal
      - properties and xattrs
      - extent buffer locking
      - selftests
      - use common file type conversions
      - many-argument functions reduction"

* tag 'for-5.2-tag' of git://git.kernel.org/pub/scm/linux/kernel/git/kdave/linux: (227 commits)
  btrfs: Use kvmalloc for allocating compressed path context
  btrfs: Factor out common extent locking code in submit_compressed_extents
  btrfs: Set io_tree only once in submit_compressed_extents
  btrfs: Replace clear_extent_bit with unlock_extent
  btrfs: Make compress_file_range take only struct async_chunk
  btrfs: Remove fs_info from struct async_chunk
  btrfs: Rename async_cow to async_chunk
  btrfs: Preallocate chunks in cow_file_range_async
  btrfs: reserve delalloc metadata differently
  btrfs: track DIO bytes in flight
  btrfs: merge calls of btrfs_setxattr and btrfs_setxattr_trans in btrfs_set_prop
  btrfs: delete unused function btrfs_set_prop_trans
  btrfs: start transaction in xattr_handler_set_prop
  btrfs: drop local copy of inode i_mode
  btrfs: drop old_fsflags in btrfs_ioctl_setflags
  btrfs: modify local copy of btrfs_inode flags
  btrfs: drop useless inode i_flags copy and restore
  btrfs: start transaction in btrfs_ioctl_setflags()
  btrfs: export btrfs_set_prop
  btrfs: refactor btrfs_set_props to validate externally
  ...
parents 78438ce1 b1c16ac9
...@@ -93,7 +93,11 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans, ...@@ -93,7 +93,11 @@ static int __btrfs_set_acl(struct btrfs_trans_handle *trans,
goto out; goto out;
} }
ret = btrfs_setxattr(trans, inode, name, value, size, 0); if (trans)
ret = btrfs_setxattr(trans, inode, name, value, size, 0);
else
ret = btrfs_setxattr_trans(inode, name, value, size, 0);
out: out:
kfree(value); kfree(value);
......
...@@ -791,7 +791,7 @@ static int add_delayed_refs(const struct btrfs_fs_info *fs_info, ...@@ -791,7 +791,7 @@ static int add_delayed_refs(const struct btrfs_fs_info *fs_info,
count = node->ref_mod * -1; count = node->ref_mod * -1;
break; break;
default: default:
BUG_ON(1); BUG();
} }
*total_refs += count; *total_refs += count;
switch (node->type) { switch (node->type) {
...@@ -1460,8 +1460,8 @@ int btrfs_find_all_roots(struct btrfs_trans_handle *trans, ...@@ -1460,8 +1460,8 @@ int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
* callers (such as fiemap) which want to know whether the extent is * callers (such as fiemap) which want to know whether the extent is
* shared but do not need a ref count. * shared but do not need a ref count.
* *
* This attempts to allocate a transaction in order to account for * This attempts to attach to the running transaction in order to account for
* delayed refs, but continues on even when the alloc fails. * delayed refs, but continues on even when no running transaction exists.
* *
* Return: 0 if extent is not shared, 1 if it is shared, < 0 on error. * Return: 0 if extent is not shared, 1 if it is shared, < 0 on error.
*/ */
...@@ -1484,13 +1484,16 @@ int btrfs_check_shared(struct btrfs_root *root, u64 inum, u64 bytenr) ...@@ -1484,13 +1484,16 @@ int btrfs_check_shared(struct btrfs_root *root, u64 inum, u64 bytenr)
tmp = ulist_alloc(GFP_NOFS); tmp = ulist_alloc(GFP_NOFS);
roots = ulist_alloc(GFP_NOFS); roots = ulist_alloc(GFP_NOFS);
if (!tmp || !roots) { if (!tmp || !roots) {
ulist_free(tmp); ret = -ENOMEM;
ulist_free(roots); goto out;
return -ENOMEM;
} }
trans = btrfs_join_transaction(root); trans = btrfs_attach_transaction(root);
if (IS_ERR(trans)) { if (IS_ERR(trans)) {
if (PTR_ERR(trans) != -ENOENT && PTR_ERR(trans) != -EROFS) {
ret = PTR_ERR(trans);
goto out;
}
trans = NULL; trans = NULL;
down_read(&fs_info->commit_root_sem); down_read(&fs_info->commit_root_sem);
} else { } else {
...@@ -1523,6 +1526,7 @@ int btrfs_check_shared(struct btrfs_root *root, u64 inum, u64 bytenr) ...@@ -1523,6 +1526,7 @@ int btrfs_check_shared(struct btrfs_root *root, u64 inum, u64 bytenr)
} else { } else {
up_read(&fs_info->commit_root_sem); up_read(&fs_info->commit_root_sem);
} }
out:
ulist_free(tmp); ulist_free(tmp);
ulist_free(roots); ulist_free(roots);
return ret; return ret;
...@@ -1747,7 +1751,7 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical, ...@@ -1747,7 +1751,7 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical,
else if (flags & BTRFS_EXTENT_FLAG_DATA) else if (flags & BTRFS_EXTENT_FLAG_DATA)
*flags_ret = BTRFS_EXTENT_FLAG_DATA; *flags_ret = BTRFS_EXTENT_FLAG_DATA;
else else
BUG_ON(1); BUG();
return 0; return 0;
} }
...@@ -1912,13 +1916,19 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info, ...@@ -1912,13 +1916,19 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
extent_item_objectid); extent_item_objectid);
if (!search_commit_root) { if (!search_commit_root) {
trans = btrfs_join_transaction(fs_info->extent_root); trans = btrfs_attach_transaction(fs_info->extent_root);
if (IS_ERR(trans)) if (IS_ERR(trans)) {
return PTR_ERR(trans); if (PTR_ERR(trans) != -ENOENT &&
PTR_ERR(trans) != -EROFS)
return PTR_ERR(trans);
trans = NULL;
}
}
if (trans)
btrfs_get_tree_mod_seq(fs_info, &tree_mod_seq_elem); btrfs_get_tree_mod_seq(fs_info, &tree_mod_seq_elem);
} else { else
down_read(&fs_info->commit_root_sem); down_read(&fs_info->commit_root_sem);
}
ret = btrfs_find_all_leafs(trans, fs_info, extent_item_objectid, ret = btrfs_find_all_leafs(trans, fs_info, extent_item_objectid,
tree_mod_seq_elem.seq, &refs, tree_mod_seq_elem.seq, &refs,
...@@ -1951,7 +1961,7 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info, ...@@ -1951,7 +1961,7 @@ int iterate_extent_inodes(struct btrfs_fs_info *fs_info,
free_leaf_list(refs); free_leaf_list(refs);
out: out:
if (!search_commit_root) { if (trans) {
btrfs_put_tree_mod_seq(fs_info, &tree_mod_seq_elem); btrfs_put_tree_mod_seq(fs_info, &tree_mod_seq_elem);
btrfs_end_transaction(trans); btrfs_end_transaction(trans);
} else { } else {
......
...@@ -147,12 +147,6 @@ struct btrfs_inode { ...@@ -147,12 +147,6 @@ struct btrfs_inode {
*/ */
u64 last_unlink_trans; u64 last_unlink_trans;
/*
* Track the transaction id of the last transaction used to create a
* hard link for the inode. This is used by the log tree (fsync).
*/
u64 last_link_trans;
/* /*
* Number of bytes outstanding that are going to need csums. This is * Number of bytes outstanding that are going to need csums. This is
* used in ENOSPC accounting. * used in ENOSPC accounting.
...@@ -203,8 +197,6 @@ struct btrfs_inode { ...@@ -203,8 +197,6 @@ struct btrfs_inode {
struct inode vfs_inode; struct inode vfs_inode;
}; };
extern unsigned char btrfs_filetype_table[];
static inline struct btrfs_inode *BTRFS_I(const struct inode *inode) static inline struct btrfs_inode *BTRFS_I(const struct inode *inode)
{ {
return container_of(inode, struct btrfs_inode, vfs_inode); return container_of(inode, struct btrfs_inode, vfs_inode);
......
...@@ -251,7 +251,7 @@ static void end_compressed_bio_write(struct bio *bio) ...@@ -251,7 +251,7 @@ static void end_compressed_bio_write(struct bio *bio)
cb->compressed_pages[0]->mapping = cb->inode->i_mapping; cb->compressed_pages[0]->mapping = cb->inode->i_mapping;
btrfs_writepage_endio_finish_ordered(cb->compressed_pages[0], btrfs_writepage_endio_finish_ordered(cb->compressed_pages[0],
cb->start, cb->start + cb->len - 1, cb->start, cb->start + cb->len - 1,
bio->bi_status ? BLK_STS_OK : BLK_STS_NOTSUPP); bio->bi_status == BLK_STS_OK);
cb->compressed_pages[0]->mapping = NULL; cb->compressed_pages[0]->mapping = NULL;
end_compressed_writeback(inode, cb); end_compressed_writeback(inode, cb);
......
This diff is collapsed.
...@@ -41,6 +41,7 @@ extern struct kmem_cache *btrfs_bit_radix_cachep; ...@@ -41,6 +41,7 @@ extern struct kmem_cache *btrfs_bit_radix_cachep;
extern struct kmem_cache *btrfs_path_cachep; extern struct kmem_cache *btrfs_path_cachep;
extern struct kmem_cache *btrfs_free_space_cachep; extern struct kmem_cache *btrfs_free_space_cachep;
struct btrfs_ordered_sum; struct btrfs_ordered_sum;
struct btrfs_ref;
#define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */ #define BTRFS_MAGIC 0x4D5F53665248425FULL /* ascii _BHRfS_M, no null */
...@@ -1015,6 +1016,7 @@ struct btrfs_fs_info { ...@@ -1015,6 +1016,7 @@ struct btrfs_fs_info {
/* used to keep from writing metadata until there is a nice batch */ /* used to keep from writing metadata until there is a nice batch */
struct percpu_counter dirty_metadata_bytes; struct percpu_counter dirty_metadata_bytes;
struct percpu_counter delalloc_bytes; struct percpu_counter delalloc_bytes;
struct percpu_counter dio_bytes;
s32 dirty_metadata_batch; s32 dirty_metadata_batch;
s32 delalloc_batch; s32 delalloc_batch;
...@@ -1092,10 +1094,7 @@ struct btrfs_fs_info { ...@@ -1092,10 +1094,7 @@ struct btrfs_fs_info {
/* holds configuration and tracking. Protected by qgroup_lock */ /* holds configuration and tracking. Protected by qgroup_lock */
struct rb_root qgroup_tree; struct rb_root qgroup_tree;
struct rb_root qgroup_op_tree;
spinlock_t qgroup_lock; spinlock_t qgroup_lock;
spinlock_t qgroup_op_lock;
atomic_t qgroup_op_seq;
/* /*
* used to avoid frequently calling ulist_alloc()/ulist_free() * used to avoid frequently calling ulist_alloc()/ulist_free()
...@@ -1152,12 +1151,6 @@ struct btrfs_fs_info { ...@@ -1152,12 +1151,6 @@ struct btrfs_fs_info {
struct mutex unused_bg_unpin_mutex; struct mutex unused_bg_unpin_mutex;
struct mutex delete_unused_bgs_mutex; struct mutex delete_unused_bgs_mutex;
/*
* Chunks that can't be freed yet (under a trim/discard operation)
* and will be latter freed. Protected by fs_info->chunk_mutex.
*/
struct list_head pinned_chunks;
/* Cached block sizes */ /* Cached block sizes */
u32 nodesize; u32 nodesize;
u32 sectorsize; u32 sectorsize;
...@@ -1348,6 +1341,12 @@ struct btrfs_root { ...@@ -1348,6 +1341,12 @@ struct btrfs_root {
* manipulation with the read-only status via SUBVOL_SETFLAGS * manipulation with the read-only status via SUBVOL_SETFLAGS
*/ */
int send_in_progress; int send_in_progress;
/*
* Number of currently running deduplication operations that have a
* destination inode belonging to this root. Protected by the lock
* root_item_lock.
*/
int dedupe_in_progress;
struct btrfs_subvolume_writers *subv_writers; struct btrfs_subvolume_writers *subv_writers;
atomic_t will_be_snapshotted; atomic_t will_be_snapshotted;
atomic_t snapshot_force_cow; atomic_t snapshot_force_cow;
...@@ -1540,6 +1539,21 @@ do { \ ...@@ -1540,6 +1539,21 @@ do { \
#define BTRFS_INODE_ROOT_ITEM_INIT (1 << 31) #define BTRFS_INODE_ROOT_ITEM_INIT (1 << 31)
#define BTRFS_INODE_FLAG_MASK \
(BTRFS_INODE_NODATASUM | \
BTRFS_INODE_NODATACOW | \
BTRFS_INODE_READONLY | \
BTRFS_INODE_NOCOMPRESS | \
BTRFS_INODE_PREALLOC | \
BTRFS_INODE_SYNC | \
BTRFS_INODE_IMMUTABLE | \
BTRFS_INODE_APPEND | \
BTRFS_INODE_NODUMP | \
BTRFS_INODE_NOATIME | \
BTRFS_INODE_DIRSYNC | \
BTRFS_INODE_COMPRESS | \
BTRFS_INODE_ROOT_ITEM_INIT)
struct btrfs_map_token { struct btrfs_map_token {
const struct extent_buffer *eb; const struct extent_buffer *eb;
char *kaddr; char *kaddr;
...@@ -2163,18 +2177,16 @@ static inline int btrfs_header_flag(const struct extent_buffer *eb, u64 flag) ...@@ -2163,18 +2177,16 @@ static inline int btrfs_header_flag(const struct extent_buffer *eb, u64 flag)
return (btrfs_header_flags(eb) & flag) == flag; return (btrfs_header_flags(eb) & flag) == flag;
} }
static inline int btrfs_set_header_flag(struct extent_buffer *eb, u64 flag) static inline void btrfs_set_header_flag(struct extent_buffer *eb, u64 flag)
{ {
u64 flags = btrfs_header_flags(eb); u64 flags = btrfs_header_flags(eb);
btrfs_set_header_flags(eb, flags | flag); btrfs_set_header_flags(eb, flags | flag);
return (flags & flag) == flag;
} }
static inline int btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag) static inline void btrfs_clear_header_flag(struct extent_buffer *eb, u64 flag)
{ {
u64 flags = btrfs_header_flags(eb); u64 flags = btrfs_header_flags(eb);
btrfs_set_header_flags(eb, flags & ~flag); btrfs_set_header_flags(eb, flags & ~flag);
return (flags & flag) == flag;
} }
static inline int btrfs_header_backref_rev(const struct extent_buffer *eb) static inline int btrfs_header_backref_rev(const struct extent_buffer *eb)
...@@ -2445,13 +2457,12 @@ static inline int btrfs_super_csum_size(const struct btrfs_super_block *s) ...@@ -2445,13 +2457,12 @@ static inline int btrfs_super_csum_size(const struct btrfs_super_block *s)
* this returns the address of the start of the last item, * this returns the address of the start of the last item,
* which is the stop of the leaf data stack * which is the stop of the leaf data stack
*/ */
static inline unsigned int leaf_data_end(const struct btrfs_fs_info *fs_info, static inline unsigned int leaf_data_end(const struct extent_buffer *leaf)
const struct extent_buffer *leaf)
{ {
u32 nr = btrfs_header_nritems(leaf); u32 nr = btrfs_header_nritems(leaf);
if (nr == 0) if (nr == 0)
return BTRFS_LEAF_DATA_SIZE(fs_info); return BTRFS_LEAF_DATA_SIZE(leaf->fs_info);
return btrfs_item_offset_nr(leaf, nr - 1); return btrfs_item_offset_nr(leaf, nr - 1);
} }
...@@ -2698,8 +2709,6 @@ void btrfs_wait_nocow_writers(struct btrfs_block_group_cache *bg); ...@@ -2698,8 +2709,6 @@ void btrfs_wait_nocow_writers(struct btrfs_block_group_cache *bg);
void btrfs_put_block_group(struct btrfs_block_group_cache *cache); void btrfs_put_block_group(struct btrfs_block_group_cache *cache);
int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, int btrfs_run_delayed_refs(struct btrfs_trans_handle *trans,
unsigned long count); unsigned long count);
int btrfs_async_run_delayed_refs(struct btrfs_fs_info *fs_info,
unsigned long count, u64 transid, int wait);
void btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info, void btrfs_cleanup_ref_head_accounting(struct btrfs_fs_info *fs_info,
struct btrfs_delayed_ref_root *delayed_refs, struct btrfs_delayed_ref_root *delayed_refs,
struct btrfs_delayed_ref_head *head); struct btrfs_delayed_ref_head *head);
...@@ -2711,8 +2720,7 @@ int btrfs_pin_extent(struct btrfs_fs_info *fs_info, ...@@ -2711,8 +2720,7 @@ int btrfs_pin_extent(struct btrfs_fs_info *fs_info,
u64 bytenr, u64 num, int reserved); u64 bytenr, u64 num, int reserved);
int btrfs_pin_extent_for_log_replay(struct btrfs_fs_info *fs_info, int btrfs_pin_extent_for_log_replay(struct btrfs_fs_info *fs_info,
u64 bytenr, u64 num_bytes); u64 bytenr, u64 num_bytes);
int btrfs_exclude_logged_extents(struct btrfs_fs_info *fs_info, int btrfs_exclude_logged_extents(struct extent_buffer *eb);
struct extent_buffer *eb);
int btrfs_cross_ref_exist(struct btrfs_root *root, int btrfs_cross_ref_exist(struct btrfs_root *root,
u64 objectid, u64 offset, u64 bytenr); u64 objectid, u64 offset, u64 bytenr);
struct btrfs_block_group_cache *btrfs_lookup_block_group( struct btrfs_block_group_cache *btrfs_lookup_block_group(
...@@ -2745,13 +2753,9 @@ int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, ...@@ -2745,13 +2753,9 @@ int btrfs_inc_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root, int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
struct extent_buffer *buf, int full_backref); struct extent_buffer *buf, int full_backref);
int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans, int btrfs_set_disk_extent_flags(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info,
u64 bytenr, u64 num_bytes, u64 flags, u64 bytenr, u64 num_bytes, u64 flags,
int level, int is_data); int level, int is_data);
int btrfs_free_extent(struct btrfs_trans_handle *trans, int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_ref *ref);
struct btrfs_root *root,
u64 bytenr, u64 num_bytes, u64 parent, u64 root_objectid,
u64 owner, u64 offset);
int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info, int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info,
u64 start, u64 len, int delalloc); u64 start, u64 len, int delalloc);
...@@ -2760,15 +2764,11 @@ int btrfs_free_and_pin_reserved_extent(struct btrfs_fs_info *fs_info, ...@@ -2760,15 +2764,11 @@ int btrfs_free_and_pin_reserved_extent(struct btrfs_fs_info *fs_info,
void btrfs_prepare_extent_commit(struct btrfs_fs_info *fs_info); void btrfs_prepare_extent_commit(struct btrfs_fs_info *fs_info);
int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans); int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans);
int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_ref *generic_ref);
u64 bytenr, u64 num_bytes, u64 parent,
u64 root_objectid, u64 owner, u64 offset);
int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans); int btrfs_start_dirty_block_groups(struct btrfs_trans_handle *trans);
int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans, int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans);
struct btrfs_fs_info *fs_info); int btrfs_setup_space_cache(struct btrfs_trans_handle *trans);
int btrfs_setup_space_cache(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info);
int btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr); int btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr);
int btrfs_free_block_groups(struct btrfs_fs_info *info); int btrfs_free_block_groups(struct btrfs_fs_info *info);
int btrfs_read_block_groups(struct btrfs_fs_info *info); int btrfs_read_block_groups(struct btrfs_fs_info *info);
...@@ -2936,10 +2936,8 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans, ...@@ -2936,10 +2936,8 @@ int btrfs_copy_root(struct btrfs_trans_handle *trans,
struct extent_buffer **cow_ret, u64 new_root_objectid); struct extent_buffer **cow_ret, u64 new_root_objectid);
int btrfs_block_can_be_shared(struct btrfs_root *root, int btrfs_block_can_be_shared(struct btrfs_root *root,
struct extent_buffer *buf); struct extent_buffer *buf);
void btrfs_extend_item(struct btrfs_fs_info *fs_info, struct btrfs_path *path, void btrfs_extend_item(struct btrfs_path *path, u32 data_size);
u32 data_size); void btrfs_truncate_item(struct btrfs_path *path, u32 new_size, int from_end);
void btrfs_truncate_item(struct btrfs_fs_info *fs_info,
struct btrfs_path *path, u32 new_size, int from_end);
int btrfs_split_item(struct btrfs_trans_handle *trans, int btrfs_split_item(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_root *root,
struct btrfs_path *path, struct btrfs_path *path,
...@@ -3015,8 +3013,7 @@ static inline int btrfs_next_item(struct btrfs_root *root, struct btrfs_path *p) ...@@ -3015,8 +3013,7 @@ static inline int btrfs_next_item(struct btrfs_root *root, struct btrfs_path *p)
{ {
return btrfs_next_old_item(root, p, 0); return btrfs_next_old_item(root, p, 0);
} }
int btrfs_leaf_free_space(struct btrfs_fs_info *fs_info, int btrfs_leaf_free_space(struct extent_buffer *leaf);
struct extent_buffer *leaf);
int __must_check btrfs_drop_snapshot(struct btrfs_root *root, int __must_check btrfs_drop_snapshot(struct btrfs_root *root,
struct btrfs_block_rsv *block_rsv, struct btrfs_block_rsv *block_rsv,
int update_ref, int for_reloc); int update_ref, int for_reloc);
...@@ -3756,8 +3753,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start, ...@@ -3756,8 +3753,7 @@ int btrfs_scrub_dev(struct btrfs_fs_info *fs_info, u64 devid, u64 start,
void btrfs_scrub_pause(struct btrfs_fs_info *fs_info); void btrfs_scrub_pause(struct btrfs_fs_info *fs_info);
void btrfs_scrub_continue(struct btrfs_fs_info *fs_info); void btrfs_scrub_continue(struct btrfs_fs_info *fs_info);
int btrfs_scrub_cancel(struct btrfs_fs_info *info); int btrfs_scrub_cancel(struct btrfs_fs_info *info);
int btrfs_scrub_cancel_dev(struct btrfs_fs_info *info, int btrfs_scrub_cancel_dev(struct btrfs_device *dev);
struct btrfs_device *dev);
int btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid, int btrfs_scrub_progress(struct btrfs_fs_info *fs_info, u64 devid,
struct btrfs_scrub_progress *progress); struct btrfs_scrub_progress *progress);
static inline void btrfs_init_full_stripe_locks_tree( static inline void btrfs_init_full_stripe_locks_tree(
...@@ -3806,6 +3802,8 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info) ...@@ -3806,6 +3802,8 @@ static inline int btrfs_defrag_cancelled(struct btrfs_fs_info *fs_info)
return signal_pending(current); return signal_pending(current);
} }
#define in_range(b, first, len) ((b) >= (first) && (b) < (first) + (len))
/* Sanity test specific functions */ /* Sanity test specific functions */
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
void btrfs_test_inode_set_ops(struct inode *inode); void btrfs_test_inode_set_ops(struct inode *inode);
......
...@@ -691,7 +691,6 @@ static int btrfs_batch_insert_items(struct btrfs_root *root, ...@@ -691,7 +691,6 @@ static int btrfs_batch_insert_items(struct btrfs_root *root,
struct btrfs_path *path, struct btrfs_path *path,
struct btrfs_delayed_item *item) struct btrfs_delayed_item *item)
{ {
struct btrfs_fs_info *fs_info = root->fs_info;
struct btrfs_delayed_item *curr, *next; struct btrfs_delayed_item *curr, *next;
int free_space; int free_space;
int total_data_size = 0, total_size = 0; int total_data_size = 0, total_size = 0;
...@@ -708,7 +707,7 @@ static int btrfs_batch_insert_items(struct btrfs_root *root, ...@@ -708,7 +707,7 @@ static int btrfs_batch_insert_items(struct btrfs_root *root,
BUG_ON(!path->nodes[0]); BUG_ON(!path->nodes[0]);
leaf = path->nodes[0]; leaf = path->nodes[0];
free_space = btrfs_leaf_free_space(fs_info, leaf); free_space = btrfs_leaf_free_space(leaf);
INIT_LIST_HEAD(&head); INIT_LIST_HEAD(&head);
next = item; next = item;
...@@ -1692,7 +1691,7 @@ int btrfs_readdir_delayed_dir_index(struct dir_context *ctx, ...@@ -1692,7 +1691,7 @@ int btrfs_readdir_delayed_dir_index(struct dir_context *ctx,
name = (char *)(di + 1); name = (char *)(di + 1);
name_len = btrfs_stack_dir_name_len(di); name_len = btrfs_stack_dir_name_len(di);
d_type = btrfs_filetype_table[di->type]; d_type = fs_ftype_to_dtype(di->type);
btrfs_disk_key_to_cpu(&location, &di->location); btrfs_disk_key_to_cpu(&location, &di->location);
over = !dir_emit(ctx, name, name_len, over = !dir_emit(ctx, name, name_len,
......
...@@ -735,8 +735,7 @@ static void init_delayed_ref_common(struct btrfs_fs_info *fs_info, ...@@ -735,8 +735,7 @@ static void init_delayed_ref_common(struct btrfs_fs_info *fs_info,
* transaction commits. * transaction commits.
*/ */
int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans,
u64 bytenr, u64 num_bytes, u64 parent, struct btrfs_ref *generic_ref,
u64 ref_root, int level, int action,
struct btrfs_delayed_extent_op *extent_op, struct btrfs_delayed_extent_op *extent_op,
int *old_ref_mod, int *new_ref_mod) int *old_ref_mod, int *new_ref_mod)
{ {
...@@ -746,10 +745,18 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, ...@@ -746,10 +745,18 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans,
struct btrfs_delayed_ref_root *delayed_refs; struct btrfs_delayed_ref_root *delayed_refs;
struct btrfs_qgroup_extent_record *record = NULL; struct btrfs_qgroup_extent_record *record = NULL;
int qrecord_inserted; int qrecord_inserted;
bool is_system = (ref_root == BTRFS_CHUNK_TREE_OBJECTID); bool is_system;
int action = generic_ref->action;
int level = generic_ref->tree_ref.level;
int ret; int ret;
u64 bytenr = generic_ref->bytenr;
u64 num_bytes = generic_ref->len;
u64 parent = generic_ref->parent;
u8 ref_type; u8 ref_type;
is_system = (generic_ref->real_root == BTRFS_CHUNK_TREE_OBJECTID);
ASSERT(generic_ref->type == BTRFS_REF_METADATA && generic_ref->action);
BUG_ON(extent_op && extent_op->is_data); BUG_ON(extent_op && extent_op->is_data);
ref = kmem_cache_alloc(btrfs_delayed_tree_ref_cachep, GFP_NOFS); ref = kmem_cache_alloc(btrfs_delayed_tree_ref_cachep, GFP_NOFS);
if (!ref) if (!ref)
...@@ -762,7 +769,9 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, ...@@ -762,7 +769,9 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans,
} }
if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags) && if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags) &&
is_fstree(ref_root)) { is_fstree(generic_ref->real_root) &&
is_fstree(generic_ref->tree_ref.root) &&
!generic_ref->skip_qgroup) {
record = kzalloc(sizeof(*record), GFP_NOFS); record = kzalloc(sizeof(*record), GFP_NOFS);
if (!record) { if (!record) {
kmem_cache_free(btrfs_delayed_tree_ref_cachep, ref); kmem_cache_free(btrfs_delayed_tree_ref_cachep, ref);
...@@ -777,13 +786,14 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, ...@@ -777,13 +786,14 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans,
ref_type = BTRFS_TREE_BLOCK_REF_KEY; ref_type = BTRFS_TREE_BLOCK_REF_KEY;
init_delayed_ref_common(fs_info, &ref->node, bytenr, num_bytes, init_delayed_ref_common(fs_info, &ref->node, bytenr, num_bytes,
ref_root, action, ref_type); generic_ref->tree_ref.root, action, ref_type);
ref->root = ref_root; ref->root = generic_ref->tree_ref.root;
ref->parent = parent; ref->parent = parent;
ref->level = level; ref->level = level;
init_delayed_ref_head(head_ref, record, bytenr, num_bytes, init_delayed_ref_head(head_ref, record, bytenr, num_bytes,
ref_root, 0, action, false, is_system); generic_ref->tree_ref.root, 0, action, false,
is_system);
head_ref->extent_op = extent_op; head_ref->extent_op = extent_op;
delayed_refs = &trans->transaction->delayed_refs; delayed_refs = &trans->transaction->delayed_refs;
...@@ -822,10 +832,9 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, ...@@ -822,10 +832,9 @@ int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans,
* add a delayed data ref. it's similar to btrfs_add_delayed_tree_ref. * add a delayed data ref. it's similar to btrfs_add_delayed_tree_ref.
*/ */
int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans,
u64 bytenr, u64 num_bytes, struct btrfs_ref *generic_ref,
u64 parent, u64 ref_root, u64 reserved, int *old_ref_mod,
u64 owner, u64 offset, u64 reserved, int action, int *new_ref_mod)
int *old_ref_mod, int *new_ref_mod)
{ {
struct btrfs_fs_info *fs_info = trans->fs_info; struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_delayed_data_ref *ref; struct btrfs_delayed_data_ref *ref;
...@@ -833,9 +842,17 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, ...@@ -833,9 +842,17 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans,
struct btrfs_delayed_ref_root *delayed_refs; struct btrfs_delayed_ref_root *delayed_refs;
struct btrfs_qgroup_extent_record *record = NULL; struct btrfs_qgroup_extent_record *record = NULL;
int qrecord_inserted; int qrecord_inserted;
int action = generic_ref->action;
int ret; int ret;
u64 bytenr = generic_ref->bytenr;
u64 num_bytes = generic_ref->len;
u64 parent = generic_ref->parent;
u64 ref_root = generic_ref->data_ref.ref_root;
u64 owner = generic_ref->data_ref.ino;
u64 offset = generic_ref->data_ref.offset;
u8 ref_type; u8 ref_type;
ASSERT(generic_ref->type == BTRFS_REF_DATA && action);
ref = kmem_cache_alloc(btrfs_delayed_data_ref_cachep, GFP_NOFS); ref = kmem_cache_alloc(btrfs_delayed_data_ref_cachep, GFP_NOFS);
if (!ref) if (!ref)
return -ENOMEM; return -ENOMEM;
...@@ -859,7 +876,9 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, ...@@ -859,7 +876,9 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans,
} }
if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags) && if (test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags) &&
is_fstree(ref_root)) { is_fstree(ref_root) &&
is_fstree(generic_ref->real_root) &&
!generic_ref->skip_qgroup) {
record = kzalloc(sizeof(*record), GFP_NOFS); record = kzalloc(sizeof(*record), GFP_NOFS);
if (!record) { if (!record) {
kmem_cache_free(btrfs_delayed_data_ref_cachep, ref); kmem_cache_free(btrfs_delayed_data_ref_cachep, ref);
...@@ -905,8 +924,7 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, ...@@ -905,8 +924,7 @@ int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans,
return 0; return 0;
} }
int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info, int btrfs_add_delayed_extent_op(struct btrfs_trans_handle *trans,
struct btrfs_trans_handle *trans,
u64 bytenr, u64 num_bytes, u64 bytenr, u64 num_bytes,
struct btrfs_delayed_extent_op *extent_op) struct btrfs_delayed_extent_op *extent_op)
{ {
......
...@@ -176,6 +176,83 @@ struct btrfs_delayed_ref_root { ...@@ -176,6 +176,83 @@ struct btrfs_delayed_ref_root {
u64 qgroup_to_skip; u64 qgroup_to_skip;
}; };
enum btrfs_ref_type {
BTRFS_REF_NOT_SET,
BTRFS_REF_DATA,
BTRFS_REF_METADATA,
BTRFS_REF_LAST,
};
struct btrfs_data_ref {
/* For EXTENT_DATA_REF */
/* Root which refers to this data extent */
u64 ref_root;
/* Inode which refers to this data extent */
u64 ino;
/*
* file_offset - extent_offset
*
* file_offset is the key.offset of the EXTENT_DATA key.
* extent_offset is btrfs_file_extent_offset() of the EXTENT_DATA data.
*/
u64 offset;
};
struct btrfs_tree_ref {
/*
* Level of this tree block
*
* Shared for skinny (TREE_BLOCK_REF) and normal tree ref.
*/
int level;
/*
* Root which refers to this tree block.
*
* For TREE_BLOCK_REF (skinny metadata, either inline or keyed)
*/
u64 root;
/* For non-skinny metadata, no special member needed */
};
struct btrfs_ref {
enum btrfs_ref_type type;
int action;
/*
* Whether this extent should go through qgroup record.
*
* Normally false, but for certain cases like delayed subtree scan,
* setting this flag can hugely reduce qgroup overhead.
*/
bool skip_qgroup;
/*
* Optional. For which root is this modification.
* Mostly used for qgroup optimization.
*
* When unset, data/tree ref init code will populate it.
* In certain cases, we're modifying reference for a different root.
* E.g. COW fs tree blocks for balance.
* In that case, tree_ref::root will be fs tree, but we're doing this
* for reloc tree, then we should set @real_root to reloc tree.
*/
u64 real_root;
u64 bytenr;
u64 len;
/* Bytenr of the parent tree block */
u64 parent;
union {
struct btrfs_data_ref data_ref;
struct btrfs_tree_ref tree_ref;
};
};
extern struct kmem_cache *btrfs_delayed_ref_head_cachep; extern struct kmem_cache *btrfs_delayed_ref_head_cachep;
extern struct kmem_cache *btrfs_delayed_tree_ref_cachep; extern struct kmem_cache *btrfs_delayed_tree_ref_cachep;
extern struct kmem_cache *btrfs_delayed_data_ref_cachep; extern struct kmem_cache *btrfs_delayed_data_ref_cachep;
...@@ -184,6 +261,38 @@ extern struct kmem_cache *btrfs_delayed_extent_op_cachep; ...@@ -184,6 +261,38 @@ extern struct kmem_cache *btrfs_delayed_extent_op_cachep;
int __init btrfs_delayed_ref_init(void); int __init btrfs_delayed_ref_init(void);
void __cold btrfs_delayed_ref_exit(void); void __cold btrfs_delayed_ref_exit(void);
static inline void btrfs_init_generic_ref(struct btrfs_ref *generic_ref,
int action, u64 bytenr, u64 len, u64 parent)
{
generic_ref->action = action;
generic_ref->bytenr = bytenr;
generic_ref->len = len;
generic_ref->parent = parent;
}
static inline void btrfs_init_tree_ref(struct btrfs_ref *generic_ref,
int level, u64 root)
{
/* If @real_root not set, use @root as fallback */
if (!generic_ref->real_root)
generic_ref->real_root = root;
generic_ref->tree_ref.level = level;
generic_ref->tree_ref.root = root;
generic_ref->type = BTRFS_REF_METADATA;
}
static inline void btrfs_init_data_ref(struct btrfs_ref *generic_ref,
u64 ref_root, u64 ino, u64 offset)
{
/* If @real_root not set, use @root as fallback */
if (!generic_ref->real_root)
generic_ref->real_root = ref_root;
generic_ref->data_ref.ref_root = ref_root;
generic_ref->data_ref.ino = ino;
generic_ref->data_ref.offset = offset;
generic_ref->type = BTRFS_REF_DATA;
}
static inline struct btrfs_delayed_extent_op * static inline struct btrfs_delayed_extent_op *
btrfs_alloc_delayed_extent_op(void) btrfs_alloc_delayed_extent_op(void)
{ {
...@@ -224,17 +333,14 @@ static inline void btrfs_put_delayed_ref_head(struct btrfs_delayed_ref_head *hea ...@@ -224,17 +333,14 @@ static inline void btrfs_put_delayed_ref_head(struct btrfs_delayed_ref_head *hea
} }
int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans, int btrfs_add_delayed_tree_ref(struct btrfs_trans_handle *trans,
u64 bytenr, u64 num_bytes, u64 parent, struct btrfs_ref *generic_ref,
u64 ref_root, int level, int action,
struct btrfs_delayed_extent_op *extent_op, struct btrfs_delayed_extent_op *extent_op,
int *old_ref_mod, int *new_ref_mod); int *old_ref_mod, int *new_ref_mod);
int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans, int btrfs_add_delayed_data_ref(struct btrfs_trans_handle *trans,
u64 bytenr, u64 num_bytes, struct btrfs_ref *generic_ref,
u64 parent, u64 ref_root, u64 reserved, int *old_ref_mod,
u64 owner, u64 offset, u64 reserved, int action, int *new_ref_mod);
int *old_ref_mod, int *new_ref_mod); int btrfs_add_delayed_extent_op(struct btrfs_trans_handle *trans,
int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info,
struct btrfs_trans_handle *trans,
u64 bytenr, u64 num_bytes, u64 bytenr, u64 num_bytes,
struct btrfs_delayed_extent_op *extent_op); struct btrfs_delayed_extent_op *extent_op);
void btrfs_merge_delayed_refs(struct btrfs_trans_handle *trans, void btrfs_merge_delayed_refs(struct btrfs_trans_handle *trans,
......
...@@ -273,9 +273,9 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info, ...@@ -273,9 +273,9 @@ static int btrfs_init_dev_replace_tgtdev(struct btrfs_fs_info *fs_info,
* called from commit_transaction. Writes changed device replace state to * called from commit_transaction. Writes changed device replace state to
* disk. * disk.
*/ */
int btrfs_run_dev_replace(struct btrfs_trans_handle *trans, int btrfs_run_dev_replace(struct btrfs_trans_handle *trans)
struct btrfs_fs_info *fs_info)
{ {
struct btrfs_fs_info *fs_info = trans->fs_info;
int ret; int ret;
struct btrfs_root *dev_root = fs_info->dev_root; struct btrfs_root *dev_root = fs_info->dev_root;
struct btrfs_path *path; struct btrfs_path *path;
...@@ -662,7 +662,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info, ...@@ -662,7 +662,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
btrfs_device_set_disk_total_bytes(tgt_device, btrfs_device_set_disk_total_bytes(tgt_device,
src_device->disk_total_bytes); src_device->disk_total_bytes);
btrfs_device_set_bytes_used(tgt_device, src_device->bytes_used); btrfs_device_set_bytes_used(tgt_device, src_device->bytes_used);
ASSERT(list_empty(&src_device->resized_list)); ASSERT(list_empty(&src_device->post_commit_list));
tgt_device->commit_total_bytes = src_device->commit_total_bytes; tgt_device->commit_total_bytes = src_device->commit_total_bytes;
tgt_device->commit_bytes_used = src_device->bytes_used; tgt_device->commit_bytes_used = src_device->bytes_used;
...@@ -696,7 +696,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info, ...@@ -696,7 +696,7 @@ static int btrfs_dev_replace_finishing(struct btrfs_fs_info *fs_info,
/* replace the sysfs entry */ /* replace the sysfs entry */
btrfs_sysfs_rm_device_link(fs_info->fs_devices, src_device); btrfs_sysfs_rm_device_link(fs_info->fs_devices, src_device);
btrfs_rm_dev_replace_free_srcdev(fs_info, src_device); btrfs_rm_dev_replace_free_srcdev(src_device);
/* write back the superblocks */ /* write back the superblocks */
trans = btrfs_start_transaction(root, 0); trans = btrfs_start_transaction(root, 0);
......
...@@ -9,8 +9,7 @@ ...@@ -9,8 +9,7 @@
struct btrfs_ioctl_dev_replace_args; struct btrfs_ioctl_dev_replace_args;
int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info); int btrfs_init_dev_replace(struct btrfs_fs_info *fs_info);
int btrfs_run_dev_replace(struct btrfs_trans_handle *trans, int btrfs_run_dev_replace(struct btrfs_trans_handle *trans);
struct btrfs_fs_info *fs_info);
int btrfs_dev_replace_by_ioctl(struct btrfs_fs_info *fs_info, int btrfs_dev_replace_by_ioctl(struct btrfs_fs_info *fs_info,
struct btrfs_ioctl_dev_replace_args *args); struct btrfs_ioctl_dev_replace_args *args);
void btrfs_dev_replace_status(struct btrfs_fs_info *fs_info, void btrfs_dev_replace_status(struct btrfs_fs_info *fs_info,
......
...@@ -36,7 +36,7 @@ static struct btrfs_dir_item *insert_with_overflow(struct btrfs_trans_handle ...@@ -36,7 +36,7 @@ static struct btrfs_dir_item *insert_with_overflow(struct btrfs_trans_handle
di = btrfs_match_dir_item_name(fs_info, path, name, name_len); di = btrfs_match_dir_item_name(fs_info, path, name, name_len);
if (di) if (di)
return ERR_PTR(-EEXIST); return ERR_PTR(-EEXIST);
btrfs_extend_item(fs_info, path, data_size); btrfs_extend_item(path, data_size);
} else if (ret < 0) } else if (ret < 0)
return ERR_PTR(ret); return ERR_PTR(ret);
WARN_ON(ret > 0); WARN_ON(ret > 0);
...@@ -429,8 +429,7 @@ int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans, ...@@ -429,8 +429,7 @@ int btrfs_delete_one_dir_name(struct btrfs_trans_handle *trans,
start = btrfs_item_ptr_offset(leaf, path->slots[0]); start = btrfs_item_ptr_offset(leaf, path->slots[0]);
memmove_extent_buffer(leaf, ptr, ptr + sub_item_len, memmove_extent_buffer(leaf, ptr, ptr + sub_item_len,
item_len - (ptr + sub_item_len - start)); item_len - (ptr + sub_item_len - start));
btrfs_truncate_item(root->fs_info, path, btrfs_truncate_item(path, item_len - sub_item_len, 1);
item_len - sub_item_len, 1);
} }
return ret; return ret;
} }
This diff is collapsed.
...@@ -39,6 +39,8 @@ static inline u64 btrfs_sb_offset(int mirror) ...@@ -39,6 +39,8 @@ static inline u64 btrfs_sb_offset(int mirror)
struct btrfs_device; struct btrfs_device;
struct btrfs_fs_devices; struct btrfs_fs_devices;
int btrfs_verify_level_key(struct extent_buffer *eb, int level,
struct btrfs_key *first_key, u64 parent_transid);
struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
u64 parent_transid, int level, u64 parent_transid, int level,
struct btrfs_key *first_key); struct btrfs_key *first_key);
...@@ -48,7 +50,7 @@ int reada_tree_block_flagged(struct btrfs_fs_info *fs_info, u64 bytenr, ...@@ -48,7 +50,7 @@ int reada_tree_block_flagged(struct btrfs_fs_info *fs_info, u64 bytenr,
struct extent_buffer *btrfs_find_create_tree_block( struct extent_buffer *btrfs_find_create_tree_block(
struct btrfs_fs_info *fs_info, struct btrfs_fs_info *fs_info,
u64 bytenr); u64 bytenr);
void clean_tree_block(struct btrfs_fs_info *fs_info, struct extent_buffer *buf); void btrfs_clean_tree_block(struct extent_buffer *buf);
int open_ctree(struct super_block *sb, int open_ctree(struct super_block *sb,
struct btrfs_fs_devices *fs_devices, struct btrfs_fs_devices *fs_devices,
char *options); char *options);
...@@ -123,8 +125,6 @@ blk_status_t btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct bio *bio, ...@@ -123,8 +125,6 @@ blk_status_t btrfs_wq_submit_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
extent_submit_bio_start_t *submit_bio_start); extent_submit_bio_start_t *submit_bio_start);
blk_status_t btrfs_submit_bio_done(void *private_data, struct bio *bio, blk_status_t btrfs_submit_bio_done(void *private_data, struct bio *bio,
int mirror_num); int mirror_num);
int btrfs_write_tree_block(struct extent_buffer *buf);
void btrfs_wait_tree_block_writeback(struct extent_buffer *buf);
int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans, int btrfs_init_log_root_tree(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info); struct btrfs_fs_info *fs_info);
int btrfs_add_log_tree(struct btrfs_trans_handle *trans, int btrfs_add_log_tree(struct btrfs_trans_handle *trans,
...@@ -134,7 +134,6 @@ void btrfs_cleanup_dirty_bgs(struct btrfs_transaction *trans, ...@@ -134,7 +134,6 @@ void btrfs_cleanup_dirty_bgs(struct btrfs_transaction *trans,
void btrfs_cleanup_one_transaction(struct btrfs_transaction *trans, void btrfs_cleanup_one_transaction(struct btrfs_transaction *trans,
struct btrfs_fs_info *fs_info); struct btrfs_fs_info *fs_info);
struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info,
u64 objectid); u64 objectid);
int btree_lock_page_hook(struct page *page, void *data, int btree_lock_page_hook(struct page *page, void *data,
void (*flush_fn)(void *)); void (*flush_fn)(void *));
......
This diff is collapsed.
This diff is collapsed.
...@@ -9,26 +9,33 @@ ...@@ -9,26 +9,33 @@
/* bits for the extent state */ /* bits for the extent state */
#define EXTENT_DIRTY (1U << 0) #define EXTENT_DIRTY (1U << 0)
#define EXTENT_WRITEBACK (1U << 1) #define EXTENT_UPTODATE (1U << 1)
#define EXTENT_UPTODATE (1U << 2) #define EXTENT_LOCKED (1U << 2)
#define EXTENT_LOCKED (1U << 3) #define EXTENT_NEW (1U << 3)
#define EXTENT_NEW (1U << 4) #define EXTENT_DELALLOC (1U << 4)
#define EXTENT_DELALLOC (1U << 5) #define EXTENT_DEFRAG (1U << 5)
#define EXTENT_DEFRAG (1U << 6) #define EXTENT_BOUNDARY (1U << 6)
#define EXTENT_BOUNDARY (1U << 9) #define EXTENT_NODATASUM (1U << 7)
#define EXTENT_NODATASUM (1U << 10) #define EXTENT_CLEAR_META_RESV (1U << 8)
#define EXTENT_CLEAR_META_RESV (1U << 11) #define EXTENT_NEED_WAIT (1U << 9)
#define EXTENT_NEED_WAIT (1U << 12) #define EXTENT_DAMAGED (1U << 10)
#define EXTENT_DAMAGED (1U << 13) #define EXTENT_NORESERVE (1U << 11)
#define EXTENT_NORESERVE (1U << 14) #define EXTENT_QGROUP_RESERVED (1U << 12)
#define EXTENT_QGROUP_RESERVED (1U << 15) #define EXTENT_CLEAR_DATA_RESV (1U << 13)
#define EXTENT_CLEAR_DATA_RESV (1U << 16) #define EXTENT_DELALLOC_NEW (1U << 14)
#define EXTENT_DELALLOC_NEW (1U << 17)
#define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
#define EXTENT_DO_ACCOUNTING (EXTENT_CLEAR_META_RESV | \ #define EXTENT_DO_ACCOUNTING (EXTENT_CLEAR_META_RESV | \
EXTENT_CLEAR_DATA_RESV) EXTENT_CLEAR_DATA_RESV)
#define EXTENT_CTLBITS (EXTENT_DO_ACCOUNTING) #define EXTENT_CTLBITS (EXTENT_DO_ACCOUNTING)
/*
* Redefined bits above which are used only in the device allocation tree,
* shouldn't be using EXTENT_LOCKED / EXTENT_BOUNDARY / EXTENT_CLEAR_META_RESV
* / EXTENT_CLEAR_DATA_RESV because they have special meaning to the bit
* manipulation functions
*/
#define CHUNK_ALLOCATED EXTENT_DIRTY
#define CHUNK_TRIMMED EXTENT_DEFRAG
/* /*
* flags for bio submission. The high bits indicate the compression * flags for bio submission. The high bits indicate the compression
* type for this bio * type for this bio
...@@ -88,9 +95,6 @@ struct btrfs_inode; ...@@ -88,9 +95,6 @@ struct btrfs_inode;
struct btrfs_io_bio; struct btrfs_io_bio;
struct io_failure_record; struct io_failure_record;
typedef blk_status_t (extent_submit_bio_hook_t)(void *private_data, struct bio *bio,
int mirror_num, unsigned long bio_flags,
u64 bio_offset);
typedef blk_status_t (extent_submit_bio_start_t)(void *private_data, typedef blk_status_t (extent_submit_bio_start_t)(void *private_data,
struct bio *bio, u64 bio_offset); struct bio *bio, u64 bio_offset);
...@@ -100,17 +104,34 @@ struct extent_io_ops { ...@@ -100,17 +104,34 @@ struct extent_io_ops {
* The following callbacks must be always defined, the function * The following callbacks must be always defined, the function
* pointer will be called unconditionally. * pointer will be called unconditionally.
*/ */
extent_submit_bio_hook_t *submit_bio_hook; blk_status_t (*submit_bio_hook)(struct inode *inode, struct bio *bio,
int mirror_num, unsigned long bio_flags);
int (*readpage_end_io_hook)(struct btrfs_io_bio *io_bio, u64 phy_offset, int (*readpage_end_io_hook)(struct btrfs_io_bio *io_bio, u64 phy_offset,
struct page *page, u64 start, u64 end, struct page *page, u64 start, u64 end,
int mirror); int mirror);
}; };
enum {
IO_TREE_FS_INFO_FREED_EXTENTS0,
IO_TREE_FS_INFO_FREED_EXTENTS1,
IO_TREE_INODE_IO,
IO_TREE_INODE_IO_FAILURE,
IO_TREE_RELOC_BLOCKS,
IO_TREE_TRANS_DIRTY_PAGES,
IO_TREE_ROOT_DIRTY_LOG_PAGES,
IO_TREE_SELFTEST,
};
struct extent_io_tree { struct extent_io_tree {
struct rb_root state; struct rb_root state;
struct btrfs_fs_info *fs_info;
void *private_data; void *private_data;
u64 dirty_bytes; u64 dirty_bytes;
int track_uptodate; bool track_uptodate;
/* Who owns this io tree, should be one of IO_TREE_* */
u8 owner;
spinlock_t lock; spinlock_t lock;
const struct extent_io_ops *ops; const struct extent_io_ops *ops;
}; };
...@@ -146,14 +167,9 @@ struct extent_buffer { ...@@ -146,14 +167,9 @@ struct extent_buffer {
struct rcu_head rcu_head; struct rcu_head rcu_head;
pid_t lock_owner; pid_t lock_owner;
/* count of read lock holders on the extent buffer */
atomic_t write_locks;
atomic_t read_locks;
atomic_t blocking_writers; atomic_t blocking_writers;
atomic_t blocking_readers; atomic_t blocking_readers;
atomic_t spinning_readers; bool lock_nested;
atomic_t spinning_writers;
short lock_nested;
/* >= 0 if eb belongs to a log tree, -1 otherwise */ /* >= 0 if eb belongs to a log tree, -1 otherwise */
short log_index; short log_index;
...@@ -171,6 +187,10 @@ struct extent_buffer { ...@@ -171,6 +187,10 @@ struct extent_buffer {
wait_queue_head_t read_lock_wq; wait_queue_head_t read_lock_wq;
struct page *pages[INLINE_EXTENT_BUFFER_PAGES]; struct page *pages[INLINE_EXTENT_BUFFER_PAGES];
#ifdef CONFIG_BTRFS_DEBUG #ifdef CONFIG_BTRFS_DEBUG
atomic_t spinning_writers;
atomic_t spinning_readers;
atomic_t read_locks;
atomic_t write_locks;
struct list_head leak_list; struct list_head leak_list;
#endif #endif
}; };
...@@ -239,7 +259,10 @@ typedef struct extent_map *(get_extent_t)(struct btrfs_inode *inode, ...@@ -239,7 +259,10 @@ typedef struct extent_map *(get_extent_t)(struct btrfs_inode *inode,
u64 start, u64 len, u64 start, u64 len,
int create); int create);
void extent_io_tree_init(struct extent_io_tree *tree, void *private_data); void extent_io_tree_init(struct btrfs_fs_info *fs_info,
struct extent_io_tree *tree, unsigned int owner,
void *private_data);
void extent_io_tree_release(struct extent_io_tree *tree);
int try_release_extent_mapping(struct page *page, gfp_t mask); int try_release_extent_mapping(struct page *page, gfp_t mask);
int try_release_extent_buffer(struct page *page); int try_release_extent_buffer(struct page *page);
int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
...@@ -309,6 +332,8 @@ int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, ...@@ -309,6 +332,8 @@ int set_record_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int set_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
unsigned bits, u64 *failed_start, unsigned bits, u64 *failed_start,
struct extent_state **cached_state, gfp_t mask); struct extent_state **cached_state, gfp_t mask);
int set_extent_bits_nowait(struct extent_io_tree *tree, u64 start, u64 end,
unsigned bits);
static inline int set_extent_bits(struct extent_io_tree *tree, u64 start, static inline int set_extent_bits(struct extent_io_tree *tree, u64 start,
u64 end, unsigned bits) u64 end, unsigned bits)
...@@ -376,6 +401,8 @@ static inline int set_extent_uptodate(struct extent_io_tree *tree, u64 start, ...@@ -376,6 +401,8 @@ static inline int set_extent_uptodate(struct extent_io_tree *tree, u64 start,
int find_first_extent_bit(struct extent_io_tree *tree, u64 start, int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
u64 *start_ret, u64 *end_ret, unsigned bits, u64 *start_ret, u64 *end_ret, unsigned bits,
struct extent_state **cached_state); struct extent_state **cached_state);
void find_first_clear_extent_bit(struct extent_io_tree *tree, u64 start,
u64 *start_ret, u64 *end_ret, unsigned bits);
int extent_invalidatepage(struct extent_io_tree *tree, int extent_invalidatepage(struct extent_io_tree *tree,
struct page *page, unsigned long offset); struct page *page, unsigned long offset);
int extent_write_full_page(struct page *page, struct writeback_control *wbc); int extent_write_full_page(struct page *page, struct writeback_control *wbc);
...@@ -405,8 +432,7 @@ void free_extent_buffer_stale(struct extent_buffer *eb); ...@@ -405,8 +432,7 @@ void free_extent_buffer_stale(struct extent_buffer *eb);
#define WAIT_NONE 0 #define WAIT_NONE 0
#define WAIT_COMPLETE 1 #define WAIT_COMPLETE 1
#define WAIT_PAGE_LOCK 2 #define WAIT_PAGE_LOCK 2
int read_extent_buffer_pages(struct extent_io_tree *tree, int read_extent_buffer_pages(struct extent_buffer *eb, int wait,
struct extent_buffer *eb, int wait,
int mirror_num); int mirror_num);
void wait_on_extent_buffer_writeback(struct extent_buffer *eb); void wait_on_extent_buffer_writeback(struct extent_buffer *eb);
...@@ -487,8 +513,7 @@ int clean_io_failure(struct btrfs_fs_info *fs_info, ...@@ -487,8 +513,7 @@ int clean_io_failure(struct btrfs_fs_info *fs_info,
struct extent_io_tree *io_tree, u64 start, struct extent_io_tree *io_tree, u64 start,
struct page *page, u64 ino, unsigned int pg_offset); struct page *page, u64 ino, unsigned int pg_offset);
void end_extent_writepage(struct page *page, int err, u64 start, u64 end); void end_extent_writepage(struct page *page, int err, u64 start, u64 end);
int repair_eb_io_failure(struct btrfs_fs_info *fs_info, int btrfs_repair_eb_io_failure(struct extent_buffer *eb, int mirror_num);
struct extent_buffer *eb, int mirror_num);
/* /*
* When IO fails, either with EIO or csum verification fails, we * When IO fails, either with EIO or csum verification fails, we
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include "ctree.h" #include "ctree.h"
#include "volumes.h"
#include "extent_map.h" #include "extent_map.h"
#include "compression.h" #include "compression.h"
...@@ -337,6 +338,37 @@ static inline void setup_extent_mapping(struct extent_map_tree *tree, ...@@ -337,6 +338,37 @@ static inline void setup_extent_mapping(struct extent_map_tree *tree,
try_merge_map(tree, em); try_merge_map(tree, em);
} }
static void extent_map_device_set_bits(struct extent_map *em, unsigned bits)
{
struct map_lookup *map = em->map_lookup;
u64 stripe_size = em->orig_block_len;
int i;
for (i = 0; i < map->num_stripes; i++) {
struct btrfs_bio_stripe *stripe = &map->stripes[i];
struct btrfs_device *device = stripe->dev;
set_extent_bits_nowait(&device->alloc_state, stripe->physical,
stripe->physical + stripe_size - 1, bits);
}
}
static void extent_map_device_clear_bits(struct extent_map *em, unsigned bits)
{
struct map_lookup *map = em->map_lookup;
u64 stripe_size = em->orig_block_len;
int i;
for (i = 0; i < map->num_stripes; i++) {
struct btrfs_bio_stripe *stripe = &map->stripes[i];
struct btrfs_device *device = stripe->dev;
__clear_extent_bit(&device->alloc_state, stripe->physical,
stripe->physical + stripe_size - 1, bits,
0, 0, NULL, GFP_NOWAIT, NULL);
}
}
/** /**
* add_extent_mapping - add new extent map to the extent tree * add_extent_mapping - add new extent map to the extent tree
* @tree: tree to insert new map in * @tree: tree to insert new map in
...@@ -357,6 +389,10 @@ int add_extent_mapping(struct extent_map_tree *tree, ...@@ -357,6 +389,10 @@ int add_extent_mapping(struct extent_map_tree *tree,
goto out; goto out;
setup_extent_mapping(tree, em, modified); setup_extent_mapping(tree, em, modified);
if (test_bit(EXTENT_FLAG_FS_MAPPING, &em->flags)) {
extent_map_device_set_bits(em, CHUNK_ALLOCATED);
extent_map_device_clear_bits(em, CHUNK_TRIMMED);
}
out: out:
return ret; return ret;
} }
...@@ -438,6 +474,8 @@ void remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em) ...@@ -438,6 +474,8 @@ void remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em)
rb_erase_cached(&em->rb_node, &tree->map); rb_erase_cached(&em->rb_node, &tree->map);
if (!test_bit(EXTENT_FLAG_LOGGING, &em->flags)) if (!test_bit(EXTENT_FLAG_LOGGING, &em->flags))
list_del_init(&em->list); list_del_init(&em->list);
if (test_bit(EXTENT_FLAG_FS_MAPPING, &em->flags))
extent_map_device_clear_bits(em, CHUNK_ALLOCATED);
RB_CLEAR_NODE(&em->rb_node); RB_CLEAR_NODE(&em->rb_node);
} }
......
...@@ -413,6 +413,16 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end, ...@@ -413,6 +413,16 @@ int btrfs_lookup_csums_range(struct btrfs_root *root, u64 start, u64 end,
return ret; return ret;
} }
/*
* btrfs_csum_one_bio - Calculates checksums of the data contained inside a bio
* @inode: Owner of the data inside the bio
* @bio: Contains the data to be checksummed
* @file_start: offset in file this bio begins to describe
* @contig: Boolean. If true/1 means all bio vecs in this bio are
* contiguous and they begin at @file_start in the file. False/0
* means this bio can contains potentially discontigous bio vecs
* so the logical offset of each should be calculated separately.
*/
blk_status_t btrfs_csum_one_bio(struct inode *inode, struct bio *bio, blk_status_t btrfs_csum_one_bio(struct inode *inode, struct bio *bio,
u64 file_start, int contig) u64 file_start, int contig)
{ {
...@@ -458,8 +468,6 @@ blk_status_t btrfs_csum_one_bio(struct inode *inode, struct bio *bio, ...@@ -458,8 +468,6 @@ blk_status_t btrfs_csum_one_bio(struct inode *inode, struct bio *bio,
BUG_ON(!ordered); /* Logic error */ BUG_ON(!ordered); /* Logic error */
} }
data = kmap_atomic(bvec.bv_page);
nr_sectors = BTRFS_BYTES_TO_BLKS(fs_info, nr_sectors = BTRFS_BYTES_TO_BLKS(fs_info,
bvec.bv_len + fs_info->sectorsize bvec.bv_len + fs_info->sectorsize
- 1); - 1);
...@@ -469,10 +477,9 @@ blk_status_t btrfs_csum_one_bio(struct inode *inode, struct bio *bio, ...@@ -469,10 +477,9 @@ blk_status_t btrfs_csum_one_bio(struct inode *inode, struct bio *bio,
offset < ordered->file_offset) { offset < ordered->file_offset) {
unsigned long bytes_left; unsigned long bytes_left;
kunmap_atomic(data);
sums->len = this_sum_bytes; sums->len = this_sum_bytes;
this_sum_bytes = 0; this_sum_bytes = 0;
btrfs_add_ordered_sum(inode, ordered, sums); btrfs_add_ordered_sum(ordered, sums);
btrfs_put_ordered_extent(ordered); btrfs_put_ordered_extent(ordered);
bytes_left = bio->bi_iter.bi_size - total_bytes; bytes_left = bio->bi_iter.bi_size - total_bytes;
...@@ -489,16 +496,16 @@ blk_status_t btrfs_csum_one_bio(struct inode *inode, struct bio *bio, ...@@ -489,16 +496,16 @@ blk_status_t btrfs_csum_one_bio(struct inode *inode, struct bio *bio,
sums->bytenr = ((u64)bio->bi_iter.bi_sector << 9) sums->bytenr = ((u64)bio->bi_iter.bi_sector << 9)
+ total_bytes; + total_bytes;
index = 0; index = 0;
data = kmap_atomic(bvec.bv_page);
} }
sums->sums[index] = ~(u32)0; sums->sums[index] = ~(u32)0;
data = kmap_atomic(bvec.bv_page);
sums->sums[index] sums->sums[index]
= btrfs_csum_data(data + bvec.bv_offset = btrfs_csum_data(data + bvec.bv_offset
+ (i * fs_info->sectorsize), + (i * fs_info->sectorsize),
sums->sums[index], sums->sums[index],
fs_info->sectorsize); fs_info->sectorsize);
kunmap_atomic(data);
btrfs_csum_final(sums->sums[index], btrfs_csum_final(sums->sums[index],
(char *)(sums->sums + index)); (char *)(sums->sums + index));
index++; index++;
...@@ -507,10 +514,9 @@ blk_status_t btrfs_csum_one_bio(struct inode *inode, struct bio *bio, ...@@ -507,10 +514,9 @@ blk_status_t btrfs_csum_one_bio(struct inode *inode, struct bio *bio,
total_bytes += fs_info->sectorsize; total_bytes += fs_info->sectorsize;
} }
kunmap_atomic(data);
} }
this_sum_bytes = 0; this_sum_bytes = 0;
btrfs_add_ordered_sum(inode, ordered, sums); btrfs_add_ordered_sum(ordered, sums);
btrfs_put_ordered_extent(ordered); btrfs_put_ordered_extent(ordered);
return 0; return 0;
} }
...@@ -551,7 +557,7 @@ static noinline void truncate_one_csum(struct btrfs_fs_info *fs_info, ...@@ -551,7 +557,7 @@ static noinline void truncate_one_csum(struct btrfs_fs_info *fs_info,
*/ */
u32 new_size = (bytenr - key->offset) >> blocksize_bits; u32 new_size = (bytenr - key->offset) >> blocksize_bits;
new_size *= csum_size; new_size *= csum_size;
btrfs_truncate_item(fs_info, path, new_size, 1); btrfs_truncate_item(path, new_size, 1);
} else if (key->offset >= bytenr && csum_end > end_byte && } else if (key->offset >= bytenr && csum_end > end_byte &&
end_byte > key->offset) { end_byte > key->offset) {
/* /*
...@@ -563,7 +569,7 @@ static noinline void truncate_one_csum(struct btrfs_fs_info *fs_info, ...@@ -563,7 +569,7 @@ static noinline void truncate_one_csum(struct btrfs_fs_info *fs_info,
u32 new_size = (csum_end - end_byte) >> blocksize_bits; u32 new_size = (csum_end - end_byte) >> blocksize_bits;
new_size *= csum_size; new_size *= csum_size;
btrfs_truncate_item(fs_info, path, new_size, 0); btrfs_truncate_item(path, new_size, 0);
key->offset = end_byte; key->offset = end_byte;
btrfs_set_item_key_safe(fs_info, path, key); btrfs_set_item_key_safe(fs_info, path, key);
...@@ -832,11 +838,11 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, ...@@ -832,11 +838,11 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
u32 diff; u32 diff;
u32 free_space; u32 free_space;
if (btrfs_leaf_free_space(fs_info, leaf) < if (btrfs_leaf_free_space(leaf) <
sizeof(struct btrfs_item) + csum_size * 2) sizeof(struct btrfs_item) + csum_size * 2)
goto insert; goto insert;
free_space = btrfs_leaf_free_space(fs_info, leaf) - free_space = btrfs_leaf_free_space(leaf) -
sizeof(struct btrfs_item) - csum_size; sizeof(struct btrfs_item) - csum_size;
tmp = sums->len - total_bytes; tmp = sums->len - total_bytes;
tmp >>= fs_info->sb->s_blocksize_bits; tmp >>= fs_info->sb->s_blocksize_bits;
...@@ -852,7 +858,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, ...@@ -852,7 +858,7 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
diff /= csum_size; diff /= csum_size;
diff *= csum_size; diff *= csum_size;
btrfs_extend_item(fs_info, path, diff); btrfs_extend_item(path, diff);
ret = 0; ret = 0;
goto csum; goto csum;
} }
......
...@@ -754,6 +754,7 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans, ...@@ -754,6 +754,7 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_fs_info *fs_info = root->fs_info;
struct extent_buffer *leaf; struct extent_buffer *leaf;
struct btrfs_file_extent_item *fi; struct btrfs_file_extent_item *fi;
struct btrfs_ref ref = { 0 };
struct btrfs_key key; struct btrfs_key key;
struct btrfs_key new_key; struct btrfs_key new_key;
u64 ino = btrfs_ino(BTRFS_I(inode)); u64 ino = btrfs_ino(BTRFS_I(inode));
...@@ -909,11 +910,14 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans, ...@@ -909,11 +910,14 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans,
btrfs_mark_buffer_dirty(leaf); btrfs_mark_buffer_dirty(leaf);
if (update_refs && disk_bytenr > 0) { if (update_refs && disk_bytenr > 0) {
ret = btrfs_inc_extent_ref(trans, root, btrfs_init_generic_ref(&ref,
disk_bytenr, num_bytes, 0, BTRFS_ADD_DELAYED_REF,
disk_bytenr, num_bytes, 0);
btrfs_init_data_ref(&ref,
root->root_key.objectid, root->root_key.objectid,
new_key.objectid, new_key.objectid,
start - extent_offset); start - extent_offset);
ret = btrfs_inc_extent_ref(trans, &ref);
BUG_ON(ret); /* -ENOMEM */ BUG_ON(ret); /* -ENOMEM */
} }
key.offset = start; key.offset = start;
...@@ -993,11 +997,14 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans, ...@@ -993,11 +997,14 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans,
extent_end = ALIGN(extent_end, extent_end = ALIGN(extent_end,
fs_info->sectorsize); fs_info->sectorsize);
} else if (update_refs && disk_bytenr > 0) { } else if (update_refs && disk_bytenr > 0) {
ret = btrfs_free_extent(trans, root, btrfs_init_generic_ref(&ref,
disk_bytenr, num_bytes, 0, BTRFS_DROP_DELAYED_REF,
disk_bytenr, num_bytes, 0);
btrfs_init_data_ref(&ref,
root->root_key.objectid, root->root_key.objectid,
key.objectid, key.offset - key.objectid,
extent_offset); key.offset - extent_offset);
ret = btrfs_free_extent(trans, &ref);
BUG_ON(ret); /* -ENOMEM */ BUG_ON(ret); /* -ENOMEM */
inode_sub_bytes(inode, inode_sub_bytes(inode,
extent_end - key.offset); extent_end - key.offset);
...@@ -1025,7 +1032,7 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans, ...@@ -1025,7 +1032,7 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans,
continue; continue;
} }
BUG_ON(1); BUG();
} }
if (!ret && del_nr > 0) { if (!ret && del_nr > 0) {
...@@ -1050,7 +1057,7 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans, ...@@ -1050,7 +1057,7 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans,
if (!ret && replace_extent && leafs_visited == 1 && if (!ret && replace_extent && leafs_visited == 1 &&
(path->locks[0] == BTRFS_WRITE_LOCK_BLOCKING || (path->locks[0] == BTRFS_WRITE_LOCK_BLOCKING ||
path->locks[0] == BTRFS_WRITE_LOCK) && path->locks[0] == BTRFS_WRITE_LOCK) &&
btrfs_leaf_free_space(fs_info, leaf) >= btrfs_leaf_free_space(leaf) >=
sizeof(struct btrfs_item) + extent_item_size) { sizeof(struct btrfs_item) + extent_item_size) {
key.objectid = ino; key.objectid = ino;
...@@ -1142,6 +1149,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -1142,6 +1149,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
struct extent_buffer *leaf; struct extent_buffer *leaf;
struct btrfs_path *path; struct btrfs_path *path;
struct btrfs_file_extent_item *fi; struct btrfs_file_extent_item *fi;
struct btrfs_ref ref = { 0 };
struct btrfs_key key; struct btrfs_key key;
struct btrfs_key new_key; struct btrfs_key new_key;
u64 bytenr; u64 bytenr;
...@@ -1287,9 +1295,11 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -1287,9 +1295,11 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
extent_end - split); extent_end - split);
btrfs_mark_buffer_dirty(leaf); btrfs_mark_buffer_dirty(leaf);
ret = btrfs_inc_extent_ref(trans, root, bytenr, num_bytes, btrfs_init_generic_ref(&ref, BTRFS_ADD_DELAYED_REF, bytenr,
0, root->root_key.objectid, num_bytes, 0);
ino, orig_offset); btrfs_init_data_ref(&ref, root->root_key.objectid, ino,
orig_offset);
ret = btrfs_inc_extent_ref(trans, &ref);
if (ret) { if (ret) {
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);
goto out; goto out;
...@@ -1311,6 +1321,9 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -1311,6 +1321,9 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
other_start = end; other_start = end;
other_end = 0; other_end = 0;
btrfs_init_generic_ref(&ref, BTRFS_DROP_DELAYED_REF, bytenr,
num_bytes, 0);
btrfs_init_data_ref(&ref, root->root_key.objectid, ino, orig_offset);
if (extent_mergeable(leaf, path->slots[0] + 1, if (extent_mergeable(leaf, path->slots[0] + 1,
ino, bytenr, orig_offset, ino, bytenr, orig_offset,
&other_start, &other_end)) { &other_start, &other_end)) {
...@@ -1321,9 +1334,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -1321,9 +1334,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
extent_end = other_end; extent_end = other_end;
del_slot = path->slots[0] + 1; del_slot = path->slots[0] + 1;
del_nr++; del_nr++;
ret = btrfs_free_extent(trans, root, bytenr, num_bytes, ret = btrfs_free_extent(trans, &ref);
0, root->root_key.objectid,
ino, orig_offset);
if (ret) { if (ret) {
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);
goto out; goto out;
...@@ -1341,9 +1352,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -1341,9 +1352,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
key.offset = other_start; key.offset = other_start;
del_slot = path->slots[0]; del_slot = path->slots[0];
del_nr++; del_nr++;
ret = btrfs_free_extent(trans, root, bytenr, num_bytes, ret = btrfs_free_extent(trans, &ref);
0, root->root_key.objectid,
ino, orig_offset);
if (ret) { if (ret) {
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);
goto out; goto out;
...@@ -2165,7 +2174,6 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -2165,7 +2174,6 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
inode_unlock(inode); inode_unlock(inode);
goto out; goto out;
} }
trans->sync = true;
ret = btrfs_log_dentry_safe(trans, dentry, start, end, &ctx); ret = btrfs_log_dentry_safe(trans, dentry, start, end, &ctx);
if (ret < 0) { if (ret < 0) {
...@@ -3132,6 +3140,7 @@ static long btrfs_fallocate(struct file *file, int mode, ...@@ -3132,6 +3140,7 @@ static long btrfs_fallocate(struct file *file, int mode,
ret = btrfs_qgroup_reserve_data(inode, &data_reserved, ret = btrfs_qgroup_reserve_data(inode, &data_reserved,
cur_offset, last_byte - cur_offset); cur_offset, last_byte - cur_offset);
if (ret < 0) { if (ret < 0) {
cur_offset = last_byte;
free_extent_map(em); free_extent_map(em);
break; break;
} }
...@@ -3181,7 +3190,7 @@ static long btrfs_fallocate(struct file *file, int mode, ...@@ -3181,7 +3190,7 @@ static long btrfs_fallocate(struct file *file, int mode,
/* Let go of our reservation. */ /* Let go of our reservation. */
if (ret != 0 && !(mode & FALLOC_FL_ZERO_RANGE)) if (ret != 0 && !(mode & FALLOC_FL_ZERO_RANGE))
btrfs_free_reserved_data_space(inode, data_reserved, btrfs_free_reserved_data_space(inode, data_reserved,
alloc_start, alloc_end - cur_offset); cur_offset, alloc_end - cur_offset);
extent_changeset_free(data_reserved); extent_changeset_free(data_reserved);
return ret; return ret;
} }
......
...@@ -88,10 +88,11 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root, ...@@ -88,10 +88,11 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root,
return inode; return inode;
} }
struct inode *lookup_free_space_inode(struct btrfs_fs_info *fs_info, struct inode *lookup_free_space_inode(
struct btrfs_block_group_cache struct btrfs_block_group_cache *block_group,
*block_group, struct btrfs_path *path) struct btrfs_path *path)
{ {
struct btrfs_fs_info *fs_info = block_group->fs_info;
struct inode *inode = NULL; struct inode *inode = NULL;
u32 flags = BTRFS_INODE_NODATASUM | BTRFS_INODE_NODATACOW; u32 flags = BTRFS_INODE_NODATASUM | BTRFS_INODE_NODATACOW;
...@@ -185,20 +186,19 @@ static int __create_free_space_inode(struct btrfs_root *root, ...@@ -185,20 +186,19 @@ static int __create_free_space_inode(struct btrfs_root *root,
return 0; return 0;
} }
int create_free_space_inode(struct btrfs_fs_info *fs_info, int create_free_space_inode(struct btrfs_trans_handle *trans,
struct btrfs_trans_handle *trans,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct btrfs_path *path) struct btrfs_path *path)
{ {
int ret; int ret;
u64 ino; u64 ino;
ret = btrfs_find_free_objectid(fs_info->tree_root, &ino); ret = btrfs_find_free_objectid(trans->fs_info->tree_root, &ino);
if (ret < 0) if (ret < 0)
return ret; return ret;
return __create_free_space_inode(fs_info->tree_root, trans, path, ino, return __create_free_space_inode(trans->fs_info->tree_root, trans, path,
block_group->key.objectid); ino, block_group->key.objectid);
} }
int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info, int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info,
...@@ -812,9 +812,9 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode, ...@@ -812,9 +812,9 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode,
goto out; goto out;
} }
int load_free_space_cache(struct btrfs_fs_info *fs_info, int load_free_space_cache(struct btrfs_block_group_cache *block_group)
struct btrfs_block_group_cache *block_group)
{ {
struct btrfs_fs_info *fs_info = block_group->fs_info;
struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
struct inode *inode; struct inode *inode;
struct btrfs_path *path; struct btrfs_path *path;
...@@ -858,7 +858,7 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info, ...@@ -858,7 +858,7 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info,
* once created get their ->cached field set to BTRFS_CACHE_FINISHED so * once created get their ->cached field set to BTRFS_CACHE_FINISHED so
* we will never try to read their inode item while the fs is mounted. * we will never try to read their inode item while the fs is mounted.
*/ */
inode = lookup_free_space_inode(fs_info, block_group, path); inode = lookup_free_space_inode(block_group, path);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
btrfs_free_path(path); btrfs_free_path(path);
return 0; return 0;
...@@ -1039,8 +1039,7 @@ update_cache_item(struct btrfs_trans_handle *trans, ...@@ -1039,8 +1039,7 @@ update_cache_item(struct btrfs_trans_handle *trans,
return -1; return -1;
} }
static noinline_for_stack int static noinline_for_stack int write_pinned_extent_entries(
write_pinned_extent_entries(struct btrfs_fs_info *fs_info,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct btrfs_io_ctl *io_ctl, struct btrfs_io_ctl *io_ctl,
int *entries) int *entries)
...@@ -1059,7 +1058,7 @@ write_pinned_extent_entries(struct btrfs_fs_info *fs_info, ...@@ -1059,7 +1058,7 @@ write_pinned_extent_entries(struct btrfs_fs_info *fs_info,
* We shouldn't have switched the pinned extents yet so this is the * We shouldn't have switched the pinned extents yet so this is the
* right one * right one
*/ */
unpin = fs_info->pinned_extents; unpin = block_group->fs_info->pinned_extents;
start = block_group->key.objectid; start = block_group->key.objectid;
...@@ -1235,7 +1234,6 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, ...@@ -1235,7 +1234,6 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
struct btrfs_io_ctl *io_ctl, struct btrfs_io_ctl *io_ctl,
struct btrfs_trans_handle *trans) struct btrfs_trans_handle *trans)
{ {
struct btrfs_fs_info *fs_info = root->fs_info;
struct extent_state *cached_state = NULL; struct extent_state *cached_state = NULL;
LIST_HEAD(bitmap_list); LIST_HEAD(bitmap_list);
int entries = 0; int entries = 0;
...@@ -1293,8 +1291,7 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, ...@@ -1293,8 +1291,7 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
* If this changes while we are working we'll get added back to * If this changes while we are working we'll get added back to
* the dirty list and redo it. No locking needed * the dirty list and redo it. No locking needed
*/ */
ret = write_pinned_extent_entries(fs_info, block_group, ret = write_pinned_extent_entries(block_group, io_ctl, &entries);
io_ctl, &entries);
if (ret) if (ret)
goto out_nospc_locked; goto out_nospc_locked;
...@@ -1370,11 +1367,11 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, ...@@ -1370,11 +1367,11 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
goto out; goto out;
} }
int btrfs_write_out_cache(struct btrfs_fs_info *fs_info, int btrfs_write_out_cache(struct btrfs_trans_handle *trans,
struct btrfs_trans_handle *trans,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct btrfs_path *path) struct btrfs_path *path)
{ {
struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
struct inode *inode; struct inode *inode;
int ret = 0; int ret = 0;
...@@ -1386,7 +1383,7 @@ int btrfs_write_out_cache(struct btrfs_fs_info *fs_info, ...@@ -1386,7 +1383,7 @@ int btrfs_write_out_cache(struct btrfs_fs_info *fs_info,
} }
spin_unlock(&block_group->lock); spin_unlock(&block_group->lock);
inode = lookup_free_space_inode(fs_info, block_group, path); inode = lookup_free_space_inode(block_group, path);
if (IS_ERR(inode)) if (IS_ERR(inode))
return 0; return 0;
...@@ -3040,11 +3037,11 @@ setup_cluster_bitmap(struct btrfs_block_group_cache *block_group, ...@@ -3040,11 +3037,11 @@ setup_cluster_bitmap(struct btrfs_block_group_cache *block_group,
* returns zero and sets up cluster if things worked out, otherwise * returns zero and sets up cluster if things worked out, otherwise
* it returns -enospc * it returns -enospc
*/ */
int btrfs_find_space_cluster(struct btrfs_fs_info *fs_info, int btrfs_find_space_cluster(struct btrfs_block_group_cache *block_group,
struct btrfs_block_group_cache *block_group,
struct btrfs_free_cluster *cluster, struct btrfs_free_cluster *cluster,
u64 offset, u64 bytes, u64 empty_size) u64 offset, u64 bytes, u64 empty_size)
{ {
struct btrfs_fs_info *fs_info = block_group->fs_info;
struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
struct btrfs_free_space *entry, *tmp; struct btrfs_free_space *entry, *tmp;
LIST_HEAD(bitmaps); LIST_HEAD(bitmaps);
...@@ -3366,10 +3363,6 @@ void btrfs_put_block_group_trimming(struct btrfs_block_group_cache *block_group) ...@@ -3366,10 +3363,6 @@ void btrfs_put_block_group_trimming(struct btrfs_block_group_cache *block_group)
em = lookup_extent_mapping(em_tree, block_group->key.objectid, em = lookup_extent_mapping(em_tree, block_group->key.objectid,
1); 1);
BUG_ON(!em); /* logic error, can't happen */ BUG_ON(!em); /* logic error, can't happen */
/*
* remove_extent_mapping() will delete us from the pinned_chunks
* list, which is protected by the chunk mutex.
*/
remove_extent_mapping(em_tree, em); remove_extent_mapping(em_tree, em);
write_unlock(&em_tree->lock); write_unlock(&em_tree->lock);
mutex_unlock(&fs_info->chunk_mutex); mutex_unlock(&fs_info->chunk_mutex);
......
...@@ -38,11 +38,10 @@ struct btrfs_free_space_op { ...@@ -38,11 +38,10 @@ struct btrfs_free_space_op {
struct btrfs_io_ctl; struct btrfs_io_ctl;
struct inode *lookup_free_space_inode(struct btrfs_fs_info *fs_info, struct inode *lookup_free_space_inode(
struct btrfs_block_group_cache struct btrfs_block_group_cache *block_group,
*block_group, struct btrfs_path *path); struct btrfs_path *path);
int create_free_space_inode(struct btrfs_fs_info *fs_info, int create_free_space_inode(struct btrfs_trans_handle *trans,
struct btrfs_trans_handle *trans,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct btrfs_path *path); struct btrfs_path *path);
...@@ -51,13 +50,11 @@ int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info, ...@@ -51,13 +50,11 @@ int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info,
int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans, int btrfs_truncate_free_space_cache(struct btrfs_trans_handle *trans,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct inode *inode); struct inode *inode);
int load_free_space_cache(struct btrfs_fs_info *fs_info, int load_free_space_cache(struct btrfs_block_group_cache *block_group);
struct btrfs_block_group_cache *block_group);
int btrfs_wait_cache_io(struct btrfs_trans_handle *trans, int btrfs_wait_cache_io(struct btrfs_trans_handle *trans,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct btrfs_path *path); struct btrfs_path *path);
int btrfs_write_out_cache(struct btrfs_fs_info *fs_info, int btrfs_write_out_cache(struct btrfs_trans_handle *trans,
struct btrfs_trans_handle *trans,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct btrfs_path *path); struct btrfs_path *path);
struct inode *lookup_free_ino_inode(struct btrfs_root *root, struct inode *lookup_free_ino_inode(struct btrfs_root *root,
...@@ -95,8 +92,7 @@ u64 btrfs_find_space_for_alloc(struct btrfs_block_group_cache *block_group, ...@@ -95,8 +92,7 @@ u64 btrfs_find_space_for_alloc(struct btrfs_block_group_cache *block_group,
u64 btrfs_find_ino_for_alloc(struct btrfs_root *fs_root); u64 btrfs_find_ino_for_alloc(struct btrfs_root *fs_root);
void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group, void btrfs_dump_free_space(struct btrfs_block_group_cache *block_group,
u64 bytes); u64 bytes);
int btrfs_find_space_cluster(struct btrfs_fs_info *fs_info, int btrfs_find_space_cluster(struct btrfs_block_group_cache *block_group,
struct btrfs_block_group_cache *block_group,
struct btrfs_free_cluster *cluster, struct btrfs_free_cluster *cluster,
u64 offset, u64 bytes, u64 empty_size); u64 offset, u64 bytes, u64 empty_size);
void btrfs_init_free_cluster(struct btrfs_free_cluster *cluster); void btrfs_init_free_cluster(struct btrfs_free_cluster *cluster);
......
...@@ -76,10 +76,11 @@ static int add_new_free_space_info(struct btrfs_trans_handle *trans, ...@@ -76,10 +76,11 @@ static int add_new_free_space_info(struct btrfs_trans_handle *trans,
EXPORT_FOR_TESTS EXPORT_FOR_TESTS
struct btrfs_free_space_info *search_free_space_info( struct btrfs_free_space_info *search_free_space_info(
struct btrfs_trans_handle *trans, struct btrfs_fs_info *fs_info, struct btrfs_trans_handle *trans,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct btrfs_path *path, int cow) struct btrfs_path *path, int cow)
{ {
struct btrfs_fs_info *fs_info = block_group->fs_info;
struct btrfs_root *root = fs_info->free_space_root; struct btrfs_root *root = fs_info->free_space_root;
struct btrfs_key key; struct btrfs_key key;
int ret; int ret;
...@@ -253,7 +254,7 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans, ...@@ -253,7 +254,7 @@ int convert_free_space_to_bitmaps(struct btrfs_trans_handle *trans,
btrfs_release_path(path); btrfs_release_path(path);
} }
info = search_free_space_info(trans, fs_info, block_group, path, 1); info = search_free_space_info(trans, block_group, path, 1);
if (IS_ERR(info)) { if (IS_ERR(info)) {
ret = PTR_ERR(info); ret = PTR_ERR(info);
goto out; goto out;
...@@ -398,7 +399,7 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans, ...@@ -398,7 +399,7 @@ int convert_free_space_to_extents(struct btrfs_trans_handle *trans,
btrfs_release_path(path); btrfs_release_path(path);
} }
info = search_free_space_info(trans, fs_info, block_group, path, 1); info = search_free_space_info(trans, block_group, path, 1);
if (IS_ERR(info)) { if (IS_ERR(info)) {
ret = PTR_ERR(info); ret = PTR_ERR(info);
goto out; goto out;
...@@ -463,8 +464,7 @@ static int update_free_space_extent_count(struct btrfs_trans_handle *trans, ...@@ -463,8 +464,7 @@ static int update_free_space_extent_count(struct btrfs_trans_handle *trans,
if (new_extents == 0) if (new_extents == 0)
return 0; return 0;
info = search_free_space_info(trans, trans->fs_info, block_group, path, info = search_free_space_info(trans, block_group, path, 1);
1);
if (IS_ERR(info)) { if (IS_ERR(info)) {
ret = PTR_ERR(info); ret = PTR_ERR(info);
goto out; goto out;
...@@ -793,8 +793,7 @@ int __remove_from_free_space_tree(struct btrfs_trans_handle *trans, ...@@ -793,8 +793,7 @@ int __remove_from_free_space_tree(struct btrfs_trans_handle *trans,
return ret; return ret;
} }
info = search_free_space_info(NULL, trans->fs_info, block_group, path, info = search_free_space_info(NULL, block_group, path, 0);
0);
if (IS_ERR(info)) if (IS_ERR(info))
return PTR_ERR(info); return PTR_ERR(info);
flags = btrfs_free_space_flags(path->nodes[0], info); flags = btrfs_free_space_flags(path->nodes[0], info);
...@@ -977,7 +976,6 @@ int __add_to_free_space_tree(struct btrfs_trans_handle *trans, ...@@ -977,7 +976,6 @@ int __add_to_free_space_tree(struct btrfs_trans_handle *trans,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct btrfs_path *path, u64 start, u64 size) struct btrfs_path *path, u64 start, u64 size)
{ {
struct btrfs_fs_info *fs_info = trans->fs_info;
struct btrfs_free_space_info *info; struct btrfs_free_space_info *info;
u32 flags; u32 flags;
int ret; int ret;
...@@ -988,7 +986,7 @@ int __add_to_free_space_tree(struct btrfs_trans_handle *trans, ...@@ -988,7 +986,7 @@ int __add_to_free_space_tree(struct btrfs_trans_handle *trans,
return ret; return ret;
} }
info = search_free_space_info(NULL, fs_info, block_group, path, 0); info = search_free_space_info(NULL, block_group, path, 0);
if (IS_ERR(info)) if (IS_ERR(info))
return PTR_ERR(info); return PTR_ERR(info);
flags = btrfs_free_space_flags(path->nodes[0], info); flags = btrfs_free_space_flags(path->nodes[0], info);
...@@ -1150,7 +1148,7 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info) ...@@ -1150,7 +1148,7 @@ int btrfs_create_free_space_tree(struct btrfs_fs_info *fs_info)
return PTR_ERR(trans); return PTR_ERR(trans);
set_bit(BTRFS_FS_CREATING_FREE_SPACE_TREE, &fs_info->flags); set_bit(BTRFS_FS_CREATING_FREE_SPACE_TREE, &fs_info->flags);
free_space_root = btrfs_create_tree(trans, fs_info, free_space_root = btrfs_create_tree(trans,
BTRFS_FREE_SPACE_TREE_OBJECTID); BTRFS_FREE_SPACE_TREE_OBJECTID);
if (IS_ERR(free_space_root)) { if (IS_ERR(free_space_root)) {
ret = PTR_ERR(free_space_root); ret = PTR_ERR(free_space_root);
...@@ -1248,7 +1246,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info) ...@@ -1248,7 +1246,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info)
list_del(&free_space_root->dirty_list); list_del(&free_space_root->dirty_list);
btrfs_tree_lock(free_space_root->node); btrfs_tree_lock(free_space_root->node);
clean_tree_block(fs_info, free_space_root->node); btrfs_clean_tree_block(free_space_root->node);
btrfs_tree_unlock(free_space_root->node); btrfs_tree_unlock(free_space_root->node);
btrfs_free_tree_block(trans, free_space_root, free_space_root->node, btrfs_free_tree_block(trans, free_space_root, free_space_root->node,
0, 1); 0, 1);
...@@ -1534,14 +1532,12 @@ static int load_free_space_extents(struct btrfs_caching_control *caching_ctl, ...@@ -1534,14 +1532,12 @@ static int load_free_space_extents(struct btrfs_caching_control *caching_ctl,
int load_free_space_tree(struct btrfs_caching_control *caching_ctl) int load_free_space_tree(struct btrfs_caching_control *caching_ctl)
{ {
struct btrfs_block_group_cache *block_group; struct btrfs_block_group_cache *block_group;
struct btrfs_fs_info *fs_info;
struct btrfs_free_space_info *info; struct btrfs_free_space_info *info;
struct btrfs_path *path; struct btrfs_path *path;
u32 extent_count, flags; u32 extent_count, flags;
int ret; int ret;
block_group = caching_ctl->block_group; block_group = caching_ctl->block_group;
fs_info = block_group->fs_info;
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) if (!path)
...@@ -1555,7 +1551,7 @@ int load_free_space_tree(struct btrfs_caching_control *caching_ctl) ...@@ -1555,7 +1551,7 @@ int load_free_space_tree(struct btrfs_caching_control *caching_ctl)
path->search_commit_root = 1; path->search_commit_root = 1;
path->reada = READA_FORWARD; path->reada = READA_FORWARD;
info = search_free_space_info(NULL, fs_info, block_group, path, 0); info = search_free_space_info(NULL, block_group, path, 0);
if (IS_ERR(info)) { if (IS_ERR(info)) {
ret = PTR_ERR(info); ret = PTR_ERR(info);
goto out; goto out;
......
...@@ -30,7 +30,6 @@ int remove_from_free_space_tree(struct btrfs_trans_handle *trans, ...@@ -30,7 +30,6 @@ int remove_from_free_space_tree(struct btrfs_trans_handle *trans,
#ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS
struct btrfs_free_space_info * struct btrfs_free_space_info *
search_free_space_info(struct btrfs_trans_handle *trans, search_free_space_info(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct btrfs_path *path, int cow); struct btrfs_path *path, int cow);
int __add_to_free_space_tree(struct btrfs_trans_handle *trans, int __add_to_free_space_tree(struct btrfs_trans_handle *trans,
......
...@@ -170,7 +170,7 @@ static int btrfs_del_inode_extref(struct btrfs_trans_handle *trans, ...@@ -170,7 +170,7 @@ static int btrfs_del_inode_extref(struct btrfs_trans_handle *trans,
memmove_extent_buffer(leaf, ptr, ptr + del_len, memmove_extent_buffer(leaf, ptr, ptr + del_len,
item_size - (ptr + del_len - item_start)); item_size - (ptr + del_len - item_start));
btrfs_truncate_item(root->fs_info, path, item_size - del_len, 1); btrfs_truncate_item(path, item_size - del_len, 1);
out: out:
btrfs_free_path(path); btrfs_free_path(path);
...@@ -234,7 +234,7 @@ int btrfs_del_inode_ref(struct btrfs_trans_handle *trans, ...@@ -234,7 +234,7 @@ int btrfs_del_inode_ref(struct btrfs_trans_handle *trans,
item_start = btrfs_item_ptr_offset(leaf, path->slots[0]); item_start = btrfs_item_ptr_offset(leaf, path->slots[0]);
memmove_extent_buffer(leaf, ptr, ptr + sub_item_len, memmove_extent_buffer(leaf, ptr, ptr + sub_item_len,
item_size - (ptr + sub_item_len - item_start)); item_size - (ptr + sub_item_len - item_start));
btrfs_truncate_item(root->fs_info, path, item_size - sub_item_len, 1); btrfs_truncate_item(path, item_size - sub_item_len, 1);
out: out:
btrfs_free_path(path); btrfs_free_path(path);
...@@ -288,7 +288,7 @@ static int btrfs_insert_inode_extref(struct btrfs_trans_handle *trans, ...@@ -288,7 +288,7 @@ static int btrfs_insert_inode_extref(struct btrfs_trans_handle *trans,
name, name_len, NULL)) name, name_len, NULL))
goto out; goto out;
btrfs_extend_item(root->fs_info, path, ins_len); btrfs_extend_item(path, ins_len);
ret = 0; ret = 0;
} }
if (ret < 0) if (ret < 0)
...@@ -347,7 +347,7 @@ int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans, ...@@ -347,7 +347,7 @@ int btrfs_insert_inode_ref(struct btrfs_trans_handle *trans,
goto out; goto out;
old_size = btrfs_item_size_nr(path->nodes[0], path->slots[0]); old_size = btrfs_item_size_nr(path->nodes[0], path->slots[0]);
btrfs_extend_item(fs_info, path, ins_len); btrfs_extend_item(path, ins_len);
ref = btrfs_item_ptr(path->nodes[0], path->slots[0], ref = btrfs_item_ptr(path->nodes[0], path->slots[0],
struct btrfs_inode_ref); struct btrfs_inode_ref);
ref = (struct btrfs_inode_ref *)((unsigned long)ref + old_size); ref = (struct btrfs_inode_ref *)((unsigned long)ref + old_size);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -189,7 +189,7 @@ void btrfs_print_leaf(struct extent_buffer *l) ...@@ -189,7 +189,7 @@ void btrfs_print_leaf(struct extent_buffer *l)
btrfs_info(fs_info, btrfs_info(fs_info,
"leaf %llu gen %llu total ptrs %d free space %d owner %llu", "leaf %llu gen %llu total ptrs %d free space %d owner %llu",
btrfs_header_bytenr(l), btrfs_header_generation(l), nr, btrfs_header_bytenr(l), btrfs_header_generation(l), nr,
btrfs_leaf_free_space(fs_info, l), btrfs_header_owner(l)); btrfs_leaf_free_space(l), btrfs_header_owner(l));
print_eb_refs_lock(l); print_eb_refs_lock(l);
for (i = 0 ; i < nr ; i++) { for (i = 0 ; i < nr ; i++) {
item = btrfs_item_nr(i); item = btrfs_item_nr(i);
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment