]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Chunk partition insert using sendfile because sendfile has a maximum transfer size
authorMichael A Cassaniti <michael@cassaniti.id.au>
Fri, 7 Oct 2022 06:14:39 +0000 (17:14 +1100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Wed, 12 Oct 2022 12:54:26 +0000 (14:54 +0200)
mkosi/__init__.py

index 1b468f398511c25ddc0ae1b4d24994120cda8be9..9418aad175c6ff57b50c1691ed7375401b965626 100644 (file)
@@ -3661,7 +3661,15 @@ def insert_partition(
 
             # Without this the entire blob will be read into memory which could exceed system memory
             with open(path, mode='wb') as path_fp:
-                os.sendfile(path_fp.fileno(), blob.fileno(), offset=0, count=blob_size)
+                # Chunk size for 32/64-bit systems
+                # Chunking required because sendfile under Linux has a maximum copy size
+                chunksize = 2 ** 30 if sys.maxsize < 2 ** 32 else 0x7ffff000
+                offset = 0
+                while True:
+                    sent = os.sendfile(path_fp.fileno(), blob.fileno(), offset=offset, count=chunksize)
+                    if not sent:
+                        break
+                    offset += sent
 
     return part