ia64/xen-unstable
changeset 910:7c2e9edb5190
bitkeeper revision 1.576 (3facdede5nZbIb45xqApby8e8U5CQA)
xi_save_linux.c, xi_restore_linux.c, Makefile:
Suspend/resume now uses zlib to reduce the state file size.
xi_save_linux.c, xi_restore_linux.c, Makefile:
Suspend/resume now uses zlib to reduce the state file size.
author | kaf24@scramble.cl.cam.ac.uk |
---|---|
date | Sat Nov 08 12:17:34 2003 +0000 (2003-11-08) |
parents | 3f85eabfe053 |
children | ab95f7d2c9d4 |
files | tools/internal/Makefile tools/internal/xi_restore_linux.c tools/internal/xi_save_linux.c |
line diff
1.1 --- a/tools/internal/Makefile Sat Nov 08 11:06:10 2003 +0000 1.2 +++ b/tools/internal/Makefile Sat Nov 08 12:17:34 2003 +0000 1.3 @@ -12,7 +12,15 @@ TARGETS += xi_phys_grant xi_list xi_save 1.4 TARGETS += xi_sched_global xi_sched_domain xi_usage xi_vif_params 1.5 INSTALL = $(TARGETS) xi_vifinit xi_helper 1.6 1.7 -all: $(TARGETS) 1.8 +all: check-for-zlib $(TARGETS) 1.9 + 1.10 +check-for-zlib: 1.11 + @if [ ! -e /usr/include/zlib.h ]; then \ 1.12 + echo "***********************************************************"; \ 1.13 + echo "ERROR: install zlib header files (http://www.gzip.org/zlib)"; \ 1.14 + echo "***********************************************************"; \ 1.15 + false; \ 1.16 + fi 1.17 1.18 install: all 1.19 mkdir -p ../../../install/bin 1.20 @@ -31,6 +39,9 @@ rpm: all 1.21 mv staging/i386/*.rpm . 1.22 rm -rf staging 1.23 1.24 +xi_save_linux xi_restore_linux: %: %.c $(HDRS) Makefile 1.25 + $(CC) $(CFLAGS) -lz -o $@ $< 1.26 + 1.27 %: %.c $(HDRS) Makefile 1.28 $(CC) $(CFLAGS) -o $@ $< 1.29
2.1 --- a/tools/internal/xi_restore_linux.c Sat Nov 08 11:06:10 2003 +0000 2.2 +++ b/tools/internal/xi_restore_linux.c Sat Nov 08 12:17:34 2003 +0000 2.3 @@ -10,6 +10,8 @@ 2.4 #include "mem_defs.h" 2.5 #include <asm-xeno/suspend.h> 2.6 2.7 +#include <zlib.h> 2.8 + 2.9 static char *argv0 = "internal_restore_linux"; 2.10 2.11 /* A table mapping each PFN to its new MFN. */ 2.12 @@ -120,10 +122,10 @@ static void unmap_pfn(void *vaddr) 2.13 (void)munmap(vaddr, PAGE_SIZE); 2.14 } 2.15 2.16 -static int checked_read(int fd, void *buf, size_t count) 2.17 +static int checked_read(gzFile fd, void *buf, size_t count) 2.18 { 2.19 int rc; 2.20 - while ( ((rc = read(fd, buf, count)) == -1) && (errno == EINTR) ) 2.21 + while ( ((rc = gzread(fd, buf, count)) == -1) && (errno == EINTR) ) 2.22 continue; 2.23 return rc == count; 2.24 } 2.25 @@ -164,8 +166,9 @@ int main(int argc, char **argv) 2.26 suspend_record_t *p_srec; 2.27 2.28 /* The name and descriptor of the file that we are reading from. */ 2.29 - char *filename; 2.30 - int fd; 2.31 + char *filename; 2.32 + int fd; 2.33 + gzFile gfd; 2.34 2.35 if ( argv[0] != NULL ) 2.36 argv0 = argv[0]; 2.37 @@ -183,19 +186,26 @@ int main(int argc, char **argv) 2.38 return 1; 2.39 } 2.40 2.41 + if ( (gfd = gzdopen(fd, "rb")) == NULL ) 2.42 + { 2.43 + ERROR("Could not allocate decompression state for state file"); 2.44 + close(fd); 2.45 + return 1; 2.46 + } 2.47 + 2.48 /* Start writing out the saved-domain record. */ 2.49 - if ( !checked_read(fd, signature, 16) || 2.50 + if ( !checked_read(gfd, signature, 16) || 2.51 (memcmp(signature, "XenoLinuxSuspend", 16) != 0) ) 2.52 { 2.53 ERROR("Unrecognised state format -- no signature found"); 2.54 goto out; 2.55 } 2.56 2.57 - if ( !checked_read(fd, name, sizeof(name)) || 2.58 - !checked_read(fd, &nr_pfns, sizeof(unsigned long)) || 2.59 - !checked_read(fd, &ctxt, sizeof(ctxt)) || 2.60 - !checked_read(fd, shared_info, PAGE_SIZE) || 2.61 - !checked_read(fd, pfn_to_mfn_frame_list, PAGE_SIZE) ) 2.62 + if ( !checked_read(gfd, name, sizeof(name)) || 2.63 + !checked_read(gfd, &nr_pfns, sizeof(unsigned long)) || 2.64 + !checked_read(gfd, &ctxt, sizeof(ctxt)) || 2.65 + !checked_read(gfd, shared_info, PAGE_SIZE) || 2.66 + !checked_read(gfd, pfn_to_mfn_frame_list, PAGE_SIZE) ) 2.67 { 2.68 ERROR("Error when reading from state file"); 2.69 goto out; 2.70 @@ -222,7 +232,7 @@ int main(int argc, char **argv) 2.71 pfn_to_mfn_table = calloc(1, 4 * nr_pfns); 2.72 pfn_type = calloc(1, 4 * nr_pfns); 2.73 2.74 - if ( !checked_read(fd, pfn_type, 4 * nr_pfns) ) 2.75 + if ( !checked_read(gfd, pfn_type, 4 * nr_pfns) ) 2.76 { 2.77 ERROR("Error when reading from state file"); 2.78 goto out; 2.79 @@ -282,7 +292,7 @@ int main(int argc, char **argv) 2.80 2.81 mfn = pfn_to_mfn_table[i]; 2.82 2.83 - if ( !checked_read(fd, page, PAGE_SIZE) ) 2.84 + if ( !checked_read(gfd, page, PAGE_SIZE) ) 2.85 { 2.86 ERROR("Error when reading from state file"); 2.87 goto out; 2.88 @@ -482,5 +492,7 @@ int main(int argc, char **argv) 2.89 printf("DOM=%ld\n", dom); 2.90 } 2.91 2.92 + gzclose(gfd); 2.93 + 2.94 return !!rc; 2.95 }
3.1 --- a/tools/internal/xi_save_linux.c Sat Nov 08 11:06:10 2003 +0000 3.2 +++ b/tools/internal/xi_save_linux.c Sat Nov 08 12:17:34 2003 +0000 3.3 @@ -10,6 +10,8 @@ 3.4 #include "mem_defs.h" 3.5 #include <asm-xeno/suspend.h> 3.6 3.7 +#include <zlib.h> 3.8 + 3.9 static char *argv0 = "internal_save_linux"; 3.10 3.11 /* A table mapping each PFN to its current MFN. */ 3.12 @@ -94,10 +96,10 @@ static unsigned int get_pfn_type(unsigne 3.13 return op.u.getpageframeinfo.type; 3.14 } 3.15 3.16 -static int checked_write(int fd, const void *buf, size_t count) 3.17 +static int checked_write(gzFile fd, void *buf, size_t count) 3.18 { 3.19 int rc; 3.20 - while ( ((rc = write(fd, buf, count)) == -1) && (errno = EINTR) ) 3.21 + while ( ((rc = gzwrite(fd, buf, count)) == -1) && (errno = EINTR) ) 3.22 continue; 3.23 return rc == count; 3.24 } 3.25 @@ -136,8 +138,9 @@ int main(int argc, char **argv) 3.26 suspend_record_t *p_srec, srec; 3.27 3.28 /* The name and descriptor of the file that we are writing to. */ 3.29 - char *filename; 3.30 - int fd; 3.31 + char *filename; 3.32 + int fd; 3.33 + gzFile gfd; 3.34 3.35 if ( argv[0] != NULL ) 3.36 argv0 = argv[0]; 3.37 @@ -162,6 +165,17 @@ int main(int argc, char **argv) 3.38 return 1; 3.39 } 3.40 3.41 + /* 3.42 + * Compression rate 1: we want speed over compression. We're mainly going 3.43 + * for those zero pages, after all. 3.44 + */ 3.45 + if ( (gfd = gzdopen(fd, "wb1")) == NULL ) 3.46 + { 3.47 + ERROR("Could not allocate compression state for state file"); 3.48 + close(fd); 3.49 + return 1; 3.50 + } 3.51 + 3.52 /* Ensure that the domain exists, and that it is stopped. */ 3.53 for ( ; ; ) 3.54 { 3.55 @@ -314,13 +328,13 @@ int main(int argc, char **argv) 3.56 3.57 /* Start writing out the saved-domain record. */ 3.58 ppage = map_pfn(shared_info_frame); 3.59 - if ( !checked_write(fd, "XenoLinuxSuspend", 16) || 3.60 - !checked_write(fd, name, sizeof(name)) || 3.61 - !checked_write(fd, &srec.nr_pfns, sizeof(unsigned long)) || 3.62 - !checked_write(fd, &ctxt, sizeof(ctxt)) || 3.63 - !checked_write(fd, ppage, PAGE_SIZE) || 3.64 - !checked_write(fd, pfn_to_mfn_frame_list, PAGE_SIZE) || 3.65 - !checked_write(fd, pfn_type, 4 * srec.nr_pfns) ) 3.66 + if ( !checked_write(gfd, "XenoLinuxSuspend", 16) || 3.67 + !checked_write(gfd, name, sizeof(name)) || 3.68 + !checked_write(gfd, &srec.nr_pfns, sizeof(unsigned long)) || 3.69 + !checked_write(gfd, &ctxt, sizeof(ctxt)) || 3.70 + !checked_write(gfd, ppage, PAGE_SIZE) || 3.71 + !checked_write(gfd, pfn_to_mfn_frame_list, PAGE_SIZE) || 3.72 + !checked_write(gfd, pfn_type, 4 * srec.nr_pfns) ) 3.73 { 3.74 ERROR("Error when writing to state file"); 3.75 goto out; 3.76 @@ -365,7 +379,7 @@ int main(int argc, char **argv) 3.77 } 3.78 } 3.79 3.80 - if ( !checked_write(fd, page, PAGE_SIZE) ) 3.81 + if ( !checked_write(gfd, page, PAGE_SIZE) ) 3.82 { 3.83 ERROR("Error when writing to state file"); 3.84 goto out; 3.85 @@ -386,6 +400,8 @@ int main(int argc, char **argv) 3.86 (void)do_dom0_op(&op); 3.87 } 3.88 3.89 + gzclose(gfd); 3.90 + 3.91 /* On error, make sure the file is deleted. */ 3.92 if ( rc != 0 ) 3.93 unlink(filename);