From: Vasily Averin <vvs@virtuozzo.com>
To: linux-ext4@vger.kernel.org, Theodore Ts'o <tytso@mit.edu>,
Andreas Dilger <adilger.kernel@dilger.ca>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] ext4: remove code duplication in free_ind_block()
Date: Tue, 6 Nov 2018 09:13:57 +0300 [thread overview]
Message-ID: <f1ec9378-6b0f-fdee-392c-bb97187fae12@virtuozzo.com> (raw)
free_ind_block(), free_dind_blocks() and free_tind_blocks() are replaced
by a single recursive function.
Signed-off-by: Vasily Averin <vvs@virtuozzo.com>
---
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:
--
2.17.1
next reply other threads:[~2018-11-06 6:14 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-11-06 6:13 Vasily Averin [this message]
2018-11-06 6:24 ` Vasily Averin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f1ec9378-6b0f-fdee-392c-bb97187fae12@virtuozzo.com \
--to=vvs@virtuozzo.com \
--cc=adilger.kernel@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®