From 11c61a3b8988191d4b81b4aaf22f212ea97aba48 Mon Sep 17 00:00:00 2001 From: Luiz Capitulino Date: Tue, 4 Nov 2014 21:21:56 +0100 Subject: [PATCH 3/5] exec: add parameter errp to gethugepagesize Message-id: <1415136116-9003-3-git-send-email-lcapitulino@redhat.com> Patchwork-id: 62104 O-Subject: [RHEL7.1 qemu-kvm-rhev PATCH 2/2] exec: add parameter errp to gethugepagesize Bugzilla: 1147354 RH-Acked-by: Markus Armbruster RH-Acked-by: Laszlo Ersek RH-Acked-by: Andrew Jones 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 (cherry picked from commit fc7a5800ad13fa14529b38d2255fa87f11db626b) Signed-off-by: Luiz Capitulino Signed-off-by: Miroslav Rezanina --- exec.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/exec.c b/exec.c index ef7622b..9a3d041 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; } -- 1.8.3.1