[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 07/11] util/vfio-helpers: Extract qemu_vfio_water_mark_reached
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v2 07/11] util/vfio-helpers: Extract qemu_vfio_water_mark_reached() |
Date: |
Thu, 26 Aug 2021 21:50:10 +0200 |
Extract qemu_vfio_water_mark_reached() for readability,
and have it provide an error hint it its Error* handle.
Suggested-by: Klaus Jensen <k.jensen@samsung.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
util/vfio-helpers.c | 17 ++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
index 77cdec845d9..306b5a83e48 100644
--- a/util/vfio-helpers.c
+++ b/util/vfio-helpers.c
@@ -721,6 +721,21 @@ qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size,
uint64_t *iova)
return -ENOMEM;
}
+/**
+ * qemu_vfio_water_mark_reached:
+ *
+ * Returns %true if high watermark has been reached, %false otherwise.
+ */
+static bool qemu_vfio_water_mark_reached(QEMUVFIOState *s, size_t size,
+ Error **errp)
+{
+ if (s->high_water_mark - s->low_water_mark + 1 < size) {
+ error_setg(errp, "iova exhausted (water mark reached)");
+ return true;
+ }
+ return false;
+}
+
/* Map [host, host + size) area into a contiguous IOVA address space, and store
* the result in @iova if not NULL. The caller need to make sure the area is
* aligned to page size, and mustn't overlap with existing mapping areas (split
@@ -742,7 +757,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t
size,
if (mapping) {
iova0 = mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->host);
} else {
- if (s->high_water_mark - s->low_water_mark + 1 < size) {
+ if (qemu_vfio_water_mark_reached(s, size, errp)) {
ret = -ENOMEM;
goto out;
}
--
2.31.1
- [PATCH v2 02/11] util/vfio-helpers: Let qemu_vfio_verify_mappings() use error_report(), (continued)
- [PATCH v2 02/11] util/vfio-helpers: Let qemu_vfio_verify_mappings() use error_report(), Philippe Mathieu-Daudé, 2021/08/26
- [PATCH v2 03/11] util/vfio-helpers: Replace qemu_mutex_lock() calls with QEMU_LOCK_GUARD, Philippe Mathieu-Daudé, 2021/08/26
- [PATCH v2 04/11] util/vfio-helpers: Remove unreachable code in qemu_vfio_dma_map(), Philippe Mathieu-Daudé, 2021/08/26
- [PATCH v2 05/11] block/nvme: Have nvme_create_queue_pair() report errors consistently, Philippe Mathieu-Daudé, 2021/08/26
- [PATCH v2 06/11] util/vfio-helpers: Pass Error handle to qemu_vfio_dma_map(), Philippe Mathieu-Daudé, 2021/08/26
- [PATCH v2 07/11] util/vfio-helpers: Extract qemu_vfio_water_mark_reached(),
Philippe Mathieu-Daudé <=
- [PATCH v2 08/11] util/vfio-helpers: Use error_setg in qemu_vfio_find_[fixed/temp]_iova, Philippe Mathieu-Daudé, 2021/08/26
- [PATCH v2 09/11] util/vfio-helpers: Simplify qemu_vfio_dma_map() returning directly, Philippe Mathieu-Daudé, 2021/08/26
- [PATCH v2 10/11] util/vfio-helpers: Let qemu_vfio_do_mapping() propagate Error, Philippe Mathieu-Daudé, 2021/08/26
- [PATCH v2 11/11] block/nvme: Only report VFIO error on failed retry, Philippe Mathieu-Daudé, 2021/08/26