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/
31 * lnet/include/lnet/lib-types.h
33 * Types used by the library side routines that do not need to be
34 * exposed to the user application
37 #ifndef __LNET_LIB_TYPES_H__
38 #define __LNET_LIB_TYPES_H__
41 # error This include is only for kernel use.
44 #include <linux/kthread.h>
45 #include <linux/uio.h>
46 #include <linux/semaphore.h>
47 #include <linux/types.h>
48 #include <linux/kref.h>
49 #include <net/genetlink.h>
51 #include <uapi/linux/lnet/lnet-nl.h>
52 #include <uapi/linux/lnet/lnet-dlc.h>
53 #include <uapi/linux/lnet/lnetctl.h>
54 #include <uapi/linux/lnet/nidstr.h>
56 char *libcfs_nidstr_r(const struct lnet_nid *nid,
57 char *buf, size_t buf_size);
59 static inline char *libcfs_nidstr(const struct lnet_nid *nid)
61 return libcfs_nidstr_r(nid, libcfs_next_nidstring(),
65 int libcfs_strnid(struct lnet_nid *nid, const char *str);
66 char *libcfs_idstr(struct lnet_processid *id);
68 int cfs_match_nid_net(struct lnet_nid *nid, u32 net,
69 struct list_head *net_num_list,
70 struct list_head *addr);
72 /* Max payload size */
73 #define LNET_MAX_PAYLOAD LNET_MTU
75 /** limit on the number of fragments in discontiguous MDs */
76 #define LNET_MAX_IOV 256
79 * This is the maximum health value.
80 * All local and peer NIs created have their health default to this value.
82 #define LNET_MAX_HEALTH_VALUE 1000
83 #define LNET_MAX_SELECTION_PRIORITY UINT_MAX
88 enum lnet_msg_hstatus {
89 LNET_MSG_STATUS_OK = 0,
90 LNET_MSG_STATUS_LOCAL_INTERRUPT,
91 LNET_MSG_STATUS_LOCAL_DROPPED,
92 LNET_MSG_STATUS_LOCAL_ABORTED,
93 LNET_MSG_STATUS_LOCAL_NO_ROUTE,
94 LNET_MSG_STATUS_LOCAL_ERROR,
95 LNET_MSG_STATUS_LOCAL_TIMEOUT,
96 LNET_MSG_STATUS_REMOTE_ERROR,
97 LNET_MSG_STATUS_REMOTE_DROPPED,
98 LNET_MSG_STATUS_REMOTE_TIMEOUT,
99 LNET_MSG_STATUS_NETWORK_TIMEOUT,
103 struct lnet_rsp_tracker {
104 /* chain on the waiting list */
105 struct list_head rspt_on_list;
108 /* nid of next hop */
109 struct lnet_nid rspt_next_hop_nid;
110 /* deadline of the REPLY/ACK */
111 ktime_t rspt_deadline;
113 struct lnet_handle_md rspt_mdh;
117 struct list_head msg_activelist;
118 struct list_head msg_list; /* Q for credits/MD */
120 struct lnet_processid msg_target;
121 /* Primary NID of the source. */
122 struct lnet_nid msg_initiator;
123 /* where is it from, it's only for building event */
124 struct lnet_nid msg_from;
128 * hold parameters in case message is with held due
131 struct lnet_nid msg_src_nid_param;
132 struct lnet_nid msg_rtr_nid_param;
135 * Deadline for the message after which it will be finalized if it
138 ktime_t msg_deadline;
140 /* The message health status. */
141 enum lnet_msg_hstatus msg_health_status;
142 /* This is a recovery message */
144 /* force an RDMA even if the message size is < 4K */
146 /* the number of times a transmission has been retried */
148 /* flag to indicate that we do not want to resend this message */
151 /* committed for sending */
152 unsigned int msg_tx_committed:1;
153 /* CPT # this message committed for sending */
154 unsigned int msg_tx_cpt:15;
155 /* committed for receiving */
156 unsigned int msg_rx_committed:1;
157 /* CPT # this message committed for receiving */
158 unsigned int msg_rx_cpt:15;
159 /* queued for tx credit */
160 unsigned int msg_tx_delayed:1;
161 /* queued for RX buffer */
162 unsigned int msg_rx_delayed:1;
163 /* ready for pending on RX delay list */
164 unsigned int msg_rx_ready_delay:1;
166 unsigned int msg_vmflush:1; /* VM trying to free memory */
167 unsigned int msg_target_is_router:1; /* sending to a router */
168 unsigned int msg_routing:1; /* being forwarded */
169 unsigned int msg_ack:1; /* ack on finalize (PUT) */
170 unsigned int msg_sending:1; /* outgoing message */
171 unsigned int msg_receiving:1; /* being received */
172 unsigned int msg_txcredit:1; /* taken an NI send credit */
173 unsigned int msg_peertxcredit:1; /* taken a peer send credit */
174 unsigned int msg_rtrcredit:1; /* taken a globel router credit */
175 unsigned int msg_peerrtrcredit:1; /* taken a peer router credit */
176 unsigned int msg_onactivelist:1; /* on the activelist */
177 unsigned int msg_rdma_get:1;
179 struct lnet_peer_ni *msg_txpeer; /* peer I'm sending to */
180 struct lnet_peer_ni *msg_rxpeer; /* peer I received from */
183 struct lnet_libmd *msg_md;
184 /* the NI the message was sent or received over */
185 struct lnet_ni *msg_txni;
186 struct lnet_ni *msg_rxni;
188 unsigned int msg_len;
189 unsigned int msg_wanted;
190 unsigned int msg_offset;
191 unsigned int msg_niov;
192 struct bio_vec *msg_kiov;
194 struct lnet_event msg_ev;
195 struct lnet_hdr msg_hdr;
198 struct lnet_libhandle {
199 struct list_head lh_hash_chain;
203 #define lh_entry(ptr, type, member) \
204 ((type *)((char *)(ptr)-(char *)(&((type *)0)->member)))
207 struct list_head me_list;
209 struct lnet_processid me_match_id;
210 unsigned int me_portal;
211 unsigned int me_pos; /* hash offset in mt_hash */
213 __u64 me_ignore_bits;
214 enum lnet_unlink me_unlink;
215 struct lnet_libmd *me_md;
219 struct list_head md_list;
220 struct lnet_libhandle md_lh;
221 struct lnet_me *md_me;
223 unsigned int md_offset;
224 unsigned int md_length;
225 unsigned int md_max_size;
228 unsigned int md_options;
229 unsigned int md_flags;
230 unsigned int md_niov; /* # frags at end of struct */
232 struct lnet_rsp_tracker *md_rspt_ptr;
233 lnet_handler_t md_handler;
234 struct lnet_handle_md md_bulk_handle;
235 struct bio_vec md_kiov[LNET_MAX_IOV];
238 #define LNET_MD_FLAG_ZOMBIE BIT(0)
239 #define LNET_MD_FLAG_AUTO_UNLINK BIT(1)
240 #define LNET_MD_FLAG_ABORTED BIT(2)
241 /* LNET_MD_FLAG_HANDLING is set when a non-unlink event handler
242 * is being called for an event relating to the md.
243 * It ensures only one such handler runs at a time.
244 * The final "unlink" event is only called once the
245 * md_refcount has reached zero, and this flag has been cleared,
246 * ensuring that it doesn't race with any other event handler
249 #define LNET_MD_FLAG_HANDLING BIT(3)
250 #define LNET_MD_FLAG_DISCARD BIT(4)
252 struct lnet_test_peer {
253 /* info about peers we are trying to fail */
254 struct list_head tp_list; /* ln_test_peers */
255 struct lnet_nid tp_nid; /* matching nid */
256 unsigned int tp_threshold; /* # failures to simulate */
259 #define LNET_COOKIE_TYPE_MD 1
260 #define LNET_COOKIE_TYPE_ME 2
261 #define LNET_COOKIE_TYPE_EQ 3
262 #define LNET_COOKIE_TYPE_BITS 2
263 #define LNET_COOKIE_MASK ((1ULL << LNET_COOKIE_TYPE_BITS) - 1ULL)
269 void (*nf_addr2str)(u32 addr, char *str, size_t size);
270 void (*nf_addr2str_size)(const __be32 *addr, size_t asize,
271 char *str, size_t size);
272 int (*nf_str2addr)(const char *str, int nob, u32 *addr);
273 int (*nf_str2addr_size)(const char *str, int nob,
274 __be32 *addr, size_t *asize);
275 int (*nf_parse_addrlist)(char *str, int len,
276 struct list_head *list);
277 int (*nf_print_addrlist)(char *buffer, int count,
278 struct list_head *list);
279 int (*nf_match_addr)(u32 addr, struct list_head *list);
280 int (*nf_min_max)(struct list_head *nidlist, u32 *min_nid,
284 struct lnet_ni; /* forward ref */
288 /* fields initialized by the LND */
291 int (*lnd_startup)(struct lnet_ni *ni);
292 void (*lnd_shutdown)(struct lnet_ni *ni);
293 int (*lnd_ctl)(struct lnet_ni *ni, unsigned int cmd, void *arg);
295 /* In data movement APIs below, payload buffers are described as a set
296 * of 'niov' fragments which are in pages.
297 * The LND may NOT overwrite these fragment descriptors.
298 * An 'offset' and may specify a byte offset within the set of
299 * fragments to start from
302 /* Start sending a preformatted message. 'private' is NULL for PUT and
303 * GET messages; otherwise this is a response to an incoming message
304 * and 'private' is the 'private' passed to lnet_parse(). Return
305 * non-zero for immediate failure, otherwise complete later with
307 int (*lnd_send)(struct lnet_ni *ni, void *private,
308 struct lnet_msg *msg);
310 /* Start receiving 'mlen' bytes of payload data, skipping the following
311 * 'rlen' - 'mlen' bytes. 'private' is the 'private' passed to
312 * lnet_parse(). Return non-zero for immedaite failure, otherwise
313 * complete later with lnet_finalize(). This also gives back a receive
314 * credit if the LND does flow control. */
315 int (*lnd_recv)(struct lnet_ni *ni, void *private, struct lnet_msg *msg,
316 int delayed, unsigned int niov,
317 struct bio_vec *kiov,
318 unsigned int offset, unsigned int mlen, unsigned int rlen);
320 /* lnet_parse() has had to delay processing of this message
321 * (e.g. waiting for a forwarding buffer or send credits). Give the
322 * LND a chance to free urgently needed resources. If called, return 0
323 * for success and do NOT give back a receive credit; that has to wait
324 * until lnd_recv() gets called. On failure return < 0 and
325 * release resources; lnd_recv() will not be called. */
326 int (*lnd_eager_recv)(struct lnet_ni *ni, void *private,
327 struct lnet_msg *msg, void **new_privatep);
329 /* notification of peer down */
330 void (*lnd_notify_peer_down)(lnet_nid_t peer);
332 /* accept a new connection */
333 int (*lnd_accept)(struct lnet_ni *ni, struct socket *sock);
335 /* get dma_dev priority */
336 unsigned int (*lnd_get_dev_prio)(struct lnet_ni *ni,
337 unsigned int dev_idx);
340 struct lnet_tx_queue {
341 int tq_credits; /* # tx credits free */
342 int tq_credits_min; /* lowest it's been */
343 int tq_credits_max; /* total # tx credits */
344 struct list_head tq_delayed; /* delayed TXs */
347 enum lnet_net_state {
348 /* set when net block is allocated */
349 LNET_NET_STATE_INIT = 0,
350 /* set when NIs in net are started successfully */
351 LNET_NET_STATE_ACTIVE,
352 /* set if all NIs in net are in FAILED state */
353 LNET_NET_STATE_INACTIVE,
354 /* set when shutting down a NET */
355 LNET_NET_STATE_DELETING
359 /* initial state when NI is created */
360 LNET_NI_STATE_INIT = 0,
361 /* set when NI is brought up */
362 LNET_NI_STATE_ACTIVE,
363 /* set when NI is being shutdown */
364 LNET_NI_STATE_DELETING,
367 #define LNET_NI_RECOVERY_PENDING BIT(0)
368 #define LNET_NI_RECOVERY_FAILED BIT(1)
370 enum lnet_stats_type {
371 LNET_STATS_TYPE_SEND = 0,
372 LNET_STATS_TYPE_RECV,
376 struct lnet_comm_count {
377 atomic_t co_get_count;
378 atomic_t co_put_count;
379 atomic_t co_reply_count;
380 atomic_t co_ack_count;
381 atomic_t co_hello_count;
384 struct lnet_element_stats {
385 struct lnet_comm_count el_send_stats;
386 struct lnet_comm_count el_recv_stats;
387 struct lnet_comm_count el_drop_stats;
390 struct lnet_health_local_stats {
391 atomic_t hlt_local_interrupt;
392 atomic_t hlt_local_dropped;
393 atomic_t hlt_local_aborted;
394 atomic_t hlt_local_no_route;
395 atomic_t hlt_local_timeout;
396 atomic_t hlt_local_error;
399 struct lnet_health_remote_stats {
400 atomic_t hlt_remote_dropped;
401 atomic_t hlt_remote_timeout;
402 atomic_t hlt_remote_error;
403 atomic_t hlt_network_timeout;
407 /* chain on the ln_nets */
408 struct list_head net_list;
410 /* net ID, which is composed of
411 * (net_type << 16) | net_num.
412 * net_type can be one of the enumerated types defined in
413 * lnet/include/lnet/nidstr.h */
416 /* round robin selection */
419 /* total number of CPTs in the array */
422 /* cumulative CPTs of all NIs in this net */
425 /* relative net selection priority */
426 __u32 net_sel_priority;
428 /* network tunables */
429 struct lnet_ioctl_config_lnd_cmn_tunables net_tunables;
432 * boolean to indicate that the tunables have been set and
435 bool net_tunables_set;
437 /* procedural interface */
438 const struct lnet_lnd *net_lnd;
440 /* list of NIs on this net */
441 struct list_head net_ni_list;
443 /* list of NIs being added, but not started yet */
444 struct list_head net_ni_added;
446 /* dying LND instances */
447 struct list_head net_ni_zombie;
449 /* when I was last alive */
450 time64_t net_last_alive;
452 /* protects access to net_last_alive */
455 /* list of router nids preferred for this network */
456 struct list_head net_rtr_pref_nids;
460 /* chain on the lnet_net structure */
461 struct list_head ni_netlist;
463 /* chain on the recovery queue */
464 struct list_head ni_recovery;
466 /* MD handle for recovery ping */
467 struct lnet_handle_md ni_ping_mdh;
474 /* bond NI on some CPTs */
477 /* interface's NID */
478 struct lnet_nid ni_nid;
480 /* instance-specific data */
484 atomic_t ni_tx_credits;
486 /* percpt TX queues */
487 struct lnet_tx_queue **ni_tx_queues;
489 /* percpt reference count */
492 /* pointer to parent network */
493 struct lnet_net *ni_net;
495 /* my health status */
496 struct lnet_ni_status *ni_status;
498 /* NI FSM. Protected by lnet_ni_lock() */
499 enum lnet_ni_state ni_state;
501 /* Recovery state. Protected by lnet_ni_lock() */
502 __u32 ni_recovery_state;
504 /* When to send the next recovery ping */
505 time64_t ni_next_ping;
506 /* How many pings sent during current recovery period did not receive
507 * a reply. NB: reset whenever _any_ message arrives on this NI
509 unsigned int ni_ping_count;
511 /* per NI LND tunables */
512 struct lnet_lnd_tunables ni_lnd_tunables;
514 /* lnd tunables set explicitly */
515 bool ni_lnd_tunables_set;
518 struct lnet_element_stats ni_stats;
519 struct lnet_health_local_stats ni_hstats;
521 /* physical device CPT */
524 /* sequence number used to round robin over nis within a net */
529 * initialized to LNET_MAX_HEALTH_VALUE
530 * Value is decremented every time we fail to send a message over
531 * this NI because of a NI specific failure.
532 * Value is incremented if we successfully send a message.
537 * Set to 1 by the LND when it receives an event telling it the device
538 * has gone into a fatal state. Set to 0 when the LND receives an
539 * even telling it the device is back online.
541 atomic_t ni_fatal_error_on;
543 /* the relative selection priority of this NI */
544 __u32 ni_sel_priority;
547 * equivalent interface to use
550 struct net *ni_net_ns; /* original net namespace */
553 #define LNET_PROTO_PING_MATCHBITS 0x8000000000000000LL
556 * Descriptor of a ping info buffer: keep a separate indicator of the
557 * size and a reference count. The type is used both as a source and
558 * sink of data, so we need to keep some information outside of the
559 * area that may be overwritten by network data.
561 struct lnet_ping_buffer {
565 struct lnet_ping_info pb_info;
568 #define LNET_PING_BUFFER_SIZE(NNIDS) \
569 offsetof(struct lnet_ping_buffer, pb_info.pi_ni[NNIDS])
570 #define LNET_PING_BUFFER_LONI(PBUF) ((PBUF)->pb_info.pi_ni[0].ns_nid)
571 #define LNET_PING_BUFFER_SEQNO(PBUF) ((PBUF)->pb_info.pi_ni[0].ns_status)
573 #define LNET_PING_INFO_TO_BUFFER(PINFO) \
574 container_of((PINFO), struct lnet_ping_buffer, pb_info)
576 struct lnet_nid_list {
577 struct list_head nl_list;
578 struct lnet_nid nl_nid;
581 struct lnet_peer_ni {
582 /* chain on lpn_peer_nis */
583 struct list_head lpni_peer_nis;
584 /* chain on remote peer list */
585 struct list_head lpni_on_remote_peer_ni_list;
586 /* chain on recovery queue */
587 struct list_head lpni_recovery;
588 /* chain on peer hash */
589 struct list_head lpni_hashlist;
590 /* messages blocking for tx credits */
591 struct list_head lpni_txq;
592 /* pointer to peer net I'm part of */
593 struct lnet_peer_net *lpni_peer_net;
594 /* statistics kept on each peer NI */
595 struct lnet_element_stats lpni_stats;
596 struct lnet_health_remote_stats lpni_hstats;
597 /* spin lock protecting credits and lpni_txq */
598 spinlock_t lpni_lock;
599 /* # tx credits available */
602 int lpni_mintxcredits;
604 * Each peer_ni in a gateway maintains its own credits. This
605 * allows more traffic to gateways that have multiple interfaces.
607 /* # router credits */
610 int lpni_minrtrcredits;
611 /* bytes queued for sending */
613 /* network peer is on */
614 struct lnet_net *lpni_net;
616 struct lnet_nid lpni_nid;
618 struct kref lpni_kref;
619 /* health value for the peer */
620 atomic_t lpni_healthv;
621 /* recovery ping mdh */
622 struct lnet_handle_md lpni_recovery_ping_mdh;
623 /* When to send the next recovery ping */
624 time64_t lpni_next_ping;
625 /* How many pings sent during current recovery period did not receive
626 * a reply. NB: reset whenever _any_ message arrives from this peer NI
628 unsigned int lpni_ping_count;
629 /* CPT this peer attached on */
631 /* state flags -- protected by lpni_lock */
633 /* status of the peer NI as reported by the peer */
634 __u32 lpni_ns_status;
635 /* sequence number used to round robin over peer nis within a net */
637 /* sequence number used to round robin over gateways */
639 /* returned RC ping features. Protected with lpni_lock */
640 unsigned int lpni_ping_feats;
641 /* time last message was received from the peer */
642 time64_t lpni_last_alive;
643 /* preferred local nids: if only one, use lpni_pref.nid */
646 struct list_head nids;
648 /* list of router nids preferred for this peer NI */
649 struct list_head lpni_rtr_pref_nids;
650 /* The relative selection priority of this peer NI */
651 __u32 lpni_sel_priority;
652 /* number of preferred NIDs in lnpi_pref_nids */
653 __u32 lpni_pref_nnids;
656 /* Preferred path added due to traffic on non-MR peer_ni */
657 #define LNET_PEER_NI_NON_MR_PREF BIT(0)
658 /* peer is being recovered. */
659 #define LNET_PEER_NI_RECOVERY_PENDING BIT(1)
660 /* recovery ping failed */
661 #define LNET_PEER_NI_RECOVERY_FAILED BIT(2)
662 /* peer is being deleted */
663 #define LNET_PEER_NI_DELETING BIT(3)
666 /* chain on pt_peer_list */
667 struct list_head lp_peer_list;
669 /* list of peer nets */
670 struct list_head lp_peer_nets;
672 /* list of messages pending discovery*/
673 struct list_head lp_dc_pendq;
675 /* chain on router list */
676 struct list_head lp_rtr_list;
678 /* primary NID of the peer */
679 struct lnet_nid lp_primary_nid;
681 /* source NID to use during discovery */
682 struct lnet_nid lp_disc_src_nid;
683 /* destination NID to use during discovery */
684 struct lnet_nid lp_disc_dst_nid;
686 /* net to perform discovery on */
687 __u32 lp_disc_net_id;
689 /* CPT of peer_table */
692 /* number of NIDs on this peer */
695 /* # refs from lnet_route::lr_gateway */
699 * peer specific health sensitivity value to decrement peer nis in
700 * this peer with if set to something other than 0
702 __u32 lp_health_sensitivity;
704 /* messages blocking for router credits */
705 struct list_head lp_rtrq;
707 /* routes on this peer */
708 struct list_head lp_routes;
710 /* reference count */
711 atomic_t lp_refcount;
713 /* lock protecting peer state flags and lpni_rtrq */
716 /* peer state flags */
719 /* buffer for data pushed by peer */
720 struct lnet_ping_buffer *lp_data;
722 /* MD handle for ping in progress */
723 struct lnet_handle_md lp_ping_mdh;
725 /* MD handle for push in progress */
726 struct lnet_handle_md lp_push_mdh;
728 /* number of NIDs for sizing push data */
731 /* NI config sequence number of peer */
734 /* Local NI config sequence number acked by peer */
737 /* Local NI config sequence number sent to peer */
738 __u32 lp_node_seqno_sent;
740 /* Ping error encountered during discovery. */
743 /* Push error encountered during discovery. */
746 /* Error encountered during discovery. */
749 /* time it was put on the ln_dc_working queue */
750 time64_t lp_last_queued;
752 /* link on discovery-related lists */
753 struct list_head lp_dc_list;
755 /* tasks waiting on discovery of this peer */
756 wait_queue_head_t lp_dc_waitq;
758 /* cached peer aliveness */
763 * The status flags in lp_state. Their semantics have chosen so that
764 * lp_state can be zero-initialized.
766 * A peer is marked MULTI_RAIL in two cases: it was configured using DLC
767 * as multi-rail aware, or the LNET_PING_FEAT_MULTI_RAIL bit was set.
769 * A peer is marked NO_DISCOVERY if the LNET_PING_FEAT_DISCOVERY bit was
770 * NOT set when the peer was pinged by discovery.
772 * A peer is marked ROUTER if it indicates so in the feature bit.
774 #define LNET_PEER_MULTI_RAIL BIT(0) /* Multi-rail aware */
775 #define LNET_PEER_NO_DISCOVERY BIT(1) /* Peer disabled discovery */
776 #define LNET_PEER_ROUTER_ENABLED BIT(2) /* router feature enabled */
779 * A peer is marked CONFIGURED if it was configured by DLC.
781 * In addition, a peer is marked DISCOVERED if it has fully passed
782 * through Peer Discovery.
784 * When Peer Discovery is disabled, the discovery thread will mark
785 * peers REDISCOVER to indicate that they should be re-examined if
786 * discovery is (re)enabled on the node.
788 * A peer that was created as the result of inbound traffic will not
791 #define LNET_PEER_CONFIGURED BIT(3) /* Configured via DLC */
792 #define LNET_PEER_DISCOVERED BIT(4) /* Peer was discovered */
793 #define LNET_PEER_REDISCOVER BIT(5) /* Discovery was disabled */
795 * A peer is marked DISCOVERING when discovery is in progress.
796 * The other flags below correspond to stages of discovery.
798 #define LNET_PEER_DISCOVERING BIT(6) /* Discovering */
799 #define LNET_PEER_DATA_PRESENT BIT(7) /* Remote peer data present */
800 #define LNET_PEER_NIDS_UPTODATE BIT(8) /* Remote peer info uptodate */
801 #define LNET_PEER_PING_SENT BIT(9) /* Waiting for REPLY to Ping */
802 #define LNET_PEER_PUSH_SENT BIT(10) /* Waiting for ACK of Push */
803 #define LNET_PEER_PING_FAILED BIT(11) /* Ping send failure */
804 #define LNET_PEER_PUSH_FAILED BIT(12) /* Push send failure */
806 * A ping can be forced as a way to fix up state, or as a manual
807 * intervention by an admin.
808 * A push can be forced in circumstances that would normally not
809 * allow for one to happen.
811 #define LNET_PEER_FORCE_PING BIT(13) /* Forced Ping */
812 #define LNET_PEER_FORCE_PUSH BIT(14) /* Forced Push */
814 /* force delete even if router */
815 #define LNET_PEER_RTR_NI_FORCE_DEL BIT(15)
817 /* gw undergoing alive discovery */
818 #define LNET_PEER_RTR_DISCOVERY BIT(16)
819 /* gw has undergone discovery (does not indicate success or failure) */
820 #define LNET_PEER_RTR_DISCOVERED BIT(17)
822 /* peer is marked for deletion */
823 #define LNET_PEER_MARK_DELETION BIT(18)
824 /* lnet_peer_del()/lnet_peer_del_locked() has been called on the peer */
825 #define LNET_PEER_MARK_DELETED BIT(19)
826 /* lock primary NID to what's requested by ULP */
827 #define LNET_PEER_LOCK_PRIMARY BIT(20)
828 /* this is for informational purposes only. It is set if a peer gets
829 * configured from Lustre with a primary NID which belongs to another peer
830 * which is also configured by Lustre as the primary NID.
832 #define LNET_PEER_BAD_CONFIG BIT(21)
834 struct lnet_peer_net {
835 /* chain on lp_peer_nets */
836 struct list_head lpn_peer_nets;
838 /* list of peer_nis on this network */
839 struct list_head lpn_peer_nis;
841 /* pointer to the peer I'm part of */
842 struct lnet_peer *lpn_peer;
847 /* peer net health */
850 /* time of next router ping on this net */
851 time64_t lpn_next_ping;
853 /* selection sequence number */
856 /* relative peer net selection priority */
857 __u32 lpn_sel_priority;
859 /* reference count */
860 atomic_t lpn_refcount;
864 #define LNET_PEER_HASH_BITS 9
865 #define LNET_PEER_HASH_SIZE (1 << LNET_PEER_HASH_BITS)
868 * peer hash table - one per CPT
870 * protected by lnet_net_lock/EX for update
875 * protected by pt_zombie_lock:
879 * pt_zombie lock nests inside lnet_net_lock
881 struct lnet_peer_table {
882 int pt_version; /* /proc validity stamp */
883 struct list_head *pt_hash; /* NID->peer hash */
884 struct list_head pt_peer_list; /* peers */
885 int pt_peers; /* # peers */
886 struct list_head pt_zombie_list; /* zombie peer_ni */
887 int pt_zombies; /* # zombie peers_ni */
888 spinlock_t pt_zombie_lock; /* protect list and count */
891 /* peer aliveness is enabled only on routers for peers in a network where the
892 * struct lnet_ni::ni_peertimeout has been set to a positive value
894 #define lnet_peer_aliveness_enabled(lp) (the_lnet.ln_routing != 0 && \
895 ((lp)->lpni_net) && \
896 (lp)->lpni_net->net_tunables.lct_peer_timeout > 0)
899 struct list_head lr_list; /* chain on net */
900 struct list_head lr_gwlist; /* chain on gateway */
901 struct lnet_peer *lr_gateway; /* router node */
902 struct lnet_nid lr_nid; /* NID used to add route */
903 __u32 lr_net; /* remote network number */
904 __u32 lr_lnet; /* local network number */
905 int lr_seq; /* sequence for round-robin */
906 __u32 lr_hops; /* how far I am */
907 unsigned int lr_priority; /* route priority */
908 atomic_t lr_alive; /* cached route aliveness */
909 bool lr_single_hop; /* this route is single-hop */
912 #define LNET_REMOTE_NETS_HASH_DEFAULT (1U << 7)
913 #define LNET_REMOTE_NETS_HASH_MAX (1U << 16)
914 #define LNET_REMOTE_NETS_HASH_SIZE (1 << the_lnet.ln_remote_nets_hbits)
916 struct lnet_remotenet {
917 /* chain on ln_remote_nets_hash */
918 struct list_head lrn_list;
920 struct list_head lrn_routes;
925 /** lnet message has credit and can be submitted to lnd for send/receive */
926 #define LNET_CREDIT_OK 0
927 /** lnet message is waiting for credit */
928 #define LNET_CREDIT_WAIT 1
929 /** lnet message is waiting for discovery */
930 #define LNET_DC_WAIT 2
932 struct lnet_rtrbufpool {
933 /* my free buffer pool */
934 struct list_head rbp_bufs;
935 /* messages blocking for a buffer */
936 struct list_head rbp_msgs;
937 /* # pages in each buffer */
939 /* requested number of buffers */
940 int rbp_req_nbuffers;
941 /* # buffers actually allocated */
943 /* # free buffers / blocked messages */
950 struct list_head rb_list; /* chain on rbp_bufs */
951 struct lnet_rtrbufpool *rb_pool; /* owning pool */
952 struct bio_vec rb_kiov[0]; /* the buffer space */
955 #define LNET_PEER_HASHSIZE 503 /* prime! */
957 enum lnet_match_flags {
958 /* Didn't match anything */
959 LNET_MATCHMD_NONE = BIT(0),
961 LNET_MATCHMD_OK = BIT(1),
962 /* Must be discarded */
963 LNET_MATCHMD_DROP = BIT(2),
964 /* match and buffer is exhausted */
965 LNET_MATCHMD_EXHAUSTED = BIT(3),
967 LNET_MATCHMD_FINISH = (LNET_MATCHMD_OK | LNET_MATCHMD_DROP),
970 /* Options for struct lnet_portal::ptl_options */
971 #define LNET_PTL_LAZY BIT(0)
972 #define LNET_PTL_MATCH_UNIQUE BIT(1) /* unique match, for RDMA */
973 #define LNET_PTL_MATCH_WILDCARD BIT(2) /* wildcard match, request portal */
975 /* parameter for matching operations (GET, PUT) */
976 struct lnet_match_info {
978 struct lnet_processid mi_id;
981 unsigned int mi_portal;
982 unsigned int mi_rlength;
983 unsigned int mi_roffset;
986 /* ME hash of RDMA portal */
987 #define LNET_MT_HASH_BITS 8
988 #define LNET_MT_HASH_SIZE (1 << LNET_MT_HASH_BITS)
989 #define LNET_MT_HASH_MASK (LNET_MT_HASH_SIZE - 1)
990 /* we allocate (LNET_MT_HASH_SIZE + 1) entries for lnet_match_table::mt_hash,
991 * the last entry is reserved for MEs with ignore-bits */
992 #define LNET_MT_HASH_IGNORE LNET_MT_HASH_SIZE
993 /* __u64 has 2^6 bits, so need 2^(LNET_MT_HASH_BITS - LNET_MT_BITS_U64) which
994 * is 4 __u64s as bit-map, and add an extra __u64 (only use one bit) for the
995 * ME-list with ignore-bits, which is mtable::mt_hash[LNET_MT_HASH_IGNORE] */
996 #define LNET_MT_BITS_U64 6 /* 2^6 bits */
997 #define LNET_MT_EXHAUSTED_BITS (LNET_MT_HASH_BITS - LNET_MT_BITS_U64)
998 #define LNET_MT_EXHAUSTED_BMAP ((1 << LNET_MT_EXHAUSTED_BITS) + 1)
1000 /* portal match table */
1001 struct lnet_match_table {
1002 /* reserved for upcoming patches, CPU partition ID */
1003 unsigned int mt_cpt;
1004 unsigned int mt_portal; /* portal index */
1005 /* match table is set as "enabled" if there's non-exhausted MD
1006 * attached on mt_mhash, it's only valid for wildcard portal */
1007 unsigned int mt_enabled;
1008 /* bitmap to flag whether MEs on mt_hash are exhausted or not */
1009 __u64 mt_exhausted[LNET_MT_EXHAUSTED_BMAP];
1010 struct list_head *mt_mhash; /* matching hash */
1013 /* these are only useful for wildcard portal */
1014 /* Turn off message rotor for wildcard portals */
1015 #define LNET_PTL_ROTOR_OFF 0
1016 /* round-robin dispatch all PUT messages for wildcard portals */
1017 #define LNET_PTL_ROTOR_ON 1
1018 /* round-robin dispatch routed PUT message for wildcard portals */
1019 #define LNET_PTL_ROTOR_RR_RT 2
1020 /* dispatch routed PUT message by hashing source NID for wildcard portals */
1021 #define LNET_PTL_ROTOR_HASH_RT 3
1023 struct lnet_portal {
1024 spinlock_t ptl_lock;
1025 unsigned int ptl_index; /* portal ID, reserved */
1026 /* flags on this portal: lazy, unique... */
1027 unsigned int ptl_options;
1028 /* list of messages which are stealing buffer */
1029 struct list_head ptl_msg_stealing;
1030 /* messages blocking for MD */
1031 struct list_head ptl_msg_delayed;
1032 /* Match table for each CPT */
1033 struct lnet_match_table **ptl_mtables;
1034 /* spread rotor of incoming "PUT" */
1035 unsigned int ptl_rotor;
1036 /* # active entries for this portal */
1038 /* array of active entries' cpu-partition-id */
1042 #define LNET_LH_HASH_BITS 12
1043 #define LNET_LH_HASH_SIZE (1ULL << LNET_LH_HASH_BITS)
1044 #define LNET_LH_HASH_MASK (LNET_LH_HASH_SIZE - 1)
1046 /* resource container (ME, MD, EQ) */
1047 struct lnet_res_container {
1048 unsigned int rec_type; /* container type */
1049 __u64 rec_lh_cookie; /* cookie generator */
1050 struct list_head rec_active; /* active resource list */
1051 struct list_head *rec_lh_hash; /* handle hash */
1054 /* message container */
1055 struct lnet_msg_container {
1056 int msc_init; /* initialized or not */
1057 /* max # threads finalizing */
1058 int msc_nfinalizers;
1059 /* msgs waiting to complete finalizing */
1060 struct list_head msc_finalizing;
1061 /* msgs waiting to be resent */
1062 struct list_head msc_resending;
1063 struct list_head msc_active; /* active message list */
1064 /* threads doing finalization */
1065 void **msc_finalizers;
1066 /* threads doing resends */
1067 void **msc_resenders;
1070 /* This UDSP structures need to match the user space liblnetconfig structures
1071 * in order for the marshall and unmarshall functions to be common.
1074 /* Net is described as a
1078 struct lnet_ud_net_descr {
1080 struct list_head udn_net_num_range;
1083 /* each NID range is defined as
1085 * 2. address range descriptor
1087 struct lnet_ud_nid_descr {
1088 struct lnet_ud_net_descr ud_net_id;
1089 struct list_head ud_addr_range;
1093 /* a UDSP rule can have up to three user defined NID descriptors
1094 * - src: defines the local NID range for the rule
1095 * - dst: defines the peer NID range for the rule
1096 * - rte: defines the router NID range for the rule
1098 * An action union defines the action to take when the rule
1102 struct list_head udsp_on_list;
1104 struct lnet_ud_nid_descr udsp_src;
1105 struct lnet_ud_nid_descr udsp_dst;
1106 struct lnet_ud_nid_descr udsp_rte;
1107 enum lnet_udsp_action_type udsp_action_type;
1109 __u32 udsp_priority;
1113 /* Peer Discovery states */
1114 #define LNET_DC_STATE_SHUTDOWN 0 /* not started */
1115 #define LNET_DC_STATE_RUNNING 1 /* started up OK */
1116 #define LNET_DC_STATE_STOPPING 2 /* telling thread to stop */
1118 /* Router Checker states */
1119 #define LNET_MT_STATE_SHUTDOWN 0 /* not started */
1120 #define LNET_MT_STATE_RUNNING 1 /* started up OK */
1121 #define LNET_MT_STATE_STOPPING 2 /* telling thread to stop */
1124 #define LNET_STATE_SHUTDOWN 0 /* not started */
1125 #define LNET_STATE_RUNNING 1 /* started up OK */
1126 #define LNET_STATE_STOPPING 2 /* telling thread to stop */
1129 /* CPU partition table of LNet */
1130 struct cfs_cpt_table *ln_cpt_table;
1131 /* number of CPTs in ln_cpt_table */
1132 unsigned int ln_cpt_number;
1133 unsigned int ln_cpt_bits;
1135 /* protect LNet resources (ME/MD/EQ) */
1136 struct cfs_percpt_lock *ln_res_lock;
1139 /* the vector of portals */
1140 struct lnet_portal **ln_portals;
1141 /* percpt MD container */
1142 struct lnet_res_container **ln_md_containers;
1144 /* Event Queue container */
1145 struct lnet_res_container ln_eq_container;
1146 spinlock_t ln_eq_wait_lock;
1148 unsigned int ln_remote_nets_hbits;
1150 /* protect NI, peer table, credits, routers, rtrbuf... */
1151 struct cfs_percpt_lock *ln_net_lock;
1152 /* percpt message containers for active/finalizing/freed message */
1153 struct lnet_msg_container **ln_msg_containers;
1154 struct lnet_counters **ln_counters;
1155 struct lnet_peer_table **ln_peer_tables;
1156 /* list of peer nis not on a local network */
1157 struct list_head ln_remote_peer_ni_list;
1158 /* failure simulation */
1159 struct list_head ln_test_peers;
1160 struct list_head ln_drop_rules;
1161 struct list_head ln_delay_rules;
1163 struct list_head ln_nets;
1164 /* the loopback NI */
1165 struct lnet_ni *ln_loni;
1166 /* network zombie list */
1167 struct list_head ln_net_zombie;
1168 /* resend messages list */
1169 struct list_head ln_msg_resend;
1170 /* spin lock to protect the msg resend list */
1171 spinlock_t ln_msg_resend_lock;
1173 /* remote networks with routes to them */
1174 struct list_head *ln_remote_nets_hash;
1175 /* validity stamp */
1176 __u64 ln_remote_nets_version;
1177 /* list of all known routers */
1178 struct list_head ln_routers;
1179 /* validity stamp */
1180 __u64 ln_routers_version;
1181 /* percpt router buffer pools */
1182 struct lnet_rtrbufpool **ln_rtrpools;
1185 * Ping target / Push source
1187 * The ping target and push source share a single buffer. The
1188 * ln_ping_target is protected against concurrent updates by
1191 struct lnet_handle_md ln_ping_target_md;
1192 lnet_handler_t ln_ping_target_handler;
1193 struct lnet_ping_buffer *ln_ping_target;
1194 atomic_t ln_ping_target_seqno;
1199 * ln_push_nnis contains the desired size of the push target.
1200 * The lnet_net_lock is used to handle update races. The old
1201 * buffer may linger a while after it has been unlinked, in
1202 * which case the event handler cleans up.
1204 lnet_handler_t ln_push_target_handler;
1205 struct lnet_handle_md ln_push_target_md;
1206 struct lnet_ping_buffer *ln_push_target;
1207 int ln_push_target_nnis;
1209 /* discovery event queue handle */
1210 lnet_handler_t ln_dc_handler;
1211 /* discovery requests */
1212 struct list_head ln_dc_request;
1213 /* discovery working list */
1214 struct list_head ln_dc_working;
1215 /* discovery expired list */
1216 struct list_head ln_dc_expired;
1217 /* discovery thread wait queue */
1218 wait_queue_head_t ln_dc_waitq;
1219 /* discovery startup/shutdown state */
1222 /* monitor thread startup/shutdown state */
1224 /* serialise startup/shutdown */
1225 struct semaphore ln_mt_signal;
1227 struct mutex ln_api_mutex;
1228 struct mutex ln_lnd_mutex;
1229 /* Have I called LNetNIInit myself? */
1231 /* LNetNIInit/LNetNIFini counter */
1233 /* SHUTDOWN/RUNNING/STOPPING */
1236 int ln_routing; /* am I a router? */
1237 lnet_pid_t ln_pid; /* requested pid */
1238 /* uniquely identifies this ni in this epoch */
1239 __u64 ln_interface_cookie;
1240 /* registered LNDs */
1241 const struct lnet_lnd *ln_lnds[NUM_LNDS];
1243 /* test protocol compatibility flags */
1244 unsigned long ln_testprotocompat;
1246 /* 0 - load the NIs from the mod params
1247 * 1 - do not load the NIs from the mod params
1248 * Reverse logic to ensure that other calls to LNetNIInit
1251 bool ln_nis_from_mod_params;
1254 * completion for the monitor thread. The monitor thread takes care of
1255 * checking routes, timedout messages and resending messages.
1257 struct completion ln_mt_wait_complete;
1259 /* per-cpt resend queues */
1260 struct list_head **ln_mt_resendqs;
1261 /* local NIs to recover */
1262 struct list_head ln_mt_localNIRecovq;
1263 /* local NIs to recover */
1264 struct list_head ln_mt_peerNIRecovq;
1266 * An array of queues for GET/PUT waiting for REPLY/ACK respectively.
1267 * There are CPT number of queues. Since response trackers will be
1268 * added on the fast path we can't afford to grab the exclusive
1269 * net lock to protect these queues. The CPT will be calculated
1270 * based on the mdh cookie.
1272 struct list_head **ln_mt_rstq;
1274 * A response tracker becomes a zombie when the associated MD is queued
1275 * for unlink before the response tracker is detached from the MD. An
1276 * entry on a zombie list can be freed when either the remaining
1277 * operations on the MD complete or when LNet has shut down.
1279 struct list_head **ln_mt_zombie_rstqs;
1280 /* recovery handler */
1281 lnet_handler_t ln_mt_handler;
1284 * Completed when the discovery and monitor threads can enter their
1287 struct completion ln_started;
1289 struct list_head ln_udsp_list;
1292 struct genl_filter_list {
1293 struct list_head lp_list;
1298 static const struct nla_policy scalar_attr_policy[LN_SCALAR_MAX + 1] = {
1299 [LN_SCALAR_ATTR_LIST] = { .type = NLA_NESTED },
1300 [LN_SCALAR_ATTR_LIST_SIZE] = { .type = NLA_U16 },
1301 [LN_SCALAR_ATTR_INDEX] = { .type = NLA_U16 },
1302 [LN_SCALAR_ATTR_NLA_TYPE] = { .type = NLA_U16 },
1303 [LN_SCALAR_ATTR_VALUE] = { .type = NLA_STRING },
1304 [LN_SCALAR_ATTR_KEY_FORMAT] = { .type = NLA_U16 },
1307 int lnet_genl_send_scalar_list(struct sk_buff *msg, u32 portid, u32 seq,
1308 const struct genl_family *family, int flags,
1309 u8 cmd, const struct ln_key_list *data[]);
1311 /* Special workaround for pre-4.19 kernels to send error messages
1312 * from dumpit routines. Newer kernels will send message with
1313 * NL_SET_ERR_MSG information by default if NETLINK_EXT_ACK is set.
1315 static inline int lnet_nl_send_error(struct sk_buff *msg, int portid, int seq,
1318 #ifndef HAVE_NL_DUMP_WITH_EXT_ACK
1319 struct nlmsghdr *nlh;
1324 nlh = nlmsg_put(msg, portid, seq, NLMSG_ERROR, sizeof(error), 0);
1327 #ifdef HAVE_NL_PARSE_WITH_EXT_ACK
1328 netlink_ack(msg, nlh, error, NULL);
1330 netlink_ack(msg, nlh, error);
1332 return nlmsg_len(nlh);