Return values of expected type by the block layer

Signed-off-by: Michal Rakowski <michal.rakowski@intel.com>
This commit is contained in:
Michal Rakowski 2019-09-06 16:13:50 +02:00
parent 02ce30adf5
commit a904a5bf66
6 changed files with 57 additions and 23 deletions

2
configure vendored
View File

@ -61,7 +61,7 @@ generate_header() {
echo "Configuring OpenCAS" echo "Configuring OpenCAS"
for file in $FIRST; do for file in $FIRST; do
CONF=$(cat ${CONFIG_FILE} | grep $(basename $file) | cut -d' ' -f2) CONF=$(cat ${CONFIG_FILE} | grep $(basename $file) | cut -d' ' -f2)
source $file "apply" "$CONF" "$file" & source $file "apply" "$CONF" "$file"
done done
wait wait

View File

@ -20,9 +20,12 @@ check() {
apply() { apply() {
case "$1" in case "$1" in
"1") "1")
add_define "CAS_BLK_STATUS_T blk_status_t" ;; add_define "CAS_BLK_STATUS_T blk_status_t"
add_define "CAS_BLK_STS_OK BLK_STS_OK" ;;
"2") "2")
add_define "CAS_BLK_STATUS_T int" ;; add_define "CAS_BLK_STATUS_T int"
add_define "CAS_BLK_STS_OK 0" ;;
*) *)
exit 1 exit 1
esac esac

View File

@ -0,0 +1,31 @@
#!/bin/bash
#
# Copyright(c) 2012-2019 Intel Corporation
# SPDX-License-Identifier: BSD-3-Clause-Clear
#
. $(dirname $3)/conf_framework
check() {
cur_name=$(basename $2)
config_file_path=$1
if compile_module $cur_name "errno_to_blk_status(0)" "linux/blkdev.h"
then
echo $cur_name "1" >> $config_file_path
else
echo $cur_name "2" >> $config_file_path
fi
}
apply() {
case "$1" in
"1")
add_define "CAS_ERRNO_TO_BLK_STS(status) errno_to_blk_status(status)" ;;
"2")
add_define "CAS_ERRNO_TO_BLK_STS(status) status" ;;
*)
exit 1
esac
}
conf_run $@

View File

@ -11,7 +11,8 @@
static inline void _blockdev_end_request_all(struct request *rq, int error) static inline void _blockdev_end_request_all(struct request *rq, int error)
{ {
CAS_END_REQUEST_ALL(rq, map_cas_err_to_generic(error)); CAS_END_REQUEST_ALL(rq, CAS_ERRNO_TO_BLK_STS(
map_cas_err_to_generic(error)));
} }
static inline bool _blockdev_can_handle_rq(struct request *rq) static inline bool _blockdev_can_handle_rq(struct request *rq)
@ -90,7 +91,7 @@ void block_dev_complete_bio_fast(struct ocf_io *io, int error)
_blockdev_end_io_acct(bio, data->start_time); _blockdev_end_io_acct(bio, data->start_time);
CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), error); CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(error));
ocf_io_put(io); ocf_io_put(io);
cas_free_blk_data(data); cas_free_blk_data(data);
} }
@ -99,7 +100,7 @@ void block_dev_complete_bio_discard(struct ocf_io *io, int error)
{ {
struct bio *bio = io->priv1; struct bio *bio = io->priv1;
CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), error); CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(error));
ocf_io_put(io); ocf_io_put(io);
} }
@ -487,16 +488,14 @@ static int __block_dev_queue_rq(struct request *rq, ocf_core_t core)
return ret; return ret;
} }
static int _block_dev_queue_request(struct casdsk_disk *dsk, struct request *rq, void *private) static CAS_BLK_STATUS_T _block_dev_queue_request(struct casdsk_disk *dsk, struct request *rq, void *private)
{ {
ocf_core_t core = private; ocf_core_t core = private;
int ret; int ret = __block_dev_queue_rq(rq, core);
ret = __block_dev_queue_rq(rq, core);
if (ret) if (ret)
_blockdev_end_request_all(rq, ret); _blockdev_end_request_all(rq, ret);
return ret; return CAS_ERRNO_TO_BLK_STS(ret);
} }
static inline int _blkdev_can_hndl_bio(struct bio *bio) static inline int _blkdev_can_hndl_bio(struct bio *bio)
@ -504,7 +503,7 @@ static inline int _blkdev_can_hndl_bio(struct bio *bio)
if (CAS_CHECK_BARRIER(bio)) { if (CAS_CHECK_BARRIER(bio)) {
CAS_PRINT_RL(KERN_WARNING CAS_PRINT_RL(KERN_WARNING
"special bio was sent, not supported!\n"); "special bio was sent, not supported!\n");
CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -EOPNOTSUPP); CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-EOPNOTSUPP));
return -ENOTSUPP; return -ENOTSUPP;
} }
@ -708,7 +707,7 @@ static void _blockdev_make_request_discard(struct casdsk_disk *dsk,
if (!io) { if (!io) {
CAS_PRINT_RL(KERN_CRIT CAS_PRINT_RL(KERN_CRIT
"Out of memory. Ending IO processing.\n"); "Out of memory. Ending IO processing.\n");
CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -ENOMEM); CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-ENOMEM));
return; return;
} }
@ -750,14 +749,14 @@ static int _blockdev_make_request_fast(struct casdsk_disk *dsk,
CAS_PRINT_RL(KERN_ERR CAS_PRINT_RL(KERN_ERR
"Not able to handle empty BIO, flags = " "Not able to handle empty BIO, flags = "
CAS_BIO_OP_FLAGS_FORMAT "\n", CAS_BIO_OP_FLAGS(bio)); CAS_BIO_OP_FLAGS_FORMAT "\n", CAS_BIO_OP_FLAGS(bio));
CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -EINVAL); CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-EINVAL));
return CASDSK_BIO_HANDLED; return CASDSK_BIO_HANDLED;
} }
data = cas_alloc_blk_data(bio_segments(bio), GFP_ATOMIC); data = cas_alloc_blk_data(bio_segments(bio), GFP_ATOMIC);
if (!data) { if (!data) {
CAS_PRINT_RL(KERN_CRIT "BIO data vector allocation error\n"); CAS_PRINT_RL(KERN_CRIT "BIO data vector allocation error\n");
CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -ENOMEM); CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-ENOMEM));
return CASDSK_BIO_HANDLED; return CASDSK_BIO_HANDLED;
} }
@ -775,7 +774,7 @@ static int _blockdev_make_request_fast(struct casdsk_disk *dsk,
if (!io) { if (!io) {
printk(KERN_CRIT "Out of memory. Ending IO processing.\n"); printk(KERN_CRIT "Out of memory. Ending IO processing.\n");
cas_free_blk_data(data); cas_free_blk_data(data);
CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -ENOMEM); CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-ENOMEM));
return CASDSK_BIO_HANDLED; return CASDSK_BIO_HANDLED;
} }
@ -783,7 +782,7 @@ static int _blockdev_make_request_fast(struct casdsk_disk *dsk,
if (ret < 0) { if (ret < 0) {
ocf_io_put(io); ocf_io_put(io);
cas_free_blk_data(data); cas_free_blk_data(data);
CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -EINVAL); CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-EINVAL));
return CASDSK_BIO_HANDLED; return CASDSK_BIO_HANDLED;
} }

View File

@ -6,6 +6,7 @@
#define __CASDISK_H__ #define __CASDISK_H__
#include <linux/blkdev.h> #include <linux/blkdev.h>
#include "linux_kernel_version.h"
/** /**
* Version of cas_disk interface * Version of cas_disk interface
@ -54,7 +55,7 @@ struct casdsk_exp_obj_ops {
* @brief queue_rq_fn of exported object (top) block device. * @brief queue_rq_fn of exported object (top) block device.
* Called by cas_disk when cas_disk device is in attached mode. * Called by cas_disk when cas_disk device is in attached mode.
*/ */
int (*queue_rq_fn)(struct casdsk_disk *dsk, struct request *rq, CAS_BLK_STATUS_T (*queue_rq_fn)(struct casdsk_disk *dsk, struct request *rq,
void *private); void *private);
/** /**

View File

@ -91,7 +91,7 @@ CAS_DECLARE_BLOCK_CALLBACK(_casdsk_exp_obj_bio_pt_io, struct bio *bio,
io = bio->bi_private; io = bio->bi_private;
BUG_ON(!io); BUG_ON(!io);
CAS_BIO_ENDIO(io->bio, CAS_BIO_BISIZE(io->bio), CAS_BIO_ENDIO(io->bio, CAS_BIO_BISIZE(io->bio),
CAS_BLOCK_CALLBACK_ERROR(bio, error)); CAS_BLOCK_CALLBACK_ERROR(bio, CAS_ERRNO_TO_BLK_STS(error)));
if (atomic_dec_return(&io->dsk->exp_obj->pt_ios) < 0) if (atomic_dec_return(&io->dsk->exp_obj->pt_ios) < 0)
BUG(); BUG();
@ -110,14 +110,14 @@ static inline void _casdsk_exp_obj_handle_bio_pt(struct casdsk_disk *dsk,
io = kmem_cache_zalloc(casdsk_module->pt_io_ctx_cache, GFP_ATOMIC); io = kmem_cache_zalloc(casdsk_module->pt_io_ctx_cache, GFP_ATOMIC);
if (!io) { if (!io) {
CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -ENOMEM); CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-ENOMEM));
return; return;
} }
cloned_bio = cas_bio_clone(bio, GFP_ATOMIC); cloned_bio = cas_bio_clone(bio, GFP_ATOMIC);
if (!cloned_bio) { if (!cloned_bio) {
kmem_cache_free(casdsk_module->pt_io_ctx_cache, io); kmem_cache_free(casdsk_module->pt_io_ctx_cache, io);
CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -ENOMEM); CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-ENOMEM));
return; return;
} }
@ -141,7 +141,7 @@ static inline void _casdsk_exp_obj_handle_bio(struct casdsk_disk *dsk,
else if (casdsk_disk_is_pt(dsk)) else if (casdsk_disk_is_pt(dsk))
_casdsk_exp_obj_handle_bio_pt(dsk, q, bio); _casdsk_exp_obj_handle_bio_pt(dsk, q, bio);
else if (casdsk_disk_is_shutdown(dsk)) else if (casdsk_disk_is_shutdown(dsk))
CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), -EIO); CAS_BIO_ENDIO(bio, CAS_BIO_BISIZE(bio), CAS_ERRNO_TO_BLK_STS(-EIO));
else else
BUG(); BUG();
} }
@ -434,7 +434,7 @@ static CAS_BLK_STATUS_T _casdsk_exp_obj_queue_qr(struct blk_mq_hw_ctx *hctx,
struct casdsk_disk *dsk = hctx->driver_data; struct casdsk_disk *dsk = hctx->driver_data;
struct casdsk_exp_obj *exp_obj = dsk->exp_obj; struct casdsk_exp_obj *exp_obj = dsk->exp_obj;
struct request *rq = bd->rq; struct request *rq = bd->rq;
int result = 0; CAS_BLK_STATUS_T result = CAS_BLK_STS_OK;
if (likely(exp_obj->ops && exp_obj->ops->queue_rq_fn)) { if (likely(exp_obj->ops && exp_obj->ops->queue_rq_fn)) {
exp_obj->ops->pending_rq_inc(dsk, dsk->private); exp_obj->ops->pending_rq_inc(dsk, dsk->private);