xref: /netbsd-src/external/cddl/osnet/dist/uts/common/fs/zfs/uberblock.c (revision 3227e6cf668bd374971740bd6660f43cee4417ac)
1c1cb2cd8Shaad /*
2c1cb2cd8Shaad  * CDDL HEADER START
3c1cb2cd8Shaad  *
4c1cb2cd8Shaad  * The contents of this file are subject to the terms of the
5c1cb2cd8Shaad  * Common Development and Distribution License (the "License").
6c1cb2cd8Shaad  * You may not use this file except in compliance with the License.
7c1cb2cd8Shaad  *
8c1cb2cd8Shaad  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9c1cb2cd8Shaad  * or http://www.opensolaris.org/os/licensing.
10c1cb2cd8Shaad  * See the License for the specific language governing permissions
11c1cb2cd8Shaad  * and limitations under the License.
12c1cb2cd8Shaad  *
13c1cb2cd8Shaad  * When distributing Covered Code, include this CDDL HEADER in each
14c1cb2cd8Shaad  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15c1cb2cd8Shaad  * If applicable, add the following below this CDDL HEADER, with the
16c1cb2cd8Shaad  * fields enclosed by brackets "[]" replaced with your own identifying
17c1cb2cd8Shaad  * information: Portions Copyright [yyyy] [name of copyright owner]
18c1cb2cd8Shaad  *
19c1cb2cd8Shaad  * CDDL HEADER END
20c1cb2cd8Shaad  */
21c1cb2cd8Shaad /*
22*3227e6cfSchs  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23*3227e6cfSchs  * Copyright (c) 2013, 2014 by Delphix. All rights reserved.
24c1cb2cd8Shaad  */
25c1cb2cd8Shaad 
26c1cb2cd8Shaad #include <sys/zfs_context.h>
27c1cb2cd8Shaad #include <sys/uberblock_impl.h>
28c1cb2cd8Shaad #include <sys/vdev_impl.h>
29c1cb2cd8Shaad 
30c1cb2cd8Shaad int
uberblock_verify(uberblock_t * ub)31c1cb2cd8Shaad uberblock_verify(uberblock_t *ub)
32c1cb2cd8Shaad {
33c1cb2cd8Shaad 	if (ub->ub_magic == BSWAP_64((uint64_t)UBERBLOCK_MAGIC))
34c1cb2cd8Shaad 		byteswap_uint64_array(ub, sizeof (uberblock_t));
35c1cb2cd8Shaad 
36c1cb2cd8Shaad 	if (ub->ub_magic != UBERBLOCK_MAGIC)
37*3227e6cfSchs 		return (SET_ERROR(EINVAL));
38c1cb2cd8Shaad 
39c1cb2cd8Shaad 	return (0);
40c1cb2cd8Shaad }
41c1cb2cd8Shaad 
42c1cb2cd8Shaad /*
43*3227e6cfSchs  * Update the uberblock and return TRUE if anything changed in this
44*3227e6cfSchs  * transaction group.
45c1cb2cd8Shaad  */
46*3227e6cfSchs boolean_t
uberblock_update(uberblock_t * ub,vdev_t * rvd,uint64_t txg)47c1cb2cd8Shaad uberblock_update(uberblock_t *ub, vdev_t *rvd, uint64_t txg)
48c1cb2cd8Shaad {
49c1cb2cd8Shaad 	ASSERT(ub->ub_txg < txg);
50c1cb2cd8Shaad 
51c1cb2cd8Shaad 	/*
52c1cb2cd8Shaad 	 * We explicitly do not set ub_version here, so that older versions
53c1cb2cd8Shaad 	 * continue to be written with the previous uberblock version.
54c1cb2cd8Shaad 	 */
55c1cb2cd8Shaad 	ub->ub_magic = UBERBLOCK_MAGIC;
56c1cb2cd8Shaad 	ub->ub_txg = txg;
57c1cb2cd8Shaad 	ub->ub_guid_sum = rvd->vdev_guid_sum;
58c1cb2cd8Shaad 	ub->ub_timestamp = gethrestime_sec();
59*3227e6cfSchs 	ub->ub_software_version = SPA_VERSION;
60c1cb2cd8Shaad 
61c1cb2cd8Shaad 	return (ub->ub_rootbp.blk_birth == txg);
62c1cb2cd8Shaad }
63