From patchwork Tue Oct 8 00:41:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marcelo Tosatti X-Patchwork-Id: 281295 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E78812C00A2 for ; Tue, 8 Oct 2013 11:48:45 +1100 (EST) Received: from localhost ([::1]:34102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTLTQ-0004iN-4m for incoming@patchwork.ozlabs.org; Mon, 07 Oct 2013 20:48:28 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52293) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTLSz-0004i5-No for qemu-devel@nongnu.org; Mon, 07 Oct 2013 20:48:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VTLSt-0005EP-KV for qemu-devel@nongnu.org; Mon, 07 Oct 2013 20:48:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:59988) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VTLSt-0005E8-Cj for qemu-devel@nongnu.org; Mon, 07 Oct 2013 20:47:55 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r980lseJ031613 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 7 Oct 2013 20:47:54 -0400 Received: from amt.cnet (vpn1-5-50.gru2.redhat.com [10.97.5.50]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r980lr2u012044; Mon, 7 Oct 2013 20:47:53 -0400 Received: from amt.cnet (localhost [127.0.0.1]) by amt.cnet (Postfix) with ESMTP id C3CEF10440C; Mon, 7 Oct 2013 21:43:29 -0300 (BRT) Received: (from marcelo@localhost) by amt.cnet (8.14.6/8.14.6/Submit) id r980hTvx005759; Mon, 7 Oct 2013 21:43:29 -0300 Message-Id: <20131008004224.581631545@amt.cnet> User-Agent: quilt/0.60-1 Date: Mon, 07 Oct 2013 21:41:28 -0300 From: Marcelo Tosatti To: qemu-devel@nongnu.org References: <20131008004126.773017235@amt.cnet> Content-Disposition: inline; filename=add-option-to-force-mem-path X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Marcelo Tosatti Subject: [Qemu-devel] [patch 2/2] qemu: add -mem-path-force option to force RAM allocation via -mem-path X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Index: qemu/exec.c =================================================================== --- qemu.orig/exec.c +++ qemu/exec.c @@ -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); } Index: qemu/vl.c =================================================================== --- qemu.orig/vl.c +++ qemu/vl.c @@ -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; Index: qemu/include/exec/cpu-all.h =================================================================== --- qemu.orig/include/exec/cpu-all.h +++ qemu/include/exec/cpu-all.h @@ -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 Index: qemu/qemu-options.def =================================================================== --- qemu.orig/qemu-options.def +++ qemu/qemu-options.def @@ -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) Index: qemu/qemu-options.hx =================================================================== --- qemu.orig/qemu-options.hx +++ qemu/qemu-options.hx @@ -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)