Skip to content

Commit

Permalink
spa: Fix FreeBSD sysctl handlers
Browse files Browse the repository at this point in the history
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().

Instead, allocate the sbuf itself statically and pass the buffer in at
creation time.  This avoids some needless memory allocation and copying.

Fixes: 6930ecb ("spa: make read/write queues configurable")
Reported-by: Peter Holm <[email protected]>
Signed-off-by: Mark Johnston <[email protected]>
  • Loading branch information
markjdb committed Dec 29, 2023
1 parent 07e95b4 commit 208c8af
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions module/zfs/spa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1460,11 +1460,12 @@ spa_taskq_read_param(ZFS_MODULE_PARAM_ARGS)
int err = 0;

if (req->newptr == NULL) {
struct sbuf s;
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);

(void) sbuf_new_for_sysctl(&s, buf, len + 1, req);
err = sbuf_finish(&s);
sbuf_delete(&s);
return (err);
}

Expand All @@ -1481,11 +1482,12 @@ spa_taskq_write_param(ZFS_MODULE_PARAM_ARGS)
int err = 0;

if (req->newptr == NULL) {
struct sbuf s;
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);

(void) sbuf_new_for_sysctl(&s, buf, len + 1, req);
err = sbuf_finish(&s);
sbuf_delete(&s);
return (err);
}

Expand Down

0 comments on commit 208c8af

Please sign in to comment.