ia64/xen-unstable

view tools/libxc/xc_gnttab.c @ 7238:971e7c7411b3

Raise an exception if an error appears on the pipes to our children, and make
sure that the child's pipes are closed even under that exception. Move the
handling of POLLHUP to the end of the loop, so that we guarantee to read any
remaining data from the child if POLLHUP and POLLIN appear at the same time.

Signed-off-by: Ewan Mellor <ewan@xensource.com>
author emellor@ewan
date Thu Oct 06 10:13:11 2005 +0100 (2005-10-06)
parents 06d84bf87159
children b3a255e88810
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 }