Skip to content

Commit

Permalink
Also store the partition name in Partition and use for messages
Browse files Browse the repository at this point in the history
This remove a bit of manual select-and-paste of paritition descriptions
like "root partition", "server data partition", etc.
  • Loading branch information
keszybz committed Sep 20, 2021
1 parent f67f59e commit 53d2771
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
29 changes: 15 additions & 14 deletions mkosi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
MkosiException,
MkosiPrinter,
OutputFormat,
Partition,
PartitionTable,
SourceFileTransfer,
die,
Expand Down Expand Up @@ -892,7 +893,7 @@ def luks_format_root(
return
assert args.passphrase is not None

with complete_step("Setting up LUKS on root partition…"):
with complete_step(f"Setting up LUKS on {part.name}…"):
luks_format(part.blockdev(loopdev), args.passphrase)


Expand All @@ -908,7 +909,7 @@ def luks_format_home(args: CommandLineArguments, loopdev: Path, do_run_build_scr
return
assert args.passphrase is not None

with complete_step("Setting up LUKS on home partition…"):
with complete_step(f"Setting up LUKS on {part.name}…"):
luks_format(part.blockdev(loopdev), args.passphrase)


Expand All @@ -924,7 +925,7 @@ def luks_format_srv(args: CommandLineArguments, loopdev: Path, do_run_build_scri
return
assert args.passphrase is not None

with complete_step("Setting up LUKS on server data partition…"):
with complete_step(f"Setting up LUKS on {part.name}…"):
luks_format(part.blockdev(loopdev), args.passphrase)


Expand All @@ -940,7 +941,7 @@ def luks_format_var(args: CommandLineArguments, loopdev: Path, do_run_build_scri
return
assert args.passphrase is not None

with complete_step("Setting up LUKS on variable data partition…"):
with complete_step(f"Setting up LUKS on {part.name}…"):
luks_format(part.blockdev(loopdev), args.passphrase)


Expand All @@ -956,16 +957,16 @@ def luks_format_tmp(args: CommandLineArguments, loopdev: Path, do_run_build_scri
return
assert args.passphrase is not None

with complete_step("Setting up LUKS on temporary data partition…"):
with complete_step(f"Setting up LUKS on {part.name}…"):
luks_format(part.blockdev(loopdev), args.passphrase)


@contextlib.contextmanager
def luks_open(dev: Path, passphrase: Dict[str, str], partition: str) -> Generator[Path, None, None]:
def luks_open(part: Partition, loopdev: Path, passphrase: Dict[str, str]) -> Generator[Path, None, None]:
name = str(uuid.uuid4())
# FIXME: partition is only used in messages, rename it?
dev = part.blockdev(loopdev)

with complete_step(f"Setting up LUKS on {partition}…"):
with complete_step(f"Setting up LUKS on {part.name}…"):
if passphrase["type"] == "stdin":
passphrase_content = (passphrase["content"] + "\n").encode("utf-8")
run(["cryptsetup", "open", "--type", "luks", dev, name], input=passphrase_content)
Expand All @@ -978,7 +979,7 @@ def luks_open(dev: Path, passphrase: Dict[str, str], partition: str) -> Generato
try:
yield path
finally:
with complete_step(f"Closing LUKS {partition}"):
with complete_step(f"Closing LUKS on {part.name}"):
run(["cryptsetup", "close", path])


Expand All @@ -996,7 +997,7 @@ def luks_setup_root(
return contextlib.nullcontext()
assert args.passphrase is not None

return luks_open(part.blockdev(loopdev), args.passphrase, "root partition")
return luks_open(part, loopdev, args.passphrase)


def luks_setup_home(
Expand All @@ -1011,7 +1012,7 @@ def luks_setup_home(
return contextlib.nullcontext()
assert args.passphrase is not None

return luks_open(part.blockdev(loopdev), args.passphrase, "home partition")
return luks_open(part, loopdev, args.passphrase)


def luks_setup_srv(
Expand All @@ -1026,7 +1027,7 @@ def luks_setup_srv(
return contextlib.nullcontext()
assert args.passphrase is not None

return luks_open(part.blockdev(loopdev), args.passphrase, "server data partition")
return luks_open(part, loopdev, args.passphrase)


def luks_setup_var(
Expand All @@ -1041,7 +1042,7 @@ def luks_setup_var(
return contextlib.nullcontext()
assert args.passphrase is not None

return luks_open(part.blockdev(loopdev), args.passphrase, "variable data partition")
return luks_open(part, loopdev, args.passphrase)


def luks_setup_tmp(
Expand All @@ -1056,7 +1057,7 @@ def luks_setup_tmp(
return contextlib.nullcontext()
assert args.passphrase is not None

return luks_open(part.blockdev(loopdev), args.passphrase, "temporary data partition")
return luks_open(part, loopdev, args.passphrase)


class LuksSetupOutput(NamedTuple):
Expand Down
3 changes: 2 additions & 1 deletion mkosi/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class ManifestFormat(Parseable, enum.Enum):
class Partition:
size: int
number: int
name: str

def blockdev(self, loopdev: Path) -> Path:
return Path(f"{loopdev}p{self.number}")
Expand Down Expand Up @@ -325,7 +326,7 @@ def add(self,
self.partitions += [', '.join(filter(None, new))]
self.last_partition_sector = self.last_partition_offset() // self.sector_size + n_sectors

part = Partition(size, len(self.partitions))
part = Partition(size, len(self.partitions), name)

if label is not None:
self._labelled[label] = part
Expand Down

0 comments on commit 53d2771

Please sign in to comment.