static int get_memory_ranges_xen(struct memory_range **range, int *ranges) { int rc, ret = -1; struct e820entry e820entries[MAX_MEMORY_RANGES]; unsigned int i; #ifdef XENCTRL_HAS_XC_INTERFACE xc_interface *xc; #else int xc; #endif #ifdef XENCTRL_HAS_XC_INTERFACE xc = xc_interface_open(NULL, NULL, 0); if (!xc) { fprintf(stderr, "%s: Failed to open Xen control interface\n", __func__); goto err; } #else xc = xc_interface_open(); if (xc == -1) { fprintf(stderr, "%s: Failed to open Xen control interface\n", __func__); goto err; } #endif rc = xc_get_machine_memory_map(xc, e820entries, MAX_MEMORY_RANGES); if (rc < 0) { fprintf(stderr, "%s: xc_get_machine_memory_map: %s\n", __func__, strerror(rc)); goto err; } for (i = 0; i < rc; ++i) { memory_range[i].start = e820entries[i].addr; memory_range[i].end = e820entries[i].addr + e820entries[i].size; memory_range[i].type = xen_e820_to_kexec_type(e820entries[i].type); } qsort(memory_range, rc, sizeof(struct memory_range), compare_ranges); *range = memory_range; *ranges = rc; ret = 0; err: xc_interface_close(xc); return ret; }
static int xen_init(MachineState *ms) { PCMachineState *pcms = PC_MACHINE(ms); /* Disable ACPI build because Xen handles it */ pcms->acpi_build_enabled = false; xen_xc = xc_interface_open(0, 0, 0); if (xen_xc == NULL) { xen_pv_printf(NULL, 0, "can't open xen interface\n"); return -1; } xen_fmem = xenforeignmemory_open(0, 0); if (xen_fmem == NULL) { xen_pv_printf(NULL, 0, "can't open xen fmem interface\n"); xc_interface_close(xen_xc); return -1; } qemu_add_vm_change_state_handler(xen_change_state_handler, NULL); global_state_set_optional(); savevm_skip_configuration(); savevm_skip_section_footers(); return 0; }
/* initialize to view an actively running Xen domain */ int xa_init_vm_private (uint32_t domain_id, xa_instance_t *instance, uint32_t error_mode) { bzero(instance, sizeof(xa_instance_t)); #ifdef ENABLE_XEN int xc_handle; instance->mode = XA_MODE_XEN; xa_dbprint("XenAccess Mode Xen\n"); instance->error_mode = error_mode; xa_dbprint("XenAccess Error Mode = %d\n", instance->error_mode); /* open handle to the libxc interface */ if ((xc_handle = xc_interface_open()) == -1){ fprintf(stderr, "ERROR: Failed to open libxc interface\n"); return XA_FAILURE; } instance->m.xen.xc_handle = xc_handle; xa_init_common(instance); instance->m.xen.domain_id = domain_id; instance->m.xen.live_pfn_to_mfn_table = NULL; instance->m.xen.nr_pfns = 0; return helper_init(instance); #else return XA_FAILURE; #endif /* ENABLE_XEN */ }
int xen_setup(void) { xs = xs_daemon_open(); if (xs == NULL) { dolog(LOG_ERR, "Failed to contact xenstore (%s). Is it running?", strerror(errno)); goto out; } xc = xc_interface_open(); if (xc == -1) { dolog(LOG_ERR, "Failed to contact hypervisor (%s)", strerror(errno)); goto out; } if (!xs_watch(xs, DOMAIN_PATH, "backend")) { dolog(LOG_ERR, "xenstore watch on backend fails."); goto out; } return 0; out: if (xs) xs_daemon_close(xs); if (xc != -1) xc_interface_close(xc); return -1; }
bool xen_setup(void) { xs = xs_daemon_open(); if (xs == NULL) { dolog(LOG_ERR, "Failed to contact xenstore (%m). Is it running?"); goto out; } xc = xc_interface_open(); if (xc == -1) { dolog(LOG_ERR, "Failed to contact hypervisor (%m)"); goto out; } if (!xs_watch(xs, "@introduceDomain", "domlist")) { dolog(LOG_ERR, "xenstore watch on @introduceDomain fails."); goto out; } if (!xs_watch(xs, "@releaseDomain", "domlist")) { dolog(LOG_ERR, "xenstore watch on @releaseDomain fails."); goto out; } return true; out: if (xs) xs_daemon_close(xs); if (xc != -1) xc_interface_close(xc); return false; }
XenDomainWatcher::XenDomainWatcher( LogHelper *logHelper ) : xsh_( NULL ), xci_( NULL ), introduceToken_( "introduce" ), releaseToken_( "release" ), logHelper_( logHelper ) { xsh_ = xs_open( 0 ); if ( !xsh_ ) throw Exception( "xs_open() failed" ); if ( !xs_watch( xsh_, "@introduceDomain", introduceToken_.c_str() ) ) { xs_close( xsh_ ); throw Exception( "xs_watch() failed" ); } if ( !xs_watch( xsh_, "@releaseDomain", releaseToken_.c_str() ) ) { xs_unwatch( xsh_, "@introduceDomain", introduceToken_.c_str() ); xs_close( xsh_ ); throw Exception( "xs_watch() failed" ); } xci_ = xc_interface_open( NULL, NULL, 0 ); if ( !xci_ ) { xs_unwatch( xsh_, "@introduceDomain", introduceToken_.c_str() ); xs_unwatch( xsh_, "@releaseDomain", releaseToken_.c_str() ); xs_close( xsh_ ); throw Exception( "xc_interface_init() failed" ); } }
int main(int argc, char **argv) { int err = 0; xc_interface *xch; int value; if (argc != 3) usage(argv); value = str2bool(argv[2]); xch = xc_interface_open(0,0,0); if ( !xch ) { fprintf(stderr, "Unable to create interface to xenctrl: %s\n", strerror(errno)); err = 1; goto done; } err = xc_flask_setbool(xch, argv[1], value, 1); if (err) { fprintf(stderr, "xc_flask_setbool: Unable to set boolean %s=%s: %s (%d)", argv[1], argv[2], strerror(errno), err); err = 2; goto done; } done: if ( xch ) xc_interface_close(xch); return err; }
libvchan_t *libvchan_server_init(int domain, int port, size_t read_min, size_t write_min) { char xs_path[255]; libvchan_t *ctrl; ctrl = malloc(sizeof(*ctrl)); if (!ctrl) return NULL; snprintf(xs_path, sizeof(xs_path), "data/vchan/%d/%d", domain, port); ctrl->xenvchan = libxenvchan_server_init(NULL, domain, xs_path, read_min, write_min); if (!ctrl->xenvchan) { free(ctrl); return NULL; } ctrl->xs_path = strdup(xs_path); ctrl->xenvchan->blocking = 1; ctrl->remote_domain = domain; ctrl->xc_handle = xc_interface_open(NULL, NULL, 0); if (!ctrl->xc_handle) { /* error already logged by xc_interface_open */ libxenvchan_close(ctrl->xenvchan); free(ctrl); return NULL; } return ctrl; }
static void openXenHandles(HSP *sp) { // need to do this while we still have root privileges if(sp->xc_handle == 0) { sp->xc_handle = xc_interface_open(); if(sp->xc_handle <= 0) { myLog(LOG_ERR, "xc_interface_open() failed : %s", strerror(errno)); } else { sp->xs_handle = xs_daemon_open_readonly(); if(sp->xs_handle == NULL) { myLog(LOG_ERR, "xs_daemon_open_readonly() failed : %s", strerror(errno)); } // get the page size [ref xenstat.c] #if defined(PAGESIZE) sp->page_size = PAGESIZE; #elif defined(PAGE_SIZE) sp->page_size = PAGE_SIZE; #else sp->page_size = sysconf(_SC_PAGE_SIZE); if(pgsiz < 0) { myLog(LOG_ERR, "Failed to retrieve page size : %s", strerror(errno)); abort(); } #endif } } }
static PyObject *pyflask_sid_to_context(PyObject *self, PyObject *args, PyObject *kwds) { int xc_handle; uint32_t sid; char ctx[CTX_LEN]; uint32_t ctx_len = CTX_LEN; int ret; static char *kwd_list[] = { "sid", NULL }; if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &sid) ) return NULL; xc_handle = xc_interface_open(); if (xc_handle < 0) { errno = xc_handle; return PyErr_SetFromErrno(xc_error_obj); } ret = flask_sid_to_context(xc_handle, sid, ctx, ctx_len); xc_interface_close(xc_handle); if ( ret != 0 ) { errno = -ret; return PyErr_SetFromErrno(xc_error_obj); } return Py_BuildValue("s", ctx, ctx_len); }
/** * map_tbufs - memory map Xen trace buffers into user space * @tbufs_mfn: mfn of the trace buffers * @num: number of trace buffers to map * @size: size of each trace buffer * * Maps the Xen trace buffers them into process address space. */ struct t_buf *map_tbufs(unsigned long tbufs_mfn, unsigned int num, unsigned long size) { int xc_handle; struct t_buf *tbufs_mapped; xc_handle = xc_interface_open(); if ( xc_handle < 0 ) { exit(EXIT_FAILURE); } tbufs_mapped = xc_map_foreign_range(xc_handle, DOMID_XEN, size * num, PROT_READ | PROT_WRITE, tbufs_mfn); xc_interface_close(xc_handle); if ( tbufs_mapped == 0 ) { PERROR("Failed to mmap trace buffers"); exit(EXIT_FAILURE); } return tbufs_mapped; }
static PyObject *pyflask_load(PyObject *self, PyObject *args, PyObject *kwds) { int xc_handle; char *policy; uint32_t len; int ret; static char *kwd_list[] = { "policy", NULL }; if( !PyArg_ParseTupleAndKeywords(args, kwds, "s#", kwd_list, &policy, &len) ) return NULL; xc_handle = xc_interface_open(); if (xc_handle < 0) { errno = xc_handle; return PyErr_SetFromErrno(xc_error_obj); } ret = flask_load(xc_handle, policy, len); xc_interface_close(xc_handle); if ( ret != 0 ) { errno = -ret; return PyErr_SetFromErrno(xc_error_obj); } return Py_BuildValue("i", ret); }
int main(int argc, char **argv) { int opt; while ((opt = getopt(argc, argv, "h")) != -1) { switch (opt) { case 'h': usage(0); break; default: usage(1); } } argv += optind; argc -= optind; if (argc <= 0) usage(1); xch = xc_interface_open(NULL, NULL, 0); if (!xch) err(1, "opening xc interface"); if (strcmp(argv[0], "reset") == 0) gcov_reset(); else if (strcmp(argv[0], "read") == 0) gcov_read(argc > 1 ? argv[1] : "-"); else usage(1); xc_interface_close(xch); return 0; }
int main(int argc, char **argv) { unsigned int domid, maxit, max_f, flags; int xc_fd, io_fd, ret; if (argc != 6) errx(1, "usage: %s iofd domid maxit maxf flags", argv[0]); xc_fd = xc_interface_open(); if (xc_fd < 0) errx(1, "failed to open control interface"); io_fd = atoi(argv[1]); domid = atoi(argv[2]); maxit = atoi(argv[3]); max_f = atoi(argv[4]); flags = atoi(argv[5]); if (suspend_evtchn_init(xc_fd, domid) < 0) warnx("suspend event channel initialization failed, using slow path"); ret = xc_domain_save(xc_fd, io_fd, domid, maxit, max_f, flags, &suspend, !!(flags & XCFLAGS_HVM), &init_qemu_maps, &qemu_flip_buffer); suspend_evtchn_release(); xc_interface_close(xc_fd); return ret; }
/* generic shared function */ static void *__getssid(int domid, uint32_t *buflen) { struct acm_getssid getssid; int xc_handle; #define SSID_BUFFER_SIZE 4096 void *buf = NULL; if ((xc_handle = xc_interface_open()) < 0) { goto out1; } if ((buf = malloc(SSID_BUFFER_SIZE)) == NULL) { PERROR("acm.policytype: Could not allocate ssid buffer!\n"); goto out2; } memset(buf, 0, SSID_BUFFER_SIZE); set_xen_guest_handle(getssid.ssidbuf, buf); getssid.ssidbuf_size = SSID_BUFFER_SIZE; getssid.get_ssid_by = ACM_GETBY_domainid; getssid.id.domainid = domid; if (xc_acm_op(xc_handle, ACMOP_getssid, &getssid, sizeof(getssid)) < 0) { if (errno == EACCES) PERROR("ACM operation failed."); free(buf); buf = NULL; goto out2; } else { *buflen = SSID_BUFFER_SIZE; goto out2; } out2: xc_interface_close(xc_handle); out1: return buf; }
static PyObject *getpolicy(PyObject *self, PyObject *args) { struct acm_getpolicy getpolicy; int xc_handle, rc; uint8_t pull_buffer[8192]; PyObject *result; uint32_t len = sizeof(pull_buffer); memset(&getpolicy, 0x0, sizeof(getpolicy)); set_xen_guest_handle(getpolicy.pullcache, pull_buffer); getpolicy.pullcache_size = sizeof(pull_buffer); if ((xc_handle = xc_interface_open()) <= 0) { PyErr_SetString(PyExc_IOError, ctrlif_op); return NULL; } rc = xc_acm_op(xc_handle, ACMOP_getpolicy, &getpolicy, sizeof(getpolicy)); xc_interface_close(xc_handle); if (rc == 0) { struct acm_policy_buffer *header = (struct acm_policy_buffer *)pull_buffer; if (ntohl(header->len) < sizeof(pull_buffer)) len = ntohl(header->len); } else { len = 0; } result = Py_BuildValue("is#", rc, pull_buffer, len); return result; }
bool xen_init_interface(xen_interface_t **xen) { *xen = g_malloc0(sizeof(xen_interface_t)); /* We create an xc interface to test connection to it */ (*xen)->xc = xc_interface_open(0, 0, 0); if ((*xen)->xc == NULL) { fprintf(stderr, "xc_interface_open() failed!\n"); goto err; } /* We don't need this at the moment, but just in case */ //xen->xsh=xs_open(XS_OPEN_READONLY); (*xen)->xl_logger = (xentoollog_logger *) xtl_createlogger_stdiostream( stderr, XTL_PROGRESS, 0); if (!(*xen)->xl_logger) { goto err; } if (libxl_ctx_alloc(&(*xen)->xl_ctx, LIBXL_VERSION, 0, (*xen)->xl_logger)) { fprintf(stderr, "libxl_ctx_alloc() failed!\n"); goto err; } return 1; err: xen_free_interface(*xen); *xen = NULL; return 0; }
static int __hypercall_perform(unsigned long cmd, unsigned long *arr) { int ret; xc_interface *xch = xc_interface_open(0, 0, 0); DECLARE_HYPERCALL; if (xch == NULL) goto err; hypercall.op = __HYPERVISOR_xen_version; hypercall.arg[0] = cmd; hypercall.arg[1] = (unsigned long) arr; ret = do_xen_hypercall(xch, &hypercall); xc_interface_close(xch); if (ret != 0) goto err; out: return ret; err: ret = -1; goto out; }
static PyObject *pyflask_setenforce(PyObject *self, PyObject *args, PyObject *kwds) { int xc_handle; int mode; int ret; static char *kwd_list[] = { "mode", NULL }; if ( !PyArg_ParseTupleAndKeywords(args, kwds, "i", kwd_list, &mode) ) return NULL; xc_handle = xc_interface_open(); if (xc_handle < 0) { errno = xc_handle; return PyErr_SetFromErrno(xc_error_obj); } ret = flask_setenforce(xc_handle, mode); xc_interface_close(xc_handle); if ( ret != 0 ) { errno = -ret; return PyErr_SetFromErrno(xc_error_obj); } return Py_BuildValue("i", ret); }
CAMLprim value stub_xenguest_init() { xc_interface *xch; xch = xc_interface_open(NULL, NULL, 0); if (xch == NULL) failwith_oss_xc(NULL, "xc_interface_open"); return (value)xch; }
int main(int argc, char *argv[]) { int i, ret = 0; xc_physinfo_t physinfo = { 0 }; int nr_matches = 0; int matches_main_options[ARRAY_SIZE(main_options)]; if ( argc < 2 ) { show_help(); return 0; } xc_handle = xc_interface_open(0,0,0); if ( !xc_handle ) { fprintf(stderr, "failed to get the handler\n"); return EIO; } ret = xc_physinfo(xc_handle, &physinfo); if ( ret ) { ret = errno; fprintf(stderr, "failed to get processor information (%d - %s)\n", ret, strerror(ret)); xc_interface_close(xc_handle); return ret; } max_cpu_nr = physinfo.nr_cpus; /* calculate how many options match with user's input */ for ( i = 0; i < ARRAY_SIZE(main_options); i++ ) if ( !strncmp(main_options[i].name, argv[1], strlen(argv[1])) ) matches_main_options[nr_matches++] = i; if ( nr_matches > 1 ) { fprintf(stderr, "Ambiguous options: "); for ( i = 0; i < nr_matches; i++ ) fprintf(stderr, " %s", main_options[matches_main_options[i]].name); fprintf(stderr, "\n"); ret = EINVAL; } else if ( nr_matches == 1 ) /* dispatch to the corresponding function handler */ main_options[matches_main_options[0]].function(argc - 2, argv + 2); else { show_help(); ret = EINVAL; } xc_interface_close(xc_handle); return ret; }
int main(int argc, char **argv) { xc_interface *xch; int domid, port, rc; xc_evtchn_status_t status; domid = (argc > 1) ? strtol(argv[1], NULL, 10) : 0; xch = xc_interface_open(0,0,0); if ( !xch ) errx(1, "failed to open control interface"); for ( port = 0; ; port++ ) { status.dom = domid; status.port = port; rc = xc_evtchn_status(xch, &status); if ( rc < 0 ) break; if ( status.status == EVTCHNSTAT_closed ) continue; printf("%4d: VCPU %u: ", port, status.vcpu); switch ( status.status ) { case EVTCHNSTAT_unbound: printf("Interdomain (Waiting connection) - Remote Domain %u", status.u.unbound.dom); break; case EVTCHNSTAT_interdomain: printf("Interdomain (Connected) - Remote Domain %u, Port %u", status.u.interdomain.dom, status.u.interdomain.port); break; case EVTCHNSTAT_pirq: printf("Physical IRQ %u", status.u.pirq); break; case EVTCHNSTAT_virq: printf("Virtual IRQ %u", status.u.virq); break; case EVTCHNSTAT_ipi: printf("IPI"); break; default: printf("Unknown"); break; } printf("\n"); } xc_interface_close(xch); return 0; }
// give index of this domain in the qos data array int indexof(int domid) { int idx; xc_dominfo_t dominfo[NDOMAINS]; int xc_handle, ndomains; extern void qos_kill_thread(int domid); if (domid < 0) { // shouldn't happen printf("bad domain id: %d\r\n", domid); return 0; } for (idx=0; idx<NDOMAINS; idx++) if ( (new_qos->domain_info[idx].id == domid) && new_qos->domain_info[idx].in_use) return idx; // not found, make a new entry for (idx=0; idx<NDOMAINS; idx++) if (new_qos->domain_info[idx].in_use == 0) { global_init_domain(domid, idx); return idx; } // call domaininfo hypercall to try and garbage collect unused entries xc_handle = xc_interface_open(); ndomains = xc_domain_getinfo(xc_handle, 0, NDOMAINS, dominfo); xc_interface_close(xc_handle); // for each domain in our data, look for it in the system dominfo structure // and purge the domain's data from our state if it does not exist in the // dominfo structure for (idx=0; idx<NDOMAINS; idx++) { int domid = new_qos->domain_info[idx].id; int jdx; for (jdx=0; jdx<ndomains; jdx++) { if (dominfo[jdx].domid == domid) break; } if (jdx == ndomains) // we didn't find domid in the dominfo struct if (domid != IDLE_DOMAIN_ID) // exception for idle domain, which is not // contained in dominfo qos_kill_thread(domid); // purge our stale data } // look again for a free slot for (idx=0; idx<NDOMAINS; idx++) if (new_qos->domain_info[idx].in_use == 0) { global_init_domain(domid, idx); return idx; } // still no space found, so bail fprintf(stderr, "out of space in domain table, increase NDOMAINS\r\n"); exit(2); }
/* retrieve access decision based on domain ids or ssidrefs */ static PyObject *getdecision(PyObject * self, PyObject * args) { char *arg1_name, *arg1, *arg2_name, *arg2, *decision = NULL; struct acm_getdecision getdecision; int xc_handle, rc; uint32_t hooktype; if (!PyArg_ParseTuple(args, "ssssi", &arg1_name, &arg1, &arg2_name, &arg2, &hooktype)) { return NULL; } if ((xc_handle = xc_interface_open()) <= 0) { PERROR("Could not open xen privcmd device!\n"); return NULL; } if ((strcmp(arg1_name, "domid") && strcmp(arg1_name, "ssidref")) || (strcmp(arg2_name, "domid") && strcmp(arg2_name, "ssidref"))) return NULL; getdecision.hook = hooktype; if (!strcmp(arg1_name, "domid")) { getdecision.get_decision_by1 = ACM_GETBY_domainid; getdecision.id1.domainid = atoi(arg1); } else { getdecision.get_decision_by1 = ACM_GETBY_ssidref; getdecision.id1.ssidref = atol(arg1); } if (!strcmp(arg2_name, "domid")) { getdecision.get_decision_by2 = ACM_GETBY_domainid; getdecision.id2.domainid = atoi(arg2); } else { getdecision.get_decision_by2 = ACM_GETBY_ssidref; getdecision.id2.ssidref = atol(arg2); } rc = xc_acm_op(xc_handle, ACMOP_getdecision, &getdecision, sizeof(getdecision)); xc_interface_close(xc_handle); if (rc < 0) { if (errno == EACCES) PERROR("ACM operation failed."); return NULL; } if (getdecision.acm_decision == ACM_ACCESS_PERMITTED) decision = "PERMITTED"; else if (getdecision.acm_decision == ACM_ACCESS_DENIED) decision = "DENIED"; return Py_BuildValue("s", decision); }
CAMLprim value stub_xenguest_init() { xc_interface *xch; openlog("xenguest", LOG_NDELAY, LOG_DAEMON); xch = xc_interface_open(NULL, NULL, 0); if (xch == NULL) failwith_oss_xc(NULL, "xc_interface_open"); return (value)xch; }
void xen_kexec_exec(void) { xc_interface *xch; xch = xc_interface_open(NULL, NULL, 0); if (!xch) return; xc_kexec_exec(xch, KEXEC_TYPE_DEFAULT); xc_interface_close(xch); }
static void startup(const char *op) { logger = (xentoollog_logger*)createlogger_tellparent(); if (!logger) { fprintf(stderr, "%s: cannot initialise logger\n", program); exit(-1); } xtl_log(logger,XTL_DEBUG,0,program,"starting %s",op); xch = xc_interface_open(logger,logger,0); if (!xch) fail(errno,"xc_interface_open failed"); }
static int xencpu_init (void) { xc_handle = xc_interface_open(XC_INTERFACE_INIT_ARGS); if (!xc_handle) { ERROR ("xencpu: xc_interface_open() failed"); return (-1); } xc_physinfo_t *physinfo; physinfo = calloc(1, sizeof(xc_physinfo_t)); if (physinfo == NULL) { ERROR ("xencpu plugin: calloc() for physinfo failed."); xc_interface_close(xc_handle); return (ENOMEM); } if (xc_physinfo(xc_handle, physinfo) < 0) { ERROR ("xencpu plugin: xc_physinfo() failed"); xc_interface_close(xc_handle); free(physinfo); return (-1); } num_cpus = physinfo->nr_cpus; free(physinfo); INFO ("xencpu plugin: Found %"PRIu32" processors.", num_cpus); cpu_info = calloc(num_cpus, sizeof(xc_cpuinfo_t)); if (cpu_info == NULL) { ERROR ("xencpu plugin: calloc() for num_cpus failed."); xc_interface_close(xc_handle); return (ENOMEM); } cpu_states = calloc (num_cpus, sizeof (value_to_rate_state_t)); if (cpu_states == NULL) { ERROR ("xencpu plugin: calloc() for cpu_states failed."); xc_interface_close(xc_handle); free(cpu_info); return (ENOMEM); } return (0); } /* static int xencpu_init */
static PyObject *chgpolicy(PyObject *self, PyObject *args) { struct acm_change_policy chgpolicy; int xc_handle, rc; char *bin_pol = NULL, *del_arr = NULL, *chg_arr = NULL; int bin_pol_len = 0, del_arr_len = 0, chg_arr_len = 0; uint errarray_mbrs = 20 * 2; uint32_t error_array[errarray_mbrs]; PyObject *result; uint len; memset(&chgpolicy, 0x0, sizeof(chgpolicy)); if (!PyArg_ParseTuple(args, "s#s#s#" ,&bin_pol, &bin_pol_len, &del_arr, &del_arr_len, &chg_arr, &chg_arr_len)) { PyErr_SetString(PyExc_TypeError, bad_arg); return NULL; } chgpolicy.policy_pushcache_size = bin_pol_len; chgpolicy.delarray_size = del_arr_len; chgpolicy.chgarray_size = chg_arr_len; chgpolicy.errarray_size = sizeof(error_array); set_xen_guest_handle(chgpolicy.policy_pushcache, bin_pol); set_xen_guest_handle(chgpolicy.del_array, del_arr); set_xen_guest_handle(chgpolicy.chg_array, chg_arr); set_xen_guest_handle(chgpolicy.err_array, error_array); if ((xc_handle = xc_interface_open()) <= 0) { PyErr_SetString(PyExc_IOError, ctrlif_op); return NULL; } rc = xc_acm_op(xc_handle, ACMOP_chgpolicy, &chgpolicy, sizeof(chgpolicy)); xc_interface_close(xc_handle); /* only pass the filled error codes */ for (len = 0; (len + 1) < errarray_mbrs; len += 2) { if (error_array[len] == 0) { len *= sizeof(error_array[0]); break; } } result = Py_BuildValue("is#", rc, error_array, len); return result; }
int main(int argc, char * argv[]) { struct xen_sysctl sysctl; int ret; xc_interface *xc_handle = xc_interface_open(0,0,0); sysctl.cmd = XEN_SYSCTL_tbuf_op; sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION; sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_get_info; ret = xc_sysctl(xc_handle, &sysctl); if ( ret != 0 ) { perror("Failure to get event mask from Xen"); exit(1); } else { printf("Current event mask: 0x%.8x\n", sysctl.u.tbuf_op.evt_mask); } sysctl.cmd = XEN_SYSCTL_tbuf_op; sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION; sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_set_evt_mask; sysctl.u.tbuf_op.evt_mask = XENMON; ret = xc_sysctl(xc_handle, &sysctl); printf("Setting mask to 0x%.8x\n", sysctl.u.tbuf_op.evt_mask); if ( ret != 0 ) { perror("Failure to get scheduler ID from Xen"); exit(1); } sysctl.cmd = XEN_SYSCTL_tbuf_op; sysctl.interface_version = XEN_SYSCTL_INTERFACE_VERSION; sysctl.u.tbuf_op.cmd = XEN_SYSCTL_TBUFOP_get_info; ret = xc_sysctl(xc_handle, &sysctl); if ( ret != 0 ) { perror("Failure to get event mask from Xen"); exit(1); } else { printf("Current event mask: 0x%.8x\n", sysctl.u.tbuf_op.evt_mask); } xc_interface_close(xc_handle); return 0; }