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 3 of 9] libxl: signal caller if domain already destroyed on domain death event
Date: Mon, 26 Jul 2010 11:56:47 +0100	[thread overview]
Message-ID: <1e0b63948031587b958e.1280141807@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 1e0b63948031587b958ea307410d19c7b2be9614
# Parent  f6300d42a667cf6a1a02fc065ecd9eaea0e10ecc
libxl: signal caller if domain already destroyed on domain death event

Currently libxl_event_get_domain_death_info returns 0 if the event was
not a domain death event and 1 if it was but does not infom the user
if someone else has already cleaned up the domain, which means the
caller must replicate some of the logic from within libxl.

Instead have the libxl_event_get_XXX_info functions required that the
event is of the right type (the caller must have recently switched on
event->type anyway).

This allows the return codes to be used in an event specific way and
we take advantage of this by returning an error from
libxl_event_get_domain_death_info if the domain is not dying.

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

diff -r f6300d42a667 -r 1e0b63948031 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
@@ -721,54 +721,54 @@ int libxl_free_waiter(libxl_waiter *wait
     return 0;
 }
 
+/*
+ * Returns:
+ *  - 0 if the domain is dead and there is no cleanup to be done. e.g because someone else has already done it.
+ *  - 1 if the domain is dead and there is cleanup to be done.
+ *
+ * Can return error if the domain exists and is still running
+ */
 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 (libxl_domain_info(ctx, info, domid) < 0)
+        return 0;
 
-        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(*info));
-        rc = 1;
-        goto out;
-    }
-out:
-    return rc;
+    if (info->running || (!info->shutdown && !info->dying && !info->crashed))
+        return ERROR_INVAL;
+
+    return 1;
 }
 
+/*
+ * Returns true and fills *disk if the caller should eject the disk
+ */
 int libxl_event_get_disk_eject_info(struct libxl_ctx *ctx, uint32_t domid, libxl_event *event, libxl_device_disk *disk)
 {
-    if (event && event->type == LIBXL_EVENT_DISK_EJECT) {
-        char *path;
-        char *backend;
-        char *value = libxl_xs_read(ctx, XBT_NULL, event->path);
+    char *path;
+    char *backend;
+    char *value;
 
-        if (!value || strcmp(value,  "eject"))
-            return 0;
+    value = libxl_xs_read(ctx, XBT_NULL, event->path);
 
-        path = strdup(event->path);
-        path[strlen(path) - 6] = '\0';
-        backend = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/backend", path));
+    if (!value || strcmp(value,  "eject"))
+        return 0;
 
-        disk->backend_domid = 0;
-        disk->domid = domid;
-        disk->physpath = NULL;
-        disk->phystype = 0;
-        /* this value is returned to the user: do not free right away */
-        disk->virtpath = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/dev", backend));
-        disk->unpluggable = 1;
-        disk->readwrite = 0;
-        disk->is_cdrom = 1;
+    path = strdup(event->path);
+    path[strlen(path) - 6] = '\0';
+    backend = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/backend", path));
 
-        free(path);
-        return 1;
-    }
-    return 0;
+    disk->backend_domid = 0;
+    disk->domid = domid;
+    disk->physpath = NULL;
+    disk->phystype = 0;
+    /* this value is returned to the user: do not free right away */
+    disk->virtpath = libxl_xs_read(ctx, XBT_NULL, libxl_sprintf(ctx, "%s/dev", backend));
+    disk->unpluggable = 1;
+    disk->readwrite = 0;
+    disk->is_cdrom = 1;
+
+    free(path);
+    return 1;
 }
 
 static int libxl_destroy_device_model(struct libxl_ctx *ctx, uint32_t domid)
diff -r f6300d42a667 -r 1e0b63948031 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
@@ -1338,7 +1338,6 @@ start:
         struct libxl_dominfo info;
         libxl_event event;
         libxl_device_disk disk;
-        memset(&info, 0x00, sizeof(xc_domaininfo_t));
 
         FD_ZERO(&rfds);
         FD_SET(fd, &rfds);
@@ -1349,12 +1348,17 @@ start:
         libxl_get_event(&ctx, &event);
         switch (event.type) {
             case LIBXL_EVENT_DOMAIN_DEATH:
-                if (libxl_event_get_domain_death_info(&ctx, domid, &event, &info)) {
-                    LOG("Domain %d is dead", domid);
-                    if (info.crashed || info.dying || (info.shutdown && info.shutdown_reason != SHUTDOWN_suspend)) {
+                ret = libxl_event_get_domain_death_info(&ctx, domid, &event, &info);
+
+                if (ret < 0) continue;
+
+                LOG("Domain %d is dead", domid);
+
+                if (ret) {
+                    if (info.shutdown_reason != SHUTDOWN_suspend) {
                         LOG("Domain %d needs to be clean: destroying the domain", domid);
                         libxl_domain_destroy(&ctx, domid, 0);
-                        if (info.shutdown && info.shutdown_reason == SHUTDOWN_reboot) {
+                        if (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 ` [PATCH 2 of 9] libxl: return libxl_dominfo from libxl_event_get_domain_death_info Ian Campbell
2010-07-26 14:32   ` 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 ` Ian Campbell [this message]
2010-07-26 14:32   ` [PATCH 3 of 9] libxl: signal caller if domain already destroyed on domain death event 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=1e0b63948031587b958e.1280141807@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).