From patchwork Tue Mar 12 13:09:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasily Averin X-Patchwork-Id: 1055386 Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-ext4-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=virtuozzo.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 44Jb0D5jMFz9s5c for ; Wed, 13 Mar 2019 00:09:16 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725957AbfCLNJQ (ORCPT ); Tue, 12 Mar 2019 09:09:16 -0400 Received: from relay.sw.ru ([185.231.240.75]:34806 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725774AbfCLNJQ (ORCPT ); Tue, 12 Mar 2019 09:09:16 -0400 Received: from [172.16.24.21] by relay.sw.ru with esmtp (Exim 4.91) (envelope-from ) id 1h3h9c-0004PT-VM; Tue, 12 Mar 2019 16:09:12 +0300 From: Vasily Averin Subject: [PATCH v2] ext4: remove code duplication in free_ind_block() To: Theodore Ts'o , Andreas Dilger , linux-ext4@vger.kernel.org Message-ID: <7751907d-738f-a533-8be9-78c6aff5c8be@virtuozzo.com> Date: Tue, 12 Mar 2019 16:09:12 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 Content-Language: en-US Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org free_ind_block(), free_dind_blocks() and free_tind_blocks() are replaced by a single recursive function. v2: rebase to v5.0 Signed-off-by: Vasily Averin Reviewed-by: Jan Kara --- fs/ext4/migrate.c | 115 +++++++++++++--------------------------------- 1 file changed, 32 insertions(+), 83 deletions(-) diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c index fde2f1bc96b0..6b811b7d110c 100644 --- a/fs/ext4/migrate.c +++ b/fs/ext4/migrate.c @@ -157,100 +157,43 @@ static int extend_credit_for_blkdel(handle_t *handle, struct inode *inode) return retval; } -static int free_dind_blocks(handle_t *handle, - struct inode *inode, __le32 i_data) +static int free_ind_blocks(handle_t *handle, + struct inode *inode, __le32 i_data, int ind) { - int i; - __le32 *tmp_idata; - struct buffer_head *bh; - unsigned long max_entries = inode->i_sb->s_blocksize >> 2; - - bh = ext4_sb_bread(inode->i_sb, le32_to_cpu(i_data), 0); - if (IS_ERR(bh)) - return PTR_ERR(bh); - - tmp_idata = (__le32 *)bh->b_data; - for (i = 0; i < max_entries; i++) { - if (tmp_idata[i]) { - extend_credit_for_blkdel(handle, inode); - ext4_free_blocks(handle, inode, NULL, - le32_to_cpu(tmp_idata[i]), 1, - EXT4_FREE_BLOCKS_METADATA | - EXT4_FREE_BLOCKS_FORGET); - } - } - put_bh(bh); - extend_credit_for_blkdel(handle, inode); - ext4_free_blocks(handle, inode, NULL, le32_to_cpu(i_data), 1, - EXT4_FREE_BLOCKS_METADATA | - EXT4_FREE_BLOCKS_FORGET); - return 0; -} - -static int free_tind_blocks(handle_t *handle, - struct inode *inode, __le32 i_data) -{ - int i, retval = 0; - __le32 *tmp_idata; - struct buffer_head *bh; - unsigned long max_entries = inode->i_sb->s_blocksize >> 2; - - bh = ext4_sb_bread(inode->i_sb, le32_to_cpu(i_data), 0); - if (IS_ERR(bh)) - return PTR_ERR(bh); - - tmp_idata = (__le32 *)bh->b_data; - for (i = 0; i < max_entries; i++) { - if (tmp_idata[i]) { - retval = free_dind_blocks(handle, - inode, tmp_idata[i]); - if (retval) { - put_bh(bh); - return retval; + if (ind > 0) { + int retval = 0; + __le32 *tmp_idata; + ext4_lblk_t i, max_entries; + struct buffer_head *bh; + + bh = ext4_sb_bread(inode->i_sb, le32_to_cpu(i_data), 0); + if (IS_ERR(bh)) + return PTR_ERR(bh); + + tmp_idata = (__le32 *)bh->b_data; + max_entries = inode->i_sb->s_blocksize >> 2; + for (i = 0; i < max_entries; i++) { + if (tmp_idata[i]) { + retval = free_ind_blocks(handle, + inode, tmp_idata[i], ind - 1); + if (retval) { + put_bh(bh); + return retval; + } } } + put_bh(bh); } - put_bh(bh); extend_credit_for_blkdel(handle, inode); ext4_free_blocks(handle, inode, NULL, le32_to_cpu(i_data), 1, - EXT4_FREE_BLOCKS_METADATA | - EXT4_FREE_BLOCKS_FORGET); - return 0; -} - -static int free_ind_block(handle_t *handle, struct inode *inode, __le32 *i_data) -{ - int retval; - - /* ei->i_data[EXT4_IND_BLOCK] */ - if (i_data[0]) { - extend_credit_for_blkdel(handle, inode); - ext4_free_blocks(handle, inode, NULL, - le32_to_cpu(i_data[0]), 1, - EXT4_FREE_BLOCKS_METADATA | - EXT4_FREE_BLOCKS_FORGET); - } - - /* ei->i_data[EXT4_DIND_BLOCK] */ - if (i_data[1]) { - retval = free_dind_blocks(handle, inode, i_data[1]); - if (retval) - return retval; - } - - /* ei->i_data[EXT4_TIND_BLOCK] */ - if (i_data[2]) { - retval = free_tind_blocks(handle, inode, i_data[2]); - if (retval) - return retval; - } + EXT4_FREE_BLOCKS_METADATA | EXT4_FREE_BLOCKS_FORGET); return 0; } static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode, struct inode *tmp_inode) { - int retval; + int i, retval; __le32 i_data[3]; struct ext4_inode_info *ei = EXT4_I(inode); struct ext4_inode_info *tmp_ei = EXT4_I(tmp_inode); @@ -307,7 +250,13 @@ static int ext4_ext_swap_inode_data(handle_t *handle, struct inode *inode, * We mark the inode dirty after, because we decrement the * i_blocks when freeing the indirect meta-data blocks */ - retval = free_ind_block(handle, inode, i_data); + for (i = 0; i < ARRAY_SIZE(i_data); i++) { + if (i_data[i]) { + retval = free_ind_blocks(handle, inode, i_data[i], i); + if (retval) + break; + } + } ext4_mark_inode_dirty(handle, inode); err_out: