Skip to content

feat: add SWAP partition detection and cleanup before loop device detach#568

Merged
rpandya28 merged 1 commit into
mainfrom
fix/ptl-pv-remove-swap-partition
May 20, 2026
Merged

feat: add SWAP partition detection and cleanup before loop device detach#568
rpandya28 merged 1 commit into
mainfrom
fix/ptl-pv-remove-swap-partition

Conversation

@rpandya28
Copy link
Copy Markdown
Contributor

Merge Checklist

All boxes should be checked before merging the PR

  • The changes in the PR have been built and tested
  • Documentation has been updated to reflect the changes (or no doc update needed)
  • Ready to merge

Description

Any Newly Introduced Dependencies

How Has This Been Tested?

2026-05-19T11:36:11.361Z INFO imagedisc/loopdev.go:112 Found SWAP partition: /dev/loop32p2, disabling it
2026-05-19T11:36:11.378Z INFO imagedisc/loopdev.go:117 Successfully disabled SWAP on /dev/loop32p2
2026-05-19T11:36:11.383Z INFO rawmaker/rawmaker.go:133 Successfully detached loopback device: /dev/loop32
2026-05-19T11:36:11.383Z INFO display/display.go:21 Checking for image artifacts in: /home/user/riddhi/image-composer-tool/workspace/ubuntu-ubuntu24-x86_64/imagebuild/minimal

@rpandya28 rpandya28 requested a review from a team as a code owner May 19, 2026 11:46
Copilot AI review requested due to automatic review settings May 19, 2026 11:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the loop device teardown path in internal/image/imagedisc to proactively detect SWAP partitions on a loop device and disable them before detaching the loop device, aiming to avoid detach failures caused by active swap.

Changes:

  • Added a pre-detach SWAP cleanup step in LoopSetupDelete.
  • Implemented lsblk -J parsing to locate swap partitions under the target loop device.
  • Issued swapoff for detected swap partitions and continued with detach regardless of swap cleanup outcome.
Comments suppressed due to low confidence (1)

internal/image/imagedisc/loopdev.go:66

  • LoopSetupDelete now executes lsblk (and potentially swapoff) via shell.ExecCmd before losetup -d. Existing unit tests for LoopSetupDelete (internal/image/imagedisc/loopdev_test.go) only mock the losetup -d ... command, so they will fall back to DefaultExecutor and try to run real lsblk/swapoff during tests. Update the tests/mocks to include the new commands (or refactor to make swap disabling injectable) so CI doesn't execute host commands.
func (loopDev *LoopDev) LoopSetupDelete(loopDevPath string) error {
	// Handle SWAP partitions before detaching
	if err := loopDev.disableSwapPartitions(loopDevPath); err != nil {
		log.Warnf("Warning while disabling SWAP partitions on %s: %v", loopDevPath, err)
		// Don't return error, try to continue with detach
	}

	cmd := fmt.Sprintf("losetup -d %s", loopDevPath)
	if _, err := shell.ExecCmd(cmd, true, shell.HostPath, nil); err != nil {
		log.Errorf("Failed to delete loop device %s: %v", loopDevPath, err)
		return fmt.Errorf("failed to delete loop device %s: %w", loopDevPath, err)

Comment thread internal/image/imagedisc/loopdev.go
Comment thread internal/image/imagedisc/loopdev.go
@rpandya28 rpandya28 force-pushed the fix/ptl-pv-remove-swap-partition branch from a7e6fcf to d2f5d48 Compare May 20, 2026 04:38
@rpandya28 rpandya28 merged commit 9a65f56 into main May 20, 2026
34 checks passed
@rpandya28 rpandya28 deleted the fix/ptl-pv-remove-swap-partition branch May 20, 2026 05:28
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