ia64/xen-unstable

view tools/libxc/xc_gnttab.c @ 6385:f34e732ed4bf

Xenstore testsuite robustness: save output rather than rerun on failure.
"make check" reruns a test which fails with more verbosity. If the test
fails intermittently, that doesn't work well: save the output and simply
dump it if the test fails.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Signed-off-by: Christian Limpach <Christian.Limpach@cl.cam.ac.uk>
author cl349@firebug.cl.cam.ac.uk
date Tue Aug 23 19:58:59 2005 +0000 (2005-08-23)
parents 522bc50588ed
children 8799d14bef77 9312a3e8a6f8 cc5f88b719d0 fa0754a9f64f 112d44270733
line source
1 /******************************************************************************
2 * xc_gnttab.c
3 *
4 * API for manipulating and accessing grant tables
5 *
6 * Copyright (c) 2005 Christopher Clark
7 * based on xc_evtchn.c Copyright (c) 2004, K A Fraser.
8 */
10 #include "xc_private.h"
11 #include "xen/grant_table.h"
13 static int
14 do_gnttab_op(int xc_handle,
15 unsigned long cmd,
16 void *op,
17 unsigned long count)
18 {
19 int ret = -1;
20 privcmd_hypercall_t hypercall;
22 hypercall.op = __HYPERVISOR_grant_table_op;
23 hypercall.arg[0] = cmd;
24 hypercall.arg[1] = (unsigned long)op;
25 hypercall.arg[2] = count;
27 if ( mlock(op, 64) )
28 {
29 PERROR("do_gnttab_op: op mlock failed");
30 goto out;
31 }
33 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
34 ERROR("do_gnttab_op: HYPERVISOR_grant_table_op failed: %d", ret);
36 safe_munlock(op, 64);
37 out:
38 return ret;
39 }
42 int xc_gnttab_map_grant_ref(int xc_handle,
43 u64 host_virt_addr,
44 u32 dom,
45 u16 ref,
46 u16 flags,
47 s16 *handle,
48 u64 *dev_bus_addr)
49 {
50 struct gnttab_map_grant_ref op;
51 int rc;
53 op.host_addr = host_virt_addr;
54 op.dom = (domid_t)dom;
55 op.ref = ref;
56 op.flags = flags;
58 if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_map_grant_ref,
59 &op, 1)) == 0 )
60 {
61 *handle = op.handle;
62 *dev_bus_addr = op.dev_bus_addr;
63 }
65 return rc;
66 }
69 int xc_gnttab_unmap_grant_ref(int xc_handle,
70 u64 host_virt_addr,
71 u64 dev_bus_addr,
72 u16 handle,
73 s16 *status)
74 {
75 struct gnttab_unmap_grant_ref op;
76 int rc;
78 op.host_addr = host_virt_addr;
79 op.dev_bus_addr = dev_bus_addr;
80 op.handle = handle;
82 if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_unmap_grant_ref,
83 &op, 1)) == 0 )
84 {
85 *status = op.status;
86 }
88 return rc;
89 }
91 int xc_gnttab_setup_table(int xc_handle,
92 u32 dom,
93 u16 nr_frames,
94 s16 *status,
95 unsigned long **frame_list)
96 {
97 struct gnttab_setup_table op;
98 int rc, i;
100 op.dom = (domid_t)dom;
101 op.nr_frames = nr_frames;
103 if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_setup_table, &op, 1)) == 0 )
104 {
105 *status = op.status;
106 for ( i = 0; i < nr_frames; i++ )
107 (*frame_list)[i] = op.frame_list[i];
108 }
110 return rc;
111 }
113 int xc_gnttab_dump_table(int xc_handle,
114 u32 dom,
115 s16 *status)
116 {
117 struct gnttab_dump_table op;
118 int rc;
120 op.dom = (domid_t)dom;
122 if ( (rc = do_gnttab_op(xc_handle, GNTTABOP_dump_table, &op, 1)) == 0 )
123 *status = op.status;
125 return rc;
126 }
128 int xc_grant_interface_open(void)
129 {
130 int fd = open("/proc/xen/grant", O_RDWR);
131 if ( fd == -1 )
132 PERROR("Could not obtain handle on grant command interface");
133 return fd;
135 }
137 int xc_grant_interface_close(int xc_grant_handle)
138 {
139 return close(xc_grant_handle);
140 }