@@ -477,14 +477,13 @@ static struct ceph_msg *get_generic_reply(struct ceph_connection *con,
477477 return m ;
478478}
479479
480- static int do_generic_request (struct ceph_mon_client * monc ,
481- struct ceph_mon_generic_request * req )
480+ static int __do_generic_request (struct ceph_mon_client * monc , u64 tid ,
481+ struct ceph_mon_generic_request * req )
482482{
483483 int err ;
484484
485485 /* register request */
486- mutex_lock (& monc -> mutex );
487- req -> tid = ++ monc -> last_tid ;
486+ req -> tid = tid != 0 ? tid : ++ monc -> last_tid ;
488487 req -> request -> hdr .tid = cpu_to_le64 (req -> tid );
489488 __insert_generic_request (monc , req );
490489 monc -> num_generic_requests ++ ;
@@ -496,13 +495,24 @@ static int do_generic_request(struct ceph_mon_client *monc,
496495 mutex_lock (& monc -> mutex );
497496 rb_erase (& req -> node , & monc -> generic_request_tree );
498497 monc -> num_generic_requests -- ;
499- mutex_unlock (& monc -> mutex );
500498
501499 if (!err )
502500 err = req -> result ;
503501 return err ;
504502}
505503
504+ static int do_generic_request (struct ceph_mon_client * monc ,
505+ struct ceph_mon_generic_request * req )
506+ {
507+ int err ;
508+
509+ mutex_lock (& monc -> mutex );
510+ err = __do_generic_request (monc , 0 , req );
511+ mutex_unlock (& monc -> mutex );
512+
513+ return err ;
514+ }
515+
506516/*
507517 * statfs
508518 */
@@ -579,6 +589,96 @@ int ceph_monc_do_statfs(struct ceph_mon_client *monc, struct ceph_statfs *buf)
579589}
580590EXPORT_SYMBOL (ceph_monc_do_statfs );
581591
592+ static void handle_get_version_reply (struct ceph_mon_client * monc ,
593+ struct ceph_msg * msg )
594+ {
595+ struct ceph_mon_generic_request * req ;
596+ u64 tid = le64_to_cpu (msg -> hdr .tid );
597+ void * p = msg -> front .iov_base ;
598+ void * end = p + msg -> front_alloc_len ;
599+ u64 handle ;
600+
601+ dout ("%s %p tid %llu\n" , __func__ , msg , tid );
602+
603+ ceph_decode_need (& p , end , 2 * sizeof (u64 ), bad );
604+ handle = ceph_decode_64 (& p );
605+ if (tid != 0 && tid != handle )
606+ goto bad ;
607+
608+ mutex_lock (& monc -> mutex );
609+ req = __lookup_generic_req (monc , handle );
610+ if (req ) {
611+ * (u64 * )req -> buf = ceph_decode_64 (& p );
612+ req -> result = 0 ;
613+ get_generic_request (req );
614+ }
615+ mutex_unlock (& monc -> mutex );
616+ if (req ) {
617+ complete_all (& req -> completion );
618+ put_generic_request (req );
619+ }
620+
621+ return ;
622+ bad :
623+ pr_err ("corrupt mon_get_version reply\n" );
624+ ceph_msg_dump (msg );
625+ }
626+
627+ /*
628+ * Send MMonGetVersion and wait for the reply.
629+ *
630+ * @what: one of "mdsmap", "osdmap" or "monmap"
631+ */
632+ int ceph_monc_do_get_version (struct ceph_mon_client * monc , const char * what ,
633+ u64 * newest )
634+ {
635+ struct ceph_mon_generic_request * req ;
636+ void * p , * end ;
637+ u64 tid ;
638+ int err ;
639+
640+ req = kzalloc (sizeof (* req ), GFP_NOFS );
641+ if (!req )
642+ return - ENOMEM ;
643+
644+ kref_init (& req -> kref );
645+ req -> buf = newest ;
646+ req -> buf_len = sizeof (* newest );
647+ init_completion (& req -> completion );
648+
649+ req -> request = ceph_msg_new (CEPH_MSG_MON_GET_VERSION ,
650+ sizeof (u64 ) + sizeof (u32 ) + strlen (what ),
651+ GFP_NOFS , true);
652+ if (!req -> request ) {
653+ err = - ENOMEM ;
654+ goto out ;
655+ }
656+
657+ req -> reply = ceph_msg_new (CEPH_MSG_MON_GET_VERSION_REPLY , 1024 ,
658+ GFP_NOFS , true);
659+ if (!req -> reply ) {
660+ err = - ENOMEM ;
661+ goto out ;
662+ }
663+
664+ p = req -> request -> front .iov_base ;
665+ end = p + req -> request -> front_alloc_len ;
666+
667+ /* fill out request */
668+ mutex_lock (& monc -> mutex );
669+ tid = ++ monc -> last_tid ;
670+ ceph_encode_64 (& p , tid ); /* handle */
671+ ceph_encode_string (& p , end , what , strlen (what ));
672+
673+ err = __do_generic_request (monc , tid , req );
674+
675+ mutex_unlock (& monc -> mutex );
676+ out :
677+ kref_put (& req -> kref , release_generic_request );
678+ return err ;
679+ }
680+ EXPORT_SYMBOL (ceph_monc_do_get_version );
681+
582682/*
583683 * pool ops
584684 */
@@ -981,6 +1081,10 @@ static void dispatch(struct ceph_connection *con, struct ceph_msg *msg)
9811081 handle_statfs_reply (monc , msg );
9821082 break ;
9831083
1084+ case CEPH_MSG_MON_GET_VERSION_REPLY :
1085+ handle_get_version_reply (monc , msg );
1086+ break ;
1087+
9841088 case CEPH_MSG_POOLOP_REPLY :
9851089 handle_poolop_reply (monc , msg );
9861090 break ;
@@ -1029,6 +1133,15 @@ static struct ceph_msg *mon_alloc_msg(struct ceph_connection *con,
10291133 case CEPH_MSG_AUTH_REPLY :
10301134 m = ceph_msg_get (monc -> m_auth_reply );
10311135 break ;
1136+ case CEPH_MSG_MON_GET_VERSION_REPLY :
1137+ if (le64_to_cpu (hdr -> tid ) != 0 )
1138+ return get_generic_reply (con , hdr , skip );
1139+
1140+ /*
1141+ * Older OSDs don't set reply tid even if the orignal
1142+ * request had a non-zero tid. Workaround this weirdness
1143+ * by falling through to the allocate case.
1144+ */
10321145 case CEPH_MSG_MON_MAP :
10331146 case CEPH_MSG_MDS_MAP :
10341147 case CEPH_MSG_OSD_MAP :
0 commit comments