]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Ignore EBUSY on partition removal
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 28 Jul 2022 10:30:59 +0000 (12:30 +0200)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Thu, 28 Jul 2022 12:29:05 +0000 (14:29 +0200)
This can happen just after inserting a partition, probably because
udev starts operating on a device which makes us unable to remove
the partition, let's ignore EBUSY as a workaround until we get a
proper fix

mkosi/__init__.py

index 30269740a0978bef2450b86baedca5582828c4f9..dea099c7cd3721f586987baf8891a329815a3047 100644 (file)
@@ -984,7 +984,13 @@ def ioctl_partition_add(fd: int, nr: int, start: int, size: int) -> None:
 def ioctl_partition_remove(fd: int, nr: int) -> None:
     bp = blkpg_partition(pno=nr)
     ba = blkpg_ioctl_arg(op=BLKPG_DEL_PARTITION, data=ctypes.addressof(bp), datalen=ctypes.sizeof(bp))
-    fcntl.ioctl(fd, BLKPG, ba)
+    try:
+        fcntl.ioctl(fd, BLKPG, ba)
+    except OSError as e:
+        if e.errno != errno.EBUSY:
+            raise
+        else:
+            warn("Got EBUSY from the kernel while trying to remove partition, ignoring")
 
 
 @contextlib.contextmanager