]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/include/spdk/rpc.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / include / spdk / rpc.h
1 /*-
2 * BSD LICENSE
3 *
4 * Copyright (c) Intel Corporation.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
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
16 * distribution.
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.
20 *
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.
32 */
33
34 #ifndef SPDK_RPC_CONFIG_H_
35 #define SPDK_RPC_CONFIG_H_
36
37 #include "spdk/stdinc.h"
38
39 #include "spdk/jsonrpc.h"
40
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44
45 /**
46 * Start listening for RPC connections.
47 *
48 * \param listen_addr Listening address.
49 *
50 * \return 0 on success, -1 on failure.
51 */
52 int spdk_rpc_listen(const char *listen_addr);
53
54 /**
55 * Poll the RPC server.
56 */
57 void spdk_rpc_accept(void);
58
59 /**
60 * Stop listening for RPC connections.
61 */
62 void spdk_rpc_close(void);
63
64 /**
65 * Function signature for RPC request handlers.
66 *
67 * \param request RPC request to handle.
68 * \param params Parameters associated with the RPC request.
69 */
70 typedef void (*spdk_rpc_method_handler)(struct spdk_jsonrpc_request *request,
71 const struct spdk_json_val *params);
72
73 /**
74 * Register an RPC method.
75 *
76 * \param method Name for the registered method.
77 * \param func Function registered for this method to handle the RPC request.
78 * \param state_mask State mask of the registered method. If the bit of the state of
79 * the RPC server is set in the state_mask, the method is allowed. Otherwise, it is rejected.
80 */
81 void spdk_rpc_register_method(const char *method, spdk_rpc_method_handler func,
82 uint32_t state_mask);
83
84 /**
85 * Register a deprecated alias for an RPC method.
86 *
87 * \param method Name for the registered method.
88 * \param alias Alias for the registered method.
89 */
90 void spdk_rpc_register_alias_deprecated(const char *method, const char *alias);
91
92 /**
93 * Check if \c method is allowed for \c state_mask
94 *
95 * \param method Method name
96 * \param state_mask state mask to check against
97 * \return 0 if method is allowed or negative error code:
98 * -EPERM method is not allowed
99 * -ENOENT method not found
100 */
101 int spdk_rpc_is_method_allowed(const char *method, uint32_t state_mask);
102
103 #define SPDK_RPC_STARTUP 0x1
104 #define SPDK_RPC_RUNTIME 0x2
105
106 #define SPDK_RPC_REGISTER(method, func, state_mask) \
107 static void __attribute__((constructor)) rpc_register_##func(void) \
108 { \
109 spdk_rpc_register_method(method, func, state_mask); \
110 }
111
112 #define SPDK_RPC_REGISTER_ALIAS_DEPRECATED(method, alias) \
113 static void __attribute__((constructor)) rpc_register_##alias(void) \
114 { \
115 spdk_rpc_register_alias_deprecated(#method, #alias); \
116 }
117
118 /**
119 * Set the state mask of the RPC server. Any RPC method whose state mask is
120 * equal to the state of the RPC server is allowed.
121 *
122 * \param state_mask New state mask of the RPC server.
123 */
124 void spdk_rpc_set_state(uint32_t state_mask);
125
126 /**
127 * Get the current state of the RPC server.
128 *
129 * \return The current state of the RPC server.
130 */
131 uint32_t spdk_rpc_get_state(void);
132
133 #ifdef __cplusplus
134 }
135 #endif
136
137 #endif