Revision 625a5bef monitor.c
b/monitor.c | ||
---|---|---|
2152 | 2152 |
vm_running, singlestep); |
2153 | 2153 |
} |
2154 | 2154 |
|
2155 |
static ram_addr_t balloon_get_value(void)
|
|
2155 |
static void print_balloon_stat(const char *key, QObject *obj, void *opaque)
|
|
2156 | 2156 |
{ |
2157 |
ram_addr_t actual; |
|
2158 |
|
|
2159 |
if (kvm_enabled() && !kvm_has_sync_mmu()) { |
|
2160 |
qemu_error_new(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); |
|
2161 |
return 0; |
|
2162 |
} |
|
2163 |
|
|
2164 |
actual = qemu_balloon_status(); |
|
2165 |
if (actual == 0) { |
|
2166 |
qemu_error_new(QERR_DEVICE_NOT_ACTIVE, "balloon"); |
|
2167 |
return 0; |
|
2168 |
} |
|
2169 |
|
|
2170 |
return actual; |
|
2171 |
} |
|
2157 |
Monitor *mon = opaque; |
|
2172 | 2158 |
|
2173 |
/** |
|
2174 |
* do_balloon(): Request VM to change its memory allocation |
|
2175 |
*/ |
|
2176 |
static void do_balloon(Monitor *mon, const QDict *qdict, QObject **ret_data) |
|
2177 |
{ |
|
2178 |
if (balloon_get_value()) { |
|
2179 |
/* ballooning is active */ |
|
2180 |
qemu_balloon(qdict_get_int(qdict, "value")); |
|
2181 |
} |
|
2159 |
if (strcmp(key, "actual")) |
|
2160 |
monitor_printf(mon, ",%s=%" PRId64, key, |
|
2161 |
qint_get_int(qobject_to_qint(obj))); |
|
2182 | 2162 |
} |
2183 | 2163 |
|
2184 | 2164 |
static void monitor_print_balloon(Monitor *mon, const QObject *data) |
... | ... | |
2186 | 2166 |
QDict *qdict; |
2187 | 2167 |
|
2188 | 2168 |
qdict = qobject_to_qdict(data); |
2169 |
if (!qdict_haskey(qdict, "actual")) |
|
2170 |
return; |
|
2189 | 2171 |
|
2190 |
monitor_printf(mon, "balloon: actual=%" PRId64 "\n", |
|
2191 |
qdict_get_int(qdict, "balloon") >> 20); |
|
2172 |
monitor_printf(mon, "balloon: actual=%" PRId64, |
|
2173 |
qdict_get_int(qdict, "actual") >> 20); |
|
2174 |
qdict_iter(qdict, print_balloon_stat, mon); |
|
2175 |
monitor_printf(mon, "\n"); |
|
2192 | 2176 |
} |
2193 | 2177 |
|
2194 | 2178 |
/** |
2195 | 2179 |
* do_info_balloon(): Balloon information |
2196 | 2180 |
* |
2197 |
* Return a QDict with the following information: |
|
2181 |
* Make an asynchronous request for balloon info. When the request completes |
|
2182 |
* a QDict will be returned according to the following specification: |
|
2198 | 2183 |
* |
2199 |
* - "balloon": current balloon value in bytes |
|
2184 |
* - "actual": current balloon value in bytes |
|
2185 |
* The following fields may or may not be present: |
|
2186 |
* - "mem_swapped_in": Amount of memory swapped in (bytes) |
|
2187 |
* - "mem_swapped_out": Amount of memory swapped out (bytes) |
|
2188 |
* - "major_page_faults": Number of major faults |
|
2189 |
* - "minor_page_faults": Number of minor faults |
|
2190 |
* - "free_mem": Total amount of free and unused memory (bytes) |
|
2191 |
* - "total_mem": Total amount of available memory (bytes) |
|
2200 | 2192 |
* |
2201 | 2193 |
* Example: |
2202 | 2194 |
* |
2203 |
* { "balloon": 1073741824 } |
|
2195 |
* { "actual": 1073741824, "mem_swapped_in": 0, "mem_swapped_out": 0, |
|
2196 |
* "major_page_faults": 142, "minor_page_faults": 239245, |
|
2197 |
* "free_mem": 1014185984, "total_mem": 1044668416 } |
|
2198 |
*/ |
|
2199 |
static int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque) |
|
2200 |
{ |
|
2201 |
int ret; |
|
2202 |
|
|
2203 |
if (kvm_enabled() && !kvm_has_sync_mmu()) { |
|
2204 |
qemu_error_new(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); |
|
2205 |
return -1; |
|
2206 |
} |
|
2207 |
|
|
2208 |
ret = qemu_balloon_status(cb, opaque); |
|
2209 |
if (!ret) { |
|
2210 |
qemu_error_new(QERR_DEVICE_NOT_ACTIVE, "balloon"); |
|
2211 |
return -1; |
|
2212 |
} |
|
2213 |
|
|
2214 |
return 0; |
|
2215 |
} |
|
2216 |
|
|
2217 |
/** |
|
2218 |
* do_balloon(): Request VM to change its memory allocation |
|
2204 | 2219 |
*/ |
2205 |
static void do_info_balloon(Monitor *mon, QObject **ret_data) |
|
2220 |
static int do_balloon(Monitor *mon, const QDict *params, |
|
2221 |
MonitorCompletion cb, void *opaque) |
|
2206 | 2222 |
{ |
2207 |
ram_addr_t actual; |
|
2223 |
int ret; |
|
2224 |
|
|
2225 |
if (kvm_enabled() && !kvm_has_sync_mmu()) { |
|
2226 |
qemu_error_new(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon"); |
|
2227 |
return -1; |
|
2228 |
} |
|
2208 | 2229 |
|
2209 |
actual = balloon_get_value();
|
|
2210 |
if (actual != 0) {
|
|
2211 |
*ret_data = qobject_from_jsonf("{ 'balloon': %" PRId64 "}",
|
|
2212 |
(int64_t) actual);
|
|
2230 |
ret = qemu_balloon(qdict_get_int(params, "value"), cb, opaque);
|
|
2231 |
if (ret == 0) {
|
|
2232 |
qemu_error_new(QERR_DEVICE_NOT_ACTIVE, "balloon");
|
|
2233 |
return -1;
|
|
2213 | 2234 |
} |
2235 |
|
|
2236 |
return 0; |
|
2214 | 2237 |
} |
2215 | 2238 |
|
2216 | 2239 |
static qemu_acl *find_acl(Monitor *mon, const char *name) |
... | ... | |
2696 | 2719 |
.params = "", |
2697 | 2720 |
.help = "show balloon information", |
2698 | 2721 |
.user_print = monitor_print_balloon, |
2699 |
.mhandler.info_new = do_info_balloon, |
|
2722 |
.mhandler.info_async = do_info_balloon, |
|
2723 |
.async = 1, |
|
2700 | 2724 |
}, |
2701 | 2725 |
{ |
2702 | 2726 |
.name = "qtree", |
Also available in: Unified diff