* [Qemu-devel] [PATCH 0/3] more vl.c/monitor.c splits @ 2010-03-19 10:35 Paolo Bonzini 2010-03-19 10:35 ` [Qemu-devel] [PATCH 1/3] move socket_init to qemu-sockets.c Paolo Bonzini ` (2 more replies) 0 siblings, 3 replies; 5+ messages in thread From: Paolo Bonzini @ 2010-03-19 10:35 UTC (permalink / raw) To: qemu-devel I've had these for a while, but as they conflicted with the timer patch I waited before sending them. Paolo Bonzini (3): move socket_init to qemu-sockets.c move two variable declarations out of vl.c move balloon handling to balloon.c Makefile.target | 2 +- balloon.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ balloon.h | 6 ++ hw/i8259.c | 1 + hw/isa-bus.c | 1 + monitor.c | 85 -------------------------------- qemu-sockets.c | 24 +++++++++ qemu_socket.h | 1 + vl.c | 64 ------------------------ 9 files changed, 179 insertions(+), 150 deletions(-) create mode 100644 balloon.c ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 1/3] move socket_init to qemu-sockets.c 2010-03-19 10:35 [Qemu-devel] [PATCH 0/3] more vl.c/monitor.c splits Paolo Bonzini @ 2010-03-19 10:35 ` Paolo Bonzini 2010-03-19 10:35 ` [Qemu-devel] [PATCH 2/3] move two variable declarations out of vl.c Paolo Bonzini 2010-03-19 10:35 ` [Qemu-devel] [PATCH 3/3] move balloon handling to balloon.c Paolo Bonzini 2 siblings, 0 replies; 5+ messages in thread From: Paolo Bonzini @ 2010-03-19 10:35 UTC (permalink / raw) To: qemu-devel Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- qemu-sockets.c | 24 ++++++++++++++++++++++++ qemu_socket.h | 1 + vl.c | 24 ------------------------ 3 files changed, 25 insertions(+), 24 deletions(-) diff --git a/qemu-sockets.c b/qemu-sockets.c index 23c3def..a7399aa 100644 --- a/qemu-sockets.c +++ b/qemu-sockets.c @@ -648,3 +648,27 @@ int unix_connect(const char *path) } #endif + +#ifdef _WIN32 +static void socket_cleanup(void) +{ + WSACleanup(); +} +#endif + +int socket_init(void) +{ +#ifdef _WIN32 + WSADATA Data; + int ret, err; + + ret = WSAStartup(MAKEWORD(2,2), &Data); + if (ret != 0) { + err = WSAGetLastError(); + fprintf(stderr, "WSAStartup: %d\n", err); + return -1; + } + atexit(socket_cleanup); +#endif + return 0; +} diff --git a/qemu_socket.h b/qemu_socket.h index 7ee46ac..164ae3e 100644 --- a/qemu_socket.h +++ b/qemu_socket.h @@ -56,5 +56,6 @@ int parse_host_port(struct sockaddr_in *saddr, const char *str); int parse_host_src_port(struct sockaddr_in *haddr, struct sockaddr_in *saddr, const char *str); +int socket_init(void); #endif /* QEMU_SOCKET_H */ diff --git a/vl.c b/vl.c index 6948157..f2056f8 100644 --- a/vl.c +++ b/vl.c @@ -531,28 +531,6 @@ static void configure_rtc(QemuOpts *opts) #endif } -#ifdef _WIN32 -static void socket_cleanup(void) -{ - WSACleanup(); -} - -static int socket_init(void) -{ - WSADATA Data; - int ret, err; - - ret = WSAStartup(MAKEWORD(2,2), &Data); - if (ret != 0) { - err = WSAGetLastError(); - fprintf(stderr, "WSAStartup: %d\n", err); - return -1; - } - atexit(socket_cleanup); - return 0; -} -#endif - /***********************************************************/ /* Bluetooth support */ static int nb_hcis; @@ -4734,9 +4712,7 @@ int main(int argc, char **argv, char **envp) } configure_icount(icount_option); -#ifdef _WIN32 socket_init(); -#endif if (net_init_clients() < 0) { exit(1); -- 1.6.6.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 2/3] move two variable declarations out of vl.c 2010-03-19 10:35 [Qemu-devel] [PATCH 0/3] more vl.c/monitor.c splits Paolo Bonzini 2010-03-19 10:35 ` [Qemu-devel] [PATCH 1/3] move socket_init to qemu-sockets.c Paolo Bonzini @ 2010-03-19 10:35 ` Paolo Bonzini 2010-03-19 10:35 ` [Qemu-devel] [PATCH 3/3] move balloon handling to balloon.c Paolo Bonzini 2 siblings, 0 replies; 5+ messages in thread From: Paolo Bonzini @ 2010-03-19 10:35 UTC (permalink / raw) To: qemu-devel Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- hw/i8259.c | 1 + hw/isa-bus.c | 1 + vl.c | 6 ------ 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/hw/i8259.c b/hw/i8259.c index 3de22e3..37ef04e 100644 --- a/hw/i8259.c +++ b/hw/i8259.c @@ -68,6 +68,7 @@ static int irq_level[16]; #ifdef DEBUG_IRQ_COUNT static uint64_t irq_count[16]; #endif +PicState2 *isa_pic; /* set irq level. If an edge is detected, then the IRR is set to 1 */ static inline void pic_set_irq1(PicState *s, int irq, int level) diff --git a/hw/isa-bus.c b/hw/isa-bus.c index 4d489d2..4e306de 100644 --- a/hw/isa-bus.c +++ b/hw/isa-bus.c @@ -28,6 +28,7 @@ struct ISABus { uint32_t assigned; }; static ISABus *isabus; +target_phys_addr_t isa_mem_base = 0; static void isabus_dev_print(Monitor *mon, DeviceState *dev, int indent); diff --git a/vl.c b/vl.c index f2056f8..fd17795 100644 --- a/vl.c +++ b/vl.c @@ -305,12 +305,6 @@ static int default_driver_check(QemuOpts *opts, void *opaque) } /***********************************************************/ -/* x86 ISA bus support */ - -target_phys_addr_t isa_mem_base = 0; -PicState2 *isa_pic; - -/***********************************************************/ void hw_error(const char *fmt, ...) { va_list ap; -- 1.6.6.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 3/3] move balloon handling to balloon.c 2010-03-19 10:35 [Qemu-devel] [PATCH 0/3] more vl.c/monitor.c splits Paolo Bonzini 2010-03-19 10:35 ` [Qemu-devel] [PATCH 1/3] move socket_init to qemu-sockets.c Paolo Bonzini 2010-03-19 10:35 ` [Qemu-devel] [PATCH 2/3] move two variable declarations out of vl.c Paolo Bonzini @ 2010-03-19 10:35 ` Paolo Bonzini 2 siblings, 0 replies; 5+ messages in thread From: Paolo Bonzini @ 2010-03-19 10:35 UTC (permalink / raw) To: qemu-devel Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- Makefile.target | 2 +- balloon.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ balloon.h | 6 ++ monitor.c | 85 -------------------------------- vl.c | 34 ------------- 5 files changed, 152 insertions(+), 120 deletions(-) create mode 100644 balloon.c diff --git a/Makefile.target b/Makefile.target index 0c28215..f927f9e 100644 --- a/Makefile.target +++ b/Makefile.target @@ -172,7 +172,7 @@ endif #CONFIG_BSD_USER ifdef CONFIG_SOFTMMU obj-y = vl.o async.o monitor.o pci.o pci_host.o pcie_host.o machine.o gdbstub.o -obj-y += qemu-error.o qemu-timer.o +obj-y += qemu-error.o qemu-timer.o balloon.o # virtio has to be here due to weird dependency between PCI and virtio-net. # need to fix this properly obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-pci.o virtio-serial-bus.o diff --git a/balloon.c b/balloon.c new file mode 100644 index 0000000..016178f --- /dev/null +++ b/balloon.c @@ -0,0 +1,145 @@ +/* + * QEMU System Emulator + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "sysemu.h" +#include "monitor.h" +#include "qjson.h" +#include "qint.h" +#include "kvm.h" +#include "balloon.h" + + +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; +} + +int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque) +{ + if (qemu_balloon_event) { + qemu_balloon_event(qemu_balloon_event_opaque, target, cb, opaque); + return 1; + } else { + return 0; + } +} + +int qemu_balloon_status(MonitorCompletion cb, void *opaque) +{ + if (qemu_balloon_event) { + qemu_balloon_event(qemu_balloon_event_opaque, 0, cb, opaque); + return 1; + } else { + return 0; + } +} + +static void print_balloon_stat(const char *key, QObject *obj, void *opaque) +{ + Monitor *mon = opaque; + + if (strcmp(key, "actual")) + monitor_printf(mon, ",%s=%" PRId64, key, + qint_get_int(qobject_to_qint(obj))); +} + +void monitor_print_balloon(Monitor *mon, const QObject *data) +{ + QDict *qdict; + + qdict = qobject_to_qdict(data); + if (!qdict_haskey(qdict, "actual")) + return; + + monitor_printf(mon, "balloon: actual=%" PRId64, + qdict_get_int(qdict, "actual") >> 20); + qdict_iter(qdict, print_balloon_stat, mon); + monitor_printf(mon, "\n"); +} + +/** + * do_info_balloon(): Balloon information + * + * Make an asynchronous request for balloon info. When the request completes + * a QDict will be returned according to the following specification: + * + * - "actual": current balloon value in bytes + * The following fields may or may not be present: + * - "mem_swapped_in": Amount of memory swapped in (bytes) + * - "mem_swapped_out": Amount of memory swapped out (bytes) + * - "major_page_faults": Number of major faults + * - "minor_page_faults": Number of minor faults + * - "free_mem": Total amount of free and unused memory (bytes) + * - "total_mem": Total amount of available memory (bytes) + * + * Example: + * + * { "actual": 1073741824, "mem_swapped_in": 0, "mem_swapped_out": 0, + * "major_page_faults": 142, "minor_page_faults": 239245, + * "free_mem": 1014185984, "total_mem": 1044668416 } + */ +int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque) +{ + int ret; + + if (kvm_enabled() && !kvm_has_sync_mmu()) { + qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); + return -1; + } + + ret = qemu_balloon_status(cb, opaque); + if (!ret) { + qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); + return -1; + } + + return 0; +} + +/** + * do_balloon(): Request VM to change its memory allocation + */ +int do_balloon(Monitor *mon, const QDict *params, + MonitorCompletion cb, void *opaque) +{ + int ret; + + if (kvm_enabled() && !kvm_has_sync_mmu()) { + qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); + return -1; + } + + ret = qemu_balloon(qdict_get_int(params, "value"), cb, opaque); + if (ret == 0) { + qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); + return -1; + } + + cb(opaque, NULL); + return 0; +} diff --git a/balloon.h b/balloon.h index c3a1ad3..5916c0e 100644 --- a/balloon.h +++ b/balloon.h @@ -15,6 +15,7 @@ #define _QEMU_BALLOON_H #include "cpu-defs.h" +#include "monitor.h" typedef void (QEMUBalloonEvent)(void *opaque, ram_addr_t target, MonitorCompletion cb, void *cb_data); @@ -25,4 +26,9 @@ int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque); int qemu_balloon_status(MonitorCompletion cb, void *opaque); +void monitor_print_balloon(Monitor *mon, const QObject *data); +int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque); +int do_balloon(Monitor *mon, const QDict *params, + MonitorCompletion cb, void *opaque); + #endif diff --git a/monitor.c b/monitor.c index 0448a70..91499e7 100644 --- a/monitor.c +++ b/monitor.c @@ -2268,91 +2268,6 @@ static void do_info_status(Monitor *mon, QObject **ret_data) vm_running, singlestep); } -static void print_balloon_stat(const char *key, QObject *obj, void *opaque) -{ - Monitor *mon = opaque; - - if (strcmp(key, "actual")) - monitor_printf(mon, ",%s=%" PRId64, key, - qint_get_int(qobject_to_qint(obj))); -} - -static void monitor_print_balloon(Monitor *mon, const QObject *data) -{ - QDict *qdict; - - qdict = qobject_to_qdict(data); - if (!qdict_haskey(qdict, "actual")) - return; - - monitor_printf(mon, "balloon: actual=%" PRId64, - qdict_get_int(qdict, "actual") >> 20); - qdict_iter(qdict, print_balloon_stat, mon); - monitor_printf(mon, "\n"); -} - -/** - * do_info_balloon(): Balloon information - * - * Make an asynchronous request for balloon info. When the request completes - * a QDict will be returned according to the following specification: - * - * - "actual": current balloon value in bytes - * The following fields may or may not be present: - * - "mem_swapped_in": Amount of memory swapped in (bytes) - * - "mem_swapped_out": Amount of memory swapped out (bytes) - * - "major_page_faults": Number of major faults - * - "minor_page_faults": Number of minor faults - * - "free_mem": Total amount of free and unused memory (bytes) - * - "total_mem": Total amount of available memory (bytes) - * - * Example: - * - * { "actual": 1073741824, "mem_swapped_in": 0, "mem_swapped_out": 0, - * "major_page_faults": 142, "minor_page_faults": 239245, - * "free_mem": 1014185984, "total_mem": 1044668416 } - */ -static int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque) -{ - int ret; - - if (kvm_enabled() && !kvm_has_sync_mmu()) { - qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); - return -1; - } - - ret = qemu_balloon_status(cb, opaque); - if (!ret) { - qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); - return -1; - } - - return 0; -} - -/** - * do_balloon(): Request VM to change its memory allocation - */ -static int do_balloon(Monitor *mon, const QDict *params, - MonitorCompletion cb, void *opaque) -{ - int ret; - - if (kvm_enabled() && !kvm_has_sync_mmu()) { - qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); - return -1; - } - - ret = qemu_balloon(qdict_get_int(params, "value"), cb, opaque); - if (ret == 0) { - qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); - return -1; - } - - cb(opaque, NULL); - return 0; -} - static qemu_acl *find_acl(Monitor *mon, const char *name) { qemu_acl *acl = qemu_acl_find(name); diff --git a/vl.c b/vl.c index fd17795..4ca2702 100644 --- a/vl.c +++ b/vl.c @@ -146,7 +146,6 @@ int main(int argc, char **argv) #include "audio/audio.h" #include "migration.h" #include "kvm.h" -#include "balloon.h" #include "qemu-option.h" #include "qemu-config.h" #include "qemu-objects.h" @@ -340,39 +339,6 @@ static void set_proc_name(const char *s) #endif } -/***************/ -/* 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; -} - -int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque) -{ - if (qemu_balloon_event) { - qemu_balloon_event(qemu_balloon_event_opaque, target, cb, opaque); - return 1; - } else { - return 0; - } -} - -int qemu_balloon_status(MonitorCompletion cb, void *opaque) -{ - if (qemu_balloon_event) { - qemu_balloon_event(qemu_balloon_event_opaque, 0, cb, opaque); - return 1; - } else { - return 0; - } -} - - /***********************************************************/ /* real time host monotonic timer */ -- 1.6.6.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH rebased 0/3] move stuff out of vl.c @ 2010-03-31 14:56 Paolo Bonzini 2010-03-31 14:56 ` [Qemu-devel] [PATCH 3/3] move balloon handling to balloon.c Paolo Bonzini 0 siblings, 1 reply; 5+ messages in thread From: Paolo Bonzini @ 2010-03-31 14:56 UTC (permalink / raw) To: qemu-devel Rebased after Blue Swirl's changes. Paolo Bonzini (3): move socket_init to qemu-sockets.c move two variable declarations out of vl.c move balloon handling to balloon.c Makefile.target | 2 +- balloon.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ balloon.h | 7 +++ hw/i8259.c | 1 + hw/isa-bus.c | 1 + monitor.c | 85 -------------------------------- qemu-sockets.c | 24 +++++++++ qemu_socket.h | 1 + vl.c | 62 ----------------------- 9 files changed, 180 insertions(+), 148 deletions(-) create mode 100644 balloon.c ^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 3/3] move balloon handling to balloon.c 2010-03-31 14:56 [Qemu-devel] [PATCH rebased 0/3] move stuff out of vl.c Paolo Bonzini @ 2010-03-31 14:56 ` Paolo Bonzini 0 siblings, 0 replies; 5+ messages in thread From: Paolo Bonzini @ 2010-03-31 14:56 UTC (permalink / raw) To: qemu-devel Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> --- Makefile.target | 2 +- balloon.c | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ balloon.h | 7 +++ monitor.c | 85 -------------------------------- vl.c | 34 ------------- 5 files changed, 153 insertions(+), 120 deletions(-) create mode 100644 balloon.c diff --git a/Makefile.target b/Makefile.target index dbffe63..9ca6636 100644 --- a/Makefile.target +++ b/Makefile.target @@ -161,7 +161,7 @@ endif #CONFIG_BSD_USER # System emulator target ifdef CONFIG_SOFTMMU -obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o +obj-y = arch_init.o cpus.o monitor.o machine.o gdbstub.o balloon.o # virtio has to be here due to weird dependency between PCI and virtio-net. # need to fix this properly obj-y += virtio-blk.o virtio-balloon.o virtio-net.o virtio-serial-bus.o diff --git a/balloon.c b/balloon.c new file mode 100644 index 0000000..016178f --- /dev/null +++ b/balloon.c @@ -0,0 +1,145 @@ +/* + * QEMU System Emulator + * + * Copyright (c) 2003-2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "sysemu.h" +#include "monitor.h" +#include "qjson.h" +#include "qint.h" +#include "kvm.h" +#include "balloon.h" + + +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; +} + +int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque) +{ + if (qemu_balloon_event) { + qemu_balloon_event(qemu_balloon_event_opaque, target, cb, opaque); + return 1; + } else { + return 0; + } +} + +int qemu_balloon_status(MonitorCompletion cb, void *opaque) +{ + if (qemu_balloon_event) { + qemu_balloon_event(qemu_balloon_event_opaque, 0, cb, opaque); + return 1; + } else { + return 0; + } +} + +static void print_balloon_stat(const char *key, QObject *obj, void *opaque) +{ + Monitor *mon = opaque; + + if (strcmp(key, "actual")) + monitor_printf(mon, ",%s=%" PRId64, key, + qint_get_int(qobject_to_qint(obj))); +} + +void monitor_print_balloon(Monitor *mon, const QObject *data) +{ + QDict *qdict; + + qdict = qobject_to_qdict(data); + if (!qdict_haskey(qdict, "actual")) + return; + + monitor_printf(mon, "balloon: actual=%" PRId64, + qdict_get_int(qdict, "actual") >> 20); + qdict_iter(qdict, print_balloon_stat, mon); + monitor_printf(mon, "\n"); +} + +/** + * do_info_balloon(): Balloon information + * + * Make an asynchronous request for balloon info. When the request completes + * a QDict will be returned according to the following specification: + * + * - "actual": current balloon value in bytes + * The following fields may or may not be present: + * - "mem_swapped_in": Amount of memory swapped in (bytes) + * - "mem_swapped_out": Amount of memory swapped out (bytes) + * - "major_page_faults": Number of major faults + * - "minor_page_faults": Number of minor faults + * - "free_mem": Total amount of free and unused memory (bytes) + * - "total_mem": Total amount of available memory (bytes) + * + * Example: + * + * { "actual": 1073741824, "mem_swapped_in": 0, "mem_swapped_out": 0, + * "major_page_faults": 142, "minor_page_faults": 239245, + * "free_mem": 1014185984, "total_mem": 1044668416 } + */ +int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque) +{ + int ret; + + if (kvm_enabled() && !kvm_has_sync_mmu()) { + qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); + return -1; + } + + ret = qemu_balloon_status(cb, opaque); + if (!ret) { + qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); + return -1; + } + + return 0; +} + +/** + * do_balloon(): Request VM to change its memory allocation + */ +int do_balloon(Monitor *mon, const QDict *params, + MonitorCompletion cb, void *opaque) +{ + int ret; + + if (kvm_enabled() && !kvm_has_sync_mmu()) { + qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); + return -1; + } + + ret = qemu_balloon(qdict_get_int(params, "value"), cb, opaque); + if (ret == 0) { + qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); + return -1; + } + + cb(opaque, NULL); + return 0; +} diff --git a/balloon.h b/balloon.h index 8c019eb..d478e28 100644 --- a/balloon.h +++ b/balloon.h @@ -14,6 +14,8 @@ #ifndef _QEMU_BALLOON_H #define _QEMU_BALLOON_H +#include "monitor.h" + typedef void (QEMUBalloonEvent)(void *opaque, ram_addr_t target, MonitorCompletion cb, void *cb_data); @@ -23,4 +25,9 @@ int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque); int qemu_balloon_status(MonitorCompletion cb, void *opaque); +void monitor_print_balloon(Monitor *mon, const QObject *data); +int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque); +int do_balloon(Monitor *mon, const QDict *params, + MonitorCompletion cb, void *opaque); + #endif diff --git a/monitor.c b/monitor.c index 822dc27..5659991 100644 --- a/monitor.c +++ b/monitor.c @@ -2266,91 +2266,6 @@ static void do_info_status(Monitor *mon, QObject **ret_data) vm_running, singlestep); } -static void print_balloon_stat(const char *key, QObject *obj, void *opaque) -{ - Monitor *mon = opaque; - - if (strcmp(key, "actual")) - monitor_printf(mon, ",%s=%" PRId64, key, - qint_get_int(qobject_to_qint(obj))); -} - -static void monitor_print_balloon(Monitor *mon, const QObject *data) -{ - QDict *qdict; - - qdict = qobject_to_qdict(data); - if (!qdict_haskey(qdict, "actual")) - return; - - monitor_printf(mon, "balloon: actual=%" PRId64, - qdict_get_int(qdict, "actual") >> 20); - qdict_iter(qdict, print_balloon_stat, mon); - monitor_printf(mon, "\n"); -} - -/** - * do_info_balloon(): Balloon information - * - * Make an asynchronous request for balloon info. When the request completes - * a QDict will be returned according to the following specification: - * - * - "actual": current balloon value in bytes - * The following fields may or may not be present: - * - "mem_swapped_in": Amount of memory swapped in (bytes) - * - "mem_swapped_out": Amount of memory swapped out (bytes) - * - "major_page_faults": Number of major faults - * - "minor_page_faults": Number of minor faults - * - "free_mem": Total amount of free and unused memory (bytes) - * - "total_mem": Total amount of available memory (bytes) - * - * Example: - * - * { "actual": 1073741824, "mem_swapped_in": 0, "mem_swapped_out": 0, - * "major_page_faults": 142, "minor_page_faults": 239245, - * "free_mem": 1014185984, "total_mem": 1044668416 } - */ -static int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque) -{ - int ret; - - if (kvm_enabled() && !kvm_has_sync_mmu()) { - qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); - return -1; - } - - ret = qemu_balloon_status(cb, opaque); - if (!ret) { - qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); - return -1; - } - - return 0; -} - -/** - * do_balloon(): Request VM to change its memory allocation - */ -static int do_balloon(Monitor *mon, const QDict *params, - MonitorCompletion cb, void *opaque) -{ - int ret; - - if (kvm_enabled() && !kvm_has_sync_mmu()) { - qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); - return -1; - } - - ret = qemu_balloon(qdict_get_int(params, "value"), cb, opaque); - if (ret == 0) { - qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon"); - return -1; - } - - cb(opaque, NULL); - return 0; -} - static qemu_acl *find_acl(Monitor *mon, const char *name) { qemu_acl *acl = qemu_acl_find(name); diff --git a/vl.c b/vl.c index 8828beb..e7192fc 100644 --- a/vl.c +++ b/vl.c @@ -146,7 +146,6 @@ int main(int argc, char **argv) #include "audio/audio.h" #include "migration.h" #include "kvm.h" -#include "balloon.h" #include "qemu-option.h" #include "qemu-config.h" #include "qemu-objects.h" @@ -307,39 +306,6 @@ static void set_proc_name(const char *s) #endif } -/***************/ -/* 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; -} - -int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque) -{ - if (qemu_balloon_event) { - qemu_balloon_event(qemu_balloon_event_opaque, target, cb, opaque); - return 1; - } else { - return 0; - } -} - -int qemu_balloon_status(MonitorCompletion cb, void *opaque) -{ - if (qemu_balloon_event) { - qemu_balloon_event(qemu_balloon_event_opaque, 0, cb, opaque); - return 1; - } else { - return 0; - } -} - - /***********************************************************/ /* real time host monotonic timer */ -- 1.6.6.1 ^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-03-31 15:02 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2010-03-19 10:35 [Qemu-devel] [PATCH 0/3] more vl.c/monitor.c splits Paolo Bonzini 2010-03-19 10:35 ` [Qemu-devel] [PATCH 1/3] move socket_init to qemu-sockets.c Paolo Bonzini 2010-03-19 10:35 ` [Qemu-devel] [PATCH 2/3] move two variable declarations out of vl.c Paolo Bonzini 2010-03-19 10:35 ` [Qemu-devel] [PATCH 3/3] move balloon handling to balloon.c Paolo Bonzini -- strict thread matches above, loose matches on Subject: below -- 2010-03-31 14:56 [Qemu-devel] [PATCH rebased 0/3] move stuff out of vl.c Paolo Bonzini 2010-03-31 14:56 ` [Qemu-devel] [PATCH 3/3] move balloon handling to balloon.c Paolo Bonzini
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).