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>, Ian Campbell <Ian.Campbell@xxxxxxxxxxxxx>
Subject: RE: [Xen-devel] [PATCH V5] libxl: make libxl communicate with xenstored by socket or xenbus driver
From: "Jun Zhu (Intern)" <Jun.Zhu@xxxxxxxxxx>
Date: Fri, 17 Sep 2010 15:12:24 +0100
Accept-language: en-US
Acceptlanguage: en-US
Cc: "xen-devel@xxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxx>, Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Delivery-date: Fri, 17 Sep 2010 07:14:27 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <433DDF91DFB08148BAD3FDB6FDDA314C9F35F3BB70@xxxxxxxxxxxxxxxxxxxxxxxxx>
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: <433DDF91DFB08148BAD3FDB6FDDA314C9F35F3BB70@xxxxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Thread-index: AQHLVnCncF5V3cCTlkyVxg6tcKf9kJMWN9GX
Thread-topic: [Xen-devel] [PATCH V5] libxl: make libxl communicate with xenstored by socket or xenbus driver
Sorry. The V5 version has one place conflicting with another patch. I will make 
a new one soon.

Jun Zhu
Citrix Systems UK
________________________________________
From: Jun Zhu (Intern)
Sent: 17 September 2010 10:02
To: Ian Campbell
Cc: Ian Jackson; xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: RE: [Xen-devel] [PATCH V5] libxl: make libxl communicate with 
xenstored by socket or xenbus driver

This version adds gc as a parameter to libxl__xs_open, and uses 
LIBXL__LOG_ERRNO for logging. If some functions cannot use the ctx, It should 
transfer NULL to libxl__xs_open to disable logging. (But it will make users 
difficult to find the problem when no logging is output.)
To make consistent with other functions in libxl__xshelp.c, I use gc as its 
parameter, not ctx. In the libxl_ctx_init function, I add “libxl__gc gc = 
LIBXL_INIT_GC(ctx)” to get the gc of ctx. Please check this.

Signed-off-by: Jun Zhu <Jun.Zhu@xxxxxxxxxx>

diff -r cca905a429aa tools/libxl/libxl.c
--- a/tools/libxl/libxl.c       Tue Sep 14 15:39:36 2010 +0100
+++ b/tools/libxl/libxl.c       Fri Sep 17 14:58:50 2010 +0100
@@ -40,6 +40,8 @@

 int libxl_ctx_init(libxl_ctx *ctx, int version, xentoollog_logger *lg)
 {
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
+
     if (version != LIBXL_VERSION)
         return ERROR_VERSION;
     memset(ctx, 0, sizeof(libxl_ctx));
@@ -53,12 +55,8 @@
         return ERROR_FAIL;
     }

-    ctx->xsh = xs_daemon_open();
-    if (!ctx->xsh)
-        ctx->xsh = xs_domain_open();
+    ctx->xsh = libxl__xs_open(&gc);
     if (!ctx->xsh) {
-        LIBXL__LOG_ERRNOVAL(ctx, LIBXL__LOG_ERROR, errno,
-                        "cannot connect to xenstore");
         xc_interface_close(ctx->xch);
         return ERROR_FAIL;
     }
@@ -69,7 +67,7 @@
 {
     if (ctx->xch) xc_interface_close(ctx->xch);
     libxl_version_info_destroy(&ctx->version_info);
-    if (ctx->xsh) xs_daemon_close(ctx->xsh);
+    if (ctx->xsh) libxl__xs_close(ctx->xsh);
     return 0;
 }

@@ -901,8 +899,7 @@
         ret = libxl_domain_destroy(ctx, stubdomid, 0);
         if (ret)
             goto out;
-    }
-    else {
+    } else {
         ret = kill(atoi(pid), SIGHUP);
         if (ret < 0 && errno == ESRCH) {
             LIBXL__LOG(ctx, LIBXL__LOG_DEBUG, "Device Model already exited");
@@ -1395,21 +1392,22 @@
 {
     libxl_device_model_starting *starting = for_spawn;
     char *kvs[3];
-    int rc;
     struct xs_handle *xsh;

-    xsh = xs_daemon_open();
-    /* we mustn't use the parent's handle in the child */
-
     kvs[0] = "image/device-model-pid";
     if (asprintf(&kvs[1], "%d", innerchild) < 0)
         return;
     kvs[2] = NULL;

-    rc = xs_writev(xsh, XBT_NULL, starting->dom_path, kvs);
-    if (rc)
-        return;
-    xs_daemon_close(xsh);
+    /* we mustn't use the parent's handle in the child */
+    xsh = libxl__xs_open(NULL);
+    if (!xsh)
+        goto out;
+    xs_writev(xsh, XBT_NULL, starting->dom_path, kvs);
+    libxl__xs_close(xsh);
+
+out:
+    free(kvs[1]);
 }

 static int libxl_vfb_and_vkb_from_device_model_info(libxl_ctx *ctx,
diff -r cca905a429aa tools/libxl/libxl_device.c
--- a/tools/libxl/libxl_device.c        Tue Sep 14 15:39:36 2010 +0100
+++ b/tools/libxl/libxl_device.c        Fri Sep 17 14:58:50 2010 +0100
@@ -405,7 +405,10 @@
     unsigned int num;
     char **l = NULL;

-    xsh = xs_daemon_open();
+    xsh = libxl__xs_open(&gc);
+    if (!xsh)
+        return -1;
+
     path = libxl__sprintf(&gc, "/local/domain/0/device-model/%d/state", domid);
     xs_watch(xsh, path, path);
     tv.tv_sec = LIBXL_DEVICE_MODEL_START_TIMEOUT;
@@ -427,7 +430,7 @@

         free(p);
         xs_unwatch(xsh, path, path);
-        xs_daemon_close(xsh);
+        libxl__xs_close(xsh);
         libxl__free_all(&gc);
         return rc;
 again:
@@ -444,7 +447,7 @@
         }
     }
     xs_unwatch(xsh, path, path);
-    xs_daemon_close(xsh);
+    libxl__xs_close(xsh);
     LIBXL__LOG(ctx, LIBXL__LOG_ERROR, "Device Model not ready");
     libxl__free_all(&gc);
     return -1;
diff -r cca905a429aa tools/libxl/libxl_dom.c
--- a/tools/libxl/libxl_dom.c   Tue Sep 14 15:39:36 2010 +0100
+++ b/tools/libxl/libxl_dom.c   Fri Sep 17 14:58:50 2010 +0100
@@ -326,14 +326,16 @@

     snprintf(path, sizeof(path), 
"/local/domain/0/device-model/%u/logdirty/cmd", domid);

-    xsh = xs_daemon_open();
+    xsh = libxl__xs_open(NULL);
+    if (!xsh)
+        return;

     if (enable)
         xs_write(xsh, XBT_NULL, path, "enable", strlen("enable"));
     else
         xs_write(xsh, XBT_NULL, path, "disable", strlen("disable"));

-    xs_daemon_close(xsh);
+    libxl__xs_close(xsh);
 }

 static int libxl__domain_suspend_common_callback(void *data)
diff -r cca905a429aa tools/libxl/libxl_internal.h
--- a/tools/libxl/libxl_internal.h      Tue Sep 14 15:39:36 2010 +0100
+++ b/tools/libxl/libxl_internal.h      Fri Sep 17 14:58:50 2010 +0100
@@ -138,6 +138,8 @@
 _hidden char *libxl__xs_get_dompath(libxl__gc *gc, uint32_t domid); // logs 
errs
 _hidden char *libxl__xs_read(libxl__gc *gc, xs_transaction_t t, char *path);
 _hidden char **libxl__xs_directory(libxl__gc *gc, xs_transaction_t t, char 
*path, unsigned int *nb);
+_hidden struct xs_handle *libxl__xs_open(libxl__gc *gc);
+_hidden void libxl__xs_close(struct xs_handle *xsh);

 /* from xl_dom */
 _hidden int libxl__domain_is_hvm(libxl_ctx *ctx, uint32_t domid);
diff -r cca905a429aa tools/libxl/libxl_utils.c
--- a/tools/libxl/libxl_utils.c Tue Sep 14 15:39:36 2010 +0100
+++ b/tools/libxl/libxl_utils.c Fri Sep 17 14:58:50 2010 +0100
@@ -366,9 +366,11 @@


 int libxl_ctx_postfork(libxl_ctx *ctx) {
+    libxl__gc gc = LIBXL_INIT_GC(ctx);
     if (ctx->xsh) xs_daemon_destroy_postfork(ctx->xsh);
-    ctx->xsh = xs_daemon_open();
-    if (!ctx->xsh) return ERROR_FAIL;
+    ctx->xsh = libxl__xs_open(&gc);
+    if (!ctx->xsh)
+        return ERROR_FAIL;
     return 0;
 }

diff -r cca905a429aa tools/libxl/libxl_xshelp.c
--- a/tools/libxl/libxl_xshelp.c        Tue Sep 14 15:39:36 2010 +0100
+++ b/tools/libxl/libxl_xshelp.c        Fri Sep 17 14:58:50 2010 +0100
@@ -141,3 +141,21 @@
     libxl__ptr_add(gc, ret);
     return ret;
 }
+
+struct xs_handle *libxl__xs_open(libxl__gc *gc)
+{
+    libxl_ctx *ctx = libxl__gc_owner(gc);
+    struct xs_handle *xsh = NULL;
+
+    xsh = xs_daemon_open();
+    if (!xsh)
+        xsh = xs_domain_open();
+    if (!xsh && !gc)
+        LIBXL__LOG_ERRNO(ctx, LIBXL__LOG_ERROR, "cannot connect to xenstore");
+    return xsh;
+}
+
+void libxl__xs_close(struct xs_handle *xsh)
+{
+    xs_daemon_close(xsh);
+}

Jun Zhu
Citrix Systems UK
________________________________________

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