Skip to content

Commit

Permalink
[KERNEL] Fix compile for 6.11+
Browse files Browse the repository at this point in the history
  • Loading branch information
srett committed Dec 11, 2024
1 parent ae91f37 commit 02b42e0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 16 deletions.
35 changes: 26 additions & 9 deletions src/kernel/blk.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,17 @@ static int dnbd3_blk_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
dev->use_server_provided_alts = msg->use_server_provided_alts;

dev_info(dnbd3_device_to_dev(dev), "opening device.\n");
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 11, 0)
/* nothing to do here, set at creation time */
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0)
// set optimal request size for the queue to half the read-ahead
blk_queue_io_opt(dev->queue, (msg->read_ahead_kb * 512));
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 0) \
# if LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 0) \
&& !RHEL_CHECK_VERSION(RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(9, 0))
// set readahead from optimal request size of the queue
// ra_pages are calculated by following formula: queue_io_opt() * 2 / PAGE_SIZE
blk_queue_update_readahead(dev->queue);
#endif
# endif
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(4, 11, 0)
if (blk_queue->backing_dev_info != NULL)
blk_queue->backing_dev_info->ra_pages = (msg->read_ahead_kb * 1024) / PAGE_SIZE;
Expand Down Expand Up @@ -386,6 +388,7 @@ struct blk_mq_ops dnbd3_mq_ops = {
.timeout = dnbd3_rq_timeout,
};

#define ONE_MEG (1048576)
int dnbd3_blk_add_device(dnbd3_device_t *dev, int minor)
{
int ret;
Expand Down Expand Up @@ -429,7 +432,21 @@ int dnbd3_blk_add_device(dnbd3_device_t *dev, int minor)

#if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 14, 0)
// set up blk-mq and disk
# if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 11, 0)
do {
struct queue_limits lim = {
.logical_block_size = DNBD3_BLOCK_SIZE, // in bytes
.physical_block_size = DNBD3_BLOCK_SIZE, // in bytes
.io_opt = ONE_MEG >> 2, // 256kb
.max_hw_sectors = ONE_MEG >> SECTOR_SHIFT, // in 512byte sectors
.max_segments = USHRT_MAX,
.max_segment_size = UINT_MAX,
};
dev->disk = blk_mq_alloc_disk(&dev->tag_set, &lim, dev);
} while (0);
# else
dev->disk = blk_mq_alloc_disk(&dev->tag_set, dev);
# endif
if (IS_ERR(dev->disk)) {
dev_err(dnbd3_device_to_dev(dev), "blk_mq_alloc_disk failed\n");
ret = PTR_ERR(dev->disk);
Expand All @@ -447,20 +464,19 @@ int dnbd3_blk_add_device(dnbd3_device_t *dev, int minor)
dev->queue->queuedata = dev;
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 11, 0)
blk_queue_logical_block_size(dev->queue, DNBD3_BLOCK_SIZE);
blk_queue_physical_block_size(dev->queue, DNBD3_BLOCK_SIZE);
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0)
# if LINUX_VERSION_CODE >= KERNEL_VERSION(4, 17, 0)
blk_queue_flag_set(QUEUE_FLAG_NONROT, dev->queue);
blk_queue_flag_clear(QUEUE_FLAG_ADD_RANDOM, dev->queue);
#else
# else
queue_flag_set_unlocked(QUEUE_FLAG_NONROT, dev->queue);
#endif
#define ONE_MEG (1048576)
# endif
blk_queue_max_segment_size(dev->queue, ONE_MEG);
blk_queue_max_segments(dev->queue, 0xffff);
blk_queue_max_hw_sectors(dev->queue, ONE_MEG / DNBD3_BLOCK_SIZE);
dev->queue->limits.max_sectors = 256;
#undef ONE_MEG
#endif

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 14, 0)
// set up disk
Expand Down Expand Up @@ -517,6 +533,7 @@ int dnbd3_blk_add_device(dnbd3_device_t *dev, int minor)
mutex_destroy(&dev->alt_servers_lock);
return ret;
}
#undef ONE_MEG

int dnbd3_blk_del_device(dnbd3_device_t *dev)
{
Expand Down
14 changes: 7 additions & 7 deletions src/kernel/sysfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
/**
* Print currently connected server IP:PORT
*/
ssize_t show_cur_server_addr(char *buf, dnbd3_device_t *dev)
static ssize_t show_cur_server_addr(char *buf, dnbd3_device_t *dev)
{
ssize_t ret;

Expand All @@ -44,7 +44,7 @@ ssize_t show_cur_server_addr(char *buf, dnbd3_device_t *dev)
* List alt servers. One line per server, format is:
* IP:PORT RTT consecutive_failures best_count
*/
ssize_t show_alt_servers(char *buf, dnbd3_device_t *dev)
static ssize_t show_alt_servers(char *buf, dnbd3_device_t *dev)
{
int i, size = PAGE_SIZE;
ssize_t ret;
Expand Down Expand Up @@ -78,7 +78,7 @@ ssize_t show_alt_servers(char *buf, dnbd3_device_t *dev)
/**
* Show name of image in use
*/
ssize_t show_image_name(char *buf, dnbd3_device_t *dev)
static ssize_t show_image_name(char *buf, dnbd3_device_t *dev)
{
ssize_t ret;

Expand All @@ -91,13 +91,13 @@ ssize_t show_image_name(char *buf, dnbd3_device_t *dev)
/**
* Show rid of image in use
*/
ssize_t show_rid(char *buf, dnbd3_device_t *dev)
static ssize_t show_rid(char *buf, dnbd3_device_t *dev)
{
// No locking here, primitive type, no pointer to allocated memory
return MIN(snprintf(buf, PAGE_SIZE, "%d\n", dev->rid), PAGE_SIZE);
}

ssize_t show_update_available(char *buf, dnbd3_device_t *dev)
static ssize_t show_update_available(char *buf, dnbd3_device_t *dev)
{
// Same story
return MIN(snprintf(buf, PAGE_SIZE, "%d\n", dev->update_available), PAGE_SIZE);
Expand Down Expand Up @@ -133,7 +133,7 @@ device_attr_t update_available = {
.store = NULL,
};

ssize_t device_show(struct kobject *kobj, struct attribute *attr, char *buf)
static ssize_t device_show(struct kobject *kobj, struct attribute *attr, char *buf)
{
device_attr_t *device_attr = container_of(attr, device_attr_t, attr);
dnbd3_device_t *dev = container_of(kobj, dnbd3_device_t, kobj);
Expand All @@ -157,7 +157,7 @@ const struct sysfs_ops device_ops = {
.show = device_show,
};

void release(struct kobject *kobj)
static void release(struct kobject *kobj)
{
kobj->state_initialized = 0;
}
Expand Down

0 comments on commit 02b42e0

Please sign in to comment.