Loading...
Searching...
No Matches
init.h File Reference

SPDK Initialization Helper. More...

Data Structures

struct  spdk_rpc_opts
 Structure with optional parameters for the JSON-RPC server initialization. More...
 
struct  spdk_subsystem
 
struct  spdk_subsystem_depend
 

Macros

#define SPDK_DEFAULT_RPC_ADDR   "/var/tmp/spdk.sock"
 
#define SPDK_SUBSYSTEM_REGISTER(_name)
 Register a new subsystem.
 
#define SPDK_SUBSYSTEM_DEPEND(_name, _depends_on)
 Declare that a subsystem depends on another subsystem.
 

Typedefs

typedef void(* spdk_subsystem_init_fn) (int rc, void *ctx)
 
typedef void(* spdk_subsystem_fini_fn) (void *ctx)
 

Functions

 SPDK_STATIC_ASSERT (sizeof(struct spdk_rpc_opts)==24, "Incorrect size")
 
int spdk_rpc_initialize (const char *listen_addr, const struct spdk_rpc_opts *opts)
 Create SPDK JSON-RPC server listening at provided address and start polling it for connections.
 
void spdk_rpc_finish (void)
 Stop SPDK JSON-RPC servers and stop polling for new connections on all addresses.
 
void spdk_rpc_server_finish (const char *listen_addr)
 Stop SPDK JSON-RPC server and stop polling for new connections on provided address.
 
void spdk_subsystem_init (spdk_subsystem_init_fn cb_fn, void *cb_arg)
 Begin the initialization process for all SPDK subsystems.
 
void spdk_subsystem_load_config (void *json, ssize_t json_size, spdk_subsystem_init_fn cb_fn, void *cb_arg, bool stop_on_error)
 Loads RPC configuration from provided JSON for current RPC state.
 
void spdk_subsystem_fini (spdk_subsystem_fini_fn cb_fn, void *cb_arg)
 Tear down all of the subsystems in the correct order.
 
bool spdk_subsystem_exists (const char *name)
 Check if the specified subsystem exists in the application.
 
void spdk_rpc_server_pause (const char *listen_addr)
 Pause polling RPC server with given address.
 
void spdk_rpc_server_resume (const char *listen_addr)
 Resume polling RPC server with given address.
 
void spdk_add_subsystem (struct spdk_subsystem *subsystem)
 Register a subsystem.
 
void spdk_add_subsystem_depend (struct spdk_subsystem_depend *depend)
 Declare a dependency between two subsystems.
 
void spdk_subsystem_init_next (int rc)
 Called by a subsystem's init callback to signal completion.
 
void spdk_subsystem_fini_next (void)
 Called by a subsystem's fini callback to signal that teardown is complete and the next subsystem may begin its teardown.
 

Detailed Description

SPDK Initialization Helper.

Macro Definition Documentation

◆ SPDK_SUBSYSTEM_DEPEND

#define SPDK_SUBSYSTEM_DEPEND ( _name,
_depends_on )
Value:
static struct spdk_subsystem_depend __subsystem_ ## _name ## _depend_on ## _depends_on = { \
.name = #_name, \
.depends_on = #_depends_on, \
}; \
__attribute__((constructor)) static void _name ## _depend_on ## _depends_on(void) \
{ \
spdk_add_subsystem_depend(&__subsystem_ ## _name ## _depend_on ## _depends_on); \
}
Definition init.h:178

Declare that a subsystem depends on another subsystem.

◆ SPDK_SUBSYSTEM_REGISTER

#define SPDK_SUBSYSTEM_REGISTER ( _name)
Value:
__attribute__((constructor)) static void _name ## _register(void) \
{ \
spdk_add_subsystem(&_name); \
}

Register a new subsystem.

Function Documentation

◆ spdk_add_subsystem()

void spdk_add_subsystem ( struct spdk_subsystem * subsystem)

Register a subsystem.

Typically called via SPDK_SUBSYSTEM_REGISTER() rather than directly.

Parameters
subsystemSubsystem to register. Must have static lifetime.

◆ spdk_add_subsystem_depend()

void spdk_add_subsystem_depend ( struct spdk_subsystem_depend * depend)

Declare a dependency between two subsystems.

Typically called via SPDK_SUBSYSTEM_DEPEND() rather than directly.

Parameters
dependDependency descriptor. Must have static lifetime.

◆ spdk_rpc_finish()

void spdk_rpc_finish ( void )

Stop SPDK JSON-RPC servers and stop polling for new connections on all addresses.

This function should be called from the SPDK app thread.

◆ spdk_rpc_initialize()

int spdk_rpc_initialize ( const char * listen_addr,
const struct spdk_rpc_opts * opts )

Create SPDK JSON-RPC server listening at provided address and start polling it for connections.

This function should be called from the SPDK app thread.

The RPC server is optional and is independent of subsystem initialization. The RPC server can be started and stopped at any time.

Parameters
listen_addrPath to a unix domain socket to listen on
optsOptions for JSON-RPC server initialization. If NULL, default values are used.
Returns
Negated errno on failure. 0 on success.

◆ spdk_rpc_server_finish()

void spdk_rpc_server_finish ( const char * listen_addr)

Stop SPDK JSON-RPC server and stop polling for new connections on provided address.

This function should be called from the SPDK app thread.

Parameters
listen_addrPath to a unix domain socket.

◆ spdk_rpc_server_pause()

void spdk_rpc_server_pause ( const char * listen_addr)

Pause polling RPC server with given address.

This function should be called from the SPDK app thread.

Parameters
listen_addrAddress, on which RPC server listens for connections.

◆ spdk_rpc_server_resume()

void spdk_rpc_server_resume ( const char * listen_addr)

Resume polling RPC server with given address.

This function should be called from the SPDK app thread.

Parameters
listen_addrAddress, on which RPC server listens for connections.

◆ spdk_subsystem_exists()

bool spdk_subsystem_exists ( const char * name)

Check if the specified subsystem exists in the application.

This function should be called from the SPDK app thread.

Parameters
nameName of the subsystem to look for
Returns
true if it exists, false if not

◆ spdk_subsystem_fini()

void spdk_subsystem_fini ( spdk_subsystem_fini_fn cb_fn,
void * cb_arg )

Tear down all of the subsystems in the correct order.

This function should be called from the SPDK app thread.

Parameters
cb_fnFunction called when the process is complete.
cb_argUser context passed to cb_fn

◆ spdk_subsystem_init()

void spdk_subsystem_init ( spdk_subsystem_init_fn cb_fn,
void * cb_arg )

Begin the initialization process for all SPDK subsystems.

This function should be called from the SPDK app thread.

SPDK is divided into subsystems at a macro-level and each subsystem automatically registers itself with this library at start up using a C constructor. Further, each subsystem can declare other subsystems that it depends on. Calling this function will correctly initialize all subsystems that are present, in the required order.

Parameters
cb_fnFunction called when the process is complete.
cb_argUser context passed to cb_fn.

◆ spdk_subsystem_init_next()

void spdk_subsystem_init_next ( int rc)

Called by a subsystem's init callback to signal completion.

A non-zero rc aborts initialization of remaining subsystems and propagates the error to the spdk_subsystem_init() caller.

Parameters
rc0 on success, negative errno on failure.

◆ spdk_subsystem_load_config()

void spdk_subsystem_load_config ( void * json,
ssize_t json_size,
spdk_subsystem_init_fn cb_fn,
void * cb_arg,
bool stop_on_error )

Loads RPC configuration from provided JSON for current RPC state.

This function should be called from the SPDK app thread.

The function will automatically start a JSON RPC server for configuration purposes and then stop it. JSON data will be copied, so parsing will not disturb the original memory.

Parameters
jsonRaw JSON data.
json_sizeSize of JSON data.
cb_fnFunction called when the process is complete.
cb_argUser context passed to cb_fn.
stop_on_errorWhether to stop initialization if one of the JSON RPCs fails.