Commit 9003ed1f authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'for-linus-4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs

Pull btrfs updates from Chris Mason:
 "This has a series of fixes and cleanups that Dave Sterba has been
  collecting.

  There is a pretty big variety here, cleaning up internal APIs and
  fixing corner cases"

* 'for-linus-4.11' of git://git.kernel.org/pub/scm/linux/kernel/git/mason/linux-btrfs: (124 commits)
  Btrfs: use the correct type when creating cow dio extent
  Btrfs: fix deadlock between dedup on same file and starting writeback
  btrfs: use btrfs_debug instead of pr_debug in transaction abort
  btrfs: btrfs_truncate_free_space_cache always allocates path
  btrfs: free-space-cache, clean up unnecessary root arguments
  btrfs: convert btrfs_inc_block_group_ro to accept fs_info
  btrfs: flush_space always takes fs_info->fs_root
  btrfs: pass fs_info to (more) routines that are only called with extent_root
  btrfs: qgroup: Move half of the qgroup accounting time out of commit trans
  btrfs: remove unused parameter from adjust_slots_upwards
  btrfs: remove unused parameters from __btrfs_write_out_cache
  btrfs: remove unused parameter from cleanup_write_cache_enospc
  btrfs: remove unused parameter from __add_inode_ref
  btrfs: remove unused parameter from clone_copy_inline_extent
  btrfs: remove unused parameters from btrfs_cmp_data
  btrfs: remove unused parameter from __add_inline_refs
  btrfs: remove unused parameters from scrub_setup_wr_ctx
  btrfs: remove unused parameter from create_snapshot
  btrfs: remove unused parameter from init_first_rw_device
  btrfs: remove unused parameter from __btrfs_alloc_chunk
  ...
parents 94eae803 6288d6ea
...@@ -956,8 +956,7 @@ static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq, ...@@ -956,8 +956,7 @@ static int __add_delayed_refs(struct btrfs_delayed_ref_head *head, u64 seq,
/* /*
* add all inline backrefs for bytenr to the list * add all inline backrefs for bytenr to the list
*/ */
static int __add_inline_refs(struct btrfs_fs_info *fs_info, static int __add_inline_refs(struct btrfs_path *path, u64 bytenr,
struct btrfs_path *path, u64 bytenr,
int *info_level, struct list_head *prefs, int *info_level, struct list_head *prefs,
struct ref_root *ref_tree, struct ref_root *ref_tree,
u64 *total_refs, u64 inum) u64 *total_refs, u64 inum)
...@@ -1284,7 +1283,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans, ...@@ -1284,7 +1283,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
*/ */
delayed_refs = &trans->transaction->delayed_refs; delayed_refs = &trans->transaction->delayed_refs;
spin_lock(&delayed_refs->lock); spin_lock(&delayed_refs->lock);
head = btrfs_find_delayed_ref_head(trans, bytenr); head = btrfs_find_delayed_ref_head(delayed_refs, bytenr);
if (head) { if (head) {
if (!mutex_trylock(&head->mutex)) { if (!mutex_trylock(&head->mutex)) {
atomic_inc(&head->node.refs); atomic_inc(&head->node.refs);
...@@ -1354,7 +1353,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans, ...@@ -1354,7 +1353,7 @@ static int find_parent_nodes(struct btrfs_trans_handle *trans,
if (key.objectid == bytenr && if (key.objectid == bytenr &&
(key.type == BTRFS_EXTENT_ITEM_KEY || (key.type == BTRFS_EXTENT_ITEM_KEY ||
key.type == BTRFS_METADATA_ITEM_KEY)) { key.type == BTRFS_METADATA_ITEM_KEY)) {
ret = __add_inline_refs(fs_info, path, bytenr, ret = __add_inline_refs(path, bytenr,
&info_level, &prefs, &info_level, &prefs,
ref_tree, &total_refs, ref_tree, &total_refs,
inum); inum);
......
...@@ -224,16 +224,16 @@ static inline void btrfs_insert_inode_hash(struct inode *inode) ...@@ -224,16 +224,16 @@ static inline void btrfs_insert_inode_hash(struct inode *inode)
__insert_inode_hash(inode, h); __insert_inode_hash(inode, h);
} }
static inline u64 btrfs_ino(struct inode *inode) static inline u64 btrfs_ino(struct btrfs_inode *inode)
{ {
u64 ino = BTRFS_I(inode)->location.objectid; u64 ino = inode->location.objectid;
/* /*
* !ino: btree_inode * !ino: btree_inode
* type == BTRFS_ROOT_ITEM_KEY: subvol dir * type == BTRFS_ROOT_ITEM_KEY: subvol dir
*/ */
if (!ino || BTRFS_I(inode)->location.type == BTRFS_ROOT_ITEM_KEY) if (!ino || inode->location.type == BTRFS_ROOT_ITEM_KEY)
ino = inode->i_ino; ino = inode->vfs_inode.i_ino;
return ino; return ino;
} }
...@@ -248,23 +248,21 @@ static inline bool btrfs_is_free_space_inode(struct inode *inode) ...@@ -248,23 +248,21 @@ static inline bool btrfs_is_free_space_inode(struct inode *inode)
struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_root *root = BTRFS_I(inode)->root;
if (root == root->fs_info->tree_root && if (root == root->fs_info->tree_root &&
btrfs_ino(inode) != BTRFS_BTREE_INODE_OBJECTID) btrfs_ino(BTRFS_I(inode)) != BTRFS_BTREE_INODE_OBJECTID)
return true; return true;
if (BTRFS_I(inode)->location.objectid == BTRFS_FREE_INO_OBJECTID) if (BTRFS_I(inode)->location.objectid == BTRFS_FREE_INO_OBJECTID)
return true; return true;
return false; return false;
} }
static inline int btrfs_inode_in_log(struct inode *inode, u64 generation) static inline int btrfs_inode_in_log(struct btrfs_inode *inode, u64 generation)
{ {
int ret = 0; int ret = 0;
spin_lock(&BTRFS_I(inode)->lock); spin_lock(&inode->lock);
if (BTRFS_I(inode)->logged_trans == generation && if (inode->logged_trans == generation &&
BTRFS_I(inode)->last_sub_trans <= inode->last_sub_trans <= inode->last_log_commit &&
BTRFS_I(inode)->last_log_commit && inode->last_sub_trans <= inode->root->last_log_commit) {
BTRFS_I(inode)->last_sub_trans <=
BTRFS_I(inode)->root->last_log_commit) {
/* /*
* After a ranged fsync we might have left some extent maps * After a ranged fsync we might have left some extent maps
* (that fall outside the fsync's range). So return false * (that fall outside the fsync's range). So return false
...@@ -272,10 +270,10 @@ static inline int btrfs_inode_in_log(struct inode *inode, u64 generation) ...@@ -272,10 +270,10 @@ static inline int btrfs_inode_in_log(struct inode *inode, u64 generation)
* will be called and process those extent maps. * will be called and process those extent maps.
*/ */
smp_mb(); smp_mb();
if (list_empty(&BTRFS_I(inode)->extent_tree.modified_extents)) if (list_empty(&inode->extent_tree.modified_extents))
ret = 1; ret = 1;
} }
spin_unlock(&BTRFS_I(inode)->lock); spin_unlock(&inode->lock);
return ret; return ret;
} }
...@@ -326,6 +324,24 @@ static inline void btrfs_inode_resume_unlocked_dio(struct inode *inode) ...@@ -326,6 +324,24 @@ static inline void btrfs_inode_resume_unlocked_dio(struct inode *inode)
&BTRFS_I(inode)->runtime_flags); &BTRFS_I(inode)->runtime_flags);
} }
static inline void btrfs_print_data_csum_error(struct inode *inode,
u64 logical_start, u32 csum, u32 csum_expected, int mirror_num)
{
struct btrfs_root *root = BTRFS_I(inode)->root;
/* Output minus objectid, which is more meaningful */
if (root->objectid >= BTRFS_LAST_FREE_OBJECTID)
btrfs_warn_rl(root->fs_info,
"csum failed root %lld ino %lld off %llu csum 0x%08x expected csum 0x%08x mirror %d",
root->objectid, btrfs_ino(BTRFS_I(inode)),
logical_start, csum, csum_expected, mirror_num);
else
btrfs_warn_rl(root->fs_info,
"csum failed root %llu ino %llu off %llu csum 0x%08x expected csum 0x%08x mirror %d",
root->objectid, btrfs_ino(BTRFS_I(inode)),
logical_start, csum, csum_expected, mirror_num);
}
bool btrfs_page_exists_in_range(struct inode *inode, loff_t start, loff_t end); bool btrfs_page_exists_in_range(struct inode *inode, loff_t start, loff_t end);
#endif #endif
...@@ -124,10 +124,8 @@ static int check_compressed_csum(struct inode *inode, ...@@ -124,10 +124,8 @@ static int check_compressed_csum(struct inode *inode,
kunmap_atomic(kaddr); kunmap_atomic(kaddr);
if (csum != *cb_sum) { if (csum != *cb_sum) {
btrfs_info(BTRFS_I(inode)->root->fs_info, btrfs_print_data_csum_error(inode, disk_start, csum,
"csum failed ino %llu extent %llu csum %u wanted %u mirror %d", *cb_sum, cb->mirror_num);
btrfs_ino(inode), disk_start, csum, *cb_sum,
cb->mirror_num);
ret = -EIO; ret = -EIO;
goto fail; goto fail;
} }
......
This diff is collapsed.
...@@ -97,6 +97,14 @@ static const int btrfs_csum_sizes[] = { 4 }; ...@@ -97,6 +97,14 @@ static const int btrfs_csum_sizes[] = { 4 };
#define BTRFS_MAX_EXTENT_SIZE SZ_128M #define BTRFS_MAX_EXTENT_SIZE SZ_128M
/*
* Count how many BTRFS_MAX_EXTENT_SIZE cover the @size
*/
static inline u32 count_max_extents(u64 size)
{
return div_u64(size + BTRFS_MAX_EXTENT_SIZE - 1, BTRFS_MAX_EXTENT_SIZE);
}
struct btrfs_mapping_tree { struct btrfs_mapping_tree {
struct extent_map_tree map_tree; struct extent_map_tree map_tree;
}; };
...@@ -1953,7 +1961,7 @@ BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64); ...@@ -1953,7 +1961,7 @@ BTRFS_SETGET_STACK_FUNCS(disk_key_offset, struct btrfs_disk_key, offset, 64);
BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8); BTRFS_SETGET_STACK_FUNCS(disk_key_type, struct btrfs_disk_key, type, 8);
static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
struct btrfs_disk_key *disk) const struct btrfs_disk_key *disk)
{ {
cpu->offset = le64_to_cpu(disk->offset); cpu->offset = le64_to_cpu(disk->offset);
cpu->type = disk->type; cpu->type = disk->type;
...@@ -1961,7 +1969,7 @@ static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu, ...@@ -1961,7 +1969,7 @@ static inline void btrfs_disk_key_to_cpu(struct btrfs_key *cpu,
} }
static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk, static inline void btrfs_cpu_key_to_disk(struct btrfs_disk_key *disk,
struct btrfs_key *cpu) const struct btrfs_key *cpu)
{ {
disk->offset = cpu_to_le64(cpu->offset); disk->offset = cpu_to_le64(cpu->offset);
disk->type = cpu->type; disk->type = cpu->type;
...@@ -1993,8 +2001,7 @@ static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb, ...@@ -1993,8 +2001,7 @@ static inline void btrfs_dir_item_key_to_cpu(struct extent_buffer *eb,
btrfs_disk_key_to_cpu(key, &disk_key); btrfs_disk_key_to_cpu(key, &disk_key);
} }
static inline u8 btrfs_key_type(const struct btrfs_key *key)
static inline u8 btrfs_key_type(struct btrfs_key *key)
{ {
return key->type; return key->type;
} }
...@@ -2577,8 +2584,7 @@ int btrfs_pin_extent_for_log_replay(struct btrfs_fs_info *fs_info, ...@@ -2577,8 +2584,7 @@ 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 btrfs_fs_info *fs_info,
struct extent_buffer *eb); struct extent_buffer *eb);
int btrfs_cross_ref_exist(struct btrfs_trans_handle *trans, int btrfs_cross_ref_exist(struct btrfs_root *root,
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(
struct btrfs_fs_info *info, struct btrfs_fs_info *info,
...@@ -2587,10 +2593,11 @@ void btrfs_get_block_group(struct btrfs_block_group_cache *cache); ...@@ -2587,10 +2593,11 @@ void btrfs_get_block_group(struct btrfs_block_group_cache *cache);
void btrfs_put_block_group(struct btrfs_block_group_cache *cache); void btrfs_put_block_group(struct btrfs_block_group_cache *cache);
int get_block_group_index(struct btrfs_block_group_cache *cache); int get_block_group_index(struct btrfs_block_group_cache *cache);
struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans, struct extent_buffer *btrfs_alloc_tree_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 parent, struct btrfs_root *root,
u64 root_objectid, u64 parent, u64 root_objectid,
struct btrfs_disk_key *key, int level, const struct btrfs_disk_key *key,
u64 hint, u64 empty_size); int level, u64 hint,
u64 empty_size);
void btrfs_free_tree_block(struct btrfs_trans_handle *trans, void btrfs_free_tree_block(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_root *root,
struct extent_buffer *buf, struct extent_buffer *buf,
...@@ -2623,8 +2630,7 @@ int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info, ...@@ -2623,8 +2630,7 @@ int btrfs_free_reserved_extent(struct btrfs_fs_info *fs_info,
u64 start, u64 len, int delalloc); u64 start, u64 len, int delalloc);
int btrfs_free_and_pin_reserved_extent(struct btrfs_fs_info *fs_info, int btrfs_free_and_pin_reserved_extent(struct btrfs_fs_info *fs_info,
u64 start, u64 len); u64 start, u64 len);
void btrfs_prepare_extent_commit(struct btrfs_trans_handle *trans, void btrfs_prepare_extent_commit(struct btrfs_fs_info *fs_info);
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,
struct btrfs_fs_info *fs_info); struct btrfs_fs_info *fs_info);
int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans, int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
...@@ -2696,8 +2702,7 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root, ...@@ -2696,8 +2702,7 @@ int btrfs_subvolume_reserve_metadata(struct btrfs_root *root,
int nitems, int nitems,
u64 *qgroup_reserved, bool use_global_rsv); u64 *qgroup_reserved, bool use_global_rsv);
void btrfs_subvolume_release_metadata(struct btrfs_fs_info *fs_info, void btrfs_subvolume_release_metadata(struct btrfs_fs_info *fs_info,
struct btrfs_block_rsv *rsv, struct btrfs_block_rsv *rsv);
u64 qgroup_reserved);
int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes); int btrfs_delalloc_reserve_metadata(struct inode *inode, u64 num_bytes);
void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes); void btrfs_delalloc_release_metadata(struct inode *inode, u64 num_bytes);
int btrfs_delalloc_reserve_space(struct inode *inode, u64 start, u64 len); int btrfs_delalloc_reserve_space(struct inode *inode, u64 start, u64 len);
...@@ -2724,7 +2729,7 @@ int btrfs_cond_migrate_bytes(struct btrfs_fs_info *fs_info, ...@@ -2724,7 +2729,7 @@ int btrfs_cond_migrate_bytes(struct btrfs_fs_info *fs_info,
void btrfs_block_rsv_release(struct btrfs_fs_info *fs_info, void btrfs_block_rsv_release(struct btrfs_fs_info *fs_info,
struct btrfs_block_rsv *block_rsv, struct btrfs_block_rsv *block_rsv,
u64 num_bytes); u64 num_bytes);
int btrfs_inc_block_group_ro(struct btrfs_root *root, int btrfs_inc_block_group_ro(struct btrfs_fs_info *fs_info,
struct btrfs_block_group_cache *cache); struct btrfs_block_group_cache *cache);
void btrfs_dec_block_group_ro(struct btrfs_block_group_cache *cache); void btrfs_dec_block_group_ro(struct btrfs_block_group_cache *cache);
void btrfs_put_block_group_cache(struct btrfs_fs_info *info); void btrfs_put_block_group_cache(struct btrfs_fs_info *info);
...@@ -2750,9 +2755,9 @@ u64 add_new_free_space(struct btrfs_block_group_cache *block_group, ...@@ -2750,9 +2755,9 @@ u64 add_new_free_space(struct btrfs_block_group_cache *block_group,
struct btrfs_fs_info *info, u64 start, u64 end); struct btrfs_fs_info *info, u64 start, u64 end);
/* ctree.c */ /* ctree.c */
int btrfs_bin_search(struct extent_buffer *eb, struct btrfs_key *key, int btrfs_bin_search(struct extent_buffer *eb, const struct btrfs_key *key,
int level, int *slot); int level, int *slot);
int btrfs_comp_cpu_keys(struct btrfs_key *k1, struct btrfs_key *k2); int btrfs_comp_cpu_keys(const struct btrfs_key *k1, const struct btrfs_key *k2);
int btrfs_previous_item(struct btrfs_root *root, int btrfs_previous_item(struct btrfs_root *root,
struct btrfs_path *path, u64 min_objectid, struct btrfs_path *path, u64 min_objectid,
int type); int type);
...@@ -2760,7 +2765,7 @@ int btrfs_previous_extent_item(struct btrfs_root *root, ...@@ -2760,7 +2765,7 @@ int btrfs_previous_extent_item(struct btrfs_root *root,
struct btrfs_path *path, u64 min_objectid); struct btrfs_path *path, u64 min_objectid);
void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info, void btrfs_set_item_key_safe(struct btrfs_fs_info *fs_info,
struct btrfs_path *path, struct btrfs_path *path,
struct btrfs_key *new_key); const struct btrfs_key *new_key);
struct extent_buffer *btrfs_root_node(struct btrfs_root *root); struct extent_buffer *btrfs_root_node(struct btrfs_root *root);
struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root); struct extent_buffer *btrfs_lock_root_node(struct btrfs_root *root);
int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path, int btrfs_find_next_key(struct btrfs_root *root, struct btrfs_path *path,
...@@ -2802,22 +2807,23 @@ void btrfs_truncate_item(struct btrfs_fs_info *fs_info, ...@@ -2802,22 +2807,23 @@ void btrfs_truncate_item(struct btrfs_fs_info *fs_info,
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,
struct btrfs_key *new_key, const struct btrfs_key *new_key,
unsigned long split_offset); unsigned long split_offset);
int btrfs_duplicate_item(struct btrfs_trans_handle *trans, int btrfs_duplicate_item(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_root *root,
struct btrfs_path *path, struct btrfs_path *path,
struct btrfs_key *new_key); const struct btrfs_key *new_key);
int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path, int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *path,
u64 inum, u64 ioff, u8 key_type, struct btrfs_key *found_key); u64 inum, u64 ioff, u8 key_type, struct btrfs_key *found_key);
int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root int btrfs_search_slot(struct btrfs_trans_handle *trans, struct btrfs_root *root,
*root, struct btrfs_key *key, struct btrfs_path *p, int const struct btrfs_key *key, struct btrfs_path *p,
ins_len, int cow); int ins_len, int cow);
int btrfs_search_old_slot(struct btrfs_root *root, struct btrfs_key *key, int btrfs_search_old_slot(struct btrfs_root *root, const struct btrfs_key *key,
struct btrfs_path *p, u64 time_seq); struct btrfs_path *p, u64 time_seq);
int btrfs_search_slot_for_read(struct btrfs_root *root, int btrfs_search_slot_for_read(struct btrfs_root *root,
struct btrfs_key *key, struct btrfs_path *p, const struct btrfs_key *key,
int find_higher, int return_any); struct btrfs_path *p, int find_higher,
int return_any);
int btrfs_realloc_node(struct btrfs_trans_handle *trans, int btrfs_realloc_node(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct extent_buffer *parent, struct btrfs_root *root, struct extent_buffer *parent,
int start_slot, u64 *last_ret, int start_slot, u64 *last_ret,
...@@ -2840,19 +2846,20 @@ static inline int btrfs_del_item(struct btrfs_trans_handle *trans, ...@@ -2840,19 +2846,20 @@ static inline int btrfs_del_item(struct btrfs_trans_handle *trans,
} }
void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path, void setup_items_for_insert(struct btrfs_root *root, struct btrfs_path *path,
struct btrfs_key *cpu_key, u32 *data_size, const struct btrfs_key *cpu_key, u32 *data_size,
u32 total_data, u32 total_size, int nr); u32 total_data, u32 total_size, int nr);
int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root int btrfs_insert_item(struct btrfs_trans_handle *trans, struct btrfs_root *root,
*root, struct btrfs_key *key, void *data, u32 data_size); const struct btrfs_key *key, void *data, u32 data_size);
int btrfs_insert_empty_items(struct btrfs_trans_handle *trans, int btrfs_insert_empty_items(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_root *root,
struct btrfs_path *path, struct btrfs_path *path,
struct btrfs_key *cpu_key, u32 *data_size, int nr); const struct btrfs_key *cpu_key, u32 *data_size,
int nr);
static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans, static inline int btrfs_insert_empty_item(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_root *root,
struct btrfs_path *path, struct btrfs_path *path,
struct btrfs_key *key, const struct btrfs_key *key,
u32 data_size) u32 data_size)
{ {
return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1); return btrfs_insert_empty_items(trans, root, path, key, &data_size, 1);
...@@ -2941,15 +2948,15 @@ int btrfs_del_root_ref(struct btrfs_trans_handle *trans, ...@@ -2941,15 +2948,15 @@ int btrfs_del_root_ref(struct btrfs_trans_handle *trans,
u64 root_id, u64 ref_id, u64 dirid, u64 *sequence, u64 root_id, u64 ref_id, u64 dirid, u64 *sequence,
const char *name, int name_len); const char *name, int name_len);
int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root, int btrfs_del_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
struct btrfs_key *key); const struct btrfs_key *key);
int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root int btrfs_insert_root(struct btrfs_trans_handle *trans, struct btrfs_root *root,
*root, struct btrfs_key *key, struct btrfs_root_item const struct btrfs_key *key,
*item); struct btrfs_root_item *item);
int __must_check btrfs_update_root(struct btrfs_trans_handle *trans, int __must_check btrfs_update_root(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_root *root,
struct btrfs_key *key, struct btrfs_key *key,
struct btrfs_root_item *item); struct btrfs_root_item *item);
int btrfs_find_root(struct btrfs_root *root, struct btrfs_key *search_key, int btrfs_find_root(struct btrfs_root *root, const struct btrfs_key *search_key,
struct btrfs_path *path, struct btrfs_root_item *root_item, struct btrfs_path *path, struct btrfs_root_item *root_item,
struct btrfs_key *root_key); struct btrfs_key *root_key);
int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info); int btrfs_find_orphan_roots(struct btrfs_fs_info *fs_info);
...@@ -3119,7 +3126,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry); ...@@ -3119,7 +3126,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry);
int btrfs_set_inode_index(struct inode *dir, u64 *index); int btrfs_set_inode_index(struct inode *dir, u64 *index);
int btrfs_unlink_inode(struct btrfs_trans_handle *trans, int btrfs_unlink_inode(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_root *root,
struct inode *dir, struct inode *inode, struct btrfs_inode *dir, struct btrfs_inode *inode,
const char *name, int name_len); const char *name, int name_len);
int btrfs_add_link(struct btrfs_trans_handle *trans, int btrfs_add_link(struct btrfs_trans_handle *trans,
struct inode *parent_inode, struct inode *inode, struct inode *parent_inode, struct inode *inode,
...@@ -3447,7 +3454,8 @@ do { \ ...@@ -3447,7 +3454,8 @@ do { \
"BTRFS: Transaction aborted (error %d)\n", \ "BTRFS: Transaction aborted (error %d)\n", \
(errno)); \ (errno)); \
} else { \ } else { \
pr_debug("BTRFS: Transaction aborted (error %d)\n", \ btrfs_debug((trans)->fs_info, \
"Transaction aborted (error %d)", \
(errno)); \ (errno)); \
} \ } \
} \ } \
......
...@@ -72,14 +72,14 @@ static inline int btrfs_is_continuous_delayed_item( ...@@ -72,14 +72,14 @@ static inline int btrfs_is_continuous_delayed_item(
return 0; return 0;
} }
static struct btrfs_delayed_node *btrfs_get_delayed_node(struct inode *inode) static struct btrfs_delayed_node *btrfs_get_delayed_node(
struct btrfs_inode *btrfs_inode)
{ {
struct btrfs_inode *btrfs_inode = BTRFS_I(inode);
struct btrfs_root *root = btrfs_inode->root; struct btrfs_root *root = btrfs_inode->root;
u64 ino = btrfs_ino(inode); u64 ino = btrfs_ino(btrfs_inode);
struct btrfs_delayed_node *node; struct btrfs_delayed_node *node;
node = ACCESS_ONCE(btrfs_inode->delayed_node); node = READ_ONCE(btrfs_inode->delayed_node);
if (node) { if (node) {
atomic_inc(&node->refs); atomic_inc(&node->refs);
return node; return node;
...@@ -107,16 +107,15 @@ static struct btrfs_delayed_node *btrfs_get_delayed_node(struct inode *inode) ...@@ -107,16 +107,15 @@ static struct btrfs_delayed_node *btrfs_get_delayed_node(struct inode *inode)
/* Will return either the node or PTR_ERR(-ENOMEM) */ /* Will return either the node or PTR_ERR(-ENOMEM) */
static struct btrfs_delayed_node *btrfs_get_or_create_delayed_node( static struct btrfs_delayed_node *btrfs_get_or_create_delayed_node(
struct inode *inode) struct btrfs_inode *btrfs_inode)
{ {
struct btrfs_delayed_node *node; struct btrfs_delayed_node *node;
struct btrfs_inode *btrfs_inode = BTRFS_I(inode);
struct btrfs_root *root = btrfs_inode->root; struct btrfs_root *root = btrfs_inode->root;
u64 ino = btrfs_ino(inode); u64 ino = btrfs_ino(btrfs_inode);
int ret; int ret;
again: again:
node = btrfs_get_delayed_node(inode); node = btrfs_get_delayed_node(btrfs_inode);
if (node) if (node)
return node; return node;
...@@ -574,7 +573,7 @@ static void btrfs_delayed_item_release_metadata(struct btrfs_fs_info *fs_info, ...@@ -574,7 +573,7 @@ static void btrfs_delayed_item_release_metadata(struct btrfs_fs_info *fs_info,
static int btrfs_delayed_inode_reserve_metadata( static int btrfs_delayed_inode_reserve_metadata(
struct btrfs_trans_handle *trans, struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_root *root,
struct inode *inode, struct btrfs_inode *inode,
struct btrfs_delayed_node *node) struct btrfs_delayed_node *node)
{ {
struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_fs_info *fs_info = root->fs_info;
...@@ -603,13 +602,13 @@ static int btrfs_delayed_inode_reserve_metadata( ...@@ -603,13 +602,13 @@ static int btrfs_delayed_inode_reserve_metadata(
* worth which is less likely to hurt us. * worth which is less likely to hurt us.
*/ */
if (src_rsv && src_rsv->type == BTRFS_BLOCK_RSV_DELALLOC) { if (src_rsv && src_rsv->type == BTRFS_BLOCK_RSV_DELALLOC) {
spin_lock(&BTRFS_I(inode)->lock); spin_lock(&inode->lock);
if (test_and_clear_bit(BTRFS_INODE_DELALLOC_META_RESERVED, if (test_and_clear_bit(BTRFS_INODE_DELALLOC_META_RESERVED,
&BTRFS_I(inode)->runtime_flags)) &inode->runtime_flags))
release = true; release = true;
else else
src_rsv = NULL; src_rsv = NULL;
spin_unlock(&BTRFS_I(inode)->lock); spin_unlock(&inode->lock);
} }
/* /*
...@@ -1196,7 +1195,7 @@ int btrfs_run_delayed_items_nr(struct btrfs_trans_handle *trans, ...@@ -1196,7 +1195,7 @@ int btrfs_run_delayed_items_nr(struct btrfs_trans_handle *trans,
} }
int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans, int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans,
struct inode *inode) struct btrfs_inode *inode)
{ {
struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode); struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode);
struct btrfs_path *path; struct btrfs_path *path;
...@@ -1233,9 +1232,9 @@ int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans, ...@@ -1233,9 +1232,9 @@ int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans,
return ret; return ret;
} }
int btrfs_commit_inode_delayed_inode(struct inode *inode) int btrfs_commit_inode_delayed_inode(struct btrfs_inode *inode)
{ {
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_fs_info *fs_info = btrfs_sb(inode->vfs_inode.i_sb);
struct btrfs_trans_handle *trans; struct btrfs_trans_handle *trans;
struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode); struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode);
struct btrfs_path *path; struct btrfs_path *path;
...@@ -1288,15 +1287,15 @@ int btrfs_commit_inode_delayed_inode(struct inode *inode) ...@@ -1288,15 +1287,15 @@ int btrfs_commit_inode_delayed_inode(struct inode *inode)
return ret; return ret;
} }
void btrfs_remove_delayed_node(struct inode *inode) void btrfs_remove_delayed_node(struct btrfs_inode *inode)
{ {
struct btrfs_delayed_node *delayed_node; struct btrfs_delayed_node *delayed_node;
delayed_node = ACCESS_ONCE(BTRFS_I(inode)->delayed_node); delayed_node = READ_ONCE(inode->delayed_node);
if (!delayed_node) if (!delayed_node)
return; return;
BTRFS_I(inode)->delayed_node = NULL; inode->delayed_node = NULL;
btrfs_release_delayed_node(delayed_node); btrfs_release_delayed_node(delayed_node);
} }
...@@ -1434,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_fs_info *fs_info) ...@@ -1434,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_fs_info *fs_info)
int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans, int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info, struct btrfs_fs_info *fs_info,
const char *name, int name_len, const char *name, int name_len,
struct inode *dir, struct btrfs_inode *dir,
struct btrfs_disk_key *disk_key, u8 type, struct btrfs_disk_key *disk_key, u8 type,
u64 index) u64 index)
{ {
...@@ -1510,7 +1509,7 @@ static int btrfs_delete_delayed_insertion_item(struct btrfs_fs_info *fs_info, ...@@ -1510,7 +1509,7 @@ static int btrfs_delete_delayed_insertion_item(struct btrfs_fs_info *fs_info,
int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans, int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info, struct btrfs_fs_info *fs_info,
struct inode *dir, u64 index) struct btrfs_inode *dir, u64 index)
{ {
struct btrfs_delayed_node *node; struct btrfs_delayed_node *node;
struct btrfs_delayed_item *item; struct btrfs_delayed_item *item;
...@@ -1558,7 +1557,7 @@ int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans, ...@@ -1558,7 +1557,7 @@ int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans,
return ret; return ret;
} }
int btrfs_inode_delayed_dir_index_count(struct inode *inode) int btrfs_inode_delayed_dir_index_count(struct btrfs_inode *inode)
{ {
struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode); struct btrfs_delayed_node *delayed_node = btrfs_get_delayed_node(inode);
...@@ -1575,7 +1574,7 @@ int btrfs_inode_delayed_dir_index_count(struct inode *inode) ...@@ -1575,7 +1574,7 @@ int btrfs_inode_delayed_dir_index_count(struct inode *inode)
return -EINVAL; return -EINVAL;
} }
BTRFS_I(inode)->index_cnt = delayed_node->index_cnt; inode->index_cnt = delayed_node->index_cnt;
btrfs_release_delayed_node(delayed_node); btrfs_release_delayed_node(delayed_node);
return 0; return 0;
} }
...@@ -1587,7 +1586,7 @@ bool btrfs_readdir_get_delayed_items(struct inode *inode, ...@@ -1587,7 +1586,7 @@ bool btrfs_readdir_get_delayed_items(struct inode *inode,
struct btrfs_delayed_node *delayed_node; struct btrfs_delayed_node *delayed_node;
struct btrfs_delayed_item *item; struct btrfs_delayed_item *item;
delayed_node = btrfs_get_delayed_node(inode); delayed_node = btrfs_get_delayed_node(BTRFS_I(inode));
if (!delayed_node) if (!delayed_node)
return false; return false;
...@@ -1776,7 +1775,7 @@ int btrfs_fill_inode(struct inode *inode, u32 *rdev) ...@@ -1776,7 +1775,7 @@ int btrfs_fill_inode(struct inode *inode, u32 *rdev)
struct btrfs_delayed_node *delayed_node; struct btrfs_delayed_node *delayed_node;
struct btrfs_inode_item *inode_item; struct btrfs_inode_item *inode_item;
delayed_node = btrfs_get_delayed_node(inode); delayed_node = btrfs_get_delayed_node(BTRFS_I(inode));
if (!delayed_node) if (!delayed_node)
return -ENOENT; return -ENOENT;
...@@ -1831,7 +1830,7 @@ int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans, ...@@ -1831,7 +1830,7 @@ int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans,
struct btrfs_delayed_node *delayed_node; struct btrfs_delayed_node *delayed_node;
int ret = 0; int ret = 0;
delayed_node = btrfs_get_or_create_delayed_node(inode); delayed_node = btrfs_get_or_create_delayed_node(BTRFS_I(inode));
if (IS_ERR(delayed_node)) if (IS_ERR(delayed_node))
return PTR_ERR(delayed_node); return PTR_ERR(delayed_node);
...@@ -1841,7 +1840,7 @@ int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans, ...@@ -1841,7 +1840,7 @@ int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans,
goto release_node; goto release_node;
} }
ret = btrfs_delayed_inode_reserve_metadata(trans, root, inode, ret = btrfs_delayed_inode_reserve_metadata(trans, root, BTRFS_I(inode),
delayed_node); delayed_node);
if (ret) if (ret)
goto release_node; goto release_node;
...@@ -1856,9 +1855,9 @@ int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans, ...@@ -1856,9 +1855,9 @@ int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans,
return ret; return ret;
} }
int btrfs_delayed_delete_inode_ref(struct inode *inode) int btrfs_delayed_delete_inode_ref(struct btrfs_inode *inode)
{ {
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_fs_info *fs_info = btrfs_sb(inode->vfs_inode.i_sb);
struct btrfs_delayed_node *delayed_node; struct btrfs_delayed_node *delayed_node;
/* /*
...@@ -1933,7 +1932,7 @@ static void __btrfs_kill_delayed_node(struct btrfs_delayed_node *delayed_node) ...@@ -1933,7 +1932,7 @@ static void __btrfs_kill_delayed_node(struct btrfs_delayed_node *delayed_node)
mutex_unlock(&delayed_node->mutex); mutex_unlock(&delayed_node->mutex);
} }
void btrfs_kill_delayed_inode_items(struct inode *inode) void btrfs_kill_delayed_inode_items(struct btrfs_inode *inode)
{ {
struct btrfs_delayed_node *delayed_node; struct btrfs_delayed_node *delayed_node;
......
...@@ -101,15 +101,15 @@ static inline void btrfs_init_delayed_root( ...@@ -101,15 +101,15 @@ static inline void btrfs_init_delayed_root(
int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans, int btrfs_insert_delayed_dir_index(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info, struct btrfs_fs_info *fs_info,
const char *name, int name_len, const char *name, int name_len,
struct inode *dir, struct btrfs_inode *dir,
struct btrfs_disk_key *disk_key, u8 type, struct btrfs_disk_key *disk_key, u8 type,
u64 index); u64 index);
int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans, int btrfs_delete_delayed_dir_index(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info, struct btrfs_fs_info *fs_info,
struct inode *dir, u64 index); struct btrfs_inode *dir, u64 index);
int btrfs_inode_delayed_dir_index_count(struct inode *inode); int btrfs_inode_delayed_dir_index_count(struct btrfs_inode *inode);
int btrfs_run_delayed_items(struct btrfs_trans_handle *trans, int btrfs_run_delayed_items(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info); struct btrfs_fs_info *fs_info);
...@@ -119,17 +119,17 @@ int btrfs_run_delayed_items_nr(struct btrfs_trans_handle *trans, ...@@ -119,17 +119,17 @@ int btrfs_run_delayed_items_nr(struct btrfs_trans_handle *trans,
void btrfs_balance_delayed_items(struct btrfs_fs_info *fs_info); void btrfs_balance_delayed_items(struct btrfs_fs_info *fs_info);
int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans, int btrfs_commit_inode_delayed_items(struct btrfs_trans_handle *trans,
struct inode *inode); struct btrfs_inode *inode);
/* Used for evicting the inode. */ /* Used for evicting the inode. */
void btrfs_remove_delayed_node(struct inode *inode); void btrfs_remove_delayed_node(struct btrfs_inode *inode);
void btrfs_kill_delayed_inode_items(struct inode *inode); void btrfs_kill_delayed_inode_items(struct btrfs_inode *inode);
int btrfs_commit_inode_delayed_inode(struct inode *inode); int btrfs_commit_inode_delayed_inode(struct btrfs_inode *inode);
int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans, int btrfs_delayed_update_inode(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct inode *inode); struct btrfs_root *root, struct inode *inode);
int btrfs_fill_inode(struct inode *inode, u32 *rdev); int btrfs_fill_inode(struct inode *inode, u32 *rdev);
int btrfs_delayed_delete_inode_ref(struct inode *inode); int btrfs_delayed_delete_inode_ref(struct btrfs_inode *inode);
/* Used for drop dead root */ /* Used for drop dead root */
void btrfs_kill_all_delayed_nodes(struct btrfs_root *root); void btrfs_kill_all_delayed_nodes(struct btrfs_root *root);
......
...@@ -550,13 +550,14 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info, ...@@ -550,13 +550,14 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info,
struct btrfs_delayed_ref_node *ref, struct btrfs_delayed_ref_node *ref,
struct btrfs_qgroup_extent_record *qrecord, struct btrfs_qgroup_extent_record *qrecord,
u64 bytenr, u64 num_bytes, u64 ref_root, u64 reserved, u64 bytenr, u64 num_bytes, u64 ref_root, u64 reserved,
int action, int is_data) int action, int is_data, int *qrecord_inserted_ret)
{ {
struct btrfs_delayed_ref_head *existing; struct btrfs_delayed_ref_head *existing;
struct btrfs_delayed_ref_head *head_ref = NULL; struct btrfs_delayed_ref_head *head_ref = NULL;
struct btrfs_delayed_ref_root *delayed_refs; struct btrfs_delayed_ref_root *delayed_refs;
int count_mod = 1; int count_mod = 1;
int must_insert_reserved = 0; int must_insert_reserved = 0;
int qrecord_inserted = 0;
/* If reserved is provided, it must be a data extent. */ /* If reserved is provided, it must be a data extent. */
BUG_ON(!is_data && reserved); BUG_ON(!is_data && reserved);
...@@ -623,6 +624,8 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info, ...@@ -623,6 +624,8 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info,
if(btrfs_qgroup_trace_extent_nolock(fs_info, if(btrfs_qgroup_trace_extent_nolock(fs_info,
delayed_refs, qrecord)) delayed_refs, qrecord))
kfree(qrecord); kfree(qrecord);
else
qrecord_inserted = 1;
} }
spin_lock_init(&head_ref->lock); spin_lock_init(&head_ref->lock);
...@@ -650,6 +653,8 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info, ...@@ -650,6 +653,8 @@ add_delayed_ref_head(struct btrfs_fs_info *fs_info,
atomic_inc(&delayed_refs->num_entries); atomic_inc(&delayed_refs->num_entries);
trans->delayed_ref_updates++; trans->delayed_ref_updates++;
} }
if (qrecord_inserted_ret)
*qrecord_inserted_ret = qrecord_inserted;
return head_ref; return head_ref;
} }
...@@ -779,6 +784,7 @@ int btrfs_add_delayed_tree_ref(struct btrfs_fs_info *fs_info, ...@@ -779,6 +784,7 @@ int btrfs_add_delayed_tree_ref(struct btrfs_fs_info *fs_info,
struct btrfs_delayed_ref_head *head_ref; struct btrfs_delayed_ref_head *head_ref;
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;
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);
...@@ -806,12 +812,15 @@ int btrfs_add_delayed_tree_ref(struct btrfs_fs_info *fs_info, ...@@ -806,12 +812,15 @@ int btrfs_add_delayed_tree_ref(struct btrfs_fs_info *fs_info,
* the spin lock * the spin lock
*/ */
head_ref = add_delayed_ref_head(fs_info, trans, &head_ref->node, record, head_ref = add_delayed_ref_head(fs_info, trans, &head_ref->node, record,
bytenr, num_bytes, 0, 0, action, 0); bytenr, num_bytes, 0, 0, action, 0,
&qrecord_inserted);
add_delayed_tree_ref(fs_info, trans, head_ref, &ref->node, bytenr, add_delayed_tree_ref(fs_info, trans, head_ref, &ref->node, bytenr,
num_bytes, parent, ref_root, level, action); num_bytes, parent, ref_root, level, action);
spin_unlock(&delayed_refs->lock); spin_unlock(&delayed_refs->lock);
if (qrecord_inserted)
return btrfs_qgroup_trace_extent_post(fs_info, record);
return 0; return 0;
free_head_ref: free_head_ref:
...@@ -829,15 +838,14 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info, ...@@ -829,15 +838,14 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info,
struct btrfs_trans_handle *trans, struct btrfs_trans_handle *trans,
u64 bytenr, u64 num_bytes, u64 bytenr, u64 num_bytes,
u64 parent, u64 ref_root, u64 parent, u64 ref_root,
u64 owner, u64 offset, u64 reserved, int action, u64 owner, u64 offset, u64 reserved, int action)
struct btrfs_delayed_extent_op *extent_op)
{ {
struct btrfs_delayed_data_ref *ref; struct btrfs_delayed_data_ref *ref;
struct btrfs_delayed_ref_head *head_ref; struct btrfs_delayed_ref_head *head_ref;
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;
BUG_ON(extent_op && !extent_op->is_data);
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 +867,7 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info, ...@@ -859,7 +867,7 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info,
} }
} }
head_ref->extent_op = extent_op; head_ref->extent_op = NULL;
delayed_refs = &trans->transaction->delayed_refs; delayed_refs = &trans->transaction->delayed_refs;
spin_lock(&delayed_refs->lock); spin_lock(&delayed_refs->lock);
...@@ -870,13 +878,15 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info, ...@@ -870,13 +878,15 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info,
*/ */
head_ref = add_delayed_ref_head(fs_info, trans, &head_ref->node, record, head_ref = add_delayed_ref_head(fs_info, trans, &head_ref->node, record,
bytenr, num_bytes, ref_root, reserved, bytenr, num_bytes, ref_root, reserved,
action, 1); action, 1, &qrecord_inserted);
add_delayed_data_ref(fs_info, trans, head_ref, &ref->node, bytenr, add_delayed_data_ref(fs_info, trans, head_ref, &ref->node, bytenr,
num_bytes, parent, ref_root, owner, offset, num_bytes, parent, ref_root, owner, offset,
action); action);
spin_unlock(&delayed_refs->lock); spin_unlock(&delayed_refs->lock);
if (qrecord_inserted)
return btrfs_qgroup_trace_extent_post(fs_info, record);
return 0; return 0;
} }
...@@ -899,7 +909,7 @@ int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info, ...@@ -899,7 +909,7 @@ int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info,
add_delayed_ref_head(fs_info, trans, &head_ref->node, NULL, bytenr, add_delayed_ref_head(fs_info, trans, &head_ref->node, NULL, bytenr,
num_bytes, 0, 0, BTRFS_UPDATE_DELAYED_HEAD, num_bytes, 0, 0, BTRFS_UPDATE_DELAYED_HEAD,
extent_op->is_data); extent_op->is_data, NULL);
spin_unlock(&delayed_refs->lock); spin_unlock(&delayed_refs->lock);
return 0; return 0;
...@@ -911,11 +921,8 @@ int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info, ...@@ -911,11 +921,8 @@ int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info,
* the head node if any where found, or NULL if not. * the head node if any where found, or NULL if not.
*/ */
struct btrfs_delayed_ref_head * struct btrfs_delayed_ref_head *
btrfs_find_delayed_ref_head(struct btrfs_trans_handle *trans, u64 bytenr) btrfs_find_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_refs, u64 bytenr)
{ {
struct btrfs_delayed_ref_root *delayed_refs;
delayed_refs = &trans->transaction->delayed_refs;
return find_ref_head(&delayed_refs->href_root, bytenr, 0); return find_ref_head(&delayed_refs->href_root, bytenr, 0);
} }
......
...@@ -250,8 +250,7 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info, ...@@ -250,8 +250,7 @@ int btrfs_add_delayed_data_ref(struct btrfs_fs_info *fs_info,
struct btrfs_trans_handle *trans, struct btrfs_trans_handle *trans,
u64 bytenr, u64 num_bytes, u64 bytenr, u64 num_bytes,
u64 parent, u64 ref_root, u64 parent, u64 ref_root,
u64 owner, u64 offset, u64 reserved, int action, u64 owner, u64 offset, u64 reserved, int action);
struct btrfs_delayed_extent_op *extent_op);
int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info, int btrfs_add_delayed_extent_op(struct btrfs_fs_info *fs_info,
struct btrfs_trans_handle *trans, struct btrfs_trans_handle *trans,
u64 bytenr, u64 num_bytes, u64 bytenr, u64 num_bytes,
...@@ -262,7 +261,8 @@ void btrfs_merge_delayed_refs(struct btrfs_trans_handle *trans, ...@@ -262,7 +261,8 @@ void btrfs_merge_delayed_refs(struct btrfs_trans_handle *trans,
struct btrfs_delayed_ref_head *head); struct btrfs_delayed_ref_head *head);
struct btrfs_delayed_ref_head * struct btrfs_delayed_ref_head *
btrfs_find_delayed_ref_head(struct btrfs_trans_handle *trans, u64 bytenr); btrfs_find_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_refs,
u64 bytenr);
int btrfs_delayed_ref_lock(struct btrfs_trans_handle *trans, int btrfs_delayed_ref_lock(struct btrfs_trans_handle *trans,
struct btrfs_delayed_ref_head *head); struct btrfs_delayed_ref_head *head);
static inline void btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head *head) static inline void btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head *head)
......
...@@ -133,7 +133,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -133,7 +133,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
struct btrfs_disk_key disk_key; struct btrfs_disk_key disk_key;
u32 data_size; u32 data_size;
key.objectid = btrfs_ino(dir); key.objectid = btrfs_ino(BTRFS_I(dir));
key.type = BTRFS_DIR_ITEM_KEY; key.type = BTRFS_DIR_ITEM_KEY;
key.offset = btrfs_name_hash(name, name_len); key.offset = btrfs_name_hash(name, name_len);
...@@ -174,8 +174,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -174,8 +174,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
btrfs_release_path(path); btrfs_release_path(path);
ret2 = btrfs_insert_delayed_dir_index(trans, root->fs_info, name, ret2 = btrfs_insert_delayed_dir_index(trans, root->fs_info, name,
name_len, dir, &disk_key, type, name_len, BTRFS_I(dir), &disk_key, type, index);
index);
out_free: out_free:
btrfs_free_path(path); btrfs_free_path(path);
if (ret) if (ret)
......
...@@ -64,8 +64,7 @@ ...@@ -64,8 +64,7 @@
static const struct extent_io_ops btree_extent_io_ops; static const struct extent_io_ops btree_extent_io_ops;
static void end_workqueue_fn(struct btrfs_work *work); static void end_workqueue_fn(struct btrfs_work *work);
static void free_fs_root(struct btrfs_root *root); static void free_fs_root(struct btrfs_root *root);
static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info, static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info);
int read_only);
static void btrfs_destroy_ordered_extents(struct btrfs_root *root); static void btrfs_destroy_ordered_extents(struct btrfs_root *root);
static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans, static int btrfs_destroy_delayed_refs(struct btrfs_transaction *trans,
struct btrfs_fs_info *fs_info); struct btrfs_fs_info *fs_info);
...@@ -1005,7 +1004,7 @@ static int __btree_submit_bio_done(struct inode *inode, struct bio *bio, ...@@ -1005,7 +1004,7 @@ static int __btree_submit_bio_done(struct inode *inode, struct bio *bio,
return ret; return ret;
} }
static int check_async_write(struct inode *inode, unsigned long bio_flags) static int check_async_write(unsigned long bio_flags)
{ {
if (bio_flags & EXTENT_BIO_TREE_LOG) if (bio_flags & EXTENT_BIO_TREE_LOG)
return 0; return 0;
...@@ -1021,7 +1020,7 @@ static int btree_submit_bio_hook(struct inode *inode, struct bio *bio, ...@@ -1021,7 +1020,7 @@ static int btree_submit_bio_hook(struct inode *inode, struct bio *bio,
u64 bio_offset) u64 bio_offset)
{ {
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb);
int async = check_async_write(inode, bio_flags); int async = check_async_write(bio_flags);
int ret; int ret;
if (bio_op(bio) != REQ_OP_WRITE) { if (bio_op(bio) != REQ_OP_WRITE) {
...@@ -1248,8 +1247,7 @@ struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr, ...@@ -1248,8 +1247,7 @@ struct extent_buffer *read_tree_block(struct btrfs_fs_info *fs_info, u64 bytenr,
} }
void clean_tree_block(struct btrfs_trans_handle *trans, void clean_tree_block(struct btrfs_fs_info *fs_info,
struct btrfs_fs_info *fs_info,
struct extent_buffer *buf) struct extent_buffer *buf)
{ {
if (btrfs_header_generation(buf) == if (btrfs_header_generation(buf) ==
...@@ -2802,7 +2800,7 @@ int open_ctree(struct super_block *sb, ...@@ -2802,7 +2800,7 @@ int open_ctree(struct super_block *sb,
memcpy(fs_info->fsid, fs_info->super_copy->fsid, BTRFS_FSID_SIZE); memcpy(fs_info->fsid, fs_info->super_copy->fsid, BTRFS_FSID_SIZE);
ret = btrfs_check_super_valid(fs_info, sb->s_flags & MS_RDONLY); ret = btrfs_check_super_valid(fs_info);
if (ret) { if (ret) {
btrfs_err(fs_info, "superblock contains fatal errors"); btrfs_err(fs_info, "superblock contains fatal errors");
err = -EINVAL; err = -EINVAL;
...@@ -3411,7 +3409,7 @@ struct buffer_head *btrfs_read_dev_super(struct block_device *bdev) ...@@ -3411,7 +3409,7 @@ struct buffer_head *btrfs_read_dev_super(struct block_device *bdev)
*/ */
static int write_dev_supers(struct btrfs_device *device, static int write_dev_supers(struct btrfs_device *device,
struct btrfs_super_block *sb, struct btrfs_super_block *sb,
int do_barriers, int wait, int max_mirrors) int wait, int max_mirrors)
{ {
struct buffer_head *bh; struct buffer_head *bh;
int i; int i;
...@@ -3696,7 +3694,7 @@ int btrfs_calc_num_tolerated_disk_barrier_failures( ...@@ -3696,7 +3694,7 @@ int btrfs_calc_num_tolerated_disk_barrier_failures(
return num_tolerated_disk_barrier_failures; return num_tolerated_disk_barrier_failures;
} }
static int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors) int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors)
{ {
struct list_head *head; struct list_head *head;
struct btrfs_device *dev; struct btrfs_device *dev;
...@@ -3753,7 +3751,7 @@ static int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors) ...@@ -3753,7 +3751,7 @@ static int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors)
flags = btrfs_super_flags(sb); flags = btrfs_super_flags(sb);
btrfs_set_super_flags(sb, flags | BTRFS_HEADER_FLAG_WRITTEN); btrfs_set_super_flags(sb, flags | BTRFS_HEADER_FLAG_WRITTEN);
ret = write_dev_supers(dev, sb, do_barriers, 0, max_mirrors); ret = write_dev_supers(dev, sb, 0, max_mirrors);
if (ret) if (ret)
total_errors++; total_errors++;
} }
...@@ -3776,7 +3774,7 @@ static int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors) ...@@ -3776,7 +3774,7 @@ static int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors)
if (!dev->in_fs_metadata || !dev->writeable) if (!dev->in_fs_metadata || !dev->writeable)
continue; continue;
ret = write_dev_supers(dev, sb, do_barriers, 1, max_mirrors); ret = write_dev_supers(dev, sb, 1, max_mirrors);
if (ret) if (ret)
total_errors++; total_errors++;
} }
...@@ -3790,12 +3788,6 @@ static int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors) ...@@ -3790,12 +3788,6 @@ static int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors)
return 0; return 0;
} }
int write_ctree_super(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info, int max_mirrors)
{
return write_all_supers(fs_info, max_mirrors);
}
/* Drop a fs root from the radix tree and free it. */ /* Drop a fs root from the radix tree and free it. */
void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info, void btrfs_drop_and_free_fs_root(struct btrfs_fs_info *fs_info,
struct btrfs_root *root) struct btrfs_root *root)
...@@ -4122,8 +4114,7 @@ int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid) ...@@ -4122,8 +4114,7 @@ int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid)
return btree_read_extent_buffer_pages(fs_info, buf, parent_transid); return btree_read_extent_buffer_pages(fs_info, buf, parent_transid);
} }
static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info, static int btrfs_check_super_valid(struct btrfs_fs_info *fs_info)
int read_only)
{ {
struct btrfs_super_block *sb = fs_info->super_copy; struct btrfs_super_block *sb = fs_info->super_copy;
u64 nodesize = btrfs_super_nodesize(sb); u64 nodesize = btrfs_super_nodesize(sb);
......
...@@ -52,14 +52,12 @@ int reada_tree_block_flagged(struct btrfs_fs_info *fs_info, u64 bytenr, ...@@ -52,14 +52,12 @@ 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_trans_handle *trans, void clean_tree_block(struct btrfs_fs_info *fs_info, struct extent_buffer *buf);
struct btrfs_fs_info *fs_info, 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);
void close_ctree(struct btrfs_fs_info *fs_info); void close_ctree(struct btrfs_fs_info *fs_info);
int write_ctree_super(struct btrfs_trans_handle *trans, int write_all_supers(struct btrfs_fs_info *fs_info, int max_mirrors);
struct btrfs_fs_info *fs_info, int max_mirrors);
struct buffer_head *btrfs_read_dev_super(struct block_device *bdev); struct buffer_head *btrfs_read_dev_super(struct block_device *bdev);
int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num, int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num,
struct buffer_head **bh_ret); struct buffer_head **bh_ret);
......
...@@ -30,7 +30,7 @@ static int btrfs_encode_fh(struct inode *inode, u32 *fh, int *max_len, ...@@ -30,7 +30,7 @@ static int btrfs_encode_fh(struct inode *inode, u32 *fh, int *max_len,
len = BTRFS_FID_SIZE_NON_CONNECTABLE; len = BTRFS_FID_SIZE_NON_CONNECTABLE;
type = FILEID_BTRFS_WITHOUT_PARENT; type = FILEID_BTRFS_WITHOUT_PARENT;
fid->objectid = btrfs_ino(inode); fid->objectid = btrfs_ino(BTRFS_I(inode));
fid->root_objectid = BTRFS_I(inode)->root->objectid; fid->root_objectid = BTRFS_I(inode)->root->objectid;
fid->gen = inode->i_generation; fid->gen = inode->i_generation;
...@@ -166,13 +166,13 @@ static struct dentry *btrfs_get_parent(struct dentry *child) ...@@ -166,13 +166,13 @@ static struct dentry *btrfs_get_parent(struct dentry *child)
if (!path) if (!path)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
if (btrfs_ino(dir) == BTRFS_FIRST_FREE_OBJECTID) { if (btrfs_ino(BTRFS_I(dir)) == BTRFS_FIRST_FREE_OBJECTID) {
key.objectid = root->root_key.objectid; key.objectid = root->root_key.objectid;
key.type = BTRFS_ROOT_BACKREF_KEY; key.type = BTRFS_ROOT_BACKREF_KEY;
key.offset = (u64)-1; key.offset = (u64)-1;
root = fs_info->tree_root; root = fs_info->tree_root;
} else { } else {
key.objectid = btrfs_ino(dir); key.objectid = btrfs_ino(BTRFS_I(dir));
key.type = BTRFS_INODE_REF_KEY; key.type = BTRFS_INODE_REF_KEY;
key.offset = (u64)-1; key.offset = (u64)-1;
} }
...@@ -235,13 +235,10 @@ static int btrfs_get_name(struct dentry *parent, char *name, ...@@ -235,13 +235,10 @@ static int btrfs_get_name(struct dentry *parent, char *name,
int ret; int ret;
u64 ino; u64 ino;
if (!dir || !inode)
return -EINVAL;
if (!S_ISDIR(dir->i_mode)) if (!S_ISDIR(dir->i_mode))
return -EINVAL; return -EINVAL;
ino = btrfs_ino(inode); ino = btrfs_ino(BTRFS_I(inode));
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) if (!path)
...@@ -255,7 +252,7 @@ static int btrfs_get_name(struct dentry *parent, char *name, ...@@ -255,7 +252,7 @@ static int btrfs_get_name(struct dentry *parent, char *name,
root = fs_info->tree_root; root = fs_info->tree_root;
} else { } else {
key.objectid = ino; key.objectid = ino;
key.offset = btrfs_ino(dir); key.offset = btrfs_ino(BTRFS_I(dir));
key.type = BTRFS_INODE_REF_KEY; key.type = BTRFS_INODE_REF_KEY;
} }
......
This diff is collapsed.
This diff is collapsed.
...@@ -45,13 +45,14 @@ ...@@ -45,13 +45,14 @@
#define EXTENT_BUFFER_IN_TREE 10 #define EXTENT_BUFFER_IN_TREE 10
#define EXTENT_BUFFER_WRITE_ERR 11 /* write IO error */ #define EXTENT_BUFFER_WRITE_ERR 11 /* write IO error */
/* these are flags for extent_clear_unlock_delalloc */ /* these are flags for __process_pages_contig */
#define PAGE_UNLOCK (1 << 0) #define PAGE_UNLOCK (1 << 0)
#define PAGE_CLEAR_DIRTY (1 << 1) #define PAGE_CLEAR_DIRTY (1 << 1)
#define PAGE_SET_WRITEBACK (1 << 2) #define PAGE_SET_WRITEBACK (1 << 2)
#define PAGE_END_WRITEBACK (1 << 3) #define PAGE_END_WRITEBACK (1 << 3)
#define PAGE_SET_PRIVATE2 (1 << 4) #define PAGE_SET_PRIVATE2 (1 << 4)
#define PAGE_SET_ERROR (1 << 5) #define PAGE_SET_ERROR (1 << 5)
#define PAGE_LOCK (1 << 6)
/* /*
* page->private values. Every page that is controlled by the extent * page->private values. Every page that is controlled by the extent
...@@ -192,7 +193,7 @@ struct extent_changeset { ...@@ -192,7 +193,7 @@ struct extent_changeset {
u64 bytes_changed; u64 bytes_changed;
/* Changed ranges */ /* Changed ranges */
struct ulist *range_changed; struct ulist range_changed;
}; };
static inline void extent_set_compress_type(unsigned long *bio_flags, static inline void extent_set_compress_type(unsigned long *bio_flags,
......
...@@ -255,7 +255,7 @@ static int __btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio, ...@@ -255,7 +255,7 @@ static int __btrfs_lookup_bio_sums(struct inode *inode, struct bio *bio,
} else { } else {
btrfs_info_rl(fs_info, btrfs_info_rl(fs_info,
"no csum found for inode %llu start %llu", "no csum found for inode %llu start %llu",
btrfs_ino(inode), offset); btrfs_ino(BTRFS_I(inode)), offset);
} }
item = NULL; item = NULL;
btrfs_release_path(path); btrfs_release_path(path);
...@@ -856,8 +856,8 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans, ...@@ -856,8 +856,8 @@ int btrfs_csum_file_blocks(struct btrfs_trans_handle *trans,
tmp = min(tmp, (next_offset - file_key.offset) >> tmp = min(tmp, (next_offset - file_key.offset) >>
fs_info->sb->s_blocksize_bits); fs_info->sb->s_blocksize_bits);
tmp = max((u64)1, tmp); tmp = max_t(u64, 1, tmp);
tmp = min(tmp, (u64)MAX_CSUM_ITEMS(fs_info, csum_size)); tmp = min_t(u64, tmp, MAX_CSUM_ITEMS(fs_info, csum_size));
ins_size = csum_size * tmp; ins_size = csum_size * tmp;
} else { } else {
ins_size = csum_size; ins_size = csum_size;
...@@ -977,7 +977,7 @@ void btrfs_extent_item_to_extent_map(struct inode *inode, ...@@ -977,7 +977,7 @@ void btrfs_extent_item_to_extent_map(struct inode *inode,
} else { } else {
btrfs_err(fs_info, btrfs_err(fs_info,
"unknown file extent item type %d, inode %llu, offset %llu, root %llu", "unknown file extent item type %d, inode %llu, offset %llu, root %llu",
type, btrfs_ino(inode), extent_start, type, btrfs_ino(BTRFS_I(inode)), extent_start,
root->root_key.objectid); root->root_key.objectid);
} }
} }
...@@ -168,7 +168,7 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans, ...@@ -168,7 +168,7 @@ int btrfs_add_inode_defrag(struct btrfs_trans_handle *trans,
if (!defrag) if (!defrag)
return -ENOMEM; return -ENOMEM;
defrag->ino = btrfs_ino(inode); defrag->ino = btrfs_ino(BTRFS_I(inode));
defrag->transid = transid; defrag->transid = transid;
defrag->root = root->root_key.objectid; defrag->root = root->root_key.objectid;
...@@ -702,7 +702,7 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans, ...@@ -702,7 +702,7 @@ int __btrfs_drop_extents(struct btrfs_trans_handle *trans,
struct btrfs_file_extent_item *fi; struct btrfs_file_extent_item *fi;
struct btrfs_key key; struct btrfs_key key;
struct btrfs_key new_key; struct btrfs_key new_key;
u64 ino = btrfs_ino(inode); u64 ino = btrfs_ino(BTRFS_I(inode));
u64 search_start = start; u64 search_start = start;
u64 disk_bytenr = 0; u64 disk_bytenr = 0;
u64 num_bytes = 0; u64 num_bytes = 0;
...@@ -1102,7 +1102,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans, ...@@ -1102,7 +1102,7 @@ int btrfs_mark_extent_written(struct btrfs_trans_handle *trans,
int del_slot = 0; int del_slot = 0;
int recow; int recow;
int ret; int ret;
u64 ino = btrfs_ino(inode); u64 ino = btrfs_ino(BTRFS_I(inode));
path = btrfs_alloc_path(); path = btrfs_alloc_path();
if (!path) if (!path)
...@@ -2062,7 +2062,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync) ...@@ -2062,7 +2062,7 @@ int btrfs_sync_file(struct file *file, loff_t start, loff_t end, int datasync)
* commit does not start nor waits for ordered extents to complete. * commit does not start nor waits for ordered extents to complete.
*/ */
smp_mb(); smp_mb();
if (btrfs_inode_in_log(inode, fs_info->generation) || if (btrfs_inode_in_log(BTRFS_I(inode), fs_info->generation) ||
(full_sync && BTRFS_I(inode)->last_trans <= (full_sync && BTRFS_I(inode)->last_trans <=
fs_info->last_trans_committed) || fs_info->last_trans_committed) ||
(!btrfs_have_ordered_extents_in_range(inode, start, len) && (!btrfs_have_ordered_extents_in_range(inode, start, len) &&
...@@ -2203,7 +2203,7 @@ static int hole_mergeable(struct inode *inode, struct extent_buffer *leaf, ...@@ -2203,7 +2203,7 @@ static int hole_mergeable(struct inode *inode, struct extent_buffer *leaf,
return 0; return 0;
btrfs_item_key_to_cpu(leaf, &key, slot); btrfs_item_key_to_cpu(leaf, &key, slot);
if (key.objectid != btrfs_ino(inode) || if (key.objectid != btrfs_ino(BTRFS_I(inode)) ||
key.type != BTRFS_EXTENT_DATA_KEY) key.type != BTRFS_EXTENT_DATA_KEY)
return 0; return 0;
...@@ -2237,7 +2237,7 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode, ...@@ -2237,7 +2237,7 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode,
if (btrfs_fs_incompat(fs_info, NO_HOLES)) if (btrfs_fs_incompat(fs_info, NO_HOLES))
goto out; goto out;
key.objectid = btrfs_ino(inode); key.objectid = btrfs_ino(BTRFS_I(inode));
key.type = BTRFS_EXTENT_DATA_KEY; key.type = BTRFS_EXTENT_DATA_KEY;
key.offset = offset; key.offset = offset;
...@@ -2285,9 +2285,8 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode, ...@@ -2285,9 +2285,8 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode,
} }
btrfs_release_path(path); btrfs_release_path(path);
ret = btrfs_insert_file_extent(trans, root, btrfs_ino(inode), offset, ret = btrfs_insert_file_extent(trans, root, btrfs_ino(BTRFS_I(inode)),
0, 0, end - offset, 0, end - offset, offset, 0, 0, end - offset, 0, end - offset, 0, 0, 0);
0, 0, 0);
if (ret) if (ret)
return ret; return ret;
......
...@@ -94,12 +94,11 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root, ...@@ -94,12 +94,11 @@ static struct inode *__lookup_free_space_inode(struct btrfs_root *root,
return inode; return inode;
} }
struct inode *lookup_free_space_inode(struct btrfs_root *root, struct inode *lookup_free_space_inode(struct btrfs_fs_info *fs_info,
struct btrfs_block_group_cache struct btrfs_block_group_cache
*block_group, struct btrfs_path *path) *block_group, struct btrfs_path *path)
{ {
struct inode *inode = NULL; struct inode *inode = NULL;
struct btrfs_fs_info *fs_info = root->fs_info;
u32 flags = BTRFS_INODE_NODATASUM | BTRFS_INODE_NODATACOW; u32 flags = BTRFS_INODE_NODATASUM | BTRFS_INODE_NODATACOW;
spin_lock(&block_group->lock); spin_lock(&block_group->lock);
...@@ -109,7 +108,7 @@ struct inode *lookup_free_space_inode(struct btrfs_root *root, ...@@ -109,7 +108,7 @@ struct inode *lookup_free_space_inode(struct btrfs_root *root,
if (inode) if (inode)
return inode; return inode;
inode = __lookup_free_space_inode(root, path, inode = __lookup_free_space_inode(fs_info->tree_root, path,
block_group->key.objectid); block_group->key.objectid);
if (IS_ERR(inode)) if (IS_ERR(inode))
return inode; return inode;
...@@ -192,7 +191,7 @@ static int __create_free_space_inode(struct btrfs_root *root, ...@@ -192,7 +191,7 @@ static int __create_free_space_inode(struct btrfs_root *root,
return 0; return 0;
} }
int create_free_space_inode(struct btrfs_root *root, int create_free_space_inode(struct btrfs_fs_info *fs_info,
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)
...@@ -200,11 +199,11 @@ int create_free_space_inode(struct btrfs_root *root, ...@@ -200,11 +199,11 @@ int create_free_space_inode(struct btrfs_root *root,
int ret; int ret;
u64 ino; u64 ino;
ret = btrfs_find_free_objectid(root, &ino); ret = btrfs_find_free_objectid(fs_info->tree_root, &ino);
if (ret < 0) if (ret < 0)
return ret; return ret;
return __create_free_space_inode(root, trans, path, ino, return __create_free_space_inode(fs_info->tree_root, trans, path, ino,
block_group->key.objectid); block_group->key.objectid);
} }
...@@ -227,21 +226,21 @@ int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info, ...@@ -227,21 +226,21 @@ int btrfs_check_trunc_cache_free_space(struct btrfs_fs_info *fs_info,
return ret; return ret;
} }
int btrfs_truncate_free_space_cache(struct btrfs_root *root, int btrfs_truncate_free_space_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 inode *inode) struct inode *inode)
{ {
struct btrfs_root *root = BTRFS_I(inode)->root;
int ret = 0; int ret = 0;
struct btrfs_path *path = btrfs_alloc_path();
bool locked = false; bool locked = false;
if (block_group) {
struct btrfs_path *path = btrfs_alloc_path();
if (!path) { if (!path) {
ret = -ENOMEM; ret = -ENOMEM;
goto fail; goto fail;
} }
if (block_group) {
locked = true; locked = true;
mutex_lock(&trans->transaction->cache_write_mutex); mutex_lock(&trans->transaction->cache_write_mutex);
if (!list_empty(&block_group->io_list)) { if (!list_empty(&block_group->io_list)) {
...@@ -258,8 +257,8 @@ int btrfs_truncate_free_space_cache(struct btrfs_root *root, ...@@ -258,8 +257,8 @@ int btrfs_truncate_free_space_cache(struct btrfs_root *root,
spin_lock(&block_group->lock); spin_lock(&block_group->lock);
block_group->disk_cache_state = BTRFS_DC_CLEAR; block_group->disk_cache_state = BTRFS_DC_CLEAR;
spin_unlock(&block_group->lock); spin_unlock(&block_group->lock);
}
btrfs_free_path(path); btrfs_free_path(path);
}
btrfs_i_size_write(inode, 0); btrfs_i_size_write(inode, 0);
truncate_pagecache(inode, 0); truncate_pagecache(inode, 0);
...@@ -286,14 +285,14 @@ int btrfs_truncate_free_space_cache(struct btrfs_root *root, ...@@ -286,14 +285,14 @@ int btrfs_truncate_free_space_cache(struct btrfs_root *root,
return ret; return ret;
} }
static int readahead_cache(struct inode *inode) static void readahead_cache(struct inode *inode)
{ {
struct file_ra_state *ra; struct file_ra_state *ra;
unsigned long last_index; unsigned long last_index;
ra = kzalloc(sizeof(*ra), GFP_NOFS); ra = kzalloc(sizeof(*ra), GFP_NOFS);
if (!ra) if (!ra)
return -ENOMEM; return;
file_ra_state_init(ra, inode->i_mapping); file_ra_state_init(ra, inode->i_mapping);
last_index = (i_size_read(inode) - 1) >> PAGE_SHIFT; last_index = (i_size_read(inode) - 1) >> PAGE_SHIFT;
...@@ -301,8 +300,6 @@ static int readahead_cache(struct inode *inode) ...@@ -301,8 +300,6 @@ static int readahead_cache(struct inode *inode)
page_cache_sync_readahead(inode->i_mapping, ra, NULL, 0, last_index); page_cache_sync_readahead(inode->i_mapping, ra, NULL, 0, last_index);
kfree(ra); kfree(ra);
return 0;
} }
static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode, static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode,
...@@ -313,7 +310,7 @@ static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode, ...@@ -313,7 +310,7 @@ static int io_ctl_init(struct btrfs_io_ctl *io_ctl, struct inode *inode,
num_pages = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE); num_pages = DIV_ROUND_UP(i_size_read(inode), PAGE_SIZE);
if (btrfs_ino(inode) != BTRFS_FREE_INO_OBJECTID) if (btrfs_ino(BTRFS_I(inode)) != BTRFS_FREE_INO_OBJECTID)
check_crcs = 1; check_crcs = 1;
/* Make sure we can fit our crcs into the first page */ /* Make sure we can fit our crcs into the first page */
...@@ -730,9 +727,7 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode, ...@@ -730,9 +727,7 @@ static int __load_free_space_cache(struct btrfs_root *root, struct inode *inode,
if (ret) if (ret)
return ret; return ret;
ret = readahead_cache(inode); readahead_cache(inode);
if (ret)
goto out;
ret = io_ctl_prepare_pages(&io_ctl, inode, 1); ret = io_ctl_prepare_pages(&io_ctl, inode, 1);
if (ret) if (ret)
...@@ -828,7 +823,6 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info, ...@@ -828,7 +823,6 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info,
struct btrfs_block_group_cache *block_group) struct btrfs_block_group_cache *block_group)
{ {
struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl; struct btrfs_free_space_ctl *ctl = block_group->free_space_ctl;
struct btrfs_root *root = fs_info->tree_root;
struct inode *inode; struct inode *inode;
struct btrfs_path *path; struct btrfs_path *path;
int ret = 0; int ret = 0;
...@@ -852,7 +846,7 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info, ...@@ -852,7 +846,7 @@ int load_free_space_cache(struct btrfs_fs_info *fs_info,
path->search_commit_root = 1; path->search_commit_root = 1;
path->skip_locking = 1; path->skip_locking = 1;
inode = lookup_free_space_inode(root, block_group, path); inode = lookup_free_space_inode(fs_info, block_group, path);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
btrfs_free_path(path); btrfs_free_path(path);
return 0; return 0;
...@@ -1128,8 +1122,7 @@ cleanup_bitmap_list(struct list_head *bitmap_list) ...@@ -1128,8 +1122,7 @@ cleanup_bitmap_list(struct list_head *bitmap_list)
static void noinline_for_stack static void noinline_for_stack
cleanup_write_cache_enospc(struct inode *inode, cleanup_write_cache_enospc(struct inode *inode,
struct btrfs_io_ctl *io_ctl, struct btrfs_io_ctl *io_ctl,
struct extent_state **cached_state, struct extent_state **cached_state)
struct list_head *bitmap_list)
{ {
io_ctl_drop_pages(io_ctl); io_ctl_drop_pages(io_ctl);
unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0, unlock_extent_cached(&BTRFS_I(inode)->io_tree, 0,
...@@ -1225,8 +1218,6 @@ int btrfs_wait_cache_io(struct btrfs_trans_handle *trans, ...@@ -1225,8 +1218,6 @@ int btrfs_wait_cache_io(struct btrfs_trans_handle *trans,
* @ctl - the free space cache we are going to write out * @ctl - the free space cache we are going to write out
* @block_group - the block_group for this cache if it belongs to a block_group * @block_group - the block_group for this cache if it belongs to a block_group
* @trans - the trans handle * @trans - the trans handle
* @path - the path to use
* @offset - the offset for the key we'll insert
* *
* This function writes out a free space cache struct to disk for quick recovery * This function writes out a free space cache struct to disk for quick recovery
* on mount. This will return 0 if it was successful in writing the cache out, * on mount. This will return 0 if it was successful in writing the cache out,
...@@ -1236,8 +1227,7 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, ...@@ -1236,8 +1227,7 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
struct btrfs_free_space_ctl *ctl, struct btrfs_free_space_ctl *ctl,
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,
struct btrfs_trans_handle *trans, struct btrfs_trans_handle *trans)
struct btrfs_path *path, u64 offset)
{ {
struct btrfs_fs_info *fs_info = root->fs_info; struct btrfs_fs_info *fs_info = root->fs_info;
struct extent_state *cached_state = NULL; struct extent_state *cached_state = NULL;
...@@ -1365,7 +1355,7 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode, ...@@ -1365,7 +1355,7 @@ static int __btrfs_write_out_cache(struct btrfs_root *root, struct inode *inode,
mutex_unlock(&ctl->cache_writeout_mutex); mutex_unlock(&ctl->cache_writeout_mutex);
out_nospc: out_nospc:
cleanup_write_cache_enospc(inode, io_ctl, &cached_state, &bitmap_list); cleanup_write_cache_enospc(inode, io_ctl, &cached_state);
if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA)) if (block_group && (block_group->flags & BTRFS_BLOCK_GROUP_DATA))
up_write(&block_group->data_rwsem); up_write(&block_group->data_rwsem);
...@@ -1378,7 +1368,6 @@ int btrfs_write_out_cache(struct btrfs_fs_info *fs_info, ...@@ -1378,7 +1368,6 @@ int btrfs_write_out_cache(struct btrfs_fs_info *fs_info,
struct btrfs_block_group_cache *block_group, struct btrfs_block_group_cache *block_group,
struct btrfs_path *path) struct btrfs_path *path)
{ {
struct btrfs_root *root = fs_info->tree_root;
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;
...@@ -1390,13 +1379,12 @@ int btrfs_write_out_cache(struct btrfs_fs_info *fs_info, ...@@ -1390,13 +1379,12 @@ 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(root, block_group, path); inode = lookup_free_space_inode(fs_info, block_group, path);
if (IS_ERR(inode)) if (IS_ERR(inode))
return 0; return 0;
ret = __btrfs_write_out_cache(root, inode, ctl, block_group, ret = __btrfs_write_out_cache(fs_info->tree_root, inode, ctl,
&block_group->io_ctl, trans, block_group, &block_group->io_ctl, trans);
path, block_group->key.objectid);
if (ret) { if (ret) {
#ifdef DEBUG #ifdef DEBUG
btrfs_err(fs_info, btrfs_err(fs_info,
...@@ -3543,8 +3531,7 @@ int btrfs_write_out_ino_cache(struct btrfs_root *root, ...@@ -3543,8 +3531,7 @@ int btrfs_write_out_ino_cache(struct btrfs_root *root,
return 0; return 0;
memset(&io_ctl, 0, sizeof(io_ctl)); memset(&io_ctl, 0, sizeof(io_ctl));
ret = __btrfs_write_out_cache(root, inode, ctl, NULL, &io_ctl, ret = __btrfs_write_out_cache(root, inode, ctl, NULL, &io_ctl, trans);
trans, path, 0);
if (!ret) { if (!ret) {
/* /*
* At this point writepages() didn't error out, so our metadata * At this point writepages() didn't error out, so our metadata
......
...@@ -51,18 +51,17 @@ struct btrfs_free_space_op { ...@@ -51,18 +51,17 @@ struct btrfs_free_space_op {
struct btrfs_io_ctl; struct btrfs_io_ctl;
struct inode *lookup_free_space_inode(struct btrfs_root *root, struct inode *lookup_free_space_inode(struct btrfs_fs_info *fs_info,
struct btrfs_block_group_cache struct btrfs_block_group_cache
*block_group, struct btrfs_path *path); *block_group, struct btrfs_path *path);
int create_free_space_inode(struct btrfs_root *root, int create_free_space_inode(struct btrfs_fs_info *fs_info,
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 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,
struct btrfs_block_rsv *rsv); struct btrfs_block_rsv *rsv);
int btrfs_truncate_free_space_cache(struct btrfs_root *root, int btrfs_truncate_free_space_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 inode *inode); struct inode *inode);
int load_free_space_cache(struct btrfs_fs_info *fs_info, int load_free_space_cache(struct btrfs_fs_info *fs_info,
......
...@@ -1269,7 +1269,7 @@ int btrfs_clear_free_space_tree(struct btrfs_fs_info *fs_info) ...@@ -1269,7 +1269,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(trans, fs_info, free_space_root->node); clean_tree_block(fs_info, 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);
......
...@@ -467,7 +467,7 @@ int btrfs_save_ino_cache(struct btrfs_root *root, ...@@ -467,7 +467,7 @@ int btrfs_save_ino_cache(struct btrfs_root *root,
} }
if (i_size_read(inode) > 0) { if (i_size_read(inode) > 0) {
ret = btrfs_truncate_free_space_cache(root, trans, NULL, inode); ret = btrfs_truncate_free_space_cache(trans, NULL, inode);
if (ret) { if (ret) {
if (ret != -ENOSPC) if (ret != -ENOSPC)
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);
......
This diff is collapsed.
This diff is collapsed.
...@@ -432,7 +432,7 @@ int btrfs_dec_test_ordered_pending(struct inode *inode, ...@@ -432,7 +432,7 @@ int btrfs_dec_test_ordered_pending(struct inode *inode,
} }
/* Needs to either be called under a log transaction or the log_mutex */ /* Needs to either be called under a log transaction or the log_mutex */
void btrfs_get_logged_extents(struct inode *inode, void btrfs_get_logged_extents(struct btrfs_inode *inode,
struct list_head *logged_list, struct list_head *logged_list,
const loff_t start, const loff_t start,
const loff_t end) const loff_t end)
...@@ -442,7 +442,7 @@ void btrfs_get_logged_extents(struct inode *inode, ...@@ -442,7 +442,7 @@ void btrfs_get_logged_extents(struct inode *inode,
struct rb_node *n; struct rb_node *n;
struct rb_node *prev; struct rb_node *prev;
tree = &BTRFS_I(inode)->ordered_tree; tree = &inode->ordered_tree;
spin_lock_irq(&tree->lock); spin_lock_irq(&tree->lock);
n = __tree_search(&tree->tree, end, &prev); n = __tree_search(&tree->tree, end, &prev);
if (!n) if (!n)
...@@ -984,8 +984,18 @@ int btrfs_ordered_update_i_size(struct inode *inode, u64 offset, ...@@ -984,8 +984,18 @@ int btrfs_ordered_update_i_size(struct inode *inode, u64 offset,
} }
disk_i_size = BTRFS_I(inode)->disk_i_size; disk_i_size = BTRFS_I(inode)->disk_i_size;
/* truncate file */ /*
if (disk_i_size > i_size) { * truncate file.
* If ordered is not NULL, then this is called from endio and
* disk_i_size will be updated by either truncate itself or any
* in-flight IOs which are inside the disk_i_size.
*
* Because btrfs_setsize() may set i_size with disk_i_size if truncate
* fails somehow, we need to make sure we have a precise disk_i_size by
* updating it as usual.
*
*/
if (!ordered && disk_i_size > i_size) {
BTRFS_I(inode)->disk_i_size = orig_offset; BTRFS_I(inode)->disk_i_size = orig_offset;
ret = 0; ret = 0;
goto out; goto out;
...@@ -1032,26 +1042,23 @@ int btrfs_ordered_update_i_size(struct inode *inode, u64 offset, ...@@ -1032,26 +1042,23 @@ int btrfs_ordered_update_i_size(struct inode *inode, u64 offset,
/* We treat this entry as if it doesn't exist */ /* We treat this entry as if it doesn't exist */
if (test_bit(BTRFS_ORDERED_UPDATED_ISIZE, &test->flags)) if (test_bit(BTRFS_ORDERED_UPDATED_ISIZE, &test->flags))
continue; continue;
if (test->file_offset + test->len <= disk_i_size)
if (entry_end(test) <= disk_i_size)
break; break;
if (test->file_offset >= i_size) if (test->file_offset >= i_size)
break; break;
if (entry_end(test) > disk_i_size) {
/* /*
* we don't update disk_i_size now, so record this * We don't update disk_i_size now, so record this undealt
* undealt i_size. Or we will not know the real * i_size. Or we will not know the real i_size.
* i_size.
*/ */
if (test->outstanding_isize < offset) if (test->outstanding_isize < offset)
test->outstanding_isize = offset; test->outstanding_isize = offset;
if (ordered && if (ordered &&
ordered->outstanding_isize > ordered->outstanding_isize > test->outstanding_isize)
test->outstanding_isize) test->outstanding_isize = ordered->outstanding_isize;
test->outstanding_isize =
ordered->outstanding_isize;
goto out; goto out;
} }
}
new_i_size = min_t(u64, offset, i_size); new_i_size = min_t(u64, offset, i_size);
/* /*
......
...@@ -75,6 +75,8 @@ struct btrfs_ordered_sum { ...@@ -75,6 +75,8 @@ struct btrfs_ordered_sum {
* in the logging code. */ * in the logging code. */
#define BTRFS_ORDERED_PENDING 11 /* We are waiting for this ordered extent to #define BTRFS_ORDERED_PENDING 11 /* We are waiting for this ordered extent to
* complete in the current transaction. */ * complete in the current transaction. */
#define BTRFS_ORDERED_REGULAR 12 /* Regular IO for COW */
struct btrfs_ordered_extent { struct btrfs_ordered_extent {
/* logical offset in the file */ /* logical offset in the file */
u64 file_offset; u64 file_offset;
...@@ -201,7 +203,7 @@ int btrfs_wait_ordered_extents(struct btrfs_root *root, int nr, ...@@ -201,7 +203,7 @@ int btrfs_wait_ordered_extents(struct btrfs_root *root, int nr,
const u64 range_start, const u64 range_len); const u64 range_start, const u64 range_len);
int btrfs_wait_ordered_roots(struct btrfs_fs_info *fs_info, int nr, int btrfs_wait_ordered_roots(struct btrfs_fs_info *fs_info, int nr,
const u64 range_start, const u64 range_len); const u64 range_start, const u64 range_len);
void btrfs_get_logged_extents(struct inode *inode, void btrfs_get_logged_extents(struct btrfs_inode *inode,
struct list_head *logged_list, struct list_head *logged_list,
const loff_t start, const loff_t start,
const loff_t end); const loff_t end);
......
...@@ -279,7 +279,7 @@ static void inode_prop_iterator(void *ctx, ...@@ -279,7 +279,7 @@ static void inode_prop_iterator(void *ctx,
if (unlikely(ret)) if (unlikely(ret))
btrfs_warn(root->fs_info, btrfs_warn(root->fs_info,
"error applying prop %s to ino %llu (root %llu): %d", "error applying prop %s to ino %llu (root %llu): %d",
handler->xattr_name, btrfs_ino(inode), handler->xattr_name, btrfs_ino(BTRFS_I(inode)),
root->root_key.objectid, ret); root->root_key.objectid, ret);
else else
set_bit(BTRFS_INODE_HAS_PROPS, &BTRFS_I(inode)->runtime_flags); set_bit(BTRFS_INODE_HAS_PROPS, &BTRFS_I(inode)->runtime_flags);
...@@ -288,7 +288,7 @@ static void inode_prop_iterator(void *ctx, ...@@ -288,7 +288,7 @@ static void inode_prop_iterator(void *ctx,
int btrfs_load_inode_props(struct inode *inode, struct btrfs_path *path) int btrfs_load_inode_props(struct inode *inode, struct btrfs_path *path)
{ {
struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_root *root = BTRFS_I(inode)->root;
u64 ino = btrfs_ino(inode); u64 ino = btrfs_ino(BTRFS_I(inode));
int ret; int ret;
ret = iterate_object_props(root, path, ino, inode_prop_iterator, inode); ret = iterate_object_props(root, path, ino, inode_prop_iterator, inode);
......
This diff is collapsed.
...@@ -94,9 +94,10 @@ int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans, ...@@ -94,9 +94,10 @@ int btrfs_qgroup_prepare_account_extents(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info); struct btrfs_fs_info *fs_info);
/* /*
* Inform qgroup to trace one dirty extent, its info is recorded in @record. * Inform qgroup to trace one dirty extent, its info is recorded in @record.
* So qgroup can account it at commit trans time. * So qgroup can account it at transaction committing time.
* *
* No lock version, caller must acquire delayed ref lock and allocate memory. * No lock version, caller must acquire delayed ref lock and allocated memory,
* then call btrfs_qgroup_trace_extent_post() after exiting lock context.
* *
* Return 0 for success insert * Return 0 for success insert
* Return >0 for existing record, caller can free @record safely. * Return >0 for existing record, caller can free @record safely.
...@@ -107,12 +108,38 @@ int btrfs_qgroup_trace_extent_nolock( ...@@ -107,12 +108,38 @@ int btrfs_qgroup_trace_extent_nolock(
struct btrfs_delayed_ref_root *delayed_refs, struct btrfs_delayed_ref_root *delayed_refs,
struct btrfs_qgroup_extent_record *record); struct btrfs_qgroup_extent_record *record);
/*
* Post handler after qgroup_trace_extent_nolock().
*
* NOTE: Current qgroup does the expensive backref walk at transaction
* committing time with TRANS_STATE_COMMIT_DOING, this blocks incoming
* new transaction.
* This is designed to allow btrfs_find_all_roots() to get correct new_roots
* result.
*
* However for old_roots there is no need to do backref walk at that time,
* since we search commit roots to walk backref and result will always be
* correct.
*
* Due to the nature of no lock version, we can't do backref there.
* So we must call btrfs_qgroup_trace_extent_post() after exiting
* spinlock context.
*
* TODO: If we can fix and prove btrfs_find_all_roots() can get correct result
* using current root, then we can move all expensive backref walk out of
* transaction committing, but not now as qgroup accounting will be wrong again.
*/
int btrfs_qgroup_trace_extent_post(struct btrfs_fs_info *fs_info,
struct btrfs_qgroup_extent_record *qrecord);
/* /*
* Inform qgroup to trace one dirty extent, specified by @bytenr and * Inform qgroup to trace one dirty extent, specified by @bytenr and
* @num_bytes. * @num_bytes.
* So qgroup can account it at commit trans time. * So qgroup can account it at commit trans time.
* *
* Better encapsulated version. * Better encapsulated version, with memory allocation and backref walk for
* commit roots.
* So this can sleep.
* *
* Return 0 if the operation is done. * Return 0 if the operation is done.
* Return <0 for error, like memory allocation failure or invalid parameter * Return <0 for error, like memory allocation failure or invalid parameter
...@@ -181,7 +208,8 @@ int btrfs_qgroup_reserve_data(struct inode *inode, u64 start, u64 len); ...@@ -181,7 +208,8 @@ int btrfs_qgroup_reserve_data(struct inode *inode, u64 start, u64 len);
int btrfs_qgroup_release_data(struct inode *inode, u64 start, u64 len); int btrfs_qgroup_release_data(struct inode *inode, u64 start, u64 len);
int btrfs_qgroup_free_data(struct inode *inode, u64 start, u64 len); int btrfs_qgroup_free_data(struct inode *inode, u64 start, u64 len);
int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes); int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes,
bool enforce);
void btrfs_qgroup_free_meta_all(struct btrfs_root *root); void btrfs_qgroup_free_meta_all(struct btrfs_root *root);
void btrfs_qgroup_free_meta(struct btrfs_root *root, int num_bytes); void btrfs_qgroup_free_meta(struct btrfs_root *root, int num_bytes);
void btrfs_qgroup_check_reserved_leak(struct inode *inode); void btrfs_qgroup_check_reserved_leak(struct inode *inode);
......
...@@ -677,11 +677,9 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio) ...@@ -677,11 +677,9 @@ static noinline int lock_stripe_add(struct btrfs_raid_bio *rbio)
struct btrfs_raid_bio *freeit = NULL; struct btrfs_raid_bio *freeit = NULL;
struct btrfs_raid_bio *cache_drop = NULL; struct btrfs_raid_bio *cache_drop = NULL;
int ret = 0; int ret = 0;
int walk = 0;
spin_lock_irqsave(&h->lock, flags); spin_lock_irqsave(&h->lock, flags);
list_for_each_entry(cur, &h->hash_list, hash_list) { list_for_each_entry(cur, &h->hash_list, hash_list) {
walk++;
if (cur->bbio->raid_map[0] == rbio->bbio->raid_map[0]) { if (cur->bbio->raid_map[0] == rbio->bbio->raid_map[0]) {
spin_lock(&cur->bio_list_lock); spin_lock(&cur->bio_list_lock);
......
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.
...@@ -184,7 +184,7 @@ DEFINE_EVENT(btrfs__inode, btrfs_inode_evict, ...@@ -184,7 +184,7 @@ DEFINE_EVENT(btrfs__inode, btrfs_inode_evict,
TRACE_EVENT_CONDITION(btrfs_get_extent, TRACE_EVENT_CONDITION(btrfs_get_extent,
TP_PROTO(struct btrfs_root *root, struct inode *inode, TP_PROTO(struct btrfs_root *root, struct btrfs_inode *inode,
struct extent_map *map), struct extent_map *map),
TP_ARGS(root, inode, map), TP_ARGS(root, inode, map),
......
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