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 : : };
32 : :
33 : : static void
34 : 1 : rpc_aio_create(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
35 : : {
36 : 1 : struct rpc_aio_create req = {};
37 : : struct spdk_json_write_ctx *w;
38 : 1 : struct spdk_fsdev *fsdev;
39 : : int rc;
40 : :
41 : 1 : spdk_fsdev_aio_get_default_opts(&req.opts);
42 : :
43 [ - + ]: 1 : if (spdk_json_decode_object(params, rpc_aio_create_decoders,
44 : : SPDK_COUNTOF(rpc_aio_create_decoders),
45 : : &req)) {
46 : 0 : SPDK_ERRLOG("spdk_json_decode_object failed\n");
47 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
48 : : "spdk_json_decode_object failed");
49 : :
50 : 0 : free_rpc_aio_create(&req);
51 : 0 : return;
52 : : }
53 : :
54 : 1 : rc = spdk_fsdev_aio_create(&fsdev, req.name, req.root_path, &req.opts);
55 [ - + ]: 1 : if (rc) {
56 : 0 : SPDK_ERRLOG("Failed to create aio %s: rc %d\n", req.name, rc);
57 : 0 : spdk_jsonrpc_send_error_response(request,
58 : : SPDK_JSONRPC_ERROR_INTERNAL_ERROR,
59 : : spdk_strerror(-rc));
60 : 0 : free_rpc_aio_create(&req);
61 : 0 : return;
62 : : }
63 : :
64 : 1 : w = spdk_jsonrpc_begin_result(request);
65 : 1 : spdk_json_write_string(w, fsdev->name);
66 : 1 : spdk_jsonrpc_end_result(request, w);
67 : 1 : free_rpc_aio_create(&req);
68 : : }
69 : 1994 : SPDK_RPC_REGISTER("fsdev_aio_create", rpc_aio_create, SPDK_RPC_RUNTIME)
70 : :
71 : : struct rpc_aio_delete {
72 : : char *name;
73 : : };
74 : :
75 : : static const struct spdk_json_object_decoder rpc_aio_delete_decoders[] = {
76 : : {"name", offsetof(struct rpc_aio_delete, name), spdk_json_decode_string},
77 : : };
78 : :
79 : : static void
80 : 0 : rpc_aio_delete_cb(void *cb_arg, int fsdeverrno)
81 : : {
82 : 0 : struct spdk_jsonrpc_request *request = cb_arg;
83 : :
84 [ # # ]: 0 : if (fsdeverrno == 0) {
85 : 0 : spdk_jsonrpc_send_bool_response(request, true);
86 : : } else {
87 : 0 : spdk_jsonrpc_send_error_response(request, fsdeverrno, spdk_strerror(-fsdeverrno));
88 : : }
89 : 0 : }
90 : :
91 : : static void
92 : 0 : rpc_aio_delete(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params)
93 : : {
94 : 0 : struct rpc_aio_delete req = {};
95 : :
96 [ # # ]: 0 : if (spdk_json_decode_object(params, rpc_aio_delete_decoders,
97 : : SPDK_COUNTOF(rpc_aio_delete_decoders),
98 : : &req)) {
99 : 0 : SPDK_ERRLOG("spdk_json_decode_object failed\n");
100 : 0 : spdk_jsonrpc_send_error_response(request, SPDK_JSONRPC_ERROR_INVALID_PARAMS,
101 : : "spdk_json_decode_object failed");
102 : :
103 : 0 : free(req.name);
104 : 0 : return;
105 : : }
106 : :
107 : 0 : spdk_fsdev_aio_delete(req.name, rpc_aio_delete_cb, request);
108 : 0 : free(req.name);
109 : : }
110 : 1994 : SPDK_RPC_REGISTER("fsdev_aio_delete", rpc_aio_delete, SPDK_RPC_RUNTIME)
|