2 * This binary provides access to the guest's balloon driver
5 * Copyright (C) 2007 Qumranet
9 * Dor Laor <dor.laor@qumranet.com>
11 * This work is licensed under the GNU LGPL license, version 2.
21 #include <sys/ioctl.h>
24 #include <linux/kvm.h>
26 #define PAGE_SIZE 4096ul
29 static int balloon_op(int *fd
, int bytes
)
31 struct kvm_balloon_op bop
;
34 bop
.npages
= bytes
/PAGE_SIZE
;
35 r
= ioctl(*fd
, KVM_BALLOON_OP
, &bop
);
38 printf("Ballon handled %d pages successfully\n", bop
.npages
);
43 static int balloon_init(int *fd
)
45 *fd
= open("/dev/kvm_balloon", O_RDWR
);
47 perror("open /dev/kvm_balloon");
54 int main(int argc
, char *argv
[])
61 perror("Please provide op=[i|d], bytes\n");
64 bytes
= atoi(argv
[2]);
73 perror("Wrong op param\n");
77 if (balloon_init(&fd
)) {
78 perror("balloon_init failed\n");
82 if ((r
= balloon_op(&fd
, bytes
))) {
83 perror("balloon_op failed\n");