From patchwork Sat Jan 27 01:58:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533896 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id B444FC47DA9 for ; Sat, 27 Jan 2024 02:02:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD7056B008A; Fri, 26 Jan 2024 21:02:50 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D5556B008C; Fri, 26 Jan 2024 21:02:50 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 52AFC6B0087; Fri, 26 Jan 2024 21:02:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 01A296B0087 for ; Fri, 26 Jan 2024 21:02:49 -0500 (EST) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 9C562A1CEE for ; Sat, 27 Jan 2024 02:02:49 +0000 (UTC) X-FDA: 81723442458.30.ED7C2C6 Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) by imf22.hostedemail.com (Postfix) with ESMTP id B3474C0019 for ; Sat, 27 Jan 2024 02:02:45 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706320967; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OeRvB9hMis2SFRCTB3XI733Q86WrQ5pD2A6MCYZWG6Q=; b=dM3A7CGOhxw+m0ArwqhzCMwUko22qAqu4PlgDc9ucbwmkso+6yCqjMdlEums2WUDZwGpxS V3VYn0gS/e0m9n/yAYiSNIm7dwT2lsWgzIfT518ZZvjIp+2R1zZI3gmdkcvdljePwT7rJh N8sBSOdct7hvhna0O6mt8MNAbY28rFc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320968; a=rsa-sha256; cv=none; b=GsCX+a/UG5Bj3h6aTz7sc7clp89xF+Rx4mJ9QAZlz3/4wbDUWh5UnnZlomvQ4XL0yGWv3S 21ueOasf5H1xctQ1vc0f3yJmMus24mzWUNer79WHtvykuY/ufb+WqRURk2ktGjD0Yziq0n Q3er7LDMIFiU9/9tX8u9BvRDVvWMuXs= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=none; spf=pass (imf22.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.51 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com; dmarc=none Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4TMHrT4R3Qz4f3lg8 for ; Sat, 27 Jan 2024 10:02:33 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id 000241A0232 for ; Sat, 27 Jan 2024 10:02:39 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S5; Sat, 27 Jan 2024 10:02:39 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, ritesh.list@gmail.com, hch@infradead.org, djwong@kernel.org, willy@infradead.org, zokeefe@google.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com, wangkefeng.wang@huawei.com Subject: [PATCH v3 01/26] ext4: refactor ext4_da_map_blocks() Date: Sat, 27 Jan 2024 09:58:00 +0800 Message-Id: <20240127015825.1608160-2-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> References: <20240127015825.1608160-1-yi.zhang@huaweicloud.com> MIME-Version: 1.0 X-CM-TRANSID: cCh0CgAX5g40ZLRlGJtmCA--.7377S5 X-Coremail-Antispam: 1UD129KBjvJXoWxJr17JF15uw4DuryfZr4rAFb_yoW8uFy7pr 9IkF93Wr1UXwnYgF4Iqr1UXF1fKa4YqrWDGrZ3Ww18Ary8AwnagFn8tF1fKa4rtrZ7ZF1Y qF4rKry5uw15GrDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUBE14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_Jr4l82xGYIkIc2 x26xkF7I0E14v26r4j6ryUM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0 Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F4UJw A2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq3wAS 0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2 IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0 Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2kIc2 xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v2 6r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIxkGc2 Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUJVWUCwCI42IY6xIIjxv20xvEc7CjxVAFwI0_ Gr0_Cr1lIxAIcVCF04k26cxKx2IYs7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r1j6r4UMI IF0xvEx4A2jsIEc7CjxVAFwI0_Gr0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUszV8UUUUU = X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Stat-Signature: 5167ci66dwowdx3u6me5kmbbb6d6pixz X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: B3474C0019 X-Rspam-User: X-HE-Tag: 1706320965-693367 X-HE-Meta: U2FsdGVkX1/pnRLDU+8/AyqTbmYsy5/v65CVlmVxEaeVppetOdcEABm+2vi/e+LV3kVMi6aHw5SiFF4S7Gi8IZI3mdoxyjEZJ6tzYIjjjZxWqCKOsTFX0eZxME/fBSLMu0ClU+uDh2+DtfBQYOp6NqloCK1o6bjv4tVRJgJugiODHsoeCn8p6rqeMS9/3wSHS8yII156Z1543C6aCAlGRfNJoHc/tHygdmiy/H7urmRQpokb5vUXZzPJL79+zeHLVBkWbfEI6LQ6aehuiwurml8QzdEn5H5iTSmFPv2cWi5xv3hjh/+0V5soyOJo9Q4TLCThBu4avzgnH95rVgbH/h/wWh0NZ60oHgMALM5spaJ5MlqNfk34cquqe1LEN7BTIj/KZtzPmT1heKcFwyqLyjlaYQEU1q87cHi//R3vilOo3/lcS9uU6chGy7XvNU7DMXHMpGWCL1IHKe8d1Zn+yxdvhxiPbElMJA8PkcYKVjM4QinbFgiHB+H+15zChniu+9fIi04LrB12gIpIwEvrbIPx+9V9dJ8NzK6nxafazrB//VSjpQZQDQxX8cg+bETHStjPF+ju/WJUPAzjkAOUKkBh/VCAuwcgXR5SuU/hn/D4qbhYztmQOC3Gg+nyaUnYPi5lBDevzY9Dx+7pXj4GxAqgYesBjyrP4hSPgrW+Uh8B7OwHKj5I3w5Ri+M7lJQeDd51+Hun+3GYWHMczm+JAQaz/NGnBNsd5EQOeVYfgjW6Fp6VFe3XJvXoe5/H4jdjtSM0zqb0L3rVw5pB5flhQXM4AnItLcCC4uf+EhWwJTbRbheJDwg57iclzOHJ/fh75G7j4KaA+0CgsoZw2hRB2TeSuzxAxjUborZ7TgcAuCMJFm7jMxAm+VhFQ0Oi+KPfYU0JUQg4qvIeFPgAcKNJGaZaBLARwXWzdCtKtYiJFmoHR7CTkFWqRHFLDi+gC5BCb2+HEWuqeLqQ6xNIpIU vBFB8qri KaKQVPi2dptbNOdVhenBg9YjTQ3Qj9THXD3IKIfp48jUgwPZGJnXV51niWlldbUknzPpZ/Xw3iM5FF1ZgqwhcJGQRcut2Q/ZJiI+GlFbsRDHc+wqgvqNqN1iO9rTd8AttVJxDZ+SrhPULATsrZriQTSlRtKlKRHpFutuBPrSgpv9jpYbfItWa0TLkrc9XEnf+rD645OnmAeVM696ChlJZyY60LcG78VFPmIMCBLWomaMgHcF2fyVeQwFiAViatvT7u3PCihVnLI6tAgj5NbqmFdkWYg1nYB7zfjgt3BIrPupNqzhTGKqe/88YKLtGF1hMDFfLN+YzWKaHVdQKfPscjPEv1Q== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Zhang Yi Refactor and cleanup ext4_da_map_blocks(), reduce some unnecessary parameters and branches, no logic changes. Signed-off-by: Zhang Yi Reviewed-by: Jan Kara --- fs/ext4/inode.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 61277f7f8722..5b0d3075be12 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -1704,7 +1704,6 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, /* Lookup extent status tree firstly */ if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) { if (ext4_es_is_hole(&es)) { - retval = 0; down_read(&EXT4_I(inode)->i_data_sem); goto add_delayed; } @@ -1749,26 +1748,9 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, retval = ext4_ext_map_blocks(NULL, inode, map, 0); else retval = ext4_ind_map_blocks(NULL, inode, map, 0); - -add_delayed: - if (retval == 0) { - int ret; - - /* - * XXX: __block_prepare_write() unmaps passed block, - * is it OK? - */ - - ret = ext4_insert_delayed_block(inode, map->m_lblk); - if (ret != 0) { - retval = ret; - goto out_unlock; - } - - map_bh(bh, inode->i_sb, invalid_block); - set_buffer_new(bh); - set_buffer_delay(bh); - } else if (retval > 0) { + if (retval < 0) + goto out_unlock; + if (retval > 0) { unsigned int status; if (unlikely(retval != map->m_len)) { @@ -1783,11 +1765,24 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock, EXTENT_STATUS_UNWRITTEN : EXTENT_STATUS_WRITTEN; ext4_es_insert_extent(inode, map->m_lblk, map->m_len, map->m_pblk, status); + goto out_unlock; } +add_delayed: + /* + * XXX: __block_prepare_write() unmaps passed block, + * is it OK? + */ + retval = ext4_insert_delayed_block(inode, map->m_lblk); + if (retval) + goto out_unlock; + + map_bh(bh, inode->i_sb, invalid_block); + set_buffer_new(bh); + set_buffer_delay(bh); + out_unlock: up_read((&EXT4_I(inode)->i_data_sem)); - return retval; }