direct-io.hg

view tools/libxc/xc_private.h @ 8686:c0a0f4db5ab1

Create a block of reserved PFNs in shadow translate mode guests, and
move the shared info and grant table pfns into that block. This
allows us to remove the get_gnttablist dom0 op, and simplifies the
domain creation code slightly. Having the reserved block managed by
Xen may also make it slightly easier to handle the case where the
grant table needs to be extended at run time.

Suggested-by: kaf24
Signed-off-by: Steven Smith, sos22@cam.ac.uk
author sos22@douglas.cl.cam.ac.uk
date Thu Jan 26 19:40:13 2006 +0100 (2006-01-26)
parents cc9bb3e0e348
children 74ee53209cca
line source
2 #ifndef XC_PRIVATE_H
3 #define XC_PRIVATE_H
5 #include <unistd.h>
6 #include <stdio.h>
7 #include <errno.h>
8 #include <fcntl.h>
9 #include <string.h>
10 #include <sys/mman.h>
11 #include <sys/types.h>
12 #include <sys/stat.h>
13 #include <stdlib.h>
14 #include <sys/ioctl.h>
16 #include "xenctrl.h"
18 #include <xen/linux/privcmd.h>
20 /* valgrind cannot see when a hypercall has filled in some values. For this
21 reason, we must zero the privcmd_hypercall_t or dom0_op_t instance before a
22 call, if using valgrind. */
23 #ifdef VALGRIND
24 #define DECLARE_HYPERCALL privcmd_hypercall_t hypercall = { 0 }
25 #define DECLARE_DOM0_OP dom0_op_t op = { 0 }
26 #else
27 #define DECLARE_HYPERCALL privcmd_hypercall_t hypercall
28 #define DECLARE_DOM0_OP dom0_op_t op
29 #endif
32 #define PAGE_SHIFT XC_PAGE_SHIFT
33 #define PAGE_SIZE (1UL << PAGE_SHIFT)
34 #define PAGE_MASK (~(PAGE_SIZE-1))
36 #define ERROR(_m, _a...) \
37 do { \
38 int __saved_errno = errno; \
39 fprintf(stderr, "ERROR: " _m "\n" , ## _a ); \
40 errno = __saved_errno; \
41 } while (0)
44 #define PERROR(_m, _a...) \
45 do { \
46 int __saved_errno = errno; \
47 fprintf(stderr, "ERROR: " _m " (%d = %s)\n" , ## _a , \
48 __saved_errno, strerror(__saved_errno)); \
49 errno = __saved_errno; \
50 } while (0)
52 static inline void safe_munlock(const void *addr, size_t len)
53 {
54 int saved_errno = errno;
55 (void)munlock(addr, len);
56 errno = saved_errno;
57 }
59 static inline int do_privcmd(int xc_handle,
60 unsigned int cmd,
61 unsigned long data)
62 {
63 return ioctl(xc_handle, cmd, data);
64 }
66 static inline int do_xen_hypercall(int xc_handle,
67 privcmd_hypercall_t *hypercall)
68 {
69 return do_privcmd(xc_handle,
70 IOCTL_PRIVCMD_HYPERCALL,
71 (unsigned long)hypercall);
72 }
74 static inline int do_xen_version(int xc_handle, int cmd, void *dest)
75 {
76 DECLARE_HYPERCALL;
78 hypercall.op = __HYPERVISOR_xen_version;
79 hypercall.arg[0] = (unsigned long) cmd;
80 hypercall.arg[1] = (unsigned long) dest;
82 return do_xen_hypercall(xc_handle, &hypercall);
83 }
85 static inline int do_dom0_op(int xc_handle, dom0_op_t *op)
86 {
87 int ret = -1;
88 DECLARE_HYPERCALL;
90 op->interface_version = DOM0_INTERFACE_VERSION;
92 hypercall.op = __HYPERVISOR_dom0_op;
93 hypercall.arg[0] = (unsigned long)op;
95 if ( mlock(op, sizeof(*op)) != 0 )
96 {
97 PERROR("Could not lock memory for Xen hypercall");
98 goto out1;
99 }
101 if ( (ret = do_xen_hypercall(xc_handle, &hypercall)) < 0 )
102 {
103 if ( errno == EACCES )
104 fprintf(stderr, "Dom0 operation failed -- need to"
105 " rebuild the user-space tool set?\n");
106 }
108 safe_munlock(op, sizeof(*op));
110 out1:
111 return ret;
112 }
115 /*
116 * ioctl-based mfn mapping interface
117 */
119 /*
120 typedef struct privcmd_mmap_entry {
121 unsigned long va;
122 unsigned long mfn;
123 unsigned long npages;
124 } privcmd_mmap_entry_t;
126 typedef struct privcmd_mmap {
127 int num;
128 domid_t dom;
129 privcmd_mmap_entry_t *entry;
130 } privcmd_mmap_t;
131 */
133 #endif /* __XC_PRIVATE_H__ */