diff --git a/.gitignore b/.gitignore index e39af3e..f44b86e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ *.bak *.log *.o -*.d *.so *.ko *.ko.* diff --git a/configure b/configure index 92642c6..2556357 100755 --- a/configure +++ b/configure @@ -4,103 +4,14 @@ # SPDX-License-Identifier: BSD-3-Clause-Clear # -MODULE_FILE=test_mod.c -OBJ_MOD=test_mod.o -KERN_VER=`uname -r` -PWD=`pwd` -NPROC=`nproc` -DEFINE_FILE=modules/generated_defines.h +SCRIPTPATH=`dirname $0` +SCRIPTPATH=`realpath $SCRIPTPATH` +CONFIG_FILES=`ls $SCRIPTPATH/configure.d/*.conf` -add_define() { - echo -n "#define " >> $DEFINE_FILE - for arg in "$@"; do - echo -e "$arg" >> $DEFINE_FILE - done -} +rm -f $SCRIPTPATH/modules/generated_defines.h -add_function() { - for arg in "$@"; do - echo -e "$arg" >> $DEFINE_FILE - done -} - -compile_module(){ - if [ $# -gt 1 ] - then - INCLUDE="#include <$2>" - else - INCLUDE="" - fi - -############# TEST MODULE ############# -cat > $MODULE_FILE << EOF -#include -#include -$INCLUDE - -int init_module(void) { - $1; - return 0; -} -void cleanup_module(void) {}; -EOF -####################################### - - make -C /lib/modules/$KERN_VER/build M=$PWD modules\ - obj-m=$OBJ_MOD -j$NPROC &> /dev/null - - local ret=$? - if [ $ret -eq 0 ]; then - make -j$NPROC -C /lib/modules/$KERN_VER/build M=$PWD clean\ - obj-m=test.o &> /dev/null - fi - - return $ret -} - -kernel_not_supp_fail() { - echo "Current kernel is not supported!" - rm $DEFINE_FILE - exit 1 -} - -rm -f $DEFINE_FILE - -compile_module "part_round_stats(1, 1)" "linux/genhd.h" -if [ $? -eq 0 ]; then - add_define "CAS_PART_ROUND_STATS(q, cpu, part) part_round_stats(cpu, part)" -else - compile_module "part_round_stats(NULL, 1, 1)" "linux/genhd.h" - if [ $? -eq 0 ]; then - add_define "CAS_PART_ROUND_STATS(q, cpu, part)\\"\ - "\tpart_round_stats(q, cpu, part)" - fi -fi - - -compile_module "part_inc_in_flight(1, 1)" "linux/genhd.h" -if [ $? -eq 0 ]; then - add_define "CAS_PART_INC_IN_FLIGHT(q, cpu, part)\\"\ - "\tpart_inc_in_flight(cpu, part)" -else - compile_module "part_inc_in_flight(NULL, 1, 1)" "linux/genhd.h" - if [ $? -eq 0 ]; then - add_define "CAS_PART_INC_IN_FLIGHT(q, cpu, part)\\"\ - "\tpart_inc_in_flight(q, cpu, part)" - fi -fi - - -compile_module "part_dec_in_flight(1, 1)" "linux/genhd.h" -if [ $? -eq 0 ]; then - add_define "CAS_PART_DEC_IN_FLIGHT(q, cpu, part)\\"\ - "\tpart_dec_in_flight(cpu, part)" -else - compile_module "part_dec_in_flight(NULL, 1, 1)" "linux/genhd.h" - if [ $? -eq 0 ]; then - add_define "CAS_PART_DEC_IN_FLIGHT(q, cpu, part)\\"\ - "\tpart_dec_in_flight(q, cpu, part)" - fi -fi +for file in $CONFIG_FILES; do + /bin/bash $file +done diff --git a/configure.d/Makefile b/configure.d/Makefile new file mode 100644 index 0000000..01ab388 --- /dev/null +++ b/configure.d/Makefile @@ -0,0 +1,14 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +obj-m += test_mod.o + +MAKE_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) + +all: + make -C /lib/modules/$(shell uname -r)/build M=$(MAKE_DIR) modules +clean: + make -C /lib/modules/$(shell uname -r)/build M=$(MAKE_DIR) clean diff --git a/configure.d/append_bio.conf b/configure.d/append_bio.conf new file mode 100644 index 0000000..8fcfbef --- /dev/null +++ b/configure.d/append_bio.conf @@ -0,0 +1,16 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "struct bio b;blk_rq_append_bio(NULL, &b)" "linux/blkdev.h" +then + add_define "cas_blk_rq_append_bio(rq, bounce_bio) \\ + blk_rq_append_bio(rq, bounce_bio" +else + add_define "cas_blk_rq_append_bio(rq, bounce_bio) \\ + blk_rq_append_bio(rq, &bounce_bio)" +fi diff --git a/configure.d/bdev_lookup.conf b/configure.d/bdev_lookup.conf new file mode 100644 index 0000000..60c52bd --- /dev/null +++ b/configure.d/bdev_lookup.conf @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "lookup_bdev(\"some_path\")" "linux/fs.h" +then + add_define "CAS_LOOKUP_BDEV(PATH) \\ + lookup_bdev(PATH)" +elif compile_module "lookup_bdev(\"some_path\", 0)" "linux/fs.h" +then + add_define "CAS_LOOKUP_BDEV(PATH) \\ + lookup_bdev(PATH, 0)" +fi diff --git a/configure.d/bio_barrier.conf b/configure.d/bio_barrier.conf new file mode 100644 index 0000000..a2ec759 --- /dev/null +++ b/configure.d/bio_barrier.conf @@ -0,0 +1,21 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "RQF_SOFTBARRIER" "linux/blkdev.h" +then + add_define "CAS_CHECK_BARRIER(bio) \\ + ((CAS_BIO_OP_FLAGS(bio) & RQF_SOFTBARRIER) != 0)" +elif compile_module "REQ_SOFTBARRIER" "linux/blk_types.h" +then + add_define "CAS_CHECK_BARRIER(bio) \\ + ((CAS_BIO_OP_FLAGS(bio) & REQ_SOFTBARRIER) != 0)" +elif compile_module "BIO_RW_BARRIER" "linux/fs.h" +then + add_define "CAS_CHECK_BARRIER(bio) \\ + (bio_rw_flagged((bio), BIO_RW_BARRIER))" +fi diff --git a/configure.d/bio_clone.conf b/configure.d/bio_clone.conf new file mode 100644 index 0000000..cda76c6 --- /dev/null +++ b/configure.d/bio_clone.conf @@ -0,0 +1,27 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "bio_clone(NULL, 0)" "linux/bio.h" +then + add_function "static inline struct bio *cas_bio_clone(struct bio *bio, gfp_t gfp_mask) + { + return bio_clone(bio, gfp_mask); + }" +elif compile_module "bio_clone_kmalloc(NULL, 0)" "linux/bio.h" +then + add_function "static inline struct bio *cas_bio_clone(struct bio *bio, gfp_t gfp_mask) + { + return bio_clone_kmalloc(bio, gfp_mask); + }" +elif compile_module "bio_clone_fast(NULL, 0, NULL)" "linux/bio.h" +then + add_function "static inline struct bio *cas_bio_clone(struct bio *bio, gfp_t gfp_mask) + { + return bio_clone_fast(bio, gfp_mask, NULL); + }" +fi diff --git a/configure.d/bio_cmpl.conf b/configure.d/bio_cmpl.conf new file mode 100644 index 0000000..0ee2a0d --- /dev/null +++ b/configure.d/bio_cmpl.conf @@ -0,0 +1,31 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "struct bio b;b.bi_end_io(NULL, 0)" "linux/bio.h" +then + add_define "CAS_BIO_ENDIO(BIO, BYTES_DONE, ERROR) \\ + bio_endio(BIO, ERROR)" + add_define "CAS_DECLARE_BLOCK_CALLBACK(name, BIO, BYTES_DONE, ERROR) \\ + void name##_callback(BIO, ERROR)" + add_define "CAS_BLOCK_CALLBACK_ERROR(BIO, ERROR) \\ + ERROR" +elif compile_module "struct bio b;b.bi_end_io(NULL)" "linux/bio.h" +then + add_define "CAS_BIO_ENDIO(BIO, BYTES_DONE, ERROR) \\ + ({ CAS_BIO_OP_STATUS(BIO) = ERROR; bio_endio(BIO); })" + add_define "CAS_DECLARE_BLOCK_CALLBACK(name, BIO, BYTES_DONE, ERROR) \\ + void name##_callback(BIO)" + add_define "CAS_BLOCK_CALLBACK_ERROR(BIO, ERROR) \\ + CAS_BIO_OP_STATUS(BIO)" +fi +add_define "CAS_REFER_BLOCK_CALLBACK(name) \\ + name##_callback" +add_define "CAS_BLOCK_CALLBACK_INIT(BIO) \\ + {; }" +add_define "CAS_BLOCK_CALLBACK_RETURN(BIO) \\ + { return; }" diff --git a/configure.d/bio_discard.conf b/configure.d/bio_discard.conf new file mode 100644 index 0000000..0d128b9 --- /dev/null +++ b/configure.d/bio_discard.conf @@ -0,0 +1,33 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "bio_op(NULL)" "linux/bio.h" +then + add_define "CAS_IS_DISCARD(bio) \\ + (bio_op(bio) == REQ_OP_DISCARD)" + add_define "CAS_BIO_DISCARD \\ + (REQ_OP_DISCARD)" +elif compile_module "REQ_OP_MASK" "linux/blk_types.h" +then + add_define "CAS_IS_DISCARD(bio) \\ + (((CAS_BIO_OP_FLAGS(bio)) & REQ_OP_MASK) == REQ_OP_DISCARD)" + add_define "CAS_BIO_DISCARD \\ + ((REQ_OP_WRITE | REQ_OP_DISCARD))" +elif compile_module "REQ_OP_DISCARD" "linux/blk_types.h" +then + add_define "CAS_IS_DISCARD(bio) \\ + ((CAS_BIO_OP_FLAGS(bio)) & REQ_OP_DISCARD)" + add_define "CAS_BIO_DISCARD \\ + ((REQ_OP_WRITE | REQ_OP_DISCARD))" +elif compile_module "REQ_DISCARD" "linux/blk_types.h" +then + add_define "CAS_IS_DISCARD(bio) \\ + ((CAS_BIO_OP_FLAGS(bio)) & REQ_DISCARD)" + add_define "CAS_BIO_DISCARD \\ + (REQ_WRITE | REQ_DISCARD)" +fi diff --git a/configure.d/bio_err.conf b/configure.d/bio_err.conf new file mode 100644 index 0000000..b980a83 --- /dev/null +++ b/configure.d/bio_err.conf @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "struct bio b;b.bi_status" "linux/bio.h" +then + add_define "CAS_BIO_OP_STATUS(bio) \\ + bio->bi_status" +elif compile_module "struct bio b;b.bi_error" "linux/bio.h" +then + add_define "CAS_BIO_OP_STATUS(bio) \\ + bio->bi_error" +fi diff --git a/configure.d/bio_flags.conf b/configure.d/bio_flags.conf new file mode 100644 index 0000000..70f9083 --- /dev/null +++ b/configure.d/bio_flags.conf @@ -0,0 +1,19 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "struct bio b;b.bi_opf" "linux/bio.h" +then + add_define "CAS_BIO_OP_FLAGS_FORMAT \"0x%016X\"" + add_define "CAS_BIO_OP_FLAGS(bio) \\ + (bio)->bi_opf" +elif compile_module "struct bio b;b.bi_rw" "linux/bio.h" +then + add_define "CAS_BIO_OP_FLAGS_FORMAT \"0x%016lX\"" + add_define "CAS_BIO_OP_FLAGS(bio) \\ + (bio)->bi_rw" +fi diff --git a/configure.d/bio_iter.conf b/configure.d/bio_iter.conf new file mode 100644 index 0000000..54c3d05 --- /dev/null +++ b/configure.d/bio_iter.conf @@ -0,0 +1,25 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "struct bio b;b.bi_iter.bi_size" "linux/bio.h" +then + add_define "CAS_BIO_BISIZE(bio) \\ + bio->bi_iter.bi_size" + add_define "CAS_BIO_BIIDX(bio) \\ + bio->bi_iter.bi_idx" + add_define "CAS_BIO_BISECTOR(bio) \\ + bio->bi_iter.bi_sector" +elif compile_module "struct bio b;b.bi_size" "linux/bio.h" +then + add_define "CAS_BIO_BISIZE(bio) \\ + bio->bi_size" + add_define "CAS_BIO_BIIDX(bio) \\ + bio->bi_idx" + add_define "CAS_BIO_BISECTOR(bio) \\ + bio->bi_sector" +fi diff --git a/configure.d/biovec.conf b/configure.d/biovec.conf new file mode 100644 index 0000000..758bcbe --- /dev/null +++ b/configure.d/biovec.conf @@ -0,0 +1,16 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "struct bio b;&bio_iovec(&b)" "linux/bio.h" +then + add_define "CAS_SEGMENT_BVEC(vec) \\ + (&(vec))" +else + add_define "CAS_SEGMENT_BVEC(vec) \\ + (vec)" +fi diff --git a/configure.d/block_pc.conf b/configure.d/block_pc.conf new file mode 100644 index 0000000..5cb4074 --- /dev/null +++ b/configure.d/block_pc.conf @@ -0,0 +1,16 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "blk_rq_set_block_pc(NULL)" "linux/blkdev.h" +then + add_define "cas_blk_rq_set_block_pc(rq) \\ + blk_rq_set_block_pc(rq)" +else + add_define "cas_blk_rq_set_block_pc(rq) \\ + {}" +fi diff --git a/configure.d/conf_framework b/configure.d/conf_framework new file mode 100644 index 0000000..18e25c2 --- /dev/null +++ b/configure.d/conf_framework @@ -0,0 +1,62 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +SCRIPTPATH=`dirname $0` +SCRIPTPATH=`realpath $SCRIPTPATH` +MODULE_FILE=$SCRIPTPATH/test_mod.c +OBJ_MOD=$SCRIPTPATH/test_mod.o +KERN_VER=`uname -r` +NPROC=`nproc` +DEFINE_FILE=$SCRIPTPATH/../modules/generated_defines.h + + +add_define() { + printf "#define %s\n" $1 >> $DEFINE_FILE +} + +add_function() { + printf "%s\n" $1 >> $DEFINE_FILE +} + +compile_module(){ + if [ $# -gt 1 ] + then + INCLUDE="#include <$2>" + else + INCLUDE="" + fi + + ############# TEST MODULE ############# + cat > $MODULE_FILE <<- EOF + #include + #include + $INCLUDE + + int init_module(void) { + $1; + return 0; + } + void cleanup_module(void) {}; + EOF + ####################################### + + make -C $SCRIPTPATH &> /dev/null + + local ret=$? + if [ $ret -eq 0 ]; then + make -C $SCRIPTPATH clean &> /dev/null + fi + + return $ret +} + +kernel_not_supp_fail() { + echo "Current kernel is not supported!" + rm $DEFINE_FILE + exit 1 +} + +IFS='?' diff --git a/configure.d/deamonize.conf b/configure.d/deamonize.conf new file mode 100644 index 0000000..36f7570 --- /dev/null +++ b/configure.d/deamonize.conf @@ -0,0 +1,16 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "deamonize(\"some_name\", NULL)" "linux/sched.h" +then + add_define "CAS_DAEMONIZE(name, arg...) \\ + daemonize(name, ##arg)" +else + add_define "CAS_DAEMONIZE(name, arg...) \\ + do { } while (0)" +fi diff --git a/configure.d/dentry.conf b/configure.d/dentry.conf new file mode 100644 index 0000000..ef3f6fe --- /dev/null +++ b/configure.d/dentry.conf @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "struct dentry dentry;dentry.d_u.d_alias" "linux/dcache.h" +then + add_define "CAS_ALIAS_NODE_TO_DENTRY(alias) \\ + container_of(alias, struct dentry, d_u.d_alias)" +elif compile_module "struct dentry dentry;dentry.d_alias" "linux/dcache.h" +then + add_define "CAS_ALIAS_NODE_TO_DENTRY(alias) \\ + container_of(alias, struct dentry, d_alias)" +fi diff --git a/configure.d/discard_zeros.conf b/configure.d/discard_zeros.conf new file mode 100644 index 0000000..eb80767 --- /dev/null +++ b/configure.d/discard_zeros.conf @@ -0,0 +1,16 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "struct queue_limits q;q.discard_zeroes_data" "linux/blkdev.h" +then + add_define "CAS_SET_DISCARD_ZEROES_DATA(queue_limits, val) \\ + queue_limits.discard_zeroes_data = val" +else + add_define "CAS_SET_DISCARD_ZEROES_DATA(queue_limits, val) \\ + ({})" +fi diff --git a/configure.d/flush_flag.conf b/configure.d/flush_flag.conf new file mode 100644 index 0000000..f7973e1 --- /dev/null +++ b/configure.d/flush_flag.conf @@ -0,0 +1,21 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "REQ_PREFLUSH" "linux/blk_types.h" +then + add_define "CAS_REQ_FLUSH \\ + REQ_PREFLUSH" + add_define "CAS_FLUSH_SUPPORTED \\ + 1" +elif compile_module "REQ_FLUSH" "linux/blk_types.h" +then + add_define "CAS_REQ_FLUSH \\ + REQ_FLUSH" + add_define "CAS_FLUSH_SUPPORTED \\ + 1" +fi diff --git a/configure.d/flush_fua.conf b/configure.d/flush_fua.conf new file mode 100644 index 0000000..9365906 --- /dev/null +++ b/configure.d/flush_fua.conf @@ -0,0 +1,32 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "WRITE_FLUSH_FUA" "linux/fs.h" +then + add_define "CAS_WRITE_FLUSH_FUA \\ + WRITE_FLUSH_FUA" + if compile_module "BIO_FUA" "linux/bio.h" + then + add_define "CAS_IS_WRITE_FLUSH_FUA(flags) \\ + ((BIO_FUA | BIO_FLUSH) == ((flags) & (BIO_FUA | BIO_FLUSH)))" + else + add_define "CAS_IS_WRITE_FLUSH_FUA(flags) \\ + ((REQ_FUA | CAS_REQ_FLUSH) == ((flags) & (REQ_FUA | CAS_REQ_FLUSH)))" + fi +elif compile_module "REQ_PREFLUSH" "linux/blk_types.h" +then + add_define "CAS_IS_WRITE_FLUSH_FUA(flags) \\ + ((REQ_PREFLUSH | REQ_FUA) == ((flags) & (REQ_PREFLUSH |REQ_FUA)))" + add_define "CAS_WRITE_FLUSH_FUA \\ + (REQ_PREFLUSH | REQ_FUA)" +else + add_define "CAS_IS_WRITE_FLUSH_FUA(flags) \\ + 0" + add_define "CAS_WRITE_FLUSH_FUA \\ + WRITE_BARRIER" +fi diff --git a/configure.d/generic_acct.conf b/configure.d/generic_acct.conf new file mode 100644 index 0000000..2f1da4a --- /dev/null +++ b/configure.d/generic_acct.conf @@ -0,0 +1,85 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if +compile_module "generic_start_io_acct(NULL, 0, 0, NULL)" "linux/bio.h" +then + add_function " +static inline void cas_generic_start_io_acct(struct request_queue *q, + int rw, unsigned long sectors, struct hd_struct *part) { + generic_start_io_acct(q, rw, sectors, part); +}" + add_function " +static inline void cas_generic_end_io_acct(struct request_queue *q, + int rw, struct hd_struct *part, unsigned long start_time) +{ + generic_end_io_acct(q, rw, part, start_time); +}" +elif compile_module "generic_start_io_acct(0, 0, NULL)" "linux/bio.h" +then + add_function " +static inline void cas_generic_start_io_acct(struct request_queue *q, + int rw, unsigned long sectors, struct hd_struct *part) +{ + generic_start_io_acct(rw, sectors, part); +}" + add_function " +static inline void cas_generic_end_io_acct(struct request_queue *q, + int rw, struct hd_struct *part, unsigned long start_time) +{ + generic_end_io_acct(rw, part, start_time); +}" +elif compile_module "part_round_stats(1, 1)" "linux/genhd.h" +then + add_function " +static inline void cas_generic_start_io_acct(struct request_queue *q, + int rw, unsigned long sectors, struct hd_struct *part) +{ + int cpu = part_stat_lock(); + part_round_stats(cpu, part); + part_stat_inc(cpu, part, ios[rw]); + part_stat_add(cpu, part, sectors[rw], sectors); + part_inc_in_flight(part, rw); + part_stat_unlock(); +}" + add_function " +static inline void cas_generic_end_io_acct(struct request_queue *q, + int rw, struct hd_struct *part, unsigned long start_time) +{ + unsigned long duration = jiffies - start_time; + int cpu = part_stat_lock(); + part_stat_add(cpu, part, ticks[rw], duration); + part_round_stats(cpu, part); + part_dec_in_flight(part, rw); + part_stat_unlock(); +}" +elif compile_module "part_round_stats(NULL, 1, 1)" "linux/genhd.h" +then + add_function " +static inline void cas_generic_start_io_acct(struct request_queue *q, + int rw, unsigned long sectors, struct hd_struct *part) +{ + int cpu = part_stat_lock(); + part_round_stats(NULL, cpu, part); + part_stat_inc(cpu, part, ios[rw]); + part_stat_add(cpu, part, sectors[rw], sectors); + part_inc_in_flight(NULL, part, rw); + part_stat_unlock(); +}" + add_function " +static inline void cas_generic_end_io_acct(struct request_queue *q, + int rw, struct hd_struct *part, unsigned long start_time) +{ + unsigned long duration = jiffies - start_time; + int cpu = part_stat_lock(); + part_stat_add(cpu, part, ticks[rw], duration); + part_round_stats(NULL, cpu, part); + part_dec_in_flight(NULL, part, rw); + part_stat_unlock(); +}" +fi diff --git a/configure.d/global_page_state.conf b/configure.d/global_page_state.conf new file mode 100644 index 0000000..386375d --- /dev/null +++ b/configure.d/global_page_state.conf @@ -0,0 +1,32 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + + +if compile_module "global_zone_page_state(1)" "linux/mm.h" +then + add_function " +static inline unsigned long cas_global_zone_page_state(enum zone_stat_item item) + { + return global_zone_page_state(item); + }" + add_define "CAS_BIO_SET_DEV(bio, bdev) \\ + bio_set_dev(bio, bdev)" + add_define "CAS_BIO_GET_DEV(bio) \\ + bio->bi_disk" +elif compile_module "global_page_state(1)" "linux/mm.h" +then + add_function " +static inline unsigned long cas_global_zone_page_state(enum zone_stat_item item) + { + return global_page_state(item); + }" + add_define "CAS_BIO_SET_DEV(bio, bdev) \\ + bio->bi_bdev = bdev" + add_define "CAS_BIO_GET_DEV(bio) \\ + bio->bi_bdev->bd_disk" +fi diff --git a/configure.d/hlist.conf b/configure.d/hlist.conf new file mode 100644 index 0000000..6d1f45c --- /dev/null +++ b/configure.d/hlist.conf @@ -0,0 +1,25 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "struct hlist_node list" "linux/types.h" +then + add_define "CAS_ALIAS_NODE_TYPE \\ + struct hlist_node" + add_define "CAS_DENTRY_LIST_EMPTY(head) \\ + hlist_empty(head)" + add_define "CAS_INODE_FOR_EACH_DENTRY(pos, head) \\ + hlist_for_each(pos, head)" +elif compile_module "struct list_head list" "linux/list.h" +then + add_define "CAS_ALIAS_NODE_TYPE \\ + struct list_head" + add_define "CAS_DENTRY_LIST_EMPTY(head) \\ + list_empty(head)" + add_define "CAS_INODE_FOR_EACH_DENTRY(pos, head) \\ + list_for_each(pos, head)" +fi diff --git a/configure.d/inode.conf b/configure.d/inode.conf new file mode 100644 index 0000000..a925287 --- /dev/null +++ b/configure.d/inode.conf @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "struct file file;file.f_inode" "linux/fs.h" +then + add_define "CAS_FILE_INODE(file) \\ + file->f_inode" +elif compile_module "struct file file;file->f_dentry->d_inode" "linux/fs.h" +then + add_define "CAS_FILE_INODE(file) \\ + file->f_dentry->d_inode" +fi diff --git a/configure.d/make_req.conf b/configure.d/make_req.conf new file mode 100644 index 0000000..b294d4a --- /dev/null +++ b/configure.d/make_req.conf @@ -0,0 +1,39 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "blk_make_request(NULL, NULL, 0)" "linux/blkdev.h" +then + add_function " +static inline struct request *cas_blk_make_request(struct request_queue *q, + struct bio *bio, gfp_t gfp_mask) +{ + return blk_make_request(q, bio, gfp_mask); +}" +else + add_function " +static inline struct request *cas_blk_make_request(struct request_queue *q, + struct bio *bio, gfp_t gfp_mask) +{ + struct request *rq = blk_get_request(q, bio_data_dir(bio), gfp_mask); + if (IS_ERR(rq)) + return rq; + cas_blk_rq_set_block_pc(rq); + rq->q = q; + for_each_bio(bio) { + struct bio *bounce_bio = bio; + int ret; + cas_blk_queue_bounce(q, &bounce_bio); + ret = cas_blk_rq_append_bio(rq, bounce_bio); + if (unlikely(ret)) { + blk_put_request(rq); + return ERR_PTR(ret); + } + } + return rq; +}" +fi diff --git a/configure.d/munmap.conf b/configure.d/munmap.conf new file mode 100644 index 0000000..2201a8b --- /dev/null +++ b/configure.d/munmap.conf @@ -0,0 +1,39 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "vm_munmap(0, 0)" "linux/mm.h" +then + add_function " +#include +static inline unsigned long cas_vm_mmap(struct file *file, + unsigned long addr, unsigned long len) +{ + return vm_mmap(file, addr, len, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, 0); +}" + add_function " +static inline int cas_vm_munmap(unsigned long start, size_t len) +{ + return vm_munmap(start, len); +}" +elif compile_module "do_munmap(NULL, 0)" "linux/mm.h" +then + add_function " +#include +static inline unsigned long cas_vm_mmap(struct file *file, + unsigned long addr, unsigned long len) +{ + return do_mmap_pgoff(file, addr, len, PROT_READ | PROT_WRITE, + MAP_ANONYMOUS | MAP_PRIVATE, 0); +}" + add_function " +static inline int cas_vm_munmap(unsigned long start, size_t len) +{ + return do_munmap(current->mm, start, len); +}" +fi diff --git a/configure.d/queue_bounce.conf b/configure.d/queue_bounce.conf new file mode 100644 index 0000000..0c20524 --- /dev/null +++ b/configure.d/queue_bounce.conf @@ -0,0 +1,16 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "blk_queue_bounce(NULL, NULL);" "linux/blkdev.h" +then + add_define "cas_blk_queue_bounce(q, bounce_bio) \\ + blk_queue_bounce(q, bounce_bio)" +else + add_define "cas_blk_queue_bounce(q, bounce_bio) \\ + ({})" +fi diff --git a/configure.d/queue_chunk_sectors.conf b/configure.d/queue_chunk_sectors.conf new file mode 100644 index 0000000..84a2bf8 --- /dev/null +++ b/configure.d/queue_chunk_sectors.conf @@ -0,0 +1,16 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "struct request_queue q;q.limits.chunk_sectors" "linux/blkdev.h" +then + add_define "CAS_SET_QUEUE_CHUNK_SECTORS(queue, chunk_size) \\ + queue->limits.chunk_sectors = chunk_size" +else + add_define "CAS_SET_QUEUE_CHUNK_SECTORS(queue, chunk_size) \\ + {;}" +fi diff --git a/configure.d/queue_flag_set.conf b/configure.d/queue_flag_set.conf new file mode 100644 index 0000000..0dcbcb4 --- /dev/null +++ b/configure.d/queue_flag_set.conf @@ -0,0 +1,16 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "blk_queue_flag_set(0, NULL)" "linux/blkdev.h" +then + add_define "cas_queue_flag_set_unlocked(flag, request_queue) \\ + blk_queue_flag_set(flag, request_queue)" +else + add_define "cas_queue_flag_set_unlocked(flag, request_queue) \\ + queue_flag_set_unlocked(flag, request_queue)" +fi diff --git a/configure.d/queue_limits.conf b/configure.d/queue_limits.conf new file mode 100644 index 0000000..0b55921 --- /dev/null +++ b/configure.d/queue_limits.conf @@ -0,0 +1,53 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +# RHEL 7.3 +if compile_module "struct queue_limits q;q.limits_aux" "linux/blkdev.h" +then + add_function " +static inline void cas_copy_queue_limits(struct request_queue *exp_q, + struct request_queue *cache_q, struct request_queue *core_q) +{ + struct queue_limits_aux *l_aux = exp_q->limits.limits_aux; + exp_q->limits = cache_q->limits; + exp_q->limits.limits_aux = l_aux; + if (exp_q->limits.limits_aux && cache_q->limits.limits_aux) + *exp_q->limits.limits_aux = *cache_q->limits.limits_aux; + exp_q->limits.max_sectors = core_q->limits.max_sectors; + exp_q->limits.max_hw_sectors = core_q->limits.max_hw_sectors; + exp_q->limits.max_segments = core_q->limits.max_segments; + exp_q->limits.max_write_same_sectors = 0; + if (queue_virt_boundary(cache_q)) + queue_flag_set(QUEUE_FLAG_NOMERGES, cache_q); +}" +elif compile_module "struct queue_limits q;q.max_write_zeroes_sectors" "linux/blkdev.h" +then + add_function " +static inline void cas_copy_queue_limits(struct request_queue *exp_q, + struct request_queue *cache_q, struct request_queue *core_q) +{ + exp_q->limits = cache_q->limits; + exp_q->limits.max_sectors = core_q->limits.max_sectors; + exp_q->limits.max_hw_sectors = core_q->limits.max_hw_sectors; + exp_q->limits.max_segments = core_q->limits.max_segments; + exp_q->limits.max_write_same_sectors = 0; + exp_q->limits.max_write_zeroes_sectors = 0; +}" +elif compile_module "struct queue_limits q;q.max_write_same_sectors" "linux/blkdev.h" +then + add_function " +static inline void cas_copy_queue_limits(struct request_queue *exp_q, + struct request_queue *cache_q, struct request_queue *core_q) +{ + exp_q->limits = cache_q->limits; + exp_q->limits.max_sectors = core_q->limits.max_sectors; + exp_q->limits.max_hw_sectors = core_q->limits.max_hw_sectors; + exp_q->limits.max_segments = core_q->limits.max_segments; + exp_q->limits.max_write_same_sectors = 0; +}" +fi diff --git a/configure.d/queue_write.conf b/configure.d/queue_write.conf new file mode 100644 index 0000000..34a6596 --- /dev/null +++ b/configure.d/queue_write.conf @@ -0,0 +1,38 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "blk_queue_write_cache(NULL, 0, 0)" "linux/blkdev.h" +then + add_define "CAS_CHECK_QUEUE_FLUSH(q) \\ + test_bit(QUEUE_FLAG_WC, &(q)->queue_flags)" + add_define "CAS_CHECK_QUEUE_FUA(q) \\ + test_bit(QUEUE_FLAG_FUA, &(q)->queue_flags)" + add_function " +static inline void cas_set_queue_flush_fua(struct request_queue *q, + bool flush, bool fua) +{ + blk_queue_write_cache(q, flush, fua); +}" +elif compile_module "struct request_queue rq;rq.flush_flags" "linux/blkdev.h" +then + add_define "CAS_CHECK_QUEUE_FLUSH(q) \\ + ((q)->flush_flags & CAS_REQ_FLUSH)" + add_define "CAS_CHECK_QUEUE_FUA(q) \\ + ((q)->flush_flags & REQ_FUA)" + add_function "static inline void cas_set_queue_flush_fua(struct request_queue *q, + bool flush, bool fua) +{ + unsigned int flags = 0; + if (flush) + flags |= CAS_REQ_FLUSH; + if (fua) + flags |= REQ_FUA; + if (flags) + blk_queue_flush(q, flags); +}" +fi diff --git a/configure.d/req_fs.conf b/configure.d/req_fs.conf new file mode 100644 index 0000000..92d9f9d --- /dev/null +++ b/configure.d/req_fs.conf @@ -0,0 +1,30 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "REQ_TYPE_FS" "linux/blkdev.h" +then + add_function " +static inline int cas_is_rq_type_fs(struct request *rq) +{ + return rq->cmd_type == REQ_TYPE_FS; +}" +else + add_function " +static inline int cas_is_rq_type_fs(struct request *rq) +{ + switch (req_op(rq)){ + case REQ_OP_READ: + case REQ_OP_WRITE: + case REQ_OP_FLUSH: + case REQ_OP_DISCARD: + return true; + default: + return false; + } +}" +fi diff --git a/configure.d/submit_bio.conf b/configure.d/submit_bio.conf new file mode 100644 index 0000000..4652f26 --- /dev/null +++ b/configure.d/submit_bio.conf @@ -0,0 +1,44 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +# submit_bio() can be defined in "bio.h" or in "fs.h" +# If it is defind in fs.h, three possibilities are available: +# * it takes one argument and retuns non-void +# * it takes two arguments and returns non-void +# * it takse two arguments and is void-type +if compile_module "submit_bio(NULL)" "linux/bio.h" +then + add_function " +static inline blk_qc_t cas_submit_bio(int rw, struct bio *bio) +{ + CAS_BIO_OP_FLAGS(bio) |= rw; + return submit_bio(bio); +}" +elif compile_module "submit_bio(NULL)" "linux/fs.h" +then + add_function " +static inline blk_qc_t cas_submit_bio(int rw, struct bio *bio) +{ + CAS_BIO_OP_FLAGS(bio) |= rw; + return submit_bio(bio); +}" +elif compile_module "void *t=submit_bio(0, NULL)" "linux/fs.h" +then + add_function " +static inline blk_qc_t cas_submit_bio(int rw, struct bio *bio) +{ + return submit_bio(rw, bio); +}" +elif compile_module "submit_bio(0, NULL)" "linux/fs.h" +then + add_function " +static inline void cas_submit_bio(int rw, struct bio *bio) +{ + submit_bio(rw, bio); +}" +fi diff --git a/configure.d/whlt.conf b/configure.d/whlt.conf new file mode 100644 index 0000000..1a4e26e --- /dev/null +++ b/configure.d/whlt.conf @@ -0,0 +1,13 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "struct bio b;b.bi_write_hint" "linux/bio.h" +then + add_define "CAS_WLTH_SUPPORT \\ + 1" +fi diff --git a/configure.d/write_flag.conf b/configure.d/write_flag.conf new file mode 100644 index 0000000..db41dff --- /dev/null +++ b/configure.d/write_flag.conf @@ -0,0 +1,17 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "WRITE" "linux/blk_types.h" +then + add_define "CAS_RQ_DATA_DIR_WR \\ + WRITE" +elif compile_module "REQ_WRITE" "linux/blk_types.h" +then + add_define "CAS_RQ_DATA_DIR_WR \\ + REQ_WRITE" +fi diff --git a/configure.d/write_flush.conf b/configure.d/write_flush.conf new file mode 100644 index 0000000..d689669 --- /dev/null +++ b/configure.d/write_flush.conf @@ -0,0 +1,38 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "WRITE_FLUSH" "linux/fs.h" +then + add_define "CAS_RQ_IS_FLUSH(rq) \\ + ((rq)->cmd_flags & CAS_REQ_FLUSH)" + add_define "CAS_WRITE_FLUSH \\ + WRITE_FLUSH" + if compile_module "BIO_FLUSH" "linux/bio.h" + then + add_define "CAS_IS_WRITE_FLUSH(flags) \\ + ((flags) & BIO_FLUSH)" + else + add_define "CAS_IS_WRITE_FLUSH(flags) \\ + ((flags) & CAS_REQ_FLUSH)" + fi +elif compile_module "REQ_PREFLUSH" "linux/blk_types.h" +then + add_define "CAS_RQ_IS_FLUSH(rq) \\ + ((rq)->cmd_flags & REQ_PREFLUSH)" + add_define "CAS_WRITE_FLUSH \\ + (REQ_OP_WRITE | REQ_PREFLUSH)" + add_define "CAS_IS_WRITE_FLUSH(flags) \\ + (CAS_WRITE_FLUSH == ((flags) & CAS_WRITE_FLUSH))" +else + add_define "CAS_RQ_IS_FLUSH(rq) \\ + 0" + add_define "CAS_IS_WRITE_FLUSH(flags) \\ + (WRITE_BARRIER == ((flags) & WRITE_BARRIER))" + add_define "CAS_WRITE_FLUSH \\ + WRITE_BARRIER" +fi diff --git a/configure.d/write_fua.conf b/configure.d/write_fua.conf new file mode 100644 index 0000000..98f7589 --- /dev/null +++ b/configure.d/write_fua.conf @@ -0,0 +1,32 @@ +#!/bin/bash +# +# Copyright(c) 2012-2019 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. `dirname $0`/conf_framework + +if compile_module "WRITE_FUA" "linux/fs.h" +then + add_define "CAS_WRITE_FUA \\ + WRITE_FUA" + if compile_module "BIO_FUA" "linux/bio.h" + then + add_define "CAS_IS_WRITE_FUA(flags) \\ + ((flags) & BIO_FUA)" + else + add_define "CAS_IS_WRITE_FUA(flags) \\ + ((flags) & REQ_FUA)" + fi +elif compile_module "REQ_FUA" "linux/blk_types.h" +then + add_define "CAS_IS_WRITE_FUA(flags) \\ + ((flags) & REQ_FUA)" + add_define "CAS_WRITE_FUA \\ + REQ_FUA" +else + add_define "CAS_IS_WRITE_FUA(flags) \\ + 0" + add_define "CAS_WRITE_FUA \\ + WRITE_BARRIER" +fi diff --git a/modules/Makefile b/modules/Makefile index 6ecbbc3..c32d182 100644 --- a/modules/Makefile +++ b/modules/Makefile @@ -47,8 +47,8 @@ default: $(VERSION_FILE) sync clean: cd $(KERNEL_DIR) && make M=$(PWD) clean - rm $(PWD)/generated_defines.h distclean: clean distsync + rm $(PWD)/generated_defines.h install: @echo "Installing Open-CAS modules" diff --git a/modules/cas_cache/classifier.c b/modules/cas_cache/classifier.c index d442e15..9dd658e 100644 --- a/modules/cas_cache/classifier.c +++ b/modules/cas_cache/classifier.c @@ -209,7 +209,7 @@ static cas_cls_eval_t _cas_cls_numeric_test_u( return cas_cls_eval_no; } -#ifdef WLTH_SUPPORT +#ifdef CAS_WLTH_SUPPORT /* Write lifetime hint condition test */ static cas_cls_eval_t _cas_cls_wlth_test(struct cas_classifier *cls, struct cas_cls_condition *c, struct cas_cls_io *io, @@ -300,9 +300,9 @@ static void _cas_cls_directory_resolve_work(struct work_struct *work) static struct dentry *_cas_cls_dir_get_inode_dentry(struct inode *inode) { struct dentry *d = NULL, *iter; - ALIAS_NODE_TYPE *pos; /* alias list current element */ + CAS_ALIAS_NODE_TYPE *pos; /* alias list current element */ - if (DENTRY_LIST_EMPTY(&inode->i_dentry)) + if (CAS_DENTRY_LIST_EMPTY(&inode->i_dentry)) return NULL; spin_lock(&inode->i_lock); @@ -310,8 +310,8 @@ static struct dentry *_cas_cls_dir_get_inode_dentry(struct inode *inode) if (S_ISDIR(inode->i_mode)) goto unlock; - INODE_FOR_EACH_DENTRY(pos, &inode->i_dentry) { - iter = ALIAS_NODE_TO_DENTRY(pos); + CAS_INODE_FOR_EACH_DENTRY(pos, &inode->i_dentry) { + iter = CAS_ALIAS_NODE_TO_DENTRY(pos); spin_lock(&iter->d_lock); if (!d_unhashed(iter)) d = iter; @@ -428,7 +428,7 @@ static struct cas_cls_condition_handler _handlers[] = { _cas_cls_generic_dtr }, { "directory", _cas_cls_directory_test, _cas_cls_directory_ctr, _cas_cls_directory_dtr }, -#ifdef WLTH_SUPPORT +#ifdef CAS_WLTH_SUPPORT { "wlth", _cas_cls_wlth_test, _cas_cls_numeric_ctr, _cas_cls_generic_dtr}, #endif @@ -929,7 +929,7 @@ static void _cas_cls_get_bio_context(struct bio *bio, return; ctx->bio = bio; - if (!SEGMENT_BVEC(bio_iovec(bio))) + if (!CAS_SEGMENT_BVEC(bio_iovec(bio))) return; page = bio_page(bio); diff --git a/modules/cas_cache/context.c b/modules/cas_cache/context.c index 583d63c..76d851d 100644 --- a/modules/cas_cache/context.c +++ b/modules/cas_cache/context.c @@ -338,7 +338,7 @@ static int _cas_ctx_logger_print_rl(ocf_logger_t logger, const char *func_name) if (!func_name) return -EINVAL; - return CAS_RATELIMIT(&cas_log_rl, func_name); + return ___ratelimit(&cas_log_rl, func_name); } /* diff --git a/modules/cas_cache/layer_cache_management.c b/modules/cas_cache/layer_cache_management.c index ffd6b71..c1baec9 100644 --- a/modules/cas_cache/layer_cache_management.c +++ b/modules/cas_cache/layer_cache_management.c @@ -368,7 +368,8 @@ int cache_mng_cache_check_device(struct kcas_cache_check_device *cmd_info) char holder[] = "CAS CHECK CACHE DEVICE\n"; int result; - bdev = OPEN_BDEV_EXCLUSIVE(cmd_info->path_name, FMODE_READ, holder); + bdev = blkdev_get_by_path(cmd_info->path_name, (FMODE_EXCL|FMODE_READ), + holder); if (IS_ERR(bdev)) { return (PTR_ERR(bdev) == -EBUSY) ? -OCF_ERR_NOT_OPEN_EXC : @@ -392,7 +393,7 @@ int cache_mng_cache_check_device(struct kcas_cache_check_device *cmd_info) cas_blk_close_volume(volume); out_bdev: - CLOSE_BDEV_EXCLUSIVE(bdev, FMODE_READ); + blkdev_put(bdev, (FMODE_EXCL|FMODE_READ)); return result; } @@ -455,7 +456,7 @@ int cache_mng_update_core_uuid(ocf_cache_t cache, ocf_core_id_t id, ocf_uuid_t u bdvol = bd_object(vol); /* lookup block device object for device pointed by uuid */ - bdev = LOOKUP_BDEV(uuid->data); + bdev = CAS_LOOKUP_BDEV(uuid->data); if (IS_ERR(bdev)) { printk(KERN_ERR "failed to lookup bdev%s\n", (char*)uuid->data); return -ENODEV; @@ -958,7 +959,8 @@ int cache_mng_prepare_cache_cfg(struct ocf_mngt_cache_config *cfg, return -OCF_ERR_INVAL; } - bdev = OPEN_BDEV_EXCLUSIVE(device_cfg->uuid.data, FMODE_READ, holder); + bdev = blkdev_get_by_path(device_cfg->uuid.data, (FMODE_EXCL|FMODE_READ), + holder); if (IS_ERR(bdev)) { return (PTR_ERR(bdev) == -EBUSY) ? -OCF_ERR_NOT_OPEN_EXC : @@ -967,7 +969,7 @@ int cache_mng_prepare_cache_cfg(struct ocf_mngt_cache_config *cfg, is_part = (bdev->bd_contains != bdev); part_count = cas_blk_get_part_count(bdev); - CLOSE_BDEV_EXCLUSIVE(bdev, FMODE_READ); + blkdev_put(bdev, (FMODE_EXCL|FMODE_READ)); if (!is_part && part_count > 1 && !device_cfg->force) return -KCAS_ERR_CONTAINS_PART; diff --git a/modules/cas_cache/linux_kernel_version.h b/modules/cas_cache/linux_kernel_version.h index aecbc87..981a1b0 100644 --- a/modules/cas_cache/linux_kernel_version.h +++ b/modules/cas_cache/linux_kernel_version.h @@ -37,6 +37,7 @@ #include #include #include +#include #include "generated_defines.h" @@ -51,294 +52,6 @@ #endif #endif -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 32) - #error Unsupported Linux Kernel Version -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 19, 0) - #define FILE_INODE(file) file->f_inode -#else - #define FILE_INODE(file) file->f_dentry->d_inode -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 76) - #define DENTRY_ALIAS_HEAD(dentry) (dentry)->d_u.d_alias - #define ALIAS_NODE_TO_DENTRY(alias) container_of(alias, struct dentry, d_u.d_alias) -#else - #define DENTRY_ALIAS_HEAD(dentry) (dentry)->d_alias - #define ALIAS_NODE_TO_DENTRY(alias) container_of(alias, struct dentry, d_alias) -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 6, 0) - #define ALIAS_NODE_TYPE struct hlist_node - #define DENTRY_LIST_EMPTY(head) hlist_empty(head) - #define INODE_FOR_EACH_DENTRY(pos, head) hlist_for_each(pos, head) -#else - #define DENTRY_LIST_EMPTY(head) list_empty(head) - #define ALIAS_NODE_TYPE struct list_head - #define INODE_FOR_EACH_DENTRY(pos, head) list_for_each(pos, head) -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0) - #define BIO_OP_STATUS(bio) bio->bi_status -#else - #define BIO_OP_STATUS(bio) bio->bi_error -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0) -#define WLTH_SUPPORT -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0) - #define BIO_ENDIO(BIO, BYTES_DONE, ERROR) \ - ({ BIO_OP_STATUS(BIO) = ERROR; bio_endio(BIO); }) -#else - #define BIO_ENDIO(BIO, BYTES_DONE, ERROR) bio_endio(BIO, ERROR) -#endif - -#define REFER_BLOCK_CALLBACK(name) name##_callback -#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 3, 0) - #define DECLARE_BLOCK_CALLBACK(name, BIO, BYTES_DONE, ERROR) \ - void name##_callback(BIO, ERROR) - #define BLOCK_CALLBACK_INIT(BIO) {; } - #define BLOCK_CALLBACK_RETURN() { return; } - #define BLOCK_CALLBACK_ERROR(BIO, ERROR) ERROR -#else - #define DECLARE_BLOCK_CALLBACK(name, BIO, BYTES_DONE, ERROR) \ - void name##_callback(BIO) - #define BLOCK_CALLBACK_INIT(BIO) {; } - #define BLOCK_CALLBACK_RETURN() { return; } - #define BLOCK_CALLBACK_ERROR(BIO, ERROR) BIO_OP_STATUS(BIO) -#endif - -#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37) - #define OPEN_BDEV_EXCLUSIVE(PATH, FMODE, HOLDER) \ - blkdev_get_by_path(PATH, (FMODE_EXCL | FMODE), HOLDER) - #define CLOSE_BDEV_EXCLUSIVE(BDEV, FMODE) \ - blkdev_put(BDEV, (FMODE_EXCL | FMODE)) -#else - #define OPEN_BDEV_EXCLUSIVE(PATH, FMODE, HOLDER) \ - open_bdev_exclusive(PATH, FMODE, HOLDER) - #define CLOSE_BDEV_EXCLUSIVE(BDEV, FMODE) \ - close_bdev_exclusive(BDEV, FMODE) -#endif - -#ifdef CAS_UBUNTU - #define LOOKUP_BDEV(PATH) lookup_bdev(PATH, 0) -#else - #define LOOKUP_BDEV(PATH) lookup_bdev(PATH) -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) || defined CAS_SLES12SP3 - #define BIO_OP_FLAGS_FORMAT "0x%016X" - #define BIO_OP_FLAGS(bio) (bio)->bi_opf -#else - #define BIO_OP_FLAGS_FORMAT "0x%016lX" - #define BIO_OP_FLAGS(bio) (bio)->bi_rw -#endif - -#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 32) - #define BIO_RW_FLAGS ((1U << BIO_RW_UNPLUG) | \ - (1U << BIO_RW_NOIDLE) | (1U << BIO_RW_SYNCIO)) - #define BIO_SET_RW_FLAGS(bio) BIO_OP_FLAGS((bio)) |= BIO_RW_FLAGS -#else - #define BIO_RW_FLAGS 0 - #define BIO_SET_RW_FLAGS(bio) -#endif - -#if defined RQF_SOFTBARRIER - #define CHECK_BARRIER(bio) ((BIO_OP_FLAGS(bio) & RQF_SOFTBARRIER) != 0) -#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 0, 1) - #define CHECK_BARRIER(bio) ((BIO_OP_FLAGS(bio) & REQ_SOFTBARRIER) != 0) -#else - #define CHECK_BARRIER(bio) (bio_rw_flagged((bio), BIO_RW_BARRIER)) -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) || defined CAS_SLES12SP3 - #define RQ_DATA_DIR(rq) rq_data_dir(rq) - #define RQ_DATA_DIR_WR WRITE -#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 34) - #define RQ_DATA_DIR(rq) rq_data_dir(rq) - #define RQ_DATA_DIR_WR REQ_WRITE -#else - #define RQ_DATA_DIR(rq) rq_data_dir(rq) - #define RQ_DATA_DIR_WR WRITE -#endif - -#if defined REQ_PREFLUSH - #define CAS_REQ_FLUSH REQ_PREFLUSH - #define CAS_FLUSH_SUPPORTED -#elif defined REQ_FLUSH - #define CAS_REQ_FLUSH REQ_FLUSH - #define CAS_FLUSH_SUPPORTED -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 6, 0) || defined CAS_SLES12SP3 -#define CHECK_QUEUE_FLUSH(q) test_bit(QUEUE_FLAG_WC, &(q)->queue_flags) -#define CHECK_QUEUE_FUA(q) test_bit(QUEUE_FLAG_FUA, &(q)->queue_flags) - -static inline void cas_set_queue_flush_fua(struct request_queue *q, - bool flush, bool fua) -{ - blk_queue_write_cache(q, flush, fua); -} - -#else -#define CHECK_QUEUE_FLUSH(q) ((q)->flush_flags & CAS_REQ_FLUSH) -#define CHECK_QUEUE_FUA(q) ((q)->flush_flags & REQ_FUA) - -static inline void cas_set_queue_flush_fua(struct request_queue *q, - bool flush, bool fua) -{ - unsigned int flags = 0; - if (flush) - flags |= CAS_REQ_FLUSH; - if (fua) - flags |= REQ_FUA; - if (flags) - blk_queue_flush(q, flags); -} -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32) - - #ifdef WRITE_FLUSH - #define RQ_IS_FLUSH(rq) ((rq)->cmd_flags & CAS_REQ_FLUSH) - #ifdef BIO_FLUSH - #define CAS_IS_WRITE_FLUSH(flags) ((flags) & BIO_FLUSH) - #else - #define CAS_IS_WRITE_FLUSH(flags) \ - ((flags) & CAS_REQ_FLUSH) - #endif - - #define OCF_WRITE_FLUSH WRITE_FLUSH - #elif defined REQ_PREFLUSH - #define RQ_IS_FLUSH(rq) ((rq)->cmd_flags & REQ_PREFLUSH) - #define OCF_WRITE_FLUSH (REQ_OP_WRITE | REQ_PREFLUSH) - #define CAS_IS_WRITE_FLUSH(flags) \ - (OCF_WRITE_FLUSH == ((flags) & OCF_WRITE_FLUSH)) - #else - #define RQ_IS_FLUSH(rq) 0 - #define CAS_IS_WRITE_FLUSH(flags) \ - (WRITE_BARRIER == ((flags) & WRITE_BARRIER)) - #define OCF_WRITE_FLUSH WRITE_BARRIER - #endif /* #ifdef WRITE_FLUSH */ - - #ifdef WRITE_FLUSH_FUA - #define OCF_WRITE_FLUSH_FUA WRITE_FLUSH_FUA - #ifdef BIO_FUA - #define CAS_IS_WRITE_FLUSH_FUA(flags) \ - ((BIO_FUA | BIO_FLUSH) == \ - ((flags) & (BIO_FUA | BIO_FLUSH))) - #else - #define CAS_IS_WRITE_FLUSH_FUA(flags) \ - ((REQ_FUA | CAS_REQ_FLUSH) == \ - ((flags) & (REQ_FUA | CAS_REQ_FLUSH))) - #endif - - #elif defined REQ_PREFLUSH - #define CAS_IS_WRITE_FLUSH_FUA(flags) \ - ((REQ_PREFLUSH | REQ_FUA) == \ - ((flags) & (REQ_PREFLUSH |REQ_FUA))) - #define OCF_WRITE_FLUSH_FUA (REQ_PREFLUSH | REQ_FUA) - #else - #define CAS_IS_WRITE_FLUSH_FUA(flags) 0 - #define OCF_WRITE_FLUSH_FUA WRITE_BARRIER - #endif /* #ifdef WRITE_FLUSH_FUA */ - - #ifdef WRITE_FUA - #ifdef BIO_FUA - #define CAS_IS_WRITE_FUA(flags) ((flags) & BIO_FUA) - #else - #define CAS_IS_WRITE_FUA(flags) ((flags) & REQ_FUA) - #endif - #define OCF_WRITE_FUA WRITE_FUA - #elif defined REQ_FUA - #define CAS_IS_WRITE_FUA(flags) ((flags) & REQ_FUA) - #define OCF_WRITE_FUA REQ_FUA - #else - #define CAS_IS_WRITE_FUA(flags) 0 - #define OCF_WRITE_FUA WRITE_BARRIER - #endif /* #ifdef WRITE_FUA */ - -#endif /* #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 32) */ - -#if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 7, 9) - #define DAEMONIZE(name, arg...) daemonize(name, ##arg) -#else - #define DAEMONIZE(name, arg...) do { } while (0) -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 16, 0) - #define SET_QUEUE_CHUNK_SECTORS(queue, chunk_size) \ - queue->limits.chunk_sectors = chunk_size; -#else - #define SET_QUEUE_CHUNK_SECTORS(queue, chunk_size) {; } -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 14, 0) - #define BIO_BISIZE(bio) bio->bi_size - #define BIO_BIIDX(bio) bio->bi_idx - #define BIO_BISECTOR(bio) bio->bi_sector -#else - #define BIO_BISIZE(bio) bio->bi_iter.bi_size - #define BIO_BISECTOR(bio) bio->bi_iter.bi_sector - #define BIO_BIIDX(bio) bio->bi_iter.bi_idx -#endif - -#ifdef CAS_SLES12SP3 - #define CAS_IS_DISCARD(bio) \ - (((BIO_OP_FLAGS(bio)) & REQ_OP_MASK) == REQ_OP_DISCARD) - #define CAS_BIO_DISCARD \ - ((REQ_OP_WRITE | REQ_OP_DISCARD)) -#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) - #define CAS_IS_DISCARD(bio) \ - (bio_op(bio) == REQ_OP_DISCARD) - #define CAS_BIO_DISCARD \ - (REQ_OP_DISCARD) -#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) - #define CAS_IS_DISCARD(bio) \ - ((BIO_OP_FLAGS(bio)) & REQ_OP_DISCARD) - #define CAS_BIO_DISCARD \ - ((REQ_OP_WRITE | REQ_OP_DISCARD)) -#elif LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) - #define CAS_IS_DISCARD(bio) ((BIO_OP_FLAGS(bio)) & REQ_DISCARD) - #define CAS_BIO_DISCARD (REQ_WRITE | REQ_DISCARD) -#else - #define CAS_IS_DISCARD(bio) ((BIO_OP_FLAGS(bio)) & (1 << BIO_RW_DISCARD)) - #define CAS_BIO_DISCARD ((1 << BIO_RW) | (1 << BIO_RW_DISCARD)) -#endif - -#include - -#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 32) -#include -static inline unsigned long cas_vm_mmap(struct file *file, - unsigned long addr, unsigned long len) -{ - return vm_mmap(file, addr, len, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE, 0); -} - -static inline int cas_vm_munmap(unsigned long start, size_t len) -{ - return vm_munmap(start, len); -} -#else -#include -static inline unsigned long cas_vm_mmap(struct file *file, - unsigned long addr, unsigned long len) -{ - return do_mmap_pgoff(file, addr, len, PROT_READ | PROT_WRITE, - MAP_ANONYMOUS | MAP_PRIVATE, 0); -} - -static inline int cas_vm_munmap(unsigned long start, size_t len) -{ - return do_munmap(current->mm, start, len); -} -#endif - /* * For 8KB process kernel stack check if request is not continous and * submit each bio as separate request. This prevent nvme driver from @@ -349,12 +62,6 @@ static inline int cas_vm_munmap(unsigned long start, size_t len) #define RQ_CHECK_CONTINOUS #endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 14, 0) - #define SEGMENT_BVEC(vec) (&(vec)) -#else - #define SEGMENT_BVEC(vec) (vec) -#endif - #ifndef SHRT_MIN #define SHRT_MIN ((s16)-32768) #endif @@ -371,125 +78,6 @@ static inline int cas_vm_munmap(unsigned long start, size_t len) #endif #endif -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 7, 0) || defined CAS_SLES12SP3 -static inline blk_qc_t cas_submit_bio(int rw, struct bio *bio) -{ - BIO_OP_FLAGS(bio) |= rw; - return submit_bio(bio); -} -#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0) -static inline blk_qc_t cas_submit_bio(int rw, struct bio *bio) -{ - return submit_bio(rw, bio); -} -#else -static inline void cas_submit_bio(int rw, struct bio *bio) -{ - submit_bio(rw, bio); -} -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) -#define cas_blk_rq_set_block_pc(rq) {} -#else -#define cas_blk_rq_set_block_pc(rq) blk_rq_set_block_pc(rq) -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0) -#define cas_blk_queue_bounce(q, bounce_bio) ({}) -#else -#define cas_blk_queue_bounce(q, bounce_bio) blk_queue_bounce(q, bounce_bio) -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 11) -#define cas_blk_rq_append_bio(rq, bounce_bio) blk_rq_append_bio(rq, &bounce_bio) -#else -#define cas_blk_rq_append_bio(rq, bounce_bio) blk_rq_append_bio(rq, bounce_bio) -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 8, 0) || defined CAS_SLES12SP3 -static inline struct request *cas_blk_make_request(struct request_queue *q, - struct bio *bio, gfp_t gfp_mask) -{ - struct request *rq = blk_get_request(q, bio_data_dir(bio), gfp_mask); - - if (IS_ERR(rq)) - return rq; - - cas_blk_rq_set_block_pc(rq); - rq->q = q; - - for_each_bio(bio) { - struct bio *bounce_bio = bio; - int ret; - - cas_blk_queue_bounce(q, &bounce_bio); - ret = cas_blk_rq_append_bio(rq, bounce_bio); - if (unlikely(ret)) { - blk_put_request(rq); - return ERR_PTR(ret); - } - } - - return rq; -} -#else -static inline struct request *cas_blk_make_request(struct request_queue *q, - struct bio *bio, gfp_t gfp_mask) -{ - return blk_make_request(q, bio, gfp_mask); -} -#endif - -#ifdef CAS_RHEL_73 -static inline void cas_copy_queue_limits(struct request_queue *exp_q, - struct request_queue *cache_q, struct request_queue *core_q) -{ - struct queue_limits_aux *l_aux = exp_q->limits.limits_aux; - - exp_q->limits = cache_q->limits; - exp_q->limits.limits_aux = l_aux; - if (exp_q->limits.limits_aux && cache_q->limits.limits_aux) - *exp_q->limits.limits_aux = *cache_q->limits.limits_aux; - - exp_q->limits.max_sectors = core_q->limits.max_sectors; - exp_q->limits.max_hw_sectors = core_q->limits.max_hw_sectors; - exp_q->limits.max_segments = core_q->limits.max_segments; - exp_q->limits.max_write_same_sectors = 0; - - /* - * Workaround for RHEL/CentOS 7.3 bug in kernel. - * Merging implementation on blk-mq does not respec virt boundary - * restriction and front merges bios with non-zero offsets. - * This leads to request with gaps between bios and in consequence - * triggers BUG_ON() in nvme driver or silently corrupts data. - * To prevent this, disable merging on cache queue if there are - * requirements regarding virt boundary (marking bios with REQ_NOMERGE - * does not solve this problem). - */ - if (queue_virt_boundary(cache_q)) - queue_flag_set(QUEUE_FLAG_NOMERGES, cache_q); - -} -#else -static inline void cas_copy_queue_limits(struct request_queue *exp_q, - struct request_queue *cache_q, struct request_queue *core_q) -{ - exp_q->limits = cache_q->limits; - - exp_q->limits.max_sectors = core_q->limits.max_sectors; - exp_q->limits.max_hw_sectors = core_q->limits.max_hw_sectors; - exp_q->limits.max_segments = core_q->limits.max_segments; -#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 7, 0) || defined CAS_SLES12SP3 - exp_q->limits.max_write_same_sectors = 0; -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 10, 0) || defined CAS_SLES12SP3 - exp_q->limits.max_write_zeroes_sectors = 0; -#endif -} -#endif - #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0) #define CAS_GARBAGE_COLLECTOR #endif @@ -499,132 +87,4 @@ static inline void cas_copy_queue_limits(struct request_queue *exp_q, if (printk_ratelimit()) \ printk(__VA_ARGS__) -#if LINUX_VERSION_CODE < KERNEL_VERSION(3, 19, 0) -static inline void cas_generic_start_io_acct(struct request_queue *q, - int rw, unsigned long sectors, struct hd_struct *part) -{ - int cpu = part_stat_lock(); - - CAS_PART_ROUND_STATS(q, cpu, part); - part_stat_inc(cpu, part, ios[rw]); - part_stat_add(cpu, part, sectors[rw], sectors); - CAS_PART_INC_IN_FLIGHT(q, part, rw); - - part_stat_unlock(); -} - -static inline void cas_generic_end_io_acct(struct request_queue *q, - int rw, struct hd_struct *part, unsigned long start_time) -{ - unsigned long duration = jiffies - start_time; - int cpu = part_stat_lock(); - - part_stat_add(cpu, part, ticks[rw], duration); - CAS_PART_ROUND_STATS(q, cpu, part); - CAS_PART_DEC_IN_FLIGHT(q, part, rw); - - part_stat_unlock(); -} -#elif LINUX_VERSION_CODE < KERNEL_VERSION(4, 14, 0) -static inline void cas_generic_start_io_acct(struct request_queue *q, - int rw, unsigned long sectors, struct hd_struct *part) -{ - generic_start_io_acct(rw, sectors, part); -} - -static inline void cas_generic_end_io_acct(struct request_queue *q, - int rw, struct hd_struct *part, unsigned long start_time) -{ - generic_end_io_acct(rw, part, start_time); -} -#else -static inline void cas_generic_start_io_acct(struct request_queue *q, - int rw, unsigned long sectors, struct hd_struct *part) -{ - generic_start_io_acct(q, rw, sectors, part); -} - -static inline void cas_generic_end_io_acct(struct request_queue *q, - int rw, struct hd_struct *part, unsigned long start_time) -{ - generic_end_io_acct(q, rw, part, start_time); -} -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 14, 0) -static inline unsigned long cas_global_zone_page_state(enum zone_stat_item item) -{ - return global_zone_page_state(item); -} -#define CAS_BIO_SET_DEV(bio, bdev) bio_set_dev(bio, bdev) -#define CAS_BIO_GET_DEV(bio) bio->bi_disk -#else -static inline unsigned long cas_global_zone_page_state(enum zone_stat_item item) -{ - return global_page_state(item); -} -#define CAS_BIO_SET_DEV(bio, bdev) bio->bi_bdev = bdev -#define CAS_BIO_GET_DEV(bio) bio->bi_bdev->bd_disk -#endif - -#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 33) - #define CAS_RATELIMIT(state, func_name) __ratelimit(state) -#else - #define CAS_RATELIMIT(state, func_name) ___ratelimit(state, func_name) -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 19, 0) -static inline struct bio *cas_bio_clone(struct bio *bio, gfp_t gfp_mask) -{ - return bio_clone_fast(bio, gfp_mask, NULL); -} -#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 13, 0) -static inline struct bio *cas_bio_clone(struct bio *bio, gfp_t gfp_mask) -{ - return bio_clone_kmalloc(bio, gfp_mask); -} - #define CAS_BLK_STATUS_T blk_status_t -#else -static inline struct bio *cas_bio_clone(struct bio *bio, gfp_t gfp_mask) -{ - return bio_clone(bio, gfp_mask); -} - #define CAS_BLK_STATUS_T int -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0) -static inline int is_rq_type_fs(struct request *rq) -{ - switch (req_op(rq)){ - case REQ_OP_READ: - case REQ_OP_WRITE: - case REQ_OP_FLUSH: - case REQ_OP_DISCARD: - return true; - default: - return false; - } -} -#else -static inline int is_rq_type_fs(struct request *rq) -{ - return rq->cmd_type == REQ_TYPE_FS; -} -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 12, 0) - #define CAS_SET_DISCARD_ZEROES_DATA(queue_limits, val) ({}) -#else - #define CAS_SET_DISCARD_ZEROES_DATA(queue_limits, val) \ - queue_limits.discard_zeroes_data = val -#endif - -#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0) - #define cas_queue_flag_set_unlocked(flag, request_queue) \ - blk_queue_flag_set(flag, request_queue) -#else - #define cas_queue_flag_set_unlocked(flag, request_queue) \ - queue_flag_set_unlocked(flag, request_queue) -#endif - #endif /* #ifndef __LINUX_KERNEL_VERSION_H__ */ diff --git a/modules/cas_cache/threads.c b/modules/cas_cache/threads.c index 76fc245..20b7245 100644 --- a/modules/cas_cache/threads.c +++ b/modules/cas_cache/threads.c @@ -31,7 +31,7 @@ static int _cas_io_queue_thread(void *data) info = ocf_queue_get_priv(q); BUG_ON(!info); - DAEMONIZE(info->thread->comm); + CAS_DAEMONIZE(info->thread->comm); complete(&info->compl); @@ -81,7 +81,7 @@ static int _cas_cleaner_thread(void *data) info = ocf_cleaner_get_priv(c); BUG_ON(!info); - DAEMONIZE(info->thread->comm); + CAS_DAEMONIZE(info->thread->comm); complete(&info->compl); @@ -127,7 +127,7 @@ static int _cas_metadata_updater_thread(void *data) info = ocf_metadata_updater_get_priv(mu); BUG_ON(!info); - DAEMONIZE(info->thread->comm); + CAS_DAEMONIZE(info->thread->comm); complete(&info->compl); diff --git a/modules/cas_cache/utils/utils_nvme.c b/modules/cas_cache/utils/utils_nvme.c index 7cb8d69..7c1717d 100644 --- a/modules/cas_cache/utils/utils_nvme.c +++ b/modules/cas_cache/utils/utils_nvme.c @@ -316,7 +316,7 @@ static int _cas_nvme_format_namespace_by_path(const char *device_path, goto out1; } - bdev = OPEN_BDEV_EXCLUSIVE(device_path, + bdev = blkdev_get_by_path(device_path, FMODE_READ | FMODE_WRITE | FMODE_EXCL, holder); if (IS_ERR(bdev)) { if (PTR_ERR(bdev) == -EBUSY) @@ -378,7 +378,7 @@ static int _cas_nvme_format_namespace_by_path(const char *device_path, ret = ioctl_by_bdev(bdev, BLKRRPART, (unsigned long)NULL); out2: - CLOSE_BDEV_EXCLUSIVE(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL); + blkdev_put(bdev, FMODE_READ | FMODE_WRITE | FMODE_EXCL); out1: kfree(id); kfree(ns); diff --git a/modules/cas_cache/volume/vol_atomic_dev_bottom.c b/modules/cas_cache/volume/vol_atomic_dev_bottom.c index 76f0c54..79a4ec3 100644 --- a/modules/cas_cache/volume/vol_atomic_dev_bottom.c +++ b/modules/cas_cache/volume/vol_atomic_dev_bottom.c @@ -434,7 +434,7 @@ static void cas_atomic_end_atom(struct cas_atomic_io *atom, int error) ocf_io_put(io); } -static DECLARE_BLOCK_CALLBACK(cas_atomic_fire_atom, struct bio *bio, +static CAS_DECLARE_BLOCK_CALLBACK(cas_atomic_fire_atom, struct bio *bio, unsigned int bytes, int error) { int err; @@ -443,12 +443,12 @@ static DECLARE_BLOCK_CALLBACK(cas_atomic_fire_atom, struct bio *bio, BUG_ON(!bio); BUG_ON(!bio->bi_private); - err = BLOCK_CALLBACK_ERROR(bio, error); + err = CAS_BLOCK_CALLBACK_ERROR(bio, error); atom = bio->bi_private; BUG_ON(!atom->master); bdobj = bd_object(atom->volume); - CAS_DEBUG_PARAM("BIO result = %d", BLOCK_CALLBACK_ERROR(bio, error)); + CAS_DEBUG_PARAM("BIO result = %d", CAS_BLOCK_CALLBACK_ERROR(bio, error)); if (err != 0) goto out; @@ -504,7 +504,7 @@ static void _cas_atomic_setup_cmd( cmd->rw.opcode = (dir == OCF_WRITE) ? nvme_cmd_write : nvme_cmd_read; cmd->rw.nsid = cpu_to_le32(ns_id); - cmd->rw.slba = cpu_to_le64(BIO_BISECTOR(bio)); + cmd->rw.slba = cpu_to_le64(CAS_BIO_BISECTOR(bio)); cmd->rw.length = cpu_to_le16((bytes / SECTOR_SIZE) - 1); cmd->rw.control = cpu_to_le16(NVME_RW_LR); @@ -562,11 +562,11 @@ static void cas_atomic_fire_atom(int dir, struct ocf_io *io, /* Setup BIO */ bio->bi_bdev = bdev; - BIO_BISECTOR(bio) = atom->addr / SECTOR_SIZE; + CAS_BIO_BISECTOR(bio) = atom->addr / SECTOR_SIZE; bio->bi_next = NULL; bio->bi_private = atom; - BIO_OP_FLAGS(bio) |= io->flags; - bio->bi_end_io = REFER_BLOCK_CALLBACK(cas_atomic_fire_atom); + CAS_BIO_OP_FLAGS(bio) |= io->flags; + bio->bi_end_io = CAS_REFER_BLOCK_CALLBACK(cas_atomic_fire_atom); /* Add pages to the BIO */ bvec = atom->data->vec; @@ -726,8 +726,8 @@ static int cas_atomic_submit_discard_bio(struct cas_atomic_io *atom) } nvm_discard->cattr = cpu_to_le32(0); - nvm_discard->nlb = cpu_to_le32(BIO_BISIZE(atom->bio) >> SECTOR_SHIFT); - nvm_discard->slba = cpu_to_le64(BIO_BISECTOR(atom->bio)); + nvm_discard->nlb = cpu_to_le32(CAS_BIO_BISIZE(atom->bio) >> SECTOR_SHIFT); + nvm_discard->slba = cpu_to_le64(CAS_BIO_BISECTOR(atom->bio)); cmd->dsm.opcode = nvme_cmd_dsm; cmd->dsm.nsid = cpu_to_le32(ns_id); @@ -739,8 +739,8 @@ static int cas_atomic_submit_discard_bio(struct cas_atomic_io *atom) offset = offset_in_page(nvm_discard); blk_add_request_payload(req, page, offset, sizeof(*nvm_discard)); - req->__sector = BIO_BISECTOR(atom->bio); - req->__data_len = BIO_BISIZE(atom->bio); + req->__sector = CAS_BIO_BISECTOR(atom->bio); + req->__data_len = CAS_BIO_BISIZE(atom->bio); req->ioprio = bio_prio(atom->bio); req->timeout = ADMIN_TIMEOUT; @@ -782,7 +782,7 @@ static int cas_atomic_special_req_prepare(struct cas_atomic_io *atom, return -ENOMEM; } - atom->bio->bi_end_io = REFER_BLOCK_CALLBACK(cas_atomic_fire_atom); + atom->bio->bi_end_io = CAS_REFER_BLOCK_CALLBACK(cas_atomic_fire_atom); atom->bio->bi_bdev = bdev; atom->bio->bi_private = atom; @@ -826,9 +826,9 @@ void cas_atomic_submit_discard(struct ocf_io *io) /* Set up specific field */ atom->discard = true; - BIO_OP_FLAGS(atom->bio) = CAS_BIO_DISCARD; - BIO_BISECTOR(atom->bio) = io->addr / SECTOR_SIZE; - BIO_BISIZE(atom->bio) = io->bytes; + CAS_BIO_OP_FLAGS(atom->bio) = CAS_BIO_DISCARD; + CAS_BIO_BISECTOR(atom->bio) = io->addr / SECTOR_SIZE; + CAS_BIO_BISIZE(atom->bio) = io->bytes; atom->request = cas_blk_make_request(q, atom->bio, GFP_NOIO); if (IS_ERR(atom->request)) { @@ -872,7 +872,7 @@ void cas_atomic_submit_flush(struct ocf_io *io) return; } - if (!CHECK_QUEUE_FLUSH(q)) { + if (!CAS_CHECK_QUEUE_FLUSH(q)) { /* This block device does not support flush */ atomic_sub(blkio->dirty, &bdobj->potentially_dirty); io->end(io, 0); diff --git a/modules/cas_cache/volume/vol_blk_utils.c b/modules/cas_cache/volume/vol_blk_utils.c index 0258a2b..c727dfd 100644 --- a/modules/cas_cache/volume/vol_blk_utils.c +++ b/modules/cas_cache/volume/vol_blk_utils.c @@ -358,12 +358,12 @@ static inline int _cas_detect_blk_type(const char *path, uint8_t *type, struct block_device *bdev; char holder[] = "CAS DETECT\n"; - bdev = OPEN_BDEV_EXCLUSIVE(path, FMODE_READ, holder); + bdev = blkdev_get_by_path(path, (FMODE_EXCL|FMODE_READ), holder); if (IS_ERR(bdev)) return -OCF_ERR_NOT_OPEN_EXC; ret = cas_blk_identify_type_by_bdev(bdev, type, atomic_params); - CLOSE_BDEV_EXCLUSIVE(bdev, FMODE_READ); + blkdev_put(bdev, (FMODE_EXCL|FMODE_READ)); return ret; } @@ -437,9 +437,9 @@ int _cas_blk_identify_type(const char *path, uint8_t *type, if (IS_ERR(file)) return -OCF_ERR_INVAL_VOLUME_TYPE; - if (S_ISBLK(FILE_INODE(file)->i_mode)) + if (S_ISBLK(CAS_FILE_INODE(file)->i_mode)) *type = BLOCK_DEVICE_VOLUME; - else if (S_ISCHR(FILE_INODE(file)->i_mode)) + else if (S_ISCHR(CAS_FILE_INODE(file)->i_mode)) *type = NVME_CONTROLLER; else result = -OCF_ERR_INVAL_VOLUME_TYPE; diff --git a/modules/cas_cache/volume/vol_blk_utils.h b/modules/cas_cache/volume/vol_blk_utils.h index 8b8ec4b..e6cbe93 100644 --- a/modules/cas_cache/volume/vol_blk_utils.h +++ b/modules/cas_cache/volume/vol_blk_utils.h @@ -11,10 +11,10 @@ static inline bool cas_blk_is_flush_io(unsigned long flags) { - if ((flags & OCF_WRITE_FLUSH) == OCF_WRITE_FLUSH) + if ((flags & CAS_WRITE_FLUSH) == CAS_WRITE_FLUSH) return true; - if ((flags & OCF_WRITE_FLUSH_FUA) == OCF_WRITE_FLUSH_FUA) + if ((flags & CAS_WRITE_FLUSH_FUA) == CAS_WRITE_FLUSH_FUA) return true; return false; diff --git a/modules/cas_cache/volume/vol_block_dev_bottom.c b/modules/cas_cache/volume/vol_block_dev_bottom.c index ecb7565..756a74b 100644 --- a/modules/cas_cache/volume/vol_block_dev_bottom.c +++ b/modules/cas_cache/volume/vol_block_dev_bottom.c @@ -198,7 +198,7 @@ static void cas_bd_io_end(struct ocf_io *io, int error) /* * */ -DECLARE_BLOCK_CALLBACK(cas_bd_io_end, struct bio *bio, +CAS_DECLARE_BLOCK_CALLBACK(cas_bd_io_end, struct bio *bio, unsigned int bytes_done, int error) { struct ocf_io *io; @@ -208,11 +208,11 @@ DECLARE_BLOCK_CALLBACK(cas_bd_io_end, struct bio *bio, BUG_ON(!bio); BUG_ON(!bio->bi_private); - BLOCK_CALLBACK_INIT(bio); + CAS_BLOCK_CALLBACK_INIT(bio); io = bio->bi_private; bdobj = bd_object(io->volume); BUG_ON(!bdobj); - err = BLOCK_CALLBACK_ERROR(bio, error); + err = CAS_BLOCK_CALLBACK_ERROR(bio, error); bdio = cas_io_to_blkio(io); BUG_ON(!bdio); @@ -235,13 +235,13 @@ DECLARE_BLOCK_CALLBACK(cas_bd_io_end, struct bio *bio, } } out: - if (err == -EOPNOTSUPP && (BIO_OP_FLAGS(bio) & CAS_BIO_DISCARD)) + if (err == -EOPNOTSUPP && (CAS_BIO_OP_FLAGS(bio) & CAS_BIO_DISCARD)) err = 0; cas_bd_io_end(io, err); bio_put(bio); - BLOCK_CALLBACK_RETURN(); + CAS_BLOCK_CALLBACK_RETURN(); } static void block_dev_submit_flush(struct ocf_io *io) @@ -274,7 +274,7 @@ static void block_dev_submit_flush(struct ocf_io *io) goto out; } - if (!CHECK_QUEUE_FLUSH(q)) { + if (!CAS_CHECK_QUEUE_FLUSH(q)) { /* This block device does not support flush, call back */ atomic_sub(blkio->dirty, &bdobj->potentially_dirty); goto out; @@ -289,12 +289,12 @@ static void block_dev_submit_flush(struct ocf_io *io) blkio->dir = io->dir; - bio->bi_end_io = REFER_BLOCK_CALLBACK(cas_bd_io_end); + bio->bi_end_io = CAS_REFER_BLOCK_CALLBACK(cas_bd_io_end); CAS_BIO_SET_DEV(bio, bdev); bio->bi_private = io; atomic_inc(&blkio->rq_remaning); - cas_submit_bio(OCF_WRITE_FLUSH, bio); + cas_submit_bio(CAS_WRITE_FLUSH, bio); out: cas_bd_io_end(io, blkio->error); @@ -374,11 +374,11 @@ void block_dev_submit_discard(struct ocf_io *io) } CAS_BIO_SET_DEV(bio, bd); - BIO_BISECTOR(bio) = start; - BIO_BISIZE(bio) = bio_sects << SECTOR_SHIFT; + CAS_BIO_BISECTOR(bio) = start; + CAS_BIO_BISIZE(bio) = bio_sects << SECTOR_SHIFT; bio->bi_next = NULL; bio->bi_private = io; - bio->bi_end_io = REFER_BLOCK_CALLBACK(cas_bd_io_end); + bio->bi_end_io = CAS_REFER_BLOCK_CALLBACK(cas_bd_io_end); atomic_inc(&blkio->rq_remaning); cas_submit_bio(CAS_BIO_DISCARD, bio); @@ -479,12 +479,11 @@ static void block_dev_submit_io(struct ocf_io *io) /* Setup BIO */ CAS_BIO_SET_DEV(bio, bdobj->btm_bd); - BIO_BISECTOR(bio) = addr / SECTOR_SIZE; + CAS_BIO_BISECTOR(bio) = addr / SECTOR_SIZE; bio->bi_next = NULL; bio->bi_private = io; - BIO_OP_FLAGS(bio) |= io->flags; - BIO_SET_RW_FLAGS(bio); - bio->bi_end_io = REFER_BLOCK_CALLBACK(cas_bd_io_end); + CAS_BIO_OP_FLAGS(bio) |= io->flags; + bio->bi_end_io = CAS_REFER_BLOCK_CALLBACK(cas_bd_io_end); /* Add pages */ while (cas_io_iter_is_next(iter) && bytes) { @@ -588,7 +587,7 @@ int block_dev_try_get_io_class(struct bio *bio, int *io_class) { struct ocf_io *io; - if (bio->bi_end_io != REFER_BLOCK_CALLBACK(cas_bd_io_end)) + if (bio->bi_end_io != CAS_REFER_BLOCK_CALLBACK(cas_bd_io_end)) return -1; io = bio->bi_private; diff --git a/modules/cas_cache/volume/vol_block_dev_top.c b/modules/cas_cache/volume/vol_block_dev_top.c index 84da64a..51e03dc 100644 --- a/modules/cas_cache/volume/vol_block_dev_top.c +++ b/modules/cas_cache/volume/vol_block_dev_top.c @@ -5,7 +5,7 @@ #include "cas_cache.h" -#define BLK_RQ_POS(rq) (BIO_BISECTOR((rq)->bio)) +#define BLK_RQ_POS(rq) (CAS_BIO_BISECTOR((rq)->bio)) #define BLK_RQ_BYTES(rq) blk_rq_bytes(rq) extern u32 use_io_scheduler; @@ -24,7 +24,7 @@ static inline bool _blockdev_can_handle_rq(struct request *rq) { int error = 0; - if (unlikely(!is_rq_type_fs(rq))) + if (unlikely(!cas_is_rq_type_fs(rq))) error = __LINE__; if (unlikely(rq->next_rq)) @@ -104,7 +104,7 @@ void block_dev_complete_bio_fast(struct ocf_io *io, int error) _blockdev_end_io_acct(bio, data->start_time); - BIO_ENDIO(bio, BIO_BISIZE(bio), error); + CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), error); ocf_io_put(io); cas_free_blk_data(data); } @@ -113,7 +113,7 @@ void block_dev_complete_bio_discard(struct ocf_io *io, int error) { struct bio *bio = io->priv1; - BIO_ENDIO(bio, BIO_BISIZE(bio), error); + CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), error); ocf_io_put(io); } @@ -161,7 +161,7 @@ bool _blockdev_is_request_barier(struct request *rq) struct bio *i_bio = rq->bio; for_each_bio(i_bio) { - if (CHECK_BARRIER(i_bio)) + if (CAS_CHECK_BARRIER(i_bio)) return true; } return false; @@ -186,13 +186,13 @@ static int _blockdev_alloc_many_requests(ocf_core_t core, bio = rq->bio; for_each_bio(bio) { /* Setup BIO flags */ - if (CAS_IS_WRITE_FLUSH_FUA(BIO_OP_FLAGS(bio))) { + if (CAS_IS_WRITE_FLUSH_FUA(CAS_BIO_OP_FLAGS(bio))) { /* FLUSH and FUA */ - flags = OCF_WRITE_FLUSH_FUA; - } else if (CAS_IS_WRITE_FUA(BIO_OP_FLAGS(bio))) { + flags = CAS_WRITE_FLUSH_FUA; + } else if (CAS_IS_WRITE_FUA(CAS_BIO_OP_FLAGS(bio))) { /* FUA */ - flags = OCF_WRITE_FUA; - } else if (CAS_IS_WRITE_FLUSH(BIO_OP_FLAGS(bio))) { + flags = CAS_WRITE_FUA; + } else if (CAS_IS_WRITE_FLUSH(CAS_BIO_OP_FLAGS(bio))) { /* FLUSH - It shall be handled in request handler */ error = -EINVAL; break; @@ -220,8 +220,8 @@ static int _blockdev_alloc_many_requests(ocf_core_t core, data->io = sub_io; - ocf_io_configure(sub_io, BIO_BISECTOR(bio) << SECTOR_SHIFT, - BIO_BISIZE(bio), (bio_data_dir(bio) == READ) ? + ocf_io_configure(sub_io, CAS_BIO_BISECTOR(bio) << SECTOR_SHIFT, + CAS_BIO_BISIZE(bio), (bio_data_dir(bio) == READ) ? OCF_READ : OCF_WRITE, cas_cls_classify(cache, bio), flags); @@ -294,7 +294,7 @@ static int _blkdev_handle_flush_request(struct request *rq, ocf_core_t core) if (!io) return -ENOMEM; - ocf_io_configure(io, 0, 0, OCF_WRITE, 0, OCF_WRITE_FLUSH); + ocf_io_configure(io, 0, 0, OCF_WRITE, 0, CAS_WRITE_FLUSH); ocf_io_set_queue(io, cache_priv->io_queues[smp_processor_id()]); ocf_io_set_cmpl(io, rq, NULL, block_dev_complete_flush); @@ -359,8 +359,8 @@ static uint32_t _blkdev_scan_request(ocf_cache_t cache, struct request *rq, * request, and prevent nvme driver from splitting requests. * For large requests, nvme splitting causes stack overrun. */ - if (!_bvec_is_mergeable(SEGMENT_BVEC(bvec_prev), - SEGMENT_BVEC(bvec))) { + if (!_bvec_is_mergeable(CAS_SEGMENT_BVEC(bvec_prev), + CAS_SEGMENT_BVEC(bvec))) { *single_io = false; continue; } @@ -404,13 +404,13 @@ static int _blkdev_handle_request(struct request *rq, ocf_core_t core) return -ENOTSUPP; } - if ((rq->cmd_flags & REQ_FUA) && RQ_IS_FLUSH(rq)) { + if ((rq->cmd_flags & REQ_FUA) && CAS_RQ_IS_FLUSH(rq)) { /* FLUSH and FUA */ - master_flags = OCF_WRITE_FLUSH_FUA; + master_flags = CAS_WRITE_FLUSH_FUA; } else if (rq->cmd_flags & REQ_FUA) { /* FUA */ - master_flags = OCF_WRITE_FUA; - } else if (RQ_IS_FLUSH(rq)) { + master_flags = CAS_WRITE_FUA; + } else if (CAS_RQ_IS_FLUSH(rq)) { /* FLUSH */ return _blkdev_handle_flush_request(rq, core); } @@ -422,7 +422,7 @@ static int _blkdev_handle_request(struct request *rq, ocf_core_t core) } ocf_io_configure(io, BLK_RQ_POS(rq) << SECTOR_SHIFT, BLK_RQ_BYTES(rq), - (RQ_DATA_DIR(rq) == RQ_DATA_DIR_WR) ? + (rq_data_dir(rq) == CAS_RQ_DATA_DIR_WR) ? OCF_WRITE : OCF_READ, cas_cls_classify(cache, rq->bio), master_flags); @@ -506,10 +506,10 @@ static int _blkdev_handle_request(struct request *rq, ocf_core_t core) static inline int _blkdev_can_hndl_bio(struct bio *bio) { - if (CHECK_BARRIER(bio)) { + if (CAS_CHECK_BARRIER(bio)) { CAS_PRINT_RL(KERN_WARNING "special bio was sent, not supported!\n"); - BIO_ENDIO(bio, BIO_BISIZE(bio), -EOPNOTSUPP); + CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -EOPNOTSUPP); return -ENOTSUPP; } @@ -518,13 +518,13 @@ static inline int _blkdev_can_hndl_bio(struct bio *bio) static inline bool _blkdev_is_flush_fua_bio(struct bio *bio) { - if (CAS_IS_WRITE_FLUSH_FUA(BIO_OP_FLAGS(bio))) { + if (CAS_IS_WRITE_FLUSH_FUA(CAS_BIO_OP_FLAGS(bio))) { /* FLUSH and FUA */ return true; - } else if (CAS_IS_WRITE_FUA(BIO_OP_FLAGS(bio))) { + } else if (CAS_IS_WRITE_FUA(CAS_BIO_OP_FLAGS(bio))) { /* FUA */ return true; - } else if (CAS_IS_WRITE_FLUSH(BIO_OP_FLAGS(bio))) { + } else if (CAS_IS_WRITE_FLUSH(CAS_BIO_OP_FLAGS(bio))) { /* FLUSH */ return true; @@ -552,8 +552,8 @@ void _blockdev_set_exported_object_flush_fua(ocf_core_t core) exp_q = casdisk_functions.casdsk_exp_obj_get_queue(bd_core_vol->dsk); cache_q = casdisk_functions.casdsk_disk_get_queue(bd_cache_vol->dsk); - flush = (CHECK_QUEUE_FLUSH(core_q) || CHECK_QUEUE_FLUSH(cache_q)); - fua = (CHECK_QUEUE_FUA(core_q) || CHECK_QUEUE_FUA(cache_q)); + flush = (CAS_CHECK_QUEUE_FLUSH(core_q) || CAS_CHECK_QUEUE_FLUSH(cache_q)); + fua = (CAS_CHECK_QUEUE_FUA(core_q) || CAS_CHECK_QUEUE_FUA(cache_q)); cas_set_queue_flush_fua(exp_q, flush, fua); #endif @@ -658,7 +658,7 @@ static int _blockdev_set_geometry(struct casdsk_disk *dsk, void *private) blk_queue_stack_limits(exp_q, core_q); /* We don't want to receive splitted requests*/ - SET_QUEUE_CHUNK_SECTORS(exp_q, 0); + CAS_SET_QUEUE_CHUNK_SECTORS(exp_q, 0); _blockdev_set_exported_object_flush_fua(core); @@ -712,11 +712,11 @@ static void _blockdev_make_request_discard(struct casdsk_disk *dsk, if (!io) { CAS_PRINT_RL(KERN_CRIT "Out of memory. Ending IO processing.\n"); - BIO_ENDIO(bio, BIO_BISIZE(bio), -ENOMEM); + CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -ENOMEM); return; } - ocf_io_configure(io, BIO_BISECTOR(bio) << SECTOR_SHIFT, BIO_BISIZE(bio), + ocf_io_configure(io, CAS_BIO_BISECTOR(bio) << SECTOR_SHIFT, CAS_BIO_BISIZE(bio), 0, 0, 0); ocf_io_set_queue(io, cache_priv->io_queues[smp_processor_id()]); @@ -754,18 +754,18 @@ static int _blockdev_make_request_fast(struct casdsk_disk *dsk, return CASDSK_BIO_HANDLED; } - if (unlikely(BIO_BISIZE(bio) == 0)) { + if (unlikely(CAS_BIO_BISIZE(bio) == 0)) { CAS_PRINT_RL(KERN_ERR "Not able to handle empty BIO, flags = " - BIO_OP_FLAGS_FORMAT "\n", BIO_OP_FLAGS(bio)); - BIO_ENDIO(bio, BIO_BISIZE(bio), -EINVAL); + CAS_BIO_OP_FLAGS_FORMAT "\n", CAS_BIO_OP_FLAGS(bio)); + CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -EINVAL); return CASDSK_BIO_HANDLED; } data = cas_alloc_blk_data(bio_segments(bio), GFP_ATOMIC); if (!data) { CAS_PRINT_RL(KERN_CRIT "BIO data vector allocation error\n"); - BIO_ENDIO(bio, BIO_BISIZE(bio), -ENOMEM); + CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -ENOMEM); return CASDSK_BIO_HANDLED; } @@ -778,11 +778,11 @@ static int _blockdev_make_request_fast(struct casdsk_disk *dsk, if (!io) { printk(KERN_CRIT "Out of memory. Ending IO processing.\n"); cas_free_blk_data(data); - BIO_ENDIO(bio, BIO_BISIZE(bio), -ENOMEM); + CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -ENOMEM); return CASDSK_BIO_HANDLED; } - ocf_io_configure(io, BIO_BISECTOR(bio) << SECTOR_SHIFT, BIO_BISIZE(bio), + ocf_io_configure(io, CAS_BIO_BISECTOR(bio) << SECTOR_SHIFT, CAS_BIO_BISIZE(bio), (bio_data_dir(bio) == READ) ? OCF_READ : OCF_WRITE, cas_cls_classify(cache, bio), 0); @@ -790,7 +790,7 @@ static int _blockdev_make_request_fast(struct casdsk_disk *dsk, if (ret < 0) { ocf_io_put(io); cas_free_blk_data(data); - BIO_ENDIO(bio, BIO_BISIZE(bio), -EINVAL); + CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -EINVAL); return CASDSK_BIO_HANDLED; } diff --git a/modules/cas_disk/exp_obj.c b/modules/cas_disk/exp_obj.c index aa599eb..0a6608b 100644 --- a/modules/cas_disk/exp_obj.c +++ b/modules/cas_disk/exp_obj.c @@ -120,25 +120,25 @@ static inline void _casdsk_exp_obj_handle_bio_att(struct casdsk_disk *dsk, dsk->exp_obj->mk_rq_fn(q, bio); } -DECLARE_BLOCK_CALLBACK(_casdsk_exp_obj_bio_pt_io, struct bio *bio, +CAS_DECLARE_BLOCK_CALLBACK(_casdsk_exp_obj_bio_pt_io, struct bio *bio, unsigned int bytes_done, int error) { struct casdsk_exp_obj_pt_io_ctx *io; BUG_ON(!bio); - BLOCK_CALLBACK_INIT(bio); + CAS_BLOCK_CALLBACK_INIT(bio); io = bio->bi_private; BUG_ON(!io); - BIO_ENDIO(io->bio, BIO_BISIZE(io->bio), - BLOCK_CALLBACK_ERROR(bio, error)); + CAS_BIO_ENDIO(io->bio, CAS_BIO_BISIZE(io->bio), + CAS_BLOCK_CALLBACK_ERROR(bio, error)); if (atomic_dec_return(&io->dsk->exp_obj->pt_ios) < 0) BUG(); bio_put(bio); kmem_cache_free(casdsk_module->pt_io_ctx_cache, io); - BLOCK_CALLBACK_RETURN(); + CAS_BLOCK_CALLBACK_RETURN(); } static inline void _casdsk_exp_obj_handle_bio_pt(struct casdsk_disk *dsk, @@ -150,14 +150,14 @@ static inline void _casdsk_exp_obj_handle_bio_pt(struct casdsk_disk *dsk, io = kmem_cache_zalloc(casdsk_module->pt_io_ctx_cache, GFP_ATOMIC); if (!io) { - BIO_ENDIO(bio, BIO_BISIZE(bio), -ENOMEM); + CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -ENOMEM); return; } cloned_bio = cas_bio_clone(bio, GFP_ATOMIC); if (!cloned_bio) { kmem_cache_free(casdsk_module->pt_io_ctx_cache, io); - BIO_ENDIO(bio, BIO_BISIZE(bio), -ENOMEM); + CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -ENOMEM); return; } @@ -168,8 +168,8 @@ static inline void _casdsk_exp_obj_handle_bio_pt(struct casdsk_disk *dsk, CAS_BIO_SET_DEV(cloned_bio, casdsk_disk_get_blkdev(dsk)); cloned_bio->bi_private = io; - cloned_bio->bi_end_io = REFER_BLOCK_CALLBACK(_casdsk_exp_obj_bio_pt_io); - cas_submit_bio(BIO_OP_FLAGS(cloned_bio), cloned_bio); + cloned_bio->bi_end_io = CAS_REFER_BLOCK_CALLBACK(_casdsk_exp_obj_bio_pt_io); + cas_submit_bio(CAS_BIO_OP_FLAGS(cloned_bio), cloned_bio); } static inline void _casdsk_exp_obj_handle_bio(struct casdsk_disk *dsk, @@ -181,7 +181,7 @@ static inline void _casdsk_exp_obj_handle_bio(struct casdsk_disk *dsk, else if (casdsk_disk_is_pt(dsk)) _casdsk_exp_obj_handle_bio_pt(dsk, q, bio); else if (casdsk_disk_is_shutdown(dsk)) - BIO_ENDIO(bio, BIO_BISIZE(bio), -EIO); + CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -EIO); else BUG(); }