[PATCH v2 4/7] ceph: bound the safe-completion wait in ceph_lock_wait_for_completion()
From: Ionut Nechita
Date: Fri Nov 20 2026 - 02:36:00 EST
When a blocking lock request is interrupted,
ceph_lock_wait_for_completion() sends an unlock request to cancel it
and then waits for the original request's r_safe_completion with no
bound. If the MDS goes away at
that point the task hangs in D state:
INFO: task flock:12345 blocked for more than 122 seconds.
Call Trace:
wait_for_completion_killable
ceph_lock_wait_for_completion
ceph_flock
Bound the wait by mount_timeout and return -ETIMEDOUT; the original
request has already been marked CEPH_MDS_R_ABORTED at this point.
mount_timeout=0 keeps waiting forever.
Signed-off-by: Ionut Nechita <ionut.nechita@xxxxxxxxxxxxx>
---
fs/ceph/locks.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/fs/ceph/locks.c b/fs/ceph/locks.c
index 677221bd64e01..b4faf112b3f84 100644
--- a/fs/ceph/locks.c
+++ b/fs/ceph/locks.c
@@ -158,9 +158,11 @@ static int ceph_lock_wait_for_completion(struct ceph_mds_client *mdsc,
struct ceph_mds_request *req)
{
struct ceph_client *cl = mdsc->fsc->client;
+ unsigned long timeout = ceph_timeout_jiffies(cl->options->mount_timeout);
struct ceph_mds_request *intr_req;
struct inode *inode = req->r_inode;
int err, lock_type;
+ long left;
BUG_ON(req->r_op != CEPH_MDS_OP_SETFILELOCK);
if (req->r_args.filelock_change.rule == CEPH_LOCK_FCNTL)
@@ -219,10 +221,15 @@ static int ceph_lock_wait_for_completion(struct ceph_mds_client *mdsc,
if (err && err != -ERESTARTSYS)
return err;
- err = wait_for_completion_killable(&req->r_safe_completion);
- if (err)
- return err;
-
+ left = wait_for_completion_killable_timeout(&req->r_safe_completion,
+ timeout);
+ if (left < 0) {
+ return left;
+ } else if (left == 0) {
+ doutc(cl, "request %llu safe completion timed out\n",
+ req->r_tid);
+ return -ETIMEDOUT;
+ }
return 0;
}
--
2.56.0