Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3e19a25e authored by Tristan Ye's avatar Tristan Ye
Browse files

Ocfs2/refcounttree: Publicize couple of funcs from refcounttree.c



The original goal of commonizing these funcs is to benefit defraging/extent_moving
codes in the future,  based on the fact that reflink and defragmentation having
the same Copy-On-Wrtie mechanism.

Signed-off-by: default avatarTristan Ye <tristan.ye@oracle.com>
parent d24a10b9
Loading
Loading
Loading
Loading
+29 −29
Original line number Original line Diff line number Diff line
@@ -66,7 +66,7 @@ struct ocfs2_cow_context {
			    u32 *num_clusters,
			    u32 *num_clusters,
			    unsigned int *extent_flags);
			    unsigned int *extent_flags);
	int (*cow_duplicate_clusters)(handle_t *handle,
	int (*cow_duplicate_clusters)(handle_t *handle,
				      struct ocfs2_cow_context *context,
				      struct file *file,
				      u32 cpos, u32 old_cluster,
				      u32 cpos, u32 old_cluster,
				      u32 new_cluster, u32 new_len);
				      u32 new_cluster, u32 new_len);
};
};
@@ -2921,20 +2921,21 @@ static int ocfs2_clear_cow_buffer(handle_t *handle, struct buffer_head *bh)
	return 0;
	return 0;
}
}


static int ocfs2_duplicate_clusters_by_page(handle_t *handle,
int ocfs2_duplicate_clusters_by_page(handle_t *handle,
					    struct ocfs2_cow_context *context,
				     struct file *file,
				     u32 cpos, u32 old_cluster,
				     u32 cpos, u32 old_cluster,
				     u32 new_cluster, u32 new_len)
				     u32 new_cluster, u32 new_len)
{
{
	int ret = 0, partial;
	int ret = 0, partial;
	struct ocfs2_caching_info *ci = context->data_et.et_ci;
	struct inode *inode = file->f_path.dentry->d_inode;
	struct ocfs2_caching_info *ci = INODE_CACHE(inode);
	struct super_block *sb = ocfs2_metadata_cache_get_super(ci);
	struct super_block *sb = ocfs2_metadata_cache_get_super(ci);
	u64 new_block = ocfs2_clusters_to_blocks(sb, new_cluster);
	u64 new_block = ocfs2_clusters_to_blocks(sb, new_cluster);
	struct page *page;
	struct page *page;
	pgoff_t page_index;
	pgoff_t page_index;
	unsigned int from, to, readahead_pages;
	unsigned int from, to, readahead_pages;
	loff_t offset, end, map_end;
	loff_t offset, end, map_end;
	struct address_space *mapping = context->inode->i_mapping;
	struct address_space *mapping = inode->i_mapping;


	trace_ocfs2_duplicate_clusters_by_page(cpos, old_cluster,
	trace_ocfs2_duplicate_clusters_by_page(cpos, old_cluster,
					       new_cluster, new_len);
					       new_cluster, new_len);
@@ -2948,8 +2949,8 @@ static int ocfs2_duplicate_clusters_by_page(handle_t *handle,
	 * We only duplicate pages until we reach the page contains i_size - 1.
	 * We only duplicate pages until we reach the page contains i_size - 1.
	 * So trim 'end' to i_size.
	 * So trim 'end' to i_size.
	 */
	 */
	if (end > i_size_read(context->inode))
	if (end > i_size_read(inode))
		end = i_size_read(context->inode);
		end = i_size_read(inode);


	while (offset < end) {
	while (offset < end) {
		page_index = offset >> PAGE_CACHE_SHIFT;
		page_index = offset >> PAGE_CACHE_SHIFT;
@@ -2972,10 +2973,9 @@ static int ocfs2_duplicate_clusters_by_page(handle_t *handle,
		if (PAGE_CACHE_SIZE <= OCFS2_SB(sb)->s_clustersize)
		if (PAGE_CACHE_SIZE <= OCFS2_SB(sb)->s_clustersize)
			BUG_ON(PageDirty(page));
			BUG_ON(PageDirty(page));


		if (PageReadahead(page) && context->file) {
		if (PageReadahead(page)) {
			page_cache_async_readahead(mapping,
			page_cache_async_readahead(mapping,
						   &context->file->f_ra,
						   &file->f_ra, file,
						   context->file,
						   page, page_index,
						   page, page_index,
						   readahead_pages);
						   readahead_pages);
		}
		}
@@ -2999,8 +2999,7 @@ static int ocfs2_duplicate_clusters_by_page(handle_t *handle,
			}
			}
		}
		}


		ocfs2_map_and_dirty_page(context->inode,
		ocfs2_map_and_dirty_page(inode, handle, from, to,
					 handle, from, to,
					 page, 0, &new_block);
					 page, 0, &new_block);
		mark_page_accessed(page);
		mark_page_accessed(page);
unlock:
unlock:
@@ -3015,14 +3014,15 @@ static int ocfs2_duplicate_clusters_by_page(handle_t *handle,
	return ret;
	return ret;
}
}


static int ocfs2_duplicate_clusters_by_jbd(handle_t *handle,
int ocfs2_duplicate_clusters_by_jbd(handle_t *handle,
					   struct ocfs2_cow_context *context,
				    struct file *file,
				    u32 cpos, u32 old_cluster,
				    u32 cpos, u32 old_cluster,
				    u32 new_cluster, u32 new_len)
				    u32 new_cluster, u32 new_len)
{
{
	int ret = 0;
	int ret = 0;
	struct super_block *sb = context->inode->i_sb;
	struct inode *inode = file->f_path.dentry->d_inode;
	struct ocfs2_caching_info *ci = context->data_et.et_ci;
	struct super_block *sb = inode->i_sb;
	struct ocfs2_caching_info *ci = INODE_CACHE(inode);
	int i, blocks = ocfs2_clusters_to_blocks(sb, new_len);
	int i, blocks = ocfs2_clusters_to_blocks(sb, new_len);
	u64 old_block = ocfs2_clusters_to_blocks(sb, old_cluster);
	u64 old_block = ocfs2_clusters_to_blocks(sb, old_cluster);
	u64 new_block = ocfs2_clusters_to_blocks(sb, new_cluster);
	u64 new_block = ocfs2_clusters_to_blocks(sb, new_cluster);
@@ -3145,8 +3145,8 @@ static int ocfs2_replace_clusters(handle_t *handle,


	/*If the old clusters is unwritten, no need to duplicate. */
	/*If the old clusters is unwritten, no need to duplicate. */
	if (!(ext_flags & OCFS2_EXT_UNWRITTEN)) {
	if (!(ext_flags & OCFS2_EXT_UNWRITTEN)) {
		ret = context->cow_duplicate_clusters(handle, context, cpos,
		ret = context->cow_duplicate_clusters(handle, context->file,
						      old, new, len);
						      cpos, old, new, len);
		if (ret) {
		if (ret) {
			mlog_errno(ret);
			mlog_errno(ret);
			goto out;
			goto out;
@@ -3162,8 +3162,8 @@ static int ocfs2_replace_clusters(handle_t *handle,
	return ret;
	return ret;
}
}


static int ocfs2_cow_sync_writeback(struct super_block *sb,
int ocfs2_cow_sync_writeback(struct super_block *sb,
				    struct ocfs2_cow_context *context,
			     struct inode *inode,
			     u32 cpos, u32 num_clusters)
			     u32 cpos, u32 num_clusters)
{
{
	int ret = 0;
	int ret = 0;
@@ -3171,13 +3171,13 @@ static int ocfs2_cow_sync_writeback(struct super_block *sb,
	pgoff_t page_index;
	pgoff_t page_index;
	struct page *page;
	struct page *page;


	if (ocfs2_should_order_data(context->inode))
	if (ocfs2_should_order_data(inode))
		return 0;
		return 0;


	offset = ((loff_t)cpos) << OCFS2_SB(sb)->s_clustersize_bits;
	offset = ((loff_t)cpos) << OCFS2_SB(sb)->s_clustersize_bits;
	end = offset + (num_clusters << OCFS2_SB(sb)->s_clustersize_bits);
	end = offset + (num_clusters << OCFS2_SB(sb)->s_clustersize_bits);


	ret = filemap_fdatawrite_range(context->inode->i_mapping,
	ret = filemap_fdatawrite_range(inode->i_mapping,
				       offset, end - 1);
				       offset, end - 1);
	if (ret < 0) {
	if (ret < 0) {
		mlog_errno(ret);
		mlog_errno(ret);
@@ -3190,7 +3190,7 @@ static int ocfs2_cow_sync_writeback(struct super_block *sb,
		if (map_end > end)
		if (map_end > end)
			map_end = end;
			map_end = end;


		page = find_or_create_page(context->inode->i_mapping,
		page = find_or_create_page(inode->i_mapping,
					   page_index, GFP_NOFS);
					   page_index, GFP_NOFS);
		BUG_ON(!page);
		BUG_ON(!page);


@@ -3349,7 +3349,7 @@ static int ocfs2_make_clusters_writable(struct super_block *sb,
	 * in write-back mode.
	 * in write-back mode.
	 */
	 */
	if (context->get_clusters == ocfs2_di_get_clusters) {
	if (context->get_clusters == ocfs2_di_get_clusters) {
		ret = ocfs2_cow_sync_writeback(sb, context, cpos,
		ret = ocfs2_cow_sync_writeback(sb, context->inode, cpos,
					       orig_num_clusters);
					       orig_num_clusters);
		if (ret)
		if (ret)
			mlog_errno(ret);
			mlog_errno(ret);
+11 −0
Original line number Original line Diff line number Diff line
@@ -84,6 +84,17 @@ int ocfs2_refcount_cow_xattr(struct inode *inode,
			     struct buffer_head *ref_root_bh,
			     struct buffer_head *ref_root_bh,
			     u32 cpos, u32 write_len,
			     u32 cpos, u32 write_len,
			     struct ocfs2_post_refcount *post);
			     struct ocfs2_post_refcount *post);
int ocfs2_duplicate_clusters_by_page(handle_t *handle,
				     struct file *file,
				     u32 cpos, u32 old_cluster,
				     u32 new_cluster, u32 new_len);
int ocfs2_duplicate_clusters_by_jbd(handle_t *handle,
				    struct file *file,
				    u32 cpos, u32 old_cluster,
				    u32 new_cluster, u32 new_len);
int ocfs2_cow_sync_writeback(struct super_block *sb,
			     struct inode *inode,
			     u32 cpos, u32 num_clusters);
int ocfs2_add_refcount_flag(struct inode *inode,
int ocfs2_add_refcount_flag(struct inode *inode,
			    struct ocfs2_extent_tree *data_et,
			    struct ocfs2_extent_tree *data_et,
			    struct ocfs2_caching_info *ref_ci,
			    struct ocfs2_caching_info *ref_ci,