Commit 1224be02 authored by Joel Becker's avatar Joel Becker Committed by Mark Fasheh

ocfs2: Wrap journal_access/journal_dirty for xattr buckets.

A common action is to call ocfs2_journal_access() and
ocfs2_journal_dirty() on the buffer heads of an xattr bucket.  Let's
create nice wrappers.

While we're there, let's drop the places that try to be smart by writing
only the first and last blocks of a bucket.  A bucket is contiguous, so
writing the whole thing is actually more efficient.
Signed-off-by: default avatarJoel Becker <joel.becker@oracle.com>
Signed-off-by: default avatarMark Fasheh <mfasheh@suse.com>
parent 784b816a
...@@ -210,6 +210,37 @@ static int ocfs2_read_xattr_bucket(struct inode *inode, ...@@ -210,6 +210,37 @@ static int ocfs2_read_xattr_bucket(struct inode *inode,
return rc; return rc;
} }
static int ocfs2_xattr_bucket_journal_access(handle_t *handle,
struct inode *inode,
struct ocfs2_xattr_bucket *bucket,
int type)
{
int i, rc = 0;
int blks = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
for (i = 0; i < blks; i++) {
rc = ocfs2_journal_access(handle, inode,
bucket->bu_bhs[i], type);
if (rc) {
mlog_errno(rc);
break;
}
}
return rc;
}
static void ocfs2_xattr_bucket_journal_dirty(handle_t *handle,
struct inode *inode,
struct ocfs2_xattr_bucket *bucket)
{
int i, blks = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
for (i = 0; i < blks; i++)
ocfs2_journal_dirty(handle, bucket->bu_bhs[i]);
}
static inline const char *ocfs2_xattr_prefix(int name_index) static inline const char *ocfs2_xattr_prefix(int name_index)
{ {
struct xattr_handler *handler = NULL; struct xattr_handler *handler = NULL;
...@@ -3218,7 +3249,7 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode, ...@@ -3218,7 +3249,7 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode,
goto out; goto out;
} }
ret = ocfs2_journal_access(handle, inode, s_bucket.bu_bhs[0], ret = ocfs2_xattr_bucket_journal_access(handle, inode, &s_bucket,
OCFS2_JOURNAL_ACCESS_WRITE); OCFS2_JOURNAL_ACCESS_WRITE);
if (ret) { if (ret) {
mlog_errno(ret); mlog_errno(ret);
...@@ -3235,8 +3266,7 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode, ...@@ -3235,8 +3266,7 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode,
goto out; goto out;
} }
for (i = 0; i < blk_per_bucket; i++) { ret = ocfs2_xattr_bucket_journal_access(handle, inode, &t_bucket,
ret = ocfs2_journal_access(handle, inode, t_bucket.bu_bhs[i],
new_bucket_head ? new_bucket_head ?
OCFS2_JOURNAL_ACCESS_CREATE : OCFS2_JOURNAL_ACCESS_CREATE :
OCFS2_JOURNAL_ACCESS_WRITE); OCFS2_JOURNAL_ACCESS_WRITE);
...@@ -3244,7 +3274,6 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode, ...@@ -3244,7 +3274,6 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode,
mlog_errno(ret); mlog_errno(ret);
goto out; goto out;
} }
}
xh = bucket_xh(&s_bucket); xh = bucket_xh(&s_bucket);
count = le16_to_cpu(xh->xh_count); count = le16_to_cpu(xh->xh_count);
...@@ -3339,11 +3368,7 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode, ...@@ -3339,11 +3368,7 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode,
else else
xh->xh_num_buckets = 0; xh->xh_num_buckets = 0;
for (i = 0; i < blk_per_bucket; i++) { ocfs2_xattr_bucket_journal_dirty(handle, inode, &t_bucket);
ocfs2_journal_dirty(handle, t_bucket.bu_bhs[i]);
if (ret)
mlog_errno(ret);
}
/* store the first_hash of the new bucket. */ /* store the first_hash of the new bucket. */
if (first_hash) if (first_hash)
...@@ -3364,9 +3389,7 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode, ...@@ -3364,9 +3389,7 @@ static int ocfs2_divide_xattr_bucket(struct inode *inode,
xh->xh_free_start = cpu_to_le16(name_offset); xh->xh_free_start = cpu_to_le16(name_offset);
xh->xh_name_value_len = cpu_to_le16(name_value_len); xh->xh_name_value_len = cpu_to_le16(name_value_len);
ocfs2_journal_dirty(handle, s_bucket.bu_bhs[0]); ocfs2_xattr_bucket_journal_dirty(handle, inode, &s_bucket);
if (ret)
mlog_errno(ret);
out: out:
ocfs2_xattr_bucket_relse(inode, &s_bucket); ocfs2_xattr_bucket_relse(inode, &s_bucket);
...@@ -3413,20 +3436,18 @@ static int ocfs2_cp_xattr_bucket(struct inode *inode, ...@@ -3413,20 +3436,18 @@ static int ocfs2_cp_xattr_bucket(struct inode *inode,
if (ret) if (ret)
goto out; goto out;
for (i = 0; i < blk_per_bucket; i++) { ret = ocfs2_xattr_bucket_journal_access(handle, inode, &t_bucket,
ret = ocfs2_journal_access(handle, inode, t_bucket.bu_bhs[i],
t_is_new ? t_is_new ?
OCFS2_JOURNAL_ACCESS_CREATE : OCFS2_JOURNAL_ACCESS_CREATE :
OCFS2_JOURNAL_ACCESS_WRITE); OCFS2_JOURNAL_ACCESS_WRITE);
if (ret) if (ret)
goto out; goto out;
}
for (i = 0; i < blk_per_bucket; i++) { for (i = 0; i < blk_per_bucket; i++) {
memcpy(bucket_block(&t_bucket, i), bucket_block(&s_bucket, i), memcpy(bucket_block(&t_bucket, i), bucket_block(&s_bucket, i),
blocksize); blocksize);
ocfs2_journal_dirty(handle, t_bucket.bu_bhs[i]);
} }
ocfs2_xattr_bucket_journal_dirty(handle, inode, &t_bucket);
out: out:
ocfs2_xattr_bucket_relse(inode, &s_bucket); ocfs2_xattr_bucket_relse(inode, &s_bucket);
...@@ -3799,9 +3820,9 @@ static int ocfs2_extend_xattr_bucket(struct inode *inode, ...@@ -3799,9 +3820,9 @@ static int ocfs2_extend_xattr_bucket(struct inode *inode,
/* /*
* We will touch all the buckets after the start_bh(include it). * We will touch all the buckets after the start_bh(include it).
* Add one more bucket and modify the first_bh. * Then we add one more bucket.
*/ */
credits = end_blk - start_blk + 2 * blk_per_bucket + 1; credits = end_blk - start_blk + 3 * blk_per_bucket + 1;
handle = ocfs2_start_trans(osb, credits); handle = ocfs2_start_trans(osb, credits);
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
ret = PTR_ERR(handle); ret = PTR_ERR(handle);
...@@ -4077,33 +4098,6 @@ static void ocfs2_xattr_set_entry_normal(struct inode *inode, ...@@ -4077,33 +4098,6 @@ static void ocfs2_xattr_set_entry_normal(struct inode *inode,
return; return;
} }
static int ocfs2_xattr_bucket_handle_journal(struct inode *inode,
handle_t *handle,
struct ocfs2_xattr_search *xs,
struct buffer_head **bhs,
u16 bh_num)
{
int ret = 0, off, block_off;
struct ocfs2_xattr_entry *xe = xs->here;
/*
* First calculate all the blocks we should journal_access
* and journal_dirty. The first block should always be touched.
*/
ret = ocfs2_journal_dirty(handle, bhs[0]);
if (ret)
mlog_errno(ret);
/* calc the data. */
off = le16_to_cpu(xe->xe_name_offset);
block_off = off >> inode->i_sb->s_blocksize_bits;
ret = ocfs2_journal_dirty(handle, bhs[block_off]);
if (ret)
mlog_errno(ret);
return ret;
}
/* /*
* Set the xattr entry in the specified bucket. * Set the xattr entry in the specified bucket.
* The bucket is indicated by xs->bucket and it should have the enough * The bucket is indicated by xs->bucket and it should have the enough
...@@ -4115,7 +4109,7 @@ static int ocfs2_xattr_set_entry_in_bucket(struct inode *inode, ...@@ -4115,7 +4109,7 @@ static int ocfs2_xattr_set_entry_in_bucket(struct inode *inode,
u32 name_hash, u32 name_hash,
int local) int local)
{ {
int i, ret; int ret;
handle_t *handle = NULL; handle_t *handle = NULL;
u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb); u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
...@@ -4143,22 +4137,16 @@ static int ocfs2_xattr_set_entry_in_bucket(struct inode *inode, ...@@ -4143,22 +4137,16 @@ static int ocfs2_xattr_set_entry_in_bucket(struct inode *inode,
goto out; goto out;
} }
for (i = 0; i < blk_per_bucket; i++) { ret = ocfs2_xattr_bucket_journal_access(handle, inode, &xs->bucket,
ret = ocfs2_journal_access(handle, inode, xs->bucket.bu_bhs[i],
OCFS2_JOURNAL_ACCESS_WRITE); OCFS2_JOURNAL_ACCESS_WRITE);
if (ret < 0) { if (ret < 0) {
mlog_errno(ret); mlog_errno(ret);
goto out; goto out;
} }
}
ocfs2_xattr_set_entry_normal(inode, xi, xs, name_hash, local); ocfs2_xattr_set_entry_normal(inode, xi, xs, name_hash, local);
ocfs2_xattr_bucket_journal_dirty(handle, inode, &xs->bucket);
/*Only dirty the blocks we have touched in set xattr. */
ret = ocfs2_xattr_bucket_handle_journal(inode, handle, xs,
xs->bucket.bu_bhs, blk_per_bucket);
if (ret)
mlog_errno(ret);
out: out:
ocfs2_commit_trans(osb, handle); ocfs2_commit_trans(osb, handle);
...@@ -4398,14 +4386,15 @@ static void ocfs2_xattr_bucket_remove_xs(struct inode *inode, ...@@ -4398,14 +4386,15 @@ static void ocfs2_xattr_bucket_remove_xs(struct inode *inode,
le16_to_cpu(xh->xh_count) - 1]; le16_to_cpu(xh->xh_count) - 1];
int ret = 0; int ret = 0;
handle = ocfs2_start_trans((OCFS2_SB(inode->i_sb)), 1); handle = ocfs2_start_trans((OCFS2_SB(inode->i_sb)),
ocfs2_blocks_per_xattr_bucket(inode->i_sb));
if (IS_ERR(handle)) { if (IS_ERR(handle)) {
ret = PTR_ERR(handle); ret = PTR_ERR(handle);
mlog_errno(ret); mlog_errno(ret);
return; return;
} }
ret = ocfs2_journal_access(handle, inode, xs->bucket.bu_bhs[0], ret = ocfs2_xattr_bucket_journal_access(handle, inode, &xs->bucket,
OCFS2_JOURNAL_ACCESS_WRITE); OCFS2_JOURNAL_ACCESS_WRITE);
if (ret) { if (ret) {
mlog_errno(ret); mlog_errno(ret);
...@@ -4418,9 +4407,8 @@ static void ocfs2_xattr_bucket_remove_xs(struct inode *inode, ...@@ -4418,9 +4407,8 @@ static void ocfs2_xattr_bucket_remove_xs(struct inode *inode,
memset(last, 0, sizeof(struct ocfs2_xattr_entry)); memset(last, 0, sizeof(struct ocfs2_xattr_entry));
le16_add_cpu(&xh->xh_count, -1); le16_add_cpu(&xh->xh_count, -1);
ret = ocfs2_journal_dirty(handle, xs->bucket.bu_bhs[0]); ocfs2_xattr_bucket_journal_dirty(handle, inode, &xs->bucket);
if (ret < 0)
mlog_errno(ret);
out_commit: out_commit:
ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle); ocfs2_commit_trans(OCFS2_SB(inode->i_sb), handle);
} }
......
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