Diff for /qemu/balloon.c between versions 1.1.1.2 and 1.1.1.3

version 1.1.1.2, 2018/04/24 18:33:20 version 1.1.1.3, 2018/04/24 18:55:37
Line 1 Line 1
 /*  /*
  * QEMU System Emulator   * Generic Balloon handlers and management
  *   *
  * Copyright (c) 2003-2008 Fabrice Bellard   * Copyright (c) 2003-2008 Fabrice Bellard
    * Copyright (C) 2011 Red Hat, Inc.
    * Copyright (C) 2011 Amit Shah <amit.shah@redhat.com>
  *   *
  * Permission is hereby granted, free of charge, to any person obtaining a copy   * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal   * of this software and associated documentation files (the "Software"), to deal
Line 22 Line 24
  * THE SOFTWARE.   * THE SOFTWARE.
  */   */
   
 #include "sysemu.h"  
 #include "monitor.h"  #include "monitor.h"
 #include "qjson.h"  #include "qjson.h"
 #include "qint.h"  #include "qint.h"
Line 31 Line 32
 #include "balloon.h"  #include "balloon.h"
 #include "trace.h"  #include "trace.h"
   
   static QEMUBalloonEvent *balloon_event_fn;
 static QEMUBalloonEvent *qemu_balloon_event;  static QEMUBalloonStatus *balloon_stat_fn;
 void *qemu_balloon_event_opaque;  static void *balloon_opaque;
   
 void qemu_add_balloon_handler(QEMUBalloonEvent *func, void *opaque)  int qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
 {                               QEMUBalloonStatus *stat_func, void *opaque)
     qemu_balloon_event = func;  {
     qemu_balloon_event_opaque = opaque;      if (balloon_event_fn || balloon_stat_fn || balloon_opaque) {
           /* We're already registered one balloon handler.  How many can
            * a guest really have?
            */
           error_report("Another balloon device already registered");
           return -1;
       }
       balloon_event_fn = event_func;
       balloon_stat_fn = stat_func;
       balloon_opaque = opaque;
       return 0;
 }  }
   
 int qemu_balloon(ram_addr_t target, MonitorCompletion cb, void *opaque)  static int qemu_balloon(ram_addr_t target)
 {  {
     if (qemu_balloon_event) {      if (!balloon_event_fn) {
         trace_balloon_event(qemu_balloon_event_opaque, target);  
         qemu_balloon_event(qemu_balloon_event_opaque, target, cb, opaque);  
         return 1;  
     } else {  
         return 0;          return 0;
     }      }
       trace_balloon_event(balloon_opaque, target);
       balloon_event_fn(balloon_opaque, target);
       return 1;
 }  }
   
 int qemu_balloon_status(MonitorCompletion cb, void *opaque)  static int qemu_balloon_status(MonitorCompletion cb, void *opaque)
 {  {
     if (qemu_balloon_event) {      if (!balloon_stat_fn) {
         qemu_balloon_event(qemu_balloon_event_opaque, 0, cb, opaque);  
         return 1;  
     } else {  
         return 0;          return 0;
     }      }
       balloon_stat_fn(balloon_opaque, cb, opaque);
       return 1;
 }  }
   
 static void print_balloon_stat(const char *key, QObject *obj, void *opaque)  static void print_balloon_stat(const char *key, QObject *obj, void *opaque)
 {  {
     Monitor *mon = opaque;      Monitor *mon = opaque;
   
     if (strcmp(key, "actual"))      if (strcmp(key, "actual")) {
         monitor_printf(mon, ",%s=%" PRId64, key,          monitor_printf(mon, ",%s=%" PRId64, key,
                        qint_get_int(qobject_to_qint(obj)));                         qint_get_int(qobject_to_qint(obj)));
       }
 }  }
   
 void monitor_print_balloon(Monitor *mon, const QObject *data)  void monitor_print_balloon(Monitor *mon, const QObject *data)
Line 76  void monitor_print_balloon(Monitor *mon, Line 86  void monitor_print_balloon(Monitor *mon,
     QDict *qdict;      QDict *qdict;
   
     qdict = qobject_to_qdict(data);      qdict = qobject_to_qdict(data);
     if (!qdict_haskey(qdict, "actual"))      if (!qdict_haskey(qdict, "actual")) {
         return;          return;
       }
     monitor_printf(mon, "balloon: actual=%" PRId64,      monitor_printf(mon, "balloon: actual=%" PRId64,
                    qdict_get_int(qdict, "actual") >> 20);                     qdict_get_int(qdict, "actual") >> 20);
     qdict_iter(qdict, print_balloon_stat, mon);      qdict_iter(qdict, print_balloon_stat, mon);
Line 130  int do_info_balloon(Monitor *mon, Monito Line 140  int do_info_balloon(Monitor *mon, Monito
 int do_balloon(Monitor *mon, const QDict *params,  int do_balloon(Monitor *mon, const QDict *params,
                MonitorCompletion cb, void *opaque)                 MonitorCompletion cb, void *opaque)
 {  {
       int64_t target;
     int ret;      int ret;
   
     if (kvm_enabled() && !kvm_has_sync_mmu()) {      if (kvm_enabled() && !kvm_has_sync_mmu()) {
Line 137  int do_balloon(Monitor *mon, const QDict Line 148  int do_balloon(Monitor *mon, const QDict
         return -1;          return -1;
     }      }
   
     ret = qemu_balloon(qdict_get_int(params, "value"), cb, opaque);      target = qdict_get_int(params, "value");
       if (target <= 0) {
           qerror_report(QERR_INVALID_PARAMETER_VALUE, "target", "a size");
           return -1;
       }
       ret = qemu_balloon(target);
     if (ret == 0) {      if (ret == 0) {
         qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon");          qerror_report(QERR_DEVICE_NOT_ACTIVE, "balloon");
         return -1;          return -1;

Removed from v.1.1.1.2  
changed lines
  Added in v.1.1.1.3


unix.superglobalmegacorp.com