On Wed, Feb 12, 2020 at 02:42:41PM +0100, David Hildenbrand wrote: > Everybody discards the error. Let's error_report() instead so this error > doesn't get lost. > > Cc: Richard Henderson <r...@twiddle.net> > Cc: Paolo Bonzini <pbonz...@redhat.com> > Cc: Eduardo Habkost <ehabk...@redhat.com> > Cc: Marcel Apfelbaum <marcel.apfelb...@gmail.com> > Cc: Alex Williamson <alex.william...@redhat.com> > Cc: Stefan Hajnoczi <stefa...@redhat.com> > Signed-off-by: David Hildenbrand <da...@redhat.com>
IMHO error_setg() should be preferred comparing to error_report() because it has a context to be delivered to the caller, so the error has a better chance to be used in a better way (e.g., QMP only supports error_setg()). A better solution is that we deliver the error upper. For example, qemu_vfio_dma_map() is one caller of qemu_vfio_undo_mapping, if you see the callers of qemu_vfio_dma_map() you'll notice most of them has Error** defined (e.g., nvme_init_queue). Then we can link all of them up. Another lazy solution (and especially if vfio-helpers are still mostly used only by advanced users) is we can simply pass in &error_abort for the three callers then they won't be missed... Thanks, > --- > util/vfio-helpers.c | 11 +++++------ > 1 file changed, 5 insertions(+), 6 deletions(-) > > diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c > index d6332522c1..13dd962d95 100644 > --- a/util/vfio-helpers.c > +++ b/util/vfio-helpers.c > @@ -540,8 +540,7 @@ static int qemu_vfio_do_mapping(QEMUVFIOState *s, void > *host, size_t size, > /** > * Undo the DMA mapping from @s with VFIO, and remove from mapping list. > */ > -static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping, > - Error **errp) > +static void qemu_vfio_undo_mapping(QEMUVFIOState *s, IOVAMapping *mapping) > { > int index; > struct vfio_iommu_type1_dma_unmap unmap = { > @@ -556,7 +555,7 @@ static void qemu_vfio_undo_mapping(QEMUVFIOState *s, > IOVAMapping *mapping, > assert(QEMU_IS_ALIGNED(mapping->size, qemu_real_host_page_size)); > assert(index >= 0 && index < s->nr_mappings); > if (ioctl(s->container, VFIO_IOMMU_UNMAP_DMA, &unmap)) { > - error_setg(errp, "VFIO_UNMAP_DMA failed: %d", -errno); > + error_report("VFIO_UNMAP_DMA failed: %d", -errno); > } > memmove(mapping, &s->mappings[index + 1], > sizeof(s->mappings[0]) * (s->nr_mappings - index - 1)); > @@ -621,7 +620,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, > size_t size, > assert(qemu_vfio_verify_mappings(s)); > ret = qemu_vfio_do_mapping(s, host, size, iova0); > if (ret) { > - qemu_vfio_undo_mapping(s, mapping, NULL); > + qemu_vfio_undo_mapping(s, mapping); > goto out; > } > s->low_water_mark += size; > @@ -681,7 +680,7 @@ void qemu_vfio_dma_unmap(QEMUVFIOState *s, void *host) > if (!m) { > goto out; > } > - qemu_vfio_undo_mapping(s, m, NULL); > + qemu_vfio_undo_mapping(s, m); > out: > qemu_mutex_unlock(&s->lock); > } > @@ -698,7 +697,7 @@ void qemu_vfio_close(QEMUVFIOState *s) > return; > } > while (s->nr_mappings) { > - qemu_vfio_undo_mapping(s, &s->mappings[s->nr_mappings - 1], NULL); > + qemu_vfio_undo_mapping(s, &s->mappings[s->nr_mappings - 1]); > } > ram_block_notifier_remove(&s->ram_notifier); > qemu_vfio_reset(s); > -- > 2.24.1 > > -- Peter Xu