From 46364cb2f35545a7fc915df9593b719a94c43a83 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Wed, 9 Aug 2017 15:31:08 -0700 Subject: Add libtpool (thread pools) OpenZFS provides a library called tpool which implements thread pools for user space applications. Porting this library means the zpool utility no longer needs to borrow the kernel mutex and taskq interfaces from libzpool. This code was updated to use the tpool library which behaves in a very similar fashion. Porting libtpool was relatively straight forward and minimal modifications were needed. The core changes were: * Fully convert the library to use pthreads. * Updated signal handling. * lmalloc/lfree converted to calloc/free * Implemented portable pthread_attr_clone() function. Finally, update the build system such that libzpool.so is no longer linked in to zfs(8), zpool(8), etc. All that is required is libzfs to which the zcommon soures were added (which is the way it always should have been). Removing the libzpool dependency resulted in several build issues which needed to be resolved. * Moved zfeature support to module/zcommon/zfeature_common.c * Moved ratelimiting to to module/zfs/zfs_ratelimit.c * Moved get_system_hostid() to lib/libspl/gethostid.c * Removed use of cmn_err() in zcommon source * Removed dprintf_setup() call from zpool_main.c and zfs_main.c * Removed highbit() and lowbit() * Removed unnecessary library dependencies from Makefiles * Removed fletcher-4 kstat in user space * Added sha2 support explicitly to libzfs * Added highbit64() and lowbit64() to zpool_util.c Reviewed-by: Tony Hutter Signed-off-by: Brian Behlendorf Closes #6442 --- module/icp/algs/sha2/sha2.c | 19 +++++++------------ module/icp/os/modhash.c | 2 +- 2 files changed, 8 insertions(+), 13 deletions(-) (limited to 'module/icp') diff --git a/module/icp/algs/sha2/sha2.c b/module/icp/algs/sha2/sha2.c index dbe008190..c585993f1 100644 --- a/module/icp/algs/sha2/sha2.c +++ b/module/icp/algs/sha2/sha2.c @@ -52,7 +52,7 @@ static void Encode(uint8_t *, uint32_t *, size_t); static void Encode64(uint8_t *, uint64_t *, size_t); -#if defined(__amd64) +#if defined(__amd64) && defined(_KERNEL) #define SHA512Transform(ctx, in) SHA512TransformBlocks((ctx), (in), 1) #define SHA256Transform(ctx, in) SHA256TransformBlocks((ctx), (in), 1) @@ -62,7 +62,7 @@ void SHA256TransformBlocks(SHA2_CTX *ctx, const void *in, size_t num); #else static void SHA256Transform(SHA2_CTX *, const uint8_t *); static void SHA512Transform(SHA2_CTX *, const uint8_t *); -#endif /* __amd64 */ +#endif /* __amd64 && _KERNEL */ static uint8_t PADDING[128] = { 0x80, /* all zeros */ }; @@ -142,7 +142,7 @@ static uint8_t PADDING[128] = { 0x80, /* all zeros */ }; #endif /* _BIG_ENDIAN */ -#if !defined(__amd64) +#if !defined(__amd64) || !defined(_KERNEL) /* SHA256 Transform */ static void @@ -600,7 +600,7 @@ SHA512Transform(SHA2_CTX *ctx, const uint8_t *blk) ctx->state.s64[7] += h; } -#endif /* !__amd64 */ +#endif /* !__amd64 || !_KERNEL */ /* @@ -783,10 +783,6 @@ SHA2Update(SHA2_CTX *ctx, const void *inptr, size_t input_len) uint32_t i, buf_index, buf_len, buf_limit; const uint8_t *input = inptr; uint32_t algotype = ctx->algotype; -#if defined(__amd64) - uint32_t block_count; -#endif /* !__amd64 */ - /* check for noop */ if (input_len == 0) @@ -842,7 +838,7 @@ SHA2Update(SHA2_CTX *ctx, const void *inptr, size_t input_len) i = buf_len; } -#if !defined(__amd64) +#if !defined(__amd64) || !defined(_KERNEL) if (algotype <= SHA256_HMAC_GEN_MECH_INFO_TYPE) { for (; i + buf_limit - 1 < input_len; i += buf_limit) { SHA256Transform(ctx, &input[i]); @@ -854,6 +850,7 @@ SHA2Update(SHA2_CTX *ctx, const void *inptr, size_t input_len) } #else + uint32_t block_count; if (algotype <= SHA256_HMAC_GEN_MECH_INFO_TYPE) { block_count = (input_len - i) >> 6; if (block_count > 0) { @@ -869,7 +866,7 @@ SHA2Update(SHA2_CTX *ctx, const void *inptr, size_t input_len) i += block_count << 7; } } -#endif /* !__amd64 */ +#endif /* !__amd64 || !_KERNEL */ /* * general optimization: @@ -951,8 +948,6 @@ SHA2Final(void *digest, SHA2_CTX *ctx) bzero(ctx, sizeof (*ctx)); } - - #ifdef _KERNEL EXPORT_SYMBOL(SHA2Init); EXPORT_SYMBOL(SHA2Update); diff --git a/module/icp/os/modhash.c b/module/icp/os/modhash.c index 1ff782afc..497e84396 100644 --- a/module/icp/os/modhash.c +++ b/module/icp/os/modhash.c @@ -312,7 +312,7 @@ mod_hash_create_ptrhash(char *name, size_t nchains, * The high bits, which are also unused, will get taken out when * mod_hash takes hashkey % nchains. */ - rshift = highbit(key_elem_size); + rshift = highbit64(key_elem_size); return mod_hash_create_extended(name, nchains, mod_hash_null_keydtor, val_dtor, mod_hash_byptr, (void *)rshift, mod_hash_ptrkey_cmp, -- cgit v1.2.3