Commit 38ff78d3 authored by Eduardo Habkost's avatar Eduardo Habkost Committed by Juan Quintela

savevm.c: Coding style fixes

Signed-off-by: default avatarEduardo Habkost <ehabkost@redhat.com>
Reviewed-by: default avatarOrit Wasserman <owasserm@redhat.com>
Signed-off-by: default avatarJuan Quintela <quintela@redhat.com>
parent 5cecf414
...@@ -137,14 +137,12 @@ struct QEMUFile { ...@@ -137,14 +137,12 @@ struct QEMUFile {
int last_error; int last_error;
}; };
typedef struct QEMUFileStdio typedef struct QEMUFileStdio {
{
FILE *stdio_file; FILE *stdio_file;
QEMUFile *file; QEMUFile *file;
} QEMUFileStdio; } QEMUFileStdio;
typedef struct QEMUFileSocket typedef struct QEMUFileSocket {
{
int fd; int fd;
QEMUFile *file; QEMUFile *file;
} QEMUFileSocket; } QEMUFileSocket;
...@@ -208,7 +206,8 @@ static int stdio_get_fd(void *opaque) ...@@ -208,7 +206,8 @@ static int stdio_get_fd(void *opaque)
return fileno(s->stdio_file); return fileno(s->stdio_file);
} }
static int stdio_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size) static int stdio_put_buffer(void *opaque, const uint8_t *buf, int64_t pos,
int size)
{ {
QEMUFileStdio *s = opaque; QEMUFileStdio *s = opaque;
return fwrite(buf, 1, size, s->stdio_file); return fwrite(buf, 1, size, s->stdio_file);
...@@ -310,7 +309,7 @@ QEMUFile *qemu_popen_cmd(const char *command, const char *mode) ...@@ -310,7 +309,7 @@ QEMUFile *qemu_popen_cmd(const char *command, const char *mode)
s->stdio_file = stdio_file; s->stdio_file = stdio_file;
if(mode[0] == 'r') { if (mode[0] == 'r') {
s->file = qemu_fopen_ops(s, &stdio_pipe_read_ops); s->file = qemu_fopen_ops(s, &stdio_pipe_read_ops);
} else { } else {
s->file = qemu_fopen_ops(s, &stdio_pipe_write_ops); s->file = qemu_fopen_ops(s, &stdio_pipe_write_ops);
...@@ -429,7 +428,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode) ...@@ -429,7 +428,7 @@ QEMUFile *qemu_fdopen(int fd, const char *mode)
s = g_malloc0(sizeof(QEMUFileSocket)); s = g_malloc0(sizeof(QEMUFileSocket));
s->fd = fd; s->fd = fd;
if(mode[0] == 'r') { if (mode[0] == 'r') {
s->file = qemu_fopen_ops(s, &unix_read_ops); s->file = qemu_fopen_ops(s, &unix_read_ops);
} else { } else {
s->file = qemu_fopen_ops(s, &unix_write_ops); s->file = qemu_fopen_ops(s, &unix_write_ops);
...@@ -491,10 +490,11 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode) ...@@ -491,10 +490,11 @@ QEMUFile *qemu_fopen(const char *filename, const char *mode)
s = g_malloc0(sizeof(QEMUFileStdio)); s = g_malloc0(sizeof(QEMUFileStdio));
s->stdio_file = fopen(filename, mode); s->stdio_file = fopen(filename, mode);
if (!s->stdio_file) if (!s->stdio_file) {
goto fail; goto fail;
}
if(mode[0] == 'w') {
if (mode[0] == 'w') {
s->file = qemu_fopen_ops(s, &stdio_file_write_ops); s->file = qemu_fopen_ops(s, &stdio_file_write_ops);
} else { } else {
s->file = qemu_fopen_ops(s, &stdio_file_read_ops); s->file = qemu_fopen_ops(s, &stdio_file_read_ops);
...@@ -550,8 +550,9 @@ static const QEMUFileOps bdrv_write_ops = { ...@@ -550,8 +550,9 @@ static const QEMUFileOps bdrv_write_ops = {
static QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable) static QEMUFile *qemu_fopen_bdrv(BlockDriverState *bs, int is_writable)
{ {
if (is_writable) if (is_writable) {
return qemu_fopen_ops(bs, &bdrv_write_ops); return qemu_fopen_ops(bs, &bdrv_write_ops);
}
return qemu_fopen_ops(bs, &bdrv_read_ops); return qemu_fopen_ops(bs, &bdrv_read_ops);
} }
...@@ -703,8 +704,9 @@ static void qemu_fill_buffer(QEMUFile *f) ...@@ -703,8 +704,9 @@ static void qemu_fill_buffer(QEMUFile *f)
f->pos += len; f->pos += len;
} else if (len == 0) { } else if (len == 0) {
qemu_file_set_error(f, -EIO); qemu_file_set_error(f, -EIO);
} else if (len != -EAGAIN) } else if (len != -EAGAIN) {
qemu_file_set_error(f, len); qemu_file_set_error(f, len);
}
} }
int qemu_get_fd(QEMUFile *f) int qemu_get_fd(QEMUFile *f)
...@@ -791,8 +793,9 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size) ...@@ -791,8 +793,9 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size)
while (size > 0) { while (size > 0) {
l = IO_BUF_SIZE - f->buf_index; l = IO_BUF_SIZE - f->buf_index;
if (l > size) if (l > size) {
l = size; l = size;
}
memcpy(f->buf + f->buf_index, buf, l); memcpy(f->buf + f->buf_index, buf, l);
f->bytes_xfer += l; f->bytes_xfer += l;
if (f->ops->writev_buffer) { if (f->ops->writev_buffer) {
...@@ -1100,8 +1103,9 @@ static int get_int32_equal(QEMUFile *f, void *pv, size_t size) ...@@ -1100,8 +1103,9 @@ static int get_int32_equal(QEMUFile *f, void *pv, size_t size)
int32_t v2; int32_t v2;
qemu_get_sbe32s(f, &v2); qemu_get_sbe32s(f, &v2);
if (*v == v2) if (*v == v2) {
return 0; return 0;
}
return -EINVAL; return -EINVAL;
} }
...@@ -1120,8 +1124,9 @@ static int get_int32_le(QEMUFile *f, void *pv, size_t size) ...@@ -1120,8 +1124,9 @@ static int get_int32_le(QEMUFile *f, void *pv, size_t size)
int32_t new; int32_t new;
qemu_get_sbe32s(f, &new); qemu_get_sbe32s(f, &new);
if (*old <= new) if (*old <= new) {
return 0; return 0;
}
return -EINVAL; return -EINVAL;
} }
...@@ -1287,8 +1292,9 @@ static int get_uint8_equal(QEMUFile *f, void *pv, size_t size) ...@@ -1287,8 +1292,9 @@ static int get_uint8_equal(QEMUFile *f, void *pv, size_t size)
uint8_t v2; uint8_t v2;
qemu_get_8s(f, &v2); qemu_get_8s(f, &v2);
if (*v == v2) if (*v == v2) {
return 0; return 0;
}
return -EINVAL; return -EINVAL;
} }
...@@ -1307,8 +1313,9 @@ static int get_uint16_equal(QEMUFile *f, void *pv, size_t size) ...@@ -1307,8 +1313,9 @@ static int get_uint16_equal(QEMUFile *f, void *pv, size_t size)
uint16_t v2; uint16_t v2;
qemu_get_be16s(f, &v2); qemu_get_be16s(f, &v2);
if (*v == v2) if (*v == v2) {
return 0; return 0;
}
return -EINVAL; return -EINVAL;
} }
...@@ -1502,8 +1509,9 @@ static int calculate_compat_instance_id(const char *idstr) ...@@ -1502,8 +1509,9 @@ static int calculate_compat_instance_id(const char *idstr)
int instance_id = 0; int instance_id = 0;
QTAILQ_FOREACH(se, &savevm_handlers, entry) { QTAILQ_FOREACH(se, &savevm_handlers, entry) {
if (!se->compat) if (!se->compat) {
continue; continue;
}
if (strcmp(idstr, se->compat->idstr) == 0 if (strcmp(idstr, se->compat->idstr) == 0
&& instance_id <= se->compat->instance_id) { && instance_id <= se->compat->instance_id) {
...@@ -1690,10 +1698,11 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, ...@@ -1690,10 +1698,11 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
} }
if (vmsd->pre_load) { if (vmsd->pre_load) {
int ret = vmsd->pre_load(opaque); int ret = vmsd->pre_load(opaque);
if (ret) if (ret) {
return ret; return ret;
}
} }
while(field->name) { while (field->name) {
if ((field->field_exists && if ((field->field_exists &&
field->field_exists(opaque, version_id)) || field->field_exists(opaque, version_id)) ||
(!field->field_exists && (!field->field_exists &&
...@@ -1729,7 +1738,8 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, ...@@ -1729,7 +1738,8 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
addr = *(void **)addr; addr = *(void **)addr;
} }
if (field->flags & VMS_STRUCT) { if (field->flags & VMS_STRUCT) {
ret = vmstate_load_state(f, field->vmsd, addr, field->vmsd->version_id); ret = vmstate_load_state(f, field->vmsd, addr,
field->vmsd->version_id);
} else { } else {
ret = field->info->get(f, addr, size); ret = field->info->get(f, addr, size);
...@@ -1759,7 +1769,7 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd, ...@@ -1759,7 +1769,7 @@ void vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
if (vmsd->pre_save) { if (vmsd->pre_save) {
vmsd->pre_save(opaque); vmsd->pre_save(opaque);
} }
while(field->name) { while (field->name) {
if (!field->field_exists || if (!field->field_exists ||
field->field_exists(opaque, vmsd->version_id)) { field->field_exists(opaque, vmsd->version_id)) {
void *base_addr = opaque + field->offset; void *base_addr = opaque + field->offset;
...@@ -1818,7 +1828,7 @@ static void vmstate_save(QEMUFile *f, SaveStateEntry *se) ...@@ -1818,7 +1828,7 @@ static void vmstate_save(QEMUFile *f, SaveStateEntry *se)
se->ops->save_state(f, se->opaque); se->ops->save_state(f, se->opaque);
return; return;
} }
vmstate_save_state(f,se->vmsd, se->opaque); vmstate_save_state(f, se->vmsd, se->opaque);
} }
bool qemu_savevm_state_blocked(Error **errp) bool qemu_savevm_state_blocked(Error **errp)
...@@ -1846,7 +1856,7 @@ void qemu_savevm_state_begin(QEMUFile *f, ...@@ -1846,7 +1856,7 @@ void qemu_savevm_state_begin(QEMUFile *f,
} }
se->ops->set_params(params, se->opaque); se->ops->set_params(params, se->opaque);
} }
qemu_put_be32(f, QEMU_VM_FILE_MAGIC); qemu_put_be32(f, QEMU_VM_FILE_MAGIC);
qemu_put_be32(f, QEMU_VM_FILE_VERSION); qemu_put_be32(f, QEMU_VM_FILE_VERSION);
...@@ -2106,7 +2116,7 @@ static SaveStateEntry *find_se(const char *idstr, int instance_id) ...@@ -2106,7 +2116,7 @@ static SaveStateEntry *find_se(const char *idstr, int instance_id)
static const VMStateDescription *vmstate_get_subsection(const VMStateSubsection *sub, char *idstr) static const VMStateDescription *vmstate_get_subsection(const VMStateSubsection *sub, char *idstr)
{ {
while(sub && sub->needed) { while (sub && sub->needed) {
if (strcmp(idstr, sub->vmsd->name) == 0) { if (strcmp(idstr, sub->vmsd->name) == 0) {
return sub->vmsd; return sub->vmsd;
} }
...@@ -2198,16 +2208,18 @@ int qemu_loadvm_state(QEMUFile *f) ...@@ -2198,16 +2208,18 @@ int qemu_loadvm_state(QEMUFile *f)
} }
v = qemu_get_be32(f); v = qemu_get_be32(f);
if (v != QEMU_VM_FILE_MAGIC) if (v != QEMU_VM_FILE_MAGIC) {
return -EINVAL; return -EINVAL;
}
v = qemu_get_be32(f); v = qemu_get_be32(f);
if (v == QEMU_VM_FILE_VERSION_COMPAT) { if (v == QEMU_VM_FILE_VERSION_COMPAT) {
fprintf(stderr, "SaveVM v2 format is obsolete and don't work anymore\n"); fprintf(stderr, "SaveVM v2 format is obsolete and don't work anymore\n");
return -ENOTSUP; return -ENOTSUP;
} }
if (v != QEMU_VM_FILE_VERSION) if (v != QEMU_VM_FILE_VERSION) {
return -ENOTSUP; return -ENOTSUP;
}
while ((section_type = qemu_get_byte(f)) != QEMU_VM_EOF) { while ((section_type = qemu_get_byte(f)) != QEMU_VM_EOF) {
uint32_t instance_id, version_id, section_id; uint32_t instance_id, version_id, section_id;
...@@ -2326,8 +2338,7 @@ static int del_existing_snapshots(Monitor *mon, const char *name) ...@@ -2326,8 +2338,7 @@ static int del_existing_snapshots(Monitor *mon, const char *name)
bs = NULL; bs = NULL;
while ((bs = bdrv_next(bs))) { while ((bs = bdrv_next(bs))) {
if (bdrv_can_snapshot(bs) && if (bdrv_can_snapshot(bs) &&
bdrv_snapshot_find(bs, snapshot, name) >= 0) bdrv_snapshot_find(bs, snapshot, name) >= 0) {
{
bdrv_snapshot_delete_by_id_or_name(bs, name, &err); bdrv_snapshot_delete_by_id_or_name(bs, name, &err);
if (error_is_set(&err)) { if (error_is_set(&err)) {
monitor_printf(mon, monitor_printf(mon,
...@@ -2437,8 +2448,9 @@ void do_savevm(Monitor *mon, const QDict *qdict) ...@@ -2437,8 +2448,9 @@ void do_savevm(Monitor *mon, const QDict *qdict)
} }
the_end: the_end:
if (saved_vm_running) if (saved_vm_running) {
vm_start(); vm_start();
}
} }
void qmp_xen_save_devices_state(const char *filename, Error **errp) void qmp_xen_save_devices_state(const char *filename, Error **errp)
...@@ -2462,8 +2474,9 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp) ...@@ -2462,8 +2474,9 @@ void qmp_xen_save_devices_state(const char *filename, Error **errp)
} }
the_end: the_end:
if (saved_vm_running) if (saved_vm_running) {
vm_start(); vm_start();
}
} }
int load_vmstate(const char *name) int load_vmstate(const char *name)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment