MCPcopy Create free account
hub / github.com/F-Stack/f-stack / zio_compress_data

Function zio_compress_data

freebsd/contrib/openzfs/module/zfs/zio_compress.c:125–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

123}
124
125size_t
126zio_compress_data(enum zio_compress c, abd_t *src, void *dst, size_t s_len,
127 uint8_t level)
128{
129 size_t c_len, d_len;
130 uint8_t complevel;
131 zio_compress_info_t *ci = &zio_compress_table[c];
132
133 ASSERT((uint_t)c < ZIO_COMPRESS_FUNCTIONS);
134 ASSERT((uint_t)c == ZIO_COMPRESS_EMPTY || ci->ci_compress != NULL);
135
136 /*
137 * If the data is all zeroes, we don't even need to allocate
138 * a block for it. We indicate this by returning zero size.
139 */
140 if (abd_iterate_func(src, 0, s_len, zio_compress_zeroed_cb, NULL) == 0)
141 return (0);
142
143 if (c == ZIO_COMPRESS_EMPTY)
144 return (s_len);
145
146 /* Compress at least 12.5% */
147 d_len = s_len - (s_len >> 3);
148
149 complevel = ci->ci_level;
150
151 if (c == ZIO_COMPRESS_ZSTD) {
152 /* If we don't know the level, we can't compress it */
153 if (level == ZIO_COMPLEVEL_INHERIT)
154 return (s_len);
155
156 if (level == ZIO_COMPLEVEL_DEFAULT)
157 complevel = ZIO_ZSTD_LEVEL_DEFAULT;
158 else
159 complevel = level;
160
161 ASSERT3U(complevel, !=, ZIO_COMPLEVEL_INHERIT);
162 }
163
164 /* No compression algorithms can read from ABDs directly */
165 void *tmp = abd_borrow_buf_copy(src, s_len);
166 c_len = ci->ci_compress(tmp, dst, s_len, d_len, complevel);
167 abd_return_buf(src, tmp, s_len);
168
169 if (c_len > d_len)
170 return (s_len);
171
172 ASSERT3U(c_len, <=, d_len);
173 return (c_len);
174}
175
176int
177zio_decompress_data_buf(enum zio_compress c, void *src, void *dst,

Callers 4

arc_hdr_authenticateFunction · 0.85
l2arc_apply_transformsFunction · 0.85
l2arc_log_blk_commitFunction · 0.85
zio_write_compressFunction · 0.85

Calls 3

abd_iterate_funcFunction · 0.85
abd_borrow_buf_copyFunction · 0.85
abd_return_bufFunction · 0.85

Tested by

no test coverage detected