Skip to content

Commit

Permalink
Add support for Linux kernel up to 6.5
Browse files Browse the repository at this point in the history
Signed-off-by: Tamar Levovitz <[email protected]>
Signed-off-by: Robert Baldyga <[email protected]>
  • Loading branch information
Tamar Levovitz authored and robertbaldyga committed May 10, 2024
1 parent ab0d7d0 commit 0fedbbf
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 22 deletions.
38 changes: 38 additions & 0 deletions configure.d/1_bdev_get_by_path.conf
Original file line number Diff line number Diff line change
@@ -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 $@
38 changes: 38 additions & 0 deletions configure.d/1_bdev_put.conf
Original file line number Diff line number Diff line change
@@ -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 $@
42 changes: 42 additions & 0 deletions configure.d/1_cas_mode.conf
Original file line number Diff line number Diff line change
@@ -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 $@
48 changes: 48 additions & 0 deletions configure.d/2_bdev_close.conf
Original file line number Diff line number Diff line change
@@ -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 $@
49 changes: 49 additions & 0 deletions configure.d/2_bdev_open.conf
Original file line number Diff line number Diff line change
@@ -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 $@
18 changes: 10 additions & 8 deletions modules/cas_cache/disk.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <linux/module.h>
Expand All @@ -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)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions modules/cas_cache/exp_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand All @@ -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)
};

Expand Down
18 changes: 9 additions & 9 deletions modules/cas_cache/layer_cache_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 :
Expand All @@ -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;
}

Expand Down Expand Up @@ -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 :
Expand All @@ -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;
}

Expand Down Expand Up @@ -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 :
Expand All @@ -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;
Expand Down

0 comments on commit 0fedbbf

Please sign in to comment.