===================================================================
@@ -985,6 +985,9 @@ static void *file_ram_alloc(RAMBlock *bl
if (area == MAP_FAILED) {
perror("file_ram_alloc: can't mmap RAM pages");
close(fd);
+ if (mem_path_force) {
+ exit(1);
+ }
return (NULL);
}
===================================================================
@@ -189,6 +189,7 @@ const char* keyboard_layout = NULL;
ram_addr_t ram_size;
const char *mem_path = NULL;
int mem_prealloc = 0; /* force preallocation of physical target memory */
+int mem_path_force = 0; /* quit in case -mem-path allocation fails */
int nb_nics;
NICInfo nd_table[MAX_NICS];
int autostart;
@@ -3203,6 +3204,9 @@ int main(int argc, char **argv, char **e
case QEMU_OPTION_mempath:
mem_path = optarg;
break;
+ case QEMU_OPTION_mempath_force:
+ mem_path_force = 1;
+ break;
case QEMU_OPTION_mem_prealloc:
mem_prealloc = 1;
break;
===================================================================
@@ -468,6 +468,7 @@ typedef struct RAMList {
extern RAMList ram_list;
extern const char *mem_path;
+extern int mem_path_force;
extern int mem_prealloc;
/* Flags stored in the low bits of the TLB virtual address. These are
===================================================================
@@ -66,6 +66,9 @@ stringify(DEFAULT_RAM_SIZE) "]\n", QEMU_
DEF("mem-path", HAS_ARG, QEMU_OPTION_mempath,
"-mem-path FILE provide backing storage for guest RAM\n", QEMU_ARCH_ALL)
+DEF("mem-path-force", 0, QEMU_OPTION_mempath_force,
+"-mem-path-force fail if unable to allocate RAM as specified by -mem-path\n", QEMU_ARCH_ALL)
+
DEF("mem-prealloc", 0, QEMU_OPTION_mem_prealloc,
"-mem-prealloc preallocate guest memory (use with -mem-path)\n",
QEMU_ARCH_ALL)
===================================================================
@@ -228,6 +228,14 @@ STEXI
Allocate guest RAM from a temporarily created file in @var{path}.
ETEXI
+DEF("mem-path-force", 0, QEMU_OPTION_mempath_force,
+ "-mem-path-force fail if unable to allocate RAM as specified by -mem-path\n", QEMU_ARCH_ALL)
+STEXI
+@item -mem-path-force
+@findex -mem-path-force
+Fail if unable to allocate RAM as specified by -mem-path.
+ETEXI
+
DEF("mem-prealloc", 0, QEMU_OPTION_mem_prealloc,
"-mem-prealloc preallocate guest memory (use with -mem-path)\n",
QEMU_ARCH_ALL)
Default behaviour is to fallback for standard RAM allocation if -mem-path allocation fails. Add an option to force -mem-path RAM allocation (failing otherwise). Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>