[XEN] New event-channel reset operation.
authorkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Fri, 19 Jan 2007 17:20:57 +0000 (17:20 +0000)
committerkfraser@localhost.localdomain <kfraser@localhost.localdomain>
Fri, 19 Jan 2007 17:20:57 +0000 (17:20 +0000)
Plumbed through libxenctrl to python.

From: Andrei Petrov <andrei.petrov@xensource.com>
Signed-off-by: Keir Fraser <keir@xensource.com>
tools/libxc/xc_evtchn.c
tools/libxc/xenctrl.h
tools/python/xen/lowlevel/xc/xc.c
xen/common/event_channel.c
xen/include/public/event_channel.h

index 8c795bce7ae46fce5998e71f204f4e0f835e30a2..c0f3b9b54c2e6e71267dff5ca9f0e9a2f69e9b44 100644 (file)
@@ -37,7 +37,7 @@ int xc_evtchn_alloc_unbound(int xc_handle,
                             uint32_t dom,
                             uint32_t remote_dom)
 {
-    int         rc;
+    int rc;
     struct evtchn_alloc_unbound arg = {
         .dom = (domid_t)dom,
         .remote_dom = (domid_t)remote_dom
@@ -49,3 +49,10 @@ int xc_evtchn_alloc_unbound(int xc_handle,
 
     return rc;
 }
+
+int xc_evtchn_reset(int xc_handle,
+                    uint32_t dom)
+{
+    struct evtchn_reset arg = { .dom = (domid_t)dom };
+    return do_evtchn_op(xc_handle, EVTCHNOP_reset, &arg, sizeof(arg));
+}
index 715764ac6e434bbbbcb0dcc601af22f14f2da81b..37d12d5788544765a195cd77e8f62de38fa29d61 100644 (file)
@@ -432,6 +432,9 @@ int xc_evtchn_alloc_unbound(int xc_handle,
                             uint32_t dom,
                             uint32_t remote_dom);
 
+int xc_evtchn_reset(int xc_handle,
+                    uint32_t dom);
+
 int xc_physdev_pci_access_modify(int xc_handle,
                                  uint32_t domid,
                                  int bus,
index a95b7d9bf8e5786e6f1b4cfe41a8fb2c8fc56691..665a61b84af8ba74b65f31b8a41e4eeb1fa8e974 100644 (file)
@@ -478,6 +478,24 @@ static PyObject *pyxc_evtchn_alloc_unbound(XcObject *self,
     return PyInt_FromLong(port);
 }
 
+static PyObject *pyxc_evtchn_reset(XcObject *self,
+                                  PyObject *args,
+                                  PyObject *kwds)
+{
+    uint32_t dom;
+
+    static char *kwd_list[] = { "dom", NULL };
+
+    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &dom) )
+        return NULL;
+
+    if ( xc_evtchn_reset(self->xc_handle, dom) < 0 )
+        return pyxc_error_to_exception();
+
+    Py_INCREF(zero);
+    return zero;
+}
+
 static PyObject *pyxc_physdev_pci_access_modify(XcObject *self,
                                                 PyObject *args,
                                                 PyObject *kwds)
@@ -1202,6 +1220,12 @@ static PyMethodDef pyxc_methods[] = {
       " remote_dom [int]: Remote domain to accept connections from.\n\n"
       "Returns: [int] Unbound event-channel port.\n" },
 
+    { "evtchn_reset", 
+      (PyCFunction)pyxc_evtchn_reset,
+      METH_VARARGS | METH_KEYWORDS, "\n"
+      "Reset all connections.\n"
+      " dom [int]: Domain to reset.\n" },
+
     { "physdev_pci_access_modify",
       (PyCFunction)pyxc_physdev_pci_access_modify,
       METH_VARARGS | METH_KEYWORDS, "\n"
index 70665a7e78db807e17c5f08e86e313173e70b4c2..0116a9aa91a9f77221795fc58a6725f4c80ffabf 100644 (file)
@@ -735,6 +735,29 @@ static long evtchn_unmask(evtchn_unmask_t *unmask)
 }
 
 
+static long evtchn_reset(evtchn_reset_t *r)
+{
+    domid_t dom = r->dom;
+    struct domain *d;
+    int i;
+
+    if ( dom == DOMID_SELF )
+        dom = current->domain->domain_id;
+    else if ( !IS_PRIV(current->domain) )
+        return -EPERM;
+
+    if ( (d = find_domain_by_id(dom)) == NULL )
+        return -ESRCH;
+
+    for ( i = 0; port_is_valid(d, i); i++ )
+        (void)__evtchn_close(d, i);
+
+    put_domain(d);
+
+    return 0;
+}
+
+
 long do_event_channel_op(int cmd, XEN_GUEST_HANDLE(void) arg)
 {
     long rc;
@@ -833,6 +856,14 @@ long do_event_channel_op(int cmd, XEN_GUEST_HANDLE(void) arg)
         break;
     }
 
+    case EVTCHNOP_reset: {
+        struct evtchn_reset reset;
+        if ( copy_from_guest(&reset, arg, 1) != 0 )
+            return -EFAULT;
+        rc = evtchn_reset(&reset);
+        break;
+    }
+
     default:
         rc = -ENOSYS;
         break;
index 62cf764040d63f3fe7f6513fe82fdfe3aa5873aa..d35cce53e4d891375bd1ab97768e6af6a3adf247 100644 (file)
@@ -216,6 +216,19 @@ struct evtchn_unmask {
 };
 typedef struct evtchn_unmask evtchn_unmask_t;
 
+/*
+ * EVTCHNOP_reset: Close all event channels associated with specified domain.
+ * NOTES:
+ *  1. <dom> may be specified as DOMID_SELF.
+ *  2. Only a sufficiently-privileged domain may specify other than DOMID_SELF.
+ */
+#define EVTCHNOP_reset           10
+struct evtchn_reset {
+    /* IN parameters. */
+    domid_t dom;
+};
+typedef struct evtchn_reset evtchn_reset_t;
+
 /*
  * Argument to event_channel_op_compat() hypercall. Superceded by new
  * event_channel_op() hypercall since 0x00030202.