-/*
- * Remove the xattr bucket pointed by bucket_bh.
- * All the buckets after it in the same xattr extent rec will be
- * move forward one by one.
- */
-static int ocfs2_rm_xattr_bucket(struct inode *inode,
- struct buffer_head *first_bh,
- struct ocfs2_xattr_bucket *bucket)
-{
- int ret = 0, credits;
- struct ocfs2_xattr_header *xh =
- (struct ocfs2_xattr_header *)first_bh->b_data;
- u16 bucket_num = le16_to_cpu(xh->xh_num_buckets);
- u64 end, start = bucket->bhs[0]->b_blocknr;
- struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
- handle_t *handle;
- u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
-
- end = first_bh->b_blocknr + (bucket_num - 1) * blk_per_bucket;
-
- mlog(0, "rm xattr bucket %llu\n", start);
- /*
- * We need to update the first xattr_header and all the buckets starting
- * from start in this xattr rec.
- *
- * XXX: Should we empty the old last bucket here?
- */
- credits = 1 + end - start;
- handle = ocfs2_start_trans(osb, credits);
- if (IS_ERR(handle)) {
- ret = PTR_ERR(handle);
- mlog_errno(ret);
- return ret;
- }
-
- ret = ocfs2_journal_access(handle, inode, first_bh,
- OCFS2_JOURNAL_ACCESS_WRITE);
- if (ret) {
- mlog_errno(ret);
- goto out_commit;
- }
-
-
- while (start < end) {
- ret = ocfs2_cp_xattr_bucket(inode, handle,
- start + blk_per_bucket,
- start, 0);
- if (ret) {
- mlog_errno(ret);
- goto out_commit;
- }
- start += blk_per_bucket;
- }
-
- /* update the first_bh. */
- xh->xh_num_buckets = cpu_to_le16(bucket_num - 1);
- ocfs2_journal_dirty(handle, first_bh);
-
-out_commit:
- ocfs2_commit_trans(osb, handle);
- return ret;
-}
-