]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/include/spdk_internal/event.h
import 15.2.0 Octopus source
[ceph.git] / ceph / src / spdk / include / spdk_internal / event.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_INTERNAL_EVENT_H
35 #define SPDK_INTERNAL_EVENT_H
36
37 #include "spdk/stdinc.h"
38
39 #include "spdk/event.h"
40 #include "spdk/json.h"
41 #include "spdk/thread.h"
42
43 struct spdk_event {
44 uint32_t lcore;
45 spdk_event_fn fn;
46 void *arg1;
47 void *arg2;
48 };
49
50 int spdk_reactors_init(void);
51 void spdk_reactors_fini(void);
52
53 void spdk_reactors_start(void);
54 void spdk_reactors_stop(void *arg1);
55
56 struct spdk_subsystem {
57 const char *name;
58 /* User must call spdk_subsystem_init_next() when they are done with their initialization. */
59 void (*init)(void);
60 void (*fini)(void);
61 void (*config)(FILE *fp);
62
63 /**
64 * Write JSON configuration handler.
65 *
66 * \param w JSON write context
67 */
68 void (*write_config_json)(struct spdk_json_write_ctx *w);
69 TAILQ_ENTRY(spdk_subsystem) tailq;
70 };
71
72 TAILQ_HEAD(spdk_subsystem_list, spdk_subsystem);
73 extern struct spdk_subsystem_list g_subsystems;
74
75 struct spdk_subsystem *spdk_subsystem_find(struct spdk_subsystem_list *list, const char *name);
76
77 struct spdk_subsystem_depend {
78 const char *name;
79 const char *depends_on;
80 TAILQ_ENTRY(spdk_subsystem_depend) tailq;
81 };
82
83 TAILQ_HEAD(spdk_subsystem_depend_list, spdk_subsystem_depend);
84 extern struct spdk_subsystem_depend_list g_subsystems_deps;
85
86 void spdk_add_subsystem(struct spdk_subsystem *subsystem);
87 void spdk_add_subsystem_depend(struct spdk_subsystem_depend *depend);
88
89 void spdk_subsystem_init(spdk_msg_fn cb_fn, void *cb_arg);
90 void spdk_subsystem_fini(spdk_msg_fn cb_fn, void *cb_arg);
91 void spdk_subsystem_init_next(int rc);
92 void spdk_subsystem_fini_next(void);
93 void spdk_subsystem_config(FILE *fp);
94
95 /**
96 * Save pointed \c subsystem configuration to the JSON write context \c w. In case of
97 * error \c null is written to the JSON context.
98 *
99 * \param w JSON write context
100 * \param subsystem the subsystem to query
101 */
102 void spdk_subsystem_config_json(struct spdk_json_write_ctx *w, struct spdk_subsystem *subsystem);
103
104 void spdk_rpc_initialize(const char *listen_addr);
105 void spdk_rpc_finish(void);
106
107 /**
108 * \brief Register a new subsystem
109 */
110 #define SPDK_SUBSYSTEM_REGISTER(_name) \
111 __attribute__((constructor)) static void _name ## _register(void) \
112 { \
113 spdk_add_subsystem(&_name); \
114 }
115
116 /**
117 * \brief Declare that a subsystem depends on another subsystem.
118 */
119 #define SPDK_SUBSYSTEM_DEPEND(_name, _depends_on) \
120 static struct spdk_subsystem_depend __subsystem_ ## _name ## _depend_on ## _depends_on = { \
121 .name = #_name, \
122 .depends_on = #_depends_on, \
123 }; \
124 __attribute__((constructor)) static void _name ## _depend_on ## _depends_on(void) \
125 { \
126 spdk_add_subsystem_depend(&__subsystem_ ## _name ## _depend_on ## _depends_on); \
127 }
128
129 #endif /* SPDK_INTERNAL_EVENT_H */