Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1480934imu; Mon, 5 Nov 2018 22:25:20 -0800 (PST) X-Google-Smtp-Source: AJdET5esJ8lLt2dUyC8GHRcPsKVOw51H1c+dP3y8fU5M2LLlhO72KDeIVhnWGLfmJfCK8ggqDfCV X-Received: by 2002:a62:76c9:: with SMTP id r192-v6mr17957266pfc.17.1541485520315; Mon, 05 Nov 2018 22:25:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541485520; cv=none; d=google.com; s=arc-20160816; b=bq71meyX6yG6rMDi+XS9DcukUYrkzCCnt6e8LkDRRlYZKuZtzk0k4b8ZNsOCbihjIM TM7vsgH9tlPCv4D/I/yLcFLvWcqSXJx89WoKpi60yItRS8qTJMuTEmCQiM76ZQe0h2pU cqoy4EomLhexV/ZQVynnRlYHyPPA/v65HAyUY7Q4SKKfm+94YkmeZ1PeBN9BftzItZNg 1joZAObWXpoCQNcHw0MpYYvf0jliacx5bRSu0NjJJxNnCXe+aPRkFT3AklqLGqv9Sd9D Rfp1nOKIpiMwyQbVZV+TTnSczBquJKAvaBF6j1nJ1tLJ1uMTyumrYWRRz3DRYh+EQS4E 1NWQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=61e4flYT2faCaoC1fdbvxHMPUcwFssUAme/psrdK+l4=; b=mPpegJx9ffGsMsuY8bPNd21A6zliU6QArqERnfxj94TAGPhYsJl0XJ5YU9E0a73jtb pTj/yJemCslBkfs2qke0nEpXtusbBusrkdBz+jJwSJouqUjgMDZGWAY5hTCdgpSyQf2X RHAkpSyfRSLmK5x2VqVti7o5TzcrVzq0e7Tvtm31G9XuGg0g18iDi5HXuybQZy1Hwejg 2V4dSwTHCyBHAC05DIHtmEUpTPErVgIJ9IaUoshvhX5JQ3GxP3de4f/FDe1O8YciVcY7 ozsh2jdbe5S0PMNC147mZPuQXtVIEvguqdadVyGoD/uoIHspbC/+XGtdlW6TGEGKOEx8 qQHw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id q17-v6si23907226pgd.438.2018.11.05.22.25.04; Mon, 05 Nov 2018 22:25:20 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387468AbeKFPsV (ORCPT + 99 others); Tue, 6 Nov 2018 10:48:21 -0500 Received: from relay.sw.ru ([185.231.240.75]:53434 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729416AbeKFPsU (ORCPT ); Tue, 6 Nov 2018 10:48:20 -0500 Received: from [172.16.24.21] by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1gJun1-0002Fh-QF; Tue, 06 Nov 2018 09:24:39 +0300 Subject: Re: [PATCH] ext4: remove code duplication in free_ind_block() To: linux-ext4@vger.kernel.org, Theodore Ts'o , Andreas Dilger Cc: linux-kernel@vger.kernel.org References: From: Vasily Averin Message-ID: <8248d9f2-b758-21cb-5cd8-30bba2bb9137@virtuozzo.com> Date: Tue, 6 Nov 2018 09:24:38 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org btw I have few related questions: 1) extend_credit_for_blkdel() can return error but its return code is not checked, neither here nor in all other places. Could somebody clarify, is it normal? 2) there is similar function free_ext_idx(). After internal failures it calls extend_credit_for_blkdel() and ext4_free_blocks(). In the same situation free_ind_blocks() returns without calling of these functions. Is it OK? Thank you, Vasily Averin On 11/6/18 9:13 AM, Vasily Averin wrote: > free_ind_block(), free_dind_blocks() and free_tind_blocks() are replaced > by a single recursive function. > > Signed-off-by: Vasily Averin > --- > 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 224e136d1c10..754f172b18d4 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 = sb_bread(inode->i_sb, le32_to_cpu(i_data)); > - if (!bh) > - return -EIO; > - > - 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 = sb_bread(inode->i_sb, le32_to_cpu(i_data)); > - if (!bh) > - return -EIO; > - > - 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 = sb_bread(inode->i_sb, le32_to_cpu(i_data)); > + if (!bh) > + return -EIO; > + > + 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: >