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