From: "Rafael J. Wysocki" <rjw@sisk.pl>
To: Jiri Slaby <jslaby@suse.cz>
Cc: jirislaby@gmail.com, pavel@ucw.cz,
linux-pm@lists.linux-foundation.org,
linux-kernel@vger.kernel.org,
Nigel Cunningham <ncunningham@crca.org.au>
Subject: Re: [RFC 05/15] PM / Hibernate: group swap ops
Date: Thu, 25 Mar 2010 22:28:25 +0100 [thread overview]
Message-ID: <201003252228.25665.rjw@sisk.pl> (raw)
In-Reply-To: <1269361063-3341-5-git-send-email-jslaby@suse.cz>
On Tuesday 23 March 2010, Jiri Slaby wrote:
> Move all the swap processing into one function. It will make swap
> calls from a non-swap code easier.
>
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Nigel Cunningham <ncunningham@crca.org.au>
> Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
Looks good.
Rafael
> ---
> kernel/power/swap.c | 117 ++++++++++++++++++++++++++++++++-------------------
> 1 files changed, 74 insertions(+), 43 deletions(-)
>
> diff --git a/kernel/power/swap.c b/kernel/power/swap.c
> index a1cff28..2edf742 100644
> --- a/kernel/power/swap.c
> +++ b/kernel/power/swap.c
> @@ -207,9 +207,10 @@ static int mark_swapfiles(struct swap_map_handle *handle, unsigned int flags)
> /**
> * swsusp_swap_check - check if the resume device is a swap device
> * and get its index (if so)
> + *
> + * This is called before saving image
> */
> -
> -static int swsusp_swap_check(void) /* This is called before saving image */
> +static int swsusp_swap_check(void)
> {
> int res;
>
> @@ -268,17 +269,33 @@ static void release_swap_writer(struct swap_map_handle *handle)
>
> static int get_swap_writer(struct swap_map_handle *handle)
> {
> + int ret;
> +
> + ret = swsusp_swap_check();
> + if (ret) {
> + if (ret != -ENOSPC)
> + printk(KERN_ERR "PM: Cannot find swap device, try "
> + "swapon -a.\n");
> + return ret;
> + }
> handle->cur = (struct swap_map_page *)get_zeroed_page(GFP_KERNEL);
> - if (!handle->cur)
> - return -ENOMEM;
> + if (!handle->cur) {
> + ret = -ENOMEM;
> + goto err_close;
> + }
> handle->cur_swap = alloc_swapdev_block(root_swap);
> if (!handle->cur_swap) {
> - release_swap_writer(handle);
> - return -ENOSPC;
> + ret = -ENOSPC;
> + goto err_rel;
> }
> handle->k = 0;
> handle->first_sector = handle->cur_swap;
> return 0;
> +err_rel:
> + release_swap_writer(handle);
> +err_close:
> + swsusp_close(FMODE_WRITE);
> + return ret;
> }
>
> static int swap_write_page(struct swap_map_handle *handle, void *buf,
> @@ -321,6 +338,24 @@ static int flush_swap_writer(struct swap_map_handle *handle)
> return -EINVAL;
> }
>
> +static int put_swap_writer(struct swap_map_handle *handle,
> + unsigned int flags, int error)
> +{
> + if (!error) {
> + flush_swap_writer(handle);
> + printk(KERN_INFO "PM: S");
> + error = mark_swapfiles(handle, flags);
> + printk("|\n");
> + }
> +
> + if (error)
> + free_all_swap_pages(root_swap);
> + release_swap_writer(handle);
> + swsusp_close(FMODE_WRITE);
> +
> + return error;
> +}
> +
> /**
> * save_image - save the suspend image data
> */
> @@ -398,48 +433,34 @@ int swsusp_write(unsigned int flags)
> struct swap_map_handle handle;
> struct snapshot_handle snapshot;
> struct swsusp_info *header;
> + unsigned long pages;
> int error;
>
> - error = swsusp_swap_check();
> + pages = snapshot_get_image_size();
> + error = get_swap_writer(&handle);
> if (error) {
> - printk(KERN_ERR "PM: Cannot find swap device, try "
> - "swapon -a.\n");
> + printk(KERN_ERR "PM: Cannot get swap writer\n");
> return error;
> }
> + if (!enough_swap(pages)) {
> + printk(KERN_ERR "PM: Not enough free swap\n");
> + error = -ENOSPC;
> + goto out_finish;
> + }
> memset(&snapshot, 0, sizeof(struct snapshot_handle));
> error = snapshot_read_next(&snapshot);
> if (error < PAGE_SIZE) {
> if (error >= 0)
> error = -EFAULT;
>
> - goto out;
> + goto out_finish;
> }
> header = (struct swsusp_info *)data_of(snapshot);
> - if (!enough_swap(header->pages)) {
> - printk(KERN_ERR "PM: Not enough free swap\n");
> - error = -ENOSPC;
> - goto out;
> - }
> - error = get_swap_writer(&handle);
> - if (!error) {
> - error = swap_write_page(&handle, header, NULL);
> - if (!error)
> - error = save_image(&handle, &snapshot,
> - header->pages - 1);
> -
> - if (!error) {
> - flush_swap_writer(&handle);
> - printk(KERN_INFO "PM: S");
> - error = mark_swapfiles(&handle, flags);
> - printk("|\n");
> - }
> - }
> - if (error)
> - free_all_swap_pages(root_swap);
> -
> - release_swap_writer(&handle);
> - out:
> - swsusp_close(FMODE_WRITE);
> + error = swap_write_page(&handle, header, NULL);
> + if (!error)
> + error = save_image(&handle, &snapshot, pages - 1);
> +out_finish:
> + error = put_swap_writer(&handle, flags, error);
> return error;
> }
>
> @@ -455,18 +476,21 @@ static void release_swap_reader(struct swap_map_handle *handle)
> handle->cur = NULL;
> }
>
> -static int get_swap_reader(struct swap_map_handle *handle, sector_t start)
> +static int get_swap_reader(struct swap_map_handle *handle,
> + unsigned int *flags_p)
> {
> int error;
>
> - if (!start)
> + *flags_p = swsusp_header->flags;
> +
> + if (!swsusp_header->image) /* how can this happen? */
> return -EINVAL;
>
> handle->cur = (struct swap_map_page *)get_zeroed_page(__GFP_WAIT | __GFP_HIGH);
> if (!handle->cur)
> return -ENOMEM;
>
> - error = sws_bio_read_page(start, handle->cur, NULL);
> + error = sws_bio_read_page(swsusp_header->image, handle->cur, NULL);
> if (error) {
> release_swap_reader(handle);
> return error;
> @@ -501,6 +525,13 @@ static int swap_read_page(struct swap_map_handle *handle, void *buf,
> return error;
> }
>
> +static int put_swap_reader(struct swap_map_handle *handle)
> +{
> + release_swap_reader(handle);
> +
> + return 0;
> +}
> +
> /**
> * load_image - load the image using the swap map handle
> * @handle and the snapshot handle @snapshot
> @@ -570,20 +601,20 @@ int swsusp_read(unsigned int *flags_p)
> struct snapshot_handle snapshot;
> struct swsusp_info *header;
>
> - *flags_p = swsusp_header->flags;
> -
> memset(&snapshot, 0, sizeof(struct snapshot_handle));
> error = snapshot_write_next(&snapshot);
> if (error < PAGE_SIZE)
> return error < 0 ? error : -EFAULT;
> header = (struct swsusp_info *)data_of(snapshot);
> - error = get_swap_reader(&handle, swsusp_header->image);
> + error = get_swap_reader(&handle, flags_p);
> + if (error)
> + goto end;
> if (!error)
> error = swap_read_page(&handle, header, NULL);
> if (!error)
> error = load_image(&handle, &snapshot, header->pages - 1);
> - release_swap_reader(&handle);
> -
> + put_swap_reader(&handle);
> +end:
> if (!error)
> pr_debug("PM: Image successfully loaded\n");
> else
>
next prev parent reply other threads:[~2010-03-25 21:25 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-23 16:17 [RFC 01/15] FS: libfs, implement simple_write_to_buffer Jiri Slaby
2010-03-23 16:17 ` [RFC 02/15] PM / Hibernate: snapshot cleanup Jiri Slaby
2010-03-24 20:29 ` Pavel Machek
2010-03-24 22:35 ` Rafael J. Wysocki
2010-03-25 5:29 ` Pavel Machek
2010-03-23 16:17 ` [RFC 03/15] PM / Hibernate: separate block_io Jiri Slaby
2010-03-24 20:30 ` Pavel Machek
2010-03-24 21:22 ` Jiri Slaby
2010-03-24 22:58 ` Nigel Cunningham
2010-03-25 2:35 ` [linux-pm] " Nigel Cunningham
2010-03-25 20:12 ` Rafael J. Wysocki
2010-03-25 20:13 ` Nigel Cunningham
2010-03-25 20:33 ` Rafael J. Wysocki
2010-03-25 20:36 ` Nigel Cunningham
2010-03-29 13:30 ` Pavel Machek
2010-03-25 14:29 ` Pavel Machek
2010-03-23 16:17 ` [RFC 04/15] PM / Hibernate: move the first_sector out of swsusp_write Jiri Slaby
2010-03-24 20:31 ` Pavel Machek
2010-03-25 21:26 ` Rafael J. Wysocki
2010-03-23 16:17 ` [RFC 05/15] PM / Hibernate: group swap ops Jiri Slaby
2010-03-25 21:28 ` Rafael J. Wysocki [this message]
2010-03-23 16:17 ` [RFC 06/15] PM / Hibernate: swap, remove swap_map_handle usages Jiri Slaby
2010-03-24 20:33 ` Pavel Machek
2010-03-24 21:29 ` Jiri Slaby
2010-03-25 21:35 ` Rafael J. Wysocki
2010-03-23 16:17 ` [RFC 07/15] PM / Hibernate: add sws_modules_ops Jiri Slaby
2010-03-24 20:36 ` Pavel Machek
2010-03-24 21:31 ` Jiri Slaby
2010-03-25 22:02 ` Rafael J. Wysocki
2010-03-23 16:17 ` [RFC 08/15] PM / Hibernate: add user module_ops Jiri Slaby
2010-03-25 22:07 ` Rafael J. Wysocki
2010-03-26 9:43 ` Jiri Slaby
2010-03-23 16:17 ` [RFC 09/15] PM / Hibernate: user, implement user_ops writer Jiri Slaby
2010-03-24 20:42 ` Pavel Machek
2010-03-24 21:40 ` Jiri Slaby
2010-03-25 21:36 ` Pavel Machek
2010-03-25 22:14 ` Rafael J. Wysocki
2010-03-26 9:34 ` Jiri Slaby
2010-03-26 22:04 ` Rafael J. Wysocki
2010-03-29 15:33 ` Jiri Slaby
2010-03-27 7:02 ` Pavel Machek
2010-03-23 16:17 ` [RFC 10/15] PM / Hibernate: user, implement user_ops reader Jiri Slaby
2010-03-25 5:30 ` what the patches do " Pavel Machek
2010-03-25 5:42 ` Nigel Cunningham
2010-03-25 6:12 ` [linux-pm] " Nigel Cunningham
2010-03-25 20:14 ` Rafael J. Wysocki
2010-03-25 20:21 ` Nigel Cunningham
2010-03-25 20:29 ` Rafael J. Wysocki
2010-03-25 20:35 ` Nigel Cunningham
2010-03-25 21:13 ` Rafael J. Wysocki
2010-03-25 21:26 ` Pavel Machek
2010-03-25 21:49 ` [linux-pm] " Nigel Cunningham
2010-04-02 6:36 ` Pavel Machek
2010-04-02 17:03 ` Rafael J. Wysocki
2010-03-25 22:21 ` Rafael J. Wysocki
2010-03-23 16:17 ` [RFC 11/15] PM / Hibernate: add chunk i/o support Jiri Slaby
2010-03-25 22:38 ` Rafael J. Wysocki
2010-03-26 9:09 ` Jiri Slaby
2010-03-26 10:02 ` Nigel Cunningham
2010-03-23 16:17 ` [RFC 12/15] PM / Hibernate: split snapshot_read_next Jiri Slaby
2010-03-25 22:44 ` Rafael J. Wysocki
2010-03-23 16:17 ` [RFC 13/15] PM / Hibernate: split snapshot_write_next Jiri Slaby
2010-03-25 22:46 ` Rafael J. Wysocki
2010-03-23 16:17 ` [RFC 14/15] PM / Hibernate: dealign swsusp_info Jiri Slaby
2010-03-25 22:46 ` Rafael J. Wysocki
2010-03-23 16:17 ` [RFC 15/15] PM / Hibernate: move non-swap code to snapshot.c Jiri Slaby
2010-03-25 22:50 ` Rafael J. Wysocki
2010-03-23 21:51 ` [RFC 01/15] FS: libfs, implement simple_write_to_buffer Rafael J. Wysocki
2010-03-23 22:09 ` [linux-pm] " Nigel Cunningham
2010-03-24 22:13 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201003252228.25665.rjw@sisk.pl \
--to=rjw@sisk.pl \
--cc=jirislaby@gmail.com \
--cc=jslaby@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@lists.linux-foundation.org \
--cc=ncunningham@crca.org.au \
--cc=pavel@ucw.cz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome