ceph: manual client session reset via debugfs
Subsystems (3)
Alex Markuze
maintainercover ceph: manual client session reset via debugfs
In production CephFS deployments we regularly encounter situations where MDS sessions become stuck or hung, requiring a full unmount/ remount cycle to recover. This is disruptive for workloads that cannot tolerate the downtime or the loss of cached state that comes with unmounting.
This series adds a mechanism to manually trigger MDS session reconnection from the client side without unmounting, exposed via debugfs:
echo "reason text" > /sys/kernel/debug/ceph/<fsid>/reset/trigger cat /sys/kernel/debug/ceph/<fsid>/reset/status
The reset lifecycle:
1. Operator writes to the trigger file
2. A work item collects all active sessions and initiates reconnection on each (via send_mds_reconnect with from_reset=true)
3. New metadata requests and lock acquisitions are blocked until the reset completes (120s timeout)
4. Session completions are tracked via a per-session generation counter to handle stale completions from timed-out prior resets
5. Lock reclamation is always attempted during reset-initiated reconnects, regardless of prior CEPH_I_ERROR_FILELOCK state
Patch breakdown:
1. Convert CEPH_I_* flags to named bit positions so test_bit/ set_bit/clear_bit can be used in reconnect paths
2. Make wait_caps_flush() bounded with periodic diagnostic dumps to aid debugging hung flush scenarios (independent improvement that surfaced during development)
3. The core reset implementation: debugfs interface, reset work function, request/lock blocking, tracepoints, and session reconnect completion tracking
4. Rework mds_peer_reset() to properly handle all session states and integrate with the reset completion tracking
Open questions / areas for review:
- Is debugfs the right interface, or should this be a mount option / sysfs attribute / netlink command?
- The request gating in ceph_mdsc_submit_request() is best-effort (no lock serialization) to avoid penalizing the normal path. Is this acceptable?
- Should the 60s reconnect timeout and 120s blocked-request timeout be configurable (e.g. via mount options)?
- mds_peer_reset() rework (patch 4) is substantial -- would reviewers prefer it split further?
Alex Markuze (4):
ceph: convert inode flags to named bit positions
ceph: add bounded timeout and diagnostics to wait_caps_flush()
ceph: implement manual client session reset via debugfs
ceph: rework mds_peer_reset() for robust session recovery
fs/ceph/caps.c | 7 + fs/ceph/debugfs.c | 171 ++++++++++- fs/ceph/locks.c | 24 +- fs/ceph/mds_client.c | 577 ++++++++++++++++++++++++++++++++++-- fs/ceph/mds_client.h | 33 +++ fs/ceph/super.h | 60 ++-- include/trace/events/ceph.h | 60 ++++ 7 files changed, 879 insertions(+), 53 deletions(-)
Signature · 1 line
2.34.1
Alex Markuze
maintainerRFC PATCH 1/4 ceph: convert inode flags to named bit positions
Define all CEPH_I_* flags as named bit positions with derived bitmask values, making them usable with test_bit/set_bit/clear_bit. Previously only CEPH_I_ODIRECT_BIT and CEPH_ASYNC_CREATE_BIT had named bit positions; the rest were bare bitmask constants.
Convert CEPH_I_ERROR_WRITE and CEPH_I_ERROR_FILELOCK usage sites to use atomic bit operations (test_bit, set_bit, clear_bit) via the new _BIT constants.
This is preparation for the client reset feature which needs test_bit() on CEPH_I_ERROR_FILELOCK_BIT in reconnect paths.
--- fs/ceph/locks.c | 8 +++---- fs/ceph/mds_client.c | 3 ++- fs/ceph/super.h | 54 +++++++++++++++++++++++++++----------------- 3 files changed, 38 insertions(+), 27 deletions(-)
fs/ceph/locks.c +3 -5
@@ -58,7 +58,7 @@ static void ceph_fl_release_lock(struct file_lock *fl)if (atomic_dec_and_test (&ci->i_filelock_ref)) {/* clear error when all locks are released */ spin_lock (&ci->i_ceph_lock); - ci->i_ceph_flags &= ~CEPH_I_ERROR_FILELOCK ; +clear_bit (CEPH_I_ERROR_FILELOCK_BIT , &ci->i_ceph_flags);spin_unlock (&ci->i_ceph_lock); } fl->fl_u.ceph.inode =NULL ;
@@ -272,9 +272,8 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl) wait =1 ;spin_lock (&ci->i_ceph_lock); -if (ci->i_ceph_flags &CEPH_I_ERROR_FILELOCK ) { +if (test_bit (CEPH_I_ERROR_FILELOCK_BIT , &ci->i_ceph_flags)) err = -EIO ; - }spin_unlock (&ci->i_ceph_lock);if (err <0 ) {if (op ==CEPH_MDS_OP_SETFILELOCK &&lock_is_unlock (fl))
@@ -332,9 +331,8 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)doutc (cl,"fl_file: %p\n" , fl->c.flc_file);spin_lock (&ci->i_ceph_lock); -if (ci->i_ceph_flags &CEPH_I_ERROR_FILELOCK ) { +if (test_bit (CEPH_I_ERROR_FILELOCK_BIT , &ci->i_ceph_flags)) err = -EIO ; - }spin_unlock (&ci->i_ceph_lock);if (err <0 ) {if (lock_is_unlock (fl))
fs/ceph/mds_client.c +2 -1
@@ -3610,7 +3610,8 @@ static void __do_request(struct ceph_mds_client *mdsc,spin_lock (&ci->i_ceph_lock); cap = ci->i_auth_cap; -if (ci->i_ceph_flags &CEPH_I_ASYNC_CREATE && mds != cap->mds) { +if (test_bit (CEPH_ASYNC_CREATE_BIT , &ci->i_ceph_flags) && + mds != cap->mds) {doutc (cl,"session changed for auth cap %d -> %d\n" , cap->session->s_mds, session->s_mds);
fs/ceph/super.h +33 -21
74 lines not on this page · raw message
Signature · 1 line
2.34.1
Re: [EXTERNAL] [RFC PATCH v1 1/4] ceph: convert inode flags to named bit positions
Quoted 5 lines · Alex Markuze
Define all CEPH_I_* flags as named bit positions with derived bitmask values, making them usable with test_bit/set_bit/clear_bit. Previously only
CEPH_I_ODIRECT_BITandCEPH_ASYNC_CREATE_BIThad named bit positions; the rest were bare bitmask constants.
As I remember, I've reworked all constants for having name for every bit. Probably, this patch has ignored and it has never been sent to upstream. And I converted pretty everything for using test_bit/set_bit/clear_bit. :) You did this work again. :)
Thanks,
Slava.
Quoted 143 lines
Convert
CEPH_I_ERROR_WRITEandCEPH_I_ERROR_FILELOCKusage sites to use atomic bit operations (test_bit,set_bit,clear_bit) via the new_BITconstants.This is preparation for the client reset feature which needs
test_bit()onCEPH_I_ERROR_FILELOCK_BITin reconnect paths.Signed-off-by Alex Markuze <[email protected]>--- fs/ceph/locks.c | 8 +++---- fs/ceph/mds_client.c | 3 ++- fs/ceph/super.h | 54 +++++++++++++++++++++++++++----------------- 3 files changed, 38 insertions(+), 27 deletions(-)fs/ceph/locks.c +3
-5@@ -58,7 +58,7 @@ static void ceph_fl_release_lock(struct file_lock *fl)if (atomic_dec_and_test (&ci->i_filelock_ref)) {/* clear error when all locks are released */ spin_lock (&ci->i_ceph_lock); - ci->i_ceph_flags &= ~CEPH_I_ERROR_FILELOCK ; +clear_bit (CEPH_I_ERROR_FILELOCK_BIT , &ci->i_ceph_flags);spin_unlock (&ci->i_ceph_lock); } fl->fl_u.ceph.inode =NULL ;@@ -272,9 +272,8 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl) wait =1 ;spin_lock (&ci->i_ceph_lock); -if (ci->i_ceph_flags &CEPH_I_ERROR_FILELOCK ) { +if (test_bit (CEPH_I_ERROR_FILELOCK_BIT , &ci->i_ceph_flags)) err = -EIO ; - }spin_unlock (&ci->i_ceph_lock);if (err <0 ) {if (op ==CEPH_MDS_OP_SETFILELOCK &&lock_is_unlock (fl))@@ -332,9 +331,8 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)doutc (cl,"fl_file: %p\n" , fl->c.flc_file);spin_lock (&ci->i_ceph_lock); -if (ci->i_ceph_flags &CEPH_I_ERROR_FILELOCK ) { +if (test_bit (CEPH_I_ERROR_FILELOCK_BIT , &ci->i_ceph_flags)) err = -EIO ; - }spin_unlock (&ci->i_ceph_lock);if (err <0 ) {if (lock_is_unlock (fl))fs/ceph/mds_client.c +2
-1@@ -3610,7 +3610,8 @@ static void __do_request(struct ceph_mds_client *mdsc,spin_lock (&ci->i_ceph_lock); cap = ci->i_auth_cap; -if (ci->i_ceph_flags &CEPH_I_ASYNC_CREATE && mds != cap->mds) { +if (test_bit (CEPH_ASYNC_CREATE_BIT , &ci->i_ceph_flags) && + mds != cap->mds) {doutc (cl,"session changed for auth cap %d -> %d\n" , cap->session->s_mds, session->s_mds);fs/ceph/super.h +33
-21@@ -655,23 +655,35 @@ static inline struct inode *ceph_find_inode(struct super_block *sb,/* * Ceph inode. */ -#define CEPH_I_DIR_ORDERED (1 << 0)/* dentries in dir are ordered */ -#define CEPH_I_FLUSH (1 << 2)/* do not delay flush of dirty metadata */ -#define CEPH_I_POOL_PERM (1 << 3)/* pool rd/wr bits are valid */ -#define CEPH_I_POOL_RD (1 << 4)/* can read from pool */ -#define CEPH_I_POOL_WR (1 << 5)/* can write to pool */ -#define CEPH_I_SEC_INITED (1 << 6)/* security initialized */ -#define CEPH_I_KICK_FLUSH (1 << 7)/* kick flushing caps */ -#define CEPH_I_FLUSH_SNAPS (1 << 8)/* need flush snapss */ -#define CEPH_I_ERROR_WRITE (1 << 9)/* have seen write errors */ -#define CEPH_I_ERROR_FILELOCK (1 << 10)/* have seen file lock errors */ -#define CEPH_I_ODIRECT_BIT (11)/* inode in direct I/O mode */ -#define CEPH_I_ODIRECT (1 << CEPH_I_ODIRECT_BIT) -#define CEPH_ASYNC_CREATE_BIT (12)/* async create in flight for this */ -#define CEPH_I_ASYNC_CREATE (1 << CEPH_ASYNC_CREATE_BIT) -#define CEPH_I_SHUTDOWN (1 << 13)/* inode is no longer usable */ -#define CEPH_I_ASYNC_CHECK_CAPS (1 << 14)/* check caps immediately after async -creating finishes */ +#define CEPH_I_DIR_ORDERED_BIT (0)/* dentries in dir are ordered */ +#define CEPH_I_FLUSH_BIT (2)/* do not delay flush of dirty metadata */ +#define CEPH_I_POOL_PERM_BIT (3)/* pool rd/wr bits are valid */ +#define CEPH_I_POOL_RD_BIT (4)/* can read from pool */ +#define CEPH_I_POOL_WR_BIT (5)/* can write to pool */ +#define CEPH_I_SEC_INITED_BIT (6)/* security initialized */ +#define CEPH_I_KICK_FLUSH_BIT (7)/* kick flushing caps */ +#define CEPH_I_FLUSH_SNAPS_BIT (8)/* need flush snapss */ +#define CEPH_I_ERROR_WRITE_BIT (9)/* have seen write errors */ +#define CEPH_I_ERROR_FILELOCK_BIT (10)/* have seen file lock errors */ +#define CEPH_I_ODIRECT_BIT (11)/* inode in direct I/O mode */ +#define CEPH_ASYNC_CREATE_BIT (12)/* async create in flight for this */ +#define CEPH_I_SHUTDOWN_BIT (13)/* inode is no longer usable */ +#define CEPH_I_ASYNC_CHECK_CAPS_BIT (14)/* check caps after async creating finishes */ + +#define CEPH_I_DIR_ORDERED (1 << CEPH_I_DIR_ORDERED_BIT) +#define CEPH_I_FLUSH (1 << CEPH_I_FLUSH_BIT) +#define CEPH_I_POOL_PERM (1 << CEPH_I_POOL_PERM_BIT) +#define CEPH_I_POOL_RD (1 << CEPH_I_POOL_RD_BIT) +#define CEPH_I_POOL_WR (1 << CEPH_I_POOL_WR_BIT) +#define CEPH_I_SEC_INITED (1 << CEPH_I_SEC_INITED_BIT) +#define CEPH_I_KICK_FLUSH (1 << CEPH_I_KICK_FLUSH_BIT) +#define CEPH_I_FLUSH_SNAPS (1 << CEPH_I_FLUSH_SNAPS_BIT) +#define CEPH_I_ERROR_WRITE (1 << CEPH_I_ERROR_WRITE_BIT) +#define CEPH_I_ERROR_FILELOCK (1 << CEPH_I_ERROR_FILELOCK_BIT) +#define CEPH_I_ODIRECT (1 << CEPH_I_ODIRECT_BIT) +#define CEPH_I_ASYNC_CREATE (1 << CEPH_ASYNC_CREATE_BIT) +#define CEPH_I_SHUTDOWN (1 << CEPH_I_SHUTDOWN_BIT) +#define CEPH_I_ASYNC_CHECK_CAPS (1 << CEPH_I_ASYNC_CHECK_CAPS_BIT)/* * Masks of ceph inode work. @@ -691,18 +703,18 @@ static inline struct inode *ceph_find_inode(struct super_block *sb,*/ static inline void ceph_set_error_write (struct ceph_inode_info *ci) { -if (!(READ_ONCE (ci->i_ceph_flags) &CEPH_I_ERROR_WRITE )) { +if (!test_bit (CEPH_I_ERROR_WRITE_BIT , &ci->i_ceph_flags)) {spin_lock (&ci->i_ceph_lock); - ci->i_ceph_flags |=CEPH_I_ERROR_WRITE ; +set_bit (CEPH_I_ERROR_WRITE_BIT , &ci->i_ceph_flags);spin_unlock (&ci->i_ceph_lock); } }static inline void ceph_clear_error_write (struct ceph_inode_info *ci) { -if (READ_ONCE (ci->i_ceph_flags) &CEPH_I_ERROR_WRITE ) { +if (test_bit (CEPH_I_ERROR_WRITE_BIT , &ci->i_ceph_flags)) {spin_lock (&ci->i_ceph_lock); - ci->i_ceph_flags &= ~CEPH_I_ERROR_WRITE ; +clear_bit (CEPH_I_ERROR_WRITE_BIT , &ci->i_ceph_flags);spin_unlock (&ci->i_ceph_lock); } }
Alex Markuze
maintainerRe: [EXTERNAL] [RFC PATCH v1 1/4] ceph: convert inode flags to named bit positions
I think I remember reviewing it, now that you mention it. Let's discuss offline, I'll set up a 1x1.
Quoted 160 lines · Viacheslav Dubeyko
Quoted 5 lines · Alex Markuze
Define all CEPH_I_* flags as named bit positions with derived bitmask values, making them usable with test_bit/set_bit/clear_bit. Previously only
CEPH_I_ODIRECT_BITandCEPH_ASYNC_CREATE_BIThad named bit positions; the rest were bare bitmask constants.As I remember, I've reworked all constants for having name for every bit. Probably, this patch has ignored and it has never been sent to upstream. And I converted pretty everything for using test_bit/set_bit/clear_bit. :) You did this work again. :)
Thanks,
Slava.Quoted 143 lines
Convert
CEPH_I_ERROR_WRITEandCEPH_I_ERROR_FILELOCKusage sites to use atomic bit operations (test_bit,set_bit,clear_bit) via the new_BITconstants.This is preparation for the client reset feature which needs
test_bit()onCEPH_I_ERROR_FILELOCK_BITin reconnect paths.Signed-off-by Alex Markuze <[email protected]>--- fs/ceph/locks.c | 8 +++---- fs/ceph/mds_client.c | 3 ++- fs/ceph/super.h | 54 +++++++++++++++++++++++++++----------------- 3 files changed, 38 insertions(+), 27 deletions(-)fs/ceph/locks.c +3
-5@@ -58,7 +58,7 @@ static void ceph_fl_release_lock(struct file_lock *fl)if (atomic_dec_and_test (&ci->i_filelock_ref)) {/* clear error when all locks are released */ spin_lock (&ci->i_ceph_lock); - ci->i_ceph_flags &= ~CEPH_I_ERROR_FILELOCK ; +clear_bit (CEPH_I_ERROR_FILELOCK_BIT , &ci->i_ceph_flags);spin_unlock (&ci->i_ceph_lock); } fl->fl_u.ceph.inode =NULL ;@@ -272,9 +272,8 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl) wait =1 ;spin_lock (&ci->i_ceph_lock); -if (ci->i_ceph_flags &CEPH_I_ERROR_FILELOCK ) { +if (test_bit (CEPH_I_ERROR_FILELOCK_BIT , &ci->i_ceph_flags)) err = -EIO ; - }spin_unlock (&ci->i_ceph_lock);if (err <0 ) {if (op ==CEPH_MDS_OP_SETFILELOCK &&lock_is_unlock (fl))@@ -332,9 +331,8 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)doutc (cl,"fl_file: %p\n" , fl->c.flc_file);spin_lock (&ci->i_ceph_lock); -if (ci->i_ceph_flags &CEPH_I_ERROR_FILELOCK ) { +if (test_bit (CEPH_I_ERROR_FILELOCK_BIT , &ci->i_ceph_flags)) err = -EIO ; - }spin_unlock (&ci->i_ceph_lock);if (err <0 ) {if (lock_is_unlock (fl))fs/ceph/mds_client.c +2
-1@@ -3610,7 +3610,8 @@ static void __do_request(struct ceph_mds_client *mdsc,spin_lock (&ci->i_ceph_lock); cap = ci->i_auth_cap; -if (ci->i_ceph_flags &CEPH_I_ASYNC_CREATE && mds != cap->mds) { +if (test_bit (CEPH_ASYNC_CREATE_BIT , &ci->i_ceph_flags) && + mds != cap->mds) {doutc (cl,"session changed for auth cap %d -> %d\n" , cap->session->s_mds, session->s_mds);fs/ceph/super.h +33
-21@@ -655,23 +655,35 @@ static inline struct inode *ceph_find_inode(struct super_block *sb,/* * Ceph inode. */ -#define CEPH_I_DIR_ORDERED (1 << 0)/* dentries in dir are ordered */ -#define CEPH_I_FLUSH (1 << 2)/* do not delay flush of dirty metadata */ -#define CEPH_I_POOL_PERM (1 << 3)/* pool rd/wr bits are valid */ -#define CEPH_I_POOL_RD (1 << 4)/* can read from pool */ -#define CEPH_I_POOL_WR (1 << 5)/* can write to pool */ -#define CEPH_I_SEC_INITED (1 << 6)/* security initialized */ -#define CEPH_I_KICK_FLUSH (1 << 7)/* kick flushing caps */ -#define CEPH_I_FLUSH_SNAPS (1 << 8)/* need flush snapss */ -#define CEPH_I_ERROR_WRITE (1 << 9)/* have seen write errors */ -#define CEPH_I_ERROR_FILELOCK (1 << 10)/* have seen file lock errors */ -#define CEPH_I_ODIRECT_BIT (11)/* inode in direct I/O mode */ -#define CEPH_I_ODIRECT (1 << CEPH_I_ODIRECT_BIT) -#define CEPH_ASYNC_CREATE_BIT (12)/* async create in flight for this */ -#define CEPH_I_ASYNC_CREATE (1 << CEPH_ASYNC_CREATE_BIT) -#define CEPH_I_SHUTDOWN (1 << 13)/* inode is no longer usable */ -#define CEPH_I_ASYNC_CHECK_CAPS (1 << 14)/* check caps immediately after async -creating finishes */ +#define CEPH_I_DIR_ORDERED_BIT (0)/* dentries in dir are ordered */ +#define CEPH_I_FLUSH_BIT (2)/* do not delay flush of dirty metadata */ +#define CEPH_I_POOL_PERM_BIT (3)/* pool rd/wr bits are valid */ +#define CEPH_I_POOL_RD_BIT (4)/* can read from pool */ +#define CEPH_I_POOL_WR_BIT (5)/* can write to pool */ +#define CEPH_I_SEC_INITED_BIT (6)/* security initialized */ +#define CEPH_I_KICK_FLUSH_BIT (7)/* kick flushing caps */ +#define CEPH_I_FLUSH_SNAPS_BIT (8)/* need flush snapss */ +#define CEPH_I_ERROR_WRITE_BIT (9)/* have seen write errors */ +#define CEPH_I_ERROR_FILELOCK_BIT (10)/* have seen file lock errors */ +#define CEPH_I_ODIRECT_BIT (11)/* inode in direct I/O mode */ +#define CEPH_ASYNC_CREATE_BIT (12)/* async create in flight for this */ +#define CEPH_I_SHUTDOWN_BIT (13)/* inode is no longer usable */ +#define CEPH_I_ASYNC_CHECK_CAPS_BIT (14)/* check caps after async creating finishes */ + +#define CEPH_I_DIR_ORDERED (1 << CEPH_I_DIR_ORDERED_BIT) +#define CEPH_I_FLUSH (1 << CEPH_I_FLUSH_BIT) +#define CEPH_I_POOL_PERM (1 << CEPH_I_POOL_PERM_BIT) +#define CEPH_I_POOL_RD (1 << CEPH_I_POOL_RD_BIT) +#define CEPH_I_POOL_WR (1 << CEPH_I_POOL_WR_BIT) +#define CEPH_I_SEC_INITED (1 << CEPH_I_SEC_INITED_BIT) +#define CEPH_I_KICK_FLUSH (1 << CEPH_I_KICK_FLUSH_BIT) +#define CEPH_I_FLUSH_SNAPS (1 << CEPH_I_FLUSH_SNAPS_BIT) +#define CEPH_I_ERROR_WRITE (1 << CEPH_I_ERROR_WRITE_BIT) +#define CEPH_I_ERROR_FILELOCK (1 << CEPH_I_ERROR_FILELOCK_BIT) +#define CEPH_I_ODIRECT (1 << CEPH_I_ODIRECT_BIT) +#define CEPH_I_ASYNC_CREATE (1 << CEPH_ASYNC_CREATE_BIT) +#define CEPH_I_SHUTDOWN (1 << CEPH_I_SHUTDOWN_BIT) +#define CEPH_I_ASYNC_CHECK_CAPS (1 << CEPH_I_ASYNC_CHECK_CAPS_BIT)/* * Masks of ceph inode work. @@ -691,18 +703,18 @@ static inline struct inode *ceph_find_inode(struct super_block *sb,*/ static inline void ceph_set_error_write (struct ceph_inode_info *ci) { -if (!(READ_ONCE (ci->i_ceph_flags) &CEPH_I_ERROR_WRITE )) { +if (!test_bit (CEPH_I_ERROR_WRITE_BIT , &ci->i_ceph_flags)) {spin_lock (&ci->i_ceph_lock); - ci->i_ceph_flags |=CEPH_I_ERROR_WRITE ; +set_bit (CEPH_I_ERROR_WRITE_BIT , &ci->i_ceph_flags);spin_unlock (&ci->i_ceph_lock); } }static inline void ceph_clear_error_write (struct ceph_inode_info *ci) { -if (READ_ONCE (ci->i_ceph_flags) &CEPH_I_ERROR_WRITE ) { +if (test_bit (CEPH_I_ERROR_WRITE_BIT , &ci->i_ceph_flags)) {spin_lock (&ci->i_ceph_lock); - ci->i_ceph_flags &= ~CEPH_I_ERROR_WRITE ; +clear_bit (CEPH_I_ERROR_WRITE_BIT , &ci->i_ceph_flags);spin_unlock (&ci->i_ceph_lock); } }
Alex Markuze
maintainerRFC PATCH 2/4 ceph: add bounded timeout and diagnostics to wait_caps_flush()
In reply to Alex MarkuzeConvert wait_caps_flush() from an unbounded wait_event() to a bounded wait_event_timeout() with a 60-second period. If the flush hasn't completed after each timeout, dump the pending cap_flush list (up to 5 times) to aid debugging hung flush scenarios.
Add a ci back-pointer to struct ceph_cap_flush so the diagnostic dump can identify which inodes have outstanding flushes. Add i_last_cap_flush_ack to ceph_inode_info for tracking the latest acknowledged flush tid per inode.
--- fs/ceph/caps.c | 7 +++++++ fs/ceph/mds_client.c | 41 +++++++++++++++++++++++++++++++++++++++-- fs/ceph/super.h | 2 ++ 3 files changed, 48 insertions(+), 2 deletions(-)
fs/ceph/caps.c +7 -0
@@ -1648,6 +1648,7 @@ static void __ceph_flush_snaps(struct ceph_inode_info *ci,spin_lock (&mdsc->cap_dirty_lock); capsnap->cap_flush.tid = ++mdsc->last_cap_flush_tid; + capsnap->cap_flush.ci = ci;list_add_tail (&capsnap->cap_flush.g_list, &mdsc->cap_flush_list);if (oldest_flush_tid ==0 )
@@ -1846,6 +1847,9 @@ struct ceph_cap_flush *ceph_alloc_cap_flush(void)return NULL ; cf->is_capsnap = false; + cf->ci =NULL ; + cf->tid =0 ; + cf->wake = false;return cf; }
@@ -1931,6 +1935,7 @@ static u64 __mark_caps_flushing(struct inode *inode,doutc (cl,"%p %llx.%llx now !dirty\n" , inode,ceph_vinop (inode));swap (cf, ci->i_prealloc_cap_flush); + cf->ci = ci; cf->caps = flushing; cf->wake = wake;
@@ -3826,6 +3831,8 @@ static void handle_cap_flush_ack(struct inode *inode, u64 flush_tid,bool wake_ci = false;bool wake_mdsc = false; + ci->i_last_cap_flush_ack = flush_tid; +list_for_each_entry_safe (cf, tmp_cf, &ci->i_cap_flush_list, i_list) {/* Is this the one that was flushed? */ if (cf->tid == flush_tid)
fs/ceph/mds_client.c +39 -2
62 lines not on this page · raw message
fs/ceph/super.h +2 -0
@@ -238,6 +238,7 @@ struct ceph_cap_flush {bool is_capsnap;/* true means capsnap */ struct list_head g_list;// global struct list_head i_list;// per inode +struct ceph_inode_info *ci; };/*
@@ -443,6 +444,7 @@ struct ceph_inode_info {struct ceph_snap_context *i_head_snapc;/* set if wr_buffer_head > 0 or dirty|flushing caps */ unsigned i_snap_caps;/* cap bits for snapped files */ +u64 i_last_cap_flush_ack;/* latest cap flush_ack tid for this inode */ unsigned long i_last_rd;unsigned long i_last_wr;
Signature · 1 line
2.34.1
Alex Markuze
maintainerRFC PATCH 3/4 ceph: implement manual client session reset via debugfs
In reply to Alex MarkuzeAdd a mechanism for operators to trigger MDS session reconnection without unmounting the filesystem. This is useful for recovering from stuck or hung MDS sessions in production environments.
The reset lifecycle:
1. Operator writes to /sys/kernel/debug/ceph/<fsid>/reset/trigger
2. A work item collects all active sessions and calls send_mds_reconnect() on each with from_reset=true
3. New metadata requests and lock acquisitions are blocked (with a 120s timeout) until the reset completes
4. Session reconnect completions are tracked via a per-session generation counter (s_reset_gen) to avoid counting stale completions from timed-out prior resets
5. The reset work waits up to 60s for all sessions to reconnect
Debugfs interface under reset/:
- trigger (write-only): initiate a reset with optional reason
- status (read-only): show counters and current state
- inject_error (write-only): fault injection for testing
Lock handling during reset-initiated reconnects always attempts optimistic lock reclamation (flock_len=1) regardless of the CEPH_I_ERROR_FILELOCK state, since the reset is meant to recover from exactly those error conditions.
Tracepoints are added for the reset lifecycle:ceph_client_reset_schedule, ceph_client_reset_complete, ceph_client_reset_blocked, ceph_client_reset_unblocked.
Note: Reset tracepoints added to include/trace/events/ceph.h (merged with existing upstream tracepoint infrastructure) instead of the separate ceph_client.h from the original patch.
--- fs/ceph/debugfs.c | 171 +++++++++++++- fs/ceph/locks.c | 16 ++ fs/ceph/mds_client.c | 444 +++++++++++++++++++++++++++++++++++- fs/ceph/mds_client.h | 33 +++ fs/ceph/super.h | 4 + include/trace/events/ceph.h | 60 +++++ 6 files changed, 707 insertions(+), 21 deletions(-)
fs/ceph/debugfs.c +161 -10
@@ -9,6 +9,8 @@#include <linux/seq_file.h> #include <linux/math64.h> #include <linux/ktime.h> +#include <linux/uaccess.h> +#include <linux/kstrtox.h> #include <linux/ceph/libceph.h> #include <linux/ceph/mon_client.h>
@@ -22,6 +24,10 @@#include "mds_client.h" #include "metric.h" +#define CEPH_DEBUGFS_MODE_READONLY 0400 +#define CEPH_DEBUGFS_MODE_WRITEONLY 0200 +#define CEPH_DEBUGFS_MODE_READWRITE 0600 +static int mdsmap_show (struct seq_file *s,void *p) {int i;
@@ -360,16 +366,140 @@ static int status_show(struct seq_file *s, void *p)return 0 ; } +static int reset_status_show (struct seq_file *s,void *p) +{ +struct ceph_fs_client *fsc = s->private; +struct ceph_mds_client *mdsc = fsc->mdsc; +struct ceph_client_reset_state *st; +u64 trigger =0 , success =0 , failure =0 ; +unsigned long last_start =0 , last_finish =0 ; +int last_errno =0 ; +bool in_progress = false; +bool inject_error = false; +int pending_reconnects =0 ; +int blocked_requests =0 ; +char reason[CEPH_CLIENT_RESET_REASON_LEN ]; + +if (!mdsc) +return 0 ; + + st = &mdsc->reset_state; + +spin_lock (&st->lock); + trigger = st->trigger_count; + success = st->success_count; + failure = st->failure_count; + last_start = st->last_start; + last_finish = st->last_finish; + last_errno = st->last_errno; + in_progress = st->in_progress; + inject_error = st->inject_error; +strscpy (reason, st->last_reason,sizeof (reason)); +spin_unlock (&st->lock); + + pending_reconnects =atomic_read (&st->pending_reconnects); + blocked_requests =atomic_read (&st->blocked_requests); + +seq_printf (s,"in_progress: %s\n" , in_progress ?"yes" :"no" ); +seq_printf (s,"trigger_count: %llu\n" , trigger); +seq_printf (s,"success_count: %llu\n" , success); +seq_printf (s,"failure_count: %llu\n" , failure); +if (last_start) +seq_printf (s,"last_start_ms_ago: %u\n" , +jiffies_to_msecs (jiffies - last_start)); +else +seq_puts (s,"last_start_ms_ago: (never)\n" ); +if (last_finish) +seq_printf (s,"last_finish_ms_ago: %u\n" , +jiffies_to_msecs (jiffies - last_finish)); +else +seq_puts (s,"last_finish_ms_ago: (never)\n" ); +seq_printf (s,"last_errno: %d\n" , last_errno); +seq_printf (s,"last_reason: %s\n" , + reason[0 ] ? reason :"(none)" ); +seq_printf (s,"inject_error_pending: %s\n" , + inject_error ?"yes" :"no" ); +seq_printf (s,"pending_reconnects: %d\n" , pending_reconnects); +seq_printf (s,"blocked_requests: %d\n" , blocked_requests); + +return 0 ; +} + +static ssize_t reset_trigger_write (struct file *file,const char __user *buf, +size_t len,loff_t *ppos) +{ +struct ceph_fs_client *fsc = file->private_data; +struct ceph_mds_client *mdsc = fsc->mdsc; +char reason[CEPH_CLIENT_RESET_REASON_LEN ]; +size_t copy; +int ret; + +if (!mdsc) +return -ENODEV ; + + copy =min_t (size_t, len,sizeof (reason) -1 ); +if (copy &©_from_user (reason, buf, copy)) +return -EFAULT ; + reason[copy] ='\0' ; +strim (reason); + + ret =ceph_mdsc_schedule_reset (mdsc, reason); +if (ret) +return ret; + +return len; +} + +static ssize_t reset_inject_error_write (struct file *file, +const char __user *buf, +size_t len,loff_t *ppos) +{ +struct ceph_fs_client *fsc = file->private_data; +struct ceph_mds_client *mdsc = fsc->mdsc; +struct ceph_client_reset_state *st; +bool enable; +int ret; + +if (!mdsc) +return -ENODEV ; + + ret =kstrtobool_from_user (buf, len, &enable); +if (ret) +return ret; + + st = &mdsc->reset_state; +spin_lock (&st->lock); + st->inject_error = enable; +spin_unlock (&st->lock); + +return len; +} +DEFINE_SHOW_ATTRIBUTE (mdsmap);DEFINE_SHOW_ATTRIBUTE (mdsc);DEFINE_SHOW_ATTRIBUTE (caps);DEFINE_SHOW_ATTRIBUTE (mds_sessions);DEFINE_SHOW_ATTRIBUTE (status); +DEFINE_SHOW_ATTRIBUTE (reset_status);DEFINE_SHOW_ATTRIBUTE (metrics_file);DEFINE_SHOW_ATTRIBUTE (metrics_latency);DEFINE_SHOW_ATTRIBUTE (metrics_size);DEFINE_SHOW_ATTRIBUTE (metrics_caps); +static const struct file_operations ceph_reset_trigger_fops = { + .owner =THIS_MODULE , + .open = simple_open, + .write = reset_trigger_write, + .llseek = noop_llseek, +}; + +static const struct file_operations ceph_reset_inject_error_fops = { + .owner =THIS_MODULE , + .open = simple_open, + .write = reset_inject_error_write, + .llseek = noop_llseek, +}; +/* * debugfs
@@ -404,6 +534,10 @@ void ceph_fs_debugfs_cleanup(struct ceph_fs_client *fsc)debugfs_remove (fsc->debugfs_caps);debugfs_remove (fsc->debugfs_status);debugfs_remove (fsc->debugfs_mdsc); +debugfs_remove (fsc->debugfs_reset_status); +debugfs_remove (fsc->debugfs_reset_force); +debugfs_remove (fsc->debugfs_reset_inject); +debugfs_remove_recursive (fsc->debugfs_reset_dir);debugfs_remove_recursive (fsc->debugfs_metrics_dir);doutc (fsc->client,"done\n" ); }
@@ -415,7 +549,7 @@ void ceph_fs_debugfs_init(struct ceph_fs_client *fsc)doutc (fsc->client,"begin\n" ); fsc->debugfs_congestion_kb =debugfs_create_file ("writeback_congestion_kb" , -0600 , +CEPH_DEBUGFS_MODE_READWRITE , fsc->client->debugfs_dir, fsc, &congestion_kb_fops);
@@ -428,31 +562,48 @@ void ceph_fs_debugfs_init(struct ceph_fs_client *fsc) name); fsc->debugfs_mdsmap =debugfs_create_file ("mdsmap" , -0400 , +CEPH_DEBUGFS_MODE_READONLY , fsc->client->debugfs_dir, fsc, &mdsmap_fops); fsc->debugfs_mds_sessions =debugfs_create_file ("mds_sessions" , -0400 , +CEPH_DEBUGFS_MODE_READONLY , fsc->client->debugfs_dir, fsc, &mds_sessions_fops); fsc->debugfs_mdsc =debugfs_create_file ("mdsc" , -0400 , +CEPH_DEBUGFS_MODE_READONLY , fsc->client->debugfs_dir, fsc, &mdsc_fops); fsc->debugfs_caps =debugfs_create_file ("caps" , -0400 , +CEPH_DEBUGFS_MODE_READONLY , fsc->client->debugfs_dir, fsc, &caps_fops); + fsc->debugfs_reset_dir =debugfs_create_dir ("reset" , + fsc->client->debugfs_dir); +if (fsc->debugfs_reset_dir) { + fsc->debugfs_reset_force = +debugfs_create_file ("trigger" ,CEPH_DEBUGFS_MODE_WRITEONLY , + fsc->debugfs_reset_dir, fsc, + &ceph_reset_trigger_fops); + fsc->debugfs_reset_status = +debugfs_create_file ("status" ,CEPH_DEBUGFS_MODE_READONLY , + fsc->debugfs_reset_dir, fsc, + &reset_status_fops); + fsc->debugfs_reset_inject = +debugfs_create_file ("inject_error" ,CEPH_DEBUGFS_MODE_WRITEONLY , + fsc->debugfs_reset_dir, fsc, + &ceph_reset_inject_error_fops); + } + fsc->debugfs_status =debugfs_create_file ("status" , -0400 , +CEPH_DEBUGFS_MODE_READONLY , fsc->client->debugfs_dir, fsc, &status_fops);
@@ -460,13 +611,13 @@ void ceph_fs_debugfs_init(struct ceph_fs_client *fsc) fsc->debugfs_metrics_dir =debugfs_create_dir ("metrics" , fsc->client->debugfs_dir); -debugfs_create_file ("file" ,0400 , fsc->debugfs_metrics_dir, fsc, +debugfs_create_file ("file" ,CEPH_DEBUGFS_MODE_READONLY , fsc->debugfs_metrics_dir, fsc, &metrics_file_fops); -debugfs_create_file ("latency" ,0400 , fsc->debugfs_metrics_dir, fsc, +debugfs_create_file ("latency" ,CEPH_DEBUGFS_MODE_READONLY , fsc->debugfs_metrics_dir, fsc, &metrics_latency_fops); -debugfs_create_file ("size" ,0400 , fsc->debugfs_metrics_dir, fsc, +debugfs_create_file ("size" ,CEPH_DEBUGFS_MODE_READONLY , fsc->debugfs_metrics_dir, fsc, &metrics_size_fops); -debugfs_create_file ("caps" ,0400 , fsc->debugfs_metrics_dir, fsc, +debugfs_create_file ("caps" ,CEPH_DEBUGFS_MODE_READONLY , fsc->debugfs_metrics_dir, fsc, &metrics_caps_fops);doutc (fsc->client,"done\n" ); }
fs/ceph/locks.c +16 -0
@@ -251,6 +251,7 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl) {struct inode *inode =file_inode (file);struct ceph_inode_info *ci =ceph_inode (inode); +struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (inode->i_sb);struct ceph_client *cl =ceph_inode_to_client (inode);int err =0 ;u16 op =CEPH_MDS_OP_SETFILELOCK ;
@@ -281,6 +282,13 @@ int ceph_lock(struct file *file, int cmd, struct file_lock *fl)return err; } +/* Wait for reset to complete before acquiring new locks */ +if (op ==CEPH_MDS_OP_SETFILELOCK && !lock_is_unlock (fl)) { + err =ceph_mdsc_wait_for_reset (mdsc); +if (err) +return err; + } +if (lock_is_read (fl)) lock_cmd =CEPH_LOCK_SHARED ;else if (lock_is_write (fl))
@@ -317,6 +325,7 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl) {struct inode *inode =file_inode (file);struct ceph_inode_info *ci =ceph_inode (inode); +struct ceph_mds_client *mdsc =ceph_sb_to_mdsc (inode->i_sb);struct ceph_client *cl =ceph_inode_to_client (inode);int err =0 ;u8 wait =0 ;
@@ -340,6 +349,13 @@ int ceph_flock(struct file *file, int cmd, struct file_lock *fl)return err; } +/* Wait for reset to complete before acquiring new locks */ +if (!lock_is_unlock (fl)) { + err =ceph_mdsc_wait_for_reset (mdsc); +if (err) +return err; + } +if (IS_SETLKW (cmd)) wait =1 ;
fs/ceph/mds_client.c +433 -11
564 lines not on this page · raw message
fs/ceph/mds_client.h +33 -0
@@ -75,6 +75,32 @@ struct ceph_cap;#define MDS_AUTH_UID_ANY -1 +#define CEPH_CLIENT_RESET_REASON_LEN 64 +#define CEPH_CLIENT_RESET_TIMEOUT_SEC 60 +#define CEPH_CLIENT_RESET_WAIT_TIMEOUT_SEC 120 + +struct ceph_client_reset_state { +spinlock_t lock; +u64 trigger_count; +u64 success_count; +u64 failure_count; +unsigned long last_start; +unsigned long last_finish; +int last_errno; +bool in_progress; +bool inject_error; +char last_reason[CEPH_CLIENT_RESET_REASON_LEN ]; + +/* Completion tracking for session reconnects */ +u64 active_reset_gen; +atomic_t pending_reconnects; +struct completion reconnect_done; + +/* Request blocking during reset */ +wait_queue_head_t blocked_wq; +atomic_t blocked_requests; +}; +struct ceph_mds_cap_match {s64 uid;/* default to MDS_AUTH_UID_ANY */ u32 num_gids;
@@ -251,6 +277,8 @@ struct ceph_mds_session {struct list_head s_waiting;/* waiting requests */ struct list_head s_unsafe;/* unsafe requests */ struct xarray s_delegated_inos; + +u64 s_reset_gen;/* generation of reset that initiated reconnect */ };/*
@@ -536,6 +564,8 @@ struct ceph_mds_client {struct list_head dentry_dir_leases;/* lru list */ struct ceph_client_metric metric; +struct work_struct reset_work; +struct ceph_client_reset_state reset_state;spinlock_t snapid_map_lock;struct rb_root snapid_map_tree;
@@ -563,6 +593,9 @@ extern const char *ceph_session_state_name(int s);extern struct ceph_mds_session *ceph_get_mds_session (struct ceph_mds_session *s);extern void ceph_put_mds_session (struct ceph_mds_session *s); +int ceph_mdsc_schedule_reset (struct ceph_mds_client *mdsc, +const char *reason); +int ceph_mdsc_wait_for_reset (struct ceph_mds_client *mdsc);extern int ceph_mdsc_init (struct ceph_fs_client *fsc);extern void ceph_mdsc_close_sessions (struct ceph_mds_client *mdsc);
fs/ceph/super.h +4 -0
@@ -179,6 +179,10 @@ struct ceph_fs_client {struct dentry *debugfs_status;struct dentry *debugfs_mds_sessions;struct dentry *debugfs_metrics_dir; +struct dentry *debugfs_reset_dir; +struct dentry *debugfs_reset_force; +struct dentry *debugfs_reset_status; +struct dentry *debugfs_reset_inject;#endif #ifdef CONFIG_CEPH_FSCACHE
include/trace/events/ceph.h +60 -0
66 lines not on this page · raw message
Signature · 1 line
2.34.1
Alex Markuze
maintainerRFC PATCH 4/4 ceph: rework mds_peer_reset() for robust session recovery
In reply to Alex MarkuzeRewrite mds_peer_reset() to properly handle all session states when the MDS resets our connection. Previously it unconditionally called send_mds_reconnect() for any state >= RECONNECT, which could leave sessions in inconsistent states.
The new implementation:
- Returns early for FENCE_IO or MDS not yet in reconnect state
- For MDS in RECONNECT state, directly reconnects (no locks)
- For active sessions (OPEN/OPENING/CLOSING), performs full
cleanup: unregister session, wake waiting requests, clean up caps, and kick pending requests
- For RECONNECTING sessions, restarts the reconnect
- Snapshots session state under s_mutex, then re-acquires locks in the correct order (s_mutex -> mdsc->mutex) matching the convention used by check_new_map() and cleanup_session_requests()
--- fs/ceph/mds_client.c | 89 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 3 deletions(-)
fs/ceph/mds_client.c +86 -3
@@ -6737,12 +6737,95 @@ static void mds_peer_reset(struct ceph_connection *con) {struct ceph_mds_session *s = con->private;struct ceph_mds_client *mdsc = s->s_mdsc; +int session_state;pr_warn_client (mdsc->fsc->client,"mds%d closed our session\n" , s->s_mds); -if (READ_ONCE (mdsc->fsc->mount_state) !=CEPH_MOUNT_FENCE_IO && -ceph_mdsmap_get_state (mdsc->mdsmap, s->s_mds) >=CEPH_MDS_STATE_RECONNECT ) -send_mds_reconnect (mdsc, s); + +if (READ_ONCE (mdsc->fsc->mount_state) ==CEPH_MOUNT_FENCE_IO || +ceph_mdsmap_get_state (mdsc->mdsmap, s->s_mds) <CEPH_MDS_STATE_RECONNECT ) +return ; + +if (ceph_mdsmap_get_state (mdsc->mdsmap, s->s_mds) ==CEPH_MDS_STATE_RECONNECT ) { +int rc =send_mds_reconnect (mdsc, s, false); +if (rc) +pr_err_client (mdsc->fsc->client, +"mds%d reconnect failed: %d\n" , + s->s_mds, rc); +return ; + } + +/* +* Snapshot session state under s->s_mutex, then release before +* re-acquiring in the correct order: s->s_mutex -> mdsc->mutex +* (matching check_new_map() and cleanup_session_requests()). +*/ +mutex_lock (&s->s_mutex); + session_state = s->s_state; +mutex_unlock (&s->s_mutex); + +switch (session_state) { +case CEPH_MDS_SESSION_RECONNECTING : { +int rc; + +pr_info_client (mdsc->fsc->client, +"mds%d reset during reconnect, restarting\n" , + s->s_mds); + rc =send_mds_reconnect (mdsc, s, false); +if (rc) { +pr_err_client (mdsc->fsc->client, +"mds%d reconnect restart failed: %d\n" , + s->s_mds, rc); +mutex_lock (&s->s_mutex); +ceph_mdsc_reconnect_session_done (mdsc, s); +mutex_unlock (&s->s_mutex); + } +return ; + } +case CEPH_MDS_SESSION_CLOSING : +case CEPH_MDS_SESSION_OPEN : +case CEPH_MDS_SESSION_HUNG : +case CEPH_MDS_SESSION_OPENING : +mutex_lock (&s->s_mutex); +mutex_lock (&mdsc->mutex); +if (s->s_state != session_state) { +pr_info_client (mdsc->fsc->client, +"mds%d state changed to %s during peer reset\n" , + s->s_mds, +ceph_session_state_name (s->s_state)); +mutex_unlock (&mdsc->mutex); +mutex_unlock (&s->s_mutex); +return ; + } + +ceph_get_mds_session (s); +__unregister_session (mdsc, s); + + s->s_state =CEPH_MDS_SESSION_CLOSED ; +__wake_requests (mdsc, &s->s_waiting); +mutex_unlock (&mdsc->mutex); +mutex_unlock (&s->s_mutex); + +mutex_lock (&s->s_mutex); +cleanup_session_requests (mdsc, s); +remove_session_caps (s); +mutex_unlock (&s->s_mutex); + +wake_up_all (&mdsc->session_close_wq); + +mutex_lock (&mdsc->mutex); +kick_requests (mdsc, s->s_mds); +mutex_unlock (&mdsc->mutex); + +ceph_put_mds_session (s); +break ; +default : +pr_warn_client (mdsc->fsc->client, +"mds%d peer reset in unexpected state %s\n" , + s->s_mds, +ceph_session_state_name (session_state)); +break ; + } }static void mds_dispatch (struct ceph_connection *con,struct ceph_msg *msg)
Signature · 1 line
2.34.1
Quoted 11 lines · Alex Markuze
In production CephFS deployments we regularly encounter situations where MDS sessions become stuck or hung, requiring a full unmount/ remount cycle to recover. This is disruptive for workloads that cannot tolerate the downtime or the loss of cached state that comes with unmounting.
This series adds a mechanism to manually trigger MDS session reconnection from the client side without unmounting, exposed via debugfs:
echo "reason text" > /sys/kernel/debug/ceph/<fsid>/reset/trigger
What do you mean by "reason text"? Usually, it should be some command. Do you mean that any string will trigger the reset? Is it good approach? What if a user sends something by mistake or any malicious garbage? Potentially, it could be security breach.
Quoted 1 line
cat /sys/kernel/debug/ceph/<fsid>/reset/status
This "reset/status" sounds slightly ambiguous. Is it status of reset process? If we didn't request the reset, then what this status means?
Quoted 24 lines
The reset lifecycle:
1. Operator writes to the trigger file
2. A work item collects all active sessions and initiates reconnection on each (viasend_mds_reconnectwith from_reset=true)
3. New metadata requests and lock acquisitions are blocked until the reset completes (120s timeout)
4. Session completions are tracked via a per-session generation counter to handle stale completions from timed-out prior resets
5. Lock reclamation is always attempted during reset-initiated reconnects, regardless of priorCEPH_I_ERROR_FILELOCKstatePatch breakdown:
1. Convert CEPH_I_* flags to named bit positions so test_bit/ set_bit/clear_bit can be used in reconnect paths
2. Makewait_caps_flush()bounded with periodic diagnostic dumps to aid debugging hung flush scenarios (independent improvement that surfaced during development)
3. The core reset implementation: debugfs interface, reset work function, request/lock blocking, tracepoints, and session reconnect completion tracking
4. Reworkmds_peer_reset()to properly handle all session states and integrate with the reset completion tracking
Quoted 3 lines
Open questions / areas for review:
- Is debugfs the right interface, or should this be a mount option / sysfs attribute / netlink command?
Recently, I had short discussion with Greg Kroah-Hartman. He was completely against of using sysfs for transferring commands from user-space to kernel- space. So, we could have troubles of using sysfs for this. And /sys/kernel/debug/ sounds like completely wrong place. Because, this is not debug feature or option. You are suggesting this as a regular feature for production.
Maybe, we can consider eBPF here?
Quoted 3 lines
- The request gating in
ceph_mdsc_submit_request()is best-effort (no lock serialization) to avoid penalizing the normal path. Is this acceptable?
So, we have "MDS sessions become stuck or hung" and we are trying to submit another request. Is it sane enough? We already have a dead session. :)
Quoted 2 lines
- Should the 60s reconnect timeout and 120s blocked-request timeout be configurable (e.g. via mount options)?
I think we already have some timeout option in the mount options. Are you suggesting yet another one?
Quoted 2 lines
-
mds_peer_reset()rework (patch 4) is substantial -- would reviewers prefer it split further?
Do you mean patch 3 or 4? Because, patch 3 is huge in size.
Thanks,
Slava.
Quoted 16 lines
Alex Markuze (4):
ceph: convert inode flags to named bit positions
ceph: add bounded timeout and diagnostics towait_caps_flush()
ceph: implement manual client session reset via debugfs
ceph: reworkmds_peer_reset()for robust session recoveryfs/ceph/caps.c | 7 + fs/ceph/debugfs.c | 171 ++++++++++- fs/ceph/locks.c | 24 +- fs/ceph/mds_client.c | 577 ++++++++++++++++++++++++++++++++++-- fs/ceph/mds_client.h | 33 +++ fs/ceph/super.h | 60 ++-- include/trace/events/ceph.h | 60 ++++ 7 files changed, 879 insertions(+), 53 deletions(-)
Alex Markuze
maintainerQuoted 4 lines
What do you mean by "reason text"? Usually, it should be some command. Do you mean that any string will trigger the reset? Is it good approach? What if a user sends something by mistake or any malicious garbage? Potentially, it could be security breach.
The string is an optional free-form operator note that gets logged and recorded in the status output for post-mortem diagnostics (e.g. "RHBZ#12345" or "mds0 stuck after failover"). Any write to the trigger file initiates the reset -- the content is not interpreted as a command.
The input length is capped at CEPH_CLIENT_RESET_REASON_LEN - 1 (63 bytes) via min_t() before copy_from_user(), then null-terminated and strim()'d. Anything longer is silently truncated -- no overflow is possible.
Regarding security: the trigger file is created with mode 0200 (write-only, owner-only), and debugfs itself is typically mounted root-only. So the write is restricted to a privileged operator, same as any other debugfs knob. That said, I agree the interface question is open -- see below.
Quoted 2 lines
This "reset/status" sounds slightly ambiguous. Is it status of reset process? If we didn't request the reset, then what this status means?
It is the status of the reset subsystem. When no reset has been requested, it shows the idle state:
``` in_progress: no trigger_count: 0 success_count: 0 failure_count: 0 last_start_ms_ago: (never) last_finish_ms_ago: (never) last_errno: 0 last_reason: (none) inject_error_pending: no pending_reconnects: 0 blocked_requests: 0 ```
Happy to rename it to something less ambiguous, maybe reset/reset_status or just moving the counters into the existing top-level status file. Open to suggestions.
Quoted 8 lines
Recently, I had short discussion with Greg Kroah-Hartman. He was completely against of using sysfs for transferring commands from user-space to kernel- space. So, we could have troubles of using sysfs for this. And
/sys/kernel/debug/sounds like completely wrong place. Because, this is not debug feature or option. You are suggesting this as a regular feature for production.Maybe, we can consider eBPF here?
Yeah, debugfs is not the right place for a production feature.
The debugfs interface is there for now as a development/testing trigger while the core reset mechanism is reviewed. The longer-term goal is automated recovery: the client would detect stuck/hung sessions and trigger the reset internally without operator intervention. Once that's in place, the manual trigger becomes a fallback rather than the primary interface.
For production manual triggering (before automated recovery is ready), we can consider other approaches, e.g., ioctl, netlink, or extending the existing recover_session=clean path. That path already handles automatic recovery from blocklisting via maybe_recover_session() / ceph_force_reconnect(); the manual reset solves a related but different problem (sessions stuck without blocklisting), so the machinery could potentially be unified.
Quoted 2 lines
So, we have "MDS sessions become stuck or hung" and we are trying to submit another request. Is it sane enough? We already have a dead session. :)
The gating does not submit requests to the dead session, it does the opposite. When a reset is in progress, ceph_mdsc_wait_for_reset() blocks new incoming requests (and new lock acquisitions) until the reset completes and sessions are re-established. Only then do the blocked requests proceed through the normal __do_request() path, which will find the freshly reconnected sessions.
The "best-effort" note refers to the fact that we don't take a lock on the hot path, a request could slip past the check in the narrow window before in_progress is set. That's acceptable because such a request would either complete normally on the still-alive session or fail and be retried by the caller after the reset.
Quoted 2 lines
I think we already have some timeout option in the mount options. Are you suggesting yet another one?
Fair point. The existing mount_timeout controls how long mount and reconnect operations wait. The two timeouts here are:
- 60s for the reset work to wait for session reconnects to complete
- 120s for blocked requests to wait for the reset to finish
I think these can stay as compile-time constants (CEPH_CLIENT_RESET_TIMEOUT_SEC / CEPH_CLIENT_RESET_WAIT_TIMEOUT_SEC) rather than becoming mount options. They're operational bounds for a rare manual operation, not something an admin would typically need to tune. If reviewers feel otherwise I can tie them to mount_timeout.
Quoted 1 line
Do you mean patch 3 or 4? Because, patch 3 is huge in size.
You're right, patch 3 is the large one (~700 lines). I can split it further if that helps review. A natural split would be:
- 3a: ceph_client_reset_state struct, init/destroy, and ceph_mdsc_wait_for_reset() blocking infrastructure
- 3b: ceph_mdsc_reset_workfn(), send_mds_reconnect() changes, and session completion tracking
- 3c: debugfs interface (trigger, status, inject_error)
- 3d: tracepoints
Let me know if that granularity makes sense or if you'd prefer a different split.
Thanks for the review, Slava.
Quoted 100 lines · Viacheslav Dubeyko
Quoted 11 lines · Alex Markuze
In production CephFS deployments we regularly encounter situations where MDS sessions become stuck or hung, requiring a full unmount/ remount cycle to recover. This is disruptive for workloads that cannot tolerate the downtime or the loss of cached state that comes with unmounting.
This series adds a mechanism to manually trigger MDS session reconnection from the client side without unmounting, exposed via debugfs:
echo "reason text" > /sys/kernel/debug/ceph/<fsid>/reset/trigger
What do you mean by "reason text"? Usually, it should be some command. Do you mean that any string will trigger the reset? Is it good approach? What if a user sends something by mistake or any malicious garbage? Potentially, it could be security breach.
Quoted 1 line
cat /sys/kernel/debug/ceph/<fsid>/reset/status
This "reset/status" sounds slightly ambiguous. Is it status of reset process? If we didn't request the reset, then what this status means?
Quoted 24 lines
The reset lifecycle:
1. Operator writes to the trigger file
2. A work item collects all active sessions and initiates reconnection on each (viasend_mds_reconnectwith from_reset=true)
3. New metadata requests and lock acquisitions are blocked until the reset completes (120s timeout)
4. Session completions are tracked via a per-session generation counter to handle stale completions from timed-out prior resets
5. Lock reclamation is always attempted during reset-initiated reconnects, regardless of priorCEPH_I_ERROR_FILELOCKstatePatch breakdown:
1. Convert CEPH_I_* flags to named bit positions so test_bit/ set_bit/clear_bit can be used in reconnect paths
2. Makewait_caps_flush()bounded with periodic diagnostic dumps to aid debugging hung flush scenarios (independent improvement that surfaced during development)
3. The core reset implementation: debugfs interface, reset work function, request/lock blocking, tracepoints, and session reconnect completion tracking
4. Reworkmds_peer_reset()to properly handle all session states and integrate with the reset completion trackingQuoted 3 lines
Open questions / areas for review:
- Is debugfs the right interface, or should this be a mount option / sysfs attribute / netlink command?Recently, I had short discussion with Greg Kroah-Hartman. He was completely against of using sysfs for transferring commands from user-space to kernel- space. So, we could have troubles of using sysfs for this. And
/sys/kernel/debug/sounds like completely wrong place. Because, this is not debug feature or option. You are suggesting this as a regular feature for production.Maybe, we can consider eBPF here?
Quoted 3 lines
- The request gating in
ceph_mdsc_submit_request()is best-effort (no lock serialization) to avoid penalizing the normal path. Is this acceptable?So, we have "MDS sessions become stuck or hung" and we are trying to submit another request. Is it sane enough? We already have a dead session. :)
Quoted 2 lines
- Should the 60s reconnect timeout and 120s blocked-request timeout be configurable (e.g. via mount options)?
I think we already have some timeout option in the mount options. Are you suggesting yet another one?
Quoted 2 lines
-
mds_peer_reset()rework (patch 4) is substantial -- would reviewers prefer it split further?Do you mean patch 3 or 4? Because, patch 3 is huge in size.
Thanks,
Slava.Quoted 16 lines
Alex Markuze (4):
ceph: convert inode flags to named bit positions
ceph: add bounded timeout and diagnostics towait_caps_flush()
ceph: implement manual client session reset via debugfs
ceph: reworkmds_peer_reset()for robust session recoveryfs/ceph/caps.c | 7 + fs/ceph/debugfs.c | 171 ++++++++++- fs/ceph/locks.c | 24 +- fs/ceph/mds_client.c | 577 ++++++++++++++++++++++++++++++++++-- fs/ceph/mds_client.h | 33 +++ fs/ceph/super.h | 60 ++-- include/trace/events/ceph.h | 60 ++++ 7 files changed, 879 insertions(+), 53 deletions(-)
Quoted 10 lines · Alex Markuze
Quoted 4 lines
What do you mean by "reason text"? Usually, it should be some command. Do you mean that any string will trigger the reset? Is it good approach? What if a user sends something by mistake or any malicious garbage? Potentially, it could be security breach.
The string is an optional free-form operator note that gets logged and recorded in the status output for post-mortem diagnostics (e.g. "RHBZ#12345" or "mds0 stuck after failover"). Any write to the trigger file initiates the reset -- the content is not interpreted as a command.
First of all, people are lazy and nobody like to compose any string. So, you will have completely useless strings at the end of the day ("1234", "dgdgdffgd", or something like this). This string could be really confusing point because everybody will expect to have some clear command that triggers the reset. I expect that end-users will be confused by likewise "free-form operator".
Quoted 32 lines
The input length is capped at
CEPH_CLIENT_RESET_REASON_LEN - 1(63 bytes) viamin_t()beforecopy_from_user(), then null-terminated andstrim()'d. Anything longer is silently truncated -- no overflow is possible.Regarding security: the trigger file is created with mode 0200 (write-only, owner-only), and debugfs itself is typically mounted root-only. So the write is restricted to a privileged operator, same as any other debugfs knob. That said, I agree the interface question is open -- see below.
Quoted 2 lines
This "reset/status" sounds slightly ambiguous. Is it status of reset process? If we didn't request the reset, then what this status means?
It is the status of the reset subsystem. When no reset has been requested, it shows the idle state:
``` in_progress: no trigger_count: 0 success_count: 0 failure_count: 0 last_start_ms_ago: (never) last_finish_ms_ago: (never) last_errno: 0 last_reason: (none) inject_error_pending: no pending_reconnects: 0 blocked_requests: 0 ```
Quoted 3 lines
Happy to rename it to something less ambiguous, maybe
reset/reset_statusor just moving the counters into the existing top-levelstatusfile. Open to suggestions.
Frankly speaking, I expected to see something like:
/sys/fs/ceph/<info>
And if we are talking about MDS sessions, then, maybe, we need to have MDS node and some status there:
/sys/fs/ceph/<fsid>/mds/status
Quoted 19 lines
Quoted 9 lines
Recently, I had short discussion with Greg Kroah-Hartman. He was completely against of using sysfs for transferring commands from user-space to kernel- space. So, we could have troubles of using sysfs for this. And
/sys/kernel/debug/sounds like completely wrong place. Because, this is not debug feature or option. You are suggesting this as a regular feature for production.Maybe, we can consider eBPF here?
Yeah, debugfs is not the right place for a production feature.
The debugfs interface is there for now as a development/testing trigger while the core reset mechanism is reviewed. The longer-term goal is automated recovery: the client would detect stuck/hung sessions and trigger the reset internally without operator intervention. Once that's in place, the manual trigger becomes a fallback rather than the primary interface.
Quoted 7 lines
For production manual triggering (before automated recovery is ready), we can consider other approaches, e.g., ioctl, netlink, or extending the existing
recover_session=cleanpath. That path already handles automatic recovery from blocklisting viamaybe_recover_session()/ceph_force_reconnect(); the manual reset solves a related but different problem (sessions stuck without blocklisting), so the machinery could potentially be unified.
The ioctl sounds like more reasonable way. However, this /sys/../<trigger_reset> sounds like an easy way to initiates the reset from command line.
Quoted 24 lines
Quoted 3 lines
So, we have "MDS sessions become stuck or hung" and we are trying to submit another request. Is it sane enough? We already have a dead session. :)
The gating does not submit requests to the dead session, it does the opposite. When a reset is in progress,
ceph_mdsc_wait_for_reset()blocks new incoming requests (and new lock acquisitions) until the reset completes and sessions are re-established. Only then do the blocked requests proceed through the normal__do_request()path, which will find the freshly reconnected sessions.The "best-effort" note refers to the fact that we don't take a lock on the hot path, a request could slip past the check in the narrow window before
in_progressis set. That's acceptable because such a request would either complete normally on the still-alive session or fail and be retried by the caller after the reset.Quoted 2 lines
I think we already have some timeout option in the mount options. Are you suggesting yet another one?
Fair point. The existing
mount_timeoutcontrols how long mount and reconnect operations wait. The two timeouts here are:
Quoted 8 lines
- 60s for the reset work to wait for session reconnects to complete
- 120s for blocked requests to wait for the reset to finishI think these can stay as compile-time constants (
CEPH_CLIENT_RESET_TIMEOUT_SEC/CEPH_CLIENT_RESET_WAIT_TIMEOUT_SEC) rather than becoming mount options. They're operational bounds for a rare manual operation, not something an admin would typically need to tune. If reviewers feel otherwise I can tie them tomount_timeout.
Potentially, we could have both options available.
Quoted 13 lines
Quoted 2 lines
Do you mean patch 3 or 4? Because, patch 3 is huge in size.
You're right, patch 3 is the large one (~700 lines). I can split it further if that helps review. A natural split would be:
- 3a:
ceph_client_reset_statestruct, init/destroy, andceph_mdsc_wait_for_reset()blocking infrastructure
- 3b:ceph_mdsc_reset_workfn(),send_mds_reconnect()changes, and session completion tracking
- 3c: debugfs interface (trigger, status,inject_error)
- 3d: tracepoints
Quoted 2 lines
Let me know if that granularity makes sense or if you'd prefer a different split.
I think it makes sense.
Thanks,
Slava.