1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2022 Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #include "spdk/bdev.h" 7 #include "spdk/log.h" 8 #include "spdk/rpc.h" 9 #include "spdk/env.h" 10 #include "spdk/string.h" 11 #include "spdk/util.h" 12 #include "spdk/thread.h" 13 14 #include "tgt_internal.h" 15 16 struct rpc_set_vfu_path { 17 char *path; 18 }; 19 20 static const struct spdk_json_object_decoder rpc_set_vfu_path_decode[] = { 21 {"path", offsetof(struct rpc_set_vfu_path, path), spdk_json_decode_string } 22 }; 23 24 static void 25 free_rpc_set_vfu_path(struct rpc_set_vfu_path *req) 26 { 27 free(req->path); 28 } 29 30 static void 31 rpc_vfu_set_base_path(struct spdk_jsonrpc_request *request, 32 const struct spdk_json_val *params) 33 { 34 struct rpc_set_vfu_path req = {0}; 35 int rc; 36 37 if (spdk_json_decode_object(params, rpc_set_vfu_path_decode, 38 SPDK_COUNTOF(rpc_set_vfu_path_decode), 39 &req)) { 40 SPDK_ERRLOG("spdk_json_decode_object failed\n"); 41 rc = -EINVAL; 42 goto invalid; 43 } 44 45 rc = spdk_vfu_set_socket_path(req.path); 46 if (rc < 0) { 47 goto invalid; 48 } 49 free_rpc_set_vfu_path(&req); 50 51 spdk_jsonrpc_send_bool_response(request, true); 52 return; 53 54 invalid: 55 free_rpc_set_vfu_path(&req); 56 spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, 57 spdk_strerror(-rc)); 58 } 59 SPDK_RPC_REGISTER("vfu_tgt_set_base_path", rpc_vfu_set_base_path, 60 SPDK_RPC_RUNTIME) 61