Skip to contentSkip to conversation

ceph: flush all the caps release when syncing the whole filesystem

PATCH In review [email protected] 2 participants 7 messages Jul 30, 2024 – Sep 27, 2024 Ceph client

lore
Share & tools
lore
#0 lore raw

v2 cover ceph: flush all the caps release when syncing the whole filesystem

From: Xiubo Li <[email protected]>

V2:
- missed the first patch in V1.

Xiubo Li (2):
ceph: rename ceph_flush_cap_releases to
ceph_flush_session_cap_releases
ceph: flush all the caps release when syncing the whole filesystem

 fs/ceph/caps.c       | 24 +++++++++++++++++++++++-
 fs/ceph/mds_client.c | 11 ++++++-----
 fs/ceph/mds_client.h |  4 ++--
 fs/ceph/super.c      |  1 +
 fs/ceph/super.h      |  1 +
 5 files changed, 33 insertions(+), 8 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 1/2 ceph: rename ceph_flush_cap_releases to ceph_flush_session_cap_releases

From: Xiubo Li <[email protected]>

Prepare for adding a helper to flush the cap releases for all sessions.

URL: https://tracker.ceph.com/issues/67221

---
 fs/ceph/caps.c       |  2 +-
 fs/ceph/mds_client.c | 10 +++++-----
 fs/ceph/mds_client.h |  4 ++--
 3 files changed, 8 insertions(+), 8 deletions(-)
fs/ceph/caps.c +1 -1
index 28ab4d42fde8..c09add6d6516 100644
@@ -4630,7 +4630,7 @@ void ceph_handle_caps(struct ceph_mds_session *session,
 		__ceph_queue_cap_release(session, cap);
 		spin_unlock(&session->s_cap_lock);
 	}
-	ceph_flush_cap_releases(mdsc, session);
+	ceph_flush_session_cap_releases(mdsc, session);
 	goto done;
 
 bad:
fs/ceph/mds_client.c +5 -5
index b7fcaa6e28b4..86d0148819b0 100644
@@ -2266,7 +2266,7 @@ int ceph_trim_caps(struct ceph_mds_client *mdsc,
 		      trim_caps - remaining);
 	}
 
-	ceph_flush_cap_releases(mdsc, session);
+	ceph_flush_session_cap_releases(mdsc, session);
 	return 0;
 }
 
@@ -2448,7 +2448,7 @@ static void ceph_cap_release_work(struct work_struct *work)
 	ceph_put_mds_session(session);
 }
 
-void ceph_flush_cap_releases(struct ceph_mds_client *mdsc,
+void ceph_flush_session_cap_releases(struct ceph_mds_client *mdsc,
 		             struct ceph_mds_session *session)
 {
 	struct ceph_client *cl = mdsc->fsc->client;
@@ -2475,7 +2475,7 @@ void __ceph_queue_cap_release(struct ceph_mds_session *session,
 	session->s_num_cap_releases++;
 
 	if (!(session->s_num_cap_releases % CEPH_CAPS_PER_RELEASE))
-		ceph_flush_cap_releases(session->s_mdsc, session);
+		ceph_flush_session_cap_releases(session->s_mdsc, session);
 }
 
 static void ceph_cap_reclaim_work(struct work_struct *work)
@@ -4368,7 +4368,7 @@ static void handle_session(struct ceph_mds_session *session,
 		/* flush cap releases */
 		spin_lock(&session->s_cap_lock);
 		if (session->s_num_cap_releases)
-			ceph_flush_cap_releases(mdsc, session);
+			ceph_flush_session_cap_releases(mdsc, session);
 		spin_unlock(&session->s_cap_lock);
 
 		send_flushmsg_ack(mdsc, session, seq);
@@ -5474,7 +5474,7 @@ static void delayed_work(struct work_struct *work)
 		}
 		mutex_unlock(&mdsc->mutex);
 
-		ceph_flush_cap_releases(mdsc, s);
+		ceph_flush_session_cap_releases(mdsc, s);
 
 		mutex_lock(&s->s_mutex);
 		if (renew_caps)
fs/ceph/mds_client.h +2 -2
index 9bcc7f181bfe..6bff2661b202 100644
@@ -602,8 +602,8 @@ extern void ceph_mdsc_iterate_sessions(struct ceph_mds_client *mdsc,
 extern struct ceph_msg *ceph_create_session_msg(u32 op, u64 seq);
 extern void __ceph_queue_cap_release(struct ceph_mds_session *session,
 				    struct ceph_cap *cap);
-extern void ceph_flush_cap_releases(struct ceph_mds_client *mdsc,
-				    struct ceph_mds_session *session);
+extern void ceph_flush_session_cap_releases(struct ceph_mds_client *mdsc,
+					    struct ceph_mds_session *session);
 extern void ceph_queue_cap_reclaim_work(struct ceph_mds_client *mdsc);
 extern void ceph_reclaim_caps_nr(struct ceph_mds_client *mdsc, int nr);
 extern void ceph_queue_cap_unlink_work(struct ceph_mds_client *mdsc);
Signature · 1 line
2.43.0
#2 lore raw

PATCH v2 2/2 ceph: flush all the caps release when syncing the whole filesystem

In reply to [email protected]

From: Xiubo Li <[email protected]>

We have hit a race between cap releases and cap revoke request that will cause the check_caps() to miss sending a cap revoke ack to MDS. And the client will depend on the cap release to release that revoking caps, which could be delayed for some unknown reasons.

In Kclient we have figured out the RCA about race and we need a way to explictly trigger this manually could help to get rid of the caps revoke stuck issue.

URL: https://tracker.ceph.com/issues/67221

---
 fs/ceph/caps.c       | 22 ++++++++++++++++++++++
 fs/ceph/mds_client.c |  1 +
 fs/ceph/super.c      |  1 +
 fs/ceph/super.h      |  1 +
 4 files changed, 25 insertions(+)
fs/ceph/caps.c +22 -0
index c09add6d6516..a0a39243aeb3 100644
@@ -4729,6 +4729,28 @@ void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc)
 	ceph_mdsc_iterate_sessions(mdsc, flush_dirty_session_caps, true);
 }
 
+/*
+ * Flush all cap releases to the mds
+ */
+static void flush_cap_releases(struct ceph_mds_session *s)
+{
+	struct ceph_mds_client *mdsc = s->s_mdsc;
+	struct ceph_client *cl = mdsc->fsc->client;
+
+	doutc(cl, "begin\n");
+	spin_lock(&s->s_cap_lock);
+	if (s->s_num_cap_releases)
+		ceph_flush_session_cap_releases(mdsc, s);
+	spin_unlock(&s->s_cap_lock);
+	doutc(cl, "done\n");
+
+}
+
+void ceph_flush_cap_releases(struct ceph_mds_client *mdsc)
+{
+	ceph_mdsc_iterate_sessions(mdsc, flush_cap_releases, true);
+}
+
 void __ceph_touch_fmode(struct ceph_inode_info *ci,
 			struct ceph_mds_client *mdsc, int fmode)
 {
fs/ceph/mds_client.c +1 -0
index 86d0148819b0..fc563b59959a 100644
@@ -5904,6 +5904,7 @@ void ceph_mdsc_sync(struct ceph_mds_client *mdsc)
 	want_tid = mdsc->last_tid;
 	mutex_unlock(&mdsc->mutex);
 
+	ceph_flush_cap_releases(mdsc);
 	ceph_flush_dirty_caps(mdsc);
 	spin_lock(&mdsc->cap_dirty_lock);
 	want_flush = mdsc->last_cap_flush_tid;
fs/ceph/super.c +1 -0
index f489b3e12429..0a1215b4f0ba 100644
@@ -126,6 +126,7 @@ static int ceph_sync_fs(struct super_block *sb, int wait)
 	if (!wait) {
 		doutc(cl, "(non-blocking)\n");
 		ceph_flush_dirty_caps(fsc->mdsc);
+		ceph_flush_cap_releases(fsc->mdsc);
 		doutc(cl, "(non-blocking) done\n");
 		return 0;
 	}
fs/ceph/super.h +1 -0
index 831e8ec4d5da..5645121337cf 100644
@@ -1273,6 +1273,7 @@ extern bool __ceph_should_report_size(struct ceph_inode_info *ci);
 extern void ceph_check_caps(struct ceph_inode_info *ci, int flags);
 extern unsigned long ceph_check_delayed_caps(struct ceph_mds_client *mdsc);
 extern void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc);
+extern void ceph_flush_cap_releases(struct ceph_mds_client *mdsc);
 extern int  ceph_drop_caps_for_unlink(struct inode *inode);
 extern int ceph_encode_inode_release(void **p, struct inode *inode,
 				     int mds, int drop, int unless, int force);
Signature · 1 line
2.43.0
maintainer
#3 lore raw
Quoted 71 lines · On Tue, Jul 30, 2024 at 7:41 AM <[email protected]> wrote:

From: Xiubo Li <[email protected]>

We have hit a race between cap releases and cap revoke request that will cause the check_caps() to miss sending a cap revoke ack to MDS. And the client will depend on the cap release to release that revoking caps, which could be delayed for some unknown reasons.

In Kclient we have figured out the RCA about race and we need a way to explictly trigger this manually could help to get rid of the caps revoke stuck issue.

URL: https://tracker.ceph.com/issues/67221

---
 fs/ceph/caps.c       | 22 ++++++++++++++++++++++
 fs/ceph/mds_client.c |  1 +
 fs/ceph/super.c      |  1 +
 fs/ceph/super.h      |  1 +
 4 files changed, 25 insertions(+)
fs/ceph/caps.c +22 -0
index c09add6d6516..a0a39243aeb3 100644
@@ -4729,6 +4729,28 @@ void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc)
        ceph_mdsc_iterate_sessions(mdsc, flush_dirty_session_caps, true);
 }
 
+/*
+ * Flush all cap releases to the mds
+ */
+static void flush_cap_releases(struct ceph_mds_session *s)
+{
+       struct ceph_mds_client *mdsc = s->s_mdsc;
+       struct ceph_client *cl = mdsc->fsc->client;
+
+       doutc(cl, "begin\n");
+       spin_lock(&s->s_cap_lock);
+       if (s->s_num_cap_releases)
+               ceph_flush_session_cap_releases(mdsc, s);
+       spin_unlock(&s->s_cap_lock);
+       doutc(cl, "done\n");
+
+}
+
+void ceph_flush_cap_releases(struct ceph_mds_client *mdsc)
+{
+       ceph_mdsc_iterate_sessions(mdsc, flush_cap_releases, true);
+}
+
 void __ceph_touch_fmode(struct ceph_inode_info *ci,
                        struct ceph_mds_client *mdsc, int fmode)
 {
fs/ceph/mds_client.c +1 -0
index 86d0148819b0..fc563b59959a 100644
@@ -5904,6 +5904,7 @@ void ceph_mdsc_sync(struct ceph_mds_client *mdsc)
        want_tid = mdsc->last_tid;
        mutex_unlock(&mdsc->mutex);
 
+       ceph_flush_cap_releases(mdsc);
        ceph_flush_dirty_caps(mdsc);
        spin_lock(&mdsc->cap_dirty_lock);
        want_flush = mdsc->last_cap_flush_tid;
fs/ceph/super.c +0 -0
index f489b3e12429..0a1215b4f0ba 100644

fs/ceph/super.c static int ceph_sync_fs(struct super_block *sb, int wait) · line 129

Quoted 4 lines
fs/ceph/super.c +1 -0
@@ -126,6 +126,7 @@ static int ceph_sync_fs(struct super_block *sb, int wait)
        if (!wait) {
                doutc(cl, "(non-blocking)\n");
                ceph_flush_dirty_caps(fsc->mdsc);
+               ceph_flush_cap_releases(fsc->mdsc);

Hi Xiubo,

Is there a significance to flushing cap releases before dirty caps on the blocking path and doing it vice versa (i.e. flushing cap releases after dirty caps) on the non-blocking path?

Thanks,

Ilya

author
#4 lore raw
Quoted 77 lines · Ilya Dryomov
Quoted 70 lines · On Tue, Jul 30, 2024 at 7:41 AM <[email protected]> wrote:

From: Xiubo Li <[email protected]>

We have hit a race between cap releases and cap revoke request that will cause the check_caps() to miss sending a cap revoke ack to MDS. And the client will depend on the cap release to release that revoking caps, which could be delayed for some unknown reasons.

In Kclient we have figured out the RCA about race and we need a way to explictly trigger this manually could help to get rid of the caps revoke stuck issue.

URL: https://tracker.ceph.com/issues/67221

---
  fs/ceph/caps.c       | 22 ++++++++++++++++++++++
  fs/ceph/mds_client.c |  1 +
  fs/ceph/super.c      |  1 +
  fs/ceph/super.h      |  1 +
  4 files changed, 25 insertions(+)
fs/ceph/caps.c +22 -0
index c09add6d6516..a0a39243aeb3 100644
@@ -4729,6 +4729,28 @@ void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc)
         ceph_mdsc_iterate_sessions(mdsc, flush_dirty_session_caps, true);
  }
 
+/*
+ * Flush all cap releases to the mds
+ */
+static void flush_cap_releases(struct ceph_mds_session *s)
+{
+       struct ceph_mds_client *mdsc = s->s_mdsc;
+       struct ceph_client *cl = mdsc->fsc->client;
+
+       doutc(cl, "begin\n");
+       spin_lock(&s->s_cap_lock);
+       if (s->s_num_cap_releases)
+               ceph_flush_session_cap_releases(mdsc, s);
+       spin_unlock(&s->s_cap_lock);
+       doutc(cl, "done\n");
+
+}
+
+void ceph_flush_cap_releases(struct ceph_mds_client *mdsc)
+{
+       ceph_mdsc_iterate_sessions(mdsc, flush_cap_releases, true);
+}
+
  void __ceph_touch_fmode(struct ceph_inode_info *ci,
                         struct ceph_mds_client *mdsc, int fmode)
  {
fs/ceph/mds_client.c +1 -0
index 86d0148819b0..fc563b59959a 100644
@@ -5904,6 +5904,7 @@ void ceph_mdsc_sync(struct ceph_mds_client *mdsc)
         want_tid = mdsc->last_tid;
         mutex_unlock(&mdsc->mutex);
 
+       ceph_flush_cap_releases(mdsc);
         ceph_flush_dirty_caps(mdsc);
         spin_lock(&mdsc->cap_dirty_lock);
         want_flush = mdsc->last_cap_flush_tid;
fs/ceph/super.c +0 -0
index f489b3e12429..0a1215b4f0ba 100644

fs/ceph/super.c static int ceph_sync_fs(struct super_block *sb, int wait) · line 129

Quoted 4 lines
fs/ceph/super.c +1 -0
@@ -126,6 +126,7 @@ static int ceph_sync_fs(struct super_block *sb, int wait)
         if (!wait) {
                 doutc(cl, "(non-blocking)\n");
                 ceph_flush_dirty_caps(fsc->mdsc);
+               ceph_flush_cap_releases(fsc->mdsc);

Hi Xiubo,

Quoted 3 lines

Is there a significance to flushing cap releases before dirty caps on the blocking path and doing it vice versa (i.e. flushing cap releases after dirty caps) on the non-blocking path?

Hi Ilya,

The dirty caps and the cap releases are not related.

If caps are dirty it should be in the dirty list anyway in theory. Else when the file is closed or inode is released will it be in the release lists.

Thanks

- Xiubo

Quoted 4 lines

Thanks,

Ilya

maintainer
#5 lore raw
Quoted 84 lines · Xiubo Li
Quoted 77 lines · Ilya Dryomov
Quoted 70 lines · On Tue, Jul 30, 2024 at 7:41 AM <[email protected]> wrote:

From: Xiubo Li <[email protected]>

We have hit a race between cap releases and cap revoke request that will cause the check_caps() to miss sending a cap revoke ack to MDS. And the client will depend on the cap release to release that revoking caps, which could be delayed for some unknown reasons.

In Kclient we have figured out the RCA about race and we need a way to explictly trigger this manually could help to get rid of the caps revoke stuck issue.

URL: https://tracker.ceph.com/issues/67221

---
  fs/ceph/caps.c       | 22 ++++++++++++++++++++++
  fs/ceph/mds_client.c |  1 +
  fs/ceph/super.c      |  1 +
  fs/ceph/super.h      |  1 +
  4 files changed, 25 insertions(+)
fs/ceph/caps.c +22 -0
index c09add6d6516..a0a39243aeb3 100644
@@ -4729,6 +4729,28 @@ void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc)
         ceph_mdsc_iterate_sessions(mdsc, flush_dirty_session_caps, true);
  }
 
+/*
+ * Flush all cap releases to the mds
+ */
+static void flush_cap_releases(struct ceph_mds_session *s)
+{
+       struct ceph_mds_client *mdsc = s->s_mdsc;
+       struct ceph_client *cl = mdsc->fsc->client;
+
+       doutc(cl, "begin\n");
+       spin_lock(&s->s_cap_lock);
+       if (s->s_num_cap_releases)
+               ceph_flush_session_cap_releases(mdsc, s);
+       spin_unlock(&s->s_cap_lock);
+       doutc(cl, "done\n");
+
+}
+
+void ceph_flush_cap_releases(struct ceph_mds_client *mdsc)
+{
+       ceph_mdsc_iterate_sessions(mdsc, flush_cap_releases, true);
+}
+
  void __ceph_touch_fmode(struct ceph_inode_info *ci,
                         struct ceph_mds_client *mdsc, int fmode)
  {
fs/ceph/mds_client.c +1 -0
index 86d0148819b0..fc563b59959a 100644
@@ -5904,6 +5904,7 @@ void ceph_mdsc_sync(struct ceph_mds_client *mdsc)
         want_tid = mdsc->last_tid;
         mutex_unlock(&mdsc->mutex);
 
+       ceph_flush_cap_releases(mdsc);
         ceph_flush_dirty_caps(mdsc);
         spin_lock(&mdsc->cap_dirty_lock);
         want_flush = mdsc->last_cap_flush_tid;
fs/ceph/super.c +0 -0
index f489b3e12429..0a1215b4f0ba 100644

fs/ceph/super.c static int ceph_sync_fs(struct super_block *sb, int wait) · line 129

Quoted 4 lines
fs/ceph/super.c +1 -0
@@ -126,6 +126,7 @@ static int ceph_sync_fs(struct super_block *sb, int wait)
         if (!wait) {
                 doutc(cl, "(non-blocking)\n");
                 ceph_flush_dirty_caps(fsc->mdsc);
+               ceph_flush_cap_releases(fsc->mdsc);

Hi Xiubo,

Quoted 3 lines

Is there a significance to flushing cap releases before dirty caps on the blocking path and doing it vice versa (i.e. flushing cap releases after dirty caps) on the non-blocking path?

Quoted 7 lines

Hi Ilya,

The dirty caps and the cap releases are not related.

If caps are dirty it should be in the dirty list anyway in theory. Else when the file is closed or inode is released will it be in the release lists.

So doing

    ceph_flush_dirty_caps(mdsc);
    ceph_flush_cap_releases(mdsc);

in both cases just so that it's consistent is fine, right?

Thanks,

Ilya

author
#6 lore raw
Quoted 90 lines · Ilya Dryomov
Quoted 82 lines · Xiubo Li
Quoted 77 lines · Ilya Dryomov
Quoted 70 lines · On Tue, Jul 30, 2024 at 7:41 AM <[email protected]> wrote:

From: Xiubo Li <[email protected]>

We have hit a race between cap releases and cap revoke request that will cause the check_caps() to miss sending a cap revoke ack to MDS. And the client will depend on the cap release to release that revoking caps, which could be delayed for some unknown reasons.

In Kclient we have figured out the RCA about race and we need a way to explictly trigger this manually could help to get rid of the caps revoke stuck issue.

URL: https://tracker.ceph.com/issues/67221

---
   fs/ceph/caps.c       | 22 ++++++++++++++++++++++
   fs/ceph/mds_client.c |  1 +
   fs/ceph/super.c      |  1 +
   fs/ceph/super.h      |  1 +
   4 files changed, 25 insertions(+)
fs/ceph/caps.c +22 -0
index c09add6d6516..a0a39243aeb3 100644
@@ -4729,6 +4729,28 @@ void ceph_flush_dirty_caps(struct ceph_mds_client *mdsc)
          ceph_mdsc_iterate_sessions(mdsc, flush_dirty_session_caps, true);
   }
 
+/*
+ * Flush all cap releases to the mds
+ */
+static void flush_cap_releases(struct ceph_mds_session *s)
+{
+       struct ceph_mds_client *mdsc = s->s_mdsc;
+       struct ceph_client *cl = mdsc->fsc->client;
+
+       doutc(cl, "begin\n");
+       spin_lock(&s->s_cap_lock);
+       if (s->s_num_cap_releases)
+               ceph_flush_session_cap_releases(mdsc, s);
+       spin_unlock(&s->s_cap_lock);
+       doutc(cl, "done\n");
+
+}
+
+void ceph_flush_cap_releases(struct ceph_mds_client *mdsc)
+{
+       ceph_mdsc_iterate_sessions(mdsc, flush_cap_releases, true);
+}
+
   void __ceph_touch_fmode(struct ceph_inode_info *ci,
                          struct ceph_mds_client *mdsc, int fmode)
   {
fs/ceph/mds_client.c +1 -0
index 86d0148819b0..fc563b59959a 100644
@@ -5904,6 +5904,7 @@ void ceph_mdsc_sync(struct ceph_mds_client *mdsc)
          want_tid = mdsc->last_tid;
          mutex_unlock(&mdsc->mutex);
 
+       ceph_flush_cap_releases(mdsc);
          ceph_flush_dirty_caps(mdsc);
          spin_lock(&mdsc->cap_dirty_lock);
          want_flush = mdsc->last_cap_flush_tid;
fs/ceph/super.c +0 -0
index f489b3e12429..0a1215b4f0ba 100644

fs/ceph/super.c static int ceph_sync_fs(struct super_block *sb, int wait) · line 129

Quoted 4 lines
fs/ceph/super.c +1 -0
@@ -126,6 +126,7 @@ static int ceph_sync_fs(struct super_block *sb, int wait)
          if (!wait) {
                  doutc(cl, "(non-blocking)\n");
                  ceph_flush_dirty_caps(fsc->mdsc);
+               ceph_flush_cap_releases(fsc->mdsc);

Hi Xiubo,

Quoted 3 lines

Is there a significance to flushing cap releases before dirty caps on the blocking path and doing it vice versa (i.e. flushing cap releases after dirty caps) on the non-blocking path?

Quoted 7 lines

Hi Ilya,

The dirty caps and the cap releases are not related.

If caps are dirty it should be in the dirty list anyway in theory. Else when the file is closed or inode is released will it be in the release lists.

Quoted 6 lines

So doing

     ceph_flush_dirty_caps(mdsc);
     ceph_flush_cap_releases(mdsc);

in both cases just so that it's consistent is fine, right?

Yeah.

Quoted 4 lines

Thanks,

Ilya