本文整理汇总了C++中xc_interface_open函数的典型用法代码示例。如果您正苦于以下问题:C++ xc_interface_open函数的具体用法?C++ xc_interface_open怎么用?C++ xc_interface_open使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xc_interface_open函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_memory_ranges_xen
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;
}
示例2: xen_init
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;
}
示例3: bzero
/* 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 */
}
示例4: xen_setup
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;
}
示例5: xen_setup
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;
}
示例6: xsh_
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" );
}
}
示例7: main
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;
}
示例8: malloc
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;
}
示例9: openXenHandles
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
}
}
}
示例10: xc_interface_open
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);
}
示例11: xc_interface_open
/**
* 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;
}
示例12: main
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;
}
示例13: PERROR
/* 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;
}
示例14: sizeof
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;
}
示例15: xen_init_interface
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;
}