file_ram_alloc: unify mem-path,mem-prealloc error handling
-mem-prealloc asks to preallocate memory residing on -mem-path path. Currently QEMU exits in case: - Memory file has been created but allocation via explicit write fails. And it fallbacks to malloc in case: - Querying huge page size fails. - Lack of sync MMU support. - Open fails. - mmap fails. Have the same behaviour for all cases: fail in case -mem-path and -mem-prealloc are specified for regions where the requested size is suitable for hugepages. Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
parent
9ba3cf540f
commit
f9a49dfa02
14
exec.c
14
exec.c
|
@ -1031,7 +1031,7 @@ static void *file_ram_alloc(RAMBlock *block,
|
||||||
|
|
||||||
hpagesize = gethugepagesize(path);
|
hpagesize = gethugepagesize(path);
|
||||||
if (!hpagesize) {
|
if (!hpagesize) {
|
||||||
return NULL;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memory < hpagesize) {
|
if (memory < hpagesize) {
|
||||||
|
@ -1040,7 +1040,7 @@ static void *file_ram_alloc(RAMBlock *block,
|
||||||
|
|
||||||
if (kvm_enabled() && !kvm_has_sync_mmu()) {
|
if (kvm_enabled() && !kvm_has_sync_mmu()) {
|
||||||
fprintf(stderr, "host lacks kvm mmu notifiers, -mem-path unsupported\n");
|
fprintf(stderr, "host lacks kvm mmu notifiers, -mem-path unsupported\n");
|
||||||
return NULL;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Make name safe to use with mkstemp by replacing '/' with '_'. */
|
/* Make name safe to use with mkstemp by replacing '/' with '_'. */
|
||||||
|
@ -1058,7 +1058,7 @@ static void *file_ram_alloc(RAMBlock *block,
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
perror("unable to create backing store for hugepages");
|
perror("unable to create backing store for hugepages");
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
return NULL;
|
goto error;
|
||||||
}
|
}
|
||||||
unlink(filename);
|
unlink(filename);
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
|
@ -1078,7 +1078,7 @@ static void *file_ram_alloc(RAMBlock *block,
|
||||||
if (area == MAP_FAILED) {
|
if (area == MAP_FAILED) {
|
||||||
perror("file_ram_alloc: can't mmap RAM pages");
|
perror("file_ram_alloc: can't mmap RAM pages");
|
||||||
close(fd);
|
close(fd);
|
||||||
return (NULL);
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mem_prealloc) {
|
if (mem_prealloc) {
|
||||||
|
@ -1122,6 +1122,12 @@ static void *file_ram_alloc(RAMBlock *block,
|
||||||
|
|
||||||
block->fd = fd;
|
block->fd = fd;
|
||||||
return area;
|
return area;
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (mem_prealloc) {
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static void *file_ram_alloc(RAMBlock *block,
|
static void *file_ram_alloc(RAMBlock *block,
|
||||||
|
|
Loading…
Reference in New Issue