xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] libxl: correct libxl to obey libxl's programming paramdigm
@ 2014-07-30 16:18 Meng Xu
  2014-07-31 14:11 ` Wei Liu
       [not found] ` <53da4e8b.12a9e00a.4198.fffffe41SMTPIN_ADDED_MISSING@mx.google.com>
  0 siblings, 2 replies; 5+ messages in thread
From: Meng Xu @ 2014-07-30 16:18 UTC (permalink / raw)
  To: xen-devel
  Cc: Meng Xu, xumengpanda, ian.jackson, ian.campbell,
	stefano.stabellini

When sched_domain_get() return rc != 0, scinfo will not be disposed.
This violates the libxl programming paradigm:
272  * The user must always calls "dispose" exactly
273  * once afterwards, to clean up, regardless of whether operations
on
274  * this object succeeded or failed.

Signed-off-by: Meng Xu <mengxu@cis.upenn.edu>
---
 tools/libxl/xl_cmdimpl.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
index 01bce2f..d1efdd7 100644
--- a/tools/libxl/xl_cmdimpl.c
+++ b/tools/libxl/xl_cmdimpl.c
@@ -5014,7 +5014,7 @@ static int sched_credit_domain_output(int domid)
     }
     rc = sched_domain_get(LIBXL_SCHEDULER_CREDIT, domid, &scinfo);
     if (rc)
-        return rc;
+        goto out;
     domname = libxl_domid_to_name(ctx, domid);
     printf("%-33s %4d %6d %4d\n",
         domname,
@@ -5022,6 +5022,7 @@ static int sched_credit_domain_output(int domid)
         scinfo.weight,
         scinfo.cap);
     free(domname);
+out:
     libxl_domain_sched_params_dispose(&scinfo);
     return 0;
 }
@@ -5060,13 +5061,14 @@ static int sched_credit2_domain_output(
     }
     rc = sched_domain_get(LIBXL_SCHEDULER_CREDIT2, domid, &scinfo);
     if (rc)
-        return rc;
+        goto out;
     domname = libxl_domid_to_name(ctx, domid);
     printf("%-33s %4d %6d\n",
         domname,
         domid,
         scinfo.weight);
     free(domname);
+out:
     libxl_domain_sched_params_dispose(&scinfo);
     return 0;
 }
@@ -5085,7 +5087,7 @@ static int sched_sedf_domain_output(
     }
     rc = sched_domain_get(LIBXL_SCHEDULER_SEDF, domid, &scinfo);
     if (rc)
-        return rc;
+        goto out;
     domname = libxl_domid_to_name(ctx, domid);
     printf("%-33s %4d %6d %6d %7d %5d %6d\n",
         domname,
@@ -5096,6 +5098,7 @@ static int sched_sedf_domain_output(
         scinfo.extratime,
         scinfo.weight);
     free(domname);
+out:
     libxl_domain_sched_params_dispose(&scinfo);
     return 0;
 }
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] libxl: correct libxl to obey libxl's programming paramdigm
  2014-07-30 16:18 [PATCH] libxl: correct libxl to obey libxl's programming paramdigm Meng Xu
@ 2014-07-31 14:11 ` Wei Liu
       [not found] ` <53da4e8b.12a9e00a.4198.fffffe41SMTPIN_ADDED_MISSING@mx.google.com>
  1 sibling, 0 replies; 5+ messages in thread
From: Wei Liu @ 2014-07-31 14:11 UTC (permalink / raw)
  To: Meng Xu
  Cc: wei.liu2, ian.campbell, stefano.stabellini, ian.jackson,
	xen-devel, xumengpanda

On Wed, Jul 30, 2014 at 12:18:55PM -0400, Meng Xu wrote:
> When sched_domain_get() return rc != 0, scinfo will not be disposed.
> This violates the libxl programming paradigm:
> 272  * The user must always calls "dispose" exactly
> 273  * once afterwards, to clean up, regardless of whether operations
> on
> 274  * this object succeeded or failed.
> 

I would remove the line number because the header file changes as much
sutffs added in.

> Signed-off-by: Meng Xu <mengxu@cis.upenn.edu>
> ---
>  tools/libxl/xl_cmdimpl.c |    9 ++++++---
>  1 file changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
> index 01bce2f..d1efdd7 100644
> --- a/tools/libxl/xl_cmdimpl.c
> +++ b/tools/libxl/xl_cmdimpl.c
> @@ -5014,7 +5014,7 @@ static int sched_credit_domain_output(int domid)
>      }
>      rc = sched_domain_get(LIBXL_SCHEDULER_CREDIT, domid, &scinfo);
>      if (rc)
> -        return rc;
> +        goto out;
>      domname = libxl_domid_to_name(ctx, domid);
>      printf("%-33s %4d %6d %4d\n",
>          domname,
> @@ -5022,6 +5022,7 @@ static int sched_credit_domain_output(int domid)
>          scinfo.weight,
>          scinfo.cap);
>      free(domname);
> +out:
>      libxl_domain_sched_params_dispose(&scinfo);

And you seem to miss this part of that paradigm:

* IDL-generated libxl types should be used as follows: the user must           
* always call the "init" function before using a type, even if the             
* variable is simply being passed by reference as an out parameter             
* to a libxl function.

So calling dispose in the end while not calling init at the beginning is
still bogus.

Wei.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libxl: correct libxl to obey libxl's programming paramdigm
       [not found] ` <53da4e8b.12a9e00a.4198.fffffe41SMTPIN_ADDED_MISSING@mx.google.com>
@ 2014-08-01 16:37   ` Meng Xu
  2014-08-01 17:02     ` Wei Liu
  0 siblings, 1 reply; 5+ messages in thread
From: Meng Xu @ 2014-08-01 16:37 UTC (permalink / raw)
  To: Wei Liu
  Cc: Ian Campbell, Stefano Stabellini, Ian Jackson, Meng Xu,
	xen-devel@lists.xen.org


[-- Attachment #1.1: Type: text/plain, Size: 2360 bytes --]

Hi Wei,

2014-07-31 22:11 GMT+08:00 Wei Liu <wei.liu2@citrix.com>:

> On Wed, Jul 30, 2014 at 12:18:55PM -0400, Meng Xu wrote:
> > When sched_domain_get() return rc != 0, scinfo will not be disposed.
> > This violates the libxl programming paradigm:
> > 272  * The user must always calls "dispose" exactly
> > 273  * once afterwards, to clean up, regardless of whether operations
> > on
> > 274  * this object succeeded or failed.
> >
>
> I would remove the line number because the header file changes as much
> sutffs added in.
>
>
​Agree and will remove it.​



> > Signed-off-by: Meng Xu <mengxu@cis.upenn.edu>
> > ---
> >  tools/libxl/xl_cmdimpl.c |    9 ++++++---
> >  1 file changed, 6 insertions(+), 3 deletions(-)
> >
> > diff --git a/tools/libxl/xl_cmdimpl.c b/tools/libxl/xl_cmdimpl.c
> > index 01bce2f..d1efdd7 100644
> > --- a/tools/libxl/xl_cmdimpl.c
> > +++ b/tools/libxl/xl_cmdimpl.c
> > @@ -5014,7 +5014,7 @@ static int sched_credit_domain_output(int domid)
> >      }
> >      rc = sched_domain_get(LIBXL_SCHEDULER_CREDIT, domid, &scinfo);
> >      if (rc)
> > -        return rc;
> > +        goto out;
> >      domname = libxl_domid_to_name(ctx, domid);
> >      printf("%-33s %4d %6d %4d\n",
> >          domname,
> > @@ -5022,6 +5022,7 @@ static int sched_credit_domain_output(int domid)
> >          scinfo.weight,
> >          scinfo.cap);
> >      free(domname);
> > +out:
> >      libxl_domain_sched_params_dispose(&scinfo);
>
> And you seem to miss this part of that paradigm:
>
> * IDL-generated libxl types should be used as follows: the user must
> * always call the "init" function before using a type, even if the
> * variable is simply being passed by reference as an out parameter
> * to a libxl function.
>
> So calling dispose in the end while not calling init at the beginning is
> still bogus.
>

​I didn't call the init function at the beginning because the init function
is called in the function ​libxl_domain_sched_params_get() at file
tools/libxl/libxl.c.

My question is: should I call the init function again in xl_cmdimpl.c?
(Although calling it twice seems causing no damage, I'm not sure if it's a
good idea.)

Thanks,

Meng


-- 


-----------
Meng Xu
PhD Student in Computer and Information Science
University of Pennsylvania

[-- Attachment #1.2: Type: text/html, Size: 3834 bytes --]

[-- Attachment #2: Type: text/plain, Size: 126 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libxl: correct libxl to obey libxl's programming paramdigm
  2014-08-01 16:37   ` Meng Xu
@ 2014-08-01 17:02     ` Wei Liu
  2014-08-04 10:20       ` Ian Campbell
  0 siblings, 1 reply; 5+ messages in thread
From: Wei Liu @ 2014-08-01 17:02 UTC (permalink / raw)
  To: Meng Xu
  Cc: Wei Liu, Ian Campbell, Stefano Stabellini, Ian Jackson,
	xen-devel@lists.xen.org, Meng Xu

On Sat, Aug 02, 2014 at 12:37:21AM +0800, Meng Xu wrote:
[...]
> > * to a libxl function.
> >
> > So calling dispose in the end while not calling init at the beginning is
> > still bogus.
> >
> 
> ​I didn't call the init function at the beginning because the init function
> is called in the function ​libxl_domain_sched_params_get() at file
> tools/libxl/libxl.c.
> 
> My question is: should I call the init function again in xl_cmdimpl.c?
> (Although calling it twice seems causing no damage, I'm not sure if it's a
> good idea.)
> 

I think _init and _dispose should be placed in same place. I would vote
for moving that _init from libxl to xl. You might want to get some input
from maintainers before submitting another version.

Wei.

> Thanks,
> 
> Meng
> 
> 
> -- 
> 
> 
> -----------
> Meng Xu
> PhD Student in Computer and Information Science
> University of Pennsylvania

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] libxl: correct libxl to obey libxl's programming paramdigm
  2014-08-01 17:02     ` Wei Liu
@ 2014-08-04 10:20       ` Ian Campbell
  0 siblings, 0 replies; 5+ messages in thread
From: Ian Campbell @ 2014-08-04 10:20 UTC (permalink / raw)
  To: Wei Liu
  Cc: Ian Jackson, Stefano Stabellini, Meng Xu, Meng Xu,
	xen-devel@lists.xen.org

On Fri, 2014-08-01 at 18:02 +0100, Wei Liu wrote:
> On Sat, Aug 02, 2014 at 12:37:21AM +0800, Meng Xu wrote:
> [...]
> > > * to a libxl function.
> > >
> > > So calling dispose in the end while not calling init at the beginning is
> > > still bogus.
> > >
> > 
> > ​I didn't call the init function at the beginning because the init function
> > is called in the function ​libxl_domain_sched_params_get() at file
> > tools/libxl/libxl.c.
> > 
> > My question is: should I call the init function again in xl_cmdimpl.c?
> > (Although calling it twice seems causing no damage, I'm not sure if it's a
> > good idea.)
> > 
> 
> I think _init and _dispose should be placed in same place. I would vote
> for moving that _init from libxl to xl. You might want to get some input
> from maintainers before submitting another version.

Since _init is idempotent for structs which are out parameters it is
fine to call _init from both from the application and libxl.

The application *should* be calling _init, but it is a good idea if
libxl does it too, just in case etc etc.

Ian.


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-08-04 10:20 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-07-30 16:18 [PATCH] libxl: correct libxl to obey libxl's programming paramdigm Meng Xu
2014-07-31 14:11 ` Wei Liu
     [not found] ` <53da4e8b.12a9e00a.4198.fffffe41SMTPIN_ADDED_MISSING@mx.google.com>
2014-08-01 16:37   ` Meng Xu
2014-08-01 17:02     ` Wei Liu
2014-08-04 10:20       ` Ian Campbell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).