open-cas-linux/configure.d/2_alloc_disk.conf
Rafal Stefanowski 7dcb9c92fe Fix checking for NULL instead of error pointer
Signed-off-by: Rafal Stefanowski <rafal.stefanowski@huawei.com>
2025-02-05 17:29:45 +01:00

105 lines
2.1 KiB
Bash

#!/bin/bash
#
# Copyright(c) 2012-2022 Intel Corporation
# Copyright(c) 2024 Huawei Technologies
# SPDX-License-Identifier: BSD-3-Clause
#
. $(dirname $3)/conf_framework.sh
check() {
cur_name=$(basename $2)
config_file_path=$1
if compile_module $cur_name "blk_mq_alloc_disk(NULL, NULL, NULL);" "linux/blk-mq.h"
then
echo $cur_name 1 >> $config_file_path
elif compile_module $cur_name "blk_mq_alloc_disk(NULL, NULL);" "linux/blk-mq.h"
then
echo $cur_name 2 >> $config_file_path
elif compile_module $cur_name "alloc_disk(0);" "linux/genhd.h"
then
echo $cur_name 3 >> $config_file_path
else
echo $cur_name X >> $config_file_path
fi
}
apply() {
case "$1" in
"1")
add_function "
static inline int cas_alloc_mq_disk(struct gendisk **gd, struct request_queue **queue,
struct blk_mq_tag_set *tag_set)
{
*gd = blk_mq_alloc_disk(tag_set, NULL, NULL);
if (IS_ERR(*gd))
return PTR_ERR(*gd);
*queue = (*gd)->queue;
return 0;
}"
add_function "
static inline void cas_cleanup_mq_disk(struct gendisk *gd)
{
cas_cleanup_disk(gd);
}"
;;
"2")
add_function "
static inline int cas_alloc_mq_disk(struct gendisk **gd, struct request_queue **queue,
struct blk_mq_tag_set *tag_set)
{
*gd = blk_mq_alloc_disk(tag_set, NULL);
if (IS_ERR(*gd))
return PTR_ERR(*gd);
*queue = (*gd)->queue;
return 0;
}"
add_function "
static inline void cas_cleanup_mq_disk(struct gendisk *gd)
{
cas_cleanup_disk(gd);
}"
;;
"3")
add_function "
static inline int cas_alloc_mq_disk(struct gendisk **gd, struct request_queue **queue,
struct blk_mq_tag_set *tag_set)
{
*gd = alloc_disk(1);
if (!(*gd))
return -ENOMEM;
*queue = blk_mq_init_queue(tag_set);
if (IS_ERR_OR_NULL(*queue)) {
put_disk(*gd);
return -ENOMEM;
}
(*gd)->queue = *queue;
return 0;
}"
add_function "
static inline void cas_cleanup_mq_disk(struct gendisk *gd)
{
blk_cleanup_queue(gd->queue);
gd->queue = NULL;
put_disk(gd);
}"
;;
*)
exit 1
esac
}
conf_run $@