Commit b5c03e74 authored by Joel Becker's avatar Joel Becker Committed by Mark Fasheh

ocfs2: Use ocfs2_cp_xattr_bucket() in ocfs2_mv_xattr_bucket_cross_cluster().

The buffer copy loop of ocfs2_mv_xattr_bucket_cross_cluster() actually
looks a lot like ocfs2_cp_xattr_bucket().  Let's just use that instead.
We also use bucket operations to update the buckets at the start of each
extent.
Signed-off-by: default avatarJoel Becker <joel.becker@oracle.com>
Signed-off-by: default avatarMark Fasheh <mfasheh@suse.com>
parent 2b656c1d
...@@ -170,6 +170,11 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode, ...@@ -170,6 +170,11 @@ static int ocfs2_xattr_set_entry_index_block(struct inode *inode,
static int ocfs2_delete_xattr_index_block(struct inode *inode, static int ocfs2_delete_xattr_index_block(struct inode *inode,
struct buffer_head *xb_bh); struct buffer_head *xb_bh);
static int ocfs2_cp_xattr_bucket(struct inode *inode,
handle_t *handle,
u64 s_blkno,
u64 t_blkno,
int t_is_new);
static inline u16 ocfs2_xattr_buckets_per_cluster(struct ocfs2_super *osb) static inline u16 ocfs2_xattr_buckets_per_cluster(struct ocfs2_super *osb)
{ {
...@@ -3526,13 +3531,21 @@ static int ocfs2_defrag_xattr_bucket(struct inode *inode, ...@@ -3526,13 +3531,21 @@ static int ocfs2_defrag_xattr_bucket(struct inode *inode,
} }
/* /*
* Move half nums of the xattr bucket in the previous cluster to this new * prev_blkno points to the start of an existing extent. new_blkno
* cluster. We only touch the last cluster of the previous extend record. * points to a newly allocated extent. Because we know each of our
* clusters contains more than bucket, we can easily split one cluster
* at a bucket boundary. So we take the last cluster of the existing
* extent and split it down the middle. We move the last half of the
* buckets in the last cluster of the existing extent over to the new
* extent.
*
* first_bh is the buffer at prev_blkno so we can update the existing
* extent's bucket count. header_bh is the bucket were we were hoping
* to insert our xattr. If the bucket move places the target in the new
* extent, we'll update first_bh and header_bh after modifying the old
* extent.
* *
* first_bh is the first buffer_head of a series of bucket in the same * first_hash will be set as the 1st xe's name_hash in the new extent.
* extent rec and header_bh is the header of one bucket in this cluster.
* They will be updated if we move the data header_bh contains to the new
* cluster. first_hash will be set as the 1st xe's name_hash of the new cluster.
*/ */
static int ocfs2_mv_xattr_bucket_cross_cluster(struct inode *inode, static int ocfs2_mv_xattr_bucket_cross_cluster(struct inode *inode,
handle_t *handle, handle_t *handle,
...@@ -3545,105 +3558,131 @@ static int ocfs2_mv_xattr_bucket_cross_cluster(struct inode *inode, ...@@ -3545,105 +3558,131 @@ static int ocfs2_mv_xattr_bucket_cross_cluster(struct inode *inode,
{ {
int i, ret, credits; int i, ret, credits;
struct ocfs2_super *osb = OCFS2_SB(inode->i_sb); struct ocfs2_super *osb = OCFS2_SB(inode->i_sb);
int blks_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
int bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1); int bpc = ocfs2_clusters_to_blocks(inode->i_sb, 1);
int num_buckets = ocfs2_xattr_buckets_per_cluster(osb); int num_buckets = ocfs2_xattr_buckets_per_cluster(osb);
int blocksize = inode->i_sb->s_blocksize; int to_move = num_buckets / 2;
struct buffer_head *old_bh, *new_bh, *prev_bh, *new_first_bh = NULL; u64 last_cluster_blkno, src_blkno;
struct ocfs2_xattr_header *new_xh;
struct ocfs2_xattr_header *xh = struct ocfs2_xattr_header *xh =
(struct ocfs2_xattr_header *)((*first_bh)->b_data); (struct ocfs2_xattr_header *)((*first_bh)->b_data);
struct ocfs2_xattr_bucket *old_first, *new_first;
BUG_ON(le16_to_cpu(xh->xh_num_buckets) < num_buckets); BUG_ON(le16_to_cpu(xh->xh_num_buckets) < num_buckets);
BUG_ON(OCFS2_XATTR_BUCKET_SIZE == osb->s_clustersize); BUG_ON(OCFS2_XATTR_BUCKET_SIZE == osb->s_clustersize);
prev_bh = *first_bh; last_cluster_blkno = prev_blkno + ((num_clusters - 1) * bpc);
get_bh(prev_bh); src_blkno = last_cluster_blkno + (to_move * blks_per_bucket);
xh = (struct ocfs2_xattr_header *)prev_bh->b_data;
prev_blkno += (num_clusters - 1) * bpc + bpc / 2;
mlog(0, "move half of xattrs in cluster %llu to %llu\n", mlog(0, "move half of xattrs in cluster %llu to %llu\n",
(unsigned long long)prev_blkno, (unsigned long long)new_blkno); (unsigned long long)prev_blkno, (unsigned long long)new_blkno);
/* The first bucket of the original extent */
old_first = ocfs2_xattr_bucket_new(inode);
/* The first bucket of the new extent */
new_first = ocfs2_xattr_bucket_new(inode);
if (!old_first || !new_first) {
ret = -ENOMEM;
mlog_errno(ret);
goto out;
}
ret = ocfs2_read_xattr_bucket(old_first, prev_blkno);
if (ret) {
mlog_errno(ret);
goto out;
}
/* /*
* We need to update the 1st half of the new cluster and * We need to update the 1st half of the new extent, and we
* 1 more for the update of the 1st bucket of the previous * need to update the first bucket of the old extent.
* extent record.
*/ */
credits = bpc / 2 + 1 + handle->h_buffer_credits; credits = ((to_move + 1) * blks_per_bucket) + handle->h_buffer_credits;
ret = ocfs2_extend_trans(handle, credits); ret = ocfs2_extend_trans(handle, credits);
if (ret) { if (ret) {
mlog_errno(ret); mlog_errno(ret);
goto out; goto out;
} }
ret = ocfs2_journal_access(handle, inode, prev_bh, ret = ocfs2_xattr_bucket_journal_access(handle, old_first,
OCFS2_JOURNAL_ACCESS_WRITE); OCFS2_JOURNAL_ACCESS_WRITE);
if (ret) { if (ret) {
mlog_errno(ret); mlog_errno(ret);
goto out; goto out;
} }
for (i = 0; i < bpc / 2; i++, prev_blkno++, new_blkno++) { for (i = 0; i < to_move; i++) {
old_bh = new_bh = NULL; ret = ocfs2_cp_xattr_bucket(inode, handle,
new_bh = sb_getblk(inode->i_sb, new_blkno); src_blkno + (i * blks_per_bucket),
if (!new_bh) { new_blkno + (i * blks_per_bucket),
ret = -EIO; 1);
if (ret) {
mlog_errno(ret); mlog_errno(ret);
goto out; goto out;
} }
}
ocfs2_set_new_buffer_uptodate(inode, new_bh); /*
* Get the new bucket ready before we dirty anything
ret = ocfs2_journal_access(handle, inode, new_bh, * (This actually shouldn't fail, because we already dirtied
OCFS2_JOURNAL_ACCESS_CREATE); * it once in ocfs2_cp_xattr_bucket()).
if (ret < 0) { */
ret = ocfs2_read_xattr_bucket(new_first, new_blkno);
if (ret) {
mlog_errno(ret); mlog_errno(ret);
brelse(new_bh);
goto out; goto out;
} }
ret = ocfs2_xattr_bucket_journal_access(handle, new_first,
ret = ocfs2_read_block(inode, prev_blkno, &old_bh, NULL); OCFS2_JOURNAL_ACCESS_WRITE);
if (ret < 0) { if (ret) {
mlog_errno(ret); mlog_errno(ret);
brelse(new_bh);
goto out; goto out;
} }
memcpy(new_bh->b_data, old_bh->b_data, blocksize); /* Now update the headers */
le16_add_cpu(&bucket_xh(old_first)->xh_num_buckets, -to_move);
ocfs2_xattr_bucket_journal_dirty(handle, old_first);
if (i == 0) { bucket_xh(new_first)->xh_num_buckets = cpu_to_le16(to_move);
new_xh = (struct ocfs2_xattr_header *)new_bh->b_data; ocfs2_xattr_bucket_journal_dirty(handle, new_first);
new_xh->xh_num_buckets = cpu_to_le16(num_buckets / 2);
if (first_hash) if (first_hash)
*first_hash = le32_to_cpu( *first_hash = le32_to_cpu(bucket_xh(new_first)->xh_entries[0].xe_name_hash);
new_xh->xh_entries[0].xe_name_hash);
new_first_bh = new_bh;
get_bh(new_first_bh);
}
ocfs2_journal_dirty(handle, new_bh); /*
* If the target bucket is anywhere past src_blkno, we moved
* it to the new extent. We need to update first_bh and header_bh.
*/
if ((*header_bh)->b_blocknr >= src_blkno) {
/* We're done with old_first, so we can re-use it. */
ocfs2_xattr_bucket_relse(old_first);
if (*header_bh == old_bh) { /* Find the block for the new target bucket */
brelse(*header_bh); src_blkno = new_blkno +
*header_bh = new_bh; ((*header_bh)->b_blocknr - src_blkno);
get_bh(*header_bh);
/*
* This shouldn't fail - the buffers are in the
* journal from ocfs2_cp_xattr_bucket().
*/
ret = ocfs2_read_xattr_bucket(old_first, src_blkno);
if (ret) {
mlog_errno(ret);
goto out;
}
brelse(*first_bh); brelse(*first_bh);
*first_bh = new_first_bh; *first_bh = new_first->bu_bhs[0];
get_bh(*first_bh); get_bh(*first_bh);
}
brelse(new_bh);
brelse(old_bh);
}
le16_add_cpu(&xh->xh_num_buckets, -(num_buckets / 2)); brelse(*header_bh);
*header_bh = old_first->bu_bhs[0];
get_bh(*header_bh);
}
ocfs2_journal_dirty(handle, prev_bh);
out: out:
brelse(prev_bh); ocfs2_xattr_bucket_free(new_first);
brelse(new_first_bh); ocfs2_xattr_bucket_free(old_first);
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