Skip to content

Commit 69f0df0

Browse files
author
John Spray
committed
ceph: send client metadata to MDS
Implement version 2 of CEPH_MSG_CLIENT_SESSION syntax, which includes additional client metadata to allow the MDS to report on clients by user-sensible names like hostname. Signed-off-by: John Spray <john.spray@redhat.com>
1 parent 00b1c70 commit 69f0df0

1 file changed

Lines changed: 70 additions & 1 deletion

File tree

fs/ceph/mds_client.c

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/sched.h>
88
#include <linux/debugfs.h>
99
#include <linux/seq_file.h>
10+
#include <linux/utsname.h>
1011

1112
#include "super.h"
1213
#include "mds_client.h"
@@ -812,6 +813,74 @@ static struct ceph_msg *create_session_msg(u32 op, u64 seq)
812813
h = msg->front.iov_base;
813814
h->op = cpu_to_le32(op);
814815
h->seq = cpu_to_le64(seq);
816+
817+
return msg;
818+
}
819+
820+
/*
821+
* session message, specialization for CEPH_SESSION_REQUEST_OPEN
822+
* to include additional client metadata fields.
823+
*/
824+
static struct ceph_msg *create_session_open_msg(struct ceph_mds_client *mdsc, u64 seq)
825+
{
826+
struct ceph_msg *msg;
827+
struct ceph_mds_session_head *h;
828+
int i = -1;
829+
int metadata_bytes = 0;
830+
int metadata_key_count = 0;
831+
u8 *buf_off = NULL;
832+
struct ceph_options *opt = mdsc->fsc->client->options;
833+
834+
const char* metadata[3][2] = {
835+
{"hostname", utsname()->nodename},
836+
{"entity_id", opt->name ? opt->name : ""},
837+
{NULL, NULL}
838+
};
839+
840+
// Calculate serialized length of metadata
841+
metadata_bytes = 4; // map length
842+
for (i = 0; metadata[i][0] != NULL; ++i) {
843+
metadata_bytes += 8 + strlen(metadata[i][0]) + strlen(metadata[i][1]);
844+
metadata_key_count++;
845+
}
846+
847+
// Allocate the message
848+
msg = ceph_msg_new(CEPH_MSG_CLIENT_SESSION, sizeof(*h) + metadata_bytes, GFP_NOFS,
849+
false);
850+
if (!msg) {
851+
pr_err("create_session_msg ENOMEM creating msg\n");
852+
return NULL;
853+
}
854+
h = msg->front.iov_base;
855+
h->op = cpu_to_le32(CEPH_SESSION_REQUEST_OPEN);
856+
h->seq = cpu_to_le64(seq);
857+
858+
// Serialize client metadata into waiting buffer space, using
859+
// the format that userspace expects for map<string, string>
860+
msg->hdr.version = 2; // ClientSession messages with metadata are v2
861+
862+
// The write pointer, following the session_head structure
863+
buf_off = msg->front.iov_base + sizeof(*h);
864+
865+
// Number of entries in the map
866+
*((u32*)buf_off) = cpu_to_le32(metadata_key_count);
867+
buf_off += sizeof(u32);
868+
869+
// Two length-prefixed strings for each entry in the map
870+
for (i = 0; metadata[i][0] != NULL; ++i) {
871+
size_t const key_len = strlen(metadata[i][0]);
872+
size_t const val_len = strlen(metadata[i][1]);
873+
874+
*((u32*)buf_off) = cpu_to_le32(key_len);
875+
buf_off += sizeof(u32);
876+
memcpy(buf_off, metadata[i][0], key_len);
877+
buf_off += key_len;
878+
*((u32*)buf_off) = cpu_to_le32(val_len);
879+
buf_off += sizeof(u32);
880+
memcpy(buf_off, metadata[i][1], val_len);
881+
buf_off += val_len;
882+
}
883+
815884
return msg;
816885
}
817886

@@ -835,7 +904,7 @@ static int __open_session(struct ceph_mds_client *mdsc,
835904
session->s_renew_requested = jiffies;
836905

837906
/* send connect message */
838-
msg = create_session_msg(CEPH_SESSION_REQUEST_OPEN, session->s_seq);
907+
msg = create_session_open_msg(mdsc, session->s_seq);
839908
if (!msg)
840909
return -ENOMEM;
841910
ceph_con_send(&session->s_con, msg);

0 commit comments

Comments
 (0)