aboutsummaryrefslogtreecommitdiff
path: root/balloon.c
diff options
context:
space:
mode:
authorMarkus Armbruster <armbru@redhat.com>2015-01-13 17:44:14 +0100
committerMarkus Armbruster <armbru@redhat.com>2015-01-29 10:04:09 +0100
commit422e0501a842fb4b3f42494f341707e809c3c6ad (patch)
tree4a478eef24c65f96e1473e66b66b1b10d21462ac /balloon.c
parent6502a14734e71b2f6dd079b0a1e546e6aa2d2f8d (diff)
balloon: Factor out common "is balloon active" test
Signed-off-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com>
Diffstat (limited to 'balloon.c')
-rw-r--r--balloon.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/balloon.c b/balloon.c
index 2884c2d37a..728bb707bf 100644
--- a/balloon.c
+++ b/balloon.c
@@ -36,6 +36,19 @@ static QEMUBalloonEvent *balloon_event_fn;
static QEMUBalloonStatus *balloon_stat_fn;
static void *balloon_opaque;
+static bool have_ballon(Error **errp)
+{
+ if (kvm_enabled() && !kvm_has_sync_mmu()) {
+ error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
+ return false;
+ }
+ if (!balloon_event_fn) {
+ error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
+ return false;
+ }
+ return true;
+}
+
int qemu_add_balloon_handler(QEMUBalloonEvent *event_func,
QEMUBalloonStatus *stat_func, void *opaque)
{
@@ -66,13 +79,7 @@ BalloonInfo *qmp_query_balloon(Error **errp)
{
BalloonInfo *info;
- if (kvm_enabled() && !kvm_has_sync_mmu()) {
- error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
- return NULL;
- }
-
- if (!balloon_stat_fn) {
- error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
+ if (!have_ballon(errp)) {
return NULL;
}
@@ -83,8 +90,7 @@ BalloonInfo *qmp_query_balloon(Error **errp)
void qmp_balloon(int64_t target, Error **errp)
{
- if (kvm_enabled() && !kvm_has_sync_mmu()) {
- error_set(errp, QERR_KVM_MISSING_CAP, "synchronous MMU", "balloon");
+ if (!have_ballon(errp)) {
return;
}
@@ -92,11 +98,6 @@ void qmp_balloon(int64_t target, Error **errp)
error_set(errp, QERR_INVALID_PARAMETER_VALUE, "target", "a size");
return;
}
-
- if (!balloon_event_fn) {
- error_set(errp, QERR_DEVICE_NOT_ACTIVE, "balloon");
- return;
- }
trace_balloon_event(balloon_opaque, target);
balloon_event_fn(balloon_opaque, target);