Merge pull request #1345 from robertbaldyga/consolidate-cas-modules

Consolidate Open CAS modules
This commit is contained in:
Robert Baldyga 2022-09-19 14:55:30 +02:00 committed by GitHub
commit 70cc908b39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 664 additions and 878 deletions

View File

@ -2508,34 +2508,6 @@ int cas_module_version(char *buff, int size)
} }
} }
int disk_module_version(char *buff, int size)
{
FILE *fd;
int n_read;
if (size <= 0 || size > MAX_STR_LEN) {
return FAILURE;
}
fd = fopen("/sys/module/cas_disk/version", "r");
if (!fd) {
return FAILURE;
}
n_read = fread(buff, 1, size, fd);
if (ferror(fd)) {
n_read = 0;
}
fclose(fd);
if (n_read > 0) {
buff[n_read - 1] = '\0';
return SUCCESS;
} else {
return FAILURE;
}
}
float calculate_flush_progress(unsigned dirty, unsigned flushed) float calculate_flush_progress(unsigned dirty, unsigned flushed)
{ {
unsigned total_dirty; unsigned total_dirty;

View File

@ -1,5 +1,5 @@
/* /*
* Copyright(c) 2012-2021 Intel Corporation * Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
@ -279,7 +279,6 @@ int partition_setup(unsigned int cache_id, const char *file);
int partition_is_name_valid(const char *name); int partition_is_name_valid(const char *name);
int cas_module_version(char *buff, int size); int cas_module_version(char *buff, int size);
int disk_module_version(char *buff, int size);
int list_caches(unsigned int list_format, bool by_id_path); int list_caches(unsigned int list_format, bool by_id_path);
int cache_status(unsigned int cache_id, unsigned int core_id, int io_class_id, int cache_status(unsigned int cache_id, unsigned int core_id, int io_class_id,
unsigned int stats_filters, unsigned int stats_format, bool by_id_path); unsigned int stats_filters, unsigned int stats_format, bool by_id_path);

View File

@ -1849,13 +1849,6 @@ static int handle_version(void)
fprintf(intermediate_file[1], "%s\n", buff); fprintf(intermediate_file[1], "%s\n", buff);
} }
fprintf(intermediate_file[1], TAG(TABLE_ROW) OCF_LOGO " Disk Kernel Module,");
if (disk_module_version(buff, MAX_STR_LEN)) {
fprintf(intermediate_file[1], "Not Loaded\n");
} else {
fprintf(intermediate_file[1], "%s\n", buff);
}
fprintf(intermediate_file[1], TAG(TABLE_ROW) OCF_LOGO " CLI Utility,"); fprintf(intermediate_file[1], TAG(TABLE_ROW) OCF_LOGO " CLI Utility,");
fprintf(intermediate_file[1], "%s\n", CAS_VERSION); fprintf(intermediate_file[1], "%s\n", CAS_VERSION);

View File

@ -34,7 +34,7 @@ apply() {
return 0; return 0;
}" }"
add_function " add_function "
static inline void cas_cleanup_mq_disk(struct casdsk_exp_obj *exp_obj) static inline void cas_cleanup_mq_disk(struct cas_exp_obj *exp_obj)
{ {
blk_cleanup_disk(exp_obj->gd); blk_cleanup_disk(exp_obj->gd);
}" }"
@ -61,7 +61,7 @@ apply() {
}" }"
add_function " add_function "
static inline void cas_cleanup_mq_disk(struct casdsk_exp_obj *exp_obj){ static inline void cas_cleanup_mq_disk(struct cas_exp_obj *exp_obj){
blk_cleanup_queue(exp_obj->queue); blk_cleanup_queue(exp_obj->queue);
put_disk(exp_obj->gd); put_disk(exp_obj->gd);
}" }"

View File

@ -9,7 +9,6 @@ ifneq ($(M),)
include $(M)/config.mk include $(M)/config.mk
obj-y += cas_cache/ obj-y += cas_cache/
obj-y += cas_disk/
# Otherwise we were called directly from the command # Otherwise we were called directly from the command
# line; invoke the kernel build system. # line; invoke the kernel build system.
@ -28,7 +27,6 @@ KERNEL_VERSION ?= "$(shell uname -r)"
KERNEL_DIR ?= "/lib/modules/$(KERNEL_VERSION)/build" KERNEL_DIR ?= "/lib/modules/$(KERNEL_VERSION)/build"
MODULES_DIR=/lib/modules/$(KERNEL_VERSION)/extra/block/opencas MODULES_DIR=/lib/modules/$(KERNEL_VERSION)/extra/block/opencas
DISK_MODULE = cas_disk
CACHE_MODULE = cas_cache CACHE_MODULE = cas_cache
DEPMOD:=$(shell which depmod) DEPMOD:=$(shell which depmod)
@ -58,16 +56,13 @@ install: install_files
install_files: install_files:
@echo "Installing Open-CAS modules" @echo "Installing Open-CAS modules"
@install -m 644 -D cas_disk/$(DISK_MODULE).ko $(DESTDIR)$(MODULES_DIR)/$(DISK_MODULE).ko
@install -m 644 -D cas_cache/$(CACHE_MODULE).ko $(DESTDIR)$(MODULES_DIR)/$(CACHE_MODULE).ko @install -m 644 -D cas_cache/$(CACHE_MODULE).ko $(DESTDIR)$(MODULES_DIR)/$(CACHE_MODULE).ko
uninstall: uninstall:
@echo "Uninstalling Open-CAS modules" @echo "Uninstalling Open-CAS modules"
$(call remove-module,$(CACHE_MODULE)) $(call remove-module,$(CACHE_MODULE))
$(call remove-module,$(DISK_MODULE))
$(call remove-file,$(DESTDIR)$(MODULES_DIR)/$(CACHE_MODULE).ko) $(call remove-file,$(DESTDIR)$(MODULES_DIR)/$(CACHE_MODULE).ko)
$(call remove-file,$(DESTDIR)$(MODULES_DIR)/$(DISK_MODULE).ko)
$(call remove-directory,$(DESTDIR)$(MODULES_DIR)) $(call remove-directory,$(DESTDIR)$(MODULES_DIR))
@$(DEPMOD) @$(DEPMOD)

View File

@ -19,7 +19,8 @@
#include "classifier.h" #include "classifier.h"
#include "context.h" #include "context.h"
#include <linux/kallsyms.h> #include <linux/kallsyms.h>
#include "../cas_disk/cas_disk.h" #include "disk.h"
#include "exp_obj.h"
#define CAS_KERN_EMERG KERN_EMERG OCF_PREFIX_SHORT #define CAS_KERN_EMERG KERN_EMERG OCF_PREFIX_SHORT
#define CAS_KERN_ALERT KERN_ALERT OCF_PREFIX_SHORT #define CAS_KERN_ALERT KERN_ALERT OCF_PREFIX_SHORT
@ -49,6 +50,20 @@ enum {
/** \endcond */ /** \endcond */
}; };
struct cas_module {
struct list_head disk_list;
uint32_t next_disk_id;
int disk_major;
int next_minor;
struct kmem_cache *disk_cache;
struct kmem_cache *exp_obj_cache;
struct kobject kobj;
};
extern struct cas_module cas_module;
struct cas_classifier; struct cas_classifier;
struct cache_priv { struct cache_priv {

45
modules/cas_cache/debug.h Normal file
View File

@ -0,0 +1,45 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __CASDISK_DEBUG_H__
#define __CASDISK_DEBUG_H__
#undef CAS_DEBUG
#ifdef CAS_DEBUG
#define CAS_DEBUG_TRACE() \
printk(KERN_INFO "%s\n", __func__)
#define CAS_DEBUG_DISK_TRACE(dsk) \
printk(KERN_INFO "[%u] %s\n", dsk->id, __func__)
#define CAS_DEBUG_MSG(msg) \
printk(KERN_INFO "%s - %s\n", __func__, msg)
#define CAS_DEBUG_PARAM(format, ...) \
printk(KERN_INFO "%s - "format"\n", \
__func__, ##__VA_ARGS__)
#define CAS_DEBUG_DISK(dsk, format, ...) \
printk(KERN_INFO "[%u] %s - "format"\n", \
dsk->id, \
__func__, ##__VA_ARGS__)
#define CAS_DEBUG_ERROR(error, ...) \
CAS_DEBUG_PARAM("ERROR(%d) "error, __LINE__, ##__VA_ARGS__)
#define CAS_DEBUG_DISK_ERROR(dsk, error, ...) \
CAS_DEBUG_DISK(dsk, "ERROR(%d) "error, __LINE__, ##__VA_ARGS__)
#else
#define CAS_DEBUG_TRACE()
#define CAS_DEBUG_DISK_TRACE(dsk)
#define CAS_DEBUG_MSG(msg)
#define CAS_DEBUG_PARAM(format, ...)
#define CAS_DEBUG_DISK(dsk, format, ...)
#define CAS_DEBUG_ERROR(error, ...)
#define CAS_DEBUG_DISK_ERROR(dsk, error, ...)
#endif
#endif

227
modules/cas_cache/disk.c Normal file
View File

@ -0,0 +1,227 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/delay.h>
#include "cas_cache.h"
#include "disk.h"
#include "exp_obj.h"
#include "debug.h"
#define CAS_DISK_OPEN_FMODE (FMODE_READ | FMODE_WRITE)
static inline struct cas_disk *cas_kobj_to_disk(struct kobject *kobj)
{
return container_of(kobj, struct cas_disk, kobj);
}
static inline struct block_device *open_bdev_exclusive(const char *path,
fmode_t mode,
void *holder)
{
return blkdev_get_by_path(path, mode | FMODE_EXCL, holder);
}
static inline void close_bdev_exclusive(struct block_device *bdev, fmode_t mode)
{
blkdev_put(bdev, mode | FMODE_EXCL);
}
static void _cas_disk_release(struct kobject *kobj)
{
struct cas_disk *dsk;
BUG_ON(!kobj);
dsk = cas_kobj_to_disk(kobj);
BUG_ON(!dsk);
CAS_DEBUG_DISK_TRACE(dsk);
kfree(dsk->path);
kmem_cache_free(cas_module.disk_cache, dsk);
}
static struct kobj_type cas_disk_ktype = {
.release = _cas_disk_release,
};
int __init cas_init_disks(void)
{
CAS_DEBUG_TRACE();
cas_module.next_disk_id = 1;
INIT_LIST_HEAD(&cas_module.disk_list);
cas_module.disk_major = register_blkdev(cas_module.disk_major,
"cas");
if (cas_module.disk_major <= 0) {
CAS_DEBUG_ERROR("Cannot allocate major number");
return -EINVAL;
}
CAS_DEBUG_PARAM("Allocated major number: %d", cas_module.disk_major);
cas_module.disk_cache =
kmem_cache_create("cas_disk", sizeof(struct cas_disk),
0, 0, NULL);
if (!cas_module.disk_cache) {
unregister_blkdev(cas_module.disk_major, "cas");
return -ENOMEM;
}
return 0;
}
void cas_deinit_disks(void)
{
CAS_DEBUG_TRACE();
kmem_cache_destroy(cas_module.disk_cache);
unregister_blkdev(cas_module.disk_major, "cas");
}
static int _cas_disk_init_kobject(struct cas_disk *dsk)
{
int result = 0;
kobject_init(&dsk->kobj, &cas_disk_ktype);
result = kobject_add(&dsk->kobj, &disk_to_dev(dsk->bd->bd_disk)->kobj,
"cas%d", dsk->id);
if (result)
CAS_DEBUG_DISK_ERROR(dsk, "Cannot register kobject");
return result;
}
struct cas_disk *cas_disk_open(const char *path, void *private)
{
struct cas_disk *dsk;
int result = 0;
BUG_ON(!path);
CAS_DEBUG_TRACE();
dsk = kmem_cache_zalloc(cas_module.disk_cache, GFP_KERNEL);
if (!dsk) {
CAS_DEBUG_ERROR("Cannot allocate memory");
result = -ENOMEM;
goto error_kmem;
}
mutex_init(&dsk->openers_lock);
dsk->path = kstrdup(path, GFP_KERNEL);
if (!dsk->path) {
result = -ENOMEM;
goto error_kstrdup;
}
dsk->bd = open_bdev_exclusive(path, CAS_DISK_OPEN_FMODE, dsk);
if (IS_ERR(dsk->bd)) {
CAS_DEBUG_ERROR("Cannot open exclusive");
result = PTR_ERR(dsk->bd);
goto error_open_bdev;
}
dsk->private = private;
dsk->id = cas_module.next_disk_id++;
list_add(&dsk->list, &cas_module.disk_list);
result = _cas_disk_init_kobject(dsk);
if (result)
goto error_kobject;
CAS_DEBUG_DISK(dsk, "Created (%p)", dsk);
return dsk;
error_kobject:
list_del(&dsk->list);
close_bdev_exclusive(dsk->bd, CAS_DISK_OPEN_FMODE);
error_open_bdev:
kfree(dsk->path);
error_kstrdup:
kmem_cache_free(cas_module.disk_cache, dsk);
error_kmem:
return ERR_PTR(result);
}
static void _cas_disk_claim(struct cas_disk *dsk, void *private)
{
dsk->private = private;
}
struct cas_disk *cas_disk_claim(const char *path, void *private)
{
struct list_head *item;
struct cas_disk *dsk = NULL;
BUG_ON(!path);
list_for_each(item, &cas_module.disk_list) {
dsk = list_entry(item, struct cas_disk, list);
if (strncmp(path, dsk->path, PATH_MAX) == 0) {
_cas_disk_claim(dsk, private);
return dsk;
}
}
return NULL;
}
static void __cas_disk_close(struct cas_disk *dsk)
{
close_bdev_exclusive(dsk->bd, CAS_DISK_OPEN_FMODE);
cas_exp_obj_free(dsk);
kobject_put(&dsk->kobj);
}
void cas_disk_close(struct cas_disk *dsk)
{
BUG_ON(!dsk);
BUG_ON(!dsk->bd);
CAS_DEBUG_DISK(dsk, "Destroying (%p)", dsk);
list_del(&dsk->list);
__cas_disk_close(dsk);
}
struct block_device *cas_disk_get_blkdev(struct cas_disk *dsk)
{
BUG_ON(!dsk);
return dsk->bd;
}
struct gendisk *cas_disk_get_gendisk(struct cas_disk *dsk)
{
BUG_ON(!dsk);
BUG_ON(!dsk->bd);
return dsk->bd->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;
}
int cas_disk_allocate_minors(int count)
{
int minor = -1;
if (cas_module.next_minor + count <= (1 << MINORBITS)) {
minor = cas_module.next_minor;
cas_module.next_minor += count;
}
return minor;
}

89
modules/cas_cache/disk.h Normal file
View File

@ -0,0 +1,89 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __CASDISK_DISK_H__
#define __CASDISK_DISK_H__
#include <linux/kobject.h>
#include <linux/fs.h>
#include <linux/blkdev.h>
#include <linux/mutex.h>
#include <linux/blk-mq.h>
#include "cas_cache.h"
struct cas_exp_obj;
struct cas_disk {
uint32_t id;
char *path;
struct mutex openers_lock;
unsigned int openers;
bool claimed;
struct block_device *bd;
int gd_flags;
int gd_minors;
struct blk_mq_tag_set tag_set;
struct cas_exp_obj *exp_obj;
struct kobject kobj;
struct list_head list;
void *private;
};
int __init cas_init_disks(void);
void cas_deinit_disks(void);
int cas_disk_allocate_minors(int count);
/**
* @brief Open block device
* @param path Path to block device
* @param private Private data
* @return Pointer to cas_disk related to opened block device
*/
struct cas_disk *cas_disk_open(const char *path, void *private);
/**
* @brief Claim previously opened block device
* @param path Path to block device
* @param private Private data
* @return Pointer to cas_disk structure related to block device, or NULL
* if device is not opened.
*/
struct cas_disk *cas_disk_claim(const char *path, void *private);
/**
* @brief Close block device and remove from cas
* @param dsk Pointer to cas_disk structure related to block device
* which should be closed.
*/
void cas_disk_close(struct cas_disk *dsk);
/**
* @brief Get block_device structure of bottom block device
* @param dsk Pointer to cas_disk structure representing a block device
* @return Pointer to block_device structure of bottom block device
*/
struct block_device *cas_disk_get_blkdev(struct cas_disk *dsk);
/**
* @brief Get request queue of bottom block device
* @param dsk Pointer to cas_disk structure representing a block device
* @return Pointer to reqest_queue structure of bottom block device
*/
struct request_queue *cas_disk_get_queue(struct cas_disk *dsk);
/**
* @brief Get gendisk structure of bottom block device
* @param dsk Pointer to cas_disk structure representing a block device
* @return Pointer to gendisk structure of bottom block device
*/
struct gendisk *cas_disk_get_gendisk(struct cas_disk *dsk);
#endif

View File

@ -10,15 +10,20 @@
#include <linux/elevator.h> #include <linux/elevator.h>
#include <linux/blk-mq.h> #include <linux/blk-mq.h>
#include "cas_disk_defs.h"
#include "cas_disk.h"
#include "disk.h" #include "disk.h"
#include "exp_obj.h" #include "exp_obj.h"
#include "linux_kernel_version.h" #include "linux_kernel_version.h"
#include "cas_cache.h"
#include "debug.h"
#define CASDSK_DEV_MINORS 16 #define CAS_DEV_MINORS 16
#define KMEM_CACHE_MIN_SIZE sizeof(void *) #define KMEM_CACHE_MIN_SIZE sizeof(void *)
static inline struct cas_exp_obj *cas_kobj_to_exp_obj(struct kobject *kobj)
{
return container_of(kobj, struct cas_exp_obj, kobj);
}
static inline int bd_claim_by_disk(struct block_device *bdev, void *holder, static inline int bd_claim_by_disk(struct block_device *bdev, void *holder,
struct gendisk *disk) struct gendisk *disk)
{ {
@ -42,54 +47,54 @@ static inline void bd_release_from_disk(struct block_device *bdev,
#define MAKE_RQ_RET_TYPE int #define MAKE_RQ_RET_TYPE int
#endif #endif
int __init casdsk_init_exp_objs(void) int __init cas_init_exp_objs(void)
{ {
CASDSK_DEBUG_TRACE(); CAS_DEBUG_TRACE();
casdsk_module->exp_obj_cache = kmem_cache_create("casdsk_exp_obj", cas_module.exp_obj_cache = kmem_cache_create("cas_exp_obj",
sizeof(struct casdsk_exp_obj), 0, 0, NULL); sizeof(struct cas_exp_obj), 0, 0, NULL);
if (!casdsk_module->exp_obj_cache) if (!cas_module.exp_obj_cache)
return -ENOMEM; return -ENOMEM;
return 0; return 0;
} }
void casdsk_deinit_exp_objs(void) void cas_deinit_exp_objs(void)
{ {
CASDSK_DEBUG_TRACE(); CAS_DEBUG_TRACE();
kmem_cache_destroy(casdsk_module->exp_obj_cache); kmem_cache_destroy(cas_module.exp_obj_cache);
} }
static inline void _casdsk_exp_obj_handle_bio(struct casdsk_disk *dsk, static inline void _cas_exp_obj_handle_bio(struct cas_disk *dsk,
struct bio *bio) struct bio *bio)
{ {
dsk->exp_obj->ops->submit_bio(dsk, bio, dsk->private); dsk->exp_obj->ops->submit_bio(dsk, bio, dsk->private);
} }
static MAKE_RQ_RET_TYPE _casdsk_exp_obj_submit_bio(struct bio *bio) static MAKE_RQ_RET_TYPE _cas_exp_obj_submit_bio(struct bio *bio)
{ {
struct casdsk_disk *dsk; struct cas_disk *dsk;
BUG_ON(!bio); BUG_ON(!bio);
dsk = CAS_BIO_GET_GENDISK(bio)->private_data; dsk = CAS_BIO_GET_GENDISK(bio)->private_data;
_casdsk_exp_obj_handle_bio(dsk, bio); _cas_exp_obj_handle_bio(dsk, bio);
KRETURN(0); KRETURN(0);
} }
static MAKE_RQ_RET_TYPE _casdsk_exp_obj_make_rq_fn(struct request_queue *q, static MAKE_RQ_RET_TYPE _cas_exp_obj_make_rq_fn(struct request_queue *q,
struct bio *bio) struct bio *bio)
{ {
_casdsk_exp_obj_submit_bio(bio); _cas_exp_obj_submit_bio(bio);
cas_blk_queue_exit(q); cas_blk_queue_exit(q);
KRETURN(0); KRETURN(0);
} }
static int _casdsk_del_partitions(struct casdsk_disk *dsk) static int _cas_del_partitions(struct cas_disk *dsk)
{ {
struct block_device *bd = casdsk_disk_get_blkdev(dsk); struct block_device *bd = cas_disk_get_blkdev(dsk);
struct file *bd_file; struct file *bd_file;
unsigned long __user usr_bpart; unsigned long __user usr_bpart;
unsigned long __user usr_barg; unsigned long __user usr_barg;
@ -155,22 +160,22 @@ out_map_bpart:
} }
#ifdef GENHD_FL_NO_PART_SCAN #ifdef GENHD_FL_NO_PART_SCAN
static int _casdsk_flags = GENHD_FL_NO_PART_SCAN | GENHD_FL_EXT_DEVT; static int _cas_flags = GENHD_FL_NO_PART_SCAN | GENHD_FL_EXT_DEVT;
#else #else
static int _casdsk_flags = GENHD_FL_EXT_DEVT; static int _cas_flags = GENHD_FL_EXT_DEVT;
#endif #endif
static int _casdsk_exp_obj_hide_parts(struct casdsk_disk *dsk) static int _cas_exp_obj_hide_parts(struct cas_disk *dsk)
{ {
struct block_device *bd = casdsk_disk_get_blkdev(dsk); struct block_device *bd = cas_disk_get_blkdev(dsk);
struct gendisk *gdsk = casdsk_disk_get_gendisk(dsk); struct gendisk *gdsk = cas_disk_get_gendisk(dsk);
if (bd != cas_bdev_whole(bd)) if (bd != cas_bdev_whole(bd))
/* It is partition, no more job required */ /* It is partition, no more job required */
return 0; return 0;
if (disk_max_parts(dsk->bd->bd_disk) > 1) { if (disk_max_parts(dsk->bd->bd_disk) > 1) {
if (_casdsk_del_partitions(dsk)) { if (_cas_del_partitions(dsk)) {
printk(KERN_ERR "Error deleting a partition on thedevice %s\n", printk(KERN_ERR "Error deleting a partition on thedevice %s\n",
gdsk->disk_name); gdsk->disk_name);
@ -181,11 +186,11 @@ static int _casdsk_exp_obj_hide_parts(struct casdsk_disk *dsk)
} }
/* Save original flags and minors */ /* Save original flags and minors */
dsk->gd_flags = gdsk->flags & _casdsk_flags; dsk->gd_flags = gdsk->flags & _cas_flags;
dsk->gd_minors = gdsk->minors; dsk->gd_minors = gdsk->minors;
/* Setup disk of bottom device as not partitioned device */ /* Setup disk of bottom device as not partitioned device */
gdsk->flags &= ~_casdsk_flags; gdsk->flags &= ~_cas_flags;
gdsk->minors = 1; gdsk->minors = 1;
/* Rescan partitions */ /* Rescan partitions */
cas_reread_partitions(bd); cas_reread_partitions(bd);
@ -193,41 +198,41 @@ static int _casdsk_exp_obj_hide_parts(struct casdsk_disk *dsk)
return 0; return 0;
} }
static int _casdsk_exp_obj_set_dev_t(struct casdsk_disk *dsk, struct gendisk *gd) static int _cas_exp_obj_set_dev_t(struct cas_disk *dsk, struct gendisk *gd)
{ {
int flags; int flags;
int minors = disk_max_parts(casdsk_disk_get_gendisk(dsk)); int minors = disk_max_parts(cas_disk_get_gendisk(dsk));
struct block_device *bdev; struct block_device *bdev;
bdev = casdsk_disk_get_blkdev(dsk); bdev = cas_disk_get_blkdev(dsk);
BUG_ON(!bdev); BUG_ON(!bdev);
if (cas_bdev_whole(bdev) != bdev) { if (cas_bdev_whole(bdev) != bdev) {
minors = 1; minors = 1;
flags = 0; flags = 0;
} else { } else {
if (_casdsk_exp_obj_hide_parts(dsk)) if (_cas_exp_obj_hide_parts(dsk))
return -EINVAL; return -EINVAL;
flags = dsk->gd_flags; flags = dsk->gd_flags;
} }
gd->first_minor = casdsk_disk_allocate_minors(minors); gd->first_minor = cas_disk_allocate_minors(minors);
if (gd->first_minor < 0) { if (gd->first_minor < 0) {
CASDSK_DEBUG_DISK_ERROR(dsk, "Cannot allocate %d minors", minors); CAS_DEBUG_DISK_ERROR(dsk, "Cannot allocate %d minors", minors);
return -EINVAL; return -EINVAL;
} }
gd->minors = minors; gd->minors = minors;
gd->major = casdsk_module->disk_major; gd->major = cas_module.disk_major;
gd->flags |= flags; gd->flags |= flags;
return 0; return 0;
} }
static void _casdsk_exp_obj_clear_dev_t(struct casdsk_disk *dsk) static void _cas_exp_obj_clear_dev_t(struct cas_disk *dsk)
{ {
struct block_device *bdev = casdsk_disk_get_blkdev(dsk); struct block_device *bdev = cas_disk_get_blkdev(dsk);
struct gendisk *gdsk = casdsk_disk_get_gendisk(dsk); struct gendisk *gdsk = cas_disk_get_gendisk(dsk);
if (cas_bdev_whole(bdev) == bdev) { if (cas_bdev_whole(bdev) == bdev) {
/* Restore previous configuration of bottom disk */ /* Restore previous configuration of bottom disk */
@ -237,9 +242,9 @@ static void _casdsk_exp_obj_clear_dev_t(struct casdsk_disk *dsk)
} }
} }
static int _casdsk_exp_obj_open(struct block_device *bdev, fmode_t mode) static int _cas_exp_obj_open(struct block_device *bdev, fmode_t mode)
{ {
struct casdsk_disk *dsk = bdev->bd_disk->private_data; struct cas_disk *dsk = bdev->bd_disk->private_data;
int result = -ENAVAIL; int result = -ENAVAIL;
mutex_lock(&dsk->openers_lock); mutex_lock(&dsk->openers_lock);
@ -257,9 +262,9 @@ static int _casdsk_exp_obj_open(struct block_device *bdev, fmode_t mode)
return result; return result;
} }
static void _casdsk_exp_obj_close(struct gendisk *gd, fmode_t mode) static void _cas_exp_obj_close(struct gendisk *gd, fmode_t mode)
{ {
struct casdsk_disk *dsk = gd->private_data; struct cas_disk *dsk = gd->private_data;
BUG_ON(dsk->openers == 0); BUG_ON(dsk->openers == 0);
@ -269,25 +274,25 @@ static void _casdsk_exp_obj_close(struct gendisk *gd, fmode_t mode)
} }
static const struct block_device_operations _casdsk_exp_obj_ops = { static const struct block_device_operations _cas_exp_obj_ops = {
.owner = THIS_MODULE, .owner = THIS_MODULE,
.open = _casdsk_exp_obj_open, .open = _cas_exp_obj_open,
.release = _casdsk_exp_obj_close, .release = _cas_exp_obj_close,
CAS_SET_SUBMIT_BIO(_casdsk_exp_obj_submit_bio) CAS_SET_SUBMIT_BIO(_cas_exp_obj_submit_bio)
}; };
static int casdsk_exp_obj_alloc(struct casdsk_disk *dsk) static int cas_exp_obj_alloc(struct cas_disk *dsk)
{ {
struct casdsk_exp_obj *exp_obj; struct cas_exp_obj *exp_obj;
BUG_ON(!dsk); BUG_ON(!dsk);
BUG_ON(dsk->exp_obj); BUG_ON(dsk->exp_obj);
CASDSK_DEBUG_DISK_TRACE(dsk); CAS_DEBUG_DISK_TRACE(dsk);
exp_obj = kmem_cache_zalloc(casdsk_module->exp_obj_cache, GFP_KERNEL); exp_obj = kmem_cache_zalloc(cas_module.exp_obj_cache, GFP_KERNEL);
if (!exp_obj) { if (!exp_obj) {
CASDSK_DEBUG_ERROR("Cannot allocate memory"); CAS_DEBUG_ERROR("Cannot allocate memory");
return -ENOMEM; return -ENOMEM;
} }
@ -296,11 +301,11 @@ static int casdsk_exp_obj_alloc(struct casdsk_disk *dsk)
return 0; return 0;
} }
void casdsk_exp_obj_free(struct casdsk_disk *dsk) void cas_exp_obj_free(struct cas_disk *dsk)
{ {
struct casdsk_exp_obj *exp_obj; struct cas_exp_obj *exp_obj;
CASDSK_DEBUG_DISK_TRACE(dsk); CAS_DEBUG_DISK_TRACE(dsk);
exp_obj = dsk->exp_obj; exp_obj = dsk->exp_obj;
@ -310,66 +315,65 @@ void casdsk_exp_obj_free(struct casdsk_disk *dsk)
kobject_put(&exp_obj->kobj); kobject_put(&exp_obj->kobj);
dsk->exp_obj = NULL; dsk->exp_obj = NULL;
} }
EXPORT_SYMBOL(casdsk_exp_obj_free);
static void __casdsk_exp_obj_release(struct casdsk_exp_obj *exp_obj) static void __cas_exp_obj_release(struct cas_exp_obj *exp_obj)
{ {
kmem_cache_free(casdsk_module->exp_obj_cache, exp_obj); kmem_cache_free(cas_module.exp_obj_cache, exp_obj);
} }
static void _casdsk_exp_obj_release(struct kobject *kobj) static void _cas_exp_obj_release(struct kobject *kobj)
{ {
struct casdsk_exp_obj *exp_obj; struct cas_exp_obj *exp_obj;
struct module *owner; struct module *owner;
BUG_ON(!kobj); BUG_ON(!kobj);
exp_obj = casdsk_kobj_to_exp_obj(kobj); exp_obj = cas_kobj_to_exp_obj(kobj);
BUG_ON(!exp_obj); BUG_ON(!exp_obj);
CASDSK_DEBUG_TRACE(); CAS_DEBUG_TRACE();
owner = exp_obj->owner; owner = exp_obj->owner;
kfree(exp_obj->dev_name); kfree(exp_obj->dev_name);
__casdsk_exp_obj_release(exp_obj); __cas_exp_obj_release(exp_obj);
if (owner) if (owner)
module_put(owner); module_put(owner);
} }
static struct kobj_type casdsk_exp_obj_ktype = { static struct kobj_type cas_exp_obj_ktype = {
.release = _casdsk_exp_obj_release .release = _cas_exp_obj_release
}; };
static int _casdsk_exp_obj_init_kobject(struct casdsk_disk *dsk) static int _cas_exp_obj_init_kobject(struct cas_disk *dsk)
{ {
int result = 0; int result = 0;
struct casdsk_exp_obj *exp_obj = dsk->exp_obj; struct cas_exp_obj *exp_obj = dsk->exp_obj;
kobject_init(&exp_obj->kobj, &casdsk_exp_obj_ktype); kobject_init(&exp_obj->kobj, &cas_exp_obj_ktype);
result = kobject_add(&exp_obj->kobj, &dsk->kobj, result = kobject_add(&exp_obj->kobj, &dsk->kobj,
"%s", exp_obj->dev_name); "%s", exp_obj->dev_name);
if (result) if (result)
CASDSK_DEBUG_DISK_ERROR(dsk, "Cannot register kobject"); CAS_DEBUG_DISK_ERROR(dsk, "Cannot register kobject");
return result; return result;
} }
static CAS_BLK_STATUS_T _casdsk_exp_obj_queue_rq(struct blk_mq_hw_ctx *hctx, static CAS_BLK_STATUS_T _cas_exp_obj_queue_rq(struct blk_mq_hw_ctx *hctx,
const struct blk_mq_queue_data *bd) const struct blk_mq_queue_data *bd)
{ {
return CAS_BLK_STS_NOTSUPP; return CAS_BLK_STS_NOTSUPP;
} }
static struct blk_mq_ops casdsk_mq_ops = { static struct blk_mq_ops cas_mq_ops = {
.queue_rq = _casdsk_exp_obj_queue_rq, .queue_rq = _cas_exp_obj_queue_rq,
#ifdef CAS_BLK_MQ_OPS_MAP_QUEUE #ifdef CAS_BLK_MQ_OPS_MAP_QUEUE
.map_queue = blk_mq_map_queue, .map_queue = blk_mq_map_queue,
#endif #endif
}; };
static void _casdsk_init_queues(struct casdsk_disk *dsk) static void _cas_init_queues(struct cas_disk *dsk)
{ {
struct request_queue *q = dsk->exp_obj->queue; struct request_queue *q = dsk->exp_obj->queue;
struct blk_mq_hw_ctx *hctx; struct blk_mq_hw_ctx *hctx;
@ -383,12 +387,12 @@ static void _casdsk_init_queues(struct casdsk_disk *dsk)
} }
} }
static int _casdsk_init_tag_set(struct casdsk_disk *dsk, struct blk_mq_tag_set *set) static int _cas_init_tag_set(struct cas_disk *dsk, struct blk_mq_tag_set *set)
{ {
BUG_ON(!dsk); BUG_ON(!dsk);
BUG_ON(!set); BUG_ON(!set);
set->ops = &casdsk_mq_ops; set->ops = &cas_mq_ops;
set->nr_hw_queues = num_online_cpus(); set->nr_hw_queues = num_online_cpus();
set->numa_node = NUMA_NO_NODE; set->numa_node = NUMA_NO_NODE;
/*TODO: Should we inherit qd from core device? */ /*TODO: Should we inherit qd from core device? */
@ -402,10 +406,10 @@ static int _casdsk_init_tag_set(struct casdsk_disk *dsk, struct blk_mq_tag_set *
return blk_mq_alloc_tag_set(set); return blk_mq_alloc_tag_set(set);
} }
int casdsk_exp_obj_create(struct casdsk_disk *dsk, const char *dev_name, int cas_exp_obj_create(struct cas_disk *dsk, const char *dev_name,
struct module *owner, struct casdsk_exp_obj_ops *ops) struct module *owner, struct cas_exp_obj_ops *ops)
{ {
struct casdsk_exp_obj *exp_obj; struct cas_exp_obj *exp_obj;
struct request_queue *queue; struct request_queue *queue;
struct gendisk *gd; struct gendisk *gd;
int result = 0; int result = 0;
@ -415,12 +419,12 @@ int casdsk_exp_obj_create(struct casdsk_disk *dsk, const char *dev_name,
BUG_ON(!ops); BUG_ON(!ops);
BUG_ON(dsk->exp_obj); BUG_ON(dsk->exp_obj);
CASDSK_DEBUG_DISK_TRACE(dsk); CAS_DEBUG_DISK_TRACE(dsk);
if (strlen(dev_name) >= DISK_NAME_LEN) if (strlen(dev_name) >= DISK_NAME_LEN)
return -EINVAL; return -EINVAL;
result = casdsk_exp_obj_alloc(dsk); result = cas_exp_obj_alloc(dsk);
if (result) if (result)
goto error_exp_obj_alloc; goto error_exp_obj_alloc;
@ -433,19 +437,19 @@ int casdsk_exp_obj_create(struct casdsk_disk *dsk, const char *dev_name,
} }
if (!try_module_get(owner)) { if (!try_module_get(owner)) {
CASDSK_DEBUG_DISK_ERROR(dsk, "Cannot get reference to module"); CAS_DEBUG_DISK_ERROR(dsk, "Cannot get reference to module");
result = -ENAVAIL; result = -ENAVAIL;
goto error_module_get; goto error_module_get;
} }
exp_obj->owner = owner; exp_obj->owner = owner;
exp_obj->ops = ops; exp_obj->ops = ops;
result = _casdsk_exp_obj_init_kobject(dsk); result = _cas_exp_obj_init_kobject(dsk);
if (result) { if (result) {
goto error_init_kobject; goto error_init_kobject;
} }
result = _casdsk_init_tag_set(dsk, &dsk->tag_set); result = _cas_init_tag_set(dsk, &dsk->tag_set);
if (result) { if (result) {
goto error_init_tag_set; goto error_init_tag_set;
} }
@ -457,7 +461,7 @@ int casdsk_exp_obj_create(struct casdsk_disk *dsk, const char *dev_name,
exp_obj->gd = gd; exp_obj->gd = gd;
result = _casdsk_exp_obj_set_dev_t(dsk, gd); result = _cas_exp_obj_set_dev_t(dsk, gd);
if (result) if (result)
goto error_exp_obj_set_dev_t; goto error_exp_obj_set_dev_t;
@ -465,13 +469,13 @@ int casdsk_exp_obj_create(struct casdsk_disk *dsk, const char *dev_name,
queue->queuedata = dsk; queue->queuedata = dsk;
exp_obj->queue = queue; exp_obj->queue = queue;
_casdsk_init_queues(dsk); _cas_init_queues(dsk);
gd->fops = &_casdsk_exp_obj_ops; gd->fops = &_cas_exp_obj_ops;
gd->private_data = dsk; gd->private_data = dsk;
strlcpy(gd->disk_name, exp_obj->dev_name, sizeof(gd->disk_name)); strlcpy(gd->disk_name, exp_obj->dev_name, sizeof(gd->disk_name));
cas_blk_queue_make_request(queue, _casdsk_exp_obj_make_rq_fn); cas_blk_queue_make_request(queue, _cas_exp_obj_make_rq_fn);
if (exp_obj->ops->set_geometry) { if (exp_obj->ops->set_geometry) {
result = exp_obj->ops->set_geometry(dsk, dsk->private); result = exp_obj->ops->set_geometry(dsk, dsk->private);
@ -482,7 +486,7 @@ int casdsk_exp_obj_create(struct casdsk_disk *dsk, const char *dev_name,
return 0; return 0;
error_set_geometry: error_set_geometry:
_casdsk_exp_obj_clear_dev_t(dsk); _cas_exp_obj_clear_dev_t(dsk);
error_exp_obj_set_dev_t: error_exp_obj_set_dev_t:
cas_cleanup_mq_disk(exp_obj); cas_cleanup_mq_disk(exp_obj);
dsk->exp_obj->gd = NULL; dsk->exp_obj->gd = NULL;
@ -498,31 +502,28 @@ error_init_kobject:
error_module_get: error_module_get:
kfree(exp_obj->dev_name); kfree(exp_obj->dev_name);
error_kstrdup: error_kstrdup:
__casdsk_exp_obj_release(exp_obj); __cas_exp_obj_release(exp_obj);
dsk->exp_obj = NULL; dsk->exp_obj = NULL;
error_exp_obj_alloc: error_exp_obj_alloc:
return result; return result;
} }
EXPORT_SYMBOL(casdsk_exp_obj_create);
struct request_queue *casdsk_exp_obj_get_queue(struct casdsk_disk *dsk) struct request_queue *cas_exp_obj_get_queue(struct cas_disk *dsk)
{ {
BUG_ON(!dsk); BUG_ON(!dsk);
BUG_ON(!dsk->exp_obj); BUG_ON(!dsk->exp_obj);
return dsk->exp_obj->queue; return dsk->exp_obj->queue;
} }
EXPORT_SYMBOL(casdsk_exp_obj_get_queue);
struct gendisk *casdsk_exp_obj_get_gendisk(struct casdsk_disk *dsk) struct gendisk *cas_exp_obj_get_gendisk(struct cas_disk *dsk)
{ {
BUG_ON(!dsk); BUG_ON(!dsk);
BUG_ON(!dsk->exp_obj); BUG_ON(!dsk->exp_obj);
return dsk->exp_obj->gd; return dsk->exp_obj->gd;
} }
EXPORT_SYMBOL(casdsk_exp_obj_get_gendisk);
static bool _casdsk_exp_obj_exists(const char *path) static bool _cas_exp_obj_exists(const char *path)
{ {
struct file *exported; struct file *exported;
@ -539,7 +540,7 @@ static bool _casdsk_exp_obj_exists(const char *path)
return true; return true;
} }
int casdsk_exp_obj_activate(struct casdsk_disk *dsk) int cas_exp_obj_activate(struct cas_disk *dsk)
{ {
char *path; char *path;
int result; int result;
@ -549,14 +550,14 @@ int casdsk_exp_obj_activate(struct casdsk_disk *dsk)
BUG_ON(!dsk->exp_obj->gd); BUG_ON(!dsk->exp_obj->gd);
BUG_ON(dsk->exp_obj->activated); BUG_ON(dsk->exp_obj->activated);
CASDSK_DEBUG_DISK_TRACE(dsk); CAS_DEBUG_DISK_TRACE(dsk);
path = kmalloc(PATH_MAX, GFP_KERNEL); path = kmalloc(PATH_MAX, GFP_KERNEL);
if (!path) if (!path)
return -ENOMEM; return -ENOMEM;
snprintf(path, PATH_MAX, "/dev/%s", dsk->exp_obj->dev_name); snprintf(path, PATH_MAX, "/dev/%s", dsk->exp_obj->dev_name);
if (_casdsk_exp_obj_exists(path)) { if (_cas_exp_obj_exists(path)) {
printk(KERN_ERR "Could not activate exported object, " printk(KERN_ERR "Could not activate exported object, "
"because file %s exists.\n", path); "because file %s exists.\n", path);
kfree(path); kfree(path);
@ -577,7 +578,7 @@ int casdsk_exp_obj_activate(struct casdsk_disk *dsk)
if (result) if (result)
goto error_sysfs_link; goto error_sysfs_link;
CASDSK_DEBUG_DISK(dsk, "Activated exp object %s", dsk->exp_obj->dev_name); CAS_DEBUG_DISK(dsk, "Activated exp object %s", dsk->exp_obj->dev_name);
return 0; return 0;
@ -588,23 +589,22 @@ error_bd_claim:
dsk->exp_obj->activated = false; dsk->exp_obj->activated = false;
return result; return result;
} }
EXPORT_SYMBOL(casdsk_exp_obj_activate);
bool casdsk_exp_obj_activated(struct casdsk_disk *dsk) bool cas_exp_obj_activated(struct cas_disk *dsk)
{ {
BUG_ON(!dsk); BUG_ON(!dsk);
return dsk->exp_obj->activated; return dsk->exp_obj->activated;
} }
int casdsk_exp_obj_lock(struct casdsk_disk *dsk) int cas_exp_obj_lock(struct cas_disk *dsk)
{ {
struct casdsk_exp_obj *exp_obj; struct cas_exp_obj *exp_obj;
int result = -EBUSY; int result = -EBUSY;
BUG_ON(!dsk); BUG_ON(!dsk);
BUG_ON(!dsk->exp_obj); BUG_ON(!dsk->exp_obj);
CASDSK_DEBUG_DISK_TRACE(dsk); CAS_DEBUG_DISK_TRACE(dsk);
exp_obj = dsk->exp_obj; exp_obj = dsk->exp_obj;
@ -618,12 +618,11 @@ int casdsk_exp_obj_lock(struct casdsk_disk *dsk)
mutex_unlock(&dsk->openers_lock); mutex_unlock(&dsk->openers_lock);
return result; return result;
} }
EXPORT_SYMBOL(casdsk_exp_obj_lock);
int casdsk_exp_obj_unlock(struct casdsk_disk *dsk) int cas_exp_obj_unlock(struct cas_disk *dsk)
{ {
BUG_ON(!dsk); BUG_ON(!dsk);
CASDSK_DEBUG_DISK_TRACE(dsk); CAS_DEBUG_DISK_TRACE(dsk);
mutex_lock(&dsk->openers_lock); mutex_lock(&dsk->openers_lock);
dsk->claimed = false; dsk->claimed = false;
@ -631,25 +630,24 @@ int casdsk_exp_obj_unlock(struct casdsk_disk *dsk)
return 0; return 0;
} }
EXPORT_SYMBOL(casdsk_exp_obj_unlock);
int casdsk_exp_obj_destroy(struct casdsk_disk *dsk) int cas_exp_obj_destroy(struct cas_disk *dsk)
{ {
struct casdsk_exp_obj *exp_obj; struct cas_exp_obj *exp_obj;
BUG_ON(!dsk); BUG_ON(!dsk);
if (!dsk->exp_obj) if (!dsk->exp_obj)
return -ENODEV; return -ENODEV;
CASDSK_DEBUG_DISK_TRACE(dsk); CAS_DEBUG_DISK_TRACE(dsk);
exp_obj = dsk->exp_obj; exp_obj = dsk->exp_obj;
if (casdsk_exp_obj_activated(dsk)) { if (cas_exp_obj_activated(dsk)) {
sysfs_remove_link(&exp_obj->kobj, "blockdev"); sysfs_remove_link(&exp_obj->kobj, "blockdev");
bd_release_from_disk(dsk->bd, exp_obj->gd); bd_release_from_disk(dsk->bd, exp_obj->gd);
_casdsk_exp_obj_clear_dev_t(dsk); _cas_exp_obj_clear_dev_t(dsk);
del_gendisk(exp_obj->gd); del_gendisk(exp_obj->gd);
} }
@ -663,4 +661,3 @@ int casdsk_exp_obj_destroy(struct casdsk_disk *dsk)
return 0; return 0;
} }
EXPORT_SYMBOL(casdsk_exp_obj_destroy);

107
modules/cas_cache/exp_obj.h Normal file
View File

@ -0,0 +1,107 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __CASDISK_EXP_OBJ_H__
#define __CASDISK_EXP_OBJ_H__
#include <linux/kobject.h>
#include <linux/fs.h>
struct cas_disk;
struct cas_exp_obj_ops {
/**
* @brief Set geometry of exported object (top) block device.
* Could be NULL.
*/
int (*set_geometry)(struct cas_disk *dsk, void *private);
/**
* @brief submit_bio of exported object (top) block device.
*
*/
void (*submit_bio)(struct cas_disk *dsk,
struct bio *bio, void *private);
};
struct cas_exp_obj {
struct gendisk *gd;
struct request_queue *queue;
struct block_device *locked_bd;
struct module *owner;
bool activated;
struct cas_exp_obj_ops *ops;
const char *dev_name;
struct kobject kobj;
atomic_t pt_ios;
atomic_t *pending_rqs;
};
int __init cas_init_exp_objs(void);
void cas_deinit_exp_objs(void);
void cas_exp_obj_free(struct cas_disk *dsk);
/**
* @brief Create exported object (top device)
* @param dsk Pointer to cas_disk structure representing a block device
* @param dev_name Name of exported object (top device)
* @param owner Pointer to cas module
* @param ops Pointer to structure with callback functions
* @return 0 if success, errno if failure
*/
int cas_exp_obj_create(struct cas_disk *dsk, const char *dev_name,
struct module *owner, struct cas_exp_obj_ops *ops);
/**
* @brief Get request queue of exported object (top) block device
* @param dsk Pointer to cas_disk structure representing a block device
* @return Pointer to reqest_queue structure of top block device
*/
struct request_queue *cas_exp_obj_get_queue(struct cas_disk *dsk);
/**
* @brief Get gendisk structure of exported object (top) block device
* @param dsk Pointer to cas_disk structure representing a block device
* @return Pointer to gendisk structure of top block device
*/
struct gendisk *cas_exp_obj_get_gendisk(struct cas_disk *dsk);
/**
* @brief Activate exported object (make it visible to OS
* and allow I/O handling)
* @param dsk Pointer to cas_disk structure representing a block device
* @return 0 if success, errno if failure
*/
int cas_exp_obj_activate(struct cas_disk *dsk);
/**
* @brief Lock exported object
* @param dsk Pointer to cas_disk structure representing a block device
* @return 0 if success, errno if failure
*/
int cas_exp_obj_lock(struct cas_disk *dsk);
/**
* @brief Unlock exported object
* @param dsk Pointer to cas_disk structure representing a block device
* @return 0 if success, errno if failure
*/
int cas_exp_obj_unlock(struct cas_disk *dsk);
/**
* @brief Destroy exported object
* @param dsk Pointer to cas_disk structure representing a block device
* @return 0 if success, errno if failure
*/
int cas_exp_obj_destroy(struct cas_disk *dsk);
#endif

View File

@ -2047,7 +2047,7 @@ static void init_instance_complete(struct _cache_mngt_attach_context *ctx,
/* Set other back information */ /* Set other back information */
name = block_dev_get_elevator_name( name = block_dev_get_elevator_name(
casdsk_disk_get_queue(bd_cache_obj->dsk)); cas_disk_get_queue(bd_cache_obj->dsk));
if (name) if (name)
strlcpy(ctx->cache_elevator, name, MAX_ELEVATOR_NAME); strlcpy(ctx->cache_elevator, name, MAX_ELEVATOR_NAME);
} }

View File

@ -40,7 +40,7 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/blk-mq.h> #include <linux/blk-mq.h>
#include <linux/ktime.h> #include <linux/ktime.h>
#include "../cas_disk/exp_obj.h" #include "exp_obj.h"
#include "generated_defines.h" #include "generated_defines.h"

View File

@ -40,17 +40,12 @@ MODULE_PARM_DESC(seq_cut_off_mb,
/* globals */ /* globals */
ocf_ctx_t cas_ctx; ocf_ctx_t cas_ctx;
struct cas_module cas_module;
static int __init cas_init_module(void) static int __init cas_init_module(void)
{ {
int result = 0; int result = 0;
if (casdsk_get_version() != CASDSK_IFACE_VERSION) {
printk(KERN_ERR OCF_PREFIX_SHORT
"Incompatible cas_disk module\n");
return -EINVAL;
}
if (!writeback_queue_unblock_size || !max_writeback_queue_size) { if (!writeback_queue_unblock_size || !max_writeback_queue_size) {
printk(KERN_ERR OCF_PREFIX_SHORT printk(KERN_ERR OCF_PREFIX_SHORT
"Invalid module parameter.\n"); "Invalid module parameter.\n");
@ -76,18 +71,26 @@ static int __init cas_init_module(void)
return -EINVAL; return -EINVAL;
} }
result = cas_init_exp_objs();
if (result)
return result;
result = cas_init_disks();
if (result)
goto error_init_disks;
result = cas_initialize_context(); result = cas_initialize_context();
if (result) { if (result) {
printk(KERN_ERR OCF_PREFIX_SHORT printk(KERN_ERR OCF_PREFIX_SHORT
"Cannot initialize cache library\n"); "Cannot initialize cache library\n");
return result; goto error_init_context;
} }
result = cas_ctrl_device_init(); result = cas_ctrl_device_init();
if (result) { if (result) {
printk(KERN_ERR OCF_PREFIX_SHORT printk(KERN_ERR OCF_PREFIX_SHORT
"Cannot initialize control device\n"); "Cannot initialize control device\n");
goto error_cas_ctx_init; goto error_init_device;
} }
printk(KERN_INFO "%s Version %s (%s)::Module loaded successfully\n", printk(KERN_INFO "%s Version %s (%s)::Module loaded successfully\n",
@ -95,8 +98,12 @@ static int __init cas_init_module(void)
return 0; return 0;
error_cas_ctx_init: error_init_device:
cas_cleanup_context(); cas_cleanup_context();
error_init_context:
cas_deinit_disks();
error_init_disks:
cas_deinit_exp_objs();
return result; return result;
} }
@ -107,6 +114,8 @@ static void __exit cas_exit_module(void)
{ {
cas_ctrl_device_deinit(); cas_ctrl_device_deinit();
cas_cleanup_context(); cas_cleanup_context();
cas_deinit_disks();
cas_deinit_exp_objs();
} }
module_exit(cas_exit_module); module_exit(cas_exit_module);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright(c) 2012-2021 Intel Corporation * Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
@ -7,7 +7,7 @@
#define __SERVICE_UI_IOCTL_H__ #define __SERVICE_UI_IOCTL_H__
struct casdsk_disk; struct cas_disk;
long cas_service_ioctl_ctrl(struct file *filp, unsigned int cmd, long cas_service_ioctl_ctrl(struct file *filp, unsigned int cmd,
unsigned long arg); unsigned long arg);

View File

@ -1,5 +1,5 @@
/* /*
* Copyright(c) 2012-2021 Intel Corporation * Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
*/ */
@ -9,10 +9,10 @@
#include "vol_block_dev_bottom.h" #include "vol_block_dev_bottom.h"
#include "vol_block_dev_top.h" #include "vol_block_dev_top.h"
struct casdsk_disk; struct cas_disk;
struct bd_object { struct bd_object {
struct casdsk_disk *dsk; struct cas_disk *dsk;
struct block_device *btm_bd; struct block_device *btm_bd;

View File

@ -28,14 +28,14 @@ int block_dev_open_object(ocf_volume_t vol, void *volume_params)
{ {
struct bd_object *bdobj = bd_object(vol); struct bd_object *bdobj = bd_object(vol);
const struct ocf_volume_uuid *uuid = ocf_volume_get_uuid(vol); const struct ocf_volume_uuid *uuid = ocf_volume_get_uuid(vol);
struct casdsk_disk *dsk; struct cas_disk *dsk;
if (bdobj->opened_by_bdev) { if (bdobj->opened_by_bdev) {
/* Bdev has been set manually, so there is nothing to do. */ /* Bdev has been set manually, so there is nothing to do. */
return 0; return 0;
} }
dsk = casdsk_disk_open(uuid->data, NULL); dsk = cas_disk_open(uuid->data, NULL);
if (IS_ERR_OR_NULL(dsk)) { if (IS_ERR_OR_NULL(dsk)) {
int error = PTR_ERR(dsk) ?: -EINVAL; int error = PTR_ERR(dsk) ?: -EINVAL;
@ -46,7 +46,7 @@ int block_dev_open_object(ocf_volume_t vol, void *volume_params)
} }
bdobj->dsk = dsk; bdobj->dsk = dsk;
bdobj->btm_bd = casdsk_disk_get_blkdev(dsk); bdobj->btm_bd = cas_disk_get_blkdev(dsk);
return 0; return 0;
} }
@ -58,7 +58,7 @@ void block_dev_close_object(ocf_volume_t vol)
if (bdobj->opened_by_bdev) if (bdobj->opened_by_bdev)
return; return;
casdsk_disk_close(bdobj->dsk); cas_disk_close(bdobj->dsk);
} }
unsigned int block_dev_get_max_io_size(ocf_volume_t vol) unsigned int block_dev_get_max_io_size(ocf_volume_t vol)

View File

@ -55,9 +55,9 @@ void blkdev_set_exported_object_flush_fua(ocf_core_t core)
bd_core_vol = bd_object(core_vol); bd_core_vol = bd_object(core_vol);
bd_cache_vol = bd_object(cache_vol); bd_cache_vol = bd_object(cache_vol);
core_q = casdsk_disk_get_queue(bd_core_vol->dsk); core_q = cas_disk_get_queue(bd_core_vol->dsk);
exp_q = casdsk_exp_obj_get_queue(bd_core_vol->dsk); exp_q = cas_exp_obj_get_queue(bd_core_vol->dsk);
cache_q = casdsk_disk_get_queue(bd_cache_vol->dsk); cache_q = cas_disk_get_queue(bd_cache_vol->dsk);
flush = (CAS_CHECK_QUEUE_FLUSH(core_q) || CAS_CHECK_QUEUE_FLUSH(cache_q)); flush = (CAS_CHECK_QUEUE_FLUSH(core_q) || CAS_CHECK_QUEUE_FLUSH(cache_q));
fua = (CAS_CHECK_QUEUE_FUA(core_q) || CAS_CHECK_QUEUE_FUA(cache_q)); fua = (CAS_CHECK_QUEUE_FUA(core_q) || CAS_CHECK_QUEUE_FUA(cache_q));
@ -96,7 +96,7 @@ static void blkdev_set_discard_properties(ocf_cache_t cache,
* Map geometry of underlying (core) object geometry (sectors etc.) * Map geometry of underlying (core) object geometry (sectors etc.)
* to geometry of exported object. * to geometry of exported object.
*/ */
static int blkdev_core_set_geometry(struct casdsk_disk *dsk, void *private) static int blkdev_core_set_geometry(struct cas_disk *dsk, void *private)
{ {
ocf_core_t core; ocf_core_t core;
ocf_cache_t cache; ocf_cache_t cache;
@ -118,19 +118,19 @@ static int blkdev_core_set_geometry(struct casdsk_disk *dsk, void *private)
bd_cache_vol = bd_object(cache_vol); bd_cache_vol = bd_object(cache_vol);
path = ocf_volume_get_uuid(core_vol)->data; path = ocf_volume_get_uuid(core_vol)->data;
core_bd = casdsk_disk_get_blkdev(dsk); core_bd = cas_disk_get_blkdev(dsk);
BUG_ON(!core_bd); BUG_ON(!core_bd);
cache_bd = casdsk_disk_get_blkdev(bd_cache_vol->dsk); cache_bd = cas_disk_get_blkdev(bd_cache_vol->dsk);
BUG_ON(!cache_bd); BUG_ON(!cache_bd);
core_q = cas_bdev_whole(core_bd)->bd_disk->queue; core_q = cas_bdev_whole(core_bd)->bd_disk->queue;
cache_q = cache_bd->bd_disk->queue; cache_q = cache_bd->bd_disk->queue;
exp_q = casdsk_exp_obj_get_queue(dsk); exp_q = cas_exp_obj_get_queue(dsk);
sectors = ocf_volume_get_length(core_vol) >> SECTOR_SHIFT; sectors = ocf_volume_get_length(core_vol) >> SECTOR_SHIFT;
set_capacity(casdsk_exp_obj_get_gendisk(dsk), sectors); set_capacity(cas_exp_obj_get_gendisk(dsk), sectors);
cas_copy_queue_limits(exp_q, cache_q, core_q); cas_copy_queue_limits(exp_q, cache_q, core_q);
@ -440,7 +440,7 @@ static void blkdev_submit_bio(struct bd_object *bvol, struct bio *bio)
blkdev_handle_bio(bvol, bio); blkdev_handle_bio(bvol, bio);
} }
static void blkdev_core_submit_bio(struct casdsk_disk *dsk, static void blkdev_core_submit_bio(struct cas_disk *dsk,
struct bio *bio, void *private) struct bio *bio, void *private)
{ {
ocf_core_t core = private; ocf_core_t core = private;
@ -453,12 +453,12 @@ static void blkdev_core_submit_bio(struct casdsk_disk *dsk,
blkdev_submit_bio(bvol, bio); blkdev_submit_bio(bvol, bio);
} }
static struct casdsk_exp_obj_ops kcas_core_exp_obj_ops = { static struct cas_exp_obj_ops kcas_core_exp_obj_ops = {
.set_geometry = blkdev_core_set_geometry, .set_geometry = blkdev_core_set_geometry,
.submit_bio = blkdev_core_submit_bio, .submit_bio = blkdev_core_submit_bio,
}; };
static int blkdev_cache_set_geometry(struct casdsk_disk *dsk, void *private) static int blkdev_cache_set_geometry(struct cas_disk *dsk, void *private)
{ {
ocf_cache_t cache; ocf_cache_t cache;
ocf_volume_t volume; ocf_volume_t volume;
@ -473,15 +473,15 @@ static int blkdev_cache_set_geometry(struct casdsk_disk *dsk, void *private)
bvol = bd_object(volume); bvol = bd_object(volume);
bd = casdsk_disk_get_blkdev(bvol->dsk); bd = cas_disk_get_blkdev(bvol->dsk);
BUG_ON(!bd); BUG_ON(!bd);
cache_q = bd->bd_disk->queue; cache_q = bd->bd_disk->queue;
exp_q = casdsk_exp_obj_get_queue(dsk); exp_q = cas_exp_obj_get_queue(dsk);
sectors = ocf_volume_get_length(volume) >> SECTOR_SHIFT; sectors = ocf_volume_get_length(volume) >> SECTOR_SHIFT;
set_capacity(casdsk_exp_obj_get_gendisk(dsk), sectors); set_capacity(cas_exp_obj_get_gendisk(dsk), sectors);
cas_copy_queue_limits(exp_q, cache_q, cache_q); cas_copy_queue_limits(exp_q, cache_q, cache_q);
@ -496,7 +496,7 @@ static int blkdev_cache_set_geometry(struct casdsk_disk *dsk, void *private)
return 0; return 0;
} }
static void blkdev_cache_submit_bio(struct casdsk_disk *dsk, static void blkdev_cache_submit_bio(struct cas_disk *dsk,
struct bio *bio, void *private) struct bio *bio, void *private)
{ {
ocf_cache_t cache = private; ocf_cache_t cache = private;
@ -509,7 +509,7 @@ static void blkdev_cache_submit_bio(struct casdsk_disk *dsk,
blkdev_submit_bio(bvol, bio); blkdev_submit_bio(bvol, bio);
} }
static struct casdsk_exp_obj_ops kcas_cache_exp_obj_ops = { static struct cas_exp_obj_ops kcas_cache_exp_obj_ops = {
.set_geometry = blkdev_cache_set_geometry, .set_geometry = blkdev_cache_set_geometry,
.submit_bio = blkdev_cache_submit_bio, .submit_bio = blkdev_cache_submit_bio,
}; };
@ -530,15 +530,15 @@ static const char *get_core_id_string(ocf_core_t core)
} }
static int kcas_volume_create_exported_object(ocf_volume_t volume, static int kcas_volume_create_exported_object(ocf_volume_t volume,
const char *name, void *priv, struct casdsk_exp_obj_ops *ops) const char *name, void *priv, struct cas_exp_obj_ops *ops)
{ {
struct bd_object *bvol = bd_object(volume); struct bd_object *bvol = bd_object(volume);
const struct ocf_volume_uuid *uuid = ocf_volume_get_uuid(volume); const struct ocf_volume_uuid *uuid = ocf_volume_get_uuid(volume);
char dev_name[DISK_NAME_LEN]; char dev_name[DISK_NAME_LEN];
struct casdsk_disk *dsk; struct cas_disk *dsk;
int result; int result;
dsk = casdsk_disk_claim(uuid->data, priv); dsk = cas_disk_claim(uuid->data, priv);
if (dsk != bvol->dsk) { if (dsk != bvol->dsk) {
result = -KCAS_ERR_SYSTEM; result = -KCAS_ERR_SYSTEM;
goto end; goto end;
@ -552,7 +552,7 @@ static int kcas_volume_create_exported_object(ocf_volume_t volume,
goto end; goto end;
} }
result = casdsk_exp_obj_create(dsk, name, result = cas_exp_obj_create(dsk, name,
THIS_MODULE, ops); THIS_MODULE, ops);
if (result) { if (result) {
destroy_workqueue(bvol->expobj_wq); destroy_workqueue(bvol->expobj_wq);
@ -582,13 +582,13 @@ static int kcas_volume_destroy_exported_object(ocf_volume_t volume)
if (!bvol->expobj_valid) if (!bvol->expobj_valid)
return 0; return 0;
result = casdsk_exp_obj_lock(bvol->dsk); result = cas_exp_obj_lock(bvol->dsk);
if (result == -EBUSY) if (result == -EBUSY)
return -KCAS_ERR_DEV_PENDING; return -KCAS_ERR_DEV_PENDING;
else if (result) else if (result)
return result; return result;
result = casdsk_exp_obj_destroy(bvol->dsk); result = cas_exp_obj_destroy(bvol->dsk);
if (result) if (result)
goto out; goto out;
@ -596,7 +596,7 @@ static int kcas_volume_destroy_exported_object(ocf_volume_t volume)
destroy_workqueue(bvol->expobj_wq); destroy_workqueue(bvol->expobj_wq);
out: out:
casdsk_exp_obj_unlock(bvol->dsk); cas_exp_obj_unlock(bvol->dsk);
return result; return result;
} }
@ -605,12 +605,12 @@ out:
* @brief this routine actually adds /dev/casM-N inode * @brief this routine actually adds /dev/casM-N inode
*/ */
static int kcas_volume_activate_exported_object(ocf_volume_t volume, static int kcas_volume_activate_exported_object(ocf_volume_t volume,
struct casdsk_exp_obj_ops *ops) struct cas_exp_obj_ops *ops)
{ {
struct bd_object *bvol = bd_object(volume); struct bd_object *bvol = bd_object(volume);
int result; int result;
result = casdsk_exp_obj_activate(bvol->dsk); result = cas_exp_obj_activate(bvol->dsk);
if (result == -EEXIST) if (result == -EEXIST)
result = -KCAS_ERR_FILE_EXISTS; result = -KCAS_ERR_FILE_EXISTS;
@ -705,15 +705,15 @@ static int kcas_core_lock_exported_object(ocf_core_t core, void *cntx)
if (!bvol->expobj_valid) if (!bvol->expobj_valid)
return 0; return 0;
result = casdsk_exp_obj_lock(bvol->dsk); result = cas_exp_obj_lock(bvol->dsk);
if (-EBUSY == result) { if (-EBUSY == result) {
printk(KERN_WARNING "Stopping %s failed - device in use\n", printk(KERN_WARNING "Stopping %s failed - device in use\n",
casdsk_exp_obj_get_gendisk(bvol->dsk)->disk_name); cas_exp_obj_get_gendisk(bvol->dsk)->disk_name);
return -KCAS_ERR_DEV_PENDING; return -KCAS_ERR_DEV_PENDING;
} else if (result) { } else if (result) {
printk(KERN_WARNING "Stopping %s failed - device unavailable\n", printk(KERN_WARNING "Stopping %s failed - device unavailable\n",
casdsk_exp_obj_get_gendisk(bvol->dsk)->disk_name); cas_exp_obj_get_gendisk(bvol->dsk)->disk_name);
return -OCF_ERR_CORE_NOT_AVAIL; return -OCF_ERR_CORE_NOT_AVAIL;
} }
@ -728,7 +728,7 @@ static int kcas_core_unlock_exported_object(ocf_core_t core, void *cntx)
struct bd_object *bvol = bd_object(ocf_core_get_volume(core)); struct bd_object *bvol = bd_object(ocf_core_get_volume(core));
if (bvol->expobj_locked) { if (bvol->expobj_locked) {
casdsk_exp_obj_unlock(bvol->dsk); cas_exp_obj_unlock(bvol->dsk);
bvol->expobj_locked = false; bvol->expobj_locked = false;
} }
@ -745,9 +745,9 @@ static int kcas_core_stop_exported_object(ocf_core_t core, void *cntx)
BUG_ON(!bvol->expobj_locked); BUG_ON(!bvol->expobj_locked);
printk(KERN_INFO "Stopping device %s\n", printk(KERN_INFO "Stopping device %s\n",
casdsk_exp_obj_get_gendisk(bvol->dsk)->disk_name); cas_exp_obj_get_gendisk(bvol->dsk)->disk_name);
ret = casdsk_exp_obj_destroy(bvol->dsk); ret = cas_exp_obj_destroy(bvol->dsk);
if (!ret) { if (!ret) {
bvol->expobj_valid = false; bvol->expobj_valid = false;
destroy_workqueue(bvol->expobj_wq); destroy_workqueue(bvol->expobj_wq);
@ -755,7 +755,7 @@ static int kcas_core_stop_exported_object(ocf_core_t core, void *cntx)
} }
if (bvol->expobj_locked) { if (bvol->expobj_locked) {
casdsk_exp_obj_unlock(bvol->dsk); cas_exp_obj_unlock(bvol->dsk);
bvol->expobj_locked = false; bvol->expobj_locked = false;
} }
@ -766,7 +766,7 @@ static int kcas_core_free_exported_object(ocf_core_t core, void *cntx)
{ {
struct bd_object *bvol = bd_object(ocf_core_get_volume(core)); struct bd_object *bvol = bd_object(ocf_core_get_volume(core));
casdsk_exp_obj_free(bvol->dsk); cas_exp_obj_free(bvol->dsk);
return 0; return 0;
} }

View File

@ -1,11 +0,0 @@
#
# Copyright(c) 2012-2022 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause
#
include $(M)/config.mk
obj-m := cas_disk.o
cas_disk-objs = main.o
cas_disk-objs += disk.o
cas_disk-objs += exp_obj.o

View File

@ -1,139 +0,0 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __CASDISK_H__
#define __CASDISK_H__
#include <linux/blkdev.h>
#include "linux_kernel_version.h"
/**
* Version of cas_disk interface
*/
#define CASDSK_IFACE_VERSION 3
struct casdsk_disk;
struct casdsk_exp_obj_ops {
/**
* @brief Set geometry of exported object (top) block device.
* Could be NULL.
*/
int (*set_geometry)(struct casdsk_disk *dsk, void *private);
/**
* @brief submit_bio of exported object (top) block device.
* Called by cas_disk when cas_disk device is in attached mode.
*
*/
void (*submit_bio)(struct casdsk_disk *dsk,
struct bio *bio, void *private);
};
/**
* @brief Get version of cas_disk interface
* @return cas_disk interface version
*/
uint32_t casdsk_get_version(void);
/**
* @brief Open block device
* @param path Path to block device
* @param private Private data
* @return Pointer to casdsk_disk related to opened block device
*/
struct casdsk_disk *casdsk_disk_open(const char *path, void *private);
/**
* @brief Claim previously opened block device (holded by cas_disk)
* @param path Path to block device
* @param private Private data
* @return Pointer to casdsk_disk structure related to block device, or NULL
* if device is not opened by cas_disk.
*/
struct casdsk_disk *casdsk_disk_claim(const char *path, void *private);
/**
* @brief Close block device and remove from cas_disk
* @param dsk Pointer to casdsk_disk structure related to block device
* which should be closed.
*/
void casdsk_disk_close(struct casdsk_disk *dsk);
/**
* @brief Get block_device structure of bottom block device
* @param dsk Pointer to casdsk_disk structure related to cas_disk device
* @return Pointer to block_device structure of bottom block device
*/
struct block_device *casdsk_disk_get_blkdev(struct casdsk_disk *dsk);
/**
* @brief Get request queue of bottom block device
* @param dsk Pointer to casdsk_disk structure related to cas_disk device
* @return Pointer to reqest_queue structure of bottom block device
*/
struct request_queue *casdsk_disk_get_queue(struct casdsk_disk *dsk);
/**
* @brief Get gendisk structure of bottom block device
* @param dsk Pointer to casdsk_disk structure related to cas_disk device
* @return Pointer to gendisk structure of bottom block device
*/
struct gendisk *casdsk_disk_get_gendisk(struct casdsk_disk *dsk);
/**
* @brief Create exported object (top device)
* @param dsk Pointer to casdsk_disk structure related to cas_disk device
* @param dev_name Name of exported object (top device)
* @param owner Pointer to cas module
* @param ops Pointer to structure with callback functions
* @return 0 if success, errno if failure
*/
int casdsk_exp_obj_create(struct casdsk_disk *dsk, const char *dev_name,
struct module *owner, struct casdsk_exp_obj_ops *ops);
/**
* @brief Get request queue of exported object (top) block device
* @param dsk Pointer to casdsk_disk structure related to cas_disk device
* @return Pointer to reqest_queue structure of top block device
*/
struct request_queue *casdsk_exp_obj_get_queue(struct casdsk_disk *dsk);
/**
* @brief Get gendisk structure of exported object (top) block device
* @param dsk Pointer to casdsk_disk structure related to cas_disk device
* @return Pointer to gendisk structure of top block device
*/
struct gendisk *casdsk_exp_obj_get_gendisk(struct casdsk_disk *dsk);
/**
* @brief Activate exported object (make it visible to OS
* and allow I/O handling)
* @param dsk Pointer to casdsk_disk structure related to cas_disk device
* @return 0 if success, errno if failure
*/
int casdsk_exp_obj_activate(struct casdsk_disk *dsk);
/**
* @brief Lock exported object
* @param dsk Pointer to casdsk_disk structure related to cas_disk device
* @return 0 if success, errno if failure
*/
int casdsk_exp_obj_lock(struct casdsk_disk *dsk);
/**
* @brief Unlock exported object
* @param dsk Pointer to casdsk_disk structure related to cas_disk device
* @return 0 if success, errno if failure
*/
int casdsk_exp_obj_unlock(struct casdsk_disk *dsk);
/**
* @brief Destroy exported object
* @param dsk Pointer to casdsk_disk structure related to cas_disk device
* @return 0 if success, errno if failure
*/
int casdsk_exp_obj_destroy(struct casdsk_disk *dsk);
#endif

View File

@ -1,33 +0,0 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __CASDISK_DEFS_H__
#define __CASDISK_DEFS_H__
#include <linux/version.h>
#include <linux/fs.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/kobject.h>
#include <linux/blkdev.h>
struct casdsk_module {
struct mutex lock;
struct list_head disk_list;
uint32_t next_disk_id;
int disk_major;
int next_minor;
struct kmem_cache *disk_cache;
struct kmem_cache *exp_obj_cache;
struct kobject kobj;
};
extern struct casdsk_module *casdsk_module;
#include "debug.h"
#endif

View File

@ -1,45 +0,0 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __CASDISK_DEBUG_H__
#define __CASDISK_DEBUG_H__
#undef CASDSK_DEBUG
#ifdef CASDSK_DEBUG
#define CASDSK_DEBUG_TRACE() \
printk(KERN_INFO "%s\n", __func__)
#define CASDSK_DEBUG_DISK_TRACE(dsk) \
printk(KERN_INFO "[%u] %s\n", dsk->id, __func__)
#define CASDSK_DEBUG_MSG(msg) \
printk(KERN_INFO "%s - %s\n", __func__, msg)
#define CASDSK_DEBUG_PARAM(format, ...) \
printk(KERN_INFO "%s - "format"\n", \
__func__, ##__VA_ARGS__)
#define CASDSK_DEBUG_DISK(dsk, format, ...) \
printk(KERN_INFO "[%u] %s - "format"\n", \
dsk->id, \
__func__, ##__VA_ARGS__)
#define CASDSK_DEBUG_ERROR(error, ...) \
CASDSK_DEBUG_PARAM("ERROR(%d) "error, __LINE__, ##__VA_ARGS__)
#define CASDSK_DEBUG_DISK_ERROR(dsk, error, ...) \
CASDSK_DEBUG_DISK(dsk, "ERROR(%d) "error, __LINE__, ##__VA_ARGS__)
#else
#define CASDSK_DEBUG_TRACE()
#define CASDSK_DEBUG_DISK_TRACE(dsk)
#define CASDSK_DEBUG_MSG(msg)
#define CASDSK_DEBUG_PARAM(format, ...)
#define CASDSK_DEBUG_DISK(dsk, format, ...)
#define CASDSK_DEBUG_ERROR(error, ...)
#define CASDSK_DEBUG_DISK_ERROR(dsk, error, ...)
#endif
#endif

View File

@ -1,243 +0,0 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/fs.h>
#include <linux/delay.h>
#include "cas_disk_defs.h"
#include "cas_cache.h"
#include "disk.h"
#include "exp_obj.h"
#define CASDSK_DISK_OPEN_FMODE (FMODE_READ | FMODE_WRITE)
static inline struct block_device *open_bdev_exclusive(const char *path,
fmode_t mode,
void *holder)
{
return blkdev_get_by_path(path, mode | FMODE_EXCL, holder);
}
static inline void close_bdev_exclusive(struct block_device *bdev, fmode_t mode)
{
blkdev_put(bdev, mode | FMODE_EXCL);
}
static void _casdsk_disk_release(struct kobject *kobj)
{
struct casdsk_disk *dsk;
BUG_ON(!kobj);
dsk = casdsk_kobj_to_disk(kobj);
BUG_ON(!dsk);
CASDSK_DEBUG_DISK_TRACE(dsk);
kfree(dsk->path);
kmem_cache_free(casdsk_module->disk_cache, dsk);
}
static struct kobj_type casdsk_disk_ktype = {
.release = _casdsk_disk_release,
};
int __init casdsk_init_disks(void)
{
CASDSK_DEBUG_TRACE();
casdsk_module->next_disk_id = 1;
INIT_LIST_HEAD(&casdsk_module->disk_list);
casdsk_module->disk_major = register_blkdev(casdsk_module->disk_major,
"cas");
if (casdsk_module->disk_major <= 0) {
CASDSK_DEBUG_ERROR("Cannot allocate major number");
return -EINVAL;
}
CASDSK_DEBUG_PARAM("Allocated major number: %d", casdsk_module->disk_major);
casdsk_module->disk_cache =
kmem_cache_create("casdsk_disk", sizeof(struct casdsk_disk),
0, 0, NULL);
if (!casdsk_module->disk_cache) {
unregister_blkdev(casdsk_module->disk_major, "cas");
return -ENOMEM;
}
return 0;
}
void casdsk_deinit_disks(void)
{
CASDSK_DEBUG_TRACE();
kmem_cache_destroy(casdsk_module->disk_cache);
unregister_blkdev(casdsk_module->disk_major, "cas");
}
static int _casdsk_disk_init_kobject(struct casdsk_disk *dsk)
{
int result = 0;
kobject_init(&dsk->kobj, &casdsk_disk_ktype);
result = kobject_add(&dsk->kobj, &disk_to_dev(dsk->bd->bd_disk)->kobj,
"cas%d", dsk->id);
if (result)
CASDSK_DEBUG_DISK_ERROR(dsk, "Cannot register kobject");
return result;
}
struct casdsk_disk *casdsk_disk_open(const char *path, void *private)
{
struct casdsk_disk *dsk;
int result = 0;
BUG_ON(!path);
CASDSK_DEBUG_TRACE();
dsk = kmem_cache_zalloc(casdsk_module->disk_cache, GFP_KERNEL);
if (!dsk) {
CASDSK_DEBUG_ERROR("Cannot allocate memory");
result = -ENOMEM;
goto error_kmem;
}
mutex_init(&dsk->lock);
mutex_init(&dsk->openers_lock);
dsk->path = kstrdup(path, GFP_KERNEL);
if (!dsk->path) {
result = -ENOMEM;
goto error_kstrdup;
}
dsk->bd = open_bdev_exclusive(path, CASDSK_DISK_OPEN_FMODE, dsk);
if (IS_ERR(dsk->bd)) {
CASDSK_DEBUG_ERROR("Cannot open exclusive");
result = PTR_ERR(dsk->bd);
goto error_open_bdev;
}
dsk->private = private;
mutex_lock(&casdsk_module->lock);
dsk->id = casdsk_module->next_disk_id++;
list_add(&dsk->list, &casdsk_module->disk_list);
mutex_unlock(&casdsk_module->lock);
result = _casdsk_disk_init_kobject(dsk);
if (result)
goto error_kobject;
CASDSK_DEBUG_DISK(dsk, "Created (%p)", dsk);
return dsk;
error_kobject:
mutex_lock(&casdsk_module->lock);
list_del(&dsk->list);
mutex_unlock(&casdsk_module->lock);
close_bdev_exclusive(dsk->bd, CASDSK_DISK_OPEN_FMODE);
error_open_bdev:
kfree(dsk->path);
error_kstrdup:
kmem_cache_free(casdsk_module->disk_cache, dsk);
error_kmem:
return ERR_PTR(result);
}
EXPORT_SYMBOL(casdsk_disk_open);
static void _casdsk_disk_claim(struct casdsk_disk *dsk, void *private)
{
dsk->private = private;
}
struct casdsk_disk *casdsk_disk_claim(const char *path, void *private)
{
struct list_head *item;
struct casdsk_disk *dsk = NULL;
BUG_ON(!path);
mutex_lock(&casdsk_module->lock);
list_for_each(item, &casdsk_module->disk_list) {
dsk = list_entry(item, struct casdsk_disk, list);
if (strncmp(path, dsk->path, PATH_MAX) == 0) {
_casdsk_disk_claim(dsk, private);
mutex_unlock(&casdsk_module->lock);
return dsk;
}
}
mutex_unlock(&casdsk_module->lock);
return NULL;
}
EXPORT_SYMBOL(casdsk_disk_claim);
static void __casdsk_disk_close(struct casdsk_disk *dsk)
{
close_bdev_exclusive(dsk->bd, CASDSK_DISK_OPEN_FMODE);
casdsk_exp_obj_free(dsk);
kobject_put(&dsk->kobj);
}
void casdsk_disk_close(struct casdsk_disk *dsk)
{
BUG_ON(!dsk);
BUG_ON(!dsk->bd);
CASDSK_DEBUG_DISK(dsk, "Destroying (%p)", dsk);
mutex_lock(&casdsk_module->lock);
list_del(&dsk->list);
mutex_unlock(&casdsk_module->lock);
__casdsk_disk_close(dsk);
}
EXPORT_SYMBOL(casdsk_disk_close);
struct block_device *casdsk_disk_get_blkdev(struct casdsk_disk *dsk)
{
BUG_ON(!dsk);
return dsk->bd;
}
EXPORT_SYMBOL(casdsk_disk_get_blkdev);
struct gendisk *casdsk_disk_get_gendisk(struct casdsk_disk *dsk)
{
BUG_ON(!dsk);
BUG_ON(!dsk->bd);
return dsk->bd->bd_disk;
}
struct request_queue *casdsk_disk_get_queue(struct casdsk_disk *dsk)
{
BUG_ON(!dsk);
BUG_ON(!dsk->bd);
return cas_bdev_whole(dsk->bd)->bd_disk->queue;
}
EXPORT_SYMBOL(casdsk_disk_get_queue);
int casdsk_disk_allocate_minors(int count)
{
int minor = -1;
mutex_lock(&casdsk_module->lock);
if (casdsk_module->next_minor + count <= (1 << MINORBITS)) {
minor = casdsk_module->next_minor;
casdsk_module->next_minor += count;
}
mutex_unlock(&casdsk_module->lock);
return minor;
}

View File

@ -1,60 +0,0 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __
#define __CASDISK_DISK_H__
#include <linux/kobject.h>
#include <linux/fs.h>
#include <linux/blkdev.h>
#include <linux/mutex.h>
#include <linux/blk-mq.h>
struct casdsk_exp_obj;
struct casdsk_disk {
uint32_t id;
char *path;
struct mutex lock;
struct mutex openers_lock;
unsigned int openers;
bool claimed;
struct block_device *bd;
int gd_flags;
int gd_minors;
struct blk_mq_tag_set tag_set;
struct casdsk_exp_obj *exp_obj;
struct kobject kobj;
struct list_head list;
void *private;
};
int __init casdsk_init_disks(void);
void casdsk_deinit_disks(void);
int casdsk_disk_allocate_minors(int count);
static inline void casdsk_disk_lock(struct casdsk_disk *dsk)
{
mutex_lock(&dsk->lock);
}
static inline void casdsk_disk_unlock(struct casdsk_disk *dsk)
{
mutex_unlock(&dsk->lock);
}
static inline struct casdsk_disk *casdsk_kobj_to_disk(struct kobject *kobj)
{
return container_of(kobj, struct casdsk_disk, kobj);
}
#endif

View File

@ -1,48 +0,0 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#ifndef __CASDISK_EXP_OBJ_H__
#define __CASDISK_EXP_OBJ_H__
#include <linux/kobject.h>
#include <linux/fs.h>
struct casdsk_disk;
struct casdsk_exp_obj_pt_io_ctx {
struct casdsk_disk *dsk;
struct bio *bio;
};
struct casdsk_exp_obj {
struct gendisk *gd;
struct request_queue *queue;
struct block_device *locked_bd;
struct module *owner;
bool activated;
struct casdsk_exp_obj_ops *ops;
const char *dev_name;
struct kobject kobj;
atomic_t pt_ios;
atomic_t *pending_rqs;
};
int __init casdsk_init_exp_objs(void);
void casdsk_deinit_exp_objs(void);
void casdsk_exp_obj_free(struct casdsk_disk *dsk);
static inline struct casdsk_exp_obj *casdsk_kobj_to_exp_obj(struct kobject *kobj)
{
return container_of(kobj, struct casdsk_exp_obj, kobj);
}
#endif

View File

@ -1,77 +0,0 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/vmalloc.h>
#include "cas_disk_defs.h"
#include "cas_disk.h"
#include "disk.h"
#include "exp_obj.h"
#define CASDSK_LOGO "CAS Disk"
/* Layer information. */
MODULE_AUTHOR("Intel(R) Corporation");
MODULE_LICENSE("Dual BSD/GPL");
MODULE_VERSION(CAS_VERSION);
static int iface_version = CASDSK_IFACE_VERSION;
module_param(iface_version, int, (S_IRUSR | S_IRGRP));
struct casdsk_module *casdsk_module;
uint32_t casdsk_get_version(void)
{
return CASDSK_IFACE_VERSION;
}
EXPORT_SYMBOL(casdsk_get_version);
static int __init casdsk_init_module(void)
{
int result = 0;
casdsk_module = kzalloc(sizeof(*casdsk_module), GFP_KERNEL);
if (!casdsk_module) {
result = -ENOMEM;
goto error_kmalloc;
}
mutex_init(&casdsk_module->lock);
mutex_lock(&casdsk_module->lock);
result = casdsk_init_exp_objs();
if (result)
goto error_init_exp_objs;
result = casdsk_init_disks();
if (result)
goto error_init_disks;
mutex_unlock(&casdsk_module->lock);
printk(KERN_INFO "%s Version %s (%s)::Module loaded successfully\n",
CASDSK_LOGO, CAS_VERSION, CAS_KERNEL);
return result;
error_init_disks:
casdsk_deinit_exp_objs();
error_init_exp_objs:
mutex_unlock(&casdsk_module->lock);
kfree(casdsk_module);
error_kmalloc:
return result;
}
module_init(casdsk_init_module);
static void __exit casdsk_exit_module(void)
{
casdsk_deinit_disks();
casdsk_deinit_exp_objs();
kfree(casdsk_module);
}
module_exit(casdsk_exit_module);

View File

@ -1,5 +1,5 @@
# #
# Copyright(c) 2019-2021 Intel Corporation # Copyright(c) 2019-2022 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# #
@ -11,7 +11,6 @@ from test_utils.os_utils import ModuleRemoveMethod
class CasModule(Enum): class CasModule(Enum):
cache = "cas_cache" cache = "cas_cache"
disk = "cas_disk"
def reload_all_cas_modules(): def reload_all_cas_modules():
@ -22,8 +21,6 @@ def reload_all_cas_modules():
def unload_all_cas_modules(): def unload_all_cas_modules():
os_utils.unload_kernel_module(CasModule.cache.value, os_utils.unload_kernel_module(CasModule.cache.value,
os_utils.ModuleRemoveMethod.rmmod) os_utils.ModuleRemoveMethod.rmmod)
os_utils.unload_kernel_module(CasModule.disk.value,
os_utils.ModuleRemoveMethod.rmmod)
def is_cas_management_dev_present(): def is_cas_management_dev_present():

View File

@ -59,7 +59,7 @@ def install_opencas(destdir: str = ""):
if output.exit_code != 0: if output.exit_code != 0:
raise CmdException("Failed to install Open CAS", output) raise CmdException("Failed to install Open CAS", output)
output = TestRun.executor.run("rmmod cas_cache cas_disk; modprobe cas_cache") output = TestRun.executor.run("rmmod cas_cache; modprobe cas_cache")
if output.exit_code != 0: if output.exit_code != 0:
raise CmdException("Failed to reload modules", output) raise CmdException("Failed to reload modules", output)

View File

@ -19,7 +19,7 @@ from test_tools.packaging import Packages
modules_links_dir = "/lib/modules/$(uname -r)/weak-updates/block/opencas" modules_links_dir = "/lib/modules/$(uname -r)/weak-updates/block/opencas"
modules_names = ["cas_cache.ko", "cas_disk.ko"] modules_names = ["cas_cache.ko"]
def test_weak_modules(): def test_weak_modules():

View File

@ -1,11 +1,8 @@
PACKAGE_NAME="<CAS_NAME>-modules" PACKAGE_NAME="<CAS_NAME>-modules"
PACKAGE_VERSION="#MODULE_VERSION#" PACKAGE_VERSION="#MODULE_VERSION#"
BUILT_MODULE_NAME[0]="cas_disk" BUILT_MODULE_NAME[0]="cas_cache"
BUILT_MODULE_NAME[1]="cas_cache" BUILT_MODULE_LOCATION[0]="modules/cas_cache/"
BUILT_MODULE_LOCATION[0]="modules/cas_disk/"
BUILT_MODULE_LOCATION[1]="modules/cas_cache/"
DEST_MODULE_LOCATION[0]="/<CAS_MODULES_DIR>" DEST_MODULE_LOCATION[0]="/<CAS_MODULES_DIR>"
DEST_MODULE_LOCATION[1]="/<CAS_MODULES_DIR>"
PRE_BUILD="./configure" PRE_BUILD="./configure"
MAKE[0]="make -j -C modules/ KERNEL_VERSION=$kernelver" MAKE[0]="make -j -C modules/ KERNEL_VERSION=$kernelver"
AUTOINSTALL=yes AUTOINSTALL=yes

View File

@ -1 +1 @@
omit_drivers+=" cas_disk cas_cache" omit_drivers+=" cas_cache"