mirror of
				git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
				synced 2025-11-01 09:13:37 +00:00 
			
		
		
		
	ocfs2: Make ocfs2_extend_trans() really extend.
In ocfs2, we use ocfs2_extend_trans() to extend a journal handle's blocks. But if jbd2_journal_extend() fails, it will only restart with the the new number of blocks. This tends to be awkward since in most cases we want additional reserved blocks. It makes our code harder to mantain since the caller can't be sure all the original blocks will not be accessed and dirtied again. There are 15 callers of ocfs2_extend_trans() in fs/ocfs2, and 12 of them have to add h_buffer_credits before they call ocfs2_extend_trans(). This makes ocfs2_extend_trans() really extend atop the original block count. Signed-off-by: Tao Ma <tao.ma@oracle.com> Signed-off-by: Joel Becker <joel.becker@oracle.com>
This commit is contained in:
		
							parent
							
								
									3e4218df31
								
							
						
					
					
						commit
						c901fb0073
					
				
					 4 changed files with 25 additions and 39 deletions
				
			
		| 
						 | 
					@ -1125,8 +1125,7 @@ static int ocfs2_adjust_rightmost_branch(handle_t *handle,
 | 
				
			||||||
		goto out;
 | 
							goto out;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	status = ocfs2_extend_trans(handle, path_num_items(path) +
 | 
						status = ocfs2_extend_trans(handle, path_num_items(path));
 | 
				
			||||||
				    handle->h_buffer_credits);
 | 
					 | 
				
			||||||
	if (status < 0) {
 | 
						if (status < 0) {
 | 
				
			||||||
		mlog_errno(status);
 | 
							mlog_errno(status);
 | 
				
			||||||
		goto out;
 | 
							goto out;
 | 
				
			||||||
| 
						 | 
					@ -2288,20 +2287,14 @@ static int ocfs2_extend_rotate_transaction(handle_t *handle, int subtree_depth,
 | 
				
			||||||
					   int op_credits,
 | 
										   int op_credits,
 | 
				
			||||||
					   struct ocfs2_path *path)
 | 
										   struct ocfs2_path *path)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int ret;
 | 
						int ret = 0;
 | 
				
			||||||
	int credits = (path->p_tree_depth - subtree_depth) * 2 + 1 + op_credits;
 | 
						int credits = (path->p_tree_depth - subtree_depth) * 2 + 1 + op_credits;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (handle->h_buffer_credits < credits) {
 | 
						if (handle->h_buffer_credits < credits)
 | 
				
			||||||
		ret = ocfs2_extend_trans(handle,
 | 
							ret = ocfs2_extend_trans(handle,
 | 
				
			||||||
					 credits - handle->h_buffer_credits);
 | 
										 credits - handle->h_buffer_credits);
 | 
				
			||||||
		if (ret)
 | 
					 | 
				
			||||||
			return ret;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
		if (unlikely(handle->h_buffer_credits < credits))
 | 
						return ret;
 | 
				
			||||||
			return ocfs2_extend_trans(handle, credits);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	return 0;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
| 
						 | 
					@ -2545,8 +2538,7 @@ static int ocfs2_update_edge_lengths(handle_t *handle,
 | 
				
			||||||
	 * records for all the bh in the path.
 | 
						 * records for all the bh in the path.
 | 
				
			||||||
	 * So we have to allocate extra credits and access them.
 | 
						 * So we have to allocate extra credits and access them.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	ret = ocfs2_extend_trans(handle,
 | 
						ret = ocfs2_extend_trans(handle, subtree_index);
 | 
				
			||||||
				 handle->h_buffer_credits + subtree_index);
 | 
					 | 
				
			||||||
	if (ret) {
 | 
						if (ret) {
 | 
				
			||||||
		mlog_errno(ret);
 | 
							mlog_errno(ret);
 | 
				
			||||||
		goto out;
 | 
							goto out;
 | 
				
			||||||
| 
						 | 
					@ -4141,17 +4133,13 @@ static int ocfs2_insert_path(handle_t *handle,
 | 
				
			||||||
	struct buffer_head *leaf_bh = path_leaf_bh(right_path);
 | 
						struct buffer_head *leaf_bh = path_leaf_bh(right_path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (left_path) {
 | 
						if (left_path) {
 | 
				
			||||||
		int credits = handle->h_buffer_credits;
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
		/*
 | 
							/*
 | 
				
			||||||
		 * There's a chance that left_path got passed back to
 | 
							 * There's a chance that left_path got passed back to
 | 
				
			||||||
		 * us without being accounted for in the
 | 
							 * us without being accounted for in the
 | 
				
			||||||
		 * journal. Extend our transaction here to be sure we
 | 
							 * journal. Extend our transaction here to be sure we
 | 
				
			||||||
		 * can change those blocks.
 | 
							 * can change those blocks.
 | 
				
			||||||
		 */
 | 
							 */
 | 
				
			||||||
		credits += left_path->p_tree_depth;
 | 
							ret = ocfs2_extend_trans(handle, left_path->p_tree_depth);
 | 
				
			||||||
 | 
					 | 
				
			||||||
		ret = ocfs2_extend_trans(handle, credits);
 | 
					 | 
				
			||||||
		if (ret < 0) {
 | 
							if (ret < 0) {
 | 
				
			||||||
			mlog_errno(ret);
 | 
								mlog_errno(ret);
 | 
				
			||||||
			goto out;
 | 
								goto out;
 | 
				
			||||||
| 
						 | 
					@ -5237,7 +5225,7 @@ static int ocfs2_split_tree(handle_t *handle, struct ocfs2_extent_tree *et,
 | 
				
			||||||
			    int index, u32 new_range,
 | 
								    int index, u32 new_range,
 | 
				
			||||||
			    struct ocfs2_alloc_context *meta_ac)
 | 
								    struct ocfs2_alloc_context *meta_ac)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int ret, depth, credits = handle->h_buffer_credits;
 | 
						int ret, depth, credits;
 | 
				
			||||||
	struct buffer_head *last_eb_bh = NULL;
 | 
						struct buffer_head *last_eb_bh = NULL;
 | 
				
			||||||
	struct ocfs2_extent_block *eb;
 | 
						struct ocfs2_extent_block *eb;
 | 
				
			||||||
	struct ocfs2_extent_list *rightmost_el, *el;
 | 
						struct ocfs2_extent_list *rightmost_el, *el;
 | 
				
			||||||
| 
						 | 
					@ -5268,8 +5256,8 @@ static int ocfs2_split_tree(handle_t *handle, struct ocfs2_extent_tree *et,
 | 
				
			||||||
	} else
 | 
						} else
 | 
				
			||||||
		rightmost_el = path_leaf_el(path);
 | 
							rightmost_el = path_leaf_el(path);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	credits += path->p_tree_depth +
 | 
						credits = path->p_tree_depth +
 | 
				
			||||||
		   ocfs2_extend_meta_needed(et->et_root_el);
 | 
							  ocfs2_extend_meta_needed(et->et_root_el);
 | 
				
			||||||
	ret = ocfs2_extend_trans(handle, credits);
 | 
						ret = ocfs2_extend_trans(handle, credits);
 | 
				
			||||||
	if (ret) {
 | 
						if (ret) {
 | 
				
			||||||
		mlog_errno(ret);
 | 
							mlog_errno(ret);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -402,9 +402,7 @@ int ocfs2_commit_trans(struct ocfs2_super *osb,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 * 'nblocks' is what you want to add to the current
 | 
					 * 'nblocks' is what you want to add to the current transaction.
 | 
				
			||||||
 * transaction. extend_trans will either extend the current handle by
 | 
					 | 
				
			||||||
 * nblocks, or commit it and start a new one with nblocks credits.
 | 
					 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * This might call jbd2_journal_restart() which will commit dirty buffers
 | 
					 * This might call jbd2_journal_restart() which will commit dirty buffers
 | 
				
			||||||
 * and then restart the transaction. Before calling
 | 
					 * and then restart the transaction. Before calling
 | 
				
			||||||
| 
						 | 
					@ -422,11 +420,15 @@ int ocfs2_commit_trans(struct ocfs2_super *osb,
 | 
				
			||||||
 */
 | 
					 */
 | 
				
			||||||
int ocfs2_extend_trans(handle_t *handle, int nblocks)
 | 
					int ocfs2_extend_trans(handle_t *handle, int nblocks)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int status;
 | 
						int status, old_nblocks;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	BUG_ON(!handle);
 | 
						BUG_ON(!handle);
 | 
				
			||||||
	BUG_ON(!nblocks);
 | 
						BUG_ON(nblocks < 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!nblocks)
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						old_nblocks = handle->h_buffer_credits;
 | 
				
			||||||
	mlog_entry_void();
 | 
						mlog_entry_void();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	mlog(0, "Trying to extend transaction by %d blocks\n", nblocks);
 | 
						mlog(0, "Trying to extend transaction by %d blocks\n", nblocks);
 | 
				
			||||||
| 
						 | 
					@ -445,7 +447,8 @@ int ocfs2_extend_trans(handle_t *handle, int nblocks)
 | 
				
			||||||
		mlog(0,
 | 
							mlog(0,
 | 
				
			||||||
		     "jbd2_journal_extend failed, trying "
 | 
							     "jbd2_journal_extend failed, trying "
 | 
				
			||||||
		     "jbd2_journal_restart\n");
 | 
							     "jbd2_journal_restart\n");
 | 
				
			||||||
		status = jbd2_journal_restart(handle, nblocks);
 | 
							status = jbd2_journal_restart(handle,
 | 
				
			||||||
 | 
										      old_nblocks + nblocks);
 | 
				
			||||||
		if (status < 0) {
 | 
							if (status < 0) {
 | 
				
			||||||
			mlog_errno(status);
 | 
								mlog_errno(status);
 | 
				
			||||||
			goto bail;
 | 
								goto bail;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1693,7 +1693,7 @@ static int ocfs2_adjust_refcount_rec(handle_t *handle,
 | 
				
			||||||
	 * 2 more credits, one for the leaf refcount block, one for
 | 
						 * 2 more credits, one for the leaf refcount block, one for
 | 
				
			||||||
	 * the extent block contains the extent rec.
 | 
						 * the extent block contains the extent rec.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	ret = ocfs2_extend_trans(handle, handle->h_buffer_credits + 2);
 | 
						ret = ocfs2_extend_trans(handle, 2);
 | 
				
			||||||
	if (ret < 0) {
 | 
						if (ret < 0) {
 | 
				
			||||||
		mlog_errno(ret);
 | 
							mlog_errno(ret);
 | 
				
			||||||
		goto out;
 | 
							goto out;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3295,8 +3295,7 @@ static int __ocfs2_xattr_set_handle(struct inode *inode,
 | 
				
			||||||
				goto out;
 | 
									goto out;
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			ret = ocfs2_extend_trans(ctxt->handle, credits +
 | 
								ret = ocfs2_extend_trans(ctxt->handle, credits);
 | 
				
			||||||
					ctxt->handle->h_buffer_credits);
 | 
					 | 
				
			||||||
			if (ret) {
 | 
								if (ret) {
 | 
				
			||||||
				mlog_errno(ret);
 | 
									mlog_errno(ret);
 | 
				
			||||||
				goto out;
 | 
									goto out;
 | 
				
			||||||
| 
						 | 
					@ -3326,8 +3325,7 @@ static int __ocfs2_xattr_set_handle(struct inode *inode,
 | 
				
			||||||
					goto out;
 | 
										goto out;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				ret = ocfs2_extend_trans(ctxt->handle, credits +
 | 
									ret = ocfs2_extend_trans(ctxt->handle, credits);
 | 
				
			||||||
					ctxt->handle->h_buffer_credits);
 | 
					 | 
				
			||||||
				if (ret) {
 | 
									if (ret) {
 | 
				
			||||||
					mlog_errno(ret);
 | 
										mlog_errno(ret);
 | 
				
			||||||
					goto out;
 | 
										goto out;
 | 
				
			||||||
| 
						 | 
					@ -3361,8 +3359,7 @@ static int __ocfs2_xattr_set_handle(struct inode *inode,
 | 
				
			||||||
					goto out;
 | 
										goto out;
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				ret = ocfs2_extend_trans(ctxt->handle, credits +
 | 
									ret = ocfs2_extend_trans(ctxt->handle, credits);
 | 
				
			||||||
						ctxt->handle->h_buffer_credits);
 | 
					 | 
				
			||||||
				if (ret) {
 | 
									if (ret) {
 | 
				
			||||||
					mlog_errno(ret);
 | 
										mlog_errno(ret);
 | 
				
			||||||
					goto out;
 | 
										goto out;
 | 
				
			||||||
| 
						 | 
					@ -4870,8 +4867,7 @@ static int ocfs2_mv_xattr_buckets(struct inode *inode, handle_t *handle,
 | 
				
			||||||
	 * We need to update the first bucket of the old extent and all
 | 
						 * We need to update the first bucket of the old extent and all
 | 
				
			||||||
	 * the buckets going to the new extent.
 | 
						 * the buckets going to the new extent.
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	credits = ((num_buckets + 1) * blks_per_bucket) +
 | 
						credits = ((num_buckets + 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);
 | 
				
			||||||
| 
						 | 
					@ -4941,7 +4937,7 @@ static int ocfs2_divide_xattr_cluster(struct inode *inode,
 | 
				
			||||||
				      u32 *first_hash)
 | 
									      u32 *first_hash)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
 | 
						u16 blk_per_bucket = ocfs2_blocks_per_xattr_bucket(inode->i_sb);
 | 
				
			||||||
	int ret, credits = 2 * blk_per_bucket + handle->h_buffer_credits;
 | 
						int ret, credits = 2 * blk_per_bucket;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	BUG_ON(OCFS2_XATTR_BUCKET_SIZE < OCFS2_SB(inode->i_sb)->s_clustersize);
 | 
						BUG_ON(OCFS2_XATTR_BUCKET_SIZE < OCFS2_SB(inode->i_sb)->s_clustersize);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -5181,8 +5177,7 @@ static int ocfs2_extend_xattr_bucket(struct inode *inode,
 | 
				
			||||||
	 * existing bucket.  Then we add the last existing bucket, the
 | 
						 * existing bucket.  Then we add the last existing bucket, the
 | 
				
			||||||
	 * new bucket, and the first bucket (3 * blk_per_bucket).
 | 
						 * new bucket, and the first bucket (3 * blk_per_bucket).
 | 
				
			||||||
	 */
 | 
						 */
 | 
				
			||||||
	credits = (end_blk - target_blk) + (3 * blk_per_bucket) +
 | 
						credits = (end_blk - target_blk) + (3 * blk_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);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue