Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 165126
b: refs/heads/master
c: 5aea1f0
h: refs/heads/master
v: v3
  • Loading branch information
Tao Ma authored and Joel Becker committed Sep 23, 2009
1 parent e05078f commit e8997c3
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 46 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: fd68a894fc9641f816d9cffa58e853ba91cbc1a1
refs/heads/master: 5aea1f0ef4024ba28213c10181e1b16ec678c82d
115 changes: 70 additions & 45 deletions trunk/fs/ocfs2/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2105,6 +2105,72 @@ static int ocfs2_xattr_block_find(struct inode *inode,
return ret;
}

static int ocfs2_create_xattr_block(handle_t *handle,
struct inode *inode,
struct buffer_head *inode_bh,
struct ocfs2_alloc_context *meta_ac,
struct buffer_head **ret_bh)
{
int ret;
u16 suballoc_bit_start;
u32 num_got;
u64 first_blkno;
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;

ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode), inode_bh,
OCFS2_JOURNAL_ACCESS_CREATE);
if (ret < 0) {
mlog_errno(ret);
goto end;
}

ret = ocfs2_claim_metadata(osb, handle, meta_ac, 1,
&suballoc_bit_start, &num_got,
&first_blkno);
if (ret < 0) {
mlog_errno(ret);
goto end;
}

new_bh = sb_getblk(inode->i_sb, first_blkno);
ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), new_bh);

ret = ocfs2_journal_access_xb(handle, INODE_CACHE(inode),
new_bh,
OCFS2_JOURNAL_ACCESS_CREATE);
if (ret < 0) {
mlog_errno(ret);
goto end;
}

/* Initialize ocfs2_xattr_block */
xblk = (struct ocfs2_xattr_block *)new_bh->b_data;
memset(xblk, 0, inode->i_sb->s_blocksize);
strcpy((void *)xblk, OCFS2_XATTR_BLOCK_SIGNATURE);
xblk->xb_suballoc_slot = cpu_to_le16(osb->slot_num);
xblk->xb_suballoc_bit = cpu_to_le16(suballoc_bit_start);
xblk->xb_fs_generation = cpu_to_le32(osb->fs_generation);
xblk->xb_blkno = cpu_to_le64(first_blkno);

ret = ocfs2_journal_dirty(handle, new_bh);
if (ret < 0) {
mlog_errno(ret);
goto end;
}
di->i_xattr_loc = cpu_to_le64(first_blkno);
ocfs2_journal_dirty(handle, inode_bh);

*ret_bh = new_bh;
new_bh = NULL;

end:
brelse(new_bh);
return ret;
}

/*
* ocfs2_xattr_block_set()
*
Expand All @@ -2117,65 +2183,24 @@ static int ocfs2_xattr_block_set(struct inode *inode,
struct ocfs2_xattr_set_ctxt *ctxt)
{
struct buffer_head *new_bh = NULL;
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;
u32 num_got;
u64 first_blkno;
int ret;

if (!xs->xattr_bh) {
ret = ocfs2_journal_access_di(handle, INODE_CACHE(inode),
xs->inode_bh,
OCFS2_JOURNAL_ACCESS_CREATE);
if (ret < 0) {
mlog_errno(ret);
goto end;
}

ret = ocfs2_claim_metadata(osb, handle, ctxt->meta_ac, 1,
&suballoc_bit_start, &num_got,
&first_blkno);
if (ret < 0) {
mlog_errno(ret);
goto end;
}

new_bh = sb_getblk(inode->i_sb, first_blkno);
ocfs2_set_new_buffer_uptodate(INODE_CACHE(inode), new_bh);

ret = ocfs2_journal_access_xb(handle, INODE_CACHE(inode),
new_bh,
OCFS2_JOURNAL_ACCESS_CREATE);
if (ret < 0) {
ret = ocfs2_create_xattr_block(handle, inode, xs->inode_bh,
ctxt->meta_ac, &new_bh);
if (ret) {
mlog_errno(ret);
goto end;
}

/* Initialize ocfs2_xattr_block */
xs->xattr_bh = new_bh;
xblk = (struct ocfs2_xattr_block *)new_bh->b_data;
memset(xblk, 0, inode->i_sb->s_blocksize);
strcpy((void *)xblk, OCFS2_XATTR_BLOCK_SIGNATURE);
xblk->xb_suballoc_slot = cpu_to_le16(osb->slot_num);
xblk->xb_suballoc_bit = cpu_to_le16(suballoc_bit_start);
xblk->xb_fs_generation = cpu_to_le32(osb->fs_generation);
xblk->xb_blkno = cpu_to_le64(first_blkno);

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;

ret = ocfs2_journal_dirty(handle, new_bh);
if (ret < 0) {
mlog_errno(ret);
goto end;
}
di->i_xattr_loc = cpu_to_le64(first_blkno);
ocfs2_journal_dirty(handle, xs->inode_bh);
} else
xblk = (struct ocfs2_xattr_block *)xs->xattr_bh->b_data;

Expand Down

0 comments on commit e8997c3

Please sign in to comment.