xref: /freebsd/sys/contrib/openzfs/include/sys/mmp.h (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1 // SPDX-License-Identifier: CDDL-1.0
2 /*
3  * CDDL HEADER START
4  *
5  * This file and its contents are supplied under the terms of the
6  * Common Development and Distribution License ("CDDL"), version 1.0.
7  * You may only use this file in accordance with the terms of version
8  * 1.0 of the CDDL.
9  *
10  * A full copy of the text of the CDDL should have accompanied this
11  * source.  A copy of the CDDL is also available via the Internet at
12  * http://www.illumos.org/license/CDDL.
13  *
14  * CDDL HEADER END
15  */
16 /*
17  * Copyright (C) 2017 by Lawrence Livermore National Security, LLC.
18  */
19 
20 #ifndef _SYS_MMP_H
21 #define	_SYS_MMP_H
22 
23 #include <sys/spa.h>
24 #include <sys/zfs_context.h>
25 #include <sys/uberblock_impl.h>
26 
27 #ifdef	__cplusplus
28 extern "C" {
29 #endif
30 
31 #define	MMP_MIN_INTERVAL		100	/* ms */
32 #define	MMP_DEFAULT_INTERVAL		1000	/* ms */
33 #define	MMP_DEFAULT_IMPORT_INTERVALS	20
34 #define	MMP_DEFAULT_FAIL_INTERVALS	10
35 #define	MMP_MIN_FAIL_INTERVALS		2	/* min if != 0 */
36 #define	MMP_IMPORT_SAFETY_FACTOR	200	/* pct */
37 #define	MMP_INTERVAL_OK(interval)	MAX(interval, MMP_MIN_INTERVAL)
38 #define	MMP_FAIL_INTVS_OK(fails)	(fails == 0 ? 0 : MAX(fails, \
39 					    MMP_MIN_FAIL_INTERVALS))
40 
41 typedef struct mmp_thread {
42 	kmutex_t	mmp_thread_lock; /* protect thread mgmt fields */
43 	kcondvar_t	mmp_thread_cv;
44 	kthread_t	*mmp_thread;
45 	uint8_t		mmp_thread_exiting;
46 	kmutex_t	mmp_io_lock;	/* protect below */
47 	hrtime_t	mmp_last_write;	/* last successful MMP write */
48 	uint64_t	mmp_delay;	/* decaying avg ns between MMP writes */
49 	uberblock_t	mmp_ub;		/* last ub written by sync */
50 	zio_t		*mmp_zio_root;	/* root of mmp write zios */
51 	uint64_t	mmp_kstat_id;	/* unique id for next MMP write kstat */
52 	int		mmp_skip_error; /* reason for last skipped write */
53 	vdev_t		*mmp_last_leaf;	/* last mmp write sent here */
54 	uint64_t	mmp_leaf_last_gen;	/* last mmp write sent here */
55 	uint32_t	mmp_seq;	/* intra-second update counter */
56 } mmp_thread_t;
57 
58 
59 extern void mmp_init(struct spa *spa);
60 extern void mmp_fini(struct spa *spa);
61 extern void mmp_thread_start(struct spa *spa);
62 extern void mmp_thread_stop(struct spa *spa);
63 extern void mmp_update_uberblock(struct spa *spa, struct uberblock *ub);
64 extern void mmp_signal_all_threads(void);
65 
66 /* Global tuning */
67 extern int param_set_multihost_interval(ZFS_MODULE_PARAM_ARGS);
68 extern uint64_t zfs_multihost_interval;
69 extern uint_t zfs_multihost_fail_intervals;
70 extern uint_t zfs_multihost_import_intervals;
71 
72 #ifdef	__cplusplus
73 }
74 #endif
75 
76 #endif	/* _SYS_MMP_H */
77