From bbd0cb57a5c047836ce8eeefd40b80a3ca834c13 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Fri, 11 Dec 2020 20:10:24 +0100 Subject: [PATCH 1/9] configure: Update generic_acct wrapper to kernel 5.8 Signed-off-by: Robert Baldyga --- configure.d/1_generic_acct.conf | 185 +++++++++++-------- modules/cas_cache/volume/vol_block_dev_top.c | 11 +- 2 files changed, 114 insertions(+), 82 deletions(-) diff --git a/configure.d/1_generic_acct.conf b/configure.d/1_generic_acct.conf index 15f6043..499a627 100644 --- a/configure.d/1_generic_acct.conf +++ b/configure.d/1_generic_acct.conf @@ -9,18 +9,21 @@ check() { cur_name=$(basename $2) config_file_path=$1 - if compile_module $cur_name "generic_start_io_acct(NULL, 0, 0, NULL)" "linux/bio.h" + if compile_module $cur_name "bio_start_io_acct(NULL)" "linux/blkdev.h" then echo $cur_name "1" >> $config_file_path - elif compile_module $cur_name "generic_start_io_acct(0, 0, NULL)" "linux/bio.h" + elif compile_module $cur_name "generic_start_io_acct(NULL, 0, 0, NULL)" "linux/bio.h" then echo $cur_name "2" >> $config_file_path - elif compile_module $cur_name "part_round_stats(1, 1)" "linux/genhd.h" + elif compile_module $cur_name "generic_start_io_acct(0, 0, NULL)" "linux/bio.h" then echo $cur_name "3" >> $config_file_path - elif compile_module $cur_name "part_round_stats(NULL, 1, 1)" "linux/genhd.h" + elif compile_module $cur_name "part_round_stats(1, 1)" "linux/genhd.h" then echo $cur_name "4" >> $config_file_path + elif compile_module $cur_name "part_round_stats(NULL, 1, 1)" "linux/genhd.h" + then + echo $cur_name "5" >> $config_file_path else echo $cur_name "X" >> $config_file_path fi @@ -29,79 +32,111 @@ check() { apply() { case "$1" in "1") - 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); - }" ;; + add_function " + static inline unsigned long long cas_generic_start_io_acct( + struct request_queue *q, struct bio *bio, + struct hd_struct *part) + { + return bio_start_io_acct(bio); + }" + add_function " + static inline void cas_generic_end_io_acct(struct request_queue *q, + struct bio *bio, struct hd_struct *part, + unsigned long start_time) + { + bio_end_io_acct(bio, start_time); + }" ;; "2") - 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); - }" ;; - "3") - 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(); - }" ;; - "4") - 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(); - }" ;; - *) + add_function " + static inline unsigned long long cas_generic_start_io_acct( + struct request_queue *q, struct bio *bio, + struct hd_struct *part) + { + generic_start_io_acct(q, bio_data_dir(bio), bio_sectors(bio), part); + return jiffies; + }" + add_function " + static inline void cas_generic_end_io_acct(struct request_queue *q, + struct bio *bio, struct hd_struct *part, + unsigned long start_time) + { + generic_end_io_acct(q, bio_data_dir(bio), part, start_time); + }" ;; + "3") + add_function " + static inline unsigned long long cas_generic_start_io_acct( + struct request_queue *q, struct bio *bio, + struct hd_struct *part) + { + generic_start_io_acct(bio_data_dir(bio), bio_sectors(bio), part); + return jiffies; + }" + add_function " + static inline void cas_generic_end_io_acct(struct request_queue *q, + struct bio *bio, struct hd_struct *part, + unsigned long start_time) + { + generic_end_io_acct(bio_data_dir(bio), part, start_time); + }" ;; + "4") + add_function " + static inline unsigned long long cas_generic_start_io_acct( + struct request_queue *q, struct bio *bio, + struct hd_struct *part) + { + int rw = bio_data_dir(bio); + int cpu = part_stat_lock(); + part_round_stats(cpu, part); + part_stat_inc(cpu, part, ios[rw]); + part_stat_add(cpu, part, sectors[rw], bio_sectors(bio)); + part_inc_in_flight(part, rw); + part_stat_unlock(); + return jiffies; + }" + add_function " + static inline void cas_generic_end_io_acct(struct request_queue *q, + struct bio *bio, struct hd_struct *part, + unsigned long start_time) + { + int rw = bio_data_dir(bio); + 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(); + }" ;; + "5") + add_function " + static inline unsigned long long cas_generic_start_io_acct( + struct request_queue *q, struct bio *bio, + struct hd_struct *part) + { + int rw = bio_data_dir(bio); + 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], bio_sectors(bio)); + part_inc_in_flight(NULL, part, rw); + part_stat_unlock(); + return jiffies; + }" + add_function " + static inline void cas_generic_end_io_acct(struct request_queue *q, + struct bio *bio, struct hd_struct *part, + unsigned long start_time) + { + int rw = bio_data_dir(bio); + 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(); + }" ;; + *) exit 1 - esac + esac } conf_run $@ diff --git a/modules/cas_cache/volume/vol_block_dev_top.c b/modules/cas_cache/volume/vol_block_dev_top.c index 950c331..3355c48 100644 --- a/modules/cas_cache/volume/vol_block_dev_top.c +++ b/modules/cas_cache/volume/vol_block_dev_top.c @@ -57,12 +57,11 @@ static void _blockdev_set_bio_data(struct blk_data *data, struct bio *bio) #endif } -static inline void _blockdev_start_io_acct(struct bio *bio) +static inline unsigned long long _blockdev_start_io_acct(struct bio *bio) { struct gendisk *gd = CAS_BIO_GET_DEV(bio); - cas_generic_start_io_acct(gd->queue, bio_data_dir(bio), - bio_sectors(bio), &gd->part0); + return cas_generic_start_io_acct(gd->queue, bio, &gd->part0); } static inline void _blockdev_end_io_acct(struct bio *bio, @@ -70,8 +69,7 @@ static inline void _blockdev_end_io_acct(struct bio *bio, { struct gendisk *gd = CAS_BIO_GET_DEV(bio); - cas_generic_end_io_acct(gd->queue, bio_data_dir(bio), - &gd->part0, start_time); + cas_generic_end_io_acct(gd->queue, bio, &gd->part0, start_time); } void block_dev_start_bio_fast(struct ocf_io *io) @@ -79,7 +77,7 @@ void block_dev_start_bio_fast(struct ocf_io *io) struct blk_data *data = ocf_io_get_data(io); struct bio *bio = data->master_io_req; - _blockdev_start_io_acct(bio); + data->start_time = _blockdev_start_io_acct(bio); } void block_dev_complete_bio_fast(struct ocf_io *io, int error) @@ -761,7 +759,6 @@ static int _blockdev_make_request_fast(struct casdsk_disk *dsk, _blockdev_set_bio_data(data, bio); data->master_io_req = bio; - data->start_time = jiffies; io = ocf_core_new_io(core, cache_priv->io_queues[smp_processor_id()], CAS_BIO_BISECTOR(bio) << SECTOR_SHIFT, From ca7f809965e9cdc70bfe11db33795e84a0477a55 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Fri, 11 Dec 2020 20:27:48 +0100 Subject: [PATCH 2/9] configure: Add __vmalloc() wrapper Signed-off-by: Robert Baldyga --- configure.d/1_vmalloc.conf | 42 +++++++++++++++++++++++++++ modules/cas_cache/ocf_env.h | 2 +- modules/cas_cache/utils/utils_mpool.c | 11 +++---- 3 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 configure.d/1_vmalloc.conf diff --git a/configure.d/1_vmalloc.conf b/configure.d/1_vmalloc.conf new file mode 100644 index 0000000..23ce8b4 --- /dev/null +++ b/configure.d/1_vmalloc.conf @@ -0,0 +1,42 @@ +#!/bin/bash +# +# Copyright(c) 2012-2020 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. $(dirname $3)/conf_framework + +check() { + cur_name=$(basename $2) + config_file_path=$1 + if compile_module $cur_name "__vmalloc(0, 0);" "linux/vmalloc.h" + then + echo $cur_name "1" >> $config_file_path + elif compile_module $cur_name "struct pgprot x; __vmalloc(0, 0, x);" "linux/vmalloc.h" + then + echo $cur_name "2" >> $config_file_path + else + echo $cur_name "X" >> $config_file_path + fi +} + +apply() { + case "$1" in + "1") + add_function " + static inline void *cas_vmalloc(unsigned long size, gfp_t gfp_mask) + { + return __vmalloc(size, gfp_mask); + }" ;; + "2") + add_function " + static inline void *cas_vmalloc(unsigned long size, gfp_t gfp_mask) + { + return __vmalloc(size, gfp_mask, PAGE_KERNEL); + }" ;; + *) + exit 1 + esac +} + +conf_run $@ diff --git a/modules/cas_cache/ocf_env.h b/modules/cas_cache/ocf_env.h index cccff29..4a64eba 100644 --- a/modules/cas_cache/ocf_env.h +++ b/modules/cas_cache/ocf_env.h @@ -41,7 +41,7 @@ static inline void env_free(const void *ptr) static inline void *env_vmalloc_flags(size_t size, int flags) { - return __vmalloc(size, flags | __GFP_HIGHMEM, PAGE_KERNEL); + return cas_vmalloc(size, flags | __GFP_HIGHMEM); } static inline void *env_vzalloc_flags(size_t size, int flags) diff --git a/modules/cas_cache/utils/utils_mpool.c b/modules/cas_cache/utils/utils_mpool.c index 01d1625..f4a0524 100644 --- a/modules/cas_cache/utils/utils_mpool.c +++ b/modules/cas_cache/utils/utils_mpool.c @@ -77,17 +77,18 @@ static env_allocator *cas_mpool_get_allocator( void *cas_mpool_new_f(struct cas_mpool *mpool, uint32_t count, int flags) { + unsigned long size; void *items = NULL; env_allocator *allocator; allocator = cas_mpool_get_allocator(mpool, count); - if (allocator) + if (allocator) { items = env_allocator_new(allocator); - else - items = __vmalloc(mpool->hdr_size + (mpool->item_size * count), - flags | __GFP_ZERO | __GFP_HIGHMEM, - PAGE_KERNEL); + } else { + size = mpool->hdr_size + (mpool->item_size * count); + items = cas_vmalloc(size, flags | __GFP_ZERO | __GFP_HIGHMEM); + } #ifdef ZERO_OR_NULL_PTR if (ZERO_OR_NULL_PTR(items)) From d9ea8d3e32eb8c29804469375fa130e08fa87c5c Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Fri, 11 Dec 2020 20:56:59 +0100 Subject: [PATCH 3/9] configure: Add blk_queue_make_request() wrapper Signed-off-by: Robert Baldyga --- configure.d/1_make_request.conf | 41 +++++++++++++++++++++++++++++++++ modules/cas_disk/exp_obj.c | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 configure.d/1_make_request.conf diff --git a/configure.d/1_make_request.conf b/configure.d/1_make_request.conf new file mode 100644 index 0000000..4c897c3 --- /dev/null +++ b/configure.d/1_make_request.conf @@ -0,0 +1,41 @@ +#!/bin/bash +# +# Copyright(c) 2012-2020 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. $(dirname $3)/conf_framework + +check() { + cur_name=$(basename $2) + config_file_path=$1 + if compile_module $cur_name "blk_queue_make_request" "linux/blkdev.h" + then + echo $cur_name "1" >> $config_file_path + else + echo $cur_name "2" >> $config_file_path + fi +} + +apply() { + case "$1" in + "1") + add_function " + static inline void cas_blk_queue_make_request(struct request_queue *q, + make_request_fn *mfn) + { + blk_queue_make_request(q, mfn); + }" ;; + "2") + add_function " + static inline void cas_blk_queue_make_request(struct request_queue *q, + make_request_fn *mfn) + { + q->make_request_fn = mfn; + }" ;; + *) + exit 1 + esac +} + +conf_run $@ diff --git a/modules/cas_disk/exp_obj.c b/modules/cas_disk/exp_obj.c index a4d2ebe..31a80c1 100644 --- a/modules/cas_disk/exp_obj.c +++ b/modules/cas_disk/exp_obj.c @@ -574,7 +574,7 @@ int casdsk_exp_obj_create(struct casdsk_disk *dsk, const char *dev_name, strlcpy(gd->disk_name, exp_obj->dev_name, sizeof(gd->disk_name)); dsk->exp_obj->mk_rq_fn = queue->make_request_fn; - blk_queue_make_request(queue, _casdsk_exp_obj_make_rq_fn); + cas_blk_queue_make_request(queue, _casdsk_exp_obj_make_rq_fn); if (exp_obj->ops->set_geometry) { result = exp_obj->ops->set_geometry(dsk, dsk->private); From 48c3598ef572addcce3b2cce2b9be39e24639bef Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Fri, 11 Dec 2020 22:11:35 +0100 Subject: [PATCH 4/9] configure: Add bdev_disk_changed() wrapper Signed-off-by: Robert Baldyga --- configure.d/1_reread_partitions.conf | 39 ++++++++++++++++++++++ modules/cas_cache/layer_cache_management.c | 2 +- modules/cas_disk/exp_obj.c | 6 ++-- 3 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 configure.d/1_reread_partitions.conf diff --git a/configure.d/1_reread_partitions.conf b/configure.d/1_reread_partitions.conf new file mode 100644 index 0000000..83f5d6a --- /dev/null +++ b/configure.d/1_reread_partitions.conf @@ -0,0 +1,39 @@ +#!/bin/bash +# +# Copyright(c) 2012-2020 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. $(dirname $3)/conf_framework + +check() { + cur_name=$(basename $2) + config_file_path=$1 + if compile_module $cur_name "bdev_disk_changed(NULL, false);" "linux/genhd.h" + then + echo $cur_name "1" >> $config_file_path + else + echo $cur_name "2" >> $config_file_path + fi +} + +apply() { + case "$1" in + "1") + add_function " + static inline void cas_reread_partitions(struct block_device *bdev) + { + bdev_disk_changed(bdev, false); + }" ;; + "2") + add_function " + static inline void cas_reread_partitions(struct block_device *bdev) + { + ioctl_by_bdev(bdev, BLKRRPART, (unsigned long)NULL); + }" ;; + *) + exit 1 + esac +} + +conf_run $@ diff --git a/modules/cas_cache/layer_cache_management.c b/modules/cas_cache/layer_cache_management.c index 3223fe0..2970ebc 100644 --- a/modules/cas_cache/layer_cache_management.c +++ b/modules/cas_cache/layer_cache_management.c @@ -1824,7 +1824,7 @@ static void init_instance_complete(struct _cache_mngt_attach_context *ctx, /* If we deal with whole device, reread partitions */ if (bdev->bd_contains == bdev) - ioctl_by_bdev(bdev, BLKRRPART, (unsigned long)NULL); + cas_reread_partitions(bdev); /* Set other back information */ name = block_dev_get_elevator_name( diff --git a/modules/cas_disk/exp_obj.c b/modules/cas_disk/exp_obj.c index 31a80c1..b66827e 100644 --- a/modules/cas_disk/exp_obj.c +++ b/modules/cas_disk/exp_obj.c @@ -267,7 +267,7 @@ static int _casdsk_exp_obj_hide_parts(struct casdsk_disk *dsk) gdsk->disk_name); /* Try restore previous partitions by rescaning */ - ioctl_by_bdev(bd, BLKRRPART, (unsigned long) NULL); + cas_reread_partitions(bd); return -EINVAL; } } @@ -280,7 +280,7 @@ static int _casdsk_exp_obj_hide_parts(struct casdsk_disk *dsk) gdsk->flags &= ~_casdsk_flags; gdsk->minors = 1; /* Rescan partitions */ - ioctl_by_bdev(bd, BLKRRPART, (unsigned long) NULL); + cas_reread_partitions(bd); return 0; } @@ -325,7 +325,7 @@ static void _casdsk_exp_obj_clear_dev_t(struct casdsk_disk *dsk) /* Restore previous configuration of bottom disk */ gdsk->minors = dsk->gd_minors; gdsk->flags |= dsk->gd_flags; - ioctl_by_bdev(bdev, BLKRRPART, (unsigned long) NULL); + cas_reread_partitions(bdev); } } From c596c66063c52a370fb8774c0a52e97328091dc9 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Tue, 15 Dec 2020 17:06:36 +0100 Subject: [PATCH 5/9] configure: Add wrappers for default make request function Signed-off-by: Robert Baldyga --- configure.d/1_default_make_request.conf | 54 +++++++++++++++++++++++++ modules/cas_disk/exp_obj.c | 4 +- 2 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 configure.d/1_default_make_request.conf diff --git a/configure.d/1_default_make_request.conf b/configure.d/1_default_make_request.conf new file mode 100644 index 0000000..c3b741c --- /dev/null +++ b/configure.d/1_default_make_request.conf @@ -0,0 +1,54 @@ +#!/bin/bash +# +# Copyright(c) 2012-2020 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. $(dirname $3)/conf_framework + +check() { + cur_name=$(basename $2) + config_file_path=$1 + if compile_module $cur_name "blk_mq_make_request(NULL, NULL);" "linux/blk-mq.h" + then + echo $cur_name "1" >> $config_file_path + else + echo $cur_name "2" >> $config_file_path + fi +} + +apply() { + case "$1" in + "1") + add_function " + static inline void *cas_get_default_mk_request_fn(struct request_queue *q) + { + if (q->make_request_fn) + return q->make_request_fn; + return blk_mq_make_request; + }" + add_function " + static inline void cas_call_default_mk_request_fn(make_request_fn *fn, + struct request_queue *q, struct bio *bio) + { + percpu_ref_get(&q->q_usage_counter); + fn(q, bio); + }" ;; + "2") + add_function " + static inline void *cas_get_default_mk_request_fn(struct request_queue *q) + { + return q->make_request_fn; + }" + add_function " + static inline void cas_call_default_mk_request_fn(make_request_fn *fn, + struct request_queue *q, struct bio *bio) + { + fn(q, bio); + }" ;; + *) + exit 1 + esac +} + +conf_run $@ diff --git a/modules/cas_disk/exp_obj.c b/modules/cas_disk/exp_obj.c index b66827e..2916d78 100644 --- a/modules/cas_disk/exp_obj.c +++ b/modules/cas_disk/exp_obj.c @@ -77,7 +77,7 @@ static inline void _casdsk_exp_obj_handle_bio_att(struct casdsk_disk *dsk, make_request_fn(dsk, q, bio, dsk->private); if (status == CASDSK_BIO_NOT_HANDLED) - dsk->exp_obj->mk_rq_fn(q, bio); + cas_call_default_mk_request_fn(dsk->exp_obj->mk_rq_fn, q, bio); } CAS_DECLARE_BLOCK_CALLBACK(_casdsk_exp_obj_bio_pt_io, struct bio *bio, @@ -573,7 +573,7 @@ int casdsk_exp_obj_create(struct casdsk_disk *dsk, const char *dev_name, gd->private_data = dsk; strlcpy(gd->disk_name, exp_obj->dev_name, sizeof(gd->disk_name)); - dsk->exp_obj->mk_rq_fn = queue->make_request_fn; + dsk->exp_obj->mk_rq_fn = cas_get_default_mk_request_fn(queue); cas_blk_queue_make_request(queue, _casdsk_exp_obj_make_rq_fn); if (exp_obj->ops->set_geometry) { From 0596597f618782c014aef0197657599282490bab Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Sat, 12 Dec 2020 11:10:28 +0100 Subject: [PATCH 6/9] Replace ioctl_by_bdev() with vfs_ioctl() Since kernel 5.8 ioctl_by_bdev() is not available. Signed-off-by: Robert Baldyga --- configure.d/1_vfs_ioctl.conf | 50 +++++++++++++++++++++++++++++++++ modules/cas_disk/exp_obj.c | 54 ++++++++++++++++++++++++++++++------ 2 files changed, 96 insertions(+), 8 deletions(-) create mode 100644 configure.d/1_vfs_ioctl.conf diff --git a/configure.d/1_vfs_ioctl.conf b/configure.d/1_vfs_ioctl.conf new file mode 100644 index 0000000..8813cc5 --- /dev/null +++ b/configure.d/1_vfs_ioctl.conf @@ -0,0 +1,50 @@ +#!/bin/bash +# +# Copyright(c) 2012-2020 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. $(dirname $3)/conf_framework + +check() { + cur_name=$(basename $2) + config_file_path=$1 + if compile_module $cur_name "vfs_ioctl(NULL, 0, 0);" "linux/fs.h" + then + echo $cur_name "1" >> $config_file_path + else + echo $cur_name "2" >> $config_file_path + fi +} + +apply() { + case "$1" in + "1") + add_function " + static inline int cas_vfs_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) + { + return vfs_ioctl(file, cmd, arg); + }" ;; + "2") + add_function " + static inline int cas_vfs_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) + { + int error = -ENOTTY; + + if (!file->f_op->unlocked_ioctl) + goto out; + + error = file->f_op->unlocked_ioctl(file, cmd, arg); + if (error == -ENOIOCTLCMD) + error = -ENOTTY; + out: + return error; + }" ;; + *) + exit 1 + esac +} + +conf_run $@ diff --git a/modules/cas_disk/exp_obj.c b/modules/cas_disk/exp_obj.c index 2916d78..0af9ad0 100644 --- a/modules/cas_disk/exp_obj.c +++ b/modules/cas_disk/exp_obj.c @@ -217,22 +217,54 @@ static int _casdsk_get_next_part_no(struct block_device *bd) return part_no; } -static int _casdsk_del_partitions(struct block_device *bd) +static int _casdsk_del_partitions(struct casdsk_disk *dsk) { - int result = 0; - int part_no; + struct block_device *bd = casdsk_disk_get_blkdev(dsk); + struct file *bd_file; + unsigned long __user usr_bpart; + unsigned long __user usr_barg; struct blkpg_partition bpart; struct blkpg_ioctl_arg barg; + int result = 0; + int part_no; - memset(&bpart, 0, sizeof(struct blkpg_partition)); - memset(&barg, 0, sizeof(struct blkpg_ioctl_arg)); - barg.data = (void __force __user *) &bpart; + bd_file = filp_open(dsk->path, 0, 0); + if (IS_ERR(bd_file)) + return PTR_ERR(bd_file); + + usr_bpart = cas_vm_mmap(NULL, 0, sizeof(bpart)); + if (IS_ERR((void *)usr_bpart)) { + result = PTR_ERR((void *)usr_bpart); + goto out_map_bpart; + } + + usr_barg = cas_vm_mmap(NULL, 0, sizeof(barg)); + if (IS_ERR((void *)usr_barg)) { + result = PTR_ERR((void *)usr_barg); + goto out_map_barg; + } + + + memset(&bpart, 0, sizeof(bpart)); + memset(&barg, 0, sizeof(barg)); + barg.data = (void __user *)usr_bpart; barg.op = BLKPG_DEL_PARTITION; + result = copy_to_user((void __user *)usr_barg, &barg, sizeof(barg)); + if (result) { + result = -EINVAL; + goto out_copy; + } while ((part_no = _casdsk_get_next_part_no(bd))) { bpart.pno = part_no; - result = ioctl_by_bdev(bd, BLKPG, (unsigned long) &barg); + result = copy_to_user((void __user *)usr_bpart, &bpart, + sizeof(bpart)); + if (result) { + result = -EINVAL; + break; + } + result = cas_vfs_ioctl(bd_file, BLKPG, usr_barg); if (result == 0) { printk(CASDSK_KERN_INFO "Partition %d on %s hidden\n", part_no, bd->bd_disk->disk_name); @@ -243,6 +275,12 @@ static int _casdsk_del_partitions(struct block_device *bd) } } +out_copy: + cas_vm_munmap(usr_barg, sizeof(barg)); +out_map_barg: + cas_vm_munmap(usr_bpart, sizeof(bpart)); +out_map_bpart: + filp_close(bd_file, NULL); return result; } @@ -262,7 +300,7 @@ static int _casdsk_exp_obj_hide_parts(struct casdsk_disk *dsk) return 0; if (disk_max_parts(dsk->bd->bd_disk) > 1) { - if (_casdsk_del_partitions(bd)) { + if (_casdsk_del_partitions(dsk)) { printk(CASDSK_KERN_ERR "Error deleting a partition on thedevice %s\n", gdsk->disk_name); From 1810010093c4997a94e815e834b4c4c650221d88 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Sat, 12 Dec 2020 11:32:40 +0100 Subject: [PATCH 7/9] Use default kernel export mechanism when symbol lookup is not available Since kernel 5.7 kallsyms_on_each_symbol() is not available. NOTE: This affects ability to perform upgrade in flight on kernels 5.7+. Signed-off-by: Robert Baldyga --- configure.d/1_kallsyms_on_each_symbol.conf | 31 ++++++++++++++++++++++ modules/cas_cache/main.c | 12 +++++++++ 2 files changed, 43 insertions(+) create mode 100644 configure.d/1_kallsyms_on_each_symbol.conf diff --git a/configure.d/1_kallsyms_on_each_symbol.conf b/configure.d/1_kallsyms_on_each_symbol.conf new file mode 100644 index 0000000..c4e3384 --- /dev/null +++ b/configure.d/1_kallsyms_on_each_symbol.conf @@ -0,0 +1,31 @@ +#!/bin/bash +# +# Copyright(c) 2012-2020 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause-Clear +# + +. $(dirname $3)/conf_framework + +check() { + cur_name=$(basename $2) + config_file_path=$1 + if compile_module $cur_name "kallsyms_on_each_symbol(NULL, NULL)" "linux/fs.h" + then + echo $cur_name "1" >> $config_file_path + else + echo $cur_name "2" >> $config_file_path + fi +} + +apply() { + case "$1" in + "1") + add_define "SYMBOL_LOOKUP_SUPPORTED 1" ;; + "2") + ;; + *) + exit 1 + esac +} + +conf_run $@ diff --git a/modules/cas_cache/main.c b/modules/cas_cache/main.c index b9850e5..af539f3 100644 --- a/modules/cas_cache/main.c +++ b/modules/cas_cache/main.c @@ -51,6 +51,8 @@ bool in_upgrade; ocf_ctx_t cas_ctx; struct casdsk_functions_mapper casdisk_functions; +#ifdef SYMBOL_LOOKUP_SUPPORTED + struct exported_symbol { char *name; unsigned long addr; @@ -74,6 +76,16 @@ int static cas_find_symbol(void *data, const char *namebuf, return -EINVAL; \ }) +#else + +#include "../cas_disk/cas_disk.h" +#include "../cas_disk/exp_obj.h" +#define cas_lookup_symbol(f) ({ \ + casdisk_functions.f = (void *)f; \ +}) + +#endif + int static cas_casdisk_lookup_funtions(void) { mutex_lock(&module_mutex); From bcd6f4831c7c54ec96ad0e1be18d53a244257829 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Fri, 11 Dec 2020 22:44:55 +0100 Subject: [PATCH 8/9] Update atomic mode support check Signed-off-by: Robert Baldyga --- modules/cas_cache/utils/utils_nvme.c | 4 ++++ modules/config.mk | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/modules/cas_cache/utils/utils_nvme.c b/modules/cas_cache/utils/utils_nvme.c index b21c432..cc7948b 100644 --- a/modules/cas_cache/utils/utils_nvme.c +++ b/modules/cas_cache/utils/utils_nvme.c @@ -3,6 +3,8 @@ * SPDX-License-Identifier: BSD-3-Clause-Clear */ +#if defined(CAS_NVME_PARTIAL) + #include "cas_cache.h" #include "utils_nvme.h" #include "utils_blk.h" @@ -62,3 +64,5 @@ out: cas_vm_munmap(buffer, sizeof(*ns)); return ret; } + +#endif diff --git a/modules/config.mk b/modules/config.mk index 9312717..e480206 100644 --- a/modules/config.mk +++ b/modules/config.mk @@ -32,28 +32,28 @@ NVME_FULL = 0 SLES ?= $(shell cat /etc/SuSE-release 2>/dev/null) ifneq ($(SLES),) EXTRA_CFLAGS += -DCAS_UAPI_LINUX_NVME_IOCTL -EXTRA_CFLAGS += -DCAS_NVME_PARTIAL EXTRA_CFLAGS += -DCAS_SLES SLES_VERSION := $(shell cat /etc/os-release |\ sed -n 's/VERSION="\([0-9]\+\)-\(.\+\)"/\1\2/p') EXTRA_CFLAGS += -DCAS_SLES$(SLES_VERSION) INCDIR = "" +NVME_PARTIAL = 1 endif ifeq ($(call check_header,$(INCDIR)/uapi/nvme.h), 1) EXTRA_CFLAGS += -DCAS_UAPI_NVME_IOCTL EXTRA_CFLAGS += -DCAS_UAPI_NVME -EXTRA_CFLAGS += -DCAS_NVME_PARTIAL +NVME_PARTIAL = 1 endif ifeq ($(call check_header,$(INCDIR)/uapi/linux/nvme.h), 1) EXTRA_CFLAGS += -DCAS_UAPI_LINUX_NVME -EXTRA_CFLAGS += -DCAS_NVME_PARTIAL +NVME_PARTIAL = 1 endif ifeq ($(call check_header,$(INCDIR)/uapi/linux/nvme_ioctl.h), 1) EXTRA_CFLAGS += -DCAS_UAPI_LINUX_NVME_IOCTL -EXTRA_CFLAGS += -DCAS_NVME_PARTIAL +NVME_PARTIAL = 1 ifeq ($(shell cat /etc/redhat-release 2>/dev/null | grep "\(Red Hat\|CentOS\) [a-zA-Z ]* 7\.[45]" | wc -l), 1) NVME_FULL = 1 endif @@ -62,10 +62,18 @@ endif KERNEL_VERSION = $(shell echo $(KERNELRELEASE) | cut -d'.' -f1) KERNEL_MAJOR = $(shell echo $(KERNELRELEASE) | cut -d'.' -f2) -ifeq ($(shell expr $(KERNEL_VERSION) \>= 4 \& $(KERNEL_MAJOR) \> 11),1) +ifeq ($(shell expr $(KERNEL_VERSION) \> 4 \| $(KERNEL_VERSION) \== 4 \& $(KERNEL_MAJOR) \> 11),1) NVME_FULL = 0 endif +ifeq ($(shell expr $(KERNEL_VERSION) \> 5 \| $(KERNEL_VERSION) \== 5 \& $(KERNEL_MAJOR) \> 7),1) +NVME_PARTIAL = 0 +endif + +ifeq ($(NVME_PARTIAL),1) +EXTRA_CFLAGS += -DCAS_NVME_PARTIAL +endif + ifeq ($(NVME_FULL),1) EXTRA_CFLAGS += -DCAS_NVME_FULL endif From 7e40570bbd319baf79735c1caed8c2b42961bcd9 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Sat, 12 Dec 2020 11:36:13 +0100 Subject: [PATCH 9/9] Remove #ifdef for unsupported kernel version Signed-off-by: Robert Baldyga --- modules/cas_cache/classifier.c | 4 ---- modules/cas_disk/cas_disk_defs.h | 2 -- 2 files changed, 6 deletions(-) diff --git a/modules/cas_cache/classifier.c b/modules/cas_cache/classifier.c index dbd3a83..d7b4995 100644 --- a/modules/cas_cache/classifier.c +++ b/modules/cas_cache/classifier.c @@ -1090,11 +1090,7 @@ static struct cas_classifier *_cas_cls_init(void) INIT_LIST_HEAD(&cls->rules); -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36) cls->wq = alloc_workqueue("kcas_clsd", WQ_UNBOUND | WQ_FREEZABLE, 1); -#else - cls->wq = create_singlethread_workqueue("kcas_clsd"); -#endif if (!cls->wq) { kfree(cls); return ERR_PTR(-ENOMEM); diff --git a/modules/cas_disk/cas_disk_defs.h b/modules/cas_disk/cas_disk_defs.h index 4c5babc..7f0d299 100644 --- a/modules/cas_disk/cas_disk_defs.h +++ b/modules/cas_disk/cas_disk_defs.h @@ -50,7 +50,6 @@ extern struct casdsk_module *casdsk_module; #define CASDSK_KERN_INFO KERN_INFO""CASDSK_PREFIX_SHORT #define CASDSK_KERN_DEBUG KERN_DEBUG""CASDSK_PREFIX_SHORT -#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 37) static inline struct block_device *open_bdev_exclusive(const char *path, fmode_t mode, void *holder) @@ -74,7 +73,6 @@ static inline void bd_release_from_disk(struct block_device *bdev, { return bd_unlink_disk_holder(bdev, disk); } -#endif #if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0) #define KRETURN(x) ({ return (x); })