diff --git a/lib/libspl/getexecname.c b/lib/libspl/getexecname.c index 43bf39ae33..c564eed055 100644 --- a/lib/libspl/getexecname.c +++ b/lib/libspl/getexecname.c @@ -48,6 +48,8 @@ getexecname(void) execname[rc] = '\0'; ptr = execname; } + } else { + ptr = execname; } pthread_mutex_unlock(&mtx); diff --git a/lib/libzpool/include/sys/zfs_context.h b/lib/libzpool/include/sys/zfs_context.h index f05bcb84f8..5649d4762e 100644 --- a/lib/libzpool/include/sys/zfs_context.h +++ b/lib/libzpool/include/sys/zfs_context.h @@ -146,7 +146,11 @@ extern void vpanic(const char *, __va_list); * Threads */ #define TS_RUN 0x00000002 +#ifdef _linux_ #define STACK_SIZE 8192 /* Linux x86 and amd64 */ +#else +#define STACK_SIZE 24576 /* Solaris */ +#endif /* in libzpool, p0 exists only to have its address taken */ typedef struct proc { diff --git a/lib/libzpool/kernel.c b/lib/libzpool/kernel.c index c8642c2f82..c7bac38b8f 100644 --- a/lib/libzpool/kernel.c +++ b/lib/libzpool/kernel.c @@ -146,14 +146,9 @@ zk_thread_create(caddr_t stk, size_t stksize, thread_func_t func, void *arg, size_t len, proc_t *pp, int state, pri_t pri) { kthread_t *kt; - pthread_t tid; pthread_attr_t attr; size_t stack; - /* - * Due to a race when getting/setting the thread ID, currently only - * detached threads are supported. - */ ASSERT3S(state & ~TS_RUN, ==, 0); kt = umem_zalloc(sizeof(kthread_t), UMEM_NOFAIL); @@ -161,23 +156,23 @@ zk_thread_create(caddr_t stk, size_t stksize, thread_func_t func, void *arg, kt->t_arg = arg; /* - * The Solaris kernel stack size in x86/x64 is 8K, so we reduce the - * default stack size in userspace, for sanity checking. + * The Solaris kernel stack size is 24k for x86/x86_64. + * The Linux kernel stack size is 8k for x86/x86_64. * - * PTHREAD_STACK_MIN is the stack required for a NULL procedure in - * userspace. - * - * XXX: Stack size for other architectures is not being taken into - * account. + * We reduce the default stack size in userspace, to ensure + * we observe stack overruns in user space as well as in + * kernel space. PTHREAD_STACK_MIN is the minimum stack + * required for a NULL procedure in user space and is added + * in to the stack requirements. */ stack = PTHREAD_STACK_MIN + MAX(stksize, STACK_SIZE); VERIFY3S(pthread_attr_init(&attr), ==, 0); VERIFY3S(pthread_attr_setstacksize(&attr, stack), ==, 0); - VERIFY3S(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED), - ==, 0); + VERIFY3S(pthread_attr_setguardsize(&attr, PAGESIZE), ==, 0); - VERIFY3S(pthread_create(&tid, &attr, &zk_thread_helper, kt), ==, 0); + VERIFY3S(pthread_create(&kt->t_tid, &attr, &zk_thread_helper, kt), + ==, 0); VERIFY3S(pthread_attr_destroy(&attr), ==, 0); diff --git a/module/zfs/dmu_objset.c b/module/zfs/dmu_objset.c index 629cba64a6..0e46edf625 100644 --- a/module/zfs/dmu_objset.c +++ b/module/zfs/dmu_objset.c @@ -916,7 +916,7 @@ dmu_objset_snapshot(char *fsname, char *snapname, if (dst->dst_err) dsl_dataset_name(ds, sn->failed); zil_resume(dmu_objset_zil(os)); - dmu_objset_rele(os, &sn); + dmu_objset_rele(os, sn); } if (err) diff --git a/module/zfs/spa_config.c b/module/zfs/spa_config.c index eed51ca664..2ffa06ff1d 100644 --- a/module/zfs/spa_config.c +++ b/module/zfs/spa_config.c @@ -96,7 +96,7 @@ spa_config_load(void) if (kobj_get_filesize(file, &fsize) != 0) goto out; - buf = kmem_alloc(fsize, KM_SLEEP); + buf = kmem_alloc(fsize, KM_SLEEP | KM_NODEBUG); /* * Read the nvlist from the file. @@ -159,7 +159,7 @@ spa_config_write(spa_config_dirent_t *dp, nvlist_t *nvl) */ VERIFY(nvlist_size(nvl, &buflen, NV_ENCODE_XDR) == 0); - buf = kmem_alloc(buflen, KM_SLEEP); + buf = kmem_alloc(buflen, KM_SLEEP | KM_NODEBUG); temp = kmem_zalloc(MAXPATHLEN, KM_SLEEP); VERIFY(nvlist_pack(nvl, &buf, &buflen, NV_ENCODE_XDR, diff --git a/module/zfs/spa_misc.c b/module/zfs/spa_misc.c index f759a717b9..228fc14fff 100644 --- a/module/zfs/spa_misc.c +++ b/module/zfs/spa_misc.c @@ -443,7 +443,7 @@ spa_add(const char *name, nvlist_t *config, const char *altroot) ASSERT(MUTEX_HELD(&spa_namespace_lock)); - spa = kmem_zalloc(sizeof (spa_t), KM_SLEEP); + spa = kmem_zalloc(sizeof (spa_t), KM_SLEEP | KM_NODEBUG); mutex_init(&spa->spa_async_lock, NULL, MUTEX_DEFAULT, NULL); mutex_init(&spa->spa_errlist_lock, NULL, MUTEX_DEFAULT, NULL); diff --git a/module/zfs/vdev_raidz.c b/module/zfs/vdev_raidz.c index d8e0dc6ad9..b987ac40b1 100644 --- a/module/zfs/vdev_raidz.c +++ b/module/zfs/vdev_raidz.c @@ -1638,8 +1638,11 @@ raidz_checksum_verify(zio_t *zio) { zio_bad_cksum_t zbc; raidz_map_t *rm = zio->io_vsd; + int ret; - int ret = zio_checksum_error(zio, &zbc); + bzero(&zbc, sizeof (zio_bad_cksum_t)); + + ret = zio_checksum_error(zio, &zbc); if (ret != 0 && zbc.zbc_injected != 0) rm->rm_ecksuminjected = 1; diff --git a/module/zfs/zio.c b/module/zfs/zio.c index 5ebdf4ca6c..ab26b8ac1a 100644 --- a/module/zfs/zio.c +++ b/module/zfs/zio.c @@ -1052,10 +1052,7 @@ zio_taskq_dispatch(zio_t *zio, enum zio_taskq_type q, boolean_t cutinline) { spa_t *spa = zio->io_spa; zio_type_t t = zio->io_type; - int flags; - - flags = (cutinline ? TQ_FRONT : 0); - flags |= ((q == ZIO_TASKQ_INTERRUPT) ? TQ_NOSLEEP : TQ_SLEEP); + int flags = TQ_NOSLEEP | (cutinline ? TQ_FRONT : 0); /* * If we're a config writer or a probe, the normal issue and diff --git a/module/zfs/zvol.c b/module/zfs/zvol.c index 333b3fb9d1..ffbb29251c 100644 --- a/module/zfs/zvol.c +++ b/module/zfs/zvol.c @@ -275,8 +275,6 @@ zvol_set_volsize(const char *name, uint64_t volsize) zvol_state_t *zv; dmu_object_info_t doi; objset_t *os = NULL; - zvol_state_t state = { 0 }; - uint64_t old_volsize = 0ULL; uint64_t readonly; int error; @@ -284,24 +282,24 @@ zvol_set_volsize(const char *name, uint64_t volsize) zv = zvol_find_by_name(name); if (zv == NULL) { - error = dmu_objset_hold(name, FTAG, &os); - if (error) - goto out; - zv = &state; + error = ENXIO; + goto out; } + error = dmu_objset_hold(name, FTAG, &os); + if (error) + goto out; + + if ((error = dmu_object_info(os, ZVOL_OBJ, &doi)) != 0 || + (error = zvol_check_volsize(volsize,doi.doi_data_block_size)) != 0) + goto out; + VERIFY(dsl_prop_get_integer(name, "readonly", &readonly, NULL) == 0); if (readonly) { error = EROFS; goto out; } - old_volsize = zv->zv_volsize; - - if ((error = dmu_object_info(os, ZVOL_OBJ, &doi)) != 0 || - (error = zvol_check_volsize(volsize,doi.doi_data_block_size)) != 0) - goto out; - if (get_disk_ro(zv->zv_disk) || (zv->zv_flags & ZVOL_RDONLY)) { error = EROFS; goto out;