diff --git a/config/Rules.am b/config/Rules.am index 00ac890e23..b462826e2c 100644 --- a/config/Rules.am +++ b/config/Rules.am @@ -10,7 +10,8 @@ AM_CPPFLAGS = \ -I$(top_srcdir)/include \ -I$(top_srcdir)/module/icp/include \ -I$(top_srcdir)/lib/libspl/include \ - -I$(top_srcdir)/lib/libspl/include/os/@ac_system_l@ + -I$(top_srcdir)/lib/libspl/include/os/@ac_system_l@ \ + -I$(top_srcdir)/lib/libzpool/include AM_LIBTOOLFLAGS = --silent diff --git a/include/os/freebsd/Makefile.am b/include/os/freebsd/Makefile.am index 292f79b8ce..d975c4fe69 100644 --- a/include/os/freebsd/Makefile.am +++ b/include/os/freebsd/Makefile.am @@ -77,6 +77,8 @@ noinst_HEADERS = \ %D%/spl/sys/zmod.h \ %D%/spl/sys/zone.h \ \ + %D%/zfs/sys/abd_os.h \ + %D%/zfs/sys/abd_impl_os.h \ %D%/zfs/sys/arc_os.h \ %D%/zfs/sys/freebsd_crypto.h \ %D%/zfs/sys/freebsd_event.h \ diff --git a/include/os/freebsd/zfs/sys/abd_impl_os.h b/include/os/freebsd/zfs/sys/abd_impl_os.h new file mode 100644 index 0000000000..309e77110d --- /dev/null +++ b/include/os/freebsd/zfs/sys/abd_impl_os.h @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or https://opensource.org/licenses/CDDL-1.0. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 2014 by Chunwei Chen. All rights reserved. + * Copyright (c) 2016, 2019 by Delphix. All rights reserved. + * Copyright (c) 2023, 2024, Klara Inc. + */ + +#ifndef _ABD_IMPL_OS_H +#define _ABD_IMPL_OS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define abd_enter_critical(flags) critical_enter() +#define abd_exit_critical(flags) critical_exit() + +#ifdef __cplusplus +} +#endif + +#endif /* _ABD_IMPL_OS_H */ diff --git a/include/os/freebsd/zfs/sys/abd_os.h b/include/os/freebsd/zfs/sys/abd_os.h new file mode 100644 index 0000000000..57122ee83e --- /dev/null +++ b/include/os/freebsd/zfs/sys/abd_os.h @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or https://opensource.org/licenses/CDDL-1.0. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 2014 by Chunwei Chen. All rights reserved. + * Copyright (c) 2016, 2019 by Delphix. All rights reserved. + */ + +#ifndef _ABD_OS_H +#define _ABD_OS_H + +#ifdef __cplusplus +extern "C" { +#endif + +struct abd_scatter { + uint_t abd_offset; + void *abd_chunks[1]; /* actually variable-length */ +}; + +struct abd_linear { + void *abd_buf; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _ABD_H */ diff --git a/include/os/linux/Makefile.am b/include/os/linux/Makefile.am index f31ae50b96..9100aebb54 100644 --- a/include/os/linux/Makefile.am +++ b/include/os/linux/Makefile.am @@ -20,6 +20,8 @@ kernel_linux_HEADERS = \ kernel_sysdir = $(kerneldir)/sys kernel_sys_HEADERS = \ + %D%/zfs/sys/abd_os.h \ + %D%/zfs/sys/abd_impl_os.h \ %D%/zfs/sys/policy.h \ %D%/zfs/sys/trace_acl.h \ %D%/zfs/sys/trace_arc.h \ diff --git a/include/os/linux/zfs/sys/abd_impl_os.h b/include/os/linux/zfs/sys/abd_impl_os.h new file mode 100644 index 0000000000..8192522cd2 --- /dev/null +++ b/include/os/linux/zfs/sys/abd_impl_os.h @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or https://opensource.org/licenses/CDDL-1.0. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 2014 by Chunwei Chen. All rights reserved. + * Copyright (c) 2016, 2019 by Delphix. All rights reserved. + * Copyright (c) 2023, 2024, Klara Inc. + */ + +#ifndef _ABD_IMPL_OS_H +#define _ABD_IMPL_OS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define abd_enter_critical(flags) local_irq_save(flags) +#define abd_exit_critical(flags) local_irq_restore(flags) + +#ifdef __cplusplus +} +#endif + +#endif /* _ABD_IMPL_OS_H */ diff --git a/include/os/linux/zfs/sys/abd_os.h b/include/os/linux/zfs/sys/abd_os.h new file mode 100644 index 0000000000..ce4f5a2bdf --- /dev/null +++ b/include/os/linux/zfs/sys/abd_os.h @@ -0,0 +1,62 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or https://opensource.org/licenses/CDDL-1.0. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 2014 by Chunwei Chen. All rights reserved. + * Copyright (c) 2016, 2019 by Delphix. All rights reserved. + */ + +#ifndef _ABD_OS_H +#define _ABD_OS_H + +#ifdef __cplusplus +extern "C" { +#endif + +struct abd_scatter { + uint_t abd_offset; + uint_t abd_nents; + struct scatterlist *abd_sgl; +}; + +struct abd_linear { + void *abd_buf; + struct scatterlist *abd_sgl; /* for LINEAR_PAGE */ +}; + +typedef struct abd abd_t; + +typedef int abd_iter_page_func_t(struct page *, size_t, size_t, void *); +int abd_iterate_page_func(abd_t *, size_t, size_t, abd_iter_page_func_t *, + void *); + +/* + * Linux ABD bio functions + * Note: these are only needed to support vdev_classic. See comment in + * vdev_disk.c. + */ +unsigned int abd_bio_map_off(struct bio *, abd_t *, unsigned int, size_t); +unsigned long abd_nr_pages_off(abd_t *, unsigned int, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* _ABD_H */ diff --git a/include/sys/abd.h b/include/sys/abd.h index ed008465c8..67bf5e802c 100644 --- a/include/sys/abd.h +++ b/include/sys/abd.h @@ -30,6 +30,7 @@ #include #include #include +#include #ifdef __cplusplus extern "C" { @@ -57,21 +58,8 @@ typedef struct abd { #endif kmutex_t abd_mtx; union { - struct abd_scatter { - uint_t abd_offset; -#if defined(__FreeBSD__) && defined(_KERNEL) - void *abd_chunks[1]; /* actually variable-length */ -#else - uint_t abd_nents; - struct scatterlist *abd_sgl; -#endif - } abd_scatter; - struct abd_linear { - void *abd_buf; -#if defined(__linux__) && defined(_KERNEL) - struct scatterlist *abd_sgl; /* for LINEAR_PAGE */ -#endif - } abd_linear; + struct abd_scatter abd_scatter; + struct abd_linear abd_linear; struct abd_gang { list_t abd_gang_chain; } abd_gang; @@ -80,9 +68,6 @@ typedef struct abd { typedef int abd_iter_func_t(void *buf, size_t len, void *priv); typedef int abd_iter_func2_t(void *bufa, void *bufb, size_t len, void *priv); -#if defined(__linux__) && defined(_KERNEL) -typedef int abd_iter_page_func_t(struct page *, size_t, size_t, void *); -#endif extern int zfs_abd_scatter_enabled; @@ -129,10 +114,6 @@ void abd_release_ownership_of_buf(abd_t *); int abd_iterate_func(abd_t *, size_t, size_t, abd_iter_func_t *, void *); int abd_iterate_func2(abd_t *, abd_t *, size_t, size_t, size_t, abd_iter_func2_t *, void *); -#if defined(__linux__) && defined(_KERNEL) -int abd_iterate_page_func(abd_t *, size_t, size_t, abd_iter_page_func_t *, - void *); -#endif void abd_copy_off(abd_t *, abd_t *, size_t, size_t, size_t); void abd_copy_from_buf_off(abd_t *, const void *, size_t, size_t); void abd_copy_to_buf_off(void *, abd_t *, size_t, size_t); @@ -226,16 +207,6 @@ abd_get_size(abd_t *abd) void abd_init(void); void abd_fini(void); -/* - * Linux ABD bio functions - * Note: these are only needed to support vdev_classic. See comment in - * vdev_disk.c. - */ -#if defined(__linux__) && defined(_KERNEL) -unsigned int abd_bio_map_off(struct bio *, abd_t *, unsigned int, size_t); -unsigned long abd_nr_pages_off(abd_t *, unsigned int, size_t); -#endif - #ifdef __cplusplus } #endif diff --git a/include/sys/abd_impl.h b/include/sys/abd_impl.h index f88ea25e24..1eb25d94ad 100644 --- a/include/sys/abd_impl.h +++ b/include/sys/abd_impl.h @@ -28,6 +28,7 @@ #define _ABD_IMPL_H #include +#include #include #ifdef __cplusplus @@ -111,19 +112,6 @@ void abd_iter_page(struct abd_iter *); #define ABD_LINEAR_BUF(abd) (abd->abd_u.abd_linear.abd_buf) #define ABD_GANG(abd) (abd->abd_u.abd_gang) -#if defined(_KERNEL) -#if defined(__FreeBSD__) -#define abd_enter_critical(flags) critical_enter() -#define abd_exit_critical(flags) critical_exit() -#else -#define abd_enter_critical(flags) local_irq_save(flags) -#define abd_exit_critical(flags) local_irq_restore(flags) -#endif -#else /* !_KERNEL */ -#define abd_enter_critical(flags) ((void)0) -#define abd_exit_critical(flags) ((void)0) -#endif - #ifdef __cplusplus } #endif diff --git a/lib/libzpool/Makefile.am b/lib/libzpool/Makefile.am index eb0dd0ace1..6989fefc66 100644 --- a/lib/libzpool/Makefile.am +++ b/lib/libzpool/Makefile.am @@ -1,3 +1,5 @@ +include $(srcdir)/%D%/include/Makefile.am + libzpool_la_CFLAGS = $(AM_CFLAGS) $(KERNEL_CFLAGS) $(LIBRARY_CFLAGS) libzpool_la_CFLAGS += $(ZLIB_CFLAGS) diff --git a/lib/libzpool/include/Makefile.am b/lib/libzpool/include/Makefile.am new file mode 100644 index 0000000000..2e0c4c5610 --- /dev/null +++ b/lib/libzpool/include/Makefile.am @@ -0,0 +1,4 @@ +libzpooldir = $(includedir)/libzpool +libzpool_HEADERS = \ + %D%/sys/abd_os.h \ + %D%/sys/abd_impl_os.h diff --git a/lib/libzpool/include/sys/abd_impl_os.h b/lib/libzpool/include/sys/abd_impl_os.h new file mode 100644 index 0000000000..3137346f3b --- /dev/null +++ b/lib/libzpool/include/sys/abd_impl_os.h @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or https://opensource.org/licenses/CDDL-1.0. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 2014 by Chunwei Chen. All rights reserved. + * Copyright (c) 2016, 2019 by Delphix. All rights reserved. + * Copyright (c) 2023, 2024, Klara Inc. + */ + +#ifndef _ABD_IMPL_OS_H +#define _ABD_IMPL_OS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define abd_enter_critical(flags) ((void)0) +#define abd_exit_critical(flags) ((void)0) + +#ifdef __cplusplus +} +#endif + +#endif /* _ABD_IMPL_OS_H */ diff --git a/lib/libzpool/include/sys/abd_os.h b/lib/libzpool/include/sys/abd_os.h new file mode 100644 index 0000000000..67f7e5606b --- /dev/null +++ b/lib/libzpool/include/sys/abd_os.h @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or https://opensource.org/licenses/CDDL-1.0. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 2014 by Chunwei Chen. All rights reserved. + * Copyright (c) 2016, 2019 by Delphix. All rights reserved. + */ + +#ifndef _ABD_OS_H +#define _ABD_OS_H + +#ifdef __cplusplus +extern "C" { +#endif + +struct abd_scatter { + uint_t abd_offset; + uint_t abd_nents; + struct scatterlist *abd_sgl; +}; + +struct abd_linear { + void *abd_buf; +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _ABD_H */ diff --git a/module/os/freebsd/zfs/abd_os.c b/module/os/freebsd/zfs/abd_os.c index ce8c30025f..f24ea3dc76 100644 --- a/module/os/freebsd/zfs/abd_os.c +++ b/module/os/freebsd/zfs/abd_os.c @@ -95,14 +95,12 @@ struct { */ static size_t zfs_abd_scatter_min_size = PAGE_SIZE + 1; -#if defined(_KERNEL) SYSCTL_DECL(_vfs_zfs); SYSCTL_INT(_vfs_zfs, OID_AUTO, abd_scatter_enabled, CTLFLAG_RWTUN, &zfs_abd_scatter_enabled, 0, "Enable scattered ARC data buffers"); SYSCTL_ULONG(_vfs_zfs, OID_AUTO, abd_scatter_min_size, CTLFLAG_RWTUN, &zfs_abd_scatter_min_size, 0, "Minimum size of scatter allocations."); -#endif kmem_cache_t *abd_chunk_cache; static kstat_t *abd_ksp;