update to 2.7
[pve-qemu-kvm.git] / debian / patches / pve / 0006-virtio-balloon-fix-query.patch
blob87e4d4197f0acd8c402ad3f61cf911acf7da65fc
1 From ff496e015b9b53c2d49a0110d247223872d5a582 Mon Sep 17 00:00:00 2001
2 From: Wolfgang Bumiller <w.bumiller@proxmox.com>
3 Date: Wed, 9 Dec 2015 14:27:49 +0100
4 Subject: [PATCH 06/41] virtio-balloon: fix query
6 Actually provide memory information via the query-balloon
7 command.
8 ---
9 hmp.c | 30 +++++++++++++++++++++++++++++-
10 hw/virtio/virtio-balloon.c | 33 +++++++++++++++++++++++++++++++--
11 qapi-schema.json | 23 +++++++++++++++++++++--
12 qmp-commands.hx | 13 +++++++++++++
13 4 files changed, 94 insertions(+), 5 deletions(-)
15 diff --git a/hmp.c b/hmp.c
16 index cc2056e..aa1395d 100644
17 --- a/hmp.c
18 +++ b/hmp.c
19 @@ -704,7 +704,35 @@ void hmp_info_balloon(Monitor *mon, const QDict *qdict)
20 return;
23 - monitor_printf(mon, "balloon: actual=%" PRId64 "\n", info->actual >> 20);
24 + monitor_printf(mon, "balloon: actual=%" PRId64, info->actual >> 20);
25 + monitor_printf(mon, " max_mem=%" PRId64, info->max_mem >> 20);
26 + if (info->has_total_mem) {
27 + monitor_printf(mon, " total_mem=%" PRId64, info->total_mem >> 20);
28 + }
29 + if (info->has_free_mem) {
30 + monitor_printf(mon, " free_mem=%" PRId64, info->free_mem >> 20);
31 + }
33 + if (info->has_mem_swapped_in) {
34 + monitor_printf(mon, " mem_swapped_in=%" PRId64, info->mem_swapped_in);
35 + }
36 + if (info->has_mem_swapped_out) {
37 + monitor_printf(mon, " mem_swapped_out=%" PRId64, info->mem_swapped_out);
38 + }
39 + if (info->has_major_page_faults) {
40 + monitor_printf(mon, " major_page_faults=%" PRId64,
41 + info->major_page_faults);
42 + }
43 + if (info->has_minor_page_faults) {
44 + monitor_printf(mon, " minor_page_faults=%" PRId64,
45 + info->minor_page_faults);
46 + }
47 + if (info->has_last_update) {
48 + monitor_printf(mon, " last_update=%" PRId64,
49 + info->last_update);
50 + }
52 + monitor_printf(mon, "\n");
54 qapi_free_BalloonInfo(info);
56 diff --git a/hw/virtio/virtio-balloon.c b/hw/virtio/virtio-balloon.c
57 index 5af429a..d87b971 100644
58 --- a/hw/virtio/virtio-balloon.c
59 +++ b/hw/virtio/virtio-balloon.c
60 @@ -376,8 +376,37 @@ static uint64_t virtio_balloon_get_features(VirtIODevice *vdev, uint64_t f,
61 static void virtio_balloon_stat(void *opaque, BalloonInfo *info)
63 VirtIOBalloon *dev = opaque;
64 - info->actual = get_current_ram_size() - ((uint64_t) dev->actual <<
65 - VIRTIO_BALLOON_PFN_SHIFT);
66 + ram_addr_t ram_size = get_current_ram_size();
67 + info->actual = ram_size - ((uint64_t) dev->actual <<
68 + VIRTIO_BALLOON_PFN_SHIFT);
70 + info->max_mem = ram_size;
72 + if (!(balloon_stats_enabled(dev) && balloon_stats_supported(dev) &&
73 + dev->stats_last_update)) {
74 + return;
75 + }
77 + info->last_update = dev->stats_last_update;
78 + info->has_last_update = true;
80 + info->mem_swapped_in = dev->stats[VIRTIO_BALLOON_S_SWAP_IN];
81 + info->has_mem_swapped_in = info->mem_swapped_in >= 0 ? true : false;
83 + info->mem_swapped_out = dev->stats[VIRTIO_BALLOON_S_SWAP_OUT];
84 + info->has_mem_swapped_out = info->mem_swapped_out >= 0 ? true : false;
86 + info->major_page_faults = dev->stats[VIRTIO_BALLOON_S_MAJFLT];
87 + info->has_major_page_faults = info->major_page_faults >= 0 ? true : false;
89 + info->minor_page_faults = dev->stats[VIRTIO_BALLOON_S_MINFLT];
90 + info->has_minor_page_faults = info->minor_page_faults >= 0 ? true : false;
92 + info->free_mem = dev->stats[VIRTIO_BALLOON_S_MEMFREE];
93 + info->has_free_mem = info->free_mem >= 0 ? true : false;
95 + info->total_mem = dev->stats[VIRTIO_BALLOON_S_MEMTOT];
96 + info->has_total_mem = info->total_mem >= 0 ? true : false;
99 static void virtio_balloon_to_target(void *opaque, ram_addr_t target)
100 diff --git a/qapi-schema.json b/qapi-schema.json
101 index 5658723..4bf7222 100644
102 --- a/qapi-schema.json
103 +++ b/qapi-schema.json
104 @@ -1278,10 +1278,29 @@
106 # @actual: the number of bytes the balloon currently contains
108 -# Since: 0.14.0
109 +# @last_update: #optional time when stats got updated from guest
111 +# @mem_swapped_in: #optional number of pages swapped in within the guest
113 +# @mem_swapped_out: #optional number of pages swapped out within the guest
115 +# @major_page_faults: #optional number of major page faults within the guest
117 +# @minor_page_faults: #optional number of minor page faults within the guest
119 +# @free_mem: #optional amount of memory (in bytes) free in the guest
121 +# @total_mem: #optional amount of memory (in bytes) visible to the guest
123 +# @max_mem: amount of memory (in bytes) assigned to the guest
125 +# Since: 0.14.0
127 -{ 'struct': 'BalloonInfo', 'data': {'actual': 'int' } }
128 +{ 'struct': 'BalloonInfo',
129 + 'data': {'actual': 'int', '*last_update': 'int', '*mem_swapped_in': 'int',
130 + '*mem_swapped_out': 'int', '*major_page_faults': 'int',
131 + '*minor_page_faults': 'int', '*free_mem': 'int',
132 + '*total_mem': 'int', 'max_mem': 'int' } }
135 # @query-balloon:
136 diff --git a/qmp-commands.hx b/qmp-commands.hx
137 index 6866264..6de28d4 100644
138 --- a/qmp-commands.hx
139 +++ b/qmp-commands.hx
140 @@ -3854,6 +3854,13 @@ Make an asynchronous request for balloon info. When the request completes a
141 json-object will be returned containing the following data:
143 - "actual": current balloon value in bytes (json-int)
144 +- "mem_swapped_in": Amount of memory swapped in bytes (json-int, optional)
145 +- "mem_swapped_out": Amount of memory swapped out in bytes (json-int, optional)
146 +- "major_page_faults": Number of major faults (json-int, optional)
147 +- "minor_page_faults": Number of minor faults (json-int, optional)
148 +- "free_mem": Total amount of free and unused memory in
149 + bytes (json-int, optional)
150 +- "total_mem": Total amount of available memory in bytes (json-int, optional)
152 Example:
154 @@ -3861,6 +3868,12 @@ Example:
155 <- {
156 "return":{
157 "actual":1073741824,
158 + "mem_swapped_in":0,
159 + "mem_swapped_out":0,
160 + "major_page_faults":142,
161 + "minor_page_faults":239245,
162 + "free_mem":1014185984,
163 + "total_mem":1044668416
168 2.1.4