Skip to content

Commit

Permalink
ocfs2: Gell into ocfs2_xa_set()
Browse files Browse the repository at this point in the history
ocfs2_xa_set() wraps the ocfs2_xa_prepare_entry()/ocfs2_xa_store_value()
logic.  Both callers can now use the same routine.  ocfs2_xa_remove()
moves directly into ocfs2_xa_set().

Signed-off-by: Joel Becker <joel.becker@oracle.com>
  • Loading branch information
Joel Becker committed Feb 26, 2010
1 parent 73857ee commit bca5e9b
Showing 1 changed file with 42 additions and 46 deletions.
88 changes: 42 additions & 46 deletions fs/ocfs2/xattr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2017,8 +2017,6 @@ static int ocfs2_xa_reuse_entry(struct ocfs2_xa_loc *loc,
* Prepares loc->xl_entry to receive the new xattr. This includes
* properly setting up the name+value pair region. If loc->xl_entry
* already exists, it will take care of modifying it appropriately.
* This also includes deleting entries, but don't call this to remove
* a non-existant entry. That's just a bug.
*
* Note that this modifies the data. You did journal_access already,
* right?
Expand All @@ -2030,11 +2028,6 @@ static int ocfs2_xa_prepare_entry(struct ocfs2_xa_loc *loc,
{
int rc = 0;

if (!xi->xi_value) {
rc = ocfs2_xa_remove(loc, ctxt);
goto out;
}

rc = ocfs2_xa_check_space(loc, xi);
if (rc)
goto out;
Expand Down Expand Up @@ -2092,9 +2085,6 @@ static int ocfs2_xa_store_value(struct ocfs2_xa_loc *loc,
char *nameval_buf;
struct ocfs2_xattr_value_buf vb;

if (!xi->xi_value)
goto out;

nameval_buf = ocfs2_xa_offset_pointer(loc, nameval_offset);
if (xi->xi_value_len > OCFS2_XATTR_INLINE_SIZE) {
ocfs2_xa_fill_value_buf(loc, &vb);
Expand All @@ -2105,10 +2095,49 @@ static int ocfs2_xa_store_value(struct ocfs2_xa_loc *loc,
} else
memcpy(nameval_buf + name_size, xi->xi_value, xi->xi_value_len);

out:
return rc;
}

static int ocfs2_xa_set(struct ocfs2_xa_loc *loc,
struct ocfs2_xattr_info *xi,
struct ocfs2_xattr_set_ctxt *ctxt)
{
int ret;
u32 name_hash = ocfs2_xattr_name_hash(loc->xl_inode, xi->xi_name,
xi->xi_name_len);

ret = ocfs2_xa_journal_access(ctxt->handle, loc,
OCFS2_JOURNAL_ACCESS_WRITE);
if (ret) {
mlog_errno(ret);
goto out;
}

/* Don't worry, we are never called with !xi_value and !xl_entry */
if (!xi->xi_value) {
ret = ocfs2_xa_remove(loc, ctxt);
goto out;
}

ret = ocfs2_xa_prepare_entry(loc, xi, name_hash, ctxt);
if (ret) {
if (ret != -ENOSPC)
mlog_errno(ret);
goto out;
}

ret = ocfs2_xa_store_value(loc, xi, ctxt);
if (ret) {
mlog_errno(ret);
goto out;
}

ocfs2_xa_journal_dirty(ctxt->handle, loc);

out:
return ret;
}

static void ocfs2_init_dinode_xa_loc(struct ocfs2_xa_loc *loc,
struct inode *inode,
struct buffer_head *bh,
Expand Down Expand Up @@ -2183,8 +2212,6 @@ static int ocfs2_xattr_set_entry(struct inode *inode,
struct ocfs2_dinode *di = (struct ocfs2_dinode *)xs->inode_bh->b_data;
handle_t *handle = ctxt->handle;
int ret;
u32 name_hash = ocfs2_xattr_name_hash(inode, xi->xi_name,
xi->xi_name_len);
struct ocfs2_xa_loc loc;

if (!(flag & OCFS2_INLINE_XATTR_FL))
Expand All @@ -2205,29 +2232,15 @@ static int ocfs2_xattr_set_entry(struct inode *inode,
else
ocfs2_init_xattr_block_xa_loc(&loc, inode, xs->xattr_bh,
xs->not_found ? NULL : xs->here);
ret = ocfs2_xa_journal_access(handle, &loc,
OCFS2_JOURNAL_ACCESS_WRITE);
if (ret) {
mlog_errno(ret);
goto out;
}

ret = ocfs2_xa_prepare_entry(&loc, xi, name_hash, ctxt);
ret = ocfs2_xa_set(&loc, xi, ctxt);
if (ret) {
if (ret != -ENOSPC)
mlog_errno(ret);
goto out;
}
xs->here = loc.xl_entry;

ret = ocfs2_xa_store_value(&loc, xi, ctxt);
if (ret) {
mlog_errno(ret);
goto out;
}

ocfs2_xa_journal_dirty(handle, &loc);

if (!(oi->ip_dyn_features & OCFS2_INLINE_XATTR_FL) &&
(flag & OCFS2_INLINE_XATTR_FL)) {
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
Expand Down Expand Up @@ -5415,8 +5428,6 @@ static int ocfs2_xattr_set_in_bucket(struct inode *inode,
int ret;
u64 blkno;
struct ocfs2_xa_loc loc;
u32 name_hash = ocfs2_xattr_name_hash(inode, xi->xi_name,
xi->xi_name_len);

if (!xs->bucket->bu_bhs[1]) {
blkno = bucket_blkno(xs->bucket);
Expand All @@ -5430,29 +5441,14 @@ static int ocfs2_xattr_set_in_bucket(struct inode *inode,

ocfs2_init_xattr_bucket_xa_loc(&loc, xs->bucket,
xs->not_found ? NULL : xs->here);
ret = ocfs2_xa_journal_access(ctxt->handle, &loc,
OCFS2_JOURNAL_ACCESS_WRITE);
if (ret < 0) {
mlog_errno(ret);
goto out;
}

ret = ocfs2_xa_prepare_entry(&loc, xi, name_hash, ctxt);
ret = ocfs2_xa_set(&loc, xi, ctxt);
if (ret) {
if (ret != -ENOSPC)
mlog_errno(ret);
goto out;
}
xs->here = loc.xl_entry;

ret = ocfs2_xa_store_value(&loc, xi, ctxt);
if (ret) {
mlog_errno(ret);
goto out;
}

ocfs2_xa_journal_dirty(ctxt->handle, &loc);

out:
return ret;
}
Expand Down

0 comments on commit bca5e9b

Please sign in to comment.