ia64/xen-unstable

changeset 19386:f00e5d83b9ec

xc_save: remove the dependency on the global si structure

Signed-off-by: Jiang Yunhong <yunhong.jiang@intel.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Mar 18 11:48:48 2009 +0000 (2009-03-18)
parents 6d65dc14d21b
children a5f497f02e34
files tools/xcutils/xc_save.c
line diff
     1.1 --- a/tools/xcutils/xc_save.c	Wed Mar 18 11:46:32 2009 +0000
     1.2 +++ b/tools/xcutils/xc_save.c	Wed Mar 18 11:48:48 2009 +0000
     1.3 @@ -46,50 +46,41 @@ static int compat_suspend(void)
     1.4              !strncmp(ans, "done\n", 5));
     1.5  }
     1.6  
     1.7 -static int suspend_evtchn_release(void)
     1.8 +static int suspend_evtchn_release(int xce, int suspend_evtchn)
     1.9  {
    1.10 -    if (si.suspend_evtchn >= 0) {
    1.11 -        xc_evtchn_unbind(si.xce, si.suspend_evtchn);
    1.12 -        si.suspend_evtchn = -1;
    1.13 -    }
    1.14 -    if (si.xce >= 0) {
    1.15 -        xc_evtchn_close(si.xce);
    1.16 -        si.xce = -1;
    1.17 -    }
    1.18 +    if (suspend_evtchn >= 0)
    1.19 +        xc_evtchn_unbind(xce, suspend_evtchn);
    1.20  
    1.21      return 0;
    1.22  }
    1.23  
    1.24 -static int await_suspend(void)
    1.25 +static int await_suspend(int xce, int suspend_evtchn)
    1.26  {
    1.27      int rc;
    1.28  
    1.29      do {
    1.30 -        rc = xc_evtchn_pending(si.xce);
    1.31 +        rc = xc_evtchn_pending(xce);
    1.32          if (rc < 0) {
    1.33              warnx("error polling suspend notification channel: %d", rc);
    1.34              return -1;
    1.35          }
    1.36 -    } while (rc != si.suspend_evtchn);
    1.37 +    } while (rc != suspend_evtchn);
    1.38  
    1.39      /* harmless for one-off suspend */
    1.40 -    if (xc_evtchn_unmask(si.xce, si.suspend_evtchn) < 0)
    1.41 +    if (xc_evtchn_unmask(xce, suspend_evtchn) < 0)
    1.42          warnx("failed to unmask suspend notification channel: %d", rc);
    1.43  
    1.44      return 0;
    1.45  }
    1.46  
    1.47 -static int suspend_evtchn_init(int xc, int domid)
    1.48 +static int suspend_evtchn_init(int xc, int xce, int domid)
    1.49  {
    1.50      struct xs_handle *xs;
    1.51      char path[128];
    1.52      char *portstr;
    1.53      unsigned int plen;
    1.54      int port;
    1.55 -    int rc;
    1.56 -
    1.57 -    si.xce = -1;
    1.58 -    si.suspend_evtchn = -1;
    1.59 +    int rc, suspend_evtchn = -1;
    1.60  
    1.61      xs = xs_daemon_open();
    1.62      if (!xs) {
    1.63 @@ -108,14 +99,8 @@ static int suspend_evtchn_init(int xc, i
    1.64      port = atoi(portstr);
    1.65      free(portstr);
    1.66  
    1.67 -    si.xce = xc_evtchn_open();
    1.68 -    if (si.xce < 0) {
    1.69 -        warnx("failed to open event channel handle");
    1.70 -        goto cleanup;
    1.71 -    }
    1.72 -
    1.73 -    si.suspend_evtchn = xc_evtchn_bind_interdomain(si.xce, domid, port);
    1.74 -    if (si.suspend_evtchn < 0) {
    1.75 +    suspend_evtchn = xc_evtchn_bind_interdomain(xce, domid, port);
    1.76 +    if (suspend_evtchn < 0) {
    1.77          warnx("failed to bind suspend event channel: %d", si.suspend_evtchn);
    1.78          goto cleanup;
    1.79      }
    1.80 @@ -127,12 +112,13 @@ static int suspend_evtchn_init(int xc, i
    1.81      }
    1.82  
    1.83      /* event channel is pending immediately after binding */
    1.84 -    await_suspend();
    1.85 +    await_suspend(xce, suspend_evtchn);
    1.86 +
    1.87 +    return suspend_evtchn;
    1.88  
    1.89 -    return 0;
    1.90 -
    1.91 -  cleanup:
    1.92 -    suspend_evtchn_release();
    1.93 +cleanup:
    1.94 +    if (suspend_evtchn > 0)
    1.95 +        suspend_evtchn_release(xce, suspend_evtchn);
    1.96  
    1.97      return -1;
    1.98  }
    1.99 @@ -150,7 +136,7 @@ static int evtchn_suspend(void)
   1.100          return 0;
   1.101      }
   1.102  
   1.103 -    if (await_suspend() < 0) {
   1.104 +    if (await_suspend(si.xce, si.suspend_evtchn) < 0) {
   1.105          warnx("suspend failed");
   1.106          return 0;
   1.107      }
   1.108 @@ -323,14 +309,23 @@ main(int argc, char **argv)
   1.109      max_f = atoi(argv[4]);
   1.110      si.flags = atoi(argv[5]);
   1.111  
   1.112 -    if (suspend_evtchn_init(si.xc_fd, si.domid) < 0)
   1.113 +
   1.114 +    si.xce = xc_evtchn_open();
   1.115 +    if (si.xce < 0)
   1.116 +        errx(1, "failed to open event channel handle");
   1.117 +
   1.118 +    si.suspend_evtchn = suspend_evtchn_init(si.xc_fd, si.xce, si.domid);
   1.119 +
   1.120 +    if (si.suspend_evtchn < 0)
   1.121          warnx("suspend event channel initialization failed, using slow path");
   1.122  
   1.123      ret = xc_domain_save(si.xc_fd, io_fd, si.domid, maxit, max_f, si.flags, 
   1.124                           &suspend, !!(si.flags & XCFLAGS_HVM),
   1.125                           &init_qemu_maps, &qemu_flip_buffer);
   1.126  
   1.127 -    suspend_evtchn_release();
   1.128 +    suspend_evtchn_release(si.xce, si.suspend_evtchn);
   1.129 +
   1.130 +    xc_evtchn_close(si.xce);
   1.131  
   1.132      xc_interface_close(si.xc_fd);
   1.133