Print this page
%B
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/zfs/zio_compress.c
+++ new/usr/src/uts/common/fs/zfs/zio_compress.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 */
26 +/*
27 + * Copyright (c) 2013 by Saso Kiselkov. All rights reserved.
28 + */
26 29
27 30 #include <sys/zfs_context.h>
28 31 #include <sys/compress.h>
29 32 #include <sys/spa.h>
30 33 #include <sys/zio.h>
31 34 #include <sys/zio_compress.h>
32 35
33 36 /*
34 37 * Compression vectors.
35 38 */
36 39
37 40 zio_compress_info_t zio_compress_table[ZIO_COMPRESS_FUNCTIONS] = {
38 41 {NULL, NULL, 0, "inherit"},
39 42 {NULL, NULL, 0, "on"},
40 43 {NULL, NULL, 0, "uncompressed"},
41 44 {lzjb_compress, lzjb_decompress, 0, "lzjb"},
42 45 {NULL, NULL, 0, "empty"},
↓ open down ↓ |
7 lines elided |
↑ open up ↑ |
43 46 {gzip_compress, gzip_decompress, 1, "gzip-1"},
44 47 {gzip_compress, gzip_decompress, 2, "gzip-2"},
45 48 {gzip_compress, gzip_decompress, 3, "gzip-3"},
46 49 {gzip_compress, gzip_decompress, 4, "gzip-4"},
47 50 {gzip_compress, gzip_decompress, 5, "gzip-5"},
48 51 {gzip_compress, gzip_decompress, 6, "gzip-6"},
49 52 {gzip_compress, gzip_decompress, 7, "gzip-7"},
50 53 {gzip_compress, gzip_decompress, 8, "gzip-8"},
51 54 {gzip_compress, gzip_decompress, 9, "gzip-9"},
52 55 {zle_compress, zle_decompress, 64, "zle"},
56 + {lz4_compress, lz4_decompress, 0, "lz4"},
57 + {lz4_compress, lz4_decompress, 1, "lz4hc"},
53 58 };
54 59
55 60 enum zio_compress
56 61 zio_compress_select(enum zio_compress child, enum zio_compress parent)
57 62 {
58 63 ASSERT(child < ZIO_COMPRESS_FUNCTIONS);
59 64 ASSERT(parent < ZIO_COMPRESS_FUNCTIONS);
60 65 ASSERT(parent != ZIO_COMPRESS_INHERIT && parent != ZIO_COMPRESS_ON);
61 66
62 67 if (child == ZIO_COMPRESS_INHERIT)
63 68 return (parent);
64 69
65 70 if (child == ZIO_COMPRESS_ON)
66 71 return (ZIO_COMPRESS_ON_VALUE);
67 72
68 73 return (child);
69 74 }
70 75
71 76 size_t
72 77 zio_compress_data(enum zio_compress c, void *src, void *dst, size_t s_len)
73 78 {
74 79 uint64_t *word, *word_end;
75 80 size_t c_len, d_len, r_len;
76 81 zio_compress_info_t *ci = &zio_compress_table[c];
77 82
78 83 ASSERT((uint_t)c < ZIO_COMPRESS_FUNCTIONS);
79 84 ASSERT((uint_t)c == ZIO_COMPRESS_EMPTY || ci->ci_compress != NULL);
80 85
81 86 /*
82 87 * If the data is all zeroes, we don't even need to allocate
83 88 * a block for it. We indicate this by returning zero size.
84 89 */
85 90 word_end = (uint64_t *)((char *)src + s_len);
86 91 for (word = src; word < word_end; word++)
87 92 if (*word != 0)
88 93 break;
89 94
90 95 if (word == word_end)
91 96 return (0);
92 97
93 98 if (c == ZIO_COMPRESS_EMPTY)
94 99 return (s_len);
95 100
96 101 /* Compress at least 12.5% */
97 102 d_len = P2ALIGN(s_len - (s_len >> 3), (size_t)SPA_MINBLOCKSIZE);
98 103 if (d_len == 0)
99 104 return (s_len);
100 105
101 106 c_len = ci->ci_compress(src, dst, s_len, d_len, ci->ci_level);
102 107
103 108 if (c_len > d_len)
104 109 return (s_len);
105 110
106 111 /*
107 112 * Cool. We compressed at least as much as we were hoping to.
108 113 * For both security and repeatability, pad out the last sector.
109 114 */
110 115 r_len = P2ROUNDUP(c_len, (size_t)SPA_MINBLOCKSIZE);
111 116 if (r_len > c_len) {
112 117 bzero((char *)dst + c_len, r_len - c_len);
113 118 c_len = r_len;
114 119 }
115 120
116 121 ASSERT3U(c_len, <=, d_len);
117 122 ASSERT(P2PHASE(c_len, (size_t)SPA_MINBLOCKSIZE) == 0);
118 123
119 124 return (c_len);
120 125 }
121 126
122 127 int
123 128 zio_decompress_data(enum zio_compress c, void *src, void *dst,
124 129 size_t s_len, size_t d_len)
125 130 {
126 131 zio_compress_info_t *ci = &zio_compress_table[c];
127 132
128 133 if ((uint_t)c >= ZIO_COMPRESS_FUNCTIONS || ci->ci_decompress == NULL)
129 134 return (EINVAL);
130 135
131 136 return (ci->ci_decompress(src, dst, s_len, d_len, ci->ci_level));
132 137 }
↓ open down ↓ |
70 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX