Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp1338001rdb; Sat, 23 Dec 2023 03:04:59 -0800 (PST) X-Google-Smtp-Source: AGHT+IEc/G4U+ObhckkpTbt9fKhzPgUdCN32D5PllwcXMYvU24lm3qxJdy921k0HrqyMWbdYgjAE X-Received: by 2002:a05:6359:6697:b0:16f:ebce:8126 with SMTP id so23-20020a056359669700b0016febce8126mr2173620rwb.19.1703329499308; Sat, 23 Dec 2023 03:04:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703329499; cv=none; d=google.com; s=arc-20160816; b=mNgAfq2yqME7PM3BvGfygLfUNtfxlaLVBL6ErtXWv7By+k+7puVyCUWYH5fAcJYUD0 QQ6gV75RXL1R06oyxcMXb8AC6KtLnJPeoOggnClPbCAa/DLUJpQPu/VLB2oaKo/+YIX8 Va6T1R/DJkkRvvYU45noL1S3yTrMJIdYdhrSs0nBKjIbF0CUSyGEJiGI2ie/Edos/dlY ByOKHH/TmC4Og9G95DCRsvYuUjzE0f3CreDtGrPzj9UbWAwFVoE6FRIg5Ij5ODCPXfQ/ 21TUurzbeZd4YBDfUDDwuYihYuPu95yOAJI1tT9AcPofR//afUj/NExzuUZyDUkZqvo4 BDWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=S8joIyK+0lBKV0AnWOovpPqngYZTNik7cE9ZKrSrriU=; fh=Uq/HK0tePPZ4uFSrjmAoQ+8fm8HBRKIYZPcFTEYnhm4=; b=AIgQAx754CMGjM7hStiply1wN0wTOY+WnzE8FDGL6yctu1HBZeeZdJQvXKVU2oY3Fz RjLj4aACH6JnDuYlUFVVJA1ck6pkRRTXBRIN3lTZBZaUad3DZ9YYoMTZVygbjz0Q74y3 ZxmfU3whBCDucydnQWEdtAZSQluQECCRfVUf9XCgktc9hWAB7wnRx8IhDGW6WtC7B/1z UVwx4BXvEoPKAyDSyQmjQPj1LlOirxbB8SUHikI4ACsJg+IH1jLFupGm0jvOHPSje80c gcVOLQSGDtJtfbViDayfg/bZx46nRO2ndPgxRYNG3Y3fK+n7o4YvR1exu16oKZPyh7d6 GuPQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-554-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-554-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id gp21-20020a17090adf1500b0028c27d66a29si1328623pjb.150.2023.12.23.03.04.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Dec 2023 03:04:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-ext4+bounces-554-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-ext4+bounces-554-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-ext4+bounces-554-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E68812842D6 for ; Sat, 23 Dec 2023 11:04:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EE12AD28B; Sat, 23 Dec 2023 11:04:48 +0000 (UTC) X-Original-To: linux-ext4@vger.kernel.org Received: from dggsgout11.his.huawei.com (unknown [45.249.212.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5EA6CA7E for ; Sat, 23 Dec 2023 11:04:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=huaweicloud.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=huaweicloud.com Received: from mail.maildlp.com (unknown [172.19.163.216]) by dggsgout11.his.huawei.com (SkyGuard) with ESMTP id 4Sy1Wz5y1Nz4f3l1d for ; Sat, 23 Dec 2023 19:04:31 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.128]) by mail.maildlp.com (Postfix) with ESMTP id 255BA1A01C1 for ; Sat, 23 Dec 2023 19:04:37 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP4 (Coremail) with SMTP id gCh0CgDX5UW6voZlWeceEg--.27538S5; Sat, 23 Dec 2023 19:04:36 +0800 (CST) From: Zhang Yi To: linux-ext4@vger.kernel.org Cc: tytso@mit.edu, adilger.kernel@dilger.ca, jack@suse.cz, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, chengzhihao1@huawei.com, yukuai3@huawei.com Subject: [RFC PATCH v2 1/6] ext4: refactor ext4_da_map_blocks() Date: Sat, 23 Dec 2023 19:02:18 +0800 Message-Id: <20231223110223.3650717-2-yi.zhang@huaweicloud.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231223110223.3650717-1-yi.zhang@huaweicloud.com> References: <20231223110223.3650717-1-yi.zhang@huaweicloud.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID:gCh0CgDX5UW6voZlWeceEg--.27538S5 X-Coremail-Antispam: 1UD129KBjvJXoW7uw4DKw45GF13urykAFy3twb_yoW8urW8pr 9IkFZ3Wr17WwnYgF4Sgr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ocks(), reduce some unnecessary parameters and branches, no logic changes. Signed-off-by: Zhang Yi --- 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; } -- 2.39.2