From 675de5aa379bfceb0258a20c4ccd1414e4798ee6 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Wed, 10 Nov 2010 15:49:40 -0800 Subject: [PATCH] Linux 2.6.36 compat, synchronous bio flag The name of the flag used to mark a bio as synchronous has changed again in the 2.6.36 kernel due to the unification of the BIO_RW_* and REQ_* flags. The new flag is called REQ_SYNC. To simplify checking this flag I have introduced the vdev_disk_dio_is_sync() helper function. Based on the results of several new autoconf tests it uses the correct mask to check for a synchronous bio. Preferred interface for flagging a synchronous bio: 2.6.12-2.6.29: BIO_RW_SYNC 2.6.30-2.6.35: BIO_RW_SYNCIO 2.6.36-2.6.xx: REQ_SYNC --- config/kernel-bio-rw-syncio.m4 | 39 +++++- config/kernel.m4 | 2 + configure | 264 +++++++++++++++++++++++++++++++++++++++++ include/sys/vdev_disk.h | 7 -- module/zfs/vdev_disk.c | 25 +++- zfs_config.h.in | 6 + 6 files changed, 330 insertions(+), 13 deletions(-) diff --git a/config/kernel-bio-rw-syncio.m4 b/config/kernel-bio-rw-syncio.m4 index 2c80f5c..6f8b5b5 100644 --- a/config/kernel-bio-rw-syncio.m4 +++ b/config/kernel-bio-rw-syncio.m4 @@ -1,7 +1,24 @@ dnl # -dnl # 2.6.29 API change -dnl # BIO_RW_SYNC renamed to BIO_RW_SYNCIO +dnl # Preferred interface for flagging a synchronous bio: +dnl # 2.6.12-2.6.29: BIO_RW_SYNC +dnl # 2.6.30-2.6.35: BIO_RW_SYNCIO +dnl # 2.6.36-2.6.xx: REQ_SYNC dnl # +AC_DEFUN([ZFS_AC_KERNEL_BIO_RW_SYNC], [ + AC_MSG_CHECKING([whether BIO_RW_SYNC is defined]) + ZFS_LINUX_TRY_COMPILE([ + #include + ],[ + int flags; + flags = BIO_RW_SYNC; + ],[ + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_BIO_RW_SYNC, 1, [BIO_RW_SYNC is defined]) + ],[ + AC_MSG_RESULT(no) + ]) +]) + AC_DEFUN([ZFS_AC_KERNEL_BIO_RW_SYNCIO], [ AC_MSG_CHECKING([whether BIO_RW_SYNCIO is defined]) ZFS_LINUX_TRY_COMPILE([ @@ -11,8 +28,22 @@ AC_DEFUN([ZFS_AC_KERNEL_BIO_RW_SYNCIO], [ flags = BIO_RW_SYNCIO; ],[ AC_MSG_RESULT(yes) - AC_DEFINE(HAVE_BIO_RW_SYNCIO, 1, - [BIO_RW_SYNCIO is defined]) + AC_DEFINE(HAVE_BIO_RW_SYNCIO, 1, [BIO_RW_SYNCIO is defined]) + ],[ + AC_MSG_RESULT(no) + ]) +]) + +AC_DEFUN([ZFS_AC_KERNEL_REQ_SYNC], [ + AC_MSG_CHECKING([whether REQ_SYNC is defined]) + ZFS_LINUX_TRY_COMPILE([ + #include + ],[ + int flags; + flags = REQ_SYNC; + ],[ + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_REQ_SYNC, 1, [REQ_SYNC is defined]) ],[ AC_MSG_RESULT(no) ]) diff --git a/config/kernel.m4 b/config/kernel.m4 index c732840..c2fc5a0 100644 --- a/config/kernel.m4 +++ b/config/kernel.m4 @@ -16,7 +16,9 @@ AC_DEFUN([ZFS_AC_CONFIG_KERNEL], [ ZFS_AC_KERNEL_BIO_FAILFAST_DTD ZFS_AC_KERNEL_REQ_FAILFAST_MASK ZFS_AC_KERNEL_BIO_END_IO_T_ARGS + ZFS_AC_KERNEL_BIO_RW_SYNC ZFS_AC_KERNEL_BIO_RW_SYNCIO + ZFS_AC_KERNEL_REQ_SYNC ZFS_AC_KERNEL_BLK_END_REQUEST ZFS_AC_KERNEL_BLK_FETCH_REQUEST ZFS_AC_KERNEL_BLK_REQUEUE_REQUEST diff --git a/configure b/configure index 58b2953..c553480 100755 --- a/configure +++ b/configure @@ -12884,6 +12884,72 @@ fi EXTRA_KCFLAGS="$tmp_flags" + { $as_echo "$as_me:$LINENO: checking whether BIO_RW_SYNC is defined" >&5 +$as_echo_n "checking whether BIO_RW_SYNC is defined... " >&6; } + + +cat confdefs.h - <<_ACEOF >conftest.c +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + + #include + +int +main (void) +{ + + int flags; + flags = BIO_RW_SYNC; + + ; + return 0; +} + +_ACEOF + + + rm -Rf build && mkdir -p build + echo "obj-m := conftest.o" >build/Makefile + if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + + { $as_echo "$as_me:$LINENO: result: yes" >&5 +$as_echo "yes" >&6; } + +cat >>confdefs.h <<\_ACEOF +#define HAVE_BIO_RW_SYNC 1 +_ACEOF + + +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + { $as_echo "$as_me:$LINENO: result: no" >&5 +$as_echo "no" >&6; } + + + +fi + + rm -Rf build + + + + { $as_echo "$as_me:$LINENO: checking whether BIO_RW_SYNCIO is defined" >&5 $as_echo_n "checking whether BIO_RW_SYNCIO is defined... " >&6; } @@ -12950,6 +13016,72 @@ fi + { $as_echo "$as_me:$LINENO: checking whether REQ_SYNC is defined" >&5 +$as_echo_n "checking whether REQ_SYNC is defined... " >&6; } + + +cat confdefs.h - <<_ACEOF >conftest.c +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + + #include + +int +main (void) +{ + + int flags; + flags = REQ_SYNC; + + ; + return 0; +} + +_ACEOF + + + rm -Rf build && mkdir -p build + echo "obj-m := conftest.o" >build/Makefile + if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + + { $as_echo "$as_me:$LINENO: result: yes" >&5 +$as_echo "yes" >&6; } + +cat >>confdefs.h <<\_ACEOF +#define HAVE_REQ_SYNC 1 +_ACEOF + + +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + { $as_echo "$as_me:$LINENO: result: no" >&5 +$as_echo "no" >&6; } + + + +fi + + rm -Rf build + + + + { $as_echo "$as_me:$LINENO: checking whether blk_end_request() is available" >&5 $as_echo_n "checking whether blk_end_request() is available... " >&6; } @@ -16087,6 +16219,72 @@ fi EXTRA_KCFLAGS="$tmp_flags" + { $as_echo "$as_me:$LINENO: checking whether BIO_RW_SYNC is defined" >&5 +$as_echo_n "checking whether BIO_RW_SYNC is defined... " >&6; } + + +cat confdefs.h - <<_ACEOF >conftest.c +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + + #include + +int +main (void) +{ + + int flags; + flags = BIO_RW_SYNC; + + ; + return 0; +} + +_ACEOF + + + rm -Rf build && mkdir -p build + echo "obj-m := conftest.o" >build/Makefile + if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + + { $as_echo "$as_me:$LINENO: result: yes" >&5 +$as_echo "yes" >&6; } + +cat >>confdefs.h <<\_ACEOF +#define HAVE_BIO_RW_SYNC 1 +_ACEOF + + +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + { $as_echo "$as_me:$LINENO: result: no" >&5 +$as_echo "no" >&6; } + + + +fi + + rm -Rf build + + + + { $as_echo "$as_me:$LINENO: checking whether BIO_RW_SYNCIO is defined" >&5 $as_echo_n "checking whether BIO_RW_SYNCIO is defined... " >&6; } @@ -16153,6 +16351,72 @@ fi + { $as_echo "$as_me:$LINENO: checking whether REQ_SYNC is defined" >&5 +$as_echo_n "checking whether REQ_SYNC is defined... " >&6; } + + +cat confdefs.h - <<_ACEOF >conftest.c +/* confdefs.h. */ +_ACEOF +cat confdefs.h >>conftest.$ac_ext +cat >>conftest.$ac_ext <<_ACEOF +/* end confdefs.h. */ + + + #include + +int +main (void) +{ + + int flags; + flags = REQ_SYNC; + + ; + return 0; +} + +_ACEOF + + + rm -Rf build && mkdir -p build + echo "obj-m := conftest.o" >build/Makefile + if { ac_try='cp conftest.c build && make modules -C $LINUX_OBJ EXTRA_CFLAGS="-Werror-implicit-function-declaration $EXTRA_KCFLAGS" $ARCH_UM M=$PWD/build' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; } >/dev/null && { ac_try='test -s build/conftest.o' + { (eval echo "$as_me:$LINENO: \"$ac_try\"") >&5 + (eval $ac_try) 2>&5 + ac_status=$? + $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 + (exit $ac_status); }; }; then + + { $as_echo "$as_me:$LINENO: result: yes" >&5 +$as_echo "yes" >&6; } + +cat >>confdefs.h <<\_ACEOF +#define HAVE_REQ_SYNC 1 +_ACEOF + + +else + $as_echo "$as_me: failed program was:" >&5 +sed 's/^/| /' conftest.$ac_ext >&5 + + { $as_echo "$as_me:$LINENO: result: no" >&5 +$as_echo "no" >&6; } + + + +fi + + rm -Rf build + + + + { $as_echo "$as_me:$LINENO: checking whether blk_end_request() is available" >&5 $as_echo_n "checking whether blk_end_request() is available... " >&6; } diff --git a/include/sys/vdev_disk.h b/include/sys/vdev_disk.h index 986c336..021e66d 100644 --- a/include/sys/vdev_disk.h +++ b/include/sys/vdev_disk.h @@ -58,13 +58,6 @@ extern int vdev_disk_read_rootlabel(char *, char *, nvlist_t **); # define BIO_END_IO_RETURN(rc) return rc #endif /* HAVE_2ARGS_BIO_END_IO_T */ -/* 2.6.29 API change */ -#ifdef HAVE_BIO_RW_SYNCIO -# define DIO_RW_SYNCIO BIO_RW_SYNCIO -#else -# define DIO_RW_SYNCIO BIO_RW_SYNC -#endif /* HAVE_BIO_RW_SYNCIO */ - /* 2.6.28 API change */ #ifdef HAVE_OPEN_BDEV_EXCLUSIVE # define vdev_bdev_open(path, md, hld) open_bdev_exclusive(path, md, hld) diff --git a/module/zfs/vdev_disk.c b/module/zfs/vdev_disk.c index 51062ef..86a089d 100644 --- a/module/zfs/vdev_disk.c +++ b/module/zfs/vdev_disk.c @@ -220,6 +220,27 @@ vdev_disk_dio_free(dio_request_t *dr) sizeof(struct bio *) * dr->dr_bio_count); } +static int +vdev_disk_dio_is_sync(dio_request_t *dr) +{ +#ifdef HAVE_BIO_RW_SYNC + /* BIO_RW_SYNC preferred interface from 2.6.12-2.6.29 */ + return (dr->dr_rw & (1 << BIO_RW_SYNC)); +#else +# ifdef HAVE_BIO_RW_SYNCIO + /* BIO_RW_SYNCIO preferred interface from 2.6.30-2.6.35 */ + return (dr->dr_rw & (1 << BIO_RW_SYNCIO)); +# else +# ifdef HAVE_REQ_SYNC + /* REQ_SYNC preferred interface from 2.6.36-2.6.xx */ + return (dr->dr_rw & REQ_SYNC); +# else +# error "Unable to determine bio sync flag" +# endif /* HAVE_REQ_SYNC */ +# endif /* HAVE_BIO_RW_SYNC */ +#endif /* HAVE_BIO_RW_SYNCIO */ +} + static void vdev_disk_dio_get(dio_request_t *dr) { @@ -284,7 +305,7 @@ BIO_END_IO_PROTO(vdev_disk_physio_completion, bio, size, error) rc = vdev_disk_dio_put(dr); /* Wake up synchronous waiter this is the last outstanding bio */ - if ((rc == 1) && (dr->dr_rw & (1 << DIO_RW_SYNCIO))) + if ((rc == 1) && vdev_disk_dio_is_sync(dr)) complete(&dr->dr_comp); BIO_END_IO_RETURN(0); @@ -421,7 +442,7 @@ retry: * only synchronous consumer is vdev_disk_read_rootlabel() all other * IO originating from vdev_disk_io_start() is asynchronous. */ - if (dr->dr_rw & (1 << DIO_RW_SYNCIO)) { + if (vdev_disk_dio_is_sync(dr)) { wait_for_completion(&dr->dr_comp); error = dr->dr_error; ASSERT3S(atomic_read(&dr->dr_ref), ==, 1); diff --git a/zfs_config.h.in b/zfs_config.h.in index f666d45..6e0e623 100644 --- a/zfs_config.h.in +++ b/zfs_config.h.in @@ -24,6 +24,9 @@ /* BIO_RW_FAILFAST_* are defined */ #undef HAVE_BIO_RW_FAILFAST_DTD +/* BIO_RW_SYNC is defined */ +#undef HAVE_BIO_RW_SYNC + /* BIO_RW_SYNCIO is defined */ #undef HAVE_BIO_RW_SYNCIO @@ -96,6 +99,9 @@ /* open_bdev_exclusive() is available */ #undef HAVE_OPEN_BDEV_EXCLUSIVE +/* REQ_SYNC is defined */ +#undef HAVE_REQ_SYNC + /* rq_for_each_segment() is available */ #undef HAVE_RQ_FOR_EACH_SEGMENT -- 1.8.3.1