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

RE: [Xen-devel] [PATCH V5] libxl: make libxl communicate with xenstored

To: "Jun Zhu (Intern)" <Jun.Zhu@xxxxxxxxxx>
Subject: RE: [Xen-devel] [PATCH V5] libxl: make libxl communicate with xenstored by socket or xenbus driver
From: Ian Campbell <Ian.Campbell@xxxxxxxxxx>
Date: Fri, 17 Sep 2010 16:05:35 +0100
Cc: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>, Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Delivery-date: Fri, 17 Sep 2010 08:06:27 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <1284733628.16095.3772.camel@xxxxxxxxxxxxxxxxxxxxxx>
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>
Organization: Citrix Systems, Inc.
References: <433DDF91DFB08148BAD3FDB6FDDA314C9F35F3BB70@xxxxxxxxxxxxxxxxxxxxxxxxx> <1284733628.16095.3772.camel@xxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
On Fri, 2010-09-17 at 15:27 +0100, Ian Campbell wrote:
> 
> This is libxl__domain_suspend_common_switch_qemu_logdirty[0] which is
> used as a callback from xc_domain_suspend. IMHO any function which
> takes
> a callback should also take a void * closure, which in this case could
> be used to pass the context from the caller of xc_domain_save to this
> function. 

e.g. this (untested) patch:

# HG changeset patch
# User Ian Campbell <ian.campbell@xxxxxxxxxx>
# Date 1284735849 -3600
# Node ID ef0d82c6be32792167870d77d9655efa268e642f
# Parent  e8d0ecb9746aa9273e5a36cf561fc1bd8bce3714
tools: add closure to xc_domain_save switch_qemu_logdirty callback

Also move the function into struct save_callbacks with the others.

Use this in libxl to pass the save context to
libxl__domain_suspend_common_switch_qemu_logdirty allowing us to reuse
the parents xenstore handle, gc context etc.

Also add an apparently missing libxl__free_all to
libxl__domain_suspend_common.

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

diff -r e8d0ecb9746a -r ef0d82c6be32 tools/libxc/xc_domain_save.c
--- a/tools/libxc/xc_domain_save.c      Fri Sep 17 14:41:26 2010 +0100
+++ b/tools/libxc/xc_domain_save.c      Fri Sep 17 16:04:09 2010 +0100
@@ -879,7 +879,7 @@ int xc_domain_save(xc_interface *xch, in
 int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t 
max_iters,
                    uint32_t max_factor, uint32_t flags,
                    struct save_callbacks* callbacks,
-                   int hvm, void (*switch_qemu_logdirty)(int, unsigned))
+                   int hvm)
 {
     xc_dominfo_t info;
     DECLARE_DOMCTL;
@@ -1015,7 +1015,7 @@ int xc_domain_save(xc_interface *xch, in
 
         /* Enable qemu-dm logging dirty pages to xen */
         if ( hvm )
-            switch_qemu_logdirty(dom, 1);
+            callbacks->switch_qemu_logdirty(dom, 1, callbacks->data);
     }
     else
     {
@@ -1876,7 +1876,7 @@ int xc_domain_save(xc_interface *xch, in
                                NULL, 0, NULL, 0, NULL) < 0 )
             DPRINTF("Warning - couldn't disable shadow mode");
         if ( hvm )
-            switch_qemu_logdirty(dom, 0);
+            callbacks->switch_qemu_logdirty(dom, 0, callbacks->data);
     }
 
     if ( live_shinfo )
diff -r e8d0ecb9746a -r ef0d82c6be32 tools/libxc/xenguest.h
--- a/tools/libxc/xenguest.h    Fri Sep 17 14:41:26 2010 +0100
+++ b/tools/libxc/xenguest.h    Fri Sep 17 16:04:09 2010 +0100
@@ -40,6 +40,8 @@ struct save_callbacks {
      * 1: take another checkpoint */
     int (*checkpoint)(void* data);
 
+    void (*switch_qemu_logdirty)(int domid, unsigned enable, void *data); /* 
HVM only */
+
     /* to be provided as the first argument to each callback function */
     void* data;
 };
@@ -55,7 +57,7 @@ int xc_domain_save(xc_interface *xch, in
 int xc_domain_save(xc_interface *xch, int io_fd, uint32_t dom, uint32_t 
max_iters,
                    uint32_t max_factor, uint32_t flags /* XCFLAGS_xxx */,
                    struct save_callbacks* callbacks,
-                   int hvm, void (*switch_qemu_logdirty)(int, unsigned)); /* 
HVM only */
+                   int hvm);
 
 
 /**
diff -r e8d0ecb9746a -r ef0d82c6be32 tools/libxl/libxl_dom.c
--- a/tools/libxl/libxl_dom.c   Fri Sep 17 14:41:26 2010 +0100
+++ b/tools/libxl/libxl_dom.c   Fri Sep 17 16:04:09 2010 +0100
@@ -325,21 +325,18 @@ struct suspendinfo {
     unsigned int flags;
 };
 
-static void libxl__domain_suspend_common_switch_qemu_logdirty(int domid, 
unsigned int enable)
+static void libxl__domain_suspend_common_switch_qemu_logdirty(int domid, 
unsigned int enable, void *data)
 {
-    struct xs_handle *xsh;
-    char path[64];
+    struct suspendinfo *si = data;
+    libxl_ctx *ctx = libxl__gc_owner(si->gc);
+    char *path;
 
-    snprintf(path, sizeof(path), 
"/local/domain/0/device-model/%u/logdirty/cmd", domid);
-
-    xsh = xs_daemon_open();
+    path = libxl__sprintf(si->gc, 
"/local/domain/0/device-model/%u/logdirty/cmd", domid);
 
     if (enable)
-        xs_write(xsh, XBT_NULL, path, "enable", strlen("enable"));
+        xs_write(ctx->xsh, XBT_NULL, path, "enable", strlen("enable"));
     else
-        xs_write(xsh, XBT_NULL, path, "disable", strlen("disable"));
-
-    xs_daemon_close(xsh);
+        xs_write(ctx->xsh, XBT_NULL, path, "disable", strlen("disable"));
 }
 
 static int libxl__domain_suspend_common_callback(void *data)
@@ -437,11 +434,11 @@ int libxl__domain_suspend_common(libxl_c
 
     memset(&callbacks, 0, sizeof(callbacks));
     callbacks.suspend = libxl__domain_suspend_common_callback;
+    callbacks.switch_qemu_logdirty = 
libxl__domain_suspend_common_switch_qemu_logdirty;
     callbacks.data = &si;
 
     xc_domain_save(ctx->xch, fd, domid, 0, 0, flags,
-                   &callbacks, hvm,
-                   &libxl__domain_suspend_common_switch_qemu_logdirty);
+                   &callbacks, hvm);
 
     if (si.suspend_eventchn > 0)
         xc_suspend_evtchn_release(ctx->xch, si.xce, domid, 
si.suspend_eventchn);
@@ -450,6 +447,7 @@ int libxl__domain_suspend_common(libxl_c
 
     rc = 0;
 out:
+    libxl__free_all(&gc);
     return rc;
 }
 
diff -r e8d0ecb9746a -r ef0d82c6be32 tools/xcutils/xc_save.c
--- a/tools/xcutils/xc_save.c   Fri Sep 17 14:41:26 2010 +0100
+++ b/tools/xcutils/xc_save.c   Fri Sep 17 16:04:09 2010 +0100
@@ -102,7 +102,7 @@ static int suspend(void* data)
  * active buffer. */
 
 
-static void switch_qemu_logdirty(int domid, unsigned int enable)
+static void switch_qemu_logdirty(int domid, unsigned int enable, void *data)
 {
     struct xs_handle *xs;
     char *path, *p, *ret_str, *cmd_str, **watch;
@@ -205,9 +205,9 @@ main(int argc, char **argv)
     }
     memset(&callbacks, 0, sizeof(callbacks));
     callbacks.suspend = suspend;
+    callbacks.switch_qemu_logdirty = switch_qemu_logdirty;
     ret = xc_domain_save(si.xch, io_fd, si.domid, maxit, max_f, si.flags, 
-                         &callbacks, !!(si.flags & XCFLAGS_HVM),
-                         &switch_qemu_logdirty);
+                         &callbacks, !!(si.flags & XCFLAGS_HVM));
 
     if (si.suspend_evtchn > 0)
         xc_suspend_evtchn_release(si.xch, si.xce, si.domid, si.suspend_evtchn);



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