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_init_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);
&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);
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) {
struct inode *tl_inode = osb->osb_tl_inode;
handle_t *handle;
struct ocfs2_alloc_context *meta_ac = NULL;
+ struct ocfs2_extent_tree et;
+
+ ocfs2_init_xattr_value_extent_tree(&et, inode, root_bh, xv);
- ret = ocfs2_lock_allocators(inode, root_bh, &xv->xr_list,
- 0, 1, NULL, &meta_ac,
- OCFS2_XATTR_VALUE_EXTENT, xv);
+ ret = ocfs2_lock_allocators(inode, &et, 0, 1, NULL, &meta_ac);
if (ret) {
mlog_errno(ret);
return ret;
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;
}
if (!(flag & OCFS2_INLINE_XATTR_FL)) {
- /*set extended attribue in external blcok*/
+ /* set extended attribute in external block. */
ret = ocfs2_extend_trans(handle,
+ OCFS2_INODE_UPDATE_CREDITS +
OCFS2_XATTR_BLOCK_UPDATE_CREDITS);
if (ret) {
mlog_errno(ret);
}
-static int ocfs2_xattr_free_block(handle_t *handle,
- struct ocfs2_super *osb,
- struct ocfs2_xattr_block *xb)
-{
- struct inode *xb_alloc_inode;
- struct buffer_head *xb_alloc_bh = NULL;
- u64 blk = le64_to_cpu(xb->xb_blkno);
- u16 bit = le16_to_cpu(xb->xb_suballoc_bit);
- u64 bg_blkno = ocfs2_which_suballoc_group(blk, bit);
- int ret = 0;
-
- xb_alloc_inode = ocfs2_get_system_file_inode(osb,
- EXTENT_ALLOC_SYSTEM_INODE,
- le16_to_cpu(xb->xb_suballoc_slot));
- if (!xb_alloc_inode) {
- ret = -ENOMEM;
- mlog_errno(ret);
- goto out;
- }
- mutex_lock(&xb_alloc_inode->i_mutex);
-
- ret = ocfs2_inode_lock(xb_alloc_inode, &xb_alloc_bh, 1);
- if (ret < 0) {
- mlog_errno(ret);
- goto out_mutex;
- }
- ret = ocfs2_extend_trans(handle, OCFS2_SUBALLOC_FREE);
- if (ret < 0) {
- mlog_errno(ret);
- goto out_unlock;
- }
- ret = ocfs2_free_suballoc_bits(handle, xb_alloc_inode, xb_alloc_bh,
- bit, bg_blkno, 1);
- if (ret < 0)
- mlog_errno(ret);
-out_unlock:
- ocfs2_inode_unlock(xb_alloc_inode, 1);
- brelse(xb_alloc_bh);
-out_mutex:
- mutex_unlock(&xb_alloc_inode->i_mutex);
- iput(xb_alloc_inode);
-out:
- return ret;
-}
-
static int ocfs2_remove_value_outside(struct inode*inode,
struct buffer_head *bh,
struct ocfs2_xattr_header *header)
return ret;
}
+static int ocfs2_xattr_free_block(struct inode *inode,
+ u64 block)
+{
+ struct inode *xb_alloc_inode;
+ struct buffer_head *xb_alloc_bh = NULL;
+ struct buffer_head *blk_bh = NULL;
+ struct ocfs2_xattr_block *xb;
+ struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
+ handle_t *handle;
+ int ret = 0;
+ u64 blk, bg_blkno;
+ u16 bit;
+
+ ret = ocfs2_read_block(osb, block, &blk_bh,
+ OCFS2_BH_CACHED, inode);
+ if (ret < 0) {
+ mlog_errno(ret);
+ goto out;
+ }
+
+ /*Verify the signature of xattr block*/
+ if (memcmp((void *)blk_bh->b_data, OCFS2_XATTR_BLOCK_SIGNATURE,
+ strlen(OCFS2_XATTR_BLOCK_SIGNATURE))) {
+ ret = -EFAULT;
+ goto out;
+ }
+
+ ret = ocfs2_xattr_block_remove(inode, blk_bh);
+ if (ret < 0) {
+ mlog_errno(ret);
+ goto out;
+ }
+
+ xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
+ blk = le64_to_cpu(xb->xb_blkno);
+ bit = le16_to_cpu(xb->xb_suballoc_bit);
+ bg_blkno = ocfs2_which_suballoc_group(blk, bit);
+
+ xb_alloc_inode = ocfs2_get_system_file_inode(osb,
+ EXTENT_ALLOC_SYSTEM_INODE,
+ le16_to_cpu(xb->xb_suballoc_slot));
+ if (!xb_alloc_inode) {
+ ret = -ENOMEM;
+ mlog_errno(ret);
+ goto out;
+ }
+ mutex_lock(&xb_alloc_inode->i_mutex);
+
+ ret = ocfs2_inode_lock(xb_alloc_inode, &xb_alloc_bh, 1);
+ if (ret < 0) {
+ mlog_errno(ret);
+ goto out_mutex;
+ }
+
+ handle = ocfs2_start_trans(osb, OCFS2_SUBALLOC_FREE);
+ if (IS_ERR(handle)) {
+ ret = PTR_ERR(handle);
+ mlog_errno(ret);
+ goto out_unlock;
+ }
+
+ ret = ocfs2_free_suballoc_bits(handle, xb_alloc_inode, xb_alloc_bh,
+ bit, bg_blkno, 1);
+ if (ret < 0)
+ mlog_errno(ret);
+
+ ocfs2_commit_trans(osb, handle);
+out_unlock:
+ ocfs2_inode_unlock(xb_alloc_inode, 1);
+ brelse(xb_alloc_bh);
+out_mutex:
+ mutex_unlock(&xb_alloc_inode->i_mutex);
+ iput(xb_alloc_inode);
+out:
+ brelse(blk_bh);
+ return ret;
+}
+
/*
* ocfs2_xattr_remove()
*
*/
int ocfs2_xattr_remove(struct inode *inode, struct buffer_head *di_bh)
{
- struct ocfs2_xattr_block *xb;
- struct buffer_head *blk_bh = NULL;
- struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
struct ocfs2_inode_info *oi = OCFS2_I(inode);
struct ocfs2_dinode *di = (struct ocfs2_dinode *)di_bh->b_data;
handle_t *handle;
goto out;
}
}
- if (di->i_xattr_loc) {
- ret = ocfs2_read_block(OCFS2_SB(inode->i_sb),
- le64_to_cpu(di->i_xattr_loc),
- &blk_bh, OCFS2_BH_CACHED, inode);
- if (ret < 0) {
- mlog_errno(ret);
- return ret;
- }
- /*Verify the signature of xattr block*/
- if (memcmp((void *)blk_bh->b_data, OCFS2_XATTR_BLOCK_SIGNATURE,
- strlen(OCFS2_XATTR_BLOCK_SIGNATURE))) {
- ret = -EFAULT;
- goto out;
- }
- ret = ocfs2_xattr_block_remove(inode, blk_bh);
+ if (di->i_xattr_loc) {
+ ret = ocfs2_xattr_free_block(inode,
+ le64_to_cpu(di->i_xattr_loc));
if (ret < 0) {
mlog_errno(ret);
goto out;
goto out_commit;
}
- if (di->i_xattr_loc) {
- xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
- ocfs2_xattr_free_block(handle, osb, xb);
- di->i_xattr_loc = cpu_to_le64(0);
- }
+ di->i_xattr_loc = 0;
spin_lock(&oi->ip_lock);
oi->ip_dyn_features &= ~(OCFS2_INLINE_XATTR_FL | OCFS2_HAS_XATTR_FL);
out_commit:
ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);
out:
- brelse(blk_bh);
-
return ret;
}
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_init_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);
}
}
+ if (handle->h_buffer_credits < credits) {
+ /*
+ * The journal has been restarted before, and don't
+ * have enough space for the insertion, so extend it
+ * here.
+ */
+ ret = ocfs2_extend_trans(handle, credits);
+ if (ret) {
+ mlog_errno(ret);
+ goto leave;
+ }
+ }
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;
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_init_xattr_tree_extent_tree(&et, inode, root_bh);
ocfs2_init_dealloc_ctxt(&dealloc);
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) {
mlog_errno(ret);
return ret;
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;