uberblock.c revision 168404
1249259Sdim/* 2249259Sdim * CDDL HEADER START 3249259Sdim * 4249259Sdim * The contents of this file are subject to the terms of the 5249259Sdim * Common Development and Distribution License (the "License"). 6249259Sdim * You may not use this file except in compliance with the License. 7249259Sdim * 8249259Sdim * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9249259Sdim * or http://www.opensolaris.org/os/licensing. 10249259Sdim * See the License for the specific language governing permissions 11249259Sdim * and limitations under the License. 12249259Sdim * 13249259Sdim * When distributing Covered Code, include this CDDL HEADER in each 14249259Sdim * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15249259Sdim * If applicable, add the following below this CDDL HEADER, with the 16249259Sdim * fields enclosed by brackets "[]" replaced with your own identifying 17249259Sdim * information: Portions Copyright [yyyy] [name of copyright owner] 18249259Sdim * 19249259Sdim * CDDL HEADER END 20249259Sdim */ 21249259Sdim/* 22249259Sdim * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23249259Sdim * Use is subject to license terms. 24249259Sdim */ 25249259Sdim 26249259Sdim#pragma ident "%Z%%M% %I% %E% SMI" 27249259Sdim 28249259Sdim#include <sys/zfs_context.h> 29249259Sdim#include <sys/uberblock_impl.h> 30249259Sdim#include <sys/vdev_impl.h> 31249259Sdim 32263508Sdimint 33263508Sdimuberblock_verify(uberblock_t *ub) 34249259Sdim{ 35249259Sdim if (ub->ub_magic == BSWAP_64((uint64_t)UBERBLOCK_MAGIC)) 36249259Sdim byteswap_uint64_array(ub, sizeof (uberblock_t)); 37249259Sdim 38249259Sdim if (ub->ub_magic != UBERBLOCK_MAGIC) 39249259Sdim return (EINVAL); 40249259Sdim 41249259Sdim return (0); 42249259Sdim} 43249259Sdim 44249259Sdim/* 45249259Sdim * Update the uberblock and return a boolean value indicating whether 46249259Sdim * anything changed in this transaction group. 47249259Sdim */ 48249259Sdimint 49249259Sdimuberblock_update(uberblock_t *ub, vdev_t *rvd, uint64_t txg) 50249259Sdim{ 51249259Sdim ASSERT(ub->ub_txg < txg); 52249259Sdim 53249259Sdim /* 54249259Sdim * We explicitly do not set ub_version here, so that older versions 55249259Sdim * continue to be written with the previous uberblock version. 56249259Sdim */ 57249259Sdim ub->ub_magic = UBERBLOCK_MAGIC; 58249259Sdim ub->ub_txg = txg; 59249259Sdim ub->ub_guid_sum = rvd->vdev_guid_sum; 60249259Sdim ub->ub_timestamp = gethrestime_sec(); 61249259Sdim 62249259Sdim return (ub->ub_rootbp.blk_birth == txg); 63249259Sdim} 64249259Sdim