2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2022-11-01 20:26:26 +00:00
|
|
|
* Copyright (C) 2016 Intel Corporation.
|
2016-07-20 18:16:23 +00:00
|
|
|
* All rights reserved.
|
2021-10-29 13:48:49 +00:00
|
|
|
* Copyright (c) 2021 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
|
2016-07-20 18:16:23 +00:00
|
|
|
*/
|
|
|
|
|
2017-07-13 04:08:53 +00:00
|
|
|
#include "bdev_malloc.h"
|
2016-07-20 18:16:23 +00:00
|
|
|
#include "spdk/rpc.h"
|
2018-06-15 07:58:57 +00:00
|
|
|
#include "spdk/string.h"
|
2020-10-06 16:16:26 +00:00
|
|
|
#include "spdk/log.h"
|
2016-11-07 22:10:28 +00:00
|
|
|
|
2017-10-06 22:00:28 +00:00
|
|
|
static void
|
2022-10-23 12:46:36 +00:00
|
|
|
free_rpc_construct_malloc(struct malloc_bdev_opts *r)
|
2017-10-06 22:00:28 +00:00
|
|
|
{
|
|
|
|
free(r->name);
|
2022-10-23 12:39:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
decode_mdisk_uuid(const struct spdk_json_val *val, void *out)
|
|
|
|
{
|
|
|
|
char *str = NULL;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = spdk_json_decode_string(val, &str);
|
|
|
|
if (rc == 0) {
|
|
|
|
rc = spdk_uuid_parse(out, str);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(str);
|
|
|
|
return rc;
|
2017-10-06 22:00:28 +00:00
|
|
|
}
|
|
|
|
|
2016-07-20 18:16:23 +00:00
|
|
|
static const struct spdk_json_object_decoder rpc_construct_malloc_decoders[] = {
|
2022-10-23 12:46:36 +00:00
|
|
|
{"name", offsetof(struct malloc_bdev_opts, name), spdk_json_decode_string, true},
|
|
|
|
{"uuid", offsetof(struct malloc_bdev_opts, uuid), decode_mdisk_uuid, true},
|
|
|
|
{"num_blocks", offsetof(struct malloc_bdev_opts, num_blocks), spdk_json_decode_uint64},
|
|
|
|
{"block_size", offsetof(struct malloc_bdev_opts, block_size), spdk_json_decode_uint32},
|
|
|
|
{"optimal_io_boundary", offsetof(struct malloc_bdev_opts, optimal_io_boundary), spdk_json_decode_uint32, true},
|
2022-10-24 13:26:19 +00:00
|
|
|
{"md_size", offsetof(struct malloc_bdev_opts, md_size), spdk_json_decode_uint32, true},
|
|
|
|
{"md_interleave", offsetof(struct malloc_bdev_opts, md_interleave), spdk_json_decode_bool, true},
|
2022-10-26 05:58:52 +00:00
|
|
|
{"dif_type", offsetof(struct malloc_bdev_opts, dif_type), spdk_json_decode_int32, true},
|
|
|
|
{"dif_is_head_of_md", offsetof(struct malloc_bdev_opts, dif_is_head_of_md), spdk_json_decode_bool, true},
|
2016-07-20 18:16:23 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-05-10 07:33:50 +00:00
|
|
|
rpc_bdev_malloc_create(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2016-07-20 18:16:23 +00:00
|
|
|
{
|
2022-10-23 12:46:36 +00:00
|
|
|
struct malloc_bdev_opts req = {NULL};
|
2016-07-20 18:16:23 +00:00
|
|
|
struct spdk_json_write_ctx *w;
|
2016-10-25 23:19:53 +00:00
|
|
|
struct spdk_bdev *bdev;
|
2019-07-01 11:05:24 +00:00
|
|
|
int rc = 0;
|
2016-07-20 18:16:23 +00:00
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_construct_malloc_decoders,
|
2017-03-03 20:44:04 +00:00
|
|
|
SPDK_COUNTOF(rpc_construct_malloc_decoders),
|
2016-07-20 18:16:23 +00:00
|
|
|
&req)) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(bdev_malloc, "spdk_json_decode_object failed\n");
|
2019-07-01 11:05:24 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
"spdk_json_decode_object failed");
|
|
|
|
goto cleanup;
|
|
|
|
}
|
|
|
|
|
2022-10-23 12:46:36 +00:00
|
|
|
rc = create_malloc_disk(&bdev, &req);
|
2019-07-01 11:05:24 +00:00
|
|
|
if (rc) {
|
|
|
|
spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
|
|
|
|
goto cleanup;
|
2016-07-20 18:16:23 +00:00
|
|
|
}
|
|
|
|
|
2017-10-06 22:00:28 +00:00
|
|
|
free_rpc_construct_malloc(&req);
|
|
|
|
|
2017-06-29 20:37:39 +00:00
|
|
|
w = spdk_jsonrpc_begin_result(request);
|
2017-05-10 20:29:31 +00:00
|
|
|
spdk_json_write_string(w, spdk_bdev_get_name(bdev));
|
2017-06-29 20:37:39 +00:00
|
|
|
spdk_jsonrpc_end_result(request, w);
|
2016-07-20 18:16:23 +00:00
|
|
|
return;
|
|
|
|
|
2019-07-01 11:05:24 +00:00
|
|
|
cleanup:
|
2017-10-06 22:00:28 +00:00
|
|
|
free_rpc_construct_malloc(&req);
|
2016-07-20 18:16:23 +00:00
|
|
|
}
|
2020-05-10 07:33:50 +00:00
|
|
|
SPDK_RPC_REGISTER("bdev_malloc_create", rpc_bdev_malloc_create, SPDK_RPC_RUNTIME)
|
2018-06-15 07:58:57 +00:00
|
|
|
|
|
|
|
struct rpc_delete_malloc {
|
|
|
|
char *name;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
|
|
|
free_rpc_delete_malloc(struct rpc_delete_malloc *r)
|
|
|
|
{
|
|
|
|
free(r->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct spdk_json_object_decoder rpc_delete_malloc_decoders[] = {
|
|
|
|
{"name", offsetof(struct rpc_delete_malloc, name), spdk_json_decode_string},
|
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2020-05-10 07:33:50 +00:00
|
|
|
rpc_bdev_malloc_delete_cb(void *cb_arg, int bdeverrno)
|
2018-06-15 07:58:57 +00:00
|
|
|
{
|
|
|
|
struct spdk_jsonrpc_request *request = cb_arg;
|
|
|
|
|
2022-03-29 12:02:58 +00:00
|
|
|
if (bdeverrno == 0) {
|
|
|
|
spdk_jsonrpc_send_bool_response(request, true);
|
|
|
|
} else {
|
|
|
|
spdk_jsonrpc_send_error_response(request, bdeverrno, spdk_strerror(-bdeverrno));
|
|
|
|
}
|
2018-06-15 07:58:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2020-05-10 07:33:50 +00:00
|
|
|
rpc_bdev_malloc_delete(struct spdk_jsonrpc_request *request,
|
|
|
|
const struct spdk_json_val *params)
|
2018-06-15 07:58:57 +00:00
|
|
|
{
|
|
|
|
struct rpc_delete_malloc req = {NULL};
|
|
|
|
|
|
|
|
if (spdk_json_decode_object(params, rpc_delete_malloc_decoders,
|
|
|
|
SPDK_COUNTOF(rpc_delete_malloc_decoders),
|
|
|
|
&req)) {
|
2020-09-04 11:27:29 +00:00
|
|
|
SPDK_DEBUGLOG(bdev_malloc, "spdk_json_decode_object failed\n");
|
2019-07-01 11:05:24 +00:00
|
|
|
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
|
|
|
|
"spdk_json_decode_object failed");
|
|
|
|
goto cleanup;
|
2018-06-15 07:58:57 +00:00
|
|
|
}
|
|
|
|
|
2022-03-29 05:55:53 +00:00
|
|
|
delete_malloc_disk(req.name, rpc_bdev_malloc_delete_cb, request);
|
2018-06-15 07:58:57 +00:00
|
|
|
|
2019-07-01 11:05:24 +00:00
|
|
|
cleanup:
|
2018-06-15 07:58:57 +00:00
|
|
|
free_rpc_delete_malloc(&req);
|
|
|
|
}
|
2020-05-10 07:33:50 +00:00
|
|
|
SPDK_RPC_REGISTER("bdev_malloc_delete", rpc_bdev_malloc_delete, SPDK_RPC_RUNTIME)
|