Skip to content

cosa diff: add support for diffing metal images #4226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025

Conversation

jbtrystram
Copy link
Member

This add two flags: --metal and metal-part-table.

The former will mount the disk partitions using guestfs tools to the tmp-diff directory, then call git diff over the two mounted filesystems. It requires multithreading because the FUSE mount call is blocking so we mount the disks in two libreguest VMs that run in separate threads.

A simpler approach would have been to copy all the content to the tmp-diff folder but that would copy a lot of data just for diffing. It may be faster though.

The second flag --metal-part-table will simply show the partition table for the two images.

@jbtrystram jbtrystram requested a review from jlebon July 18, 2025 13:26
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a valuable feature for diffing metal images by utilizing guestfs and multiprocessing to efficiently compare images. However, there are critical issues with process lifecycle management and cleanup that could lead to resource leaks or crashes. Addressing these issues is important for the stability of this new feature.

@jbtrystram jbtrystram force-pushed the diff-metal branch 3 times, most recently from 3d0140e to 1a0a833 Compare July 18, 2025 13:47
This add two flags: `--metal` and `metal-part-table`.

The former will mount the disk partitions using guestfs tools to the
tmp-diff directory, then call git diff over the two mounted filesystems.
It requires multithreading because the FUSE mount call is blocking so
we mount the disks in two libreguest VMs that run in separate threads.

A simpler approach would have been to copy all the content to the
tmp-diff folder but that would copy a lot of data just for diffing. It
may be faster though.

The second flag `--metal-part-table` will simply show the partition
table for the two images.
Copy link
Member

@dustymabe dustymabe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jbtrystram jbtrystram merged commit 4bddeda into coreos:main Jul 21, 2025
5 of 6 checks passed
Copy link
Member

@jlebon jlebon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! I like the use of the libguestfs Python bindings.

Comment on lines +373 to +374
for i, d in enumerate([mount_dir_from, mount_dir_to]):
p = p_from if i == 0 else p_to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor/optional: I think a cleaner way to do this is:

for (p, d) in [(p_from, mount_dir_from), (p_to, mount_dir_to)]:

def diff_metal_partitions(diff_from, diff_to):
metal_from = get_metal_path(diff_from)
metal_to = get_metal_path(diff_to)
diff_cmd_outputs(['sgdisk', '-p'], metal_from, metal_to)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should use sfdisk here instead.

Comment on lines +333 to +339
# Mount the disks in the guestfs VM
root = g.findfs_label("root")
g.mount_ro(root, "/")
boot = g.findfs_label("boot")
g.mount_ro(boot, "/boot")
efi = g.findfs_label("EFI-SYSTEM")
g.mount_ro(efi, "/boot/efi")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally fine to start, though this will need adjustments to make it usable on other arches.

And we should definitely check other arches as part of coreos/fedora-coreos-tracker#1827.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants