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+ 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+
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