[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 2/4] backends/hostmem: move memory region preallocation logic int
From: |
Daniil Tatianin |
Subject: |
[PATCH 2/4] backends/hostmem: move memory region preallocation logic into a helper |
Date: |
Fri, 20 Jan 2023 16:47:47 +0300 |
...so that we don't have to duplicate it in multiple places throughout
the file.
Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
---
backends/hostmem.c | 38 ++++++++++++++++++++------------------
1 file changed, 20 insertions(+), 18 deletions(-)
diff --git a/backends/hostmem.c b/backends/hostmem.c
index 747e7838c0..842bfa9eb7 100644
--- a/backends/hostmem.c
+++ b/backends/hostmem.c
@@ -216,10 +216,26 @@ static bool host_memory_backend_get_prealloc(Object *obj,
Error **errp)
return backend->prealloc;
}
+static bool do_prealloc_mr(HostMemoryBackend *backend, Error **errp)
+{
+ Error *local_err = NULL;
+ int fd = memory_region_get_fd(&backend->mr);
+ void *ptr = memory_region_get_ram_ptr(&backend->mr);
+ uint64_t sz = memory_region_size(&backend->mr);
+
+ qemu_prealloc_mem(fd, ptr, sz, backend->prealloc_threads,
+ backend->prealloc_context, &local_err);
+ if (local_err) {
+ error_propagate(errp, local_err);
+ return false;
+ }
+
+ return true;
+}
+
static void host_memory_backend_set_prealloc(Object *obj, bool value,
Error **errp)
{
- Error *local_err = NULL;
HostMemoryBackend *backend = MEMORY_BACKEND(obj);
if (!backend->reserve && value) {
@@ -233,17 +249,7 @@ static void host_memory_backend_set_prealloc(Object *obj,
bool value,
}
if (value && !backend->prealloc) {
- int fd = memory_region_get_fd(&backend->mr);
- void *ptr = memory_region_get_ram_ptr(&backend->mr);
- uint64_t sz = memory_region_size(&backend->mr);
-
- qemu_prealloc_mem(fd, ptr, sz, backend->prealloc_threads,
- backend->prealloc_context, &local_err);
- if (local_err) {
- error_propagate(errp, local_err);
- return;
- }
- backend->prealloc = true;
+ backend->prealloc = do_prealloc_mr(backend, errp);
}
}
@@ -399,12 +405,8 @@ host_memory_backend_memory_complete(UserCreatable *uc,
Error **errp)
* specified NUMA policy in place.
*/
if (backend->prealloc) {
- qemu_prealloc_mem(memory_region_get_fd(&backend->mr), ptr, sz,
- backend->prealloc_threads,
- backend->prealloc_context, &local_err);
- if (local_err) {
- goto out;
- }
+ do_prealloc_mr(backend, errp);
+ return;
}
}
out:
--
2.25.1
- [PATCH v0 0/4] backends/hostmem: add an ability to specify prealloc timeout, Daniil Tatianin, 2023/01/20
- [PATCH 2/4] backends/hostmem: move memory region preallocation logic into a helper,
Daniil Tatianin <=
- [PATCH 4/4] backends/hostmem: add an ability to make prealloc timeout fatal, Daniil Tatianin, 2023/01/20
- [PATCH 3/4] backends/hostmem: add an ability to specify prealloc timeout, Daniil Tatianin, 2023/01/20
- [PATCH 1/4] oslib: introduce new qemu_prealloc_mem_with_timeout() api, Daniil Tatianin, 2023/01/20
- Re: [PATCH v0 0/4] backends/hostmem: add an ability to specify prealloc timeout, David Hildenbrand, 2023/01/23
- Re: [PATCH v0 0/4] backends/hostmem: add an ability to specify prealloc timeout, Daniil Tatianin, 2023/01/23
- Re: [PATCH v0 0/4] backends/hostmem: add an ability to specify prealloc timeout, Daniel P . Berrangé, 2023/01/23
- Re: [PATCH v0 0/4] backends/hostmem: add an ability to specify prealloc timeout, David Hildenbrand, 2023/01/23
- Re: [PATCH v0 0/4] backends/hostmem: add an ability to specify prealloc timeout, Daniil Tatianin, 2023/01/23
- Re: [PATCH v0 0/4] backends/hostmem: add an ability to specify prealloc timeout, David Hildenbrand, 2023/01/23
- Re: [PATCH v0 0/4] backends/hostmem: add an ability to specify prealloc timeout, Daniel P . Berrangé, 2023/01/23