From patchwork Sat Jan 27 01:58:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Yi X-Patchwork-Id: 13533898 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 5AB81C47422 for ; Sat, 27 Jan 2024 02:03:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6AF876B0092; Fri, 26 Jan 2024 21:02:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 618956B008C; Fri, 26 Jan 2024 21:02:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3595D6B0098; Fri, 26 Jan 2024 21:02:51 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 085DA6B008C for ; Fri, 26 Jan 2024 21:02:51 -0500 (EST) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C75131208AA for ; Sat, 27 Jan 2024 02:02:50 +0000 (UTC) X-FDA: 81723442500.18.7780E20 Received: from dggsgout12.his.huawei.com (unknown [45.249.212.56]) by imf29.hostedemail.com (Postfix) with ESMTP id 29ECC120031 for ; Sat, 27 Jan 2024 02:02:47 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf29.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706320969; 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=Fc2ea8oBDAjhZiCLZolifIy7EWEW0yrJpaeEC6rgGJ8=; b=hMQtG1rClLIqWItU4pvBm9v9zpxle3KIrup/gE1MUhTEwaxoGJUbDW7nZCml7dYPa5gmyZ ITnm+uFBDAW81Hr4hLuw8xx/daaxYrno9wPkjkQsxYTgBIylJjth3/cl7xPeeVj9jJPdbZ y50M1Paguxr+AkF7gEKQcry1jyYN/2Q= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf29.hostedemail.com: domain of yi.zhang@huaweicloud.com designates 45.249.212.56 as permitted sender) smtp.mailfrom=yi.zhang@huaweicloud.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706320969; a=rsa-sha256; cv=none; b=PxpmKtqLrljkh78ydpteFOJ5Rnn/lsDjpjARqCz/alDBIpc7YjI2313Bv9+Il3o06O86kx RS1D13nsH/zSA+DVzbWrYAD45epSaiC2fXzEz87JkEdntMpLIBzu7FX5twncyywq0TfNf0 hZaHd+eRZ6HJQSfZKpCqVP2Md211YZw= Received: from mail.maildlp.com (unknown [172.19.163.235]) by dggsgout12.his.huawei.com (SkyGuard) with ESMTP id 4TMHrb6mYNz4f3lwZ for ; Sat, 27 Jan 2024 10:02:39 +0800 (CST) Received: from mail02.huawei.com (unknown [10.116.40.112]) by mail.maildlp.com (Postfix) with ESMTP id EC58B1A027B for ; Sat, 27 Jan 2024 10:02:43 +0800 (CST) Received: from huaweicloud.com (unknown [10.175.104.67]) by APP1 (Coremail) with SMTP id cCh0CgAX5g40ZLRlGJtmCA--.7377S11; Sat, 27 Jan 2024 10:02:43 +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: [RFC PATCH v3 07/26] iomap: don't increase i_size if it's not a write operation Date: Sat, 27 Jan 2024 09:58:06 +0800 Message-Id: <20240127015825.1608160-8-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--.7377S11 X-Coremail-Antispam: 1UD129KBjvJXoWxZrWkXr1UuF4fKr18XF4UCFg_yoW5ZFWxpr WDK398Crs7JF47Wrn5JF98Xr1Yk34rGrW2kFWxG3y3ZFn0yr47K3W8KayY9F18J3s7Ar4f JF4vya4rWr1UCr7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnRJUUUPI14x267AKxVWrJVCq3wAFc2x0x2IEx4CE42xK8VAvwI8IcIk0 rVWrJVCq3wAFIxvE14AKwVWUJVWUGwA2048vs2IY020E87I2jVAFwI0_JF0E3s1l82xGYI kIc2x26xkF7I0E14v26ryj6s0DM28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2 z4x0Y4vE2Ix0cI8IcVAFwI0_Ar0_tr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Gr1j6F 4UJwA2z4x0Y4vEx4A2jsIE14v26rxl6s0DM28EF7xvwVC2z280aVCY1x0267AKxVW0oVCq 3wAS0I0E0xvYzxvE52x082IY62kv0487Mc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7 IYx2IY67AKxVWUXVWUAwAv7VC2z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4U M4x0Y48IcxkI7VAKI48JM4x0x7Aq67IIx4CEVc8vx2IErcIFxwACI402YVCY1x02628vn2 kIc2xKxwCF04k20xvY0x0EwIxGrwCFx2IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E 14v26r1j6r18MI8I3I0E7480Y4vE14v26r106r1rMI8E67AF67kF1VAFwI0_GFv_WrylIx kGc2Ij64vIr41lIxAIcVC0I7IYx2IY67AKxVWUCVW8JwCI42IY6xIIjxv20xvEc7CjxVAF wI0_Gr1j6F4UJwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr 0_Gr1lIxAIcVC2z280aVCY1x0267AKxVW8Jr0_Cr1UYxBIdaVFxhVjvjDU0xZFpf9x0JUl 2NtUUUUU= X-CM-SenderInfo: d1lo6xhdqjqx5xdzvxpfor3voofrz/ X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 29ECC120031 X-Stat-Signature: 4u7skx8qrph8r4ty39xmnkccq58rs4m6 X-HE-Tag: 1706320967-465049 X-HE-Meta: U2FsdGVkX1/o5zUU12AL0hI1IVAyLrxLZo6TTd3EspOstrMBuCahCShTubdJ+J6ubjWkrx28cMN44u7f/+QqctbWZbPu7cY2WOFAMRgdcAPjrMocmMP0bYR6xVz1wPTHajNnnh/ByqsQDnYhyYfZD5/PvM1BNLMGxl7GfMiv/6+TKzzlE4XTj6E5IlYfUhTzrrquhWxvgxjFikhqmJ+MtC2OvLzfVkntoxcO4ovY9fa5WasABql61Dhn79NrQK8t1AmTQUHDKMgGX//iJEy2R69Suc8983fsFqfpK3TVS09H09JL7ArLlxmiKP3SaI5h07OZ9FojFNTL/eQb3PGfziAh+B2NS9Z1ak36W4bATqtSUc1sIhpQ+Bzx/k11NB/kt2+iRLL8E84DRhU6ZN7pZuMC1a3ZS0tMcGTI6KLMGHPeMfxa/+0tV+x7nJGAp5Dz6rLcDwVKd+nkve3ICVxH58gAgBqUNkI07P4mdZBAk9V8cmm98nRcvY+XHMiD3wTMU4vCvCurUmxlQ0OVmVNK7ihRGwRhs5J0cRRy1dzBK8v+Wo4nh4YbKMDwHeCyKIwLJG0wLE/1UdzyZUO+N7gTje9JHKJyBwZF4lt+oQZzaOFFRzM7n3lh18+U9daaqUn17TNcpRan/dWLzeRflho9NS8OvvveFJ1/5vOMflhVhz7lxhcPNGh9Qijwlen9+89kR5Nz6vIjYtGYiGLviN5YWLCX7AK68DYCTH1/t6BgbY7srjes4enx/Fki/P42UutXGByjNr7eN7/JHUWwMDUoz5sw+b/zhZlH+Ri29xAcaRkRjugRx6+haFh5O1WMKnSpNpBAbt5TGi1nKi5oX7YYhB/v4dMiRgGIjW5NG0zwD0hvcfidWcEMVX3ZunkgPykc1Ck4Qs4N2tzaHieWA7kApwRzEMOutBgyvtDiWmelRirMpr22uf59+o7NWqMSLP0tnxbmoIC6OG26EItUR4C uN16bhXf P+9wGYfHJvoHOBjmr0UPYBdV07+A5nrcZu9meEGtjg+jDNmpLzr7f0dqC68pZ3RMshoXXtaYxCucliXzobCQ/Vcq/aeBUf8dMKWHu5szt/FFMYbjLZnCOSURLoo1QU0PFTldaUt8UnINLV7kMe/BYdLJR/tZ23SxntKLmQUBsAdc7y7GfisjACfPZlM7svVEN4l/Yq4r55/CbN0NnKB0a97RxWA6LNo93fKfbxYNMSqA0zuJrrAcGu+ATS05b+WYAtLRqQVw1pEDjdPiikWBvQk1g3EgnkFkHHK/Hqow3cRJ5OgY= 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 Increase i_size in iomap_zero_range() and iomap_unshare_iter() is not needed, the caller should handle it. Especially, when truncate partial block, we could not increase i_size beyond the new EOF here. It dosn't affect xfs and gfs2 now because they reset the new file size after zero out, it doesn't matter that a brief increase in i_size, but it will affect ext4 because it set file size before truncate. At the same time, iomap_write_failed() is also not needed for above two cases too, so let's introduce a new helper iomap_write_end_simple() to replace the common iomap_write_end() helper which designed for buffer write, and also move out iomap_write_failed() from iomap_write_begin() to iomap_write_iter(). Signed-off-by: Zhang Yi --- fs/iomap/buffered-io.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/fs/iomap/buffered-io.c b/fs/iomap/buffered-io.c index e0c9cede82ee..2ae936e5af74 100644 --- a/fs/iomap/buffered-io.c +++ b/fs/iomap/buffered-io.c @@ -834,7 +834,6 @@ static int iomap_write_begin(struct iomap_iter *iter, loff_t pos, out_unlock: __iomap_put_folio(iter, pos, 0, folio); - iomap_write_failed(iter->inode, pos, len); return status; } @@ -881,6 +880,25 @@ static size_t iomap_write_end_inline(const struct iomap_iter *iter, return copied; } +static size_t iomap_write_end_simple(struct iomap_iter *iter, loff_t pos, + size_t len, struct folio *folio) +{ + const struct iomap *srcmap = iomap_iter_srcmap(iter); + size_t ret; + + if (srcmap->type == IOMAP_INLINE) { + ret = iomap_write_end_inline(iter, folio, pos, len); + } else if (srcmap->flags & IOMAP_F_BUFFER_HEAD) { + ret = block_write_end(NULL, iter->inode->i_mapping, pos, len, + len, &folio->page, NULL); + } else { + ret = __iomap_write_end(iter->inode, pos, len, len, folio); + } + + __iomap_put_folio(iter, pos, ret, folio); + return ret; +} + /* Returns the number of bytes copied. May be 0. Cannot be an errno. */ static size_t iomap_write_end(struct iomap_iter *iter, loff_t pos, size_t len, size_t copied, struct folio *folio) @@ -960,8 +978,10 @@ static loff_t iomap_write_iter(struct iomap_iter *iter, struct iov_iter *i) } status = iomap_write_begin(iter, pos, bytes, &folio); - if (unlikely(status)) + if (unlikely(status)) { + iomap_write_failed(iter->inode, pos, bytes); break; + } if (iter->iomap.flags & IOMAP_F_STALE) break; @@ -1343,7 +1363,7 @@ static loff_t iomap_unshare_iter(struct iomap_iter *iter) if (bytes > folio_size(folio) - offset) bytes = folio_size(folio) - offset; - bytes = iomap_write_end(iter, pos, bytes, bytes, folio); + bytes = iomap_write_end_simple(iter, pos, bytes, folio); if (WARN_ON_ONCE(bytes == 0)) return -EIO; @@ -1407,7 +1427,7 @@ static loff_t iomap_zero_iter(struct iomap_iter *iter, bool *did_zero) folio_zero_range(folio, offset, bytes); folio_mark_accessed(folio); - bytes = iomap_write_end(iter, pos, bytes, bytes, folio); + bytes = iomap_write_end_simple(iter, pos, bytes, folio); if (WARN_ON_ONCE(bytes == 0)) return -EIO;