Skip to content

Commit

Permalink
abd_os: break out platform-specific header parts
Browse files Browse the repository at this point in the history
Removing the platform #ifdefs from shared headers in favour of
per-platform headers. Makes abd_t much leaner, among other things.

Sponsored-by: Klara, Inc.
Sponsored-by: Wasabi Technology, Inc.
Reviewed-by: Alexander Motin <mav@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@klarasystems.com>
Closes openzfs#16253
  • Loading branch information
robn authored and tonyhutter committed Nov 13, 2024
1 parent 8092dd8 commit 3935db1
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 48 deletions.
3 changes: 2 additions & 1 deletion config/Rules.am
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions include/os/freebsd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,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 \
Expand Down
41 changes: 41 additions & 0 deletions include/os/freebsd/zfs/sys/abd_impl_os.h
Original file line number Diff line number Diff line change
@@ -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 */
46 changes: 46 additions & 0 deletions include/os/freebsd/zfs/sys/abd_os.h
Original file line number Diff line number Diff line change
@@ -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 */
2 changes: 2 additions & 0 deletions include/os/linux/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,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 \
Expand Down
41 changes: 41 additions & 0 deletions include/os/linux/zfs/sys/abd_impl_os.h
Original file line number Diff line number Diff line change
@@ -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 */
62 changes: 62 additions & 0 deletions include/os/linux/zfs/sys/abd_os.h
Original file line number Diff line number Diff line change
@@ -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 */
35 changes: 3 additions & 32 deletions include/sys/abd.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <sys/debug.h>
#include <sys/zfs_refcount.h>
#include <sys/uio.h>
#include <sys/abd_os.h>

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -58,21 +59,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;
Expand All @@ -81,9 +69,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;

Expand Down Expand Up @@ -130,10 +115,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);
Expand Down Expand Up @@ -220,16 +201,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
Expand Down
14 changes: 1 addition & 13 deletions include/sys/abd_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#define _ABD_IMPL_H

#include <sys/abd.h>
#include <sys/abd_impl_os.h>
#include <sys/wmsum.h>

#ifdef __cplusplus
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions lib/libzpool/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
include $(srcdir)/%D%/include/Makefile.am

libzpool_la_CFLAGS = $(AM_CFLAGS) $(KERNEL_CFLAGS) $(LIBRARY_CFLAGS)
libzpool_la_CFLAGS += $(ZLIB_CFLAGS)

Expand Down
4 changes: 4 additions & 0 deletions lib/libzpool/include/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
libzpooldir = $(includedir)/libzpool
libzpool_HEADERS = \
%D%/sys/abd_os.h \
%D%/sys/abd_impl_os.h
41 changes: 41 additions & 0 deletions lib/libzpool/include/sys/abd_impl_os.h
Original file line number Diff line number Diff line change
@@ -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 */
Loading

0 comments on commit 3935db1

Please sign in to comment.