@@ -683,6 +683,63 @@ static int osdmap_set_max_osd(struct ceph_osdmap *map, int max)
683683 return 0 ;
684684}
685685
686+ #define OSDMAP_WRAPPER_COMPAT_VER 7
687+ #define OSDMAP_CLIENT_DATA_COMPAT_VER 1
688+
689+ /*
690+ * Return 0 or error. On success, *v is set to 0 for old (v6) osdmaps,
691+ * to struct_v of the client_data section for new (v7 and above)
692+ * osdmaps.
693+ */
694+ static int get_osdmap_client_data_v (void * * p , void * end ,
695+ const char * prefix , u8 * v )
696+ {
697+ u8 struct_v ;
698+
699+ ceph_decode_8_safe (p , end , struct_v , e_inval );
700+ if (struct_v >= 7 ) {
701+ u8 struct_compat ;
702+
703+ ceph_decode_8_safe (p , end , struct_compat , e_inval );
704+ if (struct_compat > OSDMAP_WRAPPER_COMPAT_VER ) {
705+ pr_warning ("got v %d cv %d > %d of %s ceph_osdmap\n" ,
706+ struct_v , struct_compat ,
707+ OSDMAP_WRAPPER_COMPAT_VER , prefix );
708+ return - EINVAL ;
709+ }
710+ * p += 4 ; /* ignore wrapper struct_len */
711+
712+ ceph_decode_8_safe (p , end , struct_v , e_inval );
713+ ceph_decode_8_safe (p , end , struct_compat , e_inval );
714+ if (struct_compat > OSDMAP_CLIENT_DATA_COMPAT_VER ) {
715+ pr_warning ("got v %d cv %d > %d of %s ceph_osdmap client data\n" ,
716+ struct_v , struct_compat ,
717+ OSDMAP_CLIENT_DATA_COMPAT_VER , prefix );
718+ return - EINVAL ;
719+ }
720+ * p += 4 ; /* ignore client data struct_len */
721+ } else {
722+ u16 version ;
723+
724+ * p -= 1 ;
725+ ceph_decode_16_safe (p , end , version , e_inval );
726+ if (version < 6 ) {
727+ pr_warning ("got v %d < 6 of %s ceph_osdmap\n" , version ,
728+ prefix );
729+ return - EINVAL ;
730+ }
731+
732+ /* old osdmap enconding */
733+ struct_v = 0 ;
734+ }
735+
736+ * v = struct_v ;
737+ return 0 ;
738+
739+ e_inval :
740+ return - EINVAL ;
741+ }
742+
686743static int __decode_pools (void * * p , void * end , struct ceph_osdmap * map ,
687744 bool incremental )
688745{
@@ -798,7 +855,7 @@ static int decode_new_pg_temp(void **p, void *end, struct ceph_osdmap *map)
798855 */
799856static int osdmap_decode (void * * p , void * end , struct ceph_osdmap * map )
800857{
801- u16 version ;
858+ u8 struct_v ;
802859 u32 epoch = 0 ;
803860 void * start = * p ;
804861 u32 max ;
@@ -807,15 +864,9 @@ static int osdmap_decode(void **p, void *end, struct ceph_osdmap *map)
807864
808865 dout ("%s %p to %p len %d\n" , __func__ , * p , end , (int )(end - * p ));
809866
810- ceph_decode_16_safe (p , end , version , e_inval );
811- if (version > 6 ) {
812- pr_warning ("got unknown v %d > 6 of osdmap\n" , version );
813- goto e_inval ;
814- }
815- if (version < 6 ) {
816- pr_warning ("got old v %d < 6 of osdmap\n" , version );
817- goto e_inval ;
818- }
867+ err = get_osdmap_client_data_v (p , end , "full" , & struct_v );
868+ if (err )
869+ goto bad ;
819870
820871 /* fsid, epoch, created, modified */
821872 ceph_decode_need (p , end , sizeof (map -> fsid ) + sizeof (u32 ) +
@@ -943,15 +994,13 @@ struct ceph_osdmap *osdmap_apply_incremental(void **p, void *end,
943994 __s32 new_flags , max ;
944995 void * start = * p ;
945996 int err ;
946- u16 version ;
997+ u8 struct_v ;
947998
948999 dout ("%s %p to %p len %d\n" , __func__ , * p , end , (int )(end - * p ));
9491000
950- ceph_decode_16_safe (p , end , version , e_inval );
951- if (version != 6 ) {
952- pr_warning ("got unknown v %d != 6 of inc osdmap\n" , version );
953- goto e_inval ;
954- }
1001+ err = get_osdmap_client_data_v (p , end , "inc" , & struct_v );
1002+ if (err )
1003+ goto bad ;
9551004
9561005 /* fsid, epoch, modified, new_pool_max, new_flags */
9571006 ceph_decode_need (p , end , sizeof (fsid ) + sizeof (u32 ) + sizeof (modified ) +
0 commit comments