Commit 161d6f30 authored by Joel Becker's avatar Joel Becker Committed by Mark Fasheh

ocfs2: Use buckets in ocfs2_defrag_xattr_bucket().

Use the ocfs2_xattr_bucket abstraction for reading and writing the
bucket in ocfs2_defrag_xattr_bucket().
Signed-off-by: default avatarJoel Becker <joel.becker@oracle.com>
Signed-off-by: default avatarMark Fasheh <mfasheh@suse.com>
parent 178eeac3
...@@ -2894,21 +2894,11 @@ static int ocfs2_defrag_xattr_bucket(struct inode *inode, ...@@ -2894,21 +2894,11 @@ static int ocfs2_defrag_xattr_bucket(struct inode *inode,
struct ocfs2_xattr_header *xh; struct ocfs2_xattr_header *xh;
char *entries, *buf, *bucket_buf = NULL; char *entries, *buf, *bucket_buf = NULL;
u64 blkno = bucket_blkno(bucket); u64 blkno = bucket_blkno(bucket);
u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
u16 xh_free_start; u16 xh_free_start;
size_t blocksize = inode->i_sb->s_blocksize; size_t blocksize = inode->i_sb->s_blocksize;
handle_t *handle; handle_t *handle;
struct buffer_head **bhs;
struct ocfs2_xattr_entry *xe; struct ocfs2_xattr_entry *xe;
struct ocfs2_xattr_bucket *wb = NULL;
bhs = kzalloc(sizeof(struct buffer_head *) * blk_per_bucket,
GFP_NOFS);
if (!bhs)
return -ENOMEM;
ret = ocfs2_read_blocks(inode, blkno, blk_per_bucket, bhs, 0);
if (ret)
goto out;
/* /*
* In order to make the operation more efficient and generic, * In order to make the operation more efficient and generic,
...@@ -2922,11 +2912,21 @@ static int ocfs2_defrag_xattr_bucket(struct inode *inode, ...@@ -2922,11 +2912,21 @@ static int ocfs2_defrag_xattr_bucket(struct inode *inode,
goto out; goto out;
} }
wb = ocfs2_xattr_bucket_new(inode);
if (!wb) {
ret = -ENOMEM;
goto out;
}
ret = ocfs2_read_xattr_bucket(wb, blkno);
if (ret)
goto out;
buf = bucket_buf; buf = bucket_buf;
for (i = 0; i < blk_per_bucket; i++, buf += blocksize) for (i = 0; i < wb->bu_blocks; i++, buf += blocksize)
memcpy(buf, bhs[i]->b_data, blocksize); memcpy(buf, bucket_block(wb, i), blocksize);
handle = ocfs2_start_trans((OCFS2_SB(inode->i_sb)), blk_per_bucket); handle = ocfs2_start_trans((OCFS2_SB(inode->i_sb)), wb->bu_blocks);
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
ret = PTR_ERR(handle); ret = PTR_ERR(handle);
handle = NULL; handle = NULL;
...@@ -2934,13 +2934,11 @@ static int ocfs2_defrag_xattr_bucket(struct inode *inode, ...@@ -2934,13 +2934,11 @@ static int ocfs2_defrag_xattr_bucket(struct inode *inode,
goto out; goto out;
} }
for (i = 0; i < blk_per_bucket; i++) { ret = ocfs2_xattr_bucket_journal_access(handle, wb,
ret = ocfs2_journal_access(handle, inode, bhs[i], OCFS2_JOURNAL_ACCESS_WRITE);
OCFS2_JOURNAL_ACCESS_WRITE); if (ret < 0) {
if (ret < 0) { mlog_errno(ret);
mlog_errno(ret); goto commit;
goto commit;
}
} }
xh = (struct ocfs2_xattr_header *)bucket_buf; xh = (struct ocfs2_xattr_header *)bucket_buf;
...@@ -3009,21 +3007,14 @@ static int ocfs2_defrag_xattr_bucket(struct inode *inode, ...@@ -3009,21 +3007,14 @@ static int ocfs2_defrag_xattr_bucket(struct inode *inode,
cmp_xe, swap_xe); cmp_xe, swap_xe);
buf = bucket_buf; buf = bucket_buf;
for (i = 0; i < blk_per_bucket; i++, buf += blocksize) { for (i = 0; i < wb->bu_blocks; i++, buf += blocksize)
memcpy(bhs[i]->b_data, buf, blocksize); memcpy(bucket_block(wb, i), buf, blocksize);
ocfs2_journal_dirty(handle, bhs[i]); ocfs2_xattr_bucket_journal_dirty(handle, wb);
}
commit: commit:
ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle); ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);
out: out:
ocfs2_xattr_bucket_free(wb);
if (bhs) {
for (i = 0; i < blk_per_bucket; i++)
brelse(bhs[i]);
}
kfree(bhs);
kfree(bucket_buf); kfree(bucket_buf);
return ret; return ret;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment