From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:37096) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSRNv-0005uW-Oa for qemu-devel@nongnu.org; Fri, 12 Sep 2014 09:59:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XSRNr-0000uv-66 for qemu-devel@nongnu.org; Fri, 12 Sep 2014 09:59:35 -0400 Received: from mail-qc0-x235.google.com ([2607:f8b0:400d:c01::235]:43418) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSRNr-0000un-2c for qemu-devel@nongnu.org; Fri, 12 Sep 2014 09:59:31 -0400 Received: by mail-qc0-f181.google.com with SMTP id r5so750330qcx.26 for ; Fri, 12 Sep 2014 06:59:30 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 12 Sep 2014 15:58:48 +0200 Message-Id: <1410530338-17615-12-git-send-email-pbonzini@redhat.com> In-Reply-To: <1410530338-17615-1-git-send-email-pbonzini@redhat.com> References: <1410530338-17615-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PULL 11/21] exec: add parameter errp to gethugepagesize List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Hu Tao From: Hu Tao Add parameter errp to gethugepagesize thus callers can handle errors. 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) This patch fixes the problem. With this patch, qemu reports an error message like: qemu-system-x86_64: -object memory-backend-file,mem-path=/nonexistingdir,id=mem-file0,size=128M: failed to get page size of file /nonexistingdir: No such file or directory Signed-off-by: Hu Tao Reviewed-by: Peter Crosthwaite Signed-off-by: Paolo Bonzini --- exec.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/exec.c b/exec.c index 1100208..dd1e576 100644 --- a/exec.c +++ b/exec.c @@ -1031,7 +1031,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; @@ -1041,7 +1041,8 @@ static long gethugepagesize(const char *path) } while (ret != 0 && errno == EINTR); if (ret != 0) { - perror(path); + error_setg_errno(errp, errno, "failed to get page size of file %s", + path); return 0; } @@ -1062,9 +1063,11 @@ static void *file_ram_alloc(RAMBlock *block, void *area = NULL; int fd; uint64_t hpagesize; + Error *local_err = NULL; - hpagesize = gethugepagesize(path); - if (!hpagesize) { + hpagesize = gethugepagesize(path, &local_err); + if (local_err) { + error_propagate(errp, local_err); goto error; } -- 2.1.0