From: Francesco Tamberi <francesco.tamberi@gmail.com>
To: xen-devel@lists.xensource.com
Subject: Re: interdomain event channel using libxc
Date: Mon, 12 Nov 2007 09:06:03 -0800 (PST) [thread overview]
Message-ID: <13709427.post@talk.nabble.com> (raw)
In-Reply-To: <20061201143812.5cd1db7a.stephan.creutz@inf.tu-dresden.de>
Hi,
This stub works well for me, but suppose I have to "move" the domU code at
"kernel level" (i.e. as a module) which hypercalls should I invoke and in
what order?
This is a "stupid" scheme of what I mean to do:
domU --> kernel level, using hypercalls
dom0 --> user level (see code below), using libxc
Thanks
-- f
Stephan Creutz wrote:
>
> Hi,
>
> [... cut]
>
> Program running in Dom0:
>
> #include <stdio.h>
> #include <time.h>
> #include <sys/select.h>
> #include <xen/xenctrl.h>
>
> static int xc_handle = -1;
>
> static void event_channel(uint32_t domid)
> {
> int xce_handle = xc_evtchn_open();
> if (xce_handle == -1) {
> fprintf(stderr, "opening event channel failed\n");
> return;
> }
>
> int port = xc_evtchn_alloc_unbound(xc_handle, DOMID_SELF, domid);
> if (port == -1)
> fprintf(stderr, "port allocation failed\n");
> else
> printf("allocated port: %d\n", port);
>
> fd_set rfds;
>
> FD_ZERO(&rfds);
> int evtchn_fd = xc_evtchn_fd(xce_handle);
> FD_SET(evtchn_fd, &rfds);
>
> struct timeval select_timeout = {
> .tv_sec = 10,
> .tv_usec = 0
> };
>
> if (xc_evtchn_unmask(xce_handle, (evtchn_port_t)port) == -1)
> fprintf(stderr, "unmasking failed\n");
>
> printf(">>> select\n");
> int ret = select(evtchn_fd + 1, &rfds, NULL, NULL, &select_timeout);
>
> if (ret == -1)
> perror("select()");
> else if (ret && FD_ISSET(evtchn_fd, &rfds)) {
> printf(">>> event <<<\n");
> evtchn_port_t next_port;
> if ((next_port = xc_evtchn_pending(xce_handle)) ==
> (evtchn_port_t)-1)
> perror("xc_evtchn_pending");
> if (xc_evtchn_unmask(xce_handle, next_port) == -1)
> fprintf(stderr, "unable to umask\n");
> } else
> fprintf(stderr, "select timeout\n");
>
> xc_evtchn_close(xce_handle);
> printf("eventchannel closed\n");
> }
>
> int main(void)
> {
> xc_handle = xc_interface_open();
> if (xc_handle == -1) {
> fprintf(stderr, "connection to hypervisor failed\n");
> return 1;
> }
>
> xc_dominfo_t dominfo[2];
> int number_of_domains = xc_domain_getinfo(xc_handle, 0, 2, dominfo);
> if (number_of_domains < 2) {
> fprintf(stderr, "there is only one domain, but need two\n");
> goto error;
> }
>
> event_channel(dominfo[1].domid);
>
> error:
> xc_interface_close(xc_handle);
> return 0;
> }
>
> Program running in DomU:
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <time.h>
> #include <xen/xenctrl.h>
>
> static int xc_handle = -1;
> static const uint32_t domid = 0;
>
> int main(int argc, char **argv)
> {
> if (argc < 2) {
> fprintf(stderr, "usage: %s <remote-port>\n", argv[0]);
> return 1;
> }
>
> xc_handle = xc_interface_open();
> if (xc_handle == -1) {
> fprintf(stderr, "connection to hypervisor failed\n");
> return 1;
> }
>
> int xce_handle = xc_evtchn_open();
> if (xce_handle == -1) {
> fprintf(stderr, "opening of event channel failed\n");
> goto error;
> }
>
> evtchn_port_t remote_port = (evtchn_port_t)atoi(argv[1]);
> evtchn_port_t local_port;
> local_port = xc_evtchn_bind_interdomain(xce_handle, domid,
> remote_port); if (local_port == (evtchn_port_t)-1)
> fprintf(stderr, "binding to interdomain channel failed\n");
>
> if (xc_evtchn_notify(xce_handle, local_port) == -1)
> fprintf(stderr, "notify failed\n");
>
> struct timespec nano_timespec = {
> .tv_sec = 5,
> .tv_nsec = 0
> };
> nanosleep(&nano_timespec, NULL);
> if (xc_evtchn_unbind(xce_handle, local_port) == -1)
> fprintf(stderr, "unbind failed\n");
> xc_evtchn_close(xce_handle);
>
> error:
> xc_interface_close(xc_handle);
> return 0;
> }
>
--
View this message in context: http://www.nabble.com/interdomain-event-channel-using-libxc-tf2738572.html#a13709427
Sent from the Xen - Dev mailing list archive at Nabble.com.
prev parent reply other threads:[~2007-11-12 17:06 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-01 13:38 interdomain event channel using libxc Stephan Creutz
2006-12-01 14:17 ` Keir Fraser
2006-12-01 14:28 ` Keir Fraser
2006-12-04 17:59 ` Stephan Creutz
2007-11-12 17:06 ` Francesco Tamberi [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=13709427.post@talk.nabble.com \
--to=francesco.tamberi@gmail.com \
--cc=xen-devel@lists.xensource.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.