All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org, Peter Maydell <peter.maydell@linaro.org>
Cc: "Kevin Wolf" <kwolf@redhat.com>, "Fam Zheng" <fam@euphon.net>,
	qemu-block@nongnu.org, "Klaus Jensen" <k.jensen@samsung.com>,
	"Hanna Reitz" <hreitz@redhat.com>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [PULL 07/11] util/vfio-helpers: Extract qemu_vfio_water_mark_reached()
Date: Tue,  7 Sep 2021 09:13:59 +0100	[thread overview]
Message-ID: <20210907081403.816404-8-stefanha@redhat.com> (raw)
In-Reply-To: <20210907081403.816404-1-stefanha@redhat.com>

From: Philippe Mathieu-Daudé <philmd@redhat.com>

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>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20210902070025.197072-8-philmd@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@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 77cdec845d..306b5a83e4 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



  parent reply	other threads:[~2021-09-07  8:25 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-07  8:13 [PULL 00/11] Block patches Stefan Hajnoczi
2021-09-07  8:13 ` [PULL 01/11] block/nvme: Use safer trace format string Stefan Hajnoczi
2021-09-07  8:13 ` [PULL 02/11] util/vfio-helpers: Let qemu_vfio_verify_mappings() use error_report() Stefan Hajnoczi
2021-09-07  8:13 ` [PULL 03/11] util/vfio-helpers: Replace qemu_mutex_lock() calls with QEMU_LOCK_GUARD Stefan Hajnoczi
2021-09-07  8:13 ` [PULL 04/11] util/vfio-helpers: Remove unreachable code in qemu_vfio_dma_map() Stefan Hajnoczi
2021-09-07  8:13 ` [PULL 05/11] block/nvme: Have nvme_create_queue_pair() report errors consistently Stefan Hajnoczi
2021-09-07  8:13 ` [PULL 06/11] util/vfio-helpers: Pass Error handle to qemu_vfio_dma_map() Stefan Hajnoczi
2021-09-07  8:13 ` Stefan Hajnoczi [this message]
2021-09-07  8:14 ` [PULL 08/11] util/vfio-helpers: Use error_setg in qemu_vfio_find_[fixed/temp]_iova Stefan Hajnoczi
2021-09-07  8:14 ` [PULL 09/11] util/vfio-helpers: Simplify qemu_vfio_dma_map() returning directly Stefan Hajnoczi
2021-09-07  8:14 ` [PULL 10/11] util/vfio-helpers: Let qemu_vfio_do_mapping() propagate Error Stefan Hajnoczi
2021-09-07  8:14 ` [PULL 11/11] block/nvme: Only report VFIO error on failed retry Stefan Hajnoczi
2021-09-07 15:08 ` [PULL 00/11] Block patches Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210907081403.816404-8-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=fam@euphon.net \
    --cc=hreitz@redhat.com \
    --cc=k.jensen@samsung.com \
    --cc=kwolf@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.