xref: /freebsd/sys/contrib/openzfs/config/kernel-blkdev.m4 (revision 357378bbdedf24ce2b90e9bd831af4a9db3ec70a)
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 # 4.4.0-6.21 API, lookup_bdev() on Ubuntu takes mode argument.
400dnl #
401AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_LOOKUP_BDEV], [
402	ZFS_LINUX_TEST_SRC([lookup_bdev_devt], [
403		#include <linux/blkdev.h>
404	], [
405		int error __attribute__ ((unused));
406		const char path[] = "/example/path";
407		dev_t dev;
408
409		error = lookup_bdev(path, &dev);
410	])
411
412	ZFS_LINUX_TEST_SRC([lookup_bdev_1arg], [
413		#include <linux/fs.h>
414		#include <linux/blkdev.h>
415	], [
416		struct block_device *bdev __attribute__ ((unused));
417		const char path[] = "/example/path";
418
419		bdev = lookup_bdev(path);
420	])
421
422	ZFS_LINUX_TEST_SRC([lookup_bdev_mode], [
423		#include <linux/fs.h>
424	], [
425		struct block_device *bdev __attribute__ ((unused));
426		const char path[] = "/example/path";
427
428		bdev = lookup_bdev(path, FMODE_READ);
429	])
430])
431
432AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_LOOKUP_BDEV], [
433	AC_MSG_CHECKING([whether lookup_bdev() wants dev_t arg])
434	ZFS_LINUX_TEST_RESULT_SYMBOL([lookup_bdev_devt],
435	    [lookup_bdev], [fs/block_dev.c], [
436		AC_MSG_RESULT(yes)
437		AC_DEFINE(HAVE_DEVT_LOOKUP_BDEV, 1,
438		    [lookup_bdev() wants dev_t arg])
439	], [
440		AC_MSG_RESULT(no)
441
442		AC_MSG_CHECKING([whether lookup_bdev() wants 1 arg])
443		ZFS_LINUX_TEST_RESULT_SYMBOL([lookup_bdev_1arg],
444		    [lookup_bdev], [fs/block_dev.c], [
445			AC_MSG_RESULT(yes)
446			AC_DEFINE(HAVE_1ARG_LOOKUP_BDEV, 1,
447			    [lookup_bdev() wants 1 arg])
448		], [
449			AC_MSG_RESULT(no)
450
451			AC_MSG_CHECKING([whether lookup_bdev() wants mode arg])
452			ZFS_LINUX_TEST_RESULT_SYMBOL([lookup_bdev_mode],
453			    [lookup_bdev], [fs/block_dev.c], [
454				AC_MSG_RESULT(yes)
455				AC_DEFINE(HAVE_MODE_LOOKUP_BDEV, 1,
456				    [lookup_bdev() wants mode arg])
457			], [
458				ZFS_LINUX_TEST_ERROR([lookup_bdev()])
459			])
460		])
461	])
462])
463
464dnl #
465dnl # 2.6.30 API change
466dnl #
467dnl # The bdev_physical_block_size() interface was added to provide a way
468dnl # to determine the smallest write which can be performed without a
469dnl # read-modify-write operation.
470dnl #
471dnl # Unfortunately, this interface isn't entirely reliable because
472dnl # drives are sometimes known to misreport this value.
473dnl #
474AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_PHYSICAL_BLOCK_SIZE], [
475	ZFS_LINUX_TEST_SRC([bdev_physical_block_size], [
476		#include <linux/blkdev.h>
477	],[
478		struct block_device *bdev __attribute__ ((unused)) = NULL;
479		bdev_physical_block_size(bdev);
480	])
481])
482
483AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BDEV_PHYSICAL_BLOCK_SIZE], [
484	AC_MSG_CHECKING([whether bdev_physical_block_size() is available])
485	ZFS_LINUX_TEST_RESULT([bdev_physical_block_size], [
486		AC_MSG_RESULT(yes)
487	],[
488		ZFS_LINUX_TEST_ERROR([bdev_physical_block_size()])
489	])
490])
491
492dnl #
493dnl # 2.6.30 API change
494dnl # Added bdev_logical_block_size().
495dnl #
496AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_LOGICAL_BLOCK_SIZE], [
497	ZFS_LINUX_TEST_SRC([bdev_logical_block_size], [
498		#include <linux/blkdev.h>
499	],[
500		struct block_device *bdev __attribute__ ((unused)) = NULL;
501		bdev_logical_block_size(bdev);
502	])
503])
504
505AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BDEV_LOGICAL_BLOCK_SIZE], [
506	AC_MSG_CHECKING([whether bdev_logical_block_size() is available])
507	ZFS_LINUX_TEST_RESULT([bdev_logical_block_size], [
508		AC_MSG_RESULT(yes)
509	],[
510		ZFS_LINUX_TEST_ERROR([bdev_logical_block_size()])
511	])
512])
513
514dnl #
515dnl # 5.11 API change
516dnl # Added bdev_whole() helper.
517dnl #
518AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_WHOLE], [
519	ZFS_LINUX_TEST_SRC([bdev_whole], [
520		#include <linux/blkdev.h>
521	],[
522		struct block_device *bdev = NULL;
523		bdev = bdev_whole(bdev);
524	])
525])
526
527AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BDEV_WHOLE], [
528	AC_MSG_CHECKING([whether bdev_whole() is available])
529	ZFS_LINUX_TEST_RESULT([bdev_whole], [
530		AC_MSG_RESULT(yes)
531		AC_DEFINE(HAVE_BDEV_WHOLE, 1, [bdev_whole() is available])
532	],[
533		AC_MSG_RESULT(no)
534	])
535])
536
537dnl #
538dnl # 5.16 API change
539dnl # Added bdev_nr_bytes() helper.
540dnl #
541AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_NR_BYTES], [
542	ZFS_LINUX_TEST_SRC([bdev_nr_bytes], [
543		#include <linux/blkdev.h>
544	],[
545		struct block_device *bdev = NULL;
546		loff_t nr_bytes __attribute__ ((unused)) = 0;
547		nr_bytes = bdev_nr_bytes(bdev);
548	])
549])
550
551AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BDEV_NR_BYTES], [
552	AC_MSG_CHECKING([whether bdev_nr_bytes() is available])
553	ZFS_LINUX_TEST_RESULT([bdev_nr_bytes], [
554		AC_MSG_RESULT(yes)
555		AC_DEFINE(HAVE_BDEV_NR_BYTES, 1, [bdev_nr_bytes() is available])
556	],[
557		AC_MSG_RESULT(no)
558	])
559])
560
561dnl #
562dnl # 5.20 API change,
563dnl # Removed bdevname(), snprintf(.., %pg) should be used.
564dnl #
565AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BDEVNAME], [
566	ZFS_LINUX_TEST_SRC([bdevname], [
567		#include <linux/fs.h>
568		#include <linux/blkdev.h>
569	], [
570		struct block_device *bdev __attribute__ ((unused)) = NULL;
571		char path[BDEVNAME_SIZE];
572
573		(void) bdevname(bdev, path);
574	])
575])
576
577AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BDEVNAME], [
578	AC_MSG_CHECKING([whether bdevname() exists])
579	ZFS_LINUX_TEST_RESULT([bdevname], [
580		AC_DEFINE(HAVE_BDEVNAME, 1, [bdevname() is available])
581		AC_MSG_RESULT(yes)
582	], [
583		AC_MSG_RESULT(no)
584	])
585])
586
587dnl #
588dnl # TRIM support: discard and secure erase. We make use of asynchronous
589dnl #               functions when available.
590dnl #
591dnl # 3.10:
592dnl #   sync discard:  blkdev_issue_discard(..., 0)
593dnl #   sync erase:    blkdev_issue_discard(..., BLKDEV_DISCARD_SECURE)
594dnl #   async discard: [not available]
595dnl #   async erase:   [not available]
596dnl #
597dnl # 4.7:
598dnl #   sync discard:  blkdev_issue_discard(..., 0)
599dnl #   sync erase:    blkdev_issue_discard(..., BLKDEV_DISCARD_SECURE)
600dnl #   async discard: __blkdev_issue_discard(..., 0)
601dnl #   async erase:   __blkdev_issue_discard(..., BLKDEV_DISCARD_SECURE)
602dnl #
603dnl # 5.19:
604dnl #   sync discard:  blkdev_issue_discard(...)
605dnl #   sync erase:    blkdev_issue_secure_erase(...)
606dnl #   async discard: __blkdev_issue_discard(...)
607dnl #   async erase:   [not available]
608dnl #
609AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_ISSUE_DISCARD], [
610	ZFS_LINUX_TEST_SRC([blkdev_issue_discard_noflags], [
611		#include <linux/blkdev.h>
612	],[
613		struct block_device *bdev = NULL;
614		sector_t sector = 0;
615		sector_t nr_sects = 0;
616		int error __attribute__ ((unused));
617
618		error = blkdev_issue_discard(bdev,
619		    sector, nr_sects, GFP_KERNEL);
620	])
621	ZFS_LINUX_TEST_SRC([blkdev_issue_discard_flags], [
622		#include <linux/blkdev.h>
623	],[
624		struct block_device *bdev = NULL;
625		sector_t sector = 0;
626		sector_t nr_sects = 0;
627		unsigned long flags = 0;
628		int error __attribute__ ((unused));
629
630		error = blkdev_issue_discard(bdev,
631		    sector, nr_sects, GFP_KERNEL, flags);
632	])
633	ZFS_LINUX_TEST_SRC([blkdev_issue_discard_async_noflags], [
634		#include <linux/blkdev.h>
635	],[
636		struct block_device *bdev = NULL;
637		sector_t sector = 0;
638		sector_t nr_sects = 0;
639		struct bio *biop = NULL;
640		int error __attribute__ ((unused));
641
642		error = __blkdev_issue_discard(bdev,
643		    sector, nr_sects, GFP_KERNEL, &biop);
644	])
645	ZFS_LINUX_TEST_SRC([blkdev_issue_discard_async_flags], [
646		#include <linux/blkdev.h>
647	],[
648		struct block_device *bdev = NULL;
649		sector_t sector = 0;
650		sector_t nr_sects = 0;
651		unsigned long flags = 0;
652		struct bio *biop = NULL;
653		int error __attribute__ ((unused));
654
655		error = __blkdev_issue_discard(bdev,
656		    sector, nr_sects, GFP_KERNEL, flags, &biop);
657	])
658	ZFS_LINUX_TEST_SRC([blkdev_issue_secure_erase], [
659		#include <linux/blkdev.h>
660	],[
661		struct block_device *bdev = NULL;
662		sector_t sector = 0;
663		sector_t nr_sects = 0;
664		int error __attribute__ ((unused));
665
666		error = blkdev_issue_secure_erase(bdev,
667		    sector, nr_sects, GFP_KERNEL);
668	])
669])
670
671AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_ISSUE_DISCARD], [
672	AC_MSG_CHECKING([whether blkdev_issue_discard() is available])
673	ZFS_LINUX_TEST_RESULT([blkdev_issue_discard_noflags], [
674		AC_MSG_RESULT(yes)
675		AC_DEFINE(HAVE_BLKDEV_ISSUE_DISCARD_NOFLAGS, 1,
676		    [blkdev_issue_discard() is available])
677	],[
678		AC_MSG_RESULT(no)
679	])
680	AC_MSG_CHECKING([whether blkdev_issue_discard(flags) is available])
681	ZFS_LINUX_TEST_RESULT([blkdev_issue_discard_flags], [
682		AC_MSG_RESULT(yes)
683		AC_DEFINE(HAVE_BLKDEV_ISSUE_DISCARD_FLAGS, 1,
684		    [blkdev_issue_discard(flags) is available])
685	],[
686		AC_MSG_RESULT(no)
687	])
688	AC_MSG_CHECKING([whether __blkdev_issue_discard() is available])
689	ZFS_LINUX_TEST_RESULT([blkdev_issue_discard_async_noflags], [
690		AC_MSG_RESULT(yes)
691		AC_DEFINE(HAVE_BLKDEV_ISSUE_DISCARD_ASYNC_NOFLAGS, 1,
692		    [__blkdev_issue_discard() is available])
693	],[
694		AC_MSG_RESULT(no)
695	])
696	AC_MSG_CHECKING([whether __blkdev_issue_discard(flags) is available])
697	ZFS_LINUX_TEST_RESULT([blkdev_issue_discard_async_flags], [
698		AC_MSG_RESULT(yes)
699		AC_DEFINE(HAVE_BLKDEV_ISSUE_DISCARD_ASYNC_FLAGS, 1,
700		    [__blkdev_issue_discard(flags) is available])
701	],[
702		AC_MSG_RESULT(no)
703	])
704	AC_MSG_CHECKING([whether blkdev_issue_secure_erase() is available])
705	ZFS_LINUX_TEST_RESULT([blkdev_issue_secure_erase], [
706		AC_MSG_RESULT(yes)
707		AC_DEFINE(HAVE_BLKDEV_ISSUE_SECURE_ERASE, 1,
708		    [blkdev_issue_secure_erase() is available])
709	],[
710		AC_MSG_RESULT(no)
711	])
712])
713
714dnl #
715dnl # 5.13 API change
716dnl # blkdev_get_by_path() no longer handles ERESTARTSYS
717dnl #
718dnl # Unfortunately we're forced to rely solely on the kernel version
719dnl # number in order to determine the expected behavior.  This was an
720dnl # internal change to blkdev_get_by_dev(), see commit a8ed1a0607.
721dnl #
722AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_GET_ERESTARTSYS], [
723	AC_MSG_CHECKING([whether blkdev_get_by_path() handles ERESTARTSYS])
724	AS_VERSION_COMPARE([$LINUX_VERSION], [5.13.0], [
725		AC_MSG_RESULT(yes)
726		AC_DEFINE(HAVE_BLKDEV_GET_ERESTARTSYS, 1,
727			[blkdev_get_by_path() handles ERESTARTSYS])
728	],[
729		AC_MSG_RESULT(no)
730	],[
731		AC_MSG_RESULT(no)
732	])
733])
734
735dnl #
736dnl # 6.5.x API change
737dnl # BLK_STS_NEXUS replaced with BLK_STS_RESV_CONFLICT
738dnl #
739AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV_BLK_STS_RESV_CONFLICT], [
740	ZFS_LINUX_TEST_SRC([blk_sts_resv_conflict], [
741		#include <linux/blkdev.h>
742	],[
743		blk_status_t s __attribute__ ((unused)) = BLK_STS_RESV_CONFLICT;
744	])
745])
746
747AC_DEFUN([ZFS_AC_KERNEL_BLKDEV_BLK_STS_RESV_CONFLICT], [
748	AC_MSG_CHECKING([whether BLK_STS_RESV_CONFLICT is defined])
749		ZFS_LINUX_TEST_RESULT([blk_sts_resv_conflict], [
750			AC_DEFINE(HAVE_BLK_STS_RESV_CONFLICT, 1, [BLK_STS_RESV_CONFLICT is defined])
751			AC_MSG_RESULT(yes)
752		], [
753			AC_MSG_RESULT(no)
754		])
755	])
756])
757
758AC_DEFUN([ZFS_AC_KERNEL_SRC_BLKDEV], [
759	ZFS_AC_KERNEL_SRC_BLKDEV_GET_BY_PATH
760	ZFS_AC_KERNEL_SRC_BLKDEV_GET_BY_PATH_4ARG
761	ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_OPEN_BY_PATH
762	ZFS_AC_KERNEL_SRC_BDEV_FILE_OPEN_BY_PATH
763	ZFS_AC_KERNEL_SRC_BLKDEV_PUT
764	ZFS_AC_KERNEL_SRC_BLKDEV_PUT_HOLDER
765	ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_RELEASE
766	ZFS_AC_KERNEL_SRC_BLKDEV_REREAD_PART
767	ZFS_AC_KERNEL_SRC_BLKDEV_INVALIDATE_BDEV
768	ZFS_AC_KERNEL_SRC_BLKDEV_LOOKUP_BDEV
769	ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_LOGICAL_BLOCK_SIZE
770	ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_PHYSICAL_BLOCK_SIZE
771	ZFS_AC_KERNEL_SRC_BLKDEV_CHECK_DISK_CHANGE
772	ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_CHECK_MEDIA_CHANGE
773	ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_WHOLE
774	ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_NR_BYTES
775	ZFS_AC_KERNEL_SRC_BLKDEV_BDEVNAME
776	ZFS_AC_KERNEL_SRC_BLKDEV_ISSUE_DISCARD
777	ZFS_AC_KERNEL_SRC_BLKDEV_BDEV_KOBJ
778	ZFS_AC_KERNEL_SRC_BLKDEV_PART_TO_DEV
779	ZFS_AC_KERNEL_SRC_BLKDEV_DISK_CHECK_MEDIA_CHANGE
780	ZFS_AC_KERNEL_SRC_BLKDEV_BLK_STS_RESV_CONFLICT
781	ZFS_AC_KERNEL_SRC_BLKDEV_BLK_MODE_T
782])
783
784AC_DEFUN([ZFS_AC_KERNEL_BLKDEV], [
785	ZFS_AC_KERNEL_BLKDEV_GET_BY_PATH
786	ZFS_AC_KERNEL_BLKDEV_PUT
787	ZFS_AC_KERNEL_BLKDEV_REREAD_PART
788	ZFS_AC_KERNEL_BLKDEV_INVALIDATE_BDEV
789	ZFS_AC_KERNEL_BLKDEV_LOOKUP_BDEV
790	ZFS_AC_KERNEL_BLKDEV_BDEV_LOGICAL_BLOCK_SIZE
791	ZFS_AC_KERNEL_BLKDEV_BDEV_PHYSICAL_BLOCK_SIZE
792	ZFS_AC_KERNEL_BLKDEV_CHECK_DISK_CHANGE
793	ZFS_AC_KERNEL_BLKDEV_BDEV_CHECK_MEDIA_CHANGE
794	ZFS_AC_KERNEL_BLKDEV_BDEV_WHOLE
795	ZFS_AC_KERNEL_BLKDEV_BDEV_NR_BYTES
796	ZFS_AC_KERNEL_BLKDEV_BDEVNAME
797	ZFS_AC_KERNEL_BLKDEV_GET_ERESTARTSYS
798	ZFS_AC_KERNEL_BLKDEV_ISSUE_DISCARD
799	ZFS_AC_KERNEL_BLKDEV_BDEV_KOBJ
800	ZFS_AC_KERNEL_BLKDEV_PART_TO_DEV
801	ZFS_AC_KERNEL_BLKDEV_DISK_CHECK_MEDIA_CHANGE
802	ZFS_AC_KERNEL_BLKDEV_BLK_STS_RESV_CONFLICT
803	ZFS_AC_KERNEL_BLKDEV_BLK_MODE_T
804])
805