Skip to content

Commit

Permalink
Add support for Linux kernel up to 6.8
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Baldyga <[email protected]>
  • Loading branch information
robertbaldyga committed May 10, 2024
1 parent 0fedbbf commit 11f3d4e
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 82 deletions.
38 changes: 0 additions & 38 deletions configure.d/1_bdev_get_by_path.conf

This file was deleted.

53 changes: 53 additions & 0 deletions configure.d/1_bdev_open_by_path.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/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
elif compile_module $cur_name "bdev_open_by_path(NULL, 0, NULL, NULL);" "linux/blkdev.h"
then
echo $cur_name 3 >> $config_file_path
else
echo $cur_name X >> $config_file_path
fi
}

apply() {
case "$1" in
"1")
add_typedef "struct block_device *cas_bdev_handle_t;"
add_define "cas_bdev_open_by_path(path, mode, holder) \\
blkdev_get_by_path(path, mode, holder)"
add_define "cas_bdev_get_from_handle(handle) \\
((struct block_device *)handle)" ;;
"2")
add_typedef "struct block_device *cas_bdev_handle_t;"
add_define "cas_bdev_open_by_path(path, mode, holder) \\
blkdev_get_by_path(path, mode, holder, NULL)"
add_define "cas_bdev_get_from_handle(handle) \\
((struct block_device *)handle)" ;;
"3")
add_typedef "struct bdev_handle *cas_bdev_handle_t;"
add_define "cas_bdev_open_by_path(path, mode, holder) \\
bdev_open_by_path(path, mode, holder, NULL)"
add_define "cas_bdev_get_from_handle(handle) \\
(handle->bdev)" ;;
*)
exit 1
esac
}

conf_run $@
14 changes: 10 additions & 4 deletions configure.d/1_bdev_put.conf → configure.d/1_bdev_release.conf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ check() {
elif compile_module $cur_name "blkdev_put(NULL, NULL);" "linux/blkdev.h"
then
echo $cur_name 2 >> $config_file_path
elif compile_module $cur_name "bdev_release(NULL);" "linux/blkdev.h"
then
echo $cur_name 3 >> $config_file_path
else
echo $cur_name X >> $config_file_path
fi
Expand All @@ -25,11 +28,14 @@ check() {
apply() {
case "$1" in
"1")
add_define "cas_blkdev_put(bdev, mode, holder) \\
blkdev_put(bdev, mode)" ;;
add_define "cas_bdev_release(handle, mode, holder) \\
blkdev_put((struct block_device *)handle, mode)" ;;
"2")
add_define "cas_blkdev_put(bdev, mode, holder) \\
blkdev_put(bdev, holder)" ;;
add_define "cas_bdev_release(handle, mode, holder) \\
blkdev_put((struct block_device *)handle, holder)" ;;
"3")
add_define "cas_bdev_release(handle, mode, holder) \\
bdev_release(handle)" ;;
*)
exit 1
esac
Expand Down
35 changes: 35 additions & 0 deletions configure.d/1_class_create.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/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 "class_create(NULL, NULL);" "linux/device.h"
then
echo $cur_name "1" >> $config_file_path
elif compile_module $cur_name "class_create(NULL);" "linux/device.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_class_create(owner, name) \\
class_create(owner, name)";;
"2")
add_define "cas_class_create(owner, name) \\
class_create(name)";;
esac
}

conf_run $@
5 changes: 3 additions & 2 deletions configure.d/2_bio_cmpl.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
#
# Copyright(c) 2012-2022 Intel Corporation
# Copyright(c) 2024 Huawei Technologies
# SPDX-License-Identifier: BSD-3-Clause
#

Expand Down Expand Up @@ -33,14 +34,14 @@ apply() {
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)"
static void name##_callback(BIO, ERROR)"
add_define "CAS_BLOCK_CALLBACK_ERROR(BIO, ERROR) \\
ERROR" ;;
"2")
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)"
static void name##_callback(BIO)"
add_define "CAS_BLOCK_CALLBACK_ERROR(BIO, ERROR) \\
CAS_BIO_OP_STATUS(BIO)" ;;
esac
Expand Down
5 changes: 5 additions & 0 deletions configure.d/conf_framework.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash
#
# Copyright(c) 2012-2022 Intel Corporation
# Copyright(c) 2024 Huawei Technologies
# SPDX-License-Identifier: BSD-3-Clause
#

Expand All @@ -20,6 +21,10 @@ add_function() {
printf "%s\n" $1 >> $DEFINE_FILE
}

add_typedef() {
printf "typedef %s\n" $1 >> $DEFINE_FILE
}

__compile_module(){
INCLUDE=""
if [ $# -gt 1 ]
Expand Down
3 changes: 2 additions & 1 deletion modules/cas_cache/control.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <linux/cdev.h>
Expand Down Expand Up @@ -42,7 +43,7 @@ int __init cas_ctrl_device_init(void)
goto error_cdev_add;
}

ctrl->class = class_create(THIS_MODULE, "cas");
ctrl->class = cas_class_create(THIS_MODULE, "cas");
if (IS_ERR(ctrl->class)) {
printk(KERN_ERR "Cannot create control chrdev class.\n");
result = PTR_ERR(ctrl->class);
Expand Down
33 changes: 15 additions & 18 deletions modules/cas_cache/disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,15 @@

#define CAS_DISK_OPEN_MODE (CAS_MODE_READ | CAS_MODE_WRITE)

static inline struct block_device *open_bdev_exclusive(const char *path,
static inline cas_bdev_handle_t open_bdev_exclusive(const char *path,
CAS_MODE mode, void *holder)
{
return cas_blkdev_get_by_path(path, mode | CAS_MODE_EXCL,
holder);
return cas_bdev_open_by_path(path, mode | CAS_MODE_EXCL, holder);
}

static inline void close_bdev_exclusive(struct block_device *bdev,
CAS_MODE mode)
static inline void close_bdev_exclusive(cas_bdev_handle_t handle, CAS_MODE mode)
{
cas_blkdev_put(bdev, mode | CAS_MODE_EXCL, NULL);
cas_bdev_release(handle, mode | CAS_MODE_EXCL, NULL);
}

int __init cas_init_disks(void)
Expand Down Expand Up @@ -69,10 +67,10 @@ struct cas_disk *cas_disk_open(const char *path)
goto error_kstrdup;
}

dsk->bd = open_bdev_exclusive(path, CAS_DISK_OPEN_MODE, dsk);
if (IS_ERR(dsk->bd)) {
dsk->bdev_handle = open_bdev_exclusive(path, CAS_DISK_OPEN_MODE, dsk);
if (IS_ERR(dsk->bdev_handle)) {
CAS_DEBUG_ERROR("Cannot open exclusive");
result = PTR_ERR(dsk->bd);
result = PTR_ERR(dsk->bdev_handle);
goto error_open_bdev;
}

Expand All @@ -91,11 +89,11 @@ struct cas_disk *cas_disk_open(const char *path)
void cas_disk_close(struct cas_disk *dsk)
{
BUG_ON(!dsk);
BUG_ON(!dsk->bd);
BUG_ON(!dsk->bdev_handle);

CAS_DEBUG_DISK(dsk, "Destroying (%p)", dsk);

close_bdev_exclusive(dsk->bd, CAS_DISK_OPEN_MODE);
close_bdev_exclusive(dsk->bdev_handle, CAS_DISK_OPEN_MODE);

kfree(dsk->path);
kmem_cache_free(cas_module.disk_cache, dsk);
Expand All @@ -104,19 +102,18 @@ void cas_disk_close(struct cas_disk *dsk)
struct block_device *cas_disk_get_blkdev(struct cas_disk *dsk)
{
BUG_ON(!dsk);
return dsk->bd;
BUG_ON(!dsk->bdev_handle);
return cas_bdev_get_from_handle(dsk->bdev_handle);
}

struct gendisk *cas_disk_get_gendisk(struct cas_disk *dsk)
{
BUG_ON(!dsk);
BUG_ON(!dsk->bd);
return dsk->bd->bd_disk;
return cas_disk_get_blkdev(dsk)->bd_disk;
}

struct request_queue *cas_disk_get_queue(struct cas_disk *dsk)
{
BUG_ON(!dsk);
BUG_ON(!dsk->bd);
return cas_bdev_whole(dsk->bd)->bd_disk->queue;
struct block_device *bd = cas_disk_get_blkdev(dsk);

return cas_bdev_whole(bd)->bd_disk->queue;
}
3 changes: 2 additions & 1 deletion modules/cas_cache/disk.h
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
*/
#ifndef __CASDISK_DISK_H__
Expand All @@ -16,7 +17,7 @@ struct cas_exp_obj;
struct cas_disk {
char *path;

struct block_device *bd;
cas_bdev_handle_t bdev_handle;

struct cas_exp_obj *exp_obj;
};
Expand Down
6 changes: 3 additions & 3 deletions modules/cas_cache/exp_obj.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ static int _cas_exp_obj_hide_parts(struct cas_disk *dsk)
/* It is partition, no more job required */
return 0;

if (GET_DISK_MAX_PARTS(dsk->bd->bd_disk) > 1) {
if (GET_DISK_MAX_PARTS(cas_disk_get_gendisk(dsk)) > 1) {
if (_cas_del_partitions(dsk)) {
printk(KERN_ERR "Error deleting a partition on thedevice %s\n",
gdsk->disk_name);
Expand Down Expand Up @@ -490,7 +490,7 @@ int cas_exp_obj_create(struct cas_disk *dsk, const char *dev_name,
if (cas_add_disk(gd))
goto error_add_disk;

result = bd_claim_by_disk(dsk->bd, dsk, gd);
result = bd_claim_by_disk(cas_disk_get_blkdev(dsk), dsk, gd);
if (result)
goto error_bd_claim;

Expand Down Expand Up @@ -531,7 +531,7 @@ int cas_exp_obj_destroy(struct cas_disk *dsk)

exp_obj = dsk->exp_obj;

bd_release_from_disk(dsk->bd, exp_obj->gd);
bd_release_from_disk(cas_disk_get_blkdev(dsk), exp_obj->gd);
_cas_exp_obj_clear_dev_t(dsk);
del_gendisk(exp_obj->gd);

Expand Down
Loading

0 comments on commit 11f3d4e

Please sign in to comment.