43 #define M0_TRACE_SUBSYSTEM M0_TRACE_SUBSYS_HA 61 #define HAM_SERVER_EP_DEFAULT "0@lo:12345:43:100" 62 #define HAM_CLIENT_EP_DEFAULT "0@lo:12345:43:101" 63 #define HAM_SERVER_WAIT_DEFAULT 0 141 type->xct_name, *
rc, str);
167 vfprintf(stderr,
format, ap);
168 fputs(
".\n", stderr);
191 if (rc < 0 || rc >
size)
205 if (isatty(fileno(
src)))
218 " (> %lu bytes)", (
unsigned long)
size-1);
230 const char *local_endpoint,
231 const struct m0_fid *local_process)
236 M0_PRE(local_endpoint !=
NULL && *local_endpoint !=
'\0');
248 .rhia_dtm = (
void *)1,
249 .rhia_mdstore = (
void *)1,
250 .rhia_fid = local_process);
254 local_endpoint, &
ctx->mrc_reqh,
282 .hmnv_ignore_same_state =
false,
326 .hae_confd_fids = {},
327 .hae_confd_eps =
NULL,
329 .hae_active_rm_ep =
NULL,
333 ham_say(
"Got entrypoint request. Replying");
348 ham_say(
"Got entrypoint reply");
379 ham_say(
"Connection established");
439 ham_say(
"Interrupted by signal %d", signum);
442 signal(SIGINT, SIG_DFL);
443 signal(SIGTERM, SIG_DFL);
451 sigemptyset(&sa.sa_mask);
453 sigaddset(&sa.sa_mask, SIGINT);
454 sigaddset(&sa.sa_mask, SIGTERM);
456 rc = sigaction(SIGINT, &sa,
NULL) ?: sigaction(SIGTERM, &sa,
NULL);
470 "Usage: %s [option] [endpoint]\n" 471 "Send/receive data over HA link.\n" 473 " -h, --help Display this help screen\n" 474 " -l, --listen Listen for incoming connections\n" 475 " -s, --source addr Specify source address to use (doesn't affect -l);\n" 477 " -w, --wait time Wait in seconds before finishing listening mode\n" 478 " Default is zero second\n" 479 " -v, --verbose Explain what is being done\n",
500 const struct option opts[] = {
501 {
"self-check", no_argument,
NULL,
'c' },
502 {
"help", no_argument,
NULL,
'h' },
503 {
"listen", no_argument,
NULL,
'l' },
504 {
"source", required_argument,
NULL,
's' },
505 {
"wait", required_argument,
NULL,
'w' },
506 {
"verbose", no_argument,
NULL,
'v' },
514 .hp_ep_remote =
NULL,
517 .hp_progname = basename(argv[0])
519 while ((
c = getopt_long(argc, argv,
"hls:w:v", opts,
NULL)) != -1) {
534 params->hp_verbose =
true;
544 fprintf(stderr,
"`-s' can only be used in connect mode\n");
549 fprintf(stderr,
"Remote endpoint is missing\n");
561 fprintf(stderr,
"Too many arguments\n");
563 fprintf(stderr,
"Type `%s --help' for usage\n", basename(argv[0]));
576 switch (
params->hp_mode) {
581 fprintf(stderr,
"Remote and local endpoints must" 602 int main(
int argc,
char **argv)
604 enum { BUFSIZE = 2 << 21 };
605 static char buf[BUFSIZE];
609 struct m0_ha ha = {};
613 .hcf_rpc_machine = &
rpc_ctx.mrc_rpc_mach,
698 #undef M0_TRACE_SUBSYSTEM
static void ptr(struct m0_addb2__context *ctx, const uint64_t *v, char *buf)
M0_INTERNAL int m0_xcode_print(const struct m0_xcode_obj *obj, char *str, int nr)
static void ham_help(FILE *stream, char *progname)
void m0_rpc_machine_fini(struct m0_rpc_machine *machine)
struct m0_net_domain mrc_net_dom
static void rpc_fini(struct m0_client *m0c)
M0_INTERNAL void m0_reqh_services_terminate(struct m0_reqh *reqh)
void m0_net_domain_fini(struct m0_net_domain *dom)
static void ham_sighandler(int signum)
M0_INTERNAL struct m0_ha_link * m0_ha_connect(struct m0_ha *ha)
static const struct m0_ha_msg ham_self_check_msg_default
M0_INTERNAL void m0_ha_fini(struct m0_ha *ha)
static void ham_msg_is_delivered(struct m0_ha *ha, struct m0_ha_link *hl, uint64_t tag)
#define M0_REQH_INIT(reqh,...)
static struct io_request req
M0_INTERNAL bool m0_uint128_eq(const struct m0_uint128 *u0, const struct m0_uint128 *u1)
static uint64_t tag(uint8_t code, uint64_t id)
#define M0_LOG(level,...)
const struct m0_conf_obj_type * m0_conf_fid_type(const struct m0_fid *fid)
M0_INTERNAL int m0_xcode_read(struct m0_xcode_obj *obj, const char *str)
M0_INTERNAL int m0_ha_start(struct m0_ha *ha)
static struct m0_semaphore g_sem
static struct m0_uint128 g_self_req_id
M0_INTERNAL void m0_ha_send(struct m0_ha *ha, struct m0_ha_link *hl, const struct m0_ha_msg *msg, uint64_t *tag)
int const char const void * value
struct m0_ha_msg_data hm_data
static struct m0_ha_msg * g_msg
M0_INTERNAL void m0_xcode_free_obj(struct m0_xcode_obj *obj)
int m0_init(struct m0 *instance)
static void ham_link_reused(struct m0_ha *ha, const struct m0_uint128 *req_id, struct m0_ha_link *hl)
M0_INTERNAL void m0_reqh_fini(struct m0_reqh *reqh)
m0_time_t m0_time(uint64_t secs, long ns)
struct m0_fop_getxattr_rep * rep
void(* hao_entrypoint_request)(struct m0_ha *ha, const struct m0_ha_entrypoint_req *req, const struct m0_uint128 *req_id)
M0_INTERNAL void m0_reqh_shutdown_wait(struct m0_reqh *reqh)
M0_INTERNAL void m0_ha_disconnect(struct m0_ha *ha)
static void * xcode_read_as(const struct m0_xcode_type *type, const char *str, int *rc)
static void ham_msg_received(struct m0_ha *ha, struct m0_ha_link *hl, struct m0_ha_msg *msg, uint64_t tag)
static void ham_link_connected(struct m0_ha *ha, const struct m0_uint128 *req_id, struct m0_ha_link *hl)
#define M0_ERR_INFO(rc, fmt,...)
return M0_ERR(-EOPNOTSUPP)
M0_INTERNAL void m0_ha_flush(struct m0_ha *ha, struct m0_ha_link *hl)
M0_INTERNAL unsigned m0_semaphore_value(struct m0_semaphore *semaphore)
M0_INTERNAL void m0_ha_stop(struct m0_ha *ha)
#define M0_FID_TINIT(type, container, key)
M0_INTERNAL void m0_ha_delivered(struct m0_ha *ha, struct m0_ha_link *hl, struct m0_ha_msg *msg)
struct m0_ha_link * h_link
static void ham_rpc_ctx_init(struct ham_rpc_ctx *ctx, const char *local_endpoint, const struct m0_fid *local_process)
static struct m0_addb2_callback c
M0_INTERNAL int m0_rpc_net_buffer_pool_setup(struct m0_net_domain *ndom, struct m0_net_buffer_pool *app_pool, uint32_t bufs_nr, uint32_t tm_nr)
M0_INTERNAL uint32_t m0_rpc_bufs_nr(uint32_t len, uint32_t tms_nr)
static void ham_xcode_print(const struct m0_xcode_obj *x)
M0_INTERNAL int m0_rpc_machine_init(struct m0_rpc_machine *machine, struct m0_net_domain *net_dom, const char *ep_addr, struct m0_reqh *reqh, struct m0_net_buffer_pool *receive_pool, uint32_t colour, m0_bcount_t msg_size, uint32_t queue_len)
struct m0_net_xprt * m0_net_xprt_default_get(void)
M0_INTERNAL int m0_semaphore_init(struct m0_semaphore *semaphore, unsigned value)
void * m0_alloc(size_t size)
static const char * progname
#define HAM_SERVER_EP_DEFAULT
static void ham_msg_is_not_delivered(struct m0_ha *ha, struct m0_ha_link *hl, uint64_t tag)
static void ha_fini(struct m0_client *m0c)
static int ham_fread_str(char *dest, size_t size, FILE *src)
struct m0_rpc_machine mrc_rpc_mach
static int ham_params_check(struct ham_params *params)
static int ham_args_parse(struct ham_params *params, int argc, char *const *argv)
#define HAM_CLIENT_EP_DEFAULT
M0_INTERNAL void m0_ha_disconnect_incoming(struct m0_ha *ha, struct m0_ha_link *hl)
static void ham_link_absent(struct m0_ha *ha, const struct m0_uint128 *req_id)
static struct ham_params g_params
M0_INTERNAL void m0_reqh_start(struct m0_reqh *reqh)
int m0_net_domain_init(struct m0_net_domain *dom, const struct m0_net_xprt *xprt)
static int ham_sighandler_init(void)
union m0_ha_msg_data::@212 u
static void ham_link_is_disconnecting(struct m0_ha *ha, struct m0_ha_link *hl)
static void ham_send(struct m0_ha *ha, struct m0_ha_link *hl, const struct m0_ha_msg *msg)
static void ham_rpc_ctx_fini(struct ham_rpc_ctx *ctx)
static void ham_maybe_set(const char **dest, const char *value)
M0_INTERNAL int m0_ha_init(struct m0_ha *ha, struct m0_ha_cfg *ha_cfg)
M0_INTERNAL void m0_semaphore_fini(struct m0_semaphore *semaphore)
static void ham_link_disconnected(struct m0_ha *ha, struct m0_ha_link *hl)
#define HAM_SERVER_WAIT_DEFAULT
int main(int argc, char **argv)
#define M0_XCODE_OBJ(type, ptr)
void m0_ha_entrypoint_reply(struct m0_ha *ha, const struct m0_uint128 *req_id, const struct m0_ha_entrypoint_rep *rep, struct m0_ha_link **hl_ptr)
M0_INTERNAL void m0_semaphore_down(struct m0_semaphore *semaphore)
const struct m0_conf_obj_type M0_CONF_PROCESS_TYPE
struct m0_net_buffer_pool mrc_buf_pool
M0_INTERNAL void m0_semaphore_up(struct m0_semaphore *semaphore)
static void ham_entrypoint_request(struct m0_ha *ha, const struct m0_ha_entrypoint_req *req, const struct m0_uint128 *req_id)
void m0_rpc_net_buffer_pool_cleanup(struct m0_net_buffer_pool *app_pool)
static void ham_entrypoint_replied(struct m0_ha *ha, struct m0_ha_entrypoint_rep *rep)
const char * hp_ep_remote
struct m0_pdclust_src_addr src
static bool ha_msg_is_one_way(const struct m0_ha_msg *msg)
struct m0_fid hcf_process_fid
static void ham_say(const char *format,...)
#define M0_IMPOSSIBLE(fmt,...)
static const struct m0_ha_ops ham_ha_ops
int m0_nanosleep(const m0_time_t req, m0_time_t *rem)