From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.44 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796298754; b=oLLojp084vzQS3J1aW6Nm8qBsu6eMJng01+eEzlCkBkbqbWw1v4z3y8nCcF/Gf8L0aCq h00HTdVkg3FEATvZf7dMspBJ0iQfmx5JdjsWVOuewF60aWxDaYyZ0IbuT2qVG4nqzp/g8 rCwZPs7X+mjpHWM3tKL2y8FYh6TVsjZSXpH+yKv/qcH/TK7nug9TWxZMQswI8G8fmMG5h QLrBniNQ1QqeOx0KFPwG6499Sq5CstrZwRl0E5ckw5W90XW3Da0pKjlXqE98VV74MOSc3 rSW3120O6r1y6Flr9ul4oQ3XkNHvY9Oy9miAXkeeC+FB/WSL3ECUAjDnEYy/c2wpJeA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796298754; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=I/PBOhVav5WA76KeVjLooE87+EOWGSv/KUzaPdN6gdY=; b=gSyMFs4aRkvybNeWykE4pMEGfFhTNs0K8bmp3828YM5YAIpxq6ztt0afdCGIDRmA6+Q+ r9zbNEX0Kw11iWSVOEBC0TrbGYAQdO0hUarTh4jNNrGRXBrRa+tDOzbOEBSpKAZMIxzTA 89ms0bhWZ6YI9bakwsUVKkpUwZL7AgKTKStHVvdClPSf8i5dWO2TgE2HSRXQl+9TO/gYc MpEpvnpkl5D5bf+/IHlFIu71wTEYbar8N7k8lDNzii687kb4rgXn4H5EPSSblPXCnsgee pFIWX5IeXcuyiL5KdPuwUehq3Kwvq9pfWeeY1EhSk3eqMbFgVXQnwYB7OkFR8pshm6A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=bjSyJmuz; arc=none smtp.remote-ip=209.85.216.44 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6F51C606A33F for ; Thu, 3 Dec 2026 11:52:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6F51C606A33F Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=bjSyJmuz Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-3b564fe29cfso2863698a91.3 for ; Thu, 03 Dec 2026 03:52:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796298754; x=1796903554; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=I/PBOhVav5WA76KeVjLooE87+EOWGSv/KUzaPdN6gdY=; b=bjSyJmuz6Qh3NRDpT0kQHyweZPxVL5taZ9sTiizdzo+ev6HErkVEQWQ4Qr37A7gkmd riJ/i9d1ITeSizN1HY9zA/jc3vHIFxydFoaKOmxOijpSig6HuT/osFdMaWtxIPE8yv9Z uLNNzd/PnWfUdnMrzMGMSQ8W/GHTWQOLjHAAxZZQse5wh1dSeCAy1nFudBhATLAMndi0 TPNqTdMjsKdguI2RG5xUsZr8jiutGZospulZPzuxWCdCD4AuRc2ornre1yc8iwduCNCJ hpS+As+soAHurizohHfbjAB2EgbsZjiwPtP6Rnzcbpgc60KzdSnKcfzCNsl1WoSXaTuD fcQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796298754; x=1796903554; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=I/PBOhVav5WA76KeVjLooE87+EOWGSv/KUzaPdN6gdY=; b=OcSP8GvrGlH8etfW+xJNwahN76RvdEc9OxJoVMqC+rz+5wKyXxJGX3T7LSsGvuOXGr mCUQ6Zn/9EXvFfDDh6WbuHP0Vdn96ojRnenjSaqvT/ZxEKexWqqB/Ptd+bktsx6w7zxI VZkWpHO04z4q5/ISKvMzI/OZgIOtqcrGPBuj+JUin+d2f5cBCAjYtx5Oed4/A9a+aLrI J9cDYI8y8yAayjWpc7eBabKXEP/QrxlUXp2lOBk5mefz3BV5obLsK1Z32xUBC523CAOm c9g86Pc5uBXVgE3a4km3DqaDfvR1yA03oDAEHSgNQu2dg4s0DEKbRVMeljaOK7yhP+JB oDLA== X-Forwarded-Encrypted: i=1; AL+hErETl9vzPR1tCHbAAgAZLYfgGCUGCVBPxSXTKoZFg3ivYFVOduvbFMg3QmLggh9455pVTVWml99mfqjL@vger.kernel.org X-Gm-Message-State: APuU4Z8NQNVoUsgt7PQi7z2OjS5boW7iw1HdtzzicyU8SrrZETWN3lv6 aSZGUvaMh1iSHvA9/tdU1LjfzdsGSLeTLe5mp5f+du7bKAR6EXvUyXhp X-Gm-Gg: AZFdTZeAUq8mN9FzNIZC/r/CvODjbxOF+zLq32EBmt53kfIgPmJaoXmiu0tiauN6SbP 2NeixdcR7+B/MYrzqwq6fDjHEHdRLsygw3pZ3uYL8sKIdO4h0RyZfqMQyBw6E4B9sY1JmU1R4xU /3zPn8gBDOX9T+CctZxFulGsTCjeaNxgI4Kwg3pqUBLYo0zU0014x41azwl0HOnP1EB4TgVFnXt EEaHjGjTxVzgEgGiuv2v5Wcs2Mt5LvpUoPFwe4D4q8M0fliF5rWTjjYNLsa8BnS9/Xu/bEUyctQ oq/91646X8W9YrHsmzeXLZXEZxISWQhty2Ka6dPr9oLDqI2AbX6Vbu6RsXv3SPOy+3+cE7K9p/6 2wNIDHeDEJBgnKpZn6ScHh4VUackw+jMjVY3lzDpqBB/cma9fHhleAyunPC4hfMNMupP/byOkjU iJisYJraj7H4x74P/jEVVKF3sDq7cFbK6epWRYHpKCeNmsUW1+/rEnq5ULTdZ2iU8VI2SjukCzf 3ikadcxmFCr4VE+w/r7Z5xwnacl5ftqUtD/Dj9D1IeErWK3DxxgZiMTpHyNR9HxdYWJE+INwIsK CPnzPdwiMEAdNGgTsgsmjx+B/8fTTC27LUsorGU= X-Received: by 2002:a17:90b:1d03:b0:3ab:31e6:12fc with SMTP id 98e67ed59e1d1-3b41c5574f0mr44461103a91.0.1796298753587; Thu, 03 Dec 2026 03:52:33 -0800 (PST) Received: from localhost.localdomain ([64.118.140.61]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b44b6fe711sm30960221a91.1.2026.12.03.03.52.31 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Thu, 03 Dec 2026 03:52:33 -0800 (PST) From: Ding Feng To: zlang@kernel.org Cc: fstests@vger.kernel.org, linux-ext4@vger.kernel.org Subject: [PATCH v2] generic: punch a hole past EOF over preallocated blocks Date: Thu, 3 Dec 2026 19:52:29 +0800 Message-ID: <20261203115229.50163-1-dingf3ng@gmail.com> X-Mailer: git-send-email 2.55.0 X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Blocks that fallocate(FALLOC_FL_KEEP_SIZE) allocates past EOF should be freed by a later FALLOC_FL_PUNCH_HOLE over them; fallocate(2) says whole blocks in the range are removed. XFS and tmpfs do so. ext4 returns early for a hole that starts at or past i_size and leaves them allocated. Write one block, preallocate 16 blocks with KEEP_SIZE, punch the 15 blocks past EOF, and check with fiemap that no extent is left there, and that the size and the data below EOF are unchanged. Signed-off-by: Ding Feng --- v2, from the Sashiko review [1]: - Look for extents past EOF with fiemap instead of reading st_blocks, which also counts xattr and extent tree blocks. - Size the write, the preallocation and the punch in file blocks, and skip the test when falloc -k allocates nothing past EOF. - Remove the test file on exit. - Renumbered to 811: 810 is "generic: test that insert range respects RLIMIT_FSIZE". On v7.4-rc5, x86_64 under QEMU, it fails on ext4 (an unwritten extent stays past EOF), passes with v2 of "ext4: punch hole beyond i_size", and passes on XFS with and without it. v1: https://lore.kernel.org/all/20261203091452.74081-1-dingf3ng@gmail.com/ [1] https://lore.kernel.org/all/sashiko-outbox-247464@kernel.org/ tests/generic/811 | 52 +++++++++++++++++++++++++++++++++++++++++++ tests/generic/811.out | 2 ++ 2 files changed, 54 insertions(+) create mode 100755 tests/generic/811 create mode 100644 tests/generic/811.out diff --git a/tests/generic/811 b/tests/generic/811 new file mode 100755 index 00000000..b8ec6a2e --- /dev/null +++ b/tests/generic/811 @@ -0,0 +1,52 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2026 Ding Feng. All Rights Reserved. +# +# FS QA Test No. 811 +# +# Punch a hole past EOF over blocks preallocated with FALLOC_FL_KEEP_SIZE +# and check that the blocks are freed while the size and the data below +# EOF stay unchanged. +# +. ./common/preamble +_begin_fstest auto quick punch prealloc + +# Override the default cleanup function. +_cleanup() +{ + cd / + rm -f $tmp.* $file +} + +_fixed_by_fs_commit ext4 xxxxxxxxxxxx \ + "ext4: punch hole beyond i_size" + +_require_test +_require_xfs_io_command "falloc" "-k" +_require_xfs_io_command "fpunch" +_require_xfs_io_command "fiemap" "ranged" + +file=$TEST_DIR/$seq.file +bs=$(_get_file_block_size $TEST_DIR) + +# Print the extents of $file in [$bs, 16 * $bs), holes left out. +extents_past_eof() +{ + $XFS_IO_PROG -c "fiemap $bs $((15 * bs))" $file | tail -n +2 | grep -v hole +} + +rm -f $file +$XFS_IO_PROG -f -c "pwrite -S 0x61 0 $bs" -c "falloc -k 0 $((16 * bs))" \ + -c fsync $file >> $seqres.full +[ -n "$(extents_past_eof)" ] || _notrun "falloc -k allocated nothing past EOF" +before=$(md5sum < $file) + +$XFS_IO_PROG -c "fpunch $bs $((15 * bs))" -c fsync $file >> $seqres.full + +extents_past_eof +[ $(stat -c %s $file) -eq $bs ] || echo "size changed to $(stat -c %s $file)" +[ "$(md5sum < $file)" = "$before" ] || echo "data below EOF changed" + +echo "Silence is golden" +status=0 +exit diff --git a/tests/generic/811.out b/tests/generic/811.out new file mode 100644 index 00000000..cf30f69b --- /dev/null +++ b/tests/generic/811.out @@ -0,0 +1,2 @@ +QA output created by 811 +Silence is golden -- 2.55.0