loopdev icon indicating copy to clipboard operation
loopdev copied to clipboard

Use LOOP_CONFIGURE ioctl for attaching to loop devices

Open player-two opened this issue 3 years ago • 2 comments

This ioctl was added to Linux0 as a faster and atomic alternative to the combination of LOOP_SET_FD and LOOP_SET_STATUS. In order to support older kernels, the function will still fallback to those syscalls if necessary.

The attach_a_backing_file_with_part_scan_default test passed, and I verified the functionality in my project that uses this crate. I was only able to test on a recent kernel:

$ uname -r
6.0.6-arch1-1

strace confirmed that the new ioctl was being used.

I can build an old kernel to try the fallback behavior, but I have not made time for that yet.

player-two avatar Nov 06 '22 14:11 player-two

I implemented a kernel version check and depending on the result a feature loop_configure is enabled or not:

https://github.com/flxo/loopdev/tree/loop-configure

The most interesting part is that the binding generation must be moved in to a -sys crate in order to access the LINUX_KERNEL_VERSION constant from the loopdev build script.

flxo avatar Nov 07 '22 08:11 flxo

FYI. Rebased the POC.

flxo avatar Apr 19 '23 08:04 flxo