diff options
author | Mario Limonciello <mario.limonciello@dell.com> | 2018-03-08 02:41:50 -0600 |
---|---|---|
committer | Mario Limonciello <mario.limonciello@dell.com> | 2018-04-09 13:17:56 -0500 |
commit | 17c40b3a8fbfb797110c88d749bd5d37e6ee6e3c (patch) | |
tree | 70376ccc4a6c11a49c52fb0944001434f05f9a9f /src/test/test-sleep.c | |
parent | c75436067f4b392ecf161e123279720dc5c3b33a (diff) | |
download | systemd-17c40b3a8fbfb797110c88d749bd5d37e6ee6e3c.tar.gz |
sleep: Add support for setting a disk offset when hibernating
The Linux kernel is adding support for configuring the offset
into a disk. This allows swapfiles to be more usable as users
will no longer need to set the offset on their kernel command
line.
Use this API in systemd when hibernating as well.
Signed-off-by: Mario Limonciello <mario.limonciello@dell.com>
Diffstat (limited to 'src/test/test-sleep.c')
-rw-r--r-- | src/test/test-sleep.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/src/test/test-sleep.c b/src/test/test-sleep.c index cea511d8b8..05fd6c0abf 100644 --- a/src/test/test-sleep.c +++ b/src/test/test-sleep.c @@ -18,13 +18,43 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include <linux/fiemap.h> #include <stdio.h> +#include "fd-util.h" #include "log.h" #include "sleep-config.h" #include "strv.h" #include "util.h" +static int test_fiemap(const char *path) { + _cleanup_free_ struct fiemap *fiemap = NULL; + _cleanup_close_ int fd = -1; + int r; + + fd = open(path, O_RDONLY | O_CLOEXEC | O_NONBLOCK); + if (fd < 0) + return log_error_errno(errno, "failed to open %s: %m", path); + r = read_fiemap(fd, &fiemap); + if (r == -ENOTSUP) { + log_info("Skipping test, not supported"); + exit(EXIT_TEST_SKIP); + } + if (r < 0) + return log_error_errno(r, "Unable to read extent map for '%s': %m", path); + log_info("extent map information for %s:", path); + log_info("\t start: %llu", fiemap->fm_start); + log_info("\t length: %llu", fiemap->fm_length); + log_info("\t flags: %u", fiemap->fm_flags); + log_info("\t number of mapped extents: %u", fiemap->fm_mapped_extents); + log_info("\t extent count: %u", fiemap->fm_extent_count); + if (fiemap->fm_extent_count > 0) + log_info("\t first extent location: %llu", + fiemap->fm_extents[0].fe_physical / page_size()); + + return 0; +} + static void test_sleep(void) { _cleanup_strv_free_ char **standby = strv_new("standby", NULL), @@ -52,6 +82,8 @@ static void test_sleep(void) { } int main(int argc, char* argv[]) { + int i, r = 0, k; + log_parse_environment(); log_open(); @@ -60,5 +92,14 @@ int main(int argc, char* argv[]) { test_sleep(); - return 0; + if (argc <= 1) + assert_se(test_fiemap(argv[0]) == 0); + else + for (i = 1; i < argc; i++) { + k = test_fiemap(argv[i]); + if (r == 0) + r = k; + } + + return r; } |