Revision 72cf2d4f savevm.c
b/savevm.c | ||
---|---|---|
31 | 31 |
|
32 | 32 |
/* Needed early for CONFIG_BSD etc. */ |
33 | 33 |
#include "config-host.h" |
34 |
/* Needed early to override system queue definitions on BSD */ |
|
35 |
#include "sys-queue.h" |
|
36 | 34 |
|
37 | 35 |
#ifndef _WIN32 |
38 | 36 |
#include <sys/times.h> |
... | ... | |
92 | 90 |
#include "audio/audio.h" |
93 | 91 |
#include "migration.h" |
94 | 92 |
#include "qemu_socket.h" |
93 |
#include "qemu-queue.h" |
|
95 | 94 |
|
96 | 95 |
/* point to the block driver where the snapshots are managed */ |
97 | 96 |
static BlockDriverState *bs_snapshots; |
... | ... | |
912 | 911 |
}; |
913 | 912 |
|
914 | 913 |
typedef struct SaveStateEntry { |
915 |
TAILQ_ENTRY(SaveStateEntry) entry; |
|
914 |
QTAILQ_ENTRY(SaveStateEntry) entry;
|
|
916 | 915 |
char idstr[256]; |
917 | 916 |
int instance_id; |
918 | 917 |
int version_id; |
... | ... | |
924 | 923 |
void *opaque; |
925 | 924 |
} SaveStateEntry; |
926 | 925 |
|
927 |
static TAILQ_HEAD(savevm_handlers, SaveStateEntry) savevm_handlers = |
|
928 |
TAILQ_HEAD_INITIALIZER(savevm_handlers); |
|
926 |
static QTAILQ_HEAD(savevm_handlers, SaveStateEntry) savevm_handlers =
|
|
927 |
QTAILQ_HEAD_INITIALIZER(savevm_handlers);
|
|
929 | 928 |
static int global_section_id; |
930 | 929 |
|
931 | 930 |
static int calculate_new_instance_id(const char *idstr) |
... | ... | |
933 | 932 |
SaveStateEntry *se; |
934 | 933 |
int instance_id = 0; |
935 | 934 |
|
936 |
TAILQ_FOREACH(se, &savevm_handlers, entry) { |
|
935 |
QTAILQ_FOREACH(se, &savevm_handlers, entry) {
|
|
937 | 936 |
if (strcmp(idstr, se->idstr) == 0 |
938 | 937 |
&& instance_id <= se->instance_id) { |
939 | 938 |
instance_id = se->instance_id + 1; |
... | ... | |
972 | 971 |
se->instance_id = instance_id; |
973 | 972 |
} |
974 | 973 |
/* add at the end of list */ |
975 |
TAILQ_INSERT_TAIL(&savevm_handlers, se, entry); |
|
974 |
QTAILQ_INSERT_TAIL(&savevm_handlers, se, entry);
|
|
976 | 975 |
return 0; |
977 | 976 |
} |
978 | 977 |
|
... | ... | |
991 | 990 |
{ |
992 | 991 |
SaveStateEntry *se, *new_se; |
993 | 992 |
|
994 |
TAILQ_FOREACH_SAFE(se, &savevm_handlers, entry, new_se) { |
|
993 |
QTAILQ_FOREACH_SAFE(se, &savevm_handlers, entry, new_se) {
|
|
995 | 994 |
if (strcmp(se->idstr, idstr) == 0 && se->opaque == opaque) { |
996 |
TAILQ_REMOVE(&savevm_handlers, se, entry); |
|
995 |
QTAILQ_REMOVE(&savevm_handlers, se, entry);
|
|
997 | 996 |
qemu_free(se); |
998 | 997 |
} |
999 | 998 |
} |
... | ... | |
1020 | 1019 |
se->instance_id = instance_id; |
1021 | 1020 |
} |
1022 | 1021 |
/* add at the end of list */ |
1023 |
TAILQ_INSERT_TAIL(&savevm_handlers, se, entry); |
|
1022 |
QTAILQ_INSERT_TAIL(&savevm_handlers, se, entry);
|
|
1024 | 1023 |
return 0; |
1025 | 1024 |
} |
1026 | 1025 |
|
... | ... | |
1028 | 1027 |
{ |
1029 | 1028 |
SaveStateEntry *se, *new_se; |
1030 | 1029 |
|
1031 |
TAILQ_FOREACH_SAFE(se, &savevm_handlers, entry, new_se) { |
|
1030 |
QTAILQ_FOREACH_SAFE(se, &savevm_handlers, entry, new_se) {
|
|
1032 | 1031 |
if (se->vmsd == vmsd && se->opaque == opaque) { |
1033 |
TAILQ_REMOVE(&savevm_handlers, se, entry); |
|
1032 |
QTAILQ_REMOVE(&savevm_handlers, se, entry);
|
|
1034 | 1033 |
qemu_free(se); |
1035 | 1034 |
} |
1036 | 1035 |
} |
... | ... | |
1160 | 1159 |
qemu_put_be32(f, QEMU_VM_FILE_MAGIC); |
1161 | 1160 |
qemu_put_be32(f, QEMU_VM_FILE_VERSION); |
1162 | 1161 |
|
1163 |
TAILQ_FOREACH(se, &savevm_handlers, entry) { |
|
1162 |
QTAILQ_FOREACH(se, &savevm_handlers, entry) {
|
|
1164 | 1163 |
int len; |
1165 | 1164 |
|
1166 | 1165 |
if (se->save_live_state == NULL) |
... | ... | |
1192 | 1191 |
SaveStateEntry *se; |
1193 | 1192 |
int ret = 1; |
1194 | 1193 |
|
1195 |
TAILQ_FOREACH(se, &savevm_handlers, entry) { |
|
1194 |
QTAILQ_FOREACH(se, &savevm_handlers, entry) {
|
|
1196 | 1195 |
if (se->save_live_state == NULL) |
1197 | 1196 |
continue; |
1198 | 1197 |
|
... | ... | |
1216 | 1215 |
{ |
1217 | 1216 |
SaveStateEntry *se; |
1218 | 1217 |
|
1219 |
TAILQ_FOREACH(se, &savevm_handlers, entry) { |
|
1218 |
QTAILQ_FOREACH(se, &savevm_handlers, entry) {
|
|
1220 | 1219 |
if (se->save_live_state == NULL) |
1221 | 1220 |
continue; |
1222 | 1221 |
|
... | ... | |
1227 | 1226 |
se->save_live_state(f, QEMU_VM_SECTION_END, se->opaque); |
1228 | 1227 |
} |
1229 | 1228 |
|
1230 |
TAILQ_FOREACH(se, &savevm_handlers, entry) { |
|
1229 |
QTAILQ_FOREACH(se, &savevm_handlers, entry) {
|
|
1231 | 1230 |
int len; |
1232 | 1231 |
|
1233 | 1232 |
if (se->save_state == NULL && se->vmsd == NULL) |
... | ... | |
1292 | 1291 |
{ |
1293 | 1292 |
SaveStateEntry *se; |
1294 | 1293 |
|
1295 |
TAILQ_FOREACH(se, &savevm_handlers, entry) { |
|
1294 |
QTAILQ_FOREACH(se, &savevm_handlers, entry) {
|
|
1296 | 1295 |
if (!strcmp(se->idstr, idstr) && |
1297 | 1296 |
instance_id == se->instance_id) |
1298 | 1297 |
return se; |
... | ... | |
1301 | 1300 |
} |
1302 | 1301 |
|
1303 | 1302 |
typedef struct LoadStateEntry { |
1304 |
LIST_ENTRY(LoadStateEntry) entry; |
|
1303 |
QLIST_ENTRY(LoadStateEntry) entry;
|
|
1305 | 1304 |
SaveStateEntry *se; |
1306 | 1305 |
int section_id; |
1307 | 1306 |
int version_id; |
... | ... | |
1309 | 1308 |
|
1310 | 1309 |
int qemu_loadvm_state(QEMUFile *f) |
1311 | 1310 |
{ |
1312 |
LIST_HEAD(, LoadStateEntry) loadvm_handlers = |
|
1313 |
LIST_HEAD_INITIALIZER(loadvm_handlers); |
|
1311 |
QLIST_HEAD(, LoadStateEntry) loadvm_handlers =
|
|
1312 |
QLIST_HEAD_INITIALIZER(loadvm_handlers);
|
|
1314 | 1313 |
LoadStateEntry *le, *new_le; |
1315 | 1314 |
uint8_t section_type; |
1316 | 1315 |
unsigned int v; |
... | ... | |
1367 | 1366 |
le->se = se; |
1368 | 1367 |
le->section_id = section_id; |
1369 | 1368 |
le->version_id = version_id; |
1370 |
LIST_INSERT_HEAD(&loadvm_handlers, le, entry); |
|
1369 |
QLIST_INSERT_HEAD(&loadvm_handlers, le, entry);
|
|
1371 | 1370 |
|
1372 | 1371 |
ret = vmstate_load(f, le->se, le->version_id); |
1373 | 1372 |
if (ret < 0) { |
... | ... | |
1380 | 1379 |
case QEMU_VM_SECTION_END: |
1381 | 1380 |
section_id = qemu_get_be32(f); |
1382 | 1381 |
|
1383 |
LIST_FOREACH(le, &loadvm_handlers, entry) { |
|
1382 |
QLIST_FOREACH(le, &loadvm_handlers, entry) {
|
|
1384 | 1383 |
if (le->section_id == section_id) { |
1385 | 1384 |
break; |
1386 | 1385 |
} |
... | ... | |
1408 | 1407 |
ret = 0; |
1409 | 1408 |
|
1410 | 1409 |
out: |
1411 |
LIST_FOREACH_SAFE(le, &loadvm_handlers, entry, new_le) { |
|
1412 |
LIST_REMOVE(le, entry); |
|
1410 |
QLIST_FOREACH_SAFE(le, &loadvm_handlers, entry, new_le) {
|
|
1411 |
QLIST_REMOVE(le, entry);
|
|
1413 | 1412 |
qemu_free(le); |
1414 | 1413 |
} |
1415 | 1414 |
|
... | ... | |
1442 | 1441 |
|
1443 | 1442 |
if (bs_snapshots) |
1444 | 1443 |
return bs_snapshots; |
1445 |
TAILQ_FOREACH(dinfo, &drives, next) { |
|
1444 |
QTAILQ_FOREACH(dinfo, &drives, next) {
|
|
1446 | 1445 |
bs = dinfo->bdrv; |
1447 | 1446 |
if (bdrv_can_snapshot(bs)) |
1448 | 1447 |
goto ok; |
... | ... | |
1547 | 1546 |
|
1548 | 1547 |
/* create the snapshots */ |
1549 | 1548 |
|
1550 |
TAILQ_FOREACH(dinfo, &drives, next) { |
|
1549 |
QTAILQ_FOREACH(dinfo, &drives, next) {
|
|
1551 | 1550 |
bs1 = dinfo->bdrv; |
1552 | 1551 |
if (bdrv_has_snapshot(bs1)) { |
1553 | 1552 |
if (must_delete) { |
... | ... | |
1590 | 1589 |
/* Flush all IO requests so they don't interfere with the new state. */ |
1591 | 1590 |
qemu_aio_flush(); |
1592 | 1591 |
|
1593 |
TAILQ_FOREACH(dinfo, &drives, next) { |
|
1592 |
QTAILQ_FOREACH(dinfo, &drives, next) {
|
|
1594 | 1593 |
bs1 = dinfo->bdrv; |
1595 | 1594 |
if (bdrv_has_snapshot(bs1)) { |
1596 | 1595 |
ret = bdrv_snapshot_goto(bs1, name); |
... | ... | |
1653 | 1652 |
return; |
1654 | 1653 |
} |
1655 | 1654 |
|
1656 |
TAILQ_FOREACH(dinfo, &drives, next) { |
|
1655 |
QTAILQ_FOREACH(dinfo, &drives, next) {
|
|
1657 | 1656 |
bs1 = dinfo->bdrv; |
1658 | 1657 |
if (bdrv_has_snapshot(bs1)) { |
1659 | 1658 |
ret = bdrv_snapshot_delete(bs1, name); |
... | ... | |
1684 | 1683 |
return; |
1685 | 1684 |
} |
1686 | 1685 |
monitor_printf(mon, "Snapshot devices:"); |
1687 |
TAILQ_FOREACH(dinfo, &drives, next) { |
|
1686 |
QTAILQ_FOREACH(dinfo, &drives, next) {
|
|
1688 | 1687 |
bs1 = dinfo->bdrv; |
1689 | 1688 |
if (bdrv_has_snapshot(bs1)) { |
1690 | 1689 |
if (bs == bs1) |
Also available in: Unified diff