Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp414992imu; Mon, 5 Nov 2018 03:03:57 -0800 (PST) X-Google-Smtp-Source: AJdET5djASma4thmlyEaIqxJq/pY4fNNgjHrlW1rXii+w5b92vroEQOlNCz7Js2WWmLarLIgxp4i X-Received: by 2002:a62:c60a:: with SMTP id m10-v6mr21835888pfg.15.1541415836955; Mon, 05 Nov 2018 03:03:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541415836; cv=none; d=google.com; s=arc-20160816; b=PgLO8PULXv2vN+aoMsbnsFDuAuoyw9LWGLwov0gyRjzpP8//9yTUtMyn6Y7g4MN1nP pUSr6ePMuoXJTphgwoCwNORUov8WTuS+OuHI6LdQcEcc/hgcQMENwjM+86eeXpWKYg1l YVClv2OHOGPQETnHCrYcsIn1X3k5f5ftE4l/BgpyEXFGtR64xpT6fHQMXsn+4RlUe1Pf ff8KJK9E4asqwY8duuy8v5oXsVAfltPvh1EgcPU85CuG/uNBeXXfV9jTVmb5WWEtTv2D 5HOtHznkjJ8/sOireBDMKwfc8C7kn+Z+x/J+LsxeqD2j+C//VCDQn3iPPdcR7MDb9bkH IKkA== 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:references:cc:to:subject:from; bh=R5zcVdPn2VBRhzo3xTbi+InJnVRqGvEH87PzyBZfM4k=; b=uuAR/nMUgzP74aifZGoci0s9jQavv8cFtWAjheeRAC8dPUcG9mfEEwabXua43q6ohv KKkKUQgwXwpILe9YyFtHXSoYMQ4x4Coz9p+bo5DttAF71ukdJyY3MqxM+gq82PFG3ADO G201L17ANgcd5y3Nf1d/ineLjhH5e8otMOKidWKQaQv3fcB5XwgQK0m947ZOA3yOrvUF JmjkbLyxgXVkRRn/29+3qtOB9LOEMkLT287KludomGjRdV9YLqfORAzOv0LL2O8NuTw1 mD0lwSp8n3VKMyrX8LBXQ8mJWiqX0oXrlIQQUG3OI9XzesaWsTsmPmBNAjkZ/XcKQyji 9AFA== 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 i5si7865405pgn.243.2018.11.05.03.03.40; Mon, 05 Nov 2018 03:03:56 -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 S1729163AbeKEUWV (ORCPT + 99 others); Mon, 5 Nov 2018 15:22:21 -0500 Received: from relay.sw.ru ([185.231.240.75]:47536 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727275AbeKEUWV (ORCPT ); Mon, 5 Nov 2018 15:22:21 -0500 Received: from [172.16.24.21] by relay.sw.ru with esmtp (Exim 4.90_1) (envelope-from ) id 1gJcey-0007O4-UB; Mon, 05 Nov 2018 14:03:09 +0300 From: Vasily Averin Subject: [PATCH v2] ext4: remove code duplication in update_ind/bind/tind_extent_range To: linux-ext4@vger.kernel.org, Theodore Ts'o , Andreas Dilger Cc: linux-kernel@vger.kernel.org References: Message-ID: Date: Mon, 5 Nov 2018 14:03:08 +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 update_ind/bind/tind_extent_page() differs by one variable and can be replaced by unified function. These functions are called by similar way and their caller function can be simplified too. v2: minor style changes, thanks to Andreas Dilger Reviewed-by: Andreas Dilger Signed-off-by: Vasily Averin --- fs/ext4/migrate.c | 112 ++++++++++------------------------------------ 1 file changed, 24 insertions(+), 88 deletions(-) diff --git a/fs/ext4/migrate.c b/fs/ext4/migrate.c index 61a9d1927817..224e136d1c10 100644 --- a/fs/ext4/migrate.c +++ b/fs/ext4/migrate.c @@ -109,12 +109,13 @@ static int update_extent_range(handle_t *handle, struct inode *inode, static int update_ind_extent_range(handle_t *handle, struct inode *inode, ext4_fsblk_t pblock, - struct migrate_struct *lb) + struct migrate_struct *lb, + ext4_lblk_t inc) { struct buffer_head *bh; __le32 *i_data; int i, retval = 0; - unsigned long max_entries = inode->i_sb->s_blocksize >> 2; + ext4_lblk_t max_entries = inode->i_sb->s_blocksize >> 2; bh = sb_bread(inode->i_sb, pblock); if (!bh) @@ -128,67 +129,7 @@ static int update_ind_extent_range(handle_t *handle, struct inode *inode, if (retval) break; } else { - lb->curr_block++; - } - } - put_bh(bh); - return retval; - -} - -static int update_dind_extent_range(handle_t *handle, struct inode *inode, - ext4_fsblk_t pblock, - struct migrate_struct *lb) -{ - struct buffer_head *bh; - __le32 *i_data; - int i, retval = 0; - unsigned long max_entries = inode->i_sb->s_blocksize >> 2; - - bh = sb_bread(inode->i_sb, pblock); - if (!bh) - return -EIO; - - i_data = (__le32 *)bh->b_data; - for (i = 0; i < max_entries; i++) { - if (i_data[i]) { - retval = update_ind_extent_range(handle, inode, - le32_to_cpu(i_data[i]), lb); - if (retval) - break; - } else { - /* Only update the file block number */ - lb->curr_block += max_entries; - } - } - put_bh(bh); - return retval; - -} - -static int update_tind_extent_range(handle_t *handle, struct inode *inode, - ext4_fsblk_t pblock, - struct migrate_struct *lb) -{ - struct buffer_head *bh; - __le32 *i_data; - int i, retval = 0; - unsigned long max_entries = inode->i_sb->s_blocksize >> 2; - - bh = sb_bread(inode->i_sb, pblock); - if (!bh) - return -EIO; - - i_data = (__le32 *)bh->b_data; - for (i = 0; i < max_entries; i++) { - if (i_data[i]) { - retval = update_dind_extent_range(handle, inode, - le32_to_cpu(i_data[i]), lb); - if (retval) - break; - } else { - /* Only update the file block number */ - lb->curr_block += max_entries * max_entries; + lb->curr_block += inc; } } put_bh(bh); @@ -433,7 +374,7 @@ int ext4_ext_migrate(struct inode *inode) struct ext4_inode_info *ei; struct inode *tmp_inode = NULL; struct migrate_struct lb; - unsigned long max_entries; + ext4_lblk_t max_entries, inc, mult; __u32 goal; uid_t owner[2]; @@ -523,34 +464,29 @@ int ext4_ext_migrate(struct inode *inode) /* 32 bit block address 4 bytes */ max_entries = inode->i_sb->s_blocksize >> 2; - for (i = 0; i < EXT4_NDIR_BLOCKS; i++) { + + inc = 1; mult = 1; + for (i = 0; i < EXT4_N_BLOCKS; i++) { + inc *= mult; + if (i == EXT4_IND_BLOCK) + mult = max_entries; + if (i_data[i]) { - retval = update_extent_range(handle, tmp_inode, + if (i < EXT4_IND_BLOCK) + retval = update_extent_range(handle, tmp_inode, le32_to_cpu(i_data[i]), &lb); + else + retval = update_ind_extent_range(handle, + tmp_inode, + le32_to_cpu(i_data[i]), + &lb, inc); if (retval) goto err_out; - } else - lb.curr_block++; - } - if (i_data[EXT4_IND_BLOCK]) { - retval = update_ind_extent_range(handle, tmp_inode, - le32_to_cpu(i_data[EXT4_IND_BLOCK]), &lb); - if (retval) - goto err_out; - } else - lb.curr_block += max_entries; - if (i_data[EXT4_DIND_BLOCK]) { - retval = update_dind_extent_range(handle, tmp_inode, - le32_to_cpu(i_data[EXT4_DIND_BLOCK]), &lb); - if (retval) - goto err_out; - } else - lb.curr_block += max_entries * max_entries; - if (i_data[EXT4_TIND_BLOCK]) { - retval = update_tind_extent_range(handle, tmp_inode, - le32_to_cpu(i_data[EXT4_TIND_BLOCK]), &lb); - if (retval) - goto err_out; + + } else { + if (i < EXT4_TIND_BLOCK) + lb.curr_block += inc * mult; + } } /* * Build the last extent -- 2.17.1