xref: /onnv-gate/usr/src/uts/common/fs/zfs/uberblock.c (revision 1760:e1ad2821c30d)
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 /*
221544Seschrock  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23789Sahrens  * Use is subject to license terms.
24789Sahrens  */
25789Sahrens 
26789Sahrens #pragma ident	"%Z%%M%	%I%	%E% SMI"
27789Sahrens 
28789Sahrens #include <sys/zfs_context.h>
29789Sahrens #include <sys/uberblock_impl.h>
30789Sahrens #include <sys/vdev_impl.h>
31789Sahrens 
32789Sahrens int
33789Sahrens uberblock_verify(uberblock_t *ub)
34789Sahrens {
35789Sahrens 	if (ub->ub_magic == BSWAP_64((uint64_t)UBERBLOCK_MAGIC))
36789Sahrens 		byteswap_uint64_array(ub, sizeof (uberblock_t));
37789Sahrens 
38789Sahrens 	if (ub->ub_magic != UBERBLOCK_MAGIC)
39789Sahrens 		return (EINVAL);
40789Sahrens 
41789Sahrens 	return (0);
42789Sahrens }
43789Sahrens 
44789Sahrens /*
45789Sahrens  * Update the uberblock and return a boolean value indicating whether
46789Sahrens  * anything changed in this transaction group.
47789Sahrens  */
48789Sahrens int
49789Sahrens uberblock_update(uberblock_t *ub, vdev_t *rvd, uint64_t txg)
50789Sahrens {
51789Sahrens 	ASSERT(ub->ub_txg < txg);
52789Sahrens 
53*1760Seschrock 	/*
54*1760Seschrock 	 * We explicitly do not set ub_version here, so that older versions
55*1760Seschrock 	 * continue to be written with the previous uberblock version.
56*1760Seschrock 	 */
57789Sahrens 	ub->ub_magic = UBERBLOCK_MAGIC;
58789Sahrens 	ub->ub_txg = txg;
59789Sahrens 	ub->ub_guid_sum = rvd->vdev_guid_sum;
60789Sahrens 	ub->ub_timestamp = gethrestime_sec();
61789Sahrens 
62789Sahrens 	return (ub->ub_rootbp.blk_birth == txg);
63789Sahrens }
64