Skip to contentSkip to conversation

ceph: send opened files/pinned caps/opened inodes metrics to MDS daemon

PATCH Superseded [email protected] 2 participants 7 messages Nov 26, 2020 – Mar 24, 2021 Ceph client

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ceph: send opened files/pinned caps/opened inodes metrics to MDS daemon

From: Xiubo Li <[email protected]>

For the old ceph version, if it received this metric message containing the send opened files/pinned caps/opened inodes metric info, it will just ignore them.

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

---
 fs/ceph/metric.c | 38 +++++++++++++++++++++++++++++++++++++-
 fs/ceph/metric.h | 44 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 80 insertions(+), 2 deletions(-)
fs/ceph/metric.c +37 -1
index 5ec94bd4c1de..306bd599d940 100644
@@ -17,6 +17,9 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 	struct ceph_metric_write_latency *write;
 	struct ceph_metric_metadata_latency *meta;
 	struct ceph_metric_dlease *dlease;
+	struct ceph_opened_files *files;
+	struct ceph_pinned_icaps *icaps;
+	struct ceph_opened_inodes *inodes;
 	struct ceph_client_metric *m = &mdsc->metric;
 	u64 nr_caps = atomic64_read(&m->total_caps);
 	struct ceph_msg *msg;
@@ -26,7 +29,8 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 	s32 len;
 
 	len = sizeof(*head) + sizeof(*cap) + sizeof(*read) + sizeof(*write)
-	      + sizeof(*meta) + sizeof(*dlease);
+	      + sizeof(*meta) + sizeof(*dlease) + sizeof(files) + sizeof(icaps)
+	      + sizeof(inodes);
 
 	msg = ceph_msg_new(CEPH_MSG_CLIENT_METRICS, len, GFP_NOFS, true);
 	if (!msg) {
@@ -95,6 +99,38 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 	dlease->total = cpu_to_le64(atomic64_read(&m->total_dentries));
 	items++;
 
+	sum = percpu_counter_sum(&m->total_inodes);
+
+	/* encode the opened files metric */
+	files = (struct ceph_opened_files *)(dlease + 1);
+	files->type = cpu_to_le32(CLIENT_METRIC_TYPE_OPENED_FILES);
+	files->ver = 1;
+	files->compat = 1;
+	files->data_len = cpu_to_le32(sizeof(*files) - 10);
+	files->opened_files = cpu_to_le64(atomic64_read(&m->opened_files));
+	files->total = cpu_to_le64(sum);
+	items++;
+
+	/* encode the pinned icaps metric */
+	icaps = (struct ceph_pinned_icaps *)(files + 1);
+	icaps->type = cpu_to_le32(CLIENT_METRIC_TYPE_PINNED_ICAPS);
+	icaps->ver = 1;
+	icaps->compat = 1;
+	icaps->data_len = cpu_to_le32(sizeof(*icaps) - 10);
+	icaps->pinned_icaps = cpu_to_le64(nr_caps);
+	icaps->total = cpu_to_le64(sum);
+	items++;
+
+	/* encode the opened inodes metric */
+	inodes = (struct ceph_opened_inodes *)(icaps + 1);
+	inodes->type = cpu_to_le32(CLIENT_METRIC_TYPE_OPENED_INODES);
+	inodes->ver = 1;
+	inodes->compat = 1;
+	inodes->data_len = cpu_to_le32(sizeof(*inodes) - 10);
+	inodes->opened_inodes = cpu_to_le64(percpu_counter_sum(&m->opened_inodes));
+	inodes->total = cpu_to_le64(sum);
+	items++;
+
 	put_unaligned_le32(items, &head->num);
 	msg->front.iov_len = len;
 	msg->hdr.version = cpu_to_le16(1);
fs/ceph/metric.h +43 -1

63 lines not on this page · raw message

Signature · 1 line
2.27.0
author
#1 lore raw

Hi Jeff,

Ping.

The MDS side patch[1] have been merged.

[1] https://github.com/ceph/ceph/pull/37945

Thanks

Quoted 146 lines · On 2020/11/26 11:47, [email protected] wrote:

From: Xiubo Li <[email protected]>

For the old ceph version, if it received this metric message containing the send opened files/pinned caps/opened inodes metric info, it will just ignore them.

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

---
  fs/ceph/metric.c | 38 +++++++++++++++++++++++++++++++++++++-
  fs/ceph/metric.h | 44 +++++++++++++++++++++++++++++++++++++++++++-
  2 files changed, 80 insertions(+), 2 deletions(-)
fs/ceph/metric.c +37 -1
index 5ec94bd4c1de..306bd599d940 100644
@@ -17,6 +17,9 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
  	struct ceph_metric_write_latency *write;
  	struct ceph_metric_metadata_latency *meta;
  	struct ceph_metric_dlease *dlease;
+	struct ceph_opened_files *files;
+	struct ceph_pinned_icaps *icaps;
+	struct ceph_opened_inodes *inodes;
  	struct ceph_client_metric *m = &mdsc->metric;
  	u64 nr_caps = atomic64_read(&m->total_caps);
  	struct ceph_msg *msg;
@@ -26,7 +29,8 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
  	s32 len;
 
  	len = sizeof(*head) + sizeof(*cap) + sizeof(*read) + sizeof(*write)
-	      + sizeof(*meta) + sizeof(*dlease);
+	      + sizeof(*meta) + sizeof(*dlease) + sizeof(files) + sizeof(icaps)
+	      + sizeof(inodes);
 
  	msg = ceph_msg_new(CEPH_MSG_CLIENT_METRICS, len, GFP_NOFS, true);
  	if (!msg) {
@@ -95,6 +99,38 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
  	dlease->total = cpu_to_le64(atomic64_read(&m->total_dentries));
  	items++;
 
+	sum = percpu_counter_sum(&m->total_inodes);
+
+	/* encode the opened files metric */
+	files = (struct ceph_opened_files *)(dlease + 1);
+	files->type = cpu_to_le32(CLIENT_METRIC_TYPE_OPENED_FILES);
+	files->ver = 1;
+	files->compat = 1;
+	files->data_len = cpu_to_le32(sizeof(*files) - 10);
+	files->opened_files = cpu_to_le64(atomic64_read(&m->opened_files));
+	files->total = cpu_to_le64(sum);
+	items++;
+
+	/* encode the pinned icaps metric */
+	icaps = (struct ceph_pinned_icaps *)(files + 1);
+	icaps->type = cpu_to_le32(CLIENT_METRIC_TYPE_PINNED_ICAPS);
+	icaps->ver = 1;
+	icaps->compat = 1;
+	icaps->data_len = cpu_to_le32(sizeof(*icaps) - 10);
+	icaps->pinned_icaps = cpu_to_le64(nr_caps);
+	icaps->total = cpu_to_le64(sum);
+	items++;
+
+	/* encode the opened inodes metric */
+	inodes = (struct ceph_opened_inodes *)(icaps + 1);
+	inodes->type = cpu_to_le32(CLIENT_METRIC_TYPE_OPENED_INODES);
+	inodes->ver = 1;
+	inodes->compat = 1;
+	inodes->data_len = cpu_to_le32(sizeof(*inodes) - 10);
+	inodes->opened_inodes = cpu_to_le64(percpu_counter_sum(&m->opened_inodes));
+	inodes->total = cpu_to_le64(sum);
+	items++;
+
  	put_unaligned_le32(items, &head->num);
  	msg->front.iov_len = len;
  	msg->hdr.version = cpu_to_le16(1);
fs/ceph/metric.h +43 -1
index af6038ff39d4..4ceb462135d7 100644
@@ -14,8 +14,11 @@ enum ceph_metric_type {
  	CLIENT_METRIC_TYPE_WRITE_LATENCY,
  	CLIENT_METRIC_TYPE_METADATA_LATENCY,
  	CLIENT_METRIC_TYPE_DENTRY_LEASE,
+	CLIENT_METRIC_TYPE_OPENED_FILES,
+	CLIENT_METRIC_TYPE_PINNED_ICAPS,
+	CLIENT_METRIC_TYPE_OPENED_INODES,
 
-	CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_DENTRY_LEASE,
+	CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_OPENED_INODES,
  };
 
  /*
@@ -28,6 +31,9 @@ enum ceph_metric_type {
  	CLIENT_METRIC_TYPE_WRITE_LATENCY,	\
  	CLIENT_METRIC_TYPE_METADATA_LATENCY,	\
  	CLIENT_METRIC_TYPE_DENTRY_LEASE,	\
+	CLIENT_METRIC_TYPE_OPENED_FILES,	\
+	CLIENT_METRIC_TYPE_PINNED_ICAPS,	\
+	CLIENT_METRIC_TYPE_OPENED_INODES,	\
  						\
  	CLIENT_METRIC_TYPE_MAX,			\
  }
@@ -94,6 +100,42 @@ struct ceph_metric_dlease {
  	__le64 total;
  } __packed;
 
+/* metric opened files header */
+struct ceph_opened_files {
+	__le32 type;     /* ceph metric type */
+
+	__u8  ver;
+	__u8  compat;
+
+	__le32 data_len; /* length of sizeof(opened_files + total) */
+	__le64 opened_files;
+	__le64 total;
+} __packed;
+
+/* metric pinned i_caps header */
+struct ceph_pinned_icaps {
+	__le32 type;     /* ceph metric type */
+
+	__u8  ver;
+	__u8  compat;
+
+	__le32 data_len; /* length of sizeof(pinned_icaps + total) */
+	__le64 pinned_icaps;
+	__le64 total;
+} __packed;
+
+/* metric opened inodes header */
+struct ceph_opened_inodes {
+	__le32 type;     /* ceph metric type */
+
+	__u8  ver;
+	__u8  compat;
+
+	__le32 data_len; /* length of sizeof(opened_inodes + total) */
+	__le64 opened_inodes;
+	__le64 total;
+} __packed;
+
  struct ceph_metric_head {
  	__le32 num;	/* the number of metrics that will be sent */
  } __packed;
#2 lore raw

Oh! I hadn't realized that this patch was still unmerged.

Merged into testing branch. I'd have pulled this into testing a while ago if I had realized. Let me know if I miss any in the future (or am missing any now).

Cheers,
Jeff

Quoted 166 lines · Xiubo Li

Hi Jeff,

Ping.

The MDS side patch[1] have been merged.

[1] https://github.com/ceph/ceph/pull/37945

Thanks

Quoted 152 lines · On 2020/11/26 11:47, [email protected] wrote:

From: Xiubo Li <[email protected]>

For the old ceph version, if it received this metric message containing the send opened files/pinned caps/opened inodes metric info, it will just ignore them.

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

---
  fs/ceph/metric.c | 38 +++++++++++++++++++++++++++++++++++++- fs/ceph/metric.h | 44 +++++++++++++++++++++++++++++++++++++++++++-

  2 files changed, 80 insertions(+), 2 deletions(-)
fs/ceph/metric.c +3 -0
index 5ec94bd4c1de..306bd599d940 100644
@@ -17,6 +17,9 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
   	struct ceph_metric_write_latency *write;
   	struct ceph_metric_metadata_latency *meta;
   	struct ceph_metric_dlease *dlease;
+	struct ceph_opened_files *files;
+	struct ceph_pinned_icaps *icaps;
+	struct ceph_opened_inodes *inodes;
   	struct ceph_client_metric *m = &mdsc->metric;
   	u64 nr_caps = atomic64_read(&m->total_caps);
   	struct ceph_msg *msg;
@@ -26,7 +29,8 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
   	s32 len;

   len = sizeof(*head) + sizeof(*cap) + sizeof(*read) + sizeof(*write)

fs/ceph/metric.c +2 -1
-	      + sizeof(*meta) + sizeof(*dlease);
+	      + sizeof(*meta) + sizeof(*dlease) + sizeof(files) + sizeof(icaps)
+	      + sizeof(inodes);

   msg = ceph_msg_new(CEPH_MSG_CLIENT_METRICS, len, GFP_NOFS, true); if (!msg) {

fs/ceph/metric.c +0 -0
@@ -95,6 +99,38 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
   	dlease->total = cpu_to_le64(atomic64_read(&m->total_dentries));
   	items++;

fs/ceph/metric.c +32 -0
+	sum = percpu_counter_sum(&m->total_inodes);
+
+	/* encode the opened files metric */
+	files = (struct ceph_opened_files *)(dlease + 1);
+	files->type = cpu_to_le32(CLIENT_METRIC_TYPE_OPENED_FILES);
+	files->ver = 1;
+	files->compat = 1;
+	files->data_len = cpu_to_le32(sizeof(*files) - 10);
+	files->opened_files = cpu_to_le64(atomic64_read(&m->opened_files));
+	files->total = cpu_to_le64(sum);
+	items++;
+
+	/* encode the pinned icaps metric */
+	icaps = (struct ceph_pinned_icaps *)(files + 1);
+	icaps->type = cpu_to_le32(CLIENT_METRIC_TYPE_PINNED_ICAPS);
+	icaps->ver = 1;
+	icaps->compat = 1;
+	icaps->data_len = cpu_to_le32(sizeof(*icaps) - 10);
+	icaps->pinned_icaps = cpu_to_le64(nr_caps);
+	icaps->total = cpu_to_le64(sum);
+	items++;
+
+	/* encode the opened inodes metric */
+	inodes = (struct ceph_opened_inodes *)(icaps + 1);
+	inodes->type = cpu_to_le32(CLIENT_METRIC_TYPE_OPENED_INODES);
+	inodes->ver = 1;
+	inodes->compat = 1;
+	inodes->data_len = cpu_to_le32(sizeof(*inodes) - 10);
+	inodes->opened_inodes = cpu_to_le64(percpu_counter_sum(&m->opened_inodes));
+	inodes->total = cpu_to_le64(sum);
+	items++;
+

   put_unaligned_le32(items, &head->num);
   msg->front.iov_len = len;
   msg->hdr.version = cpu_to_le16(1);

fs/ceph/metric.h +3 -0
index af6038ff39d4..4ceb462135d7 100644
@@ -14,8 +14,11 @@ enum ceph_metric_type {
   	CLIENT_METRIC_TYPE_WRITE_LATENCY,
   	CLIENT_METRIC_TYPE_METADATA_LATENCY,
   	CLIENT_METRIC_TYPE_DENTRY_LEASE,
+	CLIENT_METRIC_TYPE_OPENED_FILES,
+	CLIENT_METRIC_TYPE_PINNED_ICAPS,
+	CLIENT_METRIC_TYPE_OPENED_INODES,

fs/ceph/metric.h +1 -1
-	CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_DENTRY_LEASE,
+	CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_OPENED_INODES,

  };

  /*

fs/ceph/metric.h +3 -0
@@ -28,6 +31,9 @@ enum ceph_metric_type {
   	CLIENT_METRIC_TYPE_WRITE_LATENCY,	\
   	CLIENT_METRIC_TYPE_METADATA_LATENCY,	\
   	CLIENT_METRIC_TYPE_DENTRY_LEASE,	\
+	CLIENT_METRIC_TYPE_OPENED_FILES,	\
+	CLIENT_METRIC_TYPE_PINNED_ICAPS,	\
+	CLIENT_METRIC_TYPE_OPENED_INODES,	\
   						\
   	CLIENT_METRIC_TYPE_MAX,			\
   }
@@ -94,6 +100,42 @@ struct ceph_metric_dlease {
   	__le64 total;
   } __packed;

fs/ceph/metric.h +36 -0
+/* metric opened files header */
+struct ceph_opened_files {
+	__le32 type;     /* ceph metric type */
+
+	__u8  ver;
+	__u8  compat;
+
+	__le32 data_len; /* length of sizeof(opened_files + total) */
+	__le64 opened_files;
+	__le64 total;
+} __packed;
+
+/* metric pinned i_caps header */
+struct ceph_pinned_icaps {
+	__le32 type;     /* ceph metric type */
+
+	__u8  ver;
+	__u8  compat;
+
+	__le32 data_len; /* length of sizeof(pinned_icaps + total) */
+	__le64 pinned_icaps;
+	__le64 total;
+} __packed;
+
+/* metric opened inodes header */
+struct ceph_opened_inodes {
+	__le32 type;     /* ceph metric type */
+
+	__u8  ver;
+	__u8  compat;
+
+	__le32 data_len; /* length of sizeof(opened_inodes + total) */
+	__le64 opened_inodes;
+	__le64 total;
+} __packed;
+

  struct ceph_metric_head {
   __le32 num; /* the number of metrics that will be sent */
  } __packed;

Signature · 1 line
Jeff Layton <[email protected]>
author
#3 lore raw
Quoted 1 line · Jeff Layton

Oh! I hadn't realized that this patch was still unmerged.

No worry, this patch was waiting the MDS side patch, which was just merged last week :-)

I almost forgot this patch too before I saw the ceph tracker today.

Quoted 3 lines

Merged into testing branch. I'd have pulled this into testing a while ago if I had realized. Let me know if I miss any in the future (or am missing any now).

Sure, np.

BRs

Xiubo

Quoted 169 lines

Cheers,
Jeff

Quoted 165 lines · Xiubo Li

Hi Jeff,

Ping.

The MDS side patch[1] have been merged.

[1] https://github.com/ceph/ceph/pull/37945

Thanks

Quoted 152 lines · On 2020/11/26 11:47, [email protected] wrote:

From: Xiubo Li <[email protected]>

For the old ceph version, if it received this metric message containing the send opened files/pinned caps/opened inodes metric info, it will just ignore them.

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

---
   fs/ceph/metric.c | 38 +++++++++++++++++++++++++++++++++++++-
   fs/ceph/metric.h | 44 +++++++++++++++++++++++++++++++++++++++++++-
   2 files changed, 80 insertions(+), 2 deletions(-)
fs/ceph/metric.c +5 -1
index 5ec94bd4c1de..306bd599d940 100644
@@ -17,6 +17,9 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
   	struct ceph_metric_write_latency *write;
   	struct ceph_metric_metadata_latency *meta;
   	struct ceph_metric_dlease *dlease;
+	struct ceph_opened_files *files;
+	struct ceph_pinned_icaps *icaps;
+	struct ceph_opened_inodes *inodes;
   	struct ceph_client_metric *m = &mdsc->metric;
   	u64 nr_caps = atomic64_read(&m->total_caps);
   	struct ceph_msg *msg;
@@ -26,7 +29,8 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
   	s32 len;
 
 
   	len = sizeof(*head) + sizeof(*cap) + sizeof(*read) + sizeof(*write)
-	      + sizeof(*meta) + sizeof(*dlease);
+	      + sizeof(*meta) + sizeof(*dlease) + sizeof(files) + sizeof(icaps)
+	      + sizeof(inodes);
 
 

   msg = ceph_msg_new(CEPH_MSG_CLIENT_METRICS, len, GFP_NOFS, true); if (!msg) {

fs/ceph/metric.c +32 -0
@@ -95,6 +99,38 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
   	dlease->total = cpu_to_le64(atomic64_read(&m->total_dentries));
   	items++;
 
 
+	sum = percpu_counter_sum(&m->total_inodes);
+
+	/* encode the opened files metric */
+	files = (struct ceph_opened_files *)(dlease + 1);
+	files->type = cpu_to_le32(CLIENT_METRIC_TYPE_OPENED_FILES);
+	files->ver = 1;
+	files->compat = 1;
+	files->data_len = cpu_to_le32(sizeof(*files) - 10);
+	files->opened_files = cpu_to_le64(atomic64_read(&m->opened_files));
+	files->total = cpu_to_le64(sum);
+	items++;
+
+	/* encode the pinned icaps metric */
+	icaps = (struct ceph_pinned_icaps *)(files + 1);
+	icaps->type = cpu_to_le32(CLIENT_METRIC_TYPE_PINNED_ICAPS);
+	icaps->ver = 1;
+	icaps->compat = 1;
+	icaps->data_len = cpu_to_le32(sizeof(*icaps) - 10);
+	icaps->pinned_icaps = cpu_to_le64(nr_caps);
+	icaps->total = cpu_to_le64(sum);
+	items++;
+
+	/* encode the opened inodes metric */
+	inodes = (struct ceph_opened_inodes *)(icaps + 1);
+	inodes->type = cpu_to_le32(CLIENT_METRIC_TYPE_OPENED_INODES);
+	inodes->ver = 1;
+	inodes->compat = 1;
+	inodes->data_len = cpu_to_le32(sizeof(*inodes) - 10);
+	inodes->opened_inodes = cpu_to_le64(percpu_counter_sum(&m->opened_inodes));
+	inodes->total = cpu_to_le64(sum);
+	items++;
+
   	put_unaligned_le32(items, &head->num);
   	msg->front.iov_len = len;

   msg->hdr.version = cpu_to_le16(1);

fs/ceph/metric.h +4 -1
index af6038ff39d4..4ceb462135d7 100644
@@ -14,8 +14,11 @@ enum ceph_metric_type {
   	CLIENT_METRIC_TYPE_WRITE_LATENCY,
   	CLIENT_METRIC_TYPE_METADATA_LATENCY,
   	CLIENT_METRIC_TYPE_DENTRY_LEASE,
+	CLIENT_METRIC_TYPE_OPENED_FILES,
+	CLIENT_METRIC_TYPE_PINNED_ICAPS,
+	CLIENT_METRIC_TYPE_OPENED_INODES,
 
 
-	CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_DENTRY_LEASE,
+	CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_OPENED_INODES,
   };
 

  /*

fs/ceph/metric.h +39 -0
@@ -28,6 +31,9 @@ enum ceph_metric_type {
   	CLIENT_METRIC_TYPE_WRITE_LATENCY,	\
   	CLIENT_METRIC_TYPE_METADATA_LATENCY,	\
   	CLIENT_METRIC_TYPE_DENTRY_LEASE,	\
+	CLIENT_METRIC_TYPE_OPENED_FILES,	\
+	CLIENT_METRIC_TYPE_PINNED_ICAPS,	\
+	CLIENT_METRIC_TYPE_OPENED_INODES,	\
   						\
   	CLIENT_METRIC_TYPE_MAX,			\
   }
@@ -94,6 +100,42 @@ struct ceph_metric_dlease {
   	__le64 total;
   } __packed;
 
 
+/* metric opened files header */
+struct ceph_opened_files {
+	__le32 type;     /* ceph metric type */
+
+	__u8  ver;
+	__u8  compat;
+
+	__le32 data_len; /* length of sizeof(opened_files + total) */
+	__le64 opened_files;
+	__le64 total;
+} __packed;
+
+/* metric pinned i_caps header */
+struct ceph_pinned_icaps {
+	__le32 type;     /* ceph metric type */
+
+	__u8  ver;
+	__u8  compat;
+
+	__le32 data_len; /* length of sizeof(pinned_icaps + total) */
+	__le64 pinned_icaps;
+	__le64 total;
+} __packed;
+
+/* metric opened inodes header */
+struct ceph_opened_inodes {
+	__le32 type;     /* ceph metric type */
+
+	__u8  ver;
+	__u8  compat;
+
+	__le32 data_len; /* length of sizeof(opened_inodes + total) */
+	__le64 opened_inodes;
+	__le64 total;
+} __packed;
+
   struct ceph_metric_head {
   	__le32 num;	/* the number of metrics that will be sent */

  } __packed;

#4 lore raw
Quoted 12 lines · Xiubo Li
Quoted 1 line · Jeff Layton

Oh! I hadn't realized that this patch was still unmerged.

No worry, this patch was waiting the MDS side patch, which was just merged last week :-)

I almost forgot this patch too before I saw the ceph tracker today.

Quoted 3 lines

Merged into testing branch. I'd have pulled this into testing a while ago if I had realized. Let me know if I miss any in the future (or am missing any now).

Quoted 6 lines

Sure, np.

BRs

Xiubo

After doing some testing with this patch, I hit the following KASAN pop today. I've backed this patch out of the testing branch for now:

[  110.969263] ==================================================================
[  110.972933] BUG: KASAN: slab-out-of-bounds in metric_delayed_work+0x5e9/0x880 [ceph]
[  110.976096] Write of size 8 at addr ffff88811b76ab90 by task kworker/7:2/613
[  110.978972] 
[  110.979668] CPU: 7 PID: 613 Comm: kworker/7:2 Tainted: G            E     5.12.0-rc2+ #70
[  110.983015] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.14.0-1.fc33 04/01/2014
[  110.986467] Workqueue: events metric_delayed_work [ceph]
[  110.988803] Call Trace:
[  110.989869]  dump_stack+0xa5/0xdc
[  110.991297]  print_address_description.constprop.0+0x18/0x160
[  110.993659]  ? metric_delayed_work+0x5e9/0x880 [ceph]
[  110.995892]  ? metric_delayed_work+0x5e9/0x880 [ceph]
[  110.998108]  kasan_report.cold+0x7f/0x111
[  110.999818]  ? _raw_spin_lock_irq+0x61/0x90
[  111.001563]  ? metric_delayed_work+0x5e9/0x880 [ceph]
[  111.003814]  kasan_check_range+0xf9/0x1e0
[  111.005503]  metric_delayed_work+0x5e9/0x880 [ceph]
[  111.007688]  ? ceph_caps_for_mode+0x40/0x40 [ceph]
[  111.009855]  process_one_work+0x525/0x9b0
[  111.011597]  ? pwq_dec_nr_in_flight+0x110/0x110
[  111.013504]  ? lock_acquired+0x2fe/0x560
[  111.015230]  worker_thread+0x2ea/0x6e0
[  111.016840]  ? __kthread_parkme+0xc0/0xe0
[  111.018534]  ? process_one_work+0x9b0/0x9b0
[  111.020262]  kthread+0x1fb/0x220
[  111.021622]  ? __kthread_bind_mask+0x70/0x70
[  111.023423]  ret_from_fork+0x22/0x30
[  111.025004] 
[  111.025687] Allocated by task 613:
[  111.027105]  kasan_save_stack+0x1b/0x40
[  111.028740]  __kasan_kmalloc+0x7a/0x90
[  111.029583]  ceph_kvmalloc+0xc7/0x110 [libceph]
[  111.030611]  ceph_msg_new2+0x15d/0x270 [libceph]
[  111.031537]  metric_delayed_work+0x1c5/0x880 [ceph]
[  111.032414]  process_one_work+0x525/0x9b0
[  111.033093]  worker_thread+0x2ea/0x6e0
[  111.033763]  kthread+0x1fb/0x220
[  111.034329]  ret_from_fork+0x22/0x30
[  111.038203] 
[  111.041730] The buggy address belongs to the object at ffff88811b76ab00
[  111.041730]  which belongs to the cache kmalloc-192 of size 192
[  111.050535] The buggy address is located 144 bytes inside of
[  111.050535]  192-byte region [ffff88811b76ab00, ffff88811b76abc0)
[  111.059194] The buggy address belongs to the page:
[  111.063348] page:0000000052971d41 refcount:1 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x11b76a
[  111.068337] head:0000000052971d41 order:1 compound_mapcount:0
[  111.073364] flags: 0x17ffffc0010200(slab|head)
[  111.078020] raw: 0017ffffc0010200 0000000000000000 0000000100000001 ffff888100042a00
[  111.083177] raw: 0000000000000000 0000000080200020 00000001ffffffff 0000000000000000
[  111.088350] page dumped because: kasan: bad access detected
[  111.093064] 
[  111.096773] Memory state around the buggy address:
[  111.101168]  ffff88811b76aa80: 00 00 fc fc fc fc fc fc fc fc fc fc fc fc fc fc
[  111.106154]  ffff88811b76ab00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[  111.111073] >ffff88811b76ab80: 00 00 06 fc fc fc fc fc fc fc fc fc fc fc fc fc
[  111.115973]                          ^
[  111.120219]  ffff88811b76ac00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
[  111.125263]  ffff88811b76ac80: 00 fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
[  111.130227] ==================================================================
Signature · 1 line
Jeff Layton <[email protected]>
author
#5 lore raw
In reply to Jeff Layton

On 2021/3/24 12:53, Xiubo Li wrote:

[...]

Quoted 23 lines

fs/ceph/metric.c static bool ceph_mdsc_send_metrics(struct

Quoted 5 lines
fs/ceph/metric.c +0 -0
index 5ec94bd4c1de..306bd599d940 100644
@@ -17,6 +17,9 @@ static bool ceph_mdsc_send_metrics(struct 

ceph_mds_client *mdsc,

fs/ceph/metric.c static bool ceph_mdsc_send_metrics(struct

Quoted 10 lines
fs/ceph/metric.c +3 -0
       struct ceph_metric_write_latency *write;
       struct ceph_metric_metadata_latency *meta;
       struct ceph_metric_dlease *dlease;
+    struct ceph_opened_files *files;
+    struct ceph_pinned_icaps *icaps;
+    struct ceph_opened_inodes *inodes;
       struct ceph_client_metric *m = &mdsc->metric;
       u64 nr_caps = atomic64_read(&m->total_caps);
       struct ceph_msg *msg;
@@ -26,7 +29,8 @@ static bool ceph_mdsc_send_metrics(struct 

ceph_mds_client *mdsc,

Quoted 3 lines
fs/ceph/metric.c +0 -0
       s32 len;
 

      len = sizeof(*head) + sizeof(*cap) + sizeof(*read) +

sizeof(*write)

Quoted 2 lines

-          + sizeof(*meta) + sizeof(*dlease);
+          + sizeof(*meta) + sizeof(*dlease) + sizeof(files) +

Quoted 9 lines

sizeof(icaps)

Quoted 2 lines

+          + sizeof(inodes);

These sizeof values look wrong. The buffer requires more than pointers for those. You probably want:

 ... + sizeof(*files) + sizeof(*icaps) + sizeof(*inodes);

Yeah, will fix it.

Thanks

#6 lore raw
In reply to [email protected]
Quoted 28 lines · On Thu, 2020-11-26 at 11:47 +0800, [email protected] wrote:

From: Xiubo Li <[email protected]>

For the old ceph version, if it received this metric message containing the send opened files/pinned caps/opened inodes metric info, it will just ignore them.

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

---
 fs/ceph/metric.c | 38 +++++++++++++++++++++++++++++++++++++-
 fs/ceph/metric.h | 44 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 80 insertions(+), 2 deletions(-)
fs/ceph/metric.c +3 -0
index 5ec94bd4c1de..306bd599d940 100644
@@ -17,6 +17,9 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 	struct ceph_metric_write_latency *write;
 	struct ceph_metric_metadata_latency *meta;
 	struct ceph_metric_dlease *dlease;
+	struct ceph_opened_files *files;
+	struct ceph_pinned_icaps *icaps;
+	struct ceph_opened_inodes *inodes;
 	struct ceph_client_metric *m = &mdsc->metric;
 	u64 nr_caps = atomic64_read(&m->total_caps);
 	struct ceph_msg *msg;

fs/ceph/metric.c static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc, · line 34

Quoted 7 lines
fs/ceph/metric.c +2 -1
@@ -26,7 +29,8 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 	s32 len;
 
 	len = sizeof(*head) + sizeof(*cap) + sizeof(*read) + sizeof(*write)
-	      + sizeof(*meta) + sizeof(*dlease);
+	      + sizeof(*meta) + sizeof(*dlease) + sizeof(files) + sizeof(icaps)
+	      + sizeof(inodes);
 

These sizeof values look wrong. The buffer requires more than pointers for those. You probably want:

... + sizeof(*files) + sizeof(*icaps) + sizeof(*inodes);

Quoted 111 lines
fs/ceph/metric.c +32 -0
 	msg = ceph_msg_new(CEPH_MSG_CLIENT_METRICS, len, GFP_NOFS, true);
 	if (!msg) {
@@ -95,6 +99,38 @@ static bool ceph_mdsc_send_metrics(struct ceph_mds_client *mdsc,
 	dlease->total = cpu_to_le64(atomic64_read(&m->total_dentries));
 	items++;
 
+	sum = percpu_counter_sum(&m->total_inodes);
+
+	/* encode the opened files metric */
+	files = (struct ceph_opened_files *)(dlease + 1);
+	files->type = cpu_to_le32(CLIENT_METRIC_TYPE_OPENED_FILES);
+	files->ver = 1;
+	files->compat = 1;
+	files->data_len = cpu_to_le32(sizeof(*files) - 10);
+	files->opened_files = cpu_to_le64(atomic64_read(&m->opened_files));
+	files->total = cpu_to_le64(sum);
+	items++;
+
+	/* encode the pinned icaps metric */
+	icaps = (struct ceph_pinned_icaps *)(files + 1);
+	icaps->type = cpu_to_le32(CLIENT_METRIC_TYPE_PINNED_ICAPS);
+	icaps->ver = 1;
+	icaps->compat = 1;
+	icaps->data_len = cpu_to_le32(sizeof(*icaps) - 10);
+	icaps->pinned_icaps = cpu_to_le64(nr_caps);
+	icaps->total = cpu_to_le64(sum);
+	items++;
+
+	/* encode the opened inodes metric */
+	inodes = (struct ceph_opened_inodes *)(icaps + 1);
+	inodes->type = cpu_to_le32(CLIENT_METRIC_TYPE_OPENED_INODES);
+	inodes->ver = 1;
+	inodes->compat = 1;
+	inodes->data_len = cpu_to_le32(sizeof(*inodes) - 10);
+	inodes->opened_inodes = cpu_to_le64(percpu_counter_sum(&m->opened_inodes));
+	inodes->total = cpu_to_le64(sum);
+	items++;
+
 	put_unaligned_le32(items, &head->num);
 	msg->front.iov_len = len;
 	msg->hdr.version = cpu_to_le16(1);
fs/ceph/metric.h +43 -1
index af6038ff39d4..4ceb462135d7 100644
@@ -14,8 +14,11 @@ enum ceph_metric_type {
 	CLIENT_METRIC_TYPE_WRITE_LATENCY,
 	CLIENT_METRIC_TYPE_METADATA_LATENCY,
 	CLIENT_METRIC_TYPE_DENTRY_LEASE,
+	CLIENT_METRIC_TYPE_OPENED_FILES,
+	CLIENT_METRIC_TYPE_PINNED_ICAPS,
+	CLIENT_METRIC_TYPE_OPENED_INODES,
 
-	CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_DENTRY_LEASE,
+	CLIENT_METRIC_TYPE_MAX = CLIENT_METRIC_TYPE_OPENED_INODES,
 };
 
 /*
@@ -28,6 +31,9 @@ enum ceph_metric_type {
 	CLIENT_METRIC_TYPE_WRITE_LATENCY,	\
 	CLIENT_METRIC_TYPE_METADATA_LATENCY,	\
 	CLIENT_METRIC_TYPE_DENTRY_LEASE,	\
+	CLIENT_METRIC_TYPE_OPENED_FILES,	\
+	CLIENT_METRIC_TYPE_PINNED_ICAPS,	\
+	CLIENT_METRIC_TYPE_OPENED_INODES,	\
 						\
 	CLIENT_METRIC_TYPE_MAX,			\
 }
@@ -94,6 +100,42 @@ struct ceph_metric_dlease {
 	__le64 total;
 } __packed;
 
+/* metric opened files header */
+struct ceph_opened_files {
+	__le32 type;     /* ceph metric type */
+
+	__u8  ver;
+	__u8  compat;
+
+	__le32 data_len; /* length of sizeof(opened_files + total) */
+	__le64 opened_files;
+	__le64 total;
+} __packed;
+
+/* metric pinned i_caps header */
+struct ceph_pinned_icaps {
+	__le32 type;     /* ceph metric type */
+
+	__u8  ver;
+	__u8  compat;
+
+	__le32 data_len; /* length of sizeof(pinned_icaps + total) */
+	__le64 pinned_icaps;
+	__le64 total;
+} __packed;
+
+/* metric opened inodes header */
+struct ceph_opened_inodes {
+	__le32 type;     /* ceph metric type */
+
+	__u8  ver;
+	__u8  compat;
+
+	__le32 data_len; /* length of sizeof(opened_inodes + total) */
+	__le64 opened_inodes;
+	__le64 total;
+} __packed;
+
 struct ceph_metric_head {
 	__le32 num;	/* the number of metrics that will be sent */
 } __packed;
Signature · 1 line
Jeff Layton <[email protected]>