Skip to content

Commit

Permalink
Add options for specifying integrity metadata pre-allocations
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Nov 27, 2024
1 parent ec8cd45 commit 5bd84c3
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 5 deletions.
12 changes: 10 additions & 2 deletions src/stratis_cli/_actions/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,16 @@ def create_pool(namespace): # pylint: disable=too-many-locals
if clevis_info is None
else (True, (clevis_info.pin, json.dumps(clevis_info.config)))
),
"journal_size": (False, 0),
"tag_size": (False, 0),
"journal_size": (
(False, 0)
if namespace.journal_size is None
else (True, namespace.journal_size.magnitude.numerator)
),
"tag_size": (
(False, 0)
if namespace.tag_size is None
else (True, namespace.tag_size.magnitude.numerator)
),
},
)

Expand Down
37 changes: 35 additions & 2 deletions src/stratis_cli/_parser/_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from .._error_codes import PoolErrorCode
from ._bind import BIND_SUBCMDS, REBIND_SUBCMDS
from ._debug import POOL_DEBUG_SUBCMDS
from ._range import RejectAction
from ._range import RejectAction, parse_bytes_range, parse_range


class ClevisEncryptionOptions: # pylint: disable=too-few-public-methods
Expand Down Expand Up @@ -163,7 +163,40 @@ def _ensure_nat(arg):
)
],
},
)
),
(
"integrity",
{
"description": (
"Optional parameters for configuring integrity "
"metadata pre-allocation"
),
"args": [
(
"--journal-size",
{
"help": (
"Size of integrity device's journal. "
"Each block is written to this journal "
"before being written to its address."
),
"type": parse_range,
},
),
(
"--tag-size",
{
"help": (
"Size of tag to use to verify "
"correctness of 4KiB block, e.g, 64B. "
"Must be less than 128B."
),
"type": parse_bytes_range,
},
),
],
},
),
],
"args": [
("pool_name", {"help": "Name of new pool"}),
Expand Down
16 changes: 15 additions & 1 deletion src/stratis_cli/_parser/_range.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ def _unit_map(unit_specifier):
assert False, f'Unknown unit specifier "{unit_specifier}"'


def parse_range(values):
def parse_range(values, *, bound=None):
"""
Parse a range value.
:param str values: string to parse
:param bound: upper bound on the Range value
:type bound: Range
"""
match = _RANGE_RE.search(values)
if match is None:
Expand All @@ -76,9 +78,21 @@ def parse_range(values):

assert result.magnitude.denominator == 1

if bound is not None and bound < result:
raise argparse.ArgumentTypeError(
f"Specified size {result} is at least upper bound {bound}."
)

return result


def parse_bytes_range(values):
"""
Parse a range that must be less than 128B.
"""
return parse_range(values, bound=Range(128))


class RejectAction(argparse.Action):
"""
Just reject any use of the option.
Expand Down
14 changes: 14 additions & 0 deletions tests/whitebox/integration/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,20 @@ def test_create_with_post_parser_set(self):
for prefix in [[], ["--propagate"]]:
self.check_system_exit(prefix + command_line, _PARSE_ERROR)

def test_create_with_oversize_tag_value(self):
"""
Verify that a tag value of at least 128B will result in a parser error.
"""
command_line = [
"pool",
"create",
"pn",
"/dev/n",
"--tag-size=128B",
]
for prefix in [[], ["--propagate"]]:
self.check_system_exit(prefix + command_line, _PARSE_ERROR)

def test_stratis_list_filesystem_with_name_no_pool(self):
"""
We want to get a parse error if filesystem UUID is specified but no
Expand Down

0 comments on commit 5bd84c3

Please sign in to comment.