You've already forked linux-apfs
mirror of
https://github.com/linux-apfs/linux-apfs.git
synced 2026-05-01 15:00:59 -07:00
ocfs2: Make ocfs2_extent_tree the first-class representation of a tree.
We now have three different kinds of extent trees in ocfs2: inode data (dinode), extended attributes (xattr_tree), and extended attribute values (xattr_value). There is a nice abstraction for them, ocfs2_extent_tree, but it is hidden in alloc.c. All the calling functions have to pick amongst a varied API and pass in type bits and often extraneous pointers. A better way is to make ocfs2_extent_tree a first-class object. Everyone converts their object to an ocfs2_extent_tree() via the ocfs2_get_*_extent_tree() calls, then uses the ocfs2_extent_tree for all tree calls to alloc.c. This simplifies a lot of callers, making for readability. It also provides an easy way to add additional extent tree types, as they only need to be defined in alloc.c with a ocfs2_get_<new>_extent_tree() function. Signed-off-by: Joel Becker <joel.becker@oracle.com> Signed-off-by: Mark Fasheh <mfasheh@suse.com>
This commit is contained in:
+90
-210
File diff suppressed because it is too large
Load Diff
+62
-49
@@ -26,46 +26,66 @@
|
||||
#ifndef OCFS2_ALLOC_H
|
||||
#define OCFS2_ALLOC_H
|
||||
|
||||
enum ocfs2_extent_tree_type {
|
||||
OCFS2_DINODE_EXTENT = 0,
|
||||
OCFS2_XATTR_VALUE_EXTENT,
|
||||
OCFS2_XATTR_TREE_EXTENT,
|
||||
};
|
||||
|
||||
/*
|
||||
* For xattr tree leaf, we limit the leaf byte size to be 64K.
|
||||
*/
|
||||
#define OCFS2_MAX_XATTR_TREE_LEAF_SIZE 65536
|
||||
|
||||
/*
|
||||
* ocfs2_extent_tree and ocfs2_extent_tree_operations are used to abstract
|
||||
* the b-tree operations in ocfs2. Now all the b-tree operations are not
|
||||
* limited to ocfs2_dinode only. Any data which need to allocate clusters
|
||||
* to store can use b-tree. And it only needs to implement its ocfs2_extent_tree
|
||||
* and operation.
|
||||
*
|
||||
* ocfs2_extent_tree becomes the first-class object for extent tree
|
||||
* manipulation. Callers of the alloc.c code need to fill it via one of
|
||||
* the ocfs2_get_*_extent_tree() operations below.
|
||||
*
|
||||
* ocfs2_extent_tree contains info for the root of the b-tree, it must have a
|
||||
* root ocfs2_extent_list and a root_bh so that they can be used in the b-tree
|
||||
* functions.
|
||||
* ocfs2_extent_tree_operations abstract the normal operations we do for
|
||||
* the root of extent b-tree.
|
||||
*/
|
||||
struct ocfs2_extent_tree_operations;
|
||||
struct ocfs2_extent_tree {
|
||||
struct ocfs2_extent_tree_operations *et_ops;
|
||||
struct buffer_head *et_root_bh;
|
||||
struct ocfs2_extent_list *et_root_el;
|
||||
void *et_object;
|
||||
unsigned int et_max_leaf_clusters;
|
||||
};
|
||||
|
||||
/*
|
||||
* ocfs2_*_get_extent_tree() will fill an ocfs2_extent_tree from the
|
||||
* specified object buffer. The bh is referenced until
|
||||
* ocfs2_put_extent_tree().
|
||||
*/
|
||||
void ocfs2_get_dinode_extent_tree(struct ocfs2_extent_tree *et,
|
||||
struct inode *inode,
|
||||
struct buffer_head *bh);
|
||||
void ocfs2_get_xattr_tree_extent_tree(struct ocfs2_extent_tree *et,
|
||||
struct inode *inode,
|
||||
struct buffer_head *bh);
|
||||
void ocfs2_get_xattr_value_extent_tree(struct ocfs2_extent_tree *et,
|
||||
struct inode *inode,
|
||||
struct buffer_head *bh,
|
||||
struct ocfs2_xattr_value_root *xv);
|
||||
void ocfs2_put_extent_tree(struct ocfs2_extent_tree *et);
|
||||
|
||||
struct ocfs2_alloc_context;
|
||||
int ocfs2_dinode_insert_extent(struct ocfs2_super *osb,
|
||||
handle_t *handle,
|
||||
struct inode *inode,
|
||||
struct buffer_head *root_bh,
|
||||
u32 cpos,
|
||||
u64 start_blk,
|
||||
u32 new_clusters,
|
||||
u8 flags,
|
||||
struct ocfs2_alloc_context *meta_ac);
|
||||
int ocfs2_xattr_value_insert_extent(struct ocfs2_super *osb,
|
||||
handle_t *handle,
|
||||
struct inode *inode,
|
||||
struct buffer_head *root_bh,
|
||||
u32 cpos,
|
||||
u64 start_blk,
|
||||
u32 new_clusters,
|
||||
u8 flags,
|
||||
struct ocfs2_alloc_context *meta_ac,
|
||||
struct ocfs2_xattr_value_root *xv);
|
||||
int ocfs2_xattr_tree_insert_extent(struct ocfs2_super *osb,
|
||||
handle_t *handle,
|
||||
struct inode *inode,
|
||||
struct buffer_head *root_bh,
|
||||
u32 cpos,
|
||||
u64 start_blk,
|
||||
u32 new_clusters,
|
||||
u8 flags,
|
||||
struct ocfs2_alloc_context *meta_ac);
|
||||
int ocfs2_insert_extent(struct ocfs2_super *osb,
|
||||
handle_t *handle,
|
||||
struct inode *inode,
|
||||
struct ocfs2_extent_tree *et,
|
||||
u32 cpos,
|
||||
u64 start_blk,
|
||||
u32 new_clusters,
|
||||
u8 flags,
|
||||
struct ocfs2_alloc_context *meta_ac);
|
||||
|
||||
enum ocfs2_alloc_restarted {
|
||||
RESTART_NONE = 0,
|
||||
RESTART_TRANS,
|
||||
@@ -76,32 +96,25 @@ int ocfs2_add_clusters_in_btree(struct ocfs2_super *osb,
|
||||
u32 *logical_offset,
|
||||
u32 clusters_to_add,
|
||||
int mark_unwritten,
|
||||
struct buffer_head *root_bh,
|
||||
struct ocfs2_extent_list *root_el,
|
||||
struct ocfs2_extent_tree *et,
|
||||
handle_t *handle,
|
||||
struct ocfs2_alloc_context *data_ac,
|
||||
struct ocfs2_alloc_context *meta_ac,
|
||||
enum ocfs2_alloc_restarted *reason_ret,
|
||||
enum ocfs2_extent_tree_type type,
|
||||
void *private);
|
||||
enum ocfs2_alloc_restarted *reason_ret);
|
||||
struct ocfs2_cached_dealloc_ctxt;
|
||||
int ocfs2_mark_extent_written(struct inode *inode, struct buffer_head *root_bh,
|
||||
int ocfs2_mark_extent_written(struct inode *inode,
|
||||
struct ocfs2_extent_tree *et,
|
||||
handle_t *handle, u32 cpos, u32 len, u32 phys,
|
||||
struct ocfs2_alloc_context *meta_ac,
|
||||
struct ocfs2_cached_dealloc_ctxt *dealloc,
|
||||
enum ocfs2_extent_tree_type et_type,
|
||||
void *private);
|
||||
int ocfs2_remove_extent(struct inode *inode, struct buffer_head *root_bh,
|
||||
struct ocfs2_cached_dealloc_ctxt *dealloc);
|
||||
int ocfs2_remove_extent(struct inode *inode,
|
||||
struct ocfs2_extent_tree *et,
|
||||
u32 cpos, u32 len, handle_t *handle,
|
||||
struct ocfs2_alloc_context *meta_ac,
|
||||
struct ocfs2_cached_dealloc_ctxt *dealloc,
|
||||
enum ocfs2_extent_tree_type et_type,
|
||||
void *private);
|
||||
struct ocfs2_cached_dealloc_ctxt *dealloc);
|
||||
int ocfs2_num_free_extents(struct ocfs2_super *osb,
|
||||
struct inode *inode,
|
||||
struct buffer_head *root_bh,
|
||||
enum ocfs2_extent_tree_type et_type,
|
||||
void *private);
|
||||
struct ocfs2_extent_tree *et);
|
||||
|
||||
/*
|
||||
* how many new metadata chunks would an allocation need at maximum?
|
||||
|
||||
+10
-6
@@ -1242,6 +1242,7 @@ static int ocfs2_write_cluster(struct address_space *mapping,
|
||||
int ret, i, new, should_zero = 0;
|
||||
u64 v_blkno, p_blkno;
|
||||
struct inode *inode = mapping->host;
|
||||
struct ocfs2_extent_tree et;
|
||||
|
||||
new = phys == 0 ? 1 : 0;
|
||||
if (new || unwritten)
|
||||
@@ -1276,10 +1277,11 @@ static int ocfs2_write_cluster(struct address_space *mapping,
|
||||
goto out;
|
||||
}
|
||||
} else if (unwritten) {
|
||||
ret = ocfs2_mark_extent_written(inode, wc->w_di_bh,
|
||||
ocfs2_get_dinode_extent_tree(&et, inode, wc->w_di_bh);
|
||||
ret = ocfs2_mark_extent_written(inode, &et,
|
||||
wc->w_handle, cpos, 1, phys,
|
||||
meta_ac, &wc->w_dealloc,
|
||||
OCFS2_DINODE_EXTENT, NULL);
|
||||
meta_ac, &wc->w_dealloc);
|
||||
ocfs2_put_extent_tree(&et);
|
||||
if (ret < 0) {
|
||||
mlog_errno(ret);
|
||||
goto out;
|
||||
@@ -1666,6 +1668,7 @@ int ocfs2_write_begin_nolock(struct address_space *mapping,
|
||||
struct ocfs2_alloc_context *data_ac = NULL;
|
||||
struct ocfs2_alloc_context *meta_ac = NULL;
|
||||
handle_t *handle;
|
||||
struct ocfs2_extent_tree et;
|
||||
|
||||
ret = ocfs2_alloc_write_ctxt(&wc, osb, pos, len, di_bh);
|
||||
if (ret) {
|
||||
@@ -1719,10 +1722,11 @@ int ocfs2_write_begin_nolock(struct address_space *mapping,
|
||||
(long long)i_size_read(inode), le32_to_cpu(di->i_clusters),
|
||||
clusters_to_alloc, extents_to_split);
|
||||
|
||||
ret = ocfs2_lock_allocators(inode, wc->w_di_bh, &di->id2.i_list,
|
||||
ocfs2_get_dinode_extent_tree(&et, inode, wc->w_di_bh);
|
||||
ret = ocfs2_lock_allocators(inode, &et,
|
||||
clusters_to_alloc, extents_to_split,
|
||||
&data_ac, &meta_ac,
|
||||
OCFS2_DINODE_EXTENT, NULL);
|
||||
&data_ac, &meta_ac);
|
||||
ocfs2_put_extent_tree(&et);
|
||||
if (ret) {
|
||||
mlog_errno(ret);
|
||||
goto out;
|
||||
|
||||
+12
-8
@@ -1192,6 +1192,9 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
|
||||
struct buffer_head *dirdata_bh = NULL;
|
||||
struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
|
||||
handle_t *handle;
|
||||
struct ocfs2_extent_tree et;
|
||||
|
||||
ocfs2_get_dinode_extent_tree(&et, dir, di_bh);
|
||||
|
||||
alloc = ocfs2_clusters_for_bytes(sb, bytes);
|
||||
|
||||
@@ -1305,8 +1308,8 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
|
||||
* This should never fail as our extent list is empty and all
|
||||
* related blocks have been journaled already.
|
||||
*/
|
||||
ret = ocfs2_dinode_insert_extent(osb, handle, dir, di_bh, 0, blkno,
|
||||
len, 0, NULL);
|
||||
ret = ocfs2_insert_extent(osb, handle, dir, &et, 0, blkno, len,
|
||||
0, NULL);
|
||||
if (ret) {
|
||||
mlog_errno(ret);
|
||||
goto out_commit;
|
||||
@@ -1337,8 +1340,8 @@ static int ocfs2_expand_inline_dir(struct inode *dir, struct buffer_head *di_bh,
|
||||
}
|
||||
blkno = ocfs2_clusters_to_blocks(dir->i_sb, bit_off);
|
||||
|
||||
ret = ocfs2_dinode_insert_extent(osb, handle, dir, di_bh, 1,
|
||||
blkno, len, 0, NULL);
|
||||
ret = ocfs2_insert_extent(osb, handle, dir, &et, 1,
|
||||
blkno, len, 0, NULL);
|
||||
if (ret) {
|
||||
mlog_errno(ret);
|
||||
goto out_commit;
|
||||
@@ -1360,6 +1363,7 @@ out:
|
||||
|
||||
brelse(dirdata_bh);
|
||||
|
||||
ocfs2_put_extent_tree(&et);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1437,6 +1441,7 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
|
||||
struct buffer_head *new_bh = NULL;
|
||||
struct ocfs2_dir_entry * de;
|
||||
struct super_block *sb = osb->sb;
|
||||
struct ocfs2_extent_tree et;
|
||||
|
||||
mlog_entry_void();
|
||||
|
||||
@@ -1480,10 +1485,9 @@ static int ocfs2_extend_dir(struct ocfs2_super *osb,
|
||||
spin_lock(&OCFS2_I(dir)->ip_lock);
|
||||
if (dir_i_size == ocfs2_clusters_to_bytes(sb, OCFS2_I(dir)->ip_clusters)) {
|
||||
spin_unlock(&OCFS2_I(dir)->ip_lock);
|
||||
num_free_extents = ocfs2_num_free_extents(osb, dir,
|
||||
parent_fe_bh,
|
||||
OCFS2_DINODE_EXTENT,
|
||||
NULL);
|
||||
ocfs2_get_dinode_extent_tree(&et, dir, parent_fe_bh);
|
||||
num_free_extents = ocfs2_num_free_extents(osb, dir, &et);
|
||||
ocfs2_put_extent_tree(&et);
|
||||
if (num_free_extents < 0) {
|
||||
status = num_free_extents;
|
||||
mlog_errno(status);
|
||||
|
||||
+22
-14
@@ -509,14 +509,17 @@ int ocfs2_add_inode_data(struct ocfs2_super *osb,
|
||||
struct ocfs2_alloc_context *meta_ac,
|
||||
enum ocfs2_alloc_restarted *reason_ret)
|
||||
{
|
||||
struct ocfs2_dinode *fe = (struct ocfs2_dinode *) fe_bh->b_data;
|
||||
struct ocfs2_extent_list *el = &fe->id2.i_list;
|
||||
int ret;
|
||||
struct ocfs2_extent_tree et;
|
||||
|
||||
return ocfs2_add_clusters_in_btree(osb, inode, logical_offset,
|
||||
ocfs2_get_dinode_extent_tree(&et, inode, fe_bh);
|
||||
ret = ocfs2_add_clusters_in_btree(osb, inode, logical_offset,
|
||||
clusters_to_add, mark_unwritten,
|
||||
fe_bh, el, handle,
|
||||
data_ac, meta_ac, reason_ret,
|
||||
OCFS2_DINODE_EXTENT, NULL);
|
||||
&et, handle,
|
||||
data_ac, meta_ac, reason_ret);
|
||||
ocfs2_put_extent_tree(&et);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int __ocfs2_extend_allocation(struct inode *inode, u32 logical_start,
|
||||
@@ -533,6 +536,7 @@ static int __ocfs2_extend_allocation(struct inode *inode, u32 logical_start,
|
||||
struct ocfs2_alloc_context *meta_ac = NULL;
|
||||
enum ocfs2_alloc_restarted why;
|
||||
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
|
||||
struct ocfs2_extent_tree et;
|
||||
|
||||
mlog_entry("(clusters_to_add = %u)\n", clusters_to_add);
|
||||
|
||||
@@ -564,9 +568,10 @@ restart_all:
|
||||
(unsigned long long)OCFS2_I(inode)->ip_blkno,
|
||||
(long long)i_size_read(inode), le32_to_cpu(fe->i_clusters),
|
||||
clusters_to_add);
|
||||
status = ocfs2_lock_allocators(inode, bh, &fe->id2.i_list,
|
||||
clusters_to_add, 0, &data_ac,
|
||||
&meta_ac, OCFS2_DINODE_EXTENT, NULL);
|
||||
ocfs2_get_dinode_extent_tree(&et, inode, bh);
|
||||
status = ocfs2_lock_allocators(inode, &et, clusters_to_add, 0,
|
||||
&data_ac, &meta_ac);
|
||||
ocfs2_put_extent_tree(&et);
|
||||
if (status) {
|
||||
mlog_errno(status);
|
||||
goto leave;
|
||||
@@ -1236,11 +1241,13 @@ static int __ocfs2_remove_inode_range(struct inode *inode,
|
||||
handle_t *handle;
|
||||
struct ocfs2_alloc_context *meta_ac = NULL;
|
||||
struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
|
||||
struct ocfs2_extent_tree et;
|
||||
|
||||
ret = ocfs2_lock_allocators(inode, di_bh, &di->id2.i_list,
|
||||
0, 1, NULL, &meta_ac,
|
||||
OCFS2_DINODE_EXTENT, NULL);
|
||||
ocfs2_get_dinode_extent_tree(&et, inode, di_bh);
|
||||
|
||||
ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac);
|
||||
if (ret) {
|
||||
ocfs2_put_extent_tree(&et);
|
||||
mlog_errno(ret);
|
||||
return ret;
|
||||
}
|
||||
@@ -1269,8 +1276,8 @@ static int __ocfs2_remove_inode_range(struct inode *inode,
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = ocfs2_remove_extent(inode, di_bh, cpos, len, handle, meta_ac,
|
||||
dealloc, OCFS2_DINODE_EXTENT, NULL);
|
||||
ret = ocfs2_remove_extent(inode, &et, cpos, len, handle, meta_ac,
|
||||
dealloc);
|
||||
if (ret) {
|
||||
mlog_errno(ret);
|
||||
goto out_commit;
|
||||
@@ -1297,6 +1304,7 @@ out:
|
||||
if (meta_ac)
|
||||
ocfs2_free_alloc_context(meta_ac);
|
||||
|
||||
ocfs2_put_extent_tree(&et);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+5
-7
@@ -1914,12 +1914,11 @@ static inline void ocfs2_debug_suballoc_inode(struct ocfs2_dinode *fe)
|
||||
* File systems which don't support holes call this from
|
||||
* ocfs2_extend_allocation().
|
||||
*/
|
||||
int ocfs2_lock_allocators(struct inode *inode, struct buffer_head *root_bh,
|
||||
struct ocfs2_extent_list *root_el,
|
||||
int ocfs2_lock_allocators(struct inode *inode,
|
||||
struct ocfs2_extent_tree *et,
|
||||
u32 clusters_to_add, u32 extents_to_split,
|
||||
struct ocfs2_alloc_context **data_ac,
|
||||
struct ocfs2_alloc_context **meta_ac,
|
||||
enum ocfs2_extent_tree_type type, void *private)
|
||||
struct ocfs2_alloc_context **meta_ac)
|
||||
{
|
||||
int ret = 0, num_free_extents;
|
||||
unsigned int max_recs_needed = clusters_to_add + 2 * extents_to_split;
|
||||
@@ -1931,8 +1930,7 @@ int ocfs2_lock_allocators(struct inode *inode, struct buffer_head *root_bh,
|
||||
|
||||
BUG_ON(clusters_to_add != 0 && data_ac == NULL);
|
||||
|
||||
num_free_extents = ocfs2_num_free_extents(osb, inode, root_bh,
|
||||
type, private);
|
||||
num_free_extents = ocfs2_num_free_extents(osb, inode, et);
|
||||
if (num_free_extents < 0) {
|
||||
ret = num_free_extents;
|
||||
mlog_errno(ret);
|
||||
@@ -1954,7 +1952,7 @@ int ocfs2_lock_allocators(struct inode *inode, struct buffer_head *root_bh,
|
||||
*/
|
||||
if (!num_free_extents ||
|
||||
(ocfs2_sparse_alloc(osb) && num_free_extents < max_recs_needed)) {
|
||||
ret = ocfs2_reserve_new_metadata(osb, root_el, meta_ac);
|
||||
ret = ocfs2_reserve_new_metadata(osb, et->et_root_el, meta_ac);
|
||||
if (ret < 0) {
|
||||
if (ret != -ENOSPC)
|
||||
mlog_errno(ret);
|
||||
|
||||
+2
-4
@@ -165,10 +165,8 @@ u64 ocfs2_which_cluster_group(struct inode *inode, u32 cluster);
|
||||
int ocfs2_check_group_descriptor(struct super_block *sb,
|
||||
struct ocfs2_dinode *di,
|
||||
struct ocfs2_group_desc *gd);
|
||||
int ocfs2_lock_allocators(struct inode *inode, struct buffer_head *root_bh,
|
||||
struct ocfs2_extent_list *root_el,
|
||||
int ocfs2_lock_allocators(struct inode *inode, struct ocfs2_extent_tree *et,
|
||||
u32 clusters_to_add, u32 extents_to_split,
|
||||
struct ocfs2_alloc_context **data_ac,
|
||||
struct ocfs2_alloc_context **meta_ac,
|
||||
enum ocfs2_extent_tree_type type, void *private);
|
||||
struct ocfs2_alloc_context **meta_ac);
|
||||
#endif /* _CHAINALLOC_H_ */
|
||||
|
||||
+37
-34
@@ -206,22 +206,24 @@ static int ocfs2_xattr_extend_allocation(struct inode *inode,
|
||||
struct ocfs2_alloc_context *meta_ac = NULL;
|
||||
enum ocfs2_alloc_restarted why;
|
||||
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
|
||||
struct ocfs2_extent_list *root_el = &xv->xr_list;
|
||||
u32 prev_clusters, logical_start = le32_to_cpu(xv->xr_clusters);
|
||||
struct ocfs2_extent_tree et;
|
||||
|
||||
mlog(0, "(clusters_to_add for xattr= %u)\n", clusters_to_add);
|
||||
|
||||
ocfs2_get_xattr_value_extent_tree(&et, inode, xattr_bh, xv);
|
||||
|
||||
restart_all:
|
||||
|
||||
status = ocfs2_lock_allocators(inode, xattr_bh, root_el,
|
||||
clusters_to_add, 0, &data_ac,
|
||||
&meta_ac, OCFS2_XATTR_VALUE_EXTENT, xv);
|
||||
status = ocfs2_lock_allocators(inode, &et, clusters_to_add, 0,
|
||||
&data_ac, &meta_ac);
|
||||
if (status) {
|
||||
mlog_errno(status);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
credits = ocfs2_calc_extend_credits(osb->sb, root_el, clusters_to_add);
|
||||
credits = ocfs2_calc_extend_credits(osb->sb, et.et_root_el,
|
||||
clusters_to_add);
|
||||
handle = ocfs2_start_trans(osb, credits);
|
||||
if (IS_ERR(handle)) {
|
||||
status = PTR_ERR(handle);
|
||||
@@ -244,14 +246,11 @@ restarted_transaction:
|
||||
&logical_start,
|
||||
clusters_to_add,
|
||||
0,
|
||||
xattr_bh,
|
||||
root_el,
|
||||
&et,
|
||||
handle,
|
||||
data_ac,
|
||||
meta_ac,
|
||||
&why,
|
||||
OCFS2_XATTR_VALUE_EXTENT,
|
||||
xv);
|
||||
&why);
|
||||
if ((status < 0) && (status != -EAGAIN)) {
|
||||
if (status != -ENOSPC)
|
||||
mlog_errno(status);
|
||||
@@ -276,7 +275,7 @@ restarted_transaction:
|
||||
mlog(0, "restarting transaction.\n");
|
||||
/* TODO: This can be more intelligent. */
|
||||
credits = ocfs2_calc_extend_credits(osb->sb,
|
||||
root_el,
|
||||
et.et_root_el,
|
||||
clusters_to_add);
|
||||
status = ocfs2_extend_trans(handle, credits);
|
||||
if (status < 0) {
|
||||
@@ -308,6 +307,7 @@ leave:
|
||||
goto restart_all;
|
||||
}
|
||||
|
||||
ocfs2_put_extent_tree(&et);
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -323,11 +323,13 @@ static int __ocfs2_remove_xattr_range(struct inode *inode,
|
||||
struct inode *tl_inode = osb->osb_tl_inode;
|
||||
handle_t *handle;
|
||||
struct ocfs2_alloc_context *meta_ac = NULL;
|
||||
struct ocfs2_extent_tree et;
|
||||
|
||||
ret = ocfs2_lock_allocators(inode, root_bh, &xv->xr_list,
|
||||
0, 1, NULL, &meta_ac,
|
||||
OCFS2_XATTR_VALUE_EXTENT, xv);
|
||||
ocfs2_get_xattr_value_extent_tree(&et, inode, root_bh, xv);
|
||||
|
||||
ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac);
|
||||
if (ret) {
|
||||
ocfs2_put_extent_tree(&et);
|
||||
mlog_errno(ret);
|
||||
return ret;
|
||||
}
|
||||
@@ -356,8 +358,8 @@ static int __ocfs2_remove_xattr_range(struct inode *inode,
|
||||
goto out_commit;
|
||||
}
|
||||
|
||||
ret = ocfs2_remove_extent(inode, root_bh, cpos, len, handle, meta_ac,
|
||||
dealloc, OCFS2_XATTR_VALUE_EXTENT, xv);
|
||||
ret = ocfs2_remove_extent(inode, &et, cpos, len, handle, meta_ac,
|
||||
dealloc);
|
||||
if (ret) {
|
||||
mlog_errno(ret);
|
||||
goto out_commit;
|
||||
@@ -383,6 +385,7 @@ out:
|
||||
if (meta_ac)
|
||||
ocfs2_free_alloc_context(meta_ac);
|
||||
|
||||
ocfs2_put_extent_tree(&et);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -3622,26 +3625,24 @@ static int ocfs2_add_new_xattr_cluster(struct inode *inode,
|
||||
struct ocfs2_alloc_context *data_ac = NULL;
|
||||
struct ocfs2_alloc_context *meta_ac = NULL;
|
||||
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
|
||||
struct ocfs2_xattr_block *xb =
|
||||
(struct ocfs2_xattr_block *)root_bh->b_data;
|
||||
struct ocfs2_xattr_tree_root *xb_root = &xb->xb_attrs.xb_root;
|
||||
struct ocfs2_extent_list *root_el = &xb_root->xt_list;
|
||||
enum ocfs2_extent_tree_type type = OCFS2_XATTR_TREE_EXTENT;
|
||||
struct ocfs2_extent_tree et;
|
||||
|
||||
mlog(0, "Add new xattr cluster for %llu, previous xattr hash = %u, "
|
||||
"previous xattr blkno = %llu\n",
|
||||
(unsigned long long)OCFS2_I(inode)->ip_blkno,
|
||||
prev_cpos, prev_blkno);
|
||||
|
||||
ret = ocfs2_lock_allocators(inode, root_bh, root_el,
|
||||
clusters_to_add, 0, &data_ac,
|
||||
&meta_ac, type, NULL);
|
||||
ocfs2_get_xattr_tree_extent_tree(&et, inode, root_bh);
|
||||
|
||||
ret = ocfs2_lock_allocators(inode, &et, clusters_to_add, 0,
|
||||
&data_ac, &meta_ac);
|
||||
if (ret) {
|
||||
mlog_errno(ret);
|
||||
goto leave;
|
||||
}
|
||||
|
||||
credits = ocfs2_calc_extend_credits(osb->sb, root_el, clusters_to_add);
|
||||
credits = ocfs2_calc_extend_credits(osb->sb, et.et_root_el,
|
||||
clusters_to_add);
|
||||
handle = ocfs2_start_trans(osb, credits);
|
||||
if (IS_ERR(handle)) {
|
||||
ret = PTR_ERR(handle);
|
||||
@@ -3705,9 +3706,8 @@ static int ocfs2_add_new_xattr_cluster(struct inode *inode,
|
||||
|
||||
mlog(0, "Insert %u clusters at block %llu for xattr at %u\n",
|
||||
num_bits, block, v_start);
|
||||
ret = ocfs2_xattr_tree_insert_extent(osb, handle, inode, root_bh,
|
||||
v_start, block, num_bits,
|
||||
0, meta_ac);
|
||||
ret = ocfs2_insert_extent(osb, handle, inode, &et, v_start, block,
|
||||
num_bits, 0, meta_ac);
|
||||
if (ret < 0) {
|
||||
mlog_errno(ret);
|
||||
goto leave;
|
||||
@@ -3727,6 +3727,7 @@ leave:
|
||||
if (meta_ac)
|
||||
ocfs2_free_alloc_context(meta_ac);
|
||||
|
||||
ocfs2_put_extent_tree(&et);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -4331,9 +4332,11 @@ static int ocfs2_rm_xattr_cluster(struct inode *inode,
|
||||
handle_t *handle;
|
||||
struct ocfs2_xattr_block *xb =
|
||||
(struct ocfs2_xattr_block *)root_bh->b_data;
|
||||
struct ocfs2_extent_list *root_el = &xb->xb_attrs.xb_root.xt_list;
|
||||
struct ocfs2_alloc_context *meta_ac = NULL;
|
||||
struct ocfs2_cached_dealloc_ctxt dealloc;
|
||||
struct ocfs2_extent_tree et;
|
||||
|
||||
ocfs2_get_xattr_tree_extent_tree(&et, inode, root_bh);
|
||||
|
||||
ocfs2_init_dealloc_ctxt(&dealloc);
|
||||
|
||||
@@ -4342,10 +4345,9 @@ static int ocfs2_rm_xattr_cluster(struct inode *inode,
|
||||
|
||||
ocfs2_remove_xattr_clusters_from_cache(inode, blkno, len);
|
||||
|
||||
ret = ocfs2_lock_allocators(inode, root_bh, root_el,
|
||||
0, 1, NULL, &meta_ac,
|
||||
OCFS2_XATTR_TREE_EXTENT, NULL);
|
||||
ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac);
|
||||
if (ret) {
|
||||
ocfs2_put_extent_tree(&et);
|
||||
mlog_errno(ret);
|
||||
return ret;
|
||||
}
|
||||
@@ -4374,8 +4376,8 @@ static int ocfs2_rm_xattr_cluster(struct inode *inode,
|
||||
goto out_commit;
|
||||
}
|
||||
|
||||
ret = ocfs2_remove_extent(inode, root_bh, cpos, len, handle, meta_ac,
|
||||
&dealloc, OCFS2_XATTR_TREE_EXTENT, NULL);
|
||||
ret = ocfs2_remove_extent(inode, &et, cpos, len, handle, meta_ac,
|
||||
&dealloc);
|
||||
if (ret) {
|
||||
mlog_errno(ret);
|
||||
goto out_commit;
|
||||
@@ -4405,6 +4407,7 @@ out:
|
||||
|
||||
ocfs2_run_deallocs(osb, &dealloc);
|
||||
|
||||
ocfs2_put_extent_tree(&et);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user