Open CAS Linux kernel 5.18 support

This patch introduces the support for 5.18 kernel.

Signed-off-by: Krzysztof Majzerowicz-Jaszcz <krzysztof.majzerowicz-jaszcz@intel.com>
This commit is contained in:
Krzysztof Majzerowicz-Jaszcz
2022-10-05 15:53:53 +00:00
parent 65bc955d4f
commit f0af7cb52d
25 changed files with 340 additions and 201 deletions

View File

@@ -7,7 +7,6 @@
#include <linux/slab.h>
#include <linux/string.h>
#include <linux/blkpg.h>
#include <linux/elevator.h>
#include <linux/blk-mq.h>
#include "disk.h"
@@ -31,7 +30,10 @@ static inline void bd_release_from_disk(struct block_device *bdev,
return bd_unlink_disk_holder(bdev, disk);
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 18, 0)
#define KRETURN(x) return
#define MAKE_RQ_RET_TYPE void
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 3, 0)
#define KRETURN(x) ({ return (x); })
#define MAKE_RQ_RET_TYPE blk_qc_t
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3, 2, 0)
@@ -161,12 +163,6 @@ out_map_bpart:
return result;
}
#ifdef GENHD_FL_NO_PART_SCAN
static int _cas_flags = GENHD_FL_NO_PART_SCAN | GENHD_FL_EXT_DEVT;
#else
static int _cas_flags = GENHD_FL_EXT_DEVT;
#endif
static int _cas_exp_obj_hide_parts(struct cas_disk *dsk)
{
struct cas_exp_obj *exp_obj = dsk->exp_obj;
@@ -177,7 +173,7 @@ static int _cas_exp_obj_hide_parts(struct cas_disk *dsk)
/* It is partition, no more job required */
return 0;
if (disk_max_parts(dsk->bd->bd_disk) > 1) {
if (GET_DISK_MAX_PARTS(dsk->bd->bd_disk) > 1) {
if (_cas_del_partitions(dsk)) {
printk(KERN_ERR "Error deleting a partition on thedevice %s\n",
gdsk->disk_name);
@@ -189,11 +185,11 @@ static int _cas_exp_obj_hide_parts(struct cas_disk *dsk)
}
/* Save original flags and minors */
exp_obj->gd_flags = gdsk->flags & _cas_flags;
exp_obj->gd_flags = gdsk->flags & _CAS_GENHD_FLAGS;
exp_obj->gd_minors = gdsk->minors;
/* Setup disk of bottom device as not partitioned device */
gdsk->flags &= ~_cas_flags;
gdsk->flags &= ~_CAS_GENHD_FLAGS;
gdsk->minors = 1;
/* Rescan partitions */
cas_reread_partitions(bd);
@@ -217,7 +213,7 @@ static int _cas_exp_obj_set_dev_t(struct cas_disk *dsk, struct gendisk *gd)
{
struct cas_exp_obj *exp_obj = dsk->exp_obj;
int flags;
int minors = disk_max_parts(cas_disk_get_gendisk(dsk));
int minors = GET_DISK_MAX_PARTS(cas_disk_get_gendisk(dsk));
struct block_device *bdev;
bdev = cas_disk_get_blkdev(dsk);
@@ -346,7 +342,7 @@ static void _cas_init_queues(struct cas_disk *dsk)
{
struct request_queue *q = dsk->exp_obj->queue;
struct blk_mq_hw_ctx *hctx;
int i;
unsigned long i;
queue_for_each_hw_ctx(q, hctx, i) {
if (!hctx->nr_ctx || !hctx->tags)
@@ -365,7 +361,7 @@ static int _cas_init_tag_set(struct cas_disk *dsk, struct blk_mq_tag_set *set)
set->nr_hw_queues = num_online_cpus();
set->numa_node = NUMA_NO_NODE;
/*TODO: Should we inherit qd from core device? */
set->queue_depth = BLKDEV_MAX_RQ;
set->queue_depth = CAS_BLKDEV_DEFAULT_RQ;
set->cmd_size = 0;
set->flags = BLK_MQ_F_SHOULD_MERGE | CAS_BLK_MQ_F_STACKING | CAS_BLK_MQ_F_BLOCKING;
@@ -490,7 +486,8 @@ int cas_exp_obj_create(struct cas_disk *dsk, const char *dev_name,
goto error_set_geometry;
}
add_disk(gd);
if (cas_add_disk(gd))
goto error_add_disk;
result = bd_claim_by_disk(dsk->bd, dsk, gd);
if (result)
@@ -500,6 +497,7 @@ int cas_exp_obj_create(struct cas_disk *dsk, const char *dev_name,
error_bd_claim:
del_gendisk(dsk->exp_obj->gd);
error_add_disk:
error_set_geometry:
exp_obj->private = NULL;
_cas_exp_obj_clear_dev_t(dsk);

View File

@@ -601,12 +601,11 @@ static int exit_instance_finish(void *data)
if (result == -KCAS_ERR_WAITING_INTERRUPTED)
kfree(ctx);
module_put_and_exit(0);
CAS_MODULE_PUT_AND_EXIT(0);
}
struct _cache_mngt_attach_context {
struct _cache_mngt_async_context async;
char cache_elevator[MAX_ELEVATOR_NAME];
uint64_t min_free_ram;
struct ocf_mngt_cache_device_config device_cfg;
char cache_path[MAX_STR_LEN];
@@ -649,7 +648,7 @@ static int cache_start_rollback(void *data)
if (result == -KCAS_ERR_WAITING_INTERRUPTED)
kfree(ctx);
module_put_and_exit(0);
CAS_MODULE_PUT_AND_EXIT(0);
return 0;
}
@@ -2021,7 +2020,7 @@ static void init_instance_complete(struct _cache_mngt_attach_context *ctx,
ocf_volume_t cache_obj;
struct bd_object *bd_cache_obj;
struct block_device *bdev;
const char *name;
//const char *name;
cache_obj = ocf_cache_get_volume(cache);
BUG_ON(!cache_obj);
@@ -2033,11 +2032,6 @@ static void init_instance_complete(struct _cache_mngt_attach_context *ctx,
if (cas_bdev_whole(bdev) == bdev)
cas_reread_partitions(bdev);
/* Set other back information */
name = block_dev_get_elevator_name(
cas_disk_get_queue(bd_cache_obj->dsk));
if (name)
strlcpy(ctx->cache_elevator, name, MAX_ELEVATOR_NAME);
}
static void _cache_mngt_start_complete(ocf_cache_t cache, void *priv, int error)
@@ -2572,9 +2566,6 @@ int cache_mngt_init_instance(struct ocf_mngt_cache_config *cfg,
if (result)
goto err;
strlcpy(cmd->cache_elevator, context->cache_elevator,
MAX_ELEVATOR_NAME);
result = _cache_start_finalize(cache, cmd->init_cache, false);
if (result)
goto err;

View File

@@ -20,7 +20,6 @@
#include <linux/bio.h>
#include <linux/fs.h>
#include <linux/stat.h>
#include <linux/genhd.h>
#include <linux/blkdev.h>
#include <linux/version.h>
#include <linux/workqueue.h>

View File

@@ -1,5 +1,5 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -51,7 +51,7 @@ static int _cas_io_queue_thread(void *data)
/* If we get here, then thread was signalled to terminate.
* So, let's complete and exit.
*/
complete_and_exit(&info->compl, 0);
CAS_COMPLETE_AND_EXIT(&info->compl, 0);
return 0;
}
@@ -110,7 +110,7 @@ static int _cas_cleaner_thread(void *data)
}
} while (true);
complete_and_exit(&info->compl, 0);
CAS_COMPLETE_AND_EXIT(&info->compl, 0);
return 0;
}

View File

@@ -4,7 +4,6 @@
*/
#include <linux/blkdev.h>
#include "cas_cache.h"
#define CAS_DEBUG_IO 0
@@ -82,57 +81,14 @@ uint64_t block_dev_get_byte_length(ocf_volume_t vol)
return sector_length << SECTOR_SHIFT;
}
#if LINUX_VERSION_CODE <= KERNEL_VERSION(3, 3, 0)
static const char *__block_dev_get_elevator_name(struct request_queue *q)
{
if (q->elevator->elevator_type == NULL)
return NULL;
if (q->elevator->elevator_type->elevator_name == NULL)
return NULL;
if (q->elevator->elevator_type->elevator_name[0] == 0)
return NULL;
return q->elevator->elevator_type->elevator_name;
}
#else
static const char *__block_dev_get_elevator_name(struct request_queue *q)
{
if (q->elevator->type == NULL)
return NULL;
if (q->elevator->type->elevator_name == NULL)
return NULL;
if (q->elevator->type->elevator_name[0] == 0)
return NULL;
return q->elevator->type->elevator_name;
}
#endif
/*
*
*/
const char *block_dev_get_elevator_name(struct request_queue *q)
{
if (!q)
return NULL;
if (q->elevator == NULL)
return NULL;
return __block_dev_get_elevator_name(q);
}
/*
*
*/
static inline struct bio *cas_bd_io_alloc_bio(struct blkio *bdio)
static inline struct bio *cas_bd_io_alloc_bio(struct block_device *bdev,
struct blkio *bdio)
{
struct bio *bio
= bio_alloc(GFP_NOIO, cas_io_iter_size_left(&bdio->iter));
= cas_bio_alloc(bdev, GFP_NOIO, cas_io_iter_size_left(&bdio->iter));
if (bio)
return bio;
@@ -145,7 +101,7 @@ static inline struct bio *cas_bd_io_alloc_bio(struct blkio *bdio)
}
/* Retry with smaller */
return bio_alloc(GFP_NOIO, MAX_LINES_PER_IO);
return cas_bio_alloc(bdev, GFP_NOIO, MAX_LINES_PER_IO);
}
/*
@@ -221,7 +177,7 @@ static void block_dev_submit_flush(struct ocf_io *io)
goto out;
}
bio = bio_alloc(GFP_NOIO, 0);
bio = cas_bio_alloc(bdev, GFP_NOIO, 0);
if (bio == NULL) {
CAS_PRINT_RL(KERN_ERR "Couldn't allocate memory for BIO\n");
blkio->error = -ENOMEM;
@@ -281,7 +237,7 @@ void block_dev_submit_discard(struct ocf_io *io)
start = io->addr >> SECTOR_SHIFT;
while (sects) {
bio = bio_alloc(GFP_NOIO, 1);
bio = cas_bio_alloc(bd, GFP_NOIO, 1);
if (!bio) {
CAS_PRINT_RL(CAS_KERN_ERR "Couldn't allocate memory for BIO\n");
blkio->error = -ENOMEM;
@@ -390,7 +346,7 @@ static void block_dev_submit_io(struct ocf_io *io)
/* Still IO vectors to be sent */
/* Allocate BIO */
struct bio *bio = cas_bd_io_alloc_bio(bdio);
struct bio *bio = cas_bd_io_alloc_bio(bdobj->btm_bd, bdio);
if (!bio) {
bdio->error = -ENOMEM;

View File

@@ -1,5 +1,5 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -12,8 +12,6 @@ int block_dev_open_object(ocf_volume_t vol, void *volume_params);
void block_dev_close_object(ocf_volume_t vol);
const char *block_dev_get_elevator_name(struct request_queue *q);
int block_dev_try_get_io_class(struct bio *bio, int *io_class);
int block_dev_init(void);