From 45cb875eec416b3237968851ba7cdd1cf7ae1d19 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Fri, 23 Oct 2026 00:41:41 +0200 Subject: [PATCH] configure: Fix compilation on the older kernels Signed-off-by: Robert Baldyga --- configure.d/1_ida_alloc.conf | 56 +++++++++++++++++++++++++++++++++++ configure.d/1_sysfs_emit.conf | 34 +++++++++++++++++++++ modules/cas_bd/exp_obj.c | 6 ++-- 3 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 configure.d/1_ida_alloc.conf create mode 100644 configure.d/1_sysfs_emit.conf diff --git a/configure.d/1_ida_alloc.conf b/configure.d/1_ida_alloc.conf new file mode 100644 index 000000000..a92dd2937 --- /dev/null +++ b/configure.d/1_ida_alloc.conf @@ -0,0 +1,56 @@ +#!/bin/bash +# +# Copyright(c) 2026 Unvertical +# SPDX-License-Identifier: BSD-3-Clause +# + +. $(dirname $3)/conf_framework.sh + +# ida_alloc_max()/ida_free() were introduced in v4.19; older kernels only +# have ida_simple_get()/ida_simple_remove(), which were removed in v6.9. +check() { + cur_name=$(basename $2) + config_file_path=$1 + if compile_module $cur_name "ida_alloc_max(NULL, 0, GFP_KERNEL);" "linux/idr.h" + then + echo $cur_name "1" >> $config_file_path + elif compile_module $cur_name "ida_simple_get(NULL, 0, 0, GFP_KERNEL);" "linux/idr.h" + then + echo $cur_name "2" >> $config_file_path + else + echo $cur_name "X" >> $config_file_path + fi +} + +apply() { + case "$1" in + "1") + add_function " + static inline int cas_ida_alloc_max(struct ida *ida, unsigned int max, + gfp_t gfp) + { + return ida_alloc_max(ida, max, gfp); + }" + add_function " + static inline void cas_ida_free(struct ida *ida, unsigned int id) + { + ida_free(ida, id); + }" ;; + "2") + add_function " + static inline int cas_ida_alloc_max(struct ida *ida, unsigned int max, + gfp_t gfp) + { + return ida_simple_get(ida, 0, max + 1, gfp); + }" + add_function " + static inline void cas_ida_free(struct ida *ida, unsigned int id) + { + ida_simple_remove(ida, id); + }" ;; + *) + exit 1 + esac +} + +conf_run $@ diff --git a/configure.d/1_sysfs_emit.conf b/configure.d/1_sysfs_emit.conf new file mode 100644 index 000000000..24c37db86 --- /dev/null +++ b/configure.d/1_sysfs_emit.conf @@ -0,0 +1,34 @@ +#!/bin/bash +# +# Copyright(c) 2026 Unvertical +# SPDX-License-Identifier: BSD-3-Clause +# + +. $(dirname $3)/conf_framework.sh + +# sysfs_emit() was introduced in v5.10. +check() { + cur_name=$(basename $2) + config_file_path=$1 + if compile_module $cur_name "sysfs_emit(NULL, \"\");" "linux/sysfs.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_sysfs_emit(buf, fmt, ...) \\ + sysfs_emit(buf, fmt, ##__VA_ARGS__)" ;; + "2") + add_define "cas_sysfs_emit(buf, fmt, ...) \\ + scnprintf(buf, PAGE_SIZE, fmt, ##__VA_ARGS__)" ;; + *) + exit 1 + esac +} + +conf_run $@ diff --git a/modules/cas_bd/exp_obj.c b/modules/cas_bd/exp_obj.c index 4506f4b9c..ae37da5e4 100644 --- a/modules/cas_bd/exp_obj.c +++ b/modules/cas_bd/exp_obj.c @@ -117,13 +117,13 @@ static CAS_MAKE_REQ_RET_TYPE _cas_exp_obj_make_rq_fn(struct request_queue *q, static int _cas_exp_obj_allocate_minor_slot(void) { - return ida_alloc_max(&exp_obj_global.minor_ida, + return cas_ida_alloc_max(&exp_obj_global.minor_ida, CAS_MINOR_SLOT_MAX, GFP_KERNEL); } static void _cas_exp_obj_free_minor_slot(int slot) { - ida_free(&exp_obj_global.minor_ida, slot); + cas_ida_free(&exp_obj_global.minor_ida, slot); } static int _cas_exp_obj_set_dev_t(struct cas_exp_obj *exp_obj, @@ -301,7 +301,7 @@ static ssize_t device_attr_serial_show(struct device *dev, struct gendisk *gd = dev_to_disk(dev); struct cas_exp_obj *exp_obj = gd->private_data; - return sysfs_emit(buf, "opencas-%s", exp_obj->dev_name); + return cas_sysfs_emit(buf, "opencas-%s", exp_obj->dev_name); } static struct device_attribute device_attr_serial =