@@ -24,16 +24,18 @@ static void vbdev_ocf_module_fini(void);
2424static int vbdev_ocf_module_get_ctx_size (void );
2525static void vbdev_ocf_module_examine_config (struct spdk_bdev * bdev );
2626static void vbdev_ocf_module_examine_disk (struct spdk_bdev * bdev );
27+ static int vbdev_ocf_module_config_json (struct spdk_json_write_ctx * w );
2728
2829struct spdk_bdev_module ocf_if = {
2930 .name = "OCF" ,
3031 .module_init = vbdev_ocf_module_init ,
3132 .fini_start = vbdev_ocf_module_fini_start ,
33+ .async_fini_start = true,
3234 .module_fini = vbdev_ocf_module_fini ,
3335 .get_ctx_size = vbdev_ocf_module_get_ctx_size ,
3436 .examine_config = vbdev_ocf_module_examine_config ,
3537 .examine_disk = vbdev_ocf_module_examine_disk ,
36- .async_fini_start = true ,
38+ .config_json = vbdev_ocf_module_config_json ,
3739};
3840SPDK_BDEV_MODULE_REGISTER (ocf , & ocf_if )
3941
@@ -42,17 +44,17 @@ static void vbdev_ocf_fn_submit_request(struct spdk_io_channel *ch, struct spdk_
4244static bool vbdev_ocf_fn_io_type_supported (void * ctx , enum spdk_bdev_io_type );
4345static struct spdk_io_channel * vbdev_ocf_fn_get_io_channel (void * ctx );
4446static int vbdev_ocf_fn_dump_info_json (void * ctx , struct spdk_json_write_ctx * w );
45- static void vbdev_ocf_fn_write_config_json (struct spdk_bdev * bdev , struct spdk_json_write_ctx * w );
47+ static void vbdev_ocf_fn_dump_device_stat_json (void * ctx , struct spdk_json_write_ctx * w );
48+ static void vbdev_ocf_fn_reset_device_stat (void * ctx );
4649
4750struct spdk_bdev_fn_table vbdev_ocf_fn_table = {
4851 .destruct = vbdev_ocf_fn_destruct ,
4952 .submit_request = vbdev_ocf_fn_submit_request ,
5053 .io_type_supported = vbdev_ocf_fn_io_type_supported ,
5154 .get_io_channel = vbdev_ocf_fn_get_io_channel ,
5255 .dump_info_json = vbdev_ocf_fn_dump_info_json ,
53- .write_config_json = vbdev_ocf_fn_write_config_json ,
54- .dump_device_stat_json = NULL , // todo ?
55- .reset_device_stat = NULL , // todo ?
56+ .dump_device_stat_json = vbdev_ocf_fn_dump_device_stat_json ,
57+ .reset_device_stat = vbdev_ocf_fn_reset_device_stat ,
5658};
5759
5860static int
@@ -766,6 +768,91 @@ vbdev_ocf_module_examine_disk(struct spdk_bdev *bdev)
766768 }
767769}
768770
771+ static void
772+ dump_core_config (struct spdk_json_write_ctx * w , struct vbdev_ocf_core * core_ctx )
773+ {
774+ spdk_json_write_object_begin (w );
775+ spdk_json_write_named_string (w , "method" , "bdev_ocf_add_core" );
776+
777+ spdk_json_write_named_object_begin (w , "params" );
778+ spdk_json_write_named_string (w , "core_name" , vbdev_ocf_core_get_name (core_ctx ));
779+ spdk_json_write_named_string (w , "base_name" , core_ctx -> base .name );
780+ spdk_json_write_named_string (w , "cache_name" , core_ctx -> cache_name );
781+ spdk_json_write_object_end (w );
782+
783+ spdk_json_write_object_end (w );
784+ }
785+
786+ static void
787+ dump_cache_config (struct spdk_json_write_ctx * w , ocf_cache_t cache )
788+ {
789+ struct vbdev_ocf_cache * cache_ctx = ocf_cache_get_priv (cache );
790+
791+ spdk_json_write_object_begin (w );
792+ spdk_json_write_named_string (w , "method" , "bdev_ocf_start_cache" );
793+
794+ spdk_json_write_named_object_begin (w , "params" );
795+ spdk_json_write_named_string (w , "cache_name" , ocf_cache_get_name (cache ));
796+ spdk_json_write_named_string (w , "base_name" , cache_ctx -> base .name );
797+ spdk_json_write_named_string (w , "cache_mode" ,
798+ vbdev_ocf_cachemode_get_name (ocf_cache_get_mode (cache )));
799+ spdk_json_write_named_uint32 (w , "cache_line_size" , ocf_cache_get_line_size (cache ));
800+ spdk_json_write_object_end (w );
801+
802+ spdk_json_write_object_end (w );
803+ }
804+
805+ static int
806+ _module_config_json_core_visitor (ocf_core_t core , void * ctx )
807+ {
808+ struct spdk_json_write_ctx * w = ctx ;
809+ struct vbdev_ocf_core * core_ctx = ocf_core_get_priv (core );
810+
811+ SPDK_DEBUGLOG (vbdev_ocf , "OCF core '%s': module config visit\n" , ocf_core_get_name (core ));
812+
813+ if (!core_ctx ) {
814+ /* Skip this core. If there is no context, it means that this core
815+ * was added from metadata during cache load and not manually by RPC call. */
816+ return 0 ;
817+ }
818+
819+ dump_core_config (w , core_ctx );
820+
821+ return 0 ;
822+ }
823+
824+ static int
825+ _module_config_json_cache_visitor (ocf_cache_t cache , void * ctx )
826+ {
827+ struct spdk_json_write_ctx * w = ctx ;
828+
829+ SPDK_DEBUGLOG (vbdev_ocf , "OCF cache '%s': module config visit\n" , ocf_cache_get_name (cache ));
830+
831+ dump_cache_config (w , cache );
832+
833+ return ocf_core_visit (cache , _module_config_json_core_visitor , w , false);
834+ }
835+
836+ static int
837+ vbdev_ocf_module_config_json (struct spdk_json_write_ctx * w )
838+ {
839+ struct vbdev_ocf_core * core_ctx ;
840+ int rc ;
841+
842+ SPDK_DEBUGLOG (vbdev_ocf , "OCF: generating current module configuration\n" );
843+
844+ vbdev_ocf_foreach_core_in_waitlist (core_ctx ) {
845+ dump_core_config (w , core_ctx );
846+ }
847+
848+ if ((rc = ocf_mngt_cache_visit (vbdev_ocf_ctx , _module_config_json_cache_visitor , w ))) {
849+ SPDK_ERRLOG ("OCF: failed to iterate over bdevs: %s\n" , spdk_strerror (- rc ));
850+ return rc ;
851+ }
852+
853+ return 0 ;
854+ }
855+
769856static void
770857_destruct_core_detach_cb (ocf_core_t core , void * cb_arg , int error )
771858{
@@ -966,11 +1053,52 @@ vbdev_ocf_fn_get_io_channel(void *ctx) // ctx == ocf_vbdev.ctxt
9661053static int
9671054vbdev_ocf_fn_dump_info_json (void * ctx , struct spdk_json_write_ctx * w )
9681055{
1056+ ocf_core_t core = ctx ;
1057+ ocf_cache_t cache = ocf_core_get_cache (core );
1058+ struct vbdev_ocf_core * core_ctx = ocf_core_get_priv (core );
1059+ struct vbdev_ocf_cache * cache_ctx = ocf_cache_get_priv (cache );
1060+
1061+ SPDK_DEBUGLOG (vbdev_ocf , "OCF vbdev '%s': dumping driver specific info\n" , ocf_core_get_name (core ));
1062+
1063+ spdk_json_write_named_object_begin (w , "ocf" );
1064+ spdk_json_write_named_string (w , "name" , ocf_core_get_name (core ));
1065+ spdk_json_write_named_string (w , "base_name" , core_ctx ? core_ctx -> base .name : "" );
1066+
1067+ spdk_json_write_named_object_begin (w , "cache" );
1068+ spdk_json_write_named_string (w , "name" , ocf_cache_get_name (cache ));
1069+ spdk_json_write_named_string (w , "base_name" , cache_ctx -> base .name );
1070+ spdk_json_write_named_string (w , "cache_mode" ,
1071+ vbdev_ocf_cachemode_get_name (ocf_cache_get_mode (cache )));
1072+ spdk_json_write_named_uint32 (w , "cache_line_size" , ocf_cache_get_line_size (cache ));
1073+ spdk_json_write_object_end (w );
1074+
1075+ spdk_json_write_object_end (w );
1076+
9691077 return 0 ;
9701078}
9711079
9721080static void
973- vbdev_ocf_fn_write_config_json (struct spdk_bdev * bdev , struct spdk_json_write_ctx * w )
1081+ vbdev_ocf_fn_dump_device_stat_json (void * ctx , struct spdk_json_write_ctx * w )
1082+ {
1083+ ocf_core_t core = ctx ;
1084+ struct vbdev_ocf_stats stats ;
1085+ int rc ;
1086+
1087+ SPDK_DEBUGLOG (vbdev_ocf , "OCF core '%s': collecting statistics\n" , ocf_core_get_name (core ));
1088+
1089+ if ((rc = vbdev_ocf_stats_core_get (core , & stats ))) {
1090+ SPDK_ERRLOG ("OCF core '%s': failed to collect statistics (OCF error: %d)\n" ,
1091+ ocf_core_get_name (core ), rc );
1092+ return ;
1093+ }
1094+
1095+ vbdev_ocf_stats_write_json (w , & stats );
1096+ }
1097+
1098+ /* Do not define this function to not reset OCF stats when resetting exposed bdev's stats.
1099+ * Let the user reset OCF stats independently by calling bdev_ocf_reset_stats RPC. */
1100+ static void
1101+ vbdev_ocf_fn_reset_device_stat (void * ctx )
9741102{
9751103}
9761104
0 commit comments