xref: /openbmc/linux/fs/ocfs2/cluster/tcp_internal.h (revision 379dfe9d0db99ed33fb089fcb9c07f5f92566e9e)
198211489SZach Brown /* -*- mode: c; c-basic-offset: 8; -*-
298211489SZach Brown  * vim: noexpandtab sw=8 ts=8 sts=0:
398211489SZach Brown  *
498211489SZach Brown  * Copyright (C) 2005 Oracle.  All rights reserved.
598211489SZach Brown  *
698211489SZach Brown  * This program is free software; you can redistribute it and/or
798211489SZach Brown  * modify it under the terms of the GNU General Public
898211489SZach Brown  * License as published by the Free Software Foundation; either
998211489SZach Brown  * version 2 of the License, or (at your option) any later version.
1098211489SZach Brown  *
1198211489SZach Brown  * This program is distributed in the hope that it will be useful,
1298211489SZach Brown  * but WITHOUT ANY WARRANTY; without even the implied warranty of
1398211489SZach Brown  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
1498211489SZach Brown  * General Public License for more details.
1598211489SZach Brown  *
1698211489SZach Brown  * You should have received a copy of the GNU General Public
1798211489SZach Brown  * License along with this program; if not, write to the
1898211489SZach Brown  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
1998211489SZach Brown  * Boston, MA 021110-1307, USA.
2098211489SZach Brown  */
2198211489SZach Brown 
2298211489SZach Brown #ifndef O2CLUSTER_TCP_INTERNAL_H
2398211489SZach Brown #define O2CLUSTER_TCP_INTERNAL_H
2498211489SZach Brown 
2598211489SZach Brown #define O2NET_MSG_MAGIC           ((u16)0xfa55)
2698211489SZach Brown #define O2NET_MSG_STATUS_MAGIC    ((u16)0xfa56)
2798211489SZach Brown #define O2NET_MSG_KEEP_REQ_MAGIC  ((u16)0xfa57)
2898211489SZach Brown #define O2NET_MSG_KEEP_RESP_MAGIC ((u16)0xfa58)
2998211489SZach Brown 
3098211489SZach Brown /* same as hb delay, we're waiting for another node to recognize our hb */
3198211489SZach Brown #define O2NET_RECONNECT_DELAY_MS	O2HB_REGION_TIMEOUT_MS
3298211489SZach Brown 
3398211489SZach Brown /* we're delaying our quorum decision so that heartbeat will have timed
3498211489SZach Brown  * out truly dead nodes by the time we come around to making decisions
3598211489SZach Brown  * on their number */
3698211489SZach Brown #define O2NET_QUORUM_DELAY_MS	((o2hb_dead_threshold + 2) * O2HB_REGION_TIMEOUT_MS)
3798211489SZach Brown 
3898211489SZach Brown #define O2NET_KEEPALIVE_DELAY_SECS	5
3998211489SZach Brown #define O2NET_IDLE_TIMEOUT_SECS		10
4098211489SZach Brown 
4198211489SZach Brown /*
4298211489SZach Brown  * This version number represents quite a lot, unfortunately.  It not
4398211489SZach Brown  * only represents the raw network message protocol on the wire but also
4498211489SZach Brown  * locking semantics of the file system using the protocol.  It should
4598211489SZach Brown  * be somewhere else, I'm sure, but right now it isn't.
4698211489SZach Brown  *
47*379dfe9dSMark Fasheh  * New in version 3:
48*379dfe9dSMark Fasheh  * 	- Replace dentry votes with a cluster lock
49*379dfe9dSMark Fasheh  *
5098211489SZach Brown  * New in version 2:
5198211489SZach Brown  * 	- full 64 bit i_size in the metadata lock lvbs
5298211489SZach Brown  * 	- introduction of "rw" lock and pushing meta/data locking down
5398211489SZach Brown  */
54*379dfe9dSMark Fasheh #define O2NET_PROTOCOL_VERSION 3ULL
5598211489SZach Brown struct o2net_handshake {
5698211489SZach Brown 	__be64	protocol_version;
5798211489SZach Brown 	__be64	connector_id;
5898211489SZach Brown };
5998211489SZach Brown 
6098211489SZach Brown struct o2net_node {
6198211489SZach Brown 	/* this is never called from int/bh */
6298211489SZach Brown 	spinlock_t			nn_lock;
6398211489SZach Brown 
6498211489SZach Brown 	/* set the moment an sc is allocated and a connect is started */
6598211489SZach Brown 	struct o2net_sock_container	*nn_sc;
6698211489SZach Brown 	/* _valid is only set after the handshake passes and tx can happen */
6798211489SZach Brown 	unsigned			nn_sc_valid:1;
6898211489SZach Brown 	/* if this is set tx just returns it */
6998211489SZach Brown 	int				nn_persistent_error;
7098211489SZach Brown 
7198211489SZach Brown 	/* threads waiting for an sc to arrive wait on the wq for generation
7298211489SZach Brown 	 * to increase.  it is increased when a connecting socket succeeds
7398211489SZach Brown 	 * or fails or when an accepted socket is attached. */
7498211489SZach Brown 	wait_queue_head_t		nn_sc_wq;
7598211489SZach Brown 
7698211489SZach Brown 	struct idr			nn_status_idr;
7798211489SZach Brown 	struct list_head		nn_status_list;
7898211489SZach Brown 
7998211489SZach Brown 	/* connects are attempted from when heartbeat comes up until either hb
8098211489SZach Brown 	 * goes down, the node is unconfigured, no connect attempts succeed
8198211489SZach Brown 	 * before O2NET_CONN_IDLE_DELAY, or a connect succeeds.  connect_work
8298211489SZach Brown 	 * is queued from set_nn_state both from hb up and from itself if a
8398211489SZach Brown 	 * connect attempt fails and so can be self-arming.  shutdown is
8498211489SZach Brown 	 * careful to first mark the nn such that no connects will be attempted
8598211489SZach Brown 	 * before canceling delayed connect work and flushing the queue. */
8698211489SZach Brown 	struct work_struct		nn_connect_work;
8798211489SZach Brown 	unsigned long			nn_last_connect_attempt;
8898211489SZach Brown 
8998211489SZach Brown 	/* this is queued as nodes come up and is canceled when a connection is
9098211489SZach Brown 	 * established.  this expiring gives up on the node and errors out
9198211489SZach Brown 	 * transmits */
9298211489SZach Brown 	struct work_struct		nn_connect_expired;
9398211489SZach Brown 
9498211489SZach Brown 	/* after we give up on a socket we wait a while before deciding
9598211489SZach Brown 	 * that it is still heartbeating and that we should do some
9698211489SZach Brown 	 * quorum work */
9798211489SZach Brown 	struct work_struct		nn_still_up;
9898211489SZach Brown };
9998211489SZach Brown 
10098211489SZach Brown struct o2net_sock_container {
10198211489SZach Brown 	struct kref		sc_kref;
10298211489SZach Brown 	/* the next two are vaild for the life time of the sc */
10398211489SZach Brown 	struct socket		*sc_sock;
10498211489SZach Brown 	struct o2nm_node	*sc_node;
10598211489SZach Brown 
10698211489SZach Brown 	/* all of these sc work structs hold refs on the sc while they are
10798211489SZach Brown 	 * queued.  they should not be able to ref a freed sc.  the teardown
10898211489SZach Brown 	 * race is with o2net_wq destruction in o2net_stop_listening() */
10998211489SZach Brown 
11098211489SZach Brown 	/* rx and connect work are generated from socket callbacks.  sc
11198211489SZach Brown 	 * shutdown removes the callbacks and then flushes the work queue */
11298211489SZach Brown 	struct work_struct	sc_rx_work;
11398211489SZach Brown 	struct work_struct	sc_connect_work;
11498211489SZach Brown 	/* shutdown work is triggered in two ways.  the simple way is
11598211489SZach Brown 	 * for a code path calls ensure_shutdown which gets a lock, removes
11698211489SZach Brown 	 * the sc from the nn, and queues the work.  in this case the
11798211489SZach Brown 	 * work is single-shot.  the work is also queued from a sock
11898211489SZach Brown 	 * callback, though, and in this case the work will find the sc
11998211489SZach Brown 	 * still on the nn and will call ensure_shutdown itself.. this
12098211489SZach Brown 	 * ends up triggering the shutdown work again, though nothing
12198211489SZach Brown 	 * will be done in that second iteration.  so work queue teardown
12298211489SZach Brown 	 * has to be careful to remove the sc from the nn before waiting
12398211489SZach Brown 	 * on the work queue so that the shutdown work doesn't remove the
12498211489SZach Brown 	 * sc and rearm itself.
12598211489SZach Brown 	 */
12698211489SZach Brown 	struct work_struct	sc_shutdown_work;
12798211489SZach Brown 
12898211489SZach Brown 	struct timer_list	sc_idle_timeout;
12998211489SZach Brown 	struct work_struct	sc_keepalive_work;
13098211489SZach Brown 
13198211489SZach Brown 	unsigned		sc_handshake_ok:1;
13298211489SZach Brown 
13398211489SZach Brown 	struct page 		*sc_page;
13498211489SZach Brown 	size_t			sc_page_off;
13598211489SZach Brown 
13698211489SZach Brown 	/* original handlers for the sockets */
13798211489SZach Brown 	void			(*sc_state_change)(struct sock *sk);
13898211489SZach Brown 	void			(*sc_data_ready)(struct sock *sk, int bytes);
13998211489SZach Brown 
14098211489SZach Brown 	struct timeval 		sc_tv_timer;
14198211489SZach Brown 	struct timeval 		sc_tv_data_ready;
14298211489SZach Brown 	struct timeval 		sc_tv_advance_start;
14398211489SZach Brown 	struct timeval 		sc_tv_advance_stop;
14498211489SZach Brown 	struct timeval 		sc_tv_func_start;
14598211489SZach Brown 	struct timeval 		sc_tv_func_stop;
14698211489SZach Brown 	u32			sc_msg_key;
14798211489SZach Brown 	u16			sc_msg_type;
14898211489SZach Brown };
14998211489SZach Brown 
15098211489SZach Brown struct o2net_msg_handler {
15198211489SZach Brown 	struct rb_node		nh_node;
15298211489SZach Brown 	u32			nh_max_len;
15398211489SZach Brown 	u32			nh_msg_type;
15498211489SZach Brown 	u32			nh_key;
15598211489SZach Brown 	o2net_msg_handler_func	*nh_func;
15698211489SZach Brown 	o2net_msg_handler_func	*nh_func_data;
15798211489SZach Brown 	struct kref		nh_kref;
15898211489SZach Brown 	struct list_head	nh_unregister_item;
15998211489SZach Brown };
16098211489SZach Brown 
16198211489SZach Brown enum o2net_system_error {
16298211489SZach Brown 	O2NET_ERR_NONE = 0,
16398211489SZach Brown 	O2NET_ERR_NO_HNDLR,
16498211489SZach Brown 	O2NET_ERR_OVERFLOW,
16598211489SZach Brown 	O2NET_ERR_DIED,
16698211489SZach Brown 	O2NET_ERR_MAX
16798211489SZach Brown };
16898211489SZach Brown 
16998211489SZach Brown struct o2net_status_wait {
17098211489SZach Brown 	enum o2net_system_error	ns_sys_status;
17198211489SZach Brown 	s32			ns_status;
17298211489SZach Brown 	int			ns_id;
17398211489SZach Brown 	wait_queue_head_t	ns_wq;
17498211489SZach Brown 	struct list_head	ns_node_item;
17598211489SZach Brown };
17698211489SZach Brown 
17798211489SZach Brown #endif /* O2CLUSTER_TCP_INTERNAL_H */
178