Skip to content

ceph: fix orphaned MDS locks after an interrupted lock wait

Venky Shankar ceph-devel 2 versions In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest1 patch 2 repliesIn review
  2. v11 patch 0 repliesSuperseded

Changes in v2 from the cover letter

- Use Xiubo's correct email address.

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/1ceph: don't drop a lock grant that races with an interruptfs/ceph/locks.c+35 -105 replies

Reviews trailers per patch

The patch has a Reviewed-by or Acked-by.

PatchAlex Markuze
1/1R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH v2 0/1] ceph: fix orphaned MDS locks after an interrupted lock wait

A process blocked in F_SETLKW or flock(LOCK_EX) on CephFS can leave a lock held on the MDS that nobody will ever release. This happens when the process is interrupted (typically SIGKILL) just after the MDS has granted the lock, but before the client has processed the grant.

The kernel client marks the request aborted and sends a FCNTL_INTR or FLOCK_INTR request. The MDS handles an interrupt by cancelling a *waiting* lock only. It deliberately leaves granted locks alone, because same-owner POSIX locks merge and dropping a held lock could take away locks the owner had before the interrupted request. So the MDS keeps the lock, and replies 0 to the original request. That reply arrives for an aborted request and handle_reply() drops it ("reply arrived after request N was aborted"). posix_lock_file() or locks_lock_file_wait() never runs, so nothing is sent on close or exit, and the lock isn't sent on reconnect either. Other clients block on it, or get EAGAIN, until this client drops its last cap on the inode or the MDS restarts.

The patch stops aborting a lock request once it has been sent. It still sends the interrupt, then waits for the MDS's reply to the original request. A reply of 0 means the lock was granted: it is recorded locally, and the exiting process unlocks it as usual. A reply of -EINTR means the wait was cancelled, and becomes -ERESTARTSYS as before. The wait flag is cleared too, so a request resent to a new MDS answers at once instead of blocking again; -EAGAIN from such a resend also becomes -ERESTARTSYS.

The cost is an uninterruptible wait for that reply, which is normally one round trip after the interrupt. If the MDS is down and there is no standby, the task stays in D state until the MDS recovers. Other options are a TASK_KILLABLE wait that sends an explicit unlock if a grant turns up later, or doing that unlock from handle_reply() for aborted lock requests. Both are more involved, and I'd welcome opinions.

Tracker: https://tracker.ceph.com/issues/81697
ceph PR: https://github.com/ceph/ceph/pull/72723 (qa tests)

v2:
- Use Xiubo's correct email address.

Venky Shankar (1):
ceph: don't drop a lock grant that races with an interrupt

 fs/ceph/locks.c | 45 +++++++++++++++++++++++++++++++++++----------
 1 file changed, 35 insertions(+), 10 deletions(-)
Signature · 1 line
2.50.1 (Apple Git-155)