2fa9e406ahrens * CDDL HEADER START
3fa9e406ahrens *
4fa9e406ahrens * The contents of this file are subject to the terms of the
5ecc2d60bonwick * Common Development and Distribution License (the "License").
6ecc2d60bonwick * You may not use this file except in compliance with the License.
7fa9e406ahrens *
8fa9e406ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e406ahrens * or http://www.opensolaris.org/os/licensing.
10fa9e406ahrens * See the License for the specific language governing permissions
11fa9e406ahrens * and limitations under the License.
12fa9e406ahrens *
13fa9e406ahrens * When distributing Covered Code, include this CDDL HEADER in each
14fa9e406ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e406ahrens * If applicable, add the following below this CDDL HEADER, with the
16fa9e406ahrens * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e406ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e406ahrens *
19fa9e406ahrens * CDDL HEADER END
20fa9e406ahrens */
223f9d6adLin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
238671400Serapheim Dimitropoulos * Copyright (c) 2016, 2017 by Delphix. All rights reserved.
24fa9e406ahrens */
26fa9e406ahrens#ifndef _SYS_UBERBLOCK_IMPL_H
27fa9e406ahrens#define	_SYS_UBERBLOCK_IMPL_H
29fa9e406ahrens#include <sys/uberblock.h>
31fa9e406ahrens#ifdef	__cplusplus
32fa9e406ahrensextern "C" {
36fa9e406ahrens * The uberblock version is incremented whenever an incompatible on-disk
37fa9e406ahrens * format change is made to the SPA, DMU, or ZAP.
38fa9e406ahrens *
39fa9e406ahrens * Note: the first two fields should never be moved.  When a storage pool
40fa9e406ahrens * is opened, the uberblock must be read off the disk before the version
41fa9e406ahrens * can be checked.  If the ub_version field is moved, we may not detect
42fa9e406ahrens * version mismatch.  If the ub_magic field is moved, applications that
43fa9e406ahrens * expect the magic number in the first word won't work.
44fa9e406ahrens */
45fa9e406ahrens#define	UBERBLOCK_MAGIC		0x00bab10c		/* oo-ba-bloc!	*/
46ecc2d60bonwick#define	UBERBLOCK_SHIFT		10			/* up to 1K	*/
474348eb9Olaf Faaland#define	MMP_MAGIC		0xa11cea11		/* all-see-all	*/
484348eb9Olaf Faaland
494348eb9Olaf Faaland#define	MMP_INTERVAL_VALID_BIT	0x01
504348eb9Olaf Faaland#define	MMP_SEQ_VALID_BIT	0x02
514348eb9Olaf Faaland#define	MMP_FAIL_INT_VALID_BIT	0x04
524348eb9Olaf Faaland
534348eb9Olaf Faaland#define	MMP_VALID(ubp)		(ubp->ub_magic == UBERBLOCK_MAGIC && \
544348eb9Olaf Faaland				    ubp->ub_mmp_magic == MMP_MAGIC)
554348eb9Olaf Faaland#define	MMP_INTERVAL_VALID(ubp)	(MMP_VALID(ubp) && (ubp->ub_mmp_config & \
564348eb9Olaf Faaland				    MMP_INTERVAL_VALID_BIT))
574348eb9Olaf Faaland#define	MMP_SEQ_VALID(ubp)	(MMP_VALID(ubp) && (ubp->ub_mmp_config & \
584348eb9Olaf Faaland				    MMP_SEQ_VALID_BIT))
594348eb9Olaf Faaland#define	MMP_FAIL_INT_VALID(ubp)	(MMP_VALID(ubp) && (ubp->ub_mmp_config & \
604348eb9Olaf Faaland				    MMP_FAIL_INT_VALID_BIT))
614348eb9Olaf Faaland
624348eb9Olaf Faaland#define	MMP_INTERVAL(ubp)	((ubp->ub_mmp_config & 0x00000000FFFFFF00) \
634348eb9Olaf Faaland				    >> 8)
644348eb9Olaf Faaland#define	MMP_SEQ(ubp)		((ubp->ub_mmp_config & 0x0000FFFF00000000) \
654348eb9Olaf Faaland				    >> 32)
664348eb9Olaf Faaland#define	MMP_FAIL_INT(ubp)	((ubp->ub_mmp_config & 0xFFFF000000000000) \
674348eb9Olaf Faaland				    >> 48)
684348eb9Olaf Faaland
694348eb9Olaf Faaland#define	MMP_INTERVAL_SET(write) \
704348eb9Olaf Faaland	    (((uint64_t)(write & 0xFFFFFF) << 8) | MMP_INTERVAL_VALID_BIT)
714348eb9Olaf Faaland
724348eb9Olaf Faaland#define	MMP_SEQ_SET(seq) \
734348eb9Olaf Faaland	    (((uint64_t)(seq & 0xFFFF) << 32) | MMP_SEQ_VALID_BIT)
744348eb9Olaf Faaland
754348eb9Olaf Faaland#define	MMP_FAIL_INT_SET(fail) \
764348eb9Olaf Faaland	    (((uint64_t)(fail & 0xFFFF) << 48) | MMP_FAIL_INT_VALID_BIT)
78fa9e406ahrensstruct uberblock {
79fa9e406ahrens	uint64_t	ub_magic;	/* UBERBLOCK_MAGIC		*/
80e743726ahrens	uint64_t	ub_version;	/* SPA_VERSION			*/
81fa9e406ahrens	uint64_t	ub_txg;		/* txg of last sync		*/
82fa9e406ahrens	uint64_t	ub_guid_sum;	/* sum of all vdev guids	*/
83fa9e406ahrens	uint64_t	ub_timestamp;	/* UTC time of last sync	*/
84fa9e406ahrens	blkptr_t	ub_rootbp;	/* MOS objset_phys_t		*/
853f9d6adLin Ling
863f9d6adLin Ling	/* highest SPA_VERSION supported by software that wrote this txg */
873f9d6adLin Ling	uint64_t	ub_software_version;
8879c2b81Serapheim Dimitropoulos
89e0f1c0aOlaf Faaland	/* Maybe missing in uberblocks we read, but always written */
9079c2b81Serapheim Dimitropoulos	uint64_t	ub_mmp_magic;
914348eb9Olaf Faaland	/*
924348eb9Olaf Faaland	 * If ub_mmp_delay == 0 and ub_mmp_magic is valid, MMP is off.
934348eb9Olaf Faaland	 * Otherwise, nanosec since last MMP write.
944348eb9Olaf Faaland	 */
9579c2b81Serapheim Dimitropoulos	uint64_t	ub_mmp_delay;
964348eb9Olaf Faaland
974348eb9Olaf Faaland	/*
984348eb9Olaf Faaland	 * The ub_mmp_config contains the multihost write interval, multihost
994348eb9Olaf Faaland	 * fail intervals, sequence number for sub-second granularity, and
1004348eb9Olaf Faaland	 * valid bit mask.  This layout is as follows:
1014348eb9Olaf Faaland	 *
1024348eb9Olaf Faaland	 *   64      56      48      40      32      24      16      8       0
1034348eb9Olaf Faaland	 *   +-------+-------+-------+-------+-------+-------+-------+-------+
1044348eb9Olaf Faaland	 * 0 | Fail Intervals|      Seq      |   Write Interval (ms) | VALID |
1054348eb9Olaf Faaland	 *   +-------+-------+-------+-------+-------+-------+-------+-------+
1064348eb9Olaf Faaland	 *
1074348eb9Olaf Faaland	 * This allows a write_interval of (2^24/1000)s, over 4.5 hours
1084348eb9Olaf Faaland	 *
1094348eb9Olaf Faaland	 * VALID Bits:
1104348eb9Olaf Faaland	 * - 0x01 - Write Interval (ms)
1114348eb9Olaf Faaland	 * - 0x02 - Sequence number exists
1124348eb9Olaf Faaland	 * - 0x04 - Fail Intervals
1134348eb9Olaf Faaland	 * - 0xf8 - Reserved
1144348eb9Olaf Faaland	 */
1154348eb9Olaf Faaland	uint64_t	ub_mmp_config;
1168671400Serapheim Dimitropoulos
1178671400Serapheim Dimitropoulos	/*
1188671400Serapheim Dimitropoulos	 * ub_checkpoint_txg indicates two things about the current uberblock:
1198671400Serapheim Dimitropoulos	 *
1208671400Serapheim Dimitropoulos	 * 1] If it is not zero then this uberblock is a checkpoint. If it is
1218671400Serapheim Dimitropoulos	 *    zero, then this uberblock is not a checkpoint.
1228671400Serapheim Dimitropoulos	 *
1238671400Serapheim Dimitropoulos	 * 2] On checkpointed uberblocks, the value of ub_checkpoint_txg is
1248671400Serapheim Dimitropoulos	 *    the ub_txg that the uberblock had at the time we moved it to
1258671400Serapheim Dimitropoulos	 *    the MOS config.
1268671400Serapheim Dimitropoulos	 *
1278671400Serapheim Dimitropoulos	 * The field is set when we checkpoint the uberblock and continues to
1288671400Serapheim Dimitropoulos	 * hold that value even after we've rewound (unlike the ub_txg that
1298671400Serapheim Dimitropoulos	 * is reset to a higher value).
1308671400Serapheim Dimitropoulos	 *
1318671400Serapheim Dimitropoulos	 * Besides checks used to determine whether we are reopening the
1328671400Serapheim Dimitropoulos	 * pool from a checkpointed uberblock [see spa_ld_select_uberblock()],
1338671400Serapheim Dimitropoulos	 * the value of the field is used to determine which ZIL blocks have
1348671400Serapheim Dimitropoulos	 * been allocated according to the ms_sm when we are rewinding to a
1358671400Serapheim Dimitropoulos	 * checkpoint. Specifically, if blk_birth > ub_checkpoint_txg, then
1368671400Serapheim Dimitropoulos	 * the ZIL block is not allocated [see uses of spa_min_claim_txg()].
1378671400Serapheim Dimitropoulos	 */
13879c2b81Serapheim Dimitropoulos	uint64_t	ub_checkpoint_txg;
141fa9e406ahrens#ifdef	__cplusplus
145fa9e406ahrens#endif	/* _SYS_UBERBLOCK_IMPL_H */