fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Common Development and Distribution License (the "License").
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * or http://www.opensolaris.org/os/licensing.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
231aab857f14a3e7a0ed5f2879399c3cd6ae92eaMatthew Ahrens * Copyright (c) 2013, 2014 by Delphix. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/zfs_context.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/uberblock_impl.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/vdev_impl.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensint
fa9e4066f08beec538e775443c5be79dd423fcabahrensuberblock_verify(uberblock_t *ub)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (ub->ub_magic == BSWAP_64((uint64_t)UBERBLOCK_MAGIC))
fa9e4066f08beec538e775443c5be79dd423fcabahrens byteswap_uint64_array(ub, sizeof (uberblock_t));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (ub->ub_magic != UBERBLOCK_MAGIC)
be6fd75a69ae679453d9cda5bff3326111e6d1caMatthew Ahrens return (SET_ERROR(EINVAL));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
231aab857f14a3e7a0ed5f2879399c3cd6ae92eaMatthew Ahrens * Update the uberblock and return TRUE if anything changed in this
231aab857f14a3e7a0ed5f2879399c3cd6ae92eaMatthew Ahrens * transaction group.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
231aab857f14a3e7a0ed5f2879399c3cd6ae92eaMatthew Ahrensboolean_t
fa9e4066f08beec538e775443c5be79dd423fcabahrensuberblock_update(uberblock_t *ub, vdev_t *rvd, uint64_t txg)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT(ub->ub_txg < txg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock /*
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock * We explicitly do not set ub_version here, so that older versions
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock * continue to be written with the previous uberblock version.
eaca9bbd5f5d1e4e554da4c7108e8a03c8c33481eschrock */
fa9e4066f08beec538e775443c5be79dd423fcabahrens ub->ub_magic = UBERBLOCK_MAGIC;
fa9e4066f08beec538e775443c5be79dd423fcabahrens ub->ub_txg = txg;
fa9e4066f08beec538e775443c5be79dd423fcabahrens ub->ub_guid_sum = rvd->vdev_guid_sum;
fa9e4066f08beec538e775443c5be79dd423fcabahrens ub->ub_timestamp = gethrestime_sec();
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling ub->ub_software_version = SPA_VERSION;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (ub->ub_rootbp.blk_birth == txg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}