forked from QubesOS/qubes-vmm-xen
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patch-libxl-suspend.patch
221 lines (206 loc) · 6.55 KB
/
patch-libxl-suspend.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
From 4d1ab764a2e897ef191d6dab2de4f1c139fba994 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?=
Date: Tue, 10 Feb 2015 02:20:06 +0100
Subject: [PATCH] libxl: allow libxl_domain_suspend to simply suspend a domain,
without a savefile
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Organization: Invisible Things Lab
Cc: Marek Marczykowski-Górecki <[email protected]>
When fd=-1, no savefile will be written, but the domain will still be
suspended (but not destroyed). This works pretty well on PV domains, but
is totally untested on HVM (most likely it will crash device model).
Signed-off-by: Marek Marczykowski-Górecki <[email protected]>
Ported to Xen 4.7.0
Signed-off-by: Marcus of Wetware Labs <[email protected]>
---
tools/libxl/libxl.c | 29 +++++++++++++++++++++--------
tools/libxl/xl.h | 2 ++
tools/libxl/xl_cmdimpl.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++
tools/libxl/xl_cmdtable.c | 10 ++++++++++
4 files changed, 80 insertions(+), 8 deletions(-)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index d38d0c7..ef3c79f 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -954,9 +954,11 @@ static void domain_suspend_cb(libxl__egc *egc,
STATE_AO_GC(dss->ao);
int flrc;
- flrc = libxl__fd_flags_restore(gc, dss->fd, dss->fdfl);
- /* If suspend has failed already then report that error not this one. */
- if (flrc && !rc) rc = flrc;
+ if (dss->fd >= 0) {
+ flrc = libxl__fd_flags_restore(gc, dss->fd, dss->fdfl);
+ /* If suspend has failed already then report that error not this one. */
+ if (flrc && !rc) rc = flrc;
+ }
libxl__ao_complete(egc,ao,rc);
--- xen-4.7.0/tools/libxl/libxl.c.orig 2016-07-17 20:24:05.484000000 +0300
+++ xen-4.7.0/tools/libxl/libxl.c 2016-07-17 21:01:58.717000000 +0300
@@ -934,6 +934,13 @@
}
+static void domain_suspend_empty_cb(libxl__egc *egc,
+ libxl__domain_suspend_state *dss, int rc)
+{
+ STATE_AO_GC(dss->ao);
+ libxl__ao_complete(egc,ao,rc);
+}
+
int libxl_domain_suspend(libxl_ctx *ctx, uint32_t domid, int fd, int flags,
const libxl_asyncop_how *ao_how)
{
@@ -946,25 +953,38 @@
goto out_err;
}
- libxl__domain_save_state *dss;
- GCNEW(dss);
-
- dss->ao = ao;
- dss->callback = domain_suspend_cb;
-
- dss->domid = domid;
- dss->fd = fd;
- dss->type = type;
- dss->live = flags & LIBXL_SUSPEND_LIVE;
- dss->debug = flags & LIBXL_SUSPEND_DEBUG;
- dss->checkpointed_stream = LIBXL_CHECKPOINTED_STREAM_NONE;
-
- rc = libxl__fd_flags_modify_save(gc, dss->fd,
- ~(O_NONBLOCK|O_NDELAY), 0,
- &dss->fdfl);
- if (rc < 0) goto out_err;
+ if (fd >= 0) {
+ libxl__domain_save_state *dss;
+ GCNEW(dss);
+
+ dss->ao = ao;
+ dss->callback = domain_suspend_cb;
+
+ dss->domid = domid;
+ dss->fd = fd;
+ dss->type = type;
+ dss->live = flags & LIBXL_SUSPEND_LIVE;
+ dss->debug = flags & LIBXL_SUSPEND_DEBUG;
+ dss->checkpointed_stream = LIBXL_CHECKPOINTED_STREAM_NONE;
+
+ rc = libxl__fd_flags_modify_save(gc, dss->fd,
+ ~(O_NONBLOCK|O_NDELAY), 0,
+ &dss->fdfl);
+ if (rc < 0) goto out_err;
+
+ libxl__domain_save(egc, dss);
+ } else {
+ libxl__domain_suspend_state *dsps;
+ GCNEW(dsps);
+ dsps->ao = ao;
+ dsps->domid = domid;
+ dsps->type = type;
+ rc = libxl__domain_suspend_init(egc, dsps, type);
+ if (rc) goto out_err;
+ dsps->callback_common_done = domain_suspend_empty_cb;
+ libxl__domain_suspend(egc, dsps);
+ }
- libxl__domain_save(egc, dss);
return AO_INPROGRESS;
out_err:
diff --git a/tools/libxl/xl.h b/tools/libxl/xl.h
index 13bccba..8f36a44 100644
--- a/tools/libxl/xl.h
+++ b/tools/libxl/xl.h
@@ -48,6 +48,8 @@ int main_restore(int argc, char **argv);
int main_migrate_receive(int argc, char **argv);
int main_save(int argc, char **argv);
int main_migrate(int argc, char **argv);
+int main_suspend(int argc, char **argv);
+int main_resume(int argc, char **argv);
#endif
int main_dump_core(int argc, char **argv);
int main_pause(int argc, char **argv);
diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 9a2870e..83e9a5b 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -4096,6 +4096,27 @@ static int save_domain(uint32_t domid, const char *filename, int checkpoint,
exit(rc < 0 ? EXIT_FAILURE : EXIT_SUCCESS);
}
+static int suspend_domain(uint32_t domid)
+{
+ int rc = libxl_domain_suspend(ctx, domid, -1, 0, NULL);
+
+ if (rc < 0) {
+ fprintf(stderr, "Failed to suspend domain, resuming domain\n");
+ libxl_domain_resume(ctx, domid, 1, 0);
+ }
+ exit(rc < 0 ? 1 : 0);
+}
+
+static int resume_domain(uint32_t domid)
+{
+ int rc = libxl_domain_resume(ctx, domid, 1, 0);
+
+ if (rc < 0) {
+ fprintf(stderr, "Failed to resume domain\n");
+ }
+ exit(rc < 0 ? 1 : 0);
+}
+
static pid_t create_migration_child(const char *rune, int *send_fd,
int *recv_fd)
{
@@ -4849,6 +4870,32 @@ int main_reboot(int argc, char **argv)
return main_shutdown_or_reboot(1, argc, argv);
}
+int main_suspend(int argc, char **argv)
+{
+ int opt;
+
+ SWITCH_FOREACH_OPT(opt, "", NULL, "suspend", 1) {
+ /* No options */
+ }
+
+ suspend_domain(find_domain(argv[optind]));
+
+ return 0;
+}
+
+int main_resume(int argc, char **argv)
+{
+ int opt;
+
+ SWITCH_FOREACH_OPT(opt, "", NULL, "resume", 1) {
+ /* No options */
+ }
+
+ resume_domain(find_domain(argv[optind]));
+
+ return 0;
+}
+
int main_list(int argc, char **argv)
{
int opt;
diff --git a/tools/libxl/xl_cmdtable.c b/tools/libxl/xl_cmdtable.c
index 0071f12..12e28eb 100644
--- a/tools/libxl/xl_cmdtable.c
+++ b/tools/libxl/xl_cmdtable.c
@@ -75,6 +75,16 @@ struct cmd_spec cmd_table[] = {
" no PV drivers.\n"
"-w, --wait Wait for guest(s) to shutdown.\n"
},
+ { "suspend",
+ &main_suspend, 0, 1,
+ "Suspend a domain",
+ "[options] <Domain>",
+ },
+ { "resume",
+ &main_resume, 0, 1,
+ "Resume suspended domain",
+ "[options] <Domain>",
+ },
{ "reboot",
&main_reboot, 0, 1,
"Issue a reboot signal to a domain",
--
2.1.0