direct-io.hg

view tools/balloon/balloon.c @ 399:47d2a4460ed1

bitkeeper revision 1.184.5.1 (3ead2bacOfPX2Bo4kzErV1yUs0q1qA)

Many files:
Pass dom_id and other flags to domains in start_info structure. Allow changing of IO privilege level via new hypercall.
author kaf24@scramble.cl.cam.ac.uk
date Mon Apr 28 13:25:00 2003 +0000 (2003-04-28)
parents d5a6350b99c8
children 4d18dbf45e16
line source
1 /******************************************************************************
2 * balloon.c
3 *
4 * Xeno balloon driver userspace control tool. Used to shrink/grow domain's
5 * memory.
6 *
7 * Copyright (c) 2003, B Dragovic
8 */
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include <errno.h>
14 #include <unistd.h>
15 #include <sys/types.h>
16 #include <sys/stat.h>
17 #include <fcntl.h>
19 #define INFLATE_BALLOON "inflate" /* return mem to hypervisor */
20 #define DEFLATE_BALLOON "deflate" /* claim mem from hypervisor */
22 /* THIS IS TAKEN FROM XENOLINUX BALLOON DRIVER */
23 #define USER_INFLATE_BALLOON 1 /* return mem to hypervisor */
24 #define USER_DEFLATE_BALLOON 2 /* claim mem from hypervisor */
25 typedef struct user_balloon_op {
26 unsigned int op;
27 unsigned long size;
28 } user_balloon_op_t;
29 /* END OF CODE TAKEN FROM XENOLINUX BALLOON DRIVER */
32 static int open_balloon_proc()
33 {
34 return open("/proc/xeno/balloon", O_RDWR);
35 }
37 /* inflate balloon function signals to kernel it should relinquish memory */
38 static int inflate_balloon(unsigned long num_pages)
39 {
40 user_balloon_op_t bop;
41 int proc_fd;
43 if((proc_fd = open_balloon_proc()) <= 0){
44 printf("Error opening balloon proc file.\n");
45 return 0;
46 }
48 bop.op = USER_INFLATE_BALLOON;
49 bop.size = num_pages;
50 if ( write(proc_fd, &bop, sizeof(bop)) <= 0 )
51 {
52 printf("Error writing to balloon proc file.\n");
53 return 0;
54 }
56 close(proc_fd);
57 return 1;
58 }
60 /* deflate balloon function signals to kernel it should claim memory */
61 static int deflate_balloon(unsigned long num_pages)
62 {
63 user_balloon_op_t bop;
64 int proc_fd;
66 if((proc_fd = open_balloon_proc()) <= 0){
67 printf("Error opening balloon proc file.\n");
68 return 0;
69 }
71 bop.op = USER_DEFLATE_BALLOON;
72 bop.size = num_pages;
73 if(write(proc_fd, &bop, sizeof(bop)) <= 0){
74 printf("Error writing to balloon proc file.\n");
75 return 0;
76 }
78 close(proc_fd);
79 return 1;
80 }
82 int main(int argc, char *argv[])
83 {
84 unsigned long num_pages;
86 if(argc < 2){
87 printf("Usage: balloon <inflate|deflate> <num_pages>\n");
88 return -1;
89 }
91 num_pages = atol(argv[2]);
93 if(!strcmp(argv[1], INFLATE_BALLOON)){
94 if(!inflate_balloon(num_pages)){
95 perror("Inflating balloon failed");
96 return -1;
97 }
99 } else if (!strcmp(argv[1], DEFLATE_BALLOON)){
100 if(!deflate_balloon(num_pages)){
101 perror("Deflating balloon failed");
102 return -1;
103 }
105 } else {
106 printf("Unrecognized command line argument.\n");
107 return -1;
108 }
110 return 0;
111 }