diff options
author | John Spray <john.spray@redhat.com> | 2014-09-09 14:26:01 -0400 |
---|---|---|
committer | Sage Weil <sage@redhat.com> | 2014-10-14 15:56:47 -0400 |
commit | dbd0c8bf79b2c73d11d47bdf2496e7ebf0948f02 (patch) | |
tree | 6e86fa83d6ba5cb1418e8f1051e14068c47957e8 /fs/ceph | |
parent | a4483e8a424d76bc1dfacdd94e739fba29d7f83f (diff) |
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>
Reviewed-by: Yan, Zheng <zyan@redhat.com>
Diffstat (limited to 'fs/ceph')
-rw-r--r-- | fs/ceph/mds_client.c | 71 |
1 files changed, 70 insertions, 1 deletions
diff --git a/fs/ceph/mds_client.c b/fs/ceph/mds_client.c index 5edf206354b2..5474feb77743 100644 --- a/fs/ceph/mds_client.c +++ b/fs/ceph/mds_client.c | |||
@@ -7,6 +7,7 @@ | |||
7 | #include <linux/sched.h> | 7 | #include <linux/sched.h> |
8 | #include <linux/debugfs.h> | 8 | #include <linux/debugfs.h> |
9 | #include <linux/seq_file.h> | 9 | #include <linux/seq_file.h> |
10 | #include <linux/utsname.h> | ||
10 | 11 | ||
11 | #include "super.h" | 12 | #include "super.h" |
12 | #include "mds_client.h" | 13 | #include "mds_client.h" |
@@ -812,6 +813,74 @@ static struct ceph_msg *create_session_msg(u32 op, u64 seq) | |||
812 | h = msg->front.iov_base; | 813 | h = msg->front.iov_base; |
813 | h->op = cpu_to_le32(op); | 814 | h->op = cpu_to_le32(op); |
814 | h->seq = cpu_to_le64(seq); | 815 | 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 | struct ceph_options *opt = mdsc->fsc->client->options; | ||
832 | void *p; | ||
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]) + | ||
844 | strlen(metadata[i][1]); | ||
845 | metadata_key_count++; | ||
846 | } | ||
847 | |||
848 | /* Allocate the message */ | ||
849 | msg = ceph_msg_new(CEPH_MSG_CLIENT_SESSION, sizeof(*h) + metadata_bytes, | ||
850 | GFP_NOFS, false); | ||
851 | if (!msg) { | ||
852 | pr_err("create_session_msg ENOMEM creating msg\n"); | ||
853 | return NULL; | ||
854 | } | ||
855 | h = msg->front.iov_base; | ||
856 | h->op = cpu_to_le32(CEPH_SESSION_REQUEST_OPEN); | ||
857 | h->seq = cpu_to_le64(seq); | ||
858 | |||
859 | /* | ||
860 | * Serialize client metadata into waiting buffer space, using | ||
861 | * the format that userspace expects for map<string, string> | ||
862 | */ | ||
863 | msg->hdr.version = 2; /* ClientSession messages with metadata are v2 */ | ||
864 | |||
865 | /* The write pointer, following the session_head structure */ | ||
866 | p = msg->front.iov_base + sizeof(*h); | ||
867 | |||
868 | /* Number of entries in the map */ | ||
869 | ceph_encode_32(&p, metadata_key_count); | ||
870 | |||
871 | /* Two length-prefixed strings for each entry in the map */ | ||
872 | for (i = 0; metadata[i][0] != NULL; ++i) { | ||
873 | size_t const key_len = strlen(metadata[i][0]); | ||
874 | size_t const val_len = strlen(metadata[i][1]); | ||
875 | |||
876 | ceph_encode_32(&p, key_len); | ||
877 | memcpy(p, metadata[i][0], key_len); | ||
878 | p += key_len; | ||
879 | ceph_encode_32(&p, val_len); | ||
880 | memcpy(p, metadata[i][1], val_len); | ||
881 | p += val_len; | ||
882 | } | ||
883 | |||
815 | return msg; | 884 | return msg; |
816 | } | 885 | } |
817 | 886 | ||
@@ -835,7 +904,7 @@ static int __open_session(struct ceph_mds_client *mdsc, | |||
835 | session->s_renew_requested = jiffies; | 904 | session->s_renew_requested = jiffies; |
836 | 905 | ||
837 | /* send connect message */ | 906 | /* 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); |
839 | if (!msg) | 908 | if (!msg) |
840 | return -ENOMEM; | 909 | return -ENOMEM; |
841 | ceph_con_send(&session->s_con, msg); | 910 | ceph_con_send(&session->s_con, msg); |