From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49728) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNKGv-0002rp-2V for qemu-devel@nongnu.org; Tue, 11 Mar 2014 06:51:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WNKGn-0003pn-1a for qemu-devel@nongnu.org; Tue, 11 Mar 2014 06:50:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:44865) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNKGm-0003pe-Oc for qemu-devel@nongnu.org; Tue, 11 Mar 2014 06:50:48 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s2BAolqf021856 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 11 Mar 2014 06:50:48 -0400 From: Paolo Bonzini Date: Tue, 11 Mar 2014 11:50:37 +0100 Message-Id: <1394535038-32454-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1394535038-32454-1-git-send-email-pbonzini@redhat.com> References: <1394535038-32454-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 2/3] file_ram_alloc: unify mem-path, mem-prealloc error handling List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Marcelo Tosatti From: Marcelo Tosatti -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 Signed-off-by: Paolo Bonzini --- exec.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/exec.c b/exec.c index b69fd29..f47b2b1 100644 --- a/exec.c +++ b/exec.c @@ -1031,7 +1031,7 @@ static void *file_ram_alloc(RAMBlock *block, hpagesize = gethugepagesize(path); if (!hpagesize) { - return NULL; + goto error; } if (memory < hpagesize) { @@ -1040,7 +1040,7 @@ static void *file_ram_alloc(RAMBlock *block, if (kvm_enabled() && !kvm_has_sync_mmu()) { 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 '_'. */ @@ -1058,7 +1058,7 @@ static void *file_ram_alloc(RAMBlock *block, if (fd < 0) { perror("unable to create backing store for hugepages"); g_free(filename); - return NULL; + goto error; } unlink(filename); g_free(filename); @@ -1078,7 +1078,7 @@ static void *file_ram_alloc(RAMBlock *block, if (area == MAP_FAILED) { perror("file_ram_alloc: can't mmap RAM pages"); close(fd); - return (NULL); + goto error; } if (mem_prealloc) { @@ -1122,6 +1122,12 @@ static void *file_ram_alloc(RAMBlock *block, block->fd = fd; return area; + +error: + if (mem_prealloc) { + exit(1); + } + return NULL; } #else static void *file_ram_alloc(RAMBlock *block, -- 1.8.3.1