Skip to content

Commit

Permalink
migration: Replace migration's JSON writer by the general one
Browse files Browse the repository at this point in the history
Commit 8118f09 "migration: Append JSON description of migration
stream" needs a JSON writer.  The existing qobject_to_json() wasn't a
good fit, because it requires building a QObject to convert.  Instead,
migration got its very own JSON writer, in commit 190c882 "QJSON:
Add JSON writer".  It tacitly limits numbers to int64_t, and strings
contents to characters that don't need escaping, unlike
qobject_to_json().

The previous commit factored the JSON writer out of qobject_to_json().
Replace migration's JSON writer by it.

Cc: Juan Quintela <quintela@redhat.com>
Cc: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-Id: <20201211171152.146877-17-armbru@redhat.com>
Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
  • Loading branch information
Markus Armbruster committed Dec 19, 2020
1 parent 998da0b commit 3ddba9a
Show file tree
Hide file tree
Showing 29 changed files with 114 additions and 253 deletions.
2 changes: 1 addition & 1 deletion hw/display/virtio-gpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ static const VMStateDescription vmstate_virtio_gpu_scanouts = {
};

static int virtio_gpu_save(QEMUFile *f, void *opaque, size_t size,
const VMStateField *field, QJSON *vmdesc)
const VMStateField *field, JSONWriter *vmdesc)
{
VirtIOGPU *g = opaque;
struct virtio_gpu_simple_resource *res;
Expand Down
2 changes: 1 addition & 1 deletion hw/intc/s390_flic_kvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ static void kvm_s390_release_adapter_routes(S390FLICState *fs,
* reached
*/
static int kvm_flic_save(QEMUFile *f, void *opaque, size_t size,
const VMStateField *field, QJSON *vmdesc)
const VMStateField *field, JSONWriter *vmdesc)
{
KVMS390FLICState *flic = opaque;
int len = FLIC_SAVE_INITIAL_SIZE;
Expand Down
2 changes: 1 addition & 1 deletion hw/nvram/eeprom93xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ static int get_uint16_from_uint8(QEMUFile *f, void *pv, size_t size,
}

static int put_unused(QEMUFile *f, void *pv, size_t size,
const VMStateField *field, QJSON *vmdesc)
const VMStateField *field, JSONWriter *vmdesc)
{
fprintf(stderr, "uint16_from_uint8 is used only for backwards compatibility.\n");
fprintf(stderr, "Never should be used to write a new state.\n");
Expand Down
2 changes: 1 addition & 1 deletion hw/nvram/fw_cfg.c
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ static int get_uint32_as_uint16(QEMUFile *f, void *pv, size_t size,
}

static int put_unused(QEMUFile *f, void *pv, size_t size,
const VMStateField *field, QJSON *vmdesc)
const VMStateField *field, JSONWriter *vmdesc)
{
fprintf(stderr, "uint32_as_uint16 is only used for backward compatibility.\n");
fprintf(stderr, "This functions shouldn't be called.\n");
Expand Down
2 changes: 1 addition & 1 deletion hw/pci/msix.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ void msix_unset_vector_notifiers(PCIDevice *dev)
}

static int put_msix_state(QEMUFile *f, void *pv, size_t size,
const VMStateField *field, QJSON *vmdesc)
const VMStateField *field, JSONWriter *vmdesc)
{
msix_save(pv, f);

Expand Down
4 changes: 2 additions & 2 deletions hw/pci/pci.c
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ static int get_pci_config_device(QEMUFile *f, void *pv, size_t size,

/* just put buffer */
static int put_pci_config_device(QEMUFile *f, void *pv, size_t size,
const VMStateField *field, QJSON *vmdesc)
const VMStateField *field, JSONWriter *vmdesc)
{
const uint8_t **v = pv;
assert(size == pci_config_size(container_of(pv, PCIDevice, config)));
Expand Down Expand Up @@ -597,7 +597,7 @@ static int get_pci_irq_state(QEMUFile *f, void *pv, size_t size,
}

static int put_pci_irq_state(QEMUFile *f, void *pv, size_t size,
const VMStateField *field, QJSON *vmdesc)
const VMStateField *field, JSONWriter *vmdesc)
{
int i;
PCIDevice *s = container_of(pv, PCIDevice, irq_state);
Expand Down
2 changes: 1 addition & 1 deletion hw/pci/shpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ void shpc_cap_write_config(PCIDevice *d, uint32_t addr, uint32_t val, int l)
}

static int shpc_save(QEMUFile *f, void *pv, size_t size,
const VMStateField *field, QJSON *vmdesc)
const VMStateField *field, JSONWriter *vmdesc)
{
PCIDevice *d = container_of(pv, PCIDevice, shpc);
qemu_put_buffer(f, d->shpc->config, SHPC_SIZEOF(d));
Expand Down
2 changes: 1 addition & 1 deletion hw/rtc/twl92230.c
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ static int get_int32_as_uint16(QEMUFile *f, void *pv, size_t size,
}

static int put_int32_as_uint16(QEMUFile *f, void *pv, size_t size,
const VMStateField *field, QJSON *vmdesc)
const VMStateField *field, JSONWriter *vmdesc)
{
int *v = pv;
qemu_put_be16(f, *v);
Expand Down
2 changes: 1 addition & 1 deletion hw/scsi/scsi-bus.c
Original file line number Diff line number Diff line change
Expand Up @@ -1638,7 +1638,7 @@ static char *scsibus_get_fw_dev_path(DeviceState *dev)
/* SCSI request list. For simplicity, pv points to the whole device */

static int put_scsi_requests(QEMUFile *f, void *pv, size_t size,
const VMStateField *field, QJSON *vmdesc)
const VMStateField *field, JSONWriter *vmdesc)
{
SCSIDevice *s = pv;
SCSIBus *bus = DO_UPCAST(SCSIBus, qbus, s->qdev.parent_bus);
Expand Down
7 changes: 4 additions & 3 deletions hw/usb/redirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -2227,7 +2227,7 @@ static int usbredir_post_load(void *priv, int version_id)

/* For usbredirparser migration */
static int usbredir_put_parser(QEMUFile *f, void *priv, size_t unused,
const VMStateField *field, QJSON *vmdesc)
const VMStateField *field, JSONWriter *vmdesc)
{
USBRedirDevice *dev = priv;
uint8_t *data;
Expand Down Expand Up @@ -2294,7 +2294,7 @@ static const VMStateInfo usbredir_parser_vmstate_info = {

/* For buffered packets (iso/irq) queue migration */
static int usbredir_put_bufpq(QEMUFile *f, void *priv, size_t unused,
const VMStateField *field, QJSON *vmdesc)
const VMStateField *field, JSONWriter *vmdesc)
{
struct endp_data *endp = priv;
USBRedirDevice *dev = endp->dev;
Expand Down Expand Up @@ -2421,7 +2421,8 @@ static const VMStateDescription usbredir_ep_vmstate = {

/* For PacketIdQueue migration */
static int usbredir_put_packet_id_q(QEMUFile *f, void *priv, size_t unused,
const VMStateField *field, QJSON *vmdesc)
const VMStateField *field,
JSONWriter *vmdesc)
{
struct PacketIdQueue *q = priv;
USBRedirDevice *dev = q->dev;
Expand Down
4 changes: 2 additions & 2 deletions hw/virtio/virtio.c
Original file line number Diff line number Diff line change
Expand Up @@ -2745,7 +2745,7 @@ static int get_extra_state(QEMUFile *f, void *pv, size_t size,
}

static int put_extra_state(QEMUFile *f, void *pv, size_t size,
const VMStateField *field, QJSON *vmdesc)
const VMStateField *field, JSONWriter *vmdesc)
{
VirtIODevice *vdev = pv;
BusState *qbus = qdev_get_parent_bus(DEVICE(vdev));
Expand Down Expand Up @@ -2919,7 +2919,7 @@ int virtio_save(VirtIODevice *vdev, QEMUFile *f)

/* A wrapper for use as a VMState .put function */
static int virtio_device_put(QEMUFile *f, void *opaque, size_t size,
const VMStateField *field, QJSON *vmdesc)
const VMStateField *field, JSONWriter *vmdesc)
{
return virtio_save(VIRTIO_DEVICE(opaque), f);
}
Expand Down
7 changes: 4 additions & 3 deletions include/migration/vmstate.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct VMStateInfo {
const char *name;
int (*get)(QEMUFile *f, void *pv, size_t size, const VMStateField *field);
int (*put)(QEMUFile *f, void *pv, size_t size, const VMStateField *field,
QJSON *vmdesc);
JSONWriter *vmdesc);
};

enum VMStateFlags {
Expand Down Expand Up @@ -1169,9 +1169,10 @@ extern const VMStateInfo vmstate_info_qlist;
int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
void *opaque, int version_id);
int vmstate_save_state(QEMUFile *f, const VMStateDescription *vmsd,
void *opaque, QJSON *vmdesc);
void *opaque, JSONWriter *vmdesc);
int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
void *opaque, QJSON *vmdesc, int version_id);
void *opaque, JSONWriter *vmdesc,
int version_id);

bool vmstate_save_needed(const VMStateDescription *vmsd, void *opaque);

Expand Down
2 changes: 0 additions & 2 deletions include/qapi/qmp/json-writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#ifndef JSON_WRITER_H
#define JSON_WRITER_H

typedef struct JSONWriter JSONWriter;

JSONWriter *json_writer_new(bool pretty);
const char *json_writer_get(JSONWriter *);
GString *json_writer_get_and_free(JSONWriter *);
Expand Down
4 changes: 2 additions & 2 deletions include/qemu/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ typedef struct IOMMUMemoryRegion IOMMUMemoryRegion;
typedef struct ISABus ISABus;
typedef struct ISADevice ISADevice;
typedef struct IsaDma IsaDma;
typedef struct JSONWriter JSONWriter;
typedef struct MACAddr MACAddr;
typedef struct ReservedRegion ReservedRegion;
typedef struct MachineClass MachineClass;
typedef struct MachineState MachineState;
typedef struct MemoryListener MemoryListener;
Expand Down Expand Up @@ -107,14 +107,14 @@ typedef struct QEMUSGList QEMUSGList;
typedef struct QemuSpin QemuSpin;
typedef struct QEMUTimer QEMUTimer;
typedef struct QEMUTimerListGroup QEMUTimerListGroup;
typedef struct QJSON QJSON;
typedef struct QList QList;
typedef struct QNull QNull;
typedef struct QNum QNum;
typedef struct QObject QObject;
typedef struct QString QString;
typedef struct RAMBlock RAMBlock;
typedef struct Range Range;
typedef struct ReservedRegion ReservedRegion;
typedef struct SavedIOTLB SavedIOTLB;
typedef struct SHPCDevice SHPCDevice;
typedef struct SSIBus SSIBus;
Expand Down
1 change: 0 additions & 1 deletion migration/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ migration_files = files(
'vmstate.c',
'qemu-file-channel.c',
'qemu-file.c',
'qjson.c',
)
softmmu_ss.add(migration_files)

Expand Down
114 changes: 0 additions & 114 deletions migration/qjson.c

This file was deleted.

29 changes: 0 additions & 29 deletions migration/qjson.h

This file was deleted.

Loading

0 comments on commit 3ddba9a

Please sign in to comment.