aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael J. Wysocki <rjw@sisk.pl>2006-09-26 02:32:46 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-09-26 11:48:58 -0400
commitfb13a28b0f5ada60861868c4fa48a12bd0cb8dea (patch)
treee0a4611621f2d5abc94f0b0ea5a2c41f2962e5e1
parentae83c5eef59ffe6eb61110b8c8fd1ea3e0881712 (diff)
[PATCH] swsusp: struct snapshot_handle cleanup
Add comments describing struct snapshot_handle and its members, change the confusing name of its member 'page' to 'cur'. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Cc: Pavel Machek <pavel@ucw.cz> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--kernel/power/power.h64
-rw-r--r--kernel/power/snapshot.c40
2 files changed, 76 insertions, 28 deletions
diff --git a/kernel/power/power.h b/kernel/power/power.h
index 59ce712f082d..1cefcf87a694 100644
--- a/kernel/power/power.h
+++ b/kernel/power/power.h
@@ -50,17 +50,65 @@ extern asmlinkage int swsusp_arch_resume(void);
50 50
51extern unsigned int count_data_pages(void); 51extern unsigned int count_data_pages(void);
52 52
53/**
54 * Auxiliary structure used for reading the snapshot image data and
55 * metadata from and writing them to the list of page backup entries
56 * (PBEs) which is the main data structure of swsusp.
57 *
58 * Using struct snapshot_handle we can transfer the image, including its
59 * metadata, as a continuous sequence of bytes with the help of
60 * snapshot_read_next() and snapshot_write_next().
61 *
62 * The code that writes the image to a storage or transfers it to
63 * the user land is required to use snapshot_read_next() for this
64 * purpose and it should not make any assumptions regarding the internal
65 * structure of the image. Similarly, the code that reads the image from
66 * a storage or transfers it from the user land is required to use
67 * snapshot_write_next().
68 *
69 * This may allow us to change the internal structure of the image
70 * in the future with considerably less effort.
71 */
72
53struct snapshot_handle { 73struct snapshot_handle {
54 loff_t offset; 74 loff_t offset; /* number of the last byte ready for reading
55 unsigned int page; 75 * or writing in the sequence
56 unsigned int page_offset; 76 */
57 unsigned int prev; 77 unsigned int cur; /* number of the block of PAGE_SIZE bytes the
58 struct pbe *pbe, *last_pbe; 78 * next operation will refer to (ie. current)
59 void *buffer; 79 */
60 unsigned int buf_offset; 80 unsigned int cur_offset; /* offset with respect to the current
61 int sync_read; 81 * block (for the next operation)
82 */
83 unsigned int prev; /* number of the block of PAGE_SIZE bytes that
84 * was the current one previously
85 */
86 struct pbe *pbe; /* PBE that corresponds to 'buffer' */
87 struct pbe *last_pbe; /* When the image is restored (eg. read
88 * from disk) we can store some image
89 * data directly in the page frames
90 * in which they were before suspend.
91 * In such a case the PBEs that
92 * correspond to them will be unused.
93 * This is the last PBE, so far, that
94 * does not correspond to such data.
95 */
96 void *buffer; /* address of the block to read from
97 * or write to
98 */
99 unsigned int buf_offset; /* location to read from or write to,
100 * given as a displacement from 'buffer'
101 */
102 int sync_read; /* Set to one to notify the caller of
103 * snapshot_write_next() that it may
104 * need to call wait_on_bio_chain()
105 */
62}; 106};
63 107
108/* This macro returns the address from/to which the caller of
109 * snapshot_read_next()/snapshot_write_next() is allowed to
110 * read/write data after the function returns
111 */
64#define data_of(handle) ((handle).buffer + (handle).buf_offset) 112#define data_of(handle) ((handle).buffer + (handle).buf_offset)
65 113
66extern int snapshot_read_next(struct snapshot_handle *handle, size_t count); 114extern int snapshot_read_next(struct snapshot_handle *handle, size_t count);
diff --git a/kernel/power/snapshot.c b/kernel/power/snapshot.c
index 979096c27773..81fe8de9e604 100644
--- a/kernel/power/snapshot.c
+++ b/kernel/power/snapshot.c
@@ -555,7 +555,7 @@ static inline struct pbe *pack_orig_addresses(unsigned long *buf, struct pbe *pb
555 555
556int snapshot_read_next(struct snapshot_handle *handle, size_t count) 556int snapshot_read_next(struct snapshot_handle *handle, size_t count)
557{ 557{
558 if (handle->page > nr_meta_pages + nr_copy_pages) 558 if (handle->cur > nr_meta_pages + nr_copy_pages)
559 return 0; 559 return 0;
560 if (!buffer) { 560 if (!buffer) {
561 /* This makes the buffer be freed by swsusp_free() */ 561 /* This makes the buffer be freed by swsusp_free() */
@@ -568,8 +568,8 @@ int snapshot_read_next(struct snapshot_handle *handle, size_t count)
568 handle->buffer = buffer; 568 handle->buffer = buffer;
569 handle->pbe = pagedir_nosave; 569 handle->pbe = pagedir_nosave;
570 } 570 }
571 if (handle->prev < handle->page) { 571 if (handle->prev < handle->cur) {
572 if (handle->page <= nr_meta_pages) { 572 if (handle->cur <= nr_meta_pages) {
573 handle->pbe = pack_orig_addresses(buffer, handle->pbe); 573 handle->pbe = pack_orig_addresses(buffer, handle->pbe);
574 if (!handle->pbe) 574 if (!handle->pbe)
575 handle->pbe = pagedir_nosave; 575 handle->pbe = pagedir_nosave;
@@ -577,15 +577,15 @@ int snapshot_read_next(struct snapshot_handle *handle, size_t count)
577 handle->buffer = (void *)handle->pbe->address; 577 handle->buffer = (void *)handle->pbe->address;
578 handle->pbe = handle->pbe->next; 578 handle->pbe = handle->pbe->next;
579 } 579 }
580 handle->prev = handle->page; 580 handle->prev = handle->cur;
581 } 581 }
582 handle->buf_offset = handle->page_offset; 582 handle->buf_offset = handle->cur_offset;
583 if (handle->page_offset + count >= PAGE_SIZE) { 583 if (handle->cur_offset + count >= PAGE_SIZE) {
584 count = PAGE_SIZE - handle->page_offset; 584 count = PAGE_SIZE - handle->cur_offset;
585 handle->page_offset = 0; 585 handle->cur_offset = 0;
586 handle->page++; 586 handle->cur++;
587 } else { 587 } else {
588 handle->page_offset += count; 588 handle->cur_offset += count;
589 } 589 }
590 handle->offset += count; 590 handle->offset += count;
591 return count; 591 return count;
@@ -820,7 +820,7 @@ int snapshot_write_next(struct snapshot_handle *handle, size_t count)
820{ 820{
821 int error = 0; 821 int error = 0;
822 822
823 if (handle->prev && handle->page > nr_meta_pages + nr_copy_pages) 823 if (handle->prev && handle->cur > nr_meta_pages + nr_copy_pages)
824 return 0; 824 return 0;
825 if (!buffer) { 825 if (!buffer) {
826 /* This makes the buffer be freed by swsusp_free() */ 826 /* This makes the buffer be freed by swsusp_free() */
@@ -831,7 +831,7 @@ int snapshot_write_next(struct snapshot_handle *handle, size_t count)
831 if (!handle->offset) 831 if (!handle->offset)
832 handle->buffer = buffer; 832 handle->buffer = buffer;
833 handle->sync_read = 1; 833 handle->sync_read = 1;
834 if (handle->prev < handle->page) { 834 if (handle->prev < handle->cur) {
835 if (!handle->prev) { 835 if (!handle->prev) {
836 error = load_header(handle, 836 error = load_header(handle,
837 (struct swsusp_info *)buffer); 837 (struct swsusp_info *)buffer);
@@ -854,15 +854,15 @@ int snapshot_write_next(struct snapshot_handle *handle, size_t count)
854 handle->buffer = get_buffer(handle); 854 handle->buffer = get_buffer(handle);
855 handle->sync_read = 0; 855 handle->sync_read = 0;
856 } 856 }
857 handle->prev = handle->page; 857 handle->prev = handle->cur;
858 } 858 }
859 handle->buf_offset = handle->page_offset; 859 handle->buf_offset = handle->cur_offset;
860 if (handle->page_offset + count >= PAGE_SIZE) { 860 if (handle->cur_offset + count >= PAGE_SIZE) {
861 count = PAGE_SIZE - handle->page_offset; 861 count = PAGE_SIZE - handle->cur_offset;
862 handle->page_offset = 0; 862 handle->cur_offset = 0;
863 handle->page++; 863 handle->cur++;
864 } else { 864 } else {
865 handle->page_offset += count; 865 handle->cur_offset += count;
866 } 866 }
867 handle->offset += count; 867 handle->offset += count;
868 return count; 868 return count;
@@ -871,5 +871,5 @@ int snapshot_write_next(struct snapshot_handle *handle, size_t count)
871int snapshot_image_loaded(struct snapshot_handle *handle) 871int snapshot_image_loaded(struct snapshot_handle *handle)
872{ 872{
873 return !(!handle->pbe || handle->pbe->next || !nr_copy_pages || 873 return !(!handle->pbe || handle->pbe->next || !nr_copy_pages ||
874 handle->page <= nr_meta_pages + nr_copy_pages); 874 handle->cur <= nr_meta_pages + nr_copy_pages);
875} 875}