module/raid: show raid_bdev details in bdev_raid_get_bdevs rpc

Change-Id: I30a78b63c5ecc988e2a267d58716ea79f849789a
Signed-off-by: Artur Paszkiewicz <artur.paszkiewicz@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/14508
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Krzysztof Karas <krzysztof.karas@intel.com>
Reviewed-by: Konrad Sztyber <konrad.sztyber@intel.com>
Reviewed-by: Aleksey Marchuk <alexeymar@nvidia.com>
Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
Community-CI: Mellanox Build Bot
This commit is contained in:
Artur Paszkiewicz 2022-09-01 15:47:57 +02:00 committed by Konrad Sztyber
parent 95fd6cb455
commit ec6d94b674
9 changed files with 93 additions and 57 deletions

View File

@ -57,6 +57,8 @@ names with this option to restrict allowed RPCs to only that list.
Added spdk_rpc_set_allowlist to restrict allowed RPCs to the specified list. Added spdk_rpc_set_allowlist to restrict allowed RPCs to the specified list.
Changed `bdev_raid_get_bdevs` RPC output format to include raid_bdev details.
### bdevperf ### bdevperf
Promoted the application to example to match similar programs: fio_plugin and perf. Promoted the application to example to match similar programs: fio_plugin and perf.

View File

@ -9496,7 +9496,7 @@ Example response:
### bdev_raid_get_bdevs {#rpc_bdev_raid_get_bdevs} ### bdev_raid_get_bdevs {#rpc_bdev_raid_get_bdevs}
This is used to list all the raid bdev names based on the input category requested. Category should be one This is used to list all the raid bdev details based on the input category requested. Category should be one
of 'all', 'online', 'configuring' or 'offline'. 'all' means all the raid bdevs whether they are online or of 'all', 'online', 'configuring' or 'offline'. 'all' means all the raid bdevs whether they are online or
configuring or offline. 'online' is the raid bdev which is registered with bdev layer. 'configuring' is configuring or offline. 'online' is the raid bdev which is registered with bdev layer. 'configuring' is
the raid bdev which does not have full configuration discovered yet. 'offline' is the raid bdev which is the raid bdev which does not have full configuration discovered yet. 'offline' is the raid bdev which is
@ -9531,7 +9531,30 @@ Example response:
"jsonrpc": "2.0", "jsonrpc": "2.0",
"id": 1, "id": 1,
"result": [ "result": [
"Raid0" {
"name": "RaidBdev0",
"strip_size_kb": 128,
"state": "online",
"raid_level": "raid0",
"num_base_bdevs": 2,
"num_base_bdevs_discovered": 2,
"base_bdevs_list": [
"malloc0",
"malloc1"
]
},
{
"name": "RaidBdev1",
"strip_size_kb": 128,
"state": "configuring",
"raid_level": "raid0",
"num_base_bdevs": 2,
"num_base_bdevs_discovered": 1,
"base_bdevs_list": [
"malloc2",
null
]
}
] ]
} }
~~~ ~~~

View File

@ -604,27 +604,13 @@ raid_bdev_get_io_channel(void *ctxt)
return spdk_get_io_channel(raid_bdev); return spdk_get_io_channel(raid_bdev);
} }
/* void
* brief: raid_bdev_write_info_json(struct raid_bdev *raid_bdev, struct spdk_json_write_ctx *w)
* raid_bdev_dump_info_json is the function table pointer for raid bdev
* params:
* ctx - pointer to raid_bdev
* w - pointer to json context
* returns:
* 0 - success
* non zero - failure
*/
static int
raid_bdev_dump_info_json(void *ctx, struct spdk_json_write_ctx *w)
{ {
struct raid_bdev *raid_bdev = ctx;
struct raid_base_bdev_info *base_info; struct raid_base_bdev_info *base_info;
SPDK_DEBUGLOG(bdev_raid, "raid_bdev_dump_config_json\n");
assert(raid_bdev != NULL); assert(raid_bdev != NULL);
/* Dump the raid bdev configuration related information */
spdk_json_write_named_object_begin(w, "raid");
spdk_json_write_named_uint32(w, "strip_size_kb", raid_bdev->strip_size_kb); spdk_json_write_named_uint32(w, "strip_size_kb", raid_bdev->strip_size_kb);
spdk_json_write_named_string(w, "state", raid_bdev_state_to_str(raid_bdev->state)); spdk_json_write_named_string(w, "state", raid_bdev_state_to_str(raid_bdev->state));
spdk_json_write_named_string(w, "raid_level", raid_bdev_level_to_str(raid_bdev->level)); spdk_json_write_named_string(w, "raid_level", raid_bdev_level_to_str(raid_bdev->level));
@ -640,6 +626,28 @@ raid_bdev_dump_info_json(void *ctx, struct spdk_json_write_ctx *w)
} }
} }
spdk_json_write_array_end(w); spdk_json_write_array_end(w);
}
/*
* brief:
* raid_bdev_dump_info_json is the function table pointer for raid bdev
* params:
* ctx - pointer to raid_bdev
* w - pointer to json context
* returns:
* 0 - success
* non zero - failure
*/
static int
raid_bdev_dump_info_json(void *ctx, struct spdk_json_write_ctx *w)
{
struct raid_bdev *raid_bdev = ctx;
SPDK_DEBUGLOG(bdev_raid, "raid_bdev_dump_config_json\n");
/* Dump the raid bdev configuration related information */
spdk_json_write_named_object_begin(w, "raid");
raid_bdev_write_info_json(raid_bdev, w);
spdk_json_write_object_end(w); spdk_json_write_object_end(w);
return 0; return 0;

View File

@ -171,6 +171,7 @@ enum raid_level raid_bdev_str_to_level(const char *str);
const char *raid_bdev_level_to_str(enum raid_level level); const char *raid_bdev_level_to_str(enum raid_level level);
enum raid_bdev_state raid_bdev_str_to_state(const char *str); enum raid_bdev_state raid_bdev_str_to_state(const char *str);
const char *raid_bdev_state_to_str(enum raid_bdev_state state); const char *raid_bdev_state_to_str(enum raid_bdev_state state);
void raid_bdev_write_info_json(struct raid_bdev *raid_bdev, struct spdk_json_write_ctx *w);
/* /*
* RAID module descriptor * RAID module descriptor

View File

@ -87,7 +87,10 @@ rpc_bdev_raid_get_bdevs(struct spdk_jsonrpc_request *request,
/* Get raid bdev list based on the category requested */ /* Get raid bdev list based on the category requested */
TAILQ_FOREACH(raid_bdev, &g_raid_bdev_list, global_link) { TAILQ_FOREACH(raid_bdev, &g_raid_bdev_list, global_link) {
if (raid_bdev->state == state || state == RAID_BDEV_STATE_MAX) { if (raid_bdev->state == state || state == RAID_BDEV_STATE_MAX) {
spdk_json_write_string(w, raid_bdev->bdev.name); spdk_json_write_object_begin(w);
spdk_json_write_named_string(w, "name", raid_bdev->bdev.name);
raid_bdev_write_info_json(raid_bdev, w);
spdk_json_write_object_end(w);
} }
} }
spdk_json_write_array_end(w); spdk_json_write_array_end(w);

View File

@ -374,7 +374,7 @@ def bdev_raid_get_bdevs(client, category):
category: any one of all or online or configuring or offline category: any one of all or online or configuring or offline
Returns: Returns:
List of raid bdev names List of raid bdev details
""" """
params = {'category': category} params = {'category': category}
return client.call('bdev_raid_get_bdevs', params) return client.call('bdev_raid_get_bdevs', params)

View File

@ -2010,11 +2010,11 @@ Format: 'user:u1 secret:s1 muser:mu1 msecret:ms1,user:u2 secret:s2 muser:mu2 mse
p.set_defaults(func=bdev_lvol_get_lvstores) p.set_defaults(func=bdev_lvol_get_lvstores)
def bdev_raid_get_bdevs(args): def bdev_raid_get_bdevs(args):
print_array(rpc.bdev.bdev_raid_get_bdevs(args.client, print_json(rpc.bdev.bdev_raid_get_bdevs(args.client,
category=args.category)) category=args.category))
p = subparsers.add_parser('bdev_raid_get_bdevs', p = subparsers.add_parser('bdev_raid_get_bdevs',
help="""This is used to list all the raid bdev names based on the input category help="""This is used to list all the raid bdev details based on the input category
requested. Category should be one of 'all', 'online', 'configuring' or 'offline'. 'all' means all the raid bdevs whether requested. Category should be one of 'all', 'online', 'configuring' or 'offline'. 'all' means all the raid bdevs whether
they are online or configuring or offline. 'online' is the raid bdev which is registered with bdev layer. 'configuring' they are online or configuring or offline. 'online' is the raid bdev which is registered with bdev layer. 'configuring'
is the raid bdev which does not have full configuration discovered yet. 'offline' is the raid bdev which is not registered is the raid bdev which does not have full configuration discovered yet. 'offline' is the raid bdev which is not registered

View File

@ -90,7 +90,7 @@ function raid_function_test() {
waitforlisten $raid_pid $rpc_server waitforlisten $raid_pid $rpc_server
configure_raid_bdev $raid_level configure_raid_bdev $raid_level
raid_bdev=$($rpc_py bdev_raid_get_bdevs online | cut -d ' ' -f 1) raid_bdev=$($rpc_py bdev_raid_get_bdevs online | jq -r '.[0]["name"] | select(.)')
if [ $raid_bdev = "" ]; then if [ $raid_bdev = "" ]; then
echo "No raid0 device in SPDK app" echo "No raid0 device in SPDK app"
return 1 return 1
@ -133,7 +133,7 @@ function raid_state_function_test() {
# Step1: create a RAID bdev with no base bdevs # Step1: create a RAID bdev with no base bdevs
# Expect state: CONFIGURING # Expect state: CONFIGURING
$rpc_py bdev_raid_create -z 64 -r $raid_level -b "$base_bdev1 $base_bdev2" -n $raid_bdev_name $rpc_py bdev_raid_create -z 64 -r $raid_level -b "$base_bdev1 $base_bdev2" -n $raid_bdev_name
raid_bdev=$($rpc_py bdev_raid_get_bdevs configuring | cut -d ' ' -f 1) raid_bdev=$($rpc_py bdev_raid_get_bdevs configuring | jq -r '.[0]["name"]')
if [ $raid_bdev != $raid_bdev_name ]; then if [ $raid_bdev != $raid_bdev_name ]; then
echo "No raid device in SPDK app" echo "No raid device in SPDK app"
return 1 return 1
@ -147,7 +147,7 @@ function raid_state_function_test() {
$rpc_py bdev_raid_create -z 64 -r $raid_level -b "$base_bdev1 $base_bdev2" -n $raid_bdev_name $rpc_py bdev_raid_create -z 64 -r $raid_level -b "$base_bdev1 $base_bdev2" -n $raid_bdev_name
$rpc_py bdev_malloc_create 32 512 -b $base_bdev1 $rpc_py bdev_malloc_create 32 512 -b $base_bdev1
waitforbdev $base_bdev1 waitforbdev $base_bdev1
raid_bdev=$($rpc_py bdev_raid_get_bdevs configuring | cut -d ' ' -f 1) raid_bdev=$($rpc_py bdev_raid_get_bdevs configuring | jq -r '.[0]["name"]')
if [ $raid_bdev != $raid_bdev_name ]; then if [ $raid_bdev != $raid_bdev_name ]; then
echo "$raid_bdev_name is not in CONFIGURING state" echo "$raid_bdev_name is not in CONFIGURING state"
$rpc_py bdev_malloc_delete $base_bdev1 $rpc_py bdev_malloc_delete $base_bdev1
@ -163,7 +163,7 @@ function raid_state_function_test() {
$rpc_py bdev_raid_create -z 64 -r $raid_level -b "$base_bdev1 $base_bdev2" -n $raid_bdev_name $rpc_py bdev_raid_create -z 64 -r $raid_level -b "$base_bdev1 $base_bdev2" -n $raid_bdev_name
$rpc_py bdev_malloc_create 32 512 -b $base_bdev2 $rpc_py bdev_malloc_create 32 512 -b $base_bdev2
waitforbdev $base_bdev2 waitforbdev $base_bdev2
raid_bdev=$($rpc_py bdev_raid_get_bdevs online | cut -d ' ' -f 1) raid_bdev=$($rpc_py bdev_raid_get_bdevs online | jq -r '.[0]["name"]')
if [ $raid_bdev != $raid_bdev_name ]; then if [ $raid_bdev != $raid_bdev_name ]; then
echo "$raid_bdev_name is not in ONLINE state" echo "$raid_bdev_name is not in ONLINE state"
$rpc_py bdev_malloc_delete $base_bdev1 $rpc_py bdev_malloc_delete $base_bdev1
@ -175,7 +175,7 @@ function raid_state_function_test() {
# Step4: delete one base bdev from the RAID bdev # Step4: delete one base bdev from the RAID bdev
# Expect state: OFFLINE # Expect state: OFFLINE
$rpc_py bdev_malloc_delete $base_bdev2 $rpc_py bdev_malloc_delete $base_bdev2
raid_bdev=$($rpc_py bdev_raid_get_bdevs offline | cut -d ' ' -f 1) raid_bdev=$($rpc_py bdev_raid_get_bdevs offline | jq -r '.[0]["name"]')
if [ $raid_bdev != $raid_bdev_name ]; then if [ $raid_bdev != $raid_bdev_name ]; then
echo "$raid_bdev_name is not in OFFLINE state" echo "$raid_bdev_name is not in OFFLINE state"
$rpc_py bdev_malloc_delete $base_bdev1 $rpc_py bdev_malloc_delete $base_bdev1
@ -186,7 +186,7 @@ function raid_state_function_test() {
# Step5: delete last base bdev from the RAID bdev # Step5: delete last base bdev from the RAID bdev
# Expect state: removed from system # Expect state: removed from system
$rpc_py bdev_malloc_delete $base_bdev1 $rpc_py bdev_malloc_delete $base_bdev1
raid_bdev=$($rpc_py bdev_raid_get_bdevs all | cut -d ' ' -f 1) raid_bdev=$($rpc_py bdev_raid_get_bdevs all | jq -r '.[0]["name"] | select(.)')
if [ -n "$raid_bdev" ]; then if [ -n "$raid_bdev" ]; then
echo "$raid_bdev_name is not removed" echo "$raid_bdev_name is not removed"
$rpc_py bdev_raid_delete $raid_bdev_name $rpc_py bdev_raid_delete $raid_bdev_name

View File

@ -101,6 +101,7 @@ DEFINE_STUB(spdk_json_write_name, int, (struct spdk_json_write_ctx *w, const cha
DEFINE_STUB(spdk_json_write_object_begin, int, (struct spdk_json_write_ctx *w), 0); DEFINE_STUB(spdk_json_write_object_begin, int, (struct spdk_json_write_ctx *w), 0);
DEFINE_STUB(spdk_json_write_named_object_begin, int, (struct spdk_json_write_ctx *w, DEFINE_STUB(spdk_json_write_named_object_begin, int, (struct spdk_json_write_ctx *w,
const char *name), 0); const char *name), 0);
DEFINE_STUB(spdk_json_write_string, int, (struct spdk_json_write_ctx *w, const char *val), 0);
DEFINE_STUB(spdk_json_write_object_end, int, (struct spdk_json_write_ctx *w), 0); DEFINE_STUB(spdk_json_write_object_end, int, (struct spdk_json_write_ctx *w), 0);
DEFINE_STUB(spdk_json_write_array_begin, int, (struct spdk_json_write_ctx *w), 0); DEFINE_STUB(spdk_json_write_array_begin, int, (struct spdk_json_write_ctx *w), 0);
DEFINE_STUB(spdk_json_write_array_end, int, (struct spdk_json_write_ctx *w), 0); DEFINE_STUB(spdk_json_write_array_end, int, (struct spdk_json_write_ctx *w), 0);
@ -391,19 +392,21 @@ spdk_sprintf_alloc(const char *format, ...)
int int
spdk_json_write_named_uint32(struct spdk_json_write_ctx *w, const char *name, uint32_t val) spdk_json_write_named_uint32(struct spdk_json_write_ctx *w, const char *name, uint32_t val)
{ {
struct rpc_bdev_raid_create *req = g_rpc_req; if (!g_test_multi_raids) {
if (strcmp(name, "strip_size_kb") == 0) { struct rpc_bdev_raid_create *req = g_rpc_req;
CU_ASSERT(req->strip_size_kb == val); if (strcmp(name, "strip_size_kb") == 0) {
} else if (strcmp(name, "blocklen_shift") == 0) { CU_ASSERT(req->strip_size_kb == val);
CU_ASSERT(spdk_u32log2(g_block_len) == val); } else if (strcmp(name, "blocklen_shift") == 0) {
} else if (strcmp(name, "num_base_bdevs") == 0) { CU_ASSERT(spdk_u32log2(g_block_len) == val);
CU_ASSERT(req->base_bdevs.num_base_bdevs == val); } else if (strcmp(name, "num_base_bdevs") == 0) {
} else if (strcmp(name, "state") == 0) { CU_ASSERT(req->base_bdevs.num_base_bdevs == val);
CU_ASSERT(val == RAID_BDEV_STATE_ONLINE); } else if (strcmp(name, "state") == 0) {
} else if (strcmp(name, "destruct_called") == 0) { CU_ASSERT(val == RAID_BDEV_STATE_ONLINE);
CU_ASSERT(val == 0); } else if (strcmp(name, "destruct_called") == 0) {
} else if (strcmp(name, "num_base_bdevs_discovered") == 0) { CU_ASSERT(val == 0);
CU_ASSERT(req->base_bdevs.num_base_bdevs == val); } else if (strcmp(name, "num_base_bdevs_discovered") == 0) {
CU_ASSERT(req->base_bdevs.num_base_bdevs == val);
}
} }
return 0; return 0;
} }
@ -411,9 +414,17 @@ spdk_json_write_named_uint32(struct spdk_json_write_ctx *w, const char *name, ui
int int
spdk_json_write_named_string(struct spdk_json_write_ctx *w, const char *name, const char *val) spdk_json_write_named_string(struct spdk_json_write_ctx *w, const char *name, const char *val)
{ {
struct rpc_bdev_raid_create *req = g_rpc_req; if (g_test_multi_raids) {
if (strcmp(name, "raid_level") == 0) { if (strcmp(name, "name") == 0) {
CU_ASSERT(strcmp(val, raid_bdev_level_to_str(req->level)) == 0); g_get_raids_output[g_get_raids_count] = strdup(val);
SPDK_CU_ASSERT_FATAL(g_get_raids_output[g_get_raids_count] != NULL);
g_get_raids_count++;
}
} else {
struct rpc_bdev_raid_create *req = g_rpc_req;
if (strcmp(name, "raid_level") == 0) {
CU_ASSERT(strcmp(val, raid_bdev_level_to_str(req->level)) == 0);
}
} }
return 0; return 0;
} }
@ -518,18 +529,6 @@ spdk_jsonrpc_begin_result(struct spdk_jsonrpc_request *request)
return (void *)1; return (void *)1;
} }
int
spdk_json_write_string(struct spdk_json_write_ctx *w, const char *val)
{
if (g_test_multi_raids) {
g_get_raids_output[g_get_raids_count] = strdup(val);
SPDK_CU_ASSERT_FATAL(g_get_raids_output[g_get_raids_count] != NULL);
g_get_raids_count++;
}
return 0;
}
void void
spdk_jsonrpc_send_error_response(struct spdk_jsonrpc_request *request, spdk_jsonrpc_send_error_response(struct spdk_jsonrpc_request *request,
int error_code, const char *msg) int error_code, const char *msg)