Skip to content

Commit 46b141d

Browse files
author
Rafal Stefanowski
committed
Implement info ops + tests
- current module config - generic bdev info - generic bdev stats Change-Id: If63774a399902caaa50c09ef2e89a9837e5db95a Signed-off-by: Rafal Stefanowski <rafal.stefanowski@huawei.com>
1 parent 53325c6 commit 46b141d

File tree

6 files changed

+646
-6
lines changed

6 files changed

+646
-6
lines changed

module/bdev/ocf/vbdev_ocf.c

Lines changed: 134 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,18 @@ static void vbdev_ocf_module_fini(void);
2424
static int vbdev_ocf_module_get_ctx_size(void);
2525
static void vbdev_ocf_module_examine_config(struct spdk_bdev *bdev);
2626
static 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

2829
struct 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
};
3840
SPDK_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_
4244
static bool vbdev_ocf_fn_io_type_supported(void *ctx, enum spdk_bdev_io_type);
4345
static struct spdk_io_channel *vbdev_ocf_fn_get_io_channel(void *ctx);
4446
static 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

4750
struct 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

5860
static 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+
769856
static 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
9661053
static int
9671054
vbdev_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

9721080
static 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

test/ocf/management/info_dump.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/usr/bin/env bash
2+
3+
#
4+
# SPDX-License-Identifier: BSD-3-Clause
5+
# Copyright (C) 2025 Huawei Technologies
6+
# All rights reserved.
7+
#
8+
9+
curdir=$(dirname $(readlink -f "${BASH_SOURCE[0]}"))
10+
rootdir=$(readlink -f "$curdir/../../..")
11+
source "$rootdir/test/ocf/common.sh"
12+
13+
start_spdk
14+
create_caches
15+
$rpc_py bdev_ocf_start_cache Ocf_cache1 Cache_dev1 --no-load
16+
$rpc_py bdev_ocf_start_cache Ocf_cache2 Cache_dev2 --no-load
17+
$rpc_py bdev_ocf_start_cache Ocf_cache3 Cache_dev3 --no-load --cache-mode pt --cache-line-size 64
18+
create_cores
19+
add_cores
20+
21+
# No device for first cache.
22+
$rpc_py bdev_malloc_delete Cache_dev1
23+
# No device for first core.
24+
for i in {1..3}; do
25+
$rpc_py bdev_malloc_delete Core_dev$i-1
26+
done
27+
# No device for first core in wait list.
28+
for i in {2..3}; do
29+
$rpc_py bdev_malloc_create -b Core_dev_waitlist$i 200 512
30+
done
31+
for i in {1..3}; do
32+
$rpc_py bdev_ocf_add_core Ocf_core_waitlist$i Core_dev_waitlist$i Ocf_cache_none
33+
done
34+
$rpc_py bdev_ocf_set_cachemode Ocf_cache2 wb
35+
36+
$rpc_py bdev_ocf_get_bdevs | jq -e .
37+
38+
diff <($rpc_py bdev_ocf_get_bdevs | jq -e .) <(jq -e . "$curdir/info_dump_get_bdevs.json")
39+
40+
diff <($rpc_py bdev_get_bdevs | jq -e '.[].driver_specific.ocf | select(. != null)') \
41+
<(jq -e . "$curdir/info_dump_driver_specific.json")
42+
43+
diff <($rpc_py save_subsystem_config -n bdev | jq -e '.config[] | select(.method|test("bdev_ocf_"))') \
44+
<(jq -e . "$curdir/info_dump_save_config.json")
45+
46+
stop_spdk
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
{
2+
"name": "Ocf_core1-2",
3+
"base_name": "Core_dev1-2",
4+
"cache": {
5+
"name": "Ocf_cache1",
6+
"base_name": "Cache_dev1",
7+
"cache_mode": "wt",
8+
"cache_line_size": 4096
9+
}
10+
}
11+
{
12+
"name": "Ocf_core1-3",
13+
"base_name": "Core_dev1-3",
14+
"cache": {
15+
"name": "Ocf_cache1",
16+
"base_name": "Cache_dev1",
17+
"cache_mode": "wt",
18+
"cache_line_size": 4096
19+
}
20+
}
21+
{
22+
"name": "Ocf_core2-2",
23+
"base_name": "Core_dev2-2",
24+
"cache": {
25+
"name": "Ocf_cache2",
26+
"base_name": "Cache_dev2",
27+
"cache_mode": "wb",
28+
"cache_line_size": 4096
29+
}
30+
}
31+
{
32+
"name": "Ocf_core2-3",
33+
"base_name": "Core_dev2-3",
34+
"cache": {
35+
"name": "Ocf_cache2",
36+
"base_name": "Cache_dev2",
37+
"cache_mode": "wb",
38+
"cache_line_size": 4096
39+
}
40+
}
41+
{
42+
"name": "Ocf_core3-2",
43+
"base_name": "Core_dev3-2",
44+
"cache": {
45+
"name": "Ocf_cache3",
46+
"base_name": "Cache_dev3",
47+
"cache_mode": "pt",
48+
"cache_line_size": 65536
49+
}
50+
}
51+
{
52+
"name": "Ocf_core3-3",
53+
"base_name": "Core_dev3-3",
54+
"cache": {
55+
"name": "Ocf_cache3",
56+
"base_name": "Cache_dev3",
57+
"cache_mode": "pt",
58+
"cache_line_size": 65536
59+
}
60+
}

0 commit comments

Comments
 (0)