From mboxrd@z Thu Jan 1 00:00:00 1970 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 38819C61DA4 for ; Fri, 3 Feb 2023 16:35:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B6A0F6B0072; Fri, 3 Feb 2023 11:35:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B1A2E6B0075; Fri, 3 Feb 2023 11:35:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9E2386B0078; Fri, 3 Feb 2023 11:35:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8C77B6B0072 for ; Fri, 3 Feb 2023 11:35:22 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 49A63C069D for ; Fri, 3 Feb 2023 16:35:22 +0000 (UTC) X-FDA: 80426530884.07.4FFF538 Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf21.hostedemail.com (Postfix) with ESMTP id 081391C0019 for ; Fri, 3 Feb 2023 16:35:18 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=roStwUNZ; spf=pass (imf21.hostedemail.com: domain of djwong@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=djwong@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675442119; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ZH4uyRMKA1dqXrPfaCv5ByZPiTi3ubM5E3rQXk8u4l0=; b=b4fTi0GbIumJ8RNsweuV1npx+qYlrJw8kPnIxiSRPyNjfoqyxb7/nV/crjWeQEBq8dzff2 m3/dNIDn9T8GAcXJQNOGKBwNFHzhO4F5qtLA6QibBO0jLnRABLrpdkx5w22gxurUk/y/EK Ai1KtyU9wRa5MnrFWMtVYu1BAmBofCc= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=roStwUNZ; spf=pass (imf21.hostedemail.com: domain of djwong@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=djwong@kernel.org; dmarc=pass (policy=none) header.from=kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675442119; a=rsa-sha256; cv=none; b=lSMG7ur8Yqw845RNlM3BVa8A4Gi05ZJurJ2+s/FfVkmf4Q0zjW1DSptp91feWyZdeAd+MG 5p1Dq0qFFbUEOPV+/lB0BeEIuJbnmOSgkE4pyhcw38wUISvBOLs5ZCpewXWFKzfDFoMdhk EWIPAypfDgaYu8ZPZb+s8h/XSVmzS8Y= Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sin.source.kernel.org (Postfix) with ESMTPS id CD16BCE3088; Fri, 3 Feb 2023 16:35:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1656EC433D2; Fri, 3 Feb 2023 16:35:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1675442114; bh=LAFGFgePgf3ook4iBuOc/zox8M9eHm7XWKurXaYi9tU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=roStwUNZB17qeESPC5wt3x03laInHjWwbx3Ss06y3w9LYsMErvt627S9H7FpxMb1m Og+GQc4Hpj5HsAu8K4dXX0QoT+twn1yLxlSE6JLBp+LjSpNqETOFOCz/KUcqkkQu97 2IIYFkvcWCfmrPXr+dppMqQUN7rSSUDrzje8gJz9RqamD68la3WroR4sjygBsewLvj sXxDhRD0pcMI1Lp6yacKN1H0Jq8ak1v01dQ78Ov4xC3Z7W6BAqFbq+DwgO6x7BiP0R mYKw1rfnsJ76aTMAA2yWAI4ZhazhlVOj5D4s+GY4aIaJKi81C2punu2APFLsVghkBa sf7gha6q7Wi6Q== Date: Fri, 3 Feb 2023 08:35:13 -0800 From: "Darrick J. Wong" To: "Matthew Wilcox (Oracle)" Cc: linux-fsdevel@vger.kernel.org, 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: Re: [PATCH 6/5] generic: test ftruncate zeroes bytes after EOF Message-ID: References: <20230202204428.3267832-1-willy@infradead.org> <20230202204428.3267832-7-willy@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230202204428.3267832-7-willy@infradead.org> X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 081391C0019 X-Stat-Signature: zqztmjftc4rd5hrub8ykzybh8gcec59c X-Rspam-User: X-HE-Tag: 1675442118-988071 X-HE-Meta: U2FsdGVkX1+clCTElYyOSfiNQjBP2R5Z/5vLNA3RbBB1xhJHUectCaujGS4HBG8YVznqHGv5+n7qScef0De/+o3DaLV0vDOeYnKIcQI91HdcBxTcHe07BcaqsHdw2BmcQChuyoIxb39e5Z7xkYjiwFfl4G3abfVL5EP6e9U/hvMCXRAicNUPFNJVfZDBvB/PfiHGHVwSCKW9jrQR147xmM8u6dxN8dEaDs+jpwIBICcKPpXgbsRUXKPZi3FOhDnQIYqn4fRnSEk1X3dL9C1E7P0m3vnLH6z0SdwnYjCc6/1LxxMV7rqsbmqK/4xlsTgT0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83x9RtQAsS/r+3crW2ly7DnL/sL44KoRlOHbMnmOcwlYa2yx 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: On Thu, Feb 02, 2023 at 08:44:28PM +0000, Matthew Wilcox (Oracle) wrote: > https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html > specifies that "If the file size is increased, the extended area shall > appear as if it were zero-filled." Many filesystems do not currently > do this for the portion of the page after EOF. > > Signed-off-by: Matthew Wilcox (Oracle) > --- > .gitignore | 1 + > src/Makefile | 2 +- > src/truncate-zero.c | 50 +++++++++++++++++++++++++++++++++++++++++++ > tests/generic/707 | 31 +++++++++++++++++++++++++++ > tests/generic/707.out | 2 ++ > 5 files changed, 85 insertions(+), 1 deletion(-) > create mode 100644 src/truncate-zero.c > create mode 100755 tests/generic/707 > create mode 100644 tests/generic/707.out > > diff --git a/.gitignore b/.gitignore > index a6f433f1..6aa5bca9 100644 > --- a/.gitignore > +++ b/.gitignore > @@ -169,6 +169,7 @@ tags > /src/test-nextquota > /src/testx > /src/trunc > +/src/truncate-zero > /src/truncfile > /src/unwritten_mmap > /src/unwritten_sync > diff --git a/src/Makefile b/src/Makefile > index afdf6b30..83ca11ac 100644 > --- a/src/Makefile > +++ b/src/Makefile > @@ -19,7 +19,7 @@ TARGETS = dirstress fill fill2 getpagesize holes lstat64 \ > t_ofd_locks t_mmap_collision mmap-write-concurrent \ > t_get_file_time t_create_short_dirs t_create_long_dirs t_enospc \ > t_mmap_writev_overlap checkpoint_journal mmap-rw-fault allocstale \ > - t_mmap_cow_memory_failure fake-dump-rootino > + t_mmap_cow_memory_failure fake-dump-rootino truncate-zero > > LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \ > preallo_rw_pattern_writer ftrunc trunc fs_perms testx looptest \ > diff --git a/src/truncate-zero.c b/src/truncate-zero.c > new file mode 100644 > index 00000000..67f53912 > --- /dev/null > +++ b/src/truncate-zero.c > @@ -0,0 +1,50 @@ Needs to have a SPDX header and the customary Oracle copyright. > +#include > +#include > +#include > +#include > +#include > + > +int main(int argc, char **argv) > +{ > + char *buf; > + int i, fd; > + > + if (argc != 2) { > + fprintf(stderr, "Usage: %s \n", argv[0]); > + return 1; > + } > + > + fd = open(argv[1], O_RDWR | O_CREAT, 0644); > + if (fd < 0) { > + perror(argv[1]); > + return 1; > + } > + > + if (ftruncate(fd, 1) < 0) { > + perror("ftruncate"); > + return 1; > + } > + > + buf = mmap(NULL, 1024, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); > + if (buf == MAP_FAILED) { > + perror("mmap"); > + return 1; > + } > + > + memset(buf, 'a', 10); > + > + if (ftruncate(fd, 5) < 0) { > + perror("ftruncate"); > + return 1; > + } > + > + if (memcmp(buf, "a\0\0\0\0", 5) == 0) > + return 0; > + > + fprintf(stderr, "Truncation did not zero new bytes:\n"); > + for (i = 0; i < 5; i++) > + fprintf(stderr, "%#x ", buf[i]); > + fputc('\n', stderr); > + > + return 2; > +} > diff --git a/tests/generic/707 b/tests/generic/707 > new file mode 100755 > index 00000000..ddc82a9a > --- /dev/null > +++ b/tests/generic/707 > @@ -0,0 +1,31 @@ > +#! /bin/bash > +# SPDX-License-Identifier: GPL-2.0 > +# Copyright (c) 2023 Matthew Wilcox for Oracle. All Rights Reserved. > +# > +# FS QA Test 707 > +# > +# Test whether we obey this part of POSIX-2017 ftruncate: > +# "If the file size is increased, the extended area shall appear as if > +# it were zero-filled" > +# > +. ./common/preamble > +_begin_fstest auto quick posix > + > +_supported_fs generic > +_require_test > +_require_test_program "truncate-zero" > + > +test_file=$TEST_DIR/test.$seq > + > +_cleanup() > +{ > + cd / > + rm -f $test_file > +} > + > +$here/src/truncate-zero $test_file > $seqres.full 2>&1 || > + _fail "truncate zero failed!" Omit the _fail here because any extra stdout/stderr output that is not in the .out file suffices to record the test as failed. _fail is only useful if you need to exit the shell script immediately. > + > +echo "Silence is golden" It's customary (though not required) to put "silence is golden" before "but my eyes still see"^W^W^W^W^Wthe test starts running programs. Other than those minor things, this looks reasonable to me. --D > +status=0 > +exit > diff --git a/tests/generic/707.out b/tests/generic/707.out > new file mode 100644 > index 00000000..8e57a1d8 > --- /dev/null > +++ b/tests/generic/707.out > @@ -0,0 +1,2 @@ > +QA output created by 707 > +Silence is golden > -- > 2.35.1 >