View | Details | Raw Unified | Return to bug 153173
Collapse All | Expand All

(-)/usr/src/sys/cddl/boot/zfs/README (+2 lines)
Lines 14-16 Link Here
14
The files fletcher.c, lzjb.c, lz4.c, sha256.c and blkptr.c are largely identical
14
The files fletcher.c, lzjb.c, lz4.c, sha256.c and blkptr.c are largely identical
15
to the ZFS base code (with write support removed) and could be shared but that
15
to the ZFS base code (with write support removed) and could be shared but that
16
might complicate future imports from Illumos.
16
might complicate future imports from Illumos.
17
18
    gzip.c/gzip.h		gzip decompression support
(-)/usr/src/sys/cddl/boot/zfs/gzip.c (+114 lines)
Line 0 Link Here
1
/*
2
 * CDDL HEADER START
3
 *
4
 * The contents of this file are subject to the terms of the
5
 * Common Development and Distribution License (the "License").
6
 * You may not use this file except in compliance with the License.
7
 *
8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9
 * or http://www.opensolaris.org/os/licensing.
10
 * See the License for the specific language governing permissions
11
 * and limitations under the License.
12
 *
13
 * When distributing Covered Code, include this CDDL HEADER in each
14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15
 * If applicable, add the following below this CDDL HEADER, with the
16
 * fields enclosed by brackets "[]" replaced with your own identifying
17
 * information: Portions Copyright [yyyy] [name of copyright owner]
18
 *
19
 * CDDL HEADER END
20
 */
21
22
/*
23
 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24
 * Use is subject to license terms.
25
 */
26
27
/*
28
 * Mikhail Zakharov <zmey20000@yahoo.com> 2022.01.21
29
 */
30
31
32
#include <sys/qat.h>
33
#include <contrib/zlib/zlib.h>
34
#include <contrib/zlib/zutil.h>
35
36
#include "gzip.h"
37
38
39
/*ARGSUSED*/
40
static void *
41
zfs_zcalloc(void *opaque, uint_t items, uint_t size)
42
{
43
        void *ptr;
44
45
        ptr = malloc((size_t)items * size);
46
        return ptr;
47
}
48
49
/*ARGSUSED*/
50
static void
51
zfs_zcfree(void *opaque, void *ptr)
52
{
53
        free(ptr);
54
}
55
56
/*
57
 * Uncompress the buffer 'src' into the buffer 'dst'.  The caller must store
58
 * the expected decompressed data size externally so it can be passed in.
59
 * The resulting decompressed size is then returned through dstlen.  This
60
 * function return Z_OK on success, or another error code on failure.
61
 */
62
int
63
z_uncompress(void *dst, size_t *dstlen, const void *src, size_t srclen)
64
{
65
        z_stream zs;
66
        int err;
67
68
        bzero(&zs, sizeof (zs));
69
        zs.next_in = (unsigned char *)src;
70
        zs.avail_in = srclen;
71
        zs.next_out = dst;
72
        zs.avail_out = *dstlen;
73
        zs.zalloc = zfs_zcalloc;
74
        zs.zfree = zfs_zcfree;
75
76
        /*
77
         * Call inflateInit2() specifying a window size of DEF_WBITS
78
         * with the 6th bit set to indicate that the compression format
79
         * type (zlib or gzip) should be automatically detected.
80
         */
81
        if ((err = inflateInit2(&zs, DEF_WBITS | 0x20)) != Z_OK)
82
                return (err);
83
84
        if ((err = inflate(&zs, Z_FINISH)) != Z_STREAM_END) {
85
                (void) inflateEnd(&zs);
86
                return (err == Z_OK ? Z_BUF_ERROR : err);
87
        }
88
89
        *dstlen = zs.total_out;
90
        return (inflateEnd(&zs));
91
}
92
93
/*ARGSUSED*/
94
int
95
gzip_decompress(void *s_start, void *d_start, size_t s_len, size_t d_len, int n)
96
{
97
	size_t dstlen = d_len;
98
99
	ASSERT(d_len >= s_len);
100
101
	/* check if hardware accelerator can be used */
102
	if (qat_dc_use_accel(d_len)) {
103
		if (qat_compress(QAT_DECOMPRESS, s_start, s_len,
104
		    d_start, d_len, &dstlen) == CPA_STATUS_SUCCESS)
105
			return (0);
106
		/* if hardware de-compress fail, do it again with software */
107
	}
108
109
	if (z_uncompress(d_start, &dstlen, s_start, s_len) != Z_OK)
110
		return (-1);
111
112
	return (0);
113
}
114
(-)/usr/src/sys/cddl/boot/zfs/gzip.h (+25 lines)
Line 0 Link Here
1
/*
2
 * gzip decompression functions, as well as this header file, are based 
3
 * on the code from sys/cddl/contrib/opensolaris/uts/common/zmod and 
4
 * sys/contrib/openzfs/module/zfs/gzip.c
5
 */
6
7
#define Z_OK            0
8
#define Z_STREAM_END    1
9
#define Z_NEED_DICT     2
10
#define Z_ERRNO         (-1)
11
#define Z_STREAM_ERROR  (-2)
12
#define Z_DATA_ERROR    (-3)
13
#define Z_MEM_ERROR     (-4)
14
#define Z_BUF_ERROR     (-5)
15
#define Z_VERSION_ERROR (-6)
16
17
#define Z_NO_COMPRESSION        0
18
#define Z_BEST_SPEED            1
19
#define Z_BEST_COMPRESSION      9
20
#define Z_DEFAULT_COMPRESSION   (-1)
21
22
extern int z_uncompress(void *, size_t *, const void *, size_t);
23
extern int gzip_decompress(void *src, void *dst, size_t s_len, size_t d_len,
24
    int level);
25
(-)/usr/src/sys/cddl/boot/zfs/zfssubr.c (-9 / +10 lines)
Lines 163-168 Link Here
163
163
164
#include "lzjb.c"
164
#include "lzjb.c"
165
#include "zle.c"
165
#include "zle.c"
166
#include "gzip.c"
166
167
167
/*
168
/*
168
 * Compression vectors.
169
 * Compression vectors.
Lines 173-187 Link Here
173
	{NULL,			NULL,			0,	"uncompressed"},
174
	{NULL,			NULL,			0,	"uncompressed"},
174
	{NULL,			lzjb_decompress,	0,	"lzjb"},
175
	{NULL,			lzjb_decompress,	0,	"lzjb"},
175
	{NULL,			NULL,			0,	"empty"},
176
	{NULL,			NULL,			0,	"empty"},
176
	{NULL,			NULL,			1,	"gzip-1"},
177
	{NULL,			gzip_decompress,	1,	"gzip-1"},
177
	{NULL,			NULL,			2,	"gzip-2"},
178
	{NULL,			gzip_decompress,	2,	"gzip-2"},
178
	{NULL,			NULL,			3,	"gzip-3"},
179
	{NULL,			gzip_decompress,	3,	"gzip-3"},
179
	{NULL,			NULL,			4,	"gzip-4"},
180
	{NULL,			gzip_decompress,	4,	"gzip-4"},
180
	{NULL,			NULL,			5,	"gzip-5"},
181
	{NULL,			gzip_decompress,	5,	"gzip-5"},
181
	{NULL,			NULL,			6,	"gzip-6"},
182
	{NULL,			gzip_decompress,	6,	"gzip-6"},
182
	{NULL,			NULL,			7,	"gzip-7"},
183
	{NULL,			gzip_decompress,	7,	"gzip-7"},
183
	{NULL,			NULL,			8,	"gzip-8"},
184
	{NULL,			gzip_decompress,	8,	"gzip-8"},
184
	{NULL,			NULL,			9,	"gzip-9"},
185
	{NULL,			gzip_decompress,	9,	"gzip-9"},
185
	{NULL,			zle_decompress,		64,	"zle"},
186
	{NULL,			zle_decompress,		64,	"zle"},
186
	{NULL,			lz4_decompress,		0,	"lz4"},
187
	{NULL,			lz4_decompress,		0,	"lz4"},
187
#ifdef HAS_ZSTD_ZFS
188
#ifdef HAS_ZSTD_ZFS

Return to bug 153173