mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
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 <hutter2@llnl.gov> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #6442
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -7,16 +7,17 @@ EXTRA_CFLAGS = $(ZFS_MODULE_CFLAGS) @KERNELCPPFLAGS@
|
||||
|
||||
obj-$(CONFIG_ZFS) := $(MODULE).o
|
||||
|
||||
$(MODULE)-objs += zfs_deleg.o
|
||||
$(MODULE)-objs += zfs_prop.o
|
||||
$(MODULE)-objs += zprop_common.o
|
||||
$(MODULE)-objs += zfs_namecheck.o
|
||||
$(MODULE)-objs += zfeature_common.o
|
||||
$(MODULE)-objs += zfs_comutil.o
|
||||
$(MODULE)-objs += zfs_deleg.o
|
||||
$(MODULE)-objs += zfs_fletcher.o
|
||||
$(MODULE)-objs += zfs_uio.o
|
||||
$(MODULE)-objs += zpool_prop.o
|
||||
$(MODULE)-objs += zfs_fletcher_superscalar.o
|
||||
$(MODULE)-objs += zfs_fletcher_superscalar4.o
|
||||
$(MODULE)-objs += zfs_namecheck.o
|
||||
$(MODULE)-objs += zfs_prop.o
|
||||
$(MODULE)-objs += zfs_uio.o
|
||||
$(MODULE)-objs += zpool_prop.o
|
||||
$(MODULE)-objs += zprop_common.o
|
||||
|
||||
$(MODULE)-$(CONFIG_X86) += zfs_fletcher_intel.o
|
||||
$(MODULE)-$(CONFIG_X86) += zfs_fletcher_sse.o
|
||||
|
||||
@@ -319,3 +319,12 @@ zpool_feature_init(void)
|
||||
userobj_accounting_deps);
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(_KERNEL) && defined(HAVE_SPL)
|
||||
EXPORT_SYMBOL(zfeature_lookup_name);
|
||||
EXPORT_SYMBOL(zfeature_is_supported);
|
||||
EXPORT_SYMBOL(zfeature_is_valid_guid);
|
||||
EXPORT_SYMBOL(zfeature_depends_on);
|
||||
EXPORT_SYMBOL(zpool_feature_init);
|
||||
EXPORT_SYMBOL(spa_feature_table);
|
||||
#endif
|
||||
@@ -207,85 +207,10 @@ const char *zfs_history_event_names[ZFS_NUM_LEGACY_HISTORY_EVENTS] = {
|
||||
"pool split",
|
||||
};
|
||||
|
||||
/*
|
||||
* Initialize rate limit struct
|
||||
*
|
||||
* rl: zfs_ratelimit_t struct
|
||||
* burst: Number to allow in an interval before rate limiting
|
||||
* interval: Interval time in seconds
|
||||
*/
|
||||
void
|
||||
zfs_ratelimit_init(zfs_ratelimit_t *rl, unsigned int burst,
|
||||
unsigned int interval)
|
||||
{
|
||||
rl->count = 0;
|
||||
rl->start = 0;
|
||||
rl->interval = interval;
|
||||
rl->burst = burst;
|
||||
mutex_init(&rl->lock, NULL, MUTEX_DEFAULT, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Finalize rate limit struct
|
||||
*
|
||||
* rl: zfs_ratelimit_t struct
|
||||
*/
|
||||
void
|
||||
zfs_ratelimit_fini(zfs_ratelimit_t *rl)
|
||||
{
|
||||
mutex_destroy(&rl->lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Re-implementation of the kernel's __ratelimit() function
|
||||
*
|
||||
* We had to write our own rate limiter because the kernel's __ratelimit()
|
||||
* function annoyingly prints out how many times it rate limited to the kernel
|
||||
* logs (and there's no way to turn it off):
|
||||
*
|
||||
* __ratelimit: 59 callbacks suppressed
|
||||
*
|
||||
* If the kernel ever allows us to disable these prints, we should go back to
|
||||
* using __ratelimit() instead.
|
||||
*
|
||||
* Return values are the same as __ratelimit():
|
||||
*
|
||||
* 0: If we're rate limiting
|
||||
* 1: If we're not rate limiting.
|
||||
*/
|
||||
int
|
||||
zfs_ratelimit(zfs_ratelimit_t *rl)
|
||||
{
|
||||
hrtime_t now;
|
||||
hrtime_t elapsed;
|
||||
int rc = 1;
|
||||
|
||||
mutex_enter(&rl->lock);
|
||||
|
||||
now = gethrtime();
|
||||
elapsed = now - rl->start;
|
||||
|
||||
rl->count++;
|
||||
if (NSEC2SEC(elapsed) >= rl->interval) {
|
||||
rl->start = now;
|
||||
rl->count = 0;
|
||||
} else {
|
||||
if (rl->count >= rl->burst) {
|
||||
rc = 0; /* We're ratelimiting */
|
||||
}
|
||||
}
|
||||
mutex_exit(&rl->lock);
|
||||
|
||||
return (rc);
|
||||
}
|
||||
|
||||
#if defined(_KERNEL) && defined(HAVE_SPL)
|
||||
EXPORT_SYMBOL(zfs_allocatable_devs);
|
||||
EXPORT_SYMBOL(zpool_get_rewind_policy);
|
||||
EXPORT_SYMBOL(zfs_zpl_version_map);
|
||||
EXPORT_SYMBOL(zfs_spa_version_map);
|
||||
EXPORT_SYMBOL(zfs_history_event_names);
|
||||
EXPORT_SYMBOL(zfs_ratelimit_init);
|
||||
EXPORT_SYMBOL(zfs_ratelimit_fini);
|
||||
EXPORT_SYMBOL(zfs_ratelimit);
|
||||
#endif
|
||||
|
||||
@@ -233,7 +233,7 @@ zfs_deleg_whokey(char *attr, zfs_deleg_who_type_t type,
|
||||
ZFS_DELEG_FIELD_SEP_CHR);
|
||||
break;
|
||||
default:
|
||||
cmn_err(CE_PANIC, "bad zfs_deleg_who_type_t %d", type);
|
||||
ASSERT(!"bad zfs_deleg_who_type_t");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -212,7 +212,9 @@ static struct fletcher_4_impl_selector {
|
||||
{ "scalar", IMPL_SCALAR }
|
||||
};
|
||||
|
||||
#if defined(_KERNEL)
|
||||
static kstat_t *fletcher_4_kstat;
|
||||
#endif
|
||||
|
||||
static struct fletcher_4_kstat {
|
||||
uint64_t native;
|
||||
@@ -589,7 +591,7 @@ fletcher_4_incremental_byteswap(void *buf, size_t size, void *data)
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
||||
#if defined(_KERNEL)
|
||||
/* Fletcher 4 kstats */
|
||||
|
||||
static int
|
||||
@@ -642,6 +644,7 @@ fletcher_4_kstat_addr(kstat_t *ksp, loff_t n)
|
||||
|
||||
return (ksp->ks_private);
|
||||
}
|
||||
#endif
|
||||
|
||||
#define FLETCHER_4_FASTEST_FN_COPY(type, src) \
|
||||
{ \
|
||||
@@ -753,6 +756,7 @@ fletcher_4_init(void)
|
||||
|
||||
vmem_free(databuf, data_size);
|
||||
|
||||
#if defined(_KERNEL)
|
||||
/* install kstats for all implementations */
|
||||
fletcher_4_kstat = kstat_create("zfs", 0, "fletcher_4_bench", "misc",
|
||||
KSTAT_TYPE_RAW, 0, KSTAT_FLAG_VIRTUAL);
|
||||
@@ -765,6 +769,7 @@ fletcher_4_init(void)
|
||||
fletcher_4_kstat_addr);
|
||||
kstat_install(fletcher_4_kstat);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Finish initialization */
|
||||
fletcher_4_initialized = B_TRUE;
|
||||
@@ -773,10 +778,12 @@ fletcher_4_init(void)
|
||||
void
|
||||
fletcher_4_fini(void)
|
||||
{
|
||||
#if defined(_KERNEL)
|
||||
if (fletcher_4_kstat != NULL) {
|
||||
kstat_delete(fletcher_4_kstat);
|
||||
fletcher_4_kstat = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/* ABD adapters */
|
||||
|
||||
@@ -82,7 +82,6 @@ $(MODULE)-objs += zap.o
|
||||
$(MODULE)-objs += zap_leaf.o
|
||||
$(MODULE)-objs += zap_micro.o
|
||||
$(MODULE)-objs += zfeature.o
|
||||
$(MODULE)-objs += zfeature_common.o
|
||||
$(MODULE)-objs += zfs_acl.o
|
||||
$(MODULE)-objs += zfs_byteswap.o
|
||||
$(MODULE)-objs += zfs_ctldir.o
|
||||
@@ -93,6 +92,7 @@ $(MODULE)-objs += zfs_fuid.o
|
||||
$(MODULE)-objs += zfs_ioctl.o
|
||||
$(MODULE)-objs += zfs_log.o
|
||||
$(MODULE)-objs += zfs_onexit.o
|
||||
$(MODULE)-objs += zfs_ratelimit.o
|
||||
$(MODULE)-objs += zfs_replay.o
|
||||
$(MODULE)-objs += zfs_rlock.o
|
||||
$(MODULE)-objs += zfs_sa.o
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* CDDL HEADER START
|
||||
*
|
||||
* The contents of this file are subject to the terms of the
|
||||
* Common Development and Distribution License (the "License").
|
||||
* You may not use this file except in compliance with the License.
|
||||
*
|
||||
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
|
||||
* or http://www.opensolaris.org/os/licensing.
|
||||
* See the License for the specific language governing permissions
|
||||
* and limitations under the License.
|
||||
*
|
||||
* When distributing Covered Code, include this CDDL HEADER in each
|
||||
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
|
||||
* If applicable, add the following below this CDDL HEADER, with the
|
||||
* fields enclosed by brackets "[]" replaced with your own identifying
|
||||
* information: Portions Copyright [yyyy] [name of copyright owner]
|
||||
*
|
||||
* CDDL HEADER END
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017, Lawrence Livermore National Security, LLC.
|
||||
*/
|
||||
|
||||
#include <sys/zfs_ratelimit.h>
|
||||
|
||||
/*
|
||||
* Initialize rate limit struct
|
||||
*
|
||||
* rl: zfs_ratelimit_t struct
|
||||
* burst: Number to allow in an interval before rate limiting
|
||||
* interval: Interval time in seconds
|
||||
*/
|
||||
void
|
||||
zfs_ratelimit_init(zfs_ratelimit_t *rl, unsigned int burst,
|
||||
unsigned int interval)
|
||||
{
|
||||
rl->count = 0;
|
||||
rl->start = 0;
|
||||
rl->interval = interval;
|
||||
rl->burst = burst;
|
||||
mutex_init(&rl->lock, NULL, MUTEX_DEFAULT, NULL);
|
||||
}
|
||||
|
||||
/*
|
||||
* Finalize rate limit struct
|
||||
*
|
||||
* rl: zfs_ratelimit_t struct
|
||||
*/
|
||||
void
|
||||
zfs_ratelimit_fini(zfs_ratelimit_t *rl)
|
||||
{
|
||||
mutex_destroy(&rl->lock);
|
||||
}
|
||||
|
||||
/*
|
||||
* Re-implementation of the kernel's __ratelimit() function
|
||||
*
|
||||
* We had to write our own rate limiter because the kernel's __ratelimit()
|
||||
* function annoyingly prints out how many times it rate limited to the kernel
|
||||
* logs (and there's no way to turn it off):
|
||||
*
|
||||
* __ratelimit: 59 callbacks suppressed
|
||||
*
|
||||
* If the kernel ever allows us to disable these prints, we should go back to
|
||||
* using __ratelimit() instead.
|
||||
*
|
||||
* Return values are the same as __ratelimit():
|
||||
*
|
||||
* 0: If we're rate limiting
|
||||
* 1: If we're not rate limiting.
|
||||
*/
|
||||
int
|
||||
zfs_ratelimit(zfs_ratelimit_t *rl)
|
||||
{
|
||||
hrtime_t now;
|
||||
|
||||
hrtime_t elapsed;
|
||||
int error = 1;
|
||||
|
||||
mutex_enter(&rl->lock);
|
||||
|
||||
now = gethrtime();
|
||||
elapsed = now - rl->start;
|
||||
|
||||
rl->count++;
|
||||
if (NSEC2SEC(elapsed) >= rl->interval) {
|
||||
rl->start = now;
|
||||
rl->count = 0;
|
||||
} else {
|
||||
if (rl->count >= rl->burst) {
|
||||
error = 0; /* We're ratelimiting */
|
||||
}
|
||||
}
|
||||
mutex_exit(&rl->lock);
|
||||
|
||||
return (error);
|
||||
}
|
||||
Reference in New Issue
Block a user