4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 only,
8 * as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License version 2 for more details (a copy is included
14 * in the LICENSE file that accompanied this code).
16 * You should have received a copy of the GNU General Public License
17 * version 2 along with this program; If not, see
18 * http://www.gnu.org/licenses/gpl-2.0.html
23 * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2012, 2017, Intel Corporation.
29 * This file is part of Lustre, http://www.lustre.org/
30 * Lustre is a trademark of Sun Microsystems, Inc.
32 * lnet/include/lnet/lib-types.h
34 * Types used by the library side routines that do not need to be
35 * exposed to the user application
38 #ifndef __LNET_LIB_TYPES_H__
39 #define __LNET_LIB_TYPES_H__
42 # error This include is only for kernel use.
45 #include <linux/kthread.h>
46 #include <linux/uio.h>
47 #include <linux/semaphore.h>
48 #include <linux/types.h>
49 #include <linux/kref.h>
51 #include <uapi/linux/lnet/lnet-dlc.h>
52 #include <uapi/linux/lnet/lnetctl.h>
53 #include <uapi/linux/lnet/nidstr.h>
55 /* Max payload size */
56 #define LNET_MAX_PAYLOAD LNET_MTU
58 /** limit on the number of fragments in discontiguous MDs */
59 #define LNET_MAX_IOV 256
62 * This is the maximum health value.
63 * All local and peer NIs created have their health default to this value.
65 #define LNET_MAX_HEALTH_VALUE 1000
66 #define LNET_MAX_SELECTION_PRIORITY UINT_MAX
71 enum lnet_msg_hstatus {
72 LNET_MSG_STATUS_OK = 0,
73 LNET_MSG_STATUS_LOCAL_INTERRUPT,
74 LNET_MSG_STATUS_LOCAL_DROPPED,
75 LNET_MSG_STATUS_LOCAL_ABORTED,
76 LNET_MSG_STATUS_LOCAL_NO_ROUTE,
77 LNET_MSG_STATUS_LOCAL_ERROR,
78 LNET_MSG_STATUS_LOCAL_TIMEOUT,
79 LNET_MSG_STATUS_REMOTE_ERROR,
80 LNET_MSG_STATUS_REMOTE_DROPPED,
81 LNET_MSG_STATUS_REMOTE_TIMEOUT,
82 LNET_MSG_STATUS_NETWORK_TIMEOUT,
86 struct lnet_rsp_tracker {
87 /* chain on the waiting list */
88 struct list_head rspt_on_list;
92 lnet_nid_t rspt_next_hop_nid;
93 /* deadline of the REPLY/ACK */
94 ktime_t rspt_deadline;
96 struct lnet_handle_md rspt_mdh;
100 struct list_head msg_activelist;
101 struct list_head msg_list; /* Q for credits/MD */
103 struct lnet_process_id msg_target;
104 /* Primary NID of the source. */
105 lnet_nid_t msg_initiator;
106 /* where is it from, it's only for building event */
111 * hold parameters in case message is with held due
114 lnet_nid_t msg_src_nid_param;
115 lnet_nid_t msg_rtr_nid_param;
118 * Deadline for the message after which it will be finalized if it
121 ktime_t msg_deadline;
123 /* The message health status. */
124 enum lnet_msg_hstatus msg_health_status;
125 /* This is a recovery message */
127 /* the number of times a transmission has been retried */
129 /* flag to indicate that we do not want to resend this message */
132 /* committed for sending */
133 unsigned int msg_tx_committed:1;
134 /* CPT # this message committed for sending */
135 unsigned int msg_tx_cpt:15;
136 /* committed for receiving */
137 unsigned int msg_rx_committed:1;
138 /* CPT # this message committed for receiving */
139 unsigned int msg_rx_cpt:15;
140 /* queued for tx credit */
141 unsigned int msg_tx_delayed:1;
142 /* queued for RX buffer */
143 unsigned int msg_rx_delayed:1;
144 /* ready for pending on RX delay list */
145 unsigned int msg_rx_ready_delay:1;
147 unsigned int msg_vmflush:1; /* VM trying to free memory */
148 unsigned int msg_target_is_router:1; /* sending to a router */
149 unsigned int msg_routing:1; /* being forwarded */
150 unsigned int msg_ack:1; /* ack on finalize (PUT) */
151 unsigned int msg_sending:1; /* outgoing message */
152 unsigned int msg_receiving:1; /* being received */
153 unsigned int msg_txcredit:1; /* taken an NI send credit */
154 unsigned int msg_peertxcredit:1; /* taken a peer send credit */
155 unsigned int msg_rtrcredit:1; /* taken a globel router credit */
156 unsigned int msg_peerrtrcredit:1; /* taken a peer router credit */
157 unsigned int msg_onactivelist:1; /* on the activelist */
158 unsigned int msg_rdma_get:1;
160 struct lnet_peer_ni *msg_txpeer; /* peer I'm sending to */
161 struct lnet_peer_ni *msg_rxpeer; /* peer I received from */
164 struct lnet_libmd *msg_md;
165 /* the NI the message was sent or received over */
166 struct lnet_ni *msg_txni;
167 struct lnet_ni *msg_rxni;
169 unsigned int msg_len;
170 unsigned int msg_wanted;
171 unsigned int msg_offset;
172 unsigned int msg_niov;
173 struct bio_vec *msg_kiov;
175 struct lnet_event msg_ev;
176 struct lnet_hdr msg_hdr;
179 struct lnet_libhandle {
180 struct list_head lh_hash_chain;
184 #define lh_entry(ptr, type, member) \
185 ((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
188 struct list_head me_list;
190 struct lnet_process_id me_match_id;
191 unsigned int me_portal;
192 unsigned int me_pos; /* hash offset in mt_hash */
194 __u64 me_ignore_bits;
195 enum lnet_unlink me_unlink;
196 struct lnet_libmd *me_md;
200 struct list_head md_list;
201 struct lnet_libhandle md_lh;
202 struct lnet_me *md_me;
204 unsigned int md_offset;
205 unsigned int md_length;
206 unsigned int md_max_size;
209 unsigned int md_options;
210 unsigned int md_flags;
211 unsigned int md_niov; /* # frags at end of struct */
213 struct lnet_rsp_tracker *md_rspt_ptr;
214 lnet_handler_t md_handler;
215 struct lnet_handle_md md_bulk_handle;
216 struct bio_vec md_kiov[LNET_MAX_IOV];
219 #define LNET_MD_FLAG_ZOMBIE BIT(0)
220 #define LNET_MD_FLAG_AUTO_UNLINK BIT(1)
221 #define LNET_MD_FLAG_ABORTED BIT(2)
222 /* LNET_MD_FLAG_HANDLING is set when a non-unlink event handler
223 * is being called for an event relating to the md.
224 * It ensures only one such handler runs at a time.
225 * The final "unlink" event is only called once the
226 * md_refcount has reached zero, and this flag has been cleared,
227 * ensuring that it doesn't race with any other event handler
230 #define LNET_MD_FLAG_HANDLING BIT(3)
231 #define LNET_MD_FLAG_DISCARD BIT(4)
233 struct lnet_test_peer {
234 /* info about peers we are trying to fail */
235 struct list_head tp_list; /* ln_test_peers */
236 lnet_nid_t tp_nid; /* matching nid */
237 unsigned int tp_threshold; /* # failures to simulate */
240 #define LNET_COOKIE_TYPE_MD 1
241 #define LNET_COOKIE_TYPE_ME 2
242 #define LNET_COOKIE_TYPE_EQ 3
243 #define LNET_COOKIE_TYPE_BITS 2
244 #define LNET_COOKIE_MASK ((1ULL << LNET_COOKIE_TYPE_BITS) - 1ULL)
250 void (*nf_addr2str)(u32 addr, char *str, size_t size);
251 int (*nf_str2addr)(const char *str, int nob, u32 *addr);
252 int (*nf_parse_addrlist)(char *str, int len,
253 struct list_head *list);
254 int (*nf_print_addrlist)(char *buffer, int count,
255 struct list_head *list);
256 int (*nf_match_addr)(u32 addr, struct list_head *list);
257 int (*nf_min_max)(struct list_head *nidlist, u32 *min_nid,
261 struct lnet_ni; /* forward ref */
265 /* fields initialized by the LND */
268 int (*lnd_startup)(struct lnet_ni *ni);
269 void (*lnd_shutdown)(struct lnet_ni *ni);
270 int (*lnd_ctl)(struct lnet_ni *ni, unsigned int cmd, void *arg);
272 /* In data movement APIs below, payload buffers are described as a set
273 * of 'niov' fragments which are in pages.
274 * The LND may NOT overwrite these fragment descriptors.
275 * An 'offset' and may specify a byte offset within the set of
276 * fragments to start from
279 /* Start sending a preformatted message. 'private' is NULL for PUT and
280 * GET messages; otherwise this is a response to an incoming message
281 * and 'private' is the 'private' passed to lnet_parse(). Return
282 * non-zero for immediate failure, otherwise complete later with
284 int (*lnd_send)(struct lnet_ni *ni, void *private,
285 struct lnet_msg *msg);
287 /* Start receiving 'mlen' bytes of payload data, skipping the following
288 * 'rlen' - 'mlen' bytes. 'private' is the 'private' passed to
289 * lnet_parse(). Return non-zero for immedaite failure, otherwise
290 * complete later with lnet_finalize(). This also gives back a receive
291 * credit if the LND does flow control. */
292 int (*lnd_recv)(struct lnet_ni *ni, void *private, struct lnet_msg *msg,
293 int delayed, unsigned int niov,
294 struct bio_vec *kiov,
295 unsigned int offset, unsigned int mlen, unsigned int rlen);
297 /* lnet_parse() has had to delay processing of this message
298 * (e.g. waiting for a forwarding buffer or send credits). Give the
299 * LND a chance to free urgently needed resources. If called, return 0
300 * for success and do NOT give back a receive credit; that has to wait
301 * until lnd_recv() gets called. On failure return < 0 and
302 * release resources; lnd_recv() will not be called. */
303 int (*lnd_eager_recv)(struct lnet_ni *ni, void *private,
304 struct lnet_msg *msg, void **new_privatep);
306 /* notification of peer down */
307 void (*lnd_notify_peer_down)(lnet_nid_t peer);
309 /* accept a new connection */
310 int (*lnd_accept)(struct lnet_ni *ni, struct socket *sock);
313 struct lnet_tx_queue {
314 int tq_credits; /* # tx credits free */
315 int tq_credits_min; /* lowest it's been */
316 int tq_credits_max; /* total # tx credits */
317 struct list_head tq_delayed; /* delayed TXs */
320 enum lnet_net_state {
321 /* set when net block is allocated */
322 LNET_NET_STATE_INIT = 0,
323 /* set when NIs in net are started successfully */
324 LNET_NET_STATE_ACTIVE,
325 /* set if all NIs in net are in FAILED state */
326 LNET_NET_STATE_INACTIVE,
327 /* set when shutting down a NET */
328 LNET_NET_STATE_DELETING
332 /* initial state when NI is created */
333 LNET_NI_STATE_INIT = 0,
334 /* set when NI is brought up */
335 LNET_NI_STATE_ACTIVE,
336 /* set when NI is being shutdown */
337 LNET_NI_STATE_DELETING,
340 #define LNET_NI_RECOVERY_PENDING BIT(0)
341 #define LNET_NI_RECOVERY_FAILED BIT(1)
343 enum lnet_stats_type {
344 LNET_STATS_TYPE_SEND = 0,
345 LNET_STATS_TYPE_RECV,
349 struct lnet_comm_count {
350 atomic_t co_get_count;
351 atomic_t co_put_count;
352 atomic_t co_reply_count;
353 atomic_t co_ack_count;
354 atomic_t co_hello_count;
357 struct lnet_element_stats {
358 struct lnet_comm_count el_send_stats;
359 struct lnet_comm_count el_recv_stats;
360 struct lnet_comm_count el_drop_stats;
363 struct lnet_health_local_stats {
364 atomic_t hlt_local_interrupt;
365 atomic_t hlt_local_dropped;
366 atomic_t hlt_local_aborted;
367 atomic_t hlt_local_no_route;
368 atomic_t hlt_local_timeout;
369 atomic_t hlt_local_error;
372 struct lnet_health_remote_stats {
373 atomic_t hlt_remote_dropped;
374 atomic_t hlt_remote_timeout;
375 atomic_t hlt_remote_error;
376 atomic_t hlt_network_timeout;
380 /* chain on the ln_nets */
381 struct list_head net_list;
383 /* net ID, which is composed of
384 * (net_type << 16) | net_num.
385 * net_type can be one of the enumerated types defined in
386 * lnet/include/lnet/nidstr.h */
389 /* round robin selection */
392 /* total number of CPTs in the array */
395 /* cumulative CPTs of all NIs in this net */
398 /* relative net selection priority */
399 __u32 net_sel_priority;
401 /* network tunables */
402 struct lnet_ioctl_config_lnd_cmn_tunables net_tunables;
405 * boolean to indicate that the tunables have been set and
408 bool net_tunables_set;
410 /* procedural interface */
411 const struct lnet_lnd *net_lnd;
413 /* list of NIs on this net */
414 struct list_head net_ni_list;
416 /* list of NIs being added, but not started yet */
417 struct list_head net_ni_added;
419 /* dying LND instances */
420 struct list_head net_ni_zombie;
422 /* when I was last alive */
423 time64_t net_last_alive;
425 /* protects access to net_last_alive */
428 /* list of router nids preferred for this network */
429 struct list_head net_rtr_pref_nids;
433 /* chain on the lnet_net structure */
434 struct list_head ni_netlist;
436 /* chain on the recovery queue */
437 struct list_head ni_recovery;
439 /* MD handle for recovery ping */
440 struct lnet_handle_md ni_ping_mdh;
447 /* bond NI on some CPTs */
450 /* interface's NID */
453 /* instance-specific data */
457 atomic_t ni_tx_credits;
459 /* percpt TX queues */
460 struct lnet_tx_queue **ni_tx_queues;
462 /* percpt reference count */
465 /* pointer to parent network */
466 struct lnet_net *ni_net;
468 /* my health status */
469 struct lnet_ni_status *ni_status;
471 /* NI FSM. Protected by lnet_ni_lock() */
472 enum lnet_ni_state ni_state;
474 /* Recovery state. Protected by lnet_ni_lock() */
475 __u32 ni_recovery_state;
477 /* per NI LND tunables */
478 struct lnet_lnd_tunables ni_lnd_tunables;
480 /* lnd tunables set explicitly */
481 bool ni_lnd_tunables_set;
484 struct lnet_element_stats ni_stats;
485 struct lnet_health_local_stats ni_hstats;
487 /* physical device CPT */
490 /* sequence number used to round robin over nis within a net */
495 * initialized to LNET_MAX_HEALTH_VALUE
496 * Value is decremented every time we fail to send a message over
497 * this NI because of a NI specific failure.
498 * Value is incremented if we successfully send a message.
503 * Set to 1 by the LND when it receives an event telling it the device
504 * has gone into a fatal state. Set to 0 when the LND receives an
505 * even telling it the device is back online.
507 atomic_t ni_fatal_error_on;
509 /* the relative selection priority of this NI */
510 __u32 ni_sel_priority;
513 * equivalent interface to use
516 struct net *ni_net_ns; /* original net namespace */
519 #define LNET_PROTO_PING_MATCHBITS 0x8000000000000000LL
522 * Descriptor of a ping info buffer: keep a separate indicator of the
523 * size and a reference count. The type is used both as a source and
524 * sink of data, so we need to keep some information outside of the
525 * area that may be overwritten by network data.
527 struct lnet_ping_buffer {
531 struct lnet_ping_info pb_info;
534 #define LNET_PING_BUFFER_SIZE(NNIDS) \
535 offsetof(struct lnet_ping_buffer, pb_info.pi_ni[NNIDS])
536 #define LNET_PING_BUFFER_LONI(PBUF) ((PBUF)->pb_info.pi_ni[0].ns_nid)
537 #define LNET_PING_BUFFER_SEQNO(PBUF) ((PBUF)->pb_info.pi_ni[0].ns_status)
539 #define LNET_PING_INFO_TO_BUFFER(PINFO) \
540 container_of((PINFO), struct lnet_ping_buffer, pb_info)
542 struct lnet_nid_list {
543 struct list_head nl_list;
547 struct lnet_peer_ni {
548 /* chain on lpn_peer_nis */
549 struct list_head lpni_peer_nis;
550 /* chain on remote peer list */
551 struct list_head lpni_on_remote_peer_ni_list;
552 /* chain on recovery queue */
553 struct list_head lpni_recovery;
554 /* chain on peer hash */
555 struct list_head lpni_hashlist;
556 /* messages blocking for tx credits */
557 struct list_head lpni_txq;
558 /* pointer to peer net I'm part of */
559 struct lnet_peer_net *lpni_peer_net;
560 /* statistics kept on each peer NI */
561 struct lnet_element_stats lpni_stats;
562 struct lnet_health_remote_stats lpni_hstats;
563 /* spin lock protecting credits and lpni_txq */
564 spinlock_t lpni_lock;
565 /* # tx credits available */
568 int lpni_mintxcredits;
570 * Each peer_ni in a gateway maintains its own credits. This
571 * allows more traffic to gateways that have multiple interfaces.
573 /* # router credits */
576 int lpni_minrtrcredits;
577 /* bytes queued for sending */
579 /* network peer is on */
580 struct lnet_net *lpni_net;
584 struct kref lpni_kref;
585 /* health value for the peer */
586 atomic_t lpni_healthv;
587 /* recovery ping mdh */
588 struct lnet_handle_md lpni_recovery_ping_mdh;
589 /* When to send the next recovery ping */
590 time64_t lpni_next_ping;
591 /* How many pings sent during current recovery period did not receive
592 * a reply. NB: reset whenever _any_ message arrives from this peer NI
594 unsigned int lpni_ping_count;
595 /* CPT this peer attached on */
597 /* state flags -- protected by lpni_lock */
599 /* status of the peer NI as reported by the peer */
600 __u32 lpni_ns_status;
601 /* sequence number used to round robin over peer nis within a net */
603 /* sequence number used to round robin over gateways */
605 /* returned RC ping features. Protected with lpni_lock */
606 unsigned int lpni_ping_feats;
607 /* time last message was received from the peer */
608 time64_t lpni_last_alive;
609 /* preferred local nids: if only one, use lpni_pref.nid */
612 struct list_head nids;
614 /* list of router nids preferred for this peer NI */
615 struct list_head lpni_rtr_pref_nids;
616 /* The relative selection priority of this peer NI */
617 __u32 lpni_sel_priority;
618 /* number of preferred NIDs in lnpi_pref_nids */
619 __u32 lpni_pref_nnids;
622 /* Preferred path added due to traffic on non-MR peer_ni */
623 #define LNET_PEER_NI_NON_MR_PREF BIT(0)
624 /* peer is being recovered. */
625 #define LNET_PEER_NI_RECOVERY_PENDING BIT(1)
626 /* recovery ping failed */
627 #define LNET_PEER_NI_RECOVERY_FAILED BIT(2)
628 /* peer is being deleted */
629 #define LNET_PEER_NI_DELETING BIT(3)
632 /* chain on pt_peer_list */
633 struct list_head lp_peer_list;
635 /* list of peer nets */
636 struct list_head lp_peer_nets;
638 /* list of messages pending discovery*/
639 struct list_head lp_dc_pendq;
641 /* chain on router list */
642 struct list_head lp_rtr_list;
644 /* primary NID of the peer */
645 lnet_nid_t lp_primary_nid;
647 /* source NID to use during discovery */
648 lnet_nid_t lp_disc_src_nid;
650 /* net to perform discovery on */
651 __u32 lp_disc_net_id;
653 /* CPT of peer_table */
656 /* number of NIDs on this peer */
659 /* # refs from lnet_route::lr_gateway */
663 * peer specific health sensitivity value to decrement peer nis in
664 * this peer with if set to something other than 0
666 __u32 lp_health_sensitivity;
668 /* messages blocking for router credits */
669 struct list_head lp_rtrq;
671 /* routes on this peer */
672 struct list_head lp_routes;
674 /* reference count */
675 atomic_t lp_refcount;
677 /* lock protecting peer state flags and lpni_rtrq */
680 /* peer state flags */
683 /* buffer for data pushed by peer */
684 struct lnet_ping_buffer *lp_data;
686 /* MD handle for ping in progress */
687 struct lnet_handle_md lp_ping_mdh;
689 /* MD handle for push in progress */
690 struct lnet_handle_md lp_push_mdh;
692 /* number of NIDs for sizing push data */
695 /* NI config sequence number of peer */
698 /* Local NI config sequence number acked by peer */
701 /* Local NI config sequence number sent to peer */
702 __u32 lp_node_seqno_sent;
704 /* Ping error encountered during discovery. */
707 /* Push error encountered during discovery. */
710 /* Error encountered during discovery. */
713 /* time it was put on the ln_dc_working queue */
714 time64_t lp_last_queued;
716 /* link on discovery-related lists */
717 struct list_head lp_dc_list;
719 /* tasks waiting on discovery of this peer */
720 wait_queue_head_t lp_dc_waitq;
722 /* cached peer aliveness */
727 * The status flags in lp_state. Their semantics have chosen so that
728 * lp_state can be zero-initialized.
730 * A peer is marked MULTI_RAIL in two cases: it was configured using DLC
731 * as multi-rail aware, or the LNET_PING_FEAT_MULTI_RAIL bit was set.
733 * A peer is marked NO_DISCOVERY if the LNET_PING_FEAT_DISCOVERY bit was
734 * NOT set when the peer was pinged by discovery.
736 * A peer is marked ROUTER if it indicates so in the feature bit.
738 #define LNET_PEER_MULTI_RAIL BIT(0) /* Multi-rail aware */
739 #define LNET_PEER_NO_DISCOVERY BIT(1) /* Peer disabled discovery */
740 #define LNET_PEER_ROUTER_ENABLED BIT(2) /* router feature enabled */
743 * A peer is marked CONFIGURED if it was configured by DLC.
745 * In addition, a peer is marked DISCOVERED if it has fully passed
746 * through Peer Discovery.
748 * When Peer Discovery is disabled, the discovery thread will mark
749 * peers REDISCOVER to indicate that they should be re-examined if
750 * discovery is (re)enabled on the node.
752 * A peer that was created as the result of inbound traffic will not
755 #define LNET_PEER_CONFIGURED BIT(3) /* Configured via DLC */
756 #define LNET_PEER_DISCOVERED BIT(4) /* Peer was discovered */
757 #define LNET_PEER_REDISCOVER BIT(5) /* Discovery was disabled */
759 * A peer is marked DISCOVERING when discovery is in progress.
760 * The other flags below correspond to stages of discovery.
762 #define LNET_PEER_DISCOVERING BIT(6) /* Discovering */
763 #define LNET_PEER_DATA_PRESENT BIT(7) /* Remote peer data present */
764 #define LNET_PEER_NIDS_UPTODATE BIT(8) /* Remote peer info uptodate */
765 #define LNET_PEER_PING_SENT BIT(9) /* Waiting for REPLY to Ping */
766 #define LNET_PEER_PUSH_SENT BIT(10) /* Waiting for ACK of Push */
767 #define LNET_PEER_PING_FAILED BIT(11) /* Ping send failure */
768 #define LNET_PEER_PUSH_FAILED BIT(12) /* Push send failure */
770 * A ping can be forced as a way to fix up state, or as a manual
771 * intervention by an admin.
772 * A push can be forced in circumstances that would normally not
773 * allow for one to happen.
775 #define LNET_PEER_FORCE_PING BIT(13) /* Forced Ping */
776 #define LNET_PEER_FORCE_PUSH BIT(14) /* Forced Push */
778 /* force delete even if router */
779 #define LNET_PEER_RTR_NI_FORCE_DEL BIT(15)
781 /* gw undergoing alive discovery */
782 #define LNET_PEER_RTR_DISCOVERY BIT(16)
783 /* gw has undergone discovery (does not indicate success or failure) */
784 #define LNET_PEER_RTR_DISCOVERED BIT(17)
786 /* peer is marked for deletion */
787 #define LNET_PEER_MARK_DELETION BIT(18)
788 /* lnet_peer_del()/lnet_peer_del_locked() has been called on the peer */
789 #define LNET_PEER_MARK_DELETED BIT(19)
791 struct lnet_peer_net {
792 /* chain on lp_peer_nets */
793 struct list_head lpn_peer_nets;
795 /* list of peer_nis on this network */
796 struct list_head lpn_peer_nis;
798 /* pointer to the peer I'm part of */
799 struct lnet_peer *lpn_peer;
804 /* peer net health */
807 /* time of last router net check attempt */
808 time64_t lpn_rtrcheck_timestamp;
810 /* selection sequence number */
813 /* relative peer net selection priority */
814 __u32 lpn_sel_priority;
816 /* reference count */
817 atomic_t lpn_refcount;
821 #define LNET_PEER_HASH_BITS 9
822 #define LNET_PEER_HASH_SIZE (1 << LNET_PEER_HASH_BITS)
825 * peer hash table - one per CPT
827 * protected by lnet_net_lock/EX for update
832 * protected by pt_zombie_lock:
836 * pt_zombie lock nests inside lnet_net_lock
838 struct lnet_peer_table {
839 int pt_version; /* /proc validity stamp */
840 struct list_head *pt_hash; /* NID->peer hash */
841 struct list_head pt_peer_list; /* peers */
842 int pt_peers; /* # peers */
843 struct list_head pt_zombie_list; /* zombie peer_ni */
844 int pt_zombies; /* # zombie peers_ni */
845 spinlock_t pt_zombie_lock; /* protect list and count */
848 /* peer aliveness is enabled only on routers for peers in a network where the
849 * struct lnet_ni::ni_peertimeout has been set to a positive value
851 #define lnet_peer_aliveness_enabled(lp) (the_lnet.ln_routing != 0 && \
852 ((lp)->lpni_net) && \
853 (lp)->lpni_net->net_tunables.lct_peer_timeout > 0)
856 struct list_head lr_list; /* chain on net */
857 struct list_head lr_gwlist; /* chain on gateway */
858 struct lnet_peer *lr_gateway; /* router node */
859 lnet_nid_t lr_nid; /* NID used to add route */
860 __u32 lr_net; /* remote network number */
861 __u32 lr_lnet; /* local network number */
862 int lr_seq; /* sequence for round-robin */
863 __u32 lr_hops; /* how far I am */
864 unsigned int lr_priority; /* route priority */
865 atomic_t lr_alive; /* cached route aliveness */
866 bool lr_single_hop; /* this route is single-hop */
869 #define LNET_REMOTE_NETS_HASH_DEFAULT (1U << 7)
870 #define LNET_REMOTE_NETS_HASH_MAX (1U << 16)
871 #define LNET_REMOTE_NETS_HASH_SIZE (1 << the_lnet.ln_remote_nets_hbits)
873 struct lnet_remotenet {
874 /* chain on ln_remote_nets_hash */
875 struct list_head lrn_list;
877 struct list_head lrn_routes;
882 /** lnet message has credit and can be submitted to lnd for send/receive */
883 #define LNET_CREDIT_OK 0
884 /** lnet message is waiting for credit */
885 #define LNET_CREDIT_WAIT 1
886 /** lnet message is waiting for discovery */
887 #define LNET_DC_WAIT 2
889 struct lnet_rtrbufpool {
890 /* my free buffer pool */
891 struct list_head rbp_bufs;
892 /* messages blocking for a buffer */
893 struct list_head rbp_msgs;
894 /* # pages in each buffer */
896 /* requested number of buffers */
897 int rbp_req_nbuffers;
898 /* # buffers actually allocated */
900 /* # free buffers / blocked messages */
907 struct list_head rb_list; /* chain on rbp_bufs */
908 struct lnet_rtrbufpool *rb_pool; /* owning pool */
909 struct bio_vec rb_kiov[0]; /* the buffer space */
912 #define LNET_PEER_HASHSIZE 503 /* prime! */
914 enum lnet_match_flags {
915 /* Didn't match anything */
916 LNET_MATCHMD_NONE = BIT(0),
918 LNET_MATCHMD_OK = BIT(1),
919 /* Must be discarded */
920 LNET_MATCHMD_DROP = BIT(2),
921 /* match and buffer is exhausted */
922 LNET_MATCHMD_EXHAUSTED = BIT(3),
924 LNET_MATCHMD_FINISH = (LNET_MATCHMD_OK | LNET_MATCHMD_DROP),
927 /* Options for struct lnet_portal::ptl_options */
928 #define LNET_PTL_LAZY BIT(0)
929 #define LNET_PTL_MATCH_UNIQUE BIT(1) /* unique match, for RDMA */
930 #define LNET_PTL_MATCH_WILDCARD BIT(2) /* wildcard match, request portal */
932 /* parameter for matching operations (GET, PUT) */
933 struct lnet_match_info {
935 struct lnet_process_id mi_id;
938 unsigned int mi_portal;
939 unsigned int mi_rlength;
940 unsigned int mi_roffset;
943 /* ME hash of RDMA portal */
944 #define LNET_MT_HASH_BITS 8
945 #define LNET_MT_HASH_SIZE (1 << LNET_MT_HASH_BITS)
946 #define LNET_MT_HASH_MASK (LNET_MT_HASH_SIZE - 1)
947 /* we allocate (LNET_MT_HASH_SIZE + 1) entries for lnet_match_table::mt_hash,
948 * the last entry is reserved for MEs with ignore-bits */
949 #define LNET_MT_HASH_IGNORE LNET_MT_HASH_SIZE
950 /* __u64 has 2^6 bits, so need 2^(LNET_MT_HASH_BITS - LNET_MT_BITS_U64) which
951 * is 4 __u64s as bit-map, and add an extra __u64 (only use one bit) for the
952 * ME-list with ignore-bits, which is mtable::mt_hash[LNET_MT_HASH_IGNORE] */
953 #define LNET_MT_BITS_U64 6 /* 2^6 bits */
954 #define LNET_MT_EXHAUSTED_BITS (LNET_MT_HASH_BITS - LNET_MT_BITS_U64)
955 #define LNET_MT_EXHAUSTED_BMAP ((1 << LNET_MT_EXHAUSTED_BITS) + 1)
957 /* portal match table */
958 struct lnet_match_table {
959 /* reserved for upcoming patches, CPU partition ID */
961 unsigned int mt_portal; /* portal index */
962 /* match table is set as "enabled" if there's non-exhausted MD
963 * attached on mt_mhash, it's only valid for wildcard portal */
964 unsigned int mt_enabled;
965 /* bitmap to flag whether MEs on mt_hash are exhausted or not */
966 __u64 mt_exhausted[LNET_MT_EXHAUSTED_BMAP];
967 struct list_head *mt_mhash; /* matching hash */
970 /* these are only useful for wildcard portal */
971 /* Turn off message rotor for wildcard portals */
972 #define LNET_PTL_ROTOR_OFF 0
973 /* round-robin dispatch all PUT messages for wildcard portals */
974 #define LNET_PTL_ROTOR_ON 1
975 /* round-robin dispatch routed PUT message for wildcard portals */
976 #define LNET_PTL_ROTOR_RR_RT 2
977 /* dispatch routed PUT message by hashing source NID for wildcard portals */
978 #define LNET_PTL_ROTOR_HASH_RT 3
982 unsigned int ptl_index; /* portal ID, reserved */
983 /* flags on this portal: lazy, unique... */
984 unsigned int ptl_options;
985 /* list of messages which are stealing buffer */
986 struct list_head ptl_msg_stealing;
987 /* messages blocking for MD */
988 struct list_head ptl_msg_delayed;
989 /* Match table for each CPT */
990 struct lnet_match_table **ptl_mtables;
991 /* spread rotor of incoming "PUT" */
992 unsigned int ptl_rotor;
993 /* # active entries for this portal */
995 /* array of active entries' cpu-partition-id */
999 #define LNET_LH_HASH_BITS 12
1000 #define LNET_LH_HASH_SIZE (1ULL << LNET_LH_HASH_BITS)
1001 #define LNET_LH_HASH_MASK (LNET_LH_HASH_SIZE - 1)
1003 /* resource container (ME, MD, EQ) */
1004 struct lnet_res_container {
1005 unsigned int rec_type; /* container type */
1006 __u64 rec_lh_cookie; /* cookie generator */
1007 struct list_head rec_active; /* active resource list */
1008 struct list_head *rec_lh_hash; /* handle hash */
1011 /* message container */
1012 struct lnet_msg_container {
1013 int msc_init; /* initialized or not */
1014 /* max # threads finalizing */
1015 int msc_nfinalizers;
1016 /* msgs waiting to complete finalizing */
1017 struct list_head msc_finalizing;
1018 /* msgs waiting to be resent */
1019 struct list_head msc_resending;
1020 struct list_head msc_active; /* active message list */
1021 /* threads doing finalization */
1022 void **msc_finalizers;
1023 /* threads doing resends */
1024 void **msc_resenders;
1027 /* This UDSP structures need to match the user space liblnetconfig structures
1028 * in order for the marshall and unmarshall functions to be common.
1031 /* Net is described as a
1035 struct lnet_ud_net_descr {
1037 struct list_head udn_net_num_range;
1040 /* each NID range is defined as
1042 * 2. address range descriptor
1044 struct lnet_ud_nid_descr {
1045 struct lnet_ud_net_descr ud_net_id;
1046 struct list_head ud_addr_range;
1050 /* a UDSP rule can have up to three user defined NID descriptors
1051 * - src: defines the local NID range for the rule
1052 * - dst: defines the peer NID range for the rule
1053 * - rte: defines the router NID range for the rule
1055 * An action union defines the action to take when the rule
1059 struct list_head udsp_on_list;
1061 struct lnet_ud_nid_descr udsp_src;
1062 struct lnet_ud_nid_descr udsp_dst;
1063 struct lnet_ud_nid_descr udsp_rte;
1064 enum lnet_udsp_action_type udsp_action_type;
1066 __u32 udsp_priority;
1070 /* Peer Discovery states */
1071 #define LNET_DC_STATE_SHUTDOWN 0 /* not started */
1072 #define LNET_DC_STATE_RUNNING 1 /* started up OK */
1073 #define LNET_DC_STATE_STOPPING 2 /* telling thread to stop */
1075 /* Router Checker states */
1076 #define LNET_MT_STATE_SHUTDOWN 0 /* not started */
1077 #define LNET_MT_STATE_RUNNING 1 /* started up OK */
1078 #define LNET_MT_STATE_STOPPING 2 /* telling thread to stop */
1081 #define LNET_STATE_SHUTDOWN 0 /* not started */
1082 #define LNET_STATE_RUNNING 1 /* started up OK */
1083 #define LNET_STATE_STOPPING 2 /* telling thread to stop */
1086 /* CPU partition table of LNet */
1087 struct cfs_cpt_table *ln_cpt_table;
1088 /* number of CPTs in ln_cpt_table */
1089 unsigned int ln_cpt_number;
1090 unsigned int ln_cpt_bits;
1092 /* protect LNet resources (ME/MD/EQ) */
1093 struct cfs_percpt_lock *ln_res_lock;
1096 /* the vector of portals */
1097 struct lnet_portal **ln_portals;
1098 /* percpt MD container */
1099 struct lnet_res_container **ln_md_containers;
1101 /* Event Queue container */
1102 struct lnet_res_container ln_eq_container;
1103 spinlock_t ln_eq_wait_lock;
1105 unsigned int ln_remote_nets_hbits;
1107 /* protect NI, peer table, credits, routers, rtrbuf... */
1108 struct cfs_percpt_lock *ln_net_lock;
1109 /* percpt message containers for active/finalizing/freed message */
1110 struct lnet_msg_container **ln_msg_containers;
1111 struct lnet_counters **ln_counters;
1112 struct lnet_peer_table **ln_peer_tables;
1113 /* list of peer nis not on a local network */
1114 struct list_head ln_remote_peer_ni_list;
1115 /* failure simulation */
1116 struct list_head ln_test_peers;
1117 struct list_head ln_drop_rules;
1118 struct list_head ln_delay_rules;
1120 struct list_head ln_nets;
1121 /* the loopback NI */
1122 struct lnet_ni *ln_loni;
1123 /* network zombie list */
1124 struct list_head ln_net_zombie;
1125 /* resend messages list */
1126 struct list_head ln_msg_resend;
1127 /* spin lock to protect the msg resend list */
1128 spinlock_t ln_msg_resend_lock;
1130 /* remote networks with routes to them */
1131 struct list_head *ln_remote_nets_hash;
1132 /* validity stamp */
1133 __u64 ln_remote_nets_version;
1134 /* list of all known routers */
1135 struct list_head ln_routers;
1136 /* validity stamp */
1137 __u64 ln_routers_version;
1138 /* percpt router buffer pools */
1139 struct lnet_rtrbufpool **ln_rtrpools;
1142 * Ping target / Push source
1144 * The ping target and push source share a single buffer. The
1145 * ln_ping_target is protected against concurrent updates by
1148 struct lnet_handle_md ln_ping_target_md;
1149 lnet_handler_t ln_ping_target_handler;
1150 struct lnet_ping_buffer *ln_ping_target;
1151 atomic_t ln_ping_target_seqno;
1156 * ln_push_nnis contains the desired size of the push target.
1157 * The lnet_net_lock is used to handle update races. The old
1158 * buffer may linger a while after it has been unlinked, in
1159 * which case the event handler cleans up.
1161 lnet_handler_t ln_push_target_handler;
1162 struct lnet_handle_md ln_push_target_md;
1163 struct lnet_ping_buffer *ln_push_target;
1164 int ln_push_target_nnis;
1166 /* discovery event queue handle */
1167 lnet_handler_t ln_dc_handler;
1168 /* discovery requests */
1169 struct list_head ln_dc_request;
1170 /* discovery working list */
1171 struct list_head ln_dc_working;
1172 /* discovery expired list */
1173 struct list_head ln_dc_expired;
1174 /* discovery thread wait queue */
1175 wait_queue_head_t ln_dc_waitq;
1176 /* discovery startup/shutdown state */
1179 /* monitor thread startup/shutdown state */
1181 /* serialise startup/shutdown */
1182 struct semaphore ln_mt_signal;
1184 struct mutex ln_api_mutex;
1185 struct mutex ln_lnd_mutex;
1186 /* Have I called LNetNIInit myself? */
1188 /* LNetNIInit/LNetNIFini counter */
1190 /* SHUTDOWN/RUNNING/STOPPING */
1193 int ln_routing; /* am I a router? */
1194 lnet_pid_t ln_pid; /* requested pid */
1195 /* uniquely identifies this ni in this epoch */
1196 __u64 ln_interface_cookie;
1197 /* registered LNDs */
1198 const struct lnet_lnd *ln_lnds[NUM_LNDS];
1200 /* test protocol compatibility flags */
1201 unsigned long ln_testprotocompat;
1203 /* 0 - load the NIs from the mod params
1204 * 1 - do not load the NIs from the mod params
1205 * Reverse logic to ensure that other calls to LNetNIInit
1208 bool ln_nis_from_mod_params;
1211 * completion for the monitor thread. The monitor thread takes care of
1212 * checking routes, timedout messages and resending messages.
1214 struct completion ln_mt_wait_complete;
1216 /* per-cpt resend queues */
1217 struct list_head **ln_mt_resendqs;
1218 /* local NIs to recover */
1219 struct list_head ln_mt_localNIRecovq;
1220 /* local NIs to recover */
1221 struct list_head ln_mt_peerNIRecovq;
1223 * An array of queues for GET/PUT waiting for REPLY/ACK respectively.
1224 * There are CPT number of queues. Since response trackers will be
1225 * added on the fast path we can't afford to grab the exclusive
1226 * net lock to protect these queues. The CPT will be calculated
1227 * based on the mdh cookie.
1229 struct list_head **ln_mt_rstq;
1231 * A response tracker becomes a zombie when the associated MD is queued
1232 * for unlink before the response tracker is detached from the MD. An
1233 * entry on a zombie list can be freed when either the remaining
1234 * operations on the MD complete or when LNet has shut down.
1236 struct list_head **ln_mt_zombie_rstqs;
1237 /* recovery handler */
1238 lnet_handler_t ln_mt_handler;
1241 * Completed when the discovery and monitor threads can enter their
1244 struct completion ln_started;
1246 struct list_head ln_udsp_list;