WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH 20 of 22] xenpaging: add watch thread to catch guest

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH 20 of 22] xenpaging: add watch thread to catch guest shutdown
From: Olaf Hering <olaf@xxxxxxxxx>
Date: Fri, 10 Jun 2011 11:13:09 +0200
Delivery-date: Fri, 10 Jun 2011 02:32:43 -0700
Dkim-signature: v=1; a=rsa-sha1; c=relaxed/relaxed; t=1307697188; l=2559; s=domk; d=aepfle.de; h=To:From:Date:References:In-Reply-To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:X-RZG-CLASS-ID: X-RZG-AUTH; bh=z2t5gjWZFzVRJYrbn854H1zbKRw=; b=BrKUVgTNZU62Lsb4zn/3///uOzOXd+vQH4DpTUFME5J2Zc9zwcd5WYCryF+A5C5Pd3i RkurQomRoBn/piJeDEVD6aOB1hXRBNzaNicHvMclEIhSa7RjHTxBCoI0BW6wrqgVwzLeN gbaMAgeEoBsdHxH1ykLr14/PuEivghGmO0Q=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1307697169@xxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <patchbomb.1307697169@xxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.7.5
# HG changeset patch
# User Olaf Hering <olaf@xxxxxxxxx>
# Date 1307695647 -7200
# Node ID 3446ab4866249018b1611fdfe430cbb2ff2a5b31
# Parent  c375ced18c763dd7dcebfdc923f1d5154656b578
xenpaging: add watch thread to catch guest shutdown

If xenpaging is started manually then no event is sent to xenpaging when
the guest is shutdown or rebooted.  Add a watch on the @releaseDomain
node to leave the loop and gracefully shutdown the pager.

Signed-off-by: Olaf Hering <olaf@xxxxxxxxx>

diff -r c375ced18c76 -r 3446ab486624 tools/xenpaging/xenpaging.c
--- a/tools/xenpaging/xenpaging.c       Fri Jun 10 10:47:25 2011 +0200
+++ b/tools/xenpaging/xenpaging.c       Fri Jun 10 10:47:27 2011 +0200
@@ -39,6 +39,7 @@
 #include "policy.h"
 #include "xenpaging.h"
 
+static char watch_token[16];
 static char filename[80];
 static int interrupted;
 
@@ -75,13 +76,19 @@ static int xenpaging_wait_for_event_or_t
 {
     xc_interface *xch = paging->xc_handle;
     xc_evtchn *xce = paging->mem_event.xce_handle;
-    struct pollfd fd[1];
+    char **vec;
+    unsigned int num;
+    struct pollfd fd[2];
     int port;
     int rc;
 
+    /* Wait for event channel and xenstore */
     fd[0].fd = xc_evtchn_fd(xce);
     fd[0].events = POLLIN | POLLERR;
-    rc = poll(fd, 1, 100);
+    fd[1].fd = xs_fileno(paging->xs_handle);
+    fd[1].events = POLLIN | POLLERR;
+
+    rc = poll(fd, 2, 100);
     if ( rc < 0 )
     {
         if (errno == EINTR)
@@ -91,6 +98,27 @@ static int xenpaging_wait_for_event_or_t
         return -errno;
     }
 
+    /* First check for guest shutdown */
+    if ( rc && fd[1].revents & POLLIN )
+    {
+        DPRINTF("Got event from xenstore\n");
+        vec = xs_read_watch(paging->xs_handle, &num);
+        if ( vec )
+        {
+            if ( strcmp(vec[XS_WATCH_TOKEN], watch_token) == 0 )
+            {
+                /* If our guest disappeared, set interrupt flag and fall 
through */
+                if ( xs_is_domain_introduced(paging->xs_handle, 
paging->mem_event.domain_id) == false )
+                {
+                    xs_unwatch(paging->xs_handle, "@releaseDomain", 
watch_token);
+                    interrupted = SIGQUIT;
+                    rc = 0;
+                }
+            }
+            free(vec);
+        }
+    }
+
     if ( rc && fd[0].revents & POLLIN )
     {
         DPRINTF("Got event from evtchn\n");
@@ -165,6 +193,14 @@ static xenpaging_t *xenpaging_init(domid
         goto err;
     }
 
+    /* write domain ID to watch so we can ignore other domain shutdowns */
+    snprintf(watch_token, sizeof(watch_token), "%u", domain_id);
+    if ( xs_watch(paging->xs_handle, "@releaseDomain", watch_token) == false )
+    {
+        ERROR("Could not bind to shutdown watch\n");
+        goto err;
+    }
+
     p = getenv("XENPAGING_POLICY_MRU_SIZE");
     if ( p && *p )
     {

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel