Skip to content

Commit

Permalink
Support kernel 6.11
Browse files Browse the repository at this point in the history
Signed-off-by: Robert Baldyga <robert.baldyga@huawei.com>
  • Loading branch information
robertbaldyga authored and Kamil Gierszewski committed Nov 5, 2024
1 parent 576eaca commit d1d3ca4
Show file tree
Hide file tree
Showing 12 changed files with 295 additions and 43 deletions.
32 changes: 26 additions & 6 deletions configure.d/1_bd_first_part.conf
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@
check() {
cur_name=$(basename $2)
config_file_path=$1
if compile_module $cur_name "struct gendisk *disk = NULL; struct xarray xa; xa = disk->part_tbl;" "linux/genhd.h" ||
compile_module $cur_name "struct gendisk *disk = NULL; struct xarray xa; xa = disk->part_tbl;" "linux/blkdev.h"
if compile_module $cur_name "struct block_device bd; bdev_partno;" "linux/blkdev.h"
then
echo $cur_name "1" >> $config_file_path
elif compile_module $cur_name "struct block_device bd; bd = *disk_part_iter_next(NULL);" "linux/blk_types.h" "linux/genhd.h"
elif compile_module $cur_name "struct gendisk *disk = NULL; struct xarray xa; xa = disk->part_tbl;" "linux/genhd.h" ||
compile_module $cur_name "struct gendisk *disk = NULL; struct xarray xa; xa = disk->part_tbl;" "linux/blkdev.h"
then
echo $cur_name "2" >> $config_file_path
elif compile_module $cur_name "struct hd_struct hd; hd = *disk_part_iter_next(NULL);" "linux/genhd.h"
elif compile_module $cur_name "struct block_device bd; bd = *disk_part_iter_next(NULL);" "linux/blk_types.h" "linux/genhd.h"
then
echo $cur_name "3" >> $config_file_path
elif compile_module $cur_name "struct hd_struct hd; hd = *disk_part_iter_next(NULL);" "linux/genhd.h"
then
echo $cur_name "4" >> $config_file_path
else
echo $cur_name "X" >> $config_file_path
fi
Expand All @@ -37,7 +40,7 @@ apply() {
unsigned long idx;
xa_for_each(&disk->part_tbl, idx, part) {
if ((part_no = part->bd_partno)) {
if ((part_no = bdev_partno(part))) {
break;
}
}
Expand All @@ -47,6 +50,23 @@ apply() {
"2")
add_function "
static inline int cas_bd_get_next_part(struct block_device *bd)
{
int part_no = 0;
struct gendisk *disk = bd->bd_disk;
struct block_device *part;
unsigned long idx;
xa_for_each(&disk->part_tbl, idx, part) {
if ((part_no = part->bd_partno)) {
break;
}
}
return part_no;
}" ;;
"3")
add_function "
static inline int cas_bd_get_next_part(struct block_device *bd)
{
int part_no = 0;
struct gendisk *disk = bd->bd_disk;
Expand All @@ -66,7 +86,7 @@ apply() {
return part_no;
}" ;;
"3")
"4")
add_function "
static inline int cas_bd_get_next_part(struct block_device *bd)
{
Expand Down
48 changes: 48 additions & 0 deletions configure.d/1_queue_discard.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/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_queue_max_discard_sectors(NULL, 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_function "
static inline void cas_queue_max_discard_sectors(
struct request_queue *q,
unsigned int max_discard_sectors)
{
blk_queue_max_discard_sectors(q, max_discard_sectors);
}" ;;
"2")
add_function "
static inline void cas_queue_max_discard_sectors(
struct request_queue *q,
unsigned int max_discard_sectors)
{
struct queue_limits *lim = &q->limits;
lim->max_hw_discard_sectors = max_discard_sectors;
lim->max_discard_sectors =
min(max_discard_sectors, lim->max_user_discard_sectors);
}" ;;
*)
exit 1
esac
}

conf_run $@
88 changes: 67 additions & 21 deletions configure.d/1_queue_limits.conf
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,25 @@ check() {
cur_name=$(basename $2)
config_file_path=$1

if compile_module $cur_name "struct queue_limits q; q.limits_aux;" "linux/blkdev.h"
if compile_module $cur_name "struct queue_limits q; q.max_write_zeroes_sectors;" "linux/blkdev.h"
then
echo $cur_name "1" >> $config_file_path
elif compile_module $cur_name "struct queue_limits q; q.max_write_zeroes_sectors;" "linux/blkdev.h"
then
if compile_module $cur_name "struct queue_limits q; q.max_write_same_sectors;" "linux/blkdev.h"
if compile_module $cur_name "struct queue_limits q; q.misaligned;" "linux/blkdev.h"
then
echo $cur_name "2" >> $config_file_path
if compile_module $cur_name "struct queue_limits q; q.max_write_same_sectors;" "linux/blkdev.h"
then
echo $cur_name "1" >> $config_file_path
else
echo $cur_name "2" >> $config_file_path
fi
else
echo $cur_name "3" >> $config_file_path
fi
elif compile_module $cur_name "struct queue_limits q; q.max_write_same_sectors;" "linux/blkdev.h"
then
echo $cur_name "4" >> $config_file_path
elif compile_module $cur_name "struct queue_limits q; q.limits_aux;" "linux/blkdev.h"
then
echo $cur_name "5" >> $config_file_path
else
echo $cur_name "X" >> $config_file_path
fi
Expand All @@ -38,30 +43,22 @@ apply() {
static inline void cas_copy_queue_limits(struct request_queue *exp_q,
struct queue_limits *cache_q_limits, struct request_queue *core_q)
{
struct queue_limits_aux *l_aux = exp_q->limits.limits_aux;
exp_q->limits = *cache_q_limits;
exp_q->limits.limits_aux = l_aux;
if (exp_q->limits.limits_aux && cache_q_limits->limits_aux)
*exp_q->limits.limits_aux = *cache_q_limits->limits_aux;
exp_q->limits.max_sectors = core_q->limits.max_sectors;
exp_q->limits.max_hw_sectors = core_q->limits.max_hw_sectors;
exp_q->limits.max_segments = core_q->limits.max_segments;
exp_q->limits.max_write_same_sectors = 0;
exp_q->limits.max_write_zeroes_sectors = 0;
}"

# A workaround for RHEL/CentOS 7.3 bug in kernel.
# Merging implementation on blk-mq does not respect virt boundary
# restriction and front merges bios with non-zero offsets.
# This leads to request with gaps between bios and in consequence
# triggers BUG_ON() in nvme driver or silently corrupts data.
# To prevent this, disable merging on cache queue if there are
# requirements regarding virt boundary (marking bios with REQ_NOMERGE
# does not solve this problem).
add_function "
static inline void cas_cache_set_no_merges_flag(struct request_queue *cache_q)
{
if (queue_virt_boundary(cache_q))
queue_flag_set(QUEUE_FLAG_NOMERGES, cache_q);
}
static inline bool cas_queue_limits_is_misaligned(
struct queue_limits *lim)
{
return lim->misaligned;
}" ;;
"2")
add_function "
Expand All @@ -72,13 +69,17 @@ apply() {
exp_q->limits.max_sectors = core_q->limits.max_sectors;
exp_q->limits.max_hw_sectors = core_q->limits.max_hw_sectors;
exp_q->limits.max_segments = core_q->limits.max_segments;
exp_q->limits.max_write_same_sectors = 0;
exp_q->limits.max_write_zeroes_sectors = 0;
}"

add_function "
static inline void cas_cache_set_no_merges_flag(struct request_queue *cache_q)
{
}
static inline bool cas_queue_limits_is_misaligned(
struct queue_limits *lim)
{
return lim->misaligned;
}" ;;
"3")
add_function "
Expand All @@ -95,6 +96,11 @@ apply() {
add_function "
static inline void cas_cache_set_no_merges_flag(struct request_queue *cache_q)
{
}
static inline bool cas_queue_limits_is_misaligned(
struct queue_limits *lim)
{
return lim->features & BLK_FLAG_MISALIGNED;
}" ;;
"4")
add_function "
Expand All @@ -111,6 +117,46 @@ apply() {
add_function "
static inline void cas_cache_set_no_merges_flag(struct request_queue *cache_q)
{
}
static inline bool cas_queue_limits_is_misaligned(
struct queue_limits *lim)
{
return lim->misaligned;
}" ;;
"5")
add_function "
static inline void cas_copy_queue_limits(struct request_queue *exp_q,
struct queue_limits *cache_q_limits, struct request_queue *core_q)
{
struct queue_limits_aux *l_aux = exp_q->limits.limits_aux;
exp_q->limits = *cache_q_limits;
exp_q->limits.limits_aux = l_aux;
if (exp_q->limits.limits_aux && cache_q_limits->limits_aux)
*exp_q->limits.limits_aux = *cache_q_limits->limits_aux;
exp_q->limits.max_sectors = core_q->limits.max_sectors;
exp_q->limits.max_hw_sectors = core_q->limits.max_hw_sectors;
exp_q->limits.max_segments = core_q->limits.max_segments;
exp_q->limits.max_write_same_sectors = 0;
}"

# A workaround for RHEL/CentOS 7.3 bug in kernel.
# Merging implementation on blk-mq does not respect virt boundary
# restriction and front merges bios with non-zero offsets.
# This leads to request with gaps between bios and in consequence
# triggers BUG_ON() in nvme driver or silently corrupts data.
# To prevent this, disable merging on cache queue if there are
# requirements regarding virt boundary (marking bios with REQ_NOMERGE
# does not solve this problem).
add_function "
static inline void cas_cache_set_no_merges_flag(struct request_queue *cache_q)
{
if (queue_virt_boundary(cache_q))
queue_flag_set(QUEUE_FLAG_NOMERGES, cache_q);
}
static inline bool cas_queue_limits_is_misaligned(
struct queue_limits *lim)
{
return lim->misaligned;
}" ;;


Expand Down
39 changes: 39 additions & 0 deletions configure.d/1_queue_nonrot.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/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 "(int)QUEUE_FLAG_NONROT;" "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_function "
static inline void cas_queue_set_nonrot(struct request_queue *q)
{
q->queue_flags |= (1 << QUEUE_FLAG_NONROT);
}" ;;
"2")
add_function "
static inline void cas_queue_set_nonrot(struct request_queue *q)
{
}" ;;
*)
exit 1
esac
}

conf_run $@
12 changes: 7 additions & 5 deletions configure.d/2_alloc_disk.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ check() {
apply() {
case "$1" in
"1")
add_typedef "struct queue_limits cas_queue_limits_t;"
add_function "
static inline int cas_alloc_mq_disk(struct gendisk **gd, struct request_queue **queue,
struct blk_mq_tag_set *tag_set)
struct blk_mq_tag_set *tag_set, cas_queue_limits_t *lim)
{
*gd = blk_mq_alloc_disk(tag_set, NULL, NULL);
*gd = blk_mq_alloc_disk(tag_set, lim, NULL);
if (!(*gd))
return -ENOMEM;
Expand All @@ -48,9 +49,10 @@ apply() {
;;

"2")
add_typedef "void* cas_queue_limits_t;"
add_function "
static inline int cas_alloc_mq_disk(struct gendisk **gd, struct request_queue **queue,
struct blk_mq_tag_set *tag_set)
struct blk_mq_tag_set *tag_set, cas_queue_limits_t *lim)
{
*gd = blk_mq_alloc_disk(tag_set, NULL);
if (!(*gd))
Expand All @@ -68,10 +70,10 @@ apply() {
;;

"3")

add_typedef "void* cas_queue_limits_t;"
add_function "
static inline int cas_alloc_mq_disk(struct gendisk **gd, struct request_queue **queue,
struct blk_mq_tag_set *tag_set)
struct blk_mq_tag_set *tag_set, cas_queue_limits_t *lim)
{
*gd = alloc_disk(1);
if (!(*gd))
Expand Down
Loading

0 comments on commit d1d3ca4

Please sign in to comment.