1fa9e406ahrens/*
2fa9e406ahrens * CDDL HEADER START
3fa9e406ahrens *
4fa9e406ahrens * The contents of this file are subject to the terms of the
5ea8dc4beschrock * Common Development and Distribution License (the "License").
6ea8dc4beschrock * 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 */
21fa9e406ahrens/*
223f9d6adLin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
238671400Serapheim Dimitropoulos * Copyright (c) 2013, 2017 by Delphix. All rights reserved.
24fa9e406ahrens */
25fa9e406ahrens
26fa9e406ahrens#include <sys/zfs_context.h>
27fa9e406ahrens#include <sys/uberblock_impl.h>
28fa9e406ahrens#include <sys/vdev_impl.h>
294348eb9Olaf Faaland#include <sys/mmp.h>
30fa9e406ahrens
31fa9e406ahrensint
32fa9e406ahrensuberblock_verify(uberblock_t *ub)
33fa9e406ahrens{
34fa9e406ahrens	if (ub->ub_magic == BSWAP_64((uint64_t)UBERBLOCK_MAGIC))
35fa9e406ahrens		byteswap_uint64_array(ub, sizeof (uberblock_t));
36fa9e406ahrens
37fa9e406ahrens	if (ub->ub_magic != UBERBLOCK_MAGIC)
38be6fd75Matthew Ahrens		return (SET_ERROR(EINVAL));
39fa9e406ahrens
40fa9e406ahrens	return (0);
41fa9e406ahrens}
42fa9e406ahrens
43fa9e406ahrens/*
44231aab8Matthew Ahrens * Update the uberblock and return TRUE if anything changed in this
45231aab8Matthew Ahrens * transaction group.
46fa9e406ahrens */
47231aab8Matthew Ahrensboolean_t
48e0f1c0aOlaf Faalanduberblock_update(uberblock_t *ub, vdev_t *rvd, uint64_t txg, uint64_t mmp_delay)
49fa9e406ahrens{
50fa9e406ahrens	ASSERT(ub->ub_txg < txg);
51fa9e406ahrens
52eaca9bbeschrock	/*
53eaca9bbeschrock	 * We explicitly do not set ub_version here, so that older versions
54eaca9bbeschrock	 * continue to be written with the previous uberblock version.
55eaca9bbeschrock	 */
56fa9e406ahrens	ub->ub_magic = UBERBLOCK_MAGIC;
57fa9e406ahrens	ub->ub_txg = txg;
58fa9e406ahrens	ub->ub_guid_sum = rvd->vdev_guid_sum;
59fa9e406ahrens	ub->ub_timestamp = gethrestime_sec();
603f9d6adLin Ling	ub->ub_software_version = SPA_VERSION;
61e0f1c0aOlaf Faaland	ub->ub_mmp_magic = MMP_MAGIC;
624348eb9Olaf Faaland	if (spa_multihost(rvd->vdev_spa)) {
634348eb9Olaf Faaland		ub->ub_mmp_delay = mmp_delay;
644348eb9Olaf Faaland		ub->ub_mmp_config = MMP_SEQ_SET(0) |
654348eb9Olaf Faaland		    MMP_INTERVAL_SET(zfs_multihost_interval) |
664348eb9Olaf Faaland		    MMP_FAIL_INT_SET(zfs_multihost_fail_intervals);
674348eb9Olaf Faaland	} else {
684348eb9Olaf Faaland		ub->ub_mmp_delay = 0;
694348eb9Olaf Faaland		ub->ub_mmp_config = 0;
704348eb9Olaf Faaland	}
718671400Serapheim Dimitropoulos	ub->ub_checkpoint_txg = 0;
72fa9e406ahrens
73fa9e406ahrens	return (ub->ub_rootbp.blk_birth == txg);
74fa9e406ahrens}
75