1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5ecc2d604Sbonwick  * Common Development and Distribution License (the "License").
6ecc2d604Sbonwick  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
223f9d6ad7SLin Ling  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2386714001SSerapheim Dimitropoulos  * Copyright (c) 2016, 2017 by Delphix. All rights reserved.
24fa9e4066Sahrens  */
25fa9e4066Sahrens 
26fa9e4066Sahrens #ifndef _SYS_UBERBLOCK_IMPL_H
27fa9e4066Sahrens #define	_SYS_UBERBLOCK_IMPL_H
28fa9e4066Sahrens 
29fa9e4066Sahrens #include <sys/uberblock.h>
30fa9e4066Sahrens 
31fa9e4066Sahrens #ifdef	__cplusplus
32fa9e4066Sahrens extern "C" {
33fa9e4066Sahrens #endif
34fa9e4066Sahrens 
35fa9e4066Sahrens /*
36fa9e4066Sahrens  * The uberblock version is incremented whenever an incompatible on-disk
37fa9e4066Sahrens  * format change is made to the SPA, DMU, or ZAP.
38fa9e4066Sahrens  *
39fa9e4066Sahrens  * Note: the first two fields should never be moved.  When a storage pool
40fa9e4066Sahrens  * is opened, the uberblock must be read off the disk before the version
41fa9e4066Sahrens  * can be checked.  If the ub_version field is moved, we may not detect
42fa9e4066Sahrens  * version mismatch.  If the ub_magic field is moved, applications that
43fa9e4066Sahrens  * expect the magic number in the first word won't work.
44fa9e4066Sahrens  */
45fa9e4066Sahrens #define	UBERBLOCK_MAGIC		0x00bab10c		/* oo-ba-bloc!	*/
46ecc2d604Sbonwick #define	UBERBLOCK_SHIFT		10			/* up to 1K	*/
47*4348eb90SOlaf Faaland #define	MMP_MAGIC		0xa11cea11		/* all-see-all	*/
48*4348eb90SOlaf Faaland 
49*4348eb90SOlaf Faaland #define	MMP_INTERVAL_VALID_BIT	0x01
50*4348eb90SOlaf Faaland #define	MMP_SEQ_VALID_BIT	0x02
51*4348eb90SOlaf Faaland #define	MMP_FAIL_INT_VALID_BIT	0x04
52*4348eb90SOlaf Faaland 
53*4348eb90SOlaf Faaland #define	MMP_VALID(ubp)		(ubp->ub_magic == UBERBLOCK_MAGIC && \
54*4348eb90SOlaf Faaland 				    ubp->ub_mmp_magic == MMP_MAGIC)
55*4348eb90SOlaf Faaland #define	MMP_INTERVAL_VALID(ubp)	(MMP_VALID(ubp) && (ubp->ub_mmp_config & \
56*4348eb90SOlaf Faaland 				    MMP_INTERVAL_VALID_BIT))
57*4348eb90SOlaf Faaland #define	MMP_SEQ_VALID(ubp)	(MMP_VALID(ubp) && (ubp->ub_mmp_config & \
58*4348eb90SOlaf Faaland 				    MMP_SEQ_VALID_BIT))
59*4348eb90SOlaf Faaland #define	MMP_FAIL_INT_VALID(ubp)	(MMP_VALID(ubp) && (ubp->ub_mmp_config & \
60*4348eb90SOlaf Faaland 				    MMP_FAIL_INT_VALID_BIT))
61*4348eb90SOlaf Faaland 
62*4348eb90SOlaf Faaland #define	MMP_INTERVAL(ubp)	((ubp->ub_mmp_config & 0x00000000FFFFFF00) \
63*4348eb90SOlaf Faaland 				    >> 8)
64*4348eb90SOlaf Faaland #define	MMP_SEQ(ubp)		((ubp->ub_mmp_config & 0x0000FFFF00000000) \
65*4348eb90SOlaf Faaland 				    >> 32)
66*4348eb90SOlaf Faaland #define	MMP_FAIL_INT(ubp)	((ubp->ub_mmp_config & 0xFFFF000000000000) \
67*4348eb90SOlaf Faaland 				    >> 48)
68*4348eb90SOlaf Faaland 
69*4348eb90SOlaf Faaland #define	MMP_INTERVAL_SET(write) \
70*4348eb90SOlaf Faaland 	    (((uint64_t)(write & 0xFFFFFF) << 8) | MMP_INTERVAL_VALID_BIT)
71*4348eb90SOlaf Faaland 
72*4348eb90SOlaf Faaland #define	MMP_SEQ_SET(seq) \
73*4348eb90SOlaf Faaland 	    (((uint64_t)(seq & 0xFFFF) << 32) | MMP_SEQ_VALID_BIT)
74*4348eb90SOlaf Faaland 
75*4348eb90SOlaf Faaland #define	MMP_FAIL_INT_SET(fail) \
76*4348eb90SOlaf Faaland 	    (((uint64_t)(fail & 0xFFFF) << 48) | MMP_FAIL_INT_VALID_BIT)
77fa9e4066Sahrens 
78fa9e4066Sahrens struct uberblock {
79fa9e4066Sahrens 	uint64_t	ub_magic;	/* UBERBLOCK_MAGIC		*/
80e7437265Sahrens 	uint64_t	ub_version;	/* SPA_VERSION			*/
81fa9e4066Sahrens 	uint64_t	ub_txg;		/* txg of last sync		*/
82fa9e4066Sahrens 	uint64_t	ub_guid_sum;	/* sum of all vdev guids	*/
83fa9e4066Sahrens 	uint64_t	ub_timestamp;	/* UTC time of last sync	*/
84fa9e4066Sahrens 	blkptr_t	ub_rootbp;	/* MOS objset_phys_t		*/
853f9d6ad7SLin Ling 
863f9d6ad7SLin Ling 	/* highest SPA_VERSION supported by software that wrote this txg */
873f9d6ad7SLin Ling 	uint64_t	ub_software_version;
8879c2b812SSerapheim Dimitropoulos 
89e0f1c0afSOlaf Faaland 	/* Maybe missing in uberblocks we read, but always written */
9079c2b812SSerapheim Dimitropoulos 	uint64_t	ub_mmp_magic;
91*4348eb90SOlaf Faaland 	/*
92*4348eb90SOlaf Faaland 	 * If ub_mmp_delay == 0 and ub_mmp_magic is valid, MMP is off.
93*4348eb90SOlaf Faaland 	 * Otherwise, nanosec since last MMP write.
94*4348eb90SOlaf Faaland 	 */
9579c2b812SSerapheim Dimitropoulos 	uint64_t	ub_mmp_delay;
96*4348eb90SOlaf Faaland 
97*4348eb90SOlaf Faaland 	/*
98*4348eb90SOlaf Faaland 	 * The ub_mmp_config contains the multihost write interval, multihost
99*4348eb90SOlaf Faaland 	 * fail intervals, sequence number for sub-second granularity, and
100*4348eb90SOlaf Faaland 	 * valid bit mask.  This layout is as follows:
101*4348eb90SOlaf Faaland 	 *
102*4348eb90SOlaf Faaland 	 *   64      56      48      40      32      24      16      8       0
103*4348eb90SOlaf Faaland 	 *   +-------+-------+-------+-------+-------+-------+-------+-------+
104*4348eb90SOlaf Faaland 	 * 0 | Fail Intervals|      Seq      |   Write Interval (ms) | VALID |
105*4348eb90SOlaf Faaland 	 *   +-------+-------+-------+-------+-------+-------+-------+-------+
106*4348eb90SOlaf Faaland 	 *
107*4348eb90SOlaf Faaland 	 * This allows a write_interval of (2^24/1000)s, over 4.5 hours
108*4348eb90SOlaf Faaland 	 *
109*4348eb90SOlaf Faaland 	 * VALID Bits:
110*4348eb90SOlaf Faaland 	 * - 0x01 - Write Interval (ms)
111*4348eb90SOlaf Faaland 	 * - 0x02 - Sequence number exists
112*4348eb90SOlaf Faaland 	 * - 0x04 - Fail Intervals
113*4348eb90SOlaf Faaland 	 * - 0xf8 - Reserved
114*4348eb90SOlaf Faaland 	 */
115*4348eb90SOlaf Faaland 	uint64_t	ub_mmp_config;
11686714001SSerapheim Dimitropoulos 
11786714001SSerapheim Dimitropoulos 	/*
11886714001SSerapheim Dimitropoulos 	 * ub_checkpoint_txg indicates two things about the current uberblock:
11986714001SSerapheim Dimitropoulos 	 *
12086714001SSerapheim Dimitropoulos 	 * 1] If it is not zero then this uberblock is a checkpoint. If it is
12186714001SSerapheim Dimitropoulos 	 *    zero, then this uberblock is not a checkpoint.
12286714001SSerapheim Dimitropoulos 	 *
12386714001SSerapheim Dimitropoulos 	 * 2] On checkpointed uberblocks, the value of ub_checkpoint_txg is
12486714001SSerapheim Dimitropoulos 	 *    the ub_txg that the uberblock had at the time we moved it to
12586714001SSerapheim Dimitropoulos 	 *    the MOS config.
12686714001SSerapheim Dimitropoulos 	 *
12786714001SSerapheim Dimitropoulos 	 * The field is set when we checkpoint the uberblock and continues to
12886714001SSerapheim Dimitropoulos 	 * hold that value even after we've rewound (unlike the ub_txg that
12986714001SSerapheim Dimitropoulos 	 * is reset to a higher value).
13086714001SSerapheim Dimitropoulos 	 *
13186714001SSerapheim Dimitropoulos 	 * Besides checks used to determine whether we are reopening the
13286714001SSerapheim Dimitropoulos 	 * pool from a checkpointed uberblock [see spa_ld_select_uberblock()],
13386714001SSerapheim Dimitropoulos 	 * the value of the field is used to determine which ZIL blocks have
13486714001SSerapheim Dimitropoulos 	 * been allocated according to the ms_sm when we are rewinding to a
13586714001SSerapheim Dimitropoulos 	 * checkpoint. Specifically, if blk_birth > ub_checkpoint_txg, then
13686714001SSerapheim Dimitropoulos 	 * the ZIL block is not allocated [see uses of spa_min_claim_txg()].
13786714001SSerapheim Dimitropoulos 	 */
13879c2b812SSerapheim Dimitropoulos 	uint64_t	ub_checkpoint_txg;
139fa9e4066Sahrens };
140fa9e4066Sahrens 
141fa9e4066Sahrens #ifdef	__cplusplus
142fa9e4066Sahrens }
143fa9e4066Sahrens #endif
144fa9e4066Sahrens 
145fa9e4066Sahrens #endif	/* _SYS_UBERBLOCK_IMPL_H */
146