From: Daan De Meyer Date: Sun, 21 Aug 2022 10:50:56 +0000 (+0200) Subject: Add syscall machinery to call BLKRRPART and use it X-Git-Tag: v14~61^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=514877e1adfc5ba057001553c0fbeeebac6dc2a7;p=thirdparty%2Fmkosi.git Add syscall machinery to call BLKRRPART and use it --- diff --git a/mkosi/backend.py b/mkosi/backend.py index 6b3e42791..60c0b88c5 100644 --- a/mkosi/backend.py +++ b/mkosi/backend.py @@ -37,7 +37,11 @@ from typing import ( cast, ) -from .syscall import blkpg_add_partition, blkpg_del_partition +from .syscall import ( + blkpg_add_partition, + blkpg_del_partition, + block_reread_partition_table, +) PathString = Union[Path, str] @@ -406,7 +410,7 @@ class PartitionTable: if 'disk' in ARG_DEBUG: print_between_lines(spec) - cmd: List[PathString] = ["sfdisk", "--color=never", "--no-reread", device] + cmd: List[PathString] = ["sfdisk", "--color=never", "--no-reread", "--no-tell-kernel", device] if quiet: cmd += ["--quiet"] @@ -433,6 +437,17 @@ class PartitionTable: for p in self.partitions.values(): blkpg_add_partition(f.fileno(), p.number, self.partition_offset(p), self.partition_size(p)) + try: + block_reread_partition_table(f.fileno()) + except OSError as e: + msg = f"Failed to reread partition table of {device}: {e.strerror}" + # BLKRRPART fails with EINVAL if the operation is not supported, let's not fail if that's + # the case. + if e.errno == errno.EINVAL: + warn(msg) + else: + die(msg) + @dataclasses.dataclass class MkosiArgs: diff --git a/mkosi/syscall.py b/mkosi/syscall.py index e3f364f11..abefd4b55 100644 --- a/mkosi/syscall.py +++ b/mkosi/syscall.py @@ -83,3 +83,10 @@ FICLONE = _IOW(0x94, 9, "int") def reflink(oldfd: int, newfd: int) -> None: fcntl.ioctl(newfd, FICLONE, oldfd) + + +BLKRRPART = _IO(0x12, 95) + + +def block_reread_partition_table(fd: int) -> None: + fcntl.ioctl(fd, BLKRRPART, 0)