Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright (c) 2023 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3 : : */
4 : :
5 : : #include "spdk/stdinc.h"
6 : : #include "spdk/log.h"
7 : : #include "spdk/string.h"
8 : : #include "spdk/rpc.h"
9 : : #include "spdk/util.h"
10 : : #include "fsdev_aio.h"
11 : :
12 : : struct rpc_aio_create {
13 : : char *name;
14 : : char *root_path;
15 : : struct spdk_fsdev_aio_opts opts;
16 : : };
17 : :
18 : : static void
19 : 1 : free_rpc_aio_create(struct rpc_aio_create *req)
20 : : {
21 [ # # # # ]: 1 : free(req->name);
22 [ # # # # ]: 1 : free(req->root_path);
23 : 1 : }
24 : :
25 : : static const struct spdk_json_object_decoder rpc_aio_create_decoders[] = {
26 : : {"name", offsetof(struct rpc_aio_create, name), spdk_json_decode_string},
27 : : {"root_path", offsetof(struct rpc_aio_create, root_path), spdk_json_decode_string},
28 : : {"enable_xattr", offsetof(struct rpc_aio_create, opts.xattr_enabled), spdk_json_decode_bool, true},
29 : : {"enable_writeback_cache", offsetof(struct rpc_aio_create, opts.writeback_cache_enabled), spdk_json_decode_bool, true},
30 : : {"max_write", offsetof(struct rpc_aio_create, opts.max_write), spdk_json_decode_uint32, true},
31 : : {"skip_rw", offsetof(struct rpc_aio_create, opts.skip_rw), spdk_json_decode_bool, true},
32 : : };
33 : :
34 : : static void
35 : 1 : rpc_aio_create(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
36 : : {
37 : 1 : struct rpc_aio_create req = {};
38 : : struct spdk_json_write_ctx *w;
39 : 1 : struct spdk_fsdev *fsdev;
40 : : int rc;
41 : :
42 : 1 : spdk_fsdev_aio_get_default_opts(&req.opts);
43 : :
44 [ - + ]: 1 : if (spdk_json_decode_object(params, rpc_aio_create_decoders,
45 : : SPDK_COUNTOF(rpc_aio_create_decoders),
46 : : &req)) {
47 : 0 : SPDK_ERRLOG("spdk_json_decode_object failed\n");
48 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
49 : : "spdk_json_decode_object failed");
50 : :
51 : 0 : free_rpc_aio_create(&req);
52 : 0 : return;
53 : : }
54 : :
55 [ # # ]: 1 : rc = spdk_fsdev_aio_create(&fsdev, req.name, req.root_path, &req.opts);
56 [ - + ]: 1 : if (rc) {
57 : 0 : SPDK_ERRLOG("Failed to create aio %s: rc %d\n", req.name, rc);
58 : 0 : spdk_jsonrpc_send_error_response(request,
59 : : SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
60 [ # # ]: 0 : spdk_strerror(-rc));
61 : 0 : free_rpc_aio_create(&req);
62 : 0 : return;
63 : : }
64 : :
65 : 1 : w = spdk_jsonrpc_begin_result(request);
66 [ # # # # ]: 1 : spdk_json_write_string(w, fsdev->name);
67 : 1 : spdk_jsonrpc_end_result(request, w);
68 : 1 : free_rpc_aio_create(&req);
69 : 0 : }
70 : 2069 : SPDK_RPC_REGISTER("fsdev_aio_create", rpc_aio_create, SPDK_RPC_RUNTIME)
71 : :
72 : : struct rpc_aio_delete {
73 : : char *name;
74 : : };
75 : :
76 : : static const struct spdk_json_object_decoder rpc_aio_delete_decoders[] = {
77 : : {"name", offsetof(struct rpc_aio_delete, name), spdk_json_decode_string},
78 : : };
79 : :
80 : : static void
81 : 0 : rpc_aio_delete_cb(void *cb_arg, int fsdeverrno)
82 : : {
83 : 0 : struct spdk_jsonrpc_request *request = cb_arg;
84 : :
85 [ # # ]: 0 : if (fsdeverrno == 0) {
86 : 0 : spdk_jsonrpc_send_bool_response(request, true);
87 : 0 : } else {
88 [ # # ]: 0 : spdk_jsonrpc_send_error_response(request, fsdeverrno, spdk_strerror(-fsdeverrno));
89 : : }
90 : 0 : }
91 : :
92 : : static void
93 : 0 : rpc_aio_delete(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
94 : : {
95 : 0 : struct rpc_aio_delete req = {};
96 : :
97 [ # # ]: 0 : if (spdk_json_decode_object(params, rpc_aio_delete_decoders,
98 : : SPDK_COUNTOF(rpc_aio_delete_decoders),
99 : : &req)) {
100 : 0 : SPDK_ERRLOG("spdk_json_decode_object failed\n");
101 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
102 : : "spdk_json_decode_object failed");
103 : :
104 : 0 : free(req.name);
105 : 0 : return;
106 : : }
107 : :
108 : 0 : spdk_fsdev_aio_delete(req.name, rpc_aio_delete_cb, request);
109 : 0 : free(req.name);
110 : 0 : }
111 : 2069 : SPDK_RPC_REGISTER("fsdev_aio_delete", rpc_aio_delete, SPDK_RPC_RUNTIME)
|