Spdk/lib/ublk/ublk_rpc.c
Yifan Bian a1944e0170 ublk: add ublk target creation and destruction
Add rpc methond for ublk target creation and destruction. Before to
add ublk device, need to initialize ublk target to create ublk
threads, corresponding an rpc methond to destroy ublk target is
also added. It will deinitialize ublk target and release all ublk
devices.

Signed-off-by: Yifan Bian <yifan.bian@intel.com>
Co-authored-by: Xiaodong Liu <xiaodong.liu@intel.com>
Change-Id: I5db0cf9cc68745440df999169aa1c61111010e02
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15962
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: Paul Luse <paul.e.luse@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Xiaodong Liu <xiaodong.liu@intel.com>
2023-01-20 07:48:25 +00:00

78 lines
2.1 KiB
C

/* SPDX-License-Identifier: BSD-3-Clause
* Copyright (C) 2022 Intel Corporation.
* All rights reserved.
*/
#include "spdk/string.h"
#include "spdk/env.h"
#include "spdk/rpc.h"
#include "spdk/util.h"
#include "spdk/log.h"
#include "ublk_internal.h"
struct rpc_ublk_create_target {
char *cpumask;
};
static const struct spdk_json_object_decoder rpc_ublk_create_target_decoders[] = {
{"cpumask", offsetof(struct rpc_ublk_create_target, cpumask), spdk_json_decode_string, true},
};
static void
free_rpc_ublk_create_target(struct rpc_ublk_create_target *req)
{
free(req->cpumask);
}
static void
rpc_ublk_create_target(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
{
int rc = 0;
struct rpc_ublk_create_target req = {};
if (params != NULL) {
if (spdk_json_decode_object(params, rpc_ublk_create_target_decoders,
SPDK_COUNTOF(rpc_ublk_create_target_decoders),
&req)) {
SPDK_ERRLOG("spdk_json_decode_object failed\n");
rc = -EINVAL;
goto invalid;
}
}
rc = ublk_create_target(req.cpumask);
if (rc != 0) {
goto invalid;
}
spdk_jsonrpc_send_bool_response(request, true);
free_rpc_ublk_create_target(&req);
return;
invalid:
SPDK_ERRLOG("Can't create ublk target: %s\n", spdk_strerror(-rc));
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, spdk_strerror(-rc));
free_rpc_ublk_create_target(&req);
}
SPDK_RPC_REGISTER("ublk_create_target", rpc_ublk_create_target, SPDK_RPC_RUNTIME)
static void
ublk_destroy_target_done(void *arg)
{
struct spdk_jsonrpc_request *req = arg;
spdk_jsonrpc_send_bool_response(req, true);
SPDK_NOTICELOG("ublk target has been destroyed\n");
}
static void
rpc_ublk_destroy_target(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
{
int rc = 0;
rc = ublk_destroy_target(ublk_destroy_target_done, request);
if (rc != 0) {
spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INTERNAL_ERROR, spdk_strerror(-rc));
SPDK_ERRLOG("Can't destroy ublk target: %s\n", spdk_strerror(-rc));
}
}
SPDK_RPC_REGISTER("ublk_destroy_target", rpc_ublk_destroy_target, SPDK_RPC_RUNTIME)