Skip to content

Commit

Permalink
Linux 4.3 compat: bio_end_io_t / BIO_UPTODATE
Browse files Browse the repository at this point in the history
Commit torvalds/linux@4246a0b ("block:
add a bi_error field to struct bio") dropped the error argument from
bio_end_io in favor of newly introduced bio->bi_error. This also
replaces bio->bi_flags value BIO_UPTODATE.

bio_end_io was a 3 argument function until Linux 2.6.24, which made it
a 2 argument function, and now the prototype has changed yet again now
to a 1 argument function.

Signed-off-by: Lukas Wunner <lukas@wunner.de>
Fixes openzfs#3799
  • Loading branch information
l1k committed Sep 23, 2015
1 parent 4a4809f commit da662e1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 5 deletions.
20 changes: 20 additions & 0 deletions config/kernel-bio-end-io-t-args.m4
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ dnl # that partial IO's are no longer possibe and the end_io callback
dnl # should not check bi->bi_size. Finally, the return type was updated
dnl # to void.
dnl #
dnl # 4.3 API change
dnl # Error argument dropped from bio_end_io in favor of newly introduced
dnl # bio->bi_error. This also replaces bio->bi_flags value BIO_UPTODATE.
dnl # Introduced by torvalds/linux@4246a0b63bd8f56a1469b12eafeb875b1041a451
dnl #
AC_DEFUN([ZFS_AC_KERNEL_BIO_END_IO_T_ARGS], [
AC_MSG_CHECKING([whether bio_end_io_t wants 2 args])
ZFS_LINUX_TRY_COMPILE([
Expand All @@ -22,5 +27,20 @@ AC_DEFUN([ZFS_AC_KERNEL_BIO_END_IO_T_ARGS], [
[bio_end_io_t wants 2 args])
],[
AC_MSG_RESULT(no)
AC_MSG_CHECKING([whether bio_end_io_t wants 1 args])
ZFS_LINUX_TRY_COMPILE([
#include <linux/bio.h>
void wanted_end_io(struct bio *bio) { return; }
bio_end_io_t *end_io __attribute__ ((unused)) =
wanted_end_io;
],[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_1ARGS_BIO_END_IO_T, 1,
[bio_end_io_t wants 1 args])
],[
AC_MSG_RESULT(no)
])
])
])
9 changes: 6 additions & 3 deletions include/linux/blkdev_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,14 @@ bio_set_flags_failfast(struct block_device *bdev, int *flags)
#endif /* DISK_NAME_LEN */

/*
* 2.6.24 API change,
* 2.6.24 and 4.3 API change,
* The bio_end_io() prototype changed slightly. These are helper
* macro's to ensure the prototype and return value are handled.
*/
#ifdef HAVE_2ARGS_BIO_END_IO_T
#ifdef HAVE_1ARGS_BIO_END_IO_T
#define BIO_END_IO_PROTO(fn, x, y, z) static void fn(struct bio *x)
#define BIO_END_IO_RETURN(rc) return
#elif HAVE_2ARGS_BIO_END_IO_T
#define BIO_END_IO_PROTO(fn, x, y, z) static void fn(struct bio *x, int z)
#define BIO_END_IO_RETURN(rc) return
#else
Expand All @@ -195,7 +198,7 @@ bio_set_flags_failfast(struct block_device *bdev, int *flags)
unsigned int y, \
int z)
#define BIO_END_IO_RETURN(rc) return rc
#endif /* HAVE_2ARGS_BIO_END_IO_T */
#endif /* HAVE_1ARGS_BIO_END_IO_T */

/*
* 2.6.38 - 2.6.x API,
Expand Down
9 changes: 7 additions & 2 deletions module/zfs/vdev_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,14 +428,19 @@ BIO_END_IO_PROTO(vdev_disk_physio_completion, bio, size, error)
{
dio_request_t *dr = bio->bi_private;
int rc;
#ifdef HAVE_1ARGS_BIO_END_IO_T
int error = bio->bi_error;
#endif

#ifndef HAVE_2ARGS_BIO_END_IO_T
#if !defined(HAVE_2ARGS_BIO_END_IO_T) && !defined(HAVE_1ARGS_BIO_END_IO_T)
if (BIO_BI_SIZE(bio))
return (1);
#endif /* HAVE_2ARGS_BIO_END_IO_T */
#endif

#if !defined(HAVE_1ARGS_BIO_END_IO_T)
if (error == 0 && !test_bit(BIO_UPTODATE, &bio->bi_flags))
error = (-EIO);
#endif

if (dr->dr_error == 0)
dr->dr_error = -error;
Expand Down

0 comments on commit da662e1

Please sign in to comment.