Skip to content

Commit 521b97c

Browse files
philmdstefanhaRH
authored andcommitted
util/vfio-helpers: Pass Error handle to qemu_vfio_dma_map()
Currently qemu_vfio_dma_map() displays errors on stderr. When using management interface, this information is simply lost. Pass qemu_vfio_dma_map() an Error** handle so it can propagate the error to callers. Reviewed-by: Fam Zheng <[email protected]> Reviewed-by: Stefan Hajnoczi <[email protected]> Reviewed-by: Klaus Jensen <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Message-id: [email protected] Signed-off-by: Stefan Hajnoczi <[email protected]>
1 parent 526c37c commit 521b97c

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

block/nvme.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,11 @@ static bool nvme_init_queue(BDRVNVMeState *s, NVMeQueue *q,
176176
return false;
177177
}
178178
memset(q->queue, 0, bytes);
179-
r = qemu_vfio_dma_map(s->vfio, q->queue, bytes, false, &q->iova);
179+
r = qemu_vfio_dma_map(s->vfio, q->queue, bytes, false, &q->iova, errp);
180180
if (r) {
181-
error_setg(errp, "Cannot map queue");
182-
return false;
181+
error_prepend(errp, "Cannot map queue: ");
183182
}
184-
return true;
183+
return r == 0;
185184
}
186185

187186
static void nvme_free_queue_pair(NVMeQueuePair *q)
@@ -239,9 +238,9 @@ static NVMeQueuePair *nvme_create_queue_pair(BDRVNVMeState *s,
239238
qemu_co_queue_init(&q->free_req_queue);
240239
q->completion_bh = aio_bh_new(aio_context, nvme_process_completion_bh, q);
241240
r = qemu_vfio_dma_map(s->vfio, q->prp_list_pages, bytes,
242-
false, &prp_list_iova);
241+
false, &prp_list_iova, errp);
243242
if (r) {
244-
error_setg_errno(errp, -r, "Cannot map buffer for DMA");
243+
error_prepend(errp, "Cannot map buffer for DMA: ");
245244
goto fail;
246245
}
247246
q->free_req_head = -1;
@@ -534,9 +533,9 @@ static bool nvme_identify(BlockDriverState *bs, int namespace, Error **errp)
534533
error_setg(errp, "Cannot allocate buffer for identify response");
535534
goto out;
536535
}
537-
r = qemu_vfio_dma_map(s->vfio, id, id_size, true, &iova);
536+
r = qemu_vfio_dma_map(s->vfio, id, id_size, true, &iova, errp);
538537
if (r) {
539-
error_setg(errp, "Cannot map buffer for DMA");
538+
error_prepend(errp, "Cannot map buffer for DMA: ");
540539
goto out;
541540
}
542541

@@ -1032,7 +1031,7 @@ static coroutine_fn int nvme_cmd_map_qiov(BlockDriverState *bs, NvmeCmd *cmd,
10321031
try_map:
10331032
r = qemu_vfio_dma_map(s->vfio,
10341033
qiov->iov[i].iov_base,
1035-
len, true, &iova);
1034+
len, true, &iova, NULL);
10361035
if (r == -ENOSPC) {
10371036
/*
10381037
* In addition to the -ENOMEM error, the VFIO_IOMMU_MAP_DMA
@@ -1524,14 +1523,15 @@ static void nvme_aio_unplug(BlockDriverState *bs)
15241523
static void nvme_register_buf(BlockDriverState *bs, void *host, size_t size)
15251524
{
15261525
int ret;
1526+
Error *local_err = NULL;
15271527
BDRVNVMeState *s = bs->opaque;
15281528

1529-
ret = qemu_vfio_dma_map(s->vfio, host, size, false, NULL);
1529+
ret = qemu_vfio_dma_map(s->vfio, host, size, false, NULL, &local_err);
15301530
if (ret) {
15311531
/* FIXME: we may run out of IOVA addresses after repeated
15321532
* bdrv_register_buf/bdrv_unregister_buf, because nvme_vfio_dma_unmap
15331533
* doesn't reclaim addresses for fixed mappings. */
1534-
error_report("nvme_register_buf failed: %s", strerror(-ret));
1534+
error_reportf_err(local_err, "nvme_register_buf failed: ");
15351535
}
15361536
}
15371537

include/qemu/vfio-helpers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ typedef struct QEMUVFIOState QEMUVFIOState;
1818
QEMUVFIOState *qemu_vfio_open_pci(const char *device, Error **errp);
1919
void qemu_vfio_close(QEMUVFIOState *s);
2020
int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
21-
bool temporary, uint64_t *iova_list);
21+
bool temporary, uint64_t *iova_list, Error **errp);
2222
int qemu_vfio_dma_reset_temporary(QEMUVFIOState *s);
2323
void qemu_vfio_dma_unmap(QEMUVFIOState *s, void *host);
2424
void *qemu_vfio_pci_map_bar(QEMUVFIOState *s, int index,

util/vfio-helpers.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -463,13 +463,15 @@ static void qemu_vfio_ram_block_added(RAMBlockNotifier *n, void *host,
463463
size_t size, size_t max_size)
464464
{
465465
QEMUVFIOState *s = container_of(n, QEMUVFIOState, ram_notifier);
466+
Error *local_err = NULL;
466467
int ret;
467468

468469
trace_qemu_vfio_ram_block_added(s, host, max_size);
469-
ret = qemu_vfio_dma_map(s, host, max_size, false, NULL);
470+
ret = qemu_vfio_dma_map(s, host, max_size, false, NULL, &local_err);
470471
if (ret) {
471-
error_report("qemu_vfio_dma_map(%p, %zu) failed: %s", host, max_size,
472-
strerror(-ret));
472+
error_reportf_err(local_err,
473+
"qemu_vfio_dma_map(%p, %zu) failed: ",
474+
host, max_size);
473475
}
474476
}
475477

@@ -725,7 +727,7 @@ qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size, uint64_t *iova)
725727
* mapping status within this area is not allowed).
726728
*/
727729
int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
728-
bool temporary, uint64_t *iova)
730+
bool temporary, uint64_t *iova, Error **errp)
729731
{
730732
int ret = 0;
731733
int index;

0 commit comments

Comments
 (0)