From nobody Mon Jun 8 18:58:39 2026 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 C2B162F7F12 for ; Wed, 27 May 2026 12:06:35 +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=1779883597; cv=none; b=R0OIxswqWXRHn+TwLl1BvUGGglZ8NdErifVjuWjXoeoMEVRAv7PYMYGB8sDVurHnZ/npUZFt4eEDWx0+6ngYtw+JzxA2ouHxqIo4dHucey7YzpFbsnMe0C3XYvbTmoKyVxpPWOpEuk1VJPXgx12eO5Ra8fNLgnBpjBT18345vdM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779883597; c=relaxed/simple; bh=TgEgnr1BZ0OVCPBckWRzxLonKm6/Z7rfiRA7rPtJJSE=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=hauQm03y5OhFz3gVkCaOm2iUzV7Ew8+2gteluvhfrX8Em26JWlZ+lh34uLBh9Z8qjhWd19jX2nQuKFZqDvlh0TxIP0+OHM1BnFL2nfX3G0Tr/UAXDcaOAttVIQlaBtC9hGJJ7TLteBW6vQ4hY6it4OZg+EEBe4BlSYtPi8J5DDw= 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=CYheVIci; 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="CYheVIci" Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-367c26471f5so7491911a91.1 for ; Wed, 27 May 2026 05:06:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1779883595; x=1780488395; 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; bh=w87yPUao64o6fGhq2gkW4aCOEo2iNW2ProMA0X1oPBY=; b=CYheVIcitg2m/tIs94T6u/3JVwA6nwKV92kEfT8Rmi3qDjGZ8tUhbXhjicS9jHQZ6b FIqRInmvNlntIKyowyagQusB5qWme8YPytoekjPG11X1vACJu1eXIgCp4HIxMEru6zgc A/d1u5CGJdubsuGg1iUijp92ODj3KcNmKajgGmqxbLbiqYIaGXs5gY5DtStv6inX3OfO 1moaV+1QqBLcWkh1ktEySJJBVjYYvv1k6x9ayVfdTw5n9LOT3HIrisHPo52LmGOrab0g d3G7l4vQDOXZxHI27jgzD126bs1XI8Fy/h4PEH5mKxMIRbpmzjicSHcfq5TJ7I75t83i s0HQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1779883595; x=1780488395; 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; bh=w87yPUao64o6fGhq2gkW4aCOEo2iNW2ProMA0X1oPBY=; b=ezA3gX0UMynZ0Cydsh6IMhpgakWLqk64xwWJLv6ti48nX0T6ICUnWvqySHLM5NwVN0 Ln1pcH3gnZsC+JCvFTBMuxuWVSzewA2ibfc7dmU44S5OVZMyAsNtAg3Z/ks66qVKpiA9 WaGJJzD4urALTGuR6/8+eMnz/hXeNEKgMiucdVH3RIaU0jwbrFQM0cd9l9BMJuBbEvpn 0yVDQhUCeYuYVbm6GgjPkft57BT9ecl+pZmcnXfnVj4YqbDv0hi8UGIyTBvTbC6Ay0MR c9J6Zfe05JLjmSwewrNYAzwWozhZvhU51QOkkzQ+lzgRa/OOvb67Pk8+Tsy3BAyNyMP6 0fwQ== X-Forwarded-Encrypted: i=1; AFNElJ8/g+7G835KMJ02nm/FFe/vng4cUQyT/NehjW3R18FRb8TopBmEupv8BxgIT11ub08qsGGHxEj5bzYRapA=@vger.kernel.org X-Gm-Message-State: AOJu0Yx9Pw2QlEB8zAdDfPkXCvphM+hzXlnZhTNS4Z9kJJIcI0ASq+tj gWAguTDdDl8t0EdmJMXYl9bYgY34/edaGCstE/VdRmfphYwEchTH1wiP X-Gm-Gg: Acq92OH0vm6FxjyFK9hDEakREgm82p/jKd6U5x5n9mBF8C683qDRRaUqyrF7N2PmQ76 bGEtXR/Ofds9jcjycJpUou508Bep0Ef0Vu2XqEGO2ssmJTYtKwrAGW57udOXsR9LGbunts1l3Iz xF0keBZoYBHNborgXxX2Lmt5rp7WlPRANFO+RGlaF9Ne9OhcCorsi9fVyrcZLT7zf6O8CgBlS83 H5wsBTRNJlCBrF8CLb6SV3IuLmeKSpJd/j478Ui9eonaxUoKufpUlPKu5l/iV3uXegJG5b4eNps +xgxzxkb3K1diFC9vWYM3sdUdFDB9oKJ7gPlqcwqYAMu89Jkx2jI3kCCfJ0GxOrZ3fuWHBvdFZQ eTMFay19rErq2Jl56qcb2LZtWszJvpma1325M/5d2qdTmrMDb8bsUUdT3bPmcHdtKHI09HA/OI0 /wIUExBIUQZktH4zz6tw4l+2CDjVLPjfjEIELqGy2KxmLxsZgmGZBGb2UMbhUaiAB29X4JB/9yR mgqZXpd X-Received: by 2002:a17:902:ec81:b0:2b2:4697:4370 with SMTP id d9443c01a7336-2beb0368160mr229211925ad.3.1779883594883; Wed, 27 May 2026 05:06:34 -0700 (PDT) Received: from qiwenjie-ThinkCentre-M760t.mioffice.cn ([43.224.245.241]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2beb58c4f20sm149627235ad.61.2026.05.27.05.06.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 May 2026 05:06:34 -0700 (PDT) From: Wenjie Qi X-Google-Original-From: Wenjie Qi To: jaegeuk@kernel.org, chao@kernel.org Cc: daehojeong@google.com, linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, qiwenjie@xiaomi.com, qwjhust@gmail.com Subject: [PATCH] f2fs: keep atomic write retry from zeroing original data Date: Wed, 27 May 2026 20:06:28 +0800 Message-ID: <20260527120628.2255597-1-qiwenjie@xiaomi.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" A partial atomic write reserves a block in the COW inode before reading the original data page for the untouched bytes in that page. If that read fails, write_begin returns an error but leaves the COW inode entry as NEW_ADDR. A retry of the same partial write then finds the COW entry, treats it as existing COW data, and f2fs_write_begin() zeroes the whole folio because blkaddr is NEW_ADDR. If the retry is committed, the bytes outside the retried write range are committed as zeroes instead of preserving the original file contents. Only use the COW inode as the read source when it already has a real data block. If the COW entry is still NEW_ADDR, treat it as a reservation to reuse: keep reading the old data from the original inode and avoid reserving or accounting the same atomic block again. Fixes: 3db1de0e582c ("f2fs: change the current atomic write way") Signed-off-by: Wenjie Qi --- fs/f2fs/data.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index d83a21998ec2..edda2ff72073 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -3862,6 +3862,7 @@ static int prepare_atomic_write_begin(struct f2fs_sb_= info *sbi, pgoff_t index =3D folio->index; int err =3D 0; block_t ori_blk_addr =3D NULL_ADDR; + bool cow_has_reserved_block =3D false; =20 /* If pos is beyond the end of file, reserve a new block in COW inode */ if ((pos & PAGE_MASK) >=3D i_size_read(inode)) @@ -3871,9 +3872,11 @@ static int prepare_atomic_write_begin(struct f2fs_sb= _info *sbi, err =3D __find_data_block(cow_inode, index, blk_addr); if (err) { return err; - } else if (*blk_addr !=3D NULL_ADDR) { + } else if (__is_valid_data_blkaddr(*blk_addr)) { *use_cow =3D true; return 0; + } else if (*blk_addr =3D=3D NEW_ADDR) { + cow_has_reserved_block =3D true; } =20 if (is_inode_flag_set(inode, FI_ATOMIC_REPLACE)) @@ -3886,10 +3889,13 @@ static int prepare_atomic_write_begin(struct f2fs_s= b_info *sbi, =20 reserve_block: /* Finally, we should reserve a new block in COW inode for the update */ - err =3D __reserve_data_block(cow_inode, index, blk_addr, node_changed); - if (err) - return err; - inc_atomic_write_cnt(inode); + if (!cow_has_reserved_block) { + err =3D __reserve_data_block(cow_inode, index, blk_addr, + node_changed); + if (err) + return err; + inc_atomic_write_cnt(inode); + } =20 if (ori_blk_addr !=3D NULL_ADDR) *blk_addr =3D ori_blk_addr; base-commit: c0b65f6129c7fbb526e921dd60261650f1b2bef9 --=20 2.43.0