1*29441ba3SXin LI /*
2*29441ba3SXin LI * CDDL HEADER START
3*29441ba3SXin LI *
4*29441ba3SXin LI * This file and its contents are supplied under the terms of the
5*29441ba3SXin LI * Common Development and Distribution License ("CDDL"), version 1.0.
6*29441ba3SXin LI * You may only use this file in accordance with the terms of version
7*29441ba3SXin LI * 1.0 of the CDDL.
8*29441ba3SXin LI *
9*29441ba3SXin LI * A full copy of the text of the CDDL should have accompanied this
10*29441ba3SXin LI * source. A copy of the CDDL is also available via the Internet at
11*29441ba3SXin LI * http://www.illumos.org/license/CDDL.
12*29441ba3SXin LI *
13*29441ba3SXin LI * CDDL HEADER END
14*29441ba3SXin LI */
15*29441ba3SXin LI
16*29441ba3SXin LI /*
17*29441ba3SXin LI * Copyright (c) 2013 by Delphix. All rights reserved.
18*29441ba3SXin LI */
19*29441ba3SXin LI
20*29441ba3SXin LI /*
21*29441ba3SXin LI * Embedded-data Block Pointers
22*29441ba3SXin LI *
23*29441ba3SXin LI * Normally, block pointers point (via their DVAs) to a block which holds data.
24*29441ba3SXin LI * If the data that we need to store is very small, this is an inefficient
25*29441ba3SXin LI * use of space, because a block must be at minimum 1 sector (typically 512
26*29441ba3SXin LI * bytes or 4KB). Additionally, reading these small blocks tends to generate
27*29441ba3SXin LI * more random reads.
28*29441ba3SXin LI *
29*29441ba3SXin LI * Embedded-data Block Pointers allow small pieces of data (the "payload",
30*29441ba3SXin LI * up to 112 bytes) to be stored in the block pointer itself, instead of
31*29441ba3SXin LI * being pointed to. The "Pointer" part of this name is a bit of a
32*29441ba3SXin LI * misnomer, as nothing is pointed to.
33*29441ba3SXin LI *
34*29441ba3SXin LI * BP_EMBEDDED_TYPE_DATA block pointers allow highly-compressible data to
35*29441ba3SXin LI * be embedded in the block pointer. The logic for this is handled in
36*29441ba3SXin LI * the SPA, by the zio pipeline. Therefore most code outside the zio
37*29441ba3SXin LI * pipeline doesn't need special-cases to handle these block pointers.
38*29441ba3SXin LI *
39*29441ba3SXin LI * See spa.h for details on the exact layout of embedded block pointers.
40*29441ba3SXin LI */
41*29441ba3SXin LI
42*29441ba3SXin LI /*
43*29441ba3SXin LI * buf must be at least BPE_GET_PSIZE(bp) bytes long (which will never be
44*29441ba3SXin LI * more than BPE_PAYLOAD_SIZE bytes).
45*29441ba3SXin LI */
46*29441ba3SXin LI void
decode_embedded_bp_compressed(const blkptr_t * bp,void * buf)47*29441ba3SXin LI decode_embedded_bp_compressed(const blkptr_t *bp, void *buf)
48*29441ba3SXin LI {
49*29441ba3SXin LI int psize;
50*29441ba3SXin LI uint8_t *buf8 = buf;
51*29441ba3SXin LI uint64_t w = 0;
52*29441ba3SXin LI const uint64_t *bp64 = (const uint64_t *)bp;
53*29441ba3SXin LI
54*29441ba3SXin LI ASSERT(BP_IS_EMBEDDED(bp));
55*29441ba3SXin LI
56*29441ba3SXin LI psize = BPE_GET_PSIZE(bp);
57*29441ba3SXin LI
58*29441ba3SXin LI /*
59*29441ba3SXin LI * Decode the words of the block pointer into the byte array.
60*29441ba3SXin LI * Low bits of first word are the first byte (little endian).
61*29441ba3SXin LI */
62*29441ba3SXin LI for (int i = 0; i < psize; i++) {
63*29441ba3SXin LI if (i % sizeof (w) == 0) {
64*29441ba3SXin LI /* beginning of a word */
65*29441ba3SXin LI ASSERT3P(bp64, <, bp + 1);
66*29441ba3SXin LI w = *bp64;
67*29441ba3SXin LI bp64++;
68*29441ba3SXin LI if (!BPE_IS_PAYLOADWORD(bp, bp64))
69*29441ba3SXin LI bp64++;
70*29441ba3SXin LI }
71*29441ba3SXin LI buf8[i] = BF64_GET(w, (i % sizeof (w)) * NBBY, NBBY);
72*29441ba3SXin LI }
73*29441ba3SXin LI }
74