struct ocfs2_xattr_info *xi,
struct ocfs2_xattr_search *xs);
+static int ocfs2_delete_xattr_index_block(struct inode *inode,
+ struct buffer_head *xb_bh);
+
static inline struct xattr_handler *ocfs2_xattr_handler(int name_index)
{
struct xattr_handler *handler = NULL;
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;
- ret = ocfs2_lock_allocators(inode, root_bh, &xv->xr_list,
- 0, 1, NULL, &meta_ac,
- OCFS2_XATTR_VALUE_EXTENT, xv);
+ ocfs2_init_xattr_value_extent_tree(&et, inode, root_bh, 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;
struct ocfs2_dinode *di = NULL;
struct ocfs2_inode_info *oi = OCFS2_I(dentry->d_inode);
+ if (!ocfs2_supports_xattr(OCFS2_SB(dentry->d_sb)))
+ return -EOPNOTSUPP;
+
if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL))
return ret;
.not_found = -ENODATA,
};
+ if (!ocfs2_supports_xattr(OCFS2_SB(inode->i_sb)))
+ return -EOPNOTSUPP;
+
if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL))
ret = -ENODATA;
}
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)
struct buffer_head *blk_bh)
{
struct ocfs2_xattr_block *xb;
- struct ocfs2_xattr_header *header;
int ret = 0;
xb = (struct ocfs2_xattr_block *)blk_bh->b_data;
- header = &(xb->xb_attrs.xb_header);
+ if (!(le16_to_cpu(xb->xb_flags) & OCFS2_XATTR_INDEXED)) {
+ struct ocfs2_xattr_header *header = &(xb->xb_attrs.xb_header);
+ ret = ocfs2_remove_value_outside(inode, blk_bh, header);
+ } else
+ ret = ocfs2_delete_xattr_index_block(inode, blk_bh);
+
+ 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);
- ret = ocfs2_remove_value_outside(inode, blk_bh, header);
+ 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;
}
*/
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;
int ret;
+ if (!ocfs2_supports_xattr(OCFS2_SB(inode->i_sb)))
+ return 0;
+
if (!(oi->ip_dyn_features & OCFS2_HAS_XATTR_FL))
return 0;
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;
}
.not_found = -ENODATA,
};
+ if (!ocfs2_supports_xattr(OCFS2_SB(inode->i_sb)))
+ return -EOPNOTSUPP;
+
ret = ocfs2_inode_lock(inode, &di_bh, 1);
if (ret < 0) {
mlog_errno(ret);
xe = &xh->xh_entries[start];
len = sizeof(struct ocfs2_xattr_entry) * (count - start);
mlog(0, "mv xattr entry len %d from %d to %d\n", len,
- (char *)xe - (char *)xh, (char *)xh->xh_entries - (char *)xh);
+ (int)((char *)xe - (char *)xh),
+ (int)((char *)xh->xh_entries - (char *)xh));
memmove((char *)xh->xh_entries, (char *)xe, len);
xe = &xh->xh_entries[count - start];
len = sizeof(struct ocfs2_xattr_entry) * start;
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;
u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
- mlog(0, "Set xattr entry len = %d index = %d in bucket %llu\n",
- xi->value_len, xi->name_index,
+ mlog(0, "Set xattr entry len = %lu index = %d in bucket %llu\n",
+ (unsigned long)xi->value_len, xi->name_index,
(unsigned long long)xs->bucket.bhs[0]->b_blocknr);
if (!xs->bucket.bhs[1]) {
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;
mlog_exit(ret);
return ret;
}
+
+static int ocfs2_delete_xattr_in_bucket(struct inode *inode,
+ struct ocfs2_xattr_bucket *bucket,
+ void *para)
+{
+ int ret = 0;
+ struct ocfs2_xattr_header *xh = bucket->xh;
+ u16 i;
+ struct ocfs2_xattr_entry *xe;
+
+ for (i = 0; i < le16_to_cpu(xh->xh_count); i++) {
+ xe = &xh->xh_entries[i];
+ if (ocfs2_xattr_is_local(xe))
+ continue;
+
+ ret = ocfs2_xattr_bucket_value_truncate(inode,
+ bucket->bhs[0],
+ i, 0);
+ if (ret) {
+ mlog_errno(ret);
+ break;
+ }
+ }
+
+ return ret;
+}
+
+static int ocfs2_delete_xattr_index_block(struct inode *inode,
+ struct buffer_head *xb_bh)
+{
+ struct ocfs2_xattr_block *xb =
+ (struct ocfs2_xattr_block *)xb_bh->b_data;
+ struct ocfs2_extent_list *el = &xb->xb_attrs.xb_root.xt_list;
+ int ret = 0;
+ u32 name_hash = UINT_MAX, e_cpos, num_clusters;
+ u64 p_blkno;
+
+ if (le16_to_cpu(el->l_next_free_rec) == 0)
+ return 0;
+
+ while (name_hash > 0) {
+ ret = ocfs2_xattr_get_rec(inode, name_hash, &p_blkno,
+ &e_cpos, &num_clusters, el);
+ if (ret) {
+ mlog_errno(ret);
+ goto out;
+ }
+
+ ret = ocfs2_iterate_xattr_buckets(inode, p_blkno, num_clusters,
+ ocfs2_delete_xattr_in_bucket,
+ NULL);
+ if (ret) {
+ mlog_errno(ret);
+ goto out;
+ }
+
+ ret = ocfs2_rm_xattr_cluster(inode, xb_bh,
+ p_blkno, e_cpos, num_clusters);
+ if (ret) {
+ mlog_errno(ret);
+ break;
+ }
+
+ if (e_cpos == 0)
+ break;
+
+ name_hash = e_cpos - 1;
+ }
+
+out:
+ return ret;
+}