Skip to content

Commit 5b9e695

Browse files
robnbehlendorf
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 #16253
1 parent 7a5b435 commit 5b9e695

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
@@ -77,6 +77,8 @@ noinst_HEADERS = \
7777
%D%/spl/sys/zmod.h \
7878
%D%/spl/sys/zone.h \
7979
\
80+
%D%/zfs/sys/abd_os.h \
81+
%D%/zfs/sys/abd_impl_os.h \
8082
%D%/zfs/sys/arc_os.h \
8183
%D%/zfs/sys/freebsd_crypto.h \
8284
%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
@@ -20,6 +20,8 @@ kernel_linux_HEADERS = \
2020

2121
kernel_sysdir = $(kerneldir)/sys
2222
kernel_sys_HEADERS = \
23+
%D%/zfs/sys/abd_os.h \
24+
%D%/zfs/sys/abd_impl_os.h \
2325
%D%/zfs/sys/policy.h \
2426
%D%/zfs/sys/trace_acl.h \
2527
%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" {
@@ -57,21 +58,8 @@ typedef struct abd {
5758
#endif
5859
kmutex_t abd_mtx;
5960
union {
60-
struct abd_scatter {
61-
uint_t abd_offset;
62-
#if defined(__FreeBSD__) && defined(_KERNEL)
63-
void *abd_chunks[1]; /* actually variable-length */
64-
#else
65-
uint_t abd_nents;
66-
struct scatterlist *abd_sgl;
67-
#endif
68-
} abd_scatter;
69-
struct abd_linear {
70-
void *abd_buf;
71-
#if defined(__linux__) && defined(_KERNEL)
72-
struct scatterlist *abd_sgl; /* for LINEAR_PAGE */
73-
#endif
74-
} abd_linear;
61+
struct abd_scatter abd_scatter;
62+
struct abd_linear abd_linear;
7563
struct abd_gang {
7664
list_t abd_gang_chain;
7765
} abd_gang;
@@ -80,9 +68,6 @@ typedef struct abd {
8068

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

8772
extern int zfs_abd_scatter_enabled;
8873

@@ -129,10 +114,6 @@ void abd_release_ownership_of_buf(abd_t *);
129114
int abd_iterate_func(abd_t *, size_t, size_t, abd_iter_func_t *, void *);
130115
int abd_iterate_func2(abd_t *, abd_t *, size_t, size_t, size_t,
131116
abd_iter_func2_t *, void *);
132-
#if defined(__linux__) && defined(_KERNEL)
133-
int abd_iterate_page_func(abd_t *, size_t, size_t, abd_iter_page_func_t *,
134-
void *);
135-
#endif
136117
void abd_copy_off(abd_t *, abd_t *, size_t, size_t, size_t);
137118
void abd_copy_from_buf_off(abd_t *, const void *, size_t, size_t);
138119
void abd_copy_to_buf_off(void *, abd_t *, size_t, size_t);
@@ -226,16 +207,6 @@ abd_get_size(abd_t *abd)
226207
void abd_init(void);
227208
void abd_fini(void);
228209

229-
/*
230-
* Linux ABD bio functions
231-
* Note: these are only needed to support vdev_classic. See comment in
232-
* vdev_disk.c.
233-
*/
234-
#if defined(__linux__) && defined(_KERNEL)
235-
unsigned int abd_bio_map_off(struct bio *, abd_t *, unsigned int, size_t);
236-
unsigned long abd_nr_pages_off(abd_t *, unsigned int, size_t);
237-
#endif
238-
239210
#ifdef __cplusplus
240211
}
241212
#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)