xref: /onnv-gate/usr/src/uts/common/fs/zfs/uberblock.c (revision 789:b348f31ed315)
1*789Sahrens /*
2*789Sahrens  * CDDL HEADER START
3*789Sahrens  *
4*789Sahrens  * The contents of this file are subject to the terms of the
5*789Sahrens  * Common Development and Distribution License, Version 1.0 only
6*789Sahrens  * (the "License").  You may not use this file except in compliance
7*789Sahrens  * with the License.
8*789Sahrens  *
9*789Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*789Sahrens  * or http://www.opensolaris.org/os/licensing.
11*789Sahrens  * See the License for the specific language governing permissions
12*789Sahrens  * and limitations under the License.
13*789Sahrens  *
14*789Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
15*789Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*789Sahrens  * If applicable, add the following below this CDDL HEADER, with the
17*789Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
18*789Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
19*789Sahrens  *
20*789Sahrens  * CDDL HEADER END
21*789Sahrens  */
22*789Sahrens /*
23*789Sahrens  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*789Sahrens  * Use is subject to license terms.
25*789Sahrens  */
26*789Sahrens 
27*789Sahrens #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*789Sahrens 
29*789Sahrens #include <sys/zfs_context.h>
30*789Sahrens #include <sys/uberblock_impl.h>
31*789Sahrens #include <sys/vdev_impl.h>
32*789Sahrens 
33*789Sahrens /* Keep the uberblock version in a varialbe so we can get at it with mdb */
34*789Sahrens static uint64_t uberblock_version = UBERBLOCK_VERSION;
35*789Sahrens 
36*789Sahrens int
37*789Sahrens uberblock_verify(uberblock_t *ub)
38*789Sahrens {
39*789Sahrens 	if (ub->ub_magic == BSWAP_64((uint64_t)UBERBLOCK_MAGIC))
40*789Sahrens 		byteswap_uint64_array(ub, sizeof (uberblock_t));
41*789Sahrens 
42*789Sahrens 	if (ub->ub_magic != UBERBLOCK_MAGIC)
43*789Sahrens 		return (EINVAL);
44*789Sahrens 
45*789Sahrens 	if (ub->ub_version != UBERBLOCK_VERSION)
46*789Sahrens 		return (ENOTSUP);
47*789Sahrens 
48*789Sahrens 	return (0);
49*789Sahrens }
50*789Sahrens 
51*789Sahrens /*
52*789Sahrens  * Update the uberblock and return a boolean value indicating whether
53*789Sahrens  * anything changed in this transaction group.
54*789Sahrens  */
55*789Sahrens int
56*789Sahrens uberblock_update(uberblock_t *ub, vdev_t *rvd, uint64_t txg)
57*789Sahrens {
58*789Sahrens 	ASSERT(ub->ub_txg < txg);
59*789Sahrens 
60*789Sahrens 	ub->ub_magic = UBERBLOCK_MAGIC;
61*789Sahrens 	ub->ub_version = UBERBLOCK_VERSION;
62*789Sahrens 	ub->ub_txg = txg;
63*789Sahrens 	ub->ub_guid_sum = rvd->vdev_guid_sum;
64*789Sahrens 	ub->ub_timestamp = gethrestime_sec();
65*789Sahrens 
66*789Sahrens 	return (ub->ub_rootbp.blk_birth == txg);
67*789Sahrens }
68