[RFC v3 6/8] stubs: add memory_region_from_host() and memory_region_get_fd()

Stefan Hajnoczi posted 8 patches 3 years, 7 months ago
Maintainers: Stefan Hajnoczi <stefanha@redhat.com>, Kevin Wolf <kwolf@redhat.com>, Hanna Reitz <hreitz@redhat.com>, Fam Zheng <fam@euphon.net>, John Snow <jsnow@redhat.com>, Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>, "Philippe Mathieu-Daudé" <f4bug@amsat.org>, "Michael S. Tsirkin" <mst@redhat.com>, Eduardo Habkost <eduardo@habkost.net>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Yanan Wang <wangyanan55@huawei.com>, Eric Blake <eblake@redhat.com>, Markus Armbruster <armbru@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Thomas Huth <thuth@redhat.com>, Laurent Vivier <lvivier@redhat.com>
There is a newer version of this series
[RFC v3 6/8] stubs: add memory_region_from_host() and memory_region_get_fd()
Posted by Stefan Hajnoczi 3 years, 7 months ago
The blkio block driver will need to look up the file descriptor for a
given pointer. This is possible in softmmu builds where the memory API
is available for querying guest RAM.

Add stubs so tools like qemu-img that link the block layer still build
successfully. In this case there is no guest RAM but that is fine.
Bounce buffers and their file descriptors will be allocated with
libblkio's blkio_alloc_mem_region() so we won't rely on QEMU's
memory_region_get_fd() in that case.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 stubs/memory.c    | 13 +++++++++++++
 stubs/meson.build |  1 +
 2 files changed, 14 insertions(+)
 create mode 100644 stubs/memory.c

diff --git a/stubs/memory.c b/stubs/memory.c
new file mode 100644
index 0000000000..e9ec4e384b
--- /dev/null
+++ b/stubs/memory.c
@@ -0,0 +1,13 @@
+#include "qemu/osdep.h"
+#include "exec/memory.h"
+
+MemoryRegion *memory_region_from_host(void *host, ram_addr_t *offset)
+{
+    return NULL;
+}
+
+int memory_region_get_fd(MemoryRegion *mr)
+{
+    return -1;
+}
+
diff --git a/stubs/meson.build b/stubs/meson.build
index d8f3fd5c44..fbd3dfa7b4 100644
--- a/stubs/meson.build
+++ b/stubs/meson.build
@@ -25,6 +25,7 @@ stub_ss.add(files('is-daemonized.c'))
 if libaio.found()
   stub_ss.add(files('linux-aio.c'))
 endif
+stub_ss.add(files('memory.c'))
 stub_ss.add(files('migr-blocker.c'))
 stub_ss.add(files('module-opts.c'))
 stub_ss.add(files('monitor.c'))
-- 
2.36.1
Re: [RFC v3 6/8] stubs: add memory_region_from_host() and memory_region_get_fd()
Posted by Hanna Reitz 3 years, 7 months ago
On 08.07.22 06:17, Stefan Hajnoczi wrote:
> The blkio block driver will need to look up the file descriptor for a
> given pointer. This is possible in softmmu builds where the memory API
> is available for querying guest RAM.
>
> Add stubs so tools like qemu-img that link the block layer still build
> successfully. In this case there is no guest RAM but that is fine.
> Bounce buffers and their file descriptors will be allocated with
> libblkio's blkio_alloc_mem_region() so we won't rely on QEMU's
> memory_region_get_fd() in that case.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> ---
>   stubs/memory.c    | 13 +++++++++++++
>   stubs/meson.build |  1 +
>   2 files changed, 14 insertions(+)
>   create mode 100644 stubs/memory.c

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