From: Jim Fehlig <jfehlig@suse.com>
To: Ian Campbell <ian.campbell@citrix.com>
Cc: Ian.Jackson@eu.citrix.com, wei.liu2@citrix.com, xen-devel@lists.xen.org
Subject: Re: [PATCH 3/3] libxl: Domain destroy: fork
Date: Fri, 20 Mar 2015 09:14:27 -0600 [thread overview]
Message-ID: <550C3953.7000604@suse.com> (raw)
In-Reply-To: <1426681640.18247.359.camel@citrix.com>
[-- Attachment #1: Type: text/plain, Size: 878 bytes --]
Ian Campbell wrote:
> On Tue, 2015-03-17 at 09:30 -0600, Jim Fehlig wrote:
>
>> diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
>> index b6541d4..b43db1a 100644
>> --- a/tools/libxl/libxl.c
>> +++ b/tools/libxl/libxl.c
>> @@ -1481,6 +1481,10 @@ static void domain_destroy_callback(libxl__egc *egc,
>> static void destroy_finish_check(libxl__egc *egc,
>> libxl__domain_destroy_state *dds);
>>
>> +static void domain_destroy_domid_cb(libxl__egc *egc,
>> + libxl__ev_child *destroyer,
>> + pid_t pid, int status);
>>
>
> This seems misplaced, doesn't it want to go before libxl__destroy_domid
> just after the prototype of devices_destroy_cb, which is where it lives
> in the sequence?
>
Yes, I think you are right. Here an adjusted patch.
Regards,
Jim
[-- Attachment #2: dom-destroy-fork.patch --]
[-- Type: text/x-diff, Size: 4911 bytes --]
>From 0c6fef6926580938b0fb8750c009af5151a056dc Mon Sep 17 00:00:00 2001
From: Ian Jackson <ian.jackson@eu.citrix.com>
Date: Thu, 5 Mar 2015 16:28:04 +0000
Subject: [PATCH 3/3] libxl: Domain destroy: fork
Call xc_domain_destroy in a subprocess. That allows us to do so
asynchronously, rather than blocking the whole process calling libxl.
The changes in detail:
* Provide an libxl__ev_child in libxl__domain_destroy_state, and
initialise it in libxl__domain_destroy. There is no possibility
to `clean up' a libxl__ev_child, but there need to clean it up, as
the control flow ensures that we only continue after the child has
exited.
* Call libxl__ev_child_fork at the right point and put the call to
xc_domain_destroy and associated logging in the child. (The child
opens a new xenctrl handle because we mustn't use the parent's.)
* Consequently, the success return path from domain_destroy_domid_cb
no longer calls dis->callback. Instead it simply returns.
* We plumb the errorno value through the child's exit status, if it
fits. This means we normally do the logging only in the parent.
* Incidentally, we fix the bug that we were treating the return value
from xc_domain_destroy as an errno value when in fact it is a
return value from do_domctl (in this case, 0 or -1 setting errno).
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Reviewed-by: Wei Liu <wei.liu2@citrix.com>
Reviewed-by: Jim Fehlig <jfehlig@suse.com>
Tested-by: Jim Fehlig <jfehlig@suse.com>
---
tools/libxl/libxl.c | 57 ++++++++++++++++++++++++++++++++++++++++----
tools/libxl/libxl_internal.h | 1 +
2 files changed, 53 insertions(+), 5 deletions(-)
diff --git a/tools/libxl/libxl.c b/tools/libxl/libxl.c
index b6541d4..b53a183 100644
--- a/tools/libxl/libxl.c
+++ b/tools/libxl/libxl.c
@@ -1558,6 +1558,10 @@ static void devices_destroy_cb(libxl__egc *egc,
libxl__devices_remove_state *drs,
int rc);
+static void domain_destroy_domid_cb(libxl__egc *egc,
+ libxl__ev_child *destroyer,
+ pid_t pid, int status);
+
void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis)
{
STATE_AO_GC(dis->ao);
@@ -1567,6 +1571,8 @@ void libxl__destroy_domid(libxl__egc *egc, libxl__destroy_domid_state *dis)
char *pid;
int rc, dm_present;
+ libxl__ev_child_init(&dis->destroyer);
+
rc = libxl_domain_info(ctx, NULL, domid);
switch(rc) {
case 0:
@@ -1672,17 +1678,58 @@ static void devices_destroy_cb(libxl__egc *egc,
libxl__unlock_domain_userdata(lock);
- rc = xc_domain_destroy(ctx->xch, domid);
- if (rc < 0) {
- LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, rc, "xc_domain_destroy failed for %d", domid);
+ rc = libxl__ev_child_fork(gc, &dis->destroyer, domain_destroy_domid_cb);
+ if (rc < 0) goto out;
+ if (!rc) { /* child */
+ ctx->xch = xc_interface_open(ctx->lg,0,0);
+ if (!ctx->xch) goto badchild;
+
+ rc = xc_domain_destroy(ctx->xch, domid);
+ if (rc < 0) goto badchild;
+ _exit(0);
+
+ badchild:
+ if (errno > 0 && errno < 126) {
+ _exit(errno);
+ } else {
+ LOGE(ERROR,
+ "xc_domain_destroy failed for %d (with difficult errno value %d)",
+ domid, errno);
+ _exit(-1);
+ }
+ }
+ LOG(INFO, "forked pid %ld for destroy of domain %d", (long)rc, domid);
+
+ return;
+
+out:
+ dis->callback(egc, dis, rc);
+ return;
+}
+
+static void domain_destroy_domid_cb(libxl__egc *egc,
+ libxl__ev_child *destroyer,
+ pid_t pid, int status)
+{
+ libxl__destroy_domid_state *dis = CONTAINER_OF(destroyer, *dis, destroyer);
+ STATE_AO_GC(dis->ao);
+ int rc;
+
+ if (status) {
+ if (WIFEXITED(status) && WEXITSTATUS(status)<126) {
+ LOGEV(ERROR, WEXITSTATUS(status),
+ "xc_domain_destroy failed for %"PRIu32"", dis->domid);
+ } else {
+ libxl_report_child_exitstatus(CTX, XTL_ERROR,
+ "async domain destroy", pid, status);
+ }
rc = ERROR_FAIL;
goto out;
}
rc = 0;
-out:
+ out:
dis->callback(egc, dis, rc);
- return;
}
int libxl_console_exec(libxl_ctx *ctx, uint32_t domid, int cons_num,
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index 934465a..28d32ef 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -2957,6 +2957,7 @@ struct libxl__destroy_domid_state {
libxl__domid_destroy_cb *callback;
/* private to implementation */
libxl__devices_remove_state drs;
+ libxl__ev_child destroyer;
};
struct libxl__domain_destroy_state {
--
1.8.0.1
[-- Attachment #3: Type: text/plain, Size: 126 bytes --]
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
http://lists.xen.org/xen-devel
next prev parent reply other threads:[~2015-03-20 15:14 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-03-17 15:30 [PATCH 0/3] libxl: Fixes from Ian Jackson Jim Fehlig
2015-03-17 15:30 ` [PATCH 1/3] libxl: In domain death search, start search at first domid we want Jim Fehlig
2015-03-17 17:34 ` Wei Liu
2015-03-18 12:19 ` Ian Campbell
2015-03-18 17:47 ` Jim Fehlig
2015-03-19 10:22 ` Ian Campbell
2015-03-17 15:30 ` [PATCH 2/3] libxl: Domain destroy: unlock userdata earlier Jim Fehlig
2015-03-17 17:34 ` Wei Liu
2015-03-18 12:20 ` Ian Campbell
2015-03-18 17:52 ` Jim Fehlig
2015-03-20 11:58 ` Ian Campbell
2015-03-17 15:30 ` [PATCH 3/3] libxl: Domain destroy: fork Jim Fehlig
2015-03-17 18:04 ` Wei Liu
2015-03-18 12:28 ` Ian Campbell
2015-03-18 12:27 ` Ian Campbell
2015-03-20 15:14 ` Jim Fehlig [this message]
2015-03-20 16:03 ` Ian Campbell
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=550C3953.7000604@suse.com \
--to=jfehlig@suse.com \
--cc=Ian.Jackson@eu.citrix.com \
--cc=ian.campbell@citrix.com \
--cc=wei.liu2@citrix.com \
--cc=xen-devel@lists.xen.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.