1168404Spjd/*
2168404Spjd * CDDL HEADER START
3168404Spjd *
4168404Spjd * The contents of this file are subject to the terms of the
5168404Spjd * Common Development and Distribution License (the "License").
6168404Spjd * You may not use this file except in compliance with the License.
7168404Spjd *
8168404Spjd * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9168404Spjd * or http://www.opensolaris.org/os/licensing.
10168404Spjd * See the License for the specific language governing permissions
11168404Spjd * and limitations under the License.
12168404Spjd *
13168404Spjd * When distributing Covered Code, include this CDDL HEADER in each
14168404Spjd * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15168404Spjd * If applicable, add the following below this CDDL HEADER, with the
16168404Spjd * fields enclosed by brackets "[]" replaced with your own identifying
17168404Spjd * information: Portions Copyright [yyyy] [name of copyright owner]
18168404Spjd *
19168404Spjd * CDDL HEADER END
20168404Spjd */
21168404Spjd/*
22219089Spjd * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23249643Smm * Copyright (c) 2013 by Delphix. All rights reserved.
24168404Spjd */
25168404Spjd
26168404Spjd#include <sys/zfs_context.h>
27168404Spjd#include <sys/uberblock_impl.h>
28168404Spjd#include <sys/vdev_impl.h>
29168404Spjd
30168404Spjdint
31168404Spjduberblock_verify(uberblock_t *ub)
32168404Spjd{
33168404Spjd	if (ub->ub_magic == BSWAP_64((uint64_t)UBERBLOCK_MAGIC))
34168404Spjd		byteswap_uint64_array(ub, sizeof (uberblock_t));
35168404Spjd
36168404Spjd	if (ub->ub_magic != UBERBLOCK_MAGIC)
37249643Smm		return (SET_ERROR(EINVAL));
38168404Spjd
39168404Spjd	return (0);
40168404Spjd}
41168404Spjd
42168404Spjd/*
43168404Spjd * Update the uberblock and return a boolean value indicating whether
44168404Spjd * anything changed in this transaction group.
45168404Spjd */
46168404Spjdint
47168404Spjduberblock_update(uberblock_t *ub, vdev_t *rvd, uint64_t txg)
48168404Spjd{
49168404Spjd	ASSERT(ub->ub_txg < txg);
50168404Spjd
51168404Spjd	/*
52168404Spjd	 * We explicitly do not set ub_version here, so that older versions
53168404Spjd	 * continue to be written with the previous uberblock version.
54168404Spjd	 */
55168404Spjd	ub->ub_magic = UBERBLOCK_MAGIC;
56168404Spjd	ub->ub_txg = txg;
57168404Spjd	ub->ub_guid_sum = rvd->vdev_guid_sum;
58168404Spjd	ub->ub_timestamp = gethrestime_sec();
59219089Spjd	ub->ub_software_version = SPA_VERSION;
60168404Spjd
61168404Spjd	return (ub->ub_rootbp.blk_birth == txg);
62168404Spjd}
63