From patchwork Thu Feb 2 20:44:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 13126706 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 7CD5BC64EC6 for ; Thu, 2 Feb 2023 20:44:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 635756B0078; Thu, 2 Feb 2023 15:44:41 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 60AAB6B007B; Thu, 2 Feb 2023 15:44:41 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 51FEB6B007E; Thu, 2 Feb 2023 15:44:41 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 3A5F66B0078 for ; Thu, 2 Feb 2023 15:44:41 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id ED3D5A1029 for ; Thu, 2 Feb 2023 20:44:40 +0000 (UTC) X-FDA: 80423530320.24.7BF56CD Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf28.hostedemail.com (Postfix) with ESMTP id 3694FC000B for ; Thu, 2 Feb 2023 20:44:39 +0000 (UTC) Authentication-Results: imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=nBecBO+l; dmarc=none; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1675370679; 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:dkim-signature; bh=2Gu1J17vUOqah9snYcpOpRqgXozaOqIS6UOuMS3TPDU=; b=Kp/sm1ycRawyLMSCvLMS1yibDtN4ekB66E/oHGWUPRQpfIMEinq3n1l4uusFqGIQ50JXO+ i9qHUdipCjMGEsmPJ+9+7ddms4VmADnzm9NkBQBExL5cxJbKtiRQL/xIQMFUPrEgCiDXSx Y/RjC9wKLFXTPfzJKgHmFA6aYmBFL7w= ARC-Authentication-Results: i=1; imf28.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=nBecBO+l; dmarc=none; spf=none (imf28.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1675370679; a=rsa-sha256; cv=none; b=qjS9Nth92pBLs90pCadvgzjouCJwhUEaHIe7Ip7lKpFmJsYM9ocVtHQBpG46MYmrvIZ+XB 8W/VlQgdek15hjO7chAdqpMOa1J2xAn/LCAKyGG95Y4B6i1xKHgVuA9t3ikX8a73r3r4PS EaOzM8y81YX3zH3ePykgzQ7lqbw6HJI= 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=2Gu1J17vUOqah9snYcpOpRqgXozaOqIS6UOuMS3TPDU=; b=nBecBO+le/dfpA61aDSji/IT8c Jtpk5VIkJ0m1vBtuaxptXdJ/oIIbbAH0pqvZqcVxvttuZlRtLDKXIhaa23N1SjMEkbKDNYis6ShNF Rsig0553S1/uylbIfEMobwRyeLj+CgHeUmJPqVvGzNqX88Jd57qQtQegCyncP+63tRKILRWPihjb5 yCGI0RNgt3IIXMzIMmRWkUrf5vPGvU8xF2ShjG7/W+zpd49ew3/BhME1TE88PpbjIZsdOKHx7QGXD WfS4Y1QKwclnEZiFBnuwCJT7n6IYUwe/ERhek6N/j+EKTi458KfQRGCiCnV353LqlnIg/JOWmJmF3 QwgiXE+Q==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNgRb-00Di7p-Pr; 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 6/5] generic: test ftruncate zeroes bytes after EOF Date: Thu, 2 Feb 2023 20:44:28 +0000 Message-Id: <20230202204428.3267832-7-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-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3694FC000B X-Stat-Signature: h9j9xeaauqsayr8wacjeczyy5bkmz58z X-HE-Tag: 1675370679-100491 X-HE-Meta: U2FsdGVkX1/pPkU33Tx2Xa2LU31sXXzQjYV0Mgtw7+Paalgo2jCE401r3wbhT7MhhTEq2Yt2QwhLwOmyUMqajeElkAWvoqUQLOkEafKkKah9mbkooOXoPaMT6i5HpVf/ai8bDmbnoqCHoixKVZOWQo7cbO3f9NJe1F632KIj/ZrHmNoxVTZA7UrKY5E5cyk0plOPdPK6dzm4pjOrBYKCJCsS/idktBDL1JVFA9Dx2t7a+lS5ABHJJDIvjBH9pDCFY40z1+Znr17D588ywQHQGgRC8FtS5kNl8Wqy+U2svVq2d8QSFf/jQBxtyZZXSnF/zSI6gFNLRRC/FJ9XJ2XZwy+UBGJj6jJRoEDvZuGqigtRwl4W49bjRrjYJ9fnr28v4kj6Uh/pqwa0PSdHEek9+jTWTIG9fErCG2KyW/NLHvYapF71l1le/7HT5dQsUx4gTdF2wig4lpoavlMmTXQpAA+lYubEhwKUfcDPThN/9WMlXd3Q3/WqrIPaZ7D0NLLz+M8wcNYNkgpnnSL9hgvnWpPTgoWwmD/lEAk11tPmSSDZn7YgC+XS9TW9s68o6z030obXAPKxPSjJvPvPPeYIH5axsCeSDoOimRJZ2TFeD0J4GGtrycQC96QeJTGy8FTBbeKO8yDdStZZHoKLJYpSoSDsQObc6NoZ8IrmRFQmK8cSScGZBpZb/1PiM7JTqAXwI0njsoomDMhVS01d8Qo1GmHPLYuTK8+mWK5VW3C9vPnvG5NlVfZ6OVjqekFJe9Mj0t+yUyTQsznckCHuR7RBV2rfSCMFKfPjR7OQmf3wSMYGd0W/auDfTFA4nXBixvQJS5PQkHOhxH1N8NQd+n+j78xNEr6M6/xONgVSP6jJlK5fFHMGqd5LQbBY5hPcXCkhqGa8k473IiOaTriJTcnim7qbyNhAMg2axWUC7rJ/LiH9lfCB4WY9v021Xo2UZek87eGwz8NYx/mSdFTcKjP PyjvU1yp 5Mbdn4NEzAqIvwnL2Kx6NSKSPlZp7sAg/nBMwVprjSXX4L5VEhIJHVtEPD9PBunCOL2HzU3Sl7sGKBNMxFZ0SWMXzI4HFi7EtEks5A6mxVLHF8SRQyoGrg1AKI/i0QVsauXp0GycNZ12RPK5cBiUcfkFR8+nr9Od5tP9QVUO4ES6xj6a835UkhFgeuM+bg93AO8/RBgWWRzzYG578nvpv4/FYar3/yIbyhwnlsxLFsrW+W6ezXCM0EgcfYyNaR0KjNdfqD5oYCb0NJJCKMDSZyEROp3fFsl2V4b+e 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: 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 @@ +#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!" + +echo "Silence is golden" +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