From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F311C433EF for ; Fri, 1 Oct 2021 12:24:51 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 222B461A55 for ; Fri, 1 Oct 2021 12:24:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 222B461A55 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=yandex.ru Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.200590.355110 (Exim 4.92) (envelope-from ) id 1mWHaW-00017b-9z; Fri, 01 Oct 2021 12:24:28 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 200590.355110; Fri, 01 Oct 2021 12:24:28 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mWHaW-00017U-6B; Fri, 01 Oct 2021 12:24:28 +0000 Received: by outflank-mailman (input) for mailman id 200590; Fri, 01 Oct 2021 12:24:27 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mWHaU-00017J-9Y for xen-devel@lists.xenproject.org; Fri, 01 Oct 2021 12:24:26 +0000 Received: from forward103j.mail.yandex.net (unknown [5.45.198.246]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id ac2f2a9e-3bbd-40cd-b167-6b5527d66fe2; Fri, 01 Oct 2021 12:24:23 +0000 (UTC) Received: from forward100q.mail.yandex.net (forward100q.mail.yandex.net [IPv6:2a02:6b8:c0e:4b:0:640:4012:bb97]) by forward103j.mail.yandex.net (Yandex) with ESMTP id B5AF4100B45; Fri, 1 Oct 2021 15:24:20 +0300 (MSK) Received: from vla1-faefe240866f.qloud-c.yandex.net (vla1-faefe240866f.qloud-c.yandex.net [IPv6:2a02:6b8:c0d:98f:0:640:faef:e240]) by forward100q.mail.yandex.net (Yandex) with ESMTP id B189D6F40014; Fri, 1 Oct 2021 15:24:20 +0300 (MSK) Received: from vla1-62318bfe5573.qloud-c.yandex.net (2a02:6b8:c0d:3819:0:640:6231:8bfe [2a02:6b8:c0d:3819:0:640:6231:8bfe]) by vla1-faefe240866f.qloud-c.yandex.net (mxback/Yandex) with ESMTP id 64SiCh0TmR-OKFeHp6E; Fri, 01 Oct 2021 15:24:20 +0300 Received: by vla1-62318bfe5573.qloud-c.yandex.net (smtp/Yandex) with ESMTPS id ZeWstiiHda-OJ38tSTD; Fri, 01 Oct 2021 15:24:19 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: ac2f2a9e-3bbd-40cd-b167-6b5527d66fe2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1633091060; bh=bgmuj30dggJ7JshrLX22yk3c/wj3X4um4/1rOX+GNV8=; h=Message-Id:Date:Subject:To:From:Cc; b=Jf0BGjyM4VfJWgVBAtilRqTFxxfRbqscRW/q9fNRpGUUUL79t1lHF26C7d6kNAmbC h/Cf+kFwiKPPDejFjCSIveJO24RSym6WYRA2vAqM3yG/WNnwVuc5M9NqJHPZl/61L6 Ey0bKK7hDCL55kOPEtE0/SzYCMASaD02wwXhDrHc= Authentication-Results: vla1-faefe240866f.qloud-c.yandex.net; dkim=pass header.i=@yandex.ru From: Dmitry Isaykin To: xen-devel@lists.xenproject.org Cc: Dmitry Isaykin , Ian Jackson , Wei Liu , Anthony PERARD Subject: [PATCH v5] tools/xl: fix autoballoon regex Date: Fri, 1 Oct 2021 15:24:16 +0300 Message-Id: <54c1bcb40afa8a6f36ab4bec8c91523a535c911b.1633090722.git.isaikin-dmitry@yandex.ru> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This regex is used for auto-balloon mode detection based on Xen command line. The case of specifying a negative size was handled incorrectly. >From misc/xen-command-line documentation: dom0_mem (x86) = List of ( min: | max: | ) If a size is positive, it represents an absolute value. If a size is negative, it is subtracted from the total available memory. Also add support for [tT] granularity suffix. Also add support for memory fractions (i.e. '50%' or '1G+25%'). Signed-off-by: Dmitry Isaykin Reviewed-by: Anthony PERARD --- Changes in v5: - add Anthony's reviewed-by Changes in v4: - improve regex after code review Changes in v3: - add support for [tT] granularity suffix - add support for memory fractions Changes in v2: - add missing Signed-off-by tag NB! New autoballon regex pattern is good enough, but not fully correct. See test below. ``` import pytest import re size_pattern = r"-?[0-9]+[bBkKmMgGtT]?" pattern = r"(^| )dom0_mem=((|min:|max:)({size}|({size}\+)?[0-9]{{1,2}}%),?)+($| )".format(size=size_pattern) @pytest.mark.parametrize('cmdline', [ 'dom0_mem=1', ' dom0_mem=1', 'dom0_mem=1G', 'dom0_mem=25%', 'dom0_mem=1g+25% ', ' dom0_mem=1G+10%,max:100T+50%', 'dom0_mem=-1B', 'dom0_mem=-10240M+5%,min:512M ', ' dom0_mem=min:-2048m,max:-2048M ', ]) def test_autoballoon_regex_match(cmdline): assert re.match(pattern, cmdline) @pytest.mark.parametrize('cmdline', [ 'dom0_mem = 1', 'dom0_mem= ', 'dom0_mem', 'DOM0_mem=10G', 'dom0_mem=-10%', # does not pass ' dom0_mem=-10%+10G ', 'dom0_mem=1G,', # does not pass 'dom0_mem=1G,max:25%,', #does not pass ]) def test_autoballoon_regex_dont_match(cmdline): assert not re.match(pattern, cmdline) ``` --- tools/xl/xl.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/xl/xl.c b/tools/xl/xl.c index 4107d10fd4..f422f9fed5 100644 --- a/tools/xl/xl.c +++ b/tools/xl/xl.c @@ -80,14 +80,20 @@ static int auto_autoballoon(void) if (!info) return 1; /* default to on */ +#define SIZE_PATTERN "-?[0-9]+[bBkKmMgGtT]?" + ret = regcomp(®ex, - "(^| )dom0_mem=((|min:|max:)[0-9]+[bBkKmMgG]?,?)+($| )", + "(^| )dom0_mem=((|min:|max:)(" SIZE_PATTERN "|(" SIZE_PATTERN "\\+)?[0-9]{1,2}%),?)+($| )", REG_NOSUB | REG_EXTENDED); + +#undef SIZE_PATTERN + if (ret) return 1; ret = regexec(®ex, info->commandline, 0, NULL, 0); regfree(®ex); + return ret == REG_NOMATCH; } -- 2.33.0