This patch adds a ballooning infrastructure to QEMU. This includes a pair of monitor commands, balloon and info balloon, to balloon a guest and to query the guest's balloon status.
Signed-off-by: Anthony Liguori <[EMAIL PROTECTED]> diff --git a/qemu/balloon.h b/qemu/balloon.h new file mode 100644 index 0000000..60b4a5d --- /dev/null +++ b/qemu/balloon.h @@ -0,0 +1,27 @@ +/* + * Balloon + * + * Copyright IBM, Corp. 2008 + * + * Authors: + * Anthony Liguori <[EMAIL PROTECTED]> + * + * This work is licensed under the terms of the GNU GPL, version 2. See + * the COPYING file in the top-level directory. + * + */ + +#ifndef _QEMU_BALLOON_H +#define _QEMU_BALLOON_H + +#include "cpu-defs.h" + +typedef ram_addr_t (QEMUBalloonEvent)(void *opaque, ram_addr_t target); + +void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque); + +void qemu_balloon(ram_addr_t target); + +ram_addr_t qemu_balloon_status(void); + +#endif diff --git a/qemu/monitor.c b/qemu/monitor.c index 4acf346..2240d8e 100644 --- a/qemu/monitor.c +++ b/qemu/monitor.c @@ -35,6 +35,7 @@ #include "audio/audio.h" #include "disas.h" #include "migration.h" +#include "balloon.h" #include <dirent.h> #include "qemu-timer.h" @@ -1399,6 +1400,23 @@ static void do_inject_nmi(int cpu_index) } #endif +static void do_balloon(int value) +{ + ram_addr_t target = value; + qemu_balloon(target << 20); +} + +static void do_info_balloon(void) +{ + ram_addr_t actual; + + actual = qemu_balloon_status(); + if (actual == 0) + term_printf("Ballooning not activated in VM\n"); + else + term_printf("balloon: actual=%d\n", (int)(actual >> 20)); +} + static term_cmd_t term_cmds[] = { { "help|?", "s?", do_help, "[cmd]", "show the help" }, @@ -1494,6 +1512,8 @@ static term_cmd_t term_cmds[] = { { "pci_add", "iss", device_hot_add, "bus nic|storage [[vlan=n][,macaddr=addr][,model=type]] [file=file][,if=type][,bus=nr]...", "hot-add PCI device" }, { "pci_del", "ii", device_hot_remove, "bus slot-number", "hot remove PCI device" }, #endif + { "balloon", "i", do_balloon, + "target", "request VM to change it's memory allocation (in MB)" }, { NULL, NULL, }, }; @@ -1558,6 +1578,8 @@ static term_cmd_t info_cmds[] = { #endif { "migration", "", do_info_migration, "", "show migration information" }, + { "balloon", "", do_info_balloon, + "", "show balloon information" }, { NULL, NULL, }, }; diff --git a/qemu/vl.c b/qemu/vl.c index 2dc1311..ec89921 100644 --- a/qemu/vl.c +++ b/qemu/vl.c @@ -38,6 +38,7 @@ #include "block.h" #include "audio/audio.h" #include "migration.h" +#include "balloon.h" #include "qemu-kvm.h" #include <unistd.h> @@ -530,6 +531,31 @@ void hw_error(const char *fmt, ...) va_end(ap); abort(); } + +/***************/ +/* ballooning */ + +static QEMUBalloonEvent *qemu_balloon_event; +void *qemu_balloon_event_opaque; + +void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque) +{ + qemu_balloon_event = func; + qemu_balloon_event_opaque = opaque; +} + +void qemu_balloon(ram_addr_t target) +{ + if (qemu_balloon_event) + qemu_balloon_event(qemu_balloon_event_opaque, target); +} + +ram_addr_t qemu_balloon_status(void) +{ + if (qemu_balloon_event) + return qemu_balloon_event(qemu_balloon_event_opaque, 0); + return 0; +} /***********************************************************/ /* keyboard/mouse */ -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html