From patchwork Tue Jul 17 22:47:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alex Williamson X-Patchwork-Id: 10531019 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D089A60545 for ; Tue, 17 Jul 2018 22:49:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C550929300 for ; Tue, 17 Jul 2018 22:49:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9DBA29301; Tue, 17 Jul 2018 22:49:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BF5E292FF for ; Tue, 17 Jul 2018 22:49:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731081AbeGQXW3 (ORCPT ); Tue, 17 Jul 2018 19:22:29 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:44370 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1730627AbeGQXW3 (ORCPT ); Tue, 17 Jul 2018 19:22:29 -0400 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 20087400225D; Tue, 17 Jul 2018 22:47:40 +0000 (UTC) Received: from gimli.home (ovpn-116-29.phx2.redhat.com [10.3.116.29]) by smtp.corp.redhat.com (Postfix) with ESMTP id A585D111C481; Tue, 17 Jul 2018 22:47:37 +0000 (UTC) Subject: [RFC PATCH 1/3] balloon: Allow nested inhibits From: Alex Williamson To: qemu-devel@nongnu.org Cc: kvm@vger.kernel.org Date: Tue, 17 Jul 2018 16:47:37 -0600 Message-ID: <20180717224737.14019.3324.stgit@gimli.home> In-Reply-To: <20180717222721.14019.27548.stgit@gimli.home> References: <20180717222721.14019.27548.stgit@gimli.home> User-Agent: StGit/0.18-102-gdf9f MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 17 Jul 2018 22:47:40 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Tue, 17 Jul 2018 22:47:40 +0000 (UTC) for IP:'10.11.54.3' DOMAIN:'int-mx03.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'alex.williamson@redhat.com' RCPT:'' Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP A simple true/false internal state does not allow multiple users. Fix this within the existing interface by converting to a counter, so long as the counter is elevated, ballooning is inhibited. Signed-off-by: Alex Williamson --- balloon.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/balloon.c b/balloon.c index 6bf0a9681377..2a6a7e1a22a0 100644 --- a/balloon.c +++ b/balloon.c @@ -37,16 +37,17 @@ static QEMUBalloonEvent *balloon_event_fn; static QEMUBalloonStatus *balloon_stat_fn; static void *balloon_opaque; -static bool balloon_inhibited; +static int balloon_inhibited; bool qemu_balloon_is_inhibited(void) { - return balloon_inhibited; + return balloon_inhibited > 0; } void qemu_balloon_inhibit(bool state) { - balloon_inhibited = state; + balloon_inhibited += (state ? 1 : -1); + assert(balloon_inhibited >= 0); } static bool have_balloon(Error **errp)