Revision 28c28973 monitor.c

b/monitor.c
2266 2266
                                    vm_running, singlestep);
2267 2267
}
2268 2268

  
2269
static void print_balloon_stat(const char *key, QObject *obj, void *opaque)
2270
{
2271
    Monitor *mon = opaque;
2272

  
2273
    if (strcmp(key, "actual"))
2274
        monitor_printf(mon, ",%s=%" PRId64, key,
2275
                       qint_get_int(qobject_to_qint(obj)));
2276
}
2277

  
2278
static void monitor_print_balloon(Monitor *mon, const QObject *data)
2279
{
2280
    QDict *qdict;
2281

  
2282
    qdict = qobject_to_qdict(data);
2283
    if (!qdict_haskey(qdict, "actual"))
2284
        return;
2285

  
2286
    monitor_printf(mon, "balloon: actual=%" PRId64,
2287
                   qdict_get_int(qdict, "actual") >> 20);
2288
    qdict_iter(qdict, print_balloon_stat, mon);
2289
    monitor_printf(mon, "\n");
2290
}
2291

  
2292
/**
2293
 * do_info_balloon(): Balloon information
2294
 *
2295
 * Make an asynchronous request for balloon info.  When the request completes
2296
 * a QDict will be returned according to the following specification:
2297
 *
2298
 * - "actual": current balloon value in bytes
2299
 * The following fields may or may not be present:
2300
 * - "mem_swapped_in": Amount of memory swapped in (bytes)
2301
 * - "mem_swapped_out": Amount of memory swapped out (bytes)
2302
 * - "major_page_faults": Number of major faults
2303
 * - "minor_page_faults": Number of minor faults
2304
 * - "free_mem": Total amount of free and unused memory (bytes)
2305
 * - "total_mem": Total amount of available memory (bytes)
2306
 *
2307
 * Example:
2308
 *
2309
 * { "actual": 1073741824, "mem_swapped_in": 0, "mem_swapped_out": 0,
2310
 *   "major_page_faults": 142, "minor_page_faults": 239245,
2311
 *   "free_mem": 1014185984, "total_mem": 1044668416 }
2312
 */
2313
static int do_info_balloon(Monitor *mon, MonitorCompletion cb, void *opaque)
2314
{
2315
    int ret;
2316

  
2317
    if (kvm_enabled() && !kvm_has_sync_mmu()) {
2318
        qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
2319
        return -1;
2320
    }
2321

  
2322
    ret = qemu_balloon_status(cb, opaque);
2323
    if (!ret) {
2324
        qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon");
2325
        return -1;
2326
    }
2327

  
2328
    return 0;
2329
}
2330

  
2331
/**
2332
 * do_balloon(): Request VM to change its memory allocation
2333
 */
2334
static int do_balloon(Monitor *mon, const QDict *params,
2335
                       MonitorCompletion cb, void *opaque)
2336
{
2337
    int ret;
2338

  
2339
    if (kvm_enabled() && !kvm_has_sync_mmu()) {
2340
        qerror_report(QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
2341
        return -1;
2342
    }
2343

  
2344
    ret = qemu_balloon(qdict_get_int(params, "value"), cb, opaque);
2345
    if (ret == 0) {
2346
        qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon");
2347
        return -1;
2348
    }
2349

  
2350
    cb(opaque, NULL);
2351
    return 0;
2352
}
2353

  
2354 2269
static qemu_acl *find_acl(Monitor *mon, const char *name)
2355 2270
{
2356 2271
    qemu_acl *acl = qemu_acl_find(name);

Also available in: Unified diff