Skip to contentSkip to conversation

xl: log an error if libxl_cpupool_destroy() fails

PATCH Superseded Dario Faggioli 4 participants 7 messages Oct 22, 2015 – Oct 23, 2015

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xl: log an error if libxl_cpupool_destroy() fails

In fact, right now, failing at destroying a cpupool is just not reported to the user in any explicit way. Log an error, as it is customary for xl in these cases.

While there, take the chance to turn a couple of xl exit codes into EXIT_[SUCCESS|FAILURE], as discussed and agreed here:

http://lists.xenproject.org/archives/html/xen-devel/2015-03/msg01336.html
http://lists.xenproject.org/archives/html/xen-devel/2015-03/msg01341.html

---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Juergen Gross <[email protected]>

---
 tools/libxl/xl_cmdimpl.c |   10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
tools/libxl/xl_cmdimpl.c +6 -4
index 365798b..5a5f959 100644
@@ -7581,13 +7581,15 @@ int main_cpupooldestroy(int argc, char **argv)
     if (libxl_cpupool_qualifier_to_cpupoolid(ctx, pool, &poolid, NULL) ||
         !libxl_cpupoolid_is_valid(ctx, poolid)) {
         fprintf(stderr, "unknown cpupool '%s'\n", pool);
-        return 1;
+        return EXIT_FAILURE;
     }
 
-    if (libxl_cpupool_destroy(ctx, poolid))
-        return 1;
+    if (libxl_cpupool_destroy(ctx, poolid)) {
+        fprintf(stderr, "Can't destroy cpupool '%s'\n", pool);
+        return EXIT_FAILURE;
+    }
 
-    return 0;
+    return EXIT_SUCCESS;
 }
 
 int main_cpupoolrename(int argc, char **argv)
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Dario Faggioli

In fact, right now, failing at destroying a cpupool is just not reported to the user in any explicit way. Log an error, as it is customary for xl in these cases.

Quoted 8 lines

While there, take the chance to turn a couple of xl exit codes into EXIT_[SUCCESS|FAILURE], as discussed and agreed here:

http://lists.xenproject.org/archives/html/xen-devel/2015-03/msg01336.html
http://lists.xenproject.org/archives/html/xen-devel/2015-03/msg01341.html

Quoted 36 lines

---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Ian Campbell <[email protected]>
Cc: Wei Liu <[email protected]>
Cc: Juergen Gross <[email protected]>

---
  tools/libxl/xl_cmdimpl.c |   10 ++++++----
  1 file changed, 6 insertions(+), 4 deletions(-)
tools/libxl/xl_cmdimpl.c +6 -4
index 365798b..5a5f959 100644
@@ -7581,13 +7581,15 @@ int main_cpupooldestroy(int argc, char **argv)
      if (libxl_cpupool_qualifier_to_cpupoolid(ctx, pool, &poolid, NULL) ||
          !libxl_cpupoolid_is_valid(ctx, poolid)) {
          fprintf(stderr, "unknown cpupool '%s'\n", pool);
-        return 1;
+        return EXIT_FAILURE;
      }
 
-    if (libxl_cpupool_destroy(ctx, poolid))
-        return 1;
+    if (libxl_cpupool_destroy(ctx, poolid)) {
+        fprintf(stderr, "Can't destroy cpupool '%s'\n", pool);
+        return EXIT_FAILURE;
+    }
 
-    return 0;
+    return EXIT_SUCCESS;
  }
 
  int main_cpupoolrename(int argc, char **argv)
Acked-by on v1 1/1
#2 lore raw
In reply to Dario Faggioli
Quoted 4 lines · Dario Faggioli

In fact, right now, failing at destroying a cpupool is just not reported to the user in any explicit way. Log an error, as it is customary for xl in these cases.

Quoted 8 lines

While there, take the chance to turn a couple of xl exit codes into EXIT_[SUCCESS|FAILURE], as discussed and agreed here:

http://lists.xenproject.org/archives/html/xen-devel/2015-03/msg01336.html
http://lists.xenproject.org/archives/html/xen-devel/2015-03/msg01341.html

#3 lore raw
Quoted 9 lines · Wei Liu
Quoted 8 lines · Dario Faggioli

In fact, right now, failing at destroying a cpupool is just not reported to the user in any explicit way. Log an error, as it is customary for xl in these cases.

While there, take the chance to turn a couple of xl exit codes into EXIT_[SUCCESS|FAILURE], as discussed and agreed here:

Quoted 8 lines
Quoted 6 lines

http://lists.xenproject.org/archives/html/xen-devel/2015-03/msg01336.h
tml
http://lists.xenproject.org/archives/html/xen-devel/2015-03/msg01341.h
tml

Looking at those links, I'm not sure that either you or myself was thinking of using EXIT_* as function return values, just that the eventual process exit would become one of those values instead of some negative number. Although the thread doesn't look like it is too clear if it is talking about return values from functions vs. process exit codes.

I think what I would have been expecting is for the xl internal error code would become EXIT_* either in the call to exit() or the return from main instead of being the process exit code directly.

Seeing "return EXIT_FOO" outside of a main function seems rather strange to me.

Wei, you acked so maybe you disagree?

Ian.

#4 lore raw
Quoted 9 lines · Ian Campbell

On Fri, 2015-10-23 at 09:43 +0100, Wei Liu wrote:

Looking at those links, I'm not sure that either you or myself was thinking
of using EXIT_* as function return values, just that the eventual process
exit would become one of those values instead of some negative number.

Exactly.

Quoted 4 lines

Although the thread doesn't look like it is too clear if it is talking
about return values from functions vs. process exit codes.

Well, independently from the thread, I certainly meant that I think EXIT_* should be used as process exit status, not as internal functions' return value.

Quoted 6 lines

I think what I would have been expecting is for the xl internal error code
would become EXIT_* either in the call to exit() or the return from main
instead of being the process exit code directly.

But, in this specific case, and in cases of main_foo() functions in xl_cmdimpl.c, it's exactly like that, isn't it?

    ...
    if (cspec) {
        if (dryrun_only && !cspec->can_dryrun) {
            fprintf(stderr, "command does not implement -N (dryrun) option\n");
            ret = 1;
            goto xit;
        }
        ret = cspec->cmd_impl(argc, argv);
    } else if (!strcmp(cmd, "help")) {
        help(argv[1]);
        ret = 0;
    } else {
        fprintf(stderr, "command not implemented\n");
        ret = 1;
    }

xit:

    return ret;
}

(from main() in xl.c)

Quoted 4 lines

Seeing "return EXIT_FOO" outside of a main function seems rather strange to
me.

Well, same here. Except, given xl architecture, I was considering main_foo() functions in xl_cmdimpl.c as some king of extensions of the actual main function.

The alternative would be to always use, say, 0 and 1 in xl_cmdimpl.c, and then convert them to EXIT_SUCCESS or EXIT_FAILURE in xl.c (for return-s, of course, exit()-s need to use them no matter where they are).

I'm fine with either, so, if you prefer the latter, I certainly can arrange for doing things that way.

Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel

#5 lore raw
Quoted 20 lines · Dario Faggioli
Quoted 9 lines · Ian Campbell

On Fri, 2015-10-23 at 09:43 +0100, Wei Liu wrote:

Looking at those links, I'm not sure that either you or myself was thinking
of using EXIT_* as function return values, just that the eventual process
exit would become one of those values instead of some negative number.

Exactly.

Quoted 4 lines

Although the thread doesn't look like it is too clear if it is talking
about return values from functions vs. process exit codes.

Well, independently from the thread, I certainly meant that I think EXIT_* should be used as process exit status, not as internal functions' return value.

Quoted 5 lines
Quoted 3 lines

I think what I would have been expecting is for the xl internal error code
Well, same here. Except, given xl architecture, I was considering

main_foo() functions in xl_cmdimpl.c as some king of extensions of the actual main function.

I had somehow convinced myself that these weren't being added in a main_foo, I agree that main_foo should be treated somewhat like a regular main().

Sorry for the noise.

Quoted 2 lines

I'm fine with either, so, if you prefer the latter, I certainly can arrange for doing things that way.

It would be helpful to a) not combine this change with the logging change and to b) include as part of the patch some sort of document comment in some relevant xl-ish place explaining some of this stuff (i.e. that an xl process should always return EXIT_FOO and that main_* can be treated like main() as if they are returning a process exit status and not a function return value).

I think it would also be useful to have xl's main() DTRT before starting to convert main_*. Currently it returns explicit 0 or 1 or the result of the main_*.

Ian.

#6 lore raw
Quoted 11 lines · Ian Campbell
Quoted 9 lines · Dario Faggioli
Quoted 3 lines · Ian Campbell

I think what I would have been expecting is for the xl internal error
code

Well, same here. Except, given xl architecture, I was considering main_foo() functions in xl_cmdimpl.c as some king of extensions of the
actual main function.

Quoted 5 lines

I had somehow convinced myself that these weren't being added in a main_foo, I agree that main_foo should be treated somewhat like a regular
main().

Ok, glad to see we're on the same page.

Quoted 2 lines

Sorry for the noise.

NP. :-)

Quoted 6 lines
Quoted 2 lines

I'm fine with either, so, if you prefer the latter, I certainly can arrange for doing things that way.

It would be helpful to a) not combine this change with the logging change

Sure, I'll resend the patch without changing that.

Quoted 9 lines

b) include as part of the patch some sort of document comment in some relevant xl-ish place explaining some of this stuff (i.e. that an xl
process should always return EXIT_FOO and that main_* can be treated like
main() as if they are returning a process exit status and not a function
return value).

About this...

Quoted 4 lines

I think it would also be useful to have xl's main() DTRT before starting to convert main_*. Currently it returns explicit 0 or 1 or the result of the main_*.

... and this, I'll see if I can convince Harman to pick these up, as part of her work on the subject. :-P :-P

Thanks and Regards,
Dario

Signature · 4 lines
<<This happens because I choose it to happen!>> (Raistlin Majere)
-----------------------------------------------------------------
Dario Faggioli, Ph.D, http://about.me/dario.faggioli
Senior Software Engineer, Citrix Systems R&D Ltd., Cambridge (UK)

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel