shared/sleep-config: make swap detection stricter again
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 7 Jan 2020 15:44:12 +0000 (16:44 +0100)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 8 Jan 2020 07:07:14 +0000 (08:07 +0100)
commit8efc2c1608afa5bf8d857d4ea335c88cf6b6192b
treea7d4f59ae10d9771f550ebedd0915778330c4292
parente9f0c5d08c6590c37d92dbdcf402706613d6daeb
shared/sleep-config: make swap detection stricter again

To make this easier to understand, let's always log (at debug level)
when we accept or reject each device:
/swapfile: detection of swap file offset on Btrfs is not supported
/swapfile: is a candidate device.
/dev/zram0: ignoring zram swap
/dev/vdb: ignoring device with lower priority
/dev/vdc: ignoring device with lower usable space
...

If we know that hibernation will fail, refuse. This includes cases where
/sys/power/resume is set and doesn't match any device, or
/sys/power/resume_offset is set and we're not on btrfs and it doesn't match.
If /sys/power/resume is not set at all, we still accept the device with the
highest priority (see 6d176522f5480ea9e9a83de5ef5ea5e0d95b79cb and
88bc86fcf895da0d51ddaf93d17b4280f4e60d74)

Tested cases:
1. no swap active → refuse
2. just zram swap active → refuse
3. swapfile on btrfs with /sys/power/resume{,_offset} set → OK
4. swapfile on btrfs with /sys/power/resume set, offset not set → refuse
5. swapfile on btrfs with /sys/power/resume set to nonexistent device, offset set → refuse
6. /sys/power/resume not set, offset set, candidate exists → OK (*)
7. /sys/power/resume not set, offset not set, candidate exists → OK

(*) I think this should fail, but I'm leaving that for the next commit.
src/shared/sleep-config.c