From: Xiubo Li 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> 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 List-Id: B4 Relay Submissions 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