diff options
author | Brian Behlendorf <[email protected]> | 2017-08-09 15:31:08 -0700 |
---|---|---|
committer | GitHub <[email protected]> | 2017-08-09 15:31:08 -0700 |
commit | 46364cb2f35545a7fc915df9593b719a94c43a83 (patch) | |
tree | 0fb11534892c2aaaa1c1bda3c10914e718827eb0 /module/zcommon | |
parent | 5146d802b4e371cab1d6db79bea482c056be7bf2 (diff) |
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 <[email protected]>
Signed-off-by: Brian Behlendorf <[email protected]>
Closes #6442
Diffstat (limited to 'module/zcommon')
-rw-r--r-- | module/zcommon/Makefile.in | 13 | ||||
-rw-r--r-- | module/zcommon/zfeature_common.c | 330 | ||||
-rw-r--r-- | module/zcommon/zfs_comutil.c | 75 | ||||
-rw-r--r-- | module/zcommon/zfs_deleg.c | 2 | ||||
-rw-r--r-- | module/zcommon/zfs_fletcher.c | 9 |
5 files changed, 346 insertions, 83 deletions
diff --git a/module/zcommon/Makefile.in b/module/zcommon/Makefile.in index 74bb4378e..86eb8ad39 100644 --- a/module/zcommon/Makefile.in +++ b/module/zcommon/Makefile.in @@ -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 diff --git a/module/zcommon/zfeature_common.c b/module/zcommon/zfeature_common.c new file mode 100644 index 000000000..321ee04bf --- /dev/null +++ b/module/zcommon/zfeature_common.c @@ -0,0 +1,330 @@ +/* + * 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) 2011, 2015 by Delphix. All rights reserved. + * Copyright (c) 2013 by Saso Kiselkov. All rights reserved. + * Copyright (c) 2013, Joyent, Inc. All rights reserved. + * Copyright (c) 2014, Nexenta Systems, Inc. All rights reserved. + */ + +#ifdef _KERNEL +#include <sys/systm.h> +#else +#include <errno.h> +#include <string.h> +#endif +#include <sys/debug.h> +#include <sys/fs/zfs.h> +#include <sys/inttypes.h> +#include <sys/types.h> +#include "zfeature_common.h" + +/* + * Set to disable all feature checks while opening pools, allowing pools with + * unsupported features to be opened. Set for testing only. + */ +boolean_t zfeature_checks_disable = B_FALSE; + +zfeature_info_t spa_feature_table[SPA_FEATURES]; + +/* + * Valid characters for feature guids. This list is mainly for aesthetic + * purposes and could be expanded in the future. There are different allowed + * characters in the guids reverse dns portion (before the colon) and its + * short name (after the colon). + */ +static int +valid_char(char c, boolean_t after_colon) +{ + return ((c >= 'a' && c <= 'z') || + (c >= '0' && c <= '9') || + (after_colon && c == '_') || + (!after_colon && (c == '.' || c == '-'))); +} + +/* + * Every feature guid must contain exactly one colon which separates a reverse + * dns organization name from the feature's "short" name (e.g. + * "com.company:feature_name"). + */ +boolean_t +zfeature_is_valid_guid(const char *name) +{ + int i; + boolean_t has_colon = B_FALSE; + + i = 0; + while (name[i] != '\0') { + char c = name[i++]; + if (c == ':') { + if (has_colon) + return (B_FALSE); + has_colon = B_TRUE; + continue; + } + if (!valid_char(c, has_colon)) + return (B_FALSE); + } + + return (has_colon); +} + +boolean_t +zfeature_is_supported(const char *guid) +{ + spa_feature_t i; + + if (zfeature_checks_disable) + return (B_TRUE); + + for (i = 0; i < SPA_FEATURES; i++) { + zfeature_info_t *feature = &spa_feature_table[i]; + if (strcmp(guid, feature->fi_guid) == 0) + return (B_TRUE); + } + + return (B_FALSE); +} + +int +zfeature_lookup_name(const char *name, spa_feature_t *res) +{ + spa_feature_t i; + + for (i = 0; i < SPA_FEATURES; i++) { + zfeature_info_t *feature = &spa_feature_table[i]; + if (strcmp(name, feature->fi_uname) == 0) { + if (res != NULL) + *res = i; + return (0); + } + } + + return (ENOENT); +} + +boolean_t +zfeature_depends_on(spa_feature_t fid, spa_feature_t check) +{ + zfeature_info_t *feature = &spa_feature_table[fid]; + int i; + + for (i = 0; feature->fi_depends[i] != SPA_FEATURE_NONE; i++) { + if (feature->fi_depends[i] == check) + return (B_TRUE); + } + return (B_FALSE); +} + +static boolean_t +deps_contains_feature(const spa_feature_t *deps, const spa_feature_t feature) +{ + int i; + + for (i = 0; deps[i] != SPA_FEATURE_NONE; i++) + if (deps[i] == feature) + return (B_TRUE); + + return (B_FALSE); +} + +static void +zfeature_register(spa_feature_t fid, const char *guid, const char *name, + const char *desc, zfeature_flags_t flags, const spa_feature_t *deps) +{ + zfeature_info_t *feature = &spa_feature_table[fid]; + static spa_feature_t nodeps[] = { SPA_FEATURE_NONE }; + + ASSERT(name != NULL); + ASSERT(desc != NULL); + ASSERT((flags & ZFEATURE_FLAG_READONLY_COMPAT) == 0 || + (flags & ZFEATURE_FLAG_MOS) == 0); + ASSERT3U(fid, <, SPA_FEATURES); + ASSERT(zfeature_is_valid_guid(guid)); + + if (deps == NULL) + deps = nodeps; + + VERIFY(((flags & ZFEATURE_FLAG_PER_DATASET) == 0) || + (deps_contains_feature(deps, SPA_FEATURE_EXTENSIBLE_DATASET))); + + feature->fi_feature = fid; + feature->fi_guid = guid; + feature->fi_uname = name; + feature->fi_desc = desc; + feature->fi_flags = flags; + feature->fi_depends = deps; +} + +void +zpool_feature_init(void) +{ + zfeature_register(SPA_FEATURE_ASYNC_DESTROY, + "com.delphix:async_destroy", "async_destroy", + "Destroy filesystems asynchronously.", + ZFEATURE_FLAG_READONLY_COMPAT, NULL); + + zfeature_register(SPA_FEATURE_EMPTY_BPOBJ, + "com.delphix:empty_bpobj", "empty_bpobj", + "Snapshots use less space.", + ZFEATURE_FLAG_READONLY_COMPAT, NULL); + + zfeature_register(SPA_FEATURE_LZ4_COMPRESS, + "org.illumos:lz4_compress", "lz4_compress", + "LZ4 compression algorithm support.", + ZFEATURE_FLAG_ACTIVATE_ON_ENABLE, NULL); + + zfeature_register(SPA_FEATURE_MULTI_VDEV_CRASH_DUMP, + "com.joyent:multi_vdev_crash_dump", "multi_vdev_crash_dump", + "Crash dumps to multiple vdev pools.", + 0, NULL); + + zfeature_register(SPA_FEATURE_SPACEMAP_HISTOGRAM, + "com.delphix:spacemap_histogram", "spacemap_histogram", + "Spacemaps maintain space histograms.", + ZFEATURE_FLAG_READONLY_COMPAT, NULL); + + zfeature_register(SPA_FEATURE_ENABLED_TXG, + "com.delphix:enabled_txg", "enabled_txg", + "Record txg at which a feature is enabled", + ZFEATURE_FLAG_READONLY_COMPAT, NULL); + + { + static const spa_feature_t hole_birth_deps[] = { + SPA_FEATURE_ENABLED_TXG, + SPA_FEATURE_NONE + }; + zfeature_register(SPA_FEATURE_HOLE_BIRTH, + "com.delphix:hole_birth", "hole_birth", + "Retain hole birth txg for more precise zfs send", + ZFEATURE_FLAG_MOS | ZFEATURE_FLAG_ACTIVATE_ON_ENABLE, + hole_birth_deps); + } + + zfeature_register(SPA_FEATURE_EXTENSIBLE_DATASET, + "com.delphix:extensible_dataset", "extensible_dataset", + "Enhanced dataset functionality, used by other features.", + 0, NULL); + + { + static const spa_feature_t bookmarks_deps[] = { + SPA_FEATURE_EXTENSIBLE_DATASET, + SPA_FEATURE_NONE + }; + + zfeature_register(SPA_FEATURE_BOOKMARKS, + "com.delphix:bookmarks", "bookmarks", + "\"zfs bookmark\" command", + ZFEATURE_FLAG_READONLY_COMPAT, bookmarks_deps); + } + + { + static const spa_feature_t filesystem_limits_deps[] = { + SPA_FEATURE_EXTENSIBLE_DATASET, + SPA_FEATURE_NONE + }; + zfeature_register(SPA_FEATURE_FS_SS_LIMIT, + "com.joyent:filesystem_limits", "filesystem_limits", + "Filesystem and snapshot limits.", + ZFEATURE_FLAG_READONLY_COMPAT, filesystem_limits_deps); + } + + zfeature_register(SPA_FEATURE_EMBEDDED_DATA, + "com.delphix:embedded_data", "embedded_data", + "Blocks which compress very well use even less space.", + ZFEATURE_FLAG_MOS | ZFEATURE_FLAG_ACTIVATE_ON_ENABLE, + NULL); + + { + static const spa_feature_t large_blocks_deps[] = { + SPA_FEATURE_EXTENSIBLE_DATASET, + SPA_FEATURE_NONE + }; + zfeature_register(SPA_FEATURE_LARGE_BLOCKS, + "org.open-zfs:large_blocks", "large_blocks", + "Support for blocks larger than 128KB.", + ZFEATURE_FLAG_PER_DATASET, large_blocks_deps); + } + + { + static const spa_feature_t large_dnode_deps[] = { + SPA_FEATURE_EXTENSIBLE_DATASET, + SPA_FEATURE_NONE + }; + zfeature_register(SPA_FEATURE_LARGE_DNODE, + "org.zfsonlinux:large_dnode", "large_dnode", + "Variable on-disk size of dnodes.", + ZFEATURE_FLAG_PER_DATASET, large_dnode_deps); + } + + { + static const spa_feature_t sha512_deps[] = { + SPA_FEATURE_EXTENSIBLE_DATASET, + SPA_FEATURE_NONE + }; + zfeature_register(SPA_FEATURE_SHA512, + "org.illumos:sha512", "sha512", + "SHA-512/256 hash algorithm.", + ZFEATURE_FLAG_PER_DATASET, sha512_deps); + } + { + static const spa_feature_t skein_deps[] = { + SPA_FEATURE_EXTENSIBLE_DATASET, + SPA_FEATURE_NONE + }; + zfeature_register(SPA_FEATURE_SKEIN, + "org.illumos:skein", "skein", + "Skein hash algorithm.", + ZFEATURE_FLAG_PER_DATASET, skein_deps); + } + + { + static const spa_feature_t edonr_deps[] = { + SPA_FEATURE_EXTENSIBLE_DATASET, + SPA_FEATURE_NONE + }; + zfeature_register(SPA_FEATURE_EDONR, + "org.illumos:edonr", "edonr", + "Edon-R hash algorithm.", + ZFEATURE_FLAG_PER_DATASET, edonr_deps); + } + { + static const spa_feature_t userobj_accounting_deps[] = { + SPA_FEATURE_EXTENSIBLE_DATASET, + SPA_FEATURE_NONE + }; + zfeature_register(SPA_FEATURE_USEROBJ_ACCOUNTING, + "org.zfsonlinux:userobj_accounting", "userobj_accounting", + "User/Group object accounting.", + ZFEATURE_FLAG_READONLY_COMPAT | ZFEATURE_FLAG_PER_DATASET, + 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 diff --git a/module/zcommon/zfs_comutil.c b/module/zcommon/zfs_comutil.c index 52cb7e365..685a20c44 100644 --- a/module/zcommon/zfs_comutil.c +++ b/module/zcommon/zfs_comutil.c @@ -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 diff --git a/module/zcommon/zfs_deleg.c b/module/zcommon/zfs_deleg.c index ce659d7f5..90e9048b1 100644 --- a/module/zcommon/zfs_deleg.c +++ b/module/zcommon/zfs_deleg.c @@ -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"); } } diff --git a/module/zcommon/zfs_fletcher.c b/module/zcommon/zfs_fletcher.c index 9cdf36d44..0cd992979 100644 --- a/module/zcommon/zfs_fletcher.c +++ b/module/zcommon/zfs_fletcher.c @@ -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 */ |