static int init_evt_cli(struct libxenvchan *ctrl, int domain, xentoollog_logger *logger) { evtchn_port_or_error_t port; ctrl->event = xc_evtchn_open(logger, 0); if (!ctrl->event) return -1; port = xc_evtchn_bind_interdomain(ctrl->event, domain, ctrl->event_port); if (port < 0) goto fail; ctrl->event_port = port; if (xc_evtchn_unmask(ctrl->event, ctrl->event_port)) goto fail; return 0; fail: if (port >= 0) xc_evtchn_unbind(ctrl->event, port); xc_evtchn_close(ctrl->event); ctrl->event = NULL; return -1; }
CAMLprim value stub_eventchn_init(void) { xc_interface *xce = xc_evtchn_open(NULL, XC_OPENFLAG_NON_REENTRANT); if (xce == NULL) caml_failwith(strerror(errno)); return (value)xce; }
static int suspend_evtchn_init(int xc, int domid) { struct xs_handle *xs; char path[128]; char *portstr; unsigned int plen; int port; int rc; si.xce = -1; si.suspend_evtchn = -1; xs = xs_daemon_open(); if (!xs) { warnx("failed to get xenstore handle"); return -1; } sprintf(path, "/local/domain/%d/device/suspend/event-channel", domid); portstr = xs_read(xs, XBT_NULL, path, &plen); xs_daemon_close(xs); if (!portstr || !plen) { warnx("could not read suspend event channel"); return -1; } port = atoi(portstr); free(portstr); si.xce = xc_evtchn_open(); if (si.xce < 0) { warnx("failed to open event channel handle"); goto cleanup; } si.suspend_evtchn = xc_evtchn_bind_interdomain(si.xce, domid, port); if (si.suspend_evtchn < 0) { warnx("failed to bind suspend event channel: %d", si.suspend_evtchn); goto cleanup; } rc = xc_domain_subscribe_for_suspend(xc, domid, port); if (rc < 0) { warnx("failed to subscribe to domain: %d", rc); goto cleanup; } /* event channel is pending immediately after binding */ await_suspend(); return 0; cleanup: suspend_evtchn_release(); return -1; }
CAMLprim value stub_eventchn_init(value unit) { CAMLparam1(unit); xc_interface *xce = xc_evtchn_open(NULL, XC_OPENFLAG_NON_REENTRANT); if (xce == NULL) caml_failwith(strerror(errno)); CAMLreturn((value)xce); }
CAMLprim value stub_eventchn_init(void) { CAMLparam0(); CAMLlocal1(result); xc_interface *xce = xc_evtchn_open(NULL, XC_OPENFLAG_NON_REENTRANT); if (xce == NULL) caml_failwith("open failed"); result = (value)xce; CAMLreturn(result); }
libIVC_t *openIVCLibrary() { libIVC_t *retval; assert( retval = calloc(1, sizeof(struct libIVC_interface)) ); assert( retval->xc = xc_interface_open(NULL, NULL, 0) ); assert( retval->xs = xs_open(0) ); assert( retval->ec = xc_evtchn_open(NULL, 0) ); assert( retval->gt = xc_gnttab_open(NULL, 0) ); #ifdef HAVE_XENSTORE_H retval->gs = xc_gntshr_open(NULL, 0); /* may not be available on all plats */ #endif return retval; }
struct xenfb *xenfb_new(int domid, DisplayState *ds) { struct xenfb *xenfb = qemu_malloc(sizeof(struct xenfb)); int serrno; int i; if (xenfb == NULL) return NULL; /* Prepare scancode mapping table */ for (i = 0; i < 128; i++) { scancode2linux[i] = atkbd_set2_keycode[atkbd_unxlate_table[i]]; scancode2linux[i | 0x80] = atkbd_set2_keycode[atkbd_unxlate_table[i] | 0x80]; } memset(xenfb, 0, sizeof(*xenfb)); xenfb->evt_xch = xenfb->xc = -1; xenfb_device_init(&xenfb->fb, "vfb", xenfb); xenfb_device_init(&xenfb->kbd, "vkbd", xenfb); xenfb->evt_xch = xc_evtchn_open(); if (xenfb->evt_xch == -1) goto fail; xenfb->xc = xc_interface_open(); if (xenfb->xc == -1) goto fail; xenfb->xsh = xs_daemon_open(); if (!xenfb->xsh) goto fail; xenfb->ds = ds; xenfb_device_set_domain(&xenfb->fb, domid); xenfb_device_set_domain(&xenfb->kbd, domid); fprintf(stderr, "FB: Waiting for KBD backend creation\n"); xenfb_wait_for_backend(&xenfb->kbd, xenfb_backend_created_kbd); return xenfb; fail: serrno = errno; xenfb_shutdown(xenfb); errno = serrno; return NULL; }
/* Stolen from xenstore code */ static int eventchn_init(void) { int rc; // to revert to old way: if (0) return -1; xce_handle = xc_evtchn_open(); if (xce_handle < 0) perror("Failed to open evtchn device"); if ((rc = xc_evtchn_bind_virq(xce_handle, VIRQ_TBUF)) == -1) perror("Failed to bind to domain exception virq port"); virq_port = rc; return xce_handle; }
int pa__init(pa_module*m) { struct userdata *u; pa_modargs *ma; pa_sink_new_data data; int backend_state; int ret; char strbuf[100]; pa_assert(m); if (!(ma = pa_modargs_new(m->argument, valid_modargs))) { pa_log("Failed to parse module arguments."); goto fail; } ss = m->core->default_sample_spec; map = m->core->default_channel_map; /* user arguments override these */ if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map, PA_CHANNEL_MAP_DEFAULT) < 0) { pa_log("Invalid sample format specification or channel map"); return 1; } /* Xen Basic init */ xsh = xs_domain_open(); if (xsh==NULL) { pa_log("xs_domain_open failed"); goto fail; } set_state(XenbusStateUnknown); xch = xc_interface_open(NULL, NULL, 0); if (xch==0) { pa_log("xc_interface_open failed"); goto fail; } xce = xc_evtchn_open(NULL, 0); if (xce==0) { pa_log("xc_evtchn_open failed"); goto fail; } /* use only dom0 as the backend for now */ xen_evtchn_port = xc_evtchn_bind_unbound_port(xce, 0); if (xen_evtchn_port == 0) { pa_log("xc_evtchn_bind_unbound_port failed"); } /* get grant reference & map locally */ if (alloc_gref(&gref, (void**)&ioring)) { pa_log("alloc_gref failed"); }; device_id = 0; /* hardcoded for now */ if (register_backend_state_watch()) { pa_log("Xen sink: register xenstore watch failed"); }; publish_param_int("event-channel", xen_evtchn_port); publish_param_int("ring-ref", gref.gref_ids[0]); /* let's ask for something absurd and deal with rejection */ ss.rate = 192000; publish_spec(&ss); ret=0; while (!ret) { backend_state = wait_for_backend_state_change(); if (backend_state == STATE_UNDEFINED) { pa_log("Xen Backend is taking long to respond, still waiting..."); continue; } else if (backend_state == -1) { pa_log("Error while waiting for backend: %s", strerror(errno)); break; goto fail; } ret = state_callbacks[backend_state](); } if (ret!=NEGOTIATION_OK) { pa_log("Negotiation with Xen backend failed!"); return 1; } pa_sample_spec_snprint(strbuf, 100, &ss); pa_log_debug("Negotiation ended, the result was: %s", strbuf); /* End of Phase 2, begin playback cycle */ u = pa_xnew0(struct userdata, 1); u->core = m->core; u->module = m; m->userdata = u; pa_memchunk_reset(&u->memchunk); u->rtpoll = pa_rtpoll_new(); pa_thread_mq_init(&u->thread_mq, m->core->mainloop, u->rtpoll); u->write_type = 0; /* init ring buffer */ ioring->prod_indx = ioring->cons_indx = 0; ioring->usable_buffer_space = BUFSIZE - BUFSIZE % pa_frame_size(&ss); pa_sink_new_data_init(&data); data.driver = __FILE__; data.module = m; pa_sink_new_data_set_name(&data, pa_modargs_get_value(ma, "sink_name", DEFAULT_SINK_NAME)); pa_proplist_sets(data.proplist, PA_PROP_DEVICE_STRING, "xensink"); pa_proplist_setf(data.proplist, PA_PROP_DEVICE_DESCRIPTION, "Xen PV audio sink"); pa_sink_new_data_set_sample_spec(&data, &ss); pa_sink_new_data_set_channel_map(&data, &map); if (pa_modargs_get_proplist(ma, "sink_properties", data.proplist, PA_UPDATE_REPLACE) < 0) { pa_log("Invalid properties"); pa_sink_new_data_done(&data); goto fail; } u->sink = pa_sink_new(m->core, &data, PA_SINK_LATENCY); pa_sink_new_data_done(&data); if (!u->sink) { pa_log("Failed to create sink."); goto fail; } u->sink->parent.process_msg = sink_process_msg; u->sink->userdata = u; pa_sink_set_asyncmsgq(u->sink, u->thread_mq.inq); pa_sink_set_rtpoll(u->sink, u->rtpoll); pa_sink_set_max_request(u->sink, ioring->usable_buffer_space); pa_sink_set_fixed_latency(u->sink, pa_bytes_to_usec(ioring->usable_buffer_space, &u->sink->sample_spec)); u->rtpoll_item = pa_rtpoll_item_new(u->rtpoll, PA_RTPOLL_NEVER, 1); if (!(u->thread = pa_thread_new("xenpv-sink", thread_func, u))) { pa_log("Failed to create thread."); goto fail; } pa_sink_put(u->sink); pa_modargs_free(ma); return 0; fail: if (ma) pa_modargs_free(ma); pa__done(m); return -1; }
/* open a checkpoint session to guest domid */ int checkpoint_open(checkpoint_state* s, unsigned int domid) { xc_dominfo_t dominfo; unsigned long pvirq; s->domid = domid; s->xch = xc_interface_open(); if (s->xch < 0) { s->errstr = "could not open control interface (are you root?)"; return -1; } s->xsh = xs_daemon_open(); if (!s->xsh) { checkpoint_close(s); s->errstr = "could not open xenstore handle"; return -1; } s->xce = xc_evtchn_open(); if (s->xce < 0) { checkpoint_close(s); s->errstr = "could not open event channel handle"; return -1; } if (xc_domain_getinfo(s->xch, s->domid, 1, &dominfo) < 0) { checkpoint_close(s); s->errstr = "could not get domain info"; return -1; } if (dominfo.hvm) { if (xc_get_hvm_param(s->xch, s->domid, HVM_PARAM_CALLBACK_IRQ, &pvirq)) { checkpoint_close(s); s->errstr = "could not get HVM callback IRQ"; return -1; } s->domtype = pvirq ? dt_pvhvm : dt_hvm; } else s->domtype = dt_pv; if (setup_shutdown_watch(s) < 0) { checkpoint_close(s); return -1; } if (s->domtype == dt_pv) { if (setup_suspend_evtchn(s) < 0) { fprintf(stderr, "WARNING: suspend event channel unavailable, " "falling back to slow xenstore signalling\n"); } } else if (s->domtype == dt_pvhvm) { checkpoint_close(s); s->errstr = "PV-on-HVM is unsupported"; return -1; } return 0; }
static int hp_mem_offline_func(int argc, char *argv[]) { uint32_t status, domid; int ret; unsigned long mfn; if (argc != 1) { show_help(); return -1; } sscanf(argv[0], "%lx", &mfn); printf("Prepare to offline MEMORY mfn %lx\n", mfn); ret = xc_mark_page_offline(xch, mfn, mfn, &status); if (ret < 0) { fprintf(stderr, "Offlining page mfn %lx failed, error %x\n", mfn, ret); if (status & (PG_OFFLINE_XENPAGE | PG_OFFLINE_FAILED)) fprintf(stderr, "XEN_PAGE is not permitted be offlined\n"); else if (status & (PG_OFFLINE_FAILED | PG_OFFLINE_NOT_CONV_RAM)) fprintf(stderr, "RESERVED RAM is not permitted to be offlined\n"); } else { switch(status & PG_OFFLINE_STATUS_MASK) { case PG_OFFLINE_OFFLINED: { printf("Memory mfn %lx offlined successfully, current state is" " [PG_OFFLINE_OFFLINED]\n", mfn); if (status & PG_OFFLINE_BROKEN) printf("And this offlined PAGE is already marked broken" " before!\n"); break; } case PG_OFFLINE_FAILED: { fprintf(stderr, "Memory mfn %lx offline failed\n", mfn); if ( status & PG_OFFLINE_ANONYMOUS) fprintf(stderr, "the memory is an anonymous page!\n"); ret = -1; break; } case PG_OFFLINE_PENDING: { if (status & PG_OFFLINE_XENPAGE) { ret = -1; fprintf(stderr, "Memory mfn %lx offlined succssefully," "this page is xen page, current state is" " [PG_OFFLINE_PENDING, PG_OFFLINE_XENPAGE]\n", mfn); } else if (status & PG_OFFLINE_OWNED) { int result, suspend_evtchn = -1, suspend_lockfd = -1; xc_evtchn *xce; xce = xc_evtchn_open(NULL, 0); if (xce == NULL) { fprintf(stderr, "When exchange page, fail" " to open evtchn\n"); return -1; } domid = status >> PG_OFFLINE_OWNER_SHIFT; if (suspend_guest(xch, xce, domid, &suspend_evtchn, &suspend_lockfd)) { fprintf(stderr, "Failed to suspend guest %d for" " mfn %lx\n", domid, mfn); xc_evtchn_close(xce); return -1; } result = xc_exchange_page(xch, domid, mfn); /* Exchange page successfully */ if (result == 0) printf("Memory mfn %lx offlined successfully, this " "page is DOM%d page and being swapped " "successfully, current state is " "[PG_OFFLINE_OFFLINED, PG_OFFLINE_OWNED]\n", mfn, domid); else { ret = -1; fprintf(stderr, "Memory mfn %lx offlined successfully" " , this page is DOM%d page yet failed to be " "exchanged. current state is " "[PG_OFFLINE_PENDING, PG_OFFLINE_OWNED]\n", mfn, domid); } xc_domain_resume(xch, domid, 1); xc_suspend_evtchn_release(xch, xce, domid, suspend_evtchn, &suspend_lockfd); xc_evtchn_close(xce); } break; } }//end of switch }//end of if