xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Ian Campbell <ian.campbell@citrix.com>
To: xen-devel@lists.xensource.com
Cc: Ian Campbell <ian.campbell@citrix.com>
Subject: [PATCH 2 of 9] libxl: return libxl_dominfo from libxl_event_get_domain_death_info
Date: Mon, 26 Jul 2010 11:56:46 +0100	[thread overview]
Message-ID: <f6300d42a667cf6a1a02.1280141806@localhost.localdomain> (raw)
In-Reply-To: <patchbomb.1280141804@localhost.localdomain>

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1280140562 -3600
# Node ID f6300d42a667cf6a1a02fc065ecd9eaea0e10ecc
# Parent  7a0c37f2a9b51ac012a32bcf6ab222580e7cac94
libxl: return libxl_dominfo from libxl_event_get_domain_death_info

Removes a libxc data type from the libxl interface.


Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

diff -r 7a0c37f2a9b5 -r f6300d42a667 tools/libxl/libxl.c
--- a/tools/libxl/libxl.c	Mon Jul 26 11:36:02 2010 +0100
+++ b/tools/libxl/libxl.c	Mon Jul 26 11:36:02 2010 +0100
@@ -405,8 +405,6 @@ static void xcinfo2xlinfo(const xc_domai
 static void xcinfo2xlinfo(const xc_domaininfo_t *xcinfo,
                           struct libxl_dominfo *xlinfo)
 {
-    unsigned int shutdown_reason;
-
     memcpy(&(xlinfo->uuid), xcinfo->handle, sizeof(xen_domain_handle_t));
     xlinfo->domid = xcinfo->domain;
 
@@ -416,12 +414,28 @@ static void xcinfo2xlinfo(const xc_domai
     xlinfo->blocked  = !!(xcinfo->flags&XEN_DOMINF_blocked);
     xlinfo->running  = !!(xcinfo->flags&XEN_DOMINF_running);
     xlinfo->crashed  = 0;
+    xlinfo->shutdown_reason  = -1;
 
-    shutdown_reason = (xcinfo->flags>>XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask;
-
-    if ( xlinfo->shutdown && (shutdown_reason == SHUTDOWN_crash) ) {
-        xlinfo->shutdown = 0;
-        xlinfo->crashed  = 1;
+    if (xlinfo->shutdown) {
+        switch ((xcinfo->flags>>XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask) {
+        case SHUTDOWN_poweroff:
+            xlinfo->shutdown_reason = LIBXL_SHUTDOWN_POWEROFF;
+            break;
+        case SHUTDOWN_reboot:
+            xlinfo->shutdown_reason = LIBXL_SHUTDOWN_REBOOT;
+            break;
+        case SHUTDOWN_suspend:
+            xlinfo->shutdown_reason = LIBXL_SHUTDOWN_SUSPEND;
+            break;
+        case SHUTDOWN_crash:
+            xlinfo->shutdown_reason = LIBXL_SHUTDOWN_CRASH;
+            xlinfo->shutdown = 0;
+            xlinfo->crashed  = 1;
+            break;
+        case SHUTDOWN_watchdog:
+            xlinfo->shutdown_reason = LIBXL_SHUTDOWN_WATCHDOG;
+            break;
+        }
     }
 
     xlinfo->max_memkb = PAGE_TO_MEMKB(xcinfo->tot_pages);
@@ -707,20 +721,19 @@ int libxl_free_waiter(libxl_waiter *wait
     return 0;
 }
 
-int libxl_event_get_domain_death_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, xc_domaininfo_t *info)
+int libxl_event_get_domain_death_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, struct libxl_dominfo *info)
 {
     int rc = 0, ret;
+    if (event && event->type == LIBXL_EVENT_DOMAIN_DEATH) {
+        ret = libxl_domain_info(ctx, info, domid);
 
-    if (event && event->type == LIBXL_EVENT_DOMAIN_DEATH) {
-        ret = xc_domain_getinfolist(ctx->xch, domid, 1, info);
-        if (ret == 1 && info->domain == domid) {
-                if (info->flags & XEN_DOMINF_running ||
-                    (!(info->flags & XEN_DOMINF_shutdown) && !(info->flags & XEN_DOMINF_dying)))
+        if (ret == 0 && info->domid == domid) {
+            if (info->running || (!info->shutdown && !info->dying && !info->crashed))
                     goto out;
                 rc = 1;
                 goto out;
         }
-        memset(info, 0, sizeof(xc_dominfo_t));
+        memset(info, 0, sizeof(*info));
         rc = 1;
         goto out;
     }
diff -r 7a0c37f2a9b5 -r f6300d42a667 tools/libxl/libxl.h
--- a/tools/libxl/libxl.h	Mon Jul 26 11:36:02 2010 +0100
+++ b/tools/libxl/libxl.h	Mon Jul 26 11:36:02 2010 +0100
@@ -22,6 +22,14 @@
 #include <xs.h>
 #include <sys/wait.h> /* for pid_t */
 
+enum libxl_shutdown_reason {
+    LIBXL_SHUTDOWN_POWEROFF,  /* Domain exited normally. Clean up and kill. */
+    LIBXL_SHUTDOWN_REBOOT,    /* Clean up, kill, and then restart.          */
+    LIBXL_SHUTDOWN_SUSPEND,   /* Clean up, save suspend info, kill.         */
+    LIBXL_SHUTDOWN_CRASH,     /* Tell controller we've crashed.             */
+    LIBXL_SHUTDOWN_WATCHDOG,  /* Restart because watchdog time expired.     */
+};
+
 struct libxl_dominfo {
     uint8_t uuid[16];
     uint32_t domid;
@@ -31,6 +39,8 @@ struct libxl_dominfo {
     uint8_t shutdown:1;
     uint8_t crashed:1;
     uint8_t dying:1;
+    enum libxl_shutdown_reason shutdown_reason;
+
     uint64_t max_memkb;
     uint64_t cpu_time;
     uint32_t vcpu_max_id;
@@ -385,7 +395,7 @@ int libxl_free_event(libxl_event *event)
 int libxl_free_event(libxl_event *event);
 int libxl_free_waiter(libxl_waiter *waiter);
 
-int libxl_event_get_domain_death_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, xc_domaininfo_t *info);
+int libxl_event_get_domain_death_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, struct libxl_dominfo *info);
 int libxl_event_get_disk_eject_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, libxl_device_disk *disk);
 
 int libxl_domain_rename(struct libxl_ctx *ctx, uint32_t domid,
diff -r 7a0c37f2a9b5 -r f6300d42a667 tools/libxl/xl_cmdimpl.c
--- a/tools/libxl/xl_cmdimpl.c	Mon Jul 26 11:36:02 2010 +0100
+++ b/tools/libxl/xl_cmdimpl.c	Mon Jul 26 11:36:02 2010 +0100
@@ -1335,7 +1335,7 @@ start:
     while (1) {
         int ret;
         fd_set rfds;
-        xc_domaininfo_t info;
+        struct libxl_dominfo info;
         libxl_event event;
         libxl_device_disk disk;
         memset(&info, 0x00, sizeof(xc_domaininfo_t));
@@ -1351,11 +1351,10 @@ start:
             case LIBXL_EVENT_DOMAIN_DEATH:
                 if (libxl_event_get_domain_death_info(&ctx, domid, &event, &info)) {
                     LOG("Domain %d is dead", domid);
-                    if (info.flags & XEN_DOMINF_dying || (info.flags & XEN_DOMINF_shutdown && (((info.flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask) != SHUTDOWN_suspend))) {
+                    if (info.crashed || info.dying || (info.shutdown && info.shutdown_reason != SHUTDOWN_suspend)) {
                         LOG("Domain %d needs to be clean: destroying the domain", domid);
                         libxl_domain_destroy(&ctx, domid, 0);
-                        if (info.flags & XEN_DOMINF_shutdown &&
-                            (((info.flags >> XEN_DOMINF_shutdownshift) & XEN_DOMINF_shutdownmask) == SHUTDOWN_reboot)) {
+                        if (info.shutdown && info.shutdown_reason == SHUTDOWN_reboot) {
                             libxl_free_waiter(w1);
                             libxl_free_waiter(w2);
                             free(w1);

  parent reply	other threads:[~2010-07-26 10:56 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-26 10:56 [PATCH 0 of 9] xl: handle domain shutdown/reboot/crash in a user configurable way Ian Campbell
2010-07-26 10:56 ` [PATCH 1 of 9] libxl: Add LIBXL_EVENT namespace to enum libxl_event_type Ian Campbell
2010-07-26 10:56 ` Ian Campbell [this message]
2010-07-26 14:32   ` [PATCH 2 of 9] libxl: return libxl_dominfo from libxl_event_get_domain_death_info Stefano Stabellini
2010-07-26 14:38     ` Ian Campbell
2010-07-26 14:59       ` Stefano Stabellini
2010-07-26 15:26   ` Ian Jackson
2010-07-26 15:31     ` Ian Campbell
2010-07-26 15:36       ` Ian Jackson
2010-07-26 15:34     ` Stefano Stabellini
2010-07-26 15:41       ` Ian Jackson
2010-07-26 16:23         ` Stefano Stabellini
2010-07-26 16:38           ` Ian Jackson
2010-07-27  9:22             ` Ian Campbell
2010-07-27  9:53             ` Stefano Stabellini
2010-07-26 10:56 ` [PATCH 3 of 9] libxl: signal caller if domain already destroyed on domain death event Ian Campbell
2010-07-26 14:32   ` Stefano Stabellini
2010-07-26 14:41     ` Ian Campbell
2010-07-26 14:58       ` Stefano Stabellini
2010-07-26 15:02         ` Ian Campbell
2010-07-26 15:08           ` Stefano Stabellini
2010-07-26 10:56 ` [PATCH 4 of 9] libxl: should consider shutdown_reason for dying as well as shutdown domains Ian Campbell
2010-07-26 10:56 ` [PATCH 5 of 9] libxl: add libxl_domain_preserve Ian Campbell
2010-07-26 15:30   ` Ian Jackson
2010-07-26 15:56     ` Ian Campbell
2010-07-26 10:56 ` [PATCH 6 of 9] xl: do not try and auto re-connect console on reboot Ian Campbell
2010-07-26 10:56 ` [PATCH 7 of 9] xl: Add function to generate random uuid and use it Ian Campbell
2010-07-26 10:56 ` [PATCH 8 of 9] xl: Factor out domain death handling into a separate function Ian Campbell
2010-07-26 10:56 ` [PATCH 9 of 9] xl: support on_{poweroff, reboot, crash} domain configuration options 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=f6300d42a667cf6a1a02.1280141806@localhost.localdomain \
    --to=ian.campbell@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 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).