199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2002 McAfee, Inc.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This software was developed for the FreeBSD Project by Marshall
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Kirk McKusick and McAfee Research,, the Security Research Division of
199767f8919635c4928607450d9e0abb932109ceToomas Soome * McAfee, Inc. under DARPA/SPAWAR contract N66001-01-C-8035 ("CBOSS"), as
199767f8919635c4928607450d9e0abb932109ceToomas Soome * part of the DARPA CHATS research program
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are met:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * CDDL HEADER START
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The contents of this file are subject to the terms of the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Common Development and Distribution License (the "License").
199767f8919635c4928607450d9e0abb932109ceToomas Soome * You may not use this file except in compliance with the License.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
199767f8919635c4928607450d9e0abb932109ceToomas Soome * or http://www.opensolaris.org/os/licensing.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * See the License for the specific language governing permissions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * and limitations under the License.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * When distributing Covered Code, include this CDDL HEADER in each
199767f8919635c4928607450d9e0abb932109ceToomas Soome * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If applicable, add the following below this CDDL HEADER, with the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * fields enclosed by brackets "[]" replaced with your own identifying
199767f8919635c4928607450d9e0abb932109ceToomas Soome * information: Portions Copyright [yyyy] [name of copyright owner]
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * CDDL HEADER END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Use is subject to license terms.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright 2013 by Saso Kiselkov. All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2013 by Delphix. All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MAXNAMELEN 256
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _NOTE(s)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef enum { B_FALSE, B_TRUE } boolean_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* CRC64 table */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZFS_CRC64_POLY 0xC96C5795D7870F42ULL /* ECMA-182, reflected form */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Macros for various sorts of alignment and rounding when the alignment
199767f8919635c4928607450d9e0abb932109ceToomas Soome * is known to be a power of 2.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define P2ALIGN(x, align) ((x) & -(align))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define P2PHASE(x, align) ((x) & ((align) - 1))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define P2NPHASE(x, align) (-(x) & ((align) - 1))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define P2ROUNDUP(x, align) (-(-(x) & -(align)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define P2END(x, align) (-(~(x) & -(align)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define P2PHASEUP(x, align, phase) ((phase) - (((phase) - (x)) & -(align)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define P2BOUNDARY(off, len, align) (((off) ^ ((off) + (len) - 1)) > (align) - 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * General-purpose 32-bit and 64-bit bitfield encodings.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BF32_DECODE(x, low, len) P2PHASE((x) >> (low), 1U << (len))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BF64_DECODE(x, low, len) P2PHASE((x) >> (low), 1ULL << (len))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BF32_ENCODE(x, low, len) (P2PHASE((x), 1U << (len)) << (low))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BF64_ENCODE(x, low, len) (P2PHASE((x), 1ULL << (len)) << (low))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BF32_GET(x, low, len) BF32_DECODE(x, low, len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BF64_GET(x, low, len) BF64_DECODE(x, low, len)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BF32_SET(x, low, len, val) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((x) ^= BF32_ENCODE((x >> low) ^ (val), low, len))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BF64_SET(x, low, len, val) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((x) ^= BF64_ENCODE((x >> low) ^ (val), low, len))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BF32_GET_SB(x, low, len, shift, bias) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((BF32_GET(x, low, len) + (bias)) << (shift))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BF64_GET_SB(x, low, len, shift, bias) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((BF64_GET(x, low, len) + (bias)) << (shift))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BF32_SET_SB(x, low, len, shift, bias, val) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF32_SET(x, low, len, ((val) >> (shift)) - (bias))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BF64_SET_SB(x, low, len, shift, bias, val) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF64_SET(x, low, len, ((val) >> (shift)) - (bias))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Macros to reverse byte order
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BSWAP_8(x) ((x) & 0xff)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BSWAP_16(x) ((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BSWAP_32(x) ((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BSWAP_64(x) ((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_MINBLOCKSHIFT 9
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_OLDMAXBLOCKSHIFT 17
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_MAXBLOCKSHIFT 24
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_MINBLOCKSIZE (1ULL << SPA_MINBLOCKSHIFT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_OLDMAXBLOCKSIZE (1ULL << SPA_OLDMAXBLOCKSHIFT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_MAXBLOCKSIZE (1ULL << SPA_MAXBLOCKSHIFT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The DVA size encodings for LSIZE and PSIZE support blocks up to 32MB.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The ASIZE encoding should be at least 64 times larger (6 more bits)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to support up to 4-way RAID-Z mirror mode with worst-case gang block
199767f8919635c4928607450d9e0abb932109ceToomas Soome * overhead, three DVAs per bp, plus one more bit in case we do anything
199767f8919635c4928607450d9e0abb932109ceToomas Soome * else that expands the ASIZE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_LSIZEBITS 16 /* LSIZE up to 32M (2^16 * 512) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_PSIZEBITS 16 /* PSIZE up to 32M (2^16 * 512) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_ASIZEBITS 24 /* ASIZE up to 64 times larger */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All SPA data is represented by 128-bit data virtual addresses (DVAs).
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The members of the dva_t should be considered opaque outside the SPA.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct dva {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dva_word[2];
199767f8919635c4928607450d9e0abb932109ceToomas Soome} dva_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Each block has a 256-bit checksum -- strong enough for cryptographic hashes.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct zio_cksum {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zc_word[4];
199767f8919635c4928607450d9e0abb932109ceToomas Soome} zio_cksum_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Some checksums/hashes need a 256-bit initialization salt. This salt is kept
199767f8919635c4928607450d9e0abb932109ceToomas Soome * secret and is suitable for use in MAC algorithms as the key.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct zio_cksum_salt {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t zcs_bytes[32];
199767f8919635c4928607450d9e0abb932109ceToomas Soome} zio_cksum_salt_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Each block is described by its DVAs, time of birth, checksum, etc.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The word-by-word, bit-by-bit layout of the blkptr is as follows:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 64 56 48 40 32 24 16 8 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 0 | vdev1 | GRID | ASIZE |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1 |G| offset1 |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2 | vdev2 | GRID | ASIZE |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 3 |G| offset2 |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 4 | vdev3 | GRID | ASIZE |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 5 |G| offset3 |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 6 |BDX|lvl| type | cksum |E| comp| PSIZE | LSIZE |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 7 | padding |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 8 | padding |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 9 | physical birth txg |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * a | logical birth txg |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * b | fill count |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * c | checksum[0] |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * d | checksum[1] |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * e | checksum[2] |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * f | checksum[3] |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Legend:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * vdev virtual device ID
199767f8919635c4928607450d9e0abb932109ceToomas Soome * offset offset into virtual device
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LSIZE logical size
199767f8919635c4928607450d9e0abb932109ceToomas Soome * PSIZE physical size (after compression)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ASIZE allocated size (including RAID-Z parity and gang block headers)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * GRID RAID-Z layout information (reserved for future use)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * cksum checksum function
199767f8919635c4928607450d9e0abb932109ceToomas Soome * comp compression function
199767f8919635c4928607450d9e0abb932109ceToomas Soome * G gang block indicator
199767f8919635c4928607450d9e0abb932109ceToomas Soome * B byteorder (endianness)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * D dedup
199767f8919635c4928607450d9e0abb932109ceToomas Soome * X encryption (on version 30, which is not supported)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * E blkptr_t contains embedded data (see below)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * lvl level of indirection
199767f8919635c4928607450d9e0abb932109ceToomas Soome * type DMU object type
199767f8919635c4928607450d9e0abb932109ceToomas Soome * phys birth txg of block allocation; zero if same as logical birth txg
199767f8919635c4928607450d9e0abb932109ceToomas Soome * log. birth transaction group in which the block was logically born
199767f8919635c4928607450d9e0abb932109ceToomas Soome * fill count number of non-zero blocks under this bp
199767f8919635c4928607450d9e0abb932109ceToomas Soome * checksum[4] 256-bit checksum of the data this bp describes
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * "Embedded" blkptr_t's don't actually point to a block, instead they
199767f8919635c4928607450d9e0abb932109ceToomas Soome * have a data payload embedded in the blkptr_t itself. See the comment
199767f8919635c4928607450d9e0abb932109ceToomas Soome * in blkptr.c for more details.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The blkptr_t is laid out as follows:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 64 56 48 40 32 24 16 8 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 0 | payload |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1 | payload |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2 | payload |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 3 | payload |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 4 | payload |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 5 | payload |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 6 |BDX|lvl| type | etype |E| comp| PSIZE| LSIZE |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 7 | payload |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 8 | payload |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 9 | payload |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * a | logical birth txg |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * b | payload |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * c | payload |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * d | payload |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * e | payload |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * f | payload |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +-------+-------+-------+-------+-------+-------+-------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Legend:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * payload contains the embedded data
199767f8919635c4928607450d9e0abb932109ceToomas Soome * B (byteorder) byteorder (endianness)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * D (dedup) padding (set to zero)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * X encryption (set to zero; see above)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * E (embedded) set to one
199767f8919635c4928607450d9e0abb932109ceToomas Soome * lvl indirection level
199767f8919635c4928607450d9e0abb932109ceToomas Soome * type DMU object type
199767f8919635c4928607450d9e0abb932109ceToomas Soome * etype how to interpret embedded data (BP_EMBEDDED_TYPE_*)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * comp compression function of payload
199767f8919635c4928607450d9e0abb932109ceToomas Soome * PSIZE size of payload after compression, in bytes
199767f8919635c4928607450d9e0abb932109ceToomas Soome * LSIZE logical size of payload, in bytes
199767f8919635c4928607450d9e0abb932109ceToomas Soome * note that 25 bits is enough to store the largest
199767f8919635c4928607450d9e0abb932109ceToomas Soome * "normal" BP's LSIZE (2^16 * 2^9) in bytes
199767f8919635c4928607450d9e0abb932109ceToomas Soome * log. birth transaction group in which the block was logically born
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Note that LSIZE and PSIZE are stored in bytes, whereas for non-embedded
199767f8919635c4928607450d9e0abb932109ceToomas Soome * bp's they are stored in units of SPA_MINBLOCKSHIFT.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Generally, the generic BP_GET_*() macros can be used on embedded BP's.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The B, D, X, lvl, type, and comp fields are stored the same as with normal
199767f8919635c4928607450d9e0abb932109ceToomas Soome * BP's so the BP_SET_* macros can be used with them. etype, PSIZE, LSIZE must
199767f8919635c4928607450d9e0abb932109ceToomas Soome * be set with the BPE_SET_* macros. BP_SET_EMBEDDED() should be called before
199767f8919635c4928607450d9e0abb932109ceToomas Soome * other macros, as they assert that they are only used on BP's of the correct
199767f8919635c4928607450d9e0abb932109ceToomas Soome * "embedded-ness".
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BPE_GET_ETYPE(bp) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (ASSERT(BP_IS_EMBEDDED(bp)), \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF64_GET((bp)->blk_prop, 40, 8))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BPE_SET_ETYPE(bp, t) do { \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ASSERT(BP_IS_EMBEDDED(bp)); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF64_SET((bp)->blk_prop, 40, 8, t); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome_NOTE(CONSTCOND) } while (0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BPE_GET_LSIZE(bp) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (ASSERT(BP_IS_EMBEDDED(bp)), \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF64_GET_SB((bp)->blk_prop, 0, 25, 0, 1))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BPE_SET_LSIZE(bp, x) do { \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ASSERT(BP_IS_EMBEDDED(bp)); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF64_SET_SB((bp)->blk_prop, 0, 25, 0, 1, x); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome_NOTE(CONSTCOND) } while (0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BPE_GET_PSIZE(bp) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (ASSERT(BP_IS_EMBEDDED(bp)), \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF64_GET_SB((bp)->blk_prop, 25, 7, 0, 1))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BPE_SET_PSIZE(bp, x) do { \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ASSERT(BP_IS_EMBEDDED(bp)); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF64_SET_SB((bp)->blk_prop, 25, 7, 0, 1, x); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome_NOTE(CONSTCOND) } while (0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef enum bp_embedded_type {
199767f8919635c4928607450d9e0abb932109ceToomas Soome BP_EMBEDDED_TYPE_DATA,
199767f8919635c4928607450d9e0abb932109ceToomas Soome BP_EMBEDDED_TYPE_RESERVED, /* Reserved for an unintegrated feature. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome NUM_BP_EMBEDDED_TYPES = BP_EMBEDDED_TYPE_RESERVED
199767f8919635c4928607450d9e0abb932109ceToomas Soome} bp_embedded_type_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BPE_NUM_WORDS 14
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof (uint64_t))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BPE_IS_PAYLOADWORD(bp, wp) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_BLKPTRSHIFT 7 /* blkptr_t is 128 bytes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_DVAS_PER_BP 3 /* Number of DVAs in a bp */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct blkptr {
199767f8919635c4928607450d9e0abb932109ceToomas Soome dva_t blk_dva[SPA_DVAS_PER_BP]; /* Data Virtual Addresses */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t blk_prop; /* size, compression, type, etc */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t blk_pad[2]; /* Extra space for the future */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t blk_phys_birth; /* txg when block was allocated */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t blk_birth; /* transaction group at birth */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t blk_fill; /* fill count */
199767f8919635c4928607450d9e0abb932109ceToomas Soome zio_cksum_t blk_cksum; /* 256-bit checksum */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} blkptr_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Macros to get and set fields in a bp or DVA.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DVA_GET_ASIZE(dva) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF64_GET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, SPA_MINBLOCKSHIFT, 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DVA_SET_ASIZE(dva, x) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF64_SET_SB((dva)->dva_word[0], 0, SPA_ASIZEBITS, \
199767f8919635c4928607450d9e0abb932109ceToomas Soome SPA_MINBLOCKSHIFT, 0, x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DVA_GET_GRID(dva) BF64_GET((dva)->dva_word[0], 24, 8)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DVA_SET_GRID(dva, x) BF64_SET((dva)->dva_word[0], 24, 8, x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DVA_GET_VDEV(dva) BF64_GET((dva)->dva_word[0], 32, 32)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DVA_SET_VDEV(dva, x) BF64_SET((dva)->dva_word[0], 32, 32, x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DVA_GET_OFFSET(dva) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF64_GET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DVA_SET_OFFSET(dva, x) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF64_SET_SB((dva)->dva_word[1], 0, 63, SPA_MINBLOCKSHIFT, 0, x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DVA_GET_GANG(dva) BF64_GET((dva)->dva_word[1], 63, 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DVA_SET_GANG(dva, x) BF64_SET((dva)->dva_word[1], 63, 1, x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_GET_LSIZE(bp) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (BP_IS_EMBEDDED(bp) ? \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (BPE_GET_ETYPE(bp) == BP_EMBEDDED_TYPE_DATA ? BPE_GET_LSIZE(bp) : 0): \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF64_GET_SB((bp)->blk_prop, 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_SET_LSIZE(bp, x) do { \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ASSERT(!BP_IS_EMBEDDED(bp)); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF64_SET_SB((bp)->blk_prop, \
199767f8919635c4928607450d9e0abb932109ceToomas Soome 0, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome_NOTE(CONSTCOND) } while (0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_GET_PSIZE(bp) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF64_GET_SB((bp)->blk_prop, 16, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_SET_PSIZE(bp, x) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF64_SET_SB((bp)->blk_prop, 16, SPA_LSIZEBITS, SPA_MINBLOCKSHIFT, 1, x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_GET_COMPRESS(bp) BF64_GET((bp)->blk_prop, 32, 7)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_SET_COMPRESS(bp, x) BF64_SET((bp)->blk_prop, 32, 7, x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_GET_CHECKSUM(bp) BF64_GET((bp)->blk_prop, 40, 8)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_SET_CHECKSUM(bp, x) BF64_SET((bp)->blk_prop, 40, 8, x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_GET_TYPE(bp) BF64_GET((bp)->blk_prop, 48, 8)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_SET_TYPE(bp, x) BF64_SET((bp)->blk_prop, 48, 8, x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_GET_LEVEL(bp) BF64_GET((bp)->blk_prop, 56, 5)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_SET_LEVEL(bp, x) BF64_SET((bp)->blk_prop, 56, 5, x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_IS_EMBEDDED(bp) BF64_GET((bp)->blk_prop, 39, 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_GET_DEDUP(bp) BF64_GET((bp)->blk_prop, 62, 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_SET_DEDUP(bp, x) BF64_SET((bp)->blk_prop, 62, 1, x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_GET_BYTEORDER(bp) BF64_GET((bp)->blk_prop, 63, 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_SET_BYTEORDER(bp, x) BF64_SET((bp)->blk_prop, 63, 1, x)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_PHYSICAL_BIRTH(bp) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((bp)->blk_phys_birth ? (bp)->blk_phys_birth : (bp)->blk_birth)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_GET_ASIZE(bp) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (DVA_GET_ASIZE(&(bp)->blk_dva[0]) + DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
199767f8919635c4928607450d9e0abb932109ceToomas Soome DVA_GET_ASIZE(&(bp)->blk_dva[2]))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_GET_UCSIZE(bp) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((BP_GET_LEVEL(bp) > 0 || dmu_ot[BP_GET_TYPE(bp)].ot_metadata) ? \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BP_GET_PSIZE(bp) : BP_GET_LSIZE(bp));
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_GET_NDVAS(bp) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (!!DVA_GET_ASIZE(&(bp)->blk_dva[0]) + \
199767f8919635c4928607450d9e0abb932109ceToomas Soome !!DVA_GET_ASIZE(&(bp)->blk_dva[1]) + \
199767f8919635c4928607450d9e0abb932109ceToomas Soome !!DVA_GET_ASIZE(&(bp)->blk_dva[2]))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DVA_EQUAL(dva1, dva2) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((dva1)->dva_word[1] == (dva2)->dva_word[1] && \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (dva1)->dva_word[0] == (dva2)->dva_word[0])
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZIO_CHECKSUM_EQUAL(zc1, zc2) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (0 == (((zc1).zc_word[0] - (zc2).zc_word[0]) | \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((zc1).zc_word[1] - (zc2).zc_word[1]) | \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((zc1).zc_word[2] - (zc2).zc_word[2]) | \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((zc1).zc_word[3] - (zc2).zc_word[3])))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DVA_IS_VALID(dva) (DVA_GET_ASIZE(dva) != 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZIO_SET_CHECKSUM(zcp, w0, w1, w2, w3) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome{ \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (zcp)->zc_word[0] = w0; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (zcp)->zc_word[1] = w1; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (zcp)->zc_word[2] = w2; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (zcp)->zc_word[3] = w3; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_IDENTITY(bp) (&(bp)->blk_dva[0])
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_IS_GANG(bp) DVA_GET_GANG(BP_IDENTITY(bp))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DVA_IS_EMPTY(dva) ((dva)->dva_word[0] == 0ULL && \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (dva)->dva_word[1] == 0ULL)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_IS_HOLE(bp) DVA_IS_EMPTY(BP_IDENTITY(bp))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_IS_OLDER(bp, txg) (!BP_IS_HOLE(bp) && (bp)->blk_birth < (txg))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BP_ZERO(bp) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome{ \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (bp)->blk_dva[0].dva_word[0] = 0; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (bp)->blk_dva[0].dva_word[1] = 0; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (bp)->blk_dva[1].dva_word[0] = 0; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (bp)->blk_dva[1].dva_word[1] = 0; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (bp)->blk_dva[2].dva_word[0] = 0; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (bp)->blk_dva[2].dva_word[1] = 0; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (bp)->blk_prop = 0; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (bp)->blk_pad[0] = 0; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (bp)->blk_pad[1] = 0; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (bp)->blk_phys_birth = 0; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (bp)->blk_birth = 0; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (bp)->blk_fill = 0; \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_SET_CHECKSUM(&(bp)->blk_cksum, 0, 0, 0, 0); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BPE_NUM_WORDS 14
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BPE_PAYLOAD_SIZE (BPE_NUM_WORDS * sizeof (uint64_t))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define BPE_IS_PAYLOADWORD(bp, wp) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((wp) != &(bp)->blk_prop && (wp) != &(bp)->blk_birth)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Embedded checksum
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZEC_MAGIC 0x210da7ab10c7a11ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct zio_eck {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zec_magic; /* for validation, endianness */
199767f8919635c4928607450d9e0abb932109ceToomas Soome zio_cksum_t zec_cksum; /* 256-bit checksum */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} zio_eck_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Gang block headers are self-checksumming and contain an array
199767f8919635c4928607450d9e0abb932109ceToomas Soome * of block pointers.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_GANGBLOCKSIZE SPA_MINBLOCKSIZE
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_GBH_NBLKPTRS ((SPA_GANGBLOCKSIZE - \
199767f8919635c4928607450d9e0abb932109ceToomas Soome sizeof (zio_eck_t)) / sizeof (blkptr_t))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_GBH_FILLER ((SPA_GANGBLOCKSIZE - \
199767f8919635c4928607450d9e0abb932109ceToomas Soome sizeof (zio_eck_t) - \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (SPA_GBH_NBLKPTRS * sizeof (blkptr_t))) /\
199767f8919635c4928607450d9e0abb932109ceToomas Soome sizeof (uint64_t))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct zio_gbh {
199767f8919635c4928607450d9e0abb932109ceToomas Soome blkptr_t zg_blkptr[SPA_GBH_NBLKPTRS];
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zg_filler[SPA_GBH_FILLER];
199767f8919635c4928607450d9e0abb932109ceToomas Soome zio_eck_t zg_tail;
199767f8919635c4928607450d9e0abb932109ceToomas Soome} zio_gbh_phys_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_RAIDZ_MAXPARITY 3
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_PAD_SIZE (8 << 10)
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* 2 padding areas (vl_pad1 and vl_pad2) to skip */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_SKIP_SIZE VDEV_PAD_SIZE * 2
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_PHYS_SIZE (112 << 10)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_UBERBLOCK_RING (128 << 10)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_UBERBLOCK_SHIFT(vd) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome MAX((vd)->v_top->v_ashift, UBERBLOCK_SHIFT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_UBERBLOCK_COUNT(vd) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (VDEV_UBERBLOCK_RING >> VDEV_UBERBLOCK_SHIFT(vd))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_UBERBLOCK_OFFSET(vd, n) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome offsetof(vdev_label_t, vl_uberblock[(n) << VDEV_UBERBLOCK_SHIFT(vd)])
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_UBERBLOCK_SIZE(vd) (1ULL << VDEV_UBERBLOCK_SHIFT(vd))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct vdev_phys {
199767f8919635c4928607450d9e0abb932109ceToomas Soome char vp_nvlist[VDEV_PHYS_SIZE - sizeof (zio_eck_t)];
199767f8919635c4928607450d9e0abb932109ceToomas Soome zio_eck_t vp_zbt;
199767f8919635c4928607450d9e0abb932109ceToomas Soome} vdev_phys_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct vdev_label {
199767f8919635c4928607450d9e0abb932109ceToomas Soome char vl_pad1[VDEV_PAD_SIZE]; /* 8K */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char vl_pad2[VDEV_PAD_SIZE]; /* 8K */
199767f8919635c4928607450d9e0abb932109ceToomas Soome vdev_phys_t vl_vdev_phys; /* 112K */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char vl_uberblock[VDEV_UBERBLOCK_RING]; /* 128K */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} vdev_label_t; /* 256K total */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * vdev_dirty() flags
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDD_METASLAB 0x01
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDD_DTL 0x02
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Size and offset of embedded boot loader region on each label.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The total size of the first two labels plus the boot area is 4MB.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_BOOT_OFFSET (2 * sizeof (vdev_label_t))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_BOOT_SIZE (7ULL << 19) /* 3.5M */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Size of label regions at the start and end of each leaf device.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_LABEL_START_SIZE (2 * sizeof (vdev_label_t) + VDEV_BOOT_SIZE)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_LABEL_END_SIZE (2 * sizeof (vdev_label_t))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_LABELS 4
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeenum zio_checksum {
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_CHECKSUM_INHERIT = 0,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_CHECKSUM_ON,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_CHECKSUM_OFF,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_CHECKSUM_LABEL,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_CHECKSUM_GANG_HEADER,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_CHECKSUM_ZILOG,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_CHECKSUM_FLETCHER_2,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_CHECKSUM_FLETCHER_4,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_CHECKSUM_SHA256,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_CHECKSUM_ZILOG2,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_CHECKSUM_NOPARITY,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_CHECKSUM_SHA512,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_CHECKSUM_SKEIN,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_CHECKSUM_EDONR,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_CHECKSUM_FUNCTIONS
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZIO_CHECKSUM_ON_VALUE ZIO_CHECKSUM_FLETCHER_4
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZIO_CHECKSUM_DEFAULT ZIO_CHECKSUM_ON
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomeenum zio_compress {
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_INHERIT = 0,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_ON,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_OFF,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_LZJB,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_EMPTY,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_GZIP_1,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_GZIP_2,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_GZIP_3,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_GZIP_4,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_GZIP_5,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_GZIP_6,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_GZIP_7,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_GZIP_8,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_GZIP_9,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_ZLE,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_LZ4,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZIO_COMPRESS_FUNCTIONS
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZIO_COMPRESS_ON_VALUE ZIO_COMPRESS_LZJB
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZIO_COMPRESS_DEFAULT ZIO_COMPRESS_OFF
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* nvlist pack encoding */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define NV_ENCODE_NATIVE 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define NV_ENCODE_XDR 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef enum {
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_UNKNOWN = 0,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_BOOLEAN,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_BYTE,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_INT16,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_UINT16,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_INT32,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_UINT32,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_INT64,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_UINT64,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_STRING,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_BYTE_ARRAY,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_INT16_ARRAY,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_UINT16_ARRAY,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_INT32_ARRAY,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_UINT32_ARRAY,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_INT64_ARRAY,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_UINT64_ARRAY,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_STRING_ARRAY,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_HRTIME,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_NVLIST,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_NVLIST_ARRAY,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_BOOLEAN_VALUE,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_INT8,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_UINT8,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_BOOLEAN_ARRAY,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_INT8_ARRAY,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DATA_TYPE_UINT8_ARRAY
199767f8919635c4928607450d9e0abb932109ceToomas Soome} data_type_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * On-disk version number.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_1 1ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_2 2ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_3 3ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_4 4ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_5 5ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_6 6ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_7 7ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_8 8ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_9 9ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_10 10ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_11 11ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_12 12ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_13 13ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_14 14ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_15 15ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_16 16ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_17 17ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_18 18ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_19 19ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_20 20ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_21 21ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_22 22ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_23 23ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_24 24ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_25 25ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_26 26ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_27 27ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_28 28ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_5000 5000ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * When bumping up SPA_VERSION, make sure GRUB ZFS understands the on-disk
199767f8919635c4928607450d9e0abb932109ceToomas Soome * format change. Go to usr/src/grub/grub-0.97/stage2/{zfs-include/, fsys_zfs*},
199767f8919635c4928607450d9e0abb932109ceToomas Soome * and do the appropriate changes. Also bump the version number in
199767f8919635c4928607450d9e0abb932109ceToomas Soome * usr/src/grub/capability.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION SPA_VERSION_5000
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_STRING "5000"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Symbolic names for the changes that caused a SPA_VERSION switch.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Used in the code when checking for presence or absence of a feature.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Feel free to define multiple symbolic names for each version if there
199767f8919635c4928607450d9e0abb932109ceToomas Soome * were multiple changes to on-disk structures during that version.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * NOTE: When checking the current SPA_VERSION in your code, be sure
199767f8919635c4928607450d9e0abb932109ceToomas Soome * to use spa_version() since it reports the version of the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * last synced uberblock. Checking the in-flight version can
199767f8919635c4928607450d9e0abb932109ceToomas Soome * be dangerous in some cases.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_INITIAL SPA_VERSION_1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_DITTO_BLOCKS SPA_VERSION_2
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_SPARES SPA_VERSION_3
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_RAID6 SPA_VERSION_3
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_BPLIST_ACCOUNT SPA_VERSION_3
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_RAIDZ_DEFLATE SPA_VERSION_3
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_DNODE_BYTES SPA_VERSION_3
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_ZPOOL_HISTORY SPA_VERSION_4
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_GZIP_COMPRESSION SPA_VERSION_5
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_BOOTFS SPA_VERSION_6
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_SLOGS SPA_VERSION_7
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_DELEGATED_PERMS SPA_VERSION_8
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_FUID SPA_VERSION_9
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_REFRESERVATION SPA_VERSION_9
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_REFQUOTA SPA_VERSION_9
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_UNIQUE_ACCURATE SPA_VERSION_9
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_L2CACHE SPA_VERSION_10
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_NEXT_CLONES SPA_VERSION_11
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_ORIGIN SPA_VERSION_11
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_DSL_SCRUB SPA_VERSION_11
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_SNAP_PROPS SPA_VERSION_12
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_USED_BREAKDOWN SPA_VERSION_13
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_PASSTHROUGH_X SPA_VERSION_14
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_USERSPACE SPA_VERSION_15
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_STMF_PROP SPA_VERSION_16
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_RAIDZ3 SPA_VERSION_17
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_USERREFS SPA_VERSION_18
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_HOLES SPA_VERSION_19
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_ZLE_COMPRESSION SPA_VERSION_20
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_DEDUP SPA_VERSION_21
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_RECVD_PROPS SPA_VERSION_22
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_SLIM_ZIL SPA_VERSION_23
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_SA SPA_VERSION_24
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_SCAN SPA_VERSION_25
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_DIR_CLONES SPA_VERSION_26
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_DEADLISTS SPA_VERSION_26
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_FAST_SNAP SPA_VERSION_27
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_MULTI_REPLACE SPA_VERSION_28
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_BEFORE_FEATURES SPA_VERSION_28
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_FEATURES SPA_VERSION_5000
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_VERSION_IS_SUPPORTED(v) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (((v) >= SPA_VERSION_INITIAL && (v) <= SPA_VERSION_BEFORE_FEATURES) || \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((v) >= SPA_VERSION_FEATURES && (v) <= SPA_VERSION))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The following are configuration names used in the nvlist describing a pool's
199767f8919635c4928607450d9e0abb932109ceToomas Soome * configuration.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_VERSION "version"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_POOL_NAME "name"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_POOL_STATE "state"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_POOL_TXG "txg"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_POOL_GUID "pool_guid"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_CREATE_TXG "create_txg"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_TOP_GUID "top_guid"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_VDEV_TREE "vdev_tree"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_TYPE "type"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_CHILDREN "children"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_ID "id"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_GUID "guid"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_PATH "path"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_DEVID "devid"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_PHYS_PATH "phys_path"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_METASLAB_ARRAY "metaslab_array"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_METASLAB_SHIFT "metaslab_shift"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_ASHIFT "ashift"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_ASIZE "asize"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_DTL "DTL"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_STATS "stats"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_WHOLE_DISK "whole_disk"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_ERRCOUNT "error_count"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_NOT_PRESENT "not_present"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_SPARES "spares"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_IS_SPARE "is_spare"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_NPARITY "nparity"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_HOSTID "hostid"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_HOSTNAME "hostname"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_IS_LOG "is_log"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_TIMESTAMP "timestamp" /* not stored on disk */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_FEATURES_FOR_READ "features_for_read"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The persistent vdev state is stored as separate values rather than a single
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 'vdev_state' entry. This is because a device can be in multiple states, such
199767f8919635c4928607450d9e0abb932109ceToomas Soome * as offline and degraded.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_OFFLINE "offline"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_FAULTED "faulted"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_DEGRADED "degraded"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_REMOVED "removed"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_FRU "fru"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CONFIG_AUX_STATE "aux_state"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_TYPE_ROOT "root"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_TYPE_MIRROR "mirror"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_TYPE_REPLACING "replacing"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_TYPE_RAIDZ "raidz"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_TYPE_DISK "disk"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_TYPE_FILE "file"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_TYPE_MISSING "missing"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_TYPE_HOLE "hole"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_TYPE_SPARE "spare"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_TYPE_LOG "log"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VDEV_TYPE_L2CACHE "l2cache"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This is needed in userland to report the minimum necessary device size.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SPA_MINDEVSIZE (64ULL << 20)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The location of the pool configuration repository, shared between kernel and
199767f8919635c4928607450d9e0abb932109ceToomas Soome * userland.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPOOL_CACHE "/boot/zfs/zpool.cache"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * vdev states are ordered from least to most healthy.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * A vdev that's CANT_OPEN or below is considered unusable.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef enum vdev_state {
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_STATE_UNKNOWN = 0, /* Uninitialized vdev */
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_STATE_CLOSED, /* Not currently open */
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_STATE_OFFLINE, /* Not allowed to open */
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_STATE_REMOVED, /* Explicitly removed from system */
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_STATE_CANT_OPEN, /* Tried to open, but failed */
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_STATE_FAULTED, /* External request to fault device */
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_STATE_DEGRADED, /* Replicated vdev with unhealthy kids */
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_STATE_HEALTHY /* Presumed good */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} vdev_state_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * vdev aux states. When a vdev is in the CANT_OPEN state, the aux field
199767f8919635c4928607450d9e0abb932109ceToomas Soome * of the vdev stats structure uses these constants to distinguish why.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef enum vdev_aux {
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_AUX_NONE, /* no error */
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_AUX_OPEN_FAILED, /* ldi_open_*() or vn_open() failed */
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_AUX_CORRUPT_DATA, /* bad label or disk contents */
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_AUX_NO_REPLICAS, /* insufficient number of replicas */
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_AUX_BAD_GUID_SUM, /* vdev guid sum doesn't match */
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_AUX_TOO_SMALL, /* vdev size is too small */
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_AUX_BAD_LABEL, /* the label is OK but invalid */
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_AUX_VERSION_NEWER, /* on-disk version is too new */
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_AUX_VERSION_OLDER, /* on-disk version is too old */
199767f8919635c4928607450d9e0abb932109ceToomas Soome VDEV_AUX_SPARED /* hot spare used in another pool */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} vdev_aux_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * pool state. The following states are written to disk as part of the normal
199767f8919635c4928607450d9e0abb932109ceToomas Soome * SPA lifecycle: ACTIVE, EXPORTED, DESTROYED, SPARE. The remaining states are
199767f8919635c4928607450d9e0abb932109ceToomas Soome * software abstractions used at various levels to communicate pool state.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef enum pool_state {
199767f8919635c4928607450d9e0abb932109ceToomas Soome POOL_STATE_ACTIVE = 0, /* In active use */
199767f8919635c4928607450d9e0abb932109ceToomas Soome POOL_STATE_EXPORTED, /* Explicitly exported */
199767f8919635c4928607450d9e0abb932109ceToomas Soome POOL_STATE_DESTROYED, /* Explicitly destroyed */
199767f8919635c4928607450d9e0abb932109ceToomas Soome POOL_STATE_SPARE, /* Reserved for hot spare use */
199767f8919635c4928607450d9e0abb932109ceToomas Soome POOL_STATE_UNINITIALIZED, /* Internal spa_t state */
199767f8919635c4928607450d9e0abb932109ceToomas Soome POOL_STATE_UNAVAIL, /* Internal libzfs state */
199767f8919635c4928607450d9e0abb932109ceToomas Soome POOL_STATE_POTENTIALLY_ACTIVE /* Internal libzfs state */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} pool_state_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The uberblock version is incremented whenever an incompatible on-disk
199767f8919635c4928607450d9e0abb932109ceToomas Soome * format change is made to the SPA, DMU, or ZAP.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Note: the first two fields should never be moved. When a storage pool
199767f8919635c4928607450d9e0abb932109ceToomas Soome * is opened, the uberblock must be read off the disk before the version
199767f8919635c4928607450d9e0abb932109ceToomas Soome * can be checked. If the ub_version field is moved, we may not detect
199767f8919635c4928607450d9e0abb932109ceToomas Soome * version mismatch. If the ub_magic field is moved, applications that
199767f8919635c4928607450d9e0abb932109ceToomas Soome * expect the magic number in the first word won't work.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define UBERBLOCK_MAGIC 0x00bab10c /* oo-ba-bloc! */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define UBERBLOCK_SHIFT 10 /* up to 1K */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct uberblock {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ub_magic; /* UBERBLOCK_MAGIC */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ub_version; /* SPA_VERSION */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ub_txg; /* txg of last sync */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ub_guid_sum; /* sum of all vdev guids */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ub_timestamp; /* UTC time of last sync */
199767f8919635c4928607450d9e0abb932109ceToomas Soome blkptr_t ub_rootbp; /* MOS objset_phys_t */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Flags.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DNODE_MUST_BE_ALLOCATED 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DNODE_MUST_BE_FREE 2
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Fixed constants.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DNODE_SHIFT 9 /* 512 bytes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DN_MIN_INDBLKSHIFT 12 /* 4k */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DN_MAX_INDBLKSHIFT 14 /* 16k */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DNODE_BLOCK_SHIFT 14 /* 16k */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DNODE_CORE_SIZE 64 /* 64 bytes for dnode sans blkptrs */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DN_MAX_OBJECT_SHIFT 48 /* 256 trillion (zfs_fid_t limit) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DN_MAX_OFFSET_SHIFT 64 /* 2^64 bytes in a dnode */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Derived constants.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DNODE_SIZE (1 << DNODE_SHIFT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DN_MAX_NBLKPTR ((DNODE_SIZE - DNODE_CORE_SIZE) >> SPA_BLKPTRSHIFT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DN_MAX_BONUSLEN (DNODE_SIZE - DNODE_CORE_SIZE - (1 << SPA_BLKPTRSHIFT))
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DN_MAX_OBJECT (1ULL << DN_MAX_OBJECT_SHIFT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DNODES_PER_BLOCK_SHIFT (DNODE_BLOCK_SHIFT - DNODE_SHIFT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DNODES_PER_BLOCK (1ULL << DNODES_PER_BLOCK_SHIFT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DNODES_PER_LEVEL_SHIFT (DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* The +2 here is a cheesy way to round up */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DN_MAX_LEVELS (2 + ((DN_MAX_OFFSET_SHIFT - SPA_MINBLOCKSHIFT) / \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (DN_MIN_INDBLKSHIFT - SPA_BLKPTRSHIFT)))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DN_BONUS(dnp) ((void*)((dnp)->dn_bonus + \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (((dnp)->dn_nblkptr - 1) * sizeof (blkptr_t))))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DN_USED_BYTES(dnp) (((dnp)->dn_flags & DNODE_FLAG_USED_BYTES) ? \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (dnp)->dn_used : (dnp)->dn_used << SPA_MINBLOCKSHIFT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define EPB(blkshift, typeshift) (1 << (blkshift - typeshift))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Is dn_used in bytes? if not, it's in multiples of SPA_MINBLOCKSIZE */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DNODE_FLAG_USED_BYTES (1<<0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DNODE_FLAG_USERUSED_ACCOUNTED (1<<1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* Does dnode have a SA spill blkptr in bonus? */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DNODE_FLAG_SPILL_BLKPTR (1<<2)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct dnode_phys {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t dn_type; /* dmu_object_type_t */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t dn_indblkshift; /* ln2(indirect block size) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t dn_nlevels; /* 1=dn_blkptr->data blocks */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t dn_nblkptr; /* length of dn_blkptr */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t dn_bonustype; /* type of data in bonus buffer */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t dn_checksum; /* ZIO_CHECKSUM type */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t dn_compress; /* ZIO_COMPRESS type */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t dn_flags; /* DNODE_FLAG_* */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t dn_datablkszsec; /* data block size in 512b sectors */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t dn_bonuslen; /* length of dn_bonus */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t dn_pad2[4];
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* accounting is protected by dn_dirty_mtx */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dn_maxblkid; /* largest allocated block ID */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dn_used; /* bytes (or sectors) of disk space */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dn_pad3[4];
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome blkptr_t dn_blkptr[1];
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t dn_bonus[DN_MAX_BONUSLEN - sizeof (blkptr_t)];
199767f8919635c4928607450d9e0abb932109ceToomas Soome blkptr_t dn_spill;
199767f8919635c4928607450d9e0abb932109ceToomas Soome} dnode_phys_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef enum dmu_object_byteswap {
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_BSWAP_UINT8,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_BSWAP_UINT16,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_BSWAP_UINT32,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_BSWAP_UINT64,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_BSWAP_ZAP,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_BSWAP_DNODE,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_BSWAP_OBJSET,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_BSWAP_ZNODE,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_BSWAP_OLDACL,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_BSWAP_ACL,
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Allocating a new byteswap type number makes the on-disk format
199767f8919635c4928607450d9e0abb932109ceToomas Soome * incompatible with any other format that uses the same number.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Data can usually be structured to work with one of the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DMU_BSWAP_UINT* or DMU_BSWAP_ZAP types.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_BSWAP_NUMFUNCS
199767f8919635c4928607450d9e0abb932109ceToomas Soome} dmu_object_byteswap_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DMU_OT_NEWTYPE 0x80
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DMU_OT_METADATA 0x40
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DMU_OT_BYTESWAP_MASK 0x3f
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Defines a uint8_t object type. Object types specify if the data
199767f8919635c4928607450d9e0abb932109ceToomas Soome * in the object is metadata (boolean) and how to byteswap the data
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (dmu_object_byteswap_t).
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DMU_OT(byteswap, metadata) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (DMU_OT_NEWTYPE | \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((metadata) ? DMU_OT_METADATA : 0) | \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((byteswap) & DMU_OT_BYTESWAP_MASK))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef enum dmu_object_type {
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_NONE,
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* general: */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_OBJECT_DIRECTORY, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_OBJECT_ARRAY, /* UINT64 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_PACKED_NVLIST, /* UINT8 (XDR by nvlist_pack/unpack) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_PACKED_NVLIST_SIZE, /* UINT64 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_BPLIST, /* UINT64 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_BPLIST_HDR, /* UINT64 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* spa: */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_SPACE_MAP_HEADER, /* UINT64 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_SPACE_MAP, /* UINT64 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* zil: */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_INTENT_LOG, /* UINT64 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* dmu: */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_DNODE, /* DNODE */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_OBJSET, /* OBJSET */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* dsl: */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_DSL_DIR, /* UINT64 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_DSL_DIR_CHILD_MAP, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_DSL_DS_SNAP_MAP, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_DSL_PROPS, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_DSL_DATASET, /* UINT64 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* zpl: */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_ZNODE, /* ZNODE */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_OLDACL, /* Old ACL */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_PLAIN_FILE_CONTENTS, /* UINT8 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_DIRECTORY_CONTENTS, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_MASTER_NODE, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_UNLINKED_SET, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* zvol: */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_ZVOL, /* UINT8 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_ZVOL_PROP, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* other; for testing only! */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_PLAIN_OTHER, /* UINT8 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_UINT64_OTHER, /* UINT64 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_ZAP_OTHER, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* new object types: */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_ERROR_LOG, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_SPA_HISTORY, /* UINT8 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_SPA_HISTORY_OFFSETS, /* spa_his_phys_t */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_POOL_PROPS, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_DSL_PERMS, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_ACL, /* ACL */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_SYSACL, /* SYSACL */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_FUID, /* FUID table (Packed NVLIST UINT8) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_FUID_SIZE, /* FUID table size UINT64 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_NEXT_CLONES, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_SCAN_QUEUE, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_USERGROUP_USED, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_USERGROUP_QUOTA, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_USERREFS, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_DDT_ZAP, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_DDT_STATS, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_SA, /* System attr */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_SA_MASTER_NODE, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_SA_ATTR_REGISTRATION, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_SA_ATTR_LAYOUTS, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_SCAN_XLATE, /* ZAP */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_DEDUP, /* fake dedup BP from ddt_bp_create() */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OT_NUMTYPES,
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Names for valid types declared with DMU_OT().
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OTN_UINT8_DATA = DMU_OT(DMU_BSWAP_UINT8, B_FALSE),
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OTN_UINT8_METADATA = DMU_OT(DMU_BSWAP_UINT8, B_TRUE),
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OTN_UINT16_DATA = DMU_OT(DMU_BSWAP_UINT16, B_FALSE),
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OTN_UINT16_METADATA = DMU_OT(DMU_BSWAP_UINT16, B_TRUE),
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OTN_UINT32_DATA = DMU_OT(DMU_BSWAP_UINT32, B_FALSE),
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OTN_UINT32_METADATA = DMU_OT(DMU_BSWAP_UINT32, B_TRUE),
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OTN_UINT64_DATA = DMU_OT(DMU_BSWAP_UINT64, B_FALSE),
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OTN_UINT64_METADATA = DMU_OT(DMU_BSWAP_UINT64, B_TRUE),
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OTN_ZAP_DATA = DMU_OT(DMU_BSWAP_ZAP, B_FALSE),
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OTN_ZAP_METADATA = DMU_OT(DMU_BSWAP_ZAP, B_TRUE)
199767f8919635c4928607450d9e0abb932109ceToomas Soome} dmu_object_type_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef enum dmu_objset_type {
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OST_NONE,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OST_META,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OST_ZFS,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OST_ZVOL,
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OST_OTHER, /* For testing only! */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OST_ANY, /* Be careful! */
199767f8919635c4928607450d9e0abb932109ceToomas Soome DMU_OST_NUMTYPES
199767f8919635c4928607450d9e0abb932109ceToomas Soome} dmu_objset_type_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * header for all bonus and spill buffers.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The header has a fixed portion with a variable number
199767f8919635c4928607450d9e0abb932109ceToomas Soome * of "lengths" depending on the number of variable sized
199767f8919635c4928607450d9e0abb932109ceToomas Soome * attribues which are determined by the "layout number"
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SA_MAGIC 0x2F505A /* ZFS SA */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct sa_hdr_phys {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t sa_magic;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t sa_layout_info; /* Encoded with hdrsize and layout number */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t sa_lengths[1]; /* optional sizes for variable length attrs */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* ... Data follows the lengths. */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} sa_hdr_phys_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * sa_hdr_phys -> sa_layout_info
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 16 10 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +--------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome * | hdrsz |layout |
199767f8919635c4928607450d9e0abb932109ceToomas Soome * +--------+-------+
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Bits 0-10 are the layout number
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Bits 11-16 are the size of the header.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The hdrsize is the number * 8
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * For example.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * hdrsz of 1 ==> 8 byte header
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2 ==> 16 byte header
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SA_HDR_LAYOUT_NUM(hdr) BF32_GET(hdr->sa_layout_info, 0, 10)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SA_HDR_SIZE(hdr) BF32_GET_SB(hdr->sa_layout_info, 10, 16, 3, 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SA_HDR_LAYOUT_INFO_ENCODE(x, num, size) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome{ \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF32_SET_SB(x, 10, 6, 3, 0, size); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome BF32_SET(x, 0, 10, num); \
199767f8919635c4928607450d9e0abb932109ceToomas Soome}
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SA_MODE_OFFSET 0
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SA_SIZE_OFFSET 8
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SA_GEN_OFFSET 16
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SA_UID_OFFSET 24
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SA_GID_OFFSET 32
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define SA_PARENT_OFFSET 40
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Intent log header - this on disk structure holds fields to manage
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the log. All fields are 64 bit to easily handle cross architectures.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct zil_header {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zh_claim_txg; /* txg in which log blocks were claimed */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zh_replay_seq; /* highest replayed sequence number */
199767f8919635c4928607450d9e0abb932109ceToomas Soome blkptr_t zh_log; /* log chain */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zh_claim_seq; /* highest claimed sequence number */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zh_pad[5];
199767f8919635c4928607450d9e0abb932109ceToomas Soome} zil_header_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define OBJSET_PHYS_SIZE 2048
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct objset_phys {
199767f8919635c4928607450d9e0abb932109ceToomas Soome dnode_phys_t os_meta_dnode;
199767f8919635c4928607450d9e0abb932109ceToomas Soome zil_header_t os_zil_header;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t os_type;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t os_flags;
199767f8919635c4928607450d9e0abb932109ceToomas Soome char os_pad[OBJSET_PHYS_SIZE - sizeof (dnode_phys_t)*3 -
199767f8919635c4928607450d9e0abb932109ceToomas Soome sizeof (zil_header_t) - sizeof (uint64_t)*2];
199767f8919635c4928607450d9e0abb932109ceToomas Soome dnode_phys_t os_userused_dnode;
199767f8919635c4928607450d9e0abb932109ceToomas Soome dnode_phys_t os_groupused_dnode;
199767f8919635c4928607450d9e0abb932109ceToomas Soome} objset_phys_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct dsl_dir_phys {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dd_creation_time; /* not actually used */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dd_head_dataset_obj;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dd_parent_obj;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dd_clone_parent_obj;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dd_child_dir_zapobj;
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * how much space our children are accounting for; for leaf
199767f8919635c4928607450d9e0abb932109ceToomas Soome * datasets, == physical space used by fs + snaps
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dd_used_bytes;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dd_compressed_bytes;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dd_uncompressed_bytes;
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Administrative quota setting */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dd_quota;
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* Administrative reservation setting */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dd_reserved;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dd_props_zapobj;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t dd_pad[21]; /* pad out to 256 bytes for good measure */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} dsl_dir_phys_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct dsl_dataset_phys {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_dir_obj;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_prev_snap_obj;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_prev_snap_txg;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_next_snap_obj;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_snapnames_zapobj; /* zap obj of snaps; ==0 for snaps */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_num_children; /* clone/snap children; ==0 for head */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_creation_time; /* seconds since 1970 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_creation_txg;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_deadlist_obj;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_used_bytes;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_compressed_bytes;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_uncompressed_bytes;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_unique_bytes; /* only relevant to snapshots */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The ds_fsid_guid is a 56-bit ID that can change to avoid
199767f8919635c4928607450d9e0abb932109ceToomas Soome * collisions. The ds_guid is a 64-bit ID that will never
199767f8919635c4928607450d9e0abb932109ceToomas Soome * change, so there is a small probability that it will collide.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_fsid_guid;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_guid;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_flags;
199767f8919635c4928607450d9e0abb932109ceToomas Soome blkptr_t ds_bp;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t ds_pad[8]; /* pad out to 320 bytes for good measure */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} dsl_dataset_phys_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The names of zap entries in the DIRECTORY_OBJECT of the MOS.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DMU_POOL_DIRECTORY_OBJECT 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DMU_POOL_CONFIG "config"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DMU_POOL_FEATURES_FOR_READ "features_for_read"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DMU_POOL_ROOT_DATASET "root_dataset"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DMU_POOL_SYNC_BPLIST "sync_bplist"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DMU_POOL_ERRLOG_SCRUB "errlog_scrub"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DMU_POOL_ERRLOG_LAST "errlog_last"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DMU_POOL_SPARES "spares"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DMU_POOL_DEFLATE "deflate"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DMU_POOL_HISTORY "history"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DMU_POOL_PROPS "pool_props"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZAP_MAGIC 0x2F52AB2ABULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define FZAP_BLOCK_SHIFT(zap) ((zap)->zap_block_shift)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZAP_MAXCD (uint32_t)(-1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZAP_HASHBITS 28
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MZAP_ENT_LEN 64
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MZAP_NAME_LEN (MZAP_ENT_LEN - 8 - 4 - 2)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MZAP_MAX_BLKSHIFT SPA_MAXBLOCKSHIFT
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MZAP_MAX_BLKSZ (1 << MZAP_MAX_BLKSHIFT)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct mzap_ent_phys {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t mze_value;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t mze_cd;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t mze_pad; /* in case we want to chain them someday */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char mze_name[MZAP_NAME_LEN];
199767f8919635c4928607450d9e0abb932109ceToomas Soome} mzap_ent_phys_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct mzap_phys {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t mz_block_type; /* ZBT_MICRO */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t mz_salt;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t mz_pad[6];
199767f8919635c4928607450d9e0abb932109ceToomas Soome mzap_ent_phys_t mz_chunk[1];
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* actually variable size depending on block size */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} mzap_phys_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The (fat) zap is stored in one object. It is an array of
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1<<FZAP_BLOCK_SHIFT byte blocks. The layout looks like one of:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ptrtbl fits in first block:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * [zap_phys_t zap_ptrtbl_shift < 6] [zap_leaf_t] ...
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ptrtbl too big for first block:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * [zap_phys_t zap_ptrtbl_shift >= 6] [zap_leaf_t] [ptrtbl] ...
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZBT_LEAF ((1ULL << 63) + 0)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZBT_HEADER ((1ULL << 63) + 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZBT_MICRO ((1ULL << 63) + 3)
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* any other values are ptrtbl blocks */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the embedded pointer table takes up half a block:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * block size / entry size (2^3) / 2
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZAP_EMBEDDED_PTRTBL_SHIFT(zap) (FZAP_BLOCK_SHIFT(zap) - 3 - 1)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The embedded pointer table starts half-way through the block. Since
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the pointer table itself is half the block, it starts at (64-bit)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * word number (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap)).
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZAP_EMBEDDED_PTRTBL_ENT(zap, idx) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((uint64_t *)(zap)->zap_phys) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome [(idx) + (1<<ZAP_EMBEDDED_PTRTBL_SHIFT(zap))]
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * TAKE NOTE:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If zap_phys_t is modified, zap_byteswap() must be modified.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct zap_phys {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zap_block_type; /* ZBT_HEADER */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zap_magic; /* ZAP_MAGIC */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct zap_table_phys {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zt_blk; /* starting block number */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zt_numblks; /* number of blocks */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zt_shift; /* bits to index it */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zt_nextblk; /* next (larger) copy start block */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zt_blks_copied; /* number source blocks copied */
199767f8919635c4928607450d9e0abb932109ceToomas Soome } zap_ptrtbl;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zap_freeblk; /* the next free block */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zap_num_leafs; /* number of leafs */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zap_num_entries; /* number of entries */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zap_salt; /* salt to stir into hash function */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This structure is followed by padding, and then the embedded
199767f8919635c4928607450d9e0abb932109ceToomas Soome * pointer table. The embedded pointer table takes up second
199767f8919635c4928607450d9e0abb932109ceToomas Soome * half of the block. It is accessed using the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ZAP_EMBEDDED_PTRTBL_ENT() macro.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} zap_phys_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct zap_table_phys zap_table_phys_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct fat_zap {
199767f8919635c4928607450d9e0abb932109ceToomas Soome int zap_block_shift; /* block size shift */
199767f8919635c4928607450d9e0abb932109ceToomas Soome zap_phys_t *zap_phys;
199767f8919635c4928607450d9e0abb932109ceToomas Soome} fat_zap_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZAP_LEAF_MAGIC 0x2AB1EAF
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* chunk size = 24 bytes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZAP_LEAF_CHUNKSIZE 24
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The amount of space available for chunks is:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * block size (1<<l->l_bs) - hash entry size (2) * number of hash
199767f8919635c4928607450d9e0abb932109ceToomas Soome * entries - header space (2*chunksize)
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZAP_LEAF_NUMCHUNKS(l) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (((1<<(l)->l_bs) - 2*ZAP_LEAF_HASH_NUMENTRIES(l)) / \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZAP_LEAF_CHUNKSIZE - 2)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The amount of space within the chunk available for the array is:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * chunk size - space for type (1) - space for next pointer (2)
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZAP_LEAF_ARRAY_NCHUNKS(bytes) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (((bytes)+ZAP_LEAF_ARRAY_BYTES-1)/ZAP_LEAF_ARRAY_BYTES)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Low water mark: when there are only this many chunks free, start
199767f8919635c4928607450d9e0abb932109ceToomas Soome * growing the ptrtbl. Ideally, this should be larger than a
199767f8919635c4928607450d9e0abb932109ceToomas Soome * "reasonably-sized" entry. 20 chunks is more than enough for the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * largest directory entry (MAXNAMELEN (256) byte name, 8-byte value),
199767f8919635c4928607450d9e0abb932109ceToomas Soome * while still being only around 3% for 16k blocks.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZAP_LEAF_LOW_WATER (20)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The leaf hash table has block size / 2^5 (32) number of entries,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * which should be more than enough for the maximum number of entries,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * which is less than block size / CHUNKSIZE (24) / minimum number of
199767f8919635c4928607450d9e0abb932109ceToomas Soome * chunks per entry (3).
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZAP_LEAF_HASH_SHIFT(l) ((l)->l_bs - 5)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZAP_LEAF_HASH_NUMENTRIES(l) (1 << ZAP_LEAF_HASH_SHIFT(l))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The chunks start immediately after the hash table. The end of the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * hash table is at l_hash + HASH_NUMENTRIES, which we simply cast to a
199767f8919635c4928607450d9e0abb932109ceToomas Soome * chunk_t.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZAP_LEAF_CHUNK(l, idx) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((zap_leaf_chunk_t *) \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((l)->l_phys->l_hash + ZAP_LEAF_HASH_NUMENTRIES(l)))[idx]
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZAP_LEAF_ENTRY(l, idx) (&ZAP_LEAF_CHUNK(l, idx).l_entry)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef enum zap_chunk_type {
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZAP_CHUNK_FREE = 253,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZAP_CHUNK_ENTRY = 252,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZAP_CHUNK_ARRAY = 251,
199767f8919635c4928607450d9e0abb932109ceToomas Soome ZAP_CHUNK_TYPE_MAX = 250
199767f8919635c4928607450d9e0abb932109ceToomas Soome} zap_chunk_type_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * TAKE NOTE:
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If zap_leaf_phys_t is modified, zap_leaf_byteswap() must be modified.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct zap_leaf_phys {
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct zap_leaf_header {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t lh_block_type; /* ZBT_LEAF */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t lh_pad1;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t lh_prefix; /* hash prefix of this leaf */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t lh_magic; /* ZAP_LEAF_MAGIC */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t lh_nfree; /* number free chunks */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t lh_nentries; /* number of entries */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t lh_prefix_len; /* num bits used to id this */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* above is accessable to zap, below is zap_leaf private */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t lh_freelist; /* chunk head of free list */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t lh_pad2[12];
199767f8919635c4928607450d9e0abb932109ceToomas Soome } l_hdr; /* 2 24-byte chunks */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The header is followed by a hash table with
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ZAP_LEAF_HASH_NUMENTRIES(zap) entries. The hash table is
199767f8919635c4928607450d9e0abb932109ceToomas Soome * followed by an array of ZAP_LEAF_NUMCHUNKS(zap)
199767f8919635c4928607450d9e0abb932109ceToomas Soome * zap_leaf_chunk structures. These structures are accessed
199767f8919635c4928607450d9e0abb932109ceToomas Soome * with the ZAP_LEAF_CHUNK() macro.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t l_hash[1];
199767f8919635c4928607450d9e0abb932109ceToomas Soome} zap_leaf_phys_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef union zap_leaf_chunk {
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct zap_leaf_entry {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t le_type; /* always ZAP_CHUNK_ENTRY */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t le_value_intlen; /* size of ints */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t le_next; /* next entry in hash chain */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t le_name_chunk; /* first chunk of the name */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t le_name_numints; /* bytes in name, incl null */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t le_value_chunk; /* first chunk of the value */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t le_value_numints; /* value length in ints */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t le_cd; /* collision differentiator */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t le_hash; /* hash value of the name */
199767f8919635c4928607450d9e0abb932109ceToomas Soome } l_entry;
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct zap_leaf_array {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t la_type; /* always ZAP_CHUNK_ARRAY */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t la_array[ZAP_LEAF_ARRAY_BYTES];
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t la_next; /* next blk or CHAIN_END */
199767f8919635c4928607450d9e0abb932109ceToomas Soome } l_array;
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct zap_leaf_free {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t lf_type; /* always ZAP_CHUNK_FREE */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t lf_pad[ZAP_LEAF_ARRAY_BYTES];
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t lf_next; /* next in free list, or CHAIN_END */
199767f8919635c4928607450d9e0abb932109ceToomas Soome } l_free;
199767f8919635c4928607450d9e0abb932109ceToomas Soome} zap_leaf_chunk_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct zap_leaf {
199767f8919635c4928607450d9e0abb932109ceToomas Soome int l_bs; /* block size shift */
199767f8919635c4928607450d9e0abb932109ceToomas Soome zap_leaf_phys_t *l_phys;
199767f8919635c4928607450d9e0abb932109ceToomas Soome} zap_leaf_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Define special zfs pflags
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZFS_XATTR 0x1 /* is an extended attribute */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZFS_INHERIT_ACE 0x2 /* ace has inheritable ACEs */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZFS_ACL_TRIVIAL 0x4 /* files ACL is trivial */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define MASTER_NODE_OBJ 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * special attributes for master node.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZFS_FSID "FSID"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZFS_UNLINKED_SET "DELETE_QUEUE"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZFS_ROOT_OBJ "ROOT"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPL_VERSION_OBJ "VERSION"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZFS_PROP_BLOCKPERPAGE "BLOCKPERPAGE"
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZFS_PROP_NOGROWBLOCKS "NOGROWBLOCKS"
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZFS_FLAG_BLOCKPERPAGE 0x1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZFS_FLAG_NOGROWBLOCKS 0x2
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * ZPL version - rev'd whenever an incompatible on-disk format change
199767f8919635c4928607450d9e0abb932109ceToomas Soome * occurs. Independent of SPA/DMU/ZAP versioning.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZPL_VERSION 1ULL
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * The directory entry has the type (currently unused on Solaris) in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * top 4 bits, and the object number in the low 48 bits. The "middle"
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 12 bits are unused.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZFS_DIRENT_TYPE(de) BF64_GET(de, 60, 4)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZFS_DIRENT_OBJ(de) BF64_GET(de, 0, 48)
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ZFS_DIRENT_MAKE(type, obj) (((uint64_t)type << 60) | obj)
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct ace {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uid_t a_who; /* uid or gid */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t a_access_mask; /* read,write,... */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t a_flags; /* see below */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t a_type; /* allow or deny */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} ace_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define ACE_SLOT_CNT 6
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct zfs_znode_acl {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t z_acl_extern_obj; /* ext acl pieces */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t z_acl_count; /* Number of ACEs */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t z_acl_version; /* acl version */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t z_acl_pad; /* pad */
199767f8919635c4928607450d9e0abb932109ceToomas Soome ace_t z_ace_data[ACE_SLOT_CNT]; /* 6 standard ACEs */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} zfs_znode_acl_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This is the persistent portion of the znode. It is stored
199767f8919635c4928607450d9e0abb932109ceToomas Soome * in the "bonus buffer" of the file. Short symbolic links
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are also stored in the bonus buffer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct znode_phys {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zp_atime[2]; /* 0 - last file access time */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zp_mtime[2]; /* 16 - last file modification time */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zp_ctime[2]; /* 32 - last file change time */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zp_crtime[2]; /* 48 - creation time */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zp_gen; /* 64 - generation (txg of creation) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zp_mode; /* 72 - file mode bits */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zp_size; /* 80 - size of file */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zp_parent; /* 88 - directory parent (`..') */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zp_links; /* 96 - number of links to file */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zp_xattr; /* 104 - DMU object for xattrs */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zp_rdev; /* 112 - dev_t for VBLK & VCHR files */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zp_flags; /* 120 - persistent flags */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zp_uid; /* 128 - file owner */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zp_gid; /* 136 - owning group */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t zp_pad[4]; /* 144 - future */
199767f8919635c4928607450d9e0abb932109ceToomas Soome zfs_znode_acl_t zp_acl; /* 176 - 263 ACL */
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Data may pad out any remaining bytes in the znode buffer, eg:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * |<---------------------- dnode_phys (512) ------------------------>|
199767f8919635c4928607450d9e0abb932109ceToomas Soome * |<-- dnode (192) --->|<----------- "bonus" buffer (320) ---------->|
199767f8919635c4928607450d9e0abb932109ceToomas Soome * |<---- znode (264) ---->|<---- data (56) ---->|
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * At present, we only use this space to store symbolic links.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} znode_phys_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * In-core vdev representation.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct vdev;
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef int vdev_phys_read_t(struct vdev *vdev, void *priv,
199767f8919635c4928607450d9e0abb932109ceToomas Soome off_t offset, void *buf, size_t bytes);
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef int vdev_read_t(struct vdev *vdev, const blkptr_t *bp,
199767f8919635c4928607450d9e0abb932109ceToomas Soome void *buf, off_t offset, size_t bytes);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef STAILQ_HEAD(vdev_list, vdev) vdev_list_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct vdev {
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_ENTRY(vdev) v_childlink; /* link in parent's child list */
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_ENTRY(vdev) v_alllink; /* link in global vdev list */
199767f8919635c4928607450d9e0abb932109ceToomas Soome vdev_list_t v_children; /* children of this vdev */
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *v_name; /* vdev name */
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *v_phys_path; /* vdev bootpath */
199767f8919635c4928607450d9e0abb932109ceToomas Soome const char *v_devid; /* vdev devid */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t v_guid; /* vdev guid */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int v_id; /* index in parent */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int v_ashift; /* offset to block shift */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int v_nparity; /* # parity for raidz */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct vdev *v_top; /* parent vdev */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int v_nchildren; /* # children */
199767f8919635c4928607450d9e0abb932109ceToomas Soome vdev_state_t v_state; /* current state */
199767f8919635c4928607450d9e0abb932109ceToomas Soome vdev_phys_read_t *v_phys_read; /* read from raw leaf vdev */
199767f8919635c4928607450d9e0abb932109ceToomas Soome vdev_read_t *v_read; /* read from vdev */
199767f8919635c4928607450d9e0abb932109ceToomas Soome void *v_read_priv; /* private data for read function */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} vdev_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * In-core pool representation.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef STAILQ_HEAD(spa_list, spa) spa_list_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soometypedef struct spa {
199767f8919635c4928607450d9e0abb932109ceToomas Soome STAILQ_ENTRY(spa) spa_link; /* link in global pool list */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char *spa_name; /* pool name */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t spa_guid; /* pool guid */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t spa_txg; /* most recent transaction */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct uberblock spa_uberblock; /* best uberblock so far */
199767f8919635c4928607450d9e0abb932109ceToomas Soome vdev_list_t spa_vdevs; /* list of all toplevel vdevs */
199767f8919635c4928607450d9e0abb932109ceToomas Soome objset_phys_t spa_mos; /* MOS for this pool */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int spa_inited; /* initialized */
199767f8919635c4928607450d9e0abb932109ceToomas Soome} spa_t;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestatic void decode_embedded_bp_compressed(const blkptr_t *, void *);