# HG changeset patch
# User emellor@xxxxxxxxxxxxxxxxxxxxxx
# Node ID a51fcb5de4700ffbd94e84759907c34fdfef6f35
# Parent 8af1199488d3636135f3adf3f7302d4a04e9004e
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@xxxxxxxxxxxxx>
diff -r 8af1199488d3 -r a51fcb5de470 tools/libxc/xc_ia64_stubs.c
--- a/tools/libxc/xc_ia64_stubs.c Mon Jan 9 11:22:17 2006
+++ b/tools/libxc/xc_ia64_stubs.c Tue Jan 10 14:23:56 2006
@@ -23,7 +23,7 @@
}
int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
- uint32_t max_factor, uint32_t flags)
+ uint32_t max_factor, uint32_t flags, int (*suspend)(void))
{
PERROR("xc_linux_save not implemented\n");
return -1;
diff -r 8af1199488d3 -r a51fcb5de470 tools/libxc/xc_linux_save.c
--- a/tools/libxc/xc_linux_save.c Mon Jan 9 11:22:17 2006
+++ b/tools/libxc/xc_linux_save.c Tue Jan 10 14:23:56 2006
@@ -357,21 +357,14 @@
}
-static int suspend_and_state(int xc_handle, int io_fd, int dom,
- xc_dominfo_t *info,
+static int suspend_and_state(int (*suspend)(int), int xc_handle, int io_fd,
+ int dom, xc_dominfo_t *info,
vcpu_guest_context_t *ctxt)
{
int i = 0;
- char ans[30];
-
- printf("suspend\n");
- fflush(stdout);
- if (fgets(ans, sizeof(ans), stdin) == NULL) {
- ERR("failed reading suspend reply");
- return -1;
- }
- if (strncmp(ans, "done\n", 5)) {
- ERR("suspend reply incorrect: %s", ans);
+
+ if (!(*suspend)(dom)) {
+ ERR("Suspend request failed");
return -1;
}
@@ -568,7 +561,7 @@
int xc_linux_save(int xc_handle, int io_fd, uint32_t dom, uint32_t max_iters,
- uint32_t max_factor, uint32_t flags)
+ uint32_t max_factor, uint32_t flags, int (*suspend)(int))
{
xc_dominfo_t info;
@@ -748,7 +741,7 @@
last_iter = 1;
- if (suspend_and_state( xc_handle, io_fd, dom, &info, &ctxt)) {
+ if (suspend_and_state(suspend, xc_handle, io_fd, dom, &info, &ctxt)) {
ERR("Domain appears not to have suspended");
goto out;
}
@@ -1054,7 +1047,8 @@
DPRINTF("Start last iteration\n");
last_iter = 1;
- if (suspend_and_state(xc_handle, io_fd, dom, &info, &ctxt)) {
+ if (suspend_and_state(suspend, xc_handle, io_fd, dom, &info,
+ &ctxt)) {
ERR("Domain appears not to have suspended");
goto out;
}
diff -r 8af1199488d3 -r a51fcb5de470 tools/libxc/xenguest.h
--- a/tools/libxc/xenguest.h Mon Jan 9 11:22:17 2006
+++ b/tools/libxc/xenguest.h Tue Jan 10 14:23:56 2006
@@ -22,7 +22,9 @@
* @return 0 on success, -1 on failure
*/
int xc_linux_save(int xc_handle, int fd, uint32_t dom, uint32_t max_iters,
- uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */);
+ uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */,
+ int (*suspend)(int));
+
/**
* This function will restore a saved domain running Linux.
diff -r 8af1199488d3 -r a51fcb5de470 tools/xcutils/xc_save.c
--- a/tools/xcutils/xc_save.c Mon Jan 9 11:22:17 2006
+++ b/tools/xcutils/xc_save.c Tue Jan 10 14:23:56 2006
@@ -10,9 +10,27 @@
#include <err.h>
#include <stdlib.h>
#include <stdint.h>
+#include <string.h>
#include <stdio.h>
#include <xenguest.h>
+
+
+/**
+ * Issue a suspend request through stdout, and receive the acknowledgement
+ * from stdin. This is handled by XendCheckpoint in the Python layer.
+ */
+static int suspend(int domid)
+{
+ char ans[30];
+
+ printf("suspend\n");
+ fflush(stdout);
+
+ return (fgets(ans, sizeof(ans), stdin) != NULL &&
+ !strncmp(ans, "done\n", 5));
+}
+
int
main(int argc, char **argv)
@@ -29,5 +47,5 @@
max_f = atoi(argv[5]);
flags = atoi(argv[6]);
- return xc_linux_save(xc_fd, io_fd, domid, maxit, max_f, flags);
+ return xc_linux_save(xc_fd, io_fd, domid, maxit, max_f, flags, &suspend);
}
_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog
|