mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-04 16:15:11 +00:00
btrfs: btrfs_check_shared should manage its own transaction
Commit afce772e87
("btrfs: fix check_shared for fiemap ioctl") added
transaction semantics around calls to btrfs_check_shared() in order to
provide accurate accounting of delayed refs. The transaction management
should be done inside btrfs_check_shared(), so that callers do not need
to manage transactions individually.
Signed-off-by: Edmund Nadolski <enadolski@suse.com>
Signed-off-by: Jeff Mahoney <jeffm@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
e0c476b128
commit
bb739cf08e
3 changed files with 23 additions and 33 deletions
|
@ -1580,20 +1580,21 @@ int btrfs_find_all_roots(struct btrfs_trans_handle *trans,
|
||||||
/**
|
/**
|
||||||
* btrfs_check_shared - tell us whether an extent is shared
|
* btrfs_check_shared - tell us whether an extent is shared
|
||||||
*
|
*
|
||||||
* @trans: optional trans handle
|
|
||||||
*
|
|
||||||
* btrfs_check_shared uses the backref walking code but will short
|
* btrfs_check_shared uses the backref walking code but will short
|
||||||
* circuit as soon as it finds a root or inode that doesn't match the
|
* circuit as soon as it finds a root or inode that doesn't match the
|
||||||
* one passed in. This provides a significant performance benefit for
|
* one passed in. This provides a significant performance benefit for
|
||||||
* 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
|
||||||
|
* delayed refs, but continues on even when the alloc fails.
|
||||||
|
*
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
int btrfs_check_shared(struct btrfs_trans_handle *trans,
|
int btrfs_check_shared(struct btrfs_root *root, u64 inum, u64 bytenr)
|
||||||
struct btrfs_fs_info *fs_info, u64 root_objectid,
|
|
||||||
u64 inum, u64 bytenr)
|
|
||||||
{
|
{
|
||||||
|
struct btrfs_fs_info *fs_info = root->fs_info;
|
||||||
|
struct btrfs_trans_handle *trans;
|
||||||
struct ulist *tmp = NULL;
|
struct ulist *tmp = NULL;
|
||||||
struct ulist *roots = NULL;
|
struct ulist *roots = NULL;
|
||||||
struct ulist_iterator uiter;
|
struct ulist_iterator uiter;
|
||||||
|
@ -1609,14 +1610,18 @@ int btrfs_check_shared(struct btrfs_trans_handle *trans,
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trans)
|
trans = btrfs_join_transaction(root);
|
||||||
btrfs_get_tree_mod_seq(fs_info, &elem);
|
if (IS_ERR(trans)) {
|
||||||
else
|
trans = NULL;
|
||||||
down_read(&fs_info->commit_root_sem);
|
down_read(&fs_info->commit_root_sem);
|
||||||
|
} else {
|
||||||
|
btrfs_get_tree_mod_seq(fs_info, &elem);
|
||||||
|
}
|
||||||
|
|
||||||
ULIST_ITER_INIT(&uiter);
|
ULIST_ITER_INIT(&uiter);
|
||||||
while (1) {
|
while (1) {
|
||||||
ret = find_parent_nodes(trans, fs_info, bytenr, elem.seq, tmp,
|
ret = find_parent_nodes(trans, fs_info, bytenr, elem.seq, tmp,
|
||||||
roots, NULL, root_objectid, inum, 1);
|
roots, NULL, root->objectid, inum, 1);
|
||||||
if (ret == BACKREF_FOUND_SHARED) {
|
if (ret == BACKREF_FOUND_SHARED) {
|
||||||
/* this is the only condition under which we return 1 */
|
/* this is the only condition under which we return 1 */
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
@ -1631,10 +1636,13 @@ int btrfs_check_shared(struct btrfs_trans_handle *trans,
|
||||||
bytenr = node->val;
|
bytenr = node->val;
|
||||||
cond_resched();
|
cond_resched();
|
||||||
}
|
}
|
||||||
if (trans)
|
|
||||||
|
if (trans) {
|
||||||
btrfs_put_tree_mod_seq(fs_info, &elem);
|
btrfs_put_tree_mod_seq(fs_info, &elem);
|
||||||
else
|
btrfs_end_transaction(trans);
|
||||||
|
} else {
|
||||||
up_read(&fs_info->commit_root_sem);
|
up_read(&fs_info->commit_root_sem);
|
||||||
|
}
|
||||||
ulist_free(tmp);
|
ulist_free(tmp);
|
||||||
ulist_free(roots);
|
ulist_free(roots);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -68,9 +68,7 @@ int btrfs_find_one_extref(struct btrfs_root *root, u64 inode_objectid,
|
||||||
u64 start_off, struct btrfs_path *path,
|
u64 start_off, struct btrfs_path *path,
|
||||||
struct btrfs_inode_extref **ret_extref,
|
struct btrfs_inode_extref **ret_extref,
|
||||||
u64 *found_off);
|
u64 *found_off);
|
||||||
int btrfs_check_shared(struct btrfs_trans_handle *trans,
|
int btrfs_check_shared(struct btrfs_root *root, u64 inum, u64 bytenr);
|
||||||
struct btrfs_fs_info *fs_info, u64 root_objectid,
|
|
||||||
u64 inum, u64 bytenr);
|
|
||||||
|
|
||||||
int __init btrfs_prelim_ref_init(void);
|
int __init btrfs_prelim_ref_init(void);
|
||||||
void btrfs_prelim_ref_exit(void);
|
void btrfs_prelim_ref_exit(void);
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include "locking.h"
|
#include "locking.h"
|
||||||
#include "rcu-string.h"
|
#include "rcu-string.h"
|
||||||
#include "backref.h"
|
#include "backref.h"
|
||||||
#include "transaction.h"
|
|
||||||
|
|
||||||
static struct kmem_cache *extent_state_cache;
|
static struct kmem_cache *extent_state_cache;
|
||||||
static struct kmem_cache *extent_buffer_cache;
|
static struct kmem_cache *extent_buffer_cache;
|
||||||
|
@ -4606,24 +4605,11 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
|
||||||
flags |= (FIEMAP_EXTENT_DELALLOC |
|
flags |= (FIEMAP_EXTENT_DELALLOC |
|
||||||
FIEMAP_EXTENT_UNKNOWN);
|
FIEMAP_EXTENT_UNKNOWN);
|
||||||
} else if (fieinfo->fi_extents_max) {
|
} else if (fieinfo->fi_extents_max) {
|
||||||
struct btrfs_trans_handle *trans;
|
|
||||||
|
|
||||||
u64 bytenr = em->block_start -
|
u64 bytenr = em->block_start -
|
||||||
(em->start - em->orig_start);
|
(em->start - em->orig_start);
|
||||||
|
|
||||||
disko = em->block_start + offset_in_extent;
|
disko = em->block_start + offset_in_extent;
|
||||||
|
|
||||||
/*
|
|
||||||
* We need a trans handle to get delayed refs
|
|
||||||
*/
|
|
||||||
trans = btrfs_join_transaction(root);
|
|
||||||
/*
|
|
||||||
* It's OK if we can't start a trans we can still check
|
|
||||||
* from commit_root
|
|
||||||
*/
|
|
||||||
if (IS_ERR(trans))
|
|
||||||
trans = NULL;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* As btrfs supports shared space, this information
|
* As btrfs supports shared space, this information
|
||||||
* can be exported to userspace tools via
|
* can be exported to userspace tools via
|
||||||
|
@ -4631,11 +4617,9 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
|
||||||
* then we're just getting a count and we can skip the
|
* then we're just getting a count and we can skip the
|
||||||
* lookup stuff.
|
* lookup stuff.
|
||||||
*/
|
*/
|
||||||
ret = btrfs_check_shared(trans, root->fs_info,
|
ret = btrfs_check_shared(root,
|
||||||
root->objectid,
|
btrfs_ino(BTRFS_I(inode)),
|
||||||
btrfs_ino(BTRFS_I(inode)), bytenr);
|
bytenr);
|
||||||
if (trans)
|
|
||||||
btrfs_end_transaction(trans);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out_free;
|
goto out_free;
|
||||||
if (ret)
|
if (ret)
|
||||||
|
|
Loading…
Reference in a new issue