Skip to content

Commit 80c53bc

Browse files
asomerslundman
authored andcommitted
Make the vfs.zfs.vdev.raidz_impl sysctl cross-platform
Reviewed-by: Allan Jude <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Alan Somers <[email protected]> Sponsored by: ConnectWise Closes openzfs#16980
1 parent fbc08c0 commit 80c53bc

File tree

8 files changed

+83
-41
lines changed

8 files changed

+83
-41
lines changed

include/os/freebsd/spl/sys/mod_os.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@
9494
#define param_set_max_auto_ashift_args(var) \
9595
CTLTYPE_UINT, NULL, 0, param_set_max_auto_ashift, "IU"
9696

97+
#define param_set_raidz_impl_args(var) \
98+
CTLTYPE_STRING, NULL, 0, param_set_raidz_impl, "A"
99+
97100
#define spa_taskq_read_param_set_args(var) \
98101
CTLTYPE_STRING, NULL, 0, spa_taskq_read_param, "A"
99102

include/sys/vdev_impl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,10 @@ extern int vdev_obsolete_counts_are_precise(vdev_t *vd, boolean_t *are_precise);
645645
int vdev_checkpoint_sm_object(vdev_t *vd, uint64_t *sm_obj);
646646
void vdev_metaslab_group_create(vdev_t *vd);
647647
uint64_t vdev_best_ashift(uint64_t logical, uint64_t a, uint64_t b);
648+
#if defined(__linux__)
649+
int param_get_raidz_impl(char *buf, zfs_kernel_param_t *kp);
650+
#endif
651+
int param_set_raidz_impl(ZFS_MODULE_PARAM_ARGS);
648652

649653
/*
650654
* Vdev ashift optimization tunables

include/sys/vdev_raidz.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,16 @@ extern const zio_vsd_ops_t vdev_raidz_vsd_ops;
6666
/*
6767
* vdev_raidz_math interface
6868
*/
69+
/* Required, but not used, by ZFS_MODULE_PARAM_CALL */
70+
extern uint32_t zfs_vdev_raidz_impl;
6971
void vdev_raidz_math_init(void);
7072
void vdev_raidz_math_fini(void);
7173
const struct raidz_impl_ops *vdev_raidz_math_get_ops(void);
7274
int vdev_raidz_math_generate(struct raidz_map *, struct raidz_row *);
7375
int vdev_raidz_math_reconstruct(struct raidz_map *, struct raidz_row *,
7476
const int *, const int *, const int);
7577
int vdev_raidz_impl_set(const char *);
76-
int vdev_raidz_impl_get(char *buffer, size_t max);
78+
int vdev_raidz_impl_get(char *buffer, size_t size);
7779

7880
typedef struct vdev_raidz_expand {
7981
uint64_t vre_vdev_id;

module/Kbuild.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ ZFS_OBJS_OS := \
448448
trace.o \
449449
vdev_disk.o \
450450
vdev_file.o \
451+
vdev_raidz.o \
451452
vdev_label_os.o \
452453
zfs_acl.o \
453454
zfs_ctldir.o \

module/os/freebsd/zfs/sysctl_os.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,27 @@ param_set_deadman_failmode(SYSCTL_HANDLER_ARGS)
679679
return (-param_set_deadman_failmode_common(buf));
680680
}
681681

682+
int
683+
param_set_raidz_impl(SYSCTL_HANDLER_ARGS)
684+
{
685+
const size_t bufsize = 128;
686+
char *buf;
687+
int rc;
688+
689+
buf = malloc(bufsize, M_SOLARIS, M_WAITOK | M_ZERO);
690+
if (req->newptr == NULL)
691+
vdev_raidz_impl_get(buf, bufsize);
692+
693+
rc = sysctl_handle_string(oidp, buf, bufsize, req);
694+
if (rc || req->newptr == NULL) {
695+
free(buf, M_SOLARIS);
696+
return (rc);
697+
}
698+
rc = vdev_raidz_impl_set(buf);
699+
free(buf, M_SOLARIS);
700+
return (rc);
701+
}
702+
682703
int
683704
param_set_slop_shift(SYSCTL_HANDLER_ARGS)
684705
{

module/os/linux/zfs/vdev_raidz.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9+
* or https://opensource.org/licenses/CDDL-1.0.
10+
* See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*
13+
* When distributing Covered Code, include this CDDL HEADER in each
14+
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15+
* If applicable, add the following below this CDDL HEADER, with the
16+
* fields enclosed by brackets "[]" replaced with your own identifying
17+
* information: Portions Copyright [yyyy] [name of copyright owner]
18+
*
19+
* CDDL HEADER END
20+
*/
21+
/* Copyright (C) 2025 ConnectWise */
22+
23+
#include <sys/zfs_context.h>
24+
#include <sys/spa.h>
25+
#include <sys/zio.h>
26+
#include <sys/vdev_impl.h>
27+
#include <sys/vdev_raidz.h>
28+
29+
int
30+
param_get_raidz_impl(char *buf, zfs_kernel_param_t *kp)
31+
{
32+
return (vdev_raidz_impl_get(buf, PAGE_SIZE));
33+
}
34+
35+
int
36+
param_set_raidz_impl(const char *val, zfs_kernel_param_t *kp)
37+
{
38+
int error;
39+
40+
error = vdev_raidz_impl_set(val);
41+
return (error);
42+
}

module/zfs/vdev.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6580,3 +6580,7 @@ ZFS_MODULE_PARAM_CALL(zfs_vdev, zfs_vdev_, max_auto_ashift,
65806580
param_set_max_auto_ashift, param_get_uint, ZMOD_RW,
65816581
"Maximum ashift used when optimizing for logical -> physical sector "
65826582
"size on new top-level vdevs");
6583+
6584+
ZFS_MODULE_PARAM_CALL(zfs_vdev, zfs_vdev_, raidz_impl,
6585+
param_set_raidz_impl, param_get_raidz_impl, ZMOD_RW,
6586+
"RAIDZ implementation");

module/zfs/vdev_raidz_math.c

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static boolean_t raidz_math_initialized = B_FALSE;
8181

8282
#define RAIDZ_IMPL_READ(i) (*(volatile uint32_t *) &(i))
8383

84-
static uint32_t zfs_vdev_raidz_impl = IMPL_SCALAR;
84+
uint32_t zfs_vdev_raidz_impl = IMPL_SCALAR;
8585
static uint32_t user_sel_impl = IMPL_FASTEST;
8686

8787
/* Hold all supported implementations */
@@ -635,17 +635,8 @@ vdev_raidz_impl_set(const char *val)
635635

636636
#if defined(_KERNEL)
637637

638-
#if defined(__linux__)
639-
static int
640-
zfs_vdev_raidz_impl_set(const char *val, zfs_kernel_param_t *kp)
641-
{
642-
return (vdev_raidz_impl_set(val));
643-
}
644-
#endif
645-
646-
#if defined(__linux__) || defined(__APPLE__)
647-
static int
648-
zfs_vdev_raidz_impl_get(char *buffer, zfs_kernel_param_t *kp)
638+
int
639+
vdev_raidz_impl_get(char *buffer, size_t size)
649640
{
650641
int i, cnt = 0;
651642
char *fmt;
@@ -656,44 +647,18 @@ zfs_vdev_raidz_impl_get(char *buffer, zfs_kernel_param_t *kp)
656647
/* list mandatory options */
657648
for (i = 0; i < ARRAY_SIZE(math_impl_opts) - 2; i++) {
658649
fmt = (impl == math_impl_opts[i].sel) ? "[%s] " : "%s ";
659-
cnt += kmem_scnprintf(buffer + cnt, PAGE_SIZE - cnt, fmt,
650+
cnt += kmem_scnprintf(buffer + cnt, size - cnt, fmt,
660651
math_impl_opts[i].name);
661652
}
662653

663654
/* list all supported implementations */
664655
for (i = 0; i < raidz_supp_impl_cnt; i++) {
665656
fmt = (i == impl) ? "[%s] " : "%s ";
666-
cnt += kmem_scnprintf(buffer + cnt, PAGE_SIZE - cnt, fmt,
657+
cnt += kmem_scnprintf(buffer + cnt, size - cnt, fmt,
667658
raidz_supp_impl[i]->name);
668659
}
669660

670661
return (cnt);
671662
}
672663

673-
#endif /* defined(Linux) || defined(APPLE) */
674-
675-
#if defined(__APPLE__)
676-
/* get / set function */
677-
int
678-
param_zfs_vdev_raidz_impl_set(ZFS_MODULE_PARAM_ARGS)
679-
{
680-
char buf[1024]; /* Linux module string limit */
681-
int rc = 0;
682-
683-
/* Always fill in value before calling sysctl_handle_*() */
684-
if (req->newptr == (user_addr_t)NULL)
685-
(void) zfs_vdev_raidz_impl_get(buf, NULL);
686-
687-
rc = sysctl_handle_string(oidp, buf, sizeof (buf), req);
688-
if (rc || req->newptr == (user_addr_t)NULL)
689-
return (rc);
690-
691-
rc = vdev_raidz_impl_set(buf);
692-
return (rc);
693-
}
694-
#endif /* defined(APPLE) */
695-
696-
module_param_call(zfs_vdev_raidz_impl, zfs_vdev_raidz_impl_set,
697-
zfs_vdev_raidz_impl_get, NULL, 0644);
698-
MODULE_PARM_DESC(zfs_vdev_raidz_impl, "Select raidz implementation.");
699664
#endif

0 commit comments

Comments
 (0)