[PATCH v3 2/5] ceph: make the ceph_mdsc_sync() waits killable
From: Ionut Nechita
Date: Mon Nov 23 2026 - 03:09:39 EST
When the MDS is unreachable, sync(2) and syncfs(2) wait in
ceph_mdsc_sync() in TASK_UNINTERRUPTIBLE with no way out:
flush_mdlog_and_wait_mdsc_unsafe_requests() waits for
r_safe_completion, and wait_caps_flush() waits for the cap flushes.
The task can't be killed and keeps tripping the hung task detector:
INFO: task sync:514917 blocked for more than 983 seconds.
Call Trace:
ceph_mdsc_sync+0x4d6/0x5a0 [ceph]
ceph_sync_fs+0x31/0x130 [ceph]
iterate_supers+0x97/0x100
ksys_sync+0x32/0xb0
Bounding these waits isn't an option: sync(2) ignores the ->sync_fs()
return value, so returning early would break its guarantee that
metadata is stable once it returns.
Make both waits killable instead, keeping the wait_caps_flush()
diagnostics, and propagate the error out of ceph_sync_fs(). A sync
that isn't killed still waits for everything to be flushed.
Signed-off-by: Ionut Nechita <ionut.nechita@xxxxxxxxxxxxx>
---
fs/ceph/mds_client.c | 37 +++++++++++++++++++++++++++----------
fs/ceph/mds_client.h | 2 +-
fs/ceph/super.c | 5 +++--
3 files changed, 31 insertions(+), 13 deletions(-)
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c
index 3791fc627714c..f64a9c97cb882 100644
--- a/fs/ceph/mds_client.c
+++ b/fs/ceph/mds_client.c
@@ -2522,9 +2522,10 @@ static void dump_cap_flushes(struct ceph_mds_client *mdsc, u64 want_tid)
/*
* Wait for all cap flushes through @want_flush_tid to complete.
* Periodically dumps pending cap flush state for diagnostics.
+ * Returns 0, or -ERESTARTSYS if a fatal signal is pending.
*/
-static void wait_caps_flush(struct ceph_mds_client *mdsc,
- u64 want_flush_tid)
+static int wait_caps_flush(struct ceph_mds_client *mdsc,
+ u64 want_flush_tid)
{
struct ceph_client *cl = mdsc->fsc->client;
int i = 0;
@@ -2534,9 +2535,11 @@ static void wait_caps_flush(struct ceph_mds_client *mdsc,
do {
/* 60 * HZ fits in a long on all supported architectures. */
- ret = wait_event_timeout(mdsc->cap_flushing_wq,
+ ret = wait_event_killable_timeout(mdsc->cap_flushing_wq,
check_caps_flush(mdsc, want_flush_tid),
CEPH_CAP_FLUSH_WAIT_TIMEOUT_SEC * HZ);
+ if (ret < 0)
+ return ret;
if (ret == 0) {
if (i < CEPH_CAP_FLUSH_MAX_DUMP_ITERS)
dump_cap_flushes(mdsc, want_flush_tid);
@@ -2548,6 +2551,7 @@ static void wait_caps_flush(struct ceph_mds_client *mdsc,
} while (ret == 0);
doutc(cl, "ok, flushed thru %llu\n", want_flush_tid);
+ return 0;
}
/*
@@ -6737,13 +6741,14 @@ void ceph_mdsc_pre_umount(struct ceph_mds_client *mdsc)
/*
* flush the mdlog and wait for all write mds requests to flush.
*/
-static void flush_mdlog_and_wait_mdsc_unsafe_requests(struct ceph_mds_client *mdsc,
- u64 want_tid)
+static int flush_mdlog_and_wait_mdsc_unsafe_requests(struct ceph_mds_client *mdsc,
+ u64 want_tid)
{
struct ceph_client *cl = mdsc->fsc->client;
struct ceph_mds_request *req = NULL, *nextreq;
struct ceph_mds_session *last_session = NULL;
struct rb_node *n;
+ int err;
mutex_lock(&mdsc->mutex);
doutc(cl, "want %lld\n", want_tid);
@@ -6782,7 +6787,14 @@ static void flush_mdlog_and_wait_mdsc_unsafe_requests(struct ceph_mds_client *md
}
doutc(cl, "wait on %llu (want %llu)\n",
req->r_tid, want_tid);
- wait_for_completion(&req->r_safe_completion);
+ err = wait_for_completion_killable(&req->r_safe_completion);
+ if (err) {
+ ceph_mdsc_put_request(req);
+ if (nextreq)
+ ceph_mdsc_put_request(nextreq);
+ ceph_put_mds_session(last_session);
+ return err;
+ }
mutex_lock(&mdsc->mutex);
ceph_mdsc_put_request(req);
@@ -6800,15 +6812,17 @@ static void flush_mdlog_and_wait_mdsc_unsafe_requests(struct ceph_mds_client *md
mutex_unlock(&mdsc->mutex);
ceph_put_mds_session(last_session);
doutc(cl, "done\n");
+ return 0;
}
-void ceph_mdsc_sync(struct ceph_mds_client *mdsc)
+int ceph_mdsc_sync(struct ceph_mds_client *mdsc)
{
struct ceph_client *cl = mdsc->fsc->client;
u64 want_tid, want_flush;
+ int ret;
if (READ_ONCE(mdsc->fsc->mount_state) >= CEPH_MOUNT_SHUTDOWN)
- return;
+ return 0;
doutc(cl, "sync\n");
mutex_lock(&mdsc->mutex);
@@ -6829,8 +6843,11 @@ void ceph_mdsc_sync(struct ceph_mds_client *mdsc)
doutc(cl, "sync want tid %lld flush_seq %lld\n", want_tid, want_flush);
- flush_mdlog_and_wait_mdsc_unsafe_requests(mdsc, want_tid);
- wait_caps_flush(mdsc, want_flush);
+ ret = flush_mdlog_and_wait_mdsc_unsafe_requests(mdsc, want_tid);
+ if (ret)
+ return ret;
+
+ return wait_caps_flush(mdsc, want_flush);
}
/*
diff --git a/fs/ceph/mds_client.h b/fs/ceph/mds_client.h
index 4749438d94e1f..31abbb3b3bdb3 100644
--- a/fs/ceph/mds_client.h
+++ b/fs/ceph/mds_client.h
@@ -635,7 +635,7 @@ extern void ceph_mdsc_close_sessions(struct ceph_mds_client *mdsc);
extern void ceph_mdsc_force_umount(struct ceph_mds_client *mdsc);
extern void ceph_mdsc_destroy(struct ceph_fs_client *fsc);
-extern void ceph_mdsc_sync(struct ceph_mds_client *mdsc);
+extern int ceph_mdsc_sync(struct ceph_mds_client *mdsc);
extern void ceph_invalidate_dir_request(struct ceph_mds_request *req);
extern int ceph_alloc_readdir_reply_buffer(struct ceph_mds_request *req,
diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index 7b5ef76e430d7..7936b76aa3cc0 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -126,6 +126,7 @@ static int ceph_sync_fs(struct super_block *sb, int wait)
{
struct ceph_fs_client *fsc = ceph_sb_to_fs_client(sb);
struct ceph_client *cl = fsc->client;
+ int ret;
if (!wait) {
doutc(cl, "(non-blocking)\n");
@@ -137,9 +138,9 @@ static int ceph_sync_fs(struct super_block *sb, int wait)
doutc(cl, "(blocking)\n");
ceph_osdc_sync(&fsc->client->osdc);
- ceph_mdsc_sync(fsc->mdsc);
+ ret = ceph_mdsc_sync(fsc->mdsc);
doutc(cl, "(blocking) done\n");
- return 0;
+ return ret;
}
/*
--
2.56.0