Motr  M0
ping.c File Reference
#include "lib/assert.h"
#include "lib/chan.h"
#include "lib/cond.h"
#include "lib/errno.h"
#include "lib/arith.h"
#include "lib/memory.h"
#include "lib/misc.h"
#include "net/net.h"
#include "net/lnet/lnet.h"
#include "net/lnet/st/ping.h"
Include dependency graph for ping.c:

Go to the source code of this file.

Data Structures

struct  ping_work_item
 
struct  ping_msg
 

Macros

#define DEF_RESPONSE   "active pong"
 
#define DEF_SEND   "passive ping"
 
#define SEND_RESP   " pong"
 
#define PING_QSTATS_CLIENT_TOTAL(f)   cqp->nqs_##f += qp->nqs_##f
 

Enumerations

enum  { SEND_RETRIES = 3, IDBUF_LEN = M0_NET_LNET_XEP_ADDR_LEN + 16 }
 
enum  ping_msg_type {
  PM_SEND_DESC, PM_RECV_DESC, PM_MSG, PM_SEND_DESC,
  PM_RECV_DESC, PM_MSG
}
 

Functions

static void ping_print_qstats (struct nlx_ping_ctx *ctx, struct m0_net_qstats *qp, bool accumulate)
 
void nlx_ping_print_qstats_tm (struct nlx_ping_ctx *ctx, bool reset)
 
int nlx_ping_print_qstats_total (const char *ident, const struct nlx_ping_ops *ops)
 
uint64_t nlx_ping_parse_uint64 (const char *s)
 
static void ping_sleep_secs (int secs)
 
static int alloc_buffers (int num, uint32_t segs, m0_bcount_t segsize, unsigned shift, struct m0_net_buffer **out)
 
static struct m0_net_bufferping_buf_get (struct nlx_ping_ctx *ctx)
 
static void ping_buf_put (struct nlx_ping_ctx *ctx, struct m0_net_buffer *nb)
 
static int encode_msg (struct m0_net_buffer *nb, const char *str)
 
static int encode_desc (struct m0_net_buffer *nb, bool send_desc, unsigned passive_size, const struct m0_net_buf_desc *desc)
 
static int decode_msg (struct m0_net_buffer *nb, m0_bcount_t nb_len, m0_bcount_t nb_offset, struct ping_msg *msg)
 
static void msg_free (struct ping_msg *msg)
 
static void ping_print_interfaces (struct nlx_ping_ctx *ctx)
 
static struct nlx_ping_ctxbuffer_event_to_ping_ctx (const struct m0_net_buffer_event *ev)
 
static void c_m_recv_cb (const struct m0_net_buffer_event *ev)
 
static void c_m_send_cb (const struct m0_net_buffer_event *ev)
 
static void c_p_recv_cb (const struct m0_net_buffer_event *ev)
 
static void c_p_send_cb (const struct m0_net_buffer_event *ev)
 
static void c_a_recv_cb (const struct m0_net_buffer_event *ev)
 
static void c_a_send_cb (const struct m0_net_buffer_event *ev)
 
static void event_cb (const struct m0_net_tm_event *ev)
 
static void server_event_ident (char *buf, size_t len, const char *ident, const struct m0_net_buffer_event *ev)
 
static void s_m_recv_cb (const struct m0_net_buffer_event *ev)
 
static void s_m_send_cb (const struct m0_net_buffer_event *ev)
 
static void s_p_recv_cb (const struct m0_net_buffer_event *ev)
 
static void s_p_send_cb (const struct m0_net_buffer_event *ev)
 
static void s_a_recv_cb (const struct m0_net_buffer_event *ev)
 
static void s_a_send_cb (const struct m0_net_buffer_event *ev)
 
static void ping_fini (struct nlx_ping_ctx *ctx)
 
static bool ping_workq_clink_cb (struct m0_clink *cl)
 
static bool ping_net_clink_cb (struct m0_clink *cl)
 
static int ping_init (struct nlx_ping_ctx *ctx)
 
static bool ping_tm_timedwait (struct nlx_ping_ctx *ctx, struct m0_clink *cl, m0_time_t timeout)
 
static void ping_tm_wait (struct nlx_ping_ctx *ctx, struct m0_clink *cl)
 
static void set_msg_timeout (struct nlx_ping_ctx *ctx, struct m0_net_buffer *nb)
 
static void set_bulk_timeout (struct nlx_ping_ctx *ctx, struct m0_net_buffer *nb)
 
static void nlx_ping_server_work (struct nlx_ping_ctx *ctx)
 
static void nlx_ping_server_async (struct nlx_ping_ctx *ctx)
 
static void nlx_ping_server_sync (struct nlx_ping_ctx *ctx)
 
static void nlx_ping_server (struct nlx_ping_ctx *ctx)
 
void nlx_ping_server_should_stop (struct nlx_ping_ctx *ctx)
 
void nlx_ping_server_spawn (struct m0_thread *server_thread, struct nlx_ping_ctx *sctx)
 
static int nlx_ping_client_msg_send_recv (struct nlx_ping_ctx *ctx, struct m0_net_end_point *server_ep, const char *data)
 
static int nlx_ping_client_passive_recv (struct nlx_ping_ctx *ctx, struct m0_net_end_point *server_ep)
 
static int nlx_ping_client_passive_send (struct nlx_ping_ctx *ctx, struct m0_net_end_point *server_ep, const char *data)
 
static int nlx_ping_client_init (struct nlx_ping_ctx *ctx, struct m0_net_end_point **server_ep)
 
static void nlx_ping_client_fini (struct nlx_ping_ctx *ctx, struct m0_net_end_point *server_ep)
 
void nlx_ping_client (struct nlx_ping_client_params *params)
 
void nlx_ping_init ()
 
void nlx_ping_fini ()
 

Variables

static struct m0_mutex qstats_mutex
 
static struct m0_net_qstats ping_qs_total [M0_NET_QT_NR]
 
static uint64_t ping_qs_total_errors
 
static uint64_t ping_qs_total_retries
 
static bool server_stop = false
 
static struct m0_net_buffer_callbacks cbuf_cb
 
static struct m0_net_tm_callbacks ctm_cb
 
static struct m0_atomic64 s_msg_recv_counter
 
static struct m0_net_buffer_callbacks sbuf_cb
 
static struct m0_net_tm_callbacks stm_cb
 

Macro Definition Documentation

◆ DEF_RESPONSE

#define DEF_RESPONSE   "active pong"

Definition at line 34 of file ping.c.

◆ DEF_SEND

#define DEF_SEND   "passive ping"

Definition at line 35 of file ping.c.

◆ PING_QSTATS_CLIENT_TOTAL

#define PING_QSTATS_CLIENT_TOTAL (   f)    cqp->nqs_##f += qp->nqs_##f

◆ SEND_RESP

#define SEND_RESP   " pong"

Definition at line 36 of file ping.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Descriptor for the tlist of buffers.

Enumerator
SEND_RETRIES 
IDBUF_LEN 

Definition at line 39 of file ping.c.

◆ ping_msg_type

Enumerator
PM_SEND_DESC 

client wants to do passive send, server will active recv

PM_RECV_DESC 

client wants to do active send, server will passive recv

PM_MSG 
PM_SEND_DESC 

client wants to do passive send, server will active recv

PM_RECV_DESC 

client wants to do active send, server will passive recv

PM_MSG 

Definition at line 328 of file ping.c.

Function Documentation

◆ alloc_buffers()

static int alloc_buffers ( int  num,
uint32_t  segs,
m0_bcount_t  segsize,
unsigned  shift,
struct m0_net_buffer **  out 
)
static

Definition at line 206 of file ping.c.

Here is the call graph for this function:

◆ buffer_event_to_ping_ctx()

static struct nlx_ping_ctx* buffer_event_to_ping_ctx ( const struct m0_net_buffer_event ev)
static

Definition at line 427 of file ping.c.

Here is the caller graph for this function:

◆ c_a_recv_cb()

static void c_a_recv_cb ( const struct m0_net_buffer_event ev)
static

Definition at line 640 of file ping.c.

◆ c_a_send_cb()

static void c_a_send_cb ( const struct m0_net_buffer_event ev)
static

Definition at line 647 of file ping.c.

◆ c_m_recv_cb()

static void c_m_recv_cb ( const struct m0_net_buffer_event ev)
static

Definition at line 435 of file ping.c.

Here is the call graph for this function:

◆ c_m_send_cb()

static void c_m_send_cb ( const struct m0_net_buffer_event ev)
static

Definition at line 496 of file ping.c.

Here is the call graph for this function:

◆ c_p_recv_cb()

static void c_p_recv_cb ( const struct m0_net_buffer_event ev)
static

Definition at line 539 of file ping.c.

Here is the call graph for this function:

◆ c_p_send_cb()

static void c_p_send_cb ( const struct m0_net_buffer_event ev)
static

Definition at line 608 of file ping.c.

Here is the call graph for this function:

◆ decode_msg()

static int decode_msg ( struct m0_net_buffer nb,
m0_bcount_t  nb_len,
m0_bcount_t  nb_offset,
struct ping_msg msg 
)
static

decode a net buffer, allocates memory and copies payload

Definition at line 346 of file ping.c.

Here is the call graph for this function:

◆ encode_desc()

static int encode_desc ( struct m0_net_buffer nb,
bool  send_desc,
unsigned  passive_size,
const struct m0_net_buf_desc desc 
)
static

encode a descriptor into a net buffer, not zero-copy

Definition at line 300 of file ping.c.

Here is the call graph for this function:

◆ encode_msg()

static int encode_msg ( struct m0_net_buffer nb,
const char *  str 
)
static

encode a string message into a net buffer, not zero-copy

Definition at line 279 of file ping.c.

Here is the call graph for this function:

◆ event_cb()

static void event_cb ( const struct m0_net_tm_event ev)
static

Definition at line 654 of file ping.c.

Here is the call graph for this function:

◆ msg_free()

static void msg_free ( struct ping_msg msg)
static

Definition at line 409 of file ping.c.

Here is the call graph for this function:

◆ nlx_ping_client()

void nlx_ping_client ( struct nlx_ping_client_params params)

Definition at line 1837 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nlx_ping_client_fini()

static void nlx_ping_client_fini ( struct nlx_ping_ctx ctx,
struct m0_net_end_point server_ep 
)
static

Definition at line 1829 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nlx_ping_client_init()

static int nlx_ping_client_init ( struct nlx_ping_ctx ctx,
struct m0_net_end_point **  server_ep 
)
static

Definition at line 1788 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nlx_ping_client_msg_send_recv()

static int nlx_ping_client_msg_send_recv ( struct nlx_ping_ctx ctx,
struct m0_net_end_point server_ep,
const char *  data 
)
static

Test an RPC-like exchange, sending data in a message to the server and getting back a response.

Parameters
ctxclient context
server_ependpoint of the server
Return values
0successful test
-errnofailed to send to server

Definition at line 1524 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nlx_ping_client_passive_recv()

static int nlx_ping_client_passive_recv ( struct nlx_ping_ctx ctx,
struct m0_net_end_point server_ep 
)
static

Definition at line 1623 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nlx_ping_client_passive_send()

static int nlx_ping_client_passive_send ( struct nlx_ping_ctx ctx,
struct m0_net_end_point server_ep,
const char *  data 
)
static

Definition at line 1703 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nlx_ping_fini()

void nlx_ping_fini ( void  )

Definition at line 1921 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nlx_ping_init()

void nlx_ping_init ( void  )

Definition at line 1916 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nlx_ping_parse_uint64()

uint64_t nlx_ping_parse_uint64 ( const char *  s)

Definition at line 171 of file ping.c.

Here is the caller graph for this function:

◆ nlx_ping_print_qstats_tm()

void nlx_ping_print_qstats_tm ( struct nlx_ping_ctx ctx,
bool  reset 
)

Definition at line 136 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nlx_ping_print_qstats_total()

int nlx_ping_print_qstats_total ( const char *  ident,
const struct nlx_ping_ops ops 
)

Definition at line 151 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nlx_ping_server()

static void nlx_ping_server ( struct nlx_ping_ctx ctx)
static

Definition at line 1382 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nlx_ping_server_async()

static void nlx_ping_server_async ( struct nlx_ping_ctx ctx)
static

Definition at line 1326 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nlx_ping_server_should_stop()

void nlx_ping_server_should_stop ( struct nlx_ping_ctx ctx)

Definition at line 1485 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nlx_ping_server_spawn()

void nlx_ping_server_spawn ( struct m0_thread server_thread,
struct nlx_ping_ctx sctx 
)

Definition at line 1496 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nlx_ping_server_sync()

static void nlx_ping_server_sync ( struct nlx_ping_ctx ctx)
static

Definition at line 1341 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nlx_ping_server_work()

static void nlx_ping_server_work ( struct nlx_ping_ctx ctx)
static

Definition at line 1289 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_buf_get()

static struct m0_net_buffer* ping_buf_get ( struct nlx_ping_ctx ctx)
static

Get a unused buffer from the context buffer list. On success, marks the buffer as in-use and returns it.

Return values
ptrthe buffer
NULLfailure

Definition at line 241 of file ping.c.

Here is the call graph for this function:

◆ ping_buf_put()

static void ping_buf_put ( struct nlx_ping_ctx ctx,
struct m0_net_buffer nb 
)
static

Releases a buffer back to the free buffer pool. The buffer is marked as not in-use.

Definition at line 266 of file ping.c.

Here is the call graph for this function:

◆ ping_fini()

static void ping_fini ( struct nlx_ping_ctx ctx)
static

Definition at line 1203 of file ping.c.

Here is the call graph for this function:

◆ ping_init()

static int ping_init ( struct nlx_ping_ctx ctx)
static

Initialise a ping client or server. Calls all the required m0_net APIs in the correct order, with cleanup on failure. On success, the transfer machine is started.

Parameters
ctxthe client/server context. pc_xprt, pc_nr_bufs, pc_tm, pc_hostname, pc_port and pc_id must be initialised by the caller.
Return values
0success
-errnofailure
Todo:
replace gmc and ctx

Definition at line 1042 of file ping.c.

Here is the call graph for this function:

◆ ping_net_clink_cb()

static bool ping_net_clink_cb ( struct m0_clink cl)
static

Definition at line 1024 of file ping.c.

Here is the caller graph for this function:

◆ ping_print_interfaces()

static void ping_print_interfaces ( struct nlx_ping_ctx ctx)
static

Definition at line 417 of file ping.c.

Here is the caller graph for this function:

◆ ping_print_qstats()

static void ping_print_qstats ( struct nlx_ping_ctx ctx,
struct m0_net_qstats qp,
bool  accumulate 
)
static

Definition at line 55 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_sleep_secs()

static void ping_sleep_secs ( int  secs)
static

Definition at line 200 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_tm_timedwait()

static bool ping_tm_timedwait ( struct nlx_ping_ctx ctx,
struct m0_clink cl,
m0_time_t  timeout 
)
inlinestatic

Definition at line 1175 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_tm_wait()

static void ping_tm_wait ( struct nlx_ping_ctx ctx,
struct m0_clink cl 
)
inlinestatic

Definition at line 1197 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ping_workq_clink_cb()

static bool ping_workq_clink_cb ( struct m0_clink cl)
static

Definition at line 1016 of file ping.c.

Here is the caller graph for this function:

◆ s_a_recv_cb()

static void s_a_recv_cb ( const struct m0_net_buffer_event ev)
static

Definition at line 914 of file ping.c.

Here is the call graph for this function:

◆ s_a_send_cb()

static void s_a_send_cb ( const struct m0_net_buffer_event ev)
static

Definition at line 975 of file ping.c.

Here is the call graph for this function:

◆ s_m_recv_cb()

static void s_m_recv_cb ( const struct m0_net_buffer_event ev)
static

Definition at line 718 of file ping.c.

Here is the call graph for this function:

◆ s_m_send_cb()

static void s_m_send_cb ( const struct m0_net_buffer_event ev)
static

Definition at line 874 of file ping.c.

Here is the call graph for this function:

◆ s_p_recv_cb()

static void s_p_recv_cb ( const struct m0_net_buffer_event ev)
static

Definition at line 900 of file ping.c.

◆ s_p_send_cb()

static void s_p_send_cb ( const struct m0_net_buffer_event ev)
static

Definition at line 907 of file ping.c.

◆ server_event_ident()

static void server_event_ident ( char *  buf,
size_t  len,
const char *  ident,
const struct m0_net_buffer_event ev 
)
static

Definition at line 697 of file ping.c.

Here is the caller graph for this function:

◆ set_bulk_timeout()

static void set_bulk_timeout ( struct nlx_ping_ctx ctx,
struct m0_net_buffer nb 
)
static

Definition at line 1277 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_msg_timeout()

static void set_msg_timeout ( struct nlx_ping_ctx ctx,
struct m0_net_buffer nb 
)
static

Definition at line 1265 of file ping.c.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ cbuf_cb

struct m0_net_buffer_callbacks cbuf_cb
static
Initial value:
= {
.nbc_cb = {
},
}
void c_a_send_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:451
void c_m_recv_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:250
void c_m_send_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:308
void c_a_recv_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:444
void c_p_send_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:414
void c_p_recv_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:349

Definition at line 682 of file ping.c.

◆ ctm_cb

struct m0_net_tm_callbacks ctm_cb
static
Initial value:
= {
.ntc_event_cb = event_cb
}
void event_cb(const struct m0_net_tm_event *ev)
Definition: ping.c:458

Definition at line 693 of file ping.c.

◆ ping_qs_total

struct m0_net_qstats ping_qs_total[M0_NET_QT_NR]
static

Definition at line 51 of file ping.c.

◆ ping_qs_total_errors

uint64_t ping_qs_total_errors
static

Definition at line 52 of file ping.c.

◆ ping_qs_total_retries

uint64_t ping_qs_total_retries
static

Definition at line 53 of file ping.c.

◆ qstats_mutex

struct m0_mutex qstats_mutex
static

Definition at line 50 of file ping.c.

◆ s_msg_recv_counter

struct m0_atomic64 s_msg_recv_counter
static

Definition at line 715 of file ping.c.

◆ sbuf_cb

struct m0_net_buffer_callbacks sbuf_cb
static
Initial value:
= {
.nbc_cb = {
},
}
void s_m_recv_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:519
void s_p_send_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:677
void s_m_send_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:646
void s_p_recv_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:670
void s_a_send_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:741
void s_a_recv_cb(const struct m0_net_buffer_event *ev)
Definition: ping.c:684

Definition at line 999 of file ping.c.

◆ server_stop

bool server_stop = false
static

Definition at line 680 of file ping.c.

◆ stm_cb

struct m0_net_tm_callbacks stm_cb
static
Initial value:
= {
.ntc_event_cb = event_cb
}
void event_cb(const struct m0_net_tm_event *ev)
Definition: ping.c:458

Definition at line 1010 of file ping.c.