From nobody Wed Nov 5 05:16:03 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1533670549457871.367704340998; Tue, 7 Aug 2018 12:35:49 -0700 (PDT) Received: from localhost ([::1]:40565 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fn7lk-0008IO-BW for importer@patchew.org; Tue, 07 Aug 2018 15:35:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:44292) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fn7hm-0005Fi-Tr for qemu-devel@nongnu.org; Tue, 07 Aug 2018 15:31:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fn7hk-0007z0-T1 for qemu-devel@nongnu.org; Tue, 07 Aug 2018 15:31:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:13376) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fn7hk-0007yQ-N7 for qemu-devel@nongnu.org; Tue, 07 Aug 2018 15:31:40 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F0E9C821C7; Tue, 7 Aug 2018 19:31:39 +0000 (UTC) Received: from gimli.home (ovpn-116-35.phx2.redhat.com [10.3.116.35]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5E0CE82775; Tue, 7 Aug 2018 19:31:38 +0000 (UTC) From: Alex Williamson To: alex.williamson@redhat.com, qemu-devel@nongnu.org Date: Tue, 7 Aug 2018 13:31:22 -0600 Message-Id: <20180807193125.30378-2-alex.williamson@redhat.com> In-Reply-To: <20180807193125.30378-1-alex.williamson@redhat.com> References: <20180807193125.30378-1-alex.williamson@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Tue, 07 Aug 2018 19:31:40 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v3 1/4] balloon: Allow multiple inhibit users X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Cornelia Huck , david@redhat.com, kvm@vger.kernel.org, peterx@redhat.com, "Michael S. Tsirkin" Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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. Reviewed-by: David Hildenbrand Reviewed-by: Peter Xu Reviewed-by: Cornelia Huck Signed-off-by: Alex Williamson --- balloon.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/balloon.c b/balloon.c index 6bf0a9681377..931987983858 100644 --- a/balloon.c +++ b/balloon.c @@ -26,6 +26,7 @@ =20 #include "qemu/osdep.h" #include "qemu-common.h" +#include "qemu/atomic.h" #include "exec/cpu-common.h" #include "sysemu/kvm.h" #include "sysemu/balloon.h" @@ -37,16 +38,22 @@ static QEMUBalloonEvent *balloon_event_fn; static QEMUBalloonStatus *balloon_stat_fn; static void *balloon_opaque; -static bool balloon_inhibited; +static int balloon_inhibit_count; =20 bool qemu_balloon_is_inhibited(void) { - return balloon_inhibited; + return atomic_read(&balloon_inhibit_count) > 0; } =20 void qemu_balloon_inhibit(bool state) { - balloon_inhibited =3D state; + if (state) { + atomic_inc(&balloon_inhibit_count); + } else { + atomic_dec(&balloon_inhibit_count); + } + + assert(atomic_read(&balloon_inhibit_count) >=3D 0); } =20 static bool have_balloon(Error **errp) --=20 2.18.0