All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jason Andryuk <jandryuk@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: Anthony PERARD <anthony.perard@citrix.com>,
	Ian Jackson <ian.jackson@citrix.com>, Wei Liu <wl@xen.org>,
	Jason Andryuk <jandryuk@gmail.com>
Subject: [PATCH v5 19/21] libxl: Refactor kill_device_model to libxl__kill_xs_path
Date: Tue, 28 Apr 2020 00:04:31 -0400	[thread overview]
Message-ID: <20200428040433.23504-20-jandryuk@gmail.com> (raw)
In-Reply-To: <20200428040433.23504-1-jandryuk@gmail.com>

Move kill_device_model to libxl__kill_xs_path so we have a helper to
kill a process from a pid stored in xenstore.  We'll be using it to kill
vchan-qmp-proxy.

libxl__kill_xs_path takes a "what" string for use in printing error
messages.  kill_device_model is retained in libxl_dm.c to provide the
string.

Signed-off-by: Jason Andryuk <jandryuk@gmail.com>
---
 tools/libxl/libxl_aoutils.c  | 32 ++++++++++++++++++++++++++++++++
 tools/libxl/libxl_dm.c       | 27 +--------------------------
 tools/libxl/libxl_internal.h |  3 +++
 3 files changed, 36 insertions(+), 26 deletions(-)

diff --git a/tools/libxl/libxl_aoutils.c b/tools/libxl/libxl_aoutils.c
index 1be858c93c..c4c095a5ba 100644
--- a/tools/libxl/libxl_aoutils.c
+++ b/tools/libxl/libxl_aoutils.c
@@ -626,6 +626,38 @@ void libxl__kill(libxl__gc *gc, pid_t pid, int sig, const char *what)
                 what, (unsigned long)pid, sig);
 }
 
+/* Generic function to signal (HUP) a pid stored in xenstore */
+int libxl__kill_xs_path(libxl__gc *gc, const char *xs_path_pid,
+                        const char *what)
+{
+    const char *xs_pid;
+    int ret, pid;
+
+    ret = libxl__xs_read_checked(gc, XBT_NULL, xs_path_pid, &xs_pid);
+    if (ret || !xs_pid) {
+        LOG(ERROR, "unable to find %s pid in %s", what, xs_path_pid);
+        ret = ret ? : ERROR_FAIL;
+        goto out;
+    }
+    pid = atoi(xs_pid);
+
+    ret = kill(pid, SIGHUP);
+    if (ret < 0 && errno == ESRCH) {
+        LOG(ERROR, "%s already exited", what);
+        ret = 0;
+    } else if (ret == 0) {
+        LOG(DEBUG, "%s signaled", what);
+        ret = 0;
+    } else {
+        LOGE(ERROR, "failed to kill %s [%d]", what, pid);
+        ret = ERROR_FAIL;
+        goto out;
+    }
+
+out:
+    return ret;
+}
+
 /*
  * Local variables:
  * mode: C
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index a57c13bdf4..10ca4226ba 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -3397,32 +3397,7 @@ out:
 /* Generic function to signal a Qemu instance to exit */
 static int kill_device_model(libxl__gc *gc, const char *xs_path_pid)
 {
-    const char *xs_pid;
-    int ret, pid;
-
-    ret = libxl__xs_read_checked(gc, XBT_NULL, xs_path_pid, &xs_pid);
-    if (ret || !xs_pid) {
-        LOG(ERROR, "unable to find device model pid in %s", xs_path_pid);
-        ret = ret ? : ERROR_FAIL;
-        goto out;
-    }
-    pid = atoi(xs_pid);
-
-    ret = kill(pid, SIGHUP);
-    if (ret < 0 && errno == ESRCH) {
-        LOG(ERROR, "Device Model already exited");
-        ret = 0;
-    } else if (ret == 0) {
-        LOG(DEBUG, "Device Model signaled");
-        ret = 0;
-    } else {
-        LOGE(ERROR, "failed to kill Device Model [%d]", pid);
-        ret = ERROR_FAIL;
-        goto out;
-    }
-
-out:
-    return ret;
+    return libxl__kill_xs_path(gc, xs_path_pid, "Device Model");
 }
 
 /* Helper to destroy a Qdisk backend */
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 00cfbe1fac..32aa797714 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -2707,6 +2707,9 @@ int libxl__async_exec_start(libxl__async_exec_state *aes);
 bool libxl__async_exec_inuse(const libxl__async_exec_state *aes);
 
 _hidden void libxl__kill(libxl__gc *gc, pid_t pid, int sig, const char *what);
+/* kill SIGHUP a pid stored in xenstore */
+_hidden int libxl__kill_xs_path(libxl__gc *gc, const char *xs_path_pid,
+                                const char *what);
 
 /*----- device addition/removal -----*/
 
-- 
2.20.1



  parent reply	other threads:[~2020-04-28  4:07 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-28  4:04 [PATCH v5 00/21] Add support for qemu-xen runnning in a Linux-based stubdomain Jason Andryuk
2020-04-28  4:04 ` [PATCH v5 01/21] Document ioemu MiniOS stubdomain protocol Jason Andryuk
2020-05-14 16:08   ` Ian Jackson
2020-04-28  4:04 ` [PATCH v5 02/21] Document ioemu Linux " Jason Andryuk
2020-05-14 16:08   ` Ian Jackson
2020-04-28  4:04 ` [PATCH v5 03/21] libxl: fix qemu-trad cmdline for no sdl/vnc case Jason Andryuk
2020-04-28  4:04 ` [PATCH v5 04/21] libxl: Allow running qemu-xen in stubdomain Jason Andryuk
2020-05-14 16:10   ` Ian Jackson
2020-04-28  4:04 ` [PATCH v5 05/21] libxl: Handle Linux stubdomain specific QEMU options Jason Andryuk
2020-05-14 16:19   ` Ian Jackson
2020-05-17 13:55     ` Jason Andryuk
2020-04-28  4:04 ` [PATCH v5 06/21] libxl: write qemu arguments into separate xenstore keys Jason Andryuk
2020-05-14 16:25   ` Ian Jackson
2020-05-17 14:29     ` Jason Andryuk
2020-04-28  4:04 ` [PATCH v5 07/21] xl: add stubdomain related options to xl config parser Jason Andryuk
2020-05-14 16:26   ` Ian Jackson
2020-04-28  4:04 ` [PATCH v5 08/21] tools/libvchan: notify server when client is connected Jason Andryuk
2020-05-14 16:27   ` Ian Jackson
2020-04-28  4:04 ` [PATCH v5 09/21] libxl: add save/restore support for qemu-xen in stubdomain Jason Andryuk
2020-05-14 16:35   ` Ian Jackson
2020-05-17 13:55     ` Jason Andryuk
2020-05-18 14:15       ` Ian Jackson
2020-05-18 14:50         ` Marek Marczykowski-Górecki
2020-05-18 15:18           ` [PATCH v5 09/21] libxl: add save/restore support for qemu-xen in stubdomain [and 1 more messages] Ian Jackson
2020-05-18 15:48             ` Jason Andryuk
2020-05-18 16:37               ` Ian Jackson
2020-04-28  4:04 ` [PATCH v5 10/21] tools: add missing libxenvchan cflags Jason Andryuk
2020-05-14 16:35   ` Ian Jackson
2020-04-28  4:04 ` [PATCH v5 11/21] tools: add simple vchan-socket-proxy Jason Andryuk
2020-05-14 16:37   ` Ian Jackson
2020-04-28  4:04 ` [PATCH v5 12/21] libxl: use vchan for QMP access with Linux stubdomain Jason Andryuk
2020-05-14 16:39   ` Ian Jackson
2020-04-28  4:04 ` [PATCH v5 13/21] Regenerate autotools files Jason Andryuk
2020-05-14 16:41   ` Ian Jackson
2020-04-28  4:04 ` [PATCH v5 14/21] libxl: require qemu in dom0 even if stubdomain is in use Jason Andryuk
2020-05-14 16:42   ` Ian Jackson
2020-05-14 17:36     ` Marek Marczykowski-Górecki
2020-04-28  4:04 ` [PATCH v5 15/21] libxl: ignore emulated IDE disks beyond the first 4 Jason Andryuk
2020-05-14 16:43   ` Ian Jackson
2020-04-28  4:04 ` [PATCH v5 16/21] libxl: consider also qemu in stubdomain in libxl__dm_active check Jason Andryuk
2020-05-14 16:43   ` Ian Jackson
2020-04-28  4:04 ` [PATCH v5 17/21] docs: Add device-model-domid to xenstore-paths Jason Andryuk
2020-05-14 16:44   ` Ian Jackson
2020-04-28  4:04 ` [PATCH v5 18/21] libxl: Check stubdomain kernel & ramdisk presence Jason Andryuk
2020-05-14 16:45   ` Ian Jackson
2020-04-28  4:04 ` Jason Andryuk [this message]
2020-05-14 16:45   ` [PATCH v5 19/21] libxl: Refactor kill_device_model to libxl__kill_xs_path Ian Jackson
2020-04-28  4:04 ` [PATCH v5 20/21] libxl: Kill vchan-socket-proxy when cleaning up qmp Jason Andryuk
2020-05-14 16:47   ` Ian Jackson
2020-04-28  4:04 ` [PATCH v5 21/21] tools: Clean up vchan-socket-proxy socket Jason Andryuk
2020-05-14 16:48   ` Ian Jackson
2020-05-11 20:19 ` [PATCH v5 00/21] Add support for qemu-xen runnning in a Linux-based stubdomain Jason Andryuk
2020-05-14 16:07 ` Ian Jackson
2020-05-14 16:55 ` Ian Jackson
2020-05-14 19:10   ` Jason Andryuk

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=20200428040433.23504-20-jandryuk@gmail.com \
    --to=jandryuk@gmail.com \
    --cc=anthony.perard@citrix.com \
    --cc=ian.jackson@citrix.com \
    --cc=wl@xen.org \
    --cc=xen-devel@lists.xenproject.org \
    /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.