Skip to content

Commit 3935db1

Browse files
robntonyhutter
authored andcommitted
abd_os: break out platform-specific header parts
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 <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes openzfs#16253
1 parent 8092dd8 commit 3935db1

File tree

14 files changed

+294
-48
lines changed

14 files changed

+294
-48
lines changed

config/Rules.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ AM_CPPFLAGS = \
1010
-I$(top_srcdir)/include \
1111
-I$(top_srcdir)/module/icp/include \
1212
-I$(top_srcdir)/lib/libspl/include \
13-
-I$(top_srcdir)/lib/libspl/include/os/@ac_system_l@
13+
-I$(top_srcdir)/lib/libspl/include/os/@ac_system_l@ \
14+
-I$(top_srcdir)/lib/libzpool/include
1415

1516
AM_LIBTOOLFLAGS = --silent
1617

include/os/freebsd/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ noinst_HEADERS = \
7878
%D%/spl/sys/zmod.h \
7979
%D%/spl/sys/zone.h \
8080
\
81+
%D%/zfs/sys/abd_os.h \
82+
%D%/zfs/sys/abd_impl_os.h \
8183
%D%/zfs/sys/arc_os.h \
8284
%D%/zfs/sys/freebsd_crypto.h \
8385
%D%/zfs/sys/freebsd_event.h \
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
/*
22+
* Copyright (c) 2014 by Chunwei Chen. All rights reserved.
23+
* Copyright (c) 2016, 2019 by Delphix. All rights reserved.
24+
* Copyright (c) 2023, 2024, Klara Inc.
25+
*/
26+
27+
#ifndef _ABD_IMPL_OS_H
28+
#define _ABD_IMPL_OS_H
29+
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
34+
#define abd_enter_critical(flags) critical_enter()
35+
#define abd_exit_critical(flags) critical_exit()
36+
37+
#ifdef __cplusplus
38+
}
39+
#endif
40+
41+
#endif /* _ABD_IMPL_OS_H */

include/os/freebsd/zfs/sys/abd_os.h

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
/*
22+
* Copyright (c) 2014 by Chunwei Chen. All rights reserved.
23+
* Copyright (c) 2016, 2019 by Delphix. All rights reserved.
24+
*/
25+
26+
#ifndef _ABD_OS_H
27+
#define _ABD_OS_H
28+
29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
33+
struct abd_scatter {
34+
uint_t abd_offset;
35+
void *abd_chunks[1]; /* actually variable-length */
36+
};
37+
38+
struct abd_linear {
39+
void *abd_buf;
40+
};
41+
42+
#ifdef __cplusplus
43+
}
44+
#endif
45+
46+
#endif /* _ABD_H */

include/os/linux/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ kernel_linux_HEADERS = \
1919

2020
kernel_sysdir = $(kerneldir)/sys
2121
kernel_sys_HEADERS = \
22+
%D%/zfs/sys/abd_os.h \
23+
%D%/zfs/sys/abd_impl_os.h \
2224
%D%/zfs/sys/policy.h \
2325
%D%/zfs/sys/trace_acl.h \
2426
%D%/zfs/sys/trace_arc.h \
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
/*
22+
* Copyright (c) 2014 by Chunwei Chen. All rights reserved.
23+
* Copyright (c) 2016, 2019 by Delphix. All rights reserved.
24+
* Copyright (c) 2023, 2024, Klara Inc.
25+
*/
26+
27+
#ifndef _ABD_IMPL_OS_H
28+
#define _ABD_IMPL_OS_H
29+
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
34+
#define abd_enter_critical(flags) local_irq_save(flags)
35+
#define abd_exit_critical(flags) local_irq_restore(flags)
36+
37+
#ifdef __cplusplus
38+
}
39+
#endif
40+
41+
#endif /* _ABD_IMPL_OS_H */

include/os/linux/zfs/sys/abd_os.h

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
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+
/*
22+
* Copyright (c) 2014 by Chunwei Chen. All rights reserved.
23+
* Copyright (c) 2016, 2019 by Delphix. All rights reserved.
24+
*/
25+
26+
#ifndef _ABD_OS_H
27+
#define _ABD_OS_H
28+
29+
#ifdef __cplusplus
30+
extern "C" {
31+
#endif
32+
33+
struct abd_scatter {
34+
uint_t abd_offset;
35+
uint_t abd_nents;
36+
struct scatterlist *abd_sgl;
37+
};
38+
39+
struct abd_linear {
40+
void *abd_buf;
41+
struct scatterlist *abd_sgl; /* for LINEAR_PAGE */
42+
};
43+
44+
typedef struct abd abd_t;
45+
46+
typedef int abd_iter_page_func_t(struct page *, size_t, size_t, void *);
47+
int abd_iterate_page_func(abd_t *, size_t, size_t, abd_iter_page_func_t *,
48+
void *);
49+
50+
/*
51+
* Linux ABD bio functions
52+
* Note: these are only needed to support vdev_classic. See comment in
53+
* vdev_disk.c.
54+
*/
55+
unsigned int abd_bio_map_off(struct bio *, abd_t *, unsigned int, size_t);
56+
unsigned long abd_nr_pages_off(abd_t *, unsigned int, size_t);
57+
58+
#ifdef __cplusplus
59+
}
60+
#endif
61+
62+
#endif /* _ABD_H */

include/sys/abd.h

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <sys/debug.h>
3131
#include <sys/zfs_refcount.h>
3232
#include <sys/uio.h>
33+
#include <sys/abd_os.h>
3334

3435
#ifdef __cplusplus
3536
extern "C" {
@@ -58,21 +59,8 @@ typedef struct abd {
5859
#endif
5960
kmutex_t abd_mtx;
6061
union {
61-
struct abd_scatter {
62-
uint_t abd_offset;
63-
#if defined(__FreeBSD__) && defined(_KERNEL)
64-
void *abd_chunks[1]; /* actually variable-length */
65-
#else
66-
uint_t abd_nents;
67-
struct scatterlist *abd_sgl;
68-
#endif
69-
} abd_scatter;
70-
struct abd_linear {
71-
void *abd_buf;
72-
#if defined(__linux__) && defined(_KERNEL)
73-
struct scatterlist *abd_sgl; /* for LINEAR_PAGE */
74-
#endif
75-
} abd_linear;
62+
struct abd_scatter abd_scatter;
63+
struct abd_linear abd_linear;
7664
struct abd_gang {
7765
list_t abd_gang_chain;
7866
} abd_gang;
@@ -81,9 +69,6 @@ typedef struct abd {
8169

8270
typedef int abd_iter_func_t(void *buf, size_t len, void *priv);
8371
typedef int abd_iter_func2_t(void *bufa, void *bufb, size_t len, void *priv);
84-
#if defined(__linux__) && defined(_KERNEL)
85-
typedef int abd_iter_page_func_t(struct page *, size_t, size_t, void *);
86-
#endif
8772

8873
extern int zfs_abd_scatter_enabled;
8974

@@ -130,10 +115,6 @@ void abd_release_ownership_of_buf(abd_t *);
130115
int abd_iterate_func(abd_t *, size_t, size_t, abd_iter_func_t *, void *);
131116
int abd_iterate_func2(abd_t *, abd_t *, size_t, size_t, size_t,
132117
abd_iter_func2_t *, void *);
133-
#if defined(__linux__) && defined(_KERNEL)
134-
int abd_iterate_page_func(abd_t *, size_t, size_t, abd_iter_page_func_t *,
135-
void *);
136-
#endif
137118
void abd_copy_off(abd_t *, abd_t *, size_t, size_t, size_t);
138119
void abd_copy_from_buf_off(abd_t *, const void *, size_t, size_t);
139120
void abd_copy_to_buf_off(void *, abd_t *, size_t, size_t);
@@ -220,16 +201,6 @@ abd_get_size(abd_t *abd)
220201
void abd_init(void);
221202
void abd_fini(void);
222203

223-
/*
224-
* Linux ABD bio functions
225-
* Note: these are only needed to support vdev_classic. See comment in
226-
* vdev_disk.c.
227-
*/
228-
#if defined(__linux__) && defined(_KERNEL)
229-
unsigned int abd_bio_map_off(struct bio *, abd_t *, unsigned int, size_t);
230-
unsigned long abd_nr_pages_off(abd_t *, unsigned int, size_t);
231-
#endif
232-
233204
#ifdef __cplusplus
234205
}
235206
#endif

include/sys/abd_impl.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#define _ABD_IMPL_H
2929

3030
#include <sys/abd.h>
31+
#include <sys/abd_impl_os.h>
3132
#include <sys/wmsum.h>
3233

3334
#ifdef __cplusplus
@@ -111,19 +112,6 @@ void abd_iter_page(struct abd_iter *);
111112
#define ABD_LINEAR_BUF(abd) (abd->abd_u.abd_linear.abd_buf)
112113
#define ABD_GANG(abd) (abd->abd_u.abd_gang)
113114

114-
#if defined(_KERNEL)
115-
#if defined(__FreeBSD__)
116-
#define abd_enter_critical(flags) critical_enter()
117-
#define abd_exit_critical(flags) critical_exit()
118-
#else
119-
#define abd_enter_critical(flags) local_irq_save(flags)
120-
#define abd_exit_critical(flags) local_irq_restore(flags)
121-
#endif
122-
#else /* !_KERNEL */
123-
#define abd_enter_critical(flags) ((void)0)
124-
#define abd_exit_critical(flags) ((void)0)
125-
#endif
126-
127115
#ifdef __cplusplus
128116
}
129117
#endif

lib/libzpool/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
include $(srcdir)/%D%/include/Makefile.am
2+
13
libzpool_la_CFLAGS = $(AM_CFLAGS) $(KERNEL_CFLAGS) $(LIBRARY_CFLAGS)
24
libzpool_la_CFLAGS += $(ZLIB_CFLAGS)
35

lib/libzpool/include/Makefile.am

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
libzpooldir = $(includedir)/libzpool
2+
libzpool_HEADERS = \
3+
%D%/sys/abd_os.h \
4+
%D%/sys/abd_impl_os.h
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
/*
22+
* Copyright (c) 2014 by Chunwei Chen. All rights reserved.
23+
* Copyright (c) 2016, 2019 by Delphix. All rights reserved.
24+
* Copyright (c) 2023, 2024, Klara Inc.
25+
*/
26+
27+
#ifndef _ABD_IMPL_OS_H
28+
#define _ABD_IMPL_OS_H
29+
30+
#ifdef __cplusplus
31+
extern "C" {
32+
#endif
33+
34+
#define abd_enter_critical(flags) ((void)0)
35+
#define abd_exit_critical(flags) ((void)0)
36+
37+
#ifdef __cplusplus
38+
}
39+
#endif
40+
41+
#endif /* _ABD_IMPL_OS_H */

0 commit comments

Comments
 (0)