Граф коммитов

69 Коммитов

Автор SHA1 Сообщение Дата
Leandro Pereira bad888c69b Convert README to README.md 2021-06-29 12:56:51 -07:00
Leandro Pereira 6fe522404a Respect CFLAGS and LDFLAGS passed to the make command line 2021-06-29 12:56:51 -07:00
Leandro Pereira 7e35951c2c Re-indent az-hibernate-agent.c according to .clang-format rules 2021-06-29 12:56:51 -07:00
Leandro Pereira 5dff8f6357 Add "indent" Makefile target to indent code with clang-format
Also add a slightly-tweaked .clang-format file that is as close as
the indentation style in the original program as possible.
2021-06-29 12:56:51 -07:00
Leandro Pereira 0d64d84f3b Add notice about trademarks 2021-06-29 12:56:51 -07:00
Leandro Pereira 29d9d05654 FIXME comments aren't relevant anymore 2021-06-24 12:35:06 -07:00
Leandro Pereira 71ed53e25e Fix refactoring leftovers in try_vspawn_and_wait() 2021-06-22 11:14:36 -07:00
Leandro Pereira 3ca4170b07 Fix refactoring leftovers in log_impl() 2021-06-22 11:14:36 -07:00
Leandro Pereira 32399bd8cc Fix build due to missing includes in some systems 2021-06-22 11:14:36 -07:00
Leandro Pereira 2e5404ee28 Remove FIXME from VM host notification message 2021-06-22 11:14:36 -07:00
Leandro Pereira a3c2382076 Do not proceed if running in a container
Remove a FIXME comment and check if we're running in a container by looking at
/proc/1/cgroup. Running in a container will most likely fail as this will try
to write things in the root directory, modify boot loader settings, etc.
2021-06-22 11:14:36 -07:00
Leandro Pereira c5ffa16c42 Use PATH_MAX instead of hardcoded integer 2021-06-22 11:14:36 -07:00
Leandro Pereira d12f0d017a Store state to notify VM host if hibernation succeeded 2021-06-22 11:14:36 -07:00
Leandro Pereira 302d162dda Clarify amount of space that's required if fallocate() call fails 2021-06-22 11:14:36 -07:00
Leandro Pereira 2d5afb9f8f Remove needless __builtin_unreachable() 2021-06-22 11:14:36 -07:00
Leandro Pereira 37209a085e If an unknown hibernation mode has been detected, bail out 2021-06-22 11:14:36 -07:00
Leandro Pereira 5e27f9691a Also use syslog to publish log messages 2021-06-22 11:14:36 -07:00
Leandro Pereira 5167b6de8c Add an is_hyperv() predicate 2021-06-22 11:14:36 -07:00
Leandro Pereira 90471cc68c Allow log messages to be prefixed with a global flag 2021-06-22 11:14:36 -07:00
Leandro Pereira 9795cbcd96 Remove unnecessary __bultin_unreachable() after log_fatal() 2021-06-22 11:14:36 -07:00
Leandro Pereira 1510eda0e5 Extend maximum supported amount of RAM for hibernation 2021-06-22 11:14:36 -07:00
Leandro Pereira eb4051bf6e Factor va_list -> char *[] into function that actually uses it
Cuts down some copy/pasted code.
2021-06-22 11:14:36 -07:00
Leandro A. F. Pereira 9e720ea485
Build on Ubuntu 2021-04-27 14:39:26 -07:00
Leandro Pereira 4809adbb95 Avoid memory allocation when searching for the path of an executable 2021-04-27 11:12:08 -07:00
Leandro Pereira 273e3045a1 Add missing parameter to call to log_fatal() 2021-04-27 11:01:35 -07:00
Leandro Pereira 291503e890 Location of systemctl can't be hardcoded in udev rule
Some distributions put it in different locations, so detect it when writing
the file.
2021-04-27 11:01:25 -07:00
Leandro Pereira e8de11fe22 Better detection of hibernation support
This will check hibernation first by looking for "platform" in
/sys/power/disk.  If found, then nothing else will be done.  Other
methods will be then checked, but unless we're running in a Hyper-V
environment with /sys/bus/vmbus/hibernation present and contains "1",
hibernation will be considered disabled for this VM.
2021-04-23 14:07:15 -07:00
Leandro Pereira bea90169bb If enabling a swap file that was already there fails, bail out 2021-04-23 13:59:00 -07:00
Leandro Pereira 1210f6146d Ensure swap partition has correct permissions
While the file is created with 0600 permissions, might be a good idea to
chmod() it before calling swapon() just for good measure.
2021-04-23 13:59:00 -07:00
Leandro Pereira 85e6fbe430 Remove trailing whitespaces 2021-04-23 13:07:23 -07:00
Leandro Pereira cd065ee1ec Defragmentation may fail, so don't abort if that's the case 2021-04-23 13:07:23 -07:00
Leandro Pereira 502305a582 Ensure udev rules are installed and activated as well
Hibernating through the API in Azure will trigger a non-standard uevent, so we need
to install an udev rule to hibernate the VM and notify udev about it.
2021-04-23 12:40:43 -07:00
Leandro Pereira b1dd32d1cd Fix build error after 23c5e351 2021-04-14 09:27:42 -07:00
Leandro Pereira 9af9c6ad78 Avoid using ftruncate() if the swap file is on XFS 2021-04-13 15:03:10 -07:00
Leandro Pereira d246313231 next_field() might return NULL 2021-04-13 14:40:46 -07:00
Leandro Pereira 78ac2541dc Add support for grub2-mkconfig 2021-04-13 14:19:50 -07:00
Leandro Pereira 30243c4d28 No need to allocate the pattern to warm up a swap file 2021-04-13 14:19:13 -07:00
Leandro Pereira 23c5e35105 Try to defragment swap file on XFS partitions as well
Since the patch was intertwined with a check to abort the agent if running
on Linux kernel before 5.0 with a Btrfs filesystem (which isn't supported),
this change adds this functionality as well.
2021-04-13 14:16:28 -07:00
Leandro Pereira 9c70dbc298 "-fno-plt" isn't available in older GCC versions 2021-04-13 10:34:48 -07:00
Leandro Pereira e3c278f658 Fix path of /etc/default/grub 2021-04-13 10:04:17 -07:00
Leandro Pereira f7c0f23e66 Print path to GRUB configuration file 2021-04-12 15:44:30 -07:00
Leandro Pereira 0b6a0c8995 "az-hibernate-agent" string is redundant on logs, remove it 2021-04-12 14:09:36 -07:00
Leandro Pereira b257540f3c Reorganize is_hibernation_enabled_for_vm()
With this change, we first check /sys/power/disk for supported hibernation
modes, and print out the ones that we know will work to hibernate a machine,
but bail out if none of those are found.

Then, we probe /sys/bus/vmbus/hibernation to determine if hibernation has
been enabled in Hyper-V as well.  If so, then we proceed as usual.  If not,
we don't continue.

At this point, we also verify if /sys/bus/vmbus exists as a way to determine
if we're running on a Hyper-V VM.  This is just to print a better log message
to aid in debugging should the hibernation file not be present.
2021-04-12 14:04:04 -07:00
Leandro Pereira 85489d22d5 Build with -std=gnu11, as -std=gnu17 doesn't seem to be widely supported 2021-04-12 13:38:41 -07:00
Leandro Pereira 8bb79d88fd Support /etc/default/grub.d for Grub configuration
In some systems, particularly systems set up with an image from the Azure
Marketplace, will have configuration files in that directory that will
override the default settings as found in /etc/default/grub, effectively
making our changes meaningless.

Change it so that, if /etc/default/grub.d exists, we create a file with
higher priority instead, that will add new kernel command line parameters
on top of whatever the marketplace configuration file did.
2021-04-12 10:05:15 -07:00
Leandro Pereira 5432140110 Use a better algorithm to calculate swap size for hibernation 2021-04-07 14:14:09 -07:00
Leandro Pereira b3e98b1d98 Fix typo in error message 2021-03-24 15:03:10 -07:00
Leandro Pereira ac995eae8d Add a missing failed malloc() check 2021-03-24 14:50:04 -07:00
Leandro Pereira 136c34f359 Flatten read_first_line_from_file() for readability 2021-03-24 14:04:37 -07:00
Leandro Pereira 41448d444e Clarify error message if ioctl(FIBMAP) fails 2021-03-24 14:04:37 -07:00