Move range_tree, btree, highbit64 to common code

Break out the range_tree, btree, and highbit64/lowbit64 code from kernel
space into shared kernel and userspace code.  This is needed for the
updated `zpool status -vv` error byte range reporting that will be
coming in a future commit.  That commit needs the range_tree code in
kernel and userspace.

Reviewed-by: Rob Norris <robn@despairlabs.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Tony Hutter <hutter2@llnl.gov>
Closes #18133
This commit is contained in:
Tony Hutter
2026-02-22 11:43:51 -08:00
committed by GitHub
parent 168023b603
commit d2f5cb3a50
15 changed files with 117 additions and 88 deletions
+15 -13
View File
@@ -12,19 +12,19 @@
#
# CMDS: zhack/ztest/ zfs/zpool/zed/
# raidz_{test,bench} zinject/zstream
# | |
# LIBS: | | libzfsbootenv*
# |--libzdb--zdb | |
# | | |
# libzpool libzfs* ----------------+
# | | \ / | | |
# libicp --/ | \ / | \ |
# | \ / | \ \
# libzstd ---/ \ / | \ \-------\
# \ / \ \ \
# \ / \ \-------\ \
# \ / \ \ |
# libzutil libzfs_core* | |
# | \_____ / |
# LIBS: | \ / | libzfsbootenv*
# |--libzdb--zdb \ / | |
# | | | / | |
# libzpool-\ | | //-libzfs* --------------+
# | | \ \ | | // / | \ \
# libicp --/ | \ \ | | // / | \ \
# | \ librange_tree / | \ \
# libzstd ---/ \ libbtree / | \ \--------
# \ / \ \ \
# \ / \ \------ |
# \ / \ \ |
# libzutil libzfs_core* | |
# | | | \ | | | |
# | | | | | | | |
# | | | | | | | |
@@ -55,8 +55,10 @@ noinst_LTLIBRARIES =
lib_LTLIBRARIES =
pkgconfig_DATA =
include $(srcdir)/%D%/libavl/Makefile.am
include $(srcdir)/%D%/libbtree/Makefile.am
include $(srcdir)/%D%/libicp/Makefile.am
include $(srcdir)/%D%/libnvpair/Makefile.am
include $(srcdir)/%D%/librange_tree/Makefile.am
include $(srcdir)/%D%/libspl/Makefile.am
include $(srcdir)/%D%/libzdb/Makefile.am
include $(srcdir)/%D%/libzfs_core/Makefile.am
+6
View File
@@ -0,0 +1,6 @@
# SPDX-License-Identifier: CDDL-1.0
libbtree_la_CFLAGS = $(AM_CFLAGS) $(KERNEL_CFLAGS) $(LIBRARY_CFLAGS)
noinst_LTLIBRARIES += libbtree.la
nodist_libbtree_la_SOURCES = module/zfs/btree.c
+9
View File
@@ -0,0 +1,9 @@
# SPDX-License-Identifier: CDDL-1.0
librange_tree_la_CFLAGS = $(AM_CFLAGS) $(KERNEL_CFLAGS) $(LIBRARY_CFLAGS)
librange_tree_la_CFLAGS += -fvisibility=hidden
noinst_LTLIBRARIES += librange_tree.la
nodist_librange_tree_la_SOURCES = \
module/zfs/btree.c \
module/zfs/range_tree.c
+27 -2
View File
@@ -30,6 +30,7 @@
#define _LIBSPL_SYS_SYSMACROS_H
#include <stdint.h>
#include <limits.h>
#ifdef __linux__
/*
@@ -120,7 +121,31 @@
#define CPU_SEQID ((uintptr_t)pthread_self() & (max_ncpus - 1))
#define CPU_SEQID_UNSTABLE CPU_SEQID
extern int lowbit64(uint64_t i);
extern int highbit64(uint64_t i);
/*
* Find highest one bit set.
* Returns bit number + 1 of highest bit that is set, otherwise returns 0.
*/
static inline int
highbit64(uint64_t i)
{
if (i == 0)
return (0);
return (CHAR_BIT * sizeof (uint64_t) - __builtin_clzll(i));
}
/*
* Find lowest one bit set.
* Returns bit number + 1 of lowest bit that is set, otherwise returns 0.
* The __builtin_ffsll() function is supported by both GCC and Clang.
*/
static inline int
lowbit64(uint64_t i)
{
if (i == 0)
return (0);
return (__builtin_ffsll(i));
}
#endif /* _SYS_SYSMACROS_H */
+9
View File
@@ -59,6 +59,15 @@ nodist_libzfs_la_SOURCES = \
module/zcommon/zpool_prop.c \
module/zcommon/zprop_common.c
# Special case:
#
# We need to include btree.c and range_tree.c as SOURCES rather than
# LIBADD'ing them. This is because LIBADD'ing them will add their symbols to
# the libzfs API, which we do not want at this time.
nodist_libzfs_la_SOURCES += \
module/zfs/btree.c \
module/zfs/range_tree.c
libzfs_la_LIBADD = \
libzfs_core.la \
libnvpair.la \
+9 -2
View File
@@ -74,7 +74,6 @@ nodist_libzpool_la_SOURCES = \
module/zfs/bpobj.c \
module/zfs/bptree.c \
module/zfs/bqueue.c \
module/zfs/btree.c \
module/zfs/brt.c \
module/zfs/dbuf.c \
module/zfs/dbuf_stats.c \
@@ -119,7 +118,6 @@ nodist_libzpool_la_SOURCES = \
module/zfs/multilist.c \
module/zfs/objlist.c \
module/zfs/pathname.c \
module/zfs/range_tree.c \
module/zfs/refcount.c \
module/zfs/rrwlock.c \
module/zfs/sa.c \
@@ -196,6 +194,15 @@ nodist_libzpool_la_SOURCES = \
module/zfs/zrlock.c \
module/zfs/zthr.c
# Special case:
#
# We need to include btree.c and range_tree.c as SOURCES rather than
# LIBADD'ing them. This is because LIBADD'ing them will add their symbols to
# the libzpool API, which we do not want at this time.
nodist_libzpool_la_SOURCES += \
module/zfs/btree.c \
module/zfs/range_tree.c
libzpool_la_LIBADD = \
libicp.la \
libnvpair.la \
-28
View File
@@ -315,34 +315,6 @@ delay(clock_t ticks)
(void) poll(0, 0, ticks * (1000 / hz));
}
/*
* Find highest one bit set.
* Returns bit number + 1 of highest bit that is set, otherwise returns 0.
* The __builtin_clzll() function is supported by both GCC and Clang.
*/
int
highbit64(uint64_t i)
{
if (i == 0)
return (0);
return (NBBY * sizeof (uint64_t) - __builtin_clzll(i));
}
/*
* Find lowest one bit set.
* Returns bit number + 1 of lowest bit that is set, otherwise returns 0.
* The __builtin_ffsll() function is supported by both GCC and Clang.
*/
int
lowbit64(uint64_t i)
{
if (i == 0)
return (0);
return (__builtin_ffsll(i));
}
int
ddi_strtoull(const char *str, char **nptr, int base, u_longlong_t *result)
{