diff mbox

[RFC,4/4] memory-backend-file: error out if failed to allocate memory

Message ID 5a1cdce658586b46e49ce906d56aeff502bc24bd.1402720673.git.hutao@cn.fujitsu.com
State New
Headers show

Commit Message

Hu Tao June 14, 2014, 4:48 a.m. UTC
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 this problem.

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 backends/hostmem-file.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Paolo Bonzini June 14, 2014, 5:09 p.m. UTC | #1
Il 14/06/2014 06:48, Hu Tao ha scritto:
> 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 this problem.
>
> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> ---
>  backends/hostmem-file.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
> index 5179994..70172d1 100644
> --- a/backends/hostmem-file.c
> +++ b/backends/hostmem-file.c
> @@ -55,6 +55,9 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
>                                   object_get_canonical_path(OBJECT(backend)),
>                                   backend->size, fb->share,
>                                   fb->mem_path, errp);
> +        if (backend->mr.ram_addr == -1) {
> +            error_setg(errp, "failed to allocate memory");
> +        }

qemu_ram_alloc_from_file is where this error_setg should be added instead.

Paolo

>      }
>  #endif
>  }
>
Hu Tao June 16, 2014, 6:30 a.m. UTC | #2
On Sat, Jun 14, 2014 at 07:09:37PM +0200, Paolo Bonzini wrote:
> Il 14/06/2014 06:48, Hu Tao ha scritto:
> >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 this problem.
> >
> >Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> >---
> > backends/hostmem-file.c | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> >diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
> >index 5179994..70172d1 100644
> >--- a/backends/hostmem-file.c
> >+++ b/backends/hostmem-file.c
> >@@ -55,6 +55,9 @@ file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
> >                                  object_get_canonical_path(OBJECT(backend)),
> >                                  backend->size, fb->share,
> >                                  fb->mem_path, errp);
> >+        if (backend->mr.ram_addr == -1) {
> >+            error_setg(errp, "failed to allocate memory");
> >+        }
> 
> qemu_ram_alloc_from_file is where this error_setg should be added instead.

Thanks, patch updated.

> 
> Paolo
> 
> >     }
> > #endif
> > }
> >
diff mbox

Patch

diff --git a/backends/hostmem-file.c b/backends/hostmem-file.c
index 5179994..70172d1 100644
--- a/backends/hostmem-file.c
+++ b/backends/hostmem-file.c
@@ -55,6 +55,9 @@  file_backend_memory_alloc(HostMemoryBackend *backend, Error **errp)
                                  object_get_canonical_path(OBJECT(backend)),
                                  backend->size, fb->share,
                                  fb->mem_path, errp);
+        if (backend->mr.ram_addr == -1) {
+            error_setg(errp, "failed to allocate memory");
+        }
     }
 #endif
 }