linux-apfs / linux-apfs-rw

APFS module for linux, with experimental write support
GNU General Public License v2.0
510 stars 34 forks source link

Failed to compile on RHEL 9 with Linux 5.14.0 #26

Closed lingrottin closed 2 years ago

lingrottin commented 2 years ago

When I was trying to compile this, it reports that there was an error in super.c.

Compilation log
make -C /lib/modules/5.14.0-70.13.1.el9_0.x86_64/build M=/home/tienyu/linux-apfs-rw
make[1]: Entering directory '/usr/src/kernels/5.14.0-70.13.1.el9_0.x86_64'
  CC [M]  /home/tienyu/linux-apfs-rw/btree.o
  CC [M]  /home/tienyu/linux-apfs-rw/compress.o
  CC [M]  /home/tienyu/linux-apfs-rw/dir.o
  CC [M]  /home/tienyu/linux-apfs-rw/extents.o
  CC [M]  /home/tienyu/linux-apfs-rw/file.o
  CC [M]  /home/tienyu/linux-apfs-rw/inode.o
  CC [M]  /home/tienyu/linux-apfs-rw/key.o
  CC [M]  /home/tienyu/linux-apfs-rw/message.o
  CC [M]  /home/tienyu/linux-apfs-rw/namei.o
  CC [M]  /home/tienyu/linux-apfs-rw/node.o
  CC [M]  /home/tienyu/linux-apfs-rw/object.o
  CC [M]  /home/tienyu/linux-apfs-rw/spaceman.o
  CC [M]  /home/tienyu/linux-apfs-rw/super.o
/home/tienyu/linux-apfs-rw/super.c: In function 'apfs_setup_bdi':
/home/tienyu/linux-apfs-rw/super.c:1073:31: error: 'struct block_device' has no member named 'bd_bdi'
 1073 |         bdi_dev = nxi->nx_bdev->bd_bdi;
      |                               ^~
make[2]: *** [scripts/Makefile.build:271: /home/tienyu/linux-apfs-rw/super.o] Error 1
make[1]: *** [Makefile:1862: /home/tienyu/linux-apfs-rw] Error 2
make[1]: Leaving directory '/usr/src/kernels/5.14.0-70.13.1.el9_0.x86_64'
make: *** [Makefile:16: default] Error 2

However I looked into super.c then and found a piece of code which detects kernel version:

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 15, 0)
        bdi_dev = nxi->nx_bdev->bd_bdi;
#else
        bdi_dev = nxi->nx_bdev->bd_disk->bdi;
#endif

I tried deleting the whole part and use bdi_dev = nxi->nx_bdev->bd_disk->bdi; (i.e. the one for Linux 5.15+) only and it compiled successfully. That's pretty wired since I'm on Red Hat Enterprise Linux 9 and my kernel version is 5.14.0.

My kernel info (uname -a)
Linux TienyusRHEL 5.14.0-70.13.1.el9_0.x86_64 #1 SMP PREEMPT Thu Apr 14 12:42:38 EDT 2022 x86_64 x86_64 x86_64 GNU/Linux

Is there any way to work it out? Thank you for your work!

eafer commented 2 years ago

Hi, sorry for the delay, I'm not getting email notifications from github for some reason. As for your problem, it's possible that I made a mistake with the version number check. I'll take a look and get back to you.

eafer commented 2 years ago

The version checks were correct, the problem is that your rhel kernel has picked up this change from 5.15, so I added a separate check for rhel. When you can let me know if this works for you, it looks correct but I don't have any rhel vms to test it on.

Damenly commented 2 years ago

Right, redhat backports patches from the mainstream but RHEL version never changes (except RHEL 8->9) so version judge fails on RHEL. FACEPALM.

lingrottin commented 2 years ago

I pulled down the newest source, checked out the development branch and tried to compile it on my RHEL server. It was compiled successfully without modifying the code then. The kernel is still on 5.14.0, so obviously the patch is correct. Thanks for your work!