* [PATCH v5] tools/xl: fix autoballoon regex
@ 2021-10-01 12:24 Dmitry Isaykin
2021-11-09 16:17 ` Dmitry Isaykin
0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Isaykin @ 2021-10-01 12:24 UTC (permalink / raw)
To: xen-devel; +Cc: Dmitry Isaykin, Ian Jackson, Wei Liu, Anthony PERARD
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:<sz> | max:<sz> | <sz> )
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 <isaikin-dmitry@yandex.ru>
Reviewed-by: Anthony PERARD <anthony.perard@citrix.com>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v5] tools/xl: fix autoballoon regex
2021-10-01 12:24 [PATCH v5] tools/xl: fix autoballoon regex Dmitry Isaykin
@ 2021-11-09 16:17 ` Dmitry Isaykin
2021-11-11 14:18 ` Anthony PERARD
0 siblings, 1 reply; 3+ messages in thread
From: Dmitry Isaykin @ 2021-11-09 16:17 UTC (permalink / raw)
To: xen-devel; +Cc: Ian Jackson, Wei Liu, Anthony PERARD
[-- Attachment #1: Type: text/html, Size: 3780 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v5] tools/xl: fix autoballoon regex
2021-11-09 16:17 ` Dmitry Isaykin
@ 2021-11-11 14:18 ` Anthony PERARD
0 siblings, 0 replies; 3+ messages in thread
From: Anthony PERARD @ 2021-11-11 14:18 UTC (permalink / raw)
To: Dmitry Isaykin; +Cc: xen-devel, Ian Jackson, Wei Liu
On Tue, Nov 09, 2021 at 07:17:53PM +0300, Dmitry Isaykin wrote:
> Up
The patch as been committed ;-)
https://xenbits.xen.org/gitweb/?p=xen.git;a=commitdiff;h=2faeb4213d9b412836fe80e5685bfcccc51feb92
Cheers,
--
Anthony PERARD
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-11-11 14:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-01 12:24 [PATCH v5] tools/xl: fix autoballoon regex Dmitry Isaykin
2021-11-09 16:17 ` Dmitry Isaykin
2021-11-11 14:18 ` Anthony PERARD
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).