[PATCH v2 3/7] ceph: bound the ceph_osdc_sync() wait by mount_timeout

From: Ionut Nechita

Date: Fri Nov 20 2026 - 02:36:12 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) therefore
hangs there and never gets to the bounded MDS wait:

ceph_osdc_sync [libceph]
ceph_sync_fs [ceph]
iterate_supers
ksys_sync

Bound the wait by mount_timeout in the same way and propagate
-ETIMEDOUT. The requests are not cancelled and complete once the OSD
is reachable again. mount_timeout=0 keeps waiting forever.

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 | 24 ++++++++++++++++++++++--
3 files changed, 26 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..417374c95dc14 100644
--- a/net/ceph/osd_client.c
+++ b/net/ceph/osd_client.c
@@ -4715,11 +4715,17 @@ EXPORT_SYMBOL(ceph_osdc_wait_request);

/*
* sync - wait for all in-flight requests to flush. avoid starvation.
+ *
+ * Gives up with -ETIMEDOUT after mount_timeout (0 means wait forever),
+ * leaving the requests in flight.
*/
-void ceph_osdc_sync(struct ceph_osd_client *osdc)
+int ceph_osdc_sync(struct ceph_osd_client *osdc)
{
+ unsigned long timeout = osdc->client->options->mount_timeout;
+ unsigned long deadline = jiffies + timeout;
struct rb_node *n, *p;
u64 last_tid = atomic64_read(&osdc->last_tid);
+ unsigned long left;

again:
down_read(&osdc->lock);
@@ -4742,7 +4748,20 @@ 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);
+ if (!timeout)
+ left = MAX_SCHEDULE_TIMEOUT;
+ else if (time_before(jiffies, deadline))
+ left = deadline - jiffies;
+ else
+ left = 0;
+ left = wait_for_completion_timeout(&req->r_completion,
+ left);
+ if (!left) {
+ dout("%s timed out on req %p tid %llu\n",
+ __func__, req, req->r_tid);
+ ceph_osdc_put_request(req);
+ return -ETIMEDOUT;
+ }
ceph_osdc_put_request(req);
goto again;
}
@@ -4752,6 +4771,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