From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796217517; b=0Gh1XGdxHYTHwQltriZ5x3+6MxzQ+FibPG7PmJDGNqbkH5WhZ49L7VPykyqyM/uxTMJS 42NFrm6TrQZZze2aNqu8kBOb3oAW69PekaT1ZrvhxaC8M6ZGzYeciaIJ5BP4bL0MuY61G DFCcRD0Nb9Jd4UwNOaGztJQdjMvWLKw/2hoNoZWadtMNyHnZuIcYRGMfz9NRkRDFhXIJH 4VygzhBQwXP92Icggst1pEE2PRdktepQ7RL7xLMVUaseVXh81WZFHxjIrt+zdsOT9J2HL XudvgMgdCxEY7rBHle04PGTpaGGaxFUh1EpECssiTS9cQm3FnXxlPr0d2z8MgcJVDrg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796217517; h=Received:DKIM-Signature:Received:From:Subject:Date:Message-Id: MIME-Version:Content-Type:Content-Transfer-Encoding:X-B4-Tracking: X-Change-ID:To:Cc:X-Mailer:X-Developer-Signature:X-Developer-Key: X-Endpoint-Received:X-Original-From:Reply-To; bh=VejatSYOD5DJeFD9OxXNGYQ9klHp/TBdijw2bvt23Bc=; b=PFPFEagXv2+bMww6vQWpzd8QpLybjXHC9CizSKsoYhl1GbDfbspE85fJTB4xPQds+j67 LAXblCCDRx/HaHoJi6x4FUcDM5NmoH8Cu0y3iiO5asUQVzs1zJLasXnJiGJXk0KX2jXNk MC3vLe2xnezGbeXG2tnWvc5dT1ZtKQ2qMQQ4Hy3Tz3HwTmu3yFdLtRzcwyIq0rGb9MgQf T8eNC4llzjCma6rzI2F7rlsD507CUeARof4Ntikidwf5R8hDrLGrs7pJRKadJGxoh/e8Y 4nkWu4VjHbnUWkGIqo1PAyDW67Q98bWg9jpPYq5yMZILHOT1HmINX5VYdmv+M2jPVXA== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cAr7eMTP; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DAE93606A32A; Wed, 2 Dec 2026 13:18:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=cAr7eMTP Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796217516; b=empyfiWLObJm7ARHPZcMh4CCsk3dx4xwTyvQF/1P1Keju+bD6FVa4dsX71mSTJnEDqf7 zH8BFp1lkAQL98w7L6MxpQYVaBOboBkYrz9d+GxY9TXltnHofAhqxGRm5fbbBsL7nkkPu uYQZXIK+JH5J1jXEme/JX4Gykcdjg1kUXqqVcgUdg9dgKL/jb9VqP0d6adwU/Iy77WT28 5QrNaw7axNLshN+4Hk2W3NbqG7NNdIFmj4PJ8VrRC6S5ckHZPlLkvytFdGmeLgOvMX7vu ct4qPdXFeCBvcUNOjOiIHNBwuGO6cO0DXgInJGFLE/4uCbfecvFhaasC9prPpHwxyfA== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796217516; h=DKIM-Signature:Received:From:Subject:Date:Message-Id:MIME-Version: Content-Type:Content-Transfer-Encoding:X-B4-Tracking:X-Change-ID:To: Cc:X-Mailer:X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To; bh=VejatSYOD5DJeFD9OxXNGYQ9klHp/TBdijw2bvt23Bc=; b=SiuW1Ulx0FAr/B3/RvfLZZrZw0xUyhlrZcFEcYnxfwmgCDRzpFs8mSy1StJkPz4UQZWL WDXouF7TakMbSJr+mMLJi/mN4JpBaX5P+FF0wUkKptc6YFuGB2DoXMbpdswX3vYTFCNMc mwHID8PXlloSmew6Ii7uCAkzI+Zou3MIm2DRdVVufqy7CHkRDwJuIkp364Gd5IU74+JbL ea1JyinRyV14MB1ehWrz97VTrCE5bK2XghqLNdB9/ZpPj2hPC5N9yYJNBk48EZG03Z2Nz +i/8NCT/AmrnA8NaRKaCoZMwcyjpf1xnRrDrcljRBnqhLRZnLM7OdA196l+v63Z9DMQ== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (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.kernel.org (Postfix) with ESMTPS id 615F91F00893; Wed, 2 Dec 2026 13:18:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796217516; bh=VejatSYOD5DJeFD9OxXNGYQ9klHp/TBdijw2bvt23Bc=; h=From:Subject:Date:To:Cc:Reply-To; b=cAr7eMTPKQQsugvjJyOob13rnccqlBgEw1mkmCGYsbDRTzTof7pMDWraN8n04QPtC zWdHXkLnC6sHO6SZ1R6ygRYq8ufdkfVTh9EvhLs4T6DJUx3J/6XvRksA3SOtZFDfl8 +gQnMkuzmmtfyuS6yIs2/8oma+A0oVRdkgiE+5xIZNl8yI8ezdu34LBx7RoOSADOcD auUhPMzx25iUEOIDqxzvfrHuHKrfd+36L9YI91jPpjMXqNG/RG9zSzSe7KcLc0vbDk Nrsw1EN4xPaL5UdBmwE6Pj7NLUPpjYxtR4fdnOnOqaozjuHNGvde8oFwUXLwGpqcO3 ZZpHFiarJ8hOw== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id D2F554F3FA; Wed, 2 Dec 2026 13:18:31 +0000 (UTC) From: Xiubo Li via B4 Relay Subject: [PATCH v3 0/3] ceph: serialize O_APPEND writes across clients Date: Wed, 02 Dec 2026 14:18:19 +0100 Message-Id: <20261202-ceph-append-excl-v3-0-68fdbef33f32@clyso.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit X-B4-Tracking: v=1; b=H4sIAAAAAAAC/33OTQ6CMBAF4KuYrq3pD1DiynsYFzAdpQZp02IDI dzdFjcsjMuXvPneLCSgNxjI+bAQj9EEY4cU5PFAoGuGB1KjUyaCiYpzwSmg62jjHA6a4gQ9rQp AKaTmDStIOnMe72bayOvtm8O7fSKM2cmNzoTR+nnbjDz3/vCRU0bLWjGpStTY1hfo52BPYF8k8 1HsgeoHIBKACVCapzeV2gPrun4Afa34aQMBAAA= X-Change-ID: 20261121-ceph-append-excl-64ce323d1a04 To: Ilya Dryomov , Alex Markuze , Viacheslav Dubeyko Cc: ceph-devel@vger.kernel.org, linux-kernel@vger.kernel.org, Anthony D'Atri , Xiubo Li X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796217507; l=4452; i=xiubo.li@clyso.com; s=20260625; h=from:subject:message-id; bh=0QnECK8sIoDAMTJ078OESYLWJSPH9lGU86oL9+BDRNo=; b=JRfafm84dHeRNsBlxEkQ74/tsRVWwhIZ7bchQ+k0MdYKnC3VgY7m0l4hvQ0H1rseBt6VsMmAU msAfwgqyvtXCpRs7kO/CbKfivx3k/sLGsrQLROzcnYWL54j6drlAW6E X-Developer-Key: i=xiubo.li@clyso.com; a=ed25519; pk=V3NGr0AgAopiUhaLY51ipBkLN5LlcLhjOEfLEq1RoZ8= X-Endpoint-Received: by B4 Relay for xiubo.li@clyso.com/20260625 with auth_id=840 X-Original-From: Xiubo Li Reply-To: xiubo.li@clyso.com When two clients append to one file, the filelock is in MIX and both hold Fw, so each appends at the end of file it has cached and may overwrite what the other one appended. Commit d2a8d446a09c ("ceph: revalidate ki_pos for O_APPEND writes after cap acquisition") does not cover this case: neither client waits for caps, and the other client's size only arrives after it flushed its caps. The MDS side [1] lets O_APPEND writers take turns on Fx, in request order, and sends the current size together with Fx. It is enabled by the new CEPHFS_FEATURE_APPEND_EXCL feature bit; with an MDS that does not have it, the client behaves as before, also when the auth cap moves to such an MDS while an O_APPEND write waits for its turn. Patch 1 fixes an older problem that the turns of patch 3 make easy to hit: an mmap fault with Fr but no Fc read ahead into the page cache, and a later buffered write on Fb wrote those stale folios back over another client's data. Patch 2 fixes a reordering of the cap messages of an inode that this work exposed: a later cap update could overtake the flush carrying the new size, the MDS then finished its Fw gather early and gave Fx with the old size to the other client. Patch 3 is the O_APPEND change itself. Tested on a vstart cluster with [1], KASAN and lockdep enabled, two mounts (noshare, or ceph-fuse + kernel), 4 writers on each, without any file locking; a lost record means one append overwrote another: +--------------------------------------+--------+------------------+ | case | runs | lost records | | | | base / patched | +--------------------------------------+--------+------------------+ | buffered, kernel + kernel | 4 | ~3300-4000 / 0 | | O_DIRECT, kernel + kernel | 10 | ~4000 / 0 | | buffered/O_DIRECT, ceph-fuse+kernel | 6 | - / 0 | | 2 active MDS, export every 3 s | 4 | - / 0 | | MDS failover during the writes | 2 | - / 0 | | mmap writer on one client (v3) | 3 | 62-88 (v2) / 0 | +--------------------------------------+--------+------------------+ With an MDS without the feature the patched client loses records like the base one, and does not hang. xfstests -g quick shows the same 8 failures (ceph/006, fscrypt key tests) with and without the series. [1] https://github.com/ceph/ceph/pull/70279 Signed-off-by: Xiubo Li --- Changes in v3: - New patch 1: do not read ahead on an mmap fault that holds no Fc; the folios read ahead were never invalidated and were written back stale on a later turn (found while testing the review comments). - Patch 2: allocate a cap message that flushes dirty caps with __GFP_NOFAIL, so an allocation failure cannot let a later release overtake the size update (Alex Markuze). - Patch 3: keep the reserved O_APPEND turn on the flush paths (try_flush_caps(), flush replay) too, unless the write yielded (Alex Markuze). - Patch 3: check RLIMIT_FSIZE and s_maxbytes again after moving an O_APPEND write to the new end of file (Alex Markuze). - Link to v2: https://patch.msgid.link/20261126-ceph-append-excl-v2-0-e8707d123d77@clyso.com Changes in v2: - Patch 2: fall back to the Fw-only path when the auth cap moves to an MDS without CEPHFS_FEATURE_APPEND_EXCL while an O_APPEND write waits for Fx; such an MDS may never send Fx, so the write hung (Alex Markuze). - Link to v1: https://patch.msgid.link/20261121-ceph-append-excl-v1-0-5870375edeb8@clyso.com --- Xiubo Li (3): ceph: do not read ahead on an mmap fault without Fc ceph: send the cap messages of an inode in the order they were prepared ceph: serialize O_APPEND writes across clients on Fx fs/ceph/addr.c | 18 ++- fs/ceph/caps.c | 263 ++++++++++++++++++++++++++++++++++++++++++- fs/ceph/file.c | 51 +++++++-- fs/ceph/inode.c | 6 + fs/ceph/mds_client.h | 4 +- fs/ceph/super.h | 17 +++ include/linux/ceph/ceph_fs.h | 1 + 7 files changed, 349 insertions(+), 11 deletions(-) --- base-commit: 6a9830a8f414d3830c584782568d0233be969d09 change-id: 20261121-ceph-append-excl-64ce323d1a04 Best regards, -- Xiubo Li