diff --git a/configure.d/1_bdev_get_by_path.conf b/configure.d/1_bdev_get_by_path.conf new file mode 100644 index 000000000..aa8e96866 --- /dev/null +++ b/configure.d/1_bdev_get_by_path.conf @@ -0,0 +1,38 @@ +#!/bin/bash +# +# Copyright(c) 2012-2022 Intel Corporation +# Copyright(c) 2024 Huawei Technologies +# SPDX-License-Identifier: BSD-3-Clause +# + +. $(dirname $3)/conf_framework.sh + + +check() { + cur_name=$(basename $2) + config_file_path=$1 + if compile_module $cur_name "blkdev_get_by_path(NULL, 0, NULL);" "linux/blkdev.h" + then + echo $cur_name 1 >> $config_file_path + elif compile_module $cur_name "blkdev_get_by_path(NULL, 0, NULL, NULL);" "linux/blkdev.h" + then + echo $cur_name 2 >> $config_file_path + else + echo $cur_name X >> $config_file_path + fi +} + +apply() { + case "$1" in + "1") + add_define "cas_blkdev_get_by_path(path, mode, holder) \\ + blkdev_get_by_path(path, mode, holder)" ;; + "2") + add_define "cas_blkdev_get_by_path(path, mode, holder) \\ + blkdev_get_by_path(path, mode, holder, NULL)" ;; + *) + exit 1 + esac +} + +conf_run $@ diff --git a/configure.d/1_bdev_put.conf b/configure.d/1_bdev_put.conf new file mode 100644 index 000000000..43876afbd --- /dev/null +++ b/configure.d/1_bdev_put.conf @@ -0,0 +1,38 @@ +#!/bin/bash +# +# Copyright(c) 2012-2022 Intel Corporation +# Copyright(c) 2024 Huawei Technologies +# SPDX-License-Identifier: BSD-3-Clause +# + +. $(dirname $3)/conf_framework.sh + + +check() { + cur_name=$(basename $2) + config_file_path=$1 + if compile_module $cur_name "blkdev_put(NULL, FMODE_READ);" "linux/blkdev.h" + then + echo $cur_name 1 >> $config_file_path + elif compile_module $cur_name "blkdev_put(NULL, NULL);" "linux/blkdev.h" + then + echo $cur_name 2 >> $config_file_path + else + echo $cur_name X >> $config_file_path + fi +} + +apply() { + case "$1" in + "1") + add_define "cas_blkdev_put(bdev, mode, holder) \\ + blkdev_put(bdev, mode)" ;; + "2") + add_define "cas_blkdev_put(bdev, mode, holder) \\ + blkdev_put(bdev, holder)" ;; + *) + exit 1 + esac +} + +conf_run $@ diff --git a/configure.d/1_cas_mode.conf b/configure.d/1_cas_mode.conf new file mode 100644 index 000000000..95facf385 --- /dev/null +++ b/configure.d/1_cas_mode.conf @@ -0,0 +1,42 @@ +#!/bin/bash +# +# Copyright(c) 2012-2022 Intel Corporation +# Copyright(c) 2024 Huawei Technologies +# SPDX-License-Identifier: BSD-3-Clause +# + +. $(dirname $3)/conf_framework.sh + + +check() { + cur_name=$(basename $2) + config_file_path=$1 + if compile_module $cur_name "int x = FMODE_EXCL;" "linux/fs.h" + then + echo $cur_name 1 >> $config_file_path + elif compile_module $cur_name "int x = BLK_OPEN_EXCL;" "linux/blkdev.h" + then + echo $cur_name 2 >> $config_file_path + else + echo $cur_name X >> $config_file_path + fi +} + +apply() { + case "$1" in + "1") + add_define "CAS_MODE fmode_t" + add_define "CAS_MODE_READ FMODE_READ" + add_define "CAS_MODE_WRITE FMODE_WRITE" + add_define "CAS_MODE_EXCL FMODE_EXCL" ;; + "2") + add_define "CAS_MODE blk_mode_t" + add_define "CAS_MODE_READ BLK_OPEN_READ" + add_define "CAS_MODE_WRITE BLK_OPEN_WRITE" + add_define "CAS_MODE_EXCL BLK_OPEN_EXCL" ;; + *) + exit 1 + esac +} + +conf_run $@ diff --git a/configure.d/2_bdev_close.conf b/configure.d/2_bdev_close.conf new file mode 100644 index 000000000..191f5f5c1 --- /dev/null +++ b/configure.d/2_bdev_close.conf @@ -0,0 +1,48 @@ +#!/bin/bash +# +# Copyright(c) 2012-2022 Intel Corporation +# Copyright(c) 2024 Huawei Technologies +# SPDX-License-Identifier: BSD-3-Clause +# + +. $(dirname $3)/conf_framework.sh + +check() { + cur_name=$(basename $2) + config_file_path=$1 + if compile_module $cur_name "struct block_device_operations bdo; bdo.release(NULL, 0);" "linux/blkdev.h" + then + echo $cur_name "1" >> $config_file_path + elif compile_module $cur_name "struct block_device_operations bdo; bdo.release(NULL);" "linux/blkdev.h" + then + echo $cur_name "2" >> $config_file_path + else + echo $cur_name "X" >> $config_file_path + fi +} + +apply() { + add_define "CAS_REFER_BDEV_CLOSE_CALLBACK(name) \\ + name##_callback_wrapper" + case "$1" in + "1") + add_define "CAS_BDEV_CLOSE(name, DISK) \\ + static void name##_callback(DISK); \\ + static void name##_callback_wrapper(struct gendisk *gd, \\ + CAS_MODE _mode) \\ + { \\ + name##_callback(gd); \\ + } \\ + static void name##_callback(DISK)";; + "2") + add_define "CAS_BDEV_CLOSE(name, DISK) \\ + static void name##_callback(DISK); \\ + static void name##_callback_wrapper(struct gendisk *gd) \\ + { \\ + name##_callback(gd); \\ + } \\ + static void name##_callback(DISK)";; + esac +} + +conf_run $@ diff --git a/configure.d/2_bdev_open.conf b/configure.d/2_bdev_open.conf new file mode 100644 index 000000000..9271594b0 --- /dev/null +++ b/configure.d/2_bdev_open.conf @@ -0,0 +1,49 @@ +#!/bin/bash +# +# Copyright(c) 2012-2022 Intel Corporation +# Copyright(c) 2024 Huawei Technologies +# SPDX-License-Identifier: BSD-3-Clause +# + +. $(dirname $3)/conf_framework.sh + +check() { + cur_name=$(basename $2) + config_file_path=$1 + if compile_module $cur_name "struct block_device_operations *ops; struct block_device *bd; ops->open(bd, 0);" "linux/blkdev.h" + then + echo $cur_name "1" >> $config_file_path + elif compile_module $cur_name "struct block_device_operations *ops; struct gendisk *gd; ops->open(gd, 0);" "linux/blkdev.h" + then + echo $cur_name "2" >> $config_file_path + else + echo $cur_name "X" >> $config_file_path + fi +} + +apply() { + add_define "CAS_REFER_BDEV_OPEN_CALLBACK(name) \\ + name##_callback_wrapper" + case "$1" in + "1") + add_define "CAS_BDEV_OPEN(name, DISK) \\ + static int name##_callback(DISK); \\ + static int name##_callback_wrapper(struct block_device *bdev, \\ + CAS_MODE _mode) \\ + { \\ + return name##_callback(bdev->bd_disk); \\ + } \\ + static int name##_callback(DISK)";; + "2") + add_define "CAS_BDEV_OPEN(name, DISK) \\ + static int name##_callback(DISK); \\ + static int name##_callback_wrapper(struct gendisk *gd, \\ + CAS_MODE _mode) \\ + { \\ + return name##_callback(gd->part0->bd_disk); \\ + } \\ + static int name##_callback(DISK)";; + esac +} + +conf_run $@ diff --git a/modules/cas_cache/disk.c b/modules/cas_cache/disk.c index 1738802ab..59d14ae9d 100644 --- a/modules/cas_cache/disk.c +++ b/modules/cas_cache/disk.c @@ -1,5 +1,6 @@ /* * Copyright(c) 2012-2022 Intel Corporation +* Copyright(c) 2024 Huawei Technologies * SPDX-License-Identifier: BSD-3-Clause */ #include @@ -11,18 +12,19 @@ #include "exp_obj.h" #include "debug.h" -#define CAS_DISK_OPEN_FMODE (FMODE_READ | FMODE_WRITE) +#define CAS_DISK_OPEN_MODE (CAS_MODE_READ | CAS_MODE_WRITE) static inline struct block_device *open_bdev_exclusive(const char *path, - fmode_t mode, - void *holder) + CAS_MODE mode, void *holder) { - return blkdev_get_by_path(path, mode | FMODE_EXCL, holder); + return cas_blkdev_get_by_path(path, mode | CAS_MODE_EXCL, + holder); } -static inline void close_bdev_exclusive(struct block_device *bdev, fmode_t mode) +static inline void close_bdev_exclusive(struct block_device *bdev, + CAS_MODE mode) { - blkdev_put(bdev, mode | FMODE_EXCL); + cas_blkdev_put(bdev, mode | CAS_MODE_EXCL, NULL); } int __init cas_init_disks(void) @@ -67,7 +69,7 @@ struct cas_disk *cas_disk_open(const char *path) goto error_kstrdup; } - dsk->bd = open_bdev_exclusive(path, CAS_DISK_OPEN_FMODE, dsk); + dsk->bd = open_bdev_exclusive(path, CAS_DISK_OPEN_MODE, dsk); if (IS_ERR(dsk->bd)) { CAS_DEBUG_ERROR("Cannot open exclusive"); result = PTR_ERR(dsk->bd); @@ -93,7 +95,7 @@ void cas_disk_close(struct cas_disk *dsk) CAS_DEBUG_DISK(dsk, "Destroying (%p)", dsk); - close_bdev_exclusive(dsk->bd, CAS_DISK_OPEN_FMODE); + close_bdev_exclusive(dsk->bd, CAS_DISK_OPEN_MODE); kfree(dsk->path); kmem_cache_free(cas_module.disk_cache, dsk); diff --git a/modules/cas_cache/exp_obj.c b/modules/cas_cache/exp_obj.c index 071dbba03..62c770c57 100644 --- a/modules/cas_cache/exp_obj.c +++ b/modules/cas_cache/exp_obj.c @@ -256,9 +256,9 @@ static void _cas_exp_obj_clear_dev_t(struct cas_disk *dsk) } } -static int _cas_exp_obj_open(struct block_device *bdev, fmode_t mode) +CAS_BDEV_OPEN(_cas_exp_obj_open, struct gendisk *gd) { - struct cas_disk *dsk = bdev->bd_disk->private_data; + struct cas_disk *dsk = gd->private_data; struct cas_exp_obj *exp_obj = dsk->exp_obj; int result = -ENAVAIL; @@ -277,7 +277,7 @@ static int _cas_exp_obj_open(struct block_device *bdev, fmode_t mode) return result; } -static void _cas_exp_obj_close(struct gendisk *gd, fmode_t mode) +CAS_BDEV_CLOSE(_cas_exp_obj_close, struct gendisk *gd) { struct cas_disk *dsk = gd->private_data; struct cas_exp_obj *exp_obj = dsk->exp_obj; @@ -292,8 +292,8 @@ static void _cas_exp_obj_close(struct gendisk *gd, fmode_t mode) static const struct block_device_operations _cas_exp_obj_ops = { .owner = THIS_MODULE, - .open = _cas_exp_obj_open, - .release = _cas_exp_obj_close, + .open = CAS_REFER_BDEV_OPEN_CALLBACK(_cas_exp_obj_open), + .release = CAS_REFER_BDEV_CLOSE_CALLBACK(_cas_exp_obj_close), CAS_SET_SUBMIT_BIO(_cas_exp_obj_submit_bio) }; diff --git a/modules/cas_cache/layer_cache_management.c b/modules/cas_cache/layer_cache_management.c index 4d09826b3..1d8cf3e15 100644 --- a/modules/cas_cache/layer_cache_management.c +++ b/modules/cas_cache/layer_cache_management.c @@ -1143,8 +1143,8 @@ int cache_mngt_cache_check_device(struct kcas_cache_check_device *cmd_info) char holder[] = "CAS CHECK CACHE DEVICE\n"; int result; - bdev = blkdev_get_by_path(cmd_info->path_name, (FMODE_EXCL|FMODE_READ), - holder); + bdev = cas_blkdev_get_by_path(cmd_info->path_name, + (CAS_MODE_EXCL | CAS_MODE_READ), holder); if (IS_ERR(bdev)) { return (PTR_ERR(bdev) == -EBUSY) ? -OCF_ERR_NOT_OPEN_EXC : @@ -1165,7 +1165,7 @@ int cache_mngt_cache_check_device(struct kcas_cache_check_device *cmd_info) cas_blk_close_volume(volume); out_bdev: - blkdev_put(bdev, (FMODE_EXCL|FMODE_READ)); + cas_blkdev_put(bdev, (CAS_MODE_EXCL|CAS_MODE_READ), holder); return result; } @@ -2140,8 +2140,8 @@ static int _cache_mngt_probe_metadata(char *cache_path_name, char holder[] = "CAS CHECK METADATA\n"; int result; - bdev = blkdev_get_by_path(cache_path_name, (FMODE_EXCL|FMODE_READ), - holder); + bdev = cas_blkdev_get_by_path(cache_path_name, + (CAS_MODE_EXCL | CAS_MODE_READ), holder); if (IS_ERR(bdev)) { return (PTR_ERR(bdev) == -EBUSY) ? -OCF_ERR_NOT_OPEN_EXC : @@ -2164,7 +2164,7 @@ static int _cache_mngt_probe_metadata(char *cache_path_name, cas_blk_close_volume(volume); out_bdev: - blkdev_put(bdev, (FMODE_EXCL|FMODE_READ)); + cas_blkdev_put(bdev, (CAS_MODE_EXCL|CAS_MODE_READ), holder); return result; } @@ -2232,8 +2232,8 @@ static int cache_mngt_check_bdev(struct ocf_mngt_cache_device_config *cfg, bool is_part; const struct ocf_volume_uuid *uuid = ocf_volume_get_uuid(device_cfg->volume); - bdev = blkdev_get_by_path(uuid->data, - (FMODE_EXCL|FMODE_READ), holder); + bdev = cas_blkdev_get_by_path(uuid->data, + (CAS_MODE_EXCL | CAS_MODE_READ), holder); if (IS_ERR(bdev)) { return (PTR_ERR(bdev) == -EBUSY) ? -OCF_ERR_NOT_OPEN_EXC : @@ -2242,7 +2242,7 @@ static int cache_mngt_check_bdev(struct ocf_mngt_cache_device_config *cfg, is_part = (cas_bdev_whole(bdev) != bdev); part_count = cas_blk_get_part_count(bdev); - blkdev_put(bdev, (FMODE_EXCL|FMODE_READ)); + cas_blkdev_put(bdev, (CAS_MODE_EXCL|CAS_MODE_READ), holder); if (!is_part && part_count > 1 && !force) return -KCAS_ERR_CONTAINS_PART;