2022-06-03 19:15:11 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
2022-11-01 20:26:26 +00:00
|
|
|
* Copyright (C) 2017 Intel Corporation.
|
2017-06-13 17:18:50 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "spdk/stdinc.h"
|
|
|
|
|
2017-06-15 21:48:48 +00:00
|
|
|
#include "spdk/env.h"
|
2021-03-02 19:22:03 +00:00
|
|
|
#include "spdk/init.h"
|
2018-06-11 20:32:15 +00:00
|
|
|
#include "spdk/thread.h"
|
2017-06-15 21:48:48 +00:00
|
|
|
#include "spdk/log.h"
|
2017-06-13 17:18:50 +00:00
|
|
|
#include "spdk/rpc.h"
|
|
|
|
|
2017-06-15 21:48:48 +00:00
|
|
|
#define RPC_SELECT_INTERVAL 4000 /* 4ms */
|
|
|
|
|
|
|
|
static struct spdk_poller *g_rpc_poller = NULL;
|
|
|
|
|
2018-03-13 00:16:47 +00:00
|
|
|
static int
|
2020-05-10 23:06:38 +00:00
|
|
|
rpc_subsystem_poll(void *arg)
|
2017-06-14 23:11:15 +00:00
|
|
|
{
|
2017-06-15 21:48:48 +00:00
|
|
|
spdk_rpc_accept();
|
2020-05-04 09:51:27 +00:00
|
|
|
return SPDK_POLLER_BUSY;
|
2017-06-15 21:48:48 +00:00
|
|
|
}
|
|
|
|
|
2021-03-02 19:45:59 +00:00
|
|
|
int
|
2017-11-09 23:33:29 +00:00
|
|
|
spdk_rpc_initialize(const char *listen_addr)
|
2017-06-15 21:48:48 +00:00
|
|
|
{
|
2017-06-14 23:11:15 +00:00
|
|
|
int rc;
|
|
|
|
|
2017-06-15 21:48:48 +00:00
|
|
|
if (listen_addr == NULL) {
|
2021-03-02 19:45:59 +00:00
|
|
|
/* Not treated as an error */
|
|
|
|
return 0;
|
2017-06-15 21:48:48 +00:00
|
|
|
}
|
|
|
|
|
2019-10-25 23:04:51 +00:00
|
|
|
if (!spdk_rpc_verify_methods()) {
|
2021-03-02 19:45:59 +00:00
|
|
|
return -EINVAL;
|
2019-10-25 23:04:51 +00:00
|
|
|
}
|
|
|
|
|
2017-06-15 21:48:48 +00:00
|
|
|
/* Listen on the requested address */
|
|
|
|
rc = spdk_rpc_listen(listen_addr);
|
|
|
|
if (rc != 0) {
|
|
|
|
SPDK_ERRLOG("Unable to start RPC service at %s\n", listen_addr);
|
2021-03-02 19:45:59 +00:00
|
|
|
/* TODO: Eventually, treat this as an error. But it historically has not
|
|
|
|
* been and many tests rely on this gracefully failing. */
|
|
|
|
return 0;
|
2017-06-15 21:48:48 +00:00
|
|
|
}
|
|
|
|
|
2018-05-02 04:28:57 +00:00
|
|
|
spdk_rpc_set_state(SPDK_RPC_STARTUP);
|
|
|
|
|
2017-06-15 21:48:48 +00:00
|
|
|
/* Register a poller to periodically check for RPCs */
|
2020-05-10 23:06:38 +00:00
|
|
|
g_rpc_poller = SPDK_POLLER_REGISTER(rpc_subsystem_poll, NULL, RPC_SELECT_INTERVAL);
|
2021-03-02 19:45:59 +00:00
|
|
|
|
|
|
|
return 0;
|
2017-06-15 21:48:48 +00:00
|
|
|
}
|
|
|
|
|
2017-11-06 16:31:15 +00:00
|
|
|
void
|
|
|
|
spdk_rpc_finish(void)
|
2017-06-14 23:11:15 +00:00
|
|
|
{
|
2017-06-15 21:48:48 +00:00
|
|
|
spdk_rpc_close();
|
2017-11-15 22:09:40 +00:00
|
|
|
spdk_poller_unregister(&g_rpc_poller);
|
2017-06-15 21:48:48 +00:00
|
|
|
}
|