Commit Graph
26 Commits
Author SHA1 Message Date
Yu Watanabe fbf6836812 tree-wide: include missing_fs.h only where necessary
The additional definitions provided by the header are
- EXT4_IOC_RESIZE_FS, used in resize-fs.c,
- FILEID_KERNFS, used in cgroup-util.c and pidfd-util.c.

Let's drop the inclusion at other places.
2025-06-25 00:50:06 +09:00
Zbigniew Jędrzejewski-Szmek 42ba99748d various: do not include file names directly in error messages
git grep -l 'Failed to open /'|xargs sed -r -i 's|"Failed to open (/[^ ]+): %m"|"Failed to open %s: %m", "\1"|g'
git grep -l $'Failed to open \'/'|xargs sed -r -i $'s|"Failed to open \'(/[^ ]+)\': %m"|"Failed to open %s: %m", "\\1"|g'
git grep -l "Failed to open /"|xargs sed -r -i $'s|"Failed to open (/[^ ]+), ignoring: %m"|"Failed to open %s, ignoring: %m", "\\1"|g'
+ some manual fixups.
2025-06-02 11:10:38 +02:00
Daan De Meyer 69a283c5f2 shared: Clean up includes
Split out of #37344.
2025-05-24 14:00:44 +02:00
Mike Yuan 15036f8555 fileio: modernize get_proc_field()
- Drop effectively unused "terminator" param, imply whitespace
- Make ret param optional
- Return ENODATA if the requested key is not found, rather than
  ENOENT
- Turn ENOENT -> ENOSYS if /proc/ is not mounted
- Don't skip whitespaces before ':', nothing needs this handling
  anyways
- Remove the special treatment for all "0"s. We don't actually
  use this for capabilities given pidref_get_capability() exists
- Switch away from read_full_virtual_file() - files using "field"
  scheme under /proc/ seem all to be "seq_file"s (refer to
  da65941c3e for details on file types)
2025-05-01 13:10:26 +09:00
Yu Watanabe ec32732043 basic: introduce our own sys/mount.h implementation
To resolve conflict with sys/mount.h and linux/mount.h or linux/fs.h.

The conflict between sys/mount.h and linux/mount.h is resolved in
glibc-2.37 (774058d72942249f71d74e7f2b639f77184160a6), but our baseline
is still glibc-2.31. Also, even with the version or newer, still
sys/mount.h conflicts with linux/fs.h, which is included by
linux/btrfs.h.

This introduces our own implementation of sys/mount.h, that can be
simultaneously included with linux/mount.h and linux/fs.h. This also
imports linux/fs.h, linux/mount.h, and several other dependent headers.
The introduced sys/mount.h header itself may not be enough simple, but
by using the header, we can drop most of workarounds in other source files.
2025-03-04 02:24:49 +09:00
Mike Yuan de69879b62 shared/hibernate-util: drop support for kernels lacking /sys/power/resume_offset
The current fallback path is actually unreliable, given
the kernel *supports* setting the resume offset through
cmdline after all, but just not exposed under /sys/.
For v258 let's drop it hence.

I didn't bump the baseline to 4.17, but merely documented
new requirement in README, because there's certainly more
compat stuff to drop between 4.3 and 4.17, and README is
a useful list for things to kill. We'll get to 5.4 eventually.
2025-01-02 15:55:33 +01:00
Mike Yuan bd3d361580 shared/hibernate-util: handle the case where no swap has available backing dev
This also makes find_suitable_hibernation_device() report
more accurate error (ENOSPC -> ESTALE) if there's
no swap space on the system at all but resume= is set.

Fixes #35798
Replaces #35801
2025-01-02 15:29:34 +01:00
Mike YuanandYu Watanabe 6d3b2273b1 shared/hibernate-util: don't attempt to fiemap fd if no backing dev available
Prompted by #35798

Co-authored-by: Yu Watanabe <watanabe.yu+github@gmail.com>
2025-01-02 15:29:32 +01:00
Daan De Meyer d5c12da904 efivars: Remove STRINGIFY() helper macros
The names of these conflict with macros from efi.h that we'll move
to efi-fundamental.h in a later commit. Let's avoid the conflict by
getting rid of these helpers. Arguably this also improves readability
by clearly indicating we're passing arbitrary strings and not constants
to the macros when we invoke them.
2024-11-02 23:20:57 +01:00
Mike Yuan 3fce141c1b hibernate-util,logind: also differentiate the case of misconfigured resume 2024-05-08 12:55:25 +08:00
Mike Yuan 40eb83a8fe hibernate-util,logind: emit a clear error if the specified resume dev is missing
Currently, SLEEP_NOT_ENOUGH_SWAP_SPACE (ENOSPC) is returned
on all sorts of error conditions. But one important case
that's worth differentiating from that is when the resume device
is manually specified yet missing.

Closes #32644
2024-05-08 12:54:13 +08:00
Mike Yuan b8b0704ce9 hibernate-util: check 'noresume' before reading resume setting
Also hibernation_is_safe() should really take this
into consideration too.
2024-04-07 23:28:56 +01:00
Mike Yuan 166ad35fa8 hibernate-util: say "HibernateLocation EFI variable" consistently 2024-04-05 02:59:59 +08:00
Mike Yuan fbc88824b6 hibernate-util: make clear_efi_hibernate_location_and_warn return 1 if
actually cleared the variable
2024-04-03 21:59:59 +08:00
Mike Yuan 46ce85bf7f hibernate-util: log that we actually read /sys/power/resume* rather than cmdline
/sys/power/resume is always populated by the initrd, while
/sys/power/resume_offset might have been populated by
the kernel itself. Therefore, if the user is using an initrd
that doesn't include resume hook, the hibernation would fail,
which is expected. However, it was hard to track down the real
problem, since the previous log message suggested that resume=
is not set through kernel cmdline.
2024-01-17 16:10:14 +00:00
Mike Yuan 6e819bd2bd hibernate-util: remove unused code
All callers of write_resume_config() pass non-NULL device.
2023-12-27 22:38:42 +08:00
Mike Yuan 66b9956082 hibernate-util: make sure we use blockdev path for HibernationDevice.path
Before this commit, this field could spuriously contain the path of the
swapfile.
2023-12-27 22:38:42 +08:00
Mike Yuan 8ad973ed99 hibernate-util: de-duplicate clear_efi_hibernate_location 2023-12-10 14:08:46 +09:00
Mike Yuan 232efdc5bd hibernate-util: return 1 for hibernation_is_safe only when all checks pass
The return value is currently not used, but let's correct this.
2023-12-05 16:52:19 +08:00
Mike Yuan 0e8f09561f hibernate-util: if asked to bypass space check, accept the case when we
have no swap space at all

But I shall still recommend
https://chrisdown.name/2018/01/02/in-defence-of-swap.html
to everyone ;-)

Fixes #30083
2023-11-18 20:15:42 +08:00
Mike Yuan 500ec22d09 hibernate-util: report no available swap as no enough swap space
Otherwise, ENOENT or ENXIO may be directly returned as error through
bus.

Should help to generate clearer error message for #30083.
2023-11-18 20:15:41 +08:00
Mike Yuan 080105d77a hibernate-util: add missing assertion 2023-10-23 23:12:27 +08:00
Mike Yuan 805deec039 hibernate-util: introduce hibernation_is_safe
After 7470b80763, we refuse
to hibernate if we fail to write HibernateLocation EFI
variable and resume= is not set. Let's teach sleep_supported
to follow the practice too.
2023-10-20 23:22:54 +08:00
Mike Yuan 596873c10c hibernate-util: rework find_hibernate_location
* "HibernateLocation" struct is renamed to HibernationDevice
  to avoid ambiguity with the EFI variable. Also, it no longer
  takes the reference to a SwapEntry object, since it's really
  unnecessary (only SwapEntry.path is used), but increases complexity.
* SwapEntry is no longer used externally.
* find_hibernate_location is split into read_swap_entries and
  find_suitable_hibernation_device. The former reads all swap entries
  into SwapEntries object for later use.
* Make use of btrfs_get_file_physical_offset_fd

Closes #25130
2023-10-20 23:22:54 +08:00
Mike Yuan 2abc3c6d48 hibernate-util: read_fiemap: add missing asserts 2023-10-20 23:22:28 +08:00
Mike Yuan 54d7fcc6a3 sleep-util: split into sleep-config and hibernate-util 2023-09-27 21:48:39 +08:00