From patchwork Thu Feb 2 20:44:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 52166 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp464664wrn; Thu, 2 Feb 2023 12:47:10 -0800 (PST) X-Google-Smtp-Source: AK7set8lxnodwsoKammNuhDWHdLJY9ig1ulpwItDKOfCPO2/eazUQCE2aeFU+dSTFrhWCUQomobU X-Received: by 2002:a05:6a20:1446:b0:be:93c7:4f69 with SMTP id a6-20020a056a20144600b000be93c74f69mr9538687pzi.52.1675370830226; Thu, 02 Feb 2023 12:47:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675370830; cv=none; d=google.com; s=arc-20160816; b=i/PHC5lzmEFBTOdiiNWisL6fazeN52yYOWHPuoLuEE8UeQYTrtx+Xw2ob5ZRz/RVpO FF9XgrKHD2nUCDuUVuYtwpmHa2RC/prgH8zv0HWaJI6HUZC+xe0QV3bU45412KqLSmur xYa8OEvxB5qE9yGeep4IXz0CJC7sZVAQJHuga5t97vofLpFxUwIk7LtpB/InN2z0RpBh YKERbitvzke8o5ElpjGWre+fnRzr85haoWdIG4hydg36xn5T+ay+EbaaQCTitioWhQWD 3azW1Q1KUHd1GDMzmF1famf++K52uuYJQBuR7rtzNayghGq9Hqx6O1bH769VE4Xk5scs psPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EKEz4nt5nAILCQ0WhorvddY3Ohu5ukrqmYNOFRKi6c4=; b=0+PNGUF3azvrCWPfliLFHdITPfy8L9Bz2ibskq8lnmvuNnJktxpukU2Wy0yRiJtfqr B10hpwTZMt9EPAixwjVVz8biMUmHgtA0X+t74/WqvwigE8ceXOxaiNOa8gCMgTH5r3xw s2GMAXJrdiPVZoy/Zn5a2O5qQchM74zeBUUcEp5Od6rbqMAXOeK+biPjtHrEgH5i2PJJ gnBSQ6pQbl2AIqrCAGTgkk6v23NaICr7/fHDvITKU+YgJqFFmgA0FsgES1bfk7RvgWeI UoUvtyARGKPh4OLVrk5r4unA96vhC6dLO53rhivRp55myTHCbBnoOh3YttrW3dADwwGo Uuew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=GX1Qllwr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a20-20020a637054000000b004df6eb7dfcasi551710pgn.303.2023.02.02.12.46.58; Thu, 02 Feb 2023 12:47:10 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=GX1Qllwr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232922AbjBBUoh (ORCPT + 99 others); Thu, 2 Feb 2023 15:44:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41640 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229761AbjBBUof (ORCPT ); Thu, 2 Feb 2023 15:44:35 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C73128A43; Thu, 2 Feb 2023 12:44:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=EKEz4nt5nAILCQ0WhorvddY3Ohu5ukrqmYNOFRKi6c4=; b=GX1QllwrfhDN5IKVNAciO3qEvo z1zvwuCrdT1EFPb+2uaPsl1XDsVWPvzn1FMeJ0+uKpjTftB94HKpr9d9x2074LhVEQcw+hsfCA4Ah s0I0YoFtRcRZl1R//0GffZdIIGKtEY0+gAXCMMK0Mm9Ix40T/P2zrT8FUsuOIUPpX32dwL6SOxTnF gk//hnp9hqX5Yqrk1rLBCmuZ4pue3Y9IMSfFWn25PJEwgpTvGYpLCzE5iewZvsAyqxTGcrgxzqePp RKnecjNgS+kjWIwJOXmaxQBJ1Iao/OKNm8LAHXcXxtyy6p30R/c2HxpHN4V3gsFGa6jwPx5TOr/eO tKTST7YQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNgRb-00Di7j-LB; Thu, 02 Feb 2023 20:44:31 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-afs@lists.infradead.org, linux-btrfs@vger.kernel.org, linux-ext4@vger.kernel.org, linux-mm@kvack.org, Hugh Dickins , linux-kernel@vger.kernel.org, fstests@vger.kernel.org Subject: [PATCH 5/5] btrfs: Zero bytes after 'oldsize' if we're expanding the file Date: Thu, 2 Feb 2023 20:44:27 +0000 Message-Id: <20230202204428.3267832-6-willy@infradead.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20230202204428.3267832-1-willy@infradead.org> References: <20230202204428.3267832-1-willy@infradead.org> MIME-Version: 1.0 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756753643503011501?= X-GMAIL-MSGID: =?utf-8?q?1756753643503011501?= POSIX requires that "If the file size is increased, the extended area shall appear as if it were zero-filled". It is possible to use mmap to write past EOF and that data will become visible instead of zeroes. Signed-off-by: Matthew Wilcox (Oracle) --- fs/btrfs/inode.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 98a800b8bd43..b61ec4bb9cf0 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -5234,6 +5234,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr) i_size_write(inode, newsize); btrfs_inode_safe_disk_i_size_write(BTRFS_I(inode), 0); pagecache_isize_extended(inode, oldsize, newsize); + truncate_pagecache(inode, oldsize); ret = btrfs_update_inode(trans, root, BTRFS_I(inode)); btrfs_drew_write_unlock(&root->snapshot_lock); btrfs_end_transaction(trans);