ocfs2: Abstract the creation of xattr block.
In xattr reflink, we also need to create xattr block, so abstract the process out. Signed-off-by: Tao Ma <tao.ma@oracle.com>
This commit is contained in:
parent
fd68a894fc
commit
5aea1f0ef4
|
@ -2105,37 +2105,29 @@ cleanup:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
static int ocfs2_create_xattr_block(handle_t *handle,
|
||||||
* ocfs2_xattr_block_set()
|
struct inode *inode,
|
||||||
*
|
struct buffer_head *inode_bh,
|
||||||
* Set, replace or remove an extended attribute into external block.
|
struct ocfs2_alloc_context *meta_ac,
|
||||||
*
|
struct buffer_head **ret_bh)
|
||||||
*/
|
|
||||||
static int ocfs2_xattr_block_set(struct inode *inode,
|
|
||||||
struct ocfs2_xattr_info *xi,
|
|
||||||
struct ocfs2_xattr_search *xs,
|
|
||||||
struct ocfs2_xattr_set_ctxt *ctxt)
|
|
||||||
{
|
{
|
||||||
struct buffer_head *new_bh = NULL;
|
int ret;
|
||||||
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
|
|
||||||
struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data;
|
|
||||||
handle_t *handle = ctxt->handle;
|
|
||||||
struct ocfs2_xattr_block *xblk = NULL;
|
|
||||||
u16 suballoc_bit_start;
|
u16 suballoc_bit_start;
|
||||||
u32 num_got;
|
u32 num_got;
|
||||||
u64 first_blkno;
|
u64 first_blkno;
|
||||||
int ret;
|
struct ocfs2_dinode *di = (struct ocfs2_dinode *)inode_bh->b_data;
|
||||||
|
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
|
||||||
|
struct buffer_head *new_bh = NULL;
|
||||||
|
struct ocfs2_xattr_block *xblk;
|
||||||
|
|
||||||
if (!xs->xattr_bh) {
|
ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), inode_bh,
|
||||||
ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode),
|
|
||||||
xs->inode_bh,
|
|
||||||
OCFS2_JOURNAL_ACCESS_CREATE);
|
OCFS2_JOURNAL_ACCESS_CREATE);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
mlog_errno(ret);
|
mlog_errno(ret);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = ocfs2_claim_metadata(osb, handle, ctxt->meta_ac, 1,
|
ret = ocfs2_claim_metadata(osb, handle, meta_ac, 1,
|
||||||
&suballoc_bit_start, &num_got,
|
&suballoc_bit_start, &num_got,
|
||||||
&first_blkno);
|
&first_blkno);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
@ -2155,7 +2147,6 @@ static int ocfs2_xattr_block_set(struct inode *inode,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize ocfs2_xattr_block */
|
/* Initialize ocfs2_xattr_block */
|
||||||
xs->xattr_bh = new_bh;
|
|
||||||
xblk = (struct ocfs2_xattr_block *)new_bh->b_data;
|
xblk = (struct ocfs2_xattr_block *)new_bh->b_data;
|
||||||
memset(xblk, 0, inode->i_sb->s_blocksize);
|
memset(xblk, 0, inode->i_sb->s_blocksize);
|
||||||
strcpy((void *)xblk, OCFS2_XATTR_BLOCK_SIGNATURE);
|
strcpy((void *)xblk, OCFS2_XATTR_BLOCK_SIGNATURE);
|
||||||
|
@ -2164,18 +2155,52 @@ static int ocfs2_xattr_block_set(struct inode *inode,
|
||||||
xblk->xb_fs_generation = cpu_to_le32(osb->fs_generation);
|
xblk->xb_fs_generation = cpu_to_le32(osb->fs_generation);
|
||||||
xblk->xb_blkno = cpu_to_le64(first_blkno);
|
xblk->xb_blkno = cpu_to_le64(first_blkno);
|
||||||
|
|
||||||
xs->header = &xblk->xb_attrs.xb_header;
|
|
||||||
xs->base = (void *)xs->header;
|
|
||||||
xs->end = (void *)xblk + inode->i_sb->s_blocksize;
|
|
||||||
xs->here = xs->header->xh_entries;
|
|
||||||
|
|
||||||
ret = ocfs2_journal_dirty(handle, new_bh);
|
ret = ocfs2_journal_dirty(handle, new_bh);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
mlog_errno(ret);
|
mlog_errno(ret);
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
di->i_xattr_loc = cpu_to_le64(first_blkno);
|
di->i_xattr_loc = cpu_to_le64(first_blkno);
|
||||||
ocfs2_journal_dirty(handle, xs->inode_bh);
|
ocfs2_journal_dirty(handle, inode_bh);
|
||||||
|
|
||||||
|
*ret_bh = new_bh;
|
||||||
|
new_bh = NULL;
|
||||||
|
|
||||||
|
end:
|
||||||
|
brelse(new_bh);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ocfs2_xattr_block_set()
|
||||||
|
*
|
||||||
|
* Set, replace or remove an extended attribute into external block.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static int ocfs2_xattr_block_set(struct inode *inode,
|
||||||
|
struct ocfs2_xattr_info *xi,
|
||||||
|
struct ocfs2_xattr_search *xs,
|
||||||
|
struct ocfs2_xattr_set_ctxt *ctxt)
|
||||||
|
{
|
||||||
|
struct buffer_head *new_bh = NULL;
|
||||||
|
handle_t *handle = ctxt->handle;
|
||||||
|
struct ocfs2_xattr_block *xblk = NULL;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
if (!xs->xattr_bh) {
|
||||||
|
ret = ocfs2_create_xattr_block(handle, inode, xs->inode_bh,
|
||||||
|
ctxt->meta_ac, &new_bh);
|
||||||
|
if (ret) {
|
||||||
|
mlog_errno(ret);
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
xs->xattr_bh = new_bh;
|
||||||
|
xblk = (struct ocfs2_xattr_block *)xs->xattr_bh->b_data;
|
||||||
|
xs->header = &xblk->xb_attrs.xb_header;
|
||||||
|
xs->base = (void *)xs->header;
|
||||||
|
xs->end = (void *)xblk + inode->i_sb->s_blocksize;
|
||||||
|
xs->here = xs->header->xh_entries;
|
||||||
} else
|
} else
|
||||||
xblk = (struct ocfs2_xattr_block *)xs->xattr_bh->b_data;
|
xblk = (struct ocfs2_xattr_block *)xs->xattr_bh->b_data;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue