xref: /openbmc/linux/fs/ocfs2/cluster/tcp_internal.h (revision 8be98d2f2a0a262f8bf8a0bc1fdf522b3c7aab17)
1328970deSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2*fa60ce2cSMasahiro Yamada /*
398211489SZach Brown  * Copyright (C) 2005 Oracle.  All rights reserved.
498211489SZach Brown  */
598211489SZach Brown 
698211489SZach Brown #ifndef O2CLUSTER_TCP_INTERNAL_H
798211489SZach Brown #define O2CLUSTER_TCP_INTERNAL_H
898211489SZach Brown 
998211489SZach Brown #define O2NET_MSG_MAGIC           ((u16)0xfa55)
1098211489SZach Brown #define O2NET_MSG_STATUS_MAGIC    ((u16)0xfa56)
1198211489SZach Brown #define O2NET_MSG_KEEP_REQ_MAGIC  ((u16)0xfa57)
1298211489SZach Brown #define O2NET_MSG_KEEP_RESP_MAGIC ((u16)0xfa58)
1398211489SZach Brown 
1498211489SZach Brown /* we're delaying our quorum decision so that heartbeat will have timed
1598211489SZach Brown  * out truly dead nodes by the time we come around to making decisions
1698211489SZach Brown  * on their number */
1798211489SZach Brown #define O2NET_QUORUM_DELAY_MS	((o2hb_dead_threshold + 2) * O2HB_REGION_TIMEOUT_MS)
1898211489SZach Brown 
1998211489SZach Brown /*
2098211489SZach Brown  * This version number represents quite a lot, unfortunately.  It not
2198211489SZach Brown  * only represents the raw network message protocol on the wire but also
2298211489SZach Brown  * locking semantics of the file system using the protocol.  It should
2398211489SZach Brown  * be somewhere else, I'm sure, but right now it isn't.
2498211489SZach Brown  *
25d24fbcdaSJoel Becker  * With version 11, we separate out the filesystem locking portion.  The
26d24fbcdaSJoel Becker  * filesystem now has a major.minor version it negotiates.  Version 11
27d24fbcdaSJoel Becker  * introduces this negotiation to the o2dlm protocol, and as such the
28d24fbcdaSJoel Becker  * version here in tcp_internal.h should not need to be bumped for
29d24fbcdaSJoel Becker  * filesystem locking changes.
30d24fbcdaSJoel Becker  *
31d24fbcdaSJoel Becker  * New in version 11
32d24fbcdaSJoel Becker  * 	- Negotiation of filesystem locking in the dlm join.
33d24fbcdaSJoel Becker  *
34c934a92dSMark Fasheh  * New in version 10:
35c934a92dSMark Fasheh  * 	- Meta/data locks combined
36c934a92dSMark Fasheh  *
3734d024f8SMark Fasheh  * New in version 9:
3834d024f8SMark Fasheh  * 	- All votes removed
3934d024f8SMark Fasheh  *
4050008630STiger Yang  * New in version 8:
4150008630STiger Yang  * 	- Replace delete inode votes with a cluster lock
4250008630STiger Yang  *
431faf2894SSrinivas Eeda  * New in version 7:
441faf2894SSrinivas Eeda  * 	- DLM join domain includes the live nodemap
451faf2894SSrinivas Eeda  *
46ba2bf218SKurt Hackel  * New in version 6:
47ba2bf218SKurt Hackel  * 	- DLM lockres remote refcount fixes.
48ba2bf218SKurt Hackel  *
49828ae6afSAndrew Beekhof  * New in version 5:
50828ae6afSAndrew Beekhof  * 	- Network timeout checking protocol
51828ae6afSAndrew Beekhof  *
5224c19ef4SMark Fasheh  * New in version 4:
5324c19ef4SMark Fasheh  * 	- Remove i_generation from lock names for better stat performance.
5424c19ef4SMark Fasheh  *
55379dfe9dSMark Fasheh  * New in version 3:
56379dfe9dSMark Fasheh  * 	- Replace dentry votes with a cluster lock
57379dfe9dSMark Fasheh  *
5898211489SZach Brown  * New in version 2:
5998211489SZach Brown  * 	- full 64 bit i_size in the metadata lock lvbs
6098211489SZach Brown  * 	- introduction of "rw" lock and pushing meta/data locking down
6198211489SZach Brown  */
6263b52c49SJunxiao Bi #define O2NET_PROTOCOL_VERSION 11ULL
6398211489SZach Brown struct o2net_handshake {
6498211489SZach Brown 	__be64	protocol_version;
6598211489SZach Brown 	__be64	connector_id;
66828ae6afSAndrew Beekhof 	__be32  o2hb_heartbeat_timeout_ms;
67828ae6afSAndrew Beekhof 	__be32  o2net_idle_timeout_ms;
68828ae6afSAndrew Beekhof 	__be32  o2net_keepalive_delay_ms;
69828ae6afSAndrew Beekhof 	__be32  o2net_reconnect_delay_ms;
7098211489SZach Brown };
7198211489SZach Brown 
7298211489SZach Brown struct o2net_node {
7398211489SZach Brown 	/* this is never called from int/bh */
7498211489SZach Brown 	spinlock_t			nn_lock;
7598211489SZach Brown 
7698211489SZach Brown 	/* set the moment an sc is allocated and a connect is started */
7798211489SZach Brown 	struct o2net_sock_container	*nn_sc;
7898211489SZach Brown 	/* _valid is only set after the handshake passes and tx can happen */
7998211489SZach Brown 	unsigned			nn_sc_valid:1;
8098211489SZach Brown 	/* if this is set tx just returns it */
8198211489SZach Brown 	int				nn_persistent_error;
825cc3bf27STao Ma 	/* It is only set to 1 after the idle time out. */
835cc3bf27STao Ma 	atomic_t			nn_timeout;
8498211489SZach Brown 
8598211489SZach Brown 	/* threads waiting for an sc to arrive wait on the wq for generation
8698211489SZach Brown 	 * to increase.  it is increased when a connecting socket succeeds
8798211489SZach Brown 	 * or fails or when an accepted socket is attached. */
8898211489SZach Brown 	wait_queue_head_t		nn_sc_wq;
8998211489SZach Brown 
9098211489SZach Brown 	struct idr			nn_status_idr;
9198211489SZach Brown 	struct list_head		nn_status_list;
9298211489SZach Brown 
9398211489SZach Brown 	/* connects are attempted from when heartbeat comes up until either hb
9441d6247fSJunxiao Bi 	 * goes down, the node is unconfigured, or a connect succeeds.
9541d6247fSJunxiao Bi 	 * connect_work is queued from set_nn_state both from hb up and from
9641d6247fSJunxiao Bi 	 * itself if a connect attempt fails and so can be self-arming.
9741d6247fSJunxiao Bi 	 * shutdown is careful to first mark the nn such that no connects will
9841d6247fSJunxiao Bi 	 * be attempted before canceling delayed connect work and flushing the
9941d6247fSJunxiao Bi 	 * queue. */
100c4028958SDavid Howells 	struct delayed_work		nn_connect_work;
10198211489SZach Brown 	unsigned long			nn_last_connect_attempt;
10298211489SZach Brown 
10398211489SZach Brown 	/* this is queued as nodes come up and is canceled when a connection is
10498211489SZach Brown 	 * established.  this expiring gives up on the node and errors out
10598211489SZach Brown 	 * transmits */
106c4028958SDavid Howells 	struct delayed_work		nn_connect_expired;
10798211489SZach Brown 
10898211489SZach Brown 	/* after we give up on a socket we wait a while before deciding
10998211489SZach Brown 	 * that it is still heartbeating and that we should do some
11098211489SZach Brown 	 * quorum work */
111c4028958SDavid Howells 	struct delayed_work		nn_still_up;
11298211489SZach Brown };
11398211489SZach Brown 
11498211489SZach Brown struct o2net_sock_container {
11598211489SZach Brown 	struct kref		sc_kref;
116817f2c84SNikanth Karthikesan 	/* the next two are valid for the life time of the sc */
11798211489SZach Brown 	struct socket		*sc_sock;
11898211489SZach Brown 	struct o2nm_node	*sc_node;
11998211489SZach Brown 
12098211489SZach Brown 	/* all of these sc work structs hold refs on the sc while they are
12198211489SZach Brown 	 * queued.  they should not be able to ref a freed sc.  the teardown
12298211489SZach Brown 	 * race is with o2net_wq destruction in o2net_stop_listening() */
12398211489SZach Brown 
12498211489SZach Brown 	/* rx and connect work are generated from socket callbacks.  sc
12598211489SZach Brown 	 * shutdown removes the callbacks and then flushes the work queue */
12698211489SZach Brown 	struct work_struct	sc_rx_work;
12798211489SZach Brown 	struct work_struct	sc_connect_work;
12898211489SZach Brown 	/* shutdown work is triggered in two ways.  the simple way is
12998211489SZach Brown 	 * for a code path calls ensure_shutdown which gets a lock, removes
13098211489SZach Brown 	 * the sc from the nn, and queues the work.  in this case the
13198211489SZach Brown 	 * work is single-shot.  the work is also queued from a sock
13298211489SZach Brown 	 * callback, though, and in this case the work will find the sc
13398211489SZach Brown 	 * still on the nn and will call ensure_shutdown itself.. this
13498211489SZach Brown 	 * ends up triggering the shutdown work again, though nothing
13598211489SZach Brown 	 * will be done in that second iteration.  so work queue teardown
13698211489SZach Brown 	 * has to be careful to remove the sc from the nn before waiting
13798211489SZach Brown 	 * on the work queue so that the shutdown work doesn't remove the
13898211489SZach Brown 	 * sc and rearm itself.
13998211489SZach Brown 	 */
14098211489SZach Brown 	struct work_struct	sc_shutdown_work;
14198211489SZach Brown 
14298211489SZach Brown 	struct timer_list	sc_idle_timeout;
143c4028958SDavid Howells 	struct delayed_work	sc_keepalive_work;
14498211489SZach Brown 
14598211489SZach Brown 	unsigned		sc_handshake_ok:1;
14698211489SZach Brown 
14798211489SZach Brown 	struct page 		*sc_page;
14898211489SZach Brown 	size_t			sc_page_off;
14998211489SZach Brown 
15098211489SZach Brown 	/* original handlers for the sockets */
15198211489SZach Brown 	void			(*sc_state_change)(struct sock *sk);
152676d2369SDavid S. Miller 	void			(*sc_data_ready)(struct sock *sk);
153ff1becbfSSunil Mushran 
15498211489SZach Brown 	u32			sc_msg_key;
15598211489SZach Brown 	u16			sc_msg_type;
156925037bcSZhen Wei 
157ff1becbfSSunil Mushran #ifdef CONFIG_DEBUG_FS
158ff1becbfSSunil Mushran 	struct list_head        sc_net_debug_item;
159ff1becbfSSunil Mushran 	ktime_t			sc_tv_timer;
160ff1becbfSSunil Mushran 	ktime_t			sc_tv_data_ready;
161ff1becbfSSunil Mushran 	ktime_t			sc_tv_advance_start;
162ff1becbfSSunil Mushran 	ktime_t			sc_tv_advance_stop;
163ff1becbfSSunil Mushran 	ktime_t			sc_tv_func_start;
164ff1becbfSSunil Mushran 	ktime_t			sc_tv_func_stop;
165ff1becbfSSunil Mushran #endif
1663c193b38SSunil Mushran #ifdef CONFIG_OCFS2_FS_STATS
1673c193b38SSunil Mushran 	ktime_t			sc_tv_acquiry_total;
1683c193b38SSunil Mushran 	ktime_t			sc_tv_send_total;
1693c193b38SSunil Mushran 	ktime_t			sc_tv_status_total;
1703c193b38SSunil Mushran 	u32			sc_send_count;
171e453039fSSunil Mushran 	u32			sc_recv_count;
172e453039fSSunil Mushran 	ktime_t			sc_tv_process_total;
1733c193b38SSunil Mushran #endif
174925037bcSZhen Wei 	struct mutex		sc_send_lock;
17598211489SZach Brown };
17698211489SZach Brown 
17798211489SZach Brown struct o2net_msg_handler {
17898211489SZach Brown 	struct rb_node		nh_node;
17998211489SZach Brown 	u32			nh_max_len;
18098211489SZach Brown 	u32			nh_msg_type;
18198211489SZach Brown 	u32			nh_key;
18298211489SZach Brown 	o2net_msg_handler_func	*nh_func;
183cfdce25cSChangwei Ge 	void			*nh_func_data;
184d74c9803SKurt Hackel 	o2net_post_msg_handler_func
185d74c9803SKurt Hackel 				*nh_post_func;
18698211489SZach Brown 	struct kref		nh_kref;
18798211489SZach Brown 	struct list_head	nh_unregister_item;
18898211489SZach Brown };
18998211489SZach Brown 
19098211489SZach Brown enum o2net_system_error {
19198211489SZach Brown 	O2NET_ERR_NONE = 0,
19298211489SZach Brown 	O2NET_ERR_NO_HNDLR,
19398211489SZach Brown 	O2NET_ERR_OVERFLOW,
19498211489SZach Brown 	O2NET_ERR_DIED,
19598211489SZach Brown 	O2NET_ERR_MAX
19698211489SZach Brown };
19798211489SZach Brown 
19898211489SZach Brown struct o2net_status_wait {
19998211489SZach Brown 	enum o2net_system_error	ns_sys_status;
20098211489SZach Brown 	s32			ns_status;
20198211489SZach Brown 	int			ns_id;
20298211489SZach Brown 	wait_queue_head_t	ns_wq;
20398211489SZach Brown 	struct list_head	ns_node_item;
20498211489SZach Brown };
20598211489SZach Brown 
2062309e9e0SSunil Mushran #ifdef CONFIG_DEBUG_FS
2072309e9e0SSunil Mushran /* just for state dumps */
2082309e9e0SSunil Mushran struct o2net_send_tracking {
2092309e9e0SSunil Mushran 	struct list_head		st_net_debug_item;
2102309e9e0SSunil Mushran 	struct task_struct		*st_task;
2112309e9e0SSunil Mushran 	struct o2net_sock_container	*st_sc;
2122309e9e0SSunil Mushran 	u32				st_id;
2132309e9e0SSunil Mushran 	u32				st_msg_type;
2142309e9e0SSunil Mushran 	u32				st_msg_key;
2152309e9e0SSunil Mushran 	u8				st_node;
2163f9c14faSSunil Mushran 	ktime_t				st_sock_time;
2173f9c14faSSunil Mushran 	ktime_t				st_send_time;
2183f9c14faSSunil Mushran 	ktime_t				st_status_time;
2192309e9e0SSunil Mushran };
2202309e9e0SSunil Mushran #else
2212309e9e0SSunil Mushran struct o2net_send_tracking {
2222309e9e0SSunil Mushran 	u32	dummy;
2232309e9e0SSunil Mushran };
2242309e9e0SSunil Mushran #endif	/* CONFIG_DEBUG_FS */
2252309e9e0SSunil Mushran 
22698211489SZach Brown #endif /* O2CLUSTER_TCP_INTERNAL_H */
227