1139776Simp/* 21541Srgrimes * CDDL HEADER START 31541Srgrimes * 41541Srgrimes * This file and its contents are supplied under the terms of the 51541Srgrimes * Common Development and Distribution License ("CDDL"), version 1.0. 61541Srgrimes * You may only use this file in accordance with the terms of version 71541Srgrimes * 1.0 of the CDDL. 81541Srgrimes * 91541Srgrimes * A full copy of the text of the CDDL should have accompanied this 101541Srgrimes * source. A copy of the CDDL is also available via the Internet at 111541Srgrimes * http://www.illumos.org/license/CDDL. 121541Srgrimes * 131541Srgrimes * CDDL HEADER END 141541Srgrimes */ 151541Srgrimes 161541Srgrimes/* 171541Srgrimes * Copyright (c) 2013 by Delphix. All rights reserved. 181541Srgrimes */ 191541Srgrimes 201541Srgrimes/* 211541Srgrimes * Embedded-data Block Pointers 221541Srgrimes * 231541Srgrimes * Normally, block pointers point (via their DVAs) to a block which holds data. 241541Srgrimes * If the data that we need to store is very small, this is an inefficient 251541Srgrimes * use of space, because a block must be at minimum 1 sector (typically 512 261541Srgrimes * bytes or 4KB). Additionally, reading these small blocks tends to generate 271541Srgrimes * more random reads. 281541Srgrimes * 291541Srgrimes * Embedded-data Block Pointers allow small pieces of data (the "payload", 301541Srgrimes * up to 112 bytes) to be stored in the block pointer itself, instead of 311541Srgrimes * being pointed to. The "Pointer" part of this name is a bit of a 3222521Sdyson * misnomer, as nothing is pointed to. 331541Srgrimes * 3422521Sdyson * BP_EMBEDDED_TYPE_DATA block pointers allow highly-compressible data to 3522521Sdyson * be embedded in the block pointer. The logic for this is handled in 3622521Sdyson * the SPA, by the zio pipeline. Therefore most code outside the zio 3722521Sdyson * pipeline doesn't need special-cases to handle these block pointers. 3822521Sdyson * 3950477Speter * See spa.h for details on the exact layout of embedded block pointers. 401541Srgrimes */ 411541Srgrimes 421541Srgrimes/* 431541Srgrimes * buf must be at least BPE_GET_PSIZE(bp) bytes long (which will never be 441541Srgrimes * more than BPE_PAYLOAD_SIZE bytes). 4577130Sru */ 461541Srgrimesvoid 4796755Strhodesdecode_embedded_bp_compressed(const blkptr_t *bp, void *buf) 481541Srgrimes{ 4996755Strhodes int psize; 501541Srgrimes uint8_t *buf8 = buf; 5135256Sdes uint64_t w = 0; 521541Srgrimes const uint64_t *bp64 = (const uint64_t *)bp; 531541Srgrimes 541541Srgrimes ASSERT(BP_IS_EMBEDDED(bp)); 551541Srgrimes 5696755Strhodes psize = BPE_GET_PSIZE(bp); 571541Srgrimes 581541Srgrimes /* 5996755Strhodes * Decode the words of the block pointer into the byte array. 601541Srgrimes * Low bits of first word are the first byte (little endian). 611541Srgrimes */ 621541Srgrimes for (int i = 0; i < psize; i++) { 631541Srgrimes if (i % sizeof (w) == 0) { 641541Srgrimes /* beginning of a word */ 651541Srgrimes ASSERT3P(bp64, <, bp + 1); 661541Srgrimes w = *bp64; 671541Srgrimes bp64++; 6877130Sru if (!BPE_IS_PAYLOADWORD(bp, bp64)) 6977130Sru bp64++; 701541Srgrimes } 711541Srgrimes buf8[i] = BF64_GET(w, (i % sizeof (w)) * NBBY, NBBY); 721541Srgrimes } 731541Srgrimes} 741541Srgrimes