From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 49CEC34D4C9 for ; Wed, 1 Jul 2026 14:21:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782915675; cv=none; b=SeaDbOc9jEehjC5QyMEl9z5+hlSSblQDI1SMc+mlSUGrDWw+Cr/at0EFfRKFkfzYx9H4EU8mQzV7eS9l6njUmMuD7cEaCdyRtElwLfFnIuFYkoXsykjVXsnQ4bgUgkPlsqas5fxQHWaYlYsgUOfzX1YuBbRmCxOYWlDrJsTRiHI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782915675; c=relaxed/simple; bh=9wUO5aBWCbEq79mGE8ncW3tICfB+vLnX81+Me4XzYzk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nh0+tFFj2z3D6MfaBdAIx+RGSEX7aAm8RBOc7oyQyPIZWOQejUSz4NpNPFMsdABqR8QWafTy8HsmxdUnV1xJESq61fICuiADf/dRGg44y/PtnmuziAltE1YFpELVpiQuoK9RIQRmaxp4nQcS22UyZM/G2XczHdthgzRsWZ9At3A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=QHC/rs9F; arc=none smtp.client-ip=209.85.216.52 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.b="QHC/rs9F" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-3804e42ad5fso569711a91.2 for ; Wed, 01 Jul 2026 07:21:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782915673; x=1783520473; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EtqvUk1phGJrW5Wx54M3QXgxstphVj9+abGNzMb2sGA=; b=QHC/rs9FWoxtB1PRifUr+FiAmzk8HERqC/vN8uIbt9KDSYXcrTRvkR9ZpZmk/3FL1N B9xcqcNFvREOE1FDGHv8fl+J/+MA4bFD9xT4hUgUJz6L/714LKJPAS/rnFr2f6FmReiI ymeO42glAUUtUlv0oe6p9AeFnrxSpnLvSJiQwVfLN3aICC+qnHpxEnM0fLXKjMdtzgMU QoWHPOewTlgIo5HZRmYu63zgxqISOrzovcLZjUd9/INlfMNWGnVpRzlca5z+evB5HDvq vdOyqgzQisSj40Wzoi8wYO6Abtao3nMXxIGLkWGU1eeVr+cEuPE7A7+CXlWuzmeYYHun 3LSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782915673; x=1783520473; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=EtqvUk1phGJrW5Wx54M3QXgxstphVj9+abGNzMb2sGA=; b=dg+by3o9dFZRBTJkEtqbGfsxYqMJo21AD81T6OzcEtsaN24xdkmZeiNOC1PnoEO1d1 ze2NDAgPW3DHZDYL/A7japJtjGZcLNcQKSlZzMvlwVg9M3RZmbn0r2xT+mx2Wgshmdca x9vqqqD3gYI/dk8GITpGhZzfRlo/ukKdjtfaDLw5EMAN9MB0S2scSB+koIVSO6gbJrwr FvkLITODjJxz13i5iKpPFPHAZoqWaLwzMMZOEW/4qSk7tBmpWkNhxFw5VR/D/vN2P/yw xvT8t0kVyKydUxIl/ZYidlv1cffwiSaWM7W+MC7ktPJ+UoWc7gwJo3hEfW7Le3BSAUB5 ItFg== X-Forwarded-Encrypted: i=1; AHgh+RotIR+fIKvj7jvgKUEHWed01KBFHKgCFvUZrEQkuiKm0AZNqSh7JdJn3Iep8QBrw9QNzgSXjVOs8aJmLZc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy1bCLv/8u4nUshRqq9oQuBzIL9+/htUtUWsSZl65Hr7UIwSc5G dz14Yag8BEHp14jmbBGDZs4YV/w2eCHQf6IPjEHd4AZ+zXUXqmO9a7WS X-Gm-Gg: AfdE7cl7knDCk19Q1Yy3s0NeqhzM7HtzCKXdM5uiHI3BopNwEr8lHfQ0L73Eb83OpUS XFHChsV4tMT3xabMvaM5w9n7ohJMn/z8FmeJI3OCz9erlEH37qRU5N1oxcqL7EvWnQQlumMoQBM n8Y7539oJJC02KgVPxvBQyidmKqZSf3UwJO5a9ErD4D/378BtC2iQbzlqo85ppAvQXkoE5KU6gJ DRP2VHScRtBWx5DqvK7GD22FNirm8riUP+TGH4tWrzBAQHE1Fc0bPMA5x3c04oUPRKLLBFVOOQe /izT34BPw2RF/iJmWSx8ojfIo463jIal1uGfpyTEK/MvNDzP4a1iCNGBezDa8mYgnxQpb4dW/WP 6yPaajko4S3iFEniHKNu0jMu9S1JcwpGwAE6Bfmt7t403Surwi/YtJv+9+nj1lHhwjc/1qDHst6 e9HBcu+cefiULX6Nu1ex+3jmoN8jTe6ev3 X-Received: by 2002:a17:90b:4d05:b0:37f:c2a8:ce45 with SMTP id 98e67ed59e1d1-380ba84ba5bmr971883a91.4.1782915673456; Wed, 01 Jul 2026 07:21:13 -0700 (PDT) Received: from DESKTOP-DK6PUT8.localdomain ([124.70.231.46]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c9e32ef8e49sm383894a12.19.2026.07.01.07.21.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Jul 2026 07:21:12 -0700 (PDT) From: yizhang089@gmail.com To: linux-ext4@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, tytso@mit.edu, adilger.kernel@dilger.ca, libaokun@linux.alibaba.com, jack@suse.cz, ojaswin@linux.ibm.com, ritesh.list@gmail.com, yi.zhang@huawei.com, yi.zhang@huaweicloud.com, yizhang089@gmail.com, chengzhihao1@huawei.com, yangerkun@huawei.com Subject: [PATCH 4/6] ext4: zero out whole block for clean edges in WRITE_ZEROES Date: Wed, 1 Jul 2026 22:20:07 +0800 Message-ID: <20260701142009.1510104-5-yizhang089@gmail.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260701142009.1510104-1-yizhang089@gmail.com> References: <20260701142009.1510104-1-yizhang089@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Zhang Yi FALLOC_FL_WRITE_ZEROES requires that all blocks in the requested range end up as written extents with zeroed content. For unaligned edges that were already allocated, ext4_zero_partial_blocks() zeros them directly. However, for unaligned edges whose underlying extent is a clean unwritten extent or a hole, the extent type remains unwritten after partial zeroing, which does not align with the semantics of WRITE_ZEROES. Therefore, when ext4_zero_partial_blocks() skips partial zeroing, it indicates that the corresponding edges are clean unwritten extents or holes. In this case, we need to expand the aligned allocation range outward to cover such edges, so that ext4_alloc_file_blocks() can correctly allocate blocks for the unaligned range. Edges that were partial-zeroed (i.e., written or dirty) are left untouched. Fixes: f4265b8d32c4 ("ext4: add FALLOC_FL_WRITE_ZEROES support") Cc: stable@vger.kernel.org Signed-off-by: Zhang Yi --- fs/ext4/extents.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 7a8f9f188a29..c34505765521 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -4760,6 +4760,21 @@ static long ext4_zero_range(struct file *file, loff_t offset, /* Zero range excluding the unaligned edges */ align_start = round_up(offset, blocksize); align_end = round_down(end, blocksize); + + /* + * In WRITE_ZEROES mode, edges that were not partial-zeroed (clean + * unwritten or hole) must be allocated and zeroed as whole blocks. + * Expand the aligned range outward to cover them. + */ + if (mode & FALLOC_FL_WRITE_ZEROES) { + if (!IS_ALIGNED(offset, blocksize) && + !(partial_zeroed & EXT4_PARTIAL_ZERO_START)) + align_start = round_down(offset, blocksize); + if (!IS_ALIGNED(end, blocksize) && + !(partial_zeroed & EXT4_PARTIAL_ZERO_END)) + align_end = round_up(end, blocksize); + } + if (align_end > align_start) { if (mode & FALLOC_FL_WRITE_ZEROES) flags = EXT4_GET_BLOCKS_CREATE_ZERO | EXT4_EX_NOCACHE; -- 2.53.0