diff mbox

[v6,7/7] exec: add parameter errp to gethugepagesize

Message ID 4a41f09b7f23f26dcb895711bc608b0197978578.1407402040.git.hutao@cn.fujitsu.com
State New
Headers show

Commit Message

Hu Tao Aug. 7, 2014, 9:10 a.m. UTC
Add parameter errp to gethugepagesize thus callers can handle errors.

This patch fixes a problem that 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

Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
---
 exec.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Peter Crosthwaite Aug. 7, 2014, 11:47 a.m. UTC | #1
On Thu, Aug 7, 2014 at 7:10 PM, Hu Tao <hutao@cn.fujitsu.com> wrote:
> Add parameter errp to gethugepagesize thus callers can handle errors.
>
> This patch fixes a problem that 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:

Same long sentence issue here,

>
>   /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
>
> Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>

Otherwise:

Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

> ---
>  exec.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
>
> diff --git a/exec.c b/exec.c
> index 50cd510..fdef0f7 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,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;
>      }
>
> @@ -1027,9 +1028,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.9.3
>
>
Gonglei (Arei) Aug. 7, 2014, noon UTC | #2
> -----Original Message-----

> From: qemu-devel-bounces+arei.gonglei=huawei.com@nongnu.org

> [mailto:qemu-devel-bounces+arei.gonglei=huawei.com@nongnu.org] On

> Behalf Of Peter Crosthwaite

> Sent: Thursday, August 07, 2014 7:47 PM

> To: Hu Tao

> Cc: Yasunori Goto; Paolo Bonzini; Yasuaki Isimatu; qemu-devel@nongnu.org

> Developers; Michael S. Tsirkin

> Subject: Re: [Qemu-devel] [PATCH v6 7/7] exec: add parameter errp to

> gethugepagesize

> 

> On Thu, Aug 7, 2014 at 7:10 PM, Hu Tao <hutao@cn.fujitsu.com> wrote:

> > Add parameter errp to gethugepagesize thus callers can handle errors.

> >

> > This patch fixes a problem that 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:

> 

> Same long sentence issue here,

> 

> >

> >   /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

> >

> > Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>

> 

> Otherwise:

> 

> Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>

> 

> > ---

> >  exec.c | 11 +++++++----

> >  1 file changed, 7 insertions(+), 4 deletions(-)

> >

> > diff --git a/exec.c b/exec.c

> > index 50cd510..fdef0f7 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)


I'm not following this series, but the function name is not idiomatic QEMU 
coding style IMHO.

Best regards,
-Gonglei
Hu Tao Aug. 15, 2014, 9:55 a.m. UTC | #3
On Thu, Aug 07, 2014 at 12:00:47PM +0000, Gonglei (Arei) wrote:
> > -----Original Message-----
> > From: qemu-devel-bounces+arei.gonglei=huawei.com@nongnu.org
> > [mailto:qemu-devel-bounces+arei.gonglei=huawei.com@nongnu.org] On
> > Behalf Of Peter Crosthwaite
> > Sent: Thursday, August 07, 2014 7:47 PM
> > To: Hu Tao
> > Cc: Yasunori Goto; Paolo Bonzini; Yasuaki Isimatu; qemu-devel@nongnu.org
> > Developers; Michael S. Tsirkin
> > Subject: Re: [Qemu-devel] [PATCH v6 7/7] exec: add parameter errp to
> > gethugepagesize
> > 
> > On Thu, Aug 7, 2014 at 7:10 PM, Hu Tao <hutao@cn.fujitsu.com> wrote:
> > > Add parameter errp to gethugepagesize thus callers can handle errors.
> > >
> > > This patch fixes a problem that 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:
> > 
> > Same long sentence issue here,
> > 
> > >
> > >   /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
> > >
> > > Signed-off-by: Hu Tao <hutao@cn.fujitsu.com>
> > 
> > Otherwise:
> > 
> > Reviewed-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com>
> > 
> > > ---
> > >  exec.c | 11 +++++++----
> > >  1 file changed, 7 insertions(+), 4 deletions(-)
> > >
> > > diff --git a/exec.c b/exec.c
> > > index 50cd510..fdef0f7 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)
> 
> I'm not following this series, but the function name is not idiomatic QEMU 
> coding style IMHO.

This can be another patch.

Regards,
Hu
diff mbox

Patch

diff --git a/exec.c b/exec.c
index 50cd510..fdef0f7 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,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;
     }
 
@@ -1027,9 +1028,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;
     }