199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * CDDL HEADER START
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * This file and its contents are supplied under the terms of the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Common Development and Distribution License ("CDDL"), version 1.0.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * You may only use this file in accordance with the terms of version
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1.0 of the CDDL.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * A full copy of the text of the CDDL should have accompanied this
199767f8919635c4928607450d9e0abb932109ceToomas Soome * source. A copy of the CDDL is also available via the Internet at
199767f8919635c4928607450d9e0abb932109ceToomas Soome * http://www.illumos.org/license/CDDL.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * CDDL HEADER END
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2013 by Delphix. All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Embedded-data Block Pointers
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Normally, block pointers point (via their DVAs) to a block which holds data.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * If the data that we need to store is very small, this is an inefficient
199767f8919635c4928607450d9e0abb932109ceToomas Soome * use of space, because a block must be at minimum 1 sector (typically 512
199767f8919635c4928607450d9e0abb932109ceToomas Soome * bytes or 4KB). Additionally, reading these small blocks tends to generate
199767f8919635c4928607450d9e0abb932109ceToomas Soome * more random reads.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Embedded-data Block Pointers allow small pieces of data (the "payload",
199767f8919635c4928607450d9e0abb932109ceToomas Soome * up to 112 bytes) to be stored in the block pointer itself, instead of
199767f8919635c4928607450d9e0abb932109ceToomas Soome * being pointed to. The "Pointer" part of this name is a bit of a
199767f8919635c4928607450d9e0abb932109ceToomas Soome * misnomer, as nothing is pointed to.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * BP_EMBEDDED_TYPE_DATA block pointers allow highly-compressible data to
199767f8919635c4928607450d9e0abb932109ceToomas Soome * be embedded in the block pointer. The logic for this is handled in
199767f8919635c4928607450d9e0abb932109ceToomas Soome * the SPA, by the zio pipeline. Therefore most code outside the zio
199767f8919635c4928607450d9e0abb932109ceToomas Soome * pipeline doesn't need special-cases to handle these block pointers.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * See spa.h for details on the exact layout of embedded block pointers.
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * buf must be at least BPE_GET_PSIZE(bp) bytes long (which will never be
199767f8919635c4928607450d9e0abb932109ceToomas Soome * more than BPE_PAYLOAD_SIZE bytes).
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soomevoid
199767f8919635c4928607450d9e0abb932109ceToomas Soomedecode_embedded_bp_compressed(const blkptr_t *bp, void *buf)
199767f8919635c4928607450d9e0abb932109ceToomas Soome{
199767f8919635c4928607450d9e0abb932109ceToomas Soome int psize;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint8_t *buf8 = buf;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint64_t w = 0;
199767f8919635c4928607450d9e0abb932109ceToomas Soome const uint64_t *bp64 = (const uint64_t *)bp;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome ASSERT(BP_IS_EMBEDDED(bp));
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome psize = BPE_GET_PSIZE(bp);
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome /*
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Decode the words of the block pointer into the byte array.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Low bits of first word are the first byte (little endian).
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome for (int i = 0; i < psize; i++) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (i % sizeof (w) == 0) {
199767f8919635c4928607450d9e0abb932109ceToomas Soome /* beginning of a word */
199767f8919635c4928607450d9e0abb932109ceToomas Soome ASSERT3P(bp64, <, bp + 1);
199767f8919635c4928607450d9e0abb932109ceToomas Soome w = *bp64;
199767f8919635c4928607450d9e0abb932109ceToomas Soome bp64++;
199767f8919635c4928607450d9e0abb932109ceToomas Soome if (!BPE_IS_PAYLOADWORD(bp, bp64))
199767f8919635c4928607450d9e0abb932109ceToomas Soome bp64++;
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome buf8[i] = BF64_GET(w, (i % sizeof (w)) * NBBY, NBBY);
199767f8919635c4928607450d9e0abb932109ceToomas Soome }
199767f8919635c4928607450d9e0abb932109ceToomas Soome}