diff options
author | Igor Mammedov <imammedo@redhat.com> | 2016-07-20 11:54:03 +0200 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2016-08-02 12:03:58 +0200 |
commit | 056b68af773b31fa98fe4538f6424c0079b61415 (patch) | |
tree | 2915a5d9bb46cde5af57ef14bc348ddedc6721ab /backends/hostmem.c | |
parent | 0b21757124d200ff86100a3bc7bb5f81521b42c4 (diff) | |
download | qemu-056b68af773b31fa98fe4538f6424c0079b61415.zip qemu-056b68af773b31fa98fe4538f6424c0079b61415.tar.gz qemu-056b68af773b31fa98fe4538f6424c0079b61415.tar.bz2 |
fix qemu exit on memory hotplug when allocation fails at prealloc time
When adding hostmem backend at runtime, QEMU might exit with error:
"os_mem_prealloc: Insufficient free host memory pages available to allocate guest RAM"
It happens due to os_mem_prealloc() not handling errors gracefully.
Fix it by passing errp argument so that os_mem_prealloc() could
report error to callers and undo performed allocation when
os_mem_prealloc() fails.
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Message-Id: <1469008443-72059-1-git-send-email-imammedo@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'backends/hostmem.c')
-rw-r--r-- | backends/hostmem.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/backends/hostmem.c b/backends/hostmem.c index ac80257..b7a208d 100644 --- a/backends/hostmem.c +++ b/backends/hostmem.c @@ -203,6 +203,7 @@ static bool host_memory_backend_get_prealloc(Object *obj, Error **errp) static void host_memory_backend_set_prealloc(Object *obj, bool value, Error **errp) { + Error *local_err = NULL; HostMemoryBackend *backend = MEMORY_BACKEND(obj); if (backend->force_prealloc) { @@ -223,7 +224,11 @@ static void host_memory_backend_set_prealloc(Object *obj, bool value, void *ptr = memory_region_get_ram_ptr(&backend->mr); uint64_t sz = memory_region_size(&backend->mr); - os_mem_prealloc(fd, ptr, sz); + os_mem_prealloc(fd, ptr, sz, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } backend->prealloc = true; } } @@ -286,8 +291,7 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp) if (bc->alloc) { bc->alloc(backend, &local_err); if (local_err) { - error_propagate(errp, local_err); - return; + goto out; } ptr = memory_region_get_ram_ptr(&backend->mr); @@ -343,9 +347,15 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp) * specified NUMA policy in place. */ if (backend->prealloc) { - os_mem_prealloc(memory_region_get_fd(&backend->mr), ptr, sz); + os_mem_prealloc(memory_region_get_fd(&backend->mr), ptr, sz, + &local_err); + if (local_err) { + goto out; + } } } +out: + error_propagate(errp, local_err); } static bool |