From fea5e72d8c5750a841685cd94ff2b96618df74be Mon Sep 17 00:00:00 2001 From: Gal Hammer Date: Sun, 30 Jan 2022 10:58:27 +0200 Subject: [PATCH 1/4] configure/module_mutex: adapt to kernel 5.12 The module_mutex is internal to the module loader since kernel commit 922f2a7c. Signed-off-by: Gal Hammer Signed-off-by: Shai Fultheim Signed-off-by: Robert Baldyga --- configure.d/1_module_mutex.conf | 32 ++++++++++++++++++++++++++++++++ modules/cas_cache/main.c | 6 +++++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 configure.d/1_module_mutex.conf diff --git a/configure.d/1_module_mutex.conf b/configure.d/1_module_mutex.conf new file mode 100644 index 0000000..d8cc307 --- /dev/null +++ b/configure.d/1_module_mutex.conf @@ -0,0 +1,32 @@ +#!/bin/bash +# +# Copyright(c) 2022 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause +# + +. $(dirname $3)/conf_framework + + +check() { + cur_name=$(basename $2) + config_file_path=$1 + if compile_module $cur_name "mutex_lock(&module_mutex);" "linux/module.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 "MODULE_MUTEX_SUPPORTED 1" ;; + "2") + ;; + *) + exit 1 + esac +} + +conf_run $@ diff --git a/modules/cas_cache/main.c b/modules/cas_cache/main.c index 2b4a4fd..3bebeb7 100644 --- a/modules/cas_cache/main.c +++ b/modules/cas_cache/main.c @@ -46,7 +46,7 @@ MODULE_PARM_DESC(seq_cut_off_mb, ocf_ctx_t cas_ctx; struct casdsk_functions_mapper casdisk_functions; -#ifdef SYMBOL_LOOKUP_SUPPORTED +#if defined(SYMBOL_LOOKUP_SUPPORTED) && defined(MODULE_MUTEX_SUPPORTED) struct exported_symbol { char *name; @@ -83,7 +83,9 @@ int static cas_find_symbol(void *data, const char *namebuf, int static cas_casdisk_lookup_funtions(void) { +#ifdef MODULE_MUTEX_SUPPORTED mutex_lock(&module_mutex); +#endif cas_lookup_symbol(casdsk_disk_detach); cas_lookup_symbol(casdsk_exp_obj_destroy); cas_lookup_symbol(casdsk_exp_obj_create); @@ -105,7 +107,9 @@ int static cas_casdisk_lookup_funtions(void) cas_lookup_symbol(casdsk_disk_open); cas_lookup_symbol(casdsk_disk_clear_pt); cas_lookup_symbol(casdsk_exp_obj_get_gendisk); +#ifdef MODULE_MUTEX_SUPPORTED mutex_unlock(&module_mutex); +#endif return 0; } From 4bb435555f28dc19d1782828bfa08b663686a7fe Mon Sep 17 00:00:00 2001 From: Gal Hammer Date: Sun, 30 Jan 2022 11:30:05 +0200 Subject: [PATCH 2/4] configure/bd_part_count: adapt to kernel 5.12 Moved cas_blk_get_part_count function to configure section after the the disk's partitions table was changed to xarray. Signed-off-by: Gal Hammer Signed-off-by: Shai Fultheim --- configure.d/1_bd_part_count.conf | 61 ++++++++++++++++++++++ modules/cas_cache/layer_cache_management.c | 1 - modules/cas_cache/utils/utils_blk.c | 22 -------- modules/cas_cache/utils/utils_blk.h | 14 ----- 4 files changed, 61 insertions(+), 37 deletions(-) create mode 100644 configure.d/1_bd_part_count.conf delete mode 100644 modules/cas_cache/utils/utils_blk.c delete mode 100644 modules/cas_cache/utils/utils_blk.h diff --git a/configure.d/1_bd_part_count.conf b/configure.d/1_bd_part_count.conf new file mode 100644 index 0000000..0986b23 --- /dev/null +++ b/configure.d/1_bd_part_count.conf @@ -0,0 +1,61 @@ +#!/bin/bash +# +# Copyright(c) 2012-2022 Intel Corporation +# SPDX-License-Identifier: BSD-3-Clause +# + +. $(dirname $3)/conf_framework + +check() { + cur_name=$(basename $2) + config_file_path=$1 + if compile_module $cur_name "struct gendisk *disk = NULL; struct xarray xa; xa = disk->part_tbl" "linux/genhd.h" + then + echo $cur_name "1" >> $config_file_path + elif compile_module $cur_name "struct gendisk *disk = NULL; struct disk_part_tbl *ptbl; ptbl = disk->part_tbl" "linux/genhd.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 int cas_blk_get_part_count(struct block_device *bdev) + { + struct block_device *part; + unsigned long idx; + int count = 0; + + xa_for_each(&bdev->bd_disk->part_tbl, idx, part) { + count++; + } + + return count; + }" ;; + "2") + add_function " + static inline int cas_blk_get_part_count(struct block_device *bdev) + { + struct disk_part_tbl *ptbl; + int i, count = 0; + + rcu_read_lock(); + ptbl = rcu_dereference(bdev->bd_disk->part_tbl); + for (i = 0; i < ptbl->len; ++i) { + if (rcu_access_pointer(ptbl->part[i])) + count++; + } + rcu_read_unlock(); + + return count; + }" ;; + *) + exit 1 + esac +} + +conf_run $@ diff --git a/modules/cas_cache/layer_cache_management.c b/modules/cas_cache/layer_cache_management.c index 4907a49..6f4252d 100644 --- a/modules/cas_cache/layer_cache_management.c +++ b/modules/cas_cache/layer_cache_management.c @@ -4,7 +4,6 @@ */ #include "cas_cache.h" -#include "utils/utils_blk.h" #include "threads.h" extern u32 max_writeback_queue_size; diff --git a/modules/cas_cache/utils/utils_blk.c b/modules/cas_cache/utils/utils_blk.c deleted file mode 100644 index 2286bf3..0000000 --- a/modules/cas_cache/utils/utils_blk.c +++ /dev/null @@ -1,22 +0,0 @@ -/* -* Copyright(c) 2012-2021 Intel Corporation -* SPDX-License-Identifier: BSD-3-Clause -*/ - -#include "utils_blk.h" - -int cas_blk_get_part_count(struct block_device *bdev) -{ - struct disk_part_tbl *ptbl; - int i, count = 0; - - rcu_read_lock(); - ptbl = rcu_dereference(bdev->bd_disk->part_tbl); - for (i = 0; i < ptbl->len; ++i) { - if (rcu_access_pointer(ptbl->part[i])) - count++; - } - rcu_read_unlock(); - - return count; -} diff --git a/modules/cas_cache/utils/utils_blk.h b/modules/cas_cache/utils/utils_blk.h deleted file mode 100644 index 9a3946f..0000000 --- a/modules/cas_cache/utils/utils_blk.h +++ /dev/null @@ -1,14 +0,0 @@ -/* -* Copyright(c) 2012-2021 Intel Corporation -* SPDX-License-Identifier: BSD-3-Clause -*/ - -#ifndef UTILS_BLK_H_ -#define UTILS_BLK_H_ - -#include -#include - -int cas_blk_get_part_count(struct block_device *bdev); - -#endif /* UTILS_BLK_H_ */ From 3c3cb6bdf176bcc8360b78832e201bbd47d611e5 Mon Sep 17 00:00:00 2001 From: Gal Hammer Date: Sun, 30 Jan 2022 12:52:10 +0200 Subject: [PATCH 3/4] configure/bio_dev: adapt to kernel 5.12 Signed-off-by: Gal Hammer Signed-off-by: Shai Fultheim --- configure.d/1_bio_dev.conf | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/configure.d/1_bio_dev.conf b/configure.d/1_bio_dev.conf index d8c1775..4d69a20 100644 --- a/configure.d/1_bio_dev.conf +++ b/configure.d/1_bio_dev.conf @@ -9,12 +9,15 @@ check() { cur_name=$(basename $2) config_file_path=$1 - if compile_module $cur_name "struct bio b;bio_dev(&b);" "linux/bio.h" "linux/genhd.h" + if compile_module $cur_name "struct bio b = {}; bio_dev(&b); b.bi_bdev = NULL" "linux/bio.h" "linux/genhd.h" then - echo $cur_name "1" >> $config_file_path - elif compile_module $cur_name "struct bio b;b.bi_bdev" "linux/bio.h" + echo $cur_name "1" >> $config_file_path + elif compile_module $cur_name "struct bio b = {}; bio_dev(&b); b.bi_disk = NULL" "linux/bio.h" then echo $cur_name "2" >> $config_file_path + elif compile_module $cur_name "struct bio b; b.bi_bdev = NULL" "linux/bio.h" + then + echo $cur_name "3" >> $config_file_path else echo $cur_name "X" >> $config_file_path fi @@ -26,8 +29,13 @@ apply() { add_define "CAS_BIO_SET_DEV(bio, bdev) \\ bio_set_dev(bio, bdev)" add_define "CAS_BIO_GET_DEV(bio) \\ - bio->bi_disk" ;; + bio->bi_bdev->bd_disk" ;; "2") + add_define "CAS_BIO_SET_DEV(bio, bdev) \\ + bio_set_dev(bio, bdev)" + add_define "CAS_BIO_GET_DEV(bio) \\ + bio->bi_disk" ;; + "3") add_define "CAS_BIO_SET_DEV(bio, bdev) \\ bio->bi_bdev = bdev" add_define "CAS_BIO_GET_DEV(bio) \\ From 1d64bc5294ce81b177e47dcbb9797f26f25e182d Mon Sep 17 00:00:00 2001 From: Gal Hammer Date: Mon, 7 Feb 2022 14:53:34 +0200 Subject: [PATCH 4/4] configure/bd_first_part: adapt to kernel 5.12 The disk's partitions table was changed to xarray. Signed-off-by: Gal Hammer Signed-off-by: Shai Fultheim --- configure.d/1_bd_first_part.conf | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/configure.d/1_bd_first_part.conf b/configure.d/1_bd_first_part.conf index 1495c70..a9643ba 100644 --- a/configure.d/1_bd_first_part.conf +++ b/configure.d/1_bd_first_part.conf @@ -1,6 +1,6 @@ #!/bin/bash # -# Copyright(c) 2012-2021 Intel Corporation +# Copyright(c) 2012-2022 Intel Corporation # SPDX-License-Identifier: BSD-3-Clause # @@ -9,15 +9,18 @@ check() { cur_name=$(basename $2) config_file_path=$1 - if compile_module $cur_name "struct block_device bd; bd = *disk_part_iter_next(NULL);" "linux/blk_types.h" "linux/genhd.h" + if compile_module $cur_name "struct gendisk *disk = NULL; struct xarray xa; xa = disk->part_tbl" "linux/genhd.h" then echo $cur_name "1" >> $config_file_path - elif compile_module $cur_name "struct hd_struct hd; hd = *disk_part_iter_next(NULL);" "linux/genhd.h" - then + elif compile_module $cur_name "struct block_device bd; bd = *disk_part_iter_next(NULL);" "linux/blk_types.h" + then echo $cur_name "2" >> $config_file_path + elif compile_module $cur_name "struct hd_struct hd; hd = *disk_part_iter_next(NULL);" "linux/genhd.h" + then + echo $cur_name "3" >> $config_file_path else echo $cur_name "X" >> $config_file_path - fi + fi } apply() { @@ -25,6 +28,23 @@ apply() { "1") add_function " static inline int cas_bd_get_next_part(struct block_device *bd) + { + int part_no = 0; + struct gendisk *disk = bd->bd_disk; + struct block_device *part; + unsigned long idx; + + xa_for_each(&disk->part_tbl, idx, part) { + if ((part_no = part->bd_partno)) { + break; + } + } + + return part_no; + }" ;; + "2") + add_function " + static inline int cas_bd_get_next_part(struct block_device *bd) { int part_no = 0; struct gendisk *disk = bd->bd_disk; @@ -44,7 +64,7 @@ apply() { return part_no; }" ;; - "2") + "3") add_function " static inline int cas_bd_get_next_part(struct block_device *bd) {