migration: propagate vTPM errors using Error objects
v5 cover migration: propagate vTPM errors using Error objects
Hello,
Currently, when a migration of a VM with an encrypted vTPM fails on the destination host (e.g., due to a mismatch in secret values), the error message displayed on the source host is generic and unhelpful.
For example, a typical error looks like this:
"operation failed: job 'migration out' failed: Sibling indicated error 1. operation failed: job 'migration in' failed: load of migration failed:
Input/output error"
This message does not provide any specific indication of a vTPM failure. Such generic errors are logged using error_report(), which prints to the console/monitor but does not make the detailed error accessible via the QMP query-migrate command.
This series addresses the issue, by ensuring that specific TPM error messages are propagated via the QEMU Error object.
To make this possible,
- A set of functions in the call stack is changed
to incorporate an Error object as an additional parameter.
- Also, the TPM backend makes use of a new hook called post_load_errp() that explicitly passes an Error object.
It is organized as follows,
- Patches 1-21 focuses on pushing Error object into the functions that are important in the call stack where TPM errors are observed. We still need to make changes in rest of the functions in savevm.c such that they also incorporate the errp object for propagating errors.
- Patch 22 introduces the new variants of the hooks in VMStateDescription structure. These hooks should be used in future implementations.
- Patch 23 focuses on changing the TPM backend such that the errors are set in the Error object.
While this series focuses specifically on TPM error reporting during live migration, it lays the groundwork for broader improvements. A lot of methods in savevm.c that previously returned an integer now capture errors in the Error object, enabling other modules to adopt the post_load_errp hook in the future.
One such change previously attempted:
https://lists.gnu.org/archive/html/qemu-devel/2021-02/msg01727.html
Resolves: https://issues.redhat.com/browse/RHEL-82826
---
Changes in v5:
- Solve a bug that set errp even though it was not NULL, pointed out by Fabiano in v4.
- Link to v4: https://lore.kernel.org/qemu-devel/[email protected]
Changes in v4:
- Split the patches into smaller ones based on functions. Pass NULL in the
caller until errp is made available. Every function that has an
Error **errp object passed to it, ensures that it sets the errp object
in case of failure.
- A few more functions within loadvm_process_command() now handle errors using
the errp object. I've converted these for consistency, taking Daniel's
patches (link above) as a reference.
- Along with the post_load_errp() hook, other duplicate hooks are also introduced.
This will enable us to migrate to the newer versions eventually.
- Fix some semantic errors, like using error_propagate_prepend() in places where
we need to preserve existing behaviour of accumulating the error in local_err
and then propagating it to errp. This can be refactored in a later commit.
- Add more information in commit messages explaining the changes.
- Link to v3: https://lore.kernel.org/qemu-devel/[email protected]
Changes in v3:
- Split the 2nd patch into 2. Introducing post_load_with_error() hook
has been separated from using it in the backends TPM module. This is
so that it can be acknowledged.
- Link to v2: https://lore.kernel.org/qemu-devel/[email protected]
Changes in v2:
- Combine the first two changes into one, focusing on passing the
Error object (errp) consistently through functions involved in
loading the VM's state. Other functions are not yet changed.
- As suggested in the review comment, add null checks for errp
before adding error messages, preventing crashes.
We also now correctly set errors when post-copy migration fails.
- In process_incoming_migration_co(), switch to error_prepend
instead of error_setg. This means we now null-check local_err in
the "fail" section before using it, preventing dereferencing issues.
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]
---
Arun Menon (23):
migration: push Error **errp into vmstate_subsection_load()
migration: push Error **errp into vmstate_load_state()
migration: push Error **errp into qemu_loadvm_state_header()
migration: push Error **errp into vmstate_load()
migration: push Error **errp into qemu_loadvm_section_start_full()
migration: push Error **errp into qemu_loadvm_section_part_end()
migration: push Error **errp into loadvm_process_command()
migration: push Error **errp into loadvm_handle_cmd_packaged()
migration: push Error **errp into ram_postcopy_incoming_init()
migration: push Error **errp into loadvm_postcopy_handle_advise()
migration: push Error **errp into loadvm_postcopy_handle_listen()
migration: push Error **errp into loadvm_postcopy_handle_run()
migration: push Error **errp into loadvm_postcopy_ram_handle_discard()
migration: make loadvm_postcopy_handle_resume() void
migration: push Error **errp into loadvm_handle_recv_bitmap()
migration: push Error **errp into loadvm_process_enable_colo()
migration: push Error **errp into loadvm_postcopy_handle_switchover_start()
migration: push Error **errp into qemu_loadvm_state_main()
migration: push Error **errp into qemu_loadvm_state()
migration: push Error **errp into qemu_load_device_state()
migration: Capture error in postcopy_ram_listen_thread()
migration: Add error-parameterized function variants in VMSD struct backends/tpm: Propagate vTPM error on migration failure
backends/tpm/tpm_emulator.c | 39 +++--- hw/display/virtio-gpu.c | 2 +- hw/pci/pci.c | 2 +- hw/s390x/virtio-ccw.c | 2 +- hw/scsi/spapr_vscsi.c | 2 +- hw/vfio/pci.c | 2 +- hw/virtio/virtio-mmio.c | 2 +- hw/virtio/virtio-pci.c | 2 +- hw/virtio/virtio.c | 4 +- include/migration/colo.h | 2 +- include/migration/vmstate.h | 13 +- migration/colo.c | 10 +- migration/cpr.c | 4 +- migration/migration.c | 19 +-- migration/postcopy-ram.c | 9 +- migration/postcopy-ram.h | 2 +- migration/ram.c | 14 +-- migration/ram.h | 4 +- migration/savevm.c | 293 +++++++++++++++++++++++++------------------- migration/savevm.h | 7 +- migration/vmstate-types.c | 10 +- migration/vmstate.c | 83 +++++++++---- tests/unit/test-vmstate.c | 18 +-- ui/vdagent.c | 2 +- 24 files changed, 321 insertions(+), 226 deletions(-)
---
base-commit: f96b157ebb93f94cd56ebbc99bc20982b8fd86ef
change-id: 20250624-propagate_tpm_error-bf4ae6c23d30
Best regards,
Signature · 1 line
Arun Menon <[email protected]>
PATCH v5 1/23 migration: push Error **errp into vmstate_subsection_load()
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that vmstate_subsection_load() must report an error in errp, in case of failure.
--- migration/vmstate.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
migration/vmstate.c +5 -3
@@ -25,7 +25,7 @@ static int vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, JSONWriter *vmdesc, Error **errp);static int vmstate_subsection_load (QEMUFile *f,const VMStateDescription *vmsd, -void *opaque); +void *opaque,Error **errp);/* Whether this field should exist for either save or load the VM? */ static bool
@@ -225,7 +225,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, field++; }assert (field->flags ==VMS_END ); - ret =vmstate_subsection_load (f, vmsd, opaque); + ret =vmstate_subsection_load (f, vmsd, opaque,NULL );if (ret !=0 ) {qemu_file_set_error (f, ret);return ret;
@@ -566,7 +566,7 @@ vmstate_get_subsection(const VMStateDescription * const *sub, }static int vmstate_subsection_load (QEMUFile *f,const VMStateDescription *vmsd, -void *opaque) +void *opaque,Error **errp) {trace_vmstate_subsection_load (vmsd->name);
@@ -598,6 +598,7 @@ static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd, sub_vmsd =vmstate_get_subsection (vmsd->subsections, idstr);if (sub_vmsd ==NULL ) {trace_vmstate_subsection_load_bad (vmsd->name, idstr,"(lookup)" ); +error_setg (errp,"VM subsection does not exist" );return -ENOENT ; }qemu_file_skip (f,1 );/* subsection */
@@ -608,6 +609,7 @@ static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd, ret =vmstate_load_state (f, sub_vmsd, opaque, version_id);if (ret) {trace_vmstate_subsection_load_bad (vmsd->name, idstr,"(child)" ); +error_setg (errp,"Loading VM subsection failed : %d" , ret);return ret; } }
Signature · 1 line
2.50.0
Re: [PATCH v5 01/23] migration: push Error **errp into vmstate_subsection_load()
Quoted 43 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatvmstate_subsection_load()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/vmstate.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)migration/vmstate.c +3
-3@@ -25,7 +25,7 @@ static int vmstate_subsection_save(QEMUFile *f, const VMStateDescription *vmsd, void *opaque, JSONWriter *vmdesc, Error **errp);static int vmstate_subsection_load (QEMUFile *f,const VMStateDescription *vmsd, -void *opaque); +void *opaque,Error **errp);/* Whether this field should exist for either save or load the VM? */ static bool@@ -225,7 +225,7 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, field++; }assert (field->flags ==VMS_END ); - ret =vmstate_subsection_load (f, vmsd, opaque); + ret =vmstate_subsection_load (f, vmsd, opaque,NULL );if (ret !=0 ) {qemu_file_set_error (f, ret);return ret;@@ -566,7 +566,7 @@ vmstate_get_subsection(const VMStateDescription * const *sub, }static int vmstate_subsection_load (QEMUFile *f,const VMStateDescription *vmsd, -void *opaque) +void *opaque,Error **errp) {trace_vmstate_subsection_load (vmsd->name);
migration/vmstate.c static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd, · line 601
Quoted 4 lines
migration/vmstate.c +1
-0@@ -598,6 +598,7 @@ static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd, sub_vmsd =vmstate_get_subsection (vmsd->subsections, idstr);if (sub_vmsd ==NULL ) {trace_vmstate_subsection_load_bad (vmsd->name, idstr,"(lookup)" ); +error_setg (errp,"VM subsection does not exist" );
Lets include the contextual details
error_setg(errp, "VM subsection '%s' in '%s' does not exist", idstr, vmsd->name);
migration/vmstate.c static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd, · line 612
Quoted 8 lines
migration/vmstate.c +1
-0return -ENOENT ; }qemu_file_skip (f,1 );/* subsection */ @@ -608,6 +609,7 @@ static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd, ret =vmstate_load_state (f, sub_vmsd, opaque, version_id);if (ret) {trace_vmstate_subsection_load_bad (vmsd->name, idstr,"(child)" ); +error_setg (errp,"Loading VM subsection failed : %d" , ret);
error_setg(errp, "Loading VM subsection '%s' in '%s' failed : %d", idstr, vmsd->name, ret);
migration/vmstate.c static int vmstate_subsection_load(QEMUFile *f, const VMStateDescription *vmsd, · line 615
Quoted 3 lines
migration/vmstate.c +0
-0return ret; } }
In general this method puzzles me. There are four places where we call trace_vmstate_subsection_load_bad() whose name indicates it is for an error condition.
The first two places, however, then 'return 0' to the caller indicating success, which looks inconsistent with the trace point. Assuming that is correct though, then your patch is also correct in only adding error reports to these two places.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 2/23 migration: push Error **errp into vmstate_load_state()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that vmstate_load_state() must report an error in errp, in case of failure.
--- hw/display/virtio-gpu.c | 2 +- hw/pci/pci.c | 2 +- hw/s390x/virtio-ccw.c | 2 +- hw/scsi/spapr_vscsi.c | 2 +- hw/vfio/pci.c | 2 +- hw/virtio/virtio-mmio.c | 2 +- hw/virtio/virtio-pci.c | 2 +- hw/virtio/virtio.c | 4 ++-- include/migration/vmstate.h | 2 +- migration/cpr.c | 4 ++-- migration/savevm.c | 6 ++++-- migration/vmstate-types.c | 10 +++++----- migration/vmstate.c | 43 +++++++++++++++++++++++++++---------------- tests/unit/test-vmstate.c | 18 +++++++++--------- ui/vdagent.c | 2 +- 15 files changed, 58 insertions(+), 45 deletions(-)
hw/display/virtio-gpu.c +1 -1
@@ -1343,7 +1343,7 @@ static int virtio_gpu_load(QEMUFile *f, void *opaque, size_t size, }/* load & apply scanout state */ -vmstate_load_state (f, &vmstate_virtio_gpu_scanouts, g,1 ); +vmstate_load_state (f, &vmstate_virtio_gpu_scanouts, g,1 ,NULL );return 0 ; }
hw/pci/pci.c +1 -1
@@ -934,7 +934,7 @@ void pci_device_save(PCIDevice *s, QEMUFile *f)int pci_device_load (PCIDevice *s,QEMUFile *f) {int ret; - ret =vmstate_load_state (f, &vmstate_pci_device, s, s->version_id); + ret =vmstate_load_state (f, &vmstate_pci_device, s, s->version_id,NULL );/* Restore the interrupt status bit. */ pci_update_irq_status (s);return ret;
hw/s390x/virtio-ccw.c +1 -1
@@ -1136,7 +1136,7 @@ static void virtio_ccw_save_config(DeviceState *d, QEMUFile *f)static int virtio_ccw_load_config (DeviceState *d,QEMUFile *f) {VirtioCcwDevice *dev =VIRTIO_CCW_DEVICE (d); -return vmstate_load_state (f, &vmstate_virtio_ccw_dev, dev,1 ); +return vmstate_load_state (f, &vmstate_virtio_ccw_dev, dev,1 ,NULL ); }static void virtio_ccw_pre_plugged (DeviceState *d,Error **errp)
hw/scsi/spapr_vscsi.c +1 -1
@@ -648,7 +648,7 @@ static void *vscsi_load_request(QEMUFile *f, SCSIRequest *sreq)assert (!req->active);memset (req,0 ,sizeof (*req)); - rc =vmstate_load_state (f, &vmstate_spapr_vscsi_req, req,1 ); + rc =vmstate_load_state (f, &vmstate_spapr_vscsi_req, req,1 ,NULL );if (rc) {fprintf (stderr,"VSCSI: failed loading request tag#%u\n" , sreq->tag);return NULL ;
hw/vfio/pci.c +1 -1
@@ -2797,7 +2797,7 @@ static int vfio_pci_load_config(VFIODevice *vbasedev, QEMUFile *f) old_addr[bar] = pdev->io_regions[bar].addr; } - ret =vmstate_load_state (f, &vmstate_vfio_pci_config, vdev,1 ); + ret =vmstate_load_state (f, &vmstate_vfio_pci_config, vdev,1 ,NULL );if (ret) {return ret; }
hw/virtio/virtio-mmio.c +1 -1
@@ -619,7 +619,7 @@ static int virtio_mmio_load_extra_state(DeviceState *opaque, QEMUFile *f) {VirtIOMMIOProxy *proxy =VIRTIO_MMIO (opaque); -return vmstate_load_state (f, &vmstate_virtio_mmio, proxy,1 ); +return vmstate_load_state (f, &vmstate_virtio_mmio, proxy,1 ,NULL ); }static bool virtio_mmio_has_extra_state (DeviceState *opaque)
hw/virtio/virtio-pci.c +1 -1
@@ -161,7 +161,7 @@ static int virtio_pci_load_extra_state(DeviceState *d, QEMUFile *f) {VirtIOPCIProxy *proxy =to_virtio_pci_proxy (d); -return vmstate_load_state (f, &vmstate_virtio_pci, proxy,1 ); +return vmstate_load_state (f, &vmstate_virtio_pci, proxy,1 ,NULL ); }static void virtio_pci_save_queue (DeviceState *d,int n,QEMUFile *f)
hw/virtio/virtio.c +2 -2
@@ -3317,14 +3317,14 @@ virtio_load(VirtIODevice *vdev, QEMUFile *f, int version_id) }if (vdc->vmsd) { - ret =vmstate_load_state (f, vdc->vmsd, vdev, version_id); + ret =vmstate_load_state (f, vdc->vmsd, vdev, version_id,NULL );if (ret) {return ret; } }/* Subsections */ - ret =vmstate_load_state (f, &vmstate_virtio, vdev,1 ); + ret =vmstate_load_state (f, &vmstate_virtio, vdev,1 ,NULL );if (ret) {return ret; }
include/migration/vmstate.h +1 -1
@@ -1196,7 +1196,7 @@ extern const VMStateInfo vmstate_info_qlist; }int vmstate_load_state (QEMUFile *f,const VMStateDescription *vmsd, -void *opaque,int version_id); +void *opaque,int version_id,Error **errp);int vmstate_save_state (QEMUFile *f,const VMStateDescription *vmsd,void *opaque,JSONWriter *vmdesc); int vmstate_save_state_with_err(QEMUFile *f, const VMStateDescription *vmsd,
migration/cpr.c +2 -2
@@ -233,9 +233,9 @@ int cpr_state_load(MigrationChannel *channel, Error **errp)return -ENOTSUP ; } - ret =vmstate_load_state (f, &vmstate_cpr_state, &cpr_state,1 ); + ret =vmstate_load_state (f, &vmstate_cpr_state, &cpr_state,1 , errp);if (ret) { -error_setg (errp,"vmstate_load_state error %d" , ret); +error_prepend (errp,"vmstate_load_state error %d " , ret);qemu_fclose (f);return ret; }
migration/savevm.c +4 -2
@@ -969,7 +969,8 @@ static int vmstate_load(QEMUFile *f, SaveStateEntry *se)if (!se->vmsd) {/* Old style */ return se->ops->load_state (f, se->opaque, se->load_version_id); } -return vmstate_load_state (f, se->vmsd, se->opaque, se->load_version_id); +return vmstate_load_state (f, se->vmsd, se->opaque, se->load_version_id, +NULL ); } static void vmstate_save_old_style(QEMUFile *f, SaveStateEntry *se,
@@ -2839,7 +2840,8 @@ static int qemu_loadvm_state_header(QEMUFile *f)error_report ("Configuration section missing" );return -EINVAL ; } - ret =vmstate_load_state (f, &vmstate_configuration, &savevm_state,0 ); + ret =vmstate_load_state (f, &vmstate_configuration, &savevm_state,0 , +NULL );if (ret) {return ret;
migration/vmstate-types.c +5 -5
@@ -549,7 +549,7 @@ static int get_tmp(QEMUFile *f, void *pv, size_t size,/* Writes the parent field which is at the start of the tmp */ *(void **)tmp = pv; - ret =vmstate_load_state (f, vmsd, tmp, version_id); + ret =vmstate_load_state (f, vmsd, tmp, version_id,NULL );g_free (tmp);return ret; }
@@ -649,7 +649,7 @@ static int get_qtailq(QEMUFile *f, void *pv, size_t unused_size,while (qemu_get_byte (f)) { elm =g_malloc (size); - ret =vmstate_load_state (f, vmsd, elm, version_id); + ret =vmstate_load_state (f, vmsd, elm, version_id,NULL );if (ret) {return ret; }
@@ -803,7 +803,7 @@ static int get_gtree(QEMUFile *f, void *pv, size_t unused_size, key = (void *)(uintptr_t )qemu_get_be64 (f); }else { key =g_malloc0 (key_size); - ret =vmstate_load_state (f, key_vmsd, key, version_id); + ret =vmstate_load_state (f, key_vmsd, key, version_id,NULL );if (ret) {error_report ("%s : failed to load %s (%d)" , field->name, key_vmsd->name, ret);
@@ -811,7 +811,7 @@ static int get_gtree(QEMUFile *f, void *pv, size_t unused_size, } } val =g_malloc0 (val_size); - ret =vmstate_load_state (f, val_vmsd, val, version_id); + ret =vmstate_load_state (f, val_vmsd, val, version_id,NULL );if (ret) {error_report ("%s : failed to load %s (%d)" , field->name, val_vmsd->name, ret);
@@ -892,7 +892,7 @@ static int get_qlist(QEMUFile *f, void *pv, size_t unused_size,while (qemu_get_byte (f)) { elm =g_malloc (size); - ret =vmstate_load_state (f, vmsd, elm, version_id); + ret =vmstate_load_state (f, vmsd, elm, version_id,NULL );if (ret) {error_report ("%s: failed to load %s (%d)" , field->name, vmsd->name, ret);
migration/vmstate.c +27 -16
103 lines not on this page · raw message
tests/unit/test-vmstate.c +9 -9
@@ -114,7 +114,7 @@ static int load_vmstate_one(const VMStateDescription *desc, void *obj,qemu_fclose (f); f =open_test_file (false); - ret =vmstate_load_state (f, desc, obj, version); + ret =vmstate_load_state (f, desc, obj, version,NULL );if (ret) {g_assert (qemu_file_get_error (f)); }else {
@@ -365,7 +365,7 @@ static void test_load_v1(void)QEMUFile *loading =open_test_file (false);TestStruct obj = { .b =200 , .e =500 , .f =600 }; -vmstate_load_state (loading, &vmstate_versioned, &obj,1 ); +vmstate_load_state (loading, &vmstate_versioned, &obj,1 ,NULL );g_assert (!qemu_file_get_error (loading)); g_assert_cmpint(obj.a, ==, 10); g_assert_cmpint(obj.b, ==, 200);
@@ -391,7 +391,7 @@ static void test_load_v2(void)QEMUFile *loading =open_test_file (false);TestStruct obj; -vmstate_load_state (loading, &vmstate_versioned, &obj,2 ); +vmstate_load_state (loading, &vmstate_versioned, &obj,2 ,NULL ); g_assert_cmpint(obj.a, ==, 10); g_assert_cmpint(obj.b, ==, 20); g_assert_cmpint(obj.c, ==, 30);
@@ -480,7 +480,7 @@ static void test_load_noskip(void)QEMUFile *loading =open_test_file (false);TestStruct obj = { .skip_c_e = false }; -vmstate_load_state (loading, &vmstate_skipping, &obj,2 ); +vmstate_load_state (loading, &vmstate_skipping, &obj,2 ,NULL );g_assert (!qemu_file_get_error (loading)); g_assert_cmpint(obj.a, ==, 10); g_assert_cmpint(obj.b, ==, 20);
@@ -504,7 +504,7 @@ static void test_load_skip(void)QEMUFile *loading =open_test_file (false);TestStruct obj = { .skip_c_e = true, .c =300 , .e =500 }; -vmstate_load_state (loading, &vmstate_skipping, &obj,2 ); +vmstate_load_state (loading, &vmstate_skipping, &obj,2 ,NULL );g_assert (!qemu_file_get_error (loading)); g_assert_cmpint(obj.a, ==, 10); g_assert_cmpint(obj.b, ==, 20);
@@ -773,7 +773,7 @@ static void test_load_q(void)TestQtailq tgt;QTAILQ_INIT (&tgt.q); -vmstate_load_state (fload, &vmstate_q, &tgt,1 ); +vmstate_load_state (fload, &vmstate_q, &tgt,1 ,NULL );char eof =qemu_get_byte (fload);g_assert (!qemu_file_get_error (fload)); g_assert_cmpint(tgt.i16, ==, obj_q.i16);
@@ -1127,7 +1127,7 @@ static void test_gtree_load_domain(void) fload =open_test_file (false); -vmstate_load_state (fload, &vmstate_domain, dest_domain,1 ); +vmstate_load_state (fload, &vmstate_domain, dest_domain,1 ,NULL ); eof =qemu_get_byte (fload);g_assert (!qemu_file_get_error (fload)); g_assert_cmpint(orig_domain->id, ==, dest_domain->id);
@@ -1241,7 +1241,7 @@ static void test_gtree_load_iommu(void)qemu_fclose (fsave); fload =open_test_file (false); -vmstate_load_state (fload, &vmstate_iommu, dest_iommu,1 ); +vmstate_load_state (fload, &vmstate_iommu, dest_iommu,1 ,NULL ); eof =qemu_get_byte (fload);g_assert (!qemu_file_get_error (fload)); g_assert_cmpint(orig_iommu->id, ==, dest_iommu->id);
@@ -1376,7 +1376,7 @@ static void test_load_qlist(void)qemu_fclose (fsave); fload =open_test_file (false); -vmstate_load_state (fload, &vmstate_container, dest_container,1 ); +vmstate_load_state (fload, &vmstate_container, dest_container,1 ,NULL ); eof =qemu_get_byte (fload);g_assert (!qemu_file_get_error (fload)); g_assert_cmpint(eof, ==, QEMU_VM_EOF);
ui/vdagent.c +1 -1
@@ -1008,7 +1008,7 @@ static int get_cbinfo(QEMUFile *f, void *pv, size_t size,vdagent_clipboard_peer_register (vd); - ret =vmstate_load_state (f, &vmstate_cbinfo_array, &cbinfo,0 ); + ret =vmstate_load_state (f, &vmstate_cbinfo_array, &cbinfo,0 ,NULL );if (ret) {return ret; }
Signature · 1 line
2.50.0
Re: [PATCH v5 02/23] migration: push Error **errp into vmstate_load_state()
Quoted 55 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatvmstate_load_state()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- hw/display/virtio-gpu.c | 2 +- hw/pci/pci.c | 2 +- hw/s390x/virtio-ccw.c | 2 +- hw/scsi/spapr_vscsi.c | 2 +- hw/vfio/pci.c | 2 +- hw/virtio/virtio-mmio.c | 2 +- hw/virtio/virtio-pci.c | 2 +- hw/virtio/virtio.c | 4 ++-- include/migration/vmstate.h | 2 +- migration/cpr.c | 4 ++-- migration/savevm.c | 6 ++++-- migration/vmstate-types.c | 10 +++++----- migration/vmstate.c | 43 +++++++++++++++++++++++++++---------------- tests/unit/test-vmstate.c | 18 +++++++++--------- ui/vdagent.c | 2 +- 15 files changed, 58 insertions(+), 45 deletions(-)migration/vmstate.c +4
-7@@ -132,29 +132,30 @@ static void vmstate_handle_alloc(void *ptr, const VMStateField *field, }int vmstate_load_state (QEMUFile *f,const VMStateDescription *vmsd, -void *opaque,int version_id) +void *opaque,int version_id,Error **errp) {const VMStateField *field = vmsd->fields;int ret =0 ;trace_vmstate_load_state (vmsd->name, version_id);if (version_id > vmsd->version_id) { -error_report ("%s: incoming version_id %d is too new " -"for local version_id %d" , - vmsd->name, version_id, vmsd->version_id); +error_setg (errp,"%s: incoming version_id %d is too new " +"for local version_id %d" , + vmsd->name, version_id, vmsd->version_id);trace_vmstate_load_state_end (vmsd->name,"too new" , -EINVAL );return -EINVAL ; }if (version_id < vmsd->minimum_version_id) { -error_report ("%s: incoming version_id %d is too old " -"for local minimum version_id %d" , - vmsd->name, version_id, vmsd->minimum_version_id);
migration/vmstate.c static void vmstate_handle_alloc(void *ptr, const VMStateField *field, · line 158
Quoted 10 lines
migration/vmstate.c +4
-0+error_setg (errp,"%s: incoming version_id %d is too old " +"for local minimum version_id %d" , + vmsd->name, version_id, vmsd->minimum_version_id);trace_vmstate_load_state_end (vmsd->name,"too old" , -EINVAL );return -EINVAL ; }if (vmsd->pre_load) { ret = vmsd->pre_load (opaque);if (ret) { +error_setg (errp,"VM pre load failed : %d" , ret);
Suggest including
vmsd->name, version_id, vmsd->minimum_version_id
as those are all relevant context which may aid in diagnosing this error.
Quoted 8 lines
migration/vmstate.c +0
-1return ret; } }@@ -192,10 +193,12 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,if (inner_field->flags &VMS_STRUCT ) { ret = vmstate_load_state(f, inner_field->vmsd, curr_elem, - inner_field->vmsd->version_id);
migration/vmstate.c int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, · line 204
Quoted 10 lines
migration/vmstate.c +4
-1+ inner_field->vmsd->version_id, + errp); }else if (inner_field->flags &VMS_VSTRUCT ) { ret =vmstate_load_state (f, inner_field->vmsd, curr_elem, - inner_field->struct_version_id); + inner_field->struct_version_id, + errp); }else { ret = inner_field->info->get (f, curr_elem, size, inner_field);
This should have the "error_setg" call, so...
migration/vmstate.c int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, · line 223
Quoted 13 lines
migration/vmstate.c +7
-2@@ -211,27 +214,35 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, }if (ret <0 ) {qemu_file_set_error (f, ret); -error_report ("Failed to load %s:%s" , vmsd->name, - field->name); +if (errp !=NULL ) { +error_prepend (errp,"Failed to load %s:%s " , vmsd->name, + field->name); + }else { +error_setg (errp,"Failed to load %s:%s" , vmsd->name, + field->name); + }
...this should exclusively do error_prepend.
Also include the 'version_id' here as an bit of extra context.
migration/vmstate.c int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, · line 230
Quoted 9 lines
migration/vmstate.c +2
-2trace_vmstate_load_field_error (field->name, ret);return ret; } } }else if (field->flags &VMS_MUST_EXIST ) { -error_report ("Input validation failed: %s/%s" , - vmsd->name, field->name); +error_setg (errp,"Input validation failed: %s/%s" , + vmsd->name, field->name);
Inlucde the version_id too
Quoted 6 lines
migration/vmstate.c +0
-1return -1 ; } field++; }assert (field->flags ==VMS_END ); - ret =vmstate_subsection_load (f, vmsd, opaque,NULL );
migration/vmstate.c int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, · line 245
Quoted 10 lines
migration/vmstate.c +4
-0+ ret =vmstate_subsection_load (f, vmsd, opaque, errp);if (ret !=0 ) {qemu_file_set_error (f, ret);return ret; }if (vmsd->post_load) { ret = vmsd->post_load (opaque, version_id); +if (ret <0 ) { +error_setg (errp,"VM Post load failed : %d" , ret); + }
Suggest including
vmsd->name, version_id, vmsd->minimum_version_id
migration/vmstate.c int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, · line 248
Quoted 3 lines
migration/vmstate.c +0
-0}trace_vmstate_load_state_end (vmsd->name,"end" , ret);return ret;
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v5 02/23] migration: push Error **errp into vmstate_load_state()
Hi Daniel,
Thank you so much for the review.
Quoted 79 lines · Daniel P. Berrangé
Quoted 55 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatvmstate_load_state()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- hw/display/virtio-gpu.c | 2 +- hw/pci/pci.c | 2 +- hw/s390x/virtio-ccw.c | 2 +- hw/scsi/spapr_vscsi.c | 2 +- hw/vfio/pci.c | 2 +- hw/virtio/virtio-mmio.c | 2 +- hw/virtio/virtio-pci.c | 2 +- hw/virtio/virtio.c | 4 ++-- include/migration/vmstate.h | 2 +- migration/cpr.c | 4 ++-- migration/savevm.c | 6 ++++-- migration/vmstate-types.c | 10 +++++----- migration/vmstate.c | 43 +++++++++++++++++++++++++++---------------- tests/unit/test-vmstate.c | 18 +++++++++--------- ui/vdagent.c | 2 +- 15 files changed, 58 insertions(+), 45 deletions(-)migration/vmstate.c +4
-7@@ -132,29 +132,30 @@ static void vmstate_handle_alloc(void *ptr, const VMStateField *field, }int vmstate_load_state (QEMUFile *f,const VMStateDescription *vmsd, -void *opaque,int version_id) +void *opaque,int version_id,Error **errp) {const VMStateField *field = vmsd->fields;int ret =0 ;trace_vmstate_load_state (vmsd->name, version_id);if (version_id > vmsd->version_id) { -error_report ("%s: incoming version_id %d is too new " -"for local version_id %d" , - vmsd->name, version_id, vmsd->version_id); +error_setg (errp,"%s: incoming version_id %d is too new " +"for local version_id %d" , + vmsd->name, version_id, vmsd->version_id);trace_vmstate_load_state_end (vmsd->name,"too new" , -EINVAL );return -EINVAL ; }if (version_id < vmsd->minimum_version_id) { -error_report ("%s: incoming version_id %d is too old " -"for local minimum version_id %d" , - vmsd->name, version_id, vmsd->minimum_version_id);migration/vmstate.c static void vmstate_handle_alloc(void *ptr, const VMStateField *field, · line 158
Quoted 10 lines
migration/vmstate.c +4
-0+error_setg (errp,"%s: incoming version_id %d is too old " +"for local minimum version_id %d" , + vmsd->name, version_id, vmsd->minimum_version_id);trace_vmstate_load_state_end (vmsd->name,"too old" , -EINVAL );return -EINVAL ; }if (vmsd->pre_load) { ret = vmsd->pre_load (opaque);if (ret) { +error_setg (errp,"VM pre load failed : %d" , ret);Suggest including
vmsd->name,version_id,vmsd->minimum_version_idas those are all relevant context which may aid in diagnosing this error.
Quoted 5 lines
migration/vmstate.c +0
-0return ret; } }@@ -192,10 +193,12 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,
Quoted 15 lines
migration/vmstate.c int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, · line 204
Quoted 13 lines
migration/vmstate.c +4
-2if (inner_field->flags &VMS_STRUCT ) { ret =vmstate_load_state (f, inner_field->vmsd, curr_elem, - inner_field->vmsd->version_id); + inner_field->vmsd->version_id, + errp); }else if (inner_field->flags &VMS_VSTRUCT ) { ret =vmstate_load_state (f, inner_field->vmsd, curr_elem, - inner_field->struct_version_id); + inner_field->struct_version_id, + errp); }else { ret = inner_field->info->get (f, curr_elem, size, inner_field);This should have the "
error_setg" call, so...
About this. I saw few 'get' functions that does not have error_setg() call, for example vhost_user_net_load_state() or get_fpscr() function calls. I was not sure, therefore I covered both the cases.
Now I think they do satisfy the if/else if clauses.
Please correct me if I am wrong.
Quoted 17 lines
Quoted 4 lines
migration/vmstate.c +0
-0@@ -211,27 +214,35 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, }if (ret <0 ) {migration/vmstate.c int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, · line 223
Quoted 10 lines
migration/vmstate.c +7
-2qemu_file_set_error (f, ret); -error_report ("Failed to load %s:%s" , vmsd->name, - field->name); +if (errp !=NULL ) { +error_prepend (errp,"Failed to load %s:%s " , vmsd->name, + field->name); + }else { +error_setg (errp,"Failed to load %s:%s" , vmsd->name, + field->name); + }...this should exclusively do
error_prepend.
Quoted 1 line
Also include the '
version_id' here as an bit of extra context.
Yes.
Quoted 12 lines
migration/vmstate.c int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, · line 230
Quoted 10 lines
migration/vmstate.c +2
-2trace_vmstate_load_field_error (field->name, ret);return ret; } } }else if (field->flags &VMS_MUST_EXIST ) { -error_report ("Input validation failed: %s/%s" , - vmsd->name, field->name); +error_setg (errp,"Input validation failed: %s/%s" , + vmsd->name, field->name);
Quoted 1 line
Inlucde the
version_idtoo
Yes.
Quoted 18 lines
Quoted 7 lines
migration/vmstate.c +0
-1return -1 ; } field++; }assert (field->flags ==VMS_END ); - ret =vmstate_subsection_load (f, vmsd, opaque,NULL );migration/vmstate.c int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, · line 245
Quoted 10 lines
migration/vmstate.c +4
-0+ ret =vmstate_subsection_load (f, vmsd, opaque, errp);if (ret !=0 ) {qemu_file_set_error (f, ret);return ret; }if (vmsd->post_load) { ret = vmsd->post_load (opaque, version_id); +if (ret <0 ) { +error_setg (errp,"VM Post load failed : %d" , ret); + }
Quoted 3 lines
Suggest including
vmsd->name,version_id,vmsd->minimum_version_id
Agreed.
Quoted 15 lines
migration/vmstate.c int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd, · line 248
Quoted 5 lines
migration/vmstate.c +0
-0}trace_vmstate_load_state_end (vmsd->name,"end" , ret);return ret;With regards,
DanielSignature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Regards,
Arun
PATCH v5 3/23 migration: push Error **errp into qemu_loadvm_state_header()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that qemu_loadvm_state_header() must report an error in errp, in case of failure.
--- migration/savevm.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)
migration/savevm.c +16 -9
@@ -2814,35 +2814,42 @@ qemu_loadvm_section_part_end(QEMUFile *f, uint8_t type)return 0 ; } -static int qemu_loadvm_state_header (QEMUFile *f) +static int qemu_loadvm_state_header (QEMUFile *f,Error **errp) {unsigned int v;int ret; v =qemu_get_be32 (f);if (v !=QEMU_VM_FILE_MAGIC ) { -error_report ("Not a migration stream" ); +error_setg (errp,"Not a migration stream, " +"magic: %x != %x" , v,QEMU_VM_FILE_MAGIC );return -EINVAL ; } v =qemu_get_be32 (f);if (v ==QEMU_VM_FILE_VERSION_COMPAT ) { -error_report ("SaveVM v2 format is obsolete and don't work anymore" ); +error_setg (errp,"SaveVM v2 format is obsolete and don't " +"work anymore, file version %x != %x" , + v,QEMU_VM_FILE_VERSION_COMPAT ); +return -ENOTSUP ; }if (v !=QEMU_VM_FILE_VERSION ) { -error_report ("Unsupported migration stream version" ); +error_setg (errp,"Unsupported migration stream " +"version, file version %x != %x" , v,QEMU_VM_FILE_VERSION );return -ENOTSUP ; }if (migrate_get_current ()->send_configuration) { -if (qemu_get_byte (f) !=QEMU_VM_CONFIGURATION ) { -error_report ("Configuration section missing" ); + v =qemu_get_byte (f); +if (v !=QEMU_VM_CONFIGURATION ) { +error_setg (errp,"Configuration section missing," +"%x != %x" , v,QEMU_VM_CONFIGURATION );return -EINVAL ; } - ret =vmstate_load_state (f, &vmstate_configuration, &savevm_state,0 , -NULL ); + ret =vmstate_load_state (f, &vmstate_configuration, &savevm_state,0 , + errp);if (ret) {return ret; }
@@ -3119,7 +3126,7 @@ int qemu_loadvm_state(QEMUFile *f)qemu_loadvm_thread_pool_create (mis); - ret =qemu_loadvm_state_header (f); + ret =qemu_loadvm_state_header (f,NULL );if (ret) {return ret; }
Signature · 1 line
2.50.0
Re: [PATCH v5 03/23] migration: push Error **errp into qemu_loadvm_state_header()
Quoted 28 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatqemu_loadvm_state_header()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/savevm.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-)migration/savevm.c +1
-2@@ -2814,35 +2814,42 @@ qemu_loadvm_section_part_end(QEMUFile *f, uint8_t type)return 0 ; } -static int qemu_loadvm_state_header (QEMUFile *f) +static int qemu_loadvm_state_header (QEMUFile *f,Error **errp) {unsigned int v;int ret; v =qemu_get_be32 (f);if (v !=QEMU_VM_FILE_MAGIC ) { -error_report ("Not a migration stream" );
migration/savevm.c qemu_loadvm_section_part_end(QEMUFile *f, uint8_t type) · line 2832
Quoted 10 lines
migration/savevm.c +4
-1+error_setg (errp,"Not a migration stream, " +"magic: %x != %x" , v,QEMU_VM_FILE_MAGIC );return -EINVAL ; } v =qemu_get_be32 (f);if (v ==QEMU_VM_FILE_VERSION_COMPAT ) { -error_report ("SaveVM v2 format is obsolete and don't work anymore" ); + error_setg(errp, "SaveVM v2 format is obsolete and don't " + "work anymore, file version %x != %x",
This is a pre-existing issue, but can be fix the tail end of the message to say
"SaveVM v2 format is obsolete and no longer supported, file version %x != %x"
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 4/23 migration: push Error **errp into vmstate_load()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that vmstate_load() must report an error in errp, in case of failure.
--- migration/savevm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
migration/savevm.c +4 -4
@@ -963,14 +963,14 @@ void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd, } } -static int vmstate_load (QEMUFile *f,SaveStateEntry *se) +static int vmstate_load (QEMUFile *f,SaveStateEntry *se,Error **errp) {trace_vmstate_load (se->idstr, se->vmsd ? se->vmsd->name :"(old)" );if (!se->vmsd) {/* Old style */ return se->ops->load_state (f, se->opaque, se->load_version_id); }return vmstate_load_state (f, se->vmsd, se->opaque, se->load_version_id, -NULL ); + errp); } static void vmstate_save_old_style(QEMUFile *f, SaveStateEntry *se,
@@ -2741,7 +2741,7 @@ qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type) start_ts =qemu_clock_get_us (QEMU_CLOCK_REALTIME ); } - ret =vmstate_load (f, se); + ret =vmstate_load (f, se,NULL );if (ret <0 ) {error_report ("error while loading state for instance 0x%" PRIx32" of" " device '%s'" , instance_id, idstr);
@@ -2794,7 +2794,7 @@ qemu_loadvm_section_part_end(QEMUFile *f, uint8_t type) start_ts =qemu_clock_get_us (QEMU_CLOCK_REALTIME ); } - ret =vmstate_load (f, se); + ret =vmstate_load (f, se,NULL );if (ret <0 ) {error_report ("error while loading state section id %d(%s)" , section_id, se->idstr);
Signature · 1 line
2.50.0
Re: [PATCH v5 04/23] migration: push Error **errp into vmstate_load()
Quoted 16 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatvmstate_load()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/savevm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)migration/savevm.c +0
-0
migration/savevm.c void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd, · line 970
Quoted 9 lines
migration/savevm.c +1
-1@@ -963,14 +963,14 @@ void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd, } } -static int vmstate_load (QEMUFile *f,SaveStateEntry *se) +static int vmstate_load (QEMUFile *f,SaveStateEntry *se,Error **errp) {trace_vmstate_load (se->idstr, se->vmsd ? se->vmsd->name :"(old)" );if (!se->vmsd) {/* Old style */ return se->ops->load_state (f, se->opaque, se->load_version_id);
This method can return a failure code, so we need error_setg() here surely ? (and later augment/replace 'load_state' with a variant that has an "errp" parameter)
migration/savevm.c void vmstate_unregister(VMStateIf *obj, const VMStateDescription *vmsd, · line 975
Quoted 6 lines
migration/savevm.c +1
-1}return vmstate_load_state (f, se->vmsd, se->opaque, se->load_version_id, -NULL ); + errp); }
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 5/23 migration: push Error **errp into qemu_loadvm_section_start_full()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that qemu_loadvm_section_start_full() must report an error in errp, in case of failure.
--- migration/savevm.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)
migration/savevm.c +18 -16
@@ -2684,7 +2684,7 @@ static bool check_section_footer(QEMUFile *f, SaveStateEntry *se) }static int -qemu_loadvm_section_start_full (QEMUFile *f,uint8_t type) +qemu_loadvm_section_start_full (QEMUFile *f,uint8_t type,Error **errp) {bool trace_downtime = (type ==QEMU_VM_SECTION_FULL );uint32_t instance_id, version_id, section_id;
@@ -2696,8 +2696,8 @@ qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type)/* Read section start */ section_id =qemu_get_be32 (f);if (!qemu_get_counted_string (f, idstr)) { -error_report ("Unable to read ID string for section %u" , - section_id); +error_setg (errp,"Unable to read ID string for section %u" , + section_id);return -EINVAL ; } instance_id =qemu_get_be32 (f);
@@ -2705,8 +2705,8 @@ qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type) ret =qemu_file_get_error (f);if (ret) { -error_report ("%s: Failed to read instance/version ID: %d" , - __func__, ret); +error_setg (errp,"%s: Failed to read instance/version ID: %d" , + __func__, ret);return ret; }
@@ -2715,17 +2715,17 @@ qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type)/* Find savevm section */ se =find_se (idstr, instance_id);if (se ==NULL ) { -error_report ("Unknown savevm section or instance '%s' %" PRIu32". " -"Make sure that your current VM setup matches your " -"saved VM setup, including any hotplugged devices" , - idstr, instance_id); +error_setg (errp,"Unknown savevm section or instance '%s' %" PRIu32". " +"Make sure that your current VM setup matches your " +"saved VM setup, including any hotplugged devices" , + idstr, instance_id);return -EINVAL ; }/* Validate version */ if (version_id > se->version_id) { -error_report ("savevm: unsupported version %d for '%s' v%d" , - version_id, idstr, se->version_id); +error_setg (errp,"savevm: unsupported version %d for '%s' v%d" , + version_id, idstr, se->version_id);return -EINVAL ; } se->load_version_id = version_id;
@@ -2733,7 +2733,7 @@ qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type)/* Validate if it is a device's state */ if (xen_enabled () && se->is_ram) { -error_report ("loadvm: %s RAM loading not allowed on Xen" , idstr); +error_setg (errp,"loadvm: %s RAM loading not allowed on Xen" , idstr);return -EINVAL ; }
@@ -2741,10 +2741,11 @@ qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type) start_ts =qemu_clock_get_us (QEMU_CLOCK_REALTIME ); } - ret =vmstate_load (f, se,NULL ); + ret =vmstate_load (f, se, errp);if (ret <0 ) { -error_report ("error while loading state for instance 0x%" PRIx32" of" -" device '%s'" , instance_id, idstr); +error_prepend (errp,"error while loading state for" +" instance 0x%" PRIx32" of" +" device '%s' " , instance_id, idstr);return ret; }
@@ -2755,6 +2756,7 @@ qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type) }if (!check_section_footer (f, se)) { +error_setg (errp,"Reading footer section failed" );return -EINVAL ; }
@@ -3055,7 +3057,7 @@ retry:switch (section_type) {case QEMU_VM_SECTION_START :case QEMU_VM_SECTION_FULL : - ret =qemu_loadvm_section_start_full (f, section_type); + ret =qemu_loadvm_section_start_full (f, section_type,NULL );if (ret <0 ) { goto out; }
Signature · 1 line
2.50.0
Re: [PATCH v5 05/23] migration: push Error **errp into qemu_loadvm_section_start_full()
Quoted 18 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatqemu_loadvm_section_start_full()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/savevm.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-)migration/savevm.c +0
-0@@ -2684,7 +2684,7 @@ static bool check_section_footer(QEMUFile *f, SaveStateEntry *se)
migration/savevm.c qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type) · line 2709
Quoted 7 lines
migration/savevm.c +2
-2@@ -2705,8 +2705,8 @@ qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type) ret =qemu_file_get_error (f);if (ret) { -error_report ("%s: Failed to read instance/version ID: %d" , - __func__, ret); +error_setg (errp,"%s: Failed to read instance/version ID: %d" , + __func__, ret);
If we're going to use "__func__" in error messages, it should be done universally, not as a one-off. IMHO, it is almost always not desirable though, as error messages ought to be expressive enough to not need the C function name included. IOW, just drop __func__, it is fine without it here.
migration/savevm.c qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type) · line 2759
Quoted 5 lines
migration/savevm.c +1
-0@@ -2755,6 +2756,7 @@ qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type) }if (!check_section_footer (f, se)) { +error_setg (errp,"Reading footer section failed" );
Since we have them from earlier, can you include things like idstr, instance_id, version_id as context.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 6/23 migration: push Error **errp into qemu_loadvm_section_part_end()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that qemu_loadvm_section_part_end() must report an error in errp, in case of failure.
--- migration/savevm.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)
migration/savevm.c +9 -8
@@ -2764,7 +2764,7 @@ qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type, Error **errp) }static int -qemu_loadvm_section_part_end (QEMUFile *f,uint8_t type) +qemu_loadvm_section_part_end (QEMUFile *f,uint8_t type,Error **errp) {bool trace_downtime = (type ==QEMU_VM_SECTION_END );int64_t start_ts, end_ts;
@@ -2776,8 +2776,8 @@ qemu_loadvm_section_part_end(QEMUFile *f, uint8_t type) ret =qemu_file_get_error (f);if (ret) { -error_report ("%s: Failed to read section ID: %d" , - __func__, ret); +error_setg (errp,"%s: Failed to read section ID: %d" , + __func__, ret);return ret; }
@@ -2788,7 +2788,7 @@ qemu_loadvm_section_part_end(QEMUFile *f, uint8_t type) } }if (se ==NULL ) { -error_report ("Unknown savevm section %d" , section_id); +error_setg (errp,"Unknown savevm section %d" , section_id);return -EINVAL ; }
@@ -2796,10 +2796,10 @@ qemu_loadvm_section_part_end(QEMUFile *f, uint8_t type) start_ts =qemu_clock_get_us (QEMU_CLOCK_REALTIME ); } - ret =vmstate_load (f, se,NULL ); + ret =vmstate_load (f, se, errp);if (ret <0 ) { -error_report ("error while loading state section id %d(%s)" , - section_id, se->idstr); +error_prepend (errp,"error while loading state section id %d(%s) " , + section_id, se->idstr);return ret; }
@@ -2810,6 +2810,7 @@ qemu_loadvm_section_part_end(QEMUFile *f, uint8_t type) }if (!check_section_footer (f, se)) { +error_setg (errp,"Check section footer error" );return -EINVAL ; }
@@ -3064,7 +3065,7 @@ retry:break ;case QEMU_VM_SECTION_PART :case QEMU_VM_SECTION_END : - ret =qemu_loadvm_section_part_end (f, section_type); + ret =qemu_loadvm_section_part_end (f, section_type,NULL );if (ret <0 ) { goto out; }
Signature · 1 line
2.50.0
Re: [PATCH v5 06/23] migration: push Error **errp into qemu_loadvm_section_part_end()
Quoted 25 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatqemu_loadvm_section_part_end()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/savevm.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-)migration/savevm.c +1
-1@@ -2764,7 +2764,7 @@ qemu_loadvm_section_start_full(QEMUFile *f, uint8_t type, Error **errp) }static int -qemu_loadvm_section_part_end (QEMUFile *f,uint8_t type) +qemu_loadvm_section_part_end (QEMUFile *f,uint8_t type,Error **errp) {bool trace_downtime = (type ==QEMU_VM_SECTION_END );int64_t start_ts, end_ts;
migration/savevm.c qemu_loadvm_section_part_end(QEMUFile *f, uint8_t type) · line 2780
Quoted 7 lines
migration/savevm.c +2
-2@@ -2776,8 +2776,8 @@ qemu_loadvm_section_part_end(QEMUFile *f, uint8_t type) ret =qemu_file_get_error (f);if (ret) { -error_report ("%s: Failed to read section ID: %d" , - __func__, ret); +error_setg (errp,"%s: Failed to read section ID: %d" , + __func__, ret);
Same note about dropping __func__
migration/savevm.c qemu_loadvm_section_part_end(QEMUFile *f, uint8_t type) · line 2813
Quoted 5 lines
migration/savevm.c +1
-0@@ -2810,6 +2810,7 @@ qemu_loadvm_section_part_end(QEMUFile *f, uint8_t type) }if (!check_section_footer (f, se)) { +error_setg (errp,"Check section footer error" );
Include "section_id" as that's the only context we have available.
migration/savevm.c qemu_loadvm_section_part_end(QEMUFile *f, uint8_t type) · line 2794
Quoted 3 lines
migration/savevm.c +0
-0return -EINVAL ; }
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 7/23 migration: push Error **errp into loadvm_process_command()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that loadvm_process_command() must report an error in errp, in case of failure.
--- migration/savevm.c | 89 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 22 deletions(-)
migration/savevm.c +67 -22
@@ -2540,12 +2540,13 @@ static int loadvm_postcopy_handle_switchover_start(void)* LOADVM_QUIT All good, but exit the loop * <0 Error */ -static int loadvm_process_command (QEMUFile *f) +static int loadvm_process_command (QEMUFile *f,Error **errp) {MigrationIncomingState *mis =migration_incoming_get_current ();uint16_t cmd;uint16_t len;uint32_t tmp32; +int ret; cmd =qemu_get_be16 (f); len =qemu_get_be16 (f);
@@ -2556,16 +2557,16 @@ static int loadvm_process_command(QEMUFile *f) }if (cmd >=MIG_CMD_MAX || cmd ==MIG_CMD_INVALID ) { -error_report ("MIG_CMD 0x%x unknown (len 0x%x)" , cmd, len); +error_setg (errp,"MIG_CMD 0x%x unknown (len 0x%x)" , cmd, len);return -EINVAL ; }trace_loadvm_process_command (mig_cmd_args[cmd].name, len);if (mig_cmd_args[cmd].len !=-1 && mig_cmd_args[cmd].len != len) { -error_report ("%s received with bad length - expecting %zu, got %d" , - mig_cmd_args[cmd].name, - (size_t )mig_cmd_args[cmd].len, len); +error_setg (errp,"%s received with bad length - expecting %zu, got %d" , + mig_cmd_args[cmd].name, + (size_t )mig_cmd_args[cmd].len, len);return -ERANGE ; }
@@ -2578,7 +2579,7 @@ static int loadvm_process_command(QEMUFile *f) } mis->to_src_file =qemu_file_get_return_path (f);if (!mis->to_src_file) { -error_report ("CMD_OPEN_RETURN_PATH failed" ); +error_setg (errp,"CMD_OPEN_RETURN_PATH failed" );return -1 ; }
@@ -2588,11 +2589,10 @@ static int loadvm_process_command(QEMUFile *f)* been created. */ if (migrate_switchover_ack () && !mis->switchover_ack_pending_num) { -int ret =migrate_send_rp_switchover_ack (mis); + ret =migrate_send_rp_switchover_ack (mis);if (ret) { -error_report ( -"Could not send switchover ack RP MSG, err %d (%s)" , ret, -strerror (-ret)); +error_setg (errp,"Could not send switchover ack " +"RP MSG, err %d (%s)" , ret,strerror (-ret));return ret; } }
@@ -2602,39 +2602,84 @@ static int loadvm_process_command(QEMUFile *f) tmp32 =qemu_get_be32 (f);trace_loadvm_process_command_ping (tmp32);if (!mis->to_src_file) { -error_report ("CMD_PING (0x%x) received with no return path" , - tmp32); +error_setg (errp,"CMD_PING (0x%x) received with no return path" , + tmp32);return -1 ; }migrate_send_rp_pong (mis, tmp32);break ;case MIG_CMD_PACKAGED : -return loadvm_handle_cmd_packaged (mis); + ret =loadvm_handle_cmd_packaged (mis); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_POSTCOPY_ADVISE : -return loadvm_postcopy_handle_advise (mis, len); + ret =loadvm_postcopy_handle_advise (mis, len); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_POSTCOPY_LISTEN : -return loadvm_postcopy_handle_listen (mis); + ret =loadvm_postcopy_handle_listen (mis); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_POSTCOPY_RUN : -return loadvm_postcopy_handle_run (mis); + ret =loadvm_postcopy_handle_run (mis); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_POSTCOPY_RAM_DISCARD : -return loadvm_postcopy_ram_handle_discard (mis, len); + ret =loadvm_postcopy_ram_handle_discard (mis, len); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_POSTCOPY_RESUME : -return loadvm_postcopy_handle_resume (mis); + ret =loadvm_postcopy_handle_resume (mis); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_RECV_BITMAP : -return loadvm_handle_recv_bitmap (mis, len); + ret =loadvm_handle_recv_bitmap (mis, len); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_ENABLE_COLO : -return loadvm_process_enable_colo (mis); + ret =loadvm_process_enable_colo (mis); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_SWITCHOVER_START : -return loadvm_postcopy_handle_switchover_start (); + ret =loadvm_postcopy_handle_switchover_start (); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret; }return 0 ;
@@ -3071,7 +3116,7 @@ retry: }break ;case QEMU_VM_COMMAND : - ret =loadvm_process_command (f); + ret =loadvm_process_command (f,NULL );trace_qemu_loadvm_state_section_command (ret);if ((ret <0 ) || (ret ==LOADVM_QUIT )) { goto out;
Signature · 1 line
2.50.0
Re: [PATCH v5 07/23] migration: push Error **errp into loadvm_process_command()
Quoted 42 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatloadvm_process_command()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/savevm.c | 89 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 22 deletions(-)migration/savevm.c +3
-2@@ -2540,12 +2540,13 @@ static int loadvm_postcopy_handle_switchover_start(void)* LOADVM_QUIT All good, but exit the loop * <0 Error */ -static int loadvm_process_command (QEMUFile *f) +static int loadvm_process_command (QEMUFile *f,Error **errp) {MigrationIncomingState *mis =migration_incoming_get_current ();uint16_t cmd;uint16_t len;uint32_t tmp32; +int ret; cmd =qemu_get_be16 (f); len =qemu_get_be16 (f);@@ -2556,16 +2557,16 @@ static int loadvm_process_command(QEMUFile *f) }if (cmd >=MIG_CMD_MAX || cmd ==MIG_CMD_INVALID ) { -error_report ("MIG_CMD 0x%x unknown (len 0x%x)" , cmd, len); +error_setg (errp,"MIG_CMD 0x%x unknown (len 0x%x)" , cmd, len);return -EINVAL ; }
migration/savevm.c static int loadvm_process_command(QEMUFile *f) · line 2582
Quoted 5 lines
migration/savevm.c +1
-1@@ -2578,7 +2579,7 @@ static int loadvm_process_command(QEMUFile *f) } mis->to_src_file =qemu_file_get_return_path (f);if (!mis->to_src_file) { -error_report ("CMD_OPEN_RETURN_PATH failed" ); +error_setg (errp,"CMD_OPEN_RETURN_PATH failed" );
This is a wierd one, according to the docs qemu_file_get_return_path can return NULL, but according to the impl it will always succeed.
Suggest creating an earlier patch that fixes the docs and removes the check for failure here, not least because this existing error message provides no useful information, and none will be available since it can't fail.
Quoted 71 lines
migration/savevm.c +48
-8case MIG_CMD_PACKAGED : -return loadvm_handle_cmd_packaged (mis); + ret =loadvm_handle_cmd_packaged (mis); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_POSTCOPY_ADVISE : -return loadvm_postcopy_handle_advise (mis, len); + ret =loadvm_postcopy_handle_advise (mis, len); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_POSTCOPY_LISTEN : -return loadvm_postcopy_handle_listen (mis); + ret =loadvm_postcopy_handle_listen (mis); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_POSTCOPY_RUN : -return loadvm_postcopy_handle_run (mis); + ret =loadvm_postcopy_handle_run (mis); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_POSTCOPY_RAM_DISCARD : -return loadvm_postcopy_ram_handle_discard (mis, len); + ret =loadvm_postcopy_ram_handle_discard (mis, len); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_POSTCOPY_RESUME : -return loadvm_postcopy_handle_resume (mis); + ret =loadvm_postcopy_handle_resume (mis); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_RECV_BITMAP : -return loadvm_handle_recv_bitmap (mis, len); + ret =loadvm_handle_recv_bitmap (mis, len); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_ENABLE_COLO : -return loadvm_process_enable_colo (mis); + ret =loadvm_process_enable_colo (mis); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;
migration/savevm.c static int loadvm_process_command(QEMUFile *f) · line 2683
Quoted 10 lines
migration/savevm.c +6
-1case MIG_CMD_SWITCHOVER_START : -return loadvm_postcopy_handle_switchover_start (); + ret =loadvm_postcopy_handle_switchover_start (); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret; }
Can you ensure that each of these have unique error message strings, as if they ever appear, it will be important to distinguish which of these nine commands actually failed.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v5 07/23] migration: push Error **errp into loadvm_process_command()
Quoted 99 lines · Daniel P. Berrangé
Quoted 87 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatloadvm_process_command()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/savevm.c | 89 ++++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 67 insertions(+), 22 deletions(-)migration/savevm.c +48
-8case MIG_CMD_PACKAGED : -return loadvm_handle_cmd_packaged (mis); + ret =loadvm_handle_cmd_packaged (mis); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_POSTCOPY_ADVISE : -return loadvm_postcopy_handle_advise (mis, len); + ret =loadvm_postcopy_handle_advise (mis, len); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_POSTCOPY_LISTEN : -return loadvm_postcopy_handle_listen (mis); + ret =loadvm_postcopy_handle_listen (mis); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_POSTCOPY_RUN : -return loadvm_postcopy_handle_run (mis); + ret =loadvm_postcopy_handle_run (mis); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_POSTCOPY_RAM_DISCARD : -return loadvm_postcopy_ram_handle_discard (mis, len); + ret =loadvm_postcopy_ram_handle_discard (mis, len); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_POSTCOPY_RESUME : -return loadvm_postcopy_handle_resume (mis); + ret =loadvm_postcopy_handle_resume (mis); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_RECV_BITMAP : -return loadvm_handle_recv_bitmap (mis, len); + ret =loadvm_handle_recv_bitmap (mis, len); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;case MIG_CMD_ENABLE_COLO : -return loadvm_process_enable_colo (mis); + ret =loadvm_process_enable_colo (mis); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret;migration/savevm.c static int loadvm_process_command(QEMUFile *f) · line 2683
Quoted 10 lines
migration/savevm.c +6
-1case MIG_CMD_SWITCHOVER_START : -return loadvm_postcopy_handle_switchover_start (); + ret =loadvm_postcopy_handle_switchover_start (); +if (ret <0 ) { +error_setg (errp,"Failed to load device state command: %d" , ret); +return -1 ; + } +return ret; }
Quoted 3 lines
Can you ensure that each of these have unique error message strings, as if they ever appear, it will be important to distinguish which of these nine commands actually failed.
Ignore this comment. I see you eliminate all these generic error messages in following patches, so this is only ever a transient issue half way through the patch series.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 8/23 migration: push Error **errp into loadvm_handle_cmd_packaged()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that loadvm_handle_cmd_packaged() must report an error in errp, in case of failure.
--- migration/savevm.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
migration/savevm.c +8 -10
@@ -2399,7 +2399,7 @@ static int loadvm_postcopy_handle_resume(MigrationIncomingState *mis)* Returns: Negative values on error * */ -static int loadvm_handle_cmd_packaged (MigrationIncomingState *mis) +static int loadvm_handle_cmd_packaged (MigrationIncomingState *mis,Error **errp) {int ret;size_t length;
@@ -2409,7 +2409,7 @@ static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis)trace_loadvm_handle_cmd_packaged (length);if (length >MAX_VM_CMD_PACKAGED_SIZE ) { -error_report ("Unreasonably large packaged state: %zu" , length); +error_setg (errp,"Unreasonably large packaged state: %zu" , length);return -1 ; }
@@ -2420,8 +2420,8 @@ static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis) length);if (ret != length) {object_unref (OBJECT (bioc)); -error_report ("CMD_PACKAGED: Buffer receive fail ret=%d length=%zu" , - ret, length); +error_setg (errp,"CMD_PACKAGED: Buffer receive fail ret=%d length=%zu" , + ret, length);return (ret <0 ) ? ret : -EAGAIN ; } bioc->usage += length;
@@ -2451,6 +2451,9 @@ static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis) }while (1 ); ret =qemu_loadvm_state_main (packf, mis); +if (ret <0 ) { +error_setg (errp,"VM state load failed: %d" , ret); + }trace_loadvm_handle_cmd_packaged_main (ret);qemu_fclose (packf);object_unref (OBJECT (bioc));
@@ -2610,12 +2613,7 @@ static int loadvm_process_command(QEMUFile *f, Error **errp)break ;case MIG_CMD_PACKAGED : - ret =loadvm_handle_cmd_packaged (mis); -if (ret <0 ) { -error_setg (errp,"Failed to load device state command: %d" , ret); -return -1 ; - } -return ret; +return loadvm_handle_cmd_packaged (mis, errp);case MIG_CMD_POSTCOPY_ADVISE : ret =loadvm_postcopy_handle_advise (mis, len);
Signature · 1 line
2.50.0
Re: [PATCH v5 08/23] migration: push Error **errp into loadvm_handle_cmd_packaged()
Quoted 10 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatloadvm_handle_cmd_packaged()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/savevm.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 9/23 migration: push Error **errp into ram_postcopy_incoming_init()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that ram_postcopy_incoming_init() must report an error in errp, in case of failure.
--- migration/postcopy-ram.c | 9 ++++++--- migration/postcopy-ram.h | 2 +- migration/ram.c | 6 +++--- migration/ram.h | 2 +- migration/savevm.c | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-)
migration/postcopy-ram.c +6 -3
@@ -681,6 +681,7 @@ out:*/ static int init_range (RAMBlock *rb,void *opaque) { +Error **errp = opaque;const char *block_name =qemu_ram_get_idstr (rb);void *host_addr =qemu_ram_get_host_addr (rb);ram_addr_t offset =qemu_ram_get_offset (rb);
@@ -701,6 +702,8 @@ static int init_range(RAMBlock *rb, void *opaque)* (Precopy will just overwrite this data, so doesn't need the discard) */ if (ram_discard_range (block_name,0 , length)) { +error_setg (errp,"failed to discard RAM block %s len=%zu" , + block_name, length);return -1 ; }
@@ -749,9 +752,9 @@ static int cleanup_range(RAMBlock *rb, void *opaque)* postcopy later; must be called prior to any precopy. * called from arch_init's similarly named ram_postcopy_incoming_init */ -int postcopy_ram_incoming_init (MigrationIncomingState *mis) +int postcopy_ram_incoming_init (MigrationIncomingState *mis,Error **errp) { -if (foreach_not_ignored_block (init_range,NULL )) { +if (foreach_not_ignored_block (init_range, errp)) {return -1 ; }
@@ -1703,7 +1706,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis, Error **errp)return false; } -int postcopy_ram_incoming_init (MigrationIncomingState *mis) +int postcopy_ram_incoming_init (MigrationIncomingState *mis,Error **errp) {error_report ("postcopy_ram_incoming_init: No OS support" );return -1 ;
migration/postcopy-ram.h +1 -1
@@ -30,7 +30,7 @@ int postcopy_ram_incoming_setup(MigrationIncomingState *mis);* postcopy later; must be called prior to any precopy. * called from ram.c's similarly named ram_postcopy_incoming_init */ -int postcopy_ram_incoming_init (MigrationIncomingState *mis); +int postcopy_ram_incoming_init (MigrationIncomingState *mis,Error **errp);/* * At the end of a migration where postcopy_ram_incoming_init was called.
migration/ram.c +3 -3
@@ -3708,7 +3708,7 @@ static int ram_load_cleanup(void *opaque)/** * ram_postcopy_incoming_init: allocate postcopy data structures * -* Returns 0 for success and negative if there was one error +* Returns 0 for success and -1 if there was one error * * @mis: current migration incoming state *
@@ -3716,9 +3716,9 @@ static int ram_load_cleanup(void *opaque)* postcopy-ram. postcopy-ram's similarly names * postcopy_ram_incoming_init does the work. */ -int ram_postcopy_incoming_init (MigrationIncomingState *mis) +int ram_postcopy_incoming_init (MigrationIncomingState *mis,Error **errp) { -return postcopy_ram_incoming_init (mis); +return postcopy_ram_incoming_init (mis, errp); }/**
migration/ram.h +1 -1
@@ -86,7 +86,7 @@ void ram_postcopy_migrated_memory_release(MigrationState *ms);void ram_postcopy_send_discard_bitmap (MigrationState *ms);/* For incoming postcopy discard */ int ram_discard_range (const char *block_name,uint64_t start,size_t length); -int ram_postcopy_incoming_init (MigrationIncomingState *mis); +int ram_postcopy_incoming_init (MigrationIncomingState *mis,Error **errp);int ram_load_postcopy (QEMUFile *f,int channel);void ram_handle_zero (void *host,uint64_t size);
migration/savevm.c +1 -1
@@ -1983,7 +1983,7 @@ static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis,return -1 ; } -if (ram_postcopy_incoming_init (mis)) { +if (ram_postcopy_incoming_init (mis,NULL )) {return -1 ; }
Signature · 1 line
2.50.0
Re: [PATCH v5 09/23] migration: push Error **errp into ram_postcopy_incoming_init()
Quoted 75 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatram_postcopy_incoming_init()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/postcopy-ram.c | 9 ++++++--- migration/postcopy-ram.h | 2 +- migration/ram.c | 6 +++--- migration/ram.h | 2 +- migration/savevm.c | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-)migration/postcopy-ram.c +6
-3@@ -681,6 +681,7 @@ out:*/ static int init_range (RAMBlock *rb,void *opaque) { +Error **errp = opaque;const char *block_name =qemu_ram_get_idstr (rb);void *host_addr =qemu_ram_get_host_addr (rb);ram_addr_t offset =qemu_ram_get_offset (rb);@@ -701,6 +702,8 @@ static int init_range(RAMBlock *rb, void *opaque)* (Precopy will just overwrite this data, so doesn't need the discard) */ if (ram_discard_range (block_name,0 , length)) { +error_setg (errp,"failed to discard RAM block %s len=%zu" , + block_name, length);return -1 ; }@@ -749,9 +752,9 @@ static int cleanup_range(RAMBlock *rb, void *opaque)* postcopy later; must be called prior to any precopy. * called from arch_init's similarly named ram_postcopy_incoming_init */ -int postcopy_ram_incoming_init (MigrationIncomingState *mis) +int postcopy_ram_incoming_init (MigrationIncomingState *mis,Error **errp) { -if (foreach_not_ignored_block (init_range,NULL )) { +if (foreach_not_ignored_block (init_range, errp)) {return -1 ; }@@ -1703,7 +1706,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis, Error **errp)return false; } -int postcopy_ram_incoming_init (MigrationIncomingState *mis) +int postcopy_ram_incoming_init (MigrationIncomingState *mis,Error **errp) {error_report ("postcopy_ram_incoming_init: No OS support" );return -1 ;migration/postcopy-ram.h +1
-1@@ -30,7 +30,7 @@ int postcopy_ram_incoming_setup(MigrationIncomingState *mis);* postcopy later; must be called prior to any precopy. * called from ram.c's similarly named ram_postcopy_incoming_init */ -int postcopy_ram_incoming_init (MigrationIncomingState *mis); +int postcopy_ram_incoming_init (MigrationIncomingState *mis,Error **errp);/* * At the end of a migration where postcopy_ram_incoming_init was called. migration/ram.c +0
-0
migration/ram.c static int ram_load_cleanup(void *opaque) · line 3711
Quoted 5 lines
migration/ram.c +1
-1@@ -3708,7 +3708,7 @@ static int ram_load_cleanup(void *opaque)/** * ram_postcopy_incoming_init: allocate postcopy data structures * -* Returns 0 for success and negative if there was one error +* Returns 0 for success and -1 if there was one error
This is true but not relevant in this patch's goal.
Besides, I'm not in favor of letting callers make an assumption on integer return values (i.e., let callers assume a particular integer value in the error conditions). It is subtle to make a mistake to return -errno while the documentation says it returns -1.
I think a proper way to avoid bugs due to return values here is to change the type to bool, which ensures there are two possible values; that is a nice improvement but something that can be done later.
Quoted 42 lines
migration/ram.c +2
-2* * @mis: current migration incoming state * @@ -3716,9 +3716,9 @@ static int ram_load_cleanup(void *opaque)* postcopy-ram. postcopy-ram's similarly names * postcopy_ram_incoming_init does the work. */ -int ram_postcopy_incoming_init (MigrationIncomingState *mis) +int ram_postcopy_incoming_init (MigrationIncomingState *mis,Error **errp) { -return postcopy_ram_incoming_init (mis); +return postcopy_ram_incoming_init (mis, errp); }/** migration/ram.h +1
-1@@ -86,7 +86,7 @@ void ram_postcopy_migrated_memory_release(MigrationState *ms);void ram_postcopy_send_discard_bitmap (MigrationState *ms);/* For incoming postcopy discard */ int ram_discard_range (const char *block_name,uint64_t start,size_t length); -int ram_postcopy_incoming_init (MigrationIncomingState *mis); +int ram_postcopy_incoming_init (MigrationIncomingState *mis,Error **errp);int ram_load_postcopy (QEMUFile *f,int channel);void ram_handle_zero (void *host,uint64_t size);migration/savevm.c +1
-1@@ -1983,7 +1983,7 @@ static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis,return -1 ; } -if (ram_postcopy_incoming_init (mis)) { +if (ram_postcopy_incoming_init (mis,NULL )) {return -1 ; }
Re: [PATCH v5 09/23] migration: push Error **errp into ram_postcopy_incoming_init()
Hi Akihiko,
Thanks for the review.
Quoted 80 lines · Akihiko Odaki
Quoted 71 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatram_postcopy_incoming_init()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/postcopy-ram.c | 9 ++++++--- migration/postcopy-ram.h | 2 +- migration/ram.c | 6 +++--- migration/ram.h | 2 +- migration/savevm.c | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-)migration/postcopy-ram.c +6
-3@@ -681,6 +681,7 @@ out:*/ static int init_range (RAMBlock *rb,void *opaque) { +Error **errp = opaque;const char *block_name =qemu_ram_get_idstr (rb);void *host_addr =qemu_ram_get_host_addr (rb);ram_addr_t offset =qemu_ram_get_offset (rb);@@ -701,6 +702,8 @@ static int init_range(RAMBlock *rb, void *opaque)* (Precopy will just overwrite this data, so doesn't need the discard) */ if (ram_discard_range (block_name,0 , length)) { +error_setg (errp,"failed to discard RAM block %s len=%zu" , + block_name, length);return -1 ; }@@ -749,9 +752,9 @@ static int cleanup_range(RAMBlock *rb, void *opaque)* postcopy later; must be called prior to any precopy. * called from arch_init's similarly named ram_postcopy_incoming_init */ -int postcopy_ram_incoming_init (MigrationIncomingState *mis) +int postcopy_ram_incoming_init (MigrationIncomingState *mis,Error **errp) { -if (foreach_not_ignored_block (init_range,NULL )) { +if (foreach_not_ignored_block (init_range, errp)) {return -1 ; }@@ -1703,7 +1706,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis, Error **errp)return false; } -int postcopy_ram_incoming_init (MigrationIncomingState *mis) +int postcopy_ram_incoming_init (MigrationIncomingState *mis,Error **errp) {error_report ("postcopy_ram_incoming_init: No OS support" );return -1 ;migration/postcopy-ram.h +1
-1@@ -30,7 +30,7 @@ int postcopy_ram_incoming_setup(MigrationIncomingState *mis);* postcopy later; must be called prior to any precopy. * called from ram.c's similarly named ram_postcopy_incoming_init */ -int postcopy_ram_incoming_init (MigrationIncomingState *mis); +int postcopy_ram_incoming_init (MigrationIncomingState *mis,Error **errp);/* * At the end of a migration where postcopy_ram_incoming_init was called. migration/ram.c +0
-0migration/ram.c static int ram_load_cleanup(void *opaque) · line 3711
Quoted 5 lines
migration/ram.c +1
-1@@ -3708,7 +3708,7 @@ static int ram_load_cleanup(void *opaque)/** * ram_postcopy_incoming_init: allocate postcopy data structures * -* Returns 0 for success and negative if there was one error +* Returns 0 for success and -1 if there was one error This is true but not relevant in this patch's goal.
Quoted 8 lines
Besides, I'm not in favor of letting callers make an assumption on integer return values (i.e., let callers assume a particular integer value in the error conditions). It is subtle to make a mistake to return -errno while the documentation says it returns -1.
I think a proper way to avoid bugs due to return values here is to change the type to bool, which ensures there are two possible values; that is a nice improvement but something that can be done later.
I agree, I shall remove the unnecessary documentation change as it is not in the scope.
Quoted 31 lines
Quoted 31 lines
migration/ram.c +2
-2* * @mis: current migration incoming state * @@ -3716,9 +3716,9 @@ static int ram_load_cleanup(void *opaque)* postcopy-ram. postcopy-ram's similarly names * postcopy_ram_incoming_init does the work. */ -int ram_postcopy_incoming_init (MigrationIncomingState *mis) +int ram_postcopy_incoming_init (MigrationIncomingState *mis,Error **errp) { -return postcopy_ram_incoming_init (mis); +return postcopy_ram_incoming_init (mis, errp); }/** migration/ram.h +1
-1@@ -86,7 +86,7 @@ void ram_postcopy_migrated_memory_release(MigrationState *ms);void ram_postcopy_send_discard_bitmap (MigrationState *ms);/* For incoming postcopy discard */ int ram_discard_range (const char *block_name,uint64_t start,size_t length); -int ram_postcopy_incoming_init (MigrationIncomingState *mis); +int ram_postcopy_incoming_init (MigrationIncomingState *mis,Error **errp);int ram_load_postcopy (QEMUFile *f,int channel);void ram_handle_zero (void *host,uint64_t size);migration/savevm.c +0
-0
Quoted 9 lines
migration/savevm.c static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis, · line 1988
Quoted 8 lines
migration/savevm.c +1
-1@@ -1983,7 +1983,7 @@ static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis,return -1 ; } -if (ram_postcopy_incoming_init (mis)) { +if (ram_postcopy_incoming_init (mis,NULL )) {return -1 ; }
Regards,
Arun
Re: [PATCH v5 09/23] migration: push Error **errp into ram_postcopy_incoming_init()
In reply to Akihiko OdakiQuoted 80 lines · Akihiko Odaki
Quoted 71 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatram_postcopy_incoming_init()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/postcopy-ram.c | 9 ++++++--- migration/postcopy-ram.h | 2 +- migration/ram.c | 6 +++--- migration/ram.h | 2 +- migration/savevm.c | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-)migration/postcopy-ram.c +6
-3@@ -681,6 +681,7 @@ out:*/ static int init_range (RAMBlock *rb,void *opaque) { +Error **errp = opaque;const char *block_name =qemu_ram_get_idstr (rb);void *host_addr =qemu_ram_get_host_addr (rb);ram_addr_t offset =qemu_ram_get_offset (rb);@@ -701,6 +702,8 @@ static int init_range(RAMBlock *rb, void *opaque)* (Precopy will just overwrite this data, so doesn't need the discard) */ if (ram_discard_range (block_name,0 , length)) { +error_setg (errp,"failed to discard RAM block %s len=%zu" , + block_name, length);return -1 ; }@@ -749,9 +752,9 @@ static int cleanup_range(RAMBlock *rb, void *opaque)* postcopy later; must be called prior to any precopy. * called from arch_init's similarly named ram_postcopy_incoming_init */ -int postcopy_ram_incoming_init (MigrationIncomingState *mis) +int postcopy_ram_incoming_init (MigrationIncomingState *mis,Error **errp) { -if (foreach_not_ignored_block (init_range,NULL )) { +if (foreach_not_ignored_block (init_range, errp)) {return -1 ; }@@ -1703,7 +1706,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis, Error **errp)return false; } -int postcopy_ram_incoming_init (MigrationIncomingState *mis) +int postcopy_ram_incoming_init (MigrationIncomingState *mis,Error **errp) {error_report ("postcopy_ram_incoming_init: No OS support" );return -1 ;migration/postcopy-ram.h +1
-1@@ -30,7 +30,7 @@ int postcopy_ram_incoming_setup(MigrationIncomingState *mis);* postcopy later; must be called prior to any precopy. * called from ram.c's similarly named ram_postcopy_incoming_init */ -int postcopy_ram_incoming_init (MigrationIncomingState *mis); +int postcopy_ram_incoming_init (MigrationIncomingState *mis,Error **errp);/* * At the end of a migration where postcopy_ram_incoming_init was called. migration/ram.c +0
-0migration/ram.c static int ram_load_cleanup(void *opaque) · line 3711
Quoted 5 lines
migration/ram.c +1
-1@@ -3708,7 +3708,7 @@ static int ram_load_cleanup(void *opaque)/** * ram_postcopy_incoming_init: allocate postcopy data structures * -* Returns 0 for success and negative if there was one error +* Returns 0 for success and -1 if there was one error This is true but not relevant in this patch's goal.
Quoted 4 lines
Besides, I'm not in favor of letting callers make an assumption on integer return values (i.e., let callers assume a particular integer value in the error conditions). It is subtle to make a mistake to return -errno while the documentation says it returns -1.
In general I would consider it bad practice to have an method with "Error **errp" that also returns an errno. 95% of the time the errno is just there as further info on the error scenario, which "errp" obsoletes. Only in the rare cases where the caller needs to take functional action based on errno values, is it appropriate to contine returning '-errno'.
IOW, I'd consider this appropriate for the patch as is.
Quoted 3 lines
I think a proper way to avoid bugs due to return values here is to change the type to bool, which ensures there are two possible values; that is a nice improvement but something that can be done later.
That doesn't guarantee avoidance of bugs, as bool values can be assigned to & compared against integers.
Quoted 11 lines
migration/savevm.c static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis, · line 1987
Quoted 11 lines
migration/savevm.c +1
-1@@ -1983,7 +1983,7 @@ static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis,return -1 ; } -if (ram_postcopy_incoming_init (mis)) { +if (ram_postcopy_incoming_init (mis,NULL )) {return -1 ; }
This is a definite anti-pattern though as it treats positive return values as errors, contrary to the documented API for both the old and new code.
So change this to "< 0" while we're here.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Re: [PATCH v5 09/23] migration: push Error **errp into ram_postcopy_incoming_init()
Quoted 86 lines · Daniel P. Berrangé
Quoted 80 lines · Akihiko Odaki
Quoted 71 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatram_postcopy_incoming_init()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/postcopy-ram.c | 9 ++++++--- migration/postcopy-ram.h | 2 +- migration/ram.c | 6 +++--- migration/ram.h | 2 +- migration/savevm.c | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-)migration/postcopy-ram.c +6
-3@@ -681,6 +681,7 @@ out:*/ static int init_range (RAMBlock *rb,void *opaque) { +Error **errp = opaque;const char *block_name =qemu_ram_get_idstr (rb);void *host_addr =qemu_ram_get_host_addr (rb);ram_addr_t offset =qemu_ram_get_offset (rb);@@ -701,6 +702,8 @@ static int init_range(RAMBlock *rb, void *opaque)* (Precopy will just overwrite this data, so doesn't need the discard) */ if (ram_discard_range (block_name,0 , length)) { +error_setg (errp,"failed to discard RAM block %s len=%zu" , + block_name, length);return -1 ; }@@ -749,9 +752,9 @@ static int cleanup_range(RAMBlock *rb, void *opaque)* postcopy later; must be called prior to any precopy. * called from arch_init's similarly named ram_postcopy_incoming_init */ -int postcopy_ram_incoming_init (MigrationIncomingState *mis) +int postcopy_ram_incoming_init (MigrationIncomingState *mis,Error **errp) { -if (foreach_not_ignored_block (init_range,NULL )) { +if (foreach_not_ignored_block (init_range, errp)) {return -1 ; }@@ -1703,7 +1706,7 @@ bool postcopy_ram_supported_by_host(MigrationIncomingState *mis, Error **errp)return false; } -int postcopy_ram_incoming_init (MigrationIncomingState *mis) +int postcopy_ram_incoming_init (MigrationIncomingState *mis,Error **errp) {error_report ("postcopy_ram_incoming_init: No OS support" );return -1 ;migration/postcopy-ram.h +1
-1@@ -30,7 +30,7 @@ int postcopy_ram_incoming_setup(MigrationIncomingState *mis);* postcopy later; must be called prior to any precopy. * called from ram.c's similarly named ram_postcopy_incoming_init */ -int postcopy_ram_incoming_init (MigrationIncomingState *mis); +int postcopy_ram_incoming_init (MigrationIncomingState *mis,Error **errp);/* * At the end of a migration where postcopy_ram_incoming_init was called. migration/ram.c +0
-0migration/ram.c static int ram_load_cleanup(void *opaque) · line 3711
Quoted 5 lines
migration/ram.c +1
-1@@ -3708,7 +3708,7 @@ static int ram_load_cleanup(void *opaque)/** * ram_postcopy_incoming_init: allocate postcopy data structures * -* Returns 0 for success and negative if there was one error +* Returns 0 for success and -1 if there was one error This is true but not relevant in this patch's goal.
Quoted 4 lines
Besides, I'm not in favor of letting callers make an assumption on integer return values (i.e., let callers assume a particular integer value in the error conditions). It is subtle to make a mistake to return -errno while the documentation says it returns -1.
Quoted 6 lines
In general I would consider it bad practice to have an method
with "Error **errp" that also returns an errno. 95% of the time
the errno is just there as further info on the error scenario,
which "errp" obsoletes. Only in the rare cases where the caller
needs to take functional action based on errno values, is it
appropriate to contine returning '-errno'.> > IOW, I'd consider this appropriate for the patch as is.> >> I think
a proper way to avoid bugs due to return values here is to change
Quoted 5 lines
Quoted 2 lines
the type to bool, which ensures there are two possible values; that is a nice improvement but something that can be done later.
That doesn't guarantee avoidance of bugs, as bool values can be assigned to & compared against integers.
Returning -errno with "Error **errp" is indeed a bad practice, but someone may write a return statement with -errno by mistake as long as the type is int. For callers, it is a good defensive coding practice to assume any negative value indicates an error as it will dismiss the difference of -1 or -errno, and it is what the existing documentation implicitly suggests.
On the other hand, a function can never have a bug to return -errno if its return value type is bool.
Regards,
Akihiko Odaki
PATCH v5 10/23 migration: push Error **errp into loadvm_postcopy_handle_advise()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that loadvm_postcopy_handle_advise() must report an error in errp, in case of failure.
--- migration/savevm.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-)
migration/savevm.c +17 -22
@@ -1906,39 +1906,39 @@ enum LoadVMExitCodes {* quickly. */ static int loadvm_postcopy_handle_advise (MigrationIncomingState *mis, -uint16_t len) +uint16_t len,Error **errp) {PostcopyState ps =postcopy_state_set (POSTCOPY_INCOMING_ADVISE );uint64_t remote_pagesize_summary, local_pagesize_summary, remote_tps;size_t page_size =qemu_target_page_size (); -Error *local_err =NULL ;trace_loadvm_postcopy_handle_advise ();if (ps !=POSTCOPY_INCOMING_NONE ) { -error_report ("CMD_POSTCOPY_ADVISE in wrong postcopy state (%d)" , ps); +error_setg (errp,"CMD_POSTCOPY_ADVISE in wrong postcopy " +"state (%d)" , ps);return -1 ; }switch (len) {case 0 :if (migrate_postcopy_ram ()) { -error_report ("RAM postcopy is enabled but have 0 byte advise" ); +error_setg (errp,"RAM postcopy is enabled but have 0 byte advise" );return -EINVAL ; }return 0 ;case 8 +8 :if (!migrate_postcopy_ram ()) { -error_report ("RAM postcopy is disabled but have 16 byte advise" ); +error_setg (errp,"RAM postcopy is disabled but have 16 " +"byte advise" );return -EINVAL ; }break ;default : -error_report ("CMD_POSTCOPY_ADVISE invalid length (%d)" , len); +error_setg (errp,"CMD_POSTCOPY_ADVISE invalid length (%d)" , len);return -EINVAL ; } -if (!postcopy_ram_supported_by_host (mis, &local_err)) { -error_report_err (local_err); +if (!postcopy_ram_supported_by_host (mis, errp)) {postcopy_state_set (POSTCOPY_INCOMING_NONE );return -1 ; }
@@ -1961,9 +1961,9 @@ static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis,* also fails when passed to an older qemu that doesn't * do huge pages. */ -error_report ("Postcopy needs matching RAM page sizes (s=%" PRIx64 -" d=%" PRIx64")" , - remote_pagesize_summary, local_pagesize_summary); +error_setg (errp,"Postcopy needs matching RAM " +"page sizes (s=%" PRIx64" d=%" PRIx64")" , + remote_pagesize_summary, local_pagesize_summary);return -1 ; }
@@ -1973,17 +1973,17 @@ static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis,* Again, some differences could be dealt with, but for now keep it * simple. */ -error_report ("Postcopy needs matching target page sizes (s=%d d=%zd)" , - (int )remote_tps, page_size); +error_setg (errp,"Postcopy needs matching target " +"page sizes (s=%d d=%zd)" , (int )remote_tps, page_size);return -1 ; } -if (postcopy_notify (POSTCOPY_NOTIFY_INBOUND_ADVISE , &local_err)) { -error_report_err (local_err); +if (postcopy_notify (POSTCOPY_NOTIFY_INBOUND_ADVISE , errp)) {return -1 ; } -if (ram_postcopy_incoming_init (mis,NULL )) { +if (ram_postcopy_incoming_init (mis, errp)) { +error_prepend (errp,"PostCopy RAM incoming init failed " );return -1 ; }
@@ -2616,12 +2616,7 @@ static int loadvm_process_command(QEMUFile *f, Error **errp)return loadvm_handle_cmd_packaged (mis, errp);case MIG_CMD_POSTCOPY_ADVISE : - ret =loadvm_postcopy_handle_advise (mis, len); -if (ret <0 ) { -error_setg (errp,"Failed to load device state command: %d" , ret); -return -1 ; - } -return ret; +return loadvm_postcopy_handle_advise (mis, len, errp);case MIG_CMD_POSTCOPY_LISTEN : ret =loadvm_postcopy_handle_listen (mis);
Signature · 1 line
2.50.0
Re: [PATCH v5 10/23] migration: push Error **errp into loadvm_postcopy_handle_advise()
Quoted 10 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatloadvm_postcopy_handle_advise()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/savevm.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 11/23 migration: push Error **errp into loadvm_postcopy_handle_listen()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that loadvm_postcopy_handle_listen() must report an error in errp, in case of failure.
--- migration/savevm.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
migration/savevm.c +7 -11
@@ -2173,15 +2173,16 @@ static void *postcopy_ram_listen_thread(void *opaque) }/* After this message we must be able to immediately receive postcopy data */ -static int loadvm_postcopy_handle_listen (MigrationIncomingState *mis) +static int loadvm_postcopy_handle_listen (MigrationIncomingState *mis, +Error **errp) {PostcopyState ps =postcopy_state_set (POSTCOPY_INCOMING_LISTENING ); -Error *local_err =NULL ;trace_loadvm_postcopy_handle_listen ("enter" );if (ps !=POSTCOPY_INCOMING_ADVISE && ps !=POSTCOPY_INCOMING_DISCARD ) { -error_report ("CMD_POSTCOPY_LISTEN in wrong postcopy state (%d)" , ps); +error_setg (errp,"CMD_POSTCOPY_LISTEN in wrong postcopy " +"state (%d)" , ps);return -1 ; }if (ps ==POSTCOPY_INCOMING_ADVISE ) {
@@ -2204,14 +2205,14 @@ static int loadvm_postcopy_handle_listen(MigrationIncomingState *mis)if (migrate_postcopy_ram ()) {if (postcopy_ram_incoming_setup (mis)) {postcopy_ram_incoming_cleanup (mis); +error_setg (errp,"Failed to setup incoming postcopy RAM blocks" );return -1 ; } }trace_loadvm_postcopy_handle_listen ("after uffd" ); -if (postcopy_notify (POSTCOPY_NOTIFY_INBOUND_LISTEN , &local_err)) { -error_report_err (local_err); +if (postcopy_notify (POSTCOPY_NOTIFY_INBOUND_LISTEN , errp)) {return -1 ; }
@@ -2619,12 +2620,7 @@ static int loadvm_process_command(QEMUFile *f, Error **errp)return loadvm_postcopy_handle_advise (mis, len, errp);case MIG_CMD_POSTCOPY_LISTEN : - ret =loadvm_postcopy_handle_listen (mis); -if (ret <0 ) { -error_setg (errp,"Failed to load device state command: %d" , ret); -return -1 ; - } -return ret; +return loadvm_postcopy_handle_listen (mis, errp);case MIG_CMD_POSTCOPY_RUN : ret =loadvm_postcopy_handle_run (mis);
Signature · 1 line
2.50.0
Re: [PATCH v5 11/23] migration: push Error **errp into loadvm_postcopy_handle_listen()
Quoted 10 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatloadvm_postcopy_handle_listen()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/savevm.c | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 12/23 migration: push Error **errp into loadvm_postcopy_handle_run()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that loadvm_postcopy_handle_run() must report an error in errp, in case of failure.
--- migration/savevm.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
migration/savevm.c +4 -8
@@ -2265,13 +2265,14 @@ static void loadvm_postcopy_handle_run_bh(void *opaque) }/* After all discards we can start running and asking for pages */ -static int loadvm_postcopy_handle_run (MigrationIncomingState *mis) +static int loadvm_postcopy_handle_run (MigrationIncomingState *mis,Error **errp) {PostcopyState ps =postcopy_state_get ();trace_loadvm_postcopy_handle_run ();if (ps !=POSTCOPY_INCOMING_LISTENING ) { -error_report ("CMD_POSTCOPY_RUN in wrong postcopy state (%d)" , ps); +error_setg (errp,"CMD_POSTCOPY_RUN in wrong postcopy " +"state (%d)" , ps);return -1 ; }
@@ -2623,12 +2624,7 @@ static int loadvm_process_command(QEMUFile *f, Error **errp)return loadvm_postcopy_handle_listen (mis, errp);case MIG_CMD_POSTCOPY_RUN : - ret =loadvm_postcopy_handle_run (mis); -if (ret <0 ) { -error_setg (errp,"Failed to load device state command: %d" , ret); -return -1 ; - } -return ret; +return loadvm_postcopy_handle_run (mis, errp);case MIG_CMD_POSTCOPY_RAM_DISCARD : ret =loadvm_postcopy_ram_handle_discard (mis, len);
Signature · 1 line
2.50.0
Re: [PATCH v5 12/23] migration: push Error **errp into loadvm_postcopy_handle_run()
Quoted 10 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatloadvm_postcopy_handle_run()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/savevm.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 13/23 migration: push Error **errp into loadvm_postcopy_ram_handle_discard()
In reply to Arun MenonThis is an incremental step in converting vmstate loading
code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that loadvm_postcopy_ram_handle_discard() must report an error in errp, in case of failure.
--- migration/savevm.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
migration/savevm.c +12 -14
@@ -1996,7 +1996,7 @@ static int loadvm_postcopy_handle_advise(MigrationIncomingState *mis,* There can be 0..many of these messages, each encoding multiple pages. */ static int loadvm_postcopy_ram_handle_discard (MigrationIncomingState *mis, -uint16_t len) +uint16_t len,Error **errp) {int tmp;char ramid[256 ];
@@ -2009,6 +2009,7 @@ static int loadvm_postcopy_ram_handle_discard(MigrationIncomingState *mis,/* 1st discard */ tmp =postcopy_ram_prepare_discard (mis);if (tmp) { +error_setg (errp,"Failed to prepare for RAM discard: %d" , tmp);return tmp; }break ;
@@ -2018,8 +2019,8 @@ static int loadvm_postcopy_ram_handle_discard(MigrationIncomingState *mis,break ;default : -error_report ("CMD_POSTCOPY_RAM_DISCARD in wrong postcopy state (%d)" , - ps); +error_setg (errp,"CMD_POSTCOPY_RAM_DISCARD in wrong " +"postcopy state (%d)" , ps);return -1 ; }/* We're expecting a
@@ -2028,29 +2029,30 @@ static int loadvm_postcopy_ram_handle_discard(MigrationIncomingState *mis,* then at least 1 16 byte chunk */ if (len < (1 +1 +1 +1 +2 *8 )) { -error_report ("CMD_POSTCOPY_RAM_DISCARD invalid length (%d)" , len); +error_setg (errp,"CMD_POSTCOPY_RAM_DISCARD invalid length (%d)" , len);return -1 ; } tmp =qemu_get_byte (mis->from_src_file);if (tmp != postcopy_ram_discard_version) { -error_report ("CMD_POSTCOPY_RAM_DISCARD invalid version (%d)" , tmp); +error_setg (errp,"CMD_POSTCOPY_RAM_DISCARD invalid version (%d)" , tmp);return -1 ; }if (!qemu_get_counted_string (mis->from_src_file, ramid)) { -error_report ("CMD_POSTCOPY_RAM_DISCARD Failed to read RAMBlock ID" ); +error_setg (errp,"CMD_POSTCOPY_RAM_DISCARD Failed to read " +"RAMBlock ID" );return -1 ; } tmp =qemu_get_byte (mis->from_src_file);if (tmp !=0 ) { -error_report ("CMD_POSTCOPY_RAM_DISCARD missing nil (%d)" , tmp); +error_setg (errp,"CMD_POSTCOPY_RAM_DISCARD missing nil (%d)" , tmp);return -1 ; } len -=3 +strlen (ramid);if (len %16 ) { -error_report ("CMD_POSTCOPY_RAM_DISCARD invalid length (%d)" , len); +error_setg (errp,"CMD_POSTCOPY_RAM_DISCARD invalid length (%d)" , len);return -1 ; }trace_loadvm_postcopy_ram_handle_discard_header (ramid, len);
@@ -2062,6 +2064,7 @@ static int loadvm_postcopy_ram_handle_discard(MigrationIncomingState *mis, len -=16 ;int ret =ram_discard_range (ramid, start_addr, block_length);if (ret) { +error_setg (errp,"Failed to discard RAM range %s: %d" , ramid, ret);return ret; } }
@@ -2627,12 +2630,7 @@ static int loadvm_process_command(QEMUFile *f, Error **errp)return loadvm_postcopy_handle_run (mis, errp);case MIG_CMD_POSTCOPY_RAM_DISCARD : - ret =loadvm_postcopy_ram_handle_discard (mis, len); -if (ret <0 ) { -error_setg (errp,"Failed to load device state command: %d" , ret); -return -1 ; - } -return ret; +return loadvm_postcopy_ram_handle_discard (mis, len, errp);case MIG_CMD_POSTCOPY_RESUME : ret =loadvm_postcopy_handle_resume (mis);
Signature · 1 line
2.50.0
PATCH v5 14/23 migration: make loadvm_postcopy_handle_resume() void
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
--- migration/savevm.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)
migration/savevm.c +4 -10
@@ -2333,12 +2333,12 @@ static void migrate_send_rp_req_pages_pending(MigrationIncomingState *mis) } } -static int loadvm_postcopy_handle_resume (MigrationIncomingState *mis) +static void loadvm_postcopy_handle_resume (MigrationIncomingState *mis) {if (mis->state !=MIGRATION_STATUS_POSTCOPY_RECOVER ) {error_report ("%s: illegal resume received" , __func__);/* Don't fail the load, only for this. */ -return 0 ; +return ; }/*
@@ -2390,8 +2390,6 @@ static int loadvm_postcopy_handle_resume(MigrationIncomingState *mis)/* Kick the fast ram load thread too */ qemu_sem_post (&mis->postcopy_pause_sem_fast_load); } - -return 0 ; }/**
@@ -2633,12 +2631,8 @@ static int loadvm_process_command(QEMUFile *f, Error **errp)return loadvm_postcopy_ram_handle_discard (mis, len, errp);case MIG_CMD_POSTCOPY_RESUME : - ret =loadvm_postcopy_handle_resume (mis); -if (ret <0 ) { -error_setg (errp,"Failed to load device state command: %d" , ret); -return -1 ; - } -return ret; +loadvm_postcopy_handle_resume (mis); +return 0 ;case MIG_CMD_RECV_BITMAP : ret =loadvm_handle_recv_bitmap (mis, len);
Signature · 1 line
2.50.0
Re: [PATCH v5 14/23] migration: make loadvm_postcopy_handle_resume() void
Quoted 14 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
Signed-off-by Arun Menon <[email protected]>--- migration/savevm.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-)migration/savevm.c +0
-0
migration/savevm.c static void migrate_send_rp_req_pages_pending(MigrationIncomingState *mis) · line 2339
Quoted 8 lines
migration/savevm.c +1
-1@@ -2333,12 +2333,12 @@ static void migrate_send_rp_req_pages_pending(MigrationIncomingState *mis) } } -static int loadvm_postcopy_handle_resume (MigrationIncomingState *mis) +static void loadvm_postcopy_handle_resume (MigrationIncomingState *mis) {if (mis->state !=MIGRATION_STATUS_POSTCOPY_RECOVER ) {error_report ("%s: illegal resume received" , __func__);
Pre-existing mistake, but can you change this to 'warn_report' given that we're not treating it as an error.
Aside from that
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 15/23 migration: push Error **errp into loadvm_handle_recv_bitmap()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that loadvm_handle_recv_bitmap() must report an error in errp, in case of failure.
--- migration/savevm.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
migration/savevm.c +10 -12
@@ -2471,32 +2471,35 @@ static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis, Error **errp)* len (1 byte) + ramblock_name (<255 bytes) */ static int loadvm_handle_recv_bitmap (MigrationIncomingState *mis, -uint16_t len) +uint16_t len,Error **errp) {QEMUFile *file = mis->from_src_file;RAMBlock *rb;char block_name[256 ];size_t cnt; +int ret; cnt =qemu_get_counted_string (file, block_name);if (!cnt) { -error_report ("%s: failed to read block name" , __func__); +error_setg (errp,"%s: failed to read block name" , __func__);return -EINVAL ; }/* Validate before using the data */ -if (qemu_file_get_error (file)) { -return qemu_file_get_error (file); + ret =qemu_file_get_error (file); +if (ret <0 ) { +error_setg (errp,"migration stream has error: %d" , ret); +return ret; }if (len != cnt +1 ) { -error_report ("%s: invalid payload length (%d)" , __func__, len); +error_setg (errp,"%s: invalid payload length (%d)" , __func__, len);return -EINVAL ; } rb =qemu_ram_block_by_name (block_name);if (!rb) { -error_report ("%s: block '%s' not found" , __func__, block_name); +error_setg (errp,"%s: block '%s' not found" , __func__, block_name);return -EINVAL ; }
@@ -2635,12 +2638,7 @@ static int loadvm_process_command(QEMUFile *f, Error **errp)return 0 ;case MIG_CMD_RECV_BITMAP : - ret =loadvm_handle_recv_bitmap (mis, len); -if (ret <0 ) { -error_setg (errp,"Failed to load device state command: %d" , ret); -return -1 ; - } -return ret; +return loadvm_handle_recv_bitmap (mis, len, errp);case MIG_CMD_ENABLE_COLO : ret =loadvm_process_enable_colo (mis);
Signature · 1 line
2.50.0
Re: [PATCH v5 15/23] migration: push Error **errp into loadvm_handle_recv_bitmap()
Quoted 10 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatloadvm_handle_recv_bitmap()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/savevm.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-)
Quoted 36 lines
migration/savevm.c +7
-5@@ -2471,32 +2471,35 @@ static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis, Error **errp)* len (1 byte) + ramblock_name (<255 bytes) */ static int loadvm_handle_recv_bitmap (MigrationIncomingState *mis, -uint16_t len) +uint16_t len,Error **errp) {QEMUFile *file = mis->from_src_file;RAMBlock *rb;char block_name[256 ];size_t cnt; +int ret; cnt =qemu_get_counted_string (file, block_name);if (!cnt) { -error_report ("%s: failed to read block name" , __func__); +error_setg (errp,"%s: failed to read block name" , __func__);return -EINVAL ; }/* Validate before using the data */ -if (qemu_file_get_error (file)) { -return qemu_file_get_error (file); + ret =qemu_file_get_error (file); +if (ret <0 ) { +error_setg (errp,"migration stream has error: %d" , ret); +return ret; }if (len != cnt +1 ) { -error_report ("%s: invalid payload length (%d)" , __func__, len);
migration/savevm.c static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis, Error **errp) · line 2504
Quoted 10 lines
migration/savevm.c +2
-1+error_setg (errp,"%s: invalid payload length (%d)" , __func__, len);return -EINVAL ; } rb =qemu_ram_block_by_name (block_name);if (!rb) { -error_report ("%s: block '%s' not found" , __func__, block_name); +error_setg (errp,"%s: block '%s' not found" , __func__, block_name);return -EINVAL ; }
(Pre-existing) redundant use of __func__ that can be removed.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 16/23 migration: push Error **errp into loadvm_process_enable_colo()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that loadvm_process_enable_colo() must report an error in errp, in case of failure.
--- include/migration/colo.h | 2 +- migration/migration.c | 12 ++++++------ migration/ram.c | 8 ++++---- migration/ram.h | 2 +- migration/savevm.c | 25 ++++++++++++------------- 5 files changed, 24 insertions(+), 25 deletions(-)
include/migration/colo.h +1 -1
@@ -25,7 +25,7 @@ void migrate_start_colo_process(MigrationState *s);bool migration_in_colo_state (void );/* loadvm */ -int migration_incoming_enable_colo (void ); +int migration_incoming_enable_colo (Error **errp);void migration_incoming_disable_colo (void );bool migration_incoming_colo_enabled (void );bool migration_incoming_in_colo_state (void );
migration/migration.c +6 -6
@@ -623,22 +623,22 @@ void migration_incoming_disable_colo(void) migration_colo_enabled = false; } -int migration_incoming_enable_colo (void ) +int migration_incoming_enable_colo (Error **errp) {#ifndef CONFIG_REPLICATION -error_report ("ENABLE_COLO command come in migration stream, but the " -"replication module is not built in" ); +error_setg (errp,"ENABLE_COLO command come in migration stream, but the " +"replication module is not built in" );return -ENOTSUP ;#endif if (!migrate_colo ()) { -error_report ("ENABLE_COLO command come in migration stream, but x-colo " -"capability is not set" ); +error_setg (errp,"ENABLE_COLO command come in migration stream" +", but x-colo capability is not set" );return -EINVAL ; }if (ram_block_discard_disable (true)) { -error_report ("COLO: cannot disable RAM discard" ); +error_setg (errp,"COLO: cannot disable RAM discard" );return -EBUSY ; } migration_colo_enabled = true;
migration/ram.c +4 -4
@@ -3576,7 +3576,7 @@ static void colo_init_ram_state(void)* memory of the secondary VM, it is need to hold the global lock * to call this helper. */ -int colo_init_ram_cache (void ) +int colo_init_ram_cache (Error **errp) {RAMBlock *block;
@@ -3585,9 +3585,9 @@ int colo_init_ram_cache(void) block->colo_cache =qemu_anon_ram_alloc (block->used_length,NULL , false, false);if (!block->colo_cache) { -error_report ("%s: Can't alloc memory for COLO cache of block %s," -"size 0x" RAM_ADDR_FMT , __func__, block->idstr, - block->used_length); +error_setg (errp,"%s: Can't alloc memory for COLO cache of " +"block %s, size 0x" RAM_ADDR_FMT , __func__, + block->idstr, block->used_length);RAMBLOCK_FOREACH_NOT_IGNORED (block) {if (block->colo_cache) {qemu_anon_ram_free (block->colo_cache, block->used_length);
migration/ram.h +1 -1
@@ -109,7 +109,7 @@ void ramblock_set_file_bmap_atomic(RAMBlock *block, ram_addr_t offset, bool set);/* ram cache */ -int colo_init_ram_cache (void ); +int colo_init_ram_cache (Error **errp);void colo_flush_ram_cache (void );void colo_release_ram_cache (void );void colo_incoming_start_dirty_log (void );
migration/savevm.c +12 -13
@@ -2510,15 +2510,19 @@ static int loadvm_handle_recv_bitmap(MigrationIncomingState *mis,return 0 ; } -static int loadvm_process_enable_colo (MigrationIncomingState *mis) +static int loadvm_process_enable_colo (MigrationIncomingState *mis, +Error **errp) { -int ret =migration_incoming_enable_colo (); +int ret; -if (!ret) { - ret =colo_init_ram_cache (); -if (ret) { -migration_incoming_disable_colo (); - } +if (migration_incoming_enable_colo (errp) <0 ) { +return -1 ; + } + + ret =colo_init_ram_cache (errp); +if (ret) { +error_prepend (errp,"failed to init colo RAM cache: %d" , ret); +migration_incoming_disable_colo (); }return ret; }
@@ -2641,12 +2645,7 @@ static int loadvm_process_command(QEMUFile *f, Error **errp)return loadvm_handle_recv_bitmap (mis, len, errp);case MIG_CMD_ENABLE_COLO : - ret =loadvm_process_enable_colo (mis); -if (ret <0 ) { -error_setg (errp,"Failed to load device state command: %d" , ret); -return -1 ; - } -return ret; +return loadvm_process_enable_colo (mis, errp);case MIG_CMD_SWITCHOVER_START : ret =loadvm_postcopy_handle_switchover_start ();
Signature · 1 line
2.50.0
Re: [PATCH v5 16/23] migration: push Error **errp into loadvm_process_enable_colo()
Quoted 112 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatloadvm_process_enable_colo()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- include/migration/colo.h | 2 +- migration/migration.c | 12 ++++++------ migration/ram.c | 8 ++++---- migration/ram.h | 2 +- migration/savevm.c | 25 ++++++++++++------------- 5 files changed, 24 insertions(+), 25 deletions(-)include/migration/colo.h +1
-1@@ -25,7 +25,7 @@ void migrate_start_colo_process(MigrationState *s);bool migration_in_colo_state (void );/* loadvm */ -int migration_incoming_enable_colo (void ); +int migration_incoming_enable_colo (Error **errp);void migration_incoming_disable_colo (void );bool migration_incoming_colo_enabled (void );bool migration_incoming_in_colo_state (void );migration/migration.c +6
-6@@ -623,22 +623,22 @@ void migration_incoming_disable_colo(void) migration_colo_enabled = false; } -int migration_incoming_enable_colo (void ) +int migration_incoming_enable_colo (Error **errp) {#ifndef CONFIG_REPLICATION -error_report ("ENABLE_COLO command come in migration stream, but the " -"replication module is not built in" ); +error_setg (errp,"ENABLE_COLO command come in migration stream, but the " +"replication module is not built in" );return -ENOTSUP ;#endif if (!migrate_colo ()) { -error_report ("ENABLE_COLO command come in migration stream, but x-colo " -"capability is not set" ); +error_setg (errp,"ENABLE_COLO command come in migration stream" +", but x-colo capability is not set" );return -EINVAL ; }if (ram_block_discard_disable (true)) { -error_report ("COLO: cannot disable RAM discard" ); +error_setg (errp,"COLO: cannot disable RAM discard" );return -EBUSY ; } migration_colo_enabled = true;migration/ram.c +4
-4@@ -3576,7 +3576,7 @@ static void colo_init_ram_state(void)* memory of the secondary VM, it is need to hold the global lock * to call this helper. */ -int colo_init_ram_cache (void ) +int colo_init_ram_cache (Error **errp) {RAMBlock *block;@@ -3585,9 +3585,9 @@ int colo_init_ram_cache(void) block->colo_cache =qemu_anon_ram_alloc (block->used_length,NULL , false, false);if (!block->colo_cache) { -error_report ("%s: Can't alloc memory for COLO cache of block %s," -"size 0x" RAM_ADDR_FMT , __func__, block->idstr, - block->used_length); +error_setg (errp,"%s: Can't alloc memory for COLO cache of " +"block %s, size 0x" RAM_ADDR_FMT , __func__, + block->idstr, block->used_length);RAMBLOCK_FOREACH_NOT_IGNORED (block) {if (block->colo_cache) {qemu_anon_ram_free (block->colo_cache, block->used_length);migration/ram.h +1
-1@@ -109,7 +109,7 @@ void ramblock_set_file_bmap_atomic(RAMBlock *block, ram_addr_t offset, bool set);/* ram cache */ -int colo_init_ram_cache (void ); +int colo_init_ram_cache (Error **errp);void colo_flush_ram_cache (void );void colo_release_ram_cache (void );void colo_incoming_start_dirty_log (void );migration/savevm.c +2
-1@@ -2510,15 +2510,19 @@ static int loadvm_handle_recv_bitmap(MigrationIncomingState *mis,return 0 ; } -static int loadvm_process_enable_colo (MigrationIncomingState *mis) +static int loadvm_process_enable_colo (MigrationIncomingState *mis, +Error **errp) {
migration/savevm.c static int loadvm_handle_recv_bitmap(MigrationIncomingState *mis, · line 2519
Quoted 10 lines
migration/savevm.c +3
-6-int ret =migration_incoming_enable_colo (); +int ret; -if (!ret) { - ret =colo_init_ram_cache (); -if (ret) { -migration_incoming_disable_colo (); - } +if (migration_incoming_enable_colo (errp) <0 ) { +return -1 ;
Returning -1 here while colo_init_ram_cache() returns -errno results in an inconsistent semantics of this function's return value.
Ideally, I think this function (and other similar functions) should stop returning -errno and instead return a bool value to prevent callers to make any assumption based on the return value other than success/failure. But that could be done later; let it return -errno until then.
Re: [PATCH v5 16/23] migration: push Error **errp into loadvm_process_enable_colo()
Quoted 110 lines · Akihiko Odaki
Quoted 109 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatloadvm_process_enable_colo()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- include/migration/colo.h | 2 +- migration/migration.c | 12 ++++++------ migration/ram.c | 8 ++++---- migration/ram.h | 2 +- migration/savevm.c | 25 ++++++++++++------------- 5 files changed, 24 insertions(+), 25 deletions(-)include/migration/colo.h +1
-1@@ -25,7 +25,7 @@ void migrate_start_colo_process(MigrationState *s);bool migration_in_colo_state (void );/* loadvm */ -int migration_incoming_enable_colo (void ); +int migration_incoming_enable_colo (Error **errp);void migration_incoming_disable_colo (void );bool migration_incoming_colo_enabled (void );bool migration_incoming_in_colo_state (void );migration/migration.c +6
-6@@ -623,22 +623,22 @@ void migration_incoming_disable_colo(void) migration_colo_enabled = false; } -int migration_incoming_enable_colo (void ) +int migration_incoming_enable_colo (Error **errp) {#ifndef CONFIG_REPLICATION -error_report ("ENABLE_COLO command come in migration stream, but the " -"replication module is not built in" ); +error_setg (errp,"ENABLE_COLO command come in migration stream, but the " +"replication module is not built in" );return -ENOTSUP ;#endif if (!migrate_colo ()) { -error_report ("ENABLE_COLO command come in migration stream, but x-colo " -"capability is not set" ); +error_setg (errp,"ENABLE_COLO command come in migration stream" +", but x-colo capability is not set" );return -EINVAL ; }if (ram_block_discard_disable (true)) { -error_report ("COLO: cannot disable RAM discard" ); +error_setg (errp,"COLO: cannot disable RAM discard" );return -EBUSY ; } migration_colo_enabled = true;migration/ram.c +4
-4@@ -3576,7 +3576,7 @@ static void colo_init_ram_state(void)* memory of the secondary VM, it is need to hold the global lock * to call this helper. */ -int colo_init_ram_cache (void ) +int colo_init_ram_cache (Error **errp) {RAMBlock *block;@@ -3585,9 +3585,9 @@ int colo_init_ram_cache(void) block->colo_cache =qemu_anon_ram_alloc (block->used_length,NULL , false, false);if (!block->colo_cache) { -error_report ("%s: Can't alloc memory for COLO cache of block %s," -"size 0x" RAM_ADDR_FMT , __func__, block->idstr, - block->used_length); +error_setg (errp,"%s: Can't alloc memory for COLO cache of " +"block %s, size 0x" RAM_ADDR_FMT , __func__, + block->idstr, block->used_length);RAMBLOCK_FOREACH_NOT_IGNORED (block) {if (block->colo_cache) {qemu_anon_ram_free (block->colo_cache, block->used_length);migration/ram.h +1
-1@@ -109,7 +109,7 @@ void ramblock_set_file_bmap_atomic(RAMBlock *block, ram_addr_t offset, bool set);/* ram cache */ -int colo_init_ram_cache (void ); +int colo_init_ram_cache (Error **errp);void colo_flush_ram_cache (void );void colo_release_ram_cache (void );void colo_incoming_start_dirty_log (void );migration/savevm.c +3
-4@@ -2510,15 +2510,19 @@ static int loadvm_handle_recv_bitmap(MigrationIncomingState *mis,return 0 ; } -static int loadvm_process_enable_colo (MigrationIncomingState *mis) +static int loadvm_process_enable_colo (MigrationIncomingState *mis, +Error **errp) { -int ret =migration_incoming_enable_colo (); +int ret; -if (!ret) { - ret =colo_init_ram_cache ();
Quoted 8 lines
migration/savevm.c static int loadvm_handle_recv_bitmap(MigrationIncomingState *mis, · line 2519
Quoted 5 lines
migration/savevm.c +2
-3-if (ret) { -migration_incoming_disable_colo (); - } +if (migration_incoming_enable_colo (errp) <0 ) { +return -1 ;Returning -1 here while
colo_init_ram_cache()returns -errno results in an inconsistent semantics of this function's return value.
If I understand correctly, you mean, if migration_incoming_enable_colo() fails, it should return the errno instead of -1. Will do.
Thanks
Quoted 6 lines
Ideally, I think this function (and other similar functions) should stop returning -errno and instead return a bool value to prevent callers to make any assumption based on the return value other than success/failure. But that could be done later; let it return -errno until then.
yes
PATCH v5 17/23 migration: push Error **errp into loadvm_postcopy_handle_switchover_start()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor. It is ensured that loadvm_postcopy_handle_switchover_start() must report an error in errp, in case of failure.
--- migration/savevm.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
migration/savevm.c +3 -7
@@ -2527,7 +2527,7 @@ static int loadvm_process_enable_colo(MigrationIncomingState *mis,return ret; } -static int loadvm_postcopy_handle_switchover_start (void ) +static int loadvm_postcopy_handle_switchover_start (Error **errp) {SaveStateEntry *se;
@@ -2540,6 +2540,7 @@ static int loadvm_postcopy_handle_switchover_start(void) ret = se->ops->switchover_start (se->opaque);if (ret <0 ) { +error_setg (errp,"Switchover start failed: %d" , ret);return ret; } }
@@ -2648,12 +2649,7 @@ static int loadvm_process_command(QEMUFile *f, Error **errp)return loadvm_process_enable_colo (mis, errp);case MIG_CMD_SWITCHOVER_START : - ret =loadvm_postcopy_handle_switchover_start (); -if (ret <0 ) { -error_setg (errp,"Failed to load device state command: %d" , ret); -return -1 ; - } -return ret; +return loadvm_postcopy_handle_switchover_start (errp); }return 0 ;
Signature · 1 line
2.50.0
Re: [PATCH v5 17/23] migration: push Error **errp into loadvm_postcopy_handle_switchover_start()
Quoted 9 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor. It is ensured that
loadvm_postcopy_handle_switchover_start()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/savevm.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 18/23 migration: push Error **errp into qemu_loadvm_state_main()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that qemu_loadvm_state_main() must report an error in errp, in case of failure.loadvm_process_command also sets the errp object explicitly.
--- migration/colo.c | 5 +++-- migration/savevm.c | 23 +++++++++++++---------- migration/savevm.h | 3 ++- 3 files changed, 18 insertions(+), 13 deletions(-)
migration/colo.c +3 -2
@@ -686,11 +686,12 @@ static void colo_incoming_process_checkpoint(MigrationIncomingState *mis,bql_lock ();cpu_synchronize_all_states (); - ret =qemu_loadvm_state_main (mis->from_src_file, mis); + ret =qemu_loadvm_state_main (mis->from_src_file, mis, &local_err);bql_unlock ();if (ret <0 ) { -error_setg (errp,"Load VM's live state (ram) error" ); +error_propagate_prepend (errp, local_err, +"Load VM's live state (ram) error" );return ; }
migration/savevm.c +13 -10
@@ -2102,7 +2102,7 @@ static void *postcopy_ram_listen_thread(void *opaque)qemu_file_set_blocking (f, true);/* TODO: sanity check that only postcopiable data will be loaded here */ - load_res =qemu_loadvm_state_main (f, mis); + load_res =qemu_loadvm_state_main (f, mis,NULL );/* * This is tricky, but, mis->from_src_file can change after it
@@ -2453,9 +2453,9 @@ static int loadvm_handle_cmd_packaged(MigrationIncomingState *mis, Error **errp)qemu_coroutine_yield (); }while (1 ); - ret =qemu_loadvm_state_main (packf, mis); + ret =qemu_loadvm_state_main (packf, mis, errp);if (ret <0 ) { -error_setg (errp,"VM state load failed: %d" , ret); +error_prepend (errp,"Loading VM state failed: %d " , ret); }trace_loadvm_handle_cmd_packaged_main (ret);qemu_fclose (packf);
@@ -3055,7 +3055,8 @@ static bool postcopy_pause_incoming(MigrationIncomingState *mis)return true; } -int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis) +int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis, +Error **errp) {uint8_t section_type;int ret =0 ;
@@ -3066,6 +3067,8 @@ retry: ret =qemu_file_get_error_obj_any (f, mis->postcopy_qemufile_dst,NULL );if (ret) { +error_setg (errp,"Failed to load device state section ID : %d" , + ret);break ; }
@@ -3073,20 +3076,20 @@ retry:switch (section_type) {case QEMU_VM_SECTION_START :case QEMU_VM_SECTION_FULL : - ret =qemu_loadvm_section_start_full (f, section_type,NULL ); + ret =qemu_loadvm_section_start_full (f, section_type, errp);if (ret <0 ) { goto out; }break ;case QEMU_VM_SECTION_PART :case QEMU_VM_SECTION_END : - ret =qemu_loadvm_section_part_end (f, section_type,NULL ); + ret =qemu_loadvm_section_part_end (f, section_type, errp);if (ret <0 ) { goto out; }break ;case QEMU_VM_COMMAND : - ret =loadvm_process_command (f,NULL ); + ret =loadvm_process_command (f, errp);trace_qemu_loadvm_state_section_command (ret);if ((ret <0 ) || (ret ==LOADVM_QUIT )) { goto out;
@@ -3096,7 +3099,7 @@ retry:/* This is the end of migration */ goto out;default : -error_report ("Unknown savevm section type %d" , section_type); +error_setg (errp,"Unknown savevm section type %d" , section_type); ret = -EINVAL ; goto out; }
@@ -3160,7 +3163,7 @@ int qemu_loadvm_state(QEMUFile *f)cpu_synchronize_all_pre_loadvm (); - ret =qemu_loadvm_state_main (f, mis); + ret =qemu_loadvm_state_main (f, mis,NULL );qemu_event_set (&mis->main_thread_load_event);trace_qemu_loadvm_state_post_main (ret);
@@ -3234,7 +3237,7 @@ int qemu_load_device_state(QEMUFile *f)int ret;/* Load QEMU_VM_SECTION_FULL section */ - ret =qemu_loadvm_state_main (f, mis); + ret =qemu_loadvm_state_main (f, mis,NULL );if (ret <0 ) {error_report ("Failed to load device state: %d" , ret);return ret;
migration/savevm.h +2 -1
@@ -66,7 +66,8 @@ int qemu_save_device_state(QEMUFile *f);int qemu_loadvm_state (QEMUFile *f);void qemu_loadvm_state_cleanup (MigrationIncomingState *mis); -int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis); +int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis, +Error **errp);int qemu_load_device_state (QEMUFile *f);int qemu_loadvm_approve_switchover (void ); int qemu_savevm_state_complete_precopy_non_iterable(QEMUFile *f,
Signature · 1 line
2.50.0
Re: [PATCH v5 18/23] migration: push Error **errp into qemu_loadvm_state_main()
Quoted 7 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatqemu_loadvm_state_main()must report an error in errp, in case of failure.loadvm_process_commandalso sets the errp object explicitly.
Quoted 6 lines
Signed-off-by Arun Menon <[email protected]>--- migration/colo.c | 5 +++-- migration/savevm.c | 23 +++++++++++++---------- migration/savevm.h | 3 ++- 3 files changed, 18 insertions(+), 13 deletions(-)
migration/colo.c static void colo_incoming_process_checkpoint(MigrationIncomingState *mis, · line 689
Quoted 11 lines
migration/colo.c +1
-1@@ -686,11 +686,12 @@ static void colo_incoming_process_checkpoint(MigrationIncomingState *mis,bql_lock ();cpu_synchronize_all_states (); - ret =qemu_loadvm_state_main (mis->from_src_file, mis); + ret =qemu_loadvm_state_main (mis->from_src_file, mis, &local_err);
Although earlier code in this method is using "&local_err", that it because those methods are "void" return, so checking 'local_err' is needed to detect failure.
In this case, however, you use 'ret' to detect failure so passing "errp" to this method directly is the correct pattern....
migration/colo.c static void colo_incoming_process_checkpoint(MigrationIncomingState *mis, · line 694
Quoted 6 lines
migration/colo.c +2
-1bql_unlock ();if (ret <0 ) { -error_setg (errp,"Load VM's live state (ram) error" ); +error_propagate_prepend (errp, local_err, +"Load VM's live state (ram) error" );
..and just error_prepend here.
Quoted 11 lines
migration/colo.c +2
-1@@ -3055,7 +3055,8 @@ static bool postcopy_pause_incoming(MigrationIncomingState *mis)return true; } -int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis) +int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis, +Error **errp) {uint8_t section_type;int ret =0 ;
migration/colo.c retry: · line 3071
Quoted 5 lines
migration/colo.c +2
-0@@ -3066,6 +3067,8 @@ retry: ret =qemu_file_get_error_obj_any (f, mis->postcopy_qemufile_dst,NULL );if (ret) { +error_setg (errp,"Failed to load device state section ID : %d" , + ret);
Pass "errp" to qemu_file_get_error_obj_any() instead of NULL, to get the real pre-existing error message.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 19/23 migration: push Error **errp into qemu_loadvm_state()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that qemu_loadvm_state() must report an error in errp, in case of failure.
--- migration/migration.c | 5 +++-- migration/savevm.c | 25 +++++++++++++------------ migration/savevm.h | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-)
migration/migration.c +3 -2
@@ -881,7 +881,7 @@ process_incoming_migration_co(void *opaque) MIGRATION_STATUS_ACTIVE); mis->loadvm_co =qemu_coroutine_self (); - ret =qemu_loadvm_state (mis->from_src_file); + ret =qemu_loadvm_state (mis->from_src_file, &local_err); mis->loadvm_co =NULL ;trace_vmstate_downtime_checkpoint ("dst-precopy-loadvm-completed" );
@@ -908,7 +908,8 @@ process_incoming_migration_co(void *opaque) }if (ret <0 ) { -error_setg (&local_err,"load of migration failed: %s" ,strerror (-ret)); +error_prepend (&local_err,"load of migration failed: %s " , +strerror (-ret)); goto fail; }
migration/savevm.c +13 -12
@@ -3133,27 +3133,24 @@ out:return ret; } -int qemu_loadvm_state (QEMUFile *f) +int qemu_loadvm_state (QEMUFile *f,Error **errp) {MigrationState *s =migrate_get_current ();MigrationIncomingState *mis =migration_incoming_get_current (); -Error *local_err =NULL ;int ret; -if (qemu_savevm_state_blocked (&local_err)) { -error_report_err (local_err); +if (qemu_savevm_state_blocked (errp)) {return -EINVAL ; }qemu_loadvm_thread_pool_create (mis); - ret =qemu_loadvm_state_header (f,NULL ); + ret =qemu_loadvm_state_header (f, errp);if (ret) {return ret; } -if (qemu_loadvm_state_setup (f, &local_err) !=0 ) { -error_report_err (local_err); +if (qemu_loadvm_state_setup (f, errp) !=0 ) {return -EINVAL ; }
@@ -3163,7 +3160,7 @@ int qemu_loadvm_state(QEMUFile *f)cpu_synchronize_all_pre_loadvm (); - ret =qemu_loadvm_state_main (f, mis,NULL ); + ret =qemu_loadvm_state_main (f, mis, errp);qemu_event_set (&mis->main_thread_load_event);trace_qemu_loadvm_state_post_main (ret);
@@ -3181,8 +3178,12 @@ int qemu_loadvm_state(QEMUFile *f)if (migrate_has_error (migrate_get_current ()) || !qemu_loadvm_thread_pool_wait (s, mis)) { ret = -EINVAL ; +error_setg (errp,"Error while loading vmstate : %d" , ret); }else { ret =qemu_file_get_error (f); +if (ret <0 ) { +error_setg (errp,"Error while loading vmstate : %d" , ret); + } } }/*
@@ -3468,10 +3469,10 @@ void qmp_xen_load_devices_state(const char *filename, Error **errp) f =qemu_file_new_input (QIO_CHANNEL (ioc));object_unref (OBJECT (ioc)); - ret =qemu_loadvm_state (f); + ret =qemu_loadvm_state (f, errp);qemu_fclose (f);if (ret <0 ) { -error_setg (errp,"loading Xen device state failed" ); +error_prepend (errp,"loading Xen device state failed " ); }migration_incoming_state_destroy (); }
@@ -3542,13 +3543,13 @@ bool load_snapshot(const char *name, const char *vmstate, ret = -EINVAL ; goto err_drain; } - ret =qemu_loadvm_state (f); + ret =qemu_loadvm_state (f, errp);migration_incoming_state_destroy ();bdrv_drain_all_end ();if (ret <0 ) { -error_setg (errp,"Error %d while loading VM state" , ret); +error_prepend (errp,"Error %d while loading VM state " , ret);return false; }
migration/savevm.h +1 -1
@@ -64,7 +64,7 @@ void qemu_savevm_send_colo_enable(QEMUFile *f);void qemu_savevm_live_state (QEMUFile *f);int qemu_save_device_state (QEMUFile *f); -int qemu_loadvm_state (QEMUFile *f); +int qemu_loadvm_state (QEMUFile *f,Error **errp);void qemu_loadvm_state_cleanup (MigrationIncomingState *mis);int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis,Error **errp);
Signature · 1 line
2.50.0
Re: [PATCH v5 19/23] migration: push Error **errp into qemu_loadvm_state()
Quoted 15 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatqemu_loadvm_state()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/migration.c | 5 +++-- migration/savevm.c | 25 +++++++++++++------------ migration/savevm.h | 2 +- 3 files changed, 17 insertions(+), 15 deletions(-)
migration/savevm.c int qemu_loadvm_state(QEMUFile *f) · line 3186
Quoted 9 lines
migration/savevm.c +4
-0@@ -3181,8 +3178,12 @@ int qemu_loadvm_state(QEMUFile *f)if (migrate_has_error (migrate_get_current ()) || !qemu_loadvm_thread_pool_wait (s, mis)) { ret = -EINVAL ; +error_setg (errp,"Error while loading vmstate : %d" , ret); }else { ret =qemu_file_get_error (f); +if (ret <0 ) { +error_setg (errp,"Error while loading vmstate : %d" , ret); + }
Replace qemu_file_get_error with qemu_file_get_error_obj(..., errp) so we propagate the real error message.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 20/23 migration: push Error **errp into qemu_load_device_state()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured that qemu_load_device_state() must report an error in errp, in case of failure.
--- migration/colo.c | 5 +++-- migration/savevm.c | 6 +++--- migration/savevm.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-)
migration/colo.c +3 -2
@@ -730,9 +730,10 @@ static void colo_incoming_process_checkpoint(MigrationIncomingState *mis,bql_lock (); vmstate_loading = true;colo_flush_ram_cache (); - ret =qemu_load_device_state (fb); + ret =qemu_load_device_state (fb, &local_err);if (ret <0 ) { -error_setg (errp,"COLO: load device state failed" ); +error_propagate_prepend (errp, local_err, +"COLO: load device state failed" ); vmstate_loading = false;bql_unlock ();return ;
migration/savevm.c +3 -3
@@ -3232,15 +3232,15 @@ int qemu_loadvm_state(QEMUFile *f, Error **errp)return ret; } -int qemu_load_device_state (QEMUFile *f) +int qemu_load_device_state (QEMUFile *f,Error **errp) {MigrationIncomingState *mis =migration_incoming_get_current ();int ret;/* Load QEMU_VM_SECTION_FULL section */ - ret =qemu_loadvm_state_main (f, mis,NULL ); + ret =qemu_loadvm_state_main (f, mis, errp);if (ret <0 ) { -error_report ("Failed to load device state: %d" , ret); +error_prepend (errp,"Failed to load device state: %d " , ret);return ret; }
migration/savevm.h +1 -1
@@ -68,7 +68,7 @@ int qemu_loadvm_state(QEMUFile *f, Error **errp);void qemu_loadvm_state_cleanup (MigrationIncomingState *mis);int qemu_loadvm_state_main (QEMUFile *f,MigrationIncomingState *mis,Error **errp); -int qemu_load_device_state (QEMUFile *f); +int qemu_load_device_state (QEMUFile *f,Error **errp);int qemu_loadvm_approve_switchover (void );int qemu_savevm_state_complete_precopy_non_iterable (QEMUFile *f,bool in_postcopy);
Signature · 1 line
2.50.0
Re: [PATCH v5 20/23] migration: push Error **errp into qemu_load_device_state()
Quoted 18 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
It is ensured thatqemu_load_device_state()must report an error in errp, in case of failure.Signed-off-by Arun Menon <[email protected]>--- migration/colo.c | 5 +++-- migration/savevm.c | 6 +++--- migration/savevm.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-)migration/colo.c +0
-0
migration/colo.c static void colo_incoming_process_checkpoint(MigrationIncomingState *mis, · line 733
Quoted 5 lines
migration/colo.c +1
-1@@ -730,9 +730,10 @@ static void colo_incoming_process_checkpoint(MigrationIncomingState *mis,bql_lock (); vmstate_loading = true;colo_flush_ram_cache (); - ret =qemu_load_device_state (fb); + ret =qemu_load_device_state (fb, &local_err);
Just use 'errp' here
migration/colo.c static void colo_incoming_process_checkpoint(MigrationIncomingState *mis, · line 739
Quoted 7 lines
migration/colo.c +2
-1if (ret <0 ) { -error_setg (errp,"COLO: load device state failed" ); +error_propagate_prepend (errp, local_err, +"COLO: load device state failed" ); vmstate_loading = false;bql_unlock ();return ;
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 21/23 migration: Capture error in postcopy_ram_listen_thread()
In reply to Arun MenonThis is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor. postcopy_ram_listen_thread() calls qemu_loadvm_state_main() to load the vm, and in case of a failure, it should set the error in the migration object.
When postcopy live migration runs, the device states are loaded by both the qemu coroutine process_incoming_migration_co() and the postcopy_ram_listen_thread(). Therefore, it is important that the coroutine also reports the error in case of failure, with error_report_err(). Otherwise, the source qemu will not display any errors before going into the postcopy pause state.
--- migration/migration.c | 2 +- migration/savevm.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-)
migration/migration.c +1 -1
@@ -925,7 +925,7 @@ fail:migrate_set_state (&mis->state,MIGRATION_STATUS_ACTIVE ,MIGRATION_STATUS_FAILED );migrate_set_error (s, local_err); -error_free (local_err); +error_report_err (local_err);migration_incoming_state_destroy ();
migration/savevm.c +8 -2
@@ -2086,6 +2086,7 @@ static void *postcopy_ram_listen_thread(void *opaque)QEMUFile *f = mis->from_src_file;int load_res;MigrationState *migr =migrate_get_current (); +Error *local_err =NULL ;object_ref (OBJECT (migr));
@@ -2102,7 +2103,7 @@ static void *postcopy_ram_listen_thread(void *opaque)qemu_file_set_blocking (f, true);/* TODO: sanity check that only postcopiable data will be loaded here */ - load_res =qemu_loadvm_state_main (f, mis,NULL ); + load_res =qemu_loadvm_state_main (f, mis, &local_err);/* * This is tricky, but, mis->from_src_file can change after it
@@ -2128,7 +2129,12 @@ static void *postcopy_ram_listen_thread(void *opaque) __func__, load_res); load_res =0 ;/* prevent further exit() */ }else { -error_report ("%s: loadvm failed: %d" , __func__, load_res); +if (local_err !=NULL ) { +error_prepend (&local_err,"%s: loadvm failed: %d" , __func__, + load_res); +migrate_set_error (migr, local_err); +error_report_err (local_err); + }migrate_set_state (&mis->state,MIGRATION_STATUS_POSTCOPY_ACTIVE ,MIGRATION_STATUS_FAILED ); }
Signature · 1 line
2.50.0
Re: [PATCH v5 21/23] migration: Capture error in postcopy_ram_listen_thread()
Quoted 44 lines · Arun Menon
This is an incremental step in converting vmstate loading code to report error via Error objects instead of directly printing it to console/monitor.
postcopy_ram_listen_thread()callsqemu_loadvm_state_main()to load the vm, and in case of a failure, it should set the error in the migration object.When postcopy live migration runs, the device states are loaded by both the qemu coroutine
process_incoming_migration_co()and thepostcopy_ram_listen_thread(). Therefore, it is important that the coroutine also reports the error in case of failure, witherror_report_err(). Otherwise, the source qemu will not display any errors before going into the postcopy pause state.Signed-off-by Arun Menon <[email protected]>--- migration/migration.c | 2 +- migration/savevm.c | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-)migration/savevm.c +2
-1@@ -2086,6 +2086,7 @@ static void *postcopy_ram_listen_thread(void *opaque)QEMUFile *f = mis->from_src_file;int load_res;MigrationState *migr =migrate_get_current (); +Error *local_err =NULL ;object_ref (OBJECT (migr));@@ -2102,7 +2103,7 @@ static void *postcopy_ram_listen_thread(void *opaque)qemu_file_set_blocking (f, true);/* TODO: sanity check that only postcopiable data will be loaded here */ - load_res =qemu_loadvm_state_main (f, mis,NULL ); + load_res =qemu_loadvm_state_main (f, mis, &local_err);/* * This is tricky, but, mis->from_src_file can change after it
migration/savevm.c static void *postcopy_ram_listen_thread(void *opaque) · line 2134
Quoted 7 lines
migration/savevm.c +3
-1@@ -2128,7 +2129,12 @@ static void *postcopy_ram_listen_thread(void *opaque) __func__, load_res); load_res =0 ;/* prevent further exit() */ }else { -error_report ("%s: loadvm failed: %d" , __func__, load_res); +if (local_err !=NULL ) { +error_prepend (&local_err,"%s: loadvm failed: %d" , __func__, + load_res);
IMHO __func__ is redundant if you change the message to be 'loadvm failed during postcopy' like the earlier part fo the "if { " does.
migration/savevm.c static void *postcopy_ram_listen_thread(void *opaque) · line 2139
Quoted 5 lines
migration/savevm.c +3
-0+migrate_set_error (migr, local_err); +error_report_err (local_err); + }migrate_set_state (&mis->state,MIGRATION_STATUS_POSTCOPY_ACTIVE ,MIGRATION_STATUS_FAILED );
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 22/23 migration: Add error-parameterized function variants in VMSD struct
In reply to Arun Menon- We need to have good error reporting in the callbacks in VMStateDescription struct. Specifically pre_save, post_save, pre_load and post_load callbacks.
- It is not possible to change these functions everywhere in one patch, therefore, we introduce a duplicate set of callbacks with Error object passed to them.
- So, in this commit, we implement 'errp' variants of these callbacks, introducing an explicit Error object parameter.
- This is a functional step towards transitioning the entire codebase to the new error-parameterized functions.
- Deliberately called in mutual exclusion from their counterparts, to prevent conflicts during the transition.
- New impls should preferentally use 'errp' variants of these methods, and existing impls incrementally converted. The variants without 'errp' are intended to be removed once all usage is converted.
--- include/migration/vmstate.h | 11 +++++++++++ migration/vmstate.c | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 5 deletions(-)
include/migration/vmstate.h +11 -0
@@ -200,15 +200,26 @@ struct VMStateDescription {* exclusive. For this reason, also early_setup VMSDs are migrated in a * QEMU_VM_SECTION_FULL section, while save_setup() data is migrated in * a QEMU_VM_SECTION_START section. +* +* There are duplicate impls of the post/pre save/load hooks. +* New impls should preferentally use 'errp' variants of these +* methods and existing impls incrementally converted. +* The variants without 'errp' are intended to be removed +* once all usage is converted. */ +bool early_setup;int version_id;int minimum_version_id;MigrationPriority priority;int (*pre_load)(void *opaque); +int (*pre_load_errp)(void *opaque,Error **errp);int (*post_load)(void *opaque,int version_id); +int (*post_load_errp)(void *opaque,int version_id,Error **errp);int (*pre_save)(void *opaque); +int (*pre_save_errp)(void *opaque,Error **errp);int (*post_save)(void *opaque); +int (*post_save_errp)(void *opaque,Error **errp);bool (*needed)(void *opaque);bool (*dev_unplug_pending)(void *opaque);
migration/vmstate.c +31 -5
@@ -152,7 +152,13 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,trace_vmstate_load_state_end (vmsd->name,"too old" , -EINVAL );return -EINVAL ; } -if (vmsd->pre_load) { +if (vmsd->pre_load_errp) { + ret = vmsd->pre_load_errp (opaque, errp); +if (ret) { +error_prepend (errp,"VM pre load failed : %d " , ret); +return ret; + } + }else if (vmsd->pre_load) { ret = vmsd->pre_load (opaque);if (ret) {error_setg (errp,"VM pre load failed : %d" , ret);
@@ -238,7 +244,12 @@ int vmstate_load_state(QEMUFile *f, const VMStateDescription *vmsd,qemu_file_set_error (f, ret);return ret; } -if (vmsd->post_load) { +if (vmsd->post_load_errp) { + ret = vmsd->post_load_errp (opaque, version_id, errp); +if (ret <0 ) { +error_prepend (errp,"VM Post load failed : %d " , ret); + } + }else if (vmsd->post_load) { ret = vmsd->post_load (opaque, version_id);if (ret <0 ) {error_setg (errp,"VM Post load failed : %d" , ret);
@@ -414,7 +425,14 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,trace_vmstate_save_state_top (vmsd->name); -if (vmsd->pre_save) { +if (vmsd->pre_save_errp) { + ret = vmsd->pre_save_errp (opaque, errp); +trace_vmstate_save_state_pre_save_res (vmsd->name, ret); +if (ret) { +error_prepend (errp,"pre-save failed: %s " , vmsd->name); +return ret; + } + }else if (vmsd->pre_save) { ret = vmsd->pre_save (opaque);trace_vmstate_save_state_pre_save_res (vmsd->name, ret);if (ret) {
@@ -524,7 +542,9 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,if (ret) {error_setg (errp,"Save of field %s/%s failed" , vmsd->name, field->name); -if (vmsd->post_save) { +if (vmsd->post_save_errp) { + vmsd->post_save_errp (opaque, errp); + }else if (vmsd->post_save) { vmsd->post_save (opaque); }return ret;
@@ -552,7 +572,13 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, ret =vmstate_subsection_save (f, vmsd, opaque, vmdesc, errp); -if (vmsd->post_save) { +if (vmsd->post_save_errp) { +int ps_ret = vmsd->post_save_errp (opaque, errp); +if (!ret && ps_ret) { + ret = ps_ret; +error_prepend (errp,"post-save failed: %s " , vmsd->name); + } + }else if (vmsd->post_save) {int ps_ret = vmsd->post_save (opaque);if (!ret && ps_ret) { ret = ps_ret;
Signature · 1 line
2.50.0
Re: [PATCH v5 22/23] migration: Add error-parameterized function variants in VMSD struct
Quoted 25 lines · Arun Menon
- We need to have good error reporting in the callbacks in VMStateDescription struct. Specifically
pre_save,post_save,pre_loadandpost_loadcallbacks.
- It is not possible to change these functions everywhere in one patch, therefore, we introduce a duplicate set of callbacks with Error object passed to them.
- So, in this commit, we implement 'errp' variants of these callbacks, introducing an explicit Error object parameter.
- This is a functional step towards transitioning the entire codebase to the new error-parameterized functions.
- Deliberately called in mutual exclusion from their counterparts, to prevent conflicts during the transition.
- New impls should preferentally use 'errp' variants of these methods, and existing impls incrementally converted. The variants without 'errp' are intended to be removed once all usage is converted.Signed-off-by Arun Menon <[email protected]>--- include/migration/vmstate.h | 11 +++++++++++ migration/vmstate.c | 36 +++++++++++++++++++++++++++++++----- 2 files changed, 42 insertions(+), 5 deletions(-)
migration/vmstate.c int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, · line 546
Quoted 6 lines
migration/vmstate.c +2
-1@@ -524,7 +542,9 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,if (ret) {error_setg (errp,"Save of field %s/%s failed" , vmsd->name, field->name); -if (vmsd->post_save) { +if (vmsd->post_save_errp) { + vmsd->post_save_errp (opaque, errp);
We are already in an error path here, and we set 'errp' just a few lines above. If post_save_errp tries to set it too, then we're doomed.
You'll need to pass an &Local_err in here, and then append it to the current error.
migration/vmstate.c int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, · line 573
Quoted 7 lines
migration/vmstate.c +1
-0+ }else if (vmsd->post_save) { vmsd->post_save (opaque); }return ret;@@ -552,7 +572,13 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, ret =vmstate_subsection_save (f, vmsd, opaque, vmdesc, errp);
Potentially set 'errp'
migration/vmstate.c int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd, · line 576
Quoted 3 lines
migration/vmstate.c +2
-1-if (vmsd->post_save) { +if (vmsd->post_save_errp) { +int ps_ret = vmsd->post_save_errp (opaque, errp);
so must not be passing 'errp' here.
Quoted 9 lines
migration/vmstate.c +5
-0+if (!ret && ps_ret) { + ret = ps_ret; +error_prepend (errp,"post-save failed: %s " , vmsd->name); + } + }else if (vmsd->post_save) {int ps_ret = vmsd->post_save (opaque);if (!ret && ps_ret) {
Quoted 6 lines
ret = ps_ret;Signature · 1 line
2.50.0
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
PATCH v5 23/23 backends/tpm: Propagate vTPM error on migration failure
In reply to Arun Menon- When migration of a VM with encrypted vTPM fails on the destination host, (e.g., due to a mismatch in secret values), the error message displayed on the source host is generic and unhelpful.
- For example, a typical error looks like this:
"operation failed: job 'migration out' failed: Sibling indicated error 1. operation failed: job 'migration in' failed: load of migration failed:
Input/output error"
- Such generic errors are logged using error_report(), which prints to the console/monitor but does not make the detailed error accessible via the QMP query-migrate command.
- This change, along with the set of changes of passing errp Error object to the VM state loading functions, help in addressing the issue. We use the post_load_errp hook of VMStateDescription to propagate errors by setting Error **errp objects in case of failure in the TPM backend.
- It can then be retrieved using QMP command:
{"execute" : "query-migrate"}
--- backends/tpm/tpm_emulator.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-)
backends/tpm/tpm_emulator.c +20 -19
@@ -819,7 +819,8 @@ static int tpm_emulator_get_state_blobs(TPMEmulator *tpm_emu)static int tpm_emulator_set_state_blob (TPMEmulator *tpm_emu,uint32_t type,TPMSizedBuffer *tsb, -uint32_t flags) +uint32_t flags, +Error **errp) {ssize_t n;ptm_setstate pss;
@@ -838,17 +839,17 @@ static int tpm_emulator_set_state_blob(TPMEmulator *tpm_emu,/* write the header only */ if (tpm_emulator_ctrlcmd (tpm_emu,CMD_SET_STATEBLOB , &pss, offsetof(ptm_setstate, u.req.data), 0, 0) < 0) { -error_report ("tpm-emulator: could not set state blob type %d : %s" , - type,strerror (errno)); +error_setg (errp,"tpm-emulator: could not set state blob type %d : %s" , + type,strerror (errno));return -1 ; }/* now the body */ n =qemu_chr_fe_write_all (&tpm_emu->ctrl_chr, tsb->buffer, tsb->size);if (n != tsb->size) { -error_report ("tpm-emulator: Writing the stateblob (type %d) " -"failed; could not write %u bytes, but only %zd" , - type, tsb->size, n); +error_setg (errp,"tpm-emulator: Writing the stateblob (type %d) " +"failed; could not write %u bytes, but only %zd" , + type, tsb->size, n);return -1 ; }
@@ -856,17 +857,17 @@ static int tpm_emulator_set_state_blob(TPMEmulator *tpm_emu, n =qemu_chr_fe_read_all (&tpm_emu->ctrl_chr, (uint8_t *)&pss,sizeof (pss.u.resp));if (n !=sizeof (pss.u.resp)) { -error_report ("tpm-emulator: Reading response from writing stateblob " -"(type %d) failed; expected %zu bytes, got %zd" , type, -sizeof (pss.u.resp), n); +error_setg (errp,"tpm-emulator: Reading response from writing " +"stateblob (type %d) failed; expected %zu bytes, " +"got %zd" , type,sizeof (pss.u.resp), n);return -1 ; } tpm_result =be32_to_cpu (pss.u.resp.tpm_result);if (tpm_result !=0 ) { -error_report ("tpm-emulator: Setting the stateblob (type %d) failed " -"with a TPM error 0x%x %s" , type, tpm_result, -tpm_emulator_strerror (tpm_result)); +error_setg (errp,"tpm-emulator: Setting the stateblob (type %d) " +"failed with a TPM error 0x%x %s" , type, tpm_result, +tpm_emulator_strerror (tpm_result));return -1 ; }
@@ -880,7 +881,7 @@ static int tpm_emulator_set_state_blob(TPMEmulator *tpm_emu,* * Returns a negative errno code in case of error. */ -static int tpm_emulator_set_state_blobs (TPMBackend *tb) +static int tpm_emulator_set_state_blobs (TPMBackend *tb,Error **errp) {TPMEmulator *tpm_emu =TPM_EMULATOR (tb);TPMBlobBuffers *state_blobs = &tpm_emu->state_blobs;
@@ -894,13 +895,13 @@ static int tpm_emulator_set_state_blobs(TPMBackend *tb)if (tpm_emulator_set_state_blob (tpm_emu,PTM_BLOB_TYPE_PERMANENT , &state_blobs->permanent, - state_blobs->permanent_flags) <0 || + state_blobs->permanent_flags, errp) <0 ||tpm_emulator_set_state_blob (tpm_emu,PTM_BLOB_TYPE_VOLATILE , &state_blobs->volatil, - state_blobs->volatil_flags) <0 || + state_blobs->volatil_flags, errp) <0 ||tpm_emulator_set_state_blob (tpm_emu,PTM_BLOB_TYPE_SAVESTATE , &state_blobs->savestate, - state_blobs->savestate_flags) <0 ) { + state_blobs->savestate_flags, errp) <0 ) {return -EIO ; }
@@ -948,12 +949,12 @@ static void tpm_emulator_vm_state_change(void *opaque, bool running,* * Returns negative errno codes in case of error. */ -static int tpm_emulator_post_load (void *opaque,int version_id) +static int tpm_emulator_post_load (void *opaque,int version_id,Error **errp) {TPMBackend *tb = opaque;int ret; - ret =tpm_emulator_set_state_blobs (tb); + ret =tpm_emulator_set_state_blobs (tb, errp);if (ret <0 ) {return ret; }
@@ -969,7 +970,7 @@ static const VMStateDescription vmstate_tpm_emulator = { .name = "tpm-emulator", .version_id = 0, .pre_save = tpm_emulator_pre_save, - .post_load = tpm_emulator_post_load, + .post_load_errp = tpm_emulator_post_load, .fields = (const VMStateField []) {VMSTATE_UINT32 (state_blobs.permanent_flags, TPMEmulator),VMSTATE_UINT32 (state_blobs.permanent.size, TPMEmulator),
Signature · 1 line
2.50.0
Re: [PATCH v5 23/23] backends/tpm: Propagate vTPM error on migration failure
Quoted 17 lines · Arun Menon
- When migration of a VM with encrypted vTPM fails on the destination host, (e.g., due to a mismatch in secret values), the error message displayed on the source host is generic and unhelpful.
- For example, a typical error looks like this:
"operation failed: job 'migration out' failed: Sibling indicated error 1. operation failed: job 'migration in' failed: load of migration failed:
Input/output error"
- Such generic errors are logged usingerror_report(), which prints to the console/monitor but does not make the detailed error accessible via the QMP query-migrate command.
- This change, along with the set of changes of passing errp Error object to the VM state loading functions, help in addressing the issue. We use thepost_load_errphook of VMStateDescription to propagate errors by setting Error **errp objects in case of failure in the TPM backend.
- It can then be retrieved using QMP command:
{"execute" : "query-migrate"}
Quoted 7 lines
Reviewed-by Stefan Berger <[email protected]>Signed-off-by Arun Menon <[email protected]>--- backends/tpm/tpm_emulator.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-)
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|