debuggers.hg

view tools/xenpaging/xc.c @ 21067:b4a1832a916f

Update Xen version to 4.0.0-rc6
author Keir Fraser <keir.fraser@citrix.com>
date Tue Mar 09 18:18:05 2010 +0000 (2010-03-09)
parents 47ec2d131c22
children 17fa3cd04361
line source
1 /******************************************************************************
2 * tools/xenpaging/lib/xc.c
3 *
4 * libxc-type add-ons for paging support.
5 *
6 * Copyright (c) 2009 Citrix Systems, Inc. (Patrick Colp)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
24 #include <errno.h>
25 #include <sys/poll.h>
26 #include <xc_private.h>
27 #include <xg_save_restore.h>
28 #include <xs.h>
29 #include "xc.h"
32 int alloc_bitmap(unsigned long **bitmap, unsigned long bitmap_size)
33 {
34 if ( *bitmap == NULL )
35 {
36 *bitmap = calloc(bitmap_size / BITS_PER_LONG, sizeof(unsigned long));
38 if ( *bitmap == NULL )
39 return -ENOMEM;
40 }
42 memset(*bitmap, 0, bitmap_size / 8);
44 return 0;
45 }
47 int xc_mem_paging_flush_ioemu_cache(domid_t domain_id)
48 {
49 struct xs_handle *xsh = NULL;
50 char path[80];
51 int rc;
53 sprintf(path, "/local/domain/0/device-model/%u/command", domain_id);
55 xsh = xs_daemon_open();
56 if ( xsh == NULL )
57 return -EIO;
59 rc = xs_write(xsh, XBT_NULL, path, "flush-cache", strlen(path));
61 xs_daemon_close(xsh);
63 return rc;
64 }
66 int xc_wait_for_event_or_timeout(int xce_handle, unsigned long ms)
67 {
68 struct pollfd fd = { .fd = xce_handle, .events = POLLIN | POLLERR };
69 int port;
70 int rc;
72 rc = poll(&fd, 1, ms);
73 if ( rc == -1 )
74 {
75 if (errno == EINTR)
76 return 0;
78 ERROR("Poll exited with an error");
79 goto err;
80 }
82 if ( rc == 1 )
83 {
84 port = xc_evtchn_pending(xce_handle);
85 if ( port == -1 )
86 {
87 ERROR("Failed to read port from event channel");
88 goto err;
89 }
91 rc = xc_evtchn_unmask(xce_handle, port);
92 if ( rc != 0 )
93 {
94 ERROR("Failed to unmask event channel port");
95 goto err;
96 }
97 }
98 else
99 port = -1;
101 return port;
103 err:
104 return -errno;
105 }
107 int xc_wait_for_event(int xce_handle)
108 {
109 return xc_wait_for_event_or_timeout(xce_handle, -1);
110 }
112 int xc_get_platform_info(int xc_handle, domid_t domain_id,
113 xc_platform_info_t *platform_info)
114 {
115 return get_platform_info(xc_handle, domain_id,
116 &platform_info->max_mfn,
117 &platform_info->hvirt_start,
118 &platform_info->pt_levels,
119 &platform_info->guest_width);
120 }
123 /*
124 * Local variables:
125 * mode: C
126 * c-set-style: "BSD"
127 * c-basic-offset: 4
128 * tab-width: 4
129 * indent-tabs-mode: nil
130 * End:
131 */