spa: Fix FreeBSD sysctl handlers

sbuf_cpy() resets the sbuf state, which is wrong for sbufs allocated by
sbuf_new_for_sysctl().  In particular, this code triggers an assertion
failure in sbuf_clear().

Simplify by just using sysctl_handle_string() for both reading and
setting the tunable.

Fixes: 6930ecbb7 ("spa: make read/write queues configurable")
Reviewed-by: Rob Norris <robn@despairlabs.com>
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reported-by: Peter Holm <pho@FreeBSD.org>
Signed-off-by: Mark Johnston <markj@FreeBSD.org>
Closes #15719
This commit is contained in:
Mark Johnston 2023-12-29 10:22:58 -05:00 committed by Brian Behlendorf
parent 478c5b4f3f
commit b4481996bd
1 changed files with 6 additions and 24 deletions

View File

@ -1345,8 +1345,6 @@ spa_taskq_write_param_get(char *buf, zfs_kernel_param_t *kp)
return (spa_taskq_param_get(ZIO_TYPE_WRITE, buf)); return (spa_taskq_param_get(ZIO_TYPE_WRITE, buf));
} }
#else #else
#include <sys/sbuf.h>
/* /*
* On FreeBSD load-time parameters can be set up before malloc() is available, * On FreeBSD load-time parameters can be set up before malloc() is available,
* so we have to do all the parsing work on the stack. * so we have to do all the parsing work on the stack.
@ -1357,19 +1355,11 @@ static int
spa_taskq_read_param(ZFS_MODULE_PARAM_ARGS) spa_taskq_read_param(ZFS_MODULE_PARAM_ARGS)
{ {
char buf[SPA_TASKQ_PARAM_MAX]; char buf[SPA_TASKQ_PARAM_MAX];
int err = 0; int err;
if (req->newptr == NULL) {
int len = spa_taskq_param_get(ZIO_TYPE_READ, buf);
struct sbuf *s = sbuf_new_for_sysctl(NULL, NULL, len+1, req);
sbuf_cpy(s, buf);
err = sbuf_finish(s);
sbuf_delete(s);
return (err);
}
(void) spa_taskq_param_get(ZIO_TYPE_READ, buf);
err = sysctl_handle_string(oidp, buf, sizeof (buf), req); err = sysctl_handle_string(oidp, buf, sizeof (buf), req);
if (err) if (err || req->newptr == NULL)
return (err); return (err);
return (spa_taskq_param_set(ZIO_TYPE_READ, buf)); return (spa_taskq_param_set(ZIO_TYPE_READ, buf));
} }
@ -1378,19 +1368,11 @@ static int
spa_taskq_write_param(ZFS_MODULE_PARAM_ARGS) spa_taskq_write_param(ZFS_MODULE_PARAM_ARGS)
{ {
char buf[SPA_TASKQ_PARAM_MAX]; char buf[SPA_TASKQ_PARAM_MAX];
int err = 0; int err;
if (req->newptr == NULL) {
int len = spa_taskq_param_get(ZIO_TYPE_WRITE, buf);
struct sbuf *s = sbuf_new_for_sysctl(NULL, NULL, len+1, req);
sbuf_cpy(s, buf);
err = sbuf_finish(s);
sbuf_delete(s);
return (err);
}
(void) spa_taskq_param_get(ZIO_TYPE_WRITE, buf);
err = sysctl_handle_string(oidp, buf, sizeof (buf), req); err = sysctl_handle_string(oidp, buf, sizeof (buf), req);
if (err) if (err || req->newptr == NULL)
return (err); return (err);
return (spa_taskq_param_set(ZIO_TYPE_WRITE, buf)); return (spa_taskq_param_set(ZIO_TYPE_WRITE, buf));
} }