Skip to content

Commit 71e3038

Browse files
philmdstefanhaRH
authored andcommitted
util/vfio-helpers: Extract qemu_vfio_water_mark_reached()
Extract qemu_vfio_water_mark_reached() for readability, and have it provide an error hint it its Error* handle. Suggested-by: Klaus Jensen <[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 521b97c commit 71e3038

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

util/vfio-helpers.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,21 @@ qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size, uint64_t *iova)
721721
return -ENOMEM;
722722
}
723723

724+
/**
725+
* qemu_vfio_water_mark_reached:
726+
*
727+
* Returns %true if high watermark has been reached, %false otherwise.
728+
*/
729+
static bool qemu_vfio_water_mark_reached(QEMUVFIOState *s, size_t size,
730+
Error **errp)
731+
{
732+
if (s->high_water_mark - s->low_water_mark + 1 < size) {
733+
error_setg(errp, "iova exhausted (water mark reached)");
734+
return true;
735+
}
736+
return false;
737+
}
738+
724739
/* Map [host, host + size) area into a contiguous IOVA address space, and store
725740
* the result in @iova if not NULL. The caller need to make sure the area is
726741
* 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,
742757
if (mapping) {
743758
iova0 = mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->host);
744759
} else {
745-
if (s->high_water_mark - s->low_water_mark + 1 < size) {
760+
if (qemu_vfio_water_mark_reached(s, size, errp)) {
746761
ret = -ENOMEM;
747762
goto out;
748763
}

0 commit comments

Comments
 (0)