[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-changelog] [xen-unstable] xc_save: remove the dependency on the global si structure



# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1237376928 0
# Node ID f00e5d83b9ecb5ba9be48ec53bd7536fe85118bf
# Parent  6d65dc14d21b5b598de925d1b1e0aa8305092273
xc_save: remove the dependency on the global si structure

Signed-off-by: Jiang Yunhong <yunhong.jiang@xxxxxxxxx>
---
 tools/xcutils/xc_save.c |   67 ++++++++++++++++++++++--------------------------
 1 files changed, 31 insertions(+), 36 deletions(-)

diff -r 6d65dc14d21b -r f00e5d83b9ec tools/xcutils/xc_save.c
--- a/tools/xcutils/xc_save.c   Wed Mar 18 11:46:32 2009 +0000
+++ b/tools/xcutils/xc_save.c   Wed Mar 18 11:48:48 2009 +0000
@@ -46,50 +46,41 @@ static int compat_suspend(void)
             !strncmp(ans, "done\n", 5));
 }
 
-static int suspend_evtchn_release(void)
-{
-    if (si.suspend_evtchn >= 0) {
-        xc_evtchn_unbind(si.xce, si.suspend_evtchn);
-        si.suspend_evtchn = -1;
-    }
-    if (si.xce >= 0) {
-        xc_evtchn_close(si.xce);
-        si.xce = -1;
-    }
+static int suspend_evtchn_release(int xce, int suspend_evtchn)
+{
+    if (suspend_evtchn >= 0)
+        xc_evtchn_unbind(xce, suspend_evtchn);
 
     return 0;
 }
 
-static int await_suspend(void)
+static int await_suspend(int xce, int suspend_evtchn)
 {
     int rc;
 
     do {
-        rc = xc_evtchn_pending(si.xce);
+        rc = xc_evtchn_pending(xce);
         if (rc < 0) {
             warnx("error polling suspend notification channel: %d", rc);
             return -1;
         }
-    } while (rc != si.suspend_evtchn);
+    } while (rc != suspend_evtchn);
 
     /* harmless for one-off suspend */
-    if (xc_evtchn_unmask(si.xce, si.suspend_evtchn) < 0)
+    if (xc_evtchn_unmask(xce, suspend_evtchn) < 0)
         warnx("failed to unmask suspend notification channel: %d", rc);
 
     return 0;
 }
 
-static int suspend_evtchn_init(int xc, int domid)
+static int suspend_evtchn_init(int xc, int xce, int domid)
 {
     struct xs_handle *xs;
     char path[128];
     char *portstr;
     unsigned int plen;
     int port;
-    int rc;
-
-    si.xce = -1;
-    si.suspend_evtchn = -1;
+    int rc, suspend_evtchn = -1;
 
     xs = xs_daemon_open();
     if (!xs) {
@@ -108,14 +99,8 @@ static int suspend_evtchn_init(int xc, i
     port = atoi(portstr);
     free(portstr);
 
-    si.xce = xc_evtchn_open();
-    if (si.xce < 0) {
-        warnx("failed to open event channel handle");
-        goto cleanup;
-    }
-
-    si.suspend_evtchn = xc_evtchn_bind_interdomain(si.xce, domid, port);
-    if (si.suspend_evtchn < 0) {
+    suspend_evtchn = xc_evtchn_bind_interdomain(xce, domid, port);
+    if (suspend_evtchn < 0) {
         warnx("failed to bind suspend event channel: %d", si.suspend_evtchn);
         goto cleanup;
     }
@@ -127,12 +112,13 @@ static int suspend_evtchn_init(int xc, i
     }
 
     /* event channel is pending immediately after binding */
-    await_suspend();
-
-    return 0;
-
-  cleanup:
-    suspend_evtchn_release();
+    await_suspend(xce, suspend_evtchn);
+
+    return suspend_evtchn;
+
+cleanup:
+    if (suspend_evtchn > 0)
+        suspend_evtchn_release(xce, suspend_evtchn);
 
     return -1;
 }
@@ -150,7 +136,7 @@ static int evtchn_suspend(void)
         return 0;
     }
 
-    if (await_suspend() < 0) {
+    if (await_suspend(si.xce, si.suspend_evtchn) < 0) {
         warnx("suspend failed");
         return 0;
     }
@@ -323,14 +309,23 @@ main(int argc, char **argv)
     max_f = atoi(argv[4]);
     si.flags = atoi(argv[5]);
 
-    if (suspend_evtchn_init(si.xc_fd, si.domid) < 0)
+
+    si.xce = xc_evtchn_open();
+    if (si.xce < 0)
+        errx(1, "failed to open event channel handle");
+
+    si.suspend_evtchn = suspend_evtchn_init(si.xc_fd, si.xce, si.domid);
+
+    if (si.suspend_evtchn < 0)
         warnx("suspend event channel initialization failed, using slow path");
 
     ret = xc_domain_save(si.xc_fd, io_fd, si.domid, maxit, max_f, si.flags, 
                          &suspend, !!(si.flags & XCFLAGS_HVM),
                          &init_qemu_maps, &qemu_flip_buffer);
 
-    suspend_evtchn_release();
+    suspend_evtchn_release(si.xce, si.suspend_evtchn);
+
+    xc_evtchn_close(si.xce);
 
     xc_interface_close(si.xc_fd);
 

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.