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 4 of 4] pyxl: Export libxl_domain_create_new() to pyt

To: <xen-devel@xxxxxxxxxxxxxxxxxxx>
Subject: [Xen-devel] [PATCH 4 of 4] pyxl: Export libxl_domain_create_new() to python binding
From: Gianni Tedesco <gianni.tedesco@xxxxxxxxxx>
Date: Wed, 12 Jan 2011 14:19:02 +0000
Cc: Ian Campbell <Ian.Campbell@xxxxxxxxxxxxx>, Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
Delivery-date: Wed, 12 Jan 2011 06:32:47 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <patchbomb.1294841938@xxxxxxxxxxxxxxxxxxxxxxx>
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.1294841938@xxxxxxxxxxxxxxxxxxxxxxx>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mercurial-patchbomb/1.6.3
 tools/libxl/libxl.h               |  45 ++++++----------------
 tools/libxl/libxl.idl             |  16 ++++++++
 tools/libxl/libxl_create.c        |  33 ----------------
 tools/python/xen/lowlevel/xl/xl.c |  76 +++++++++++++++++++++++++++++++++++++-
 4 files changed, 102 insertions(+), 68 deletions(-)


# HG changeset patch
# User Gianni Tedesco <gianni.tedesco@xxxxxxxxxx>
# Date 1294841273 0
# Node ID 7bf63de9fcdc67e5ad7579f0f2837373fdbab6e3
# Parent  7049135bb6b7c0ec9f1c7a4f616b3c6c0a035693
pyxl: Export libxl_domain_create_new() to python binding

This also moves struct libxl_domain_config to be an IDL generated type.

Signed-off-by: Gianni Tedesco <gianni.tedesco@xxxxxxxxxx>

diff -r 7049135bb6b7 -r 7bf63de9fcdc tools/libxl/libxl.h
--- a/tools/libxl/libxl.h       Wed Jan 12 14:07:53 2011 +0000
+++ b/tools/libxl/libxl.h       Wed Jan 12 14:07:53 2011 +0000
@@ -205,6 +205,18 @@ typedef struct libxl__cpuid_policy libxl
 typedef libxl_cpuid_policy * libxl_cpuid_policy_list;
 void libxl_cpuid_destroy(libxl_cpuid_policy_list *cpuid_list);
 
+enum libxl_action_on_shutdown {
+    LIBXL_ACTION_DESTROY,
+
+    LIBXL_ACTION_RESTART,
+    LIBXL_ACTION_RESTART_RENAME,
+
+    LIBXL_ACTION_PRESERVE,
+
+    LIBXL_ACTION_COREDUMP_DESTROY,
+    LIBXL_ACTION_COREDUMP_RESTART,
+};
+
 #define LIBXL_PCI_FUNC_ALL (~0U)
 
 #include "_libxl_types.h"
@@ -241,38 +253,6 @@ enum {
 
 #define LIBXL_VERSION 0
 
-enum libxl_action_on_shutdown {
-    LIBXL_ACTION_DESTROY,
-
-    LIBXL_ACTION_RESTART,
-    LIBXL_ACTION_RESTART_RENAME,
-
-    LIBXL_ACTION_PRESERVE,
-
-    LIBXL_ACTION_COREDUMP_DESTROY,
-    LIBXL_ACTION_COREDUMP_RESTART,
-};
-
-typedef struct {
-    libxl_domain_create_info c_info;
-    libxl_domain_build_info b_info;
-    libxl_device_model_info dm_info;
-
-    int num_disks, num_vifs, num_vif2s, num_pcidevs, num_vfbs, num_vkbs;
-
-    libxl_device_disk *disks;
-    libxl_device_nic *vifs;
-    libxl_device_net2 *vif2s;
-    libxl_device_pci *pcidevs;
-    libxl_device_vfb *vfbs;
-    libxl_device_vkb *vkbs;
-
-    enum libxl_action_on_shutdown on_poweroff;
-    enum libxl_action_on_shutdown on_reboot;
-    enum libxl_action_on_shutdown on_watchdog;
-    enum libxl_action_on_shutdown on_crash;
-} libxl_domain_config;
-
 /* context functions */
 int libxl_ctx_init(libxl_ctx *ctx, int version, xentoollog_logger*);
 int libxl_ctx_free(libxl_ctx *ctx);
@@ -286,7 +266,6 @@ void libxl_init_dm_info(libxl_device_mod
 typedef int (*libxl_console_ready)(libxl_ctx *ctx, uint32_t domid, void *priv);
 int libxl_domain_create_new(libxl_ctx *ctx, libxl_domain_config *d_config, 
libxl_console_ready cb, void *priv, uint32_t *domid);
 int libxl_domain_create_restore(libxl_ctx *ctx, libxl_domain_config *d_config, 
libxl_console_ready cb, void *priv, uint32_t *domid, int restore_fd);
-void libxl_domain_config_destroy(libxl_domain_config *d_config);
 int libxl_domain_suspend(libxl_ctx *ctx, libxl_domain_suspend_info *info,
                           uint32_t domid, int fd);
 int libxl_domain_resume(libxl_ctx *ctx, uint32_t domid);
diff -r 7049135bb6b7 -r 7bf63de9fcdc tools/libxl/libxl.idl
--- a/tools/libxl/libxl.idl     Wed Jan 12 14:07:53 2011 +0000
+++ b/tools/libxl/libxl.idl     Wed Jan 12 14:07:53 2011 +0000
@@ -328,3 +328,19 @@ libxl_net2info = Struct("net2info", [
     ("back_mac", libxl_mac),
     ("filter_mac", integer),
     ])
+
+libxl_domain_config = Struct("domain_config", [
+    ("c_info", libxl_domain_create_info),
+    ("b_info", libxl_domain_build_info),
+    ("dm_info", libxl_device_model_info),
+    ("disks", Array(libxl_device_disk)),
+    ("vifs", Array(libxl_device_nic)),
+    ("vif2s", Array(libxl_device_net2)),
+    ("pcidevs", Array(libxl_device_pci)),
+    ("vfbs", Array(libxl_device_vfb)),
+    ("vkbs", Array(libxl_device_vkb)),
+    ("on_poweroff", Enum("libxl_action_on_shutdown")),
+    ("on_reboot", Enum("libxl_action_on_shutdown")),
+    ("on_watchdog", Enum("libxl_action_on_shutdown")),
+    ("on_crash", Enum("libxl_action_on_shutdown")),
+    ])
diff -r 7049135bb6b7 -r 7bf63de9fcdc tools/libxl/libxl_create.c
--- a/tools/libxl/libxl_create.c        Wed Jan 12 14:07:53 2011 +0000
+++ b/tools/libxl/libxl_create.c        Wed Jan 12 14:07:53 2011 +0000
@@ -27,39 +27,6 @@
 #include "libxl_internal.h"
 #include "flexarray.h"
 
-void libxl_domain_config_destroy(libxl_domain_config *d_config)
-{
-    int i;
-
-    for (i=0; i<d_config->num_disks; i++)
-        libxl_device_disk_destroy(&d_config->disks[i]);
-    free(d_config->disks);
-
-    for (i=0; i<d_config->num_vifs; i++)
-        libxl_device_nic_destroy(&d_config->vifs[i]);
-    free(d_config->vifs);
-
-    for (i=0; i<d_config->num_vif2s; i++)
-        libxl_device_net2_destroy(&d_config->vif2s[i]);
-    free(d_config->vif2s);
-
-    for (i=0; i<d_config->num_pcidevs; i++)
-        libxl_device_pci_destroy(&d_config->pcidevs[i]);
-    free(d_config->pcidevs);
-
-    for (i=0; i<d_config->num_vfbs; i++)
-        libxl_device_vfb_destroy(&d_config->vfbs[i]);
-    free(d_config->vfbs);
-
-    for (i=0; i<d_config->num_vkbs; i++)
-        libxl_device_vkb_destroy(&d_config->vkbs[i]);
-    free(d_config->vkbs);
-
-    libxl_domain_create_info_destroy(&d_config->c_info);
-    libxl_domain_build_info_destroy(&d_config->b_info);
-    libxl_device_model_info_destroy(&d_config->dm_info);
-}
-
 void libxl_init_create_info(libxl_domain_create_info *c_info)
 {
     memset(c_info, '\0', sizeof(*c_info));
diff -r 7049135bb6b7 -r 7bf63de9fcdc tools/python/xen/lowlevel/xl/xl.c
--- a/tools/python/xen/lowlevel/xl/xl.c Wed Jan 12 14:07:53 2011 +0000
+++ b/tools/python/xen/lowlevel/xl/xl.c Wed Jan 12 14:07:53 2011 +0000
@@ -443,6 +443,68 @@ static PyObject *pyxl_domid_to_name(XlOb
     return ret;
 }
 
+struct cb_priv {
+    PyObject *xl_ctx, *cb, *cb_priv;
+};
+
+static int console_ready(libxl_ctx *ctx, uint32_t domid, void *priv)
+{
+    struct cb_priv *p = priv;
+    PyObject *d;
+
+    /* no callback provided, succeed */
+    if ( p->cb == Py_None )
+        return 0;
+
+    d = PyInt_FromLong(domid);
+    if ( d == NULL )
+        return -1;
+
+    if ( PyObject_CallFunctionObjArgs(p->cb, p->xl_ctx, d, p->cb_priv, NULL) ) 
{
+        Py_DECREF(d);
+        return 0;
+    }
+
+    Py_DECREF(d);
+    return -1;
+}
+
+static PyObject *pyxl_domain_create(XlObject *self, PyObject *args)
+{
+    PyObject *console_cb, *cb_priv, *rfile = NULL;
+    Py_domain_config *d_config;
+    struct cb_priv priv;
+    uint32_t domid;
+
+    if ( !PyArg_ParseTuple(args, "OOO|O", &d_config, &console_cb, &cb_priv, 
&rfile) )
+        return NULL;
+
+    if ( !Pydomain_config_Check((PyObject *)d_config) ) {
+        PyErr_SetString(PyExc_TypeError, "Expected xl.domain_config");
+        return NULL;
+    }
+
+    if ( console_cb != Py_None && !PyCallable_Check(console_cb) ) {
+        PyErr_SetString(PyExc_TypeError, "Expected callable console callback");
+        return NULL;
+    }
+
+    if ( !Pydomain_config_Unshadow(d_config) )
+        return NULL;
+
+    priv.xl_ctx = (PyObject *)self;
+    priv.cb = console_cb;
+    priv.cb_priv = cb_priv;
+
+    if ( libxl_domain_create_new(&self->ctx, &d_config->obj,
+                                    console_ready, &priv, &domid) ) {
+        PyErr_SetString(xl_error_obj, "Error creating domain");
+        return NULL;
+    }
+
+    return PyInt_FromLong(domid);
+}
+
 static PyObject *pyxl_domain_shutdown(XlObject *self, PyObject *args)
 {
     int domid, req = 0;
@@ -517,7 +579,7 @@ static PyObject *pyxl_pci_add(XlObject *
     if ( !PyArg_ParseTuple(args, "iO", &domid, &obj) )
         return NULL;
     if ( !Pydevice_pci_Check(obj) ) {
-        PyErr_SetString(PyExc_TypeError, "Xxpected xl.device_pci");
+        PyErr_SetString(PyExc_TypeError, "Expected xl.device_pci");
         return NULL;
     }
     pci = (Py_device_pci *)obj;
@@ -538,7 +600,7 @@ static PyObject *pyxl_pci_del(XlObject *
     if ( !PyArg_ParseTuple(args, "iO|i", &domid, &obj, &force) )
         return NULL;
     if ( !Pydevice_pci_Check(obj) ) {
-        PyErr_SetString(PyExc_TypeError, "Xxpected xl.device_pci");
+        PyErr_SetString(PyExc_TypeError, "Expected xl.device_pci");
         return NULL;
     }
     pci = (Py_device_pci *)obj;
@@ -649,6 +711,8 @@ static PyMethodDef pyxl_methods[] = {
          "Retrieve name from domain-id"},
     {"domain_shutdown", (PyCFunction)pyxl_domain_shutdown, METH_VARARGS,
          "Shutdown a domain"},
+    {"domain_create", (PyCFunction)pyxl_domain_create, METH_VARARGS,
+         "Create or restore a domain"},
     {"domain_destroy", (PyCFunction)pyxl_domain_destroy, METH_VARARGS,
          "Destroy a domain"},
     {"domain_pause", (PyCFunction)pyxl_domain_pause, METH_VARARGS,
@@ -813,6 +877,14 @@ PyMODINIT_FUNC initxl(void)
 
     _INT_CONST(m, POWER_BUTTON);
     _INT_CONST(m, SLEEP_BUTTON);
+
+    _INT_CONST_LIBXL(m, ACTION_DESTROY);
+    _INT_CONST_LIBXL(m, ACTION_RESTART);
+    _INT_CONST_LIBXL(m, ACTION_RESTART_RENAME);
+    _INT_CONST_LIBXL(m, ACTION_PRESERVE);
+    _INT_CONST_LIBXL(m, ACTION_COREDUMP_DESTROY);
+    _INT_CONST_LIBXL(m, ACTION_COREDUMP_RESTART);
+
     genwrap__init(m);
 }
 

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