1 Index: new/qapi-schema.json
2 ===================================================================
3 --- new.orig/qapi-schema.json 2012-09-04 12:52:21.000000000 +0200
4 +++ new/qapi-schema.json 2012-09-04 12:53:35.000000000 +0200
8 { 'command': 'query-target', 'returns': 'TargetInfo' }
11 +{ 'command': 'snapshot-start' 'data': { 'statefile': 'str' } }
13 +{ 'command': 'snapshot-drive', 'data': { 'device': 'str', 'name': 'str' } }
15 +{ 'command': 'snapshot-end' }
17 ===================================================================
18 --- new.orig/qmp.c 2012-09-04 12:52:21.000000000 +0200
19 +++ new/qmp.c 2012-09-05 10:34:10.000000000 +0200
21 return arch_query_cpu_definitions(errp);
24 +static struct SnapshotState {
26 + int saved_vm_running;
29 +void qmp_snapshot_start(const char *statefile, Error **errp)
34 + if (snap_state.in_progress) {
35 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
36 + "VM snapshot already started\n");
40 + snap_state.in_progress = 1;
42 + snap_state.saved_vm_running = runstate_is_running();
44 + vm_stop(RUN_STATE_SAVE_VM);
46 + f = qemu_fopen(statefile, "wb");
48 + error_set(errp, QERR_OPEN_FILE_FAILED, statefile);
52 + ret = qemu_savevm_state(f);
55 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
56 + "Error %d while writing VM state\n", ret);
64 + snap_state.in_progress = 0;
66 + if (snap_state.saved_vm_running) {
71 +void qmp_snapshot_end(Error **errp)
73 + if (!snap_state.in_progress) {
74 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
75 + "VM snapshot not started\n");
78 + snap_state.in_progress = 0;
80 + if (snap_state.saved_vm_running) {
85 +/* Fixme: Copied from savevm */
86 +static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
89 + QEMUSnapshotInfo *sn_tab, *sn;
93 + nb_sns = bdrv_snapshot_list(bs, &sn_tab);
96 + for(i = 0; i < nb_sns; i++) {
98 + if (!strcmp(sn->id_str, name) || !strcmp(sn->name, name)) {
108 +void qmp_snapshot_drive(const char *device, const char *name, Error **errp)
110 + BlockDriverState *bs;
111 + QEMUSnapshotInfo sn1, *sn = &sn1;
119 + if (!snap_state.in_progress) {
120 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
121 + "VM snapshot not started\n");
125 + bs = bdrv_find(device);
127 + error_set(errp, QERR_DEVICE_NOT_FOUND, device);
131 + if (!bdrv_is_inserted(bs)) {
132 + error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
136 + if (bdrv_is_read_only(bs)) {
137 + error_set(errp, QERR_DEVICE_IS_READ_ONLY, device);
141 + if (!bdrv_can_snapshot(bs)) {
142 + error_set(errp, QERR_NOT_SUPPORTED);
146 + if (bdrv_snapshot_find(bs, sn, name) >= 0) {
147 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
148 + "snapshot '%s' already exists", name);
153 + memset(sn, 0, sizeof(*sn));
157 + sn->date_sec = tb.time;
158 + sn->date_nsec = tb.millitm * 1000000;
160 + gettimeofday(&tv, NULL);
161 + sn->date_sec = tv.tv_sec;
162 + sn->date_nsec = tv.tv_usec * 1000;
164 + sn->vm_clock_nsec = qemu_get_clock_ns(vm_clock);
166 + pstrcpy(sn->name, sizeof(sn->name), name);
168 + sn->vm_state_size = 0; /* do not save state */
170 + ret = bdrv_snapshot_create(bs, sn);
172 + error_set(errp, ERROR_CLASS_GENERIC_ERROR, "Error while creating snapshot on '%s'\n", device);
176 Index: new/qmp-commands.hx
177 ===================================================================
178 --- new.orig/qmp-commands.hx 2012-09-04 12:52:21.000000000 +0200
179 +++ new/qmp-commands.hx 2012-09-04 12:53:35.000000000 +0200
180 @@ -2514,3 +2514,21 @@
182 .mhandler.cmd_new = qmp_marshal_input_query_target,
186 + .name = "snapshot-start",
187 + .args_type = "statefile:s",
188 + .mhandler.cmd_new = qmp_marshal_input_snapshot_start,
192 + .name = "snapshot-drive",
193 + .args_type = "device:s,name:s",
194 + .mhandler.cmd_new = qmp_marshal_input_snapshot_drive,
198 + .name = "snapshot-end",
200 + .mhandler.cmd_new = qmp_marshal_input_snapshot_end,
203 ===================================================================
204 --- new.orig/hmp.c 2012-09-04 12:52:21.000000000 +0200
205 +++ new/hmp.c 2012-09-04 12:53:35.000000000 +0200
206 @@ -1102,3 +1102,30 @@
207 qmp_closefd(fdname, &errp);
208 hmp_handle_error(mon, &errp);
211 +void hmp_snapshot_start(Monitor *mon, const QDict *qdict)
213 + Error *errp = NULL;
214 + const char *statefile = qdict_get_str(qdict, "statefile");
216 + qmp_snapshot_start(statefile, &errp);
217 + hmp_handle_error(mon, &errp);
220 +void hmp_snapshot_drive(Monitor *mon, const QDict *qdict)
222 + Error *errp = NULL;
223 + const char *name = qdict_get_str(qdict, "name");
224 + const char *device = qdict_get_str(qdict, "device");
226 + qmp_snapshot_drive(device, name, &errp);
227 + hmp_handle_error(mon, &errp);
230 +void hmp_snapshot_end(Monitor *mon, const QDict *qdict)
232 + Error *errp = NULL;
234 + qmp_snapshot_end(&errp);
235 + hmp_handle_error(mon, &errp);
238 ===================================================================
239 --- new.orig/hmp.h 2012-09-04 12:52:21.000000000 +0200
240 +++ new/hmp.h 2012-09-04 12:53:35.000000000 +0200
242 void hmp_netdev_del(Monitor *mon, const QDict *qdict);
243 void hmp_getfd(Monitor *mon, const QDict *qdict);
244 void hmp_closefd(Monitor *mon, const QDict *qdict);
245 +void hmp_snapshot_start(Monitor *mon, const QDict *qdict);
246 +void hmp_snapshot_drive(Monitor *mon, const QDict *qdict);
247 +void hmp_snapshot_end(Monitor *mon, const QDict *qdict);
250 Index: new/hmp-commands.hx
251 ===================================================================
252 --- new.orig/hmp-commands.hx 2012-09-04 12:52:21.000000000 +0200
253 +++ new/hmp-commands.hx 2012-09-04 12:53:35.000000000 +0200
254 @@ -1494,3 +1494,28 @@
260 + .name = "snapshot-start",
261 + .args_type = "statefile:s",
262 + .params = "statefile",
263 + .help = "Prepare for snapshot and halt VM. Save VM state to statefile.",
264 + .mhandler.cmd = hmp_snapshot_start,
269 + .name = "snapshot-drive",
270 + .args_type = "device:s,name:s",
271 + .params = "device name",
272 + .help = "Create internal snapshot.",
273 + .mhandler.cmd = hmp_snapshot_drive,
277 + .name = "snapshot-end",
280 + .help = "Resume VM after snaphot.",
281 + .mhandler.cmd = hmp_snapshot_end,
284 ===================================================================
285 --- new.orig/savevm.c 2012-09-05 10:27:37.000000000 +0200
286 +++ new/savevm.c 2012-09-05 10:27:44.000000000 +0200
287 @@ -1724,7 +1724,7 @@
291 -static int qemu_savevm_state(QEMUFile *f)
292 +int qemu_savevm_state(QEMUFile *f)
295 MigrationParams params = {
297 ===================================================================
298 --- new.orig/sysemu.h 2012-09-05 10:30:42.000000000 +0200
299 +++ new/sysemu.h 2012-09-05 10:30:58.000000000 +0200
301 int qemu_savevm_state_iterate(QEMUFile *f);
302 int qemu_savevm_state_complete(QEMUFile *f);
303 void qemu_savevm_state_cancel(QEMUFile *f);
304 +int qemu_savevm_state(QEMUFile *f);
305 int qemu_loadvm_state(QEMUFile *f);