From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.216.49 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796298754; b=nLlT/d/VC/98LEjCHQwgM7bNnBQaqCpox0kechbd/G9QXH+nho/ifuG3DvtdDi6IOBue SRj3y+lWVMCOOnAfgiql6OIY01EPmfdEcda9Ew35ncOXJhhbJR/gv31JROfu19dN85aGo gLGZe24ShARcP8wXMMhkgioAxWpzuWV0ieDiuopbN7GP7uSLzq2AfymgO42B/kQkAn8p7 kTY81PVIkyQ/bzWxWLym1fMKJUKwajk1vDz1iDj0nBYi5Bo5fPMKHbhdp2vilSBba22// LQg9O1PzpR4YX508JFOwQGXkvaoKGvVHaG/XVI10Y0rQ+UtO52RX1vjfjUfPQPwYWFg== 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-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=yQ3SUZXWxvyvzO2hGrXgjPm68Nt05mwPIV9uRFitHjmhmyQilKZr0ftH3lIIGi1UfGYl 3n6tZxzuzFZHcL3xMOnUxa+IASw9Gt+dyTPVSMk2r7JQtZj8TQ1cNnD1Xf1FbxzyTAyg7 KwNyR5NgtSsDo3pSpQgTeDugAc9He6Tk9xZxiAAj33mrTzL82vKUyfZA/40km8731bqjD 93AIokV55eRAVXeBt7q6fGPKfsxYJxwtf/FL77yTQXIBXEjuwV6zCmCcn7UNpx4wB77DM l+V/1x9hZXyfgVGGtqB6btZjQaqDJ9drcGQcadC/XH2PqXVmJJrz25ZUVejARlAM24w== 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.49 Received: from mail-pj1-f49.google.com (mail-pj1-f49.google.com [209.85.216.49]) (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 57FCE606A33D for ; Thu, 3 Dec 2026 11:52:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 57FCE606A33D 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, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=bjSyJmuz Received: by mail-pj1-f49.google.com with SMTP id 98e67ed59e1d1-3b532f8a51eso3199444a91.1 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=YuP6CjVK7q2UJ4bH3CTlluN3q5yoryAvddSsIoY1SvnG6F2MCLzpl1cNqgSzG74Cw6 wgEG5YkBMh+HnrmFgSSWZGT9xeBUwCHVzUCCgEWYy94mYgUlhf9+OvlSiu1RV6ioefkP 495Z+IjXjbqms6YxL2brGETn3nBw0l4YKM7FwszB6bZzUhUh7LBfYH5gNqLPms5C3X7h 9g09P8n81hZfF+3ATiWbA2DhEluqOCsJLiWkFdBDXz1d2Kj0vdD8tb7dsaH/0bUBxpJu jaef5ahns43PYRxKHgCI/OyTBwS3560A0oxXUMqT+LkeVEeF2hgeTp38OxujAQ6aqpcl QmWg== X-Gm-Message-State: APuU4Z8tWz0kGcsPQMmeWlrT24rZFIR7NO5kGzm/tUqrk/sP9/PMsY/W U5Psyd2mrFCEqx6lHBa7Sfppe1xv17aJAbLQCD5Gk1wpWAsS+ZSAiLeSaWLO4A== X-Gm-Gg: AZFdTZdUKBPMHLcS+Trv/HeffOaZA98c3iK+FAtzXmvOvvrtCe0axG6Iw/mBCAIcOIj 14+iB9+AeesanJvX49dvj6P1x8omA1BDEln/Yb2CfBzfhPgNwbQ2F2veErBr3WUqy+R7lwjrsee iOtl+49aDgHRELGGroQYKW+VqMrbGaNAU0AkKmNM08FEVkyJU0tP+quA6QqpF83NEPvyRcOtGLr UmwHuO9t7Np13stmlEHnYH3eF1l7tL/1WjaWm7k9EHgCcQWBx/K3gL82Cb01tWDpDCjcLexH8Ye s+iRPmT383oVE60NYQ6EvJvcvvkkDo0+5/BRcZ3YhrYQSUonkfWyKmaszc3+56o57iP8IAjkPaH 4+DEAznqddC8q4QzWms1akd8oliDV70ei2GDGIQScr6Nr9kZEOdIIbKKFjP+BIwkVndkipAN2ld RxHjm3xjdfL7YWFwMVTIXPg/i9SNlnKRnh8XGERdyl+f1/LtMvdTMmocQDu51P2E4Ge7Gx66fTU tNhkwM+My3EHSjXUNldEUf8AqYQ60WvpYpyCekWArcJuaBgdCrhboLOSNEp4NjD3LMjFvs5QzyB yb/h4S4ko14edJ9ktf7SACl/8a/+gCemSQiylww= 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: fstests@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