qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4 3/4] qemu-io: add -r option to register I/O buffer


From: Hanna Czenczek
Subject: Re: [PATCH v4 3/4] qemu-io: add -r option to register I/O buffer
Date: Wed, 8 Feb 2023 10:08:27 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1

On 07.02.23 21:37, Stefan Hajnoczi wrote:
The blk_register_buf() API is an optimization hint that allows some
block drivers to avoid I/O buffer housekeeping or bounce buffers.

Add an -r option to register the I/O buffer so that qemu-io can be used
to test the blk_register_buf() API. The next commit will add a test that
uses the new option.

Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
  qemu-io-cmds.c | 204 +++++++++++++++++++++++++++++++------------------
  1 file changed, 129 insertions(+), 75 deletions(-)

Reviewed-by: Hanna Czenczek <hreitz@redhat.com>

diff --git a/qemu-io-cmds.c b/qemu-io-cmds.c
index 1f60c23ba4..e7a02f5b99 100644
--- a/qemu-io-cmds.c
+++ b/qemu-io-cmds.c
@@ -414,24 +419,23 @@ static void *qemu_io_alloc_from_file(BlockBackend *blk, 
size_t len,
      fclose(f);
      f = NULL;
- if (len > pattern_len) {
-        len -= pattern_len;
-        buf += pattern_len;
-
-        while (len > 0) {
-            size_t len_to_copy = MIN(pattern_len, len);
-
-            memcpy(buf, buf_origin, len_to_copy);
+    if (register_buf) {
+        blk_register_buf(blk, alloc_buf, alloc_len, &error_abort);
+    }
- len -= len_to_copy;
-            buf += len_to_copy;
-        }
+    end = buf + len;
+    for (char *p = buf + pattern_len; p < end; p += pattern_len) {
+        memcpy(p, buf, MIN(pattern_len, end - p));
      }

Cool rewrite of this loop!




reply via email to

[Prev in Thread] Current Thread [Next in Thread]