1 /* -*- mode: c; c-basic-offset: 8; indent-tabs-mode: nil; -*-
2 * vim:expandtab:shiftwidth=8:tabstop=8:
6 * Types used by the library side routines that do not need to be
7 * exposed to the user application
10 #ifndef __LNET_LIB_TYPES_H__
11 #define __LNET_LIB_TYPES_H__
13 #if defined(__linux__)
14 #include <lnet/linux/lib-types.h>
15 #elif defined(__APPLE__)
16 #include <lnet/darwin/lib-types.h>
17 #elif defined(__WINNT__)
18 #include <lnet/winnt/lib-types.h>
20 #error Unsupported Operating System
23 #include <libcfs/libcfs.h>
24 #include <libcfs/list.h>
25 #include <lnet/types.h>
27 #define WIRE_ATTR __attribute__((packed))
29 /* The wire handle's interface cookie only matches one network interface in
30 * one epoch (i.e. new cookie when the interface restarts or the node
31 * reboots). The object cookie only matches one object on that interface
32 * during that object's lifetime (i.e. no cookie re-use). */
34 __u64 wh_interface_cookie;
35 __u64 wh_object_cookie;
36 } WIRE_ATTR lnet_handle_wire_t;
38 /* byte-flip insensitive! */
39 #define LNET_WIRE_HANDLE_NONE \
40 ((const lnet_handle_wire_t) {.wh_interface_cookie = -1, .wh_object_cookie = -1})
50 /* The variant fields of the portals message header are aligned on an 8
51 * byte boundary in the message header. Note that all types used in these
52 * wire structs MUST be fixed size and the smaller types are placed at the
54 typedef struct lnet_ack {
55 lnet_handle_wire_t dst_wmd;
58 } WIRE_ATTR lnet_ack_t;
60 typedef struct lnet_put {
61 lnet_handle_wire_t ack_wmd;
66 } WIRE_ATTR lnet_put_t;
68 typedef struct lnet_get {
69 lnet_handle_wire_t return_wmd;
74 } WIRE_ATTR lnet_get_t;
76 typedef struct lnet_reply {
77 lnet_handle_wire_t dst_wmd;
78 } WIRE_ATTR lnet_reply_t;
80 typedef struct lnet_hello {
83 } WIRE_ATTR lnet_hello_t;
90 __u32 type; /* lnet_msg_type_t */
91 __u32 payload_length; /* payload data to follow */
92 /*<------__u64 aligned------->*/
100 } WIRE_ATTR lnet_hdr_t;
102 /* A HELLO message contains a magic number and protocol version
103 * code in the header's dest_nid, the peer's NID in the src_nid, and
104 * LNET_MSG_HELLO in the type field. All other common fields are zero
105 * (including payload_size; i.e. no payload).
106 * This is for use by byte-stream LNDs (e.g. TCP/IP) to check the peer is
107 * running the same protocol and to find out its NID. These LNDs should
108 * exchange HELLO messages when a connection is first established. Individual
109 * LNDs can put whatever else they fancy in lnet_hdr_t::msg.
112 __u32 magic; /* LNET_PROTO_TCP_MAGIC */
113 __u16 version_major; /* increment on incompatible change */
114 __u16 version_minor; /* increment on compatible change */
115 } WIRE_ATTR lnet_magicversion_t;
117 /* PROTO MAGIC for LNDs */
118 #define LNET_PROTO_IB_MAGIC 0x0be91b91
119 #define LNET_PROTO_OPENIB_MAGIC LNET_PROTO_IB_MAGIC
120 #define LNET_PROTO_IIB_MAGIC LNET_PROTO_IB_MAGIC
121 #define LNET_PROTO_VIB_MAGIC LNET_PROTO_IB_MAGIC
122 #define LNET_PROTO_RA_MAGIC 0x0be91b92
123 #define LNET_PROTO_QSW_MAGIC 0x0be91b93
124 #define LNET_PROTO_TCP_MAGIC 0xeebc0ded
125 #define LNET_PROTO_PTL_MAGIC 0x50746C4E /* 'PtlN' unique magic */
126 #define LNET_PROTO_GM_MAGIC 0x6d797269 /* 'myri'! */
127 #define LNET_PROTO_MX_MAGIC 0x4d583130 /* 'MX10'! */
128 #define LNET_PROTO_ACCEPTOR_MAGIC 0xacce7100
129 #define LNET_PROTO_PING_MAGIC 0x70696E67 /* 'ping' */
131 /* Placeholder for a future "unified" protocol across all LNDs */
132 /* Current LNDs that receive a request with this magic will respond with a
133 * "stub" reply using their current protocol */
134 #define LNET_PROTO_MAGIC 0x45726963 /* ! */
137 #define LNET_PROTO_TCP_VERSION_MAJOR 1
138 #define LNET_PROTO_TCP_VERSION_MINOR 0
140 /* Acceptor connection request */
142 __u32 acr_magic; /* PTL_ACCEPTOR_PROTO_MAGIC */
143 __u32 acr_version; /* protocol version */
144 __u64 acr_nid; /* target NID */
145 } WIRE_ATTR lnet_acceptor_connreq_t;
147 #define LNET_PROTO_ACCEPTOR_VERSION 1
152 typedef struct lnet_msg {
153 struct list_head msg_activelist;
154 struct list_head msg_list; /* Q for credits/MD */
156 lnet_process_id_t msg_target;
159 unsigned int msg_target_is_router:1; /* sending to a router */
160 unsigned int msg_routing:1; /* being forwarded */
161 unsigned int msg_ack:1; /* ack on finalize (PUT) */
162 unsigned int msg_sending:1; /* outgoing message */
163 unsigned int msg_receiving:1; /* being received */
164 unsigned int msg_delayed:1; /* had to Q for buffer or tx credit */
165 unsigned int msg_txcredit:1; /* taken an NI send credit */
166 unsigned int msg_peertxcredit:1; /* taken a peer send credit */
167 unsigned int msg_rtrcredit:1; /* taken a globel router credit */
168 unsigned int msg_peerrtrcredit:1; /* taken a peer router credit */
169 unsigned int msg_onactivelist:1; /* on the activelist */
171 struct lnet_peer *msg_txpeer; /* peer I'm sending to */
172 struct lnet_peer *msg_rxpeer; /* peer I received from */
175 struct lnet_libmd *msg_md;
177 unsigned int msg_len;
178 unsigned int msg_wanted;
179 unsigned int msg_offset;
180 unsigned int msg_niov;
181 struct iovec *msg_iov;
182 lnet_kiov_t *msg_kiov;
189 typedef struct lnet_libhandle {
190 struct list_head lh_hash_chain;
194 #define lh_entry(ptr, type, member) \
195 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
197 typedef struct lnet_eq {
198 struct list_head eq_list;
199 lnet_libhandle_t eq_lh;
200 lnet_seq_t eq_enq_seq;
201 lnet_seq_t eq_deq_seq;
202 unsigned int eq_size;
203 lnet_event_t *eq_events;
205 lnet_eq_handler_t eq_callback;
208 typedef struct lnet_me {
209 struct list_head me_list;
210 lnet_libhandle_t me_lh;
211 lnet_process_id_t me_match_id;
212 unsigned int me_portal;
214 __u64 me_ignore_bits;
215 lnet_unlink_t me_unlink;
216 struct lnet_libmd *me_md;
219 typedef struct lnet_libmd {
220 struct list_head md_list;
221 lnet_libhandle_t md_lh;
224 unsigned int md_offset;
225 unsigned int md_length;
226 unsigned int md_max_size;
229 unsigned int md_options;
230 unsigned int md_flags;
234 unsigned int md_niov; /* # frags */
236 struct iovec iov[LNET_MAX_IOV];
237 lnet_kiov_t kiov[LNET_MAX_IOV];
241 #define LNET_MD_FLAG_ZOMBIE (1 << 0)
242 #define LNET_MD_FLAG_AUTO_UNLINK (1 << 1)
244 #ifdef LNET_USE_LIB_FREELIST
247 void *fl_objs; /* single contiguous array of objects */
248 int fl_nobjs; /* the number of them */
249 int fl_objsize; /* the size (including overhead) of each of them */
250 struct list_head fl_list; /* where they are enqueued */
255 struct list_head fo_list; /* enqueue on fl_list */
256 void *fo_contents; /* aligned contents */
261 /* info about peers we are trying to fail */
262 struct list_head tp_list; /* ln_test_peers */
263 lnet_nid_t tp_nid; /* matching nid */
264 unsigned int tp_threshold; /* # failures to simulate */
267 #define LNET_COOKIE_TYPE_MD 1
268 #define LNET_COOKIE_TYPE_ME 2
269 #define LNET_COOKIE_TYPE_EQ 3
270 #define LNET_COOKIE_TYPES 4
271 /* LNET_COOKIE_TYPES must be a power of 2, so the cookie type can be
272 * extracted by masking with (LNET_COOKIE_TYPES - 1) */
274 struct lnet_ni; /* forward ref */
276 typedef struct lnet_lnd
278 /* fields managed by portals */
279 struct list_head lnd_list; /* stash in the LND table */
280 int lnd_refcount; /* # active instances */
282 /* fields initialised by the LND */
283 unsigned int lnd_type;
285 int (*lnd_startup) (struct lnet_ni *ni);
286 void (*lnd_shutdown) (struct lnet_ni *ni);
287 int (*lnd_ctl)(struct lnet_ni *ni, unsigned int cmd, void *arg);
289 /* In data movement APIs below, payload buffers are described as a set
290 * of 'niov' fragments which are...
292 * in virtual memory (struct iovec *iov != NULL)
294 * in pages (kernel only: plt_kiov_t *kiov != NULL).
295 * The LND may NOT overwrite these fragment descriptors.
296 * An 'offset' and may specify a byte offset within the set of
297 * fragments to start from
300 /* Start sending a preformatted message. 'private' is NULL for PUT and
301 * GET messages; otherwise this is a response to an incoming message
302 * and 'private' is the 'private' passed to lnet_parse(). Return
303 * non-zero for immediate failure, otherwise complete later with
305 int (*lnd_send)(struct lnet_ni *ni, void *private, lnet_msg_t *msg);
307 /* Start receiving 'mlen' bytes of payload data, skipping the following
308 * 'rlen' - 'mlen' bytes. 'private' is the 'private' passed to
309 * lnet_parse(). Return non-zero for immedaite failure, otherwise
310 * complete later with lnet_finalize(). This also gives back a receive
311 * credit if the LND does flow control. */
312 int (*lnd_recv)(struct lnet_ni *ni, void *private, lnet_msg_t *msg,
313 int delayed, unsigned int niov,
314 struct iovec *iov, lnet_kiov_t *kiov,
315 unsigned int offset, unsigned int mlen, unsigned int rlen);
317 /* lnet_parse() has had to delay processing of this message
318 * (e.g. waiting for a forwarding buffer or send credits). Give the
319 * LND a chance to free urgently needed resources. If called, return 0
320 * for success and do NOT give back a receive credit; that has to wait
321 * until lnd_recv() gets called. On failure return < 0 and
322 * release resources; lnd_recv() will not be called. */
323 int (*lnd_eager_recv)(struct lnet_ni *ni, void *private, lnet_msg_t *msg,
324 void **new_privatep);
326 /* notification of peer health */
327 void (*lnd_notify)(struct lnet_ni *ni, lnet_nid_t peer, int alive);
330 /* accept a new connection */
331 int (*lnd_accept)(struct lnet_ni *ni, cfs_socket_t *sock);
333 /* wait for something to happen */
334 void (*lnd_wait)(struct lnet_ni *ni, int milliseconds);
336 /* ensure non-RDMA messages can be received outside liblustre */
337 int (*lnd_setasync)(struct lnet_ni *ni, lnet_process_id_t id, int nasync);
341 #define LNET_MAX_INTERFACES 16
343 typedef struct lnet_ni {
344 struct list_head ni_list; /* chain on ln_nis */
345 struct list_head ni_txq; /* messages waiting for tx credits */
346 int ni_maxtxcredits; /* # tx credits */
347 int ni_txcredits; /* # tx credits free */
348 int ni_mintxcredits; /* lowest it's been */
349 int ni_peertxcredits; /* # per-peer send credits */
350 lnet_nid_t ni_nid; /* interface's NID */
351 void *ni_data; /* instance-specific data */
352 lnd_t *ni_lnd; /* procedural interface */
353 int ni_refcount; /* reference count */
354 char *ni_interfaces[LNET_MAX_INTERFACES]; /* equivalent interfaces to use */
357 typedef struct lnet_peer {
358 struct list_head lp_hashlist; /* chain on peer hash */
359 struct list_head lp_txq; /* messages blocking for tx credits */
360 struct list_head lp_rtrq; /* messages blocking for router credits */
361 struct list_head lp_rtr_list; /* chain on router list */
362 int lp_txcredits; /* # tx credits available */
363 int lp_mintxcredits; /* low water mark */
364 int lp_rtrcredits; /* # router credits */
365 int lp_minrtrcredits; /* low water mark */
366 unsigned int lp_alive:1; /* alive/dead? */
367 unsigned int lp_notify:1; /* notification outstanding? */
368 unsigned int lp_notifylnd:1; /* outstanding notification for LND? */
369 unsigned int lp_notifying:1; /* some thread is handling notification */
370 unsigned int lp_ping_notsent; /* SEND event outstanding from ping */
371 int lp_alive_count; /* # times router went dead<->alive */
372 long lp_txqnob; /* bytes queued for sending */
373 time_t lp_timestamp; /* time of last aliveness news */
374 time_t lp_ping_timestamp; /* time of last ping attempt */
375 time_t lp_ping_deadline; /* != 0 if ping reply expected */
376 lnet_ni_t *lp_ni; /* interface peer is on */
377 lnet_nid_t lp_nid; /* peer's NID */
378 int lp_refcount; /* # refs */
379 int lp_rtr_refcount; /* # refs from lnet_route_t::lr_gateway */
383 struct list_head lr_list; /* chain on net */
384 lnet_peer_t *lr_gateway; /* router node */
388 struct list_head lrn_list; /* chain on ln_remote_nets */
389 struct list_head lrn_routes; /* routes to me */
390 __u32 lrn_net; /* my net number */
391 unsigned int lrn_hops; /* how far I am */
395 struct list_head rbp_bufs; /* my free buffer pool */
396 struct list_head rbp_msgs; /* messages blocking for a buffer */
397 int rbp_npages; /* # pages in each buffer */
398 int rbp_nbuffers; /* # buffers */
399 int rbp_credits; /* # free buffers / blocked messages */
400 int rbp_mincredits; /* low water mark */
404 struct list_head rb_list; /* chain on rbp_bufs */
405 lnet_rtrbufpool_t *rb_pool; /* owning pool */
406 lnet_kiov_t rb_kiov[0]; /* the buffer space */
423 #define LNET_PEER_HASHSIZE 503 /* prime! */
425 #define LNET_NRBPOOLS 3 /* # different router buffer pools */
427 #define LNET_PROTO_PING_MATCHBITS 0x8000000000000000LL
428 #define LNET_PROTO_PING_VERSION 1
434 lnet_nid_t pi_nid[0];
435 } WIRE_ATTR lnet_ping_info_t;
437 /* Options for lnet_portal_t::ptl_options */
438 #define LNET_PTL_LAZY (1 << 0)
440 struct list_head ptl_ml; /* match list */
441 struct list_head ptl_msgq; /* messages blocking for MD */
442 __u64 ptl_msgq_version; /* validity stamp */
443 unsigned int ptl_options;
447 /* < 0 == startup error */
448 #define LNET_RC_STATE_SHUTDOWN 0 /* not started */
449 #define LNET_RC_STATE_RUNNING 1 /* started up OK */
450 #define LNET_RC_STATE_STOPTHREAD 2 /* telling thread to stop */
451 #define LNET_RC_STATE_UNLINKING 3 /* unlinking RC MD */
452 #define LNET_RC_STATE_UNLINKED 4 /* RC's MD has been unlinked */
456 /* Stuff initialised at LNetInit() */
457 int ln_init; /* LNetInit() called? */
458 int ln_refcount; /* LNetNIInit/LNetNIFini counter */
459 int ln_niinit_self; /* Have I called LNetNIInit myself? */
461 int ln_ptlcompat; /* do I support talking to portals? */
463 struct list_head ln_lnds; /* registered LNDs */
467 cfs_waitq_t ln_waitq;
468 struct semaphore ln_api_mutex;
469 struct semaphore ln_lnd_mutex;
471 # ifndef HAVE_LIBPTHREAD
476 pthread_cond_t ln_cond;
477 pthread_mutex_t ln_lock;
478 pthread_mutex_t ln_api_mutex;
479 pthread_mutex_t ln_lnd_mutex;
483 /* Stuff initialised at LNetNIInit() */
485 int ln_shutdown; /* shutdown in progress */
486 int ln_nportals; /* # portals */
487 lnet_portal_t *ln_portals; /* the vector of portals */
489 lnet_pid_t ln_pid; /* requested pid */
491 struct list_head ln_nis; /* LND instances */
492 lnet_ni_t *ln_loni; /* the loopback NI */
493 lnet_ni_t *ln_eqwaitni; /* NI to wait for events in */
494 struct list_head ln_zombie_nis; /* dying LND instances */
495 int ln_nzombie_nis; /* # of NIs to wait for */
497 struct list_head ln_remote_nets; /* remote networks with routes to them */
498 __u64 ln_remote_nets_version; /* validity stamp */
500 struct list_head ln_routers; /* list of all known routers */
501 __u64 ln_routers_version; /* validity stamp */
503 struct list_head *ln_peer_hash; /* NID->peer hash */
504 int ln_npeers; /* # peers extant */
505 int ln_peertable_version; /* /proc validity stamp */
507 int ln_routing; /* am I a router? */
508 lnet_rtrbufpool_t ln_rtrpools[LNET_NRBPOOLS]; /* router buffer pools */
510 int ln_lh_hash_size; /* size of lib handle hash table */
511 struct list_head *ln_lh_hash_table; /* all extant lib handles, this interface */
512 __u64 ln_next_object_cookie; /* cookie generator */
513 __u64 ln_interface_cookie; /* uniquely identifies this ni in this epoch */
515 char *ln_network_tokens; /* space for network names */
516 int ln_network_tokens_nob;
518 int ln_testprotocompat; /* test protocol compatibility flags */
520 struct list_head ln_finalizeq; /* msgs waiting to complete finalizing */
522 void **ln_finalizers; /* threads doing finalization */
523 int ln_nfinalizers; /* max # threads finalizing */
527 struct list_head ln_test_peers; /* failure simulation */
529 lnet_handle_md_t ln_ping_target_md;
530 lnet_handle_eq_t ln_ping_target_eq;
531 lnet_ping_info_t *ln_ping_info;
534 int ln_rc_state; /* router checker startup/shutdown state */
535 struct semaphore ln_rc_signal; /* serialise startup/shutdown */
536 lnet_handle_eq_t ln_rc_eqh; /* router checker's event queue */
539 #ifdef LNET_USE_LIB_FREELIST
540 lnet_freelist_t ln_free_mes;
541 lnet_freelist_t ln_free_msgs;
542 lnet_freelist_t ln_free_mds;
543 lnet_freelist_t ln_free_eqs;
545 struct list_head ln_active_msgs;
546 struct list_head ln_active_mds;
547 struct list_head ln_active_eqs;
549 lnet_counters_t ln_counters;