Skip to content

Commit

Permalink
Merge pull request #1512 from robertbaldyga/various_fixes
Browse files Browse the repository at this point in the history
Bunch of smaller fixes
  • Loading branch information
robertbaldyga authored Sep 10, 2024
2 parents de16763 + ded760a commit 7c7e7bf
Show file tree
Hide file tree
Showing 15 changed files with 70 additions and 62 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*.ko.*
*.obj
*.a
tags
Module.symvers
Module.markers
*.mod.c
Expand Down
3 changes: 3 additions & 0 deletions Makefile
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
#

Expand All @@ -20,6 +21,8 @@ ifneq ($(MAKECMDGOALS),srpm)
ifneq ($(MAKECMDGOALS),deb)
ifneq ($(MAKECMDGOALS),dsc)
cd $@ && $(MAKE) $(MAKECMDGOALS)
casadm: modules
cd $@ && $(MAKE) $(MAKECMDGOALS)
endif
endif
endif
Expand Down
4 changes: 3 additions & 1 deletion casadm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ $(OBJDIR)%.o: %.c
ifeq ($(strip $(CAS_VERSION_MAIN)),)
$(error "No version file")
endif
@$(CC) -c $(CFLAGS) -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -o "$@" "$<"
@$(CC) -c $(CFLAGS) -MMD -o "$@" "$<"

-include $(addprefix $(OBJDIR),$(OBJS:.o=.d))

clean:
@echo " CLEAN "
Expand Down
2 changes: 1 addition & 1 deletion casadm/casadm.8
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Stop cache instance.
Set runtime parameter for cache/core instance.

.TP
.B -G, --set-param
.B -G, --get-param
Get runtime parameter for cache/core instance.

.TP
Expand Down
17 changes: 2 additions & 15 deletions modules/cas_cache/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static int _cas_page_get_cpu(struct page *page)
/*
*
*/
static ctx_data_t *__cas_ctx_data_alloc(uint32_t pages, bool zalloc)
static ctx_data_t *__cas_ctx_data_alloc(uint32_t pages)
{
struct blk_data *data;
uint32_t i;
Expand Down Expand Up @@ -116,14 +116,6 @@ static ctx_data_t *__cas_ctx_data_alloc(uint32_t pages, bool zalloc)
if (!data->vec[i].bv_page)
break;

if (zalloc) {
if (!page_addr) {
page_addr = page_address(
data->vec[i].bv_page);
}
memset(page_addr, 0, PAGE_SIZE);
}

data->vec[i].bv_len = PAGE_SIZE;
data->vec[i].bv_offset = 0;
}
Expand Down Expand Up @@ -153,12 +145,7 @@ static ctx_data_t *__cas_ctx_data_alloc(uint32_t pages, bool zalloc)

ctx_data_t *cas_ctx_data_alloc(uint32_t pages)
{
return __cas_ctx_data_alloc(pages, false);
}

ctx_data_t *cas_ctx_data_zalloc(uint32_t pages)
{
return __cas_ctx_data_alloc(pages, true);
return __cas_ctx_data_alloc(pages);
}

/*
Expand Down
2 changes: 1 addition & 1 deletion modules/cas_cache/context.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
*/

Expand Down Expand Up @@ -69,7 +70,6 @@ struct blk_data *cas_alloc_blk_data(uint32_t size, gfp_t flags);
void cas_free_blk_data(struct blk_data *data);

ctx_data_t *cas_ctx_data_alloc(uint32_t pages);
ctx_data_t *cas_ctx_data_zalloc(uint32_t pages);
void cas_ctx_data_free(ctx_data_t *ctx_data);
void cas_ctx_data_secure_erase(ctx_data_t *ctx_data);

Expand Down
7 changes: 4 additions & 3 deletions modules/cas_cache/debug.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_DEBUG_H__
Expand All @@ -12,7 +13,7 @@
printk(KERN_INFO "%s\n", __func__)

#define CAS_DEBUG_DISK_TRACE(dsk) \
printk(KERN_INFO "[%u] %s\n", dsk->id, __func__)
printk(KERN_INFO "[%s] %s\n", dsk->path, __func__)

#define CAS_DEBUG_MSG(msg) \
printk(KERN_INFO "%s - %s\n", __func__, msg)
Expand All @@ -22,8 +23,8 @@
__func__, ##__VA_ARGS__)

#define CAS_DEBUG_DISK(dsk, format, ...) \
printk(KERN_INFO "[%u] %s - "format"\n", \
dsk->id, \
printk(KERN_INFO "[%s] %s - "format"\n", \
dsk->path, \
__func__, ##__VA_ARGS__)

#define CAS_DEBUG_ERROR(error, ...) \
Expand Down
4 changes: 1 addition & 3 deletions modules/cas_cache/exp_obj.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_EXP_OBJ_H__
Expand Down Expand Up @@ -46,9 +47,6 @@ struct cas_exp_obj {

struct blk_mq_tag_set tag_set;

atomic_t pt_ios;
atomic_t *pending_rqs;

void *private;
};

Expand Down
47 changes: 24 additions & 23 deletions modules/cas_cache/layer_cache_management.c
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,9 @@ int cache_mngt_core_pool_get_paths(struct kcas_core_pool_path *cmd_info)
struct get_paths_ctx visitor_ctx = {0};
int result;

if (visitor_ctx->core_path_name_tab == NULL)
return -EINVAL;

visitor_ctx.core_path_name_tab = cmd_info->core_path_tab;
visitor_ctx.max_count = cmd_info->core_pool_count;

Expand Down Expand Up @@ -2058,6 +2061,7 @@ static int _cache_mngt_start_queues(ocf_cache_t cache)
cache_priv->mngt_queue, CAS_CPUS_ALL);
if (result) {
ocf_queue_put(cache_priv->mngt_queue);
cache_priv->mngt_queue = NULL;
goto err;
}

Expand Down Expand Up @@ -2697,17 +2701,21 @@ int cache_mngt_init_instance(struct ocf_mngt_cache_config *cfg,
switch (cmd->init_cache) {
case CACHE_INIT_STANDBY_NEW:
case CACHE_INIT_STANDBY_LOAD:
ocf_volume_destroy(attach_cfg->device.volume);
printk(KERN_ERR "Standby mode is not supported!\n");
return -ENOTSUP;
default:
break;
}

if (!try_module_get(THIS_MODULE))
if (!try_module_get(THIS_MODULE)) {
ocf_volume_destroy(attach_cfg->device.volume);
return -KCAS_ERR_SYSTEM;
}

result = cache_mngt_check_bdev(&attach_cfg->device, attach_cfg->force, false, NULL);
if (result) {
ocf_volume_destroy(attach_cfg->device.volume);
module_put(THIS_MODULE);
return result;
}
Expand All @@ -2719,6 +2727,7 @@ int cache_mngt_init_instance(struct ocf_mngt_cache_config *cfg,
cache_name_meta, &cache_mode_meta,
&cache_line_size_meta);
if (result) {
ocf_volume_destroy(attach_cfg->device.volume);
module_put(THIS_MODULE);
return result;
}
Expand All @@ -2729,6 +2738,7 @@ int cache_mngt_init_instance(struct ocf_mngt_cache_config *cfg,
printk(KERN_ERR "Improper cache name format on %s.\n",
cmd->cache_path_name);

ocf_volume_destroy(attach_cfg->device.volume);
module_put(THIS_MODULE);
return -OCF_ERR_START_CACHE_FAIL;
}
Expand All @@ -2741,6 +2751,7 @@ int cache_mngt_init_instance(struct ocf_mngt_cache_config *cfg,
"already exists.\n", cache_name_meta);

ocf_mngt_cache_put(tmp_cache);
ocf_volume_destroy(attach_cfg->device.volume);
module_put(THIS_MODULE);
return -OCF_ERR_CACHE_EXIST;
}
Expand All @@ -2755,6 +2766,7 @@ int cache_mngt_init_instance(struct ocf_mngt_cache_config *cfg,

context = kzalloc(sizeof(*context), GFP_KERNEL);
if (!context) {
ocf_volume_destroy(attach_cfg->device.volume);
module_put(THIS_MODULE);
return -ENOMEM;
}
Expand All @@ -2764,6 +2776,7 @@ int cache_mngt_init_instance(struct ocf_mngt_cache_config *cfg,
if (IS_ERR(context->rollback_thread)) {
result = PTR_ERR(context->rollback_thread);
kfree(context);
ocf_volume_destroy(attach_cfg->device.volume);
module_put(THIS_MODULE);
return result;
}
Expand All @@ -2779,19 +2792,20 @@ int cache_mngt_init_instance(struct ocf_mngt_cache_config *cfg,
if (result) {
cas_lazy_thread_stop(context->rollback_thread);
kfree(context);
ocf_volume_destroy(attach_cfg->device.volume);
module_put(THIS_MODULE);
return result;
}
context->cache = cache;

result = _cache_mngt_cache_priv_init(cache);
if (result)
goto err;
goto err_deinit_config;
context->priv_inited = true;

result = _cache_mngt_start_queues(cache);
if (result)
goto err;
goto err_deinit_config;

cache_priv = ocf_cache_get_priv(cache);
cache_priv->attach_context = context;
Expand Down Expand Up @@ -2838,6 +2852,9 @@ int cache_mngt_init_instance(struct ocf_mngt_cache_config *cfg,
ocf_mngt_cache_unlock(cache);

return result;

err_deinit_config:
ocf_volume_destroy(attach_cfg->device.volume);
err:
cmd->min_free_ram = context->min_free_ram;

Expand Down Expand Up @@ -3196,10 +3213,6 @@ int cache_mngt_exit_instance(const char *cache_name, size_t name_len, int flush)
if (status)
return status;

cache_priv = ocf_cache_get_priv(cache);
mngt_queue = cache_priv->mngt_queue;
context = cache_priv->stop_context;

/*
* Flush cache. Flushing may take a long time, so we allow user
* to interrupt this operation. Hence we do first flush before
Expand All @@ -3218,6 +3231,10 @@ int cache_mngt_exit_instance(const char *cache_name, size_t name_len, int flush)
if (status)
goto put;

cache_priv = ocf_cache_get_priv(cache);
mngt_queue = cache_priv->mngt_queue;
context = cache_priv->stop_context;

context->finish_thread = cas_lazy_thread_create(exit_instance_finish,
context, "cas_%s_stop", cache_name);
if (IS_ERR(context->finish_thread)) {
Expand Down Expand Up @@ -3504,22 +3521,6 @@ int cache_mngt_get_core_info(struct kcas_core_info *info)
return result;
}

static int cache_mngt_wait_for_rq_finish_visitor(ocf_core_t core, void *cntx)
{
ocf_volume_t obj = ocf_core_get_volume(core);
struct bd_object *bdobj = bd_object(obj);

while (atomic64_read(&bdobj->pending_rqs))
io_schedule();

return 0;
}

void cache_mngt_wait_for_rq_finish(ocf_cache_t cache)
{
ocf_core_visit(cache, cache_mngt_wait_for_rq_finish_visitor, NULL, true);
}

int cache_mngt_set_core_params(struct kcas_set_core_param *info)
{
ocf_cache_t cache;
Expand Down
2 changes: 1 addition & 1 deletion modules/cas_cache/service_ui_ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
return map_cas_err_to_generic(ret); \
})

/* this handles IOctl for /dev/cas */
/* this handles IOctl for /dev/cas_ctrl */
/*********************************************/
long cas_service_ioctl_ctrl(struct file *filp, unsigned int cmd,
unsigned long arg)
Expand Down
7 changes: 1 addition & 6 deletions modules/cas_cache/volume/obj_blk.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
*/

Expand All @@ -25,12 +26,6 @@ struct bd_object {
uint32_t opened_by_bdev : 1;
/*!< Opened by supplying bdev manually */

atomic64_t pending_rqs;
/*!< This fields describes in flight IO requests */

struct workqueue_struct *btm_wq;
/*< Workqueue for I/O internally trigerred in bottom vol */

struct workqueue_struct *expobj_wq;
/*< Workqueue for I/O handled by top vol */

Expand Down
17 changes: 16 additions & 1 deletion modules/cas_cache/volume/vol_block_dev_bottom.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,21 @@ static inline bool cas_bd_io_prepare(int *dir, struct ocf_io *io)
return true;
}

/*
* Returns only flags that are relevant to request's direction.
*/
static inline uint64_t filter_req_flags(int dir, uint64_t flags)
{
/* Remove REQ_RAHEAD flag from write request to cache which are a
result of a missed read-head request. This flag caused the nvme
driver to send write command with access frequency value that is
reserved */
if (dir == WRITE)
flags &= ~REQ_RAHEAD;

return flags;
}

/*
*
*/
Expand Down Expand Up @@ -359,7 +374,7 @@ static void block_dev_submit_io(struct ocf_io *io)
CAS_BIO_BISECTOR(bio) = addr / SECTOR_SIZE;
bio->bi_next = NULL;
bio->bi_private = io;
CAS_BIO_OP_FLAGS(bio) |= io->flags;
CAS_BIO_OP_FLAGS(bio) |= filter_req_flags(dir, io->flags);
bio->bi_end_io = CAS_REFER_BLOCK_CALLBACK(cas_bd_io_end);

/* Add pages */
Expand Down
5 changes: 1 addition & 4 deletions modules/cas_cache/volume/vol_block_dev_top.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,10 +370,7 @@ static void blkdev_complete_flush(struct ocf_io *io, int error)
return;
}

if (in_interrupt())
blkdev_defer_bio(bvol, bio, blkdev_handle_bio_noflush);
else
blkdev_handle_bio_noflush(bvol, bio);
blkdev_defer_bio(bvol, bio, blkdev_handle_bio_noflush);
}

static void blkdev_handle_flush(struct bd_object *bvol, struct bio *bio)
Expand Down
3 changes: 2 additions & 1 deletion modules/config.mk
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
#

Expand All @@ -14,7 +15,7 @@ EXTRA_CFLAGS += -DCAS_VERSION_MAIN=$(CAS_VERSION_MAIN)
EXTRA_CFLAGS += -DCAS_VERSION_MAJOR=$(CAS_VERSION_MAJOR)
EXTRA_CFLAGS += -DCAS_VERSION_MINOR=$(CAS_VERSION_MINOR)
EXTRA_CFLAGS += -DCAS_VERSION=\"$(CAS_VERSION)\"
EXTRA_CFLAGS += -O2 -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security
EXTRA_CFLAGS += -Ofast -D_FORTIFY_SOURCE=2 -Wformat -Wformat-security

EXTRA_CFLAGS += -I$(M)
EXTRA_CFLAGS += -I$(M)/cas_cache
Expand Down
Loading

0 comments on commit 7c7e7bf

Please sign in to comment.