Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upsystemctl hibernate does not hibernate on swapfile on Btrfs after kernel 5.0 #11939
Comments
|
The related discussion to get the physical offset of Btrfs swapfile is in https://bugzilla.kernel.org/show_bug.cgi?id=202803. |
|
Hmm, so why does btrfs not follow the same APIs as other file systems on this? Isn#t this a btrfs interface issue? |
|
I think this is by design for Btrfs since it can handle multiple storage devices. virtual physical offsets are provided to have a consistent view of file addressing. Seems like hibernation on swapfile requires real physical offset to work. |
|
Yes, as @helloworld1 said, Btrfs gives you a virtual device number for stat and a virtual offset for fiemap by design. Even in the single device case, we make use of the virtual offsets to simplify block allocation. In my opinion, the issue is that the hibernate interface is stupid. We should have an interface (system call? ioctl?) that just takes an fd and sets that swap device or file as the resume device. @poettering, would systemd make use of that if we were to implement it in the kernel? Or do you have any better ideas? |
Yes, please add that. Would love to simply remove the previous code then and just use the new API. The ioctl mucking is really terrible for this purpose. |
|
May i ask how would people (with rights to merge pull requests) like to have this one solved? Current status: neither resume, nor resume_offset gets detected properly, yet systemd will override both |
|
anything specified on the kernel cmdline should take precedence over any automatic discovery. Hence, yes, I'd be happy to merge a patch that makes sure we always use the kernel parameters if they are specified. That said, given that btrfs hibernation is a pretty new feature I think we'd also be fine to wait until the kernel learns a new hibernation API that allows us to just pass an fd in, and only support it when that's done. The sleep code could generally use some love though. For example the s2h code uses RTC ioctls, where it probably should just use |
|
I was able to reproduce this bug on a virtual machine running Arch using the steps @helloworld1 provided in the initial report. I did have to use the utility @osandov provided in the issue reported in bugzilla to calculate the offset for I submitted #12760 which solves the general issue of ignoring the The route I took is fairly simple but I think it serves the purpose. Rather than inspecting the kernel cmdline for It does not check for systemd/src/shared/sleep-config.c Line 200 in c5e6f73 If anybody using |
systemd version the issue has been seen with
241.7
Used distribution
Archlinux
Expected behaviour you didn't see
systemctl hibernateshould hibernate on swap file on Btrfs after kernel 5.0Unexpected behaviour you saw
Btrfs supports swapfile after kernel 5.0.
echo disk > /sys/power/stateworks fine to hibernate butsystemctl hibernatefailed.Since Btrfs is using virtual physical offset of the file. The current logic in sleep.c does not get the correct physical offset of the file. The resume_offset kernel parameter is also ignored and overriden by systemd so it is unable to get the correct offset.
systemd/src/sleep/sleep.c
Line 80 in c5e6f73
Steps to reproduce the problem
resume=/dev/nvme1n1p2 resume_offset=52761856
[ 26.828436] PM: Cannot find swap device, try swapon -a
[ 26.828441] PM: Cannot get swap writer