1789Sahrens /*
2789Sahrens * CDDL HEADER START
3789Sahrens *
4789Sahrens * The contents of this file are subject to the terms of the
51544Seschrock * Common Development and Distribution License (the "License").
61544Seschrock * You may not use this file except in compliance with the License.
7789Sahrens *
8789Sahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9789Sahrens * or http://www.opensolaris.org/os/licensing.
10789Sahrens * See the License for the specific language governing permissions
11789Sahrens * and limitations under the License.
12789Sahrens *
13789Sahrens * When distributing Covered Code, include this CDDL HEADER in each
14789Sahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15789Sahrens * If applicable, add the following below this CDDL HEADER, with the
16789Sahrens * fields enclosed by brackets "[]" replaced with your own identifying
17789Sahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18789Sahrens *
19789Sahrens * CDDL HEADER END
20789Sahrens */
21789Sahrens /*
22*12296SLin.Ling@Sun.COM * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23789Sahrens */
24789Sahrens
25789Sahrens #include <sys/zfs_context.h>
26789Sahrens #include <sys/uberblock_impl.h>
27789Sahrens #include <sys/vdev_impl.h>
28789Sahrens
29789Sahrens int
uberblock_verify(uberblock_t * ub)30789Sahrens uberblock_verify(uberblock_t *ub)
31789Sahrens {
32789Sahrens if (ub->ub_magic == BSWAP_64((uint64_t)UBERBLOCK_MAGIC))
33789Sahrens byteswap_uint64_array(ub, sizeof (uberblock_t));
34789Sahrens
35789Sahrens if (ub->ub_magic != UBERBLOCK_MAGIC)
36789Sahrens return (EINVAL);
37789Sahrens
38789Sahrens return (0);
39789Sahrens }
40789Sahrens
41789Sahrens /*
42789Sahrens * Update the uberblock and return a boolean value indicating whether
43789Sahrens * anything changed in this transaction group.
44789Sahrens */
45789Sahrens int
uberblock_update(uberblock_t * ub,vdev_t * rvd,uint64_t txg)46789Sahrens uberblock_update(uberblock_t *ub, vdev_t *rvd, uint64_t txg)
47789Sahrens {
48789Sahrens ASSERT(ub->ub_txg < txg);
49789Sahrens
501760Seschrock /*
511760Seschrock * We explicitly do not set ub_version here, so that older versions
521760Seschrock * continue to be written with the previous uberblock version.
531760Seschrock */
54789Sahrens ub->ub_magic = UBERBLOCK_MAGIC;
55789Sahrens ub->ub_txg = txg;
56789Sahrens ub->ub_guid_sum = rvd->vdev_guid_sum;
57789Sahrens ub->ub_timestamp = gethrestime_sec();
58*12296SLin.Ling@Sun.COM ub->ub_software_version = SPA_VERSION;
59789Sahrens
60789Sahrens return (ub->ub_rootbp.blk_birth == txg);
61789Sahrens }
62