All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ian Jackson <ian.jackson@eu.citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>,
	Euan Harris <euan.harris@citrix.com>
Subject: [PATCH 11/29] libxl: events: Make libxl__async_exec_* pass caller an rc
Date: Tue, 10 Feb 2015 20:09:58 +0000	[thread overview]
Message-ID: <1423599016-32639-12-git-send-email-ian.jackson@eu.citrix.com> (raw)
In-Reply-To: <1423599016-32639-1-git-send-email-ian.jackson@eu.citrix.com>

The internal user of libxl__async_exec_start et al now gets an rc as
well as the process's exit status.

For now this is always either 0 or ERROR_FAIL, but with ao
cancellation this will possibly be CANCELLED or TIMEDOUT too.

Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
---
v2: New patch due to rebause; v1 had changes to device_hotplug_*
     scripts instead.
    Callback now gets unambiguous information about error situation:
     previously, if only thing that went wrong was that child died
     badly, rc would be FAILED, which was unambigously; now rc=0.
    Add a comment document the meaning of the rc and status parameters
     to the callback.
---
 tools/libxl/libxl_aoutils.c         |    9 ++++++---
 tools/libxl/libxl_device.c          |   13 +++++++++----
 tools/libxl/libxl_internal.h        |   11 ++++++++++-
 tools/libxl/libxl_netbuffer.c       |   19 ++++++++++---------
 tools/libxl/libxl_remus_disk_drbd.c |    8 +++++---
 5 files changed, 40 insertions(+), 20 deletions(-)

diff --git a/tools/libxl/libxl_aoutils.c b/tools/libxl/libxl_aoutils.c
index 754e2d1..891cdb8 100644
--- a/tools/libxl/libxl_aoutils.c
+++ b/tools/libxl/libxl_aoutils.c
@@ -483,11 +483,12 @@ static void async_exec_done(libxl__egc *egc,
     libxl__ev_time_deregister(gc, &aes->time);
 
     if (status) {
-        libxl_report_child_exitstatus(CTX, LIBXL__LOG_ERROR,
-                                      aes->what, pid, status);
+        if (!aes->rc)
+            libxl_report_child_exitstatus(CTX, LIBXL__LOG_ERROR,
+                                          aes->what, pid, status);
     }
 
-    aes->callback(egc, aes, status);
+    aes->callback(egc, aes, aes->rc, status);
 }
 
 void libxl__async_exec_init(libxl__async_exec_state *aes)
@@ -506,6 +507,8 @@ int libxl__async_exec_start(libxl__async_exec_state *aes)
     libxl__ev_child *const child = &aes->child;
     char ** const args = aes->args;
 
+    aes->rc = 0;
+
     /* Set execution timeout */
     if (libxl__ev_time_register_rel(ao, &aes->time,
                                     async_exec_timeout,
diff --git a/tools/libxl/libxl_device.c b/tools/libxl/libxl_device.c
index c80749f..84114ff 100644
--- a/tools/libxl/libxl_device.c
+++ b/tools/libxl/libxl_device.c
@@ -729,7 +729,7 @@ static void device_hotplug(libxl__egc *egc, libxl__ao_device *aodev);
 
 static void device_hotplug_child_death_cb(libxl__egc *egc,
                                           libxl__async_exec_state *aes,
-                                          int status);
+                                          int rc, int status);
 
 static void device_destroy_be_watch_cb(libxl__egc *egc,
                                        libxl__xswait_state *xswait,
@@ -1052,7 +1052,7 @@ out:
 
 static void device_hotplug_child_death_cb(libxl__egc *egc,
                                           libxl__async_exec_state *aes,
-                                          int status)
+                                          int rc, int status)
 {
     libxl__ao_device *aodev = CONTAINER_OF(aes, *aodev, aes);
     STATE_AO_GC(aodev->ao);
@@ -1061,12 +1061,17 @@ static void device_hotplug_child_death_cb(libxl__egc *egc,
 
     device_hotplug_clean(gc, aodev);
 
-    if (status) {
+    if (status && !rc) {
         hotplug_error = libxl__xs_read(gc, XBT_NULL,
                                        GCSPRINTF("%s/hotplug-error", be_path));
         if (hotplug_error)
             LOG(ERROR, "script: %s", hotplug_error);
-        aodev->rc = ERROR_FAIL;
+        rc = ERROR_FAIL;
+    }
+
+    if (rc) {
+        if (!aodev->rc)
+            aodev->rc = rc;
         if (aodev->action == LIBXL__DEVICE_ACTION_ADD)
             /*
              * Only fail on device connection, on disconnection
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index b615fc5..02cac7b 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -2089,7 +2089,15 @@ _hidden const char *libxl__run_dir_path(void);
 typedef struct libxl__async_exec_state libxl__async_exec_state;
 
 typedef void libxl__async_exec_callback(libxl__egc *egc,
-                        libxl__async_exec_state *aes, int status);
+                        libxl__async_exec_state *aes, int rc, int status);
+/*
+ * Meaning of status and rc:
+ *  rc==0, status==0    all went well
+ *  rc==0, status!=0    everything OK except child exited nonzero (logged)
+ *  rc!=0               something else went wrong (status is real
+ *                       exit status, maybe reflecting SIGKILL if aes
+ *                       code killed the child).  Logged unless CANCELLED.
+ */
 
 struct libxl__async_exec_state {
     /* caller must fill these in */
@@ -2105,6 +2113,7 @@ struct libxl__async_exec_state {
     /* private */
     libxl__ev_time time;
     libxl__ev_child child;
+    int rc;
 };
 
 void libxl__async_exec_init(libxl__async_exec_state *aes);
diff --git a/tools/libxl/libxl_netbuffer.c b/tools/libxl/libxl_netbuffer.c
index edc6843..ff2d6c7 100644
--- a/tools/libxl/libxl_netbuffer.c
+++ b/tools/libxl/libxl_netbuffer.c
@@ -219,10 +219,10 @@ out:
 
 static void netbuf_setup_script_cb(libxl__egc *egc,
                                    libxl__async_exec_state *aes,
-                                   int status);
+                                   int rc, int status);
 static void netbuf_teardown_script_cb(libxl__egc *egc,
                                       libxl__async_exec_state *aes,
-                                      int status);
+                                      int rc, int status);
 
 /*
  * the script needs the following env & args
@@ -327,14 +327,13 @@ out:
  */
 static void netbuf_setup_script_cb(libxl__egc *egc,
                                    libxl__async_exec_state *aes,
-                                   int status)
+                                   int rc, int status)
 {
     libxl__ao_device *aodev = CONTAINER_OF(aes, *aodev, aes);
     libxl__remus_device *dev = CONTAINER_OF(aodev, *dev, aodev);
     libxl__remus_device_nic *remus_nic = dev->concrete_data;
     libxl__remus_devices_state *rds = dev->rds;
     const char *out_path_base, *hotplug_error = NULL;
-    int rc;
 
     STATE_AO_GC(rds->ao);
 
@@ -344,6 +343,11 @@ static void netbuf_setup_script_cb(libxl__egc *egc,
     const char *const vif = remus_nic->vif;
     const char **const ifb = &remus_nic->ifb;
 
+    if (status && !rc)
+        rc = ERROR_FAIL;
+    if (rc)
+        goto out;
+
     /*
      * we need to get ifb first because it's needed for teardown
      */
@@ -411,17 +415,14 @@ out:
 
 static void netbuf_teardown_script_cb(libxl__egc *egc,
                                       libxl__async_exec_state *aes,
-                                      int status)
+                                      int rc, int status)
 {
-    int rc;
     libxl__ao_device *aodev = CONTAINER_OF(aes, *aodev, aes);
     libxl__remus_device *dev = CONTAINER_OF(aodev, *dev, aodev);
     libxl__remus_device_nic *remus_nic = dev->concrete_data;
 
-    if (status)
+    if (status && !rc)
         rc = ERROR_FAIL;
-    else
-        rc = 0;
 
     free_qdisc(remus_nic);
 
diff --git a/tools/libxl/libxl_remus_disk_drbd.c b/tools/libxl/libxl_remus_disk_drbd.c
index 5e0c9a6..fc76b89 100644
--- a/tools/libxl/libxl_remus_disk_drbd.c
+++ b/tools/libxl/libxl_remus_disk_drbd.c
@@ -78,7 +78,7 @@ out:
 /* callbacks */
 static void match_async_exec_cb(libxl__egc *egc,
                                 libxl__async_exec_state *aes,
-                                int status);
+                                int rc, int status);
 
 /* implementations */
 
@@ -133,9 +133,8 @@ out:
 
 static void match_async_exec_cb(libxl__egc *egc,
                                 libxl__async_exec_state *aes,
-                                int status)
+                                int rc, int status)
 {
-    int rc;
     libxl__ao_device *aodev = CONTAINER_OF(aes, *aodev, aes);
     libxl__remus_device *dev = CONTAINER_OF(aodev, *dev, aodev);
     libxl__remus_drbd_disk *drbd_disk;
@@ -143,6 +142,9 @@ static void match_async_exec_cb(libxl__egc *egc,
 
     STATE_AO_GC(aodev->ao);
 
+    if (rc)
+        goto out;
+
     if (status) {
         rc = ERROR_REMUS_DEVOPS_DOES_NOT_MATCH;
         /* BUG: seems to assume that any exit status means `no match' */
-- 
1.7.10.4

  parent reply	other threads:[~2015-02-10 20:09 UTC|newest]

Thread overview: 98+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-10 20:09 [RFC PATCH v2 00/29] libxl: Cancelling asynchronous operations Ian Jackson
2015-02-10 20:09 ` [PATCH 01/29] libxl: Further fix exit paths from libxl_device_events_handler Ian Jackson
2015-02-18 16:23   ` Roger Pau Monné
2015-03-24 10:49     ` Ian Campbell
2015-02-10 20:09 ` [PATCH 02/29] libxl: Comment cleanups Ian Jackson
2015-02-11  1:46   ` Hongyang Yang
2015-02-11 12:05     ` Ian Jackson
2015-03-30  9:08     ` Ian Campbell
2015-03-24 10:50   ` Ian Campbell
2015-02-10 20:09 ` [PATCH 03/29] libxl: suspend: switch_logdirty_done takes rc Ian Jackson
2015-03-24 10:53   ` Ian Campbell
2015-03-31 18:02     ` Ian Jackson
2015-02-10 20:09 ` [PATCH 04/29] libxl: suspend: common suspend callbacks take rc Ian Jackson
2015-03-24 10:55   ` Ian Campbell
2015-03-31 18:03     ` Ian Jackson
2015-02-10 20:09 ` [PATCH 05/29] libxl: suspend: Return correct error from callbacks Ian Jackson
2015-03-24 10:58   ` Ian Campbell
2015-02-10 20:09 ` [PATCH 06/29] libxl: Use libxl__xswait* in libxl__ao_device Ian Jackson
2015-03-24 11:04   ` Ian Campbell
2015-03-31 18:06     ` Ian Jackson
2015-04-01  9:25       ` Ian Campbell
2015-02-10 20:09 ` [PATCH 07/29] libxl: xswait/devstate: Move xswait to before devstate Ian Jackson
2015-03-24 11:05   ` Ian Campbell
2015-02-10 20:09 ` [PATCH 08/29] libxl: devstate: Use libxl__xswait* Ian Jackson
2015-03-24 11:07   ` Ian Campbell
2015-02-10 20:09 ` [PATCH 09/29] libxl: New error codes CANCELLED etc Ian Jackson
2015-03-24 11:08   ` Ian Campbell
2015-02-10 20:09 ` [PATCH 10/29] libxl: events: Make timeout and async exec setup take an ao, not a gc Ian Jackson
2015-02-11  1:04   ` Wen Congyang
2015-02-11 12:04     ` Ian Jackson
2015-03-31 18:09     ` Ian Jackson
2015-03-24 11:09   ` Ian Campbell
2015-02-10 20:09 ` Ian Jackson [this message]
2015-03-24 11:20   ` [PATCH 11/29] libxl: events: Make libxl__async_exec_* pass caller an rc Ian Campbell
2015-03-31 18:12     ` Ian Jackson
2015-04-01  9:29       ` Ian Campbell
2015-02-10 20:09 ` [PATCH 12/29] libxl: events: Permit timeouts to signal cancellation Ian Jackson
2015-03-24 11:22   ` Ian Campbell
2015-02-10 20:10 ` [PATCH 13/29] libxl: domain create: Do not destroy on cancellation Ian Jackson
2015-03-24 11:24   ` Ian Campbell
2015-03-31 18:14     ` Ian Jackson
2015-02-10 20:10 ` [PATCH 14/29] libxl: ao: Record ultimate parent of a nested ao Ian Jackson
2015-03-24 11:26   ` Ian Campbell
2015-02-10 20:10 ` [PATCH 15/29] libxl: ao: Count the nested progeny of an ao Ian Jackson
2015-03-24 11:27   ` Ian Campbell
2015-02-10 20:10 ` [PATCH 16/29] libxl: ao: Provide manip_refcnt Ian Jackson
2015-03-24 11:32   ` Ian Campbell
2015-03-31 18:23     ` Ian Jackson
2015-04-01  9:34       ` Ian Campbell
2015-02-10 20:10 ` [PATCH 17/29] libxl: cancellation: Provide public ao cancellation API Ian Jackson
2015-03-24 11:45   ` Ian Campbell
2015-03-31 18:26     ` Ian Jackson
2015-03-24 11:48   ` Ian Campbell
2015-03-31 18:33     ` Ian Jackson
2015-04-01  9:38       ` Ian Campbell
2015-02-10 20:10 ` [PATCH 18/29] libxl: cancellation: Provide explicit internal cancel check API Ian Jackson
2015-03-24 11:45   ` Ian Campbell
2015-02-10 20:10 ` [PATCH 19/29] libxl: cancellation: Make timeouts cancellable Ian Jackson
2015-03-24 11:50   ` Ian Campbell
2015-02-10 20:10 ` [PATCH 20/29] libxl: cancellation: Note that driver domain task cannot be usefully cancelled Ian Jackson
2015-02-18 16:24   ` Roger Pau Monné
2015-03-24 11:51   ` Ian Campbell
2015-03-31 18:37     ` Ian Jackson
2015-02-10 20:10 ` [PATCH 21/29] libxl: cancellation: Make spawns cancellable Ian Jackson
2015-03-24 11:53   ` Ian Campbell
2015-03-31 18:45     ` Ian Jackson
2015-04-01  9:40       ` Ian Campbell
2015-02-10 20:10 ` [PATCH 22/29] libxl: Introduce DOMAIN_DESTROYED error code Ian Jackson
2015-03-24 11:56   ` Ian Campbell
2015-03-31 18:47     ` Ian Jackson
2015-04-01  9:41       ` Ian Campbell
2015-02-10 20:10 ` [PATCH 23/29] libxl: cancellation: Support cancellation where we spot domain death Ian Jackson
2015-03-24 11:58   ` Ian Campbell
2015-02-10 20:10 ` [PATCH 24/29] libxl: Introduce FILLZERO Ian Jackson
2015-03-24 12:03   ` Ian Campbell
2015-03-31 18:51     ` Ian Jackson
2015-04-01  9:42       ` Ian Campbell
2015-02-10 20:10 ` [PATCH 25/29] libxl: cancellation: Preparations for save/restore cancellation Ian Jackson
2015-03-24 12:04   ` Ian Campbell
2015-02-10 20:10 ` [PATCH 26/29] libxl: cancellation: Handle SIGTERM in save/restore helper Ian Jackson
2015-03-24 12:07   ` Ian Campbell
2015-02-10 20:10 ` [PATCH 27/29] libxl: cancellation: Cancel libxc save/restore Ian Jackson
2015-03-24 12:08   ` Ian Campbell
2015-02-10 20:10 ` [PATCH 28/29] libxl: ao: datacopier callback gets an rc Ian Jackson
2015-03-24 12:10   ` Ian Campbell
2015-02-10 20:10 ` [PATCH 29/29] libxl: cancellation: Make datacopiers cancellable Ian Jackson
2015-03-24 12:11   ` Ian Campbell
2015-02-10 20:13 ` [RFC PATCH v2 00/29] libxl: Cancelling asynchronous operations Ian Jackson
2015-02-18 16:10 ` Euan Harris
2015-02-18 16:12   ` Ian Jackson
2015-04-07 17:08   ` Euan Harris
2015-04-07 17:19     ` Ian Jackson
2015-04-09 16:44       ` Euan Harris
2015-04-09 16:50         ` Ian Jackson
2015-04-14  9:43       ` Euan Harris
2015-03-03 12:08 ` Ian Campbell
2015-03-20 10:39   ` Euan Harris
2015-04-07 17:22   ` Ian Jackson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1423599016-32639-12-git-send-email-ian.jackson@eu.citrix.com \
    --to=ian.jackson@eu.citrix.com \
    --cc=euan.harris@citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.