pkoutoupis / rapiddisk

An Advanced Linux RAM Drive and Caching kernel modules. Dynamically allocate RAM as block devices. Use them as stand alone drives or even map them as caching nodes to slower local disk drives. Access those volumes locally or export them across an NVMe Target network. Manage it all from a web API.
http://www.rapiddisk.org
GNU General Public License v2.0
296 stars 49 forks source link

Build error with kernel 6.9 #185

Closed manualinux closed 3 weeks ago

manualinux commented 3 months ago

When compiling the module with kernel 6.9, the following error message occurs:

drivers/block/rapiddisk/rapiddisk.c:809:54: error: too few arguments provided to function-like macro invocation
  809 |         disk = rdsk->rdsk_disk = blk_alloc_disk(NUMA_NO_NODE);
      |                                                             ^
./include/linux/blkdev.h:787:9: note: macro 'blk_alloc_disk' defined here
  787 | #define blk_alloc_disk(lim, node_id)                                    \
      |         ^
drivers/block/rapiddisk/rapiddisk.c:809:27: error: use of undeclared identifier 'blk_alloc_disk'; did you mean '__blk_alloc_disk'?
  809 |         disk = rdsk->rdsk_disk = blk_alloc_disk(NUMA_NO_NODE);
      |                                  ^~~~~~~~~~~~~~
      |                                  __blk_alloc_disk
./include/linux/blkdev.h:772:17: note: '__blk_alloc_disk' declared here
  772 | struct gendisk *__blk_alloc_disk(struct queue_limits *lim, int node,
      |                 ^
drivers/block/rapiddisk/rapiddisk.c:816:54: error: too few arguments provided to function-like macro invocation
  816 |         disk = rdsk->rdsk_disk = blk_alloc_disk(NUMA_NO_NODE);
      |                                                             ^
./include/linux/blkdev.h:787:9: note: macro 'blk_alloc_disk' defined here
  787 | #define blk_alloc_disk(lim, node_id)                                    \
      |         ^
drivers/block/rapiddisk/rapiddisk.c:816:27: error: use of undeclared identifier 'blk_alloc_disk'; did you mean '__blk_alloc_disk'?
  816 |         disk = rdsk->rdsk_disk = blk_alloc_disk(NUMA_NO_NODE);
      |                                  ^~~~~~~~~~~~~~
      |                                  __blk_alloc_disk
./include/linux/blkdev.h:772:17: note: '__blk_alloc_disk' declared here
  772 | struct gendisk *__blk_alloc_disk(struct queue_limits *lim, int node,
      |                 ^
4 errors generated.

Regards

manualinux commented 3 months ago

Hello,

I have taken as a reference the modification of openZFS that can be found here. And I have added the following:

struct queue_limits *lim = NULL;

Modifying the following:

disk = rdsk->rdsk_disk = blk_alloc_disk(lim, NUMA_NO_NODE);

It is obvious that you will have to adapt it depending on the kernel that is used, but with these modifications the compilation can be carried out successfully. If more lines of code need to be added, I leave that up to you.

Regards.

bberberov commented 3 months ago

What is the latest known compatible kernel that works with the 9.1.0 release?

I'm getting the same build errors with 6.9:

...
[   24s] /home/abuild/rpmbuild/BUILD/rapiddisk-9.1.0/obj/default/rapiddisk.c: In function ‘attach_device’:
[   24s] /home/abuild/rpmbuild/BUILD/rapiddisk-9.1.0/obj/default/rapiddisk.c:809:61: error: macro "blk_alloc_disk" requires 2 arguments, but only 1 given
[   24s]   809 |         disk = rdsk->rdsk_disk = blk_alloc_disk(NUMA_NO_NODE);
...

I'd like to try a known working build.

anbe42 commented 1 month ago

While looking at this issue, I noticed that the blk_alloc_disk() call is duplicated, the second one overwriting the result from the first, probably causing some memory leak. So lets drop the duplicate one first:

--- a/module/rapiddisk.c
+++ b/module/rapiddisk.c
@@ -813,13 +813,6 @@ static int attach_device(unsigned long n
        if (!disk)
                goto out_free_queue;
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0)
-       disk = rdsk->rdsk_disk = blk_alloc_disk(NUMA_NO_NODE);
-#else
-       disk = rdsk->rdsk_disk = alloc_disk(1);
-#endif
-       if (!disk)
-               goto out_free_queue;
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0)
        blk_queue_logical_block_size(disk->queue, BYTES_PER_SECTOR);
        blk_queue_physical_block_size(disk->queue, PAGE_SIZE);
 #else
anbe42 commented 1 month ago

Adjust for Linux commit "block: pass a queue_limits argument to blk_alloc_disk" (https://github.com/torvalds/linux/commit/74fa8f9c553f7b5ccab7d103acae63cc2e080465) in v6.9-rc1:

--- a/module/rapiddisk.c
+++ b/module/rapiddisk.c
@@ -805,12 +805,18 @@ static int attach_device(unsigned long n
        blk_queue_make_request(rdsk->rdsk_queue, rdsk_make_request);
 #endif
 #endif
-#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,9,0)
+       disk = rdsk->rdsk_disk = blk_alloc_disk(NULL, NUMA_NO_NODE);
+#elif LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0)
        disk = rdsk->rdsk_disk = blk_alloc_disk(NUMA_NO_NODE);
 #else
        disk = rdsk->rdsk_disk = alloc_disk(1);
 #endif
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(6,9,0)
+       if (IS_ERR(disk))
+#else
        if (!disk)
+#endif
                goto out_free_queue;
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,14,0)
        blk_queue_logical_block_size(disk->queue, BYTES_PER_SECTOR);

In the failure case (IS_ERR(disk)) you could get the actual error returned by the new blk_alloc_disk() with PTR_ERR(disk).

pkoutoupis commented 1 month ago

Can you please create a pull request for me to pull and review/merge into master?

EDIT: Oh, and THANK YOU! :-)

pkoutoupis commented 3 weeks ago

Merged https://github.com/pkoutoupis/rapiddisk/pull/189 to master.