>From f3472f84e44ccf41010aecc3971801c8825ae045 Mon Sep 17 00:00:00 2001 From: Ferenc Wagner Date: Sat, 14 Nov 2009 01:25:05 +0100 Subject: [PATCH] Add debugging around syscalls and ioctls --- suspend.c | 22 +++++++++++++++++++--- swsusp.h | 29 ++++++++++++++++++++++++++--- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/suspend.c b/suspend.c index 5248dba..6a7dbb4 100644 --- a/suspend.c +++ b/suspend.c @@ -295,17 +295,26 @@ static int atomic_snapshot(int dev, int *in_suspend) { int error; + fprintf (stderr, "SNAPSHOT_CREATE_IMAGE...\n"); error = ioctl(dev, SNAPSHOT_CREATE_IMAGE, in_suspend); + fprintf (stderr, "SNAPSHOT_CREATE_IMAGE: %d\n", error); if (error && errno == ENOTTY) { report_unsupported_ioctl("SNAPSHOT_CREATE_IMAGE"); + fprintf (stderr, "SNAPSHOT_ATOMIC_SNAPSHOT...\n"); error = ioctl(dev, SNAPSHOT_ATOMIC_SNAPSHOT, in_suspend); + fprintf (stderr, "SNAPSHOT_ATOMIC_SNAPSHOT: %d\n", error); } return error; } static inline int free_snapshot(int dev) { - return ioctl(dev, SNAPSHOT_FREE, 0); + int error; + + fprintf (stderr, "SNAPSHOT_FREE...\n"); + error = ioctl(dev, SNAPSHOT_FREE, 0); + fprintf (stderr, "SNAPSHOT_FREE: %d\n", error); + return error; } static int set_image_size(int dev, unsigned int size) @@ -329,10 +338,14 @@ static int platform_enter(int dev) { int error; + fprintf (stderr, "SNAPSHOT_POWER_OFF...\n"); error = ioctl(dev, SNAPSHOT_POWER_OFF, 0); + fprintf (stderr, "SNAPSHOT_POWER_OFF: %d\n", error); if (error && errno == ENOTTY) { report_unsupported_ioctl("SNAPSHOT_POWER_OFF"); + fprintf (stderr, "SNAPSHOT_PMOPS(PMOPS_ENTER)...\n"); error = ioctl(dev, SNAPSHOT_PMOPS, PMOPS_ENTER); + fprintf (stderr, "SNAPSHOT_PMOPS(PMOPS_ENTER): %d\n", error); } return error; } @@ -1258,7 +1271,7 @@ static int flush_buffer(struct swap_writer *handle) */ static int save_image(struct swap_writer *handle, unsigned int nr_pages) { - unsigned int m, writeout_rate; + unsigned int m, writeout_rate, expected_nr_pages = nr_pages; ssize_t ret; struct termios newtrm, savedtrm; int abort_possible, key, error = 0; @@ -1350,7 +1363,7 @@ static int save_image(struct swap_writer *handle, unsigned int nr_pages) if (!error) error = save_extents(handle, 1); if (!error) - printf(" done (%u pages)\n", nr_pages); + printf(" done (%u pages of expected %u)\n", nr_pages, expected_nr_pages); } Exit: @@ -1670,12 +1683,15 @@ static void suspend_shutdown(int snapshot_fd) splash.set_caption("Done."); if (shutdown_method == SHUTDOWN_METHOD_REBOOT) { + fprintf (stderr, "Shutdown method was REBOOT, so rebooting...\n"); reboot(); } else if (shutdown_method == SHUTDOWN_METHOD_PLATFORM) { + fprintf (stderr, "Shutdown method was PLATFORM, so entering...\n"); if (platform_enter(snapshot_fd)) suspend_error("Could not enter the hibernation state, " "calling power_off."); } + fprintf (stderr, "Shutdown method was SHUTDOWN or something went wrong, so powering off...\n"); power_off(); /* Signature is on disk, it is very dangerous to continue now. * We'd do resume with stale caches on next boot. */ diff --git a/swsusp.h b/swsusp.h index e6abc83..fe47702 100644 --- a/swsusp.h +++ b/swsusp.h @@ -90,41 +90,64 @@ static inline void report_unsupported_ioctl(char *name) static inline int freeze(int dev) { - return ioctl(dev, SNAPSHOT_FREEZE, 0); + int error; + + fprintf (stderr, "SNAPSHOT_FREEZE...\n"); + error = ioctl(dev, SNAPSHOT_FREEZE, 0); + fprintf (stderr, "SNAPSHOT_FREEZE: %d\n", error); + return error; } static inline int unfreeze(int dev) { - return ioctl(dev, SNAPSHOT_UNFREEZE, 0); + int error; + + fprintf (stderr, "SNAPSHOT_UNFREEZE...\n"); + error = ioctl(dev, SNAPSHOT_UNFREEZE, 0); + fprintf (stderr, "SNAPSHOT_UNFREEZE: %d\n", error); + return error; } static inline int platform_prepare(int dev) { int error; + fprintf (stderr, "SNAPSHOT_PLATFORM_SUPPORT(1)...\n"); error = ioctl(dev, SNAPSHOT_PLATFORM_SUPPORT, 1); + fprintf (stderr, "SNAPSHOT_PLATFORM_SUPPORT(1): %d\n", error); if (error && errno == ENOTTY) { report_unsupported_ioctl("SNAPSHOT_PLATFORM_SUPPORT"); + fprintf (stderr, "SNAPSHOT_PMOPS(PMOPS_PREPARE)...\n"); error = ioctl(dev, SNAPSHOT_PMOPS, PMOPS_PREPARE); + fprintf (stderr, "SNAPSHOT_PMOPS(PMOPS_PREPARE): %d\n", error); } return error; } static inline int platform_finish(int dev) { - return ioctl(dev, SNAPSHOT_PMOPS, PMOPS_FINISH); + int error; + + fprintf (stderr, "SNAPSHOT_PMOPS(PMOPS_FINISH)...\n"); + error = ioctl(dev, SNAPSHOT_PMOPS, PMOPS_FINISH); + fprintf (stderr, "SNAPSHOT_PMOPS(PMOPS_FINISH): %d\n", error); + return error; } static inline void reboot(void) { + fprintf (stderr, "reboot syscall...\n"); syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_RESTART, 0); + fprintf (stderr, "reboot syscall failed!\n"); } static inline void power_off(void) { + fprintf (stderr, "power off syscall...\n"); syscall(SYS_reboot, LINUX_REBOOT_MAGIC1, LINUX_REBOOT_MAGIC2, LINUX_REBOOT_CMD_POWER_OFF, 0); + fprintf (stderr, "power off syscall failed!\n"); } #ifndef SYS_sync_file_range -- 1.5.6.5