From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=109.224.244.108 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796257077; b=D4DOVeM5keTu7Nbsuob+3iNtyhcMR9OxicGAaWqAWNoO3dLWqMOfg+I5J0TF+swXZYSw 7lfaXvdDzM+qmLhwJtmxIga+CNzwvx2HMumkA9l6ShnWqwKtZ/tJCqiYl8IYshISpuMRO MPjw1ivB90eu/B619OLPaQmzHudY2Ys/lodHGq2t2EBve86CWHRVsGcNNUCZaNfP4+Ue1 hv1v/ckqLF8RRJQG1q2p5g1uZrNtwEyXk3SK2vthinLmRBvmxAJShaFVlV69+Wb7xfAEi bUql8qCFHNbJHX54XOvhu0DG0lRLGXQBC1Gy03W5QsyA8wFc/jNln/3UiitI9oLpuxQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796257077; h=DMARC-Filter:DKIM-Signature:X-Pm-Submission-Id:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=TJNZVNibmG5XhhgYVwLaD4GYV1J+eWvPUl3dVyEdUdQ=; b=XGRGksOEwby86apMFaCSzMwLSXBiWgo1rPQWNHkwyw/13mi4g4nTSYqy8VPIUeKReuNy Im9/mxY0Em3izJT20ZAgp2ZQGY4UobitSR+UFuEnH3oSzVHSGMqXI9AI3hPOlB8LTdCme 2BvoXtDkEAnKj3chW9ug7RCS9gefa7ZxeHd5pXityufQuoSNtH5GjqlLgwNF64S4IDUsu EhZbPdX68I/82JKYim/UyllnVx/F3M+8SOiUrbAtPQAOmlpbGl47vZlKKNrfF/8eiQ0MQ rxTkYmh/cMcyzLcN277J9OHvkOlTIzqrU+txqYpACPTShhEayFa+BB6rpF96Z2elIig== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=raidlab.org; spf=pass smtp.mailfrom=raidlab.org; dkim=pass header.d=raidlab.org header.i=@raidlab.org header.a=rsa-sha256 header.s=protonmail header.b=cPdE0nao; arc=none smtp.remote-ip=109.224.244.108 Received: from mail-244108.protonmail.ch (mail-244108.protonmail.ch [109.224.244.108]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 451A7606A322 for ; Thu, 3 Dec 2026 00:17:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 451A7606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=raidlab.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=raidlab.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key, unprotected) header.d=raidlab.org header.i=@raidlab.org header.a=rsa-sha256 header.s=protonmail header.b=cPdE0nao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raidlab.org; s=protonmail; t=1796257071; x=1796516271; bh=TJNZVNibmG5XhhgYVwLaD4GYV1J+eWvPUl3dVyEdUdQ=; h=From:To:Cc:Subject:Date:Message-ID:From:To:Cc:Date:Subject: Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=cPdE0naoGyqXULUECfHLtbYzNwPg9NatraBZYSj5XrX1BvDCl8VlPmiKnDIZrvKlZ 6Woqlaz/US9oqIpOwprGWZh/XvLmpJt5orfLICPkZe6Hh1x7IgXBjzFykQ7ZIFwP+U tOSiZAj/3jMHHMDU9qlLwSp1ztVIjPHeNS2H8sDjB0FNtsYfCyGDSXHcPg7fsjEdfj hWQahiUtW5egV6CeYrMKfYIvgVYhsbh0orRC/u4ZaGLHHMMuSPxWAMkDZIgWxGmO2p BY1DJvKXE4Bvemd2VHx+x6USUtK7MSUIPErV/zy3v2gi61lOYIhGuOJn3qCqBv2O9o RcMfi1usvKguQ== X-Pm-Submission-Id: 4jfwF73vmbz2SccZ From: Miroslav Cimerman To: linux-btrfs@vger.kernel.org Cc: David Sterba , Chris Mason , Filipe Manana Subject: [PATCH] btrfs: fix fsync of an evicted file logged only as existing Date: Thu, 3 Dec 2026 00:17:43 +0000 Message-ID: <20261203001743.401733-1-mc@raidlab.org> X-Mailer: git-send-email 2.53.0 X-Mailing-List: linux-btrfs@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 btrfs_inode_in_log() takes a file as logged if it was logged in the current transaction after its last change: logged_trans == generation last_sub_trans <= inode->last_log_commit last_sub_trans <= root->last_log_commit A directory fsync logs its new files with LOG_INODE_EXISTS. This sets their logged_trans but not their last_log_commit, so that a later fsync of such a file still logs its data. However, an inode that was evicted and loaded again starts with last_sub_trans and last_log_commit both 0. The check then passes, and the fsync of the file returns 0 without logging its data: mkdir /mnt/dir sync xfs_io -f -d -c "pwrite 0 64K" /mnt/dir/foo touch /mnt/dir/bar ( cd /mnt/dir; sleep 60 ) & # keep dir in memory sleep 0.1 echo 2 > /proc/sys/vm/drop_caches xfs_io -c fsync /mnt/dir xfs_io -c fsync /mnt/dir/foo After log replay foo has a size of 0. Start last_log_commit at -1, so that an inode counts as logged only after it was logged with LOG_INODE_ALL. Fixes: 2f2ff0ee5e43 ("Btrfs: fix metadata inconsistencies after directory fsync") CC: stable@vger.kernel.org Signed-off-by: Miroslav Cimerman --- Found while analyzing a FuzzyRAID finding. Reproduced on for-next with dm-flakey dropping writes after the last fsync: the data is lost on stock and kept with the fix. Prepared with help from an LLM. fs/btrfs/inode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c index 539b1851a477..2e1cb26a5aa1 100644 --- a/fs/btrfs/inode.c +++ b/fs/btrfs/inode.c @@ -8057,7 +8057,7 @@ struct inode *btrfs_alloc_inode(struct super_block *sb) ei->dir_index = 0; ei->last_unlink_trans = 0; ei->last_reflink_trans = 0; - ei->last_log_commit = 0; + ei->last_log_commit = -1; spin_lock_init(&ei->lock); ei->outstanding_extents = 0; base-commit: 6dc1b4de5a72572f84cc3af901172205d2b82ff2 -- 2.53.0