[PATCH v3 3/5] ceph: make the ceph_osdc_sync() wait killable

From: Ionut Nechita

Date: Mon Nov 23 2026 - 03:10:15 EST


ceph_sync_fs() calls ceph_osdc_sync() before ceph_mdsc_sync(), and
ceph_osdc_sync() waits for every in-flight write with a plain
wait_for_completion(). With an OSD unreachable, sync(2) hangs there
in TASK_UNINTERRUPTIBLE:

ceph_osdc_sync [libceph]
ceph_sync_fs [ceph]
iterate_supers
ksys_sync

Make the wait killable like the MDS side and propagate the error.
The requests are not cancelled, and a sync that isn't killed still
waits for all of them.

Signed-off-by: Ionut Nechita <ionut.nechita@xxxxxxxxxxxxx>
---
fs/ceph/super.c | 4 +++-
include/linux/ceph/osd_client.h | 2 +-
net/ceph/osd_client.c | 9 +++++++--
3 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/fs/ceph/super.c b/fs/ceph/super.c
index 7936b76aa3cc0..166f6eb21f0af 100644
--- a/fs/ceph/super.c
+++ b/fs/ceph/super.c
@@ -137,7 +137,9 @@ static int ceph_sync_fs(struct super_block *sb, int wait)
}

doutc(cl, "(blocking)\n");
- ceph_osdc_sync(&fsc->client->osdc);
+ ret = ceph_osdc_sync(&fsc->client->osdc);
+ if (ret)
+ return ret;
ret = ceph_mdsc_sync(fsc->mdsc);
doutc(cl, "(blocking) done\n");
return ret;
diff --git a/include/linux/ceph/osd_client.h b/include/linux/ceph/osd_client.h
index 7349ca09a227a..674dd9221d657 100644
--- a/include/linux/ceph/osd_client.h
+++ b/include/linux/ceph/osd_client.h
@@ -579,7 +579,7 @@ void ceph_osdc_start_request(struct ceph_osd_client *osdc,
extern void ceph_osdc_cancel_request(struct ceph_osd_request *req);
extern int ceph_osdc_wait_request(struct ceph_osd_client *osdc,
struct ceph_osd_request *req);
-extern void ceph_osdc_sync(struct ceph_osd_client *osdc);
+extern int ceph_osdc_sync(struct ceph_osd_client *osdc);

extern void ceph_osdc_flush_notifies(struct ceph_osd_client *osdc);
void ceph_osdc_maybe_request_map(struct ceph_osd_client *osdc);
diff --git a/net/ceph/osd_client.c b/net/ceph/osd_client.c
index 4479ec7a932b3..ff82aa16b5f52 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -4715,11 +4715,13 @@ EXPORT_SYMBOL(ceph_osdc_wait_request);

/*
* sync - wait for all in-flight requests to flush. avoid starvation.
+ * Returns 0, or -ERESTARTSYS if a fatal signal is pending.
*/
-void ceph_osdc_sync(struct ceph_osd_client *osdc)
+int ceph_osdc_sync(struct ceph_osd_client *osdc)
{
struct rb_node *n, *p;
u64 last_tid = atomic64_read(&osdc->last_tid);
+ int ret;

again:
down_read(&osdc->lock);
@@ -4742,8 +4744,10 @@ void ceph_osdc_sync(struct ceph_osd_client *osdc)
up_read(&osdc->lock);
dout("%s waiting on req %p tid %llu last_tid %llu\n",
__func__, req, req->r_tid, last_tid);
- wait_for_completion(&req->r_completion);
+ ret = wait_for_completion_killable(&req->r_completion);
ceph_osdc_put_request(req);
+ if (ret)
+ return ret;
goto again;
}

@@ -4752,6 +4756,7 @@ void ceph_osdc_sync(struct ceph_osd_client *osdc)

up_read(&osdc->lock);
dout("%s done last_tid %llu\n", __func__, last_tid);
+ return 0;
}
EXPORT_SYMBOL(ceph_osdc_sync);

--
2.56.0