Branch data Line data Source code
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 : 3 : free_rpc_set_vfu_path(struct rpc_set_vfu_path *req) 26 : : { 27 : 3 : free(req->path); 28 : 3 : } 29 : : 30 : : static void 31 : 3 : rpc_vfu_set_base_path(struct spdk_jsonrpc_request *request, 32 : : const struct spdk_json_val *params) 33 : : { 34 : 3 : struct rpc_set_vfu_path req = {0}; 35 : : int rc; 36 : : 37 [ - + ]: 3 : if (spdk_json_decode_object(params, rpc_set_vfu_path_decode, 38 : : SPDK_COUNTOF(rpc_set_vfu_path_decode), 39 : : &req)) { 40 : 0 : SPDK_ERRLOG("spdk_json_decode_object failed\n"); 41 : 0 : rc = -EINVAL; 42 : 0 : goto invalid; 43 : : } 44 : : 45 : 3 : rc = spdk_vfu_set_socket_path(req.path); 46 [ - + ]: 3 : if (rc < 0) { 47 : 0 : goto invalid; 48 : : } 49 : 3 : free_rpc_set_vfu_path(&req); 50 : : 51 : 3 : spdk_jsonrpc_send_bool_response(request, true); 52 : 3 : return; 53 : : 54 : 0 : invalid: 55 : 0 : free_rpc_set_vfu_path(&req); 56 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS, 57 : : spdk_strerror(-rc)); 58 : : } 59 : 405 : SPDK_RPC_REGISTER("vfu_tgt_set_base_path", rpc_vfu_set_base_path, 60 : : SPDK_RPC_RUNTIME)