From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37026) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X40RK-0004tP-Au for qemu-devel@nongnu.org; Mon, 07 Jul 2014 00:22:10 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X40RF-0003qq-M5 for qemu-devel@nongnu.org; Mon, 07 Jul 2014 00:22:06 -0400 Received: from mx1.redhat.com ([209.132.183.28]:58945) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X40RF-0003qm-Cy for qemu-devel@nongnu.org; Mon, 07 Jul 2014 00:22:01 -0400 Date: Mon, 7 Jul 2014 06:24:02 +0300 From: "Michael S. Tsirkin" Message-ID: <20140707032402.GB4589@redhat.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Subject: Re: [Qemu-devel] [PATCH V2 for 2.1 3/3] exec: improve error handling and reporting in file_ram_alloc() and gethugepagesize() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Hu Tao Cc: Yasunori Goto , Paolo Bonzini , qemu-devel@nongnu.org, Igor Mammedov On Mon, Jul 07, 2014 at 10:58:08AM +0800, Hu Tao wrote: > This patch fixes two problems of memory-backend-file: > > 1. If user adds a memory-backend-file object using object_add command, > specifying a non-existing directory for property mem-path, qemu > will core dump with message: > > /nonexistingdir: No such file or directory > Bad ram offset fffffffffffff000 > Aborted (core dumped) > > with this patch, qemu reports error message like: > > qemu-system-x86_64: -object memory-backend-file,mem-path=/nonexistingdir,id=mem-file0,size=128M: > failed to stat file /nonexistingdir: No such file or directory > > 2. If user adds a memory-backend-file object using object_add command, > specifying a size that is less than huge page size, qemu > will core dump with message: > > Bad ram offset fffffffffffff000 > Aborted (core dumped) > > with this patch, qemu reports error message like: > > qemu-system-x86_64: -object memory-backend-file,mem-path=/hugepages,id=mem-file0,size=1M: memory > size 0x100000 should be euqal or larger than huge page size 0x200000 > > Signed-off-by: Hu Tao Fixed up some messages below. > --- > exec.c | 19 +++++++++++-------- > 1 file changed, 11 insertions(+), 8 deletions(-) > > diff --git a/exec.c b/exec.c > index ca7741b..9ecd9cf 100644 > --- a/exec.c > +++ b/exec.c > @@ -996,7 +996,7 @@ void qemu_mutex_unlock_ramlist(void) > > #define HUGETLBFS_MAGIC 0x958458f6 > > -static long gethugepagesize(const char *path) > +static long gethugepagesize(const char *path, Error **errp) > { > struct statfs fs; > int ret; > @@ -1006,7 +1006,7 @@ static long gethugepagesize(const char *path) > } while (ret != 0 && errno == EINTR); > > if (ret != 0) { > - perror(path); > + error_setg_errno(errp, errno, "failed to stat file %s", path); > return 0; > } > s/to stat/to get size/ stat is an implementation detail. > @@ -1024,17 +1024,20 @@ static void *file_ram_alloc(RAMBlock *block, > char *filename; > char *sanitized_name; > char *c; > - void *area; > + void *area = NULL; > int fd; > unsigned long hpagesize; > > - hpagesize = gethugepagesize(path); > - if (!hpagesize) { > + hpagesize = gethugepagesize(path, errp); > + if (errp && *errp) { > goto error; > } > > if (memory < hpagesize) { > - return NULL; > + error_setg(errp, "memory size 0x" RAM_ADDR_FMT " should be euqal " s/should be euqal/must be equal to/ > + "or larger than huge page size 0x%" PRIx64, > + memory, hpagesize); > + goto error; > } > > if (kvm_enabled() && !kvm_has_sync_mmu()) { > @@ -1094,8 +1097,8 @@ static void *file_ram_alloc(RAMBlock *block, > return area; > > error: > - if (mem_prealloc) { > - exit(1); > + if (area && area != MAP_FAILED) { > + munmap(area, memory); > } > return NULL; > } > -- > 1.9.3