-typedef struct ksock_conn
-{
- struct ksock_peer *ksnc_peer; /* owning peer */
- struct ksock_route *ksnc_route; /* owning route */
- struct list_head ksnc_list; /* stash on peer's conn list */
- cfs_socket_t *ksnc_sock; /* actual socket */
- void *ksnc_saved_data_ready; /* socket's original data_ready() callback */
- void *ksnc_saved_write_space; /* socket's original write_space() callback */
- atomic_t ksnc_conn_refcount; /* conn refcount */
- atomic_t ksnc_sock_refcount; /* sock refcount */
- ksock_sched_t *ksnc_scheduler; /* who schedules this connection */
- __u32 ksnc_myipaddr; /* my IP */
- __u32 ksnc_ipaddr; /* peer's IP */
- int ksnc_port; /* peer's port */
- int ksnc_type:3; /* type of connection, should be signed value */
- int ksnc_closing:1; /* being shut down */
- int ksnc_flip:1; /* flip or not, only for V2.x */
- int ksnc_zc_capable:1; /* enable to ZC */
- struct ksock_proto *ksnc_proto; /* protocol for the connection */
-
- /* reader */
- struct list_head ksnc_rx_list; /* where I enq waiting input or a forwarding descriptor */
- cfs_time_t ksnc_rx_deadline; /* when (in jiffies) receive times out */
- __u8 ksnc_rx_started; /* started receiving a message */
- __u8 ksnc_rx_ready; /* data ready to read */
- __u8 ksnc_rx_scheduled; /* being progressed */
- __u8 ksnc_rx_state; /* what is being read */
- int ksnc_rx_nob_left; /* # bytes to next hdr/body */
- int ksnc_rx_nob_wanted; /* bytes actually wanted */
- int ksnc_rx_niov; /* # iovec frags */
- struct iovec *ksnc_rx_iov; /* the iovec frags */
- int ksnc_rx_nkiov; /* # page frags */
- lnet_kiov_t *ksnc_rx_kiov; /* the page frags */
- ksock_rxiovspace_t ksnc_rx_iov_space; /* space for frag descriptors */
- __u32 ksnc_rx_csum; /* partial checksum for incoming data */
- void *ksnc_cookie; /* rx lnet_finalize passthru arg */
- ksock_msg_t ksnc_msg; /* incoming message buffer:
- * V2.x message takes the whole struct
- * V1.x message is a bare lnet_hdr_t, it's stored
- * in ksnc_msg.ksm_u.lnetmsg */
-
- /* WRITER */
- struct list_head ksnc_tx_list; /* where I enq waiting for output space */
- struct list_head ksnc_tx_queue; /* packets waiting to be sent */
- ksock_tx_t *ksnc_tx_mono; /* V2.x only, next mono-packet, mono-packet is :
- * a. lnet packet without piggyback
- * b. noop ZC-ACK packet */
- cfs_time_t ksnc_tx_deadline; /* when (in jiffies) tx times out */
- int ksnc_tx_bufnob; /* send buffer marker */
- atomic_t ksnc_tx_nob; /* # bytes queued */
- int ksnc_tx_ready; /* write space */
- int ksnc_tx_scheduled; /* being progressed */
-
-#if !SOCKNAL_SINGLE_FRAG_RX
- struct iovec ksnc_rx_scratch_iov[LNET_MAX_IOV];
-#endif
-#if !SOCKNAL_SINGLE_FRAG_TX
- struct iovec ksnc_tx_scratch_iov[LNET_MAX_IOV];
-#endif
-} ksock_conn_t;
-
-typedef struct ksock_route
-{
- struct list_head ksnr_list; /* chain on peer route list */
- struct list_head ksnr_connd_list; /* chain on ksnr_connd_routes */
- struct ksock_peer *ksnr_peer; /* owning peer */
- atomic_t ksnr_refcount; /* # users */
- cfs_time_t ksnr_timeout; /* when (in jiffies) reconnection can happen next */
- cfs_duration_t ksnr_retry_interval; /* how long between retries */
- __u32 ksnr_myipaddr; /* my IP */
- __u32 ksnr_ipaddr; /* IP address to connect to */
- int ksnr_port; /* port to connect to */
- unsigned int ksnr_scheduled:1; /* scheduled for attention */
- unsigned int ksnr_connecting:1; /* connection establishment in progress */
- unsigned int ksnr_connected:4; /* connections established by type */
- unsigned int ksnr_deleted:1; /* been removed from peer? */
- unsigned int ksnr_share_count; /* created explicitly? */
- int ksnr_conn_count; /* # conns established by this route */
-} ksock_route_t;
-
-typedef struct ksock_peer
-{
- struct list_head ksnp_list; /* stash on global peer list */
- lnet_process_id_t ksnp_id; /* who's on the other end(s) */
- atomic_t ksnp_refcount; /* # users */
- int ksnp_sharecount; /* lconf usage counter */
- int ksnp_closing; /* being closed */
- int ksnp_accepting; /* # passive connections pending */
- int ksnp_error; /* errno on closing last conn */
- __u64 ksnp_zc_next_cookie;/* ZC completion cookie */
- __u64 ksnp_incarnation; /* latest known peer incarnation */
- struct ksock_proto *ksnp_proto; /* latest known peer protocol */
- struct list_head ksnp_conns; /* all active connections */
- struct list_head ksnp_routes; /* routes */
- struct list_head ksnp_tx_queue; /* waiting packets */
- spinlock_t ksnp_lock; /* serialize, NOT safe in g_lock */
- struct list_head ksnp_zc_req_list; /* zero copy requests wait for ACK */
- cfs_time_t ksnp_last_alive; /* when (in jiffies) I was last alive */
- lnet_ni_t *ksnp_ni; /* which network */
- int ksnp_n_passive_ips; /* # of... */
- __u32 ksnp_passive_ips[LNET_MAX_INTERFACES]; /* preferred local interfaces */
-} ksock_peer_t;
-
-typedef struct ksock_connreq
-{
- struct list_head ksncr_list; /* stash on ksnd_connd_connreqs */
- lnet_ni_t *ksncr_ni; /* chosen NI */
- cfs_socket_t *ksncr_sock; /* accepted socket */
-} ksock_connreq_t;
-
-extern ksock_nal_data_t ksocknal_data;
-extern ksock_tunables_t ksocknal_tunables;
-
-typedef struct ksock_proto
-{
- int pro_version; /* version number of protocol */
- int (*pro_send_hello)(ksock_conn_t *, ksock_hello_msg_t *); /* handshake function */
- int (*pro_recv_hello)(ksock_conn_t *, ksock_hello_msg_t *, int);/* handshake function */
- void (*pro_pack)(ksock_tx_t *); /* message pack */
- void (*pro_unpack)(ksock_msg_t *); /* message unpack */
-} ksock_proto_t;
-
-extern ksock_proto_t ksocknal_protocol_v1x;
-extern ksock_proto_t ksocknal_protocol_v2x;
+struct ksock_conn {
+ struct ksock_peer_ni *ksnc_peer; /* owning peer_ni */
+ struct ksock_conn_cb *ksnc_conn_cb; /* owning conn control block */
+ struct list_head ksnc_list; /* on peer_ni's conn list */
+ struct socket *ksnc_sock; /* actual socket */
+ void *ksnc_saved_data_ready; /* socket's original
+ * data_ready() cb */
+ void *ksnc_saved_write_space; /* socket's original
+ * write_space() cb */
+ refcount_t ksnc_conn_refcount; /* conn refcount */
+ refcount_t ksnc_sock_refcount; /* sock refcount */
+ struct ksock_sched *ksnc_scheduler; /* who schedules this
+ * connection */
+ struct sockaddr_storage ksnc_myaddr; /* my address */
+ struct sockaddr_storage ksnc_peeraddr; /* peer_ni's address */
+ signed int ksnc_type:3; /* type of connection,
+ * should be signed
+ * value */
+ unsigned int ksnc_closing:1; /* being shut down */
+ unsigned int ksnc_flip:1; /* flip or not, only for V2.x */
+ unsigned int ksnc_zc_capable:1; /* enable to ZC */
+ const struct ksock_proto *ksnc_proto; /* protocol for the connection */
+
+ /* READER */
+
+ /* where I enq waiting input or a forwarding descriptor */
+ struct list_head ksnc_rx_list;
+ time64_t ksnc_rx_deadline; /* when (in seconds) receive times out */
+ __u8 ksnc_rx_started; /* started receiving a message */
+ __u8 ksnc_rx_ready; /* data ready to read */
+ __u8 ksnc_rx_scheduled;/* being progressed */
+ __u8 ksnc_rx_state; /* what is being read */
+ int ksnc_rx_nob_left; /* # bytes to next hdr/body */
+ int ksnc_rx_nob_wanted; /* bytes actually wanted */
+ int ksnc_rx_niov; /* # kvec frags */
+ struct kvec *ksnc_rx_iov; /* the kvec frags */
+ int ksnc_rx_nkiov; /* # page frags */
+ struct bio_vec *ksnc_rx_kiov; /* the page frags */
+ union ksock_rxiovspace ksnc_rx_iov_space;/* space for frag descriptors */
+ __u32 ksnc_rx_csum; /* partial checksum for incoming
+ * data */
+ struct lnet_msg *ksnc_lnet_msg; /* rx lnet_finalize arg*/
+ struct ksock_msg ksnc_msg; /* incoming message buffer:
+ * V2.x message takes the
+ * whole struct
+ * V1.x message is a bare
+ * struct lnet_hdr, it's stored
+ * in ksnc_msg.ksm_u.lnetmsg
+ */
+ /* -- WRITER -- */
+ /* where I enq waiting for output space */
+ struct list_head ksnc_tx_list;
+ /* packets waiting to be sent */
+ struct list_head ksnc_tx_queue;
+ /* next TX that can carry a LNet message or ZC-ACK */
+ struct ksock_tx *ksnc_tx_carrier;
+ /* when (in seconds) tx times out */
+ time64_t ksnc_tx_deadline;
+ /* send buffer marker */
+ int ksnc_tx_bufnob;
+ /* # bytes queued */
+ atomic_t ksnc_tx_nob;
+ /* write space */
+ int ksnc_tx_ready;
+ /* being progressed */
+ int ksnc_tx_scheduled;
+ /* time stamp of the last posted TX */
+ time64_t ksnc_tx_last_post;
+};
+
+#define SOCKNAL_CONN_COUNT_MAX_BITS 8 /* max conn count bits */
+
+struct ksock_conn_cb {
+ struct list_head ksnr_connd_list;/* chain on ksnr_connd_routes */
+ struct ksock_peer_ni *ksnr_peer; /* owning peer_ni */
+ refcount_t ksnr_refcount; /* # users */
+ time64_t ksnr_timeout; /* when (in secs) reconnection
+ * can happen next
+ */
+ time64_t ksnr_retry_interval;/* secs between retries */
+ int ksnr_myiface; /* interface index */
+ struct sockaddr_storage ksnr_addr; /* IP address to connect to */
+ unsigned int ksnr_scheduled:1;/* scheduled for attention */
+ unsigned int ksnr_connecting:1;/* connection in progress */
+ unsigned int ksnr_connected:4;/* connections by type */
+ unsigned int ksnr_deleted:1; /* been removed from peer_ni? */
+ unsigned int ksnr_ctrl_conn_count:1; /* # conns by type */
+ unsigned int ksnr_blki_conn_count:8;
+ unsigned int ksnr_blko_conn_count:8;
+ int ksnr_conn_count;/* total # conns for this cb */
+
+};
+
+#define SOCKNAL_KEEPALIVE_PING 1 /* cookie for keepalive ping */
+
+struct ksock_peer_ni {
+ struct hlist_node ksnp_list; /* stash on global peer_ni list */
+ time64_t ksnp_last_alive;/* when (in seconds) I was last alive */
+ struct lnet_process_id ksnp_id; /* who's on the other end(s) */
+ refcount_t ksnp_refcount; /* # users */
+ int ksnp_closing; /* being closed */
+ int ksnp_accepting; /* # passive connections pending */
+ int ksnp_error; /* errno on closing last conn */
+ __u64 ksnp_zc_next_cookie;/* ZC completion cookie */
+ __u64 ksnp_incarnation; /* latest known peer_ni incarnation */
+ const struct ksock_proto *ksnp_proto; /* latest known protocol */
+ struct list_head ksnp_conns; /* all active connections */
+ struct ksock_conn_cb *ksnp_conn_cb; /* conn control block */
+ struct list_head ksnp_tx_queue; /* waiting packets */
+ spinlock_t ksnp_lock; /* serialize, g_lock unsafe */
+ /* zero copy requests wait for ACK */
+ struct list_head ksnp_zc_req_list;
+ time64_t ksnp_send_keepalive; /* time to send keepalive */
+ struct lnet_ni *ksnp_ni; /* which network */
+ int ksnp_n_passive_ips; /* # of... */
+ __u32 ksnp_passive_ips[LNET_INTERFACES_NUM]; /* preferred local interfaces */
+};
+
+struct ksock_connreq {
+ /* stash on ksnd_connd_connreqs */
+ struct list_head ksncr_list;
+ /* chosen NI */
+ struct lnet_ni *ksncr_ni;
+ /* accepted socket */
+ struct socket *ksncr_sock;
+};
+
+extern struct ksock_nal_data ksocknal_data;
+extern struct ksock_tunables ksocknal_tunables;
+
+#define SOCKNAL_MATCH_NO 0 /* TX can't match type of connection */
+#define SOCKNAL_MATCH_YES 1 /* TX matches type of connection */
+#define SOCKNAL_MATCH_MAY 2 /* TX can be sent on the connection, but not preferred */
+
+struct ksock_proto {
+ int pro_version; /* version number of protocol */
+ int (*pro_send_hello)(struct ksock_conn *, struct ksock_hello_msg *); /* handshake function */
+ int (*pro_recv_hello)(struct ksock_conn *, struct ksock_hello_msg *, int);/* handshake function */
+ void (*pro_pack)(struct ksock_tx *); /* message pack */
+ void (*pro_unpack)(struct ksock_msg *); /* message unpack */
+ struct ksock_tx *(*pro_queue_tx_msg)(struct ksock_conn *, struct ksock_tx *); /* queue tx on the connection */
+ int (*pro_queue_tx_zcack)(struct ksock_conn *, struct ksock_tx *, __u64); /* queue ZC ack on the connection */
+ int (*pro_handle_zcreq)(struct ksock_conn *, __u64, int); /* handle ZC request */
+ int (*pro_handle_zcack)(struct ksock_conn *, __u64, __u64); /* handle ZC ACK */
+ int (*pro_match_tx)(struct ksock_conn *, struct ksock_tx *, int); /* msg type matches the connection type:
+ * return value:
+ * return MATCH_NO : no
+ * return MATCH_YES : matching type
+ * return MATCH_MAY : can be backup */
+};
+
+extern const struct ksock_proto ksocknal_protocol_v1x;
+extern const struct ksock_proto ksocknal_protocol_v2x;
+extern const struct ksock_proto ksocknal_protocol_v3x;