From: Pavel Machek <pavel@ucw.cz>
To: Jiri Slaby <jslaby@suse.cz>
Cc: jirislaby@gmail.com, linux-pm@lists.linux-foundation.org,
linux-kernel@vger.kernel.org,
Nigel Cunningham <ncunningham@crca.org.au>,
"Rafael J. Wysocki" <rjw@sisk.pl>
Subject: Re: [RFC 06/15] PM / Hibernate: swap, remove swap_map_handle usages
Date: Wed, 24 Mar 2010 21:33:30 +0100 [thread overview]
Message-ID: <20100324203329.GG5798@elf.ucw.cz> (raw)
In-Reply-To: <1269361063-3341-6-git-send-email-jslaby@suse.cz>
On Tue 2010-03-23 17:17:34, Jiri Slaby wrote:
> Some code, which will be moved out of swap.c, needs know nothing about
> swap. There will be also other than swap writers later, so that it
> won't make sense at all.
>
> Make it a global static in swap.c as a singleton.
I guess I just dislike global static. Logically, methods do operate on
handles, so...
I don't see a point and I do not think the change is an improvement.
Pavel
> Signed-off-by: Jiri Slaby <jslaby@suse.cz>
> Cc: Nigel Cunningham <ncunningham@crca.org.au>
> Cc: "Rafael J. Wysocki" <rjw@sisk.pl>
> ---
> kernel/power/swap.c | 58 +++++++++++++++++++++++++-------------------------
> 1 files changed, 29 insertions(+), 29 deletions(-)
>
> diff --git a/kernel/power/swap.c b/kernel/power/swap.c
> index 2edf742..ac1a351 100644
> --- a/kernel/power/swap.c
> +++ b/kernel/power/swap.c
> @@ -70,6 +70,7 @@ struct swsusp_header {
> char sig[10];
> } __attribute__((packed));
>
> +static struct swap_map_handle swap_map_handle;
> static struct swsusp_header *swsusp_header;
>
> /**
> @@ -267,8 +268,9 @@ static void release_swap_writer(struct swap_map_handle *handle)
> handle->cur = NULL;
> }
>
> -static int get_swap_writer(struct swap_map_handle *handle)
> +static int get_swap_writer(void)
> {
> + struct swap_map_handle *handle = &swap_map_handle;
> int ret;
>
> ret = swsusp_swap_check();
> @@ -278,6 +280,7 @@ static int get_swap_writer(struct swap_map_handle *handle)
> "swapon -a.\n");
> return ret;
> }
> + memset(handle, 0, sizeof(*handle));
> handle->cur = (struct swap_map_page *)get_zeroed_page(GFP_KERNEL);
> if (!handle->cur) {
> ret = -ENOMEM;
> @@ -298,9 +301,9 @@ err_close:
> return ret;
> }
>
> -static int swap_write_page(struct swap_map_handle *handle, void *buf,
> - struct bio **bio_chain)
> +static int swap_write_page(void *buf, struct bio **bio_chain)
> {
> + struct swap_map_handle *handle = &swap_map_handle;
> int error = 0;
> sector_t offset;
>
> @@ -338,9 +341,10 @@ 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)
> +static int put_swap_writer(unsigned int flags, int error)
> {
> + struct swap_map_handle *handle = &swap_map_handle;
> +
> if (!error) {
> flush_swap_writer(handle);
> printk(KERN_INFO "PM: S");
> @@ -360,8 +364,7 @@ static int put_swap_writer(struct swap_map_handle *handle,
> * save_image - save the suspend image data
> */
>
> -static int save_image(struct swap_map_handle *handle,
> - struct snapshot_handle *snapshot,
> +static int save_image(struct snapshot_handle *snapshot,
> unsigned int nr_to_write)
> {
> unsigned int m;
> @@ -384,7 +387,7 @@ static int save_image(struct swap_map_handle *handle,
> ret = snapshot_read_next(snapshot);
> if (ret <= 0)
> break;
> - ret = swap_write_page(handle, data_of(*snapshot), &bio);
> + ret = swap_write_page(data_of(*snapshot), &bio);
> if (ret)
> break;
> if (!(nr_pages % m))
> @@ -430,14 +433,13 @@ static int enough_swap(unsigned int nr_pages)
>
> int swsusp_write(unsigned int flags)
> {
> - struct swap_map_handle handle;
> struct snapshot_handle snapshot;
> struct swsusp_info *header;
> unsigned long pages;
> int error;
>
> pages = snapshot_get_image_size();
> - error = get_swap_writer(&handle);
> + error = get_swap_writer();
> if (error) {
> printk(KERN_ERR "PM: Cannot get swap writer\n");
> return error;
> @@ -456,11 +458,11 @@ int swsusp_write(unsigned int flags)
> goto out_finish;
> }
> header = (struct swsusp_info *)data_of(snapshot);
> - error = swap_write_page(&handle, header, NULL);
> + error = swap_write_page(header, NULL);
> if (!error)
> - error = save_image(&handle, &snapshot, pages - 1);
> + error = save_image(&snapshot, pages - 1);
> out_finish:
> - error = put_swap_writer(&handle, flags, error);
> + error = put_swap_writer(flags, error);
> return error;
> }
>
> @@ -476,9 +478,9 @@ static void release_swap_reader(struct swap_map_handle *handle)
> handle->cur = NULL;
> }
>
> -static int get_swap_reader(struct swap_map_handle *handle,
> - unsigned int *flags_p)
> +static int get_swap_reader(unsigned int *flags_p)
> {
> + struct swap_map_handle *handle = &swap_map_handle;
> int error;
>
> *flags_p = swsusp_header->flags;
> @@ -486,6 +488,7 @@ static int get_swap_reader(struct swap_map_handle *handle,
> if (!swsusp_header->image) /* how can this happen? */
> return -EINVAL;
>
> + memset(handle, 0, sizeof(*handle));
> handle->cur = (struct swap_map_page *)get_zeroed_page(__GFP_WAIT | __GFP_HIGH);
> if (!handle->cur)
> return -ENOMEM;
> @@ -499,9 +502,9 @@ static int get_swap_reader(struct swap_map_handle *handle,
> return 0;
> }
>
> -static int swap_read_page(struct swap_map_handle *handle, void *buf,
> - struct bio **bio_chain)
> +static int swap_read_page(void *buf, struct bio **bio_chain)
> {
> + struct swap_map_handle *handle = &swap_map_handle;
> sector_t offset;
> int error;
>
> @@ -525,22 +528,20 @@ static int swap_read_page(struct swap_map_handle *handle, void *buf,
> return error;
> }
>
> -static int put_swap_reader(struct swap_map_handle *handle)
> +static int put_swap_reader(void)
> {
> - release_swap_reader(handle);
> + release_swap_reader(&swap_map_handle);
>
> return 0;
> }
>
> /**
> - * load_image - load the image using the swap map handle
> + * load_image - load the image
> * @handle and the snapshot handle @snapshot
> * (assume there are @nr_pages pages to load)
> */
>
> -static int load_image(struct swap_map_handle *handle,
> - struct snapshot_handle *snapshot,
> - unsigned int nr_to_read)
> +static int load_image(struct snapshot_handle *snapshot, unsigned int nr_to_read)
> {
> unsigned int m;
> int error = 0;
> @@ -562,7 +563,7 @@ static int load_image(struct swap_map_handle *handle,
> error = snapshot_write_next(snapshot);
> if (error <= 0)
> break;
> - error = swap_read_page(handle, data_of(*snapshot), &bio);
> + error = swap_read_page(data_of(*snapshot), &bio);
> if (error)
> break;
> if (snapshot->sync_read)
> @@ -597,7 +598,6 @@ static int load_image(struct swap_map_handle *handle,
> int swsusp_read(unsigned int *flags_p)
> {
> int error;
> - struct swap_map_handle handle;
> struct snapshot_handle snapshot;
> struct swsusp_info *header;
>
> @@ -606,14 +606,14 @@ int swsusp_read(unsigned int *flags_p)
> if (error < PAGE_SIZE)
> return error < 0 ? error : -EFAULT;
> header = (struct swsusp_info *)data_of(snapshot);
> - error = get_swap_reader(&handle, flags_p);
> + error = get_swap_reader(flags_p);
> if (error)
> goto end;
> if (!error)
> - error = swap_read_page(&handle, header, NULL);
> + error = swap_read_page(header, NULL);
> if (!error)
> - error = load_image(&handle, &snapshot, header->pages - 1);
> - put_swap_reader(&handle);
> + error = load_image(&snapshot, header->pages - 1);
> + put_swap_reader();
> end:
> if (!error)
> pr_debug("PM: Image successfully loaded\n");
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
next prev parent reply other threads:[~2010-03-24 20:33 UTC|newest]
Thread overview: 158+ 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 ` 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 20:29 ` Pavel Machek
2010-03-24 22:35 ` Rafael J. Wysocki
2010-03-24 22:35 ` Rafael J. Wysocki
2010-03-25 5:29 ` Pavel Machek
2010-03-25 5:29 ` Pavel Machek
2010-03-23 16:17 ` Jiri Slaby
2010-03-23 16:17 ` [RFC 03/15] PM / Hibernate: separate block_io Jiri Slaby
2010-03-23 16:17 ` 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-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:12 ` [linux-pm] " Rafael J. Wysocki
2010-03-25 20:13 ` Nigel Cunningham
2010-03-25 20:13 ` [linux-pm] " Nigel Cunningham
2010-03-25 20:33 ` Rafael J. Wysocki
2010-03-25 20:36 ` Nigel Cunningham
2010-03-25 20:36 ` Nigel Cunningham
2010-03-25 20:33 ` Rafael J. Wysocki
2010-03-29 13:30 ` Pavel Machek
2010-03-29 13:30 ` [linux-pm] " Pavel Machek
2010-03-25 2:35 ` Nigel Cunningham
2010-03-25 14:29 ` Pavel Machek
2010-03-25 14:29 ` Pavel Machek
2010-03-24 21:22 ` Jiri Slaby
2010-03-24 20:30 ` Pavel Machek
2010-03-23 16:17 ` [RFC 04/15] PM / Hibernate: move the first_sector out of swsusp_write Jiri Slaby
2010-03-23 16:17 ` Jiri Slaby
2010-03-24 20:31 ` Pavel Machek
2010-03-24 20:31 ` Pavel Machek
2010-03-25 21:26 ` Rafael J. Wysocki
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
2010-03-25 21:28 ` Rafael J. Wysocki
2010-03-23 16:17 ` Jiri Slaby
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 20:33 ` Pavel Machek [this message]
2010-03-24 21:29 ` Jiri Slaby
2010-03-25 21:35 ` Rafael J. Wysocki
2010-03-25 21:35 ` Rafael J. Wysocki
2010-03-24 21:29 ` Jiri Slaby
2010-03-23 16:17 ` Jiri Slaby
2010-03-23 16:17 ` [RFC 07/15] PM / Hibernate: add sws_modules_ops Jiri Slaby
2010-03-23 16:17 ` Jiri Slaby
2010-03-24 20:36 ` Pavel Machek
2010-03-24 21:31 ` Jiri Slaby
2010-03-24 21:31 ` Jiri Slaby
2010-03-24 20:36 ` Pavel Machek
2010-03-25 22:02 ` Rafael J. Wysocki
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-23 16:17 ` Jiri Slaby
2010-03-25 22:07 ` Rafael J. Wysocki
2010-03-25 22:07 ` Rafael J. Wysocki
2010-03-26 9:43 ` Jiri Slaby
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 21:36 ` Pavel Machek
2010-03-25 22:14 ` Rafael J. Wysocki
2010-03-25 22:14 ` Rafael J. Wysocki
2010-03-26 9:34 ` Jiri Slaby
2010-03-26 9:34 ` Jiri Slaby
2010-03-26 22:04 ` Rafael J. Wysocki
2010-03-29 15:33 ` Jiri Slaby
2010-03-29 22:09 ` Rafael J. Wysocki
2010-03-30 1:14 ` Nigel Cunningham
2010-03-30 21:03 ` Rafael J. Wysocki
2010-03-31 2:31 ` Nigel Cunningham
2010-03-31 14:47 ` Pavel Machek
2010-03-31 21:01 ` Nigel Cunningham
2010-03-31 20:25 ` Rafael J. Wysocki
2010-03-31 21:06 ` Nigel Cunningham
2010-03-31 21:36 ` Rafael J. Wysocki
2010-04-04 23:08 ` Nigel Cunningham
2010-04-04 23:13 ` Rafael J. Wysocki
2010-03-31 21:54 ` Nigel Cunningham
2010-03-30 8:59 ` Jiri Slaby
2010-03-30 20:50 ` Rafael J. Wysocki
2010-03-31 14:41 ` Jiri Slaby
2010-03-31 20:29 ` Rafael J. Wysocki
2010-04-21 21:22 ` Jiri Slaby
2010-04-22 3:43 ` Rafael J. Wysocki
2010-03-29 15:33 ` Jiri Slaby
2010-03-26 22:04 ` Rafael J. Wysocki
2010-03-27 7:02 ` Pavel Machek
2010-03-27 7:02 ` Pavel Machek
2010-03-24 21:40 ` Jiri Slaby
2010-03-24 20:42 ` Pavel Machek
2010-03-23 16:17 ` Jiri Slaby
2010-03-23 16:17 ` [RFC 10/15] PM / Hibernate: user, implement user_ops reader Jiri Slaby
2010-03-23 16:17 ` Jiri Slaby
2010-03-25 5:30 ` what the patches do " Pavel Machek
2010-03-25 5:30 ` Pavel Machek
2010-03-25 5:42 ` Nigel Cunningham
2010-03-25 6:12 ` [linux-pm] " Nigel Cunningham
2010-03-25 6:12 ` Nigel Cunningham
2010-03-25 20:14 ` Rafael J. Wysocki
2010-03-25 20:21 ` Nigel Cunningham
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:13 ` Rafael J. Wysocki
2010-03-25 20:35 ` Nigel Cunningham
2010-03-25 21:26 ` Pavel Machek
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 6:36 ` [linux-pm] " Pavel Machek
2010-04-02 17:03 ` Rafael J. Wysocki
2010-04-02 17:03 ` Rafael J. Wysocki
2010-03-25 21:49 ` Nigel Cunningham
2010-03-25 20:29 ` Rafael J. Wysocki
2010-03-25 20:14 ` Rafael J. Wysocki
2010-03-25 5:42 ` Nigel Cunningham
2010-03-25 22:21 ` 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-23 16:17 ` Jiri Slaby
2010-03-25 22:38 ` Rafael J. Wysocki
2010-03-26 9:09 ` Jiri Slaby
2010-03-26 9:09 ` Jiri Slaby
2010-03-26 10:02 ` Nigel Cunningham
2010-03-26 10:02 ` Nigel Cunningham
2010-03-25 22:38 ` Rafael J. Wysocki
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-25 22:44 ` Rafael J. Wysocki
2010-03-23 16:17 ` Jiri Slaby
2010-03-23 16:17 ` [RFC 13/15] PM / Hibernate: split snapshot_write_next Jiri Slaby
2010-03-23 16:17 ` Jiri Slaby
2010-03-25 22:46 ` Rafael J. Wysocki
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-23 16:17 ` Jiri Slaby
2010-03-25 22:46 ` Rafael J. Wysocki
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-25 22:50 ` Rafael J. Wysocki
2010-03-23 16:17 ` Jiri Slaby
2010-03-23 21:51 ` [RFC 01/15] FS: libfs, implement simple_write_to_buffer Rafael J. Wysocki
2010-03-23 21:51 ` Rafael J. Wysocki
2010-03-23 22:09 ` [linux-pm] " Nigel Cunningham
2010-03-23 22:09 ` Nigel Cunningham
2010-03-24 22:13 ` Rafael J. Wysocki
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=20100324203329.GG5798@elf.ucw.cz \
--to=pavel@ucw.cz \
--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=rjw@sisk.pl \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.