22
22
*
23
23
* Solaris Porting Layer (SPL) Proc Implementation.
24
24
*/
25
+ /*
26
+ * Copyright (c) 2024, Rob Norris <[email protected] >
27
+ */
25
28
26
29
#include <sys/systeminfo.h>
27
30
#include <sys/kstat.h>
@@ -694,6 +697,37 @@ static void spl_proc_cleanup(void)
694
697
}
695
698
}
696
699
700
+ #ifndef HAVE_REGISTER_SYSCTL_TABLE
701
+
702
+ /*
703
+ * Traditionally, struct ctl_table arrays have been terminated by an "empty"
704
+ * sentinel element (specifically, one with .procname == NULL).
705
+ *
706
+ * Linux 6.6 began migrating away from this, adding register_sysctl_sz() so
707
+ * that callers could provide the size directly, and redefining
708
+ * register_sysctl() to just call register_sysctl_sz() with the array size. It
709
+ * retained support for the terminating element so that existing callers would
710
+ * continue to work.
711
+ *
712
+ * Linux 6.11 removed support for the terminating element, instead interpreting
713
+ * it as a real malformed element, and rejecting it.
714
+ *
715
+ * In order to continue support older kernels, we retain the terminating
716
+ * sentinel element for our sysctl tables, but instead detect availability of
717
+ * register_sysctl_sz(). If it exists, we pass it the array size -1, stopping
718
+ * the kernel from trying to process the terminator. For pre-6.6 kernels that
719
+ * don't have register_sysctl_sz(), we just use register_sysctl(), which can
720
+ * handle the terminating element as it always has.
721
+ */
722
+ #ifdef HAVE_REGISTER_SYSCTL_SZ
723
+ #define spl_proc_register_sysctl (p , t ) \
724
+ register_sysctl_sz(p, t, ARRAY_SIZE(t)-1)
725
+ #else
726
+ #define spl_proc_register_sysctl (p , t ) \
727
+ register_sysctl(p, t)
728
+ #endif
729
+ #endif
730
+
697
731
int
698
732
spl_proc_init (void )
699
733
{
@@ -704,16 +738,17 @@ spl_proc_init(void)
704
738
if (spl_header == NULL )
705
739
return (- EUNATCH );
706
740
#else
707
- spl_header = register_sysctl ("kernel/spl" , spl_table );
741
+ spl_header = spl_proc_register_sysctl ("kernel/spl" , spl_table );
708
742
if (spl_header == NULL )
709
743
return (- EUNATCH );
710
744
711
- spl_kmem = register_sysctl ("kernel/spl/kmem" , spl_kmem_table );
745
+ spl_kmem = spl_proc_register_sysctl ("kernel/spl/kmem" , spl_kmem_table );
712
746
if (spl_kmem == NULL ) {
713
747
rc = - EUNATCH ;
714
748
goto out ;
715
749
}
716
- spl_kstat = register_sysctl ("kernel/spl/kstat" , spl_kstat_table );
750
+ spl_kstat = spl_proc_register_sysctl ("kernel/spl/kstat" ,
751
+ spl_kstat_table );
717
752
if (spl_kstat == NULL ) {
718
753
rc = - EUNATCH ;
719
754
goto out ;
0 commit comments