Motr  M0
sock.c File Reference
#include <sys/epoll.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <arpa/inet.h>
#include <string.h>
#include <unistd.h>
#include "lib/trace.h"
#include "lib/errno.h"
#include "lib/thread.h"
#include "lib/misc.h"
#include "lib/tlist.h"
#include "lib/types.h"
#include "lib/chan.h"
#include "lib/memory.h"
#include "lib/cookie.h"
#include "lib/bitmap.h"
#include "lib/refs.h"
#include "lib/time.h"
#include "sm/sm.h"
#include "motr/magic.h"
#include "net/net.h"
#include "net/buffer_pool.h"
#include "net/net_internal.h"
#include "format/format.h"
#include "net/sock/xcode.h"
#include "net/sock/xcode_xc.h"
Include dependency graph for sock.c:

Go to the source code of this file.

Data Structures

struct  ep
 
struct  ma
 
struct  mover_op
 
struct  mover_op_vec
 
struct  mover
 
struct  buf
 
struct  sock
 
struct  socktype
 
struct  pfamily
 

Macros

#define M0_TRACE_SUBSYSTEM   M0_TRACE_SUBSYS_NET
 
#define EP_DEBUG   (1)
 
#define MOCK_LNET   (0)
 
#define SAFE(val, exp, fallback)   ((val) != NULL ? (exp) : (fallback))
 
#define EP_F   "%s"
 
#define EP_P(e)   SAFE(e, (e)->e_ep.nep_addr, "null")
 
#define EP_FL   EP_F "->" EP_F
 
#define EP_PL(e)   EP_P(SAFE(e, ma_src(ep_ma(e)), NULL)), EP_P(e)
 
#define SOCK_F   EP_FL "/%i/%" PRIx64 "/%i"
 
#define SOCK_P(s)
 
#define B_F   "[[%i]@%p:"EP_FL"]"
 
#define B_P(b)   (b)->b_buf->nb_qtype, (b), EP_PL((b)->b_other)
 
#define TLOG(...)   do { /* M0_LOG(M0_DEBUG, __VA_ARGS__) */; } while (0)
 
#define EP_GET(e, f)   ({ struct ep *__ep = (e); ep_get(__ep); M0_CNT_INC(__ep->e_r_ ## f); })
 
#define EP_PUT(e, f)   ({ struct ep *__ep = (e); ep_put(__ep); M0_CNT_DEC(__ep->e_r_ ## f); })
 

Enumerations

enum  sock_state {
  S_INIT, S_LISTENING, S_CONNECTING, S_OPEN,
  S_DELETED
}
 
enum  mover_opcode { M_READ, M_WRITE, M_CLOSE, M_NR }
 
enum  sock_flags { HAS_READ = M0_BITS(M_READ), HAS_WRITE = M0_BITS(M_WRITE), WRITE_POLL = M0_BITS(M_NR + 1) }
 
enum  rw_state {
  R_IDLE, R_PK, R_HEADER, R_INTERVAL,
  R_PK_DONE, R_FAIL, R_DONE, R_NR,
  STATE_NR = R_NR
}
 
enum  { M0_NET_SOCK_PROTO_VERSION = 1, M0_NET_SOCK_PROTO_PUT = 0x1, M0_NET_SOCK_PROTO_GET = 0x2 }
 

Functions

 M0_TL_DESCR_DEFINE (s, "sockets", static, struct sock, s_linkage, s_magix, M0_NET_SOCK_SOCK_MAGIC, M0_NET_SOCK_SOCK_HEAD_MAGIC)
 
 M0_TL_DEFINE (s, static, struct sock)
 
 M0_TL_DESCR_DEFINE (m, "movers", static, struct mover, m_linkage, m_magix, M0_NET_SOCK_MOVER_MAGIC, M0_NET_SOCK_MOVER_HEAD_MAGIC)
 
 M0_TL_DEFINE (m, static, struct mover)
 
 M0_TL_DESCR_DEFINE (b, "buffers", static, struct buf, b_linkage, b_magix, M0_NET_SOCK_BUF_MAGIC, M0_NET_SOCK_BUF_HEAD_MAGIC)
 
 M0_TL_DEFINE (b, static, struct buf)
 
static int dom_init (const struct m0_net_xprt *xprt, struct m0_net_domain *dom)
 
static void dom_fini (struct m0_net_domain *dom)
 
static int ma_init (struct m0_net_transfer_mc *ma)
 
static int ma_confine (struct m0_net_transfer_mc *ma, const struct m0_bitmap *processors)
 
static int ma_start (struct m0_net_transfer_mc *ma, const char *name)
 
static int ma_stop (struct m0_net_transfer_mc *ma, bool cancel)
 
static void ma_fini (struct m0_net_transfer_mc *ma)
 
static int end_point_create (struct m0_net_end_point **epp, struct m0_net_transfer_mc *ma, const char *name)
 
static int buf_register (struct m0_net_buffer *nb)
 
static void buf_deregister (struct m0_net_buffer *nb)
 
static int buf_add (struct m0_net_buffer *nb)
 
static void buf_del (struct m0_net_buffer *nb)
 
static int bev_deliver_sync (struct m0_net_transfer_mc *ma)
 
static void bev_deliver_all (struct m0_net_transfer_mc *ma)
 
static bool bev_pending (struct m0_net_transfer_mc *ma)
 
static void bev_notify (struct m0_net_transfer_mc *ma, struct m0_chan *chan)
 
static m0_bcount_t get_max_buffer_size (const struct m0_net_domain *dom)
 
static m0_bcount_t get_max_buffer_segment_size (const struct m0_net_domain *)
 
static int32_t get_max_buffer_segments (const struct m0_net_domain *dom)
 
static m0_bcount_t get_max_buffer_desc_size (const struct m0_net_domain *)
 
static void poller (struct ma *ma)
 
static void ma__fini (struct ma *ma)
 
static void ma_prune (struct ma *ma)
 
static void ma_lock (struct ma *ma)
 
static void ma_unlock (struct ma *ma)
 
static bool ma_is_locked (const struct ma *ma)
 
static bool ma_invariant (const struct ma *ma)
 
static void ma_event_post (struct ma *ma, enum m0_net_tm_state state)
 
static void ma_buf_done (struct ma *ma)
 
static void ma_buf_timeout (struct ma *ma)
 
static struct bufma_recv_buf (struct ma *ma, m0_bcount_t len)
 
static struct epma_src (struct ma *ma)
 
static int ep_find (struct ma *ma, const char *name, struct ep **out)
 
static int ep_create (struct ma *ma, struct addr *addr, const char *name, struct ep **out)
 
static void ep_free (struct ep *ep)
 
static void ep_put (struct ep *ep)
 
static void ep_get (struct ep *ep)
 
static bool ep_eq (const struct ep *ep, const struct addr *addr)
 
static struct maep_ma (struct ep *ep)
 
static struct epep_net (struct m0_net_end_point *net)
 
static void ep_release (struct m0_ref *ref)
 
static bool ep_invariant (const struct ep *ep)
 
static int ep_add (struct ep *ep, struct mover *w)
 
static void ep_del (struct mover *w)
 
static int ep_balance (struct ep *ep)
 
static int addr_resolve (struct addr *addr, const char *name)
 
static int addr_parse (struct addr *addr, const char *name)
 
static int addr_parse_lnet (struct addr *addr, const char *name)
 
static int addr_parse_native (struct addr *addr, const char *name)
 
static void addr_decode (struct addr *addr, const struct sockaddr *sa)
 
static void addr_encode (const struct addr *addr, struct sockaddr *sa)
 
static char * addr_print (const struct addr *addr)
 
static bool addr_invariant (const struct addr *addr)
 
static bool addr_eq (const struct addr *a0, const struct addr *a1)
 
static int sock_in (struct sock *s)
 
static void sock_out (struct sock *s)
 
static void sock_close (struct sock *s)
 
static void sock_done (struct sock *s, bool balance)
 
static void sock_fini (struct sock *s)
 
static bool sock_event (struct sock *s, uint32_t ev)
 
static int sock_ctl (struct sock *s, int op, uint32_t flags)
 
static int sock_init_fd (int fd, struct sock *s, struct ep *ep, uint32_t flags)
 
static int sock_init (int fd, struct ep *src, struct ep *tgt, uint32_t flags)
 
static struct moversock_writer (struct sock *s)
 
static bool sock_invariant (const struct sock *s)
 
static struct mabuf_ma (struct buf *buf)
 
static bool buf_invariant (const struct buf *buf)
 
static void buf_fini (struct buf *buf)
 
static int buf_accept (struct buf *buf, struct mover *m)
 
static void buf_done (struct buf *buf, int rc)
 
static void buf_complete (struct buf *buf)
 
static int bdesc_create (struct addr *addr, struct buf *buf, struct m0_net_buf_desc *out)
 
static int bdesc_encode (const struct bdesc *bd, struct m0_net_buf_desc *out)
 
static int bdesc_decode (const struct m0_net_buf_desc *nbd, struct bdesc *out)
 
static void mover_init (struct mover *m, struct ma *ma, const struct mover_op_vec *vop)
 
static void mover_fini (struct mover *m)
 
static int mover_op (struct mover *m, struct sock *s, int op)
 
static bool mover_is_reader (const struct mover *m)
 
static bool mover_is_writer (const struct mover *m)
 
static bool mover_invariant (const struct mover *m)
 
static m0_bcount_t pk_size (const struct mover *m, const struct sock *s)
 
static m0_bcount_t pk_tsize (const struct mover *m)
 
static m0_bcount_t pk_dnob (const struct mover *m)
 
static int pk_state (const struct mover *w)
 
static int pk_io (struct mover *w, struct sock *s, uint64_t flag, struct m0_bufvec *bv, m0_bcount_t size)
 
static int pk_iov_prep (struct mover *m, struct iovec *iv, int nr, struct m0_bufvec *bv, m0_bcount_t size, int *count)
 
static void pk_header_init (struct mover *m, struct sock *s)
 
static int pk_header_done (struct mover *m)
 
static void pk_done (struct mover *m)
 
static void pk_encdec (struct mover *m, enum m0_xcode_what what)
 
static void pk_decode (struct mover *m)
 
static void pk_encode (struct mover *m)
 
static int stream_idle (struct mover *self, struct sock *s)
 
static int stream_pk (struct mover *self, struct sock *s)
 
static int stream_header (struct mover *self, struct sock *s)
 
static int stream_interval (struct mover *self, struct sock *s)
 
static int stream_pk_done (struct mover *self, struct sock *s)
 
static int dgram_idle (struct mover *self, struct sock *s)
 
static int dgram_pk (struct mover *self, struct sock *s)
 
static int dgram_header (struct mover *self, struct sock *s)
 
static int dgram_interval (struct mover *self, struct sock *s)
 
static int dgram_pk_done (struct mover *self, struct sock *s)
 
static int writer_idle (struct mover *self, struct sock *s)
 
static int writer_pk (struct mover *self, struct sock *s)
 
static int writer_write (struct mover *self, struct sock *s)
 
static int writer_pk_done (struct mover *self, struct sock *s)
 
static int get_idle (struct mover *self, struct sock *s)
 
static int get_pk (struct mover *self, struct sock *s)
 
static void writer_done (struct mover *self, struct sock *s)
 
static void writer_error (struct mover *w, struct sock *s, int rc)
 
static m0_bcount_t stream_pk_size (const struct mover *w, const struct sock *s)
 
static void stream_error (struct mover *m, struct sock *s)
 
static m0_bcount_t dgram_pk_size (const struct mover *w, const struct sock *s)
 
static void dgram_error (struct mover *m, struct sock *s)
 
static void ip4_encode (const struct addr *a, struct sockaddr *sa)
 
static void ip4_decode (struct addr *a, const struct sockaddr *sa)
 
static void ip6_encode (const struct addr *a, struct sockaddr *sa)
 
static void ip6_decode (struct addr *a, const struct sockaddr *sa)
 
static m0_bcount_t get_rpc_max_seg_size (struct m0_net_domain *ndom)
 
static uint32_t get_rpc_max_segs_nr (struct m0_net_domain *ndom)
 
static void get_done (struct mover *w, struct sock *s)
 
M0_INTERNAL int m0_net_sock_mod_init (void)
 
M0_INTERNAL void m0_net_sock_mod_fini (void)
 
M0_INTERNAL void mover__print (const struct mover *m)
 
M0_INTERNAL void addr__print (const struct addr *addr)
 
M0_INTERNAL void sock__print (const struct sock *sock)
 
M0_INTERNAL void ep__print (const struct ep *ep)
 
M0_INTERNAL void buf__print (const struct buf *buf)
 
M0_INTERNAL void ma__print (const struct ma *ma)
 

Variables

enum sock_state M0_XCA_DOMAIN
 
static const struct m0_sm_conf sock_conf
 
static const struct m0_sm_conf rw_conf
 
static const struct mover_op_vec stream_reader_op
 
static const struct mover_op_vec dgram_reader_op
 
static const struct mover_op_vec writer_op
 
static const struct mover_op_vec get_op
 
static const struct pfamily pf []
 
static const struct socktype stype []
 
static const struct m0_format_tag put_tag
 
static const struct m0_format_tag get_tag
 
static char autotm [1024] = {}
 
static struct m0_sm_state_descr sock_conf_state []
 
static struct m0_sm_trans_descr sock_conf_trans []
 
static struct m0_sm_state_descr rw_conf_state []
 
static struct m0_sm_trans_descr rw_conf_trans []
 
static const struct m0_net_xprt_ops xprt_ops
 
const struct m0_net_xprt m0_net_lnet_xprt
 
const struct m0_net_xprt m0_net_sock_xprt