4 * Copyright (c) Intel Corporation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #include "spdk/stdinc.h"
36 #include "spdk/event.h"
38 #include "spdk/string.h"
39 #include "spdk/util.h"
41 #include "spdk_internal/log.h"
43 struct rpc_kill_instance
{
48 free_rpc_kill_instance(struct rpc_kill_instance
*req
)
53 static const struct spdk_json_object_decoder rpc_kill_instance_decoders
[] = {
54 {"sig_name", offsetof(struct rpc_kill_instance
, sig_name
), spdk_json_decode_string
},
58 spdk_rpc_kill_instance(struct spdk_jsonrpc_request
*request
,
59 const struct spdk_json_val
*params
)
62 const char *signal_string
;
73 struct rpc_kill_instance req
= {};
74 struct spdk_json_write_ctx
*w
;
76 if (spdk_json_decode_object(params
, rpc_kill_instance_decoders
,
77 SPDK_COUNTOF(rpc_kill_instance_decoders
),
79 SPDK_DEBUGLOG(SPDK_LOG_REACTOR
, "spdk_json_decode_object failed\n");
83 sig_count
= SPDK_COUNTOF(signals
);
84 signal
= spdk_strtol(req
.sig_name
, 10);
85 for (i
= 0 ; i
< sig_count
; i
++) {
86 if (strcmp(req
.sig_name
, signals
[i
].signal_string
) == 0 ||
87 signal
== signals
[i
].signal
) {
96 SPDK_DEBUGLOG(SPDK_LOG_REACTOR
, "sending signal %d\n", signals
[i
].signal
);
97 free_rpc_kill_instance(&req
);
98 kill(getpid(), signals
[i
].signal
);
100 w
= spdk_jsonrpc_begin_result(request
);
104 spdk_json_write_bool(w
, true);
105 spdk_jsonrpc_end_result(request
, w
);
109 spdk_jsonrpc_send_error_response(request
, SPDK_JSONRPC_ERROR_INVALID_PARAMS
, "Invalid parameters");
110 free_rpc_kill_instance(&req
);
112 SPDK_RPC_REGISTER("kill_instance", spdk_rpc_kill_instance
, SPDK_RPC_RUNTIME
)
115 struct rpc_context_switch_monitor
{
119 static const struct spdk_json_object_decoder rpc_context_switch_monitor_decoders
[] = {
120 {"enabled", offsetof(struct rpc_context_switch_monitor
, enabled
), spdk_json_decode_bool
},
124 spdk_rpc_context_switch_monitor(struct spdk_jsonrpc_request
*request
,
125 const struct spdk_json_val
*params
)
127 struct rpc_context_switch_monitor req
= {};
128 struct spdk_json_write_ctx
*w
;
130 if (params
!= NULL
) {
131 if (spdk_json_decode_object(params
, rpc_context_switch_monitor_decoders
,
132 SPDK_COUNTOF(rpc_context_switch_monitor_decoders
),
134 SPDK_DEBUGLOG(SPDK_LOG_REACTOR
, "spdk_json_decode_object failed\n");
135 spdk_jsonrpc_send_error_response(request
, SPDK_JSONRPC_ERROR_INVALID_PARAMS
, "Invalid parameters");
139 spdk_reactor_enable_context_switch_monitor(req
.enabled
);
142 w
= spdk_jsonrpc_begin_result(request
);
147 spdk_json_write_object_begin(w
);
149 spdk_json_write_named_bool(w
, "enabled", spdk_reactor_context_switch_monitor_enabled());
151 spdk_json_write_object_end(w
);
152 spdk_jsonrpc_end_result(request
, w
);
155 SPDK_RPC_REGISTER("context_switch_monitor", spdk_rpc_context_switch_monitor
, SPDK_RPC_RUNTIME
)