[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v2 fixed 03/16] util: vfio-helpers: Remove Error parameter fr
From: |
Peter Xu |
Subject: |
Re: [PATCH v2 fixed 03/16] util: vfio-helpers: Remove Error parameter from qemu_vfio_undo_mapping() |
Date: |
Tue, 18 Feb 2020 17:07:46 -0500 |
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 <address@hidden>
> Cc: Paolo Bonzini <address@hidden>
> Cc: Eduardo Habkost <address@hidden>
> Cc: Marcel Apfelbaum <address@hidden>
> Cc: Alex Williamson <address@hidden>
> Cc: Stefan Hajnoczi <address@hidden>
> Signed-off-by: David Hildenbrand <address@hidden>
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
- [PATCH v2 fixed 00/16] Ram blocks with resizable anonymous allocations under POSIX, David Hildenbrand, 2020/02/12
- [PATCH v2 fixed 01/16] util: vfio-helpers: Factor out and fix processing of existing ram blocks, David Hildenbrand, 2020/02/12
- [PATCH v2 fixed 02/16] util: vfio-helpers: Fix qemu_vfio_close(), David Hildenbrand, 2020/02/12
- [PATCH v2 fixed 03/16] util: vfio-helpers: Remove Error parameter from qemu_vfio_undo_mapping(), David Hildenbrand, 2020/02/12
- Re: [PATCH v2 fixed 03/16] util: vfio-helpers: Remove Error parameter from qemu_vfio_undo_mapping(),
Peter Xu <=
- [PATCH v2 fixed 04/16] util: vfio-helpers: Factor out removal from qemu_vfio_undo_mapping(), David Hildenbrand, 2020/02/12
- [PATCH v2 fixed 06/16] exec: Reuse qemu_ram_apply_settings() in qemu_ram_remap(), David Hildenbrand, 2020/02/12
- [PATCH v2 fixed 05/16] exec: Factor out setting ram settings (madvise ...) into qemu_ram_apply_settings(), David Hildenbrand, 2020/02/12
- [PATCH v2 fixed 07/16] exec: Drop "shared" parameter from ram_block_add(), David Hildenbrand, 2020/02/12
- [PATCH v2 fixed 08/16] util/mmap-alloc: Factor out calculation of pagesize to mmap_pagesize(), David Hildenbrand, 2020/02/12