| 2159 | } |
| 2160 | |
| 2161 | static void |
| 2162 | snprintf_zstd_header(spa_t *spa, char *blkbuf, size_t buflen, |
| 2163 | const blkptr_t *bp) |
| 2164 | { |
| 2165 | abd_t *pabd; |
| 2166 | void *buf; |
| 2167 | zio_t *zio; |
| 2168 | zfs_zstdhdr_t zstd_hdr; |
| 2169 | int error; |
| 2170 | |
| 2171 | if (BP_GET_COMPRESS(bp) != ZIO_COMPRESS_ZSTD) |
| 2172 | return; |
| 2173 | |
| 2174 | if (BP_IS_HOLE(bp)) |
| 2175 | return; |
| 2176 | |
| 2177 | if (BP_IS_EMBEDDED(bp)) { |
| 2178 | buf = malloc(SPA_MAXBLOCKSIZE); |
| 2179 | if (buf == NULL) { |
| 2180 | (void) fprintf(stderr, "out of memory\n"); |
| 2181 | exit(1); |
| 2182 | } |
| 2183 | decode_embedded_bp_compressed(bp, buf); |
| 2184 | memcpy(&zstd_hdr, buf, sizeof (zstd_hdr)); |
| 2185 | free(buf); |
| 2186 | zstd_hdr.c_len = BE_32(zstd_hdr.c_len); |
| 2187 | zstd_hdr.raw_version_level = BE_32(zstd_hdr.raw_version_level); |
| 2188 | (void) snprintf(blkbuf + strlen(blkbuf), |
| 2189 | buflen - strlen(blkbuf), |
| 2190 | " ZSTD:size=%u:version=%u:level=%u:EMBEDDED", |
| 2191 | zstd_hdr.c_len, zstd_hdr.version, zstd_hdr.level); |
| 2192 | return; |
| 2193 | } |
| 2194 | |
| 2195 | pabd = abd_alloc_for_io(SPA_MAXBLOCKSIZE, B_FALSE); |
| 2196 | zio = zio_root(spa, NULL, NULL, 0); |
| 2197 | |
| 2198 | /* Decrypt but don't decompress so we can read the compression header */ |
| 2199 | zio_nowait(zio_read(zio, spa, bp, pabd, BP_GET_PSIZE(bp), NULL, NULL, |
| 2200 | ZIO_PRIORITY_SYNC_READ, ZIO_FLAG_CANFAIL | ZIO_FLAG_RAW_COMPRESS, |
| 2201 | NULL)); |
| 2202 | error = zio_wait(zio); |
| 2203 | if (error) { |
| 2204 | (void) fprintf(stderr, "read failed: %d\n", error); |
| 2205 | return; |
| 2206 | } |
| 2207 | buf = abd_borrow_buf_copy(pabd, BP_GET_LSIZE(bp)); |
| 2208 | memcpy(&zstd_hdr, buf, sizeof (zstd_hdr)); |
| 2209 | zstd_hdr.c_len = BE_32(zstd_hdr.c_len); |
| 2210 | zstd_hdr.raw_version_level = BE_32(zstd_hdr.raw_version_level); |
| 2211 | |
| 2212 | (void) snprintf(blkbuf + strlen(blkbuf), |
| 2213 | buflen - strlen(blkbuf), |
| 2214 | " ZSTD:size=%u:version=%u:level=%u:NORMAL", |
| 2215 | zstd_hdr.c_len, zstd_hdr.version, zstd_hdr.level); |
| 2216 | |
| 2217 | abd_return_buf_copy(pabd, buf, BP_GET_LSIZE(bp)); |
| 2218 | } |
no test coverage detected