1 Index: new/qapi-schema.json
2 ===================================================================
3 --- new.orig/qapi-schema.json 2012-09-07 07:41:45.000000000 +0200
4 +++ new/qapi-schema.json 2012-09-13 09:22:06.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': 'delete-drive-snapshot', 'data': { 'device': 'str', 'name': 'str' } }
17 +{ 'command': 'snapshot-end' }
19 ===================================================================
20 --- new.orig/qmp.c 2012-09-07 07:41:45.000000000 +0200
21 +++ new/qmp.c 2012-09-13 09:22:06.000000000 +0200
23 return arch_query_cpu_definitions(errp);
26 +static struct SnapshotState {
28 + int saved_vm_running;
31 +void qmp_snapshot_start(bool has_statefile, const char *statefile, Error **errp)
36 + if (snap_state.in_progress) {
37 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
38 + "VM snapshot already started\n");
42 + snap_state.in_progress = 1;
44 + snap_state.saved_vm_running = runstate_is_running();
46 + vm_stop(RUN_STATE_SAVE_VM);
51 + f = qemu_fopen(statefile, "wb");
53 + error_set(errp, QERR_OPEN_FILE_FAILED, statefile);
57 + ret = qemu_savevm_state(f);
60 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
61 + "Error %d while writing VM state\n", ret);
69 + snap_state.in_progress = 0;
71 + if (snap_state.saved_vm_running) {
76 +void qmp_snapshot_end(Error **errp)
78 + if (!snap_state.in_progress) {
79 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
80 + "VM snapshot not started\n");
83 + snap_state.in_progress = 0;
85 + if (snap_state.saved_vm_running) {
90 +/* Fixme: Copied from savevm */
91 +static int bdrv_snapshot_find(BlockDriverState *bs, QEMUSnapshotInfo *sn_info,
94 + QEMUSnapshotInfo *sn_tab, *sn;
98 + nb_sns = bdrv_snapshot_list(bs, &sn_tab);
101 + for(i = 0; i < nb_sns; i++) {
103 + if (!strcmp(sn->id_str, name) || !strcmp(sn->name, name)) {
113 +void qmp_snapshot_drive(const char *device, const char *name, Error **errp)
115 + BlockDriverState *bs;
116 + QEMUSnapshotInfo sn1, *sn = &sn1;
124 + if (!snap_state.in_progress) {
125 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
126 + "VM snapshot not started\n");
130 + bs = bdrv_find(device);
132 + error_set(errp, QERR_DEVICE_NOT_FOUND, device);
136 + if (!bdrv_is_inserted(bs)) {
137 + error_set(errp, QERR_DEVICE_HAS_NO_MEDIUM, device);
141 + if (bdrv_is_read_only(bs)) {
142 + error_set(errp, QERR_DEVICE_IS_READ_ONLY, device);
146 + if (!bdrv_can_snapshot(bs)) {
147 + error_set(errp, QERR_NOT_SUPPORTED);
151 + if (bdrv_snapshot_find(bs, sn, name) >= 0) {
152 + error_set(errp, ERROR_CLASS_GENERIC_ERROR,
153 + "snapshot '%s' already exists", name);
158 + memset(sn, 0, sizeof(*sn));
162 + sn->date_sec = tb.time;
163 + sn->date_nsec = tb.millitm * 1000000;
165 + gettimeofday(&tv, NULL);
166 + sn->date_sec = tv.tv_sec;
167 + sn->date_nsec = tv.tv_usec * 1000;
169 + sn->vm_clock_nsec = qemu_get_clock_ns(vm_clock);
171 + pstrcpy(sn->name, sizeof(sn->name), name);
173 + sn->vm_state_size = 0; /* do not save state */
175 + ret = bdrv_snapshot_create(bs, sn);
177 + error_set(errp, ERROR_CLASS_GENERIC_ERROR, "Error while creating snapshot on '%s'\n", device);
182 +void qmp_delete_drive_snapshot(const char *device, const char *name, Error **errp)
184 + BlockDriverState *bs;
185 + QEMUSnapshotInfo sn1, *sn = &sn1;
188 + bs = bdrv_find(device);
190 + error_set(errp, QERR_DEVICE_NOT_FOUND, device);
193 + if (bdrv_is_read_only(bs)) {
194 + error_set(errp, QERR_DEVICE_IS_READ_ONLY, device);
198 + if (!bdrv_can_snapshot(bs)) {
199 + error_set(errp, QERR_NOT_SUPPORTED);
203 + if (bdrv_snapshot_find(bs, sn, name) < 0) {
204 + /* return success if snapshot does not exists */
208 + ret = bdrv_snapshot_delete(bs, name);
210 + error_set(errp, ERROR_CLASS_GENERIC_ERROR, "Error while deleting snapshot on '%s'\n", device);
214 Index: new/qmp-commands.hx
215 ===================================================================
216 --- new.orig/qmp-commands.hx 2012-09-07 07:41:45.000000000 +0200
217 +++ new/qmp-commands.hx 2012-09-13 09:30:33.000000000 +0200
218 @@ -2514,3 +2514,27 @@
220 .mhandler.cmd_new = qmp_marshal_input_query_target,
224 + .name = "snapshot-start",
225 + .args_type = "statefile:s?",
226 + .mhandler.cmd_new = qmp_marshal_input_snapshot_start,
230 + .name = "snapshot-drive",
231 + .args_type = "device:s,name:s",
232 + .mhandler.cmd_new = qmp_marshal_input_snapshot_drive,
236 + .name = "delete-drive-snapshot",
237 + .args_type = "device:s,name:s",
238 + .mhandler.cmd_new = qmp_marshal_input_delete_drive_snapshot,
242 + .name = "snapshot-end",
244 + .mhandler.cmd_new = qmp_marshal_input_snapshot_end,
247 ===================================================================
248 --- new.orig/hmp.c 2012-09-07 07:41:45.000000000 +0200
249 +++ new/hmp.c 2012-09-13 09:22:06.000000000 +0200
250 @@ -1102,3 +1102,40 @@
251 qmp_closefd(fdname, &errp);
252 hmp_handle_error(mon, &errp);
255 +void hmp_snapshot_start(Monitor *mon, const QDict *qdict)
257 + Error *errp = NULL;
258 + const char *statefile = qdict_get_try_str(qdict, "statefile");
260 + qmp_snapshot_start(statefile != NULL, statefile, &errp);
261 + hmp_handle_error(mon, &errp);
264 +void hmp_snapshot_drive(Monitor *mon, const QDict *qdict)
266 + Error *errp = NULL;
267 + const char *name = qdict_get_str(qdict, "name");
268 + const char *device = qdict_get_str(qdict, "device");
270 + qmp_snapshot_drive(device, name, &errp);
271 + hmp_handle_error(mon, &errp);
274 +void hmp_delete_drive_snapshot(Monitor *mon, const QDict *qdict)
276 + Error *errp = NULL;
277 + const char *name = qdict_get_str(qdict, "name");
278 + const char *device = qdict_get_str(qdict, "device");
280 + qmp_delete_drive_snapshot(device, name, &errp);
281 + hmp_handle_error(mon, &errp);
284 +void hmp_snapshot_end(Monitor *mon, const QDict *qdict)
286 + Error *errp = NULL;
288 + qmp_snapshot_end(&errp);
289 + hmp_handle_error(mon, &errp);
292 ===================================================================
293 --- new.orig/hmp.h 2012-09-07 07:41:45.000000000 +0200
294 +++ new/hmp.h 2012-09-13 09:22:06.000000000 +0200
296 void hmp_netdev_del(Monitor *mon, const QDict *qdict);
297 void hmp_getfd(Monitor *mon, const QDict *qdict);
298 void hmp_closefd(Monitor *mon, const QDict *qdict);
299 +void hmp_snapshot_start(Monitor *mon, const QDict *qdict);
300 +void hmp_snapshot_drive(Monitor *mon, const QDict *qdict);
301 +void hmp_delete_drive_snapshot(Monitor *mon, const QDict *qdict);
302 +void hmp_snapshot_end(Monitor *mon, const QDict *qdict);
305 Index: new/hmp-commands.hx
306 ===================================================================
307 --- new.orig/hmp-commands.hx 2012-09-07 07:41:45.000000000 +0200
308 +++ new/hmp-commands.hx 2012-09-13 09:22:06.000000000 +0200
309 @@ -1494,3 +1494,35 @@
315 + .name = "snapshot-start",
316 + .args_type = "statefile:s?",
317 + .params = "[statefile]",
318 + .help = "Prepare for snapshot and halt VM. Save VM state to statefile.",
319 + .mhandler.cmd = hmp_snapshot_start,
323 + .name = "snapshot-drive",
324 + .args_type = "device:s,name:s",
325 + .params = "device name",
326 + .help = "Create internal snapshot.",
327 + .mhandler.cmd = hmp_snapshot_drive,
331 + .name = "delete-drive-snapshot",
332 + .args_type = "device:s,name:s",
333 + .params = "device name",
334 + .help = "Delete internal snapshot.",
335 + .mhandler.cmd = hmp_delete_drive_snapshot,
339 + .name = "snapshot-end",
342 + .help = "Resume VM after snaphot.",
343 + .mhandler.cmd = hmp_snapshot_end,
346 ===================================================================
347 --- new.orig/savevm.c 2012-09-07 07:41:45.000000000 +0200
348 +++ new/savevm.c 2012-09-13 09:22:06.000000000 +0200
349 @@ -1724,7 +1724,7 @@
353 -static int qemu_savevm_state(QEMUFile *f)
354 +int qemu_savevm_state(QEMUFile *f)
357 MigrationParams params = {
359 ===================================================================
360 --- new.orig/sysemu.h 2012-09-07 07:41:46.000000000 +0200
361 +++ new/sysemu.h 2012-09-13 09:22:06.000000000 +0200
363 int qemu_savevm_state_iterate(QEMUFile *f);
364 int qemu_savevm_state_complete(QEMUFile *f);
365 void qemu_savevm_state_cancel(QEMUFile *f);
366 +int qemu_savevm_state(QEMUFile *f);
367 int qemu_loadvm_state(QEMUFile *f);