xref: /freebsd/sys/contrib/openzfs/config/kernel-blkdev.m4 (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
1dnl #
2dnl # 2.6.38 API change,
3dnl # Added blkdev_get_by_path()
4dnl #
5AC_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;
14
15		bdev = blkdev_get_by_path(path, mode, holder);
16	])
17])
18
19dnl #
20dnl # 6.5.x API change,
21dnl # blkdev_get_by_path() takes 4 args
22dnl #
23AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_GET_BY_PATH_4ARG], [
24	ZFS_LINUX_TEST_SRC([blkdev_get_by_path_4arg], [
25		#include <linux/fs.h>
26		#include <linux/blkdev.h>
27	], [
28		struct block_device *bdev __attribute__ ((unused)) = NULL;
29		const char *path = "path";
30		fmode_t mode = 0;
31		void *holder = NULL;
32		struct blk_holder_ops h;
33
34		bdev = blkdev_get_by_path(path, mode, holder, &h);
35	])
36])
37
38dnl #
39dnl # 6.8.x API change
40dnl # bdev_open_by_path() replaces blkdev_get_by_path()
41dnl #
42AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_OPEN_BY_PATH], [
43	ZFS_LINUX_TEST_SRC([bdev_open_by_path], [
44		#include <linux/fs.h>
45		#include <linux/blkdev.h>
46	], [
47		struct bdev_handle *bdh __attribute__ ((unused)) = NULL;
48		const char *path = "path";
49		fmode_t mode = 0;
50		void *holder = NULL;
51		struct blk_holder_ops h;
52
53		bdh = bdev_open_by_path(path, mode, holder, &h);
54	])
55])
56
57dnl #
58dnl # 6.9.x API change
59dnl # bdev_file_open_by_path() replaced bdev_open_by_path(),
60dnl # and returns struct file*
61dnl #
62AC_DEFUN([ZFS_AC_KERNEL_SRC_BDEV_FILE_OPEN_BY_PATH], [
63	ZFS_LINUX_TEST_SRC([bdev_file_open_by_path], [
64		#include <linux/fs.h>
65		#include <linux/blkdev.h>
66	], [
67		struct file *file __attribute__ ((unused)) = NULL;
68		const char *path = "path";
69		fmode_t mode = 0;
70		void *holder = NULL;
71		struct blk_holder_ops h;
72
73		file = bdev_file_open_by_path(path, mode, holder, &h);
74	])
75])
76
77AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_GET_BY_PATH], [
78	AC_MSG_CHECKING([whether blkdev_get_by_path() exists and takes 3 args])
79	ZFS_LINUX_TEST_RESULT([blkdev_get_by_path], [
80		AC_MSG_RESULT(yes)
81	], [
82		AC_MSG_RESULT(no)
83		AC_MSG_CHECKING([whether blkdev_get_by_path() exists and takes 4 args])
84		ZFS_LINUX_TEST_RESULT([blkdev_get_by_path_4arg], [
85			AC_DEFINE(HAVE_BLKDEV_GET_BY_PATH_4ARG, 1,
86				[blkdev_get_by_path() exists and takes 4 args])
87			AC_MSG_RESULT(yes)
88		], [
89			AC_MSG_RESULT(no)
90			AC_MSG_CHECKING([whether bdev_open_by_path() exists])
91			ZFS_LINUX_TEST_RESULT([bdev_open_by_path], [
92				AC_DEFINE(HAVE_BDEV_OPEN_BY_PATH, 1,
93					[bdev_open_by_path() exists])
94				AC_MSG_RESULT(yes)
95			], [
96				AC_MSG_RESULT(no)
97				AC_MSG_CHECKING([whether bdev_file_open_by_path() exists])
98				ZFS_LINUX_TEST_RESULT([bdev_file_open_by_path], [
99					AC_DEFINE(HAVE_BDEV_FILE_OPEN_BY_PATH, 1,
100						[bdev_file_open_by_path() exists])
101					AC_MSG_RESULT(yes)
102				], [
103					AC_MSG_RESULT(no)
104					ZFS_LINUX_TEST_ERROR([blkdev_get_by_path()])
105				])
106			])
107		])
108	])
109])
110
111dnl #
112dnl # 6.5.x API change
113dnl # blk_mode_t was added as a type to supercede some places where fmode_t
114dnl # is used
115dnl #
116AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BLK_MODE_T], [
117	ZFS_LINUX_TEST_SRC([blk_mode_t], [
118		#include <linux/fs.h>
119		#include <linux/blkdev.h>
120	], [
121		blk_mode_t m __attribute((unused)) = (blk_mode_t)0;
122	])
123])
124
125AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BLK_MODE_T], [
126	AC_MSG_CHECKING([whether blk_mode_t is defined])
127	ZFS_LINUX_TEST_RESULT([blk_mode_t], [
128		AC_MSG_RESULT(yes)
129		AC_DEFINE(HAVE_BLK_MODE_T, 1, [blk_mode_t is defined])
130	], [
131		AC_MSG_RESULT(no)
132	])
133])
134
135dnl #
136dnl # 2.6.38 API change,
137dnl # Added blkdev_put()
138dnl #
139AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_PUT], [
140	ZFS_LINUX_TEST_SRC([blkdev_put], [
141		#include <linux/fs.h>
142		#include <linux/blkdev.h>
143	], [
144		struct block_device *bdev = NULL;
145		fmode_t mode = 0;
146
147		blkdev_put(bdev, mode);
148	])
149])
150
151dnl #
152dnl # 6.5.x API change.
153dnl # blkdev_put() takes (void* holder) as arg 2
154dnl #
155AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_PUT_HOLDER], [
156	ZFS_LINUX_TEST_SRC([blkdev_put_holder], [
157		#include <linux/fs.h>
158		#include <linux/blkdev.h>
159	], [
160		struct block_device *bdev = NULL;
161		void *holder = NULL;
162
163		blkdev_put(bdev, holder);
164	])
165])
166
167dnl #
168dnl # 6.8.x API change
169dnl # bdev_release() replaces blkdev_put()
170dnl #
171AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_RELEASE], [
172	ZFS_LINUX_TEST_SRC([bdev_release], [
173		#include <linux/fs.h>
174		#include <linux/blkdev.h>
175	], [
176		struct bdev_handle *bdh = NULL;
177		bdev_release(bdh);
178	])
179])
180
181dnl #
182dnl # 6.9.x API change
183dnl #
184dnl # bdev_release() now private, but because bdev_file_open_by_path() returns
185dnl # struct file*, we can just use fput(). So the blkdev_put test no longer
186dnl # fails if not found.
187dnl #
188
189AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_PUT], [
190	AC_MSG_CHECKING([whether blkdev_put() exists])
191	ZFS_LINUX_TEST_RESULT([blkdev_put], [
192		AC_MSG_RESULT(yes)
193		AC_DEFINE(HAVE_BLKDEV_PUT, 1, [blkdev_put() exists])
194	], [
195		AC_MSG_RESULT(no)
196		AC_MSG_CHECKING([whether blkdev_put() accepts void* as arg 2])
197		ZFS_LINUX_TEST_RESULT([blkdev_put_holder], [
198			AC_MSG_RESULT(yes)
199			AC_DEFINE(HAVE_BLKDEV_PUT_HOLDER, 1,
200				[blkdev_put() accepts void* as arg 2])
201		], [
202			AC_MSG_RESULT(no)
203			AC_MSG_CHECKING([whether bdev_release() exists])
204			ZFS_LINUX_TEST_RESULT([bdev_release], [
205				AC_MSG_RESULT(yes)
206				AC_DEFINE(HAVE_BDEV_RELEASE, 1,
207					[bdev_release() exists])
208			], [
209				AC_MSG_RESULT(no)
210			])
211		])
212	])
213])
214
215dnl #
216dnl # 4.1 API, exported blkdev_reread_part() symbol, back ported to the
217dnl # 3.10.0 CentOS 7.x enterprise kernels.
218dnl #
219AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_REREAD_PART], [
220	ZFS_LINUX_TEST_SRC([blkdev_reread_part], [
221		#include <linux/fs.h>
222		#include <linux/blkdev.h>
223	], [
224		struct block_device *bdev = NULL;
225		int error;
226
227		error = blkdev_reread_part(bdev);
228	])
229])
230
231AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_REREAD_PART], [
232	AC_MSG_CHECKING([whether blkdev_reread_part() exists])
233	ZFS_LINUX_TEST_RESULT([blkdev_reread_part], [
234		AC_MSG_RESULT(yes)
235		AC_DEFINE(HAVE_BLKDEV_REREAD_PART, 1,
236		    [blkdev_reread_part() exists])
237	], [
238		AC_MSG_RESULT(no)
239	])
240])
241
242dnl #
243dnl # check_disk_change() was removed in 5.10
244dnl #
245AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_CHECK_DISK_CHANGE], [
246	ZFS_LINUX_TEST_SRC([check_disk_change], [
247		#include <linux/fs.h>
248		#include <linux/blkdev.h>
249	], [
250		struct block_device *bdev = NULL;
251		bool error;
252
253		error = check_disk_change(bdev);
254	])
255])
256
257AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_CHECK_DISK_CHANGE], [
258	AC_MSG_CHECKING([whether check_disk_change() exists])
259	ZFS_LINUX_TEST_RESULT([check_disk_change], [
260		AC_MSG_RESULT(yes)
261		AC_DEFINE(HAVE_CHECK_DISK_CHANGE, 1,
262		    [check_disk_change() exists])
263	], [
264		AC_MSG_RESULT(no)
265	])
266])
267
268dnl #
269dnl # 6.5.x API change
270dnl # disk_check_media_change() was added
271dnl #
272AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_DISK_CHECK_MEDIA_CHANGE], [
273	ZFS_LINUX_TEST_SRC([disk_check_media_change], [
274		#include <linux/fs.h>
275		#include <linux/blkdev.h>
276	], [
277		struct block_device *bdev = NULL;
278		bool error;
279
280		error = disk_check_media_change(bdev->bd_disk);
281	])
282])
283
284AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_DISK_CHECK_MEDIA_CHANGE], [
285	AC_MSG_CHECKING([whether disk_check_media_change() exists])
286	ZFS_LINUX_TEST_RESULT([disk_check_media_change], [
287		AC_MSG_RESULT(yes)
288		AC_DEFINE(HAVE_DISK_CHECK_MEDIA_CHANGE, 1,
289		    [disk_check_media_change() exists])
290	], [
291		AC_MSG_RESULT(no)
292	])
293])
294
295dnl #
296dnl # bdev_kobj() is introduced from 5.12
297dnl #
298AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_KOBJ], [
299	ZFS_LINUX_TEST_SRC([bdev_kobj], [
300		#include <linux/fs.h>
301		#include <linux/blkdev.h>
302		#include <linux/kobject.h>
303	], [
304		struct block_device *bdev = NULL;
305		struct kobject *disk_kobj;
306		disk_kobj = bdev_kobj(bdev);
307	])
308])
309
310AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BDEV_KOBJ], [
311	AC_MSG_CHECKING([whether bdev_kobj() exists])
312	ZFS_LINUX_TEST_RESULT([bdev_kobj], [
313		AC_MSG_RESULT(yes)
314		AC_DEFINE(HAVE_BDEV_KOBJ, 1,
315		    [bdev_kobj() exists])
316	], [
317		AC_MSG_RESULT(no)
318	])
319])
320
321dnl #
322dnl # part_to_dev() was removed in 5.12
323dnl #
324AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_PART_TO_DEV], [
325	ZFS_LINUX_TEST_SRC([part_to_dev], [
326		#include <linux/fs.h>
327		#include <linux/blkdev.h>
328	], [
329		struct hd_struct *p = NULL;
330		struct device *pdev;
331		pdev = part_to_dev(p);
332	])
333])
334
335AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_PART_TO_DEV], [
336	AC_MSG_CHECKING([whether part_to_dev() exists])
337	ZFS_LINUX_TEST_RESULT([part_to_dev], [
338		AC_MSG_RESULT(yes)
339		AC_DEFINE(HAVE_PART_TO_DEV, 1,
340		    [part_to_dev() exists])
341	], [
342		AC_MSG_RESULT(no)
343	])
344])
345
346dnl #
347dnl # 5.10 API, check_disk_change() is removed, in favor of
348dnl # bdev_check_media_change(), which doesn't force revalidation
349dnl #
350AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_CHECK_MEDIA_CHANGE], [
351	ZFS_LINUX_TEST_SRC([bdev_check_media_change], [
352		#include <linux/fs.h>
353		#include <linux/blkdev.h>
354	], [
355		struct block_device *bdev = NULL;
356		int error;
357
358		error = bdev_check_media_change(bdev);
359	])
360])
361
362AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BDEV_CHECK_MEDIA_CHANGE], [
363	AC_MSG_CHECKING([whether bdev_check_media_change() exists])
364	ZFS_LINUX_TEST_RESULT([bdev_check_media_change], [
365		AC_MSG_RESULT(yes)
366		AC_DEFINE(HAVE_BDEV_CHECK_MEDIA_CHANGE, 1,
367		    [bdev_check_media_change() exists])
368	], [
369		AC_MSG_RESULT(no)
370	])
371])
372
373dnl #
374dnl # 2.6.22 API change
375dnl # Single argument invalidate_bdev()
376dnl #
377AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_INVALIDATE_BDEV], [
378	ZFS_LINUX_TEST_SRC([invalidate_bdev], [
379		#include <linux/buffer_head.h>
380		#include <linux/blkdev.h>
381	],[
382		struct block_device *bdev = NULL;
383		invalidate_bdev(bdev);
384	])
385])
386
387AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_INVALIDATE_BDEV], [
388	AC_MSG_CHECKING([whether invalidate_bdev() exists])
389	ZFS_LINUX_TEST_RESULT([invalidate_bdev], [
390		AC_MSG_RESULT(yes)
391	],[
392		ZFS_LINUX_TEST_ERROR([invalidate_bdev()])
393	])
394])
395
396dnl #
397dnl # 5.11 API, lookup_bdev() takes dev_t argument.
398dnl # 2.6.27 API, lookup_bdev() was first exported.
399dnl #
400AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_LOOKUP_BDEV], [
401	ZFS_LINUX_TEST_SRC([lookup_bdev_devt], [
402		#include <linux/blkdev.h>
403	], [
404		int error __attribute__ ((unused));
405		const char path[] = "/example/path";
406		dev_t dev;
407
408		error = lookup_bdev(path, &dev);
409	])
410
411	ZFS_LINUX_TEST_SRC([lookup_bdev_1arg], [
412		#include <linux/fs.h>
413		#include <linux/blkdev.h>
414	], [
415		struct block_device *bdev __attribute__ ((unused));
416		const char path[] = "/example/path";
417
418		bdev = lookup_bdev(path);
419	])
420])
421
422AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_LOOKUP_BDEV], [
423	AC_MSG_CHECKING([whether lookup_bdev() wants dev_t arg])
424	ZFS_LINUX_TEST_RESULT_SYMBOL([lookup_bdev_devt],
425	    [lookup_bdev], [fs/block_dev.c], [
426		AC_MSG_RESULT(yes)
427		AC_DEFINE(HAVE_DEVT_LOOKUP_BDEV, 1,
428		    [lookup_bdev() wants dev_t arg])
429	], [
430		AC_MSG_RESULT(no)
431
432		AC_MSG_CHECKING([whether lookup_bdev() wants 1 arg])
433		ZFS_LINUX_TEST_RESULT_SYMBOL([lookup_bdev_1arg],
434		    [lookup_bdev], [fs/block_dev.c], [
435			AC_MSG_RESULT(yes)
436			AC_DEFINE(HAVE_1ARG_LOOKUP_BDEV, 1,
437			    [lookup_bdev() wants 1 arg])
438		], [
439			ZFS_LINUX_TEST_ERROR([lookup_bdev()])
440		])
441	])
442])
443
444dnl #
445dnl # 2.6.30 API change
446dnl #
447dnl # The bdev_physical_block_size() interface was added to provide a way
448dnl # to determine the smallest write which can be performed without a
449dnl # read-modify-write operation.
450dnl #
451dnl # Unfortunately, this interface isn't entirely reliable because
452dnl # drives are sometimes known to misreport this value.
453dnl #
454AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_PHYSICAL_BLOCK_SIZE], [
455	ZFS_LINUX_TEST_SRC([bdev_physical_block_size], [
456		#include <linux/blkdev.h>
457	],[
458		struct block_device *bdev __attribute__ ((unused)) = NULL;
459		bdev_physical_block_size(bdev);
460	])
461])
462
463AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BDEV_PHYSICAL_BLOCK_SIZE], [
464	AC_MSG_CHECKING([whether bdev_physical_block_size() is available])
465	ZFS_LINUX_TEST_RESULT([bdev_physical_block_size], [
466		AC_MSG_RESULT(yes)
467	],[
468		ZFS_LINUX_TEST_ERROR([bdev_physical_block_size()])
469	])
470])
471
472dnl #
473dnl # 2.6.30 API change
474dnl # Added bdev_logical_block_size().
475dnl #
476AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_LOGICAL_BLOCK_SIZE], [
477	ZFS_LINUX_TEST_SRC([bdev_logical_block_size], [
478		#include <linux/blkdev.h>
479	],[
480		struct block_device *bdev __attribute__ ((unused)) = NULL;
481		bdev_logical_block_size(bdev);
482	])
483])
484
485AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BDEV_LOGICAL_BLOCK_SIZE], [
486	AC_MSG_CHECKING([whether bdev_logical_block_size() is available])
487	ZFS_LINUX_TEST_RESULT([bdev_logical_block_size], [
488		AC_MSG_RESULT(yes)
489	],[
490		ZFS_LINUX_TEST_ERROR([bdev_logical_block_size()])
491	])
492])
493
494dnl #
495dnl # 5.11 API change
496dnl # Added bdev_whole() helper.
497dnl #
498AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_WHOLE], [
499	ZFS_LINUX_TEST_SRC([bdev_whole], [
500		#include <linux/blkdev.h>
501	],[
502		struct block_device *bdev = NULL;
503		bdev = bdev_whole(bdev);
504	])
505])
506
507AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BDEV_WHOLE], [
508	AC_MSG_CHECKING([whether bdev_whole() is available])
509	ZFS_LINUX_TEST_RESULT([bdev_whole], [
510		AC_MSG_RESULT(yes)
511		AC_DEFINE(HAVE_BDEV_WHOLE, 1, [bdev_whole() is available])
512	],[
513		AC_MSG_RESULT(no)
514	])
515])
516
517dnl #
518dnl # 5.16 API change
519dnl # Added bdev_nr_bytes() helper.
520dnl #
521AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_NR_BYTES], [
522	ZFS_LINUX_TEST_SRC([bdev_nr_bytes], [
523		#include <linux/blkdev.h>
524	],[
525		struct block_device *bdev = NULL;
526		loff_t nr_bytes __attribute__ ((unused)) = 0;
527		nr_bytes = bdev_nr_bytes(bdev);
528	])
529])
530
531AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BDEV_NR_BYTES], [
532	AC_MSG_CHECKING([whether bdev_nr_bytes() is available])
533	ZFS_LINUX_TEST_RESULT([bdev_nr_bytes], [
534		AC_MSG_RESULT(yes)
535		AC_DEFINE(HAVE_BDEV_NR_BYTES, 1, [bdev_nr_bytes() is available])
536	],[
537		AC_MSG_RESULT(no)
538	])
539])
540
541dnl #
542dnl # 5.20 API change,
543dnl # Removed bdevname(), snprintf(.., %pg) should be used.
544dnl #
545AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEVNAME], [
546	ZFS_LINUX_TEST_SRC([bdevname], [
547		#include <linux/fs.h>
548		#include <linux/blkdev.h>
549	], [
550		struct block_device *bdev __attribute__ ((unused)) = NULL;
551		char path[BDEVNAME_SIZE];
552
553		(void) bdevname(bdev, path);
554	])
555])
556
557AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BDEVNAME], [
558	AC_MSG_CHECKING([whether bdevname() exists])
559	ZFS_LINUX_TEST_RESULT([bdevname], [
560		AC_DEFINE(HAVE_BDEVNAME, 1, [bdevname() is available])
561		AC_MSG_RESULT(yes)
562	], [
563		AC_MSG_RESULT(no)
564	])
565])
566
567dnl #
568dnl # TRIM support: discard and secure erase. We make use of asynchronous
569dnl #               functions when available.
570dnl #
571dnl # 3.10:
572dnl #   sync discard:  blkdev_issue_discard(..., 0)
573dnl #   sync erase:    blkdev_issue_discard(..., BLKDEV_DISCARD_SECURE)
574dnl #   async discard: [not available]
575dnl #   async erase:   [not available]
576dnl #
577dnl # 4.7:
578dnl #   sync discard:  blkdev_issue_discard(..., 0)
579dnl #   sync erase:    blkdev_issue_discard(..., BLKDEV_DISCARD_SECURE)
580dnl #   async discard: __blkdev_issue_discard(..., 0)
581dnl #   async erase:   __blkdev_issue_discard(..., BLKDEV_DISCARD_SECURE)
582dnl #
583dnl # 5.19:
584dnl #   sync discard:  blkdev_issue_discard(...)
585dnl #   sync erase:    blkdev_issue_secure_erase(...)
586dnl #   async discard: __blkdev_issue_discard(...)
587dnl #   async erase:   [not available]
588dnl #
589AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_ISSUE_DISCARD], [
590	ZFS_LINUX_TEST_SRC([blkdev_issue_discard_noflags], [
591		#include <linux/blkdev.h>
592	],[
593		struct block_device *bdev = NULL;
594		sector_t sector = 0;
595		sector_t nr_sects = 0;
596		int error __attribute__ ((unused));
597
598		error = blkdev_issue_discard(bdev,
599		    sector, nr_sects, GFP_KERNEL);
600	])
601	ZFS_LINUX_TEST_SRC([blkdev_issue_discard_flags], [
602		#include <linux/blkdev.h>
603	],[
604		struct block_device *bdev = NULL;
605		sector_t sector = 0;
606		sector_t nr_sects = 0;
607		unsigned long flags = 0;
608		int error __attribute__ ((unused));
609
610		error = blkdev_issue_discard(bdev,
611		    sector, nr_sects, GFP_KERNEL, flags);
612	])
613	ZFS_LINUX_TEST_SRC([blkdev_issue_discard_async_noflags], [
614		#include <linux/blkdev.h>
615	],[
616		struct block_device *bdev = NULL;
617		sector_t sector = 0;
618		sector_t nr_sects = 0;
619		struct bio *biop = NULL;
620		int error __attribute__ ((unused));
621
622		error = __blkdev_issue_discard(bdev,
623		    sector, nr_sects, GFP_KERNEL, &biop);
624	])
625	ZFS_LINUX_TEST_SRC([blkdev_issue_discard_async_flags], [
626		#include <linux/blkdev.h>
627	],[
628		struct block_device *bdev = NULL;
629		sector_t sector = 0;
630		sector_t nr_sects = 0;
631		unsigned long flags = 0;
632		struct bio *biop = NULL;
633		int error __attribute__ ((unused));
634
635		error = __blkdev_issue_discard(bdev,
636		    sector, nr_sects, GFP_KERNEL, flags, &biop);
637	])
638	ZFS_LINUX_TEST_SRC([blkdev_issue_secure_erase], [
639		#include <linux/blkdev.h>
640	],[
641		struct block_device *bdev = NULL;
642		sector_t sector = 0;
643		sector_t nr_sects = 0;
644		int error __attribute__ ((unused));
645
646		error = blkdev_issue_secure_erase(bdev,
647		    sector, nr_sects, GFP_KERNEL);
648	])
649])
650
651AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_ISSUE_DISCARD], [
652	AC_MSG_CHECKING([whether blkdev_issue_discard() is available])
653	ZFS_LINUX_TEST_RESULT([blkdev_issue_discard_noflags], [
654		AC_MSG_RESULT(yes)
655		AC_DEFINE(HAVE_BLKDEV_ISSUE_DISCARD_NOFLAGS, 1,
656		    [blkdev_issue_discard() is available])
657	],[
658		AC_MSG_RESULT(no)
659	])
660	AC_MSG_CHECKING([whether blkdev_issue_discard(flags) is available])
661	ZFS_LINUX_TEST_RESULT([blkdev_issue_discard_flags], [
662		AC_MSG_RESULT(yes)
663		AC_DEFINE(HAVE_BLKDEV_ISSUE_DISCARD_FLAGS, 1,
664		    [blkdev_issue_discard(flags) is available])
665	],[
666		AC_MSG_RESULT(no)
667	])
668	AC_MSG_CHECKING([whether __blkdev_issue_discard() is available])
669	ZFS_LINUX_TEST_RESULT([blkdev_issue_discard_async_noflags], [
670		AC_MSG_RESULT(yes)
671		AC_DEFINE(HAVE_BLKDEV_ISSUE_DISCARD_ASYNC_NOFLAGS, 1,
672		    [__blkdev_issue_discard() is available])
673	],[
674		AC_MSG_RESULT(no)
675	])
676	AC_MSG_CHECKING([whether __blkdev_issue_discard(flags) is available])
677	ZFS_LINUX_TEST_RESULT([blkdev_issue_discard_async_flags], [
678		AC_MSG_RESULT(yes)
679		AC_DEFINE(HAVE_BLKDEV_ISSUE_DISCARD_ASYNC_FLAGS, 1,
680		    [__blkdev_issue_discard(flags) is available])
681	],[
682		AC_MSG_RESULT(no)
683	])
684	AC_MSG_CHECKING([whether blkdev_issue_secure_erase() is available])
685	ZFS_LINUX_TEST_RESULT([blkdev_issue_secure_erase], [
686		AC_MSG_RESULT(yes)
687		AC_DEFINE(HAVE_BLKDEV_ISSUE_SECURE_ERASE, 1,
688		    [blkdev_issue_secure_erase() is available])
689	],[
690		AC_MSG_RESULT(no)
691	])
692])
693
694dnl #
695dnl # 5.13 API change
696dnl # blkdev_get_by_path() no longer handles ERESTARTSYS
697dnl #
698dnl # Unfortunately we're forced to rely solely on the kernel version
699dnl # number in order to determine the expected behavior.  This was an
700dnl # internal change to blkdev_get_by_dev(), see commit a8ed1a0607.
701dnl #
702AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_GET_ERESTARTSYS], [
703	AC_MSG_CHECKING([whether blkdev_get_by_path() handles ERESTARTSYS])
704	AS_VERSION_COMPARE([$LINUX_VERSION], [5.13.0], [
705		AC_MSG_RESULT(yes)
706		AC_DEFINE(HAVE_BLKDEV_GET_ERESTARTSYS, 1,
707			[blkdev_get_by_path() handles ERESTARTSYS])
708	],[
709		AC_MSG_RESULT(no)
710	],[
711		AC_MSG_RESULT(no)
712	])
713])
714
715dnl #
716dnl # 6.5.x API change
717dnl # BLK_STS_NEXUS replaced with BLK_STS_RESV_CONFLICT
718dnl #
719AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BLK_STS_RESV_CONFLICT], [
720	ZFS_LINUX_TEST_SRC([blk_sts_resv_conflict], [
721		#include <linux/blkdev.h>
722	],[
723		blk_status_t s __attribute__ ((unused)) = BLK_STS_RESV_CONFLICT;
724	])
725])
726
727AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BLK_STS_RESV_CONFLICT], [
728	AC_MSG_CHECKING([whether BLK_STS_RESV_CONFLICT is defined])
729		ZFS_LINUX_TEST_RESULT([blk_sts_resv_conflict], [
730			AC_DEFINE(HAVE_BLK_STS_RESV_CONFLICT, 1, [BLK_STS_RESV_CONFLICT is defined])
731			AC_MSG_RESULT(yes)
732		], [
733			AC_MSG_RESULT(no)
734		])
735	])
736])
737
738AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV], [
739	ZFS_AC_KERNEL_SRC_BLKDEV_GET_BY_PATH
740	ZFS_AC_KERNEL_SRC_BLKDEV_GET_BY_PATH_4ARG
741	ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_OPEN_BY_PATH
742	ZFS_AC_KERNEL_SRC_BDEV_FILE_OPEN_BY_PATH
743	ZFS_AC_KERNEL_SRC_BLKDEV_PUT
744	ZFS_AC_KERNEL_SRC_BLKDEV_PUT_HOLDER
745	ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_RELEASE
746	ZFS_AC_KERNEL_SRC_BLKDEV_REREAD_PART
747	ZFS_AC_KERNEL_SRC_BLKDEV_INVALIDATE_BDEV
748	ZFS_AC_KERNEL_SRC_BLKDEV_LOOKUP_BDEV
749	ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_LOGICAL_BLOCK_SIZE
750	ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_PHYSICAL_BLOCK_SIZE
751	ZFS_AC_KERNEL_SRC_BLKDEV_CHECK_DISK_CHANGE
752	ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_CHECK_MEDIA_CHANGE
753	ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_WHOLE
754	ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_NR_BYTES
755	ZFS_AC_KERNEL_SRC_BLKDEV_BDEVNAME
756	ZFS_AC_KERNEL_SRC_BLKDEV_ISSUE_DISCARD
757	ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_KOBJ
758	ZFS_AC_KERNEL_SRC_BLKDEV_PART_TO_DEV
759	ZFS_AC_KERNEL_SRC_BLKDEV_DISK_CHECK_MEDIA_CHANGE
760	ZFS_AC_KERNEL_SRC_BLKDEV_BLK_STS_RESV_CONFLICT
761	ZFS_AC_KERNEL_SRC_BLKDEV_BLK_MODE_T
762])
763
764AC_DEFUN([ZFS_AC_KERNEL_BLKDEV], [
765	ZFS_AC_KERNEL_BLKDEV_GET_BY_PATH
766	ZFS_AC_KERNEL_BLKDEV_PUT
767	ZFS_AC_KERNEL_BLKDEV_REREAD_PART
768	ZFS_AC_KERNEL_BLKDEV_INVALIDATE_BDEV
769	ZFS_AC_KERNEL_BLKDEV_LOOKUP_BDEV
770	ZFS_AC_KERNEL_BLKDEV_BDEV_LOGICAL_BLOCK_SIZE
771	ZFS_AC_KERNEL_BLKDEV_BDEV_PHYSICAL_BLOCK_SIZE
772	ZFS_AC_KERNEL_BLKDEV_CHECK_DISK_CHANGE
773	ZFS_AC_KERNEL_BLKDEV_BDEV_CHECK_MEDIA_CHANGE
774	ZFS_AC_KERNEL_BLKDEV_BDEV_WHOLE
775	ZFS_AC_KERNEL_BLKDEV_BDEV_NR_BYTES
776	ZFS_AC_KERNEL_BLKDEV_BDEVNAME
777	ZFS_AC_KERNEL_BLKDEV_GET_ERESTARTSYS
778	ZFS_AC_KERNEL_BLKDEV_ISSUE_DISCARD
779	ZFS_AC_KERNEL_BLKDEV_BDEV_KOBJ
780	ZFS_AC_KERNEL_BLKDEV_PART_TO_DEV
781	ZFS_AC_KERNEL_BLKDEV_DISK_CHECK_MEDIA_CHANGE
782	ZFS_AC_KERNEL_BLKDEV_BLK_STS_RESV_CONFLICT
783	ZFS_AC_KERNEL_BLKDEV_BLK_MODE_T
784])
785