Skip to content

Commit cc98596

Browse files
authored
Merge pull request myugan#24 from yashdiq/main
enhance: add filesystem check and cleanup in MicroVM class
2 parents 523a888 + ae10c1f commit cc98596

2 files changed

Lines changed: 18 additions & 3 deletions

File tree

firecracker/microvm.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1366,6 +1366,10 @@ def _build_rootfs(self, image: str, file: str, size: str):
13661366
if self._config.verbose:
13671367
self._logger.debug(f"Formatting filesystem: {file} with size {size}")
13681368

1369+
run(f"e2fsck -f -y {file}")
1370+
if self._config.verbose:
1371+
self._logger.debug(f"Filesystem check completed for: {file}")
1372+
13691373
tmp_dir = tempfile.mkdtemp()
13701374
run(f"mount -o loop {file} {tmp_dir}")
13711375

@@ -1376,6 +1380,11 @@ def _build_rootfs(self, image: str, file: str, size: str):
13761380
if self._config.verbose:
13771381
self._logger.debug(f"Removed tar file: {tar_file}")
13781382

1383+
run(f"umount {tmp_dir}")
1384+
os.rmdir(tmp_dir)
1385+
if self._config.verbose:
1386+
self._logger.debug(f"Unmounted and removed temporary directory: {tmp_dir}")
1387+
13791388
if self._config.verbose:
13801389
self._logger.info("Build rootfs completed")
13811390

firecracker/network.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,9 +727,15 @@ def add_port_forward(self, id: str, host_ip: str, host_port: int, dest_ip: str,
727727

728728
try:
729729
for rule in rules["nftables"]:
730-
rc, output, error = self._nft.json_cmd({"nftables": [rule]})
731-
if rc != 0 and "File exists" not in str(error):
732-
raise NetworkError(f"Failed to add port forwarding rule: {error}")
730+
rc, _, error = self._nft.json_cmd({"nftables": [rule]})
731+
if rc != 0:
732+
error_str = str(error)
733+
ignore_errors = [
734+
"File exists",
735+
"already exists",
736+
]
737+
if not any(err in error_str for err in ignore_errors):
738+
raise NetworkError(f"Failed to add port forwarding rule: {error}")
733739

734740
if self._config.verbose:
735741
self._logger.info(f"Added port forwarding rule: {host_ip}:{host_port} -> {dest_ip}:{dest_port}")

0 commit comments

Comments
 (0)