ia64/xen-unstable

changeset 8535:a51fcb5de470

Extend the xc_linux_save interface to take a callback function for handling the
suspend, and push the printf("suspend") out of xc_linux_save and into xc_save.
This means that xc_linux_save can be used without the xc_save wrapper if
desired.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@leeni.uk.xensource.com
date Tue Jan 10 14:23:56 2006 +0000 (2006-01-10)
parents 8af1199488d3
children a4ce0ba0f8ff
files tools/libxc/xc_ia64_stubs.c tools/libxc/xc_linux_save.c tools/libxc/xenguest.h tools/xcutils/xc_save.c
line diff
     1.1 --- a/tools/libxc/xc_ia64_stubs.c	Mon Jan 09 11:22:17 2006 +0000
     1.2 +++ b/tools/libxc/xc_ia64_stubs.c	Tue Jan 10 14:23:56 2006 +0000
     1.3 @@ -23,7 +23,7 @@ unsigned long xc_ia64_fpsr_default(void)
     1.4  }
     1.5  
     1.6  int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, 
     1.7 -                  uint32_t max_factor, uint32_t flags)
     1.8 +                  uint32_t max_factor, uint32_t flags, int (*suspend)(void))
     1.9  {
    1.10      PERROR("xc_linux_save not implemented\n");
    1.11      return -1;
     2.1 --- a/tools/libxc/xc_linux_save.c	Mon Jan 09 11:22:17 2006 +0000
     2.2 +++ b/tools/libxc/xc_linux_save.c	Tue Jan 10 14:23:56 2006 +0000
     2.3 @@ -357,21 +357,14 @@ static int analysis_phase(int xc_handle,
     2.4  }
     2.5  
     2.6  
     2.7 -static int suspend_and_state(int xc_handle, int io_fd, int dom,       
     2.8 -                             xc_dominfo_t *info,
     2.9 +static int suspend_and_state(int (*suspend)(int), int xc_handle, int io_fd,
    2.10 +                             int dom, xc_dominfo_t *info,
    2.11                               vcpu_guest_context_t *ctxt)
    2.12  {
    2.13      int i = 0;
    2.14 -    char ans[30];
    2.15  
    2.16 -    printf("suspend\n");
    2.17 -    fflush(stdout);
    2.18 -    if (fgets(ans, sizeof(ans), stdin) == NULL) {
    2.19 -        ERR("failed reading suspend reply");
    2.20 -        return -1;
    2.21 -    }
    2.22 -    if (strncmp(ans, "done\n", 5)) {
    2.23 -        ERR("suspend reply incorrect: %s", ans);
    2.24 +    if (!(*suspend)(dom)) {
    2.25 +        ERR("Suspend request failed");
    2.26          return -1;
    2.27      }
    2.28  
    2.29 @@ -568,7 +561,7 @@ static unsigned long *xc_map_m2p(int xc_
    2.30  
    2.31  
    2.32  int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters, 
    2.33 -                  uint32_t max_factor, uint32_t flags)
    2.34 +                  uint32_t max_factor, uint32_t flags, int (*suspend)(int))
    2.35  {
    2.36      xc_dominfo_t info;
    2.37  
    2.38 @@ -748,7 +741,7 @@ int xc_linux_save(int xc_handle, int io_
    2.39          
    2.40          last_iter = 1;
    2.41          
    2.42 -        if (suspend_and_state( xc_handle, io_fd, dom, &info, &ctxt)) {
    2.43 +        if (suspend_and_state(suspend, xc_handle, io_fd, dom, &info, &ctxt)) {
    2.44              ERR("Domain appears not to have suspended");
    2.45              goto out;
    2.46          }
    2.47 @@ -1054,7 +1047,8 @@ int xc_linux_save(int xc_handle, int io_
    2.48                  DPRINTF("Start last iteration\n");
    2.49                  last_iter = 1;
    2.50                  
    2.51 -                if (suspend_and_state(xc_handle, io_fd, dom, &info, &ctxt)) {
    2.52 +                if (suspend_and_state(suspend, xc_handle, io_fd, dom, &info,
    2.53 +                                      &ctxt)) {
    2.54                      ERR("Domain appears not to have suspended");
    2.55                      goto out;
    2.56                  }
     3.1 --- a/tools/libxc/xenguest.h	Mon Jan 09 11:22:17 2006 +0000
     3.2 +++ b/tools/libxc/xenguest.h	Tue Jan 10 14:23:56 2006 +0000
     3.3 @@ -22,7 +22,9 @@
     3.4   * @return 0 on success, -1 on failure
     3.5   */
     3.6  int xc_linux_save(int xc_handle, int fd, uint32_t dom, uint32_t max_iters, 
     3.7 -                  uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */);
     3.8 +                  uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */,
     3.9 +                  int (*suspend)(int));
    3.10 +
    3.11  
    3.12  /**
    3.13   * This function will restore a saved domain running Linux.
     4.1 --- a/tools/xcutils/xc_save.c	Mon Jan 09 11:22:17 2006 +0000
     4.2 +++ b/tools/xcutils/xc_save.c	Tue Jan 10 14:23:56 2006 +0000
     4.3 @@ -10,10 +10,28 @@
     4.4  #include <err.h>
     4.5  #include <stdlib.h>
     4.6  #include <stdint.h>
     4.7 +#include <string.h>
     4.8  #include <stdio.h>
     4.9  
    4.10  #include <xenguest.h>
    4.11  
    4.12 +
    4.13 +/**
    4.14 + * Issue a suspend request through stdout, and receive the acknowledgement
    4.15 + * from stdin.  This is handled by XendCheckpoint in the Python layer.
    4.16 + */
    4.17 +static int suspend(int domid)
    4.18 +{
    4.19 +    char ans[30];
    4.20 +
    4.21 +    printf("suspend\n");
    4.22 +    fflush(stdout);
    4.23 +
    4.24 +    return (fgets(ans, sizeof(ans), stdin) != NULL &&
    4.25 +            !strncmp(ans, "done\n", 5));
    4.26 +}
    4.27 +
    4.28 +
    4.29  int
    4.30  main(int argc, char **argv)
    4.31  {
    4.32 @@ -29,5 +47,5 @@ main(int argc, char **argv)
    4.33      max_f = atoi(argv[5]);
    4.34      flags = atoi(argv[6]);
    4.35  
    4.36 -    return xc_linux_save(xc_fd, io_fd, domid, maxit, max_f, flags);
    4.37 +    return xc_linux_save(xc_fd, io_fd, domid, maxit, max_f, flags, &suspend);
    4.38  }