Fix -Wuse-after-free warning in dbuf_destroy()
[zfs.git] / config / kernel-blkdev.m4
blobfb7b1a458638fc82b8ec8d5229c9a93fba38f940
1 dnl #
2 dnl # 2.6.38 API change,
3 dnl # Added blkdev_get_by_path()
4 dnl #
5 AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_GET_BY_PATH], [
6         ZFS_LINUX_TEST_SRC([blkdev_get_by_path], [
7                 #include <linux/fs.h>
8                 #include <linux/blkdev.h>
9         ], [
10                 struct block_device *bdev __attribute__ ((unused)) = NULL;
11                 const char *path = "path";
12                 fmode_t mode = 0;
13                 void *holder = NULL;
15                 bdev = blkdev_get_by_path(path, mode, holder);
16         ])
19 AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_GET_BY_PATH], [
20         AC_MSG_CHECKING([whether blkdev_get_by_path() exists])
21         ZFS_LINUX_TEST_RESULT([blkdev_get_by_path], [
22                 AC_MSG_RESULT(yes)
23         ], [
24                 ZFS_LINUX_TEST_ERROR([blkdev_get_by_path()])
25         ])
28 dnl #
29 dnl # 2.6.38 API change,
30 dnl # Added blkdev_put()
31 dnl #
32 AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_PUT], [
33         ZFS_LINUX_TEST_SRC([blkdev_put], [
34                 #include <linux/fs.h>
35                 #include <linux/blkdev.h>
36         ], [
37                 struct block_device *bdev = NULL;
38                 fmode_t mode = 0;
40                 blkdev_put(bdev, mode);
41         ])
44 AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_PUT], [
45         AC_MSG_CHECKING([whether blkdev_put() exists])
46         ZFS_LINUX_TEST_RESULT([blkdev_put], [
47                 AC_MSG_RESULT(yes)
48         ], [
49                 ZFS_LINUX_TEST_ERROR([blkdev_put()])
50         ])
53 dnl #
54 dnl # 4.1 API, exported blkdev_reread_part() symbol, back ported to the
55 dnl # 3.10.0 CentOS 7.x enterprise kernels.
56 dnl #
57 AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_REREAD_PART], [
58         ZFS_LINUX_TEST_SRC([blkdev_reread_part], [
59                 #include <linux/fs.h>
60                 #include <linux/blkdev.h>
61         ], [
62                 struct block_device *bdev = NULL;
63                 int error;
65                 error = blkdev_reread_part(bdev);
66         ])
69 AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_REREAD_PART], [
70         AC_MSG_CHECKING([whether blkdev_reread_part() exists])
71         ZFS_LINUX_TEST_RESULT([blkdev_reread_part], [
72                 AC_MSG_RESULT(yes)
73                 AC_DEFINE(HAVE_BLKDEV_REREAD_PART, 1,
74                     [blkdev_reread_part() exists])
75         ], [
76                 AC_MSG_RESULT(no)
77         ])
80 dnl #
81 dnl # check_disk_change() was removed in 5.10
82 dnl #
83 AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_CHECK_DISK_CHANGE], [
84         ZFS_LINUX_TEST_SRC([check_disk_change], [
85                 #include <linux/fs.h>
86                 #include <linux/blkdev.h>
87         ], [
88                 struct block_device *bdev = NULL;
89                 bool error;
91                 error = check_disk_change(bdev);
92         ])
95 AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_CHECK_DISK_CHANGE], [
96         AC_MSG_CHECKING([whether check_disk_change() exists])
97         ZFS_LINUX_TEST_RESULT([check_disk_change], [
98                 AC_MSG_RESULT(yes)
99                 AC_DEFINE(HAVE_CHECK_DISK_CHANGE, 1,
100                     [check_disk_change() exists])
101         ], [
102                 AC_MSG_RESULT(no)
103         ])
106 dnl #
107 dnl # 5.10 API, check_disk_change() is removed, in favor of
108 dnl # bdev_check_media_change(), which doesn't force revalidation
109 dnl #
110 AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_CHECK_MEDIA_CHANGE], [
111         ZFS_LINUX_TEST_SRC([bdev_check_media_change], [
112                 #include <linux/fs.h>
113                 #include <linux/blkdev.h>
114         ], [
115                 struct block_device *bdev = NULL;
116                 int error;
118                 error = bdev_check_media_change(bdev);
119         ])
122 AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BDEV_CHECK_MEDIA_CHANGE], [
123         AC_MSG_CHECKING([whether bdev_check_media_change() exists])
124         ZFS_LINUX_TEST_RESULT([bdev_check_media_change], [
125                 AC_MSG_RESULT(yes)
126                 AC_DEFINE(HAVE_BDEV_CHECK_MEDIA_CHANGE, 1,
127                     [bdev_check_media_change() exists])
128         ], [
129                 AC_MSG_RESULT(no)
130         ])
133 dnl #
134 dnl # 2.6.22 API change
135 dnl # Single argument invalidate_bdev()
136 dnl #
137 AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_INVALIDATE_BDEV], [
138         ZFS_LINUX_TEST_SRC([invalidate_bdev], [
139                 #include <linux/buffer_head.h>
140                 #include <linux/blkdev.h>
141         ],[
142                 struct block_device *bdev = NULL;
143                 invalidate_bdev(bdev);
144         ])
147 AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_INVALIDATE_BDEV], [
148         AC_MSG_CHECKING([whether invalidate_bdev() exists])
149         ZFS_LINUX_TEST_RESULT([invalidate_bdev], [
150                 AC_MSG_RESULT(yes)
151         ],[
152                 ZFS_LINUX_TEST_ERROR([invalidate_bdev()])
153         ])
156 dnl #
157 dnl # 5.11 API, lookup_bdev() takes dev_t argument.
158 dnl # 2.6.27 API, lookup_bdev() was first exported.
159 dnl # 4.4.0-6.21 API, lookup_bdev() on Ubuntu takes mode argument.
160 dnl #
161 AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_LOOKUP_BDEV], [
162         ZFS_LINUX_TEST_SRC([lookup_bdev_devt], [
163                 #include <linux/blkdev.h>
164         ], [
165                 int error __attribute__ ((unused));
166                 const char path[] = "/example/path";
167                 dev_t dev;
169                 error = lookup_bdev(path, &dev);
170         ])
172         ZFS_LINUX_TEST_SRC([lookup_bdev_1arg], [
173                 #include <linux/fs.h>
174                 #include <linux/blkdev.h>
175         ], [
176                 struct block_device *bdev __attribute__ ((unused));
177                 const char path[] = "/example/path";
179                 bdev = lookup_bdev(path);
180         ])
182         ZFS_LINUX_TEST_SRC([lookup_bdev_mode], [
183                 #include <linux/fs.h>
184         ], [
185                 struct block_device *bdev __attribute__ ((unused));
186                 const char path[] = "/example/path";
188                 bdev = lookup_bdev(path, FMODE_READ);
189         ])
192 AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_LOOKUP_BDEV], [
193         AC_MSG_CHECKING([whether lookup_bdev() wants dev_t arg])
194         ZFS_LINUX_TEST_RESULT_SYMBOL([lookup_bdev_devt],
195             [lookup_bdev], [fs/block_dev.c], [
196                 AC_MSG_RESULT(yes)
197                 AC_DEFINE(HAVE_DEVT_LOOKUP_BDEV, 1,
198                     [lookup_bdev() wants dev_t arg])
199         ], [
200                 AC_MSG_RESULT(no)
202                 AC_MSG_CHECKING([whether lookup_bdev() wants 1 arg])
203                 ZFS_LINUX_TEST_RESULT_SYMBOL([lookup_bdev_1arg],
204                     [lookup_bdev], [fs/block_dev.c], [
205                         AC_MSG_RESULT(yes)
206                         AC_DEFINE(HAVE_1ARG_LOOKUP_BDEV, 1,
207                             [lookup_bdev() wants 1 arg])
208                 ], [
209                         AC_MSG_RESULT(no)
211                         AC_MSG_CHECKING([whether lookup_bdev() wants mode arg])
212                         ZFS_LINUX_TEST_RESULT_SYMBOL([lookup_bdev_mode],
213                             [lookup_bdev], [fs/block_dev.c], [
214                                 AC_MSG_RESULT(yes)
215                                 AC_DEFINE(HAVE_MODE_LOOKUP_BDEV, 1,
216                                     [lookup_bdev() wants mode arg])
217                         ], [
218                                 ZFS_LINUX_TEST_ERROR([lookup_bdev()])
219                         ])
220                 ])
221         ])
224 dnl #
225 dnl # 2.6.30 API change
226 dnl #
227 dnl # The bdev_physical_block_size() interface was added to provide a way
228 dnl # to determine the smallest write which can be performed without a
229 dnl # read-modify-write operation.
230 dnl #
231 dnl # Unfortunately, this interface isn't entirely reliable because
232 dnl # drives are sometimes known to misreport this value.
233 dnl #
234 AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_PHYSICAL_BLOCK_SIZE], [
235         ZFS_LINUX_TEST_SRC([bdev_physical_block_size], [
236                 #include <linux/blkdev.h>
237         ],[
238                 struct block_device *bdev __attribute__ ((unused)) = NULL;
239                 bdev_physical_block_size(bdev);
240         ])
243 AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BDEV_PHYSICAL_BLOCK_SIZE], [
244         AC_MSG_CHECKING([whether bdev_physical_block_size() is available])
245         ZFS_LINUX_TEST_RESULT([bdev_physical_block_size], [
246                 AC_MSG_RESULT(yes)
247         ],[
248                 ZFS_LINUX_TEST_ERROR([bdev_physical_block_size()])
249         ])
252 dnl #
253 dnl # 2.6.30 API change
254 dnl # Added bdev_logical_block_size().
255 dnl #
256 AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_LOGICAL_BLOCK_SIZE], [
257         ZFS_LINUX_TEST_SRC([bdev_logical_block_size], [
258                 #include <linux/blkdev.h>
259         ],[
260                 struct block_device *bdev __attribute__ ((unused)) = NULL;
261                 bdev_logical_block_size(bdev);
262         ])
265 AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BDEV_LOGICAL_BLOCK_SIZE], [
266         AC_MSG_CHECKING([whether bdev_logical_block_size() is available])
267         ZFS_LINUX_TEST_RESULT([bdev_logical_block_size], [
268                 AC_MSG_RESULT(yes)
269         ],[
270                 ZFS_LINUX_TEST_ERROR([bdev_logical_block_size()])
271         ])
274 dnl #
275 dnl # 5.11 API change
276 dnl # Added bdev_whole() helper.
277 dnl #
278 AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_WHOLE], [
279         ZFS_LINUX_TEST_SRC([bdev_whole], [
280                 #include <linux/blkdev.h>
281         ],[
282                 struct block_device *bdev = NULL;
283                 bdev = bdev_whole(bdev);
284         ])
287 AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BDEV_WHOLE], [
288         AC_MSG_CHECKING([whether bdev_whole() is available])
289         ZFS_LINUX_TEST_RESULT([bdev_whole], [
290                 AC_MSG_RESULT(yes)
291                 AC_DEFINE(HAVE_BDEV_WHOLE, 1, [bdev_whole() is available])
292         ],[
293                 AC_MSG_RESULT(no)
294         ])
297 dnl #
298 dnl # 5.19 API: blkdev_issue_secure_erase()
299 dnl # 3.10 API: blkdev_issue_discard(..., BLKDEV_DISCARD_SECURE)
300 dnl #
301 AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_ISSUE_SECURE_ERASE], [
302         ZFS_LINUX_TEST_SRC([blkdev_issue_secure_erase], [
303                 #include <linux/blkdev.h>
304         ],[
305                 struct block_device *bdev = NULL;
306                 sector_t sector = 0;
307                 sector_t nr_sects = 0;
308                 int error __attribute__ ((unused));
310                 error = blkdev_issue_secure_erase(bdev,
311                     sector, nr_sects, GFP_KERNEL);
312         ])
314         ZFS_LINUX_TEST_SRC([blkdev_issue_discard_flags], [
315                 #include <linux/blkdev.h>
316         ],[
317                 struct block_device *bdev = NULL;
318                 sector_t sector = 0;
319                 sector_t nr_sects = 0;
320                 unsigned long flags = 0;
321                 int error __attribute__ ((unused));
323                 error = blkdev_issue_discard(bdev,
324                     sector, nr_sects, GFP_KERNEL, flags);
325         ])
328 AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_ISSUE_SECURE_ERASE], [
329         AC_MSG_CHECKING([whether blkdev_issue_secure_erase() is available])
330         ZFS_LINUX_TEST_RESULT([blkdev_issue_secure_erase], [
331                 AC_MSG_RESULT(yes)
332                 AC_DEFINE(HAVE_BLKDEV_ISSUE_SECURE_ERASE, 1,
333                     [blkdev_issue_secure_erase() is available])
334         ],[
335                 AC_MSG_RESULT(no)
337                 AC_MSG_CHECKING([whether blkdev_issue_discard() is available])
338                 ZFS_LINUX_TEST_RESULT([blkdev_issue_discard_flags], [
339                         AC_MSG_RESULT(yes)
340                         AC_DEFINE(HAVE_BLKDEV_ISSUE_DISCARD, 1,
341                             [blkdev_issue_discard() is available])
342                 ],[
343                         ZFS_LINUX_TEST_ERROR([blkdev_issue_discard()])
344                 ])
345         ])
348 dnl #
349 dnl # 5.13 API change
350 dnl # blkdev_get_by_path() no longer handles ERESTARTSYS
351 dnl #
352 dnl # Unfortunately we're forced to rely solely on the kernel version
353 dnl # number in order to determine the expected behavior.  This was an
354 dnl # internal change to blkdev_get_by_dev(), see commit a8ed1a0607.
355 dnl #
356 AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_GET_ERESTARTSYS], [
357         AC_MSG_CHECKING([whether blkdev_get_by_path() handles ERESTARTSYS])
358         AS_VERSION_COMPARE([$LINUX_VERSION], [5.13.0], [
359                 AC_MSG_RESULT(yes)
360                 AC_DEFINE(HAVE_BLKDEV_GET_ERESTARTSYS, 1,
361                         [blkdev_get_by_path() handles ERESTARTSYS])
362         ],[
363                 AC_MSG_RESULT(no)
364         ],[
365                 AC_MSG_RESULT(no)
366         ])
369 AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV], [
370         ZFS_AC_KERNEL_SRC_BLKDEV_GET_BY_PATH
371         ZFS_AC_KERNEL_SRC_BLKDEV_PUT
372         ZFS_AC_KERNEL_SRC_BLKDEV_REREAD_PART
373         ZFS_AC_KERNEL_SRC_BLKDEV_INVALIDATE_BDEV
374         ZFS_AC_KERNEL_SRC_BLKDEV_LOOKUP_BDEV
375         ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_LOGICAL_BLOCK_SIZE
376         ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_PHYSICAL_BLOCK_SIZE
377         ZFS_AC_KERNEL_SRC_BLKDEV_CHECK_DISK_CHANGE
378         ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_CHECK_MEDIA_CHANGE
379         ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_WHOLE
380         ZFS_AC_KERNEL_SRC_BLKDEV_ISSUE_SECURE_ERASE
383 AC_DEFUN([ZFS_AC_KERNEL_BLKDEV], [
384         ZFS_AC_KERNEL_BLKDEV_GET_BY_PATH
385         ZFS_AC_KERNEL_BLKDEV_PUT
386         ZFS_AC_KERNEL_BLKDEV_REREAD_PART
387         ZFS_AC_KERNEL_BLKDEV_INVALIDATE_BDEV
388         ZFS_AC_KERNEL_BLKDEV_LOOKUP_BDEV
389         ZFS_AC_KERNEL_BLKDEV_BDEV_LOGICAL_BLOCK_SIZE
390         ZFS_AC_KERNEL_BLKDEV_BDEV_PHYSICAL_BLOCK_SIZE
391         ZFS_AC_KERNEL_BLKDEV_CHECK_DISK_CHANGE
392         ZFS_AC_KERNEL_BLKDEV_BDEV_CHECK_MEDIA_CHANGE
393         ZFS_AC_KERNEL_BLKDEV_BDEV_WHOLE
394         ZFS_AC_KERNEL_BLKDEV_GET_ERESTARTSYS
395         ZFS_AC_KERNEL_BLKDEV_ISSUE_SECURE_ERASE